akhauriyash/Code-Regression huggingface dataset:
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1LL<<31)-1;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}ll a,b; string s;
struct SegmentTree {
private:
	int n;
	vector<ll> node;
public:
	SegmentTree(vector<ll> v) {
		int sz = v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1, INF); // here
		rep(i, sz) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]);
		// here
	}
	void update(int x, int val) {
		x += (n - 1);
		node[x] = val;  ///  here
		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = min(node[2 * x + 1], node[2 * x + 2]); // here
		}
	}
	ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		if (r <= a || b <= l) return INF; // here
		if (a <= l && r <= b) return node[k];
		int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr); // here
	}
};

int main() {
	int n, q; cin >> n >> q;
	SegmentTree seg(vector<ll>(n, INF));
	rep(i, q) {
		int c, x, y; cin >> c >> x >> y;
		if (c == 0) seg.update(x, y);
		else cout << seg.query(x, y + 1) << endl;
	}
}


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

int main() {
	int n, ans;
	while (cin >> n) {
		ans = 0;
		for (int a = 0; a <= 9; a++) {
			if (n < a) { continue; }
			for (int b = 0; b <= 9; b++) {
				if (n < a + b) { continue; }
				for (int c = 0; c <= 9; c++) {
					if (n < a + b + c) { continue; }
					for (int d = 0; d <= 9; d++) {
						if (n < a + b + c + d) { continue; }
						if (a + b + c + d == n) { ans++; }
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

typedef long long 			ll;
typedef unsigned long long 	ull;

const int N = 2e5 + 20;

ll a[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	ll n, k, sum = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	if (k >= n)
		return cout << 0 << endl, 0;
	sort(a, a + n);
	for (int i = 0; i < n - k; i++)
		sum += a[i];
	cout << sum << endl;
	return 0;
}


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

vector<int> pa, lch, rch;

void dfs_pre(int id) {
    std::cout << " " << id;
    if ( lch[id] != -1 ) dfs_pre(lch[id]);
    if ( rch[id] != -1 ) dfs_pre(rch[id]);
}

void dfs_in(int id) {
    if ( lch[id] != -1 ) dfs_in(lch[id]);
    std::cout << " " << id;
    if ( rch[id] != -1 ) dfs_in(rch[id]);
}

void dfs_post(int id) {
    if ( lch[id] != -1 ) dfs_post(lch[id]);
    if ( rch[id] != -1 ) dfs_post(rch[id]);
    std::cout << " " << id;
}


int main() {
    int N;
    cin >> N;
    pa.resize(N, -1);
    lch.resize(N, -1);
    rch.resize(N, -1);
    int id, l, r;
    for ( int i = 0; i < N; i++ ) {
        cin >> id >> l >> r;
        lch[id] = l;
        rch[id] = r;
        if ( l != -1 ) pa[l] = id;
        if ( r != -1 ) pa[r] = id;
    }
    
    int root = 0;
    while ( pa[root] != -1 ) root++;

    std::cout << "Preorder\n";
    dfs_pre(root);
    std::cout << "\n";

    std::cout << "Inorder\n";
    dfs_in(root);
    std::cout << "\n";

    std::cout << "Postorder\n";
    dfs_post(root);
    std::cout << "\n";

    return 0;
}


Measured memory_bytes: 3088
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll d;
    cin >> d;
    rep(i, d){
        cout << 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3576
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int K;
	cin >> K;
	vector<int> A(K);
	for (int i = 0; i < K; i++) cin >> A[i];


	auto judge1 = [&](auto x) {
		auto res = x;
		for (int i = 0; i < K; i++) {
			x -= x % A[i];
		}
		return x >= 2;
	};

	auto judge2 = [&](auto x) {
		auto res = x;
		for (int i = 0; i < K; i++) {
			x -= x % A[i];
		}
		return x == 2;
	};

	auto binary_search = [&](auto f, auto min, auto max) {

		auto ng = min;
		auto ok = max;

		while (abs(ok - ng) > 1) {
			auto mid = (ok + ng) / 2;

			if (f(mid)) ok = mid;
			else ng = mid;
		}

		return ok;
	};

	auto m = binary_search(judge1, 0LL, LINF);
	if (!judge2(m)) {
		cout << -1 << "\n";
		return 0;
	}

	cout << m << endl;
	cout << binary_search(judge2, LINF, m) << endl;

	return 0;
}

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

using namespace std;

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

  int a, b;
  cin >> a >> b;
  if ((a % 2) == 0 || (b % 2) == 0) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc= new Scanner(System.in);

        int num = 0;
        int min = 1000000;
        int max = -1000000;
        long sum = 0;

        num = sc.nextInt();

        int[] a = new int[num];

        for( int i = 0 ; i < num ; i++ ) {
            a[i] = sc.nextInt();

        	if ( a[i] <= min ) {
        		min = a[i];
        	}
        	if ( a[i] >= max ) {
        		max = a[i];
        	}
        	sum += a[i];
        }
        System.out.println( min + " " + max + " " + sum );
        sc.close();
    }
}


Measured memory_bytes: 41548
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    sort(all(s));
    s.resize(unique(all(s)) - s.begin());
    if (s.size() == 2)
        cout << "Yes";
    else
        cout << "No";
}


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

int main(){
    int w, h, x, y, r;
    
    cin >> w >> h >> x >> y >> r;
    
    if(x-r >= 0 && x+r <= w && y-r >= 0 && y+r <= h){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;   
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>

using namespace std;

enum coins{ ten = 0, fifty, hundred, five_hundred, coin_max };
const int kcoin[coin_max] = {10,50,100,500};

int M;
int min_nums;
int ans_nums[coin_max];
int nums[coin_max];
int tans_nums[coin_max];

int minimumExchange(int m, int *nums)
{
	int t = 0;
	int ans = 0;

	for(int i = five_hundred; i >= ten; --i){
		t = m / kcoin[i];
		m -= kcoin[i] * t;
		nums[i] = t;
		ans += t;
	}

	return ans;
}

void solve(){
	for(int a = 0; a <= nums[ten]; ++a){
		for(int b = 0; b <= nums[fifty]; ++b){
			for(int c = 0; c <= nums[hundred]; ++c){
				for(int d = 0; d <= nums[five_hundred]; ++d){
					int m = a * kcoin[ten] +
						b * kcoin[fifty] +
						c * kcoin[hundred] +
						d * kcoin[five_hundred];

					if( m >= M ){
						int t = 0;
						int exchanges[coin_max];
						
						nums[0] -= a; nums[1] -= b; nums[2] -= c; nums[3] -= d;
						tans_nums[0] += a; tans_nums[1] += b; tans_nums[2] += c; tans_nums[3] += d;
						
						minimumExchange( m - M, exchanges );
						
						for(int i = 0; i < coin_max; ++i){
							t += nums[i] + exchanges[i];
						}
						
						if( min_nums > t ){
							min_nums = t;
							for(int i = 0; i < coin_max; ++i){
								ans_nums[i] = tans_nums[i];
							}
						}
						
						tans_nums[0] -= a; tans_nums[1] -= b; tans_nums[2] -= c; tans_nums[3] -= d;
						nums[0] += a; nums[1] += b; nums[2] += c; nums[3] += d;
					}
				}
			}
		}
	}
}

int main(){
	bool bFirstDataSet = true;

	while(true){
		scanf("%d", &M);
		if(M==0)break;

		for(int i = 0; i < coin_max; ++i){
			tans_nums[i] = ans_nums[i] = nums[i] = 0;
		}

		for(int i = 0; i < coin_max; ++i){
			scanf("%d", nums+i);
		}
		
		if( !bFirstDataSet ){
			printf("\n");	
		}
		bFirstDataSet = false;
		
		min_nums = 100;
		solve();

		for(int i = 0; i < 4; ++i){
			if( ans_nums[i] ){
				printf("%d %d\n", kcoin[i], ans_nums[i]);
			}
		}
	}

	return 0;
}

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

const int MAX_R = 128;
const int MAX_C = 16+1;
const int BIT = 1<<MAX_C;

int r, c;
string s[MAX_R];
int dp[2][BIT];

int main() {
  while(1) {
    if(cin >> r >> c) ; else break;
    for(int i = 0; i < r; ++i) cin >> s[i];

    int p = 0;

    fill(dp[0], dp[2], -1);
    for(int k = 0; k < (1<<c); ++k) {
      if(__builtin_popcount(k) != s[0].size()) continue;
      string tmp = "";
      for(int i = 0, a = 0; i < c; ++i) {
        if(k&(1<<i)) tmp += s[0][a++];
        else tmp += '.';
      }
      dp[p][k] = 0;
      for(int i = 1; i < tmp.size(); ++i) {
        if(tmp[i] != '.' && tmp[i-1] == tmp[i]) {
          dp[p][k] += 2;
        }
      }
    }

    for(int i = 1; i < r; ++i) {
      for(int j = 0; j < c; ++j) {
        int q = 1-p;
        for(int k = 0; k < (1<<c); ++k) dp[q][k] = -1;
        for(int k = 0; k < (1<<c); ++k) {
          if(dp[p][k] == -1) continue;
          int Lu = c - j;
          char u, l;
          int use;
          u = l = '.';
          for(int t = Lu-1, a = (int)s[i-1].size()-1; t >= 0; --t) {
            if(k&(1<<t)) u = s[i-1][a--];
            else u = '.';
          }
          use = 0;
          for(int t = Lu; t < c; ++t) {
            if(k&(1<<t)) l = s[i][use++];
            else l = '.';
          }

          if(use + (c-j) < s[i].size()) continue;

          // space
          {
            int nk = k/2;
            if(j+1 == c && __builtin_popcount(nk) != s[i].size()); else {
              dp[q][nk] = max(dp[q][nk], dp[p][k]);
            }
          }

          // char
          if(use < s[i].size()) {
            int nk = k/2 + (1<<(c-1));
            int add = 0;
            add += (s[i][use] == u) * 2;
            add += (s[i][use] == l) * 2;
            if(j+1 == c && __builtin_popcount(nk) != s[i].size()); else {
              dp[q][nk] = max(dp[q][nk], dp[p][k] + add);
            }
          }
        }
        p = q;
      }
    }

    int res = 0;
    for(int k = 0; k < (1<<c); ++k) {
      res = max(res, dp[p][k]);
    }
    cout << res << endl;
  }
  return 0;
}

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

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

    int two[3] = {0,0,0};
    for (int i=0; i<N; i++) {
        if (A[i] % 4 == 0) {
            two[2]++;
        } else if (A[i] % 2 == 0) {
            two[1]++;
        } else {
            two[0]++;
        }
    }

    if (two[2] >= two[0]) {
        cout << "Yes" << endl;
    } else if (two[2]+1 == two[0] && two[1] == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

int cnts[10] = {
    0,
    2,5,5,
    4,5,6,
    3,7,6
};

#define DP_MAX 36 // 10**18

int asc(const void *a1, const void *a2) { return *(int*)a1 - *(int*)a2; }

int main(void) {
    int num, kinds;
    get_int2(&num, &kinds);
    int arr[10];
    fget_array(arr, kinds);
    qsort(arr, kinds, sizeof(int), asc);
    int i, j;
    int consume = 10;
    int cdigit;
    for(i = kinds-1; i >= 0; i--) {
        int digit = arr[i];
        if(consume > cnts[digit]) {
            consume = cnts[digit];
            cdigit = digit;
        }
    }

    static int64_t dp[DP_MAX+1];
    for(i = 0; i <=DP_MAX; i++) dp[i] = -1;
    dp[0] = 0;
    for(i = kinds-1; i >= 0; i--) {
        int digit = arr[i];
        int cnt = cnts[digit];
        for(j = 0; j <= DP_MAX; j++) {
            if(j >= cnt) dp[j] = max(dp[j], dp[j-cnt]*10 + digit);
        }
    }
#ifdef DEBUG
    for(i = 0; i <= DP_MAX; i++) printf("%d -> %lld\n", i, dp[i]);
#endif
    

    // # of counts of digits
    static int cnt_map[10];
    int base_digit = cdigit;
    while(num > DP_MAX) {
        num -= consume;
        cnt_map[base_digit]++;
    }
    int64_t rem = dp[num];
    while(rem) {
        cnt_map[rem%10]++;
        rem /= 10;
    }

    // presentation
    for(i = 9; i >= 1; i--) {
        while(cnt_map[i]) {
            putchar('0' + i);
            cnt_map[i]--;
        }
    }
    putchar('\n');
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define V vector
#define SI size()
#define pb push_back
#define mk make_pair
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Test int test;cin>>test;while(test--)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
using namespace std;
const int mod = 1e9+7;
int main() {
    Fast
    int a=0,w=0,t=0,r=0;
    int n;
    cin>>n;
    V<string> v;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(s == "AC"){
            a++;
        }
        else if(s == "TLE"){
            t++;
        }
        else if(s == "WA"){
            w++;
        }
        else if(s == "RE"){
            r++;
        }
    }
    cout<<"AC x "<<a<<endl<<"WA x "<<w<<endl<<"TLE x "<<t<<endl<<"RE x "<<r;
}


Measured memory_bytes: 3656
import bisect
from collections import deque

h, w, m = map(int, input().split())
l = 3 * pow(10, 5) + 5
cnt1, cnt2 = [[0, i] for i in range(l)], [[0, i] for i in range(l)]
d = {}
for _ in range(m):
    x, y = map(int, input().split())
    i = x + y * 1000000
    d[i] = 1
    cnt1[x][0] += 1
    cnt2[y][0] += 1
cnt1.sort(reverse = True)
cnt2.sort(reverse = True)
ans = cnt1[0][0] + cnt2[0][0] - 1
for i in range(l):
    if not cnt1[i][0] == cnt1[0][0]:
        break
    for j in range(l):
        if not cnt2[j][0] == cnt2[0][0]:
            break
        if not ((cnt1[i][1]) + (cnt2[j][1]) * 1000000) in d:
            print(ans + 1)
            exit()
print(ans)

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

int main () {
  int a, b, c;
  cin >> a >> b >> c;
  int M = max(a, max(b, c));
  int sum = a + b + c;
  int ans = 0;

  if ((3 * M % 2) == (sum % 2)) {
    ans = (3 * M -sum) / 2;
  }
  else {
    ans = (3 * (M+1) - sum) / 2;
  }
  cout << ans << endl;
}


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

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

	int ans;
	while (true) {
		bool flag = true;
		for (int i = 2; i <= x / 2; i++) {
			if (x % i == 0) {
				flag = false;
			}
		}
		if (flag == true) {
			ans = x;
			break;
		} else {
			x++;
		}
	}

	cout << ans << endl;
}


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

int main(){
	int a,
		b;
	char suuti[3][20],
		 *edp,
		 c;
	long l[3];
	for(a = 0;a < 3;a++){

		for(b = 0; b < 19 && (c = getchar()) != ' ' && c != '\n';b++ ){
			suuti[a][b] = c;
		}suuti[a][b] = 0;

		l[a] = strtol(suuti[a],&edp,10);
		if(*edp != '\0'){
			exit(0);
		}
	}suuti[a][b] = 0;

	if(l[0] < l[1] && l[0] < l[2]){
		if(l[1] < l[2]){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}else{
		printf("No\n");
	}
	return 0;	

}

Measured memory_bytes: 524
#include<stdio.h>
#include<string.h>

int main(void)
{
  int i,a;
  char ch,al[26];

  for(i=0;i<26;i++)
    al[i]=0;

  for(i=0;i<1200;i++)
    {
      scanf("%c",&ch);
      
      if(('A'<=ch)&&(ch<='Z'))
	ch=ch-'A'+'a';
      
      a=ch-'a';
      al[a]+=1;
    }
  for(i=0;i<26;i++)
    {
      printf("%c : %d\n",'a'+i,al[i]);	
    }
}



Measured memory_bytes: 2080
import sys
from fractions import gcd
import bisect
 
stdin = sys.stdin
 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

x, a, b = [ni() for _ in range(3)]

print((x - a) % b)

Measured memory_bytes: 5076
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;

using namespace std;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 998244353;

template <typename T>
void read(vector<T>& a) {
    for (auto &v : a)
        cin >> v;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie();
    int n, k;
    cin >> n >> k;
    cout << (n >= 10 ? k : k + 100*(10-n));
}

Measured memory_bytes: 256
#ABC178 D
from scipy.special import comb
s = int(input())
mod = 1000000007
if s < 3:
  print(0)
else:
  q = s // 3
  count = 0
  for i in range(1, q+1):
    m = s - (3 * i)
    base = comb(m + (i-1), i-1, exact=True)
    count += base
    # print(i, m, count)
  print(count % mod)

Measured memory_bytes: 42424
H, W = map(int, input().split())
a = []
for i in range(H):
    a.append(list(map(int, input().split())))
count = 0
result = []
for i in range(H):
    j = 0
    while j < W:
        if a[i][j] % 2 != 0:
            s = j
            j += 1
            while j < W:
                if a[i][j] % 2 != 0 or j == W - 1:
                    a[i][s] -= 1
                    a[i][j] += 1
                    for k in range(s, j):
                        count += 1
                        result.append(((i, k), (i, k + 1)))
                    break
                j += 1
        j += 1

i = 0
while i < H:
    if a[i][-1] % 2 != 0:
        s = i
        i += 1
        while i < H:
            if a[i][-1] % 2 != 0 or i == H - 1:
                for k in range(s, i):
                    count += 1
                    result.append(((k, W - 1), (k + 1, W - 1)))
                break
            i += 1
    i += 1


print(count)
for e in result:
    print(e[0][0] + 1, e[0][1] + 1, e[1][0] + 1, e[1][1] + 1)


Measured memory_bytes: 37976
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii>tri;

const int N=1e5+5;
string ans[N];

string go(int num){
	string s;
	while(num)s.pb((num%10+'0')),num/=10;
	while(sz(s)<6)s.pb('0');
	reverse(all(s));
	return s;
}

int main(){	
	fastio;
	int n,m;cin>>n>>m;
	vector<tri>vec;
	FER(i,0,m){
		int p,k;cin>>p>>k;
		vec.pb({k,{p,i}});
	}
	sort(all(vec));
	map<int,int>M;
	for(tri lel:vec){
		//cout<<"lel"<<endl;
		//cout<<lel.tm1<<" "<<lel.tm2<<" "<<lel.tm3<<endl;
		int val=++M[lel.tm2];
		string s=go(lel.tm2);
		s+=go(val);
		ans[lel.tm3]=s;
	}
	FER(i,0,m)cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 14452
if __name__ == "__main__":
    A = input()
    B = input()
    if (len(A) > len(B)):
        print ("GREATER")
    if (len(A) < len(B)):
        print ("LESS")
    if (len(A) == len(B)):
        if (A == B):
            print ("EQUAL")
        for x,y in zip(A, B):
            x = int(x)
            y = int(y)
            if (x > y):
                print ("GREATER")
                break
            if (x < y):
                print ("LESS")
                break


Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc139/tasks/abc139_c
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#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 - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    int val = 0, cnt = -1, cmax = 0;
    REPR(i, n) {
        if (val <= v[i]) {
            val = v[i];
            cnt++;
        } else {
            cmax = max(cmax, cnt);
            val = v[i];
            cnt = 0;
        }
    }
    cmax = max(cmax, cnt);
    cout << cmax << endl;

    return 0;
}


Measured memory_bytes: 640
/******
author :- Mahmoud Tarek.
*******/

#include<bits/stdc++.h>

using namespace std ;

#define rg register
#define dbg(v) cerr << #v << " " << v ;
typedef long long ll ;

int n, k;
vector<int> a ;
int mx = 0 ;
int mem[100002] ;

int solve(int i){
if(i + 1 == n) return 0 ;
int & ret = mem[i];
if(~ret) return ret ;
ret = mx ;
for(int j = 1 ; j <= k ; j++){
    if(i + j < n){
        ret = min(ret, abs(a[i] - a[i + j]) + solve(i + j)) ;
    }
}
return ret ;
}

int main() {
//    freopen("in.txt", "r", stdin) ;
     cin >> n >> k ;
     a.resize(n) ;

     for(int i = 0 ; i < n ; i++){
        cin >> a[i] ;
        if(i >= 1){
            mx += abs(a[i] - a[i - 1]) ;
        }
     }

     if(mx == 0) mx = a[0] ;


     memset(mem, -1, sizeof mem) ;

     cout << solve(0);
}

/*
  Empty set of troubles.
*/


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n;
V vi;

int main(){
	while (cin >> n){
		for (int i = 9; i >= 0; i--){
			if (n >= pow(2, i)){
				n -= pow(2, i);
				vi.push_back(pow(2, i));
				if (n == 0)break;
			}
		}
		sort(ALL(vi));
		REP(i, vi.size()){
			cout << vi[i];
			if (i == vi.size() - 1)cout << endl;
			else cout << " ";
		}
		vi.clear();
	}
}

Measured memory_bytes: 1252
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
mask = n2 - 1

dp = [[a, 0] for a in aaa]


def update(dpi, dpk):
    if dpk[0] < dpi[0]:
        dpk[1] = max(dpk[0], dpi[1])
        dpk[0] = dpi[0]
    elif dpk[1] < dpi[0]:
        dpk[1] = dpi[0]


for j in range(n):
    b = 1 << j
    c = i = mask ^ b
    while i:
        update(dp[i], dp[i | b])
        i = (i - 1) & c
    update(dp[0], dp[b])

ans = list(accumulate(map(sum, dp[1:]), func=max))
print(*ans)


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  double L; cin >> L;
  double d = (L / 3) * (L / 3) * (L / 3);
  cout << std::fixed << std::setprecision(15) << d << endl;
}


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

using namespace std;

int main() {
	long long a,b,c,d;
	cin >> a >> b >> c >> d;
	
	long long p1 = a*c,p2 = a*d,p3 = b*c,p4 = b*d;
	
	cout << max(p1, max(p2, max(p3, p4)));
	return 0;
}

Measured memory_bytes: 3392
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
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;
}
ll gcd(ll x,ll y){
    if(x<y) swap(x,y);
    //xの方が常に大きい
    ll r;
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}
int main(){
    int cnt=0;
    bool flag=false;
    int N;cin>>N;
    rep(i,N){
        int a,b;
        cin>>a>>b;
        if(a==b){
            cnt++;
        }
        else{
            cnt=0;
        }
        if(cnt==3){
            flag=true;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3632
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}


fn solve(i: usize, s: usize, n: usize, g: &Vec<Vec<usize>>) -> i64 {
    if s == (1<<n)-1 { return 1; }
    let mut r = 0;
    for &j in g[i].iter() {
        if (s & (1<<j)) != 0 { continue; }
        r += solve(j, s | (1<<j), n, g);
    }
    return r;
}

fn main() {
    let (n, m) = get!(usize, usize);
    let mut g = vec![Vec::new(); n];
    for _ in 0..m {
        let (a, b) = get!(usize, usize);
        g[a-1].push(b-1);
        g[b-1].push(a-1);
    }
    let r = solve(0, 1, n, &g);
    println!("{}", r);
}

Measured memory_bytes: 4352
#include <stdio.h>

int main(void){
  char m[8][8];
  char a;
  int i,j;
  a='1';
  while((scanf("%s",&*m[0]))!=EOF){

    for(i=1;i<8;i++){
      scanf("%s",&*m[i]);
    }

    for(i=0;i<8;i++){
      for(j=0;j<8;j++){
	if(m[i][j]==a){
	  if(m[i][j+1]==a&&j+1<8){   //A,C,E,G
	    if(m[i+1][j]==a&&i+1<8){
	      if(m[i+1][j+1]==a){
		printf("A\n");
		break;
	      }else if(m[i+1][j-1]==a&&j>0){
		printf("G\n");
		break;
	      }
	    }else if(m[i][j+2]==a&&m[i][j+3]==a&&j+2<8&&j+3<8){
	      printf("C\n");
	      break;
	    }else if(m[i+1][j+1]==a&&m[i+1][j+2]==a&&i+1<8&&j+1<8&&j+2<8){
	      printf("E\n");
	      break;
	    }
	  }else if(m[i+1][j]==a&&i+1<8){  //B,D,F
	    if(m[i+2][j]==a&&m[i+3][j]==a&&i+2<8&&i+3<8){
	      printf("B\n");
	      break;
	    }else if(m[i+1][j-1]==a&&m[i+2][j-1]==a&&j>0&&i+2<8){
	      printf("D\n");
	      break;
	    }else if(m[i+1][j+1]==a&&m[i+2][j+1]==a&&j+1<8&&i+2<8){
	      printf("F\n");
	      break;
	    }
	  }
	}
      }
    }
    /*
    for(i=0;i<8;i++){
      printf("//");
      for(j=0;j<8;j++){
	printf("%c",m[i][j]);
      }
      printf("\n");
    }
    */
  }
  return 0;
}

Measured memory_bytes: 524
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var L = one[0];
	var R = one[1];
	if(R - L >= 2019){
		myout(0);
		return;
	}
	
	L %= 2019;
	R %= 2019;
	if(L >= R){
		myout(0);
		return;
	}
	var min = 2019;
	for(var i = L; i <= R - 1; i++){
		for(var j = i + 1; j <= R; j++){
			min = Math.min(min, i * j % 2019);
		}
	}
	myout(min);
}


Measured memory_bytes: 32892
n = input()
code = raw_input().split()
# DP(N, <parentheses nested>)
a = int(code[0]); b = c = -10**18
for op, v in zip(code[1::2], map(int,code[2::2])):
    if op is "+":
        d = max(b-v, c+v)
        a,b,c = max(a+v, d), d, c+v
    else:
        d = max(b+v, c-v)
        a,b,c = max(a-v, d), max(a-v, d), d
print max(a, b, c)

Measured memory_bytes: 20724
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,mp;
	cin>>n>>mp;
	vector<ar<ll,2>> v[n+1];
	for(int i = 0,j,k,l; i<mp; i++)
	{
		cin>>j>>k>>l;
		v[j].pb({k,l});
		v[k].pb({j,-l});
	}
	int flag = 0;
	bool vis[n+1] = {0};
	ll dist[n+1] = {0};
	for(int i = 1; i<=n; i++)
	{
		if(!int(v[i].size()) || vis[i]) continue;
		queue<ar<ll,2>> q;
		q.push({i,0});
		vis[i] = 1;
		while(!q.empty())
		{
			auto y = q.front();
			q.pop();
			for(auto it:v[y[0]])
			{
				if(!vis[it[0]])
				{
					vis[it[0]] = 1;
					dist[it[0]] = it[1]+y[1];
					q.push({it[0],dist[it[0]]});
				}
				else if(dist[it[0]]!=dist[y[0]]+it[1]) flag = 1;
			}
		}
	}
	if(flag) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 14576
local s = io.read()
local n = #s
local found = false
for i = 1, n - 1 do
  local s1 = s:sub(i, i)
  if s1 == s:sub(i + 1, i + 1) then
    print(i .. " " .. i + 1)
    found = true
    break
  elseif i <= n - 2 and s1 == s:sub(i + 2, i + 2) then
    print(i .. " " .. i + 2)
    found = true
    break
  end
end
if not found then print("-1 -1") end



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int q,a,b,c,d;
    string s,t;
    cin>>s>>t>>q;
    vec S(s.size()+1,0),T(t.size()+1,0);
    rep(i,s.size()) S[i+1]=S[i]+(s[i]=='A');
    rep(i,t.size()) T[i+1]=T[i]+(t[i]=='A');
    rep(i,q){
        cin>>a>>b>>c>>d;
        if(((S[b]-S[a-1])*2+a-b%3+2)%3==((T[d]-T[c-1])*2+c-d%3+2)%3) cout<<"YES\n";
        else cout<<"NO\n";
    }
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(void)
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  ll n;
  string s;
  cin>>n>>s;
  cout<<(n>=3200?s:"red")<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int a,b,c,d,e,k;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;
    if (e-a <= k){
        cout << "Yay!" << endl;
    }
    else{
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    s = S()
    t = S()
    ans = 0

    for i in range(len(s)):
        if s[i] != t[i]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 75352
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int P[] = new int[N];
		int A[] = new int[N + 1];
		for(int i = 0 ; i < N ; ++i) {
			P[i] = sc.nextInt();
			A[P[i]] = i + 1;
		}
		TreeSet<Integer> phigh = new TreeSet<>();
		phigh.add(0);
		phigh.add(N + 1);
		phigh.add(A[N]);
		long S = 0;
		//X [i,j]  = P => [i,j] P未満かつP以上が一つ
		for(int n = N - 1; n >= 1 ; --n) {
			int Xi = A[n];
			long y = phigh.higher(Xi);
			long z = N + 1;
			if(y < N + 1) {
				z = phigh.higher((int)y);				
			}
			long x = phigh.lower(Xi);
			long w = 0;
			if(x != 0) {
				w = phigh.lower((int)x);				
			}
			long C = (x - w) * (y - Xi) + (Xi - x) * (z - y);
			S += C * n;
			phigh.add(Xi);
		}
		System.out.println(S);
	}
}


Measured memory_bytes: 60596
(function(input) {
  var p = input.replace(/\n$/, '').split('\n').map(Number);
  var s = - Infinity;
  var m = - Infinity;
  while (true) {
    var n = p.shift();
    if (n === 0) {
      break;
    }
    s = - Infinity;
    m = - Infinity;
    for (var i = 0; i < n; i++) {
      var a = p.shift();
      if (a > s + a) {
        s = a;
      } else {
        s = s + a;
      }
      if (s > m) {
        m = s;
      }
    }
    console.log(m);
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7640
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define NIL -1
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

const double PI=(acos(-1));

int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    int sum=0,mm=0; 
    rep(i,n){
        cin>>p[i];
        mm=max(mm,p[i]);
        sum+=p[i];
    }
    cout<<sum-mm/2<<endl;
}


Measured memory_bytes: 3604
#include<stdio.h>

int main(){
  int a,b,c,d;
  while(scanf("%d%d",&a,&b)!=EOF){
	d=0;
	c=a+b;
	while(c>=1){
		c=c/10;
		d++;}
	printf("%d\n",d);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include <ios>
#include <iomanip>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef tuple<ll,ll,ll> Tl;


int atcoder(){
    //入力
    string sa,sb,sc;
    cin >> sa >> sb >> sc;
    string ans = "";
    string next="a";
    
    while(ans==""){
        if(next=="a"){
            if(sa=="") ans += "A";
            else{
                next = sa[0];
                sa.erase(sa.begin());
            }
        }
        else if(next=="b"){
            if(sb=="") ans += "B";
            else{
                next = sb[0];
                sb.erase(sb.begin());
            }
        }
        else if(next=="c"){
            if(sc=="") ans += "C";
            else{
                next = sc[0];
                sc.erase(sc.begin());
            }
        }
    }


    cout << ans << ENT;
    
    return 0;
}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 200000000
#define INF 2000000000
  
int size;
int h[N];
  
void swap(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}
  
void maxHeapify(i){
  int l = 2*i;
  int r = 2*i+1;
  int valM;
  if(l <= size && h[l] > h[i]) valM = l;
  else valM = i;
  if(r <= size && h[r] > h[valM]) valM = r;
  if(valM != i){
    swap(&h[i], &h[valM]);
    maxHeapify(valM);
  }
}
  
void hIncreaseKey(int i, int key){
  if(key < h[i]) return;
  h[i] = key;
  while(i>1 && h[i/2]<h[i]){
    swap(&h[i], &h[i/2]);
    i = i/2;
  }
}
  
void maxHeapInsert(int key){
  size++;
  h[size] = -INF;
  hIncreaseKey(size, key);
}
  
int heapExtractMax(){
  int valM;
  if(size < 1) return 0;
  valM = h[1];
  h[1] = h[size--];
  maxHeapify(1);
  return valM;
}
  
int main(){
  char input[20];
  size = 0;
  while(scanf("%s", input)){
    if(!strcmp(input, "end")) break;
    if(!strcmp(input, "extract")) printf("%d\n", heapExtractMax());
    else{
      char val[20];
      scanf("%s", val);
      maxHeapInsert(atoi(val));
    }
  }
  return 0;
}

Measured memory_bytes: 4632
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> lP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n, p;
    cin >> n >> p;
    vector<int> a;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}

    vector<lP> dp(n, {0, 0});
    if (a[0]%2==0){
        dp[0].first+=2;
    } else {
        dp[0].first++;
        dp[0].second++;
    }

    rep1(i, n-1){
        if (a[i]%2==0){
            dp[i].first = dp[i-1].first*2; 
            dp[i].second = dp[i-1].second*2;
        } else {
            dp[i].first = dp[i-1].first + dp[i-1].second; 
            dp[i].second = dp[i-1].first + dp[i-1].second;
        }
    }
    if (p==0) cout << dp[n-1].first << endl;
    else cout << dp[n-1].second << endl;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n;
    while(cin>>n){
        int sum=0;
        int m=n;
        while(n){
            sum+=n%10;
            n/=10;
        }
        if(m%sum==0){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    return 0;
}


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

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
const int maxn = 2e5+100;

const ll inf = 1e18;
int mask[maxn][50][2];
int raw[50][2];

int main()
{
    ll n , k;
    cin >> n >> k;
    for(int i = 1; i<=n; i++){
        ll p; cin >> p;
        for(int j = 0; j<50; j++){
            ll bit = (p & (1ll << j)) > 0 ? 1 : 0;
            mask[i][j][bit]++;
        }
    }
    for(int i = 1; i<=n; i++){
        for(int j = 0; j<50; j++){
            raw[j][0]+=mask[i][j][0];
            raw[j][1]+=mask[i][j][1];
        }
    }
    ll K = 0 , ans = 0;
    for(ll i = 50; i>=0; i--){
        ll one = raw[i][1];
        ll zero = raw[i][0];
        if(one > zero){
            ans += (1ll << i) * one;
        }
        else if(((1ll << i)+K)<=k){
            K += (1ll << i);
            ans += (1ll<<i) * zero;
        }
        else{
            ans += (1ll << i) * one;
        }
    }
    cout << ans << endl;



}



Measured memory_bytes: 41216
#include <stdio.h>

#define SENTINEL 2000000000 
#define MAX 500000
int L[MAX],R[MAX];
int count=0;
void Merge(int A[],int n,int left,int mid,int right);
void MergeSort(int A[],int n,int left,int right);

int main(void){

	int i,n;	
	int A[MAX];	
	scanf("%d",&n);
	for(i=0;i<n;i++){ scanf("%d",&A[i]); }
	MergeSort(A,n,0,n);
	for(i=0;i<n;i++){
		if(i){ printf(" "); }
		printf("%d",A[i]);
	}
	
	printf("\n%d\n",count);

	

return 0;
}


void Merge(int A[],int n,int left,int mid,int right){

	int i,j,k,n1,n2;

	n1 = mid - left;
	n2 = right - mid;
	
	for(i=0;i<n1;i++){ L[i] = A[left+i]; } 
	for(i=0;i<n2;i++){ R[i] = A[mid+i]; }
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;
	i = j = 0;
	for(k=left;k<right;k++){
		count++;
		if(L[i] <= R[j]){ 
			A[k] = L[i];
		    i++; 
		}else{
			A[k] = R[j];
			j++;
		}
	}
	
}

void MergeSort(int A[],int n,int left,int right){
    int mid;	
	if(left+1 < right){
		mid = (left + right)/2;
		MergeSort(A,n,left,mid);
		MergeSort(A,n,mid,right);
		Merge(A,n,left,mid,right);
	}
}



Measured memory_bytes: 5692
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <bitset>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define rrep(i,a,b) for(ll i=a-1;i>=(ll)(b);i--)

#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

#define popcount __builtin_popcount
#define LIST(a) memset(a, 0, sizeof(a))


int main(void){
    ll n, k;
    cin >> n >> k;
    vector<int> h(n), memo(n);
    rep(i, 0, n){
        cin >> h[i];
    }
    memo[0] = 0;
    rep(i, 1, n){
        ll minv = memo[i-1] + abs(h[i] - h[i - 1]);
        //cout << memo[i - 1] << ':' << minv << endl;
        rep(j, 1, min(k+1, i+1)){
            minv = min(minv, (memo[i - j] + ll(abs(h[i] - h[i - j]))));
        }
        memo[i] = minv;
        //cout << minv << endl;
    }
    cout << memo[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;


public class Main {

    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int sum = 0;
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for(int i=1;i<=n;i++){
            map.put(i, 0);
        }
        for(int i=0;i<k;i++){
            int d = sc.nextInt();
            for(int j=0;j<d;j++){
                int a = sc.nextInt();
                map.put(a, 1);
            }
        }
        sc.close();
        for(int ans : map.values()){
            if(ans == 0){
                sum++;
            }
        }
        System.out.println(sum); 
    }
}

Measured memory_bytes: 46156
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  int ans = 100000;
  for(int i = 1000; i <= 10000; i = i + 1000) {
    int tmp = i - N;
    if(ans > tmp && tmp >= 0) ans = tmp;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632