akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int num[] = {1, 2, 1, 2, 1, 4, 1, 4};

    for(;;){
        vector<int> p(8);
        for(int i=0; i<8; ++i){
            if(!(cin >> p[i]))
                return 0;
        }

        int maxNum = -1;
        int v;
        int k;
        for(int i=0; i<8; ++i){
            int tmp = 0;
            int v0 = 0;
            for(int j=0; j<8; ++j){
                tmp += min(num[(i+j)%8], p[j]);
                v0 *= 10;
                v0 += num[(i+j)%8];
            }
            if(tmp > maxNum || tmp == maxNum && v0 < v){
                maxNum = tmp;
                v = v0;
                k = i;
            }
        }

        cout << num[k];
        for(int i=1; i<8; ++i)
            cout << ' ' << num[(i+k)%8];
        cout << endl;
    }
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M);
    vector<int> b(M);
    vector<int> city(N);
    vector<int> cityCount(N, 0);
    
    for (int i = 0; i < N; i++) {
        city.at(i) = i + 1;
    }
    
    for (int j = 0; j < M; j++) {
        
        cin >> a.at(j) >> b.at(j);
        
        for (int k = 0; k < N; k++) {
            
            if (a.at(j) == city.at(k)) {
                cityCount.at(k)++;
            }
            
            if (b.at(j) == city.at(k)) {
                cityCount.at(k)++;
            }
            
        }
        
    }
    for (int l = 0; l < N; l++) {
        cout << cityCount.at(l) << endl;
    }
    
}


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

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

	if(a.at(0)==b.at(2) && a.at(1)==b.at(1) && a.at(2)==b.at(0)) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

int main()
{
    string s1, s2;
    cin>>s1>>s2;



    if(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0])
        cout<<"YES";
    else
        cout<<"NO";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>

using namespace std;

void insertionSort(vector<int> A, int n)
{
	for (int i = 0; i < n; i++)
	{
		int v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > v)
		{
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;

		ostringstream oss;
		for (int k = 0; k < n; k++)
		{
			if (k == n - 1)
			{
				oss << A[k];
			}
			else
			{
				oss << A[k] << " ";
			}
		}
		cout << oss.str() << endl;
	}
}

int main()
{
	int N;
	cin >> N;
	cin.ignore();

	string A;
	getline(cin, A);

	vector<int> va;

	istringstream iss(A);
	while (!iss.eof())
	{
		int t;
		iss >> t;
		va.push_back(t);
	}

	insertionSort(va, N);

	return 0;
}

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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> a(N);

  for( int i=0; i<N; i++ ){
  	cin >> a.at(i);
  }
  
  int swapcnt=0;
  for(int i=0; i<N; i++){
  	if( a.at(i)!=i+1 ){
    	if( a.at(a.at(i)-1)==i+1 ){ swapcnt++; }
        else{
        	cout << "NO" << endl;
            exit(0);
        }
    }
  }
  
  if( swapcnt==0 || swapcnt==2 ){
  	cout << "YES" << endl;
  }else{
  	cout << "NO" << endl;
  }
  
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <cstdio>
#include<algorithm>
#include <utility>
#define SIZE 1001;
using namespace std;
int main() {
	long long ans, x, y, memox, memoy;
	while (cin >> x >> y) {
		memox = x; memoy = y;
		if (y > x) {
			swap(x, y);
		}
		while (1) {
			if (y == 0) {
				break;
			}
			x %= y;
			swap(x, y);
		}
		ans = (memox*memoy)/x;
		cout << x << " " << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
 using namespace std;
 
int main() {
  int a,b,c,d;
  
  cin >> a >> b >> c;

  if (a > b){
    d = b;
    b = a;
    a = d; 
  }
  if (b > c){
    d = c;
    c = b;
    b = d; 
  }
  if (a > b){
    d = b;
    b = a;
    a = d;     
  } 

  cout << a << " " << b << " " << c << endl;

  return 0;
}



Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
    int N;
    cin >> N;
    if(N == 1)
    {
        cout << "Hello World" << endl;
    }
    else
    {
        int a,b;
        cin >> a >> b;
        cout << (a + b) << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#define int long long
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<int, int>;
ll mod = 1000000007;
ll MOD = 998244353;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x) % mod, n / 2) % mod);
	else
		return (x * pow(x, n - 1)) % mod;
}
signed main() {
	int l, r; cin >> l >> r;
	int k = (l + 1) / 2019;
	int m = (r + 1) / 2019;
	if (m > k)cout << 0 << endl;
	else {
		l %= 2019;
		r %= 2019;
		int ans = 2019;
		for (int i = l; i <= r; i++) {
			for (int j =i+1; j <= r; j++) {
				ans = min(ans,j*i%2019 );

			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>
int main(){
  double a,b,c,C,S,L,h,rad;
  scanf("%lf %lf %lf",&a,&b,&C);
  rad=M_PI*C/180.0;
  S=(1.0/2.0)*a*b*sin(rad);
  c=sqrt(a*a+b*b-2*a*b*cos(rad));
  L=a+b+c;
  h=2.0*S/a;
  printf("%f\n",S);
  printf("%f\n",L);
  printf("%f\n",h);
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> pint;
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,v.size()) {cin >> v[i];}
//最終奥義
#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());
signed main(void){
  int n,m;cin >> n >> m;
  priority_queue<int> q;
  rep(i,n){
    int t;cin >> t;
    q.push(t);
  }
  rep(i,m){
    int max=q.top();
    q.pop();
    q.push(max/2);
  }
  int ans=0;
  while(!q.empty()){
    ans+=q.top();
    q.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

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

    if(S=="MON"){
        cout << 6 << endl;
    }else if(S=="TUE"){
        cout << 5 << endl;
    }else if(S=="WED"){
        cout << 4 << endl;
    }else if(S=="THU"){
        cout << 3 << endl;
    }else if(S=="FRI"){
        cout << 2 << endl;
    }else if(S=="SAT"){
        cout << 1 << endl;
    }else if(S=="SUN"){
        cout << 7 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 205;

int n;
char s[N][N];
int b[N][N];
int co[N], d[N], d0, dis[N];

int main() {
	scanf("%d", &n);
	fo(i, 1, n) {
		scanf("%s", s[i] + 1);
		fo(j, 1, n) if(s[i][j] == '1')
			b[i][j] = b[j][i] = 1;
	}
	fo(i, 1, n) co[i] = -1;
	co[1] = 0; d[d0 = 1] = 1;
	for(int i = 1; i <= d0; i ++) {
		int x = d[i];
		fo(j, 1, n) if(b[x][j]) {
			if(co[j] != -1 && co[j] == co[x]) {
				pp("-1\n");
				return 0;
			}
			if(co[j] == -1) {
				co[j] = !co[x];
				d[++ d0] = j;
			}
		}
	}
	int ans = 0;
	fo(st, 1, n) {
		fo(i, 1, n) co[i] = 0;
		co[st] = 1, d[d0 = 1] = st; dis[st] = 1;
		for(int i = 1; i <= d0; i ++) {
			int x = d[i];
			ans = max(ans, dis[x]);
			fo(j, 1, n) if(b[x][j]) {
				if(!co[j]) co[j] = 1, d[++ d0] = j, dis[j] = dis[x] + 1;
			}
		}
	}
	pp("%d\n", ans);
}

Measured memory_bytes: 512
function token(s) {
  var len = s.length;
  return function (target, pos) {
    return target.substr(pos, len) === s ? [true, s, pos + len]
      : [false, null, pos];
  };
}

function choice() {
  var parsers = arguments;
  return function (target, pos) {
    for (var i = 0; i < parsers.length; i++) {
      var parsed = parsers[i](target, pos);
      if (parsed[0]) return parsed;
    }
    return [false, null, pos];
  };
}

function seq() {
  var parsers = arguments;
  return function (target, pos) {
    var result = [];
    var nextPos = pos;
    for (var i = 0; i < parsers.length; i++) {
      var parsed = parsers[i](target, nextPos);
      if (!parsed[0]) return [false, null, pos];
      result.push(parsed[1]);
      nextPos = parsed[2];
    }
    return [true, result, nextPos];
  };
}

function lazy(f) {
  var parser;
  return function (target, position) {
    if (!parser) parser = f();
    return parser(target, position);
  };
}

function fmap(parser, f) {
  return function (target, pos) {
    var result = parser(target, pos);
    return result[0] ? [result[0], f(result[1]), result[2]]
      : result;
  };
}

function oneOf(s) {
  var d = {};
  for (var i = 0; i < s.length; i++) d[s[i]] = s[i];
  return function (target, pos) {
    var c = target.substr(pos, 1);
    return d[c] ? [true, c, pos + 1] : [false, null, pos];
  };
}

(function (stdin) {
  var formulaP = lazy(function () {
    var andP = fmap(seq(token('('), formulaP, token('*'), formulaP, token(')')), function (x) {
      return { op: '*', fs: [x[1], x[3]] };
    });
    var orP = fmap(seq(token('('), formulaP, token('+'), formulaP, token(')')), function (x) {
      return { op: '+', fs: [x[1], x[3]] };
    });
    var impP = fmap(seq(token('('), formulaP, token('->'), formulaP, token(')')), function (x) {
      return { op: '->', fs: [x[1], x[3]] };
    });
    var notP = fmap(seq(token('-'), formulaP), function (x) {
      return { op: '-', fs: [x[1]] };
    });
    var valP = fmap(oneOf('abcdefghijkTF'), function (x) { return { val: x, fs: [] }; });
    return choice(andP, orP, impP, notP, valP);
  });
  var equationP = fmap(seq(formulaP, token('='), formulaP), function (x) {
    return { left: x[0], right: x[2] };
  });

  stdin.toString().split('\n').forEach(function (s) {
    if (s == '#') process.exit(0);
    var r = equationP(s, 0);
    var isValid = true;
    var toBool = function (c) {
      if (c === 'T') return true;
      if (c === 'F') return false;
      return !!(i >> (c.charCodeAt() - 'a'.charCodeAt()) & 1);
    };
    var evalF = function (f) {
      switch (f.fs.length) {
        case 0: return toBool(f.val);
        case 1: return !evalF(f.fs[0]);
        case 2:
          switch (f.op) {
            case '*': return evalF(f.fs[0]) && evalF(f.fs[1]);
            case '+': return evalF(f.fs[0]) || evalF(f.fs[1]);
            case '->': return !evalF(f.fs[0]) || evalF(f.fs[1]);
          }
      }
    };
    for (var i = 0; i < (1 << 11); i++) isValid &= evalF(r[1].left) === evalF(r[1].right);
    console.log(isValid ? 'YES' : 'NO');
  });
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29852
#include <iostream>
#include <algorithm>
#include <queue>

#define X first
#define Y second

using namespace std;

typedef pair<int, int> PII;

const int MAX_HW = 8 + 2;
const int MAX_C  = 6;
int dy[] = { -1, 0, 1, 0 };
int dx[] = { 0, -1, 0, 1 };

int H, W, C;
int fd[MAX_HW][MAX_HW];
int tp[MAX_HW][MAX_HW];
bool used[MAX_HW][MAX_HW];

void dfs ( int x, int y, int dest, int src, int m[MAX_HW][MAX_HW] )
{
	if (dest == src || m[y][x] == -1 || m[y][x] != dest) { return; }
	m[y][x] = src;
	for (int d = 0; d < 4; ++d) {
		dfs(x+dx[d], y+dy[d], dest, src, m);
	}
}

int bfs ( int x, int y, int color, int m[MAX_HW][MAX_HW] )
{
	int count = 0;
	for (int i = 0; i < MAX_HW; ++i) {
		fill(used[i], used[i]+MAX_HW, false);
	}
	queue<PII> que;
	que.push(PII(x, y));
	while(!que.empty()) {
		PII p = que.front(); que.pop();
		if (!used[p.Y][p.X]) { ++count; }
		used[p.Y][p.X] = true;
		for (int d = 0; d < 4; ++d) {
			int mx = p.X + dx[d], my = p.Y + dy[d];
			if (!used[my][mx] && m[my][mx] == color) {
				que.push(PII(mx, my));
			}
		}
	}
	return count;
}

void copy2dArray ( int h, int w, int d[MAX_HW][MAX_HW], int s[MAX_HW][MAX_HW] )
{
	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {
			d[y][x] = s[y][x];
		}
	}
}

int main ( void )
{
	while (cin >> H >> W >> C, H|W|C) {
		for (int i = 0; i < MAX_HW; ++i) {
			fill(fd[i], fd[i]+MAX_HW, -1);
			fill(tp[i], tp[i]+MAX_HW, -1);
		}
		for (int y = 1; y <= H; ++y) {
			for (int x = 1; x <= W; ++x) {
				cin >> fd[y][x];
			}
		}
		int ans = 0;
		for (int a = 1; a <= MAX_C; ++a) {
			for (int b = 1; b <= MAX_C; ++b) {
				for (int c = 1; c <= MAX_C; ++c) {
					for (int d = 1; d <= MAX_C; ++d) {
						copy2dArray(MAX_HW, MAX_HW, tp, fd);
						int &color = tp[1][1];
						dfs(1, 1, color, a, tp);
						dfs(1, 1, color, b, tp);
						dfs(1, 1, color, c, tp);
						dfs(1, 1, color, d, tp);
						dfs(1, 1, color, C, tp);
						ans = max(ans, bfs(1, 1, C, tp));
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1252
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 1000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
map<int, int> factor(int m) {
	map<int, int>res;
	for (int i = 2; i*i <= m; i++) {
		while (m%i == 0) {
			res[i]++;
			m /= i;
		}
	}
	if (m != 1)res[m]++;
	return res;
}

/*--------Library Zone!--------*/


signed main() {
	int x;
	cin >> x;
	int ans = 2;
	rep(i, x)ans = ans * 2 + 2;
	cout << ans << endl;
	endre;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;


public class Main {
	//0-WHITE
	//1-BLACK
	static ArrayList<par>[] adj;;
	static int ans[];
	public static void dfs(int u,int par,int color)
	{
		
//		System.out.println(u);
		for(par next:adj[u])
		{
			if(next.v==par)continue;
			if(next.weight%2==0)
			{
				ans[next.v]=color;
			}else {
				ans[next.v]=(1-color);
			}
			dfs(next.v,u,ans[next.v]);
			
		}
		
	}
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int val[]=new int[n];
		adj=new ArrayList[n];
		ans=new int[n];
		for(int i=0;i<n;i++)
		{
			adj[i]=new ArrayList<par>();
		}
		
		
		for(int i=0;i<n-1;i++)
		{
			int u=scan.nextInt();
			int v=scan.nextInt();
			int w=scan.nextInt();
			
			u--;
			v--;
			
			adj[u].add(new par(v,w));
			adj[v].add(new par(u,w));
		}
//		System.out.println("start");
//		for(int i=0;i<n;i++)
//		{
//			System.out.print(i+" ");
//			for(par v:adj[0])
//			{
//				System.out.print(v.v+" ");
//			}
//			System.out.println();
//		}
		dfs(0,-1,0);
		for(int i=0;i<n;i++)
		{
			System.out.println(ans[i]);
		}
		
		
	}
}
class par{
	int v;
	int weight;
	par(int a,int b)
	{
		v=a;
		weight=b;
	}
	
}

Measured memory_bytes: 117524
#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;

int n;
pii a[maxn],b[maxn];
int f[maxn];
int find(int x){
	if(x!=f[x]) f[x]=find(f[x]);
	return f[x];
}

int main(){
	//freopen("test.txt","r",stdin);
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].fi),a[i].se=i;
	for(int i=1;i<=n;i++) scanf("%d",&b[i].fi),b[i].se=i;
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)if(a[i].fi>b[i].fi){
		puts("No");
		return 0;
	}
	for(int i=1;i<=n;i++) f[i]=i;
	for(int i=1;i<=n;i++){
		find(a[i].se);
		find(b[i].se);
		f[f[a[i].se]]=f[b[i].se];
	}
	int cnt=0;
	for(int i=1;i<=n;i++)if(f[i]==i) cnt++;
	if(cnt>1){
		puts("Yes");
	}else{
		bool flag=false;
		for(int i=1;i<n;i++)
			if(a[i+1].first<=b[i].fi) flag=true;
		if(flag) puts("Yes");
		else puts("No");
	}
		
	return 0;
} 

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int p,q,r,ans;
    cin>>p>>q>>r;
    ans=p+q+r-max({p,q,r});
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import numpy as np
x,n=(int(x) for x in input().split())
p = np.array([int(x) for x in input().split()])

a = 0
while True:
    if x-a not in p:
        print(x-a)
        break
    elif x+a not in p:
        print(x+a)
        break
    a += 1

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i, n){ cin >> a[i]; }
	ll ans1 = 0;
	ll sum = 0;
	REP(i, n){
		sum += a[i];
		if (i%2==0){
			if (sum<=0){
				ans1 += (1-sum);
				sum = 1;
			}
		}
		else {
			if (sum>=0){
				ans1 += (sum+1);
				sum = -1;
			}
		}
	}
	ll ans2 = 0;
	sum = 0;
	REP(i, n){
		sum += a[i];
		if (i%2==1){
			if (sum<=0){
				ans2 += (1-sum);
				sum = 1;
			}
		}
		else {
			if (sum>=0){
				ans2 += (sum+1);
				sum = -1;
			}
		}
		if (ans2>=ans1){ break; }
	}
	cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384626433832795

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, d, x, in,ans=0;
	cin >> n >> d >> x;
	vi a;
	rep(i, n) {
		cin >> in;
		a.push_back(in);
	}
	rep(i,n){
		int t = 1;
		while (t <= d) {
			ans++;
			t += a[i];
		}
	}
	ans += x;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>


using namespace std;

int main(){
  
  int n;
  cin >> n;
  vector<uint64_t> len(n, 0);
  for(int i=0; i<n; i++){
    cin >> len.at(i);
  }
  

  int cnt = 0;
  
  for(int i=0; i<len.size(); i++){
    for(int j=i+1; j<len.size(); j++){
      for(int k=j+1; k<len.size(); k++){
        uint64_t a = len.at(i);
        uint64_t b = len.at(j);
        uint64_t c = len.at(k);
        if(a!=b && b!=c && a!= c){
          if(a+b>c && b+c>a && c+a>b){
            cnt++;
          }
          else{
              continue;
          }
        }
      }
    }
  }

  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<vector<ll>> g(n);
  REP(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<ll> c(n+1);
  c[2] = 1;
  for(ll i=4; i<=n; i+=2) {
    (c[i] = c[i-2] * (i-1)) %= MOD;
  }
  // cout << c << endl;

  // 2乗の木DP
  function<vector<vector<ll>>(ll,ll)> dfs = [&](ll v, ll par) {
    auto ret = make_v<ll>(2,2);
    fill_v(ret, 0);
    ret[1][0] = 1;
    for(auto to: g[v]) {
      if(to == par) continue;
      auto tmp = dfs(to, v);
      auto nret = make_v<ll>(ret.size()+tmp.size()-1, 2);
      fill_v(nret, 0);
      REP(i, ret.size()) REP(j, tmp.size()) {
        // vからtoまでの辺を切断
        (nret[i][0] += ret[i][0] * tmp[j][1] % MOD * c[j] + ret[i][1] * tmp[j][0] % MOD * c[j]) %= MOD; 
        (nret[i][1] += ret[i][0] * tmp[j][0] % MOD * c[j] + ret[i][1] * tmp[j][1] % MOD * c[j]) %= MOD;
        // vからtoまでの辺をつないだまま
        (nret[i+j][0] += ret[i][0] * tmp[j][0] + ret[i][1] * tmp[j][1]) %= MOD;
        (nret[i+j][1] += ret[i][0] * tmp[j][1] + ret[i][1] * tmp[j][0]) %= MOD;
      }
      ret = nret;
    }
    return ret;
  };

  auto ret = dfs(0, -1);

  ll ans = 0;
  REP(i, ret.size()) {
    (ans += ret[i][0] * c[i] % MOD) %= MOD;
    (ans -= ret[i][1] * c[i] % MOD) %= MOD;
    if(ans < 0) ans += MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout <<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

struct UnionFind {
  vector< int > par;
  UnionFind(int n = 1) {
    init(n);
  }

  void init(int n = 1) {
    par.resize(n);
    for(int i = 0; i < n; i++)
      par[i] = -1;
  }
  
  int root(int n) {
    if (par[n] < 0) return n;
    return par[n] = root(par[n]);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;

    return true;
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }
};

signed main() {
  INIT;

  VAR(int, N, K, L);
  UnionFind road(N + 1);
  REP(i, K) {
    VAR(int, p, q);
    p--; q--;
    road.merge(p, q);
  }
  UnionFind train(N + 1);
  REP(i, L) {
    VAR(int, s, t);
    s--; t--;
    train.merge(s, t);
  }

  map< PAIR, int > mp;
  REP(i, N) {
    mp[PAIR(road.root(i), train.root(i))]++;
  }

  REP(i, N) {
    OUT(mp[PAIR(road.root(i), train.root(i))]);
    if (i < N - 1) SP;
  }
  BR;
  
  return 0;
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, k;
  cin >> n >> k;
  int a = n / k;
  if (k % 2 == 0) {
    int b = (n + k / 2) / k;
    cout << a * a * a + b * b * b << endl;
  } else {
    cout << a * a * a << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import heapq
def main():
    n,m = map(int,input().split())
    lb = [[] for _ in range(10**5+5)]
    for _ in range(n):
        a,b = map(int,input().split())
        lb[a].append(b)
    res = 0
    q = []
    heapq.heapify(q)
    for i in range(1,m+1):
        for b in lb[i]:
            heapq.heappush(q,b * (-1))
        if q:
            res += heapq.heappop(q) * (-1)

    print(res)

main()

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

int main(){
  int x;
  cin >> x;
  for(int i = 1; i*i*i <= x; i++){
    for(int j = i-1; j >= -(i-1); j--){
      if(i*i*i*i*i - j*j*j*j*j == x){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

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

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

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

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

int base[100005] = {};

ll func(string& s) {
    if (s.size() <= 3) return 0;
    string left(s.begin(), s.begin()+s.size()/2);
    string right(s.begin()+s.size()/2, s.end());

    ll rst = func(left) + func(right);
    
    int rem[2019] = {};
    int cur = 0;
    for (auto it = left.rbegin(); it != left.rend(); ++it) {
        cur += (*it - '0') * base[it-left.rbegin()];
        cur %= 2019;
        ++rem[cur];
    }

    cur = 0;
    for (auto it = right.begin(); it != right.end(); ++it) {
        cur *= 10;
        cur += *it - '0';
        cur %= 2019;

        for (int j = 0; j < 2019; j++) {
            if ((cur + j*base[it-right.begin()+1]) % 2019 == 0) {
                rst += rem[j];
                break;
            }
        }
    }

    return rst;
}

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

    base[0] = 1;
    for (int i = 1; i < 100005; i++) {
        base[i] = base[i-1] * 10;
        base[i] %= 2019;
    }

    string s; cin >> s;
    cout << func(s);
}

Measured memory_bytes: 4556
S = gets.to_i
yy43 = 0; mm43 = 0
yy21 = 0; mm21 = 0
yy43 = 1 if S % 100 >= 0 && S % 100 <= 99
mm43 = 1 if S % 100 >= 1 && S % 100 <= 12
yy21 = 1 if S / 100 >= 0 && S / 100 <= 99
mm21 = 1 if S / 100 >= 1 && S / 100 <= 12
if yy21 == 1 && mm43 == 1 && mm21 == 1 && yy43 == 1
  puts 'AMBIGUOUS'
elsif mm21 == 1 && yy43 == 1
  puts 'MMYY'
elsif yy21 == 1 && mm43 == 1
  puts 'YYMM'
else
  puts 'NA'
end

Measured memory_bytes: 3836
// Last Change: 08/20/2019 17:09:26.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

const int ALPH = 26;

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

  size_t sSize = s.size();
  size_t tSize = t.size();
  vector<vector<ll>> vectS(ALPH, vector<ll>());
  for (size_t i = 0; i < sSize; ++i) {
    vectS[s[i] - 'a'].push_back(i);
  }

  // i should separate ans from tmp pos.
  ll pos = -1; // if this val is zero, it cause WA.
  ll ans = 0;
  for (size_t i = 0; i < tSize; ++i) {
    ll c = t[i] - 'a';
    if (vectS[c].empty()) {
      cout << -1 << endl;
      return 0;
    }
    auto itr = upper_bound(vectS[c].begin(), vectS[c].end(), pos);
    if (itr == vectS[c].end()) {
      pos = vectS[c][0];
      ++ans;
    } else {
      pos = *itr;
    }
  }

  cout << ans * sSize + pos + 1 << endl;
}


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

int main(int argc, const char * argv[]) {



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

    /////////////////////
    // Write code below /
    /////////////////////
    int N,K,a,i;
    vector<int>x;

    cin>>N>>K;

    for(i=0;N>0;i++){
        N/=K;
    }

    cout<<i<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>

using namespace std;

int N;
map<string,int> m;
int idx=0;
vector<int> G[101];
vector<string> CS[101];
string names[101];
int strong[101];
bool used[101];
int optNum;

// 現在選べるものから選ぶ
void dfs(int idx,int sum){
  if(idx==N){
    optNum=max(optNum,sum);
    return;
  }
  if(used[idx]){
    dfs(idx+1,sum);
    return;
  }
  int allSum=0;
  bool cur[50];
  for(int i=0;i<N;i++){
    cur[i]=used[i];
    if(!used[i])allSum+=strong[i];
  }
  if(allSum+sum<=optNum)return;
  bool ok=true;
  // これから選ぶ頂点のどれかと隣接しているかチェック
  for(int i=idx+1;i<N;i++){
    if(used[i])continue;
    for(int j=0;j<(int)G[i].size();j++){
      if(G[i][j]==idx){
	ok=false;
	break;
      }
    }
    if(!ok)break;
  }
  // 隣接している頂点が存在する場合
  if(idx!=0&&!ok){
    // 取らない
    dfs(idx+1,sum);
  }
  if(!used[idx]){
    used[idx]=true;
    for(int j=0;j<(int)G[idx].size();j++){
      int to=G[idx][j];
      used[to]=true;
    }
    dfs(idx+1,sum+strong[idx]);
    for(int j=0;j<N;j++)used[j]=cur[j];
  }
}

int main(){
  while(cin>>N&&N){
    idx=0;
    optNum=-1;
    for(int i=0;i<101;i++){
      G[i].clear();
      CS[i].clear();
    }
    m.clear();
    for(int i=0;i<N;i++){
      cin>>names[i]>>strong[i];
      int C;
      cin>>C;
      for(int j=0;j<C;j++){
	string s;
	cin>>s;
	if(m.count(s)==0)m[s]=idx++;
	CS[i].push_back(s);
      }
    }
    for(int i=0;i<N;i++)
      m[names[i]]=i;
    for(int i=0;i<N;i++){
      for(int j=0;j<(int)CS[i].size();j++){
	G[m[names[i]]].push_back(m[CS[i][j]]);
	G[m[CS[i][j]]].push_back(m[names[i]]);
      }
    }
    memset(used,0,sizeof(used));
    dfs(0,0);
    cout<<optNum<<endl;
  }

  return 0;
}

Measured memory_bytes: 1032
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int n, m;
vector<vector<int>> road(100100);

int main () {
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        road[a].push_back(b);
        road[b].push_back(a);
    }
    vector<int> dist(n, -1);
    queue<int> q;
    vector<int> ans(n);

    dist[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int v = q.front();
        q.pop();

        for (int nv : road[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            ans[nv] = v;
            q.push(nv);
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << ans[i]+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 10724
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; i<n; i++)
#define REP2(i, a, b) for(int i=a; i<b; i++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

long long solve(string T, long long R, long long S, long long P){
    int N = T.size();
    vector<vector<long long>> dp(3, vector<long long>(N));
    vector<int> v(N);
    REP(i, N)
        if(T[i] == 'r') v[i] = 0;
        else if(T[i] == 's') v[i] = 1;
        else v[i] = 2;
    long long points[3] = {P, R, S};

    dp[v[0]][0] = points[v[0]];
    for(int i=1; i<N; i++){
        int a = v[i];
        int b = (a+1)%3;
        int c = (a+2)%3;
        dp[a][i] = max(dp[b][i-1], dp[c][i-1])+points[v[i]];
        dp[b][i] = max(dp[a][i-1], dp[c][i-1]);
        dp[c][i] = max(dp[a][i-1], dp[b][i-1]);
    }
    long long ret = 0;
    REP(i, 3)
        ret = max(ret, dp[i][N-1]);
    return ret;
}

int main(){
    long long N, K, R, S, P;
    string T;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    long long ans = 0;
    REP(i, K){
        string TT = "";
        for(int j=i; j<N; j+=K) TT += T[j];
        ans += solve(TT, R, S, P);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N=5e5+7,M=1048600,mod=1e9+7;
struct tree{
	int sum[N<<2];
	void build(int l,int r,int rt)
	{
		if(l==r){sum[rt]=(l==0);return;}
		int mid=l+r>>1;
		build(lson),build(rson);
		sum[rt]=(sum[rt<<1]+sum[rt<<1|1])%mod;
	}
	void update(int k,int v,int l,int r,int rt)
	{
		if(l==r){sum[rt]=v;return;}
		int mid=l+r>>1;
		if(k<=mid)update(k,v,lson);else update(k,v,rson);
		sum[rt]=(sum[rt<<1]+sum[rt<<1|1])%mod;
	}
	int query(int L,int R,int l,int r,int rt)
	{
		if(L<=l&&r<=R)return sum[rt];
		int ret=0,mid=l+r>>1;
		if(L<=mid)ret=(ret+query(L,R,lson))%mod;
		if(R>mid)ret=(ret+query(L,R,rson))%mod;
		return ret;
	}
}tr[2];
int n,ans,psum,tot,a[N],s[20][N],sum[N],pw[N],f[N];
vector<int>G[M];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=0;i<20;i++)for(int j=1;j<=n;j++)s[i][j]=(s[i][j-1]+((a[j]>>i)&1))%2;
	int flag=0;
	for(int i=0;i<20;i++)if(s[i][n])flag=1;
	if(!flag)
	{
		int n0=1,lst=0;
		for(int i=1;i<=n;i++)a[i]^=a[i-1];
		for(int i=1;i<n;i++)
		if(!a[i])n0=2ll*n0%mod,sum[i]=sum[i-1]+1;else G[a[i]].push_back(i),sum[i]=sum[i-1];
		for(int v=1;v<(1<<20);v++)
		if(G[v].size())
		{
			int sz=G[v].size(),pre=0;
			for(int i=0;i<sz;i++)f[i]=0;
			f[0]=1,ans=(ans+1)%mod;
			for(int i=1;i<sz;i++)
			{
				int s0=sum[G[v][i]-1]-sum[G[v][i-1]];
				pre=(pre+1ll*f[i-1]*s0)%mod;
				ans=(ans+pre+1)%mod;
				f[i]=(f[i-1]+pre+1)%mod;
			}
		}
		ans=(ans+n0)%mod;
		printf("%d\n",ans);
		return 0;
	}
	tr[0].build(0,n,1);
	tr[1].build(0,n,1);
	tr[1].update(0,0,0,n,1);
	for(int i=1;i<=n;i++)
	{
		int s1=0,dif=0,add;
		for(int j=0;j<20;j++)
		{
			if(s[j][i])s1++;
			if(s[j][i]!=s[j][n])dif++;
		}
		if(!s1)add=tr[1].query(0,i-1,0,n,1),tr[0].update(i,add,0,n,1);
		if(!dif)add=tr[0].query(0,i-1,0,n,1),tr[1].update(i,add,0,n,1);
	}
	ans=tr[1].query(n,n,0,n,1);
	printf("%d\n",ans);
}

Measured memory_bytes: 80896
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(a) (a).begin(),(a).end()


int main(){
  vector<ll> x(5);
  rep(i,5) cin >> x.at(i);
  rep(i,5){
    if( x.at(i) == 0 ){
      cout << i+1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3620
import itertools
n,c=map(int,input().split())
ld=[list(map(int,input().split())) for i in range(c)]
lc=[list(map(int,input().split())) for i in range(n)]
ct=[[0 for i in range(c)] for i in range(3)]
for i in range(n):
  for j in range(n):
    ct[(i+j+2)%3][lc[i][j]-1]+=1
L=list(itertools.permutations([i for i in range(c)],3))

ans=[]
for i in range(len(L)):
  ct2=0
  for j in range(3):
    for k in range(c):
      ct2+=ld[k][L[i][j]]*ct[j][k]
  ans.append(ct2)
print(min(ans))

Measured memory_bytes: 46428
#include <iostream>

using namespace std;

int main() {
    char b;
    cin >> b;
    if (b == 'A') {
        cout << 'T' << endl;
    }
    if (b == 'T') {
        cout << 'A' << endl;
    }
    if (b == 'C') {
        cout << 'G' << endl;
    }
    if (b == 'G') {
        cout << 'C' << endl;
    }
}

Measured memory_bytes: 256
a = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
    sc = input().split()
    a[int(sc[0]) - 1][int(sc[1]) - 1][int(sc[2]) - 1] += int(sc[3])
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(' {}'.format(a[i][j][k]), end = '')
        print('')
    if i != 3:
        print('####################')


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

const string YES = "Yes";
const string NO = "No";

void solve(std::vector<std::vector<long long>> A, long long N, std::vector<long long> b){
    vector<vector<bool>> bingo(3,vector<bool>(3,false));
    for (int i=0;i<3;i++){
        for (int j=0;j<3;j++){
            for (const int num : b){
                if (A[i][j] == num) bingo[i][j] =true;
            }
        }
    }
    //tate
    bool flag = false;
    for (int i=0;i<3;i++){
        if (bingo[i][0]&& bingo[i][1]&&bingo[i][2]) flag =true;
        if (bingo[0][i]&& bingo[1][i]&&bingo[2][i]) flag=true;
    }
    if (bingo[0][0]&& bingo[1][1]&&bingo[2][2]) flag=true;
    if (bingo[2][0]&& bingo[1][1]&&bingo[0][2]) flag=true;

    if (flag) printf("Yes\n");
    else printf("No\n");

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::vector<std::vector<long long>> A(3, std::vector<long long>(3));
    for(int i = 0 ; i < 3 ; i++){
        for(int j = 0 ; j < 3 ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    long long N;
    scanf("%lld",&N);
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&b[i]);
    }
    solve(std::move(A), N, std::move(b));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int d,n;cin>>d>>n;
    if(d==0 && n<100) cout<<n<<endl;
    else if(d==0 && n==100) cout<<n+1<<endl;
    else if(d==1 && n<100) cout<<100*n<<endl;
    else if(d==1 && n==100) cout<<101*100<<endl;
    else if(d==2 && n<100) cout<<n*100*100<<endl;
    else if(d==2 && n==100) cout<<101*100*100<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    int n;
    cin >> n;
    cout << pow(n,3) << endl;

    return 0;
}

Measured memory_bytes: 4316
#include <iostream>
#include <stdio.h>
#include <stdint.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <deque>

using namespace::std;

int ri()
{
	int x;
	scanf("%d", &x);

	return x;
}

int64_t ri64()
{
	int64_t x;
	scanf("%lld", &x);

	return x;
}

void wi(int x)
{
	printf("%d\n", x);
}

void wvi(vector<int> &v)
{
	for (int i = 0; i < v.size(); i++)
		printf("%d ", v[i]);
	printf("\n");
}

void dbg(string &str, int x)
{
	cout << str << ": ";
	wi(x);
}

void dbg(string &str, vector<int> &x)
{
	cout << str << ": ";
	wvi(x);
}

int main()
{
        int64_t N, A, B;
        cin >> N >> A >> B;

        if ((A % 2) == (B % 2))
        {
                int64_t ans = (B - A) / 2;
                cout << ans << endl;

                return 0;
        }

        int64_t ans = min(B - 1, N - A);
        
        // can also rebound
        if (ans > (A + (B - A - 1)/2))
                ans = A + (B - A - 1)/2;

        if (ans > (N - B + 1 + (B - A - 1)/2))
                ans = N - B + 1 + (B - A - 1)/2;

        cout << ans << endl;

	return 0;
}


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

#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(v) v.begin(), v.end()

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

  int n, q; cin >> n >> q;
  VI c(n); rep(i, n) cin >> c[i];
  vector<pair<int, int>> lr(q); rep(i, q) cin >> lr[i].first >> lr[i].second;
  rep(i, q) lr[i].first--;

  const int sq = 10;
  VI ri(q), lri(q);
  VI cnt(n+1);
  rep(i, q) cnt[lr[i].second]++;
  rep(i, n) cnt[i+1] += cnt[i];
  repr(i, q) ri[--cnt[lr[i].second]] = i;
  fill(all(cnt), 0);
  rep(i, q) cnt[lr[i].first >> sq]++;
  rep(i, n) cnt[i+1] += cnt[i];
  repr(i, q) lri[--cnt[lr[ri[i]].first >> sq]] = ri[i];
  fill(all(cnt), 0);

  VI ans(q);

  int prev = -1;
  int lx, rx;
  int sum = 0;
  for (auto i : lri) {
    auto [l, r] = lr[i];
    if (l >> sq != prev) {
      fill(all(cnt), 0);
      lx = rx = r;
      prev = l >> sq;
      sum = 0;
    }
    int cx;
    while (lx > l) if (cnt[cx=c[--lx]]++ == 0) sum += 1;
    while (lx < l) if (--cnt[c[lx++]] == 0) sum -= 1;
    while (rx < r) if (cnt[cx=c[rx++]]++ == 0) sum += 1;
    ans[i] = sum;
  }
  rep(i, q) cout << ans[i] << "\n";
}


Measured memory_bytes: 17408
n = int(input())
a = list(map(int, input().split()))
med_l = int(sum(a)/n)
med_h = med_l + 1
sum_l = 0
sum_h = 0

for i in range(n):
  sum_l += (med_l - a[i])**2
  sum_h += (med_h - a[i])**2
  
print(min(sum_l, sum_h))

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
int main() { int N;
  cin >> N;

  string S;

  cin >> S;
  int sum = 1;
  for (int i = 0;i<S.size()-1;i++){
      if(S[i]!=S[i+1]){
        sum++;
      }
  }
  cout << sum << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll K;	cin>>K;
	int a = 7, count = 1;
	while (a % K != 0&&count<=K)
	{
		a = ((a % K) * 10 + 7) % K;
		count++;
	}

	if(a%K==0)
		cout << count << endl;
	else
		cout << -1 << endl;

		return 0;
}



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

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> math(h);
    int cnt=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            char tmp;
            cin >> tmp;
            math[i].push_back(tmp);
            if(tmp=='#')cnt++;
        }
    }
    int cntw=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w-1; j++){
            if(math[i][j]=='#'&&math[i][j+1]=='#')cntw++;
        }
    }
    int cnth=0;
    for(int i=0; i<w; i++){
        for(int j=0; j<h-1; j++){
            if(math[j][i]=='#'&&math[j+1][i]=='#')cnth++;
        }
    }
    if(h-1==cnth&&w-1==cntw&&h+w-1==cnt)cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
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 dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = 0;
	ll s;
	while (1) {
		s = 0;
		for (int i = 0; i < n; i++) {
			s += a[i] / n;
		}
		ans += s;
		for (int i = 0; i < n; i++) {
			a[i] = a[i] % n + s - a[i] / n;
		}
		bool ok = true;
		for (int i = 0; i < n; i++) {
			if (a[i] >= n) ok = false;
		}
		if (ok) break;
	}
	dump(ans);
	return 0;
}


Measured memory_bytes: 256