akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#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;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;

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

    // まずa[i]が必要かどうかは
    // 「要素の総和がk-a[i]以上k未満のa[i]を含まない部分集合が存在するならa[i]は必要。そうでなければ不必要」
    // と判定できる。

    // 次に解の単調性 「a[i] < a[j]のとき、a[j]が不必要 ⇒ a[i]も不必要」 を示す。
    // 仮定より要素の総和がk-a[j]以上k未満のa[j]を含まない部分集合は存在しない。
    // つまりa[j]を含まない部分集合の要素の総和はk-a[j]未満またはk以上。
    // k-a[j] < k-a[i] より要素の総和がk-a[i]以上k未満のa[i]もa[j]も含まない部分集合は存在しない。
    // a[j]を含む部分集合の要素の総和はk未満またはk+a[j]以上なので、
    // a[j]を含むがa[i]は含まない部分集合の要素の総和はk-a[i]未満またはk+a[j]-a[i]以上。
    // k < k + (a[j] - a[i]) より要素の総和がk-a[i]以上k未満のa[j]を含むがa[i]は含まない部分集合は存在しない。
    // 以上よりa[j]を含むかどうかによらずa[i]は不必要。

    // 判定問題「a[x]は不必要か？」を二分探索で解く
    ll left = -1;
    ll right = n;
    while(right - left > 1) {
        ll x = (left + right)/2;
        vector<vector<bool>> dp(n+1, vector<bool>(k+1, false));  // dp[i+1][j] : a[i]までで総和をjにできるならtrue
        dp[0][0] = true;
        rep(i, n) {
            exrep(j, 0, k) {
                if(dp[i][j]) {
                    dp[i+1][j] = true;
                }
                if(i == x) {
                    continue;
                }
                if(j >= a[i] && dp[i][j - a[i]]) {
                    dp[i+1][j] = true;
                }
            }
        }
        bool noneed = true;
        exrep(j, max(0LL, k-a[x]), k-1) {
            if(dp[n][j]) {
                noneed = false;
            }
        }
        if(noneed) {
            left = x;
        }
        else {
            right = x;
        }
    }

    out(right);
    re0;
}

Measured memory_bytes: 5636
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll r, d, x;
    cin>>r>>d>>x;
    rep(i, 10) {
        x = r * x - d;
        cout<<x<<endl;
    }
}

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

int main(void) {
  string s;
  string out = "None";
  cin >> s;
  for (int i = 0; i < 26; i++) {
    char a = 'a' + i;
    if (s.find(a) == string::npos) {
      out = a;
      break;
    }
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a<b) swap(a,b);
	if(b<c) swap(b,c);
	if(a<b) swap(a,b);
	cout<<b+c<<endl;
	return 0;
}

Measured memory_bytes: 256
import math

n = int(input())
a = []  
for i in range(n):
  a.append(int(input()))
if n == 1:
  print(a[0])
else:
  lcm = (a[0] * a[1]) // math.gcd(a[0], a[1])
  for i in range(2, n):
    lcm = (lcm * a[i]) // math.gcd(lcm, a[i])
  print(lcm)


Measured memory_bytes: 9144
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

//AOJ0069
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){
int n,hi,at,d;
int my[12][32]={-1};
string ws,am[32];
	
	while(cin >> n){
		if(n==0) break;
		cin >> hi >> at >> d;
		rep(i,d){
			cin >> ws;
//			if(ws == "0" ) break;
			am[i+1] = "0" + ws + "0";
		}
		
		rep2(x,1,n+1){
			my[x][0]=x;
			rep2(i,1,d+2){
				int z = my[x][i-1];
				if(am[i][z-1]=='1') my[x][i] = z -1;
				else if(am[i][z]=='1') my[x][i] = z +1;
				else my[x][i] = z;
			}
		}
		
		int svat=-1;
		rep(i,n+2) if(my[i][d] == at){
				svat = i ; break; 
		}

//	printf("ss:%d %d %d\n",svat,n, at);
		if(svat == hi){
			cout << 0 << endl;
		}else{
			int ngsw=0;
			rep2(i,1,d+1){
				if(abs(my[svat][i] - my[hi][i] )== 1 ){
					int smn = min(my[svat][i] , my[hi][i] );
					if( am[i][smn-1] != '1' && am[i][smn +1] != '1'
						&& am[i][smn] != '1' ){
						cout << i << " " << smn << endl;
						ngsw=1;
						break;
					}
				}
			}
			if(ngsw==0) cout << 1 << endl;
		}
//			rep(x,n+1){rep(i,d+2) printf("%d:%d, ",i,my[x][i] ); printf("\n");}
	}
	return 0;
	
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long i, o, t, j, l, s, z;
    cin >> i >> o >> t >> j >> l >> s >> z;
    long long ans = 0;
    long long m = min({l, i, j});
    for (long long n = 0; n <= min({l, i, j, 2LL}); n++) {
        ans = max(ans, n*3+(l-n)/2*2+(i-n)/2*2+(j-n)/2*2+o);
    }
    cout << ans << "\n";
    return 0;
}

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

const int MAXN = 200;
const int MAXK = 100;

int main() {
	string s;
	int k;
	cin >> s >> k;
	vector<vector<vector<int>>> dp(s.size() + 1, vector<vector<int>>(k + 1, vector<int>(2, 0)));
	// empty string without non-zero digit equal is 1
	dp[0][0][1] = 1;

	for (int i = 1; i <= s.size(); ++i) {
		// current digit
		int cur = s[i - 1] - '0';

		for (int j = 0; j <= k; ++j) {
			// fill 0 to smaller
			dp[i][j][0] = dp[i - 1][j][0];

			// fill 1-9 to smaller
			if (j) {
				dp[i][j][0] += dp[i - 1][j - 1][0] * 9;
			}

			// fill 0 to equal if cur > 0
			if (cur) {
				dp[i][j][0] += dp[i - 1][j][1];
			}

			// fill 1 to (cur-1) to equal
			if (cur > 1 && j) {
				dp[i][j][0] += dp[i - 1][j - 1][1] * (cur - 1);
			}

			// fill cur to equal
			if (cur) {
				if (j) {
					dp[i][j][1] += dp[i - 1][j - 1][1];
				}
			}
			else {
				dp[i][j][1] += dp[i - 1][j][1];
			}
		}
	}
	cout << dp[s.size()][k][0] + dp[s.size()][k][1] << endl;
	return 0;
}

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

using ll = long long;
const ll mod=1e9+7 ;

ll powmod(ll n,ll k){
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

int main(){
    string s;
    cin >> s;
    ll ans = 0;
    ll cnt = 0;
    int n = s.size();
    for(int i = 0; i < n; ++i){
        if(s[i] == '0')continue;
        ans += powmod(2,cnt) * powmod(3,n-i-1) % mod;
        ++cnt;
    }
    ans += powmod(2,cnt);
    cout << ans % mod << endl;
    return 0;
}


Measured memory_bytes: 512
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

k = INT()
q = Queue()

for i in range(1,10):
    q.put(i)
for i in range(k):
    x = q.get()
    y = x % 10
    if y != 0:
        q.put( 10*x + y - 1 )
    q.put( 10*x + y )
    if y != 9:
        q.put( 10*x + y + 1 )
print(x)

Measured memory_bytes: 19664
using System;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        string a, b, c;
        a = str[0];
        b = str[1];
        c = str[2];
        bool f = (a[a.Length - 1] == b[0]) && (b[b.Length - 1] == c[0]);
        Console.WriteLine(f ? "YES" : "NO");
    }
}

Measured memory_bytes: 13140
//Code By PMD
#include<bits/stdc++.h>
#define faster() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long i64;
map < int , int > cnt;
int a,b,c;
void input(){
    cin >> a >> b >> c;
}
void solve(){
   cnt[a]++;
   cnt[b]++;
   cnt[c]++;
   if ( cnt.size() == 2 ) cout << "Yes" << endl;
   else cout << "No" << endl;
    
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    faster();int t=1; 
    //cin>>t; cin.ignore();
    while(t--){ input();solve();}
    cerr << "\nRunning is : " << 1.0*clock()/1000 ;
    return 0;
}
//Code By PMD
 

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

int main() {
  long long x, y;
  cin >> x >> y;
  vector<long long> array;
  array.push_back(x);
  int i;
  for (i = 0; i < 100; i++) {
    if (array[i] * 2 <= y) {
      array.push_back(array[i] * 2);
    } else {
      break;
    }
  }
  cout << array.size() << endl;
  return 0;
}


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

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

Measured memory_bytes: 3572
#include <stdio.h>
int main(void){

	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if(x>=r && x<=W-r && y>=r && y<=H-r){
		printf("Yes\n");
    }else{
		printf("No\n");
	}
	return 0;
}

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

int N=0, M=0, L=0, R=0, max_L=0, min_R=pow(10,5)+1;

int main(){
  cin >> N >> M;
  rep(m, M){
    cin >> L >> R;
    max_L = max(max_L, L);
    min_R = min(min_R, R);
  }
  cout << max(0, min_R - max_L + 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n, sm=0, mx=0;
    cin >> n;
    for(int i=0;i<n;i++){
        int l;
        cin >> l;
        sm+=l;
        mx = max(mx, l);
    }
    sm-=mx;
    if(sm>mx){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<iomanip>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
const ll mod=1e9+7;


int main(){
    int N;
    cin >> N;
    ll ans=1;
    for(int i=1; i<=N; i++){
        ans *= i;
        ans%=mod;
    }
    cout << ans << endl;
    
    return 0;
}

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast
    ll n;
    cin >> n;
    vi arr(n);
    REP(i, 0, n)
        cin >> arr[i];
    ll ans = 0, c = 0;
    REP(i, 1, n) {
        if (arr[i] <= arr[i-1])
            c++;
        else  {
            ans = max(ans, c);
            c = 0;
        }
    }
    ans = max(ans, c);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stack>
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <cstdio>
using namespace std;
typedef pair<int, int> p;
int det(p a, p b) {
	return a.first*b.second - a.second*b.first;
}
p mainasu(p a, p b) {
	return p(a.first - b.first, a.second - b.second);
}
int main()
{
	int n;
	cin >> n;
	p points[100005];
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &points[i].second, &points[i].first);
	}
	sort(points, points + n);
	int k = 0;
	vector <p> qs(n*2);
	for (int i = 0; i < n; i++) {
		while (k > 1 && det(mainasu(qs[k - 1], qs[k - 2]), mainasu(points[i], qs[k - 1])) > 0)k--;
		qs[k++] = points[i];
	}
	for (int i = n - 2, t = k; i >= 0; i--) {
		while (k > t&&det(mainasu(qs[k - 1], qs[k - 2]), mainasu(points[i], qs[k - 1])) > 0)k--;
		qs[k++] = points[i];
	}
	qs.resize(k - 1);
	cout << qs.size()<<endl;
	for (int i = 0; i < (int)qs.size(); i++) {
		cout << qs[i].second << " " << qs[i].first << endl;
	}
}

Measured memory_bytes: 3380
N,C = map(int,input().split())
cum = [0]*(10**5+1)
tail = {}
head = {}
for i in range(10**5+1):
    tail[i] = []
    head[i] = []
for i in range(N):
    s,t,c = map(int,input().split())
    if c not in tail[s] and c not in head[t-1]:
        cum[s-1] += 1
        cum[t] -= 1
    elif c not in head[t-1]:
        cum[s] += 1
        cum[t] -= 1
    elif c not in tail[s]:
        cum[s-1] += 1
        cum[t-1] -= 1
    else:
        cum[s] += 1
        cum[t-1] -= 1
    tail[t].append(c)
    head[s-1].append(c)
    
import numpy as np
print(np.cumsum(cum).max())

Measured memory_bytes: 52156
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

int main()
{
	int w,a,b;
	cin>>w>>a>>b;
	if(a>b+w)cout<<a-(b+w)<<endl;
	else if(b>a+w)cout<<b-(a+w)<<endl;
	else cout<<"0\n";
}

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

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

using namespace std;

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

void solve_A(){
    int n, m;
    cin >> n >> m;

    int ans = n * (n-1) / 2 + m * (m-1) / 2;

    cout << ans;
}

void solve_B(){
    string s;
    cin >> s;

    int n = s.size();

    string s_1 = s.substr(0,(n-1)/2);
    string s_2 = s.substr((n+3)/2-1, n-1);

    bool ok_1 = true, ok_2 = true;
    for(int i = 0; i < s_1.size(); i++){
        if(s_1[i] != s_1[s_1.size() - i - 1]){
            ok_1 = false;
        }
    }
    
    for(int j = 0; j < s_2.size(); j++){
        if(s_2[j] != s_2[s_2.size()-j-1]) ok_2 = false;
    }

    if(ok_1 && ok_2) cout << "Yes";
    else cout << "No";   
}

void solve_C(){
    int L;
    scanf("%d", &L);

    double vertex = (double) L/3;
    printf("%.7f", vertex * vertex * vertex);
}

int main(void){
    solve_C();
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <functional>
#include <numeric>
#include <string>
#include <iterator>
#include <sstream>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cstring>

using namespace std;

struct TEAM{
	int cnt,pt,id;

	bool operator < (const TEAM& x) const{
		if(cnt != x.cnt) return greater<int>()(cnt,x.cnt);
		if(pt != x.pt) return less<int>()(pt,x.pt);
		return false;
	}
};


bool co[55][10];
int w_cnt[55][10];


int main()
{
	int T,P,R;
	while(cin>>T>>P>>R,(T||P||R)){
		vector<TEAM> team(T);
		for(int i = 0; i < T; i++){
			team[i].id = i + 1;
		}
		memset(co,0,sizeof(co));
		memset(w_cnt,0,sizeof(w_cnt));
		for (int i = 0; i < R; i++){
			int ti,pi,time; string s;
			cin>>ti>>pi>>time>>s;
			if(co[ti][pi]) continue;
			if(s[0] == 'W'){
				w_cnt[ti][pi]++; continue;
			}
			team[ti - 1].cnt++;
			team[ti - 1].pt += time + w_cnt[ti][pi] * 1200;
		}

		stable_sort(team.begin(),team.end());

		for (int i = 0; i < T; i++){
			printf("%d %d %d\n",team[i].id,team[i].cnt,team[i].pt);
		}
	}

	return 0;
}

Measured memory_bytes: 948
//by xxj
#include<bits/stdc++.h>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define lowbit(x) x&-x
const int inf=1e9+7;
const double eps=1e-10;
const ll linf=1e18+7;
const ll hh=523;
//const int mod=;
ll dp[25000007];
int a[3],b[3];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	scanf("%d",&n);
	for (int i=0;i<3;i++){
		scanf("%d",a+i);
	}
	for (int i=0;i<3;i++){
		scanf("%d",b+i);
	}
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	ll mx=n;
	for (int i=0;i<3;i++){
		for (int j=a[i];j<=n;j++){
			if (dp[j-a[i]]!=-1){
				dp[j]=max(dp[j],dp[j-a[i]]+b[i]);
				mx=max(mx,n-j+dp[j]);
			}
		}
	}
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	ll ans=mx;
	for (int i=0;i<3;i++){
		for (int j=b[i];j<=mx;j++){
			if (dp[j-b[i]]!=-1){
				dp[j]=max(dp[j],dp[j-b[i]]+a[i]);
				ans=max(ans,dp[j]+mx-j);
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}
/*
input:
*/


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

int parent(int index){
    return index/2;
}

int left(int index){
    return 2*index;
}

int right(int index){
    return 2*index+1;
}

int main(){
    int H,A[250+1]={0};//1-indexedにする
    scanf("%d",&H);
    for(int i=1;i<=H;i++) scanf("%d",&A[i]);//keyを各節点に設定

    for(int i=1;i<=H;i++){
        printf("node %d: key = %d, ",i,A[i]);
        if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]);
        if(left(i)<=H) printf("left key = %d, ",A[left(i)]);
        if(right(i)<=H) printf("right key = %d, ",A[right(i)]);
        printf("\n");
    }


    return 0;
}


Measured memory_bytes: 3196
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(100000)
from collections import deque
from collections import defaultdict
INF = float("inf")

MOD = 1000000007  # type: int


def solve(N: int, K: int, a: "List[int]", b: "List[int]"):
    # 枝
    edges = defaultdict(list)
    for from_, to_ in zip(a, b):
        edges[from_].append(to_)
        edges[to_].append(from_)

    # 色を決定済みかどうか
    flag = [False]*(N+1)

    def recur(n, preK, prepreK):
        count = 1
        count *= K-preK-prepreK
        count %= MOD
        flag[n] = True
        if edges[n] == 1:
            print(n, preK, prepreK, count)
            return count
        else:
            e = [ee for ee in edges[n] if flag[ee] is False]
            for i, to_ in enumerate(e):
                count *= recur(to_, 1, preK+i)
                count %= MOD
            return count

    print(recur(1, 0, 0) % MOD)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    a = [int()] * (N-1)  # type: "List[int]"
    b = [int()] * (N-1)  # type: "List[int]"
    for i in range(N-1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, K, a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 131360
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
#define next nxt
 
int n,x[N],y[N],next[N],p[N],f[N],size[N],d[N];
long long ans;
char s[N];
 
void travel(int x){
	size[x]=(s[x]=='1');
	for (int t=p[x];t;t=next[t])
		if (y[t]!=f[x]){
			f[y[t]]=x;travel(y[t]);
			size[x]+=size[y[t]];
			d[x]=max(d[x],d[y[t]]+1);
		}
}
 
void solve(int x,int mx){
	int mn=(s[x]=='0')<<30,nx=0;
	if (size[x]!=size[1]) mn=min(mn,mx);
	for (int t=p[x];t;t=next[t])
		if (y[t]!=f[x]){
			nx=max(nx,d[y[t]]+1);
			if (nx>mx) swap(nx,mx);
			if (size[y[t]]) mn=min(mn,d[y[t]]+1);
		}
	ans+=max(min(mx-1,nx+1)-mn+1,0);
	for (int t=p[x];t;t=next[t])
		if (y[t]!=f[x])
		solve(y[t],(d[y[t]]+1!=mx)?(mx+1):(nx+1));
}
 
int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
 
int main(){
	n=read();
	for (int i=1;i<=n-1;i++){
		x[2*i-1]=y[2*i]=read();
		y[2*i-1]=x[2*i]=read();
		next[2*i-1]=p[x[2*i-1]];p[x[2*i-1]]=2*i-1;
		next[2*i]=p[x[2*i]];p[x[2*i]]=2*i;
	}
	scanf(" %s",s+1);
	travel(1);solve(1,0);
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 28800
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int sum = a[0];
    RREP(i, 1, n) sum = sum ^ a[i];

    for(int i = 0; i < n; i++) {
        cout << (sum ^ a[i]) << endl;
    }

    return 0;
}

Measured memory_bytes: 4008
# -*- coding: utf-8 -*-
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r < 0: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n, k = map(int, input().split())
red_n = n - k + 1

const = 1000000007

for i in range(1, k+1, 1):
    cnt = cmb(red_n, i) * cmb(k-1, i-1)
    print(cnt % const)


Measured memory_bytes: 3944
#include <iostream>

using namespace std;

int main()
{
   int a,b ;
   char op ;
   cin>>a>>op>>b ;
   if (a>=1 && a<=1000000000)
     if (op!= '+' && op!='-')
        cout <<"Error " ;
     else if (op == '+')
        cout << a+b ;
     else if (op == '-')
        cout << a-b ;

   return 0 ;
}


Measured memory_bytes: 256
a=list(input())
b=list(input())
c=list(input())

que = a.pop(0)
while True:
    if que=='a':
        if len(a)==0:
            print('A')
            break
        que=a.pop(0)
    elif que=='b':
        if len(b)==0:
            print('B')
            break
        que=b.pop(0)
    elif que=='c':
        if len(c)==0:
            print('C')
            break
        que=c.pop(0)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int a,b;
	cin>>a>>b;
	if(a==0||b==0||a<0&&b>0){
		cout<<"Zero"<<endl;
		return 0;
	}
	else if(a>0||(a<0&&-(b+a)%2==1)){
		cout<<"Positive"<<endl;
		return 0;
	}
	else{
		cout<<"Negative"<<endl;
		return 0;
	}
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
//ABC122-C
//Reference: editorial.
#include<iostream>
#include<string.h>
#include<vector>
#include<stdio.h>
using namespace std;

int main(){
  int N,Q;
  string S;
  
  cin>>N>>Q;
  cin>>S;
  vector<int> l,r,t;
  for(int i=0; i<Q; i++){
    int l_temp,r_temp;
    cin >> l_temp >> r_temp;
    l.push_back(l_temp);
    r.push_back(r_temp);
  }
  t.resize(N);
  t[0] = 0;
  for(int i=0; i<N; i++){
    int temp = 0;
    if(S[i+1] == 'C' && S[i] == 'A') temp =1;
    t[i+1] = t[i] + temp;
  }
  for(int i=0; i<Q; i++){
    //Note that string starts from index 0, r and l starts from 1
    int result = t[r[i]-1] - t[l[i]-1];
    cout<<result<<endl;
  }
  
  /*TLE
  for(int k=0; k<Q; k++){
    int result=0;
    for(int i = l[k] ;i<r[k]; i++){

      char c1,c2;
      c1= S[i-1];
      c2 = S[i];
   
      if(c1== 'A' &&c2 =='C') result++;
      //cout<<c1<<endl;
    }
    cout<<result<<endl;
  }
  */
}



Measured memory_bytes: 2420
import math
N=int(input())
def 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
def tri(num):
  s=int(math.sqrt(2*num))
  t=s*(s+1)//2
  if t>num:
    return s-1
  else:
    return s

if N==1:
  print(0)
else:
  ls=factorization(N)
  ans=0
  for a,b in ls:
    ans+=tri(b)
  print(ans)

Measured memory_bytes: 9500
import java.util.Scanner;

import javax.script.ScriptException;

public class Main {

	public static void main(String[] args) throws ScriptException {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt();
			String op = scanner.next();
			int b = scanner.nextInt();
			System.out.println("+".equals(op) ? a + b : a - b);
		}
	}
}


Measured memory_bytes: 35716
import sys
from collections import defaultdict

lines = 1
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())


s = inp[0]
n = len(s)

tmp = defaultdict(int)
tmp[0] = 1

b = 0
d = 1

for i in range(1, n + 1):
    a = int(s[n - i])
    b = ((d * a) + b) % 2019
    tmp[b] += 1
    d = (d * 10) % 2019

result = 0

for v in tmp.values():
    result += int(v * (v - 1) / 2)

print(result)


Measured memory_bytes: 9492
#include <stdio.h>
#include <math.h>

int main()
{
	double x1,y1,x2,y2,x3,y3,xp,yp;
	double s,s1,s2,s3;
	double ab,bc,ca,ap,bp,cp;
	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF){
	ab=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    	bc=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
    	ca=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
    	ap=sqrt((x1-xp)*(x1-xp)+(y1-yp)*(y1-yp));
    	bp=sqrt((x2-xp)*(x2-xp)+(y2-yp)*(y2-yp));
    	cp=sqrt((x3-xp)*(x3-xp)+(y3-yp)*(y3-yp));
	s=sqrt(((ab+bc+ca)*(-ab+bc+ca)*(ab-bc+ca)*(ab+bc-ca))/16);
	s1=sqrt(((ap+ab+bp)*(-ap+ab+bp)*(ap-ab+bp)*(ap+ab-bp))/16);
	s2=sqrt(((bp+bc+cp)*(-bp+bc+cp)*(bp-bc+cp)*(bp+bc-cp))/16);
	s3=sqrt(((cp+ca+ap)*(-cp+ca+ap)*(cp-ca+ap)*(cp+ca-ap))/16);
	if(fabs(s1+s2+s3-s)<0.000000001)puts("YES");
	else puts("NO");
	}
	return 0;
}

Measured memory_bytes: 612
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc103/tasks/abc103_b
S = input()
T = input()
S += S

print('Yes' if S.count(T) else 'No')


Measured memory_bytes: 3316
/**
 * Created by hiramekun at 20:53 on 2019-11-23.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    vl a(n);
    cin >> a;

    ll sum = accumulate(all(a), 0LL);
    ll now = 0, prev = 0;
    rep(i, n) {
        prev = now;
        now += a[i];
        if (now * 2 >= sum) break;
    }
    cout << min(2 * now - sum, sum - 2 * prev) << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

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

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

    sort(h.begin(), h.end(), greater<int>());

    long long res = 0;
    for (int i = k; i < n; i++) {
        res += h[i];
    }

    cout << res << endl;
}


Measured memory_bytes: 1024
#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 vector<pii> VP;
typedef vector<string> VS;
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
//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;
	}
}



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

	int K, N; cin >> N >> K;

	int ans = 0;

	VI memo(K + 1, 0);

	for (int i = K; i > 0; i--) {
		int a = modpow(K / i, N);

		int j = 2;
		while (j*i<=K) {
			a -= memo[j*i];
			a = (a + mod) % mod;
			j++;
		}


		int cnt = a * i%mod;
		memo[i] = a;
		ans = (ans + cnt) % mod;;
	}

	

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



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

void solve() {
        long long n;
        cin >> n;
        vector<int> p;
        int m;
        for (m = 40; m > 0; m --) if (n >= (1LL << m) - 1) break;
        n -= (1LL << m) - 1;
        for (int i = 1; i <= m; i ++) p.push_back(i);
        for (int i = m - 1; i >= 0; i --) {
                if (n < (1LL << i)) continue;
                m ++;
                p.insert(p.begin() + i, m);
                n -= (1LL << i);
        }
        for (int i = 1; i <= m; i ++) p.push_back(i);
        cout << p.size() << endl;
        for (int i = 0; i < 2 * m; i ++) cout << p[i] << (i == 2 * m - 1 ? '\n' : ' ');
        return;
}

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

        //int T;
        //freopen("a.in", "r", stdin);
        //cin >> T;
        //while (T --) solve();
        
        solve();
        return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
int a[N]={};

int main(){
	int n, k, q; scanf("%d%d%d", &n, &k, &q);
	REP(i, q){
		int x; scanf("%d", &x); x--;
		a[x]++;
	}
	REP(i, n){
		if(k - (q-a[i]) <= 0){
			printf("No\n");
		}else{
			printf("Yes\n");
		}
	}
}


Measured memory_bytes: 1024
//算是暴力题了 
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int len;
    string s;
    cin>>len>>s;
    ll s1=0,s2=0,s3=0,sum=0;
    for(int i=0;i<len;i++){
        if(s[i]=='R') sum+=s2*s3,s1++;
        if(s[i]=='G') sum+=s1*s3,s2++;
        if(s[i]=='B') sum+=s1*s2,s3++;
    }//找所有三元组的个数
    for(int i=0;i<len;i++)
    for(int k=i;k<len;k+=2)//i+k必须为偶数
        if(s[i]!=s[k] && s[i]!=s[(i+k)/2] && s[k]!=s[(i+k)/2]) sum--;
    //用循环遍历去掉不符合条件的三元组:2*j=i+k
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define int long long 
using namespace std ;
const int inf=1e9;

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n,k; cin>>n>>k;
	int arr[n] ; 
	for(int& i:arr) cin>>i;

	vector<int>dp(n,inf);
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=1;j<=k;j++){
			if(i+j<n) dp[i+j]=min(dp[i+j],dp[i]+abs(arr[i]-arr[i+j]));
		}
	}
	cout<<dp.back()<<endl;

	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main()
{
  int n;
   int i;
  
  scanf("%d",&n);
  
  int a[n];
  
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
  }
  
  int min,max;
  
  min=a[0];
  max=a[0];
  for(i=1;i<n;i++)
  {
    if(a[i]<min)
    {
      min=a[i];
    }
    
    if(max<a[i])
    {
      max=a[i];
    }
  }
  
 printf("%d\n",max-min);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int a, b, c;
	cin >> a >> b >> c;
	cout << ((a+b+c >= 22)? "bust": "win") << endl;

	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
#include <ctype.h>
using namespace std;

#define PI acos(-1.0)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

#define eps 1e-8
#define mod 1000000007

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;

struct Matrix {
    vvi data;
    int r, c;
    Matrix(int row, int col, bool identity = false) : r(row), c(col) {
        data.assign(row, vector<int>(col, 0));
        if (identity) {
            for (int i = 0; i < r; ++i) {
                data[i][i] = 1;
            }
        }
    }
    Matrix operator * (Matrix& other) {
        int m = r, n = c, p = other.c;
        Matrix res(m, p);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < p; ++j) {
                for (int k = 0; k < n; ++k) {
                    res.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        return res;
    }
};

// 扩展欧几里得算法 res[1] * a + res[2] * b = res[0] = gcd(a, b)
vector<int> extendGcd(int a, int b) {
    if (b == 0) {
        return {a, 1, 0};
    } else {
        vector<int> tmp = extendGcd(b, a % b);
        return {tmp[0], tmp[2], tmp[1] - (a / b) * tmp[2]};
    }
}

// 矩阵快速幂
Matrix matrix_power(Matrix base, ll exp) {
    int n = base.r;
    Matrix res(n, n, true);
    while (exp) {
        if (exp & 1) {
            res = res * base;
        }
        base = base * base;
        exp >>= 1;
    }
    return res;
}

// 带模快速幂
ll power_mod(ll base, int exp) {
    ll res = 1;
    while (exp) {
        if (exp & 1) res = res * base % mod;
        base = base * base % mod;
        exp >>= 1;
    }
    return res;
}

// 快速幂
ll power(ll base, int exp) {
    ll res = 1;
    while (exp) {
        if (exp & 1) res *= base;
        base *= base;
        exp >>= 1;
    }
    return res;
}

// 求逆元
ll inv(ll a) {
    return power_mod(a, mod - 2);
}

#define MAXFAC 100010

ll fac[MAXFAC];

void initFac() {
    fac[0] = 1;
    for (int i = 1; i < MAXFAC; ++i) {
        fac[i] = i * fac[i - 1] % mod;
    }
}

ll Combine(ll a, ll b) {
    return (fac[a] * inv(fac[b]) % mod) * inv(fac[a - b]) % mod;
}

/******************************** template ********************************/
#define MAXN 100010
int n;
string s1, s2;

int main() {
    cin >> n;
    cin >> s1 >> s2;

    ll res = 1;
    for (int i = 0; i < s1.length(); ++i) {
        if (s1[i] == s2[i]) {
            if (i == 0) {
                res = 3;
            } else if (s1[i - 1] == s2[i - 1]) {
                res = res * 2 % mod;
            }
        } else {
            if (i == 0) {
                res = 6;
            } else if (s1[i - 1] == s2[i - 1]) {
                res = res * 2 % mod;
            } else {
                res = res * 3 % mod;
            }
            ++i;
        }
    }

    cout << res;

    return 0;
}

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

using namespace std;

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());
    cout << (accumulate(A.begin(), A.end(), 0) >= h ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 100010;
int h[N], f[N], n;

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

  cin >> n;
  for (int i = 0; i < n; i++) cin >> h[i];
  f[n - 1] = 0;
  f[n - 2] = abs(h[n - 1] - h[n - 2]);
  for (int i = n - 3; i >= 0; i--) {
    f[i] = min(
      abs(h[i] - h[i + 1]) + f[i + 1],
      abs(h[i] - h[i + 2]) + f[i + 2]
    );
  }
  cout << f[0] << "\n";
}



Measured memory_bytes: 4268
n = gets.chomp.to_i
v = gets.chomp.split.map(&:to_i)

v.sort!

b = 0
(n-1).times do |i|
  if i == 0
    b = (v[i] + v[i + 1]) / 2.0
  else
    b = (b + v[i + 1]) / 2.0
  end
end
p b



Measured memory_bytes: 1788
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}


		public static void main(String[] args) {
			Scanner scan=new Scanner(System.in);
			int a=scan.nextInt();
			int c=scan.nextInt();
			int b[]=new int[a];
			for(int i=0;i<a;i++) {
				b[i]=scan.nextInt();
			}
			int min=1145141919;
			for(int i=0;i<a-c+1;i++) {
				int cnt1=Math.abs(b[i])+Math.abs(b[i]-b[i+c-1]);
				int cnt2=Math.abs(b[i+c-1])+Math.abs(b[i]-b[i+c-1]);
				min=min<cnt1?min:cnt1;
				min=min<cnt2?min:cnt2;
			}
			System.out.println(min);
		}
}

Measured memory_bytes: 50724
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
ll INF = 1000000007;

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	ll ans = 0;
	for(ll i=0;i<n;i++) {
		if ((i + 1) % 3 != 0 && (i + 1) % 5 != 0) ans += i + 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 11076
N = int(input())
S = input()

left,right = [0]*N,[0]*N
cnt = 0
for i in range(1,N):
    if S[i-1]=="W":
        cnt += 1
    left[i] = cnt
cnt = 0
for i in range(N-2,-1,-1):
    if S[i+1]=="E":
        cnt += 1
    right[i] = cnt

ans = 10**9
for i in range(N):
    ans = min(ans, left[i]+right[i])

print(ans)

Measured memory_bytes: 17596
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <functional>
#include <ctime>
#include <queue>
#include <string>
#include <map>
#include <utility>
#include <sstream>
#include <cmath>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define form(i,a,b) for(int i=(a);i<(b);i++)
#define sz(x) ((int)(x).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
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 long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
int cmp( const void *p, const void *q ) {if( *(double*)p > *(double*)q ) return 1;if( *(double*)p < *(double*)q ) return -1;return 0;}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    //vi ad,bd,cd,dd;
    //vs as,bs,cs,ds;
    cin>>a;
    printa("ABC",a);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

vector<ll> a, b, N;
int main()
{
	ll A, B;
	cin >> A >> B;
	for (ll i = 1; i * i <= A; i++) {
		if (A % i == 0) {
			a.push_back(i);
			if (A / i != i) {
				a.push_back(A / i);
			}
		}
	}
	for (ll i = 1; i * i <= B; i++) {
		if (B % i == 0) {
			b.push_back(i);
			if (B / i != i) {
				b.push_back(B / i);
			}
		}
	}
	sort(a.begin(), a.end()); 
	sort(b.begin(), b.end());
	int j = 0;
	for (int i = 0; i < a.size(); i++) {
		while (a[i] > b[j]) {
			j++;
			if (j == b.size()) break;
		}
		if (j == b.size()) break;
		if (a[i] == b[j]) {
			N.push_back(a[i]);
		}
	}
	ll ans = 1;
	bool flag = true;
	for (int i = 1; i < N.size(); i++) {
		flag = true;
		if (N[i] == 2) ans++;
		else {
			for (int j = 1; j < i; j++) {
				if (N[i] % N[j] == 0) {
					flag = false;
					break;
				}
			}
			if (flag) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

#define MAX 100005
#define NIL -1

typedef struct{
  int p, l, r;
}Node;

Node T[MAX];
int n, D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);
  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l==NIL) printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  for(i=0, c=T[u].l; c!=NIL; i++, c=T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}

int rec(int u, int p){
  D[u] = p;
  if(T[u].r!=NIL) rec(T[u].r, p);
  if(T[u].l!=NIL) rec(T[u].l, p+1);
}

int main(){
  int i, j, d, v, c, l, r;
  
  scanf("%d", &n);

  for(i=0; i<n; i++) T[i].p=T[i].l=T[i].r=NIL;

  for(i=0; i<n; i++){
    scanf("%d %d", &v, &d);
    for(j=0; j<d; j++){
      scanf("%d", &c);
      if(j==0) T[v].l=c;
      else T[l].r=c;
      l = c;
      T[c].p = v;
    }
  }
  
  for(i=0; i<n; i++){
    if(T[i].p==NIL) r=i;
  }

  rec(r, 0);

  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 6396
//Solution for aoj: 0594
#include <iostream>
#include <algorithm>
using namespace std;
int n,w,h,gx,gy,sx,sy,m,sum;
int main(){
  cin>>w>>h>>n;
  cin>>sx>>sy;
  for(int i=0;i<n-1;i++){
    cin>>gx>>gy;
    if(sx>gx && sy>gy || sx<gx && sy<gy){
     m = min(abs(gx - sx), abs(gy - sy));
     m += abs(gx - sx) - m + abs(gy - sy) - m;
    }
    else{
      m = abs(gx - sx) + abs(gy - sy);
    }
    sum += m;
    sx = gx;
    sy = gy;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 1160