akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
    int n,q,a,v,i,j,max;
    scanf("%d %d",&n,&q);
    int fish[n],ans[q][2];
    for(i=0;i<n;i++) fish[i]=0;
    for(i=0;i<q;i++){
        scanf("%d %d",&a,&v);
        fish[a-1]+=v;
        if(i==0) {
            max=a-1;
        } else if(v>0){
            if (fish[a-1]>fish[max]||(fish[a-1]==fish[max]&&a-1<max)){
                max = a-1;
            }
        } else if (a-1==max){
            for(j=0;j<n;j++) {
                if(fish[j]>fish[max]||(fish[j]==fish[max]&&j<max)){
                    max=j;
                }
            }
        }
        ans[i][0] = max + 1;
        ans[i][1] = fish[max];
    }
    for(i=0;i<q;i++) printf("%d %d\n",ans[i][0],ans[i][1]);
    return 0;
}

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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    cin>>n;

    int d = n%10;
    if(d==2 ||d==4 ||d==5 ||d==7 ||d==9)cout<<"hon"<<endl;
    else if(d==0 || d==1 ||d==6 ||d==8)cout<<"pon"<<endl;
    else{cout<<"bon"<<endl;}
    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const char sp = ' ';

int N;
string S;
map<string, int>mp;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S;
		mp[S]++;
	}
	int m = 0;
	for (auto p : mp) {
		m = max(m, p.second);
	}
	for (auto p : mp) {
		if (p.second == m) {
			cout << p.first << endl;
		}
	}
}

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

const string f = "hi";
string s;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
	if((int)s.size() % (int)f.size() != 0) return cout << "No" << endl, 0;
	for(int i = 0; i < s.size(); i += f.size()) {
		if(s.substr(i, f.size()) != f) return cout << "No" << endl, 0;
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
int main()
{
	dhoom;
	int a , b;
	cin >> a >> b;
	if(a <= 8 && b <= 8)
		cout <<"Yay!" << endl;
	else
		cout << ":(" << endl;

	return 0;
} 



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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

const int mod = 1000000000 + 7;

// ベクトルはvec
// 行列はmat
// 行列はmat(row_size,vec(col_size,initial_value))でインスタンスを差作成
typedef vector<ll> vec;
typedef vector<vec> mat;

// A*B
// modに-1を渡したときはmodの計算を行わない
mat MulMat(mat &A,mat &B,ll mod=-1){
    mat C(A.size(),vec(B[0].size()));
    for(int i = 0; i < (int)A.size(); i++){
        for(int k = 0; k < (int)B.size(); k++){
            for(int j = 0; j < (int)B[0].size(); j++){
                C[i][j]=(C[i][j]+A[i][k]*B[k][j]);
                if(mod!=-1) C[i][j]%=mod;
            }
        }
    }
    return C;
}

// A^Nの計算
// modに-1を渡したときはmodの計算を行わない
mat PowMat(mat A,ll n,ll mod=-1){
    mat B(A.size(),vec(A.size()));
    for(int i = 0; i < (int)A.size(); i++)
        B[i][i]=1;
    while(n>0){
        if(n&1)B=MulMat(B,A,mod);
        A=MulMat(A,A,mod);
        n>>=1;
    }
    return B;
}

int N;
ll K;

int main() {

    cin >> N >> K;
    mat M(N, vec(N, 0));
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            cin >> M[i][j];
    mat M2 = PowMat(M, K, mod);
    ll sum = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++) (sum += M2[i][j]) %= mod;
    }
    
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

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

    ll num[3];
    REP(i, 3) cin >> num[i];
    sort(num, num + 3, greater<ll>());
    ll maxLine = num[0];
    if(num[0]%2 & 1 && num[1]%2 & 1 && num[2]%2 & 1) {
        cout << num[1] * num[2] << endl;
    }
    else cout << 0 << endl;


}




Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                emplace_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i, b, e)	  for (int i = (int)b; i < (int)e; i++)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double EPS = 1e-9;
const double PI = acos(-1);

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int h, n;
    cin >> h >> n;
    vi a(n);
    fore(i, 0, n)
    {
    	cin >> a[i];
    	h -= a[i];
    }
    if (h <= 0) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}
// PLUS ULTRA!

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}

const string YES = "APPROVED";
const string NO = "DENIED";
#define judge(f) cout<<(f?YES:NO)<<"\n";

void solve(long long N, V A){
    bool f=true;;
    for (ll i = 0; i < N; i++) {
        if(A[i]%2==0){
            if(A[i]%3==0||A[i]%5==0){
                f=true;
            }else{
                f=false;
                break;
            }
        }
    }
    judge(f);
}

int main(){
    ll N;
    cin>>N;
    V A(N);
    for (ll i = 0; i < N; i++) {
        cin>>A[i];
    }
    solve(N, move(A));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> pass(N, 0);
	for (int i = 0; i < M; i++)
	{
		int l, r;
		cin >> l >> r;
		l--;
		pass[l]++;
		pass[r]--;
	}

	for (int i = 1; i < N; i++)
	{
		pass[i] += pass[i - 1];
	}
	int res = 0;
	for (int i = 0; i < N; i++)
	{
		if (pass[i] == M)
			res++;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <utility>
#include <tuple>
#include <queue>

using namespace std;

int main()
{
    int n, a[110], cnt=0;
    vector<int> vec;
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
        if (a[i]%2==1) vec.push_back(a[i]);
        else cnt+=a[i];
    }
    if (vec.size()%2==0)
    {
        for (int i=0; i<vec.size(); i++) cnt+=vec[i];
    }
    else
    {
        sort(vec.begin(), vec.end());
        for (int i=1; i<vec.size(); i++) cnt+=vec[i];
    }
    cout<<cnt/2<<endl;
    return 0;
}



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

//問題文より、入力される文字列の最大の長さ
#define MAXLENGTH 100

int main(void)
{
	char sentence[MAXLENGTH], phrase[MAXLENGTH];
	int sentence_length, phrase_length;
	int start_point, i, j;
	int flag;

	//それぞれ文字列sと文字列pを入力し、その長さを取得する
	scanf("%s", sentence);
	scanf("%s", phrase);
	sentence_length = strlen(sentence);
	phrase_length = strlen(phrase);

	//flagが1ならば文字列sから文字列pが作れる
	flag = 0;
	//文字列の開始位置が最後まで到達すると繰り返し終了
	for(start_point = 0; start_point < sentence_length; start_point++){
		i = start_point;
		j = 0;
		//文字が一致していれば次の文字と比較
		while(sentence[i] == phrase[j]){
			i++;
			//文字列はリング状となっているため最初の文字に戻る
			if(i >= sentence_length){
				i = 0;
			}
			j++;
		}
		//一致した文字数と文字列pの長さが等しければ "Yes" となる
		if(j >= phrase_length){
			flag = 1;
			break;
		}
	}

	//結果を出力
	if(flag){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
}


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

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

    vector<double> a(n);
    double suma=0;
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
        suma += a.at(i);
    }

    int c=0;

    for (int i=0; i<n; i++) {
        if (suma/(4.0*m) <= a.at(i)) c++;
    }

    if (c >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    string s; cin>>s;
    int n=s.size();
    int scnt=0, ans=0;
    for(int i=0; i<n; i++){
        if(s[i]=='S') scnt++;
        if(scnt>0 && s[i]=='T'){
            scnt--;
            ans++;
        }
    }
    cout << n-ans*2 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
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();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  int l[10], v[2];

  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
	&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v[0],&v[1]) != EOF) {
    int sum = 0;
    double time = 0;

    REP(i, 10) sum += l[i];
    time = (double)sum / (v[0]+v[1]);
    double len = v[0] * time;
    REP(i, 10) {
      len -= l[i];
      if(len <= 0) {
	cout << i+1 << endl;
	break;
      }
    }
  }
}

Measured memory_bytes: 1208
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    if len(S)+1 == len(T) and S == T[:len(S)]:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9136
def main():
    n, k = map(int, input().split())
    a_list = list(map(int, input().split()))
    ans = 10 ** 12

    for i in range(2 ** n):
        highest = 0
        cost = 0
        cnt = 0

        for j in range(n):
            if (i >> j) & 1:
                cnt += 1
                if highest < a_list[j]:
                    highest = a_list[j]
                else:
                    highest += 1
                    cost += highest - a_list[j]
            else:
                highest = max(highest, a_list[j])

        if cnt < k:
            continue

        ans = min(ans, cost)

    print(ans)


if __name__ == "__main__":
    main()


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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n;

vector<int> G[maxn];

int f[maxn];

void dfs(int u,int fa){
	for(auto v:G[u])if(v!=fa){
		dfs(v,u);
		f[u]^=f[v]+1;
	}
}

void Work(){
	dfs(1,0);
	if(f[1])puts("Alice");else puts("Bob");
}

void Init(){
	read(n);
	REP(i,2,n){
		int u,v;read(u,v);
		G[u].PB(v);G[v].PB(u);
	}
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 12288
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

int N;

int main(void) {

	cin >> N;

	int ans = (int) ((1.0*N) / 1.08);

	if (N == (int) (1.0*ans*1.08)) { cout << ans << endl; }
	else if (N == (int)((1.0*ans + 1.0)*1.08)) { cout << ans + 1 << endl; }
	else { cout << ":(" << endl; }

	//cout << ans << " "<<ans*1.08 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(ll i = s; i < n; i++)
typedef long long ll;
const ll P = 1000000007;
const ll maxn = 1005;
int H,W;
string grid[maxn];
ll d[maxn][maxn];

ll dp(ll x, ll y){
	if(d[x][y]!=-1) return d[x][y];
	ll ans = 0; int nx,ny;
	//right
	nx = x; ny = y+1;
	if(ny>=W||grid[nx][ny]=='#');
	else{
		ans+=dp(nx,ny);
	}
	//down
	nx = x+1;ny = y;
	if(nx>=H||grid[nx][ny]=='#');
	else ans+=dp(nx,ny);
	return d[x][y] = ans%P;
}


int main(){
	cin>>H>>W;
	rep(i,0,H) cin>>grid[i];
	memset(d,-1,sizeof d);
	d[H-1][W-1] = 1;
	cout<<dp(0,0)<<endl;
}

Measured memory_bytes: 9344
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll N, K; cin >> N >> K;
    if(K > (N-1)*(N-2)/2){
        prtl(-1);
        return 0;
    } 
    if(K == 0){
        vector<P> ans(0);
        rep(i, 2, N+1){
            rep(j, 1, i){
                ans.emplace_back(mp(i, j));
            }
        }
        prtl(sz(ans));
        for(auto x: ans){
            prt(x.first); prt(" "); prtl(x.second);
        }
        return 0;
    }
    ll n = 0;
    bool t = true;
    while(t){
        ll c = n*(n-1)/2;
        n++;
        ll d = n*(n-1)/2;
        if(c < K&&d >= K){
            t = false;
        }
    }
    ll r = n*(n-1)/2 - K;
    vector<P> ans(0);
    rep(i, 0, n){
        ans.emplace_back(mp(1, i+2));
    }
    rep(i, 0, r){
        ans.emplace_back(mp(i+2, i+3));
    }
    rep(i, n+2, N+1){
        rep(j, 1, i){
            ans.emplace_back(mp(i, j));
        }
    }
    prtl(sz(ans));
    for(auto x: ans){
        prt(x.first); prt(" "); prtl(x.second);
    }
}


    





Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    ll f[n][35];
    ll a[n];
    rep(i,n){
        cin >> a[i];
        ll aa = a[i];
        rep(j,35){
            f[i][j] = aa % 2;
            aa /= 2;
        }
    }

    ll two[40] = {};
    two[0] = 1;
    srep(i,1,40)two[i] = two[i-1] * 2;
    ll b[n] = {};
    rep(j,35){
        int cnt = 0;
        rep(i,n)cnt += f[i][j];
        rep(i,n){
            if(cnt % 2 == 0){
                b[i] += two[j] * f[i][j];
            }else{
                b[i] += two[j] * ((f[i][j] + 1) % 2);
            }
        }
    }

    rep(i,n)cout << b[i] << ' ';
    cout << endl;
    return 0;
}




Measured memory_bytes: 61336
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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 int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//桁数のカウント
//pow(x,n) == x^n
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}



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

int h,a,count = 0;
cin >> h >> a;
while(1) {
    h -= a;
    count++;
    if(h <= 0) break;
}
cout << count << endl;

//////////////////////////////////////////////////////
return 0;}

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

int main() {
  int N, W;
  cin >> N >> W;
  
  vector<int> v(N);
  vector<int> w(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i] >> w[i];
  }

  vector<vector<int> > DP(N);
  for (int i = 0; i < N; i++) {
    DP[i].resize(W + 1);
    fill(DP[i].begin(), DP[i].end(), 0);
  }

  for (int i = 1; w[0] * i <= W; i++) {
    DP[0][w[0] * i] = v[0] * i;
  }
  for (int i = 1; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      if (j < w[i]) {
	DP[i][j] = DP[i - 1][j];
      } else {
	DP[i][j] = max(DP[i][j - w[i]] + v[i], DP[i - 1][j]);
      }
    }
  }
  
  int maxVal = 0;
  for (int i = 0; i <= W; i++) {
    maxVal = max(DP[N - 1][i], maxVal);
  }
  cout << maxVal << endl;
  
  return 0;
}

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double
#define DUMP(v) "," #v ":" << v


int main(){
  int n, x, t;
  cin >> n >> x >> t;
  cout << ((n % x > 0) ? (n/x+1)*t : n/x*t ) << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a,b;
int main() {
	scanf("%d%d",&a,&b);
	int x=a+b,y=a-b,z=a*b;
	printf("%d\n",max(max(x,y),z));
	return 0;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String input = sc.next();
		
		boolean flag = input.length() >= 6 && input.matches(".*[a-z]+.*") && input.matches(".*[A-Z]+.*") && input.matches(".*[0-9]+.*");
		
		System.out.println(flag ? "VALID" : "INVALID");
	}

}

Measured memory_bytes: 17324
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}








int main(int argc, const char * argv[]) {
    
    
    int n; cin >> n;
    int ans = 0;
    rep(i,n){
        int r,l; cin >> r >> l;
        ans += l-r+1;
    }
    cout << ans << endl;
    
    
    
    
}



Measured memory_bytes: 256
int main(void)
{
	int b1;
	int b2;
	int b3;
	
	scanf ("%d %d %d", &b1, &b2, &b3);
	
	if ((b1 == 1 && b2 == 0 && b3 == 0) || (b1 == 0 && b2 == 1 && b3 == 0) || (b1 == 0 && b2 == 0 && b3 == 0)){
		printf ("Close\n");
	}
	
	else if ((b1 == 1 && b2 == 1 && b3 == 0) || (b1 == 0 && b2 == 0 && b3 == 1)){
		printf ("Open\n");
	}
	
	return (0);
}

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

int main() {

    string S;
    cin >> S;

    int n = S.size();

    int minD = INF;
    rep(i, n-2){

        int num = stoi(S.substr(i,3));

        if(abs(num-753) < minD){
            minD = abs(num-753);
        }
    }

    cout << minD << endl;
    return 0;
}

Measured memory_bytes: 256
a, b, c, d, e, f = map(int, input().split())
x = []
y = []
t = 100 * e / (100 + e)
for i in range(f // (100 * a) + 1):
    bb = f - 100 * a * i
    for j in range(bb // (100 * b) + 1):
        if 100 * (a * i + b * j) in x:
            continue
        else:
            x.append(100 * (a * i + b * j))
for i in range(f // c + 1):
    dd = f - c * i
    for j in range(dd // d + 1):
        if c * i + d * j in y:
            continue
        else:
            y.append(c * i + d * j)
y.sort()
rr = 0
ans = []
for i, xi in enumerate(x):
    for j, yi in enumerate(y):
        if xi + yi == 0:
            continue
        r = 100 * yi / (xi + yi)
        if r > t:
            break
        elif xi + yi <= f and rr <= r:
            ans = [xi + yi, yi]
            rr = r
print(ans[0], ans[1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,x,i,ans=0;cin>>N>>x;ll A[N];
  REP(i,N)cin>>A[i];
  if(A[0]>x){ans+=A[0]-x;A[0]=x;}
  FOR(i,1,N)if(A[i]+A[i-1]>x){
    ans+=A[i]+A[i-1]-x;
    A[i]=x-A[i-1];
  }
  cout<<ans<<endl;
  return 0;
}

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


int main(){
	int n,m,a,b;
	cin >> n;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	cin >> m;
	for(int i=0;i<m;i++){
		int sum=0;
		cin >> a >> b;
		for(int j=0;j<n;j++){
			if(a-1==j){
				sum+=b;
			}
			else{
				sum+=v[j];
			}
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
#include<stack>
#include<cmath>
#define int long long
using namespace std;
inline void read(int &x){
	x=0;int f=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();	}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	x*=f;
}
char s[100020];
int n,cnt;
signed main()
{
    scanf("%lld",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
        if(s[i]!=s[i-1])
            cnt++;
    
    cout<<cnt;
}

Measured memory_bytes: 384
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        H: usize,
        W: usize,
        h: usize,
        w: usize,
    }
    println!("{}", (H - h) * (W - w));
}


Measured memory_bytes: 4352
import heapq
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB = sorted(AB, key=lambda x: x[0])

x = 0
res = 0

hq = []
heapq.heapify(hq)

for i in range(M):
    for j in range(x, N):
        if AB[j][0] > i+1:
            x = j
            break
        heapq.heappush(hq, AB[j][1]*-1)
    else:
        x = N
    
    if hq:
        res += heapq.heappop(hq)*-1

print(res)


Measured memory_bytes: 30816
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        //値を取得
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        String[] S = new String[N];
        for (int i = 0; i < N; ++i){
            S[i] = sc.next();
        }
        
        int[] C = new int[4];
        
        for (int i = 0; i < N; ++i){
            if(S[i].equals("AC")){
                C[0]++;
            } else if(S[i].equals("WA")){
                C[1]++;
            } else if(S[i].equals("TLE")){
                C[2]++;
            } else if(S[i].equals("RE")){
                C[3]++;
            }
        }
        
        //出力
        System.out.println("AC x " + C[0]);
        System.out.println("WA x " + C[1]);
        System.out.println("TLE x " + C[2]);
        System.out.println("RE x " + C[3]);
    }
}


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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(auto &e : A) cin >> e;
    map<int, int> ma;
    int64_t ans = 0;
    for(int i = 0; i < N; ++i) {
        ans += ma[i - A[i]];
        ma[i + A[i]]++;
    }
    cout << ans << '\n';
    return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
ll a,b,c,k;
cin>>a>>b>>c>>k;

if(a+b>=k){
  cout<<min(a,k)<<endl;
}
else 
{
  cout<<a-(k-a-b)<<endl;
}



  return 0;
}


Measured memory_bytes: 3588
def main():
    x, y = map(int, input().split())

    tsuru = x
    kame = 0

    while tsuru >= 0:
        if tsuru * 2 + kame * 4 == y:
            return "Yes"
        tsuru -= 1
        kame += 1
    

    return "No"

if __name__ == "__main__":
    print(main())



Measured memory_bytes: 9172
#include<stdio.h>
int main(){
  int a,b,i,j,n;
  while(scanf("%d %d",&a,&b)!=EOF){
    i=a+b;
    for(j=0;i>=10;j++){
      n=i/10;
      i=n;
    }
    j++;
    printf("%d\n",j);
  }
  return (0);
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long int ll;

const ll MAX_N = 2 * 1000;

int main () {
    ll n;
    ll L[MAX_N];
    ll ans = 0;

    cin >> n;

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

    sort(L, L + n, greater<>());

    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            for (int k = j + 1; k < n; k++) {
                if ((L[i] < L[j] + L[k]) && (L[j] < L[i] + L[k]) && (L[k] < L[i] + L[j])) {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  if (N % 2 == 0 && K <= N / 2){
    cout << "YES" << endl;
  }
  else if (N % 2 == 1 && K <= N / 2 + 1){
    cout << "YES" << endl;
  }
  else{
      cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import itertools
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-(10**12)
for i in range(1,11):
    num=list(itertools.combinations(range(10),i))
    for j in range(len(num)):
        cnt=[0]*n
        cnt2=0
        for k in range(i):
            for l in range(n):
                if f[l][num[j][k]]==1:
                    cnt[l]+=1
        for k in range(n):
            cnt2+=p[k][cnt[k]]
        ans=max(cnt2,ans)
print(ans)


Measured memory_bytes: 9200
#include<stdio.h>

#define MAX 25

typedef struct{
  int parent;
  int left;
  int right;
}Tree;

int DEGREE( int );
int DEPTH( int );
int HEIGHT( int );
int get_sibling( int );

Tree T[MAX];

int main()
{
  int i, n, id, left, right, degree, depth, height, sibling;

  scanf("%d", &n);

  for( i=0; i<n; i++ )
    {
      T[i].parent = -1;
      T[i].left = -1;
      T[i].right = -1;
    }

  for( i=0; i<n; i++ )
    {
      scanf("%d%d%d", &id, &left, &right);
      
      T[id].left = left;
      T[id].right = right;
      if( left != -1) T[left].parent = id;
      if( right != -1 ) T[right].parent = id;
    }


  for( i=0; i<n; i++ )
    {
      printf("node %d: ", i);
      printf("parent = %d, ", T[i].parent);

      sibling = get_sibling(i);
      printf("sibling = %d, ", sibling);

  
      degree = DEGREE(i);
      printf("degree = %d, ", degree );


      depth = DEPTH(i);
      printf("depth = %d, ", depth);

      height = HEIGHT(i);

      printf("height = %d, ", height);

      if( T[i].parent == -1 ) printf("root\n");

      else if( degree == 0 ) printf("leaf\n");

      else printf("internal node\n");
    }

  return 0;
}

      
int DEGREE( int id )
{
  int count=0;

  if( T[id].left != -1 ) count++;
  if( T[id].right != -1 ) count++;

  return count;
}
      

int DEPTH( int id )
{
  int count=0;

  while( T[id].parent != -1 )
    {
      id = T[id].parent;
      count++;
    }
  return count;
}


int HEIGHT( int id )
{
  int h1=0, h2=0;
  if( T[id].right != -1 )
    {
      h1 = HEIGHT( T[id].right ) + 1;
    }
  if( T[id].left != -1 )
    {
      h2 = HEIGHT( T[id].left ) + 1;
    }

  if( h1 > h2 ) return h1;
  else return h2;
}


int get_sibling( int id )
{
  if( T[id].parent == -1 )
    {
      return -1;
    }
  else if( T[T[id].parent].left != id )
    {
      return T[T[id].parent].left;
    }
  else if( T[T[id].parent].right != id )
    {
      return T[T[id].parent].right;
    }
}
  



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

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



Measured memory_bytes: 3112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int n = Integer.parseInt(tmpArray[0]);
		int m = Integer.parseInt(tmpArray[1]);
		int x = Integer.parseInt(tmpArray[2]);
		int y = Integer.parseInt(tmpArray[3]);
		
		int inputX[] = new int[n];
		int inputY[] = new int[m];
		
		tmpArray = br.readLine().split(" ");
		
		for(int i = 0; i < n; i++){
			inputX[i] = Integer.parseInt(tmpArray[i]);
		}
		
		tmpArray = br.readLine().split(" ");
		
		for(int i = 0; i < m; i++){
			inputY[i] = Integer.parseInt(tmpArray[i]);
		}
		
		Arrays.sort(inputX);
		Arrays.sort(inputY);
		
		
		for(int i = x + 1; i <= y; i++){
			if(i > inputX[n - 1] && i <= inputY[0]){
				System.out.println("No War");
				return;
			}
		}
		
		System.out.println("War");
	}

}


Measured memory_bytes: 22484
#include <stdio.h>
 
int main(){
  int N,Q;scanf("%d%d",&N,&Q);
  char S[N];scanf("%s",S);
  int AC[N];AC[0]=0;
  for(int j=1;j<N;j++){
    AC[j]=(S[j-1]=='A'&&S[j]=='C')?AC[j-1]+1:AC[j-1];
  }
  int l,r;
  for (int k=0;k<Q;k++){
    scanf("%d%d",&l,&r);
   	printf("%d\n",AC[r-1]-AC[l-1]);
  }
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int main(){
	ll N; cin >> N;
	static ll A[200002];
	
	REP(i,N){
		cin >> A[i];
	}
	
	ll nsum = 0;
	ll nxor = 0;
	ll ret = 0;
	
	ll right = 0;
	
	for (ll left = 0 ; left < N ; left++){
		while((right < N) && ((nsum + A[right]) == (nxor ^ A[right]))){
			nsum += A[right];
			nxor ^= A[right];
			right++;
		}
		
		ret += right - left;
		if (left == right) {
			right++;
		}else{
			nsum -= A[left];
			nxor ^= A[left];
		}
	}
	
	PRINTLLD(ret);
	
	return 0;
}


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

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

  for(int i = 0; i < N; i++) cin >> v.at(i);
  
  sort(v.begin(), v.end());
  
  double sum = 0;
  
  for(int i = 0; i < N; i++) {
    if(i == 0) sum += double(v.at(0)) / pow(2, N - 1);
    else sum += double(v.at(i)) / pow(2, N - i);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
n = gets.chomp.to_i

S = 'MARCH'.split('')

counter = {}
S.each{|c| counter[c] = 0}

n.times do |i|
  s = gets.chomp
  
  if S.find{|c| c == s[0]} != nil then
    counter[ s[0] ] += 1
  end
end

counter.select!{|k, v| v > 0}
if counter.size >= 3 then
  comb = 0
  
  counter.map{|k, v| k}.combination(3).each do |a|
    comb += a.map{|c| counter[c]}.reduce(:*)
  end
  
  puts comb.to_s
else
  puts 0.to_s
end

Measured memory_bytes: 3836
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

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

int main(void) {
    int A, B; cin >> A >> B;
    cout << (A*3+B)/2 << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    ll mod = 1e9 + 7;
    int N;
    cin >> N;
    vector<vector<ll>> a(N, vector<ll>(N));
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++) cin >> a[i][j];

    vector<vector<ll>> dp(N+1, vector<ll>(1<<N, 0));

    dp[0][0] = 1;
    for(int i=1; i<=N; i++)
        for(int s=0; s<(1<<N); s++) {
            if (__builtin_popcount(s) != i) continue;
            for(int j=1; j<=N; j++) {
                if(a[i-1][j-1] == 1 && (s&(1<<(j-1))))
                    (dp[i][s] += dp[i-1][s&~(1<<(j-1))]) %= mod;
            }
        }

    // for(int s=0; s<(1<<N); s++) cerr << s << " "; cerr << endl;
    // for(int i=0; i<=N; i++){
    //     for(int s=0; s<(1<<N); s++) cerr << dp[i][s] << " "; cerr << endl;
    // }

    cout << dp[N][(1<<N)-1] << endl;
    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

const ll mod = 998244353LL;
ll N,A,B,K;


long long extgcd(long long a,long long b,long long& x,long long& y) {
  long long d = a;
  if(b != 0){
    d = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  } else {
    x = 1,y = 0;
  }
  return d;
}

long long mod_inv(long long a,long long m) {
  long long x,y;
  extgcd(a,m,x,y);
  return (m+x%m)%m;
}

#define MAX 300010
ll mfact[MAX];
ll mfactr[MAX];
ll mfactrs[MAX];

void expt() {
  rep(a,N+1) {
    ll Av = A * a;
    if( Av > K ) continue;
    if( ( K - Av ) % B ) continue;
    ll b = ( K - Av ) / B;
    ll need = min((ll)a,b) + ((ll)a-min((ll)a,b)) + (b-min((ll)a,b));
    if( need > N ) continue;
    //if( a + b > N ) continue;
    ll Bv = B * b;
    assert( Av + Bv == K );
    /*
    cout << "Av = " << Av << " ( = " << A << " * " << a << " )" << endl;
    cout << "Bv = " << Bv << " ( = " << B << " * " << b << " )" << endl;
    cout << "N<?> " << need << endl;
    */
    puts("");
  }
}

// [L,R]
ll calc(ll L,ll  R) {
  ll ret = mfactrs[R];
  if( L-1LL >= 0LL ) ret -= mfactrs[L-1];
  while( ret < 0LL ) ( ret += mod ) %= mod;
  return ret;
}

void expt2() {
  ll sum = 0;
  rep(a,N+1) {
    ll Av = A * a;
    if( Av > K ) continue;
    if( ( K - Av ) % B ) continue;
    ll b = ( K - Av ) / B;
    ll Bv = B * b;
    assert( Av + Bv == K );
    if( b > N ) continue;
    ll costa = 0, costb=0;
    costa = ( mfact[N] * mfactr[N-a] ) % mod;
    costa = ( costa * mfactr[a] ) % mod;
    costb = ( mfact[N] * mfactr[N-b] ) % mod;
    costb = ( costb * mfactr[b] ) % mod;
    ( sum += ( ( costa * costb) % mod ) ) %= mod;
  }
  cout << sum << endl;
}

void compute() {
  mfact[0] = 1 % mod;
  REP(i,1,N+1) mfact[i] = ( mfact[i-1] * (ll)i ) % mod;
  rep(i,N+1) mfactr[i] = mod_inv(mfact[i],mod);
  mfactrs[0] = mfactr[0];
  REP(i,1,N+1) mfactrs[i] = ( mfactrs[i-1] + mfactr[i] ) % mod;
  expt2();
}

int main() {
  cin >> N >> A >> B >> K;
  compute();
  return 0;
}


Measured memory_bytes: 7296
A=list(input())
B=list(input())
C=list(input())
t="a"
while True:
  if t=="a":
    if not A:
      print("A")
      break
    else:
      t=A.pop(0)
  elif t=="b":
    if not B:
      print("B")
      break
    else:
      t=B.pop(0)
  else:
    if not C:
      print("C")
      break
    else:
      t=C.pop(0)


Measured memory_bytes: 9052
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
int n[]={0,1,2,1,3,1,3,1,1,3,1,3,1};
int main() {
  int a, b;
  cin >> a >> b;
  if(n[a]==n[b])cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll s;
	scanf("%lld", &s);
	ll n = sqrt(s);
	while(n * n < s) ++n;
	if((n * n - s) % 2 == 0)
	{
		int ret = n * n - s;
		printf("%d %d %d %d %d %d\n", 0, 0, n, 2, ret / 2, n);
	}
	else
	{
		int ret1 = n * (n - 1) - s;
		int ret2 = n * n - s;
		if(ret1 >= 0)
			printf("%d %d %d %d %d %d\n", 0, 0, n, 1, ret1, n - 1);
		else
			printf("%d %d %d %d %d %d\n", 0, 0, n, 1, ret2, n);
	}
	return 0;
}
	 

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, B: "List[int]"):
    A = [B[0]]
    for i in range(len(B)-1):
        A.append(min(B[i],B[i+1]))
    A.append(B[-1])

    print(sum(A))




# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    B = [ int(next(tokens)) for _ in range(N-1) ]  # type: "List[int]"
    solve(N, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[1010][1010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc;

int main(){
    cin>>n;
    C n*800-n/15*200 E;

}

//g++ atcoder.cpp ; ./a.exe

Measured memory_bytes: 256