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

char a[55][55];
int wh[55][55], bl[55][55];

int di[] = {-1, 0, 1, 0};
int dj[] = {0, -1, 0, 1};

int main() {
    int w, h;
    while (cin >> w >> h, w | h) {
        queue<pii> q1, q2;
        for (int i = 0; i < 55; i++) {
            for (int j = 0; j < 55; j++) {
                wh[i][j] = bl[i][j] = 0;
            }
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> a[j][i];
                if (a[j][i] == 'W') {
                    q1.push(pii(j, i));
                    wh[j][i] = bl[j][i] = 2;
                } else if (a[j][i] == 'B') {
                    q2.push(pii(j, i));
                    wh[j][i] = bl[j][i] = 2;
                }
            }
        }
        while (!q1.empty()) {
            int ci = q1.front().second;
            int cj = q1.front().first;
            q1.pop();
            for (int i = 0; i < 4; i++) {
                int ni = ci + di[i];
                int nj = cj + dj[i];
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if (wh[nj][ni] == 0 && a[nj][ni] == '.') {
                    wh[nj][ni] = 1;
                    q1.push(pii(nj, ni));
                }
            }
        }
        while (!q2.empty()) {
            int ci = q2.front().second;
            int cj = q2.front().first;
            q2.pop();
            for (int i = 0; i < 4; i++) {
                int ni = ci + di[i];
                int nj = cj + dj[i];
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if (bl[nj][ni] == 0 && a[nj][ni] == '.') {
                    bl[nj][ni] = 1;
                    q2.push(pii(nj, ni));
                }
            }
        }
        int r1 = 0, r2 = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (wh[j][i] == 0 && bl[j][i] == 1) r1++;
                if (wh[j][i] == 1 && bl[j][i] == 0) r2++;
            }
        }
        cout << r1 << " " << r2 << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;


public class Prog
{
    public struct Pair { public int x, y; public Pair(int a, int b) { y = a; x = b; } }
    public static void Solve()
    {
        int N = NextInt();
        string s = NextString();
        int ans = 0;
        for (int i = 2; i < N; i++)
            if (s[i - 2].ToString() + s[i - 1].ToString() + s[i].ToString() == "ABC") ans++;
        Console.WriteLine(ans);
    }
    public static long GCD(long a, long b)
    {
        if (a < b) GCD(b, a);
        long d = a % b;
        while (b != 0)
        {
            d = a % b;
            a = b;
            b = d;
        }
        return a;
    }
    public static long LCM(long a, long b)
    {
        return a / GCD(a, b) * b;
    }

    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        return;
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


Measured memory_bytes: 13268
def main():
    s = input()
    t = input()

    slen = len(s)
    tlen = len(t)
    
    ans = 10 ** 10

    for i in range(slen - tlen+1):
        tmp = 0
        for j in range(tlen):
            if s[i+j] != t[j]:
                tmp += 1
        if ans > tmp:
            ans = tmp
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 9056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll cord,koita;
    cin >> koita >> cord; /// 3 7
    ll start = cord - koita + 1; /// 5
    for (int i=start; i<cord; i++){
        cout << i << " "; /// 5 6
    }
    cout << cord << " "; // 7
    ll en = cord + koita - 1; /// 9
    for (int i= cord + 1; i<=en; i++){
        cout << i << " ";
    }
    return 0;
}


Measured memory_bytes: 3604
//Practice
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 2e5 + 5;
const ll INF = 1e9 + 5;
const ll mxN = 1000000007;
const double E = 1e-9;

//------------------------------------------------------------------------------
int n;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*ifstream cin("input.txt");
	ofstream cout("output.txt");*/
	cin >> n;
	vector<int> a(n + 1, 0);
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int ini = 1;
	if (a[1] == 1)
	{
		cout << -1;
		return 0;
	}
	if (a[1] == 2)
	{
		cout << 1;
		return 0;
	}
	ll ans = 0;
	while (ans <= n)
	{
		++ans;
		if (a[ini] == 2)
		{
			cout << ans;
			return 0;
		}
		ini = a[ini];
	}
	cout << -1;
	return 0;
}
//29-08-2020 11:45:44
//------------------------------------------------------------------------------

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

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

    for(int i=0;i<=n;i++)
         for(int j=0;j<=m;j++)
    {
        if(k==i*m+j*n-(2*(i*j))){
            cout<<"Yes";return 0;}
    }
    cout<<"No";
}


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


int main () {
   std::string s; std::cin >> s;
   std::string ans;

   int count = 0;

   int CID = 0;
   if(s[0] == 'A') {
      count ++;
   }

   for(auto i = 2; i <= s.length() - 2; i++) {
      if(s[i] == 'C') {
         count ++;
         CID = i;
      }
   }

   bool isLow = true;


   for(auto i = 1; i < s.length(); i++) {
      if(i != CID) {
         if(std::isupper(s[i])) {
            isLow = false;
         }
      }
   }

   if(isLow && count == 2) {
      ans = "AC";
   } else {
      ans = "WA";
   }

   std::cout << ans << std::endl;
}


   


Measured memory_bytes: 3608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String word = in.next();
            int cnt = 0;
            for (int i = 1; i < word.length(); i++) {
                if (word.charAt(i) != word.charAt(i - 1)) cnt++;
            }
            out.println(cnt);
        }

    }

    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();
        }

    }
}


Measured memory_bytes: 10964
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
int main(){
		LL n,k,x,y;
		cin >> n >> k >> x >> y;
		if(n <= k){
			cout << n*x << endl;
			}
		else {
			cout << k*x + (n-k)*y <<endl;
			}
		return 0;
	}

Measured memory_bytes: 256
#include<stdio.h>
typedef long long int lli;
#define max(a,b) (((a)>(b))?(a):(b))
int main() {
  lli a,b,c,d;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
  
  printf("%lld", max(max(a*c,b*d),max(a*d,b*c)));
  return 0;
}



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

/*============================ DEBUGGING =============================*/

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

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

/*============================= DEFINES ==============================*/

#define eps 1e-9
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define B begin()
#define E end()
#define F first
#define S second
#define tostr(x) to_string(x)
#define SZ(x) ((int)x.size())
#define ins insert
#define rep(i,x,y) for(int i=x;i<y;i++)
#define per(i,x,y) for(int i=x;i>y;i--)
#define repi(i,x,y) for(int i=x;i<=y;i++)
#define peri(i,x,y) for(int i=x;i>=y;i--)
#define inf (ll)LLONG_MAX
#define ds1(i,x) for(auto i=x.begin();i!=x.end();i++)
#define ds2(i,x) for(auto i:x)
#define fib(n) ceil(pow((1+sqrt(5),n)-pow((1-sqrt(5),n)/(float)(pow(2,n)*sqrt(5)
#define FIO {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define dig(n) (int)(log10(n)+1)
#define ss(x,k) substr(x,k)  // x is the start pos and k is the length of substr.
#define set(x,k) memset(x,k,sizeof x)

/*============================== TYPEDEFS ============================*/

typedef long long ll;
typedef long l;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vlli;
typedef vector<bool> vb;
typedef queue<int> qi;
typedef vector<pair<int,int> > vpii;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
/*============================ START FROM HERE =======================*/

int main(){
	FIO
	
	int n;cin>>n;
	str s;cin>>s;
	int i=0,ans=0;char c=s[0];
	while(i<=SZ(s)){
		if(s[i]!=c){
			ans++;
			c=s[i];
		}
		i++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 512
n = int(input())
x = [tuple(map(int, input().split())) for _ in range(n)]

if n % 2 == 1:
    x.sort()
    l = x[n // 2][0]
    x.sort(key=lambda x: -x[1])
    r = x[n // 2][1]
    print(r - l + 1)

else:
    x.sort()
    l1 = x[n // 2 - 1][0]
    l2 = x[n // 2][0]
    x.sort(key=lambda x: -x[1])
    r1 = x[n // 2 - 1][1]
    r2 = x[n // 2][1]
    print(r1 + r2 - l1 - l2 + 1)

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


int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int gcdtry(int a,int b, int c){
    int d,e;
    d=gcd(a,b);
    e=gcd(d,c);
    return e;
} 

int main(){
    int k;
    cin>>k;
    long int ans=0;
    for(int i=1;i<=k;i++){
        for(int h=1;h<=k;h++){
            for(int j=1;j<=k;j++){
                ans+=gcdtry(i,h,j);

            }
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< string, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789


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

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


int N;

int main(){

  cin>>N;

  if( N % 10 == 3 ) puts("bon");
  else if( N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8 ){
    puts("pon");
  }
  else{
    puts("hon");
  }
  return 0;
}



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

using namespace std;

typedef long long ll;

void pv(vector <int> &v) {
    for(int i = 0; i < v.size(); i++) cout << v[i] << " ";
    cout << endl;
}

void solve() {
	
}

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

    ll n;
    cin >> n;
    vector <int> a(n, 0);
    vector <int> b(n, 0);
    
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    
    reverse(b.begin(),b.end());
    // pv(b);
    int prob = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] == b[i]) prob++;
    }
    int c = -1;
    int l = INT_MAX;
    int r = INT_MIN;
    for(int i = 0; i < n; i++) {
        if(a[i] == b[i]) {
            c = a[i];
            l = i;
            break;
        }
    }
    for(int i = n-1; i >= 0; i--) {
        if(a[i] == b[i]) {
            r = i;
            break;
        }
    }

    int toSwap = (r-l+1);
    if(toSwap == 0 || prob == 0) {
        cout << "Yes" << endl;
        pv(b);
        return 0;
    }
    int l0 = l;
    int r0 = r;
    int avail = 0;
    for(int i = 0; i < l; i++) {
        if(a[i] != c && b[i] != c) avail++;
    }
    for(int i = r+1; i < n; i++) {
        if(a[i] != c && b[i] != c) avail++;
    }
    if(avail < toSwap) {
        cout << "No" << endl;
        return 0;
    }
    else cout << "Yes" << endl;

    int i = 0;
    int j = r0+1;

    while(l <= r) {
        if(i < l0 && a[i] != c && b[i] != c) {
            swap(b[i], b[l]);
            l++;
        }
        i++;
        if(i == n) break;
    }
    if(j < n) {
        while(l <= r) {
            if(j < n && a[j] != c && b[j] != c) {
                swap(b[j], b[l]);
                l++;
            }
            j++;
            // if(j == n) break;
        }
    }


    // while(l <= r) {
    //     if(i < l0 && a[i] != c && b[i] != c) {
    //         swap(b[i], b[l]);
    //         l++;
    //         i++;
    //         continue;
    //     }
    //     else if(i == l0 && a[j] != c && b[j] != c && j < n) {
    //         swap(b[j], b[l]);
    //         l++;
    //         j++;
    //         continue;
    //     }
    //     i++;
    //     if(i == l0) j++;
    // }
    pv(b);
    


    
    return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;
const int N=2e5+5;


int main(){
    int N; cin >> N;
    string S, T; cin >> S >> T;
    for(int i=0; i<N; i++){
        cout << S[i] << T[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import * as fs from 'fs';
// main
function main(input: string[]) {
    // param
    let n: number = 0;
    let ans: number = 0;
    // init
    n = Number(input.shift());
    // solve
    let a0 = 1n;
    let an = 8n;
    let a9 = 1n;
    let a09 = 0n;
    for (let nx = 1; nx < n; nx++) {
        let bn = an * 8n;
        let b0 = a0 * 9n + an * 1n;
        let b9 = a9 * 9n + an * 1n;
        let b09 = a09 * 10n + a0 * 1n + a9 * 1n;
        an = bn % 1000000007n;
        a0 = b0 % 1000000007n;
        a9 = b9 % 1000000007n;
        a09 = b09 % 1000000007n;
    }
    ans = Number(a09);
    // answer
    console.log(ans);
}
// entrypoint
function entrypoint() {
    try {
        // linux
        let input = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        console.debug = function () { };
        main(input);
    }
    catch (ex) {
        // windows
        const lines: string[] = [];
        // @ts-ignore
        const reader = require('readline').createInterface({
            // @ts-ignore
            input: process.stdin,
            // @ts-ignore
            output: process.stdout
        });
        reader.on('line', function (line: string) {
            lines.push(line);
        });
        reader.on('close', function () {
            let input = lines;
            main(input);
        });
    }
}
entrypoint();


Measured memory_bytes: 35264
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

ll A, B , C , D;

ll gcd(ll a, ll b){return (a == 0) ? b : gcd(b%a, a);}
ll lcm(ll a, ll b){return (a*b) / gcd(a,b);}
ll f(ll a)
{
	return a - a/C - a/D + a/lcm(D,C);
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	
	cin >> A >> B >> C >> D;
	//10 40 6 8
	cout << fixed << f(B) - f(A-1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
 #define rep(i,n) for(int i=0;i<n;++i)
 #define all(v) v.begin(), v.end()
 typedef long long int ll;
 typedef unsigned long long ull;
 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;}
 typedef pair<ll,ll> P;
 const long long MOD = 1e9+7;
 const ll INF = 1LL << 60;

 int main(){

     int n;
     cin >> n;
     ll sum = 0;
     vector<int> a(n);
     map<ll,ll> map;

     rep(i,n){
         cin >> a[i];
         map[a[i]]++;
         sum += a[i];
     }

     int q;
     cin >> q;
     rep(i,q){
         int b,c;
         cin >> b >> c;
         sum -= b* map[b];
         sum += c * map[b];
         map[c]+= map[b];
         map[b] = 0;

         cout << sum << endl;

     }



 }


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

int main(){
    int N, P, i;
    string S;
    cin >> N;
    vector<tuple<string,int,int>>a;

    for (i = 1; i <= N; i++){
      cin >> S >> P;
      P = -P;
      a.push_back(tie(S,P,i));
    }
    sort(a.begin(), a.end());
    for (i = 0; i < N; i++){
      cout << get<2>(a[i]) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using  P=pair<long long,long long>;
int main(){
  long long N;
  cin>>N;
  vector<vector<long long>> vec(N);
  map<P,long long> mp;
  vector<long long> color(N);
  for(long long i=0;i<N-1;i++){
    long long a,b,c;
    cin>>a>>b>>c;
    c%=2;
    vec.at(a-1).push_back(b-1);
    vec.at(b-1).push_back(a-1);
    mp[make_pair(a-1,b-1)]=c;
    mp[make_pair(b-1,a-1)]=c;
  }
  color.at(0)=0;
  vector<long long> dist(N,-1);//全頂点を「未訪問」に初期化
  queue<long long> que;
  dist[0]=0;
  que.push(0);
  while(!que.empty()){
    long long v=que.front();//キューから先頭頂点を取り出す
    que.pop();
    //v から辿れる頂点をすべて調べる
    for(long long i=0;i<(long long)vec.at(v).size();i++){
      long long nv=vec.at(v).at(i);
      if(dist[nv]!=-1)continue;//すでに発見済みの頂点は探索しない
      //新たな白色頂点 nv について距離情報を更新してキューに追加する
      dist[nv]=dist[v]+mp[make_pair(v,nv)];
      color.at(nv)=dist[nv]%2;
      que.push(nv);
    }
  }
  for(long long i=0;i<N;i++){
    cout<<color.at(i)<<endl;
  }
}

Measured memory_bytes: 23268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    string s, t;
    cin >> s >> t;
    int slen = s.length(), tlen = t.length();
    vector<vector<int>> m(26);
    for(int i = 0; i < slen; ++i)
        m[s[i] - 'a'].push_back(i);
    ll ans = 0, pos = 0;
    for(int i = 0; i < tlen; ++i) {
        int n = t[i] - 'a';
        auto itr = lower_bound(m[n].begin(), m[n].end(), pos);
        if(itr == m[n].end()) {
            if(!m[n].empty()) {
                ans += slen - (pos - m[n][0]) + 1;
                pos = ans % slen;
                continue;
            } else {
                ans = -1;
                break;
            }
        }
        ans += *itr - pos + 1;
        pos = ans % slen;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1216
/*
Hanit Banga
Problem: 
*/

#include <iostream>
#include <vector>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

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

const int N = 1e5 + 5;

bool dp[N] = {0};
string words[4] = {"dream", "dreamer", "eraser", "erase"};

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

	int n = s.length();

	for (int i = 4; i < n; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			int m = words[j].length();

			if (i-m+1 >= 0 and (i-m == -1 or dp[i-m]) and s.substr(i-m+1, m) == words[j])
			{
				dp[i] = true;
				break;
			}
		}
	}

	if (dp[n-1])
		cout << "YES";

	else
		cout << "NO";
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

// imos-hou
class Program
{
    static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        new Program().solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();


    void solve()
    {
        int N = cin.nextint;
        int T = cin.nextint;
        var A = new int[T + 1];

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

        var max = A[0];
        for (int i = 1; i <= T; i++)
        {
            A[i] += A[i - 1];
            max = Math.Max(A[i], max);
        }

        Console.WriteLine(max);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return Console.ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 9876
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int s=sc.nextInt();
    int d1=0,d2=0,count=0;
    for(int i=0;i<s;i++){
      d1=sc.nextInt();
      d2=sc.nextInt();
      if(d1==d2){
        count++;
        if(count==3)break;
      }
      else{
        count=0;
      }
      
    }
    if(count>=3)System.out.println("Yes");
    else System.out.println("No");
  }
}

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

typedef long long ll;
#define mod 1000000007

template<typename T>
void deb(initializer_list<T> l)
{
    for (auto &e : l)
        cout << e << ' ';
    cout << endl;
}

void solve(){
    ll a, b, c;
    cin>>a>>b>>c;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int x, y;
    cin >> x >> y;
    if(y%2 ==  0 && y/2 - x >= 0 && y/2 - x <= x){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }

    return 0;
}

Measured memory_bytes: 3528
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long LL;

LL n,m,a[500005],sum = 0;

bool cmp(LL x,LL y){
	return x > y;
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(LL i = 1;i <= n;i ++){
		cin >> a[i];
		sum += a[i];
	}
	sort(a + 1,a + 1 + n,cmp);
	cout << (a[m] * m * 4LL >= sum ? "Yes" : "No") << endl;
	return 0;
}
//

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <deque>
 
using namespace std;
using ll = long long;
 
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << endl; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }
 
#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
 
// constexpr int MOD = 998244353;

int main(void){
    Cin(int, n);
    ll ans = 0;
    for(int i = 1; i <= n; i ++){
        ll m = n/i;
        ans += m*(m+1)/2 * i;
    }
    Cout(ans);
}



Measured memory_bytes: 3632
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

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

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

    std::vector<int> l(n, 0), r(n + 1, 0);

    for (int i = 1; i < n; i++) {
        l[i] = gcd(l[i - 1], a[i - 1]);
    }

    for (int i = n - 1; i >= 0; i--) {
        r[i] = gcd(r[i + 1], a[i]);
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = std::max(ans, (int)gcd(l[i], r[i + 1]));
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 1408
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  lines.shift().split(' ').map(Number).forEach(function(key, i, a) {
    console.log(`node ${i+1}: key = ${a[i]}, `+(i?`parent key = ${a[Math.floor((i-1)/2)]}, `:'')+(2*i+1<a.length?`left key = ${a[2*i+1]}, `:'')+(2*i+2<a.length?`right key = ${a[2*i+2]}, `:''));
  });
})();



Measured memory_bytes: 17304
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final BigInteger MOD = BigInteger.valueOf((long) 1e9 + 7);

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        Map<Integer, Set<Integer>> graph = new HashMap<>();

        for (int i=0; i < m; i++) {
            int u = in.nextInt();
            int v = in.nextInt();

            if (!graph.containsKey(u))
                graph.put(u, new HashSet<>());
            graph.get(u).add(v);
        }

        // out.println(graph);

        int s = in.nextInt();
        int t = in.nextInt();

        Map<Integer, Set<Integer>> graph2 = new HashMap<>();
        for (Map.Entry<Integer, Set<Integer>> e : graph.entrySet()) {
            for (int i=0; i < 3; i++) {
                if (!graph2.containsKey(e.getKey()*3 + i))
                    graph2.put(e.getKey()*3 + i, new HashSet<>());
                int finalI = i;
                e.getValue().forEach(v -> graph2.get(e.getKey()*3 + finalI).add(v*3 + (finalI +1)%3));
            }
        }

        Set<Integer> been = new HashSet<>();
        ArrayDeque<Map.Entry<Integer, Integer>> toVisit = new ArrayDeque<>();

        int ans = -1;
        if (graph2.containsKey(s*3))
            graph2.get(s*3).forEach(v -> toVisit.addLast(new AbstractMap.SimpleEntry<>(v, 1)));
        while (!toVisit.isEmpty()) {
            Map.Entry<Integer, Integer> e = toVisit.poll();
            if (been.contains(e.getKey()))
                continue;

            if (e.getKey() == t * 3) {
                ans = e.getValue() / 3;
                break;
            }
            been.add(e.getKey());
            if (graph2.containsKey(e.getKey()))
                graph2.get(e.getKey()).forEach(v -> toVisit.addLast(new AbstractMap.SimpleEntry<>(v, e.getValue() + 1)));
        }

        out.println(ans);
    }

}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(3*n);
  rep(i,3*n) cin >> a[i];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  ll ans = 0;
  rep(i,2*n) {
    if(i%2!=0) ans += a.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>

int main()
{
  int A, B;
  std::cin >> A >> B;
  int ans = 0;
  for ( int n = A; n <= B; n++ ) {
    std::string s = std::to_string(n);
    int len = s.size();
    bool can = true;

    for ( int i = 0; i < len/2; i++ ) {
      if ( s[i] != s[len-i-1] ) {
        can = false;
        break;
      }
    }
    if (can) ans++;
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;

int dp[300010][2][2];

string s;

bool ok(int i, int j, int k) {
	char c = '0' + (1 - j);
	char d = '0' + (1 - k);
	if (s[i - 1] != c && s[i] != d) return true;
	return false;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	cin >> s;
	int n = s.size();
	if (n == 1) {
		if (s == "1" || s == "?") cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	vector<int> cnt(n);
	int res = 1;
	if (s[0] == '?') res *= 2;
	for (int i = 0; i < n; i += 2) {
		cnt[i] = res;
		if (i == n - 1) continue;
		if (s[i + 1] == '?') res *= 2;
		if (s[i + 2] == '?') res *= 2;
		res %= mod;
	}
	if (s[0] != '1') {
		dp[2][1][1]++;
	}
	if (s[0] != '0') {
		dp[2][0][1]++; dp[2][1][0]++; dp[2][1][1]++;
	}
	for (int i = 2; i < n - 2; i++) {
		if (ok(i, 0, 0)) dp[i + 2][0][0] += dp[i][0][0];
		if (ok(i, 0, 1)) dp[i + 2][0][0] += dp[i][0][0];
		if (ok(i, 1, 0)) dp[i + 2][0][0] += dp[i][1][0];
		if (ok(i, 1, 1)) dp[i + 2][0][0] += dp[i][1][0];
		dp[i + 2][0][0] %= mod;
		if (ok(i, 0, 0)) dp[i + 2][0][1] += dp[i][0][1];
		if (ok(i, 0, 1)) dp[i + 2][0][1] += dp[i][0][1];
		if (ok(i, 1, 0)) dp[i + 2][0][1] += dp[i][0][1];
		if (ok(i, 1, 1)) dp[i + 2][0][1] += dp[i][1][1];
		dp[i + 2][0][1] %= mod;
		rep(j, 2) rep(k, 2) if (ok(i, j, k)) dp[i + 2][1][0] += dp[i][j][k];
		dp[i + 2][1][0] %= mod;
		dp[i + 2][1][1] = cnt[i];
	}
	int ans = 0;
	rep(j, 2) rep(k, 2) if (ok(n - 1, j, k)) ans += dp[n - 1][j][k];
	cout << ans % mod << endl;
}

Measured memory_bytes: 12436
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<iomanip>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;

string table[]={"qwertasdfgzxcvb","yuiophjklnm"};


int main(){
	
	while(true){
		int member,winner,pool;
		int monney=0,all_monney=0,w_monney=0;

		cin >> member >> winner >> pool;
	
		if(monney==0&&winner==0&&pool==0) break;

		for(int i=1;i<=member;i++){
			cin >> monney;
			if(i==winner){
				w_monney=monney;
			}
			all_monney+=monney;
		}

		if(w_monney==0){
			cout << 0 << endl;
		}else{
			/*all_monney=(all_monney*100)-((all_monney*100)*(pool/100));
			all_monney=all_monney/w_monney;
			*/
			int sub=0;
			all_monney=all_monney*100;
			sub=(all_monney*pool)/100;
			w_monney=(all_monney-sub)/w_monney;

			cout << w_monney << endl;
		}
	}

}

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

int a, b;

int main()
{
    while (cin >> a >> b)
    {
        a += b;
        int ans = 0;
        while (a)
        {
            a /= 10, ans++;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3084
function splitMap(input: string) {
  return input.split(' ').map(s => parseInt(s, 10))
}

function main(input: string) {
  const [op, base, ...rest] = input.split('\n').map(l => splitMap(l))
  
  let clearCount = 0
  for (let i = 0; i < rest.length; i++) {
    let res = []
    for (let j = 0; j < op[1]; j++) {
      res.push(base[j] * rest[i][j])
    }
    
    const calced = res.reduce((a, c) => a + c, op[2])
    if (calced > 0) {
      clearCount++
    }
  }
  
  console.log(clearCount)
}

main(require("fs").readFileSync("/dev/stdin", "utf8").trim())

Measured memory_bytes: 7500
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

long long p[100][11];
bool f[100][10];
int n;
long long ans = -9999999999999999;
void solve(int a , vector<int> v){
  
  //printf("a:%d\n",a);

  if(a > 9 ){

    long tmp = 0; 
    bool ffff = false;
    rep(i,0,n){
      if(v[i] > 0)
        ffff = true;
      //printf("i:%d v:%d p:%ld\n",i,v[i],p[i][v[i]]);
      tmp = tmp +  p[i][v[i]];
    }
    
    //cout << "tmp:" << tmp << endl; 
    //printf("ans:%ld ff:%d\n",ans , ff);
    
    if(ffff)
      if(ans < tmp)
        ans = tmp;
  }
  else{
    solve(a+1,v);
    
    rep(i,0,n){
      if(f[i][a]){
        v[i]++;
      }
    }

    solve(a+1,v);
  }

  ret;

}

int main(){
 
  cin >> n;
  //cout << "n:" << n << endl;
  
  rep(i,0,n){
    rep(j,0,10){      
      cin >> f[i][j];
    }
  }
    
  rep(i,0,n){
    rep(j,0,11){
      cin >> p[i][j];
    }
  }


  vector<int> v(n);
  
  rep(i,0,n)
    v[i] = 0;
  
  solve(0 , v );
  
  P(ans);

  ret 0;
}

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

int main(){
    int N;
    cin >> N;
    string x[N];
    string u[N];
    int i;
    for(i = 0; i<N; i++){
        cin >> x[i] >> u[i];
    }
    double sum = 0;
    for(i = 0; i < N; i++){
        if(u[i] == "JPY"){
            sum += atoi(x[i].c_str());
        }else{
            sum += (double)380000.0 * stod(x[i]);
        }
    }
    cout << sum << endl;
    return 0;
}

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

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

    int ans = 0;
    string pm[4];
    pm[3] = "=7";
    for(int i = 0; i < 1 << 4 - 1; i++){
        ans = s[0] - '0';
        for(int j = 0; j < 3; j++){
            if(i & 1 << j){
                ans += (s[j+1] - '0');
                pm[j] = "+";
            }
            else{
                ans -= (s[j+1] - '0');
                pm[j] = "-";
            }
        }
        if(ans == 7){
            for(int k = 0; k < 4; k++){
                cout << s[k] << pm[k];
            }
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define INF 10000000


int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		int card[201];
		CLR(card);
		VI taro,hanako;
		REP(i,n){
			int num;
			cin>>num;
			taro.PB(num);
			card[num]++;
		}
		FOR(i,1,2*n+1)if(card[i]==0)hanako.PB(i);
		SORT(taro);SORT(hanako);
		int turn=0,np=0;
		vector<int>::iterator itr;
		while(!taro.empty()&&!hanako.empty()){
			if(turn==0){
				itr=upper_bound(ALL(taro),np);
				if(itr==taro.end()){
					np=0;
				}else{
					np=(int)*itr;
					taro.erase(itr);
				}
			}else{
				itr=upper_bound(ALL(hanako),np);
				if(itr==hanako.end()){
					np=0;
				}else{
					np=(int)*itr;
					hanako.erase(itr);
				}
			}
			turn++;
			turn%=2;
		}
		cout<<SZ(hanako)<<endl;
		cout<<SZ(taro)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
using namespace std;
int main(void){
    int N,dg[300001]={},db[300001]={},checkg=0,checkb=0;
    cin>>N;
    for(int i=0;i<N;i++){
        int a;cin>>a;a/=10;
        if(i+1<300001)dg[i+1]++;
        if(i+1+a<300001)dg[i+1+a]--;
        if(0<=i-1)db[i-1]++;
        if(0<=i-1-a)db[i-1-a]--;
    }
    for(int i=1;i<N;i++){
        dg[i]+=dg[i-1];
        db[N-1-i]+=db[N-i];
    }
    for(int i=0;i<N;i++){
        if(dg[i]==0)checkg++;
        if(db[i]==0)checkb++;
    }
    if(checkg>1 || checkb>1)cout<<"no"<<endl;
    else cout<<"yes"<<endl;
    return 0;
}



Measured memory_bytes: 5444
#include <iostream>

int main() {
  std::cin.tie(nullptr);

  int N;
  std::cin >> N;

  char s;
  std::cout << N-1 << std::endl;
  std::cin >> s;
  std::cin.ignore(16, '\n');
  if (s == 'V') return 0;

  std::cout << 0 << std::endl;
  std::cin >> s;
  std::cin.ignore(16, '\n');
  if (s == 'V') return 0;  

  int lb=0, ub=N-1;
  while (ub-lb > 1) {
    int mid=(lb+ub)>>1;
    std::cout << mid << std::endl;

    char t;
    std::cin >> t;
    std::cin.ignore(16, '\n');
    if (t == 'V') return 0;
    ((mid&1)^(s==t)? lb:ub) = mid;
  }
}

Measured memory_bytes: 852
#include <iostream>
#define int long long
using namespace std;

int n, x;

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

signed main() {
	cin >> n >> x;
	cout << 3 * (n - gcd(n, x)) << endl;
	return 0;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N, K;
    cin >> N >> K;
    if (N % K == 0) {
        print(0);
    } else {
        print(1);
    }
}

signed main() {
    solve();
}


Measured memory_bytes: 256
import scala.io.StdIn
object Main extends App {
  val List(n,k,q) = StdIn.readLine().split(" ").map(_.toInt).toList
  val A = for {
    i <- 1 to q
    a = StdIn.readLine().toInt
  } yield a
  var gainPoints = new Array[Int](n)
  for (a <- A) gainPoints(a-1) = gainPoints(a-1) + 1
  for (p <- gainPoints) println(if(k + p - q > 0) "Yes" else "No")
}


Measured memory_bytes: 46124
#include <bits/stdc++.h>
using namespace std;
#define rep(it,st,en) for(int it=(st);it<(int)(en);++it)
#define allof(c) (c).begin(), (c).end()
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define X first
#define Y second
typedef long long int ll; 
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
const int INF=(int)1e9; 
const double EPS=(ld)1e-7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,k;
    cin>>n>>m>>k;
    rep(i,0,n+1) rep(j,0,m+1){
        if(m*i + n*j - 2*i*j == k){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


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

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
//~ const int mod = (int)1e9 + 7;
const int mod = 998244353;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

string conv(int a){stringstream ss;ss << a;string str = ss.str();return str;}
string conv(char a){stringstream ss;ss << a;string str = ss.str();return str;}
int conv(string a){stringstream geek(a); int x = 0; geek >> x;   return x;}

bool year(string s){
	int y = conv(s);
	return 0<= y && y <= 99;
}

bool month(string s){
	int m = conv(s);
	return 1<= m && m <=12;
}

int main(void) 
{	
	string s; cin>> s;
	string s1 = "";
	s1+= s[0]; s1+= s[1];
	string s2 = "";
	s2+=s[2]; s2+=s[3];
	if(year(s1) && month(s2) && year(s2) && month(s1))
		cout<<"AMBIGUOUS";
	else if(year(s1) && month(s2)){
		cout<<"YYMM";
	}
	else if(year(s2) && month(s1))
		cout<<"MMYY";
	else
		cout<<"NA";
	return 0;
} 


Measured memory_bytes: 256