akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void){
    int n, a, b, x;
    while(scanf("%d%d%d", &n, &a, &b) && n+a+b){
        int dp[1000001], ans = 0;
        for(x = 0; x <= n; x++){
            dp[x] = 0;
        }
        dp[0] = 1;
        for(x = 0; x <= n; x++){
            if(!dp[x]) ++ans;
            else{
                if(x+a <= n) dp[x+a] = 1;
                if(x+b <= n) dp[x+b] = 1;
            }
        }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 4504
n,k = map(int,input().split())
p = [int(i) for i in input().split()]

a = sum(p[0:k])
m = a
o = 0
for i in range(n - k):
    a += p[i + k] - p[i]
    #print(i, p[i + k], p[i], a)
    if a > m:
        m = a
        o = i + 1
'''
q = []
for i in range(n):
    q.append((p[i] + 1) / 2)
'''
ans = 0
#for i in range(k - 1, n):
#tmp = 0
for j in range(o, o + k):
    ans += (p[j] + 1) / 2

print(ans)


Measured memory_bytes: 25188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
typedef complex<double> P;
double dot(P a, P b){ //内積
    return (a.real() * b.real() + a.imag() * b.imag());
}

double cross(P a, P b){ //外積
    return (a.real() * b.imag() - a.imag() * b.real());
}

bool is_orth(P a1, P a2, P b1, P b2){ //垂直か
    return EQ(dot(a1 - a2, b1 - b2), 0.0);
}

bool is_para(P a1, P a2, P b1, P b2){ //平行か
    return EQ(cross(a1 - a2, b1 - b2), 0.0);
}

bool is_online(P a, P b, P c){ //cが線分上か
    return (abs(a-c) + abs(c-b) < abs(a-b) + EPS);
}

bool distance_lp(P a, P b, P c){ //直線abと点cの距離
    return abs(cross(b-a, c-a)) / abs(b-a);
}

bool is_intersect(P a1, P a2, P b1, P b2){ //線分の交差判定
    return (cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS) && 
        (cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS);
}

P intersect_pos(P a1, P a2, P b1, P b2){ //直線同士の交点
    P a = a2 - a1;
    P b = b2 - b1;
    return a1 + a * cross(b, b1 - a1) / cross(b, a);
}





int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    P p1(x1,y1), p2(x2,y2), p12(x2-x1, y2-y1);
    ll q;
    cin >> q;
    P n = p12 * P(0,1);
    while(q--){
        double x,y;
        cin >> x >> y;
        P p(x,y);
        P ans = intersect_pos(p1, p2, p, p+n);
        ans *= 2;
        ans -= p;
        cout << setprecision(16) << ans.real() << " " << ans.imag() << endl;

    }
}


Measured memory_bytes: 3312
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  string s,t;cin >> s >> t;
  rep(i,N) cout << s[i] << t[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	int H,W;
	cin >> H >> W;
	string S[H];
	for(int i=0;i<H;i++) cin >> S[i];
	
	int dx[4]{1,0,-1,0};
	int dy[4]{0,-1,0,1};
	
	bool chk = true;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(S[i][j] != '#') continue;
			bool chk2 = false;
			for(int t=0;t<4;t++){
				int ny = i + dy[t];
				int nx = j + dx[t];
				if(InRange(ny, 0, H) && InRange(nx, 0, W) && S[ny][nx] == '#') chk2 = true;
			}
			if(!chk2) chk = false;
		}
	}
	
	cout << (chk ? "Yes" : "No") << endl;
	
	
    return 0;
}

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

void edit(char* s,int* o){
    char ans[10];
    int count = 0;
    for (int i = 0; i < *o; ++i) {
        if (s[i] == '0'){
            ans[count] = '0';
            count++;
        } else if (s[i] == '1'){
            ans[count] = '1';
            count++;
        } else if (s[i] == 'B'){
            if (count > 0) {
                count--;
            }
        }
    }
    for (int j = 0; j < count; ++j) {
        cout << ans[j];
    }
}

int main() {
    string s;
    cin >> s;
    int o = s.size();
    edit(&s[0],&o);
    return 0;
}

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

int main() {
	
	int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
	int  ans;
	if (a == 0) ans = 1;
	else if (b == 0) ans = 2;
	else if (c == 0) ans = 3;
	else if (d == 0) ans = 4;
	else if (e == 0) ans = 5;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  Array.to_list as_
  |> List.sort compare
  |> List.fold_left (fun (acc, prev) a ->
      match prev with
      | None -> (acc, Some a)
      | Some a' ->
          if a = a' then (a :: acc, None)
          else (acc, Some a)) ([], None)
  |> fst
  |> (function (n :: m :: _) -> n * m | _ -> 0)
  |> Printf.printf "%d\n"

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
int main(void){
    int n,h;
    cin>>n>>h;
    vector<int> b(n);
    int d=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a>>b[i];
        d=max(d,a);
    }
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    long long ans=0;
    for(int i=0;i<n;i++){
        if(b[i]<d)break;
        h-=b[i];
        ans++;
        if(h<=0){
            cout<<ans<<endl;
            return 0;
        }
    }
    ans+=h/d;
    if(h%d!=0)ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
import math
n, m = map(int, input().split())
MOD = 10**9 + 7

if abs(n-m) > 1:
    print(0)
    exit()

if n == m:
    print(math.factorial(n) * math.factorial(m) * 2 % MOD)
else:
    print(math.factorial(n) * math.factorial(m) % MOD)


Measured memory_bytes: 83840
import fractions
import functools
import sys

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

lcm_A = lcm_list(A)

B = [None]*N
B = [lcm_A//a for a in A]
print(sum(B)%(10**9+7))

Measured memory_bytes: 264700
#include <iostream>
int main()
{
    int N,A;
    std::cin >> N;
    std::cin >> A;

    int Needed_1yen = N % 500;

    if(Needed_1yen <= A)
	std::cout << "Yes" << std::endl;
    else
	std::cout << "No" << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define si(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define sl(a) scanf("%ld",&a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%ld\n",a)
#define pll(a) printf("%lld\n",a) 
#define sc(a) scanf("%c",&a)a
#define pc(a) printf("%c",a)
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF INT_MAX
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define VI vector<int>
#define VL vector<ll>
#define PI pair<int,int>
#define PL pair<ll,ll>
long double PIE=acos(-1);
//////////////////////////////////////////////////////////////
const ll N=1e5+5;
ll Ans=1;
bool done[1000009];
vector < ll > primes;

void FindPrime(ll N)
{
    done[1] = 1;
    for(int i=2;i<=N;i++)
	{
        if(done[i]) continue;
        for(int j=i*2;j<=N;j+=i)
		{
            done[j] = 1;
        }
        primes.push_back(i);
    }
}

ll solve(ll Num)
{
    for(int i=0;i<primes.size();i++)
	{
    	int p=primes[i];
        if(p*p*p > Num) break;
        ll Count = 1;
        while(Num%p == 0)
		{
            Num /= p,Count++;
        }
        Ans *= Count;
    }
    ll sq = (ll)sqrt(Num);
    if(!done[Num]) 
	Ans *= 2;
    else if(sq*sq == Num && !done[sq]) 
	Ans *= 3;
    else if(Num != 1) 
	Ans *= 4;
    return Ans;
}


ll fact[N], invfact[N];



ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

ll modinv(ll k)
{
	return pow(k, mod-2, mod);
}


ll nCr(ll x, ll y)
{
	if(y>x)
		return 0;
	ll num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}

void initinv()
{
	fact[0]=1;
	fr(i,1,N)
	{
		fact[i]=(i*fact[i-1])%mod;
	}
	invfact[N]=modinv(fact[N]);
	for(int i=N-1;i>=1;i--)
	{
		invfact[i]=((i+1)*invfact[i+1])%mod;
	}
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

int main()
{
	ll n,d;
	cin>>n>>d;
	d=d*d;
	int c=0;
	fr(i,1,n)
	{
		ll x,y;
		cin>>x>>y;
		ll temp=x*x+y*y;
		if(temp<=d)
		c++;
	}
	cout<<c;
	return 0;
}



//eVTWvt22KTVSm@v

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)
int main(){
    string n; cin>> n;
    int sum=0;
    for(int i=0; i<n.size(); i++){
        int a = n[i] - '0';
        sum += a;
    }
    if(sum % 9 == 0) cout<< "Yes" << endl;
    else cout<< "No" << endl;
}


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

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree < int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define smallk order_of_key
#define kth find_by_order
*/

#define nl '\n'
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back

typedef long long ll;

const int N = (int)1e5 + 123;
const int M = 1e9 + 7;
const int K = 500;

int n, m;
char a[1011][1011];
int dp[1011][1011];
int main(){

    //ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

    #ifdef LOCAL
        freopen("B.txt", "r", stdin);
    #endif // LOCAL

    cin >> n >> m;
    for(int i = 1; i <= n; ++i){
        a[i][0] = '#';
    }
    for(int i = 1; i <= m; ++i){
        a[0][i] = '#';
    }
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j){
            cin >> a[i][j];
        }
    }
    dp[1][1] = 1;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j){
            if(a[i][j] != '#'){
                dp[i][j] += dp[i - 1][j] % M+ dp[i][j - 1] % M;
                dp[i][j] %= M;
            }
        }
    }
    cout << dp[n][m] % M;
    return 0;
}



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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;

int N, K;
int A[2][MAX_N];

signed main()
{
  cin >> N >> K;
  REP(n,N) {
    cin >> A[0][n];
  }

  int now, next;
  REP(k,min((LL)50,K)) {
    now = k%2;
    next = (k+1)%2;
    
    memset(A[next], 0, sizeof(A[next]));

    REP(n,N) {
      int l = max((LL)0,n-A[now][n]);
      int r = min((LL)N, n+A[now][n]+1);
      A[next][l]++;
      A[next][r]--;
    }
    REP(n,N) {
      A[next][n+1] += A[next][n];
    }
  }

  REP(n,N) {
    if (0 < n) {
      cout << " ";
    }
    cout << A[next][n];
  }
  cout << endl;

  return 0;
}


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


int main()
{
	long long n, m, l, a[100][100] = {}, b[100][100] = {}, c[100][100] = {};
	cin >> n >> m >> l;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < m;j++)
			cin >> a[i][j];
	}
	for (int I = 0;I < m;I++) {
		for (int J = 0;J < l;J++)
			cin >> b[I][J];
	}

	for (int z = 0;z < n;z++) {
		for (int y = 0;y < l;y++) {
			for (int x = 0;x <m ;x++) {
				c[z][y] = c[z][y] + a[z][x] * b[x][y];
			}
		}
	}

	for (int d = 0;d < n;d++) {
		for (int e = 0;e < l;e++) {
			if (e != l - 1)
				cout << c[d][e] << " ";
			else
				cout << c[d][e];
		}
		cout << endl;
	}
    return 0;
}


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

void Main()
{
  string S; cin >> S;
  if (S == "ARC") cout << "ABC" << endl;
  else cout << "ARC" << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

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

ll dp[700][700];
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	ll n, m, a = 0, b = 0, c = 0, cnt = 0, ans = 0;
	cin >> n;
	a = modpow(10, n);
	b = modpow(9, n);
	c = modpow(8, n);
	ans = a - b - b + c; ans %= mod;
	while (ans < 0) { ans += mod; }
	cout << ans << endl;
	return 0;
}

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

int main(){
  
  int A, B, C, D;
  
  cin >> A >> B >> C >> D;
  
  while( (A > 0 ) && (C > 0)){
    
    C -= B;
    
    if( C <= 0){
      
      cout << "Yes" << endl;
      
      break;
    }
    
    A -= D;
    
     if( A <= 0){
      
      cout << "No" << endl;
      
      break;
    }
  }
}   

Measured memory_bytes: 3620
def resolve():
    # nCk = n! / n!(n-k)! のテーブル作成
    def COMinit(n, MOD):
        fact = [1, 1]
        fact_inv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fact.append((fact[-1] * i) % MOD)
            inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
            fact_inv.append((fact_inv[-1] * inv[i]) % MOD)
        return fact, fact_inv

    # 二項係数計算
    def Combination(n, k, MOD=10 ** 9 + 7):
        fac, finv = COMinit(n, MOD)
        if n < k: return 0
        if n < 0 or k < 0: return 0
        ret = fac[n] * finv[k] * finv[n - k] % MOD
        return ret

    #指数:exponent
    def dic_factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
            if temp % i == 0:
                cnt = 0
                while temp % i == 0:
                    cnt += 1
                    temp //= i
                arr.append([i, cnt])
        if temp != 1:
            arr.append([temp, 1])
        if arr == []:
            arr.append([n, 1])
        return arr

    MOD = 10**9+7
    N, M = map(int, input().split())
    if M==1:
        print(1)
        return
    
    fact = dic_factorization(M)
    ans = 1
    for v in fact:
        ans *= Combination(N+v[1]-1, v[1])
        ans %= MOD

    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 17100
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

struct edge{int to, cost; };

int N;
int M;
int L[200000];
int R[200000];
int D[200000];

vector<edge> G[200000];
long long d[200000];
bool changed[200000];


bool dfs(int s){
	changed[s] = true;
	//printf("dfs(%d)\n", s);
	for(int i=0;i<G[s].size();i++){
		struct edge e = G[s][i];
		int p = e.to;
		long long tmp = d[s] + e.cost;
		if(changed[p]){
			if(tmp != d[p]) return false;
			continue;
		}else{
			d[p] = tmp;
			if(!dfs(p)) return false;
		}
		//printf("e.to:%d d[e.to]%lld\n",e.to,d[e.to]);
	}
	return true;
}


int main(){
	scanf("%d %d", &N, &M);
	for(int i=0;i<M;i++) scanf("%d %d %d", &L[i],&R[i],&D[i]);
	for(int i=0;i<M;i++){
		struct edge e;
		L[i]--;
		R[i]--;
		e.cost = D[i];
		e.to = R[i];
		G[L[i]].push_back(e);
		//
		struct edge e2;
		e2.cost = -D[i];
		e2.to = L[i];
		G[R[i]].push_back(e2);
		//
	}
	for(int i=0;i<N;i++) changed[i] = false;

	for(int i=0;i<N;i++){
		if(changed[i]) continue;
		d[i] = 0;
		if(!dfs(i)){
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");
	return 0;
}


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

class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String a = buffer.readLine();
        String b = buffer.readLine();
        int cnt = 0;
        for (int pos = 0; pos < a.length(); pos++) {
            if (a.charAt(pos)!=b.charAt(pos))
                cnt++;
        }
        sb.append(cnt);
        System.out.println(sb);
    }
}


Measured memory_bytes: 37132
from itertools import product
from copy import deepcopy
H, W, K = map(int, input().split())
c = []
for _ in range(H):
    c.append(list(input()))
ans = 0
for h in range(2**H):
    for w in range(2**W):
        tmp = deepcopy(c)
        for i in range(H):
            for j in range(W):
                if 1&(w>>j) or 1&(h>>i):
                    tmp[i][j] = "?"
        cnt = 0
        for i in range(H):
            cnt += tmp[i].count("#")
        if cnt==K:
            ans += 1
print(ans)

Measured memory_bytes: 9304
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter
from itertools import accumulate

n, *a = map(int, read().split())
ans = 0
for v in Counter([0] + list(accumulate(a))).values():
    ans += v * (v - 1) // 2
print(ans)


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

int main()
{
  ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
  ll n, m;
  cin >> n >> m;
  
  if(n >= m/2)
    cout << m/2 << endl;
  else
    cout << n+(m-2*n)/4 << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_sum = a[0]
b_sum = sum(b)
maxer = a_sum + b_sum
for i in range(1,n):
  a_sum += a[i]
  b_sum -= b[i-1]
  if a_sum+b_sum > maxer:
    maxer = a_sum+b_sum
print(maxer)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <string.h>
#include <string>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    for (int i=0; i<n; i++) cin >> p[i];
    for (int i=0; i<n; i++) cin >> q[i];
    int pp = 1, qq = 1;
    while (prev_permutation(p.begin(), p.end())) pp++;
    while (prev_permutation(q.begin(), q.end())) qq++;
    cout << abs(pp - qq) << '\n';
    return 0;
}

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

int main() {
  int n,r; cin>>n>>r;
  if (n>=10) cout<<r<<endl;
  else cout<<r+(10-n)*100<<endl;
}


Measured memory_bytes: 256
N,M,R=map(int, input().split())
r=list(map(int, input().split()))
ABC=[list(map(int,input().split())) for i in range(M)]
c=[[10**9]*N for i in range(N)]
for i,j,w in ABC:
    c[i-1][j-1]=w
    c[j-1][i-1]=w
mat=[]
for start in r:
    start-=1
    d=[10**9]*N
    d[start]=0
    prev=[-1]*N
    from heapq import heappop,heappush
    q=[]
    heappush(q,(0,start))
    while len(q)>0:
        u=heappop(q)[1]
        for v in range(N):
            if c[u][v]<10**9:
                temp=d[u]+c[u][v]
                if d[v]>temp:
                    d[v]=temp
                    prev[v]=u
                    heappush(q,(d[v],v))
    m=[]
    for i in range(R):
        m.append(d[r[i]-1])
    mat.append(m)
from itertools import permutations
ans=10**9
for i in permutations(range(R),R):
    a=0
    for j in range(R-1):
        a+=mat[i[j]][i[j+1]]
    ans=min(ans,a)
print(ans)

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

int main() {
	int N;
	cin >> N;
	
	int ans = 0;
	for(int i = 0; i < N; i++){
		int a;
		cin >> a;
		ans += a - 1;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define mo 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int modpow(int a, int p) {
	if (p == 0) return 1;
	if (p % 2 == 0) {

		int halfP = p / 2;
		int half = modpow(a, halfP);

		return half * half % mod;
	}
	else {

		return a * modpow(a, p - 1) % mod;
	}
}



int comb(int a, int b) {
	if (b > a - b) return comb(a, a - b);


	int ansMul = 1;
	int ansDiv = 1;
	for (int i = 0; i < b; i++)
	{
		ansMul *= (a - i);
		ansDiv *= (i + 1);
		ansMul %= mod;
		ansDiv %= mod;
	}

	int ans = ansMul * modpow(ansDiv, mod - 2) % mod;

	return ans;
}

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

	int N, A, B;
	cin >> N >> A >> B;

	cout << (modpow(2, N) - comb(N, A) - comb(N, B)-1+mod+mod)%mod << endl;





	/*
	int ans = 1;
	A++; B++;
	int tmp = 0,tmpp=0;
	eFOR(i,1, N) {
		if (i == B)tmp = ans-1;
		if (i == A)tmpp = ans - 1;
		ans *= 2;
		ans %= mod;
		//cout << ans << endl;
	}
	cout << tmp << endl;
	cout << tmpp << endl;
	//ans -= comb(N, A);
	cout << ((ans - tmp - tmpp) + mod) % mod << endl;
	*/
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
     
    public class Main {
    	public static void main (String[] args) {
    		Scanner sc = new Scanner(System.in);
    		
    		int N = sc.nextInt();
    		
    		int x[] = new int[N];
    		
    		for (int i = 0; i < N; i++) {
    			x[i] = sc.nextInt();
    		}
    		
    		int max = x[0];
    		int min = x[0];
    		
    		for (int i = 0; i < N; i++) {
    			if (max < x[i]) {
    				max = x[i];
    			}
    			
    			if (min > x[i]) {
    				min = x[i];
    			}
    		}
    		
    		System.out.println(max - min);
    		
    		
    		
    	}
    }

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        a--;
    }
    return ans;
}
int main(){
    int n;cin >> n;
    map<int,int> v;
    rep(i,n){
        int a;cin >> a;
        v[a]++;
    }
    ll ans=0;
    for(auto p:v){
        int x = p.first;
        int y = p.second;
        if(y<x) ans += y;
        if(x<y) ans += y-x;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4736
def main():
  N = int(input())
  v = [int(i) for i in input().split()]
  v.sort()
  ans = 0
  for i in range(len(v)-1):
    ans = (ans+v[i+1])/2 if i > 0 else (v[i]+v[i+1])/2
  print(ans)

if __name__ == '__main__':
  main()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vl rui(n+1);  // rui[i+1] : a[0]からa[i]の総和
    rep(i, n) {
        rui[i+1] = rui[i] + a[i];
        rui[i+1] %= mod;
    }

    ll ans = 0;
    for(ll i = n-1; i >= 1; i--) {
        ans += a[i]*rui[i]%mod;
        ans %= mod;
    }

    out(ans);
    re0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool ok = true;
    rep (i, s.size()) {
        if (i > 0 && s[i] != '9') ok = false; 
    }
    int ans = 0;
    ans += (s.size() - 1) * 9;
    if (ok) ans += s[0] - '0';
    else ans += s[0] - '0' - 1;
    cout << ans << endl;
    
    return 0;
}



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

using namespace std;

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

    int count = 0;
    bool p = false;
    bool w = false;
    bool g = false;
    bool y = false;

    for(int i = 0; i < n; i++) {
        if(s[i] == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
}

Measured memory_bytes: 256
AA=list(input())

A=[int(n) for n in AA]
Q=sum(A)
B=Q-2*A[1]
C=Q-2*A[2]
D=Q-2*A[3]
E=Q-2*A[1]-2*A[2]
F=Q-2*A[1]-2*A[3]
G=Q-2*A[1]-2*A[2]-2*A[3]
H=Q-2*A[2]-2*A[3]
if Q==7:
    print(AA[0]+'+'+AA[1]+'+'+AA[2]+'+'+AA[3]+'='+'7')
elif B==7:
    print(AA[0]+'-'+AA[1]+'+'+AA[2]+'+'+AA[3]+'='+'7')
elif C==7:
    print(AA[0]+'+'+AA[1]+'-'+AA[2]+'+'+AA[3]+'='+'7')
elif D==7:
    print(AA[0]+'+'+AA[1]+'+'+AA[2]+'-'+AA[3]+'='+'7')
elif E==7:
    print(AA[0]+'-'+AA[1]+'-'+AA[2]+'+'+AA[3]+'='+'7')
elif F==7:
    print(AA[0]+'-'+AA[1]+'+'+AA[2]+'-'+AA[3]+'='+'7')
elif G==7:
    print(AA[0]+'-'+AA[1]+'-'+AA[2]+'-'+AA[3]+'='+'7')
elif H==7:
    print(AA[0]+'+'+AA[1]+'-'+AA[2]+'-'+AA[3]+'='+'7')

Measured memory_bytes: 9312
N,D,A=map(int,input().split())
D*=2 # 爆発の長さ
X=[None]*N
for i in range(N):
  X[i]=list(map(int,input().split()))

X=sorted(X,key=lambda x:x[0])
lastX=X[-1][0] # 最後のモンスターの場所
from collections import defaultdict
damage=defaultdict(int)
ans=0
for i in range(len(X)):
  x=X[i][0]
  if X[i][1]>0:
    dele=set()
    for d in damage.items():
      if d[0]<x:
        dele.add(d[0])
      else:
        X[i][1]-=d[1]
        if X[i][1]<=0:
          break
    for p in dele:
      del damage[p]
  if X[i][1]>0:
    turn=(X[i][1]+A-1)//A
    if x+D>lastX:
      damage[lastX]+=turn*A
    else:
      damage[x+D]=turn*A
    ans+=turn
print(ans)


Measured memory_bytes: 80600
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int mod = 1e9+7;

int main() {

  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0; i<n; i++) cin >> s[i];
  sort(s.begin(), s.end());
  s.push_back("-");

  vector<long long int> v(5, 0);

  for(int i=0; i<n; i++){
    if( s[i] == s[i+1] ) continue;

    if( s[i][0] == 'M' ) v[0]++;
    if( s[i][0] == 'A' ) v[1]++;
    if( s[i][0] == 'R' ) v[2]++;
    if( s[i][0] == 'C' ) v[3]++;
    if( s[i][0] == 'H' ) v[4]++;
  }
  sort(v.begin(), v.end());

  long long int ans = 0;
  for(int i1=0; i1<5; i1++){
    for(int i2=i1+1; i2<5; i2++){
      for(int i3=i2+1; i3<5; i3++){
        ans += v[i1]*v[i2]*v[i3];
      }
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
#include<numeric>
#include<cstdlib>
#define ll long long int
#define all(x) x.begin(),x.end()
 
 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
#define v vector<long long int> 
#define vv vector< int> 
#define gcd(m,n) __gcd(m,n)
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int> 
#define f(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,n) for (ll i=a ; i<n ;i+=1)
#define fe(d,e) for(auto d:e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
# define N 100005LL
using namespace std;

vector<vector<ll>> graph(200005);
ll visited[200005]; 

void dfs(ll node){
    visited[node]=1;
    cout<<node<<" ";
    for (ll u:graph[node]){
        if(!visited[u])dfs(u);
    }
}



int main(){
    ll n;
    cin>>n;
    if (n>=30)cout<<"Yes\n";
    else cout<<"No\n";


    

}
    


Measured memory_bytes: 7860
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

signed main(void) {
  int i,j;
  int n,a,b;
  string s;
  cin>>n>>a>>b;
  int ans1=a+b*(n-1);
  int ans2=a*(n-1)+b; 
  int c=0;
  cout<<max(c,ans1-ans2+1)<<endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> t(n);
    vector<int> x(n);
    vector<int> y(n);
    rep(i, n) cin >> t[i] >> x[i] >> y[i];
    int ct = 0, cx = 0, cy = 0;
    int dt, dd;
    
    rep(i, n) {
        dt = t[i];
        dd = abs(cx - x[i]) + abs(cy - y[i]);
        
        if (dt < dd) {
            cout << "No" << endl;
            return 0;
        }
        
        if ((dt % 2) != (dd % 2)) {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <queue>
#include <stack>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef long double lld;
typedef vector<int> vi;
#define lowbit(x) (x&-x)
#define fi first
#define se second
#define fin freopen("1.txt","r",stdin);
#define fout freopen("1.txt","w",stdout);
ll mod = 1000000007;
const int maxn = 1000000;


inline int Read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int n, m;

int main() {
	cin >> n >> m;
	cout << n - m + 1;
	return 0;
}






Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
Ps = gets.split.map(&:to_i) #r, s, p
#↓勝ったら貰えるPsのindexにしておく
Ts = gets.chomp.gsub(/s/,'0').gsub(/p/,'1').gsub(/r/,'2').split("").map(&:to_i)

ans = 0
N.times do |i|
  next if Ts[i] == -1
  ans += Ps[Ts[i]]
  if Ts[i] == Ts[i + K] && i < N - K
    Ts[i + K] = -1
  end
end
p ans

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

using namespace std;

typedef long long ll;
typedef double long dl;
typedef pair < int , int > pii;
typedef pair < pii, pii > p2i;
const int maxn = (int) 3e5 + 1;
const int mod = (int) 1e9 + 7;
const ll inf = (ll)1e18;

#define fi first
#define se second
#define acel ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define next continue
#define getsz(x) (int) log10(x)

int n;
ll d;
ll a[maxn], b[maxn], c[maxn], mx1[maxn], mx2[maxn];
ll cur, p[maxn], s[maxn], ans;
int main(){
    cin >> n >> d;
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
        p[i] = p[i - 1] + b[i];
        cur += b[i];
        mx1[i] = max(mx1[i - 1], (cur - a[i]) - a[i]);
    }
    for(int i = n; i >= 1; i--){
        s[i] = s[i + 1] + b[i];
    }
    cur = 0;
    for(int i = 1; i <= n; i++){
        c[i] = d - a[i];
    }
    for(int i = n; i >= 1; i--){
        cur += b[i];
        mx2[i] = max(mx2[i + 1], (cur - c[i]) - c[i]);
    }
    for(int i = 1; i <= n; i++){
        ans = max(ans, max({ p[i] - a[i], s[i] - c[i], p[i] + mx2[i + 1] - a[i], s[i] + mx1[i - 1] - c[i]}) );
    }
    cout << ans;
}


Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  ll a;
  string s;
  cin >> n;
  map<ll, ll> mp;
  for (int i = 0; i < n; i++) {
    int tmp[26] = { };
    cin >> s;
    for (char c : s) {
      tmp[c - 'a']++;
    }
    a=0;
    for (int j = 0; j < 26; j++) {
      a = a * 26LL + tmp[j];
    }
    mp[a]++;
  }
  ll ans = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    int s = it->second;
    ans += (ll) s * (s - 1) / 2;
  }
  cout << ans;
  return 0;
}

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

int main(){
    int N,A;
    cin >> N >> A;
    if(N<A){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
#define int long long
int ans,ans2;
vector<int> r;
main()
{
    int n;
    cin>>n;
	for(int i=1;i*i<=n;i++){
        if(n%i==0){
            r.push_back(i);
            if(n/i!=i)r.push_back(n/i);
        }
    }
    int j=r.size();
    for(int i=0;i<j;i++){
        if(r[i]==1)continue;
        if(n%(r[i]-1)==n/(r[i]-1))ans+=r[i]-1;
    }
    cout<<ans<<endl;
}

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

UL N;
vector<ULL> C[300000];
priority_queue<ULL> Q;

int main(){
  scanf("%u", &N);
  rep(i,N){
    UL M; scanf("%u", &M);
    C[i].resize(M);
    rep(j,M) scanf("%u",&C[i][j]);
  }
  reverse(C,C+N);
  ULL ans = 0;
  rep(i,N){
    for(ULL c : C[i]) Q.push(c);
    if(Q.size()){
      ans+=Q.top();
      Q.pop();
    }
  }
  printf("%llu\n", ans);
  return 0;
}


Measured memory_bytes: 19616
#include <stdio.h>
#define max(p,q)((p)>(q)?(p):(q))

//辺の情報を個別に持つタイプ
int n;
int oya[30];
int ko1[30],ko2[30];

int f(int v,int mode){
	if(mode==0)printf(" %d",v);
	if(ko1[v]!=-1)f(ko1[v],mode);
	if(mode==1)printf(" %d",v);
	if(ko2[v]!=-1)f(ko2[v],mode);
	if(mode==2)printf(" %d",v);
}

int cnt[30];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)oya[i]=-1;
	for(int i=0;i<n;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		ko1[x]=y;
		ko2[x]=z;
		oya[y]=x;
		oya[z]=x;
		cnt[y]++;
		cnt[z]++;
	}
	int root;
	for(int i=0;i<n;i++)if(cnt[i]==0)root=i;
	puts("Preorder");
	f(root,0);
	puts("");
	puts("Inorder");
	f(root,1);
	puts("");
	puts("Postorder");
	f(root,2);
	puts("");
}



Measured memory_bytes: 2036
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
int main(){
  random_device rnd;
  mt19937 mt(rnd());
  int D;
  cin >> D;
  vector<int> c(26);
  for (int i = 0; i < 26; i++){
    cin >> c[i];
  }
  vector<vector<int>> s(D, vector<int>(26));
  for (int i = 0; i < D; i++){
    for (int j = 0; j < 26; j++){
      cin >> s[i][j];
    }
  }
  vector<int> last(26, -1);
  for (int i = 0; i < D; i++){
    int t = min(8, D - i);
    vector<vector<int>> L(26, vector<int>(t, 0));
    for (int j = 0; j < 26; j++){
      for (int k = 0; k < t; k++){
        L[j][k] = c[j] * (i + k - last[j]);
      }
    }
    int mx = 0;
    int a = 0;
    vector<int> best(t);
    vector<vector<int>> L2 = L;
    for (int j = 0; j < 32000; j++){
      vector<int> next(t, 0);
      if (j < 20000){
        for (int k = 0; k < t; k++){
          next[k] = mt() % 26;
        }
      } else if (j < 28000){
        next = best;
        for (int k = 0; k < 3; k++){
          int pos = mt() % t;
          int upd = mt() % 26;
          next[pos] = upd;
        }
      } else {
        next = best;
        for (int k = 0; k < 2; k++){
          int pos = mt() % t;
          int upd = mt() % 26;
          next[pos] = upd;
        }
      }
      int diff = 0;
      for (int k = 0; k < t; k++){
        diff += s[i + k][next[k]];
        for (int l = k; l < t; l++){
          diff += L2[next[k]][l] - (l - k) * c[next[k]];
          L2[next[k]][l] = (l - k) * c[next[k]];
        }
      }
      if (diff > mx){
        mx = diff;
        best = next;
      }
      for (int k = 0; k < t; k++){
        if (L2[next[k]].back() != L[next[k]].back()){
          L2[next[k]] = L[next[k]];
        }
      }
    }
    cout << best[0] + 1 << endl;
    last[best[0]] = i;
  }
}

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

int n, m;
vector<int> edges[100100];
bool vis[100100];
int dp[100100];

int dfs( int node ) {
  if ( vis[node] ) return dp[node];
  vis[node] = 1;
  int res = 0;
  for (auto el: edges[node])
    res = max(res, 1 + dfs(el));
  return dp[node] = res;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    edges[u].push_back(v);
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, dfs(i));
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8320
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = getLine >> readInts >>= print . length . filter odd . map fst . filter snd . flip zip ( cycle [ True, False ] )

Measured memory_bytes: 3728
#include <string>
#include <iostream>
using namespace std;
int main(void) {
	string instr;
	getline(cin, instr);
	for (register int i = 0; i < 19; i++) {
		if (instr.at(i) == ',') {
			instr.at(i) = ' ';
		}
	}
	cout << instr;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);
        final int iNum = sc.nextInt();
        String sResult;
        if (iNum < 1200) {
            sResult = "ABC";
        } else if (iNum < 2800) {
            sResult = "ARC";
        } else {
            sResult = "AGC";
        }
        System.out.print(sResult);
    }
}


Measured memory_bytes: 21844
//https://atcoder.jp/contests/agc009/tasks/agc009_a
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll N; cin>>N;
    vector<ll> an(N),bn(N);
    REP(i,N){
        cin>>an[i];
        cin>>bn[i];
    }
    ll ans=0;
    for(ll i=N-1;i>=0;--i){
        ll a=an[i]+ans;
        ll b=bn[i];
        ll r=(a+b-1)/b;
        ans += r*b-a;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
 class Main {
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        int n=scan.nextInt();
        boolean flag=false;
        while(n!=0){
            int dig=n%10;
            if(dig==7){
                flag=true;
            }
            n/=10;
        }
        if(flag){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
    
        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
    
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
    
        int nextInt()
        {
            return Integer.parseInt(next());
        }
    
        long nextLong()
        {
            return Long.parseLong(next());
        }
    
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
    
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    
}


Measured memory_bytes: 32648
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
    int N, K, Q, seikaisya[110000];
    cin >> N >> K >> Q;
    rep(i,Q) cin >> seikaisya[i];
    
    int A[110000] = {0,};

    rep(i, Q) {
        A[seikaisya[i]]++;

    }

    if (Q < K) {
        rep(i, N) {
            cout << "Yes" << endl;
        }
    } else {
        for (int i = 1; i <= N; i++) {
            if (Q-K+1 <= A[i]) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }
    }
    return 0;




}

Measured memory_bytes: 1408
#include<stdio.h>

	int main(){
		int a;
		int b;
	
		 
		 	scanf("%d", &a);
			b=3*a*a;
		 	
		 	
		 	printf("%d",b);
		 	
		 	
		 
		
		
		
		
		
		
		
		
			return 0;
		
	}
	

Measured memory_bytes: 128
def is_prime(n):
  if n < 2: return False
  for i in range(2, int(n ** 0.5) + 1):
    if n % i == 0: return False
  return True

count = 0
for i in range(int(input())):
  if is_prime(int(input())) : count += 1
print(count)

Measured memory_bytes: 7836
#!python3

LI = lambda: list(map(int, input().split()))

# input
N = int(input())
A = LI()
Q = int(input())
BC = [LI() for _ in range(Q)]

MAX = 10 ** 5


def main():
    d = {i: 0 for i in range(MAX + 1)}
    s = 0
    for a in A:
        d[a] += 1
        s += a
    for b, c in BC:
        x = d[b]
        s += (c - b) * x
        print(s)
        d[c] += d[b]
        d[b] = 0


if __name__ == "__main__":
    main()


Measured memory_bytes: 42468
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  
  int A = 0;
  
  int B = 0;
  
  cin >> N;
  
  int C = N;
  
  for (int i = 100000000; i > 0; i = i / 10) {
    
    B = N / i;
    
    N = N % i;
    
    A = A + B;
 
  }
  if (C % A == 0) {
    
    cout << "Yes" << endl;
    
  }
  else {
    
    cout << "No" << endl;
    
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 200001;
int main()
{
  int n,t,i,res;
  int b[N_MAX];
  cin >> n;
  fill(b+1,b+n+1,0);
  for(i=1;i<n;i++){
    cin >> t;
    b[t]++;
  }
  for(i=1;i<=n;i++)
    cout << b[i] << endl;
  return 0;
}

Measured memory_bytes: 3944
import sys
n = int(input())
if n <= 3:
    print(3)
    sys.exit()
def check(a):
    sqrt = round(a ** 0.5 + 0.5)
    factors = {1, a}
    for i in range(2, sqrt + 1):
        if not a % i:
            if not i in factors:
                factors.add(i)
            j = a // i
            if not j in factors:
                factors.add(j)
    return len(factors)
ans = 0
for i in range(3, n + 1, 2):
    if check(i) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3188