akhauriyash/Code-Regression huggingface dataset:
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = (1 << 30) + 1000;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n;

vector<int> prefix_function(vector<int>& a){
   int n = a.size();
   int j = 0;
   vector<int> pi(n);
   for (int i = 1; i < n; ++i)
   {
      while(j and a[j] != a[i]){
         j = pi[j-1];
      }
      j += a[j] == a[i];
      pi[i] = j;
   }
   return pi;
}
vector<int> a, b;

vector<int> get(int bits, vector<int>& a, int type){
   vector<int> curr;
   for (int i = 0; i < sz(a); ++i)
   {
      if(a[i] & (1LL << bits)){
         curr.push_back(1 ^ type);
      }
      else{
         curr.push_back(0 ^ type);
      }
   }
   vector<int> v;
   for(auto it: b)
      v.push_back((it & (1LL << bits)) > 0);

   v.push_back(-123456);

   for(auto it: curr)
      v.push_back(it);

   //[b1,b2,b3,...bn] + k + [a1,a2,a3,...an,an+1,an+2,...a2n]
   v = prefix_function(v);
   return v;
}

int32_t main(){_
   
   cin>>n;
   a.resize(2*n);
   b.resize(n);
   vector<vector<int>> bit_pi[31];

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

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

   for (int bits = 30; bits >= 0; --bits)
   {
      vector<int> pref0 = get(bits, a, 0);
      vector<int> pref1 = get(bits, a, 1);
      bit_pi[bits].push_back(pref0);
      bit_pi[bits].push_back(pref1);
   }

   for (int k = 0; k < n; ++k)
   {
      int x = 0;
      for (int bits = 30; bits >= 0; --bits)
      {
         if(bit_pi[bits][0][2*n+k] == n){
         }
         else if (bit_pi[bits][1][2*n+k] == n){
            x |= (1LL << bits);
         }
         else{
            x = -inf;
            break;
         }
      }
      if(x != -inf){
         cout<<k<<" "<<x<<endl;
      }
   }

   return 0;
}

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

string S;
int mod = 1e9 + 7;

int main() {
    cin >> S;
    
    vector<vector<long long>> dp(S.size() + 1, vector<long long>(4));
    dp[0][0] = 1;
    for (int i = 0; i < S.size(); i++) {
        switch (S[i]) {
            case 'A':
                dp[i + 1][0] = dp[i][0];
                dp[i + 1][1] = (dp[i][1] + dp[i][0]) % mod;
                dp[i + 1][2] = dp[i][2];
                dp[i + 1][3] = dp[i][3];
                break;
            case 'B':
                dp[i + 1][0] = dp[i][0];
                dp[i + 1][1] = dp[i][1];
                dp[i + 1][2] = (dp[i][2] + dp[i][1]) % mod;
                dp[i + 1][3] = dp[i][3];
                break;
            case 'C':
                dp[i + 1][0] = dp[i][0];
                dp[i + 1][1] = dp[i][1];
                dp[i + 1][2] = dp[i][2];
                dp[i + 1][3] = (dp[i][3] + dp[i][2]) % mod;
                break;
            default:
                dp[i + 1][0] = (dp[i][0] * 3) % mod;
                dp[i + 1][1] = (dp[i][1] * 3 + dp[i][0]) % mod;
                dp[i + 1][2] = (dp[i][2] * 3 + dp[i][1]) % mod;
                dp[i + 1][3] = (dp[i][3] * 3 + dp[i][2]) % mod;
                break;
        }
    }
    cout << dp[S.size()][3] << endl;
}

Measured memory_bytes: 7424
a=[list(map(int,list(input().split()))) for _ in range(3)]
b=[[0]*3 for _ in range(3)] 
n = int(input())
##################
for ni in range(n):
  x = int(input())
  for i in range(3):
    for j in range(3):
      if a[i][j] == x:
        b[i][j] = 1
##################
ans = False
##################
for i in range(3):
  cnt = 0
  for j in range(3):
    cnt += b[i][j]
    if cnt == 3:
      ans = True
##################
for i in range(3):
  cnt = 0
  for j in range(3):
    cnt += b[j][i]
    if cnt == 3:
      ans = True
##################
cnt = 0
for j in range(3):
  cnt += b[j][j]
  if cnt == 3:
    ans = True
##################
cnt = 0
for j in range(3):
  cnt += b[j][2-j]
  if cnt == 3:
    ans = True
##################
if ans == True:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007
#define modhalf 500000004

ll modpow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y % 2)ans = ans * x % MOD;
		x = x * x % MOD;
		y /= 2;
	}
	return ans;
}

ll RW[200010], fcr[200010];

ll nCk(ll n, ll k) {
	return fcr[n] * modpow(fcr[k], MOD - 2) % MOD * modpow(fcr[n - k], MOD - 2) % MOD;
}

int main() {
	ll W, B, N, p;
	cin >> B >> W;
	N = B + W;
	RW[0] = 0, fcr[0] = 1;
	for (int i = 1;i < 200010;i++) {
		RW[i] = 0;
		fcr[i] = fcr[i - 1] * (ll)i % MOD;
	}
	for (ll i = N;i > W + 1;i--) {
		ll al = nCk(i - 2, W - 1);
		ll cb = nCk(i - 3, W - 1);
		p = modpow((MOD + 1) / 2, i - 1);
		RW[1] += p * cb;
		RW[1] %= MOD;
		RW[i - 1] -= p * cb;
		RW[i - 1] %= MOD;
		if (RW[i - 1] < 0)RW[i - 1] += MOD;
		RW[i] += p * al;
		RW[i] %= MOD;
	}
	RW[W + 1] += modpow((MOD + 1) / 2, W);
	RW[W + 1] %= MOD;
	for (ll i = N;i > B + 1;i--) {
		ll al = nCk(i - 2, B - 1);
		ll cb = nCk(i - 3, B - 2);
		p = modpow((MOD + 1) / 2, i - 1);
		RW[1] += p * cb;
		RW[1] %= MOD;
		RW[i - 1] -= p * cb;
		RW[i - 1] += p * al;
		RW[i - 1] %= MOD;
		if (RW[i - 1] < 0)RW[i - 1] += MOD;
		RW[i] += MOD - p * al % MOD;
		RW[i] %= MOD;
	}

	p = modpow((MOD + 1) / 2, B);
	RW[1] += p;
	RW[1] %= MOD;
	RW[B + 1] -= p;
	RW[B + 1] %= MOD;
	if (RW[B + 1] < 0)RW[B + 1] += MOD;

	for (int i = 1;i < 200010;i++) {
		RW[i] += RW[i - 1];
		RW[i] %= MOD;
	}
	for (int i = 1;i <= B + W;i++) {
		cout << RW[i] << endl;
	}
}

Measured memory_bytes: 5376
#include <iostream>

using namespace std;

int main() {
  int H,W;
  while (true) {
    cin >> H >> W;
    if(H == 0 && W == 0)break;
    for(int i=0; i < H; ++i){
      for(int j=0; j < W ;++j){
        cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    if (A == 1)A += 13;
    if (B == 1)B += 13;
    if (A > B)cout << "Alice" << '\n';
    else if (A < B)cout << "Bob" << '\n';
    else cout << "Draw" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		//int[] s=sc.Ia;
		string t=sc.S;
		long ans=0,p=0;
		char c='B';
		for(int i = t.Length-1;i>=0;i--) {
			if(t[i]=='A'){
				if(c=='C'){
					p=0;
					c=t[i];
				}
				else{ans+=p;}
				continue;
			}
			if(t[i]=='B'&&c=='C'){
				p++;
			}
			else if(t[i]=='C'&&c=='B'){
				
			}
			else{p=0;}
			c=t[i];
			//Console.WriteLine("{0} {1}",t[i],p);

		}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return a[n];}}
	public string Sz{get{return Console.ReadLine();}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2(int b){return Array.ConvertAll((((b&1)!=0?"0 ":"")+Console.ReadLine()+((b&2)!=0?" 0":"")).Split(),int.Parse);}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public string[] Sa2{get{return (Console.ReadLine()+" 0").Split();}}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
}

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

public class Main {
	private static void solve(){
		//Implement solution here.
		char[] ca = next().toCharArray();
		for(int i = 1; i < 4; i++) {
			if(ca[i] == ca[i -1]) {
				System.out.println("Bad");
				return;
			}
		}
		System.out.println("Good");	
		
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 21204
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int n;
	vector<int> l;
	scanf("%d", &n);
	for (int i=0; i<2*n; i++){
		int x;
		scanf("%d", &x);
		l.push_back(x);
	}
	sort(l.begin(), l.end());
	int t=0;
	for (int i=0; i<n; i++){
		t += l[2*i];
	}
	printf("%d\n", t);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
int main(){
    ll N, X;
    cin >> N >> X;
    ll x[N];
    for(ll i = 0; i < N; i++) cin >> x[i];
    ll ans = abs(X - x[0]);
    for(ll i = 1; i < N; i++) ans = gcd(ans, abs(X - x[i]));
    cout << ans << endl;
    return 0;
}


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

#define REP(i, x) for (int i = 0; i < (x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define CHMIN(a, b) (a) = min((a), (b))

using P = pair<int, int>;

const int MAXN = 1010;
const int MAXX = 5010;
const int INF = (1 << 28);

int N;
int X[MAXN];
int dp[MAXN][MAXX];

vector<int> tree[MAXN];

int dfs(int v, int p) {
    vector<P> children;
    for (int to : tree[v]) {
        if (to == p) continue;
        children.push_back(make_pair(dfs(to, v), X[to]));
    }

    // 初期化
    REP (i, children.size() + 1) REP (j, X[v] + 1) dp[i][j] = INF;

    dp[0][0] = 0;
    REP (i, children.size()) {
        REP (j, X[v] + 1) {
            if (dp[i][j] >= INF) continue;

            int cost1 = children[i].first,
                cost2 = children[i].second;
            if (j + cost1 <= X[v]) CHMIN(dp[i + 1][j + cost1], dp[i][j] + cost2);
            if (j + cost2 <= X[v]) CHMIN(dp[i + 1][j + cost2], dp[i][j] + cost1);
        }
    }
    int res = INF;
    REP (i, X[v] + 1) CHMIN(res, dp[children.size()][i]);

    return res;
}

int main() {
    cin >> N;
    FOR (i, 1, N) {
        int P;
        cin >> P;
        P--;

        tree[i].push_back(P);
        tree[P].push_back(i);
    }

    REP (i, N) {
        cin >> X[i];
    }

    if (dfs(0, -1) >= INF) cout << "IMPOSSIBLE" << endl;
    else cout << "POSSIBLE" << endl;

    return 0;
}

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

int calc(int a,int i){
	if(i==0 || i==4) return a;
	if(i==1 || i==3) return a>0?a%2:2;
	else return a%2==0;
}

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

	long dp[5][l+1];
	for(int i=0;i<5;i++) dp[i][0]=0;
	for(int i=1;i<=l;i++){
		for(int j=0;j<5;j++){
			int add=calc(a[i-1],j);
			dp[j][i]=dp[j][i-1]+add;
			for(int k=0;k<j;k++) dp[j][i]=min(dp[j][i],dp[k][i-1]+add);
		}
	}

	long ans=1e18;
	for(int i=0;i<5;i++) ans=min(ans,dp[i][l]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8832
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		int left = a + b;
		int right = c + d;
		if(left > right) {
			System.out.println("Left");
		} else if(left == right) {
			System.out.println("Balanced");
		} else {
			System.out.println("Right");
		}
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
using ulong = unsigned long;
using ll = long long;
const int M = 1e9 + 7;
#pragma unused(M)

int main(){
	string s;
	cin >> s;
	string cor = "CODEFESTIVAL2016";
	int cnt = 0;
	for(int i=0;i<16;i++){
		if(cor[i] != s[i]){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h,w;
    cin>>h>>w;
    //const int dx[8]={0,1,1,1,0,-1,-1,-1};
    ///onst int dy[8]={1,0,-1,1,-1,-1,0,1};
    char s[h][w];
    for(int i=0;i<h;i++){
        string ss;
            cin>>ss;
        for(int j=0;j<w;j++){
            s[i][j]=ss[j];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int pt=0;
            if(s[i][j]=='#')cout<<'#';
            else{
                for(int k=-1;k<=1;k++){
                    for(int l=-1;l<=1;l++){
                    //cout<<(k+i>=0)<<(k+i<h)<<(l+j>=0)<<" "<<w<<endl;
                    if(k+i>=0 && k+i<h && l+j>=0 && l+j<w && s[k+i][l+j]=='#'){
                        pt++;
                        //cout<<"WW"<<endl;}
                }}}
                cout<<pt;
            }
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main(void) {
	ll N, p;
	cin >> N >> p;

	ll ans2 = 0;
	ll K = min(p, 2 * N);
	deque<ll> V(N);
	vector<ll> sum(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> V[i];
		if (V[i] > 0) ans2 += V[i];
		sum[i + 1] = sum[i] + V[i];
	}


	vector<vector<ll>> dpL(N + 1, vector<ll>(min(2 * N + 1, K + 1)));
	vector<ll> vl;
	for (int i = 1; i <= N; i++) {
		ll temp = sum[i];
		vl.push_back(V[i - 1]);
		sort(vl.begin(), vl.end());
		for (int j = 1; j <= min(2*N, K); j++) {
			if (i == j) {
				dpL[i][j] = max(temp, max(dpL[i - 1][j], dpL[i][j - 1]));
			}
			else if (i + 1 <= j && j <= 2 * i - 1) {
				if (vl[j - i - 1] < 0) temp -= vl[j - i - 1];
				dpL[i][j] = max(temp, max(dpL[i - 1][j], dpL[i][j - 1]));
			}
			else {
				dpL[i][j] = max(dpL[i - 1][j], dpL[i][j - 1]);
			}
		}
	}

	vector<vector<ll>> dpR(N + 1, vector<ll>(min(2*N + 1, K + 1)));
	vector<ll> vr;
	for (int i = 1; i <= N; i++) {
		ll temp = sum[N] - sum[N - i];
		vr.push_back(V[N - i]);
		sort(vr.begin(), vr.end());
		for (int j = 1; j <= min(K, 2*N); j++) {
			if (i == j) {
				dpR[i][j] = max(temp, max(dpR[i - 1][j], dpR[i][j - 1]));
			}
			else if (i + 1 <= j && j <= 2 * i - 1) {
				if (vr[j - i - 1] < 0) temp -= vr[j - i - 1];
				dpR[i][j] = max(temp, max(dpR[i - 1][j], dpR[i][j - 1]));
			}
			else {
				dpR[i][j] = max(dpR[i - 1][j], dpR[i][j - 1]);
			}
		}
	}
	ll ans = 0;
	
	for (int j = 0; j <= min(K,2* N); j++) {
		ans = max(ans, dpL[N][j] + dpR[N][min(2*N, K) - j]);
	}
	cout << min(ans,ans2) << endl;
}


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

typedef long long ll;
typedef long double ld;

ll a[100005];
ll sum;

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

    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        sum += a[i];
    }
    sort(a+1, a+1+n);
    reverse(a+1, a+1+n);
    if(a[m]*4*m >= sum){
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}

struct UnionFind {
    int n;
    vector<int> parent;
    UnionFind(int _n=0): n(_n), parent(_n, -1) {}
    int root(int x) {
        if (parent[x] < 0) return x;
        return parent[x] = root(parent[x]);
    }
    bool connect(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
        return true;
    }
    int group() {
        int res = 0;
        for (int i=0;i<n;++i) if (root(i) == i) res++;
        return res; 
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -parent[root(x)]; }
};


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

    vector<P> e;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        e.emplace_back(a, b);
    }

    int ans = 0;
    rep(i, m) {
        UnionFind tree(n);
        rep(j, m) if (i != j) tree.connect(e[j].first, e[j].second);
        if (tree.group() > 1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())
 
#define ALL(a)  (a).begin(),(a).end()
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	vector<int> ret(N);
	string pre;
	REP(i, N){
		string s;
		cin >> s;
		if(s == "AB"){
			if(A == 0 && B == 0){
				if(pre == "BC" && ret[i - 1] == 'C') { B += 2; C -= 2; ret[i - 1] = 'B'; }
				if(pre == "AC" && ret[i - 1] == 'C') { A += 2; C -= 2; ret[i - 1] = 'A'; }
			}
			if(A < B) { A++; B--; ret[i] = 'A'; }
			else 	  { A--; B++; ret[i] = 'B'; }
		}
		if(s == "BC"){
			if(B == 0 && C == 0){
				if(pre == "AB" && ret[i - 1] == 'A') { B += 2; A -= 2; ret[i - 1] = 'B'; }
				if(pre == "AC" && ret[i - 1] == 'A') { C += 2; A -= 2; ret[i - 1] = 'C'; }
			}
			if(B < C) { B++; C--; ret[i] = 'B'; }
			else      { B--; C++; ret[i] = 'C'; }
		}
		if(s == "AC"){
			if(A == 0 && C == 0){
				if(pre == "AB" && ret[i - 1] == 'B') { A += 2; B -= 2; ret[i - 1] = 'A'; }
				if(pre == "BC" && ret[i - 1] == 'B') { C += 2; B -= 2; ret[i - 1] = 'C'; }
			}
			if(A < C) { A++; C--; ret[i] = 'A'; }
			else      { A--; C++; ret[i] = 'C'; }
		}
		if(A < 0 || B < 0 || C < 0){
			cout << "No" << endl;
			return 0;
		}
		pre = s;
	}
 
	cout << "Yes" << endl;
	REP(i, N) cout << (char)ret[i] << endl;
 
	return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pii pair<int,int>
using namespace std;
int main()
{
    fast;
  
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans = n / (a+b);
    ll rem = n - ((a+b) * ans);
    ans *= a;
    ans += min(rem, a);
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;



int main(){
  lint N;
  string s;
  cin>>N;
  cout<<N*N;
}

Measured memory_bytes: 256
object Main extends App{
  import scala.io.StdIn.readLine
  
  val _ = readLine
  val a = readLine.split(" ").map(_.toLong) 
  
  def shift(x:Long):Long ={
  	def shiftRe(acc:Long,x:Long):Long =
    {
    if(x % 2 == 0) shiftRe(acc + 1,x / 2);
      else acc
    }
    shiftRe(0,x)
  }
  
  println(a.map(shift(_)).min.toString)
}


Measured memory_bytes: 54884
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <numeric>

#define REP(i, n) for(int i = 0;i < (n); i++)
#define REP2(i, x, n) for(int i = (x); i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;

//================================================

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N, yen = 100000;
	cin >> N;

	REP(i, N) {
		yen *= 1.05;
		if (yen % 1000 != 0) {
			yen += 1000;
			yen -= yen % 1000;
		}
	}

	cout << yen << "\n";
	return 0;
}

Measured memory_bytes: 3136
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
MOD = 10**9 + 7
N,M,K = map(int,input().split())
# lisA = list(map(int,input().split()))
arrA = np.array([0] + list(map(int,input().split())))
arrB = np.array([0] + list(map(int,input().split())))

arrA = np.cumsum(arrA,dtype="int64")
arrB = np.cumsum(arrB,dtype="int64")

# memo = np.add.outer(arrA,arrB) <= K
j = M
ans = 0
for i in range(N+1):
    while j >= 0:
        if arrA[i]+arrB[j] <= K:
            ans = max(i+j,ans)
            break
        j -= 1

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

int main() {
	string s;
	cin>>s;
	
	REP(i,(1<<3)){
		int sum=s[0]-'0';
		REP(j,3){
			if(1&(i>>j)) sum+=s[j+1]-'0';
			else sum-=s[j+1]-'0';
		}
		//cout<<sum<<endl;
		
		if(sum==7){
			string ans="";
			ans+=s[0];
			REP(k,3){
				if(1&(i>>k)){
					ans+="+";
					ans+=s[k+1];
				}else{
					ans+="-";
					ans+=s[k+1];
				}
			}
			ans+="=7";
			cout<<ans<<endl;
			return 0;
		}
	}
}//bit全探索.

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    bool res = false;
    for (int i = 0; i <= x; i++) {
        res = res || 2 * i + 4 * (x - i) == y;
    }

    cout << (res ? "Yes" : "No") << endl;
}


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

int main() {
  ll n; cin >> n;
  ll h;
  if(n<10) h=n;
  else if(n>=10 && n<100) h=n%10;
  else if(n>=100) h=(n%100)%10;
  
  if(h==2 || h==4 || h==5 || h==7 || h==9) cout << "hon" << endl;
  else if(h==0 || h==1 || h==6 || h==8) cout << "pon" << endl;
  else if(h==3) cout << "bon" << endl;
    
  return 0;
}






Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

int main()
{
  string s;cin >> s;
  int n=s.size();
  vector<vector<mint>> dp(n+1,vector<mint>(2));
  dp[0][0].x = 1;
  rep(i,n){
    if(s[i]=='0'){
      dp[i+1][0] += dp[i][0];
      dp[i+1][1] += dp[i][1]*(mint)3;
    }
    else{
      dp[i+1][0] += dp[i][0]*(mint)2;
      dp[i+1][1] += dp[i][0]+dp[i][1]*(mint)3;
    }
  }

  mint res = dp[n][0]+dp[n][1];
  cout << res.x << "\n";
  
  return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

const int MXN=300;
long double dp[MXN+1][MXN+1][MXN+1];
bool vis[MXN+1][MXN+1][MXN+1];
int n;
long double solve(int a,int b,int c){
	if( a==0 && b==0 && c==0 )return 0;
	if( a < 0 || b < 0 || c < 0 )return 0;
	if( vis[a][b][c] ){
		return dp[a][b][c];
	}
	vis[a][b][c]=1;
	dp[a][b][c]=0;
	long double tot = a + b + c ;
	dp[a][b][c]+=((long double)n/(long double)tot);
	dp[a][b][c]+=((long double)a/(long double)tot)*solve(a-1,b,c);
	dp[a][b][c]+=((long double)b/(long double)tot)*solve(a+1,b-1,c);
	dp[a][b][c]+=((long double)c/(long double)tot)*solve(a,b+1,c-1);
	return dp[a][b][c];
}
	
int32_t main()
{
   IOS
   cin>>n;
   vector<int>v(4);
   for(int i=0;i<n;i++)
   {
	   int x;cin>>x;
	   v[x]++;
   }
   memset(vis,false,sizeof(vis));
   for(int i=0;i<=MXN;i++)
   for(int j=0;j<=MXN;j++)
   for(int k=0;k<=MXN;k++)
   dp[i][j][k]=0;
   cout << fixed << setprecision(10)  << solve(v[1],v[2],v[3]) << endl;
   
   
	  
}


Measured memory_bytes: 453120
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 ans = 1;
		for (int i = 0; i < n; i++) {
			ans = Math.min(ans * 2, ans + k);
		}

		System.out.println(ans);

		sc.close();
	}
}


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

class UnionFind {
public:
  vector<int> rank, p, num_of_nodes;
  //rank : 各ノードxを根としたときの木の高さをrank[x]とする
  //p : 各ノードxの親をp[x]とする

  UnionFind() {} // Default constructor

  UnionFind(int size = 0) {
    rank.resize(size, 0);
    p.resize(size, 0);
    num_of_nodes.resize(size, 1);
    for (int i = 0; i < size; i++) makeSet(i);
  }

  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }

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

  void unite(int x, int y) {
    link(root(x), root(y));
  }

  void link(int x, int y) {
    //低い木を高い木に結合する
    if (rank[x] > rank[y]) { // xのほうが高い木 : xにyを統合
      num_of_nodes[x] += num_of_nodes[y];
      p[y] = x;
    }
    else if (rank[y] > rank[x]){ // yのほうが高い木 : yにxを統合
      num_of_nodes[y] += num_of_nodes[x];
      p[x] = y;
    }
    else {
      num_of_nodes[y] += num_of_nodes[x];
      p[x] = y;
      rank[y]++;
    }
  }

  int root(int x) {
    if (x != p[x]) { // if x is not root
      p[x] = root(p[x]);
    }
    return p[x];
  }

  int size(int x) {
    return num_of_nodes[root(x)];
  }

private:

};

int main() {
  int n, a, b, q;
  int t;

  cin >> n >> q;
  UnionFind ds = UnionFind(n);
  for (int i = 0; i < q; i++) {
    cin >> t >> a >> b;

    if (t == 0) ds.unite(a, b);
    if (t == 1) {
      if (ds.same(a, b)) cout << 1 << endl;
      else cout << 0 << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
    x.erase(unique(x.begin(), x.end()), x.end());
}
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    ll d, t, s;
    cin >> d >> t >> s;
    cout << (t * s >= d ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int w, n, x[50000], dp[50010];
ll s[50010];

inline int cost(int i, int j){
	assert(i + 1 < j);
	ll len = s[j] - s[i];
	if(len + j - i - 1 > w) return inf;
	return (w - len + j - i - 2) / (j - i - 1);
}
const int MX = 65536;
int dat[2 * MX], same[2 * MX];

inline int query(int a, int b, int k, int l, int r){
	if(b <= l || a >= r) return inf;
	if(a <= l && r <= b) return dat[k];
	if(same[k]){
		same[k] = 0;
		same[2 * k + 1] = same[2 * k + 2] = 1;
		dat[2 * k + 1] = min(dat[2 * k + 1], dat[k]);
		dat[2 * k + 2] = min(dat[2 * k + 2], dat[k]);
	}
	return min(query(a, b, k * 2 + 1, l, (l + r) / 2),
		query(a, b, k * 2 + 2, (l + r) / 2, r));
}
inline void fix(int a, int b, int k, int l, int r, int x){
	if(b <= l || a >= r) return;
	if(a <= l && r <= b){
		same[k] = 1;
		dat[k] = min(dat[k], x);
		return;
	}
	if(same[k]){
		same[k] = 0;
		same[2 * k + 1] = same[2 * k + 2] = 1;
		dat[2 * k + 1] = min(dat[2 * k + 1], dat[k]);
		dat[2 * k + 2] = min(dat[2 * k + 2], dat[k]);
	}
	fix(a, b, k * 2 + 1, l, (l + r) / 2, x);
	fix(a, b, k * 2 + 2, (l + r) / 2, r, x);
}
int main(){
	int cs = 0;
	while(cin >> w >> n, w){
		rep(i, n){
			cin >> x[i];
			s[i + 1] = s[i] + x[i];
			dp[i + 1] = inf;
		}
		rep(i, MX * 2) dat[i] = inf, same[i] = 1;
		
		dp[0] = 1;
		int j = 0, ans = inf, co;
		rep(i, n){
			dp[i] = min(dp[i], query(i, i + 1, 0, 0, MX));
			
			if(i >= n - 1 || cost(i, n) < inf){
				ans = min(ans, dp[i]);
				continue;
			}
			while(j <= i + 1) j++;
			
			int lo = j - 1, hi = n + 1, mid;
			while(lo + 1 < hi){
				mid = (lo + hi) / 2;
				if(cost(i, mid) < inf) lo = mid;
				else hi = mid;
			}
			while(j <= n){
				if((co = cost(i, j)) >= inf) break;
				if(co < dp[i]) break;
				dp[j] = min(dp[j], max(dp[i], co));
				j++;
			}
			fix(j, hi, 0, 0, MX, dp[i]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
ll fac[200005], inv[200005];
ll exp(ll a, ll x){
    if (x ==0 ) return 1ll;
    ll p = exp(a,x/2);
    p *= p;
    p %= mod;
    if (x & 1){
        p *= a;
        p %= mod;
    }
    return p;
}
ll nck(int n, int k){
    return ((fac[n]*inv[n-k])%mod*inv[k])%mod;
}
int n,m,k;
int main(){
    scanf("%d%d%d",&n,&m,&k);
    fac[0] = inv[0] = 1;
    for (int i = 1; i <= 200000; i++){
        fac[i] = (fac[i-1]*i)%mod;
        inv[i] = exp(fac[i],mod-2);
    }
    ll ans = 0;
    for (int i = 0; i <= k; i++){
        ll res = (m*exp(m-1,n-i-1))%mod;
        res = (res*nck(n-1,i))%mod;;
        ans += res;
        ans %= mod;
    }
    printf("%lld",ans);
}


Measured memory_bytes: 6900
// I need some holiday
// But I don't wish that everyday is holiday
// Because I didn't bear the pain
// Because it wasn't a true freedom
//         ——『イヤホンと蝉時雨』·Orangestar

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned int UI;
typedef pair<int, int> pii;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define MP make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline int chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline int chkmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template<typename T> inline T sqr(const T &val) { return val * val; }

namespace fastIO
{
	const int MAX_BUFFER_SIZE = 1 << 16;

	char buffer[MAX_BUFFER_SIZE], *cur = buffer, *ed = buffer;

	inline char getc() { return cur == ed && (ed = (cur = buffer) + fread(buffer, 1, MAX_BUFFER_SIZE, stdin), cur == ed) ? EOF : *cur++; }
}
using fastIO::getc;

template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getc());
	for(; !isdigit(ch); ch = getc()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getc()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

inline char *read_str(char *s)
{
	register char ch(getc());
	while(!isgraph(ch)) ch = getc();
	for(; isgraph(ch); ch = getc()) *s++ = ch;
	*s = '\0';
	return s;
}

// END tpl.

const int MAXN = (int) 1e5;

int n;

int a[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i) a[i] = read<int>();
}

inline void solve()
{
	char hito[2][10] = {"First", "Second"};

	for(int slf = 0; ; slf ^= 1)
	{
		int cnt[2] = {0, 0}, fg = 0;
		for(int i = 1; i <= n; ++i) ++cnt[a[i] % 2], fg |= a[i] == 1;
		if(fg) { puts(hito[cnt[0] & 1 ? slf : !slf]); return; }

		if(cnt[0] % 2 == 1 && cnt[1] >= 1) { puts(hito[slf]); return; }
		if(cnt[0] % 2 == 0 && cnt[1] >= 2) { puts(hito[!slf]); return; }
		if(cnt[0] % 2 == 0 && cnt[1] == 1)
		{
			for(int i = 1; i <= n; ++i) if(a[i] % 2 == 1) --a[i];
			int d = 0;
			for(int i = 1; i <= n; ++i) d = __gcd(d, a[i]);
			for(int i = 1; i <= n; ++i) a[i] /= d;
		}
	}
}

int main()
{
#ifdef K_ON
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}




Measured memory_bytes: 640
import java.util.*;
public class Main {
  
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char prev = 'x';
    for (int i = 0; i < S.length(); i++) {
      char c = S.charAt(i);
      if (prev == c) {
        System.out.println("Bad");
        return;
      }
      prev = c;
    }
    System.out.println("Good");
  }  
}


Measured memory_bytes: 22868
#include <iostream>


using namespace std;

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    if(A >= B && A >= C){
        cout << A*10 + B + C << endl;
    }else if(B >= A && B >= C){
        cout << B*10 + A + C << endl;
    }else{
        cout << C*10 + A + B << endl;
    }


    return 0;

}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>

using namespace std;


class B {
	int N;
public:
	void solve()
	{
		cin >> N;
		int base{ (int)sqrt(N) };
		
		cout << (base * base) << endl;
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

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



int main(){
    ll N, M; cin >> N >> M;
    vector<ll> H(N); for(int i = 0; i < N; i++) cin >> H[i];
    vector<vector<ll>> G(N);
    for(int i = 0; i < M; i++){
        int a, b; cin >> a >> b; a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ll ans = 0;
    for(int i = 0; i < N; i++){
        bool flag = true;
        for(auto x : G[i]) if(H[x] >= H[i]) {
            flag = false;
            break;
        }

        if(flag)ans++;
    }
    cout << ans << endl;


}


Measured memory_bytes: 9804
import collections

n = int(input())
A = list(map(int, input().split()))

L, R = [], []

for i in range(n):
    L.append(i+1+A[i])
    R.append(i+1-A[i])

cl = collections.Counter(L)
cr = collections.Counter(R)

ans = 0

for c in cl:
    ans += cl[c] * cr[c]

print(ans)


Measured memory_bytes: 63372
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
//#include <windows.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VVC = vector<VC>;
using VS = vector<string>;
using VVS = vector<VS>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
const int INF = 2e9;
const LL MOD = 1e9 + 7;

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

void END(){cout << 1 << endl; exit(0);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  VPII data(m);
  REP(i, m)
  {
    int a, b;
    cin >> a >> b;
    data[i] = {b, a};
  }
  SORT(data);
  int l = 0, ans = 0;
  REP(i, m)
  {
    int right = data[i].first, left = data[i].second;
    if (left >= l)
    {
      ans++;
      l = right;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;

int main(){
	ll N,M;
	cin >> N >> M;

	ll ans = 0;
	if(N <= M/2){
		ans += N;
		M -= 2*N;
		ans += M/4;
	}
	else{
		ans += M/2;
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 636
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);
    int n;
    cin >> n;
    int ans[200010];
    rep(i, n + 1) ans[i] = -1;
    int a[200010];
    rep(i, n) cin >> a[i + 1];
    for (int i = n; i >= 1; --i) {
        int sum = 0;
        for (int j = i * 2; j <= n; j += i) {
            if (ans[j] == -1) ans[j] = 0;
            else sum ^= ans[j];
        }
        ans[i] = sum ^ a[i];
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++i) cnt += ans[i];
    cout << cnt << endl;
    for (int i = 1; i <= n; ++i) if (ans[i]) cout << i << endl;

    return 0;
}



Measured memory_bytes: 2560
#include <cstdio>
int main()
{
	long long s;
	scanf("%lld", &s);
	long long x3 = (1000000000 - s % 1000000000) % 1000000000;
	long long y3 = (s + x3) / 1000000000;
	printf("0 0 1000000000 1 %lld %lld\n", x3, y3);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    void calc()
    {
        Scanner cin = new Scanner();
        while (true)
        {
            int N = cin.nextInt();
            int R = cin.nextInt();
            if (N == 0) break;
            int[] P = new int[R];
            int[] C = new int[R];
            for (int i = 0; i < R; i++)
            {
                P[i] = cin.nextInt() - 1;
                C[i] = cin.nextInt();
            }

            int top = 0;
            for (int i = R - 1; i >= 0; i--)
            {
                if (C[i] > top)
                {
                    top += P[i];
                }
                else if (P[i] + C[i] > top)
                {
                    top -= C[i];
                }
            }
            Console.WriteLine(N - top);
        }

    }
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        do
        {
            s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
        } while ((s.Length == 1 && s[0] == "") || s.Length == 0);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;
using tTree=__gnu_pbds::tree< ll , __gnu_pbds::null_type, less< ll >, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n;
  cin>>n;
  vector<ll> h(n);
  rep(i,n) cin>>h[i];

  vector<ll> l(n);
  rep(i,n){
    if(i==0) l[i]=h[i];
    else l[i]=max(l[i-1],h[i]);
    if( l[i]-h[i]>1 ){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;


  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 1792