akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int _main(){
    
    int h,w;
    cin >> h >> w;  
    int _sx,_sy,sx,sy;
    cin >> _sy >> _sx;  
    int _gx,_gy,gx,gy;
    cin >> _gy >> _gx;
    sx = _sx-1; sy = _sy-1;
    gx = _gx-1; gy = _gy-1;

    vector<vector<bool>> road(w, vector<bool>(h));
    for (int y=0; y<h; y++) {
        for (int x=0; x<w; x++) {
            char c;
            cin >> c;
            if(c=='.'){
                road[x][y]=true;
            }else{
                road[x][y]=false;
            }
        }
    }

    vector<vector<int>> cost(w, vector<int>(h,INFINITY));
    queue<tuple<int,int>> searchfrom;
    vector<vector<bool>> searched_b(w, vector<bool>(h,false));
    searchfrom.push(tuple<int,int>(sx,sy));
    int costnow = 0;
    while(true){
        queue<tuple<int,int>> searching = queue<tuple<int,int>>(searchfrom);
        queue<tuple<int,int>> searched  = queue<tuple<int,int>>();
        searchfrom = queue<tuple<int,int>>();
        while(searching.size()>0){
            tuple<int,int> coord = searching.front();
            int cx = get<0>(coord); int cy = get<1>(coord);
            searching.pop();
            if(cx==gx && cy==gy){
                return costnow;
            }

            for(int x=max(0,cx-1); x<=min(w-1,cx+1); x++){
                for(int y=max(0,cy-1); y<=min(h-1,cy+1); y++){
                    int lenSu = abs(x-cx)+abs(y-cy);
                    if(road[x][y] && costnow<cost[x][y]){
                        if(lenSu==0){
                            cost[x][y] = costnow;
                            searched_b[x][y]=true;
                            searched.push(tuple<int,int>(x,y));
                        }else if(lenSu==1 && !searched_b[x][y]){
                            searched_b[x][y]=true;
                            searching.push(tuple<int,int>(x,y));
                        }
                    }
                }
            }
        }
        while(searched.size()>0){
            tuple<int,int> coord = searched.front();
            int cx = get<0>(coord); int cy = get<1>(coord);
            searched.pop();

            for(int x=max(0,get<0>(coord)-2); x<=min(w-1,get<0>(coord)+2); x++){
                for(int y=max(0,get<1>(coord)-2); y<=min(h-1,get<1>(coord)+2); y++){
                    if(road[x][y] && costnow<cost[x][y]){
                        searchfrom.push(tuple<int,int>(x,y));
                    }
                }
            }
        }
        if(searchfrom.size()==0) return -1;
        costnow++;
    }
}

int main(){
    int result = _main();
    cout << result;
    return 0;
}

Measured memory_bytes: 8024
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		int enda = 0, startb = 0, startbenda = 0;
		for(int i = 0; i < N; i++) {
			char[] s = sc.next().toCharArray();
			for(int j = 0; j < s.length-1; j++) {
				if(s[j] == 'A' && s[j+1] == 'B')
					ans++;
			}
			if(s[0] == 'B' && s[s.length-1] == 'A')
				startbenda++;
			if(s[0] == 'B')
				startb++;
			if(s[s.length-1] == 'A')
				enda++;			
		}
		ans += Math.min(enda, startb);
		if(enda == startbenda && startb == startbenda && startbenda != 0)
			ans--;
		System.out.println(ans);

	}

}


Measured memory_bytes: 30976
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}
 
int main() {
    ll h;
    cin >> h;
    ll wow = log2(h);
    ll ans = pow(2,wow+1);
    cout << ans-1 << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int main()
{
int a ;
cin >> a ;
if(a%10==7){cout<<"Yes" ;}
else {a=a/10 ;

if(a%10==7){cout << "Yes" ;}
else {a=a/10 ;
if(a%10==7){cout << "Yes" ;}
else cout << "No" ;
}
}

   return 0;
}


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

int main(){
	while(true){
		int h, w;
		cin >> h >> w;
		
		if(h == 0) break;
		
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++) cout << "#";
			cout << "\n";
		}
		cout << "\n";
	}
	cout << flush;
	
	return 0;
}


Measured memory_bytes: 3104
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 2e9;



int main() {
	int n; cin >> n;
	set<int> a;
	rep(i, 0, n) {
		int p; cin >> p;
		a.insert(p);
	}
	if (a.size() % 2) printf("%d", a.size());
	else printf("%d", a.size() - 1);
	return 0;
}

Measured memory_bytes: 4992
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
using namespace std;
int main() {
	string base;
	int n;
	cin >> base;
	cin >> n;
	int cnt = 0;
	for (int i = 0;i < n;++i) {
		string yubi;
		cin >> yubi;
		for (int i = 0;i < 10;++i) {
			if (base[0] == yubi[i]) {
				int now = 0;
				for (int q = i;now < base.size();++q) {
					if (base[now] != yubi[q]) goto fail;
					if (q == 9) q = -1;
					now++;
				}
				cnt++;
				goto nice;
			fail:;
			}

		}
	nice:;
	}
	cout << cnt << endl;

}


Measured memory_bytes: 1204
x,k,d = $stdin.gets.chomp.split(' ').map(&:to_i)

if x < 0
  nums = (-x).divmod(d)
  if nums[0] > k
    puts (x + (k*d)).abs
  else
    poj = -nums[1]
    if (k - nums[0]) % 2 == 0
      puts (poj).abs
    else
      puts (poj+d).abs
    end
  end
else
  nums  = (x).divmod(d)
    if nums[0] > k
    puts (x - (k*d)).abs
  else
    poj = nums[1]
    if (k - nums[0]) % 2 == 0
      puts (poj).abs
    else
      puts (poj-d).abs
    end
    end
end

Measured memory_bytes: 14284
#include<bits/stdc++.h>
#include<iostream>

using namespace std;

#define forn(i,n) for ( int i=0 ; i < n ; i++ )
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define vi vector<int >
#define pii pair<int, int>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SQ(a) (a)*(a)
#define ll long long
#define lli long long int
#define ull unsigned long long
#define endl '\n'
#define Pi(a) printf("%d\n",a);
#define debug2(a,b) printf("%d\t%d\n",a,b);
#define debug1(a) printf("%d\n",a);
#define Si(a) scanf("%d",&a);
#define mod 1000000007
#define w(n) while(n--)


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//code
	int n;
	cin >> n;
	int arr[n];
	forn(i,n) {cin >> arr[i];arr[i]-=i+1;}
	sort(arr,arr+n);
	ll ans=0;
	ll rem=arr[n/2];
	forn(i,n){
		ans+=abs(arr[i]-rem);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
#include<iostream>
#include<bitset>
#include<functional>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<random>
#include<ctime>
#include<complex>
using namespace std;
typedef long long LL;
mt19937 gene(233);
typedef complex<double> Complex;
#define fi first
#define se second
#define ins insert
#define pb push_back
inline char GET_CHAR(){
	const int maxn = 131072;
	static char buf[maxn],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxn,stdin),p1==p2)?EOF:*p1++;
}
inline int getInt() {
	int res(0);
	char c = getchar();
	while(c < '0') c = getchar();
	while(c >= '0') {
		res = res * 10 + (c - '0');
		c = getchar();
	}
	return res;
}

inline int fastpo(int x, int n, int mod) {
	int res(1);
	while(n) {
		if(n & 1) {
			res = res * (LL)x % mod;
		}
		x = x * (LL) x % mod;
		n /= 2;
	}
	return res;
}

inline string itoa(int x, int width = 0) {
  string res;
  if(x == 0) res.push_back('0');
  while(x) {
    res.push_back('0' + x % 10);
    x /= 10;
  }
  while((int)res.size() < width) res.push_back('0');
  reverse(res.begin(), res.end());
  return res;
}

const int N = 131072;
const int LOG = 17;
const int mod = 998244353;
const int inf = 1e9 + 7;
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector<int> e[N];
int vst[N], par[N];
struct M {
	LL a;
	M operator + (const M & b) const {
		M res;
		res.a = a + b.a;
		if(res.a >= mod) res.a -= mod;
		return res;
	}
	M operator - (const M & b) const {
		M res;
		res.a = a - b.a;
		if(res.a < 0) res.a += mod;
		return res;
	}
	M operator * (const M & b) const {
		return M{a * b.a % mod};
	}
};
M s[3][N];
M pw[N];
set<int> st[N];
int main() {
	int n;
	scanf("%d", &n);
	pw[0] = M{1};
	int bs = 1000000000000000000ll % mod;
	for(int i = 1; i <= n; i++) pw[i] = pw[i - 1] * M{bs};
	for(int d = 0; d < 3; d++) {
		int m;
		scanf("%d", &m);
		for(int i = 1; i <= n; i++) e[i].clear();
		for(int i = 1; i <= m; i++) {
			int x, y;
			scanf("%d%d", &x, &y);
			if(y < x) swap(x, y);
//			e[x].push_back(y);
			e[y].push_back(x);
		}
		for(int i = 1; i <= n; i++) {
			st[i].clear();
		}
		for(int i(n); i >= 1; i--) {
			int val = 0;
			while(st[i].count(val)) val++;
			//cout << val << endl;
			s[d][val] = s[d][val] + pw[i];
			for(int y : e[i]) {
				st[y].insert(val);
			}
		}
		for(int i = 0; i < LOG; i++) {
			for(int j = 0; j < N; j++) {
				if((j >> i) & 1) {
					M a = s[d][j], b = s[d][j - (1 << i)];
					s[d][j] = a + b;
					s[d][j - (1 << i)] = b - a;
				}
			}
		}
	}
	for(int i = 0; i < N; i++) {
		s[0][i] = s[1][i] * s[0][i] * s[2][i];
	}
	//cout << s[0][0].a << ' ' << s[0][1].a << endl;
	for(int i = LOG - 1; i >= 0; i--) {
		for(int j = 0; j < N; j++) {
			if((j >> i) & 1) {
				M a = s[0][j], b = s[0][j - (1 << i)];
				s[0][j] = (a - b) * M{(mod + 1) / 2};
				s[0][j - (1 << i)] = (a + b) * M{(mod + 1) / 2};
			}
		}
	}
	cout << s[0][0].a << endl;
}




Measured memory_bytes: 20992
def tenmod(n,c=0):
    if (n+c) % 10 == 0:
        return (n,c)
    return tenmod(n,c+1)

lst = list(map(int,[input() for i in range(5)]))
order_sort = sorted(list(map(tenmod,lst)),key=lambda x: x[1])
print(sum([x+y for x,y in order_sort[:4]])+order_sort[4][0])


Measured memory_bytes: 3060
#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int N, K;
    cin >> N >> K;

    long long int A[N], visited[N]={0}, f[N];

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

    long long int current=0, moves=0;
    f[current]=moves;

    while(visited[current]==0 && K>0)
    {
        //cout << current << endl;
        visited[current]=1;
        current=A[current];
        moves++;
        if(visited[current]==0)
        {
        f[current]=moves;
        }
        K--;
    }
    //cout << "Here" << endl;
    if(moves!=f[current])
    {
    K=K%(moves-f[current]);
    }
    //cout << "EOL: " << K << endl;

    while(K>0)
    {
        current=A[current];
        K--;
    }
    cout << current+1;
}


Measured memory_bytes: 8280
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())
ver = [[] for i in range(N+1)]
for i in range(N-1):
    u,v,w = map(int,readline().split())
    ver[u].append((v,w))
    ver[v].append((u,w))
color = [-1]*(N+1)
color[1] = 0
def dfs(fro,to,d):
    color[to] = d%2
    for v in ver[to]:
        if v[0] == fro:
            continue
        dfs(to,v[0],d+v[1])


for v in ver[1]:
    dfs(1,v[0],v[1])

for i in range(1,N+1):
    print(color[i])


Measured memory_bytes: 86832
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    x, k, d = i_map()

    x = abs(x)

    if x > k * d:
        ans = x - k * d
    else:
        if k % 2 == (x // d) % 2:
            ans = x % d
        else:
            ans = abs(x % d - d)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 95728
<?php
list($H,$W,$N) = explode(" ",trim(fgets(STDIN)));

$ans = array(0,0,0,0,0,0,0,0,0,0);

if($N > 0){
    for($i = 1;$i <= $N;$i++){
        list($a,$b) = explode(" ",trim(fgets(STDIN)));
        for($j = -1;$j <= 1;$j++){
            if($a + $j > 1 && $a + $j < $H){
                for($k = -1;$k <= 1;$k++){
                    if($b + $k > 1 && $b + $k < $W){
                        if(isset($map[$a + $j][$b + $k]) == true){
                            $map[$a + $j][$b + $k] ++;
                        }else{
                            $map[$a + $j][$b + $k] = 1;
                        }
                    }
                }
            }
        }
    }
    
    foreach($map as $val){
        foreach($val as $val2){
            $ans[$val2] ++;
        }
    }

    $num0 = ($H - 2) * ($W - 2) - array_sum($ans);
    echo $num0 . PHP_EOL;
}else{
    echo ($H - 2) * ($W - 2) . PHP_EOL;
}

for($i = 1;$i <= 9;$i++){
    echo $ans[$i] . PHP_EOL;
}
?>

Measured memory_bytes: 219768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt( br.readLine() );
      int num;
      int result = 0;

      for (int i=0; i<n; i++) {
        num = Integer.parseInt(br.readLine());
        if (isPrime(num)) result++;
      }
      System.out.println(result);
    }
  }

  public static boolean isPrime(int num) {
    if( num == 2 ) return true;
    if( (num % 2) == 0 ) return false;

    int k = Double.valueOf( Math.sqrt(num) ).intValue();
    for(int i=3; i <= k; i+=2 ) {
      if ( num % i == 0 ) return false;
    }
    return true;
  }
}


Measured memory_bytes: 29712
#include<bits/stdc++.h>
#define fi        first
#define se        second
#define pb        push_back
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
inline void solve()
{
	string a,b;cin>>a>>b;
	b.erase(--b.end());
	if(a==b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

}
int main()
{
	IOS();
	solve();
	return 0;
}




Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(c-a)<=d){
        cout << "Yes" << endl;
    }else if(abs(b-a)<=d && abs(c-b)<=d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    } 

    return 0;
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    a, b = map(int, input().split())

    if (a + b) % 3 == 0 or a % 3 == 0 or b % 3 == 0:
        print('Possible')
    else:
        print('Impossible')

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;

int main(){
    ll n,k; cin >> n >> k;
    ll a = 1;
    rep(i,n){
        a = min(a*2,a+k);
    }
    cout << a << endl;
}

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

int main() {
	ll n;
	cin >> n;
	vector<ll> a(5);
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}

	ll ans = 0;
	sort(a.begin(), a.end());
	ans += n / a[0];
	if (n%a[0] != 0) {
		ans++;
	}
	ans += 4;

	

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int U=0;
  cin>>N;
  vector<int>V(N);
  vector<int>C(N);
  for(int X=0;X<N;X++){
    cin>>V[X];
  }
  for(int X=0;X<N;X++){
    cin>>C[X];
  }
  for(int X=0;X<N;X++){
    if(V[X]>C[X]){
      U+=V[X]-C[X];
    }
  }
  cout<<U<<endl;
}


Measured memory_bytes: 3600
import math
import fractions

A, B, C, D = map(int, input().split())

def lcm(a, b):
  return (a * b) // fractions.gcd(a, b)

# Cで割り切れる数
divC = B // C - (A-1) // C

# Dで割り切れる数
divD = B // D - (A-1) // D

# CとDの最小公倍数で割り切れる数
lcmCD = lcm(C, D)
divCD = B // lcmCD - (A-1) // lcmCD

# CとDの少なくとも一方で割り切れる数
divCorD = divC + divD - divCD

# AからBまでの数
AB = B - A + 1

print(AB - divCorD)

Measured memory_bytes: 5076
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let k: usize = read();
    let mut ans = 0;
    for a in 1..k+1 {
        for b in 1..k+1 {
            for c in 1..k+1 {
                let x = gcd(a, b);
                let y = gcd(x, c);
                ans += y;
            }
        }
    }
    println!("{}", ans);
}

fn gcd(x: usize, y: usize) -> usize {
    if y == 0 {
        return x;
    }
    return gcd(y, x % y);
}

Measured memory_bytes: 2132
// Date: 2020-03-13

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

LL inv[N], fac[N], dp[N];
pii a[N];

LL C(int x, int y) {
    return fac[x] * inv[x-y] % mod * inv[y] % mod;
}

int main() {
    FIO;
    int n, m, k;
    cin >> n >> m >> k;
    rep(i, 1, k) cin >> a[i].fi >> a[i].se;
    a[++k].fi = n, a[k].se = m;
    sort(a+1, a+1+k);
    inv[0] = fac[0] = 1;
    rep(i, 1, N-1) fac[i] = fac[i-1] * i % mod, inv[i] = qpow(fac[i], mod-2, mod);
    rep(i, 1, k) dp[i] = C(a[i].fi + a[i].se - 2, a[i].fi - 1);
    rep(i, 1, k) rep(j, 1, i-1) if(a[j].fi <= a[i].fi && a[j].se <= a[i].se) {
        int dx = a[i].fi-a[j].fi, dy = a[i].se-a[j].se;
        dp[i] = (dp[i] - dp[j] * C(dx+dy, dx) % mod + mod) % mod;
    }
    cout << dp[k];


    return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
long long int mod = 998244353;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
//↓,→,↑,←
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 

ll i,j,k,ii,jj;
ll n,m,num,sumxor,sum,ans;
ll a,b,c,d,e,f,g,h,w,v;
ll x[800005],y[800005],z[900005];

int main(){	
	cin>>w>>h;
	for(i=0;i<w;i++){
		cin>>a;
		x[i] = 2 * a;
	}
	for(i=0;i<h;i++){
		cin>>a;
		x[i+w] = 2 * a + 1;
	}
	//for(i=0;i<h+w;i++)p(x[i]);
	sort(x,x+h+w);
	a = w + 1;
	b = h + 1;
	for(i=0;i<h+w;i++){
		if(x[i]%2==0){
			ans += b * (x[i]/2);
			a--;
		}else{
			ans += a * (x[i]/2);
			b--;
		}
	}
	p(ans);


	
	return 0;
}

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

int main(){
  int N,K;
  string S;

  cin>>N>>K;
  cin>>S;

  vector<int> a;

  int i,count,now;

  now=1;
  count=0;
  for(i=0;i<N;i++){
    if(S.at(i)==(char)('0'+now))
    count++;
    else{
      a.push_back(count);
      now=1-now;
      count=1;
    }
  }
  if(count!=0)
  a.push_back(count);

  int maxsum=0;
  int left=0;
  int right=left;


  for(left=0;left<a.size();left+=2){
    int sum=0;
    int res=0;

    // cout<<"aaa"<<endl;
    while(res<=2*K-1){
      right+=2;
      res=right-left;
    }
    if(right>=a.size()){
      for(i=left;i<a.size();i++)
      sum+=a.at(i);
      if(maxsum<sum)
      maxsum=sum;
      break;
    }
    for(i=left;i<=right;i++)
    sum+=a.at(i);

    if(maxsum<sum)
    maxsum=sum;

    // cout<<maxsum<<endl;
  }

  cout<<maxsum<<endl;


}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 7;
const int MOD = 1e9 + 7;

ll dp[N][N];
ll fact[N], inv[N];


ll bpow(ll a, ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

int main()
{
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;

	fact[0] = inv[0] = 1;
	for (int i=1; i<N; i++)
		fact[i] = fact[i-1] * i % MOD, inv[i] = bpow(fact[i], MOD - 2);

	for (int i=0; i<N; i++)
		dp[i][0] = 1;
	for (int i=a; i<=b; i++)
		for (int j=1; j<=n; j++)
		{
			dp[i][j] = dp[i-1][j];
			for (int k=c; k<=d && j >= k * i; k++)
				dp[i][j] = (dp[i][j] + dp[i-1][j-k*i] * bpow(inv[i], k) % MOD * inv[k] % MOD) % MOD;
		}
	cout << dp[b][n] * fact[n] % MOD << "\n";

	return 0;
}

Measured memory_bytes: 8192
#include <stdio.h>
    #include <stdlib.h>
        int main()
        {
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        if((abs(c-a))<=d)
        printf("Yes");
        else if((abs(b-a))<=d&&(abs(c-b))<=d)
        printf("Yes");
        else
        printf("No");
return 0;
        }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
 
int N, Q, K;
vector<vector<P>> root(100001);  //pair<辺の距離, 行先の頂点>
vector<ll> dist(100001, 0);

int main(void){
    
    cin >> N;
    for(int i = 0; i < N - 1; ++i){
        int a, b, c; scanf("%d %d %d", &a, &b, &c);
        root[a].push_back(make_pair(c, b)), root[b].push_back(make_pair(c, a));
    }
    
    scanf("%d %d", &Q, &K);
    
    bitset<100001> bit; bit.reset();
    queue<P> que;
    que.push(make_pair(0, K));
    while(!que.empty()){
        P q = que.front(); que.pop();
        ll cost = q.first; int corrent = q.second;
        dist[corrent] = cost;
        bit[corrent] = true;
        for(auto p : root[corrent]) if(!bit[p.second]) que.push(make_pair(cost + p.first, p.second));
    }
    
    for(int i = 0; i < Q; ++i){
        ll x, y; cin >> x >> y;
        cout << dist[x] + dist[y] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 10736
m, d = [int(el) for el in input().split(' ')]

total = 0
for i in range(1,m+1):
    for j in range(10,d+1):
        tmp = list(str(j))
        d1 = int(tmp[0])
        d2 = int(tmp[1])
        if d1 >= 2 and d2 >= 2 and i == d1 * d2:
            total += 1
print(total)


Measured memory_bytes: 3060
require 'matrix'

h, w = gets.split.map(&:to_i)
rows = Array.new(h, w){gets.chomp.chars}
a = Matrix.rows(rows.shift(h))
b1 = Matrix[['#', '#'], ['#', '#']]
b2 = Matrix[['.', '#'], ['#', '#']]
b3 = Matrix[['#', '#'], ['#', '.']]
(h - 1).times do |i|
  (w - 1).times do |j|
    if a.minor(i, 2, j, 2) == b1 || a.minor(i, 2, j, 2) == b2 || a.minor(i, 2, j, 2) == b3
      puts 'Impossible'
      exit
    end
  end
end
puts 'Possible'

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

int main() {
int x,n;
cin>>x>>n;
set<int> s;
for(int i=0;i<n;i++)
{  int a;
   cin>>a;
   s.insert(a);}
   int i=x,j=x;
   int ans=0;
   if(s.find(x)==s.end())
   {
   	cout<<x<<endl;
   	return 0;
   }
   while(1)
   {
   	i--;
   	if(s.find(i)==s.end())
   	{
   		cout<<i<<endl;
   		return 0;
   	}
   	j++;
   	if(s.find(j)==s.end())
   	{
   		cout<<j<<endl;
   		return 0;
   	}
   }
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;

int main() {
	long N,M;
	cin >>N>>M;
	long output = 0;
	if(N*2 >= M)
		output = (M-M%2)/2;
	else{
		output = N;
		output+= ((M-2*N)-(M-2*N)%4)/4;
	}
	
	cout<<output;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n, ans;
int a[114514], b[114514];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i] >> b[i];
	for (int i = n - 1; i >= 0; i--) {
		a[i] += ans;
		if (!a[i])continue;
		int memo = ((a[i] - 1) / b[i] + 1) * b[i] - a[i];
		ans += memo;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**6)
n = int(input())
p = list(map(int, input().split()))
c = [[] for _ in range(n)]
is_leaf = [True for _ in range(n)]
for i in range(n):
	p[i] -= 1
	c[p[i]].append(i)
	is_leaf[p[i]] = False

if sum(is_leaf) == 0:
	if n%2 == 0:
		print("POSSIBLE")
	else:
		print("IMPOSSIBLE")
	sys.exit()

for i in range(n):
	if is_leaf[i]:
		cur = i
		break

visited_set = {cur}
visited_list = [cur]
while p[cur] not in visited_set:
	visited_list.append(p[cur])
	visited_set.add(p[cur])
	cur = p[cur]

root = p[cur]

grundy = [-1 for _ in range(n)]
g_set = [set() for _ in range(n)]

def dfs(x):
	res = 0
	for v in c[x]:
		dfs(v)
		g_set[x].add(grundy[v])
	while res in g_set[x]:
		res += 1
	grundy[x] = res
	return res

loop = [False for _ in range(n)]
loop[root] = True
ind = len(visited_list)-1
while visited_list[ind] != root:
	loop[visited_list[ind]] = True
	ind -= 1
#print(loop)

for i in range(n):
	if loop[i]:
		for x in c[i]:
			if not loop[x]:
				dfs(x)
				g_set[i].add(grundy[x])

cand = []
num = 0
while num in g_set[root]:
	num += 1
cand.append(num)
num += 1
while num in g_set[root]:
	num += 1
cand.append(num)

for x in cand:
	cur = root
	grundy[root] = x
	while True:
		num = 0
		while num in g_set[p[cur]] or num == grundy[cur]:
			num += 1
		grundy[p[cur]] = num
		if p[cur] == root:
			break
		cur = p[cur]
	if grundy[root] == x:
		#print(grundy)
		print("POSSIBLE")
		sys.exit()

print("IMPOSSIBLE")

Measured memory_bytes: 94188
import collections
def inpl(): return [int(i) for i in input().split()]

H, W = inpl()
a = collections.Counter(''.join([input() for _ in range(H)]))
nd2, nd4 = 0, 0 
for i in a.values():
    if i%2:
        nd2 += 1
        i -= 1
    if i%4:
        nd4 += 1
ans = 'No'
if H%2 and W%2:
    if nd2 == 1 and (H+W-2)//2 >= nd4:
        ans = 'Yes'
elif H%2:
    if not nd2 and W//2 >= nd4:
        ans = 'Yes'
elif W%2:
    if not nd2 and H//2 >= nd4:
        ans = 'Yes'
else:
    if not nd2 and not nd4:
        ans = 'Yes'
print(ans)

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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  vector<int> ans(s.size(),1);
  for (int i=0; i<n-1; i++) {
    if (s[i]=='R'&&s[i+1]=='L') {
      int j=1;
      while (i-j>=0&&s[i-j]=='R') {
	if (j%2) ans[i+1]++;
	else ans[i]++;
	ans[i-j]=0;
	j++;
      }
      j=1;
      while (i+j+1<n&&s[i+j+1]=='L') {
	if (j%2) ans[i]++;
	else ans[i+1]++;
	ans[i+j+1]=0;
	j++;
      }
    }
  }
  rep(i,s.size()) {
    cout<<ans[i]<<' ';
  }
  cout<<endl;
  return 0;
}



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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string a,b; cin >> a >> b;
    string s = "EQUAL";
    if(a.size() == b.size()){
        if(a>b) s = "GREATER";
        else if(a<b)s = "LESS";
    }
    else if(a.size() > b.size())s = "GREATER";
    else s = "LESS";
    cout << s << endl;
}


Measured memory_bytes: 256
N = int(input())


def to753(q):
    q, r = divmod(q, 4)
    r = 0 if r == 0 else 2 * r + 1  # 1->3, 2->5, 3->7
    if q == 0:
        return str(r)
    else:
        return to753(q) + str(r)


ans = 0
for qt in range(1, 4 ** 9):
    s = to753(qt)
    # print(qt, list(s))
    if '0' in s: continue
    if int(s) > N: break
    if all(c in s for c in '753'): ans += 1
print(ans)


Measured memory_bytes: 3188
from collections import Counter
H,W=list(map(int, input().split()))
C=[list(map(int, input().split())) for _ in range(10)]
A=Counter()
for _ in range(H):
    A+=Counter(list(map(int, input().split())))
del A[-1]
# print(A)
# Warshall–Floydを使います

for i in range(10):
    via=C[i]
    for j in range(10):
        c=C[j]
        for k in range(10):
            c[k]=min(c[i]+via[k], c[k])
# print(C)

ans=0
for i in A:
    ans+=C[i][1]*A[i]
print(ans)

Measured memory_bytes: 74304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  ll n; cin >> n;
  map<string, ll> mp;
  for (int i=0; i<n; i++){
    string s; cin>>s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;

  return 0;
}


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

int main(){
    ll n;
    cin >> n;
    ll ans=0;
    rep(i,n+1){
        if(i==0){
            continue;
        }
        else{
            ans+=(n-1)/i;
        }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
typedef long long ll;
#define pb push_back
const ll INF=1e18;
const int inf=0x3f3f3f3f;
const int M=2e6+6;
void py(){
    cout<<"Yes"<<'\n';
}
void pn(){
    cout<<"No"<<'\n';
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int flag=0;
    while(n){
        if(n%10==7)
            flag=1;
        n/=10;
    }
    if(flag)
        py();
    else
        pn();
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int D;
  cin >> D;
  int c[26];
  int las[26];
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
    las[i] = 0;
  }
  int s[D][26];
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  
  for (int i = 1; i <= D; i++) {
    int score[26];
    for (int j = 0; j < 26; j++) {
      score[j] = 0;
      score[j] += s[i-1][j];
      for (int k = 0; k < 26; k++) {
        if (j != k) {
          score[j] -= c[k] * (i - las[k]);
        }
      }
    }
    int choose = -1;
    int max_score = -99999999;
    int max_score_2 = -99999999;
    for (int j = 0; j < 26; j++) {
      if (score[j] > max_score) {
        choose = j;
        max_score = score[j];
        int sum = 0;
        for (int k = i; k <= D; k++) {
          sum += s[k-1][j];
        }
        max_score_2 = sum;
      } else if (score[j] == max_score) {
        int sum = 0;
        for (int k = i; k <= D; k++) {
          sum += s[k-1][j];
        }
        if (sum > max_score_2) {
          choose = j;
          max_score_2 = sum;
        }
      }
    }
    las[choose] = i;
    cout << choose + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3648
unittest
{
	assert( [ "10" ].parse.expand.solve == "Yes" );
	assert( [ "50" ].parse.expand.solve == "No" );
	assert( [ "81" ].parse.expand.solve == "Yes" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	foreach( a; 1 .. 10 )
	{
		foreach( b; 1 .. 10 )
		{
			if( a * b == n ) return "Yes";
		}
	}
	return "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int X;
    cin>>X;
    for(int i=0;i<X+1;i++){
        int rest =X-i*100;
        if(0 <= rest && rest <= 5*i ){
            cout<<1<<endl;
            return 0;
        }
        if(rest<0)break;
    }
    cout<<0<<endl;
    return 0;
    }


Measured memory_bytes: 256
N = int(input())
flag = -1
t,x,y=0,0,0

for i in range(N):
    t2,x2,y2 = map(int,input().split())
    if abs(x+y-x2-y2) > t2-t:
        break
    elif abs(x+y-x2-y2) == t2-t:
        t,x,y=t2,x2,y2
    elif abs(x+y-x2-y2) < t2-t:
        if abs(x+y-x2-y2)%2 != (t2-t)%2:
            break
        else:
            t,x,y=t2,x2,y2
    if i+1 == N:
        flag = 1
        break
            
if flag == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 46568
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void solve()
{
	ll n,k;
	cin>>n>>k;
	if(k==n)
	cout<<0;
	else if(k>n)
	cout<<min(n,(k-n));
	else
	{	
		ll ans=n-(n/k)*k;
		ll res=abs(n-(n/k +1 )*k);
		cout<<min(ans,res);
	}
	
}
int main()
{
//	int t;cin>>t;
//	while(t--)
	solve();
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
even=0
odd=0
for i in A:
    if i%2==0:
        even+=1
    else:
        odd+=1

if odd%2 == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 62448
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;
int main(){
    int M1,D1,M2,D2;
    cin >> M1 >> D1 >> M2 >> D2;
    if(M1!=M2) cout << 1 << endl;
    else cout << 0 << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

//adds b into a
void binaryAdd(int a[], int b[], int length) {
    int c = 0;
    int sum[length];
    for(int i = 0; i < length ; i++){
        sum[i] = ((a[i] ^ b[i]) ^ c); // c is carry
        c = ((a[i] & b[i]) | (a[i] & c)) | (b[i] & c);
    }
    for(int i = 0; i < length; i++) {
        a[i] = sum[i];
    }

}

//returns true if all the elements in the int array are 1
bool arrayIs1s(int arr[], int length) {
    for(int i =0; i < length; i++) {
        if(arr[i] != 1)
            return false;
    }
    return true;
}

int main() {
    long long input;
    cin >> input;
    string inputStr = to_string(input);
    int lengthCount = inputStr.length();
    if(lengthCount <= 1) { //special case
        cout << input;
        return 0;
    }
    int current[lengthCount-1] = {0};
    int binaryOne[lengthCount-1] = {0};
    binaryOne[0] = 1;
    long long sum = input;
    reverse(inputStr.begin(), inputStr.end()); //starting for LSB to MSB
    //main loop
    do {
        binaryAdd(current, binaryOne, lengthCount-1);
        long long currNum = (inputStr[0] - '0'), times = 10;
        for(int i = 0; i < lengthCount-1; i++) {
            if(current[i] == 1) {   //1 means a plus between input [i] and [i+1]
                sum += currNum;
                currNum = (inputStr[i+1] - '0');
                times = 10;
            } else if(current[i] == 0) { //0 means no plus, keep adding the number
                currNum += (inputStr[i+1] - '0') * times;
                times *= 10;
            }
        }
        //one more time for the MSB
        sum += currNum;
    } while(arrayIs1s(current, lengthCount-1) == false);
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    string S;
    cin >> S;
    if(S == "ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;
    return 0;
}

Measured memory_bytes: 3636
N = int(input())

# 1食 800 円で、15食食べる毎にその場で200 円値引き。
# 合計 N 食
# 今までに払った金額を x 円、レストランからもらった金額を y 円として、
# x−y を求めなさい。
x = 800 * N
y = N // 15 * 200

print(x - y)

Measured memory_bytes: 8768
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // int n;
    // cin >> n;
    multiset<int> s;
    int q, a, b, c;
    cin >> q;
    rep(i, q) {
        cin >> a >> b;
        if(a == 0) {
            s.insert(b);
            cout << s.size() << "\n";
        } else if(a == 1) {
            cout << s.count(b) << "\n";
        } else if(a == 2) {
            s.erase(b);
        } else {
            cin >> c;
            auto p1 = s.equal_range(b);
            auto p2 = s.equal_range(c);

            while(p1.first != p2.second) {
                cout << *p1.first++ << "\n";
            }
        }
    }
}



Measured memory_bytes: 12412
import java.io.*;
import java.util.*;

/**
 * Created by fcdkbear on 15.10.16.
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        new Task().solve(in, out);
        out.close();
    }


    static class Task {

        public void solve(InputReader in, PrintWriter out) {

            int k = in.nextInt();
            int t = in.nextInt();
            int[] a = new int[t];
            for (int i = 0; i < t; ++i) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a);
            int maxNumber = a[t - 1];
            int other = k - maxNumber;
            int res = Math.max(0, maxNumber - 1 - other);
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }

}


Measured memory_bytes: 8532
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main()
{

  int x, n;
  cin >> x >> n;

  vector<int> a;
  a.resize(n);

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

  sort(a.begin(), a.end());

  auto it = find(a.begin(), a.end(), x);
  if (it == a.end())
  {
    cout << x << endl;
    return 0;
  }

  int idx = distance(a.begin(), it);

  int i = 1;
  while (1)
  {
    // 隣を探す
    int mi = min(n - 1, idx + i);
    int ma = max(0, idx - i);
    int r = a[mi] - a[idx];
    int l = a[idx] - a[ma];

    if (l == i && r == i)
    {
      i++;
      continue;
    }

    bool lflg = false;
    if (i != l && i != r)
    {
      lflg = true;
    }
    if (i != l)
    {
      lflg = true;
    }

    if (lflg)
    {
      cout << a[idx] - i << endl;
    }
    else
    {
      cout << a[idx] + i << endl;
    }
    break;
  }

  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
	cin >> s;
	int z = s.size();
	for (int i = 1; i < s.size(); i++) {
		if (s[i] != s[i - 1]) {
			z = min(z, max(i, (int)s.size() - i));
		}
	}
	printf("%d\n", z);
	return 0;
}

Measured memory_bytes: 512