akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner

fun main(args:Array<String>){
  val sc = Scanner(System.`in`)
  var right = sc.nextInt();
  right += sc.nextInt();
  var left = sc.nextInt();
  left += sc.nextInt();
 when{
  right > left -> println("Left")
  right < left -> println("Right")
  else -> println("Balanced")
}
}

Measured memory_bytes: 31268
#include <iostream>
#define MAX 100005
#define NIL -1

struct Node{int p,l,r;};

Node T[MAX];
int n,D[MAX];

void print(int u){
int c;
std::cout << "node " << u << ": ";
std::cout << "parent = " << T[u].p << ", ";
std::cout << "depth = " << D[u] << ", " ;

if(T[u].p == NIL)std::cout << "root, ";
else if(T[u].l == NIL) std::cout << "leaf, ";
else std::cout << "internal node, ";

std::cout << "[";

for(int i = 0,c=T[u].l;c!=NIL;++i,c=T[c].r){
if(i)std::cout<<", ";
std::cout << c;
}

std::cout << "]" <<std::endl;
}

int rec(int u,int p){
D[u] = p;
if(T[u].r != NIL)rec(T[u].r,p);
if(T[u].l != NIL)rec(T[u].l,p + 1);
}

int main(){
int v,d,c,l,r;
std::cin >> n;
for(int i=0;i<n;++i){
T[i].p = T[i].l = T[i].r = NIL;
}

for(int i=0;i<n;++i){
std::cin >> v >> d;
for(int j=0;j<d;++j){
std::cin >> c;
if(j==0)T[v].l = c;
else T[l].r =c;
l=c;
T[c].p = v;
}
}

for(int i=0;i<n;++i){
if(T[i].p == NIL) r=i;
}

rec(r,0);

for(int i=0;i<n;++i){
print(i);
}

return 0;

}

Measured memory_bytes: 7692
from collections import deque
import copy
import sys
#import numpy as np
sys.setrecursionlimit(410000)

INF = 10**6

h,w = map(int,input().split())
org_maze = [list(input()) for _ in range(h)]

def solve(sy,sx):
  d = [[INF]*w for _ in range(h)]
  for i in range(h):
    for j in range(w):
      if maze[i][j] == '#':
        d[i][j] = -INF          
  
  que = deque()
  que.append([sx,sy])
  d[sy][sx]=0

  while len(que)>0:
    px,py = que.popleft()

    for dx,dy in ((-1,0),(0,1),(1,0),(0,-1)):
      nx = px + dx
      ny = py + dy

      if (0 <= nx and nx < w and 0<=ny and ny < h) \
          and maze[ny][nx] != '#' \
          and (d[ny][nx] == INF or d[ny][nx] > d[py][px] +1):              
        que.append((nx,ny))
        d[ny][nx] = d[py][px] +1

  return d

ans = 0
for sy in range(h):
  for sx in range(w):
    maze = copy.deepcopy(org_maze)
    if maze[sy][sx] == '.':      
      f = solve(sy,sx)      
      for i in range(h):        
        ans = max(ans,max(f[i]))
          
print(ans)    

Measured memory_bytes: 54236
#include "bits/stdc++.h"
using namespace std;

#define say(obj) (cout << (obj) << endl)
#define endline (cout << endl)
#define all(container) (container).begin(), (container).end()
#define sortall(container) (sort((container).begin(), (container).end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to, cost;
	edge_(ll to, ll cost) : to(to), cost(cost) {}
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr int		INF = (int)1e7;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template <typename T>
T getSum(std::vector<T>& v) {
	T ret = 0;
	for (T& x : v) ret += x;
	return ret;
}

template <typename T>
istream& operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x;  return is; }
template <typename S, typename T>
istream& operator >> (istream & is, pair<S, T> & p) { is >> p.first >> p.second; return is; }
istream& operator >> (istream & is, point & p) { is >> p.x >> p.y;          return is; }

template <typename T>
ostream& operator << (ostream & os, const vector<T> & vec) { for (const T& x : vec) os << x << " "; return os; }
template <typename T>
ostream& operator << (ostream & os, const vector<vector<T>> & mat) { for (const vector<T>& m : mat) os << m << endl; return os; }
template <typename S, typename T>
ostream& operator << (ostream & os, const pair<S, T> & p) { os << "{" << p.first << " : " << p.second << "}"; return os; }
template <typename T>
ostream& operator << (ostream & os, const set<T> & s) { for (const T& x : s) os << x << " "; return os; }
ostream& operator << (ostream & os, const edge e) { os << "{to: " << e.to << ", cost: " << e.cost << "}"; return os; }
ostream& operator << (ostream & os, const point & p) { os << "(" << p.x << " " << p.y << ")"; return os; }

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	ll r, D, x2000;
	cin >> r >> D >> x2000;

	ll x = x2000;
	for (int i = 0; i < 10; i++)
	{
		x = x * r - D;
		say(x);
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static int const MAX = 100;

void trace(int A[], int N)
{
  for (int i = 0; i < N; i++)
  {
    if (i > 0)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
}

int bubbleSort(int A[], int N)
{
  bool flag = true;
  int i = 0;
  int count = 0;
  while (flag)
  {
    flag = false; // 交換できない時も終わりにするため
    for (int j = N - 1; j > i; j--)
    {
      if (A[j] < A[j - 1])
      {
        int temp = A[j - 1];
        A[j - 1] = A[j];
        A[j] = temp;
        flag = true;
        count++;
      }
    }
    i++;
  }
  return count;
}

int main()
{
  int N;
  int A[MAX];

  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }

  int count = bubbleSort(A, N);
  trace(A, N);
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3100
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N := ReadInt()
	as := ReadInts(N)

	sort.Ints(as)

	if N%2 == 0 {
		ans := 0
		i := N / 2
		ans += as[i]
		ans += 2 * Sum(as[i+1:]...)
		j := N/2 - 1
		ans -= as[j]
		ans -= 2 * Sum(as[:j]...)
		fmt.Println(ans)
		return
	}

	smalles := as[:N/2]
	larges := as[N/2:]
	ans1 := Sum(larges...) + Sum(larges[2:]...)
	ans1 -= 2 * Sum(smalles...)

	smalles = as[:N/2+1]
	larges = as[N/2+1:]
	ans2 := 2 * Sum(larges...)
	ans2 -= Sum(smalles...) + Sum(smalles[:len(smalles)-2]...)

	fmt.Println(Max(ans1, ans2))
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

func Sum(slice ...int) int {
	sum := 0
	for _, v := range slice {
		sum += v
	}
	return sum
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 4240
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int arr[6];
 
 int main()
 {
   while(cin>>arr[0])
   {
     for(int i=1;i<5;i++)
     {
       char temp;
       cin>>temp>>arr[i];        
     }                  
     sort(arr,arr+5);
     if((arr[0]==arr[1]&&arr[1]==arr[2]&&arr[2]==arr[3])||(arr[1]==arr[2]&&arr[2]==arr[3]&&arr[3]==arr[4])) cout<<"four card"<<endl;
     else if((arr[0]==arr[1]&&arr[1]==arr[2]&&arr[3]==arr[4])||(arr[0]==arr[1]&&arr[2]==arr[3]&&arr[3]==arr[4])) cout<<"full house"<<endl;
     else if((arr[0]==arr[1]&&arr[1]==arr[2])||(arr[1]==arr[2]&&arr[2]==arr[3])||(arr[2]==arr[3]&&arr[3]==arr[4])) cout<<"three card"<<endl;
     else
     {
       int count=0;
       for(int i=0;i<4;i++)
       {
         if(arr[i]==arr[i+1]) count++;        
       }    
       if(count==1) cout<<"one pair"<<endl;
       else if(count==2) cout<<"two pair"<<endl;
       else
       {
         bool flag=true;
         for(int i=0;i<4;i++)
         {
           int kk=arr[i+1]-arr[i];
           if(!(kk==1||kk==9))
           {
             flag=false;
             break;                     
           }          
         }    
         if(flag) cout<<"straight"<<endl;
         else cout<<"null"<<endl; 
       }
     }       
   }
   //while(1);
   return 0;
 }

 

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

ll n,K,x[55],y[55],xm,xM,ym,yM,ans=5e18;

bool f(ll i,ll j,ll k, ll l){
  int a=0;
  fr(I,n) if(i<=x[I]&&x[I]<=j&&k<=y[I]&&y[I]<=l) a++;
  //cout<<a<<endl;
  return a>=K;
}

int main(){
  cin>>n>>K;
  fr(i,n) cin>>x[i]>>y[i];
  fr(i,n){
    fr(j,n){
      fr(k,n){
        fr(l,n){
          xm=min(min(x[i],x[j]),min(x[k],x[l]));
          xM=max(max(x[i],x[j]),max(x[k],x[l]));
          ym=min(min(y[i],y[j]),min(y[k],y[l]));
          yM=max(max(y[i],y[j]),max(y[k],y[l]));
          //cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;
          //cout<<xm<<" "<<xM<<" "<<ym<<" "<<yM<<endl;
          if(f(xm,xM,ym,yM)) ans=min(ans,(xM-xm)*(yM-ym));
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
while true
    n, m = gets.chomp.split.map(&:to_i)
    break if [n, m] == [0, 0]
    h = Hash.new(0)
    n.times{gets.chomp.split.map(&:to_i).each_with_index{|x, i| h[i + 1] += x}}
    puts h.to_a.sort_by{|a, b| [-b, a]}.map{|a, b| a}.join(" ")
end



Measured memory_bytes: 7096
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int a,b,c,x;
    int an=0,bn=0,cn=0;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    int count=0;

    for(int i = 0; i<=a;i++){
        for(int j = 0; j<=b;j++){
            for(int k = 0; k<=c;k++){
                if(500*i+100*j+50*k==x){
                    count++;
                }
            }
        }
    }


    cout << count << endl;
}

Measured memory_bytes: 256
import math
prime = [i for i in range(2, 10**5+1)]
for i in range(2, math.floor(math.sqrt(10**5))+1):
    prime = [p for p in prime if (p == i or p % i != 0)]
isPrime = [False for i in range(10**5+1)]
for p in prime:
    isPrime[p] = True
cntPrime = [0 for i in range(10**5+1)]
for i in range(2, 10**5+1):
    if i % 2 == 1 and isPrime[i] and isPrime[(i+1)//2]:
        cntPrime[i] = cntPrime[i-1]+1
    else:
        cntPrime[i] = cntPrime[i-1]

Q = int(input())
for i in range(Q):
    l, r = [int(_) for _ in input().split()]
    print(cntPrime[r]-cntPrime[l-1])

Measured memory_bytes: 8216
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   int N;
   cin >> N;
   int A[N];
   for (int i = 0; i < N; i++)
   {
      cin >> A[i];
   }
   long long ans = INT_MAX;
   for(int p = 0; p < 110; p++){
      long long sum = 0;
      for(int j = 0;j<N;j++){
         sum += (A[j]-p)*(A[j]-p);
      }
      ans = min(ans,sum);
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
int f(int N,int i){
    if (i>=1) return i;
    else return N+i;
}

int main(){
    integer N,x;
    SCLLD2(N,x);

    integer a[2002];

    FORq(i,1,N){ SCLLD(a[i]); }

    static integer dp[2002][2002];

    FORq(i,1,N){
        dp[i][0] = a[i];
    }

    FORq(k,1,N-1){
        dp[1][k] = min(dp[1][k-1],a[f(N,1-k)]);
    }

    FORq(i,2,N){
        FORq(k,1,N-1){
            dp[i][k] = min(dp[i][k-1],a[f(N,i-k)]);
        }
    }

    integer ans = 1000000000000000;
    FORq(k,0,N-1){
        integer msum = 0;
        FORq(i,1,N){
            msum += dp[i][k];
        }
        ans = min(ans,k*x + msum);
    }
    PRINTLLD(ans);
}




Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
typedef long long ll;
using namespace std;

int main(){
  string s,s1,s2;
  ll count1=0,count2=0,count3=0;
  cin >> s;
  s1=s+s;
  s2=s+s+s;
  r(i,s.length()-1){
    if(s.at(i)==s.at(i+1)){
      count1++;
      s.at(i+1)='A';
    }
  }
  r(i,s1.length()-1){
    if(s1.at(i)==s1.at(i+1)){
      count2++;
      s1.at(i+1)='A';
    }
  }
  r(i,s2.length()-1){
    if(s2.at(i)==s2.at(i+1)){
      count3++;
      s2.at(i+1)='A';
    }
  }
  ll k,ans;
  cin >> k;
  ans=(k-1)/2*(count3-count2)+k/2*(count2-count1)+count1;
  cout << ans << endl;
  }

Measured memory_bytes: 256
N, M = (int(i) for i in input().split())

dd = [[0]*N for i in range(8)]


for i in range(N):
    x, y, z = (int(i) for i in input().split())
    for j in range(8):
        xx, yy, zz = (x, y, z)
        if format(j, "b").zfill(3)[0] == "1":
            xx = -x
        if format(j, "b").zfill(3)[1] == "1":
            yy = -y
        if format(j, "b").zfill(3)[2] == "1":
            zz = -z
        dd[j][i] = xx + yy + zz
        

reslis = []
for d in dd:
    d.sort()
    d.reverse()
    reslis.append(sum(d[:M]))
print(max(reslis))

Measured memory_bytes: 49260
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long  a[100050];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    sort(a,a+n);
    long long x=0,y=0;
    int i=n-1;
    int l=1;
   while(i>0)
    {
        if(x!=0&&y!=0)break;
        if(a[i]==a[i-1])
        {

            l++;
           if(l>=2&&x==0)
            {x=a[i];l=1;}
            else if(l>=2&&x!=0)
            {
                y=a[i];l=1;
            }
           i=i-2;
        }
        else
        {
            i--;
        }
    }
    long long  sum=x*y;
    printf("%lld\n",sum);
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n,m = list(map(int,input().split()))
#n=1 もしくは m=1の時とその他の時を分けて考える
ret = 0
if n==1:
    if m==1:
        ret=1
    else:
        ret=m-2
else:
    #n>=2
    if m==1:
        ret=n-2
    else:
        ret=(n-2)*(m-2)
print(ret)

Measured memory_bytes: 3060
n, l, t = map(int,input().split())

c = []
s = 0

for i in range(n):
    x, w = map(int,input().split())
    if w == 1:
        c.append((x+t)%l)
        s += (x+t)//l
    else: # w == 2
        c.append((x-t)%l)
        s += (x-t)//l

c.sort()
s %= n
c = c[s:] + c[:s]
print(*[i for i in c], sep='\n')

Measured memory_bytes: 9688
#include <bits/stdc++.h>
using namespace std;

#define IOS cin.tie(0);ios::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?' ':'\n'); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

void split_int(vector<int> &v,string s){
    for(auto item:s){
        v.emplace_back(item-'0');
    }
}

signed main(){
    SCIN(N);
    vi vec;
    split_int(vec,N);
    flag=false;
    rep(i,3)if(vec[i]==7)flag=true;
    Yes(flag);

    return 0;
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> x(n);
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=2*min(abs(x[i]),abs(k-x[i]));
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include <stdio.h>
int max(int a,int b){return a>b?a:b;}
int main(void){
    int n,i,j,c[40]={},kb[40];
    long k,a,s,ans=0;
    scanf("%d%ld",&n,&k);k++;
    for(i=0;i<n;i++){
        scanf("%ld",&a);
        for(j=0;j<40;j++){
            c[j]+=a%2;a>>=1;
        }
    }
    for(i=0;i<40;i++){
        kb[i]=k%2;k>>=1;
    }
    for(i=0;i<40;i++){
        if(kb[i]){
            s=0;
            for(j=39;j>i;j--)s+=(1l<<j)*(kb[j]?(n-c[j]):c[j]);
            s+=(1l<<i)*c[j];
            for(j=0;j<i;j++)s+=(1l<<j)*max(c[j],n-c[j]);
            ans=ans>s?ans:s;
        }
    }
    printf("%ld",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int h,w,n;
    cin >> h >> w >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    int ans[h][w];

    int count = a[0], counti = 1;
    for (int i = 0; i < h; i++)
    {
        if(i % 2 == 0)
        {
            for (int j = 0; j < w; j++)
            {
                ans[i][j] = counti;
                count--;
                if(count == 0)
                {
                    count = a[counti];
                    counti++;
                }
            }
        }
        else
        {
            for (int j = w - 1; j >= 0; j--)
            {
                ans[i][j] = counti;
                count--;
                if(count == 0)
                {
                    count = a[counti];
                    counti++;
                }
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    
    
}

Measured memory_bytes: 384
l=gets.to_i;n=l.bit_length;p n,n*2+l.to_s(2).count(?1)-3;(n-1).times{|i|p i+1,i+2,0;p i+1,i+2,1<<i;l[i]==1&&p(i+1,n,l-=1<<i)}

Measured memory_bytes: 1788
n = int(input())
a = sorted(list(map(int, input().split())))
if n % 2 == 0:
    b,s = [1,1],3
else:
    b,s = [0],2
for i in range(s,n,2):
    b += [i,i]
if a == b:
    print(pow(2,n//2,1000000007))
else:
    print(0)

Measured memory_bytes: 20580
/*************************************************************************
    > File Name: 010A.cpp
    > Author: HandsomeHow
    > Mail: handsomehowyxh@gmail.com 
    > Created Time: 2017/2/5 18:16:24
 ************************************************************************/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1.0);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★------------------------------------------------
int cnt[4];
int main(){
#ifdef HandsomeHow
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	int n;
	gn(n);
	rep(i,1,n){
		int x;gn(x);
		x = x % 2;
		cnt[x]++;
	}
	rep(i,2,n){
		if(cnt[0] >= 2){
			cnt[0]--;
		}else if(cnt[1] >= 2){
			cnt[0]++;
			cnt[1]-=2;
		}else{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    int n; cin >> n;
    map<int, int> mp;
    rep(i, n-1) {
        int a; cin >> a;
        mp[a-1]++;
    }
    rep(i, n) cout << mp[i] << endl;
}


Measured memory_bytes: 12980
#include<bits/stdc++.h>
using namespace std;
#define gc getchar
inline int read(){
    register int x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
int n,m,a[188][188],sum[188][188];
inline bool ok(int _x1,int _y1,int _x2,int _y2){
	int xx=sum[_x2][_y2]-sum[_x2][_y1-1]-sum[_x1-1][_y2]+sum[_x1-1][_y1-1];
	return (xx==0||xx==(_x2-_x1+1)*(_y2-_y1+1));
}
int R[17][188][188][188],D[17][188][188][188];
inline void chkmax(int &a,const int &b){if (a<b) a=b;}
signed main(){
	n=read(),m=read();
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			char ch=gc();
			while (ch!='.'&&ch!='#') ch=gc();
			a[i][j]=(ch=='.'?0:1);
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j];
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=i;j<=n;j++){
			int las=-1;
			for (int k=m;k;k--){
				if (ok(i,k,j,k)){
					if (las==-1||!ok(i,k,j,las)) las=k;
				}else las=-1;				
				R[0][i][j][k]=las;
			}
		}
	}
	for (int i=1;i<=m;i++){
		for (int j=i;j<=m;j++){
			int las=-1;
			for (int k=n;k;k--){
				if (ok(k,i,k,j)){
					if (las==-1||!ok(k,i,las,j)) las=k;
				}else las=-1;				
				D[0][i][j][k]=las;
			}
		}
	}
	//
	if (ok(1,1,n,m)){
		puts("0");
		return 0;
	}
	for (int as=1;;as++){
		for (int i=1;i<=n;i++){
			for (int j=i;j<=n;j++){
				for (int k=1;k<=m;k++){
					if (R[as-1][i][j][k]==m) R[as][i][j][k]=m;
					else if (R[as-1][i][j][k]==-1) R[as][i][j][k]=-1;
					R[as][i][j][k]=max(R[as-1][i][j][k],R[as-1][i][j][R[as-1][i][j][k]+1]);
				}
			}
		}
		for (int i=1;i<=m;i++){
			for (int j=i;j<=m;j++){
				for (int k=1;k<=n;k++){
					if (D[as-1][i][j][k]==n) D[as][i][j][k]=n;
					else if (D[as-1][i][j][k]==-1) D[as][i][j][k]=-1;
					D[as][i][j][k]=max(D[as-1][i][j][k],D[as-1][i][j][D[as-1][i][j][k]+1]);
				}
			}
		}
		for (int i=1;i<=n;i++){
			for (int j=i;j<=n;j++){
				int las=m+1;
				for (int k=m;k;k--){
					for (;las>k;las--){
						int nxt=D[as-1][k][las-1][i];
						if (nxt==-1) continue;
						if (nxt<j){
							if (D[as-1][k][las-1][nxt+1]>=j) break;
						}else break;
					}
					if (las!=k)	chkmax(R[as][i][j][k],las-1);
				}
			}
		}
		for (int i=1;i<=m;i++){
			for (int j=i;j<=m;j++){
				int las=n+1;
				for (int k=n;k;k--){
					for (;las>k;las--){
						int nxt=R[as-1][k][las-1][i];
						if (nxt==-1) continue;
						if (nxt<j){
							if (R[as-1][k][las-1][nxt+1]>=j) break;
						}else break;
					}
					if (las!=k)	chkmax(D[as][i][j][k],las-1);
				}
			}
		}
		if (R[as][1][n][1]==m){
			cout<<as;
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 458180
s = input()
if len(s) >= 6 and\
   any([(c in s) for c in "1234567890"]) and\
   any([(c in s) for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]) and\
   any([(c in s) for c in "abcdefghijklmnopqrstuvwxyz"]):
   print("VALID")
else:
  print("INVALID")


Measured memory_bytes: 5568
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::pair<ll,int> pli;
typedef std::vector<int> vi;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N,M;
int B[100010];
ll A[100010],C[100010];
bool comp(pli& a,pli& b){
  return a.first>b.first;
}
int main(){
  cin>>N>>M;
  rep(i,N) cin>>A[i];
  rep(i,M){
    cin>>B[i]>>C[i];
  }
  pli p[100010];
  rep(i,M){
    p[i]=mp(C[i],B[i]);
  }
  std::sort(A,A+N);
  std::sort(p,p+M,comp);
  int j=0;
  rep(i,M){
    int b=p[i].second,c=p[i].first;
    rep(k,b){
      if(A[j]<c){
	A[j]=c;
	j++;
      }
      else{
	ll res=0;
	rep(i,N){
	  res+=A[i];
	}
	prin(res);
	return 0;
      }
    }
  }
  ll res=0;
  rep(i,N){
    res+=A[i];
  }
  prin(res);
  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    int n,m;
    cin >>n >>m;

    int ct=0;
    rep(i,n/2+1)
    {
        if(i) printf(" ");
        printf("%d", 0);
        ++ct;
    }
    while(ct<n)
    {
        printf(" %d", m);
        ++ct;
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 3232
func main2(input1: String = readLine()!) {
    let integers = input1.split(separator: " ").map { Int($0)! }
    let n = integers[0]
    let m = integers[1]
    
    var parents = [Int](repeating: -1, count: n)
    
    func groupLeader(of someone: Int) -> Int {
        let parent = parents[someone]
        if parent < 0 {
            return someone
        } else {
            let leader = groupLeader(of: parent)
            parents[someone] = leader
            return leader
        }
    }
    
    for _ in 0..<m {
        let integers = readLine()!.split(separator: " ").map { Int($0)! }
        let a = integers[0] - 1
        let b = integers[1] - 1
        
        var leader1 = groupLeader(of: a)
        var leader2 = groupLeader(of: b)
        if leader1 == leader2 { continue }
        if parents[leader1] > parents[leader2] {
            swap(&leader1, &leader2)
        }
        parents[leader1] += parents[leader2]
        parents[leader2] = leader1
    }
    
    var answer = 0
    for someone in 0..<n {
        answer = max(answer, -parents[groupLeader(of: someone)])
    }
    print(answer)
}

main2()

Measured memory_bytes: 9372
n,k = map(int,input().split())
a = list(map(int,input().split()))

for _ in range(k):
    r = [0]*(n+1)
    for i in range(n):
        r[max(i-a[i],0)] += 1
        r[min(i+a[i]+1,n)] -= 1
    for i in range(n-1):
        r[i+1] += r[i]
    a = r
    if a.count(n)==n:
        break
print(*a[:-1])


Measured memory_bytes: 109380
h,w=map(int,input().split())
grid=[None]*h
for i in range(h):
  grid[i]=input()
  
dp=[[0 for i in range(w)] for j in range(h)]
DIV=10**9+7

for i in range(h):
  for j in range(w):
    if grid[i][j]=="#":
      dp[i][j]=0
    elif i==0 and j==0:
      dp[i][j]=1
    else:
      up=0
      left=0
      if i>0:
        up=dp[i-1][j]
      if j>0:
        left=dp[i][j-1]
      dp[i][j]=(up+left)%DIV
        
print(dp[-1][-1])

Measured memory_bytes: 44628
#include <stdio.h>
#include <stdlib.h>


void swap(int *x,int *y)
{
	int tmp = *x;
	*x = *y;
	*y = tmp;
}

void SelectionSort(int *list,int n)
{
	int i,j;
	int minindex;
	int count = 0;
	for(i=0; i<n; i++){
		minindex = i;
		for(j=i; j<n; j++){
			if(list[minindex] > list[j])
				minindex = j;
		}
		if(minindex != i){
			swap(&list[i],&list[minindex]);
			count++;
		}
	}

	for(i=0; i<n; i++){
		printf("%d",list[i]);
		if(i != (n-1)){
			printf(" ");
		}
	}
	printf("\n%d\n",count);
}

int main()
{
	int n;
	scanf("%d",&n);

	int *list = malloc(n*sizeof(int));

	int i;
	for(i=0; i<n; i++){
		scanf("%d",&list[i]);
	}

	SelectionSort(list,n);

	return(0);
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

vector<ll> div(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.push_back(i);
			if (i * i != n) res.push_back(n / i);
		}
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	auto mp = div(n);
	ll ans = 0;
	for (auto& c : mp) {
		if (c == 1) continue;
		ll tmp = n;
		ll now = c;
		while (tmp % now == 0) tmp /= now;
		tmp %= now;
		if (tmp == 1) ans++;
	}
	ans += div(n - 1).size() - 1;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3732
import java.util.*;

class Main{
    int[] a;
    long out;
    void solve(){
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        a = new int[s.length()];
        for(int i = 0; i < s.length(); i++){
            a[i] = Integer.parseInt(Character.toString(s.charAt(i)));
        }
        dfs(0, a[0], 0);
        System.out.println(out);
        scan.close();
    }
    
    void dfs(int i, long cn, long sum){
        int n = a.length;
        if(i == n - 1){
            out += sum + cn;
            return;
        }
        dfs(i + 1, a[i + 1], sum + cn);
        dfs(i + 1, cn * 10 + a[i + 1], sum);
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 26760
S = []
mod=[]
for _ in range(5):
  S.append(int(input()))

for _ in S:
  if(_%10==0):
    mod.append(10)
  else:
    mod.append((_)%10)

sum=0    

for _ in range(len(S)):
  if _ == mod.index(min(mod)):
	# mod10のあまりが一番大きいやつを最後に足す(のでそのまま)
    sum += S[_]
  else:
    #mod10のあまりがなかったらそのまま足す
    if mod[_]==10:
      sum += S[_]
    #余りがあるなら
    else:
      sum += (S[_]//10+1)*10
      
print(sum)
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;
    long long ans = 0;
    for (int b = 1; b <= N; b++) {
        ans += (N / b) * max(b - K, 0);
        ans += K > 0 ? max(N % b - K + 1, 0) : N % b;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  cin >> S;

  int counta = 0;
  int countb = 0;
  
  for (int i = 0; i < S.size(); i++) {
  
    if (S.at(i) == 'A') {
      counta++;
    }
    else if (S.at(i) == 'B') {
      countb++;
    }
  }
  
  if (counta == 3 or countb == 3){
   cout << "No" << endl;
  }
  else{
   cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

int N;
int a[100005], b[100005];
int A[100005], B[100005];
UnionFind uf(100005);
vector<int> comp;

int main(void)
{
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> a[i];
	for(int i = 1; i <= N; i++) a[0] ^= a[i];
	for(int i = 1; i <= N; i++) cin >> b[i];
	
	for(int i = 0; i <= N; i++) A[i] = a[i], B[i] = b[i];
	sort(A, A+N+1), sort(B+1, B+N+1);
	
	int p = 0, dif = -1;
	for(int i = 1; i <= N; i++, p++){
		if(B[i] != A[p]){
			if(dif == -1){
				i--;
				dif = p;
			}
			else{
				cout << -1 << endl;
				return 0;
			}
		}
	}
	if(dif == -1) b[0] = A[N];
	else b[0] = A[dif];
	
	for(int i = 0; i <= N; i++) comp.push_back(a[i]);
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	for(int i = 0; i <= N; i++){
		a[i] = lower_bound(comp.begin(), comp.end(), a[i]) - comp.begin();
		b[i] = lower_bound(comp.begin(), comp.end(), b[i]) - comp.begin();
	}
	
	int ans = 0;
	for(int i = 1; i <= N; i++){
		if(a[i] != b[i]) uf.unite(a[i], b[i]), ans++;
	}
	set<int> S;
	S.insert(uf.root(a[0]));
	for(int i = 1; i <= N; i++) if(a[i] != b[i]) S.insert(uf.root(a[i]));
	ans += S.size() - 1;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4984
#include<set>  
#include<map> 
#include<stack>
#include<cmath>  
#include<cstdio>  
#include<queue>  
#include<vector>  
#include<climits>  
#include<cstring>  
#include<iostream>  
#include<algorithm>  
using namespace std;
#define eps 1
#define MAXN 1000
#define INF 0x3f3f3f3f  
long long read(){  
    long long f=1,x=0;  
    char c=getchar();  
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}  
    while('0'<=c&&c<='9') x=x*10+c-'0',c=getchar();  
    return f*x;  
}
int main()  
{
	long long n=read(),m=read(),tmp=n*m-2LL*(n-1+m-1);
	if(n==1&&m==1){printf("1\n");return 0;}
	if(n==1||m==1){printf("%d\n",max(n,m)-2);return 0;}
	printf("%lld\n",tmp);
	return 0;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

void dfs(ll a, ll use, ll n, ll& ans) {
  if (a > n) return;
  if (use == 0b111) ans++;
  rep(i,3) {
    int j = i * 2 + 3;
    int mask = 1 << i;
    dfs(a * 10 + j, use | mask, n, ans);
  }
}

int main() {
  ll n; cin >> n;
  ll ans = 0;
  dfs(0, 0, n, ans);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> l(n + 1), r(n + 1);
  for (int i = 0; i < n; i++) l[i + 1] = gcd(l[i], a[i]);
  for (int i = n - 1; i >= 0; i--) r[i] = gcd(r[i + 1], a[i]);

  ll ans = 0;
  rep(i, n) {
    ll g = gcd(l[i], r[i + 1]);
    ans = max(ans, g);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4580
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 1000005
#define PI 3.14159265358979323846264338327950
 
#define ll    long long int
#define mod  1000000007
ll t ,  ans;
int main()
{
	FAST;
	ll n;
	cin >> n;
	ans = n*(1 + n) + n*(n*n);
	cout << ans;
	return 0;
}

Measured memory_bytes: 3624
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int na, nb, m;
    cin >> na >> nb >> m;
    vector<int> a(na), b(nb);
    for(auto &x : a){
        cin >> x;
    }
    for(auto &x : b){
        cin >> x;
    }
    int mn = *min_element(ALL(a));
    mn += *min_element(ALL(b));
    // debug(mn);
    while(m--){
        int x, y, c;
        cin >> x >> y >> c;
        int cost = a[x - 1] + b[y - 1] - c;
        if(cost < mn){
            mn = cost;
        }
    }
    cout << mn;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Linq.Expressions;

static class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int N, A, B;
    private void Scan()
    {
        var line = Console.ReadLine().Split(' ');
        N = int.Parse(line[0]);
        A = int.Parse(line[1]);
        B = int.Parse(line[2]);
    }



    public void Solve()
    {
        Scan();
        if (A > B)
        {
            Console.WriteLine(0);
            return;
        }
        if (A == B)
        {
            Console.WriteLine(1);
            return;
        }
        if(N == 1)
        {
            Console.WriteLine(0);
            return;
        }
        long min = (long)A * (N - 1) +(long) B;
        long max = (long)A + (long)B * (N - 1);
        Console.WriteLine(max - min + 1);
    }
}

Measured memory_bytes: 11092
n,k=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr, key=lambda x:x[0])
sum=0
for i in range(n):
  if sum<k<=sum+arr[i][1]:
    print(arr[i][0])
  sum=sum+arr[i][1]

Measured memory_bytes: 29912
#include <bits/stdc++.h>
using namespace std;

long long MOD=1000000007LL;

int main(){
	int N;
	long long ans=1;
	cin >> N;
	vector<int> T(N);
	vector<int> A(N);
	for(auto &i:T)cin >> i;
	for(auto &i:A)cin >> i;
	
	vector<bool> t(N,false);
	vector<bool> a(N,false);
	
	for(int i=0;i<N;i++){
		if(i==0)t[i]=true;
		else if(T[i-1]<T[i])t[i]=true;
	}
	for(int i=N-1;i>=0;i--){
		if(i==N-1)a[i]=true;
		else if(A[i+1]<A[i])a[i]=true;
	}
	
	for(int i=0;i<N;i++){
		if(t[i] && a[i]){
			if(T[i]!=A[i])ans*=0;
		}
		else if(t[i]){
			if(T[i]>A[i])ans*=0;
		}
		else if(a[i]){
			if(T[i]<A[i])ans*=0;
		}
		else{
			ans*=1LL*min(T[i],A[i]);
		}
		if(ans>=MOD)ans%=MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  
  if(s < t) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main() {
	string str;
	cin >> str;
	int len = str.length();
	char* s = new char[len + 1];
	memcpy(s, str.c_str(), len + 1);
	len += 1;
	int i;
	int a = 0;
	for (i = 0; i < len - 2; i++) {
		if (s[i] == s[i + 1]) {
			cout << i+1 << " " << i + 2 << endl;
			a = 1;
			break;
		}
		if (s[i] == s[i + 2]) {
			cout << i+1 << " " << i + 3 << endl;
			a = 1;
			break;
		}
		if (s[i+1] == s[i + 2]) {
			cout << i+2 << " " << i + 3 << endl;
			a = 1;
			break;
		}
	}
	if (a == 0) {
		cout << -1 << " " << -1 << endl;
	}
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
long long int n,m,k;
long long int all=0;
vector<long long int> a,b;
int main(void){
  cin>>n>>m>>k;
  a.resize(n+1);
  b.resize(m+1);
  a.at(0)=0;
  b.at(0)=0;
  for(long long int i=0; i<n; i++){
    long long int hoge;
    cin>>hoge;
    a.at(i+1)=a.at(i)+hoge;
  }
  for(long long int i=0; i<m; i++){
    long long int hoge;
    cin>>hoge;
    b.at(i+1)=b.at(i)+hoge;
  }
  all=a.at(n)+b.at(m);
  if(all<=k){
    cout<<n+m<<endl;
  }else{
    long long int ans=0;
    for(long long int i=0; i<=n; i++){
      long long int pre=i;
      long long int high=m;
      long long int low=0;
      long long int mid;
      long long int hoge;
      while(high>=low){
        mid=(high+low)/2;
        hoge=a.at(i)+b.at(mid);
        if(hoge==k){
          break;
        }else if(hoge>k){
          high=mid-1;
        }else{
          low=mid+1;
        }
      }
      if(hoge>k){
        if(mid!=0&&a.at(i)+b.at(mid-1)<=k){
          ans=max(ans,i+mid-1);
        }
      }else{
        if(mid!=m&&a.at(i)+b.at(mid+1)<=k){
          ans=max(ans,i+mid+1);
        }else{
          ans=max(ans,i+mid);
        }
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 6320
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int n, comparison;
int num[101];

void binarysearch(int v){
  int l = 0;
  int r = n-1;
  int x;
 
  while(l <= r){
    x = (l+r)/2;
    comparison++;
    if(num[x] < v) l = x+1;
    else if(num[x] > v) r = x-1;
    else break;
  }
}

int main(){
  int search_value;
  
  while(cin >> n, n){
    comparison = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> num[i];
    }
    cin >> search_value;
    
    binarysearch(search_value);
    
    cout << comparison << endl;
  }
  return 0;
}



    
    

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define main() int main()
#define ff1(i,n) for(int i=1;i<=n;++i)
#define ff0(i,n) for(int i=0;i<n;++i)
#define pi acos(-1.0)
#define ms(a, x) memset(a, x, sizeof(a))
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define binarycount __builtin_popcount(x)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define fir first
#define sec second
#define debug(x) cout<<x<<'\n'
#define sa(a) scanf("%d", &a)
#define sab(a, b) scanf("%d%d", &a, &b)
#define pa(a) printf("%d",a)
#define pab(a,b) printf("%d%d",a,b)
#define pii pair<string,int>
using namespace std;

#define maxn 100010
const int inf = 0x3f3f3f3f;
const int mod = 9973;
const double eps = 1e-8;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
int max(int x,int y){if(x>y) return x;return y;}
ll powmod(ll a,ll b){
    ull ans = 1, pow = a%mod;
    while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; }
    return ans%mod;
}
main(){
	IO;
    ll n,w;
	cin>>n>>w;
	ll a[n+1][2]={0};
	for(ll i=1;i<=n;i++) {
		cin>>a[i][0]>>a[i][1];
	}
	
	ll dp[n+1][w+5]={0};
	ms(dp,0);
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=w;j++){
			
			if(j<a[i][0])dp[i][j]=dp[i-1][j];
			else dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i][0]]+a[i][1]);
		}
	}
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 79232
using System;

namespace ITP1_6_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var memo = new int[5, 4, 11];
            var n = int.Parse(Console.ReadLine());
            for(int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split(' ');
                var b = int.Parse(input[0]);
                var f = int.Parse(input[1]);
                var r = int.Parse(input[2]);
                var v = int.Parse(input[3]);
                memo[b, f, r] += v;
            }

            var s = new string('#', 20);
            for(int i = 1; i < 5; i++)
            {
                for(int j = 1; j < 4; j++)
                {
                    for(int k = 1; k < 11; k++)
                    {
                        Console.Write(" {0}", memo[i, j, k]);
                    }
                    Console.WriteLine();
                }
                if (i < 4)
                    Console.WriteLine(s);
            }
        }
    }
}

Measured memory_bytes: 9172
#include<iostream>
#include<cstdlib>
#include<vector>
using namespace std;

void makeSet(vector<int>* set, int size);
int find(vector<int> *v, int x);
void unite(vector<int> *v, int root1, int root2);
void printV(vector<int>* v);

int main()
{
    int n, q;
    cin >> n >> q;

    vector<int> set;
    makeSet(&set, n);

    int com, x, y;
    for(int i=0; i<q; i++){
        cin >> com >> x >> y;

        switch(com){
        case 0 :
            unite(&set, find(&set, x), find(&set, y));
            break; 
        case 1 :
            find(&set, x) == find(&set, y) ? cout << "1" : cout << "0";
            cout << endl;
            break;
        }
        // printV(&set);
    }
    
    return 0;
}

void makeSet(vector<int>* set, int size)
{
    for(int i=0; i<size; i++) set->push_back(i);
}

int find(vector<int> *v, int x)
{
    if( !(x >= 0 && x < v->size()) ) exit(1);

    if( v->at(x) == x ) return x;
    else find(v, v->at(x));
}

void unite(vector<int> *v, int root1, int root2)
{
    if( find(v, root1) == find(v, root2) ) return;

    if( !( (root1>=0 && root1<v->size()) && (root2>=0 && root2<v->size()) ) )
        return;

    v->at(root1) = root2;
}

void printV(vector<int>* v)
{
    for(int i=0; i<v->size(); i++) cout << v->at(i) << " ";
    cout << endl;
}

Measured memory_bytes: 1320