akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#define min(x,y) (x)<(y)?(x):(y)
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
typedef struct{
    int group;
    int spare;
}Data;
int h,w,s,all,t[32][32];
int rec[32][32][32][32];
Data dp[32][32][32][32];
Data max(Data x,Data y){
    if(x.group<y.group) return y;
    else if(x.group==y.group){
        if(x.spare<y.spare) return y;
        else return x;
    }
    else return x;
}
void mkRec(){
    memset(rec,0,sizeof(rec));
    rep(i,h){
        rep(j,w){
            rec[i][j][i][j]=t[i][j];
            for(int y=i-1;y>=0;y--)
                rec[y][j][i][j]=rec[y+1][j][i][j]+t[y][j];
            for(int y=i;y>=0;y--){
                int sum=0;
                for(int x=j;x>=0;x--){
                    sum+=rec[y][x][i][x];
                    rec[y][x][i][j]=sum;
                }
            }
        }
    }
}
Data dfs(int lx,int ly,int hx,int hy){
    if(dp[ly][lx][hy][hx].group!=0) return dp[ly][lx][hy][hx];
    Data res={1,s-(all-rec[ly][lx][hy][hx])};
    for(int i=ly;i<hy;i++){
        if(all-rec[ly][lx][i][hx]>s ||
           all-rec[i+1][lx][hy][hx]>s) continue;
        Data a=dfs(lx,ly,hx,i);
        Data b=dfs(lx,i+1,hx,hy);
        Data cal={a.group+b.group,min(a.spare,b.spare)};
        res=max(res,cal);
    }
    for(int j=lx;j<hx;j++){
        if(all-rec[ly][lx][hy][j]>s ||
           all-rec[ly][j+1][hy][hx]>s) continue;
        Data a=dfs(lx,ly,j,hy);
        Data b=dfs(j+1,ly,hx,hy);
        Data cal={a.group+b.group,min(a.spare,b.spare)};
        res=max(res,cal);
    }
    return dp[ly][lx][hy][hx]=res;
}
int main(){
    while(1){
        scanf("%d%d%d",&h,&w,&s);
        all=0;
        if(h+w+s==0) break;
        rep(i,h){
            rep(j,w){
                scanf("%d",&t[i][j]);
                all+=t[i][j];
            }
        }
        mkRec();
        memset(dp,0,sizeof(dp));
        Data d=dfs(0,0,w-1,h-1);
        printf("%d %d\n",d.group,d.spare);
    }
}



Measured memory_bytes: 14012
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

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

int main() {
    ll n; cin >> n;
    if(n == 0){ co(0); return 0;}
    string ans = {};
    ll p = n, q;
    while(1){
        q = p%2; // あまり
        if(q < 0) q += 2;
        ans.push_back((char)'0'+q);
        p = (p - q)/(-2);
        if(p == 1){
            ans.push_back((char)'1');
            break;
        }
    }
    reverse(ALL(ans));
    co(ans);

    return 0;
}


Measured memory_bytes: 256
n=int(input())
#a,b=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

def chk(A):
    if all([ai%2==0 for ai in A]):
        return True
    else:
        return False
count=0
while chk(al):
    count+=1
    for i in range(n):
        al[i]=al[i]//2
print(count)

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n,k,s;
    cin >> n >> k >> s;
    REP(i,k){
        cout << s;
        if(i!=n-1)cout << " ";
    }
    REP(i,n-k){
        if(s!=INF)cout << INF;
        else cout << 1;
        if(i!=(n-k-1))cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<map>
#define int long long
//const int mx = 1e5+5;
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n,m;
	cin>>n>>m;
	int p,q;
	cin>>p>>q;
	int mi = min(p,q);
	int mx = max(p,q);
	for(int i=1;i<m;i++)
	{
		int p,q;
		cin>>p>>q;
		int mi1 = min(p,q);
		int mx1 = max(p,q);
		mi = max(mi,mi1);
		mx = min(mx,mx1);
	}
	int p1 = mx- mi;
	if(p1 >= 0)
	{
		cout<<p1+1<<endl;
	}
	else
	{
		cout<<"0"<<endl;
	}
}

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

#define debug(x) cout<<#x<<"="<<x<<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int) (x).size())
#define pii pair<int,int>
#define PQ priority_queue
#define sqr(x) (x)*(x)
#define ll long long
#define pb push_back
#define mp make_pair
#define re return

const int INF=0x7fffffff;

string s,t,p;

bool check(){
	for (int i=0;i<p.size();i++){
		if (p[i]!='?' && t[i]!=p[i]){
			return false;
		}
	}
	return true;
}

int main(){
	cin>>s>>t;
	for (int i=s.size()-t.size();i>=0;i--){
		p=s.substr(i,t.size());
		if (check()){
			for (int j=0;j<s.size();j++){
				if (j==i){
					cout<<t;
					j+=t.size()-1;
				}else{
					if (s[j]=='?') cout<<"a"; else cout<<s[j];
				}
			}
			return 0;
		}
	}
	cout<<"UNRESTORABLE";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
const int Maxn = 1e5 + 5;
typedef int arr[Maxn];
//ll Add(ll x, ll y) { return (x += y) >= Mod ? x - Mod : (x < 0 ? x + Mod : x); }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
struct str
{
	int cnt, *addr;
	bool operator<(str A) const { return cnt < A.cnt; }
} d[Maxn];
int Disc(int t)
{
	rg int tmp = 0;
	std::sort(d + 1, d + t + 1);
	for (int i = 1; i <= t; i++)
	{
		if (i == 1 || d[i].cnt != d[i - 1].cnt)
			d[++tmp] = d[i];
		*d[i].addr = tmp;
	}
	return tmp;
}
int a, b;
int main()
{
	cin >> a >> b;
	cout << 6 - a - b << '\n';
	return 0;
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
  int a[3];
  rep(i, 3) cin >> a[i];
  int mi=100, ma=0;
  rep(i,3){
    mi = min(mi, a[i]);
    ma = max(ma, a[i]);
  }
  cout << ma-mi<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(reverse = True, key = lambda x:x[0]+x[1])
ans = 0
for i in range(n):
    ans += (1-i%2)*ab[i][0] - (i%2)*ab[i][1]
print(ans)

Measured memory_bytes: 32224
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;

using namespace std;

int main() 
{
    string a, b;
    cin >> a >> b;

    if(a==b) {
        cout << "=" << endl;
    } else if(a < b) {
        cout << "<" << endl;
    } else {
        cout << ">" << endl;
    }
    return 0;
}
    



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

using s64 = long long;

const int MaxN = 50;
const int L = 50;

int n;
int a[MaxN + 1], b[MaxN + 1];

bool chosen[L + 1];

inline bool validate(int k) {
  chosen[k] = false;

  s64 reach[L + 1];
  for (int i = 0; i <= L; ++i) {
    reach[i] = 1ll << i;
    for (int j = 1; j <= i; ++j) {
      if (chosen[j]) {
        reach[i] |= reach[i % j];
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    if (~reach[a[i]] >> b[i] & 1) {
      return false;
    }
  }
  return true;
}

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

  fill(chosen, chosen + L + 1, true);
  s64 answer = 0;
  for (int i = L; i >= 0; --i) {
    if (!validate(i)) {
      chosen[i] = true;
      answer |= 1ll << i;
    }
  }

  if (answer == (1ll << L + 1) - 1) {
    answer = -1;
  }
  cout << answer << endl;

  return 0;
}

Measured memory_bytes: 256
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define F first
#define S second
#define sz(x) (int)x.size() - 1
#define rep(i,a,n) for (int i = a; i <= n; ++i)
#define fo(i, n)   for (int i = 1; i <= n; ++i)
#define all(v)  v.begin(), v.end()
#define pb push_back
#define P pair < int, int >
#define E cout << '\n'

const int mod = 1e9 + 7;
const int N = 3e5 + 5;

int a[N];

inline void solve() {
	string s;int n;cin >> n;
	cin >> s;int c(0), r(0);
	for(auto i : s)
		if(i == 'R')
			++r;
		else
			++c;
	cout << ((r > c) ? "Yes\n" : "No");
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t; while(t--)
                solve();
    return 0;
}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[][] c = new String[3][3];
    String[] str = new String[10];
    for(int i=0; i<3; i++) {
      str = in.readLine().split("");
      for(int j=0; j<3; j++) {
        c[i][j] = str[j];
      }
    }
    System.out.println(c[0][0] + "" + c[1][1] + "" + c[2][2]);
  }
}

Measured memory_bytes: 37328
def f():
    n,k=map(int,input().split())
    s=input()

    ans=0
    pre="1"
    right,SUM=0,0
    for left in range(n):
        while right<n and SUM+int(pre=="1" and s[right]=="0")<=k:
            SUM+=int(pre=="1" and s[right]=="0")
            pre=s[right]
            right+=1

        while right<n and s[right]=="1":
            right+=1
        if ans<max(ans,right-left):
            ans=right-left

        if right==left:right+=1;pre="1"
        elif left<n-1:SUM-=int(s[left]=="0"and s[left+1]=="1")
    print(ans)
if __name__ == "__main__":
    f()

Measured memory_bytes: 9264
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc126/tasks/abc126_a

n, k = [int(x) for x in input().split()]
s = input()
for i, l in enumerate(s):
    if i == k - 1:
        print(l.lower(), end='')
    else:
        print(l, end='')
print('')


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <map>
#include <cmath>
using namespace std;

int main(void) {

    string S;

    cin >> S;

    map<int, int> mp;

    int count = 0;
    int res = 0;
    int Ti[S.length()];
    int pow_10 = 1;
    for(int i = S.length() - 1; i >= 0; i--) {
        string str = S.substr(i, 1);
        int num = atoi(str.c_str());

        res = ((num % 2019) * pow_10 + res) % 2019;

        if (mp.find(res) != mp.end()) { mp[res] += 1; }
        else { mp[res] = 1; }

        pow_10 = (pow_10 * 10) % 2019;

        //cout << num << " " << res << " " << pow_10 << endl;
    }

    for (auto const& [ key, value ] : mp) {
        if (key == 0) count += value;
        int counter = value * (value - 1) / 2;
        //if (counter >= 1) cout << key << " " << value << endl;
        count += counter;
    }

    cout << count;

    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------
int n, m;
int a[301][301];

int solve(set<int> use, int best) {
    if (use.size() == 0) return best;
    int cnt[m] = {};

    rep(i, n) {
        rep(j, m) if (use.count(a[i][j])) {
            cnt[a[i][j]]++;
            break;
        }
    }

    int Max = -1, Max_num;

    rep(i, m) if (Max < cnt[i]) {
        Max = cnt[i];
        Max_num = i;
    }
    use.erase(Max_num);
    best = min({best, Max, solve(use, Max)});
    return best;
}

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

    rep(i, n) rep(j, m) {
        cin >> a[i][j];
        a[i][j]--;
    }
    set<int> st;
    rep(i, m) st.insert(i);
    cout << solve(st, INF) << endl;
    return 0;
}



Measured memory_bytes: 3072
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int N = int.Parse(s[0]);
        int T = int.Parse(s[1]);
        int min = int.MaxValue;
        for(int i = 0; i < N; i++)
        {
            s = Console.ReadLine().Split(' ');
            int c = int.Parse(s[0]);
            int t = int.Parse(s[1]);
            if(t <= T && c < min)
            {
                min = c;
            }
        }
        Console.WriteLine((min == int.MaxValue ? "TLE" : min.ToString()));
    }
}


Measured memory_bytes: 13140
#include<cctype>
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    char n;
    
    while(1){
        scanf("%c",&n);
        
        if(n == '\n') break;   //改行のときおわり
        
        if(isalpha(n)){    //入力されたものがアルファベットのとき
            
            if(islower(n)) printf("%c",toupper(n));
            else if(isupper(n)) printf("%c",tolower(n));
            
        }else{
            printf("%c",n);
        }
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 3132
#include <cstdio>
#include <algorithm>
using namespace std;
int vis[110];
int main(){
	int x,n,i,a,l,r;
	scanf("%d%d",&x,&n);
	if(n==0){printf("%d\n",x);return 0;}
	for(i=1;i<=n;i++)scanf("%d",&a),vis[a]=1;
	if(!vis[x]){printf("%d\n",x);return 0;}
	l=r=x;
	while(1){
		l--,r++;
		if(!vis[l]){printf("%d\n",l);break;}
		if(!vis[r]){printf("%d\n",r);break;}
	}
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
int v[maxn], n, m, q;
int a[maxn], b[maxn], c[maxn], d[maxn], res;
void dfs(int now, int lst = 1) {
	if (now == n+1) {
		int val = 0;
		for (int i = 0;i < q;++i) 
			if (v[ b[i] ] - v[ a[i] ] == c[i]) val += d[i];
		res = max(res, val);
	}
	else {
		for (int i = lst;i <= m;++i) {
			v[now] = i;
			dfs(now+1, i);
		}
	}
}

signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m >> q;
	for (int i = 0;i < q;++i)
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	dfs(1);
	cout << res << '\n';
}



Measured memory_bytes: 3672
#include <iostream>
#include <vector>

using namespace std;

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

  vector<int> v(n, 0);
  vector<int> c(n, 0);

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

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

  int sum = 0;
  for (int i = 0; i < n; i++) {
    int diff = v[i] - c[i];
    if (diff > 0) {
      sum += diff;
    }
  }

  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  //input
  string str; cin >> str;
  int size;
  size = str.size();
  
  //compute
  vector<int> check(size);

  for(int i = 0; i < size; i++)  check[i] = 0;

for(int i = 0; i < size / 2 - 1; i++) {
  for(int j = 0; j < (size - 2 * i)/2 - 1; j++) {
      if(str.at(j) != str.at((size - 2 * i)/2 + j)){
          check[i] = -1;
          break;
      }
  }
}

  //output
  for(int i = 1; i < size/2; i++) {
      if(check[i] == 0){
          cout << size - 2 * i  << endl;
          return 0;
      }
  }

}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n, 0);
    rep(i, n)
    {
        int t;
        cin >> t;
        a[t - 1]++;
    }

    sort(all(a));
    reverse(all(a));

    int res = 0;
    rep(i, k)
    {
        res += a[i];
    }
    cout << n - res << endl;
    return (0);
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int circle,house;
  int king,i,j;
  cin >> circle >> house;
  int dis[house];
  for(i=0;i<house;i++){
    cin >> dis[i];
  }
  int a[house];
  king = circle - dis[house-1] + dis[0];
  for(j=0;j<house-1;j++){
    a[j] = dis[j+1] - dis[j];
    king = max(a[j],king);
  }
  cout << circle - king <<endl;
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

int main() {

	long long N;
	cin >> N;

	vector<long long> L(N, 0);
	for (long long i = 0; i < N; i++) {
		cin >> L[i];
	}

	long long ans = 0;

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

	if (N < 3) {
		ans = 0;
	}
	else {
		for (long long i = 0; i < N - 2; i++) {
			for (long long j = i + 1; j < N - 1; j++) {
				for (long long k = j + 1; k < N; k++) {
					if (L[i] != L[j] && L[j] != L[k] && L[i] != L[k]) {
						if (L[k] < L[i] + L[j]) {
							ans += 1;
						}
					}
				}
			}
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();

        if (x == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }

        sc.close();
    }

}

Measured memory_bytes: 35824
def main():
 num = list(map(int,input().split()))
 bad = list(map(str,input().split()))

 while True :
  flg=0
  
  for i in range(0,len(str(num[0]))):
   stnum=str(num[0])
   if stnum[i] in bad:
    flg=1
    break
   
  if flg==1:
   num[0]+=1
   continue
  else:
   break
  
 print(num[0])

main()

Measured memory_bytes: 2940
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
V e,s;
int N,M;
V mul(const V &a, const V &b){
	V c(N*N);
	int i=0,j;
	for(;i<N;i++)for(j=0;j<N;j++)c[i*N+j]=(a[slice(i*N,N,1)]*b[slice(j,N,N)]).sum()%M;
	return c;
}
V exp(const V &a, const int n){
	//if(!n)return e;
	if(n==1)return a;
	if(n%2==1)return mul(exp(a,n-1),a);
	V b=exp(a,n/2);
	return mul(b,b);
}

main(){
	int i,a,b,c,t;
	for(;scanf("%d%d%d%d%d%d",&N,&M,&a,&b,&c,&t),N;){
		s.resize(N);
		e.resize(1);
		e.resize(N*N);
		V x(N*N);
		for(i=0;i<N;i++){
			scanf("%d",&s[i]);
			e[i*N+i]=1;
			if(i>0)x[i*N+i-1]=a;
			x[i*N+i]=b;
			if(i<N-1)x[i*N+i+1]=c;
		}
		const V r=t?exp(x,t):e;
		for(i=0;i<N;i++){
			printf(i<N-1?"%d ":"%d\n",(r[slice(i*N,N,1)]*s).sum()%M);
		}
	}
}

Measured memory_bytes: 1092
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
sentinel = pow(10,9) + 1
def merge(target_list, left_index, mid_index,right_index):
    
    l = target_list[left_index:mid_index] + [sentinel]
    r = target_list[mid_index:right_index] + [sentinel]
    l_target = 0
    r_target = 0
    count = 0
    #print(left_index, right_index, mid_index, l,r)
    for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1

    return count
    #print(target_list)
            
def merge_sort(target_list, left_index, right_index):
    count = 0
    if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        count += merge_sort(target_list, left_index, mid_index)
        count += merge_sort(target_list, mid_index, right_index)
        count += merge(target_list, left_index, mid_index,right_index)
        
    return count
if __name__ == "__main__":
    l = input()
    target_list = [int(a) for a in input().split()]
    count = merge_sort(target_list, 0, len(target_list))
    print(" ".join([str(n) for n in target_list]))
    print(count)

Measured memory_bytes: 69012
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k,s;
    int x,y,z;
    int cnt = 0;
    cin>>k>>s;
    for(int x=0;x<=k;x++){
        for(int y=0;y<=k;y++){
            z = s-x-y;
            cnt += 0<=z && z<=k;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan=new Scanner(System.in);
    		
    		int x=Integer.parseInt(scan.next());
    		int a=Integer.parseInt(scan.next());
    		int b=Integer.parseInt(scan.next());
    		
    		System.out.print(Math.abs(x-a)<Math.abs(x-b)?"A":"B");

    		
    	
  
    				
 
     
    }
    }

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

template<class T>
struct SegmentTree {
	using F = function<T(T, T)>;
	const T init;
	const F f;
	int sz;
	vector<T> seg;
	SegmentTree(int n, const T init, const F f) :
		init(init),
		f(f)
		{
			sz = 1;
			while(sz < n) sz <<= 1;
			seg.resize(sz << 1, init);
		}
	void update(int id) {
		while(id >>= 1) {
			seg[id] = f(seg[2 * id], seg[2 * id + 1]);
		}
	}
	void replace(int id, T x){
		id += sz;
		seg[id] = x;
		update(id);
	}
	// [l,r)
	T get(int l, int r){
		T L = init, R = init;
		for(l += sz, r += sz; l < r; l >>= 1, r>>= 1) {
			if(l & 1) L = f(L, seg[l++]);
			if(r & 1) R = f(seg[--r], R);
		}
		return f(L, R);
	}
	void debug(){
		int i = 1;
		for(int r = 2; r <= 2 * sz; r <<= 1) {
			while(i < r) {
				cout << seg[i++] << " ";
			}
			cout << "\n";
		}
	}
};

int main() {
	int n, m; cin >> n >> m;
	pair<int, pair<int, int>> p[n];
	for(int i = 0; i < n; ++i) {
		int l, r; cin >> l >> r;
		p[i] = {r - l + 1, {l, r}};
	}
	sort(p, p + n);
	SegmentTree<int> seg(m + 2, 0, [](int lhs, int rhs){return lhs + rhs;});
	int now = 0;
	for(int d = 1; d <= m; ++d) {
		while(now < n) {
			if(d < p[now].first) break;
			int l, r; tie(l, r) = p[now].second;
			seg.replace(l, seg.get(l, l + 1) + 1);
			seg.replace(r + 1, seg.get(r + 1, r + 2) - 1);
			++now;
		}
		int ans = n - now;
		for(int dd = d; dd <= m; dd += d) {
			ans += seg.get(0, dd + 1);
		}
		cout << ans << '\n';
	}
	return 0;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

using Graph = vector<vector<int>>;

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

    Graph g(n);
    for (size_t i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--; // 0-indexed
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> tsukushi(n, -1);
    queue<int> que;

    que.push(0);

    while (!que.empty())
    {
        int v = que.front();
        que.pop();

        for (auto &&nv : g[v])
        {
            if (tsukushi[nv] != -1)
                continue;
            tsukushi[nv] = v;
            que.push(nv);
        }
    }

    bool isok = true;
    for (size_t i = 1; i < n; i++)
    {
        isok &= tsukushi[i] >= 0;
    }
    if (isok)
    {
        cout << "Yes" << endl;
        for (size_t i = 1; i < n; i++)
            cout << tsukushi[i] + 1 << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 10120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n, point, q, mini = 10000000000, i;
    scanf("%lld %lld %lld", &n, &point, &q);
    long long int a[q], fr[100002] = {0};
    for (i=0; i<q; i++) {
        scanf("%lld", &a[i]);
        long long int j = a[i];
        fr[j]++;
    }
//    for (i=0; i<n; i++) {
//        printf("%I64d\t", fr[i]);
//    }
//    printf("\n");
    long long int player[n+1] = {0};
    for (i=1; i<n+1; i++) {
        player[i] = (point-q);
        player[i] += fr[i];
    }
//    for (i=1; i<n+1; i++) {
//        if (player[i] < mini) mini = player[i];
//    }
    for (i=1; i<n+1; i++) {
        //printf("%I64d\n", player[i]);
        if ( (player[i] <= 0))printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 2944
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int A = sc.nextInt();

		if(H%A==0) {
			System.out.println(H/A);
		} else {
			System.out.println(H/A+1);
		}

	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

string s;
int n;
int cntl[30];
int cntr[30];

int main(void) {
	cin >> s;
	string d;
	int sum = 0;
	rep(i, s.size()) {
		if(s[i] != 'x') d += s[i];
		else sum++;
	}
	// cout << d << endl;
	bool f = true;
	rep(i, d.size() / 2) if(d[i] != d[d.size() - 1 - i]) {
		// printf("%c %c\n", );
		f = false;
	}
	int suml = 0;
	int tcnt = 0;
	rep(i, s.size()) {
		if(tcnt == d.size() / 2) break;
		if(s[i] == 'x') suml++;
		else tcnt++;
	}
	int ans = 0;
	int l = 0, r = s.size() - 1;
	while(r - l > 0) {
		if(s[l] == s[r]) l++, r--;
		else if(s[l] == 'x') {
			ans++;
			l++;
		}else {
			ans++;
			r--;
		}
	}
	if(f) printf("%d\n", ans);
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 512
implicit none
character(10**5+5) s,s_rev
character(5):: a
character(5):: b
character(6):: c
character(7):: d
integer:: s_len,i,count
 
a='maerd'
b='esare'
c='resare'
d='remaerd'
s_rev=''
 
read(*,*) s
s_len=len_trim(s)
 
do i=1,s_len
s_rev(s_len+1-i:s_len+1-i)=s(i:i)
end do
 
count=0
do while (count<s_len)
if(index(s_rev,a)==1)then
count=count+len(a)
s_rev=s_rev(len(a)+1:)
 
else if(index(s_rev,b)==1)then
count=count+len(b)
s_rev=s_rev(len(b)+1:)
 
else if(index(s_rev,c)==1)then
count=count+len(c)
s_rev=s_rev(len(c)+1:)
 
else if(index(s_rev,d)==1)then
count=count+len(d)
s_rev=s_rev(len(d)+1:)
 
else
write(*,*) 'NO'
goto 100
endif
end do
 
write(*,*) 'YES'
 
100 end

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

using namespace std;

const int MOD = 1e9 + 7;
const int MAX = 1000001;
ll fac[MAX], finv[MAX], inv[MAX];

// nCr inv
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k){
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

	ll x, y;
	cin >> x >> y;

	COMinit();
	ll res = 0;

	if ((x + y) % 3 == 0) {

		ll n = (2 * y - x) / 3;
		ll m = y - 2 * n;
		if (n >= 0 && m >= 0) {
			res = COM(n + m, n);
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 23680
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


int n, m;
string s;

int main() {
	cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i / 100000)continue;
		if (i / 10000) {
			cnt++;continue;
		}
		if (i / 1000)continue;
		if (i / 100) {
			cnt++;continue;
		}
		if (i / 10)continue;
		cnt++;
	}
	cout << cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------
int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
    }

    vector<ll> x(n);
    x[0] = a[0];
    vector<ll> y(n);
    y[n-1] = a[n-1];
    for(ll i=1;i<n;++i){
        x[i] = gcd(a[i], x[i-1]);
        y[n-i-1] = gcd(a[n-i-1], y[n-i]);
    }
    ll ans = max(x[n-2], y[1]);
    for(ll i=1;i<n-1;++i){
        ans = max(ans, gcd(x[i-1], y[i+1]));
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 13
#define pi M_PI

int main(){
    int x,y,r;
    scanf("%d%d",&x,&y);
    while(1){
        r=x%y;
        x=y;
        y=r;
        if(y==0) break;
    }
    printf("%d\n",x);
   return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace __gnu_pbds;
using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll i = 0; i < n; i++)
#define FORN(i, a, b) for (ll i = a; i < b; i++)
#define FORE(i, l) for (auto i : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) n.begin(), n.end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

#define SIZE (ll)(1e6 + 1)

vll nums;
ll x;

void recur(ll cur, ll d)
{
    if (d > 9) return;
    nums.pb(cur);
    if (cur % 10 > 0) recur(cur * 10 + cur % 10 - 1, d + 1);
    recur(cur * 10 + cur % 10, d + 1);
    if (cur % 10 < 9) recur (cur * 10 + cur % 10 + 1, d + 1);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll k;
    cin >> k;
    //nums.resize(SIZE);
    x = 0;
    FORN(i,1, 10) recur(i, 0);
    sort(all(nums));
    cout << nums[k - 1] << '\n';
}



Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define em3 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define EPS 1e-6
#define endl '\n'
long long mod = 1e9 + 7;
const int N = 1e5 + 5;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1);
typedef complex <double> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
ll sz[N], rep[N], n, m, x[N], y[N], totalsize, ans;
vector<ll> v;
ll findu(ll u)
{
    return ( rep[u] == u ) ? u : rep[u] = findu(rep[u]);
}
void join(ll a, ll b)
{
    a = findu(a);
    b = findu(b);
    if( a == b )
        return;
    if( sz[a] < sz[b] )
        swap(a, b);
    ll temp1 = sz[a], temp2 = sz[b];
    sz[a] += sz[b];
    rep[b] = rep[a];
    ///cout << rep[b] << " " << rep[a];
    if(totalsize != 0)

        totalsize -= ((temp1 * (temp1 - 1)) / 2)+ ((temp2 * (temp2 - 1)) / 2);
    totalsize += (sz[a] * (sz[a] - 1)) / 2;
    ///cout << " temp1 : " << (temp1 * (temp1 - 1)) << " temp2 : " << (temp2 * (temp2 - 1)) / 2 <<  " total size : " << totalsize << endl;
}

int main()
{
    em3
    for(int i = 0 ; i < N ; i++)
        sz[i] = 1, rep[i] = i;
    cin >> n >> m;
    ans = (n * (n - 1)) / 2;
    for(int i = 0 ; i < m ; i++)
    {
        cin >> x[i] >> y[i];
    }
    for(int i = m - 1 ; i >= 0 ; i--)
    {
        v.push_back(ans - totalsize);
        join(x[i], y[i]);
    }
    for(int i = v.size() - 1 ; i >= 0 ; i--)
        cout << v[i] << endl;

    return 0;
}


Measured memory_bytes: 5364
n=int(input())
w = [input() for _ in range(n)]
words=[]
for i in range(n):
    s=w[i]
    if s in words:
        print("No")
        exit()
    if i == 0:
        end = s[-1]
        words.append(s)
        continue
    
    if end != s[0]:
        print("No")
        exit()
    else:
        end = s[-1]
        words.append(s)
print("Yes")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;
long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}
ll modinv(ll a){ ll b=mod,u=1,v=0,t; while(b){ t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return (u+mod)%mod; }
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
ll modncr(ll n,ll r){ ll i,plus=1; rep(i,r){ plus=(plus*(n-i))%mod; plus=moddevide(plus,i+1); } return plus; }
ll euclidean_gcd(ll a, ll b) { if(a<b) return euclidean_gcd(b, a); ll r; while ((r=a%b)){a=b;b=r;} return b; }
ll countdigits(ll n){ ll ans=0; while(n){n/=10;ans++;} return ans; }
ll sumdigits(ll n){ ll ans=0; while(n){ans+=n%10;n/=10;} return ans; }
void printmap(vector<ll>& a,ll H,ll W){ ll i,j; For(i,0,H+2){ For(j,0,W+2){cout<<a[i*(W+2)+j];} cout<<endl; } } void inputmap(vector<ll>& a,ll H,ll W){ ll i,j; string ss; For(i,1,H+1){ cin>>ss; For(j,1,W+1){ if(ss[j-1]=='#'){ a[i*(W+2)+j]=1; }else{ a[i*(W+2)+j]=0; } } } }
int main(){
  ll i,j,N,K,a=1000000000;
  string ss;
  cin>>N>>K;
  K--;
  vec v(N);
  rep(i,N){
    cin>>v[i];
  }
  vsort(v);
  For(i,K,N){
    a=min(a,v[i]-v[i-K]);
  }
  cout<<a;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M;
  cin>>N>>M;

  vector<Int> A(N), B(M);;
  cin>>A>>B;

  for(Int i=0;i<N;i++) A[i] = N * M - A[i];
  for(Int i=0;i<M;i++) B[i] = N * M - B[i];
  
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  B.erase(unique(B.begin(), B.end()), B.end());
  if((Int)A.size() != N || (Int)B.size() != M){
    cout<<0<<endl;
    return 0;
  }


  auto exist=[&](Int x, vector<Int>&A){
    auto it = lower_bound(A.begin(), A.end(), x);
    return it != A.end() && *it == x;
  };

  auto count = [&](Int x, vector<Int> &A){
    return lower_bound(A.begin(), A.end(), x) - A.begin();
  };
  
  Int ans = 1;
  for(Int x=0;x<N * M;x++){
    if(exist(x, A) && exist(x, B)) continue;
    if(exist(x, A)) ans = ans * count(x, B) % mod;
    else if(exist(x, B)) ans = ans * count(x, A) % mod;
    else ans = ans * (count(x, A) * count(x, B) - x) % mod;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int m,d;
int main(){
	cin>>m>>d;
	int ans=0;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=d;j++){
			int d1=j%10;
			int d2=j/10;
			if(d1>=2&&d2>=2&&d1*d2==i)ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int x;
bool is_prime(ll n){
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    if(n==1) return false;
    return true;
}
int main(void){
    cin>>x;
    while(true){
        if(is_prime(x)){
            cout<<x<<endl;
            return 0;
        }
        x++;
    }

}


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

class Solver {
  public:
    bool solve() {
        long long  N; cin >> N;        
        long long  ans = N / 11 * 2;
        N %= 11;
        if(N) ans += N > 6 ? 2 : 1;
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  vector<pair<ll,ll>> a(n);rep(i,n)cin>>a[i].fi>>a[i].se;
  
  ll cnt = 0;
  rep(i,n){
    int now = n-i-1;
    a[now].fi += cnt;

    cnt += a[now].se - ((a[now].fi % a[now].se)?a[now].fi % a[now].se : a[now].se);
    // test(cnt);
  }

  print(cnt);
  return 0;
}



Measured memory_bytes: 1792
#include <stdio.h>

#define NMAX 100001
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[NMAX];

int n, Depth[NMAX];

void print(int);
int rec(int,int);

int main(void){
  int i,j,degree,value,c,l,r;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    T[i].parent = T[i].left = T[i].right = NIL;
  }

  for(i = 0;i < n;i++){
    scanf("%d%d",&value,&degree);
    for(j = 0;j < degree;j++){
      scanf("%d",&c);
      if(j == 0){
	T[value].left = c;
      }else{
	T[l].right = c;
      }
      l = c;
      T[c].parent = value;
    }
  }

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

  rec(r,0);

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

void print(int u){
  int i,c;

  printf("node %d: parent = %d, depth = %d, ",u,T[u].parent,Depth[u]);

  if(T[u].parent == NIL){
    printf("root, ");
  }else if(T[u].left == NIL){
    printf("leaf, ");
  }else{
    printf("internal node, ");
  }
  printf("[");
  for(i = 0,c = T[u].left;c != NIL;i++,c = T[c].right){
    if(i == 0){
      printf("%d",c);
    }else{
      printf(", %d",c);
    }
  }
  printf("]\n");
}

int rec(int u,int p){
  Depth[u] = p;
  if(T[u].right != NIL){
    rec(T[u].right,p);
  }
  if(T[u].left != NIL){
    rec(T[u].left,p + 1);
  }
  return 0;
}

      



Measured memory_bytes: 6404
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush =
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadLong;
			var K = cin.ReadLong;
			N %= K;
			var N1 = K - N;
			Console.WriteLine(Min(N,N1));
		}
	}
	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);

	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i < N; ++i)
				ret[i] = Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek() == -1; }
		}
	}

}


Measured memory_bytes: 13268