akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, u, v, m;
	cin >> n >> u >> v >> m;
	map<int, pii> a, b;
	REP(i, n)REP(j, n) {
		int c;
		cin >> c;
		a[c] = { i,j };
	}
	REP(i, n)REP(j, n) {
		int c;
		cin >> c;
		b[c] = { i,j };
	}
	vi ra(n, 0), ca(n, 0), rb(n, 0), cb(n, 0);
	int cnta = 0, cntb = 0, da1 = 0, da2 = 0, db1 = 0, db2 = 0;
	bool done = false;
	REP(aaa, m) {
		int num; cin >> num;
		if (a.count(num)) {
			int x, y;
			tie(x, y) = a[num];
			
			if (++ra[x] == n)cnta++;
			if (++ca[y] == n)cnta++;
			if (x + y == n - 1 && ++da1 == n)cnta++;
			if (x == y && ++da2 == n)cnta++;
		}
		if (b.count(num)) {
			int x, y;
			tie(x, y) = b[num];

			if (++rb[x] == n)cntb++;
			if (++cb[y] == n)cntb++;
			if (x + y == n - 1 && ++db1 == n)cntb++;
			if (x == y && ++db2 == n)cntb++;
		}
		if (n == 1) {
			chmin(cnta, 1);
			chmin(cntb, 1);
		}
		if (cnta >= u && cntb >= v) {
			cout << "DRAW" << endl;
			done = true;
			break;
		}
		else if (cnta >= u) {
			cout << "USAGI" << endl;
			done = true;
			break;
		}
		else if(cntb>=v) {
			cout << "NEKO" << endl;
			done = true;
				break;
		}
	}
	if (!done) {
		cout << "DRAW" << endl;
	}
}


Measured memory_bytes: 21052
#define _CRT_SECURE_NO_WARNINGS
//                  Allah_Almost3aan       
//      *{ربى..  كنْ لىِ خيرَ مدبر فإنى لا احسنُ التدبير}*
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
using ll = long long;
ll mod = 1e9 + 7;
const ll  OO = 1e18;
#define ed "\n"
#define ff first
#define ss second
#define sz(a) a.size()
#define INF 1e9
#define SZ 1000007
#define RT(v) return cout<<v<<ed,0
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stpr(n) fixed<<setprecision(n)
#define pi 3.14159265358979323846
int di[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dj[8] = { 0, -1, 0, 1, 1, 1, -1, -1 };
const int N = 1.5 * 10000000 + 16;
string ys = "YES", no = "NO";
void fast() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
}
int main() {
	fast();
	int n; cin >> n; 
cout<<n*n<<ed;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	 long long int N, c = 0;
	bool flag = true;
	cin >> N;
	vector<int>A(N + 1);
	vector<int>B(N);
	for ( long long int i = 0; i < N + 1; i++)cin >> A[i];
	for ( long long int i = 0; i < N; i++)cin >> B[i];
	for ( long long int i = 0; i < N + 1; i++)
	{
		if (i != 0 && i != N) {
			if (A[i] <= B[i - 1]) {
				c += A[i];
				A[i] = 0;
			}
			else {
				A[i] -= max(B[i - 1], 0);
				c += B[i - 1];
				B[i - 1] = 0;
			}
			if (A[i] != 0 && A[i] <= B[i]) {
				c += A[i];
				B[i] -= A[i];
				A[i] = 0;
			}
			else if (A[i] != 0 && A[i] > B[i]) {
				c += B[i];
				A[i] -= B[i];
				B[i] = 0;
			}
		}
		else if (i == 0)
		{
			if (A[i] <= B[i]) {
				c += A[i];
				B[i] -= A[i];
				A[i] = 0;
			}
			else {
				c += B[i];
				B[i] = 0;
			}
		}
		else if (i == N)
		{
			if (A[i] <= B[i - 1]) {
				c += A[i];
				B[i - 1] -= A[i];
				A[i] = 0;
			}
			else {
				c += B[i - 1];
			}
		}
		//c+=A[i];
	}
	cout << c;
}


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

int main() {
  ll N, C;
  cin >> N >> C;
  vector<pair<ll, ll>> sushi(N);
  for (int i = 0; i < N; i++) cin >> sushi[i].first >> sushi[i].second;
  vector<ll> R(N), S(N), Rmax(N), Smax(N);
  //原点から時計回り
  R[0] = sushi[0].second - sushi[0].first;
  Rmax[0] = max((ll)0, R[0]);
  for (int i = 1; i < N; i++) {
    R[i] = R[i-1] + sushi[i].second - (sushi[i].first - sushi[i-1].first);
    Rmax[i] = max(Rmax[i-1], R[i]);
  }
  //原点から反時計回り
  S[N-1] = sushi[N-1].second - (C - sushi[N-1].first);
  Smax[N-1] = max((ll)0, S[N-1]);
  for (int i = N-2; i >= 0; i--) {
    S[i] = S[i+1] + sushi[i].second - (sushi[i+1].first - sushi[i].first);
    Smax[i] = max(Smax[i+1], S[i]);
  }

  ll ans = 0;
  // 時計回り→反時計回り
  for (int i = 0; i < N-1; i++) ans = max(ans, R[i] - sushi[i].first + Smax[i+1]);
  ans = max(ans, Rmax[N-1]);
  // 反時計回り→時計回り
  for (int i = N-1; i > 0; i--) ans = max(ans, S[i] - (C - sushi[i].first) + Rmax[i-1]);
  ans = max(ans, Smax[0]);
  cout << ans << endl;
}


Measured memory_bytes: 8000
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
		cin >> a.at(i);

	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	int A = 0, B = 0;
	for (int i = 0; i < N; i = i + 2)
		A += a.at(i);
	for (int i = 1; i < N; i = i + 2)
		B += a.at(i);
	cout << A - B << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

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

int main(void){
  int N;
  while(cin>>N,N){
    int W,H;
    cin>>W>>H;
    int dp[101][101]={};
    int tree[101][101]={};
    while(N--){
      int x,y;
      cin>>x>>y;
      tree[y][x] = 1;
    }
    REP(y,H+1){
      REP(x,W+1){
        dp[y+1][x+1] = -dp[y][x] + dp[y+1][x] + dp[y][x+1] + tree[y+1][x+1];
      }
    }
    int DX,DY;
    cin>>DX>>DY;
    int maxtree = 0;
    PII ans;
    for(int y=0;y+DY<=H;y++){
      for(int x=0;x+DX<=W;x++){
        int treesize = dp[y][x]+dp[y+DY][x+DX]-dp[y][x+DX]-dp[y+DY][x];
        if(treesize>maxtree){
          maxtree = treesize;
        }
      }
    }
    cout<<maxtree<<endl;
  } 

  return 0;
}

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

int main(){
    vector<int> ary;
    for(int i = 2; i <= 55555; i++){
        bool flag = true;
        for(int j = 2; j <= sqrt(i); j++){
            if(i % j == 0){
                flag = false;
                break;
            }
        }
        if(flag && i % 5 == 1) ary.push_back(i);
    }
    int n;
    cin >> n;
    rep(i, n){
        if(i) printf(" ");
        printf("%d", ary[i]);
    }
    printf("\n");
}

Measured memory_bytes: 256
n,m,k = map(int,input().split())
A = [int(p) for p in input().split()]
B = [int(p) for p in input().split()]
a,b = [0],[0]

a_apnd = a.append
b_apnd = b.append
for i in range(n):
  a_apnd(a[i]+A[i])
for i in range(m):
  b_apnd(b[i]+B[i])

count = 0
t = m
for i in range(n+1):
  if k<a[i]:
    break
  while b[t] > k-a[i]:
    t -= 1
  count = max(count,i+t)

print(count)

Measured memory_bytes: 47368
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int W = scanner.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        for (int i = 0; i < n; ++i) {
            w[i] = scanner.nextInt();
            v[i] = scanner.nextInt();
        }
        System.out.println(solve(W, w, v));
    }

    private static long solve(int W, int[] w, int[] v) {
        long[][] dp = new long[w.length][W + 1];
        for (int i = 0; i < dp.length; ++i)
            Arrays.fill(dp[i], -1);
        return findMax(0, w, v, W, dp);
    }

    private static long findMax(int ind, int[] w, int[] v, int W, long[][] dp) {
        if (ind > w.length - 1)
            return 0;
        if (dp[ind][W] >= 0)
            return dp[ind][W];
        long res;
        if (w[ind] > W) {
             res = findMax(ind + 1, w, v, W, dp);
        } else {
            res = Math.max(
                    v[ind] + findMax(ind + 1, w, v, W - w[ind], dp),
                    findMax(ind + 1, w, v, W, dp));
        }
        dp[ind][W] = res;
        return res;
    }
}


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

int main() {
    string w;
    cin >> w;
    vector <char> W;
    bool flag = true;
    for (int i = 0; i < w.size(); i++){
        W.push_back(w[i]);
    }
    sort(W.begin(), W.end());
    char tmp = W.at(0);
    int cnt = 1;
    for (int i = 1; i<W.size(); i++){
        if (tmp == W.at(i)) cnt++;
        else{
            if (cnt%2 != 0) flag = false;
            cnt = 1;
            tmp = W.at(i);
        }
    }
    if (cnt%2 != 0) {
        flag = false;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int64_t n, m, l;
	cin >> n >> m >> l;
	vector<vector<int64_t>> a(n, vector<int64_t>(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a.at(i).at(j);
		}
	}
	vector<vector<int64_t>> b(m, vector<int64_t>(l));
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			cin >> b.at(i).at(j);
		}
	}
	vector<vector<int64_t>> c(n, vector<int64_t>(l));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			int64_t sum = 0;
			for (int k = 0; k < m; k++) {
				sum += a.at(i).at(k) * b.at(k).at(j);
			}
			cout << sum;
			if (j < l - 1) cout << " ";
			else cout << endl;
		}
	}
}


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

using namespace std;

using ll = long long;

int main(){
    ll l, r; cin >> l >> r;
    ll ans = INT_MAX;
    if(r - l >= 10000)cout << 0;
    else{
        for(ll i = l; i < r; ++i){
            for(ll j = l + 1; j <= r; ++j){
                ans = min(ans, i * j % 2019);
            }
        }
        cout << ans;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int n,m;
int p[20],c[20];
int f[200][200];
int minA=1000000;
int tt=0;
void check(int s)
{
    bool sel[20];
    int ans=0;
    int remin=m;
    memset(sel,0,sizeof(sel));
    for (int i=1; i<=n; ++i)
    {
        sel[i] = ((1<<i)&s);
        if (sel[i]==1)
        {
            ans+=p[i];
            remin-=c[i];
            remin-=i*100*p[i];
        }
    }
    for (int i=n; i>=1; --i)
        if (sel[i]==0)
        {
            if (remin<=0) break;
            for (int j=0; j<=p[i]; ++j)
            {
                if (remin<=0) break;
                remin-=i*100;
                ans+=1;
            }
        }
    if (remin>0) return;
    if (ans<minA) minA=ans;
}
void dps(int s,int i)
{
    if (i==n+1)
    {
        check(s);
    }else
    {
    dps(s+(1<<i),i+1);
    dps(s,i+1);
    }
}

int main()
{
    cin>>n>>m;
    for (int i=1; i<=n; ++i)
        cin>>p[i]>>c[i];
    dps(0,1);
    cout<<minA<<endl;
}



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

struct edge{int to;int cost;};
vector<edge> g[100001];
vector<bool> memo(100001,0);
vector<bool> ans(100001,0);

void arc(int t,int c){
  int i;
  memo[t]=1;
  for(i=0;i<g[t].size();i++){
    int nt=g[t][i].to;
    if(memo[nt]) continue;
    else{
      ll nc=c+g[t][i].cost;
      if(nc%2!=0) ans[nt]=1;
      arc(nt,nc);
    }
  }
}

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

  int i;
  for(i=0;i<n-1;i++){
    int u,v,w;
    cin>>u>>v>>w;
    u--;v--;
    edge a={u,w};
    edge b={v,w};
    g[u].push_back(b);
    g[v].push_back(a);
  }

  arc(0,0);
  for(i=0;i<n;i++){
    if(ans[i])
    cout<<1<<endl;
    else
    cout<<0<<endl;
  }

}


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

int main(){
    int sx,sy,gx,gy;
    cin>>sx>>sy>>gx>>gy;
    string ans="";
    for(int i=0;i<gy-sy;i++){
        ans+="U";
    }
    for(int i=0;i<gx-sx;i++){
        ans+="R";
    }
    for(int i=0;i<gy-sy;i++){
        ans+="D";
    }
    for(int i=0;i<gx-sx+1;i++){
        ans+="L";
    }
    for(int i=0;i<gy-sy+1;i++){
        ans+="U";
    }
    for(int i=0;i<gx-sx+1;i++){
        ans+="R";
    }
    ans+="D";
    ans+="R";
    for(int i=0;i<gy-sy+1;i++){
        ans+="D";
    }
    for(int i=0;i<gx-sx+1;i++){
        ans+="L";
    }
    ans+="U";
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int N,K,S;

int dfs(int d,int n,int s)
{
	int i,r=0;
	if(d==K&&n==0)
		return 1;
	if(s>N||d>=K)return 0;
	for(i=s;i<=N;i++)
	{
		r+=dfs(d+1,n-i,i+1);
	}
	return r;
}

int main()
{
	for(;scanf("%d%d%d",&N,&K,&S),N;)
	{
		printf("%d\n",dfs(0,S,1));
	}
	return 0;
}

Measured memory_bytes: 596
function Main(input) {
    var S = input[0];

    var list = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];

    var index = list.indexOf(S);
    console.log(7 - index);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 21060
/*
AizuOnline A0108
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int n;
int p1[12];
int p[12];
int hist[32767]; 
//
hindo(int q[],int q1[],int n)
{
  int i;

  for(i=0;i<32767;i++)
    hist[i]=0;
  for(i=0;i<n;i++)
    hist[q[i]]++;
  for(i=0;i<n;i++)
    q1[i]=hist[q[i]];
}
void	 print_retu(int q[],int n) 
{
  int i;

  for(i=0;i<n;i++)
    {
      printf("%d",q[i]);
      if(i<n-1)
	printf(" ");
    }
  printf("\n");
}
int main()
{
  int i,kai;

  while(EOF!=scanf("%d",&n) && n)
    {
      for(i=0;i<n;i++)
	scanf("%d",&p[i]);

#ifdef DEBUG
	  print_retu(p,n);
#endif

      kai=0;
      while(1)
	{
	  hindo(p,p1,n);
	  if(0==memcmp(p1,p,n*sizeof(int)))
	     break;
#ifdef DEBUG
	  print_retu(p1,n);
#endif
	  memcpy(p,p1,n*sizeof(int));	 
	  kai++;
	}

      printf("%d\n",kai);
      print_retu(p1,n);
    }
      return(0);
}

Measured memory_bytes: 756
f = True
n,m=map(int,input().split())
number = [-1 for i in range(n)]
for i in range(m):
  s,c=list(map(int,input().split()))
  s -= 1
  if s == 0 and c == 0 and n > 1:
    f = False
  elif number[s] == -1 or number[s] == c:
    number[s] = c
  else:
    f = False
if not f:
  print(-1)
elif n == 1:
  if number[0] == -1:
    print(0)
  else:
    print(number[0])
else:
  if number[0] == -1:
    number[0] = 1
  for i in range(1,n):
    if number[i] == -1:
      number[i] = 0
  print(''.join(map(str,number)))

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

int main()
{
  int K,A,B,i=0,n=0;
  
  cin >> K >> A >> B;
  
  for(i = A ; i <= B ; i++)
  {
    if ( i % K == 0 )
    {
      cout << "OK" << endl;
      return 0;
    }
  }
  
  cout <<"\nNG";
  
}


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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    
    sort(a.begin(), a.end(), greater<int> ());

    int al = 0, b=0;
    for(int i=0; i<n; ++i){
        if(i&1)
            b += a[i];
        else
            al += a[i];
    }

    cout << al-b ;
    return 0;
}


Measured memory_bytes: 3576
import sys
import copy
import heapq
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
INF = 10**9 + 7


def solve():
    N, K = map(int, input().split())
    V = deque(list(map(int, input().split())))

    ans = -INF
    for n in range(1, N + 1):
        if n > K:
            break
        for rn in range(n + 1):
            ln = n - rn
            tv = copy.copy(V)
            pv = 0
            mv = []
            heapq.heapify(mv)
            for _ in range(rn):
                v = tv.pop()
                if v >= 0:
                    pv += v
                else:
                    heapq.heappush(mv, v)
            for _ in range(ln):
                v = tv.popleft()
                if v >= 0:
                    pv += v
                else:
                    heapq.heappush(mv, v)

            mvlen = min(K - n, len(mv))
            for _ in range(0, mvlen):
                heapq.heappop(mv)

            #print(ln, rn, pv, mv)
            ans = max(ans, pv + sum(mv))

    print(max(0, ans))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3572
import sys
from io import StringIO
import unittest


def resolve():

    # 問題の前提：1 <= X <= 10億。
    x = int(input())

    # 最下部で行った検証を基に処理を書く。
    # Aが取りうる範囲は・・0~119
    for a in range(120):
        # Bが取りうる範囲は・・-118~119
        for b in range(-118, 120, 1):
            if pow(a, 5) - pow(b, 5) is x:
                print('{} {}'.format(a, b))
                return


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """33"""
        output = """2 -1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1"""
        output = """0 -1"""
        self.assertIO(input, output)

if __name__ == "__main__":

    # unittest.main()
    resolve()

    # (調査)
    # A+Bがいくら以上になる場合、10億を超えるか。(結果が10億を超えるパターンは検証不要)
    # が、例を見てわかるように、「A(40) + B(-39)」の様に、Bは負数にできる。
    # = Xは1以上なので-Aを超えることは無い。
    # なので、必要な情報は、「数値xの5乗 - 数値-(x-1)の5乗 >= 1億」を満たすタイミング。
    #  =>119。これが、ありえる最大パターン。(Aが119でBが-118というパターン)
    # Aが取りうる範囲は・・0~119  Bが取りうる範囲は・・-118~119
    #  =>このパターン数なら、全網羅できる。

    # for i in range(99999999):
    #     if pow(i, 5) + pow(-(i - 1), 5) >= 1000000000:
    #         print(i)
    #         pow(i, 5)
    #         break


Measured memory_bytes: 71140
def factorize(n):
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append([b, e])
        b, e = b + 1, 0
    if n > 1:
        fct.append([n, 1])
    return fct
N=int(input())
fct = factorize(N)
count=0
if fct :
    for i in range(len(fct)):
        tmp=1
        while True:
            if fct[i][1]>=tmp:
                fct[i][1]=fct[i][1]-tmp
                tmp+=1
                count+=1
            else:
                break
    print(count)
else:
    print("0")


Measured memory_bytes: 9228
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


class State
{
public:
	int cost, x, y;
	State(int _cost, int _x, int _y)
	{
		cost = _cost;
		x = _x;
		y = _y;
	}
};

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


int main()
{
	int sx, sy;
	
	while (cin >> sx >> sy, sx || sy)
	{
		int n;
		cin >> n;
		
		bool t[10][10][10];
		memset(t, 0, sizeof(t));
		rep(i, n)
		{
			int x, y;
			cin >> x >> y;
			for (int j=-1; j<=1; j++)
			{
				for (int k=-1; k<=1; k++)
				{
					int nx = x + j;
					int ny = y + k;
					if (nx>=0 && nx<10 && ny>=0 && ny<10) t[i][ny][nx] = true;
				}
			}
		}
		
		queue<State> open;
		open.push(State(-1, sx, sy));
		bool ans = false;
		
		if (n == 0)
		{
			cout << "NA" << endl;
			continue;
		}
		
		while (!open.empty())
		{
			State st = open.front(); open.pop();
			if (st.cost == n - 1)
			{
				ans = true;
				break;
			}
			
			rep(i, 12)
			{
				int nx = st.x + dx[i];
				int ny = st.y + dy[i];
				int nc = st.cost + 1;
				if (nx>=0 && nx<10 && ny>=0 && ny<10 && t[nc][ny][nx])
				{
					open.push(State(nc, nx, ny));
					t[nc][ny][nx] = false;
				}
			}
		}
		cout << (ans ? "OK" : "NA") << endl;
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

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

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

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

int main() {
  int n;
  cin >> n;
  
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if ((i % 3) != 0 && (i % 5) != 0)
      sum += i;
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 3632
i=raw_input()
N,A,B=i.split()

N = int(N)
A = int(A)
B = int(B)

if abs(A-B)%2==0:
  print abs(A-B)/2
else:
  e=min(A-1,N-B)
  d=(B-A+1)/2
  print e+d

Measured memory_bytes: 2568
s=input()
l=len(s)//2
s0="01"*l
if len(s)%2!=0:
    s0+="0"
s1="10"*l
if len(s)%2!=0:
    s1+="1"
ans0=0
ans1=0
for i in range(len(s)):
    if s[i]!=s0[i]:
        ans0+=1
    if s[i]!=s1[i]:
        ans1+=1
print(min(ans0,ans1))

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

using namespace std;

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

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

    int q;
    cin >> q;
    while (q--) {
        int b, e;
        cin >> b >> e;
        reverse(a.begin() + b, a.begin() + e);
    }

    for (int i = 0; i < a.size(); ++i) {
        cout << (i ? " " : "") << a[i];
    }
    cout << endl;
    return 0;
}


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

int t=1;
int n;
int d[101],f[101];
int v[101];
vector<int> edges[101];

void dfs(int cur)
{
    if(d[cur]==-1)
    {
        d[cur]=t;
        v[cur]=1;
        t+=1;
    }
    int dst;
    for(dst=1;dst<=n;dst++)
    {
        int flag=0;
        for(int i=0;i<edges[cur].size();i++)
        {
            if(edges[cur][i]==dst)
				{
					flag=1;
					break;
				}
        }
        if(v[dst]==-1&&flag)
		  dfs(dst);
    }
    if(f[cur]==-1)
    {
        f[cur]=t;
        t+=1;
    }
}

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int u,k,y;
		cin >> u >> k;
		for(int j=0;j<k;j++)
        {
            cin >> y;
            edges[u].push_back(y);
        }
	}
	for(int i=1;i<=n;i++)
	{
        d[i]=-1;
        f[i]=-1;
        v[i]=-1;
    }
	for(int dst=1;dst<=n;dst++)
        dfs(dst);
	for(int i=1;i<=n;i++)
	   cout << i << ' ' << d[i] <<  ' ' <<  f[i] <<  endl;
}


Measured memory_bytes: 3180
import numpy as np
import itertools

N, M, X = map(int, input().split())

As = []

for i in range(N) :
  As.append(list(map(int, input().split())))
  
L_As = len(As[0])
cal = np.zeros(L_As)
ans = []
for j in range(1, N+1) :
  for k in itertools.combinations(As, j) :
    for l in k :
      cal = cal + np.array(l)
    if min(cal[1:L_As]) >= X :
      ans.append(cal[0])
    cal = np.zeros(len(As[0]))

if len(ans) == 0 :
  print("-1")
else :
  print(int(min(ans)))

Measured memory_bytes: 27304
import sys
input = sys.stdin.readline

n = int(input())
a_lst = list(map(int, input().split()))
b_lst = [0]*n

def multiple_i(i, n):
        lst = []
        j = 2
        while(1):
            if i*j <= n:
                lst += [i*j]
                j += 1
            else:
                break
        return lst

for i in range(1, n+1):
    r = a_lst[-i]
    if not n+1-i > n / 2:
        mul_lst = multiple_i(n+1-i, n)
        ball = 0
        for mul in mul_lst:
            if b_lst[mul - 1] == 1:
                ball += 1
        if not ball % 2 == r:
            b_lst[-i] = 1
    else:
        if r == 1:
            b_lst[-i] = 1

m = 0
ans_lst = []
for i in range(n):
    if b_lst[i] == 1:
        m += 1
        ans_lst += [i + 1]

print(m)
for i in range(m):
    print(ans_lst[i], end=" ")


Measured memory_bytes: 20300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<vector<double>> vvd;
typedef vector<double> vd;

#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 1000*1001;

#define forn(i, n) for(int i = 0; i < n; i++)
#define forsn(i, s, n) for(int i = s; i < n; i++)
#define all(x) x.begin(), x.end()


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int h, a;
	cin >> h >> a;
	cout << (h + a - 1) / a << endl;
}		


Measured memory_bytes: 256
#include<stdio.h>

int main() {

	long long int pushCount = 0;
	long long int n;
	scanf("%lld", &n);

	long long int a[100010];
	long long int b[100010];

	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &a[i], &b[i]);
	}
	for (int i = n - 1; i >= 0; i--) {
		long long int plus = 0;
		if ((a[i] + pushCount) % b[i] == 0)	continue;
		plus = b[i] * ((a[i] + pushCount) / b[i] + 1) - (a[i] + pushCount);
		pushCount += plus;
	}
	
	printf("%lld", pushCount);

}



Measured memory_bytes: 1792
# https://atcoder.jp/contests/abc146/submissions/8617148

def solve(N, M, S):
    from collections import namedtuple
    from heapq import heappop, heappush

    INF = N * 2
    V = namedtuple('V', 'cnt index')

    cnt_from_N = [INF] * (N + 1)
    cnt_from_N[N] = 0

    parent = [0] * (N + 1)

    h = [V(cnt=0, index=N)]

    for j in range(N - 1, -1, -1):
        # S[j]に到達する最小回数とその経路を求める
        if S[j]:
            continue

        while h:
            cnt, par = h[0]
            if par > j + M:
                # jまで移動できない(距離>M)
                heappop(h)
                continue
            break
            # jまで最小回数で到達できる頂点par
            # parまでの回数cnt

        if not h:
            return -1,
            # jまで到達できる頂点がない

        cnt_from_N[j] = cnt + 1
        parent[j] = par

        heappush(h, V(cnt=cnt + 1, index=j))

    ret = []
    curr = 0
    while curr < N:
        par = parent[curr]
        ret.append(par - curr)
        curr = par

    return ret


def main():
    N, M = map(int, input().split())
    *S, = map(int, input())
    print(*solve(N, M, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 15084
N , K = map(int, input().split())
tmp = [0]*N
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    
    for j in A:
        if tmp[j-1] == 0:
            tmp[j-1] = 1

print(N - sum(tmp))

Measured memory_bytes: 9152
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	int x, n;
	cin >> x >> n;

	set<int> p;
	int a;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		p.insert(a);
	}

	int closest = INT_MAX;
	for (int i = 0; i <= 101; ++i) {
		if (p.find(i) == p.end()) {
			if (abs(x - closest) > abs(x - i)) {
				closest = i;
			}
		}
	}

	cout << closest << "\n";

	return 0;

}

Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int c[101000];int ok[100000],tot[100000];
int h[101000],nxt[201000],K=0,to[201000],cost[201000];int cnt[16],ans=0;
void ins(int u,int v,int c){nxt[++K]=h[u];h[u]=K;to[K]=v;cost[K]=c;}
void dfs(int x,int f,int val)
{
	int k=0;
	for(int i=h[x];i;i=nxt[i])
	{
		if(to[i]==f)continue;
		k^=cost[i];dfs(to[i],x,cost[i]);
	}
	if(x)cnt[val^k]++;
}
int a[18],dp[1<<15];
int DP(int S)
{
	if(dp[S]!=-1)return dp[S];dp[S]=2000000000;
	for(int i=S;i&=S;i--)if(ok[i]==0)dp[S]=min(dp[S],DP(S^i)+tot[i]-1); 
	return dp[S];
}
int main()
{
	for(int S=0;S<(1<<15);S++)
	{
		int k=0,u=0;
		for(int i=0;i<15;i++)if((S>>i)&1)k^=(i+1),u++;
		ok[S]=k;tot[S]=u;
		if(u==1)ok[S]=0,tot[S]=2;
	}
	int n;scanf("%d",&n);
	for(int i=1;i<n;i++){int x,y,c;scanf("%d%d%d",&x,&y,&c);ins(x,y,c);ins(y,x,c);}
	dfs(0,-1,0);
	int S=0;
	for(int i=1;i<=15;i++)
	{
		ans+=cnt[i]/2;
		if(cnt[i]&1)S|=1<<(i-1);
	}
	memset(dp,-1,sizeof(dp));dp[0]=0;
	printf("%d",DP(S)+ans);
	return 0;
}

Measured memory_bytes: 7808
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"8"# => r#"5"#,
//a={8,4,2,1,4,2,1,4,2,1,....} です。a5=a2なので、答えは5
r#"7"# => r#"18"#,
//a={7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,.....} です。
r#"54"# => r#"114"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        s: isize,
    }
    let max = 1000000;

    let mut a = vec![0; max];
    let mut map = std::collections::HashMap::new();
    let mut ans = 0;

    for i in 0..max {
        a[i] = if i == 0 { s } else { if a[i-1] % 2 == 0 { a[i-1] / 2 } else { 3 * a[i-1] + 1 } };

        let count = map.entry(a[i]).or_insert(0);
        *count += 1;
        if *count == 2 {
            ans = i + 1;
            break;
        }
    }
    // println!("{:?}", a[..10].to_vec());

    ans.to_string()
}

Measured memory_bytes: 12540
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N=scan.nextInt();
		int h[]=new int[N];
		int m[]=new int[N];
		for(int i=0;i<N;i++){
			h[i]=scan.nextInt();
			m[i]=scan.nextInt();
		}
		
		int M=scan.nextInt();
		int q[]=new int[N+M];
		
		for(int i=0; i<N; i++){
			q[i] = h[i]*60 + m[i];
		}
		int k[]=new int[M];
		int g[]=new int[M];
		for(int i=0;i<M;i++){
			k[i]=scan.nextInt();
			g[i]=scan.nextInt();
			q[N+i] = k[i]*60 + g[i];
		}
		
		int r = 0;
		for(int i=0; i<N+M; i++){
			for(int j=i+1; j<N+M; j++){
				if(q[i]>q[j]){
					r = q[i];
					q[i] = q[j];
					q[j] = r;
				}
			}
		}
		
		for(int i=0; i<N+M; i++){
			String s = String.valueOf(q[i]%60);
			if(i==M+N-1){
				if(s.length() == 1){
					System.out.println(q[i]/60 + ":0" + q[i]%60);
				}else{
					System.out.println(q[i]/60 + ":" + q[i]%60);
				}
			}else{
				if(q[i+1] != q[i]){
					if(s.length() == 1){
						System.out.print(q[i]/60 + ":0" + q[i]%60 + " ");
					}else{
						System.out.print(q[i]/60 + ":" + q[i]%60 + " ");
					}
				}
			}
		}
	}
}

Measured memory_bytes: 20816
/*#include<stdio.h>

int main(){

    char S[3];

    scanf("%s",S);
  	printf("%s",S);

    if (S[1] == "SUN")
        if (S[2] == "N") printf("7");
        else if (S[2] == "E") printf("5");
    else if (S[1] =="O" ) printf("6");
    else if (S[1] == "E") printf("4");
    else if (S[1] == "H") printf("3");
    else if (S[1] == "R") printf("2");
    else if (S[1] == "A") printf("1");
    
    return 0;
}*/

#include<stdio.h>
#include<string.h>

int main(){

    char S[3];

    scanf("%s",S);
  	//printf("%s",S[1]);

    if (strncmp(S,"SUN",3) == 0) printf("7");
    else if (strncmp(S,"MON",3) == 0) printf("6");
    else if (strncmp(S,"TUE",3) == 0) printf("5"); 
    else if (strncmp(S,"WED",3) == 0) printf("4");
    else if (strncmp(S,"THU",3) == 0) printf("3");
    else if (strncmp(S,"FRI",3) == 0) printf("2");
    else if (strncmp(S,"SAT",3) == 0) printf("1");
    
    return 0;
}

Measured memory_bytes: 128
/**
 *   created: 28 April 2019  23:46:46
**/
#include<bits/stdc++.h>
using namespace std;

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

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
// #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

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

int main()
{
	optimizeIO();
	int tc=1;
	// cin>>tc;
	for(int tt=0;tt<tc;tt++){
		int n;
		cin>>n;
		vi v(n),c(n);
		rep(i,0,n)
			cin>>v[i];
		rep(i,0,n)
			cin>>c[i];
		int res=0;
		rep(i,0,n){
			res += max(0,v[i]-c[i]);
		}
		cout<<res;
	}
	return 0;
}




Measured memory_bytes: 256
n = int(input())
peer = [[] for _ in range(n)]
for _ in range(n-1):
  u,v,w = map(int,input().split())
  u -= 1
  v -= 1
  w %= 2
  peer[u].append([v,w])
  peer[v].append([u,w])
now = [0]
clr = [-1 for _ in range(n)]
clr[0] = 0
while now:
  last = now
  now = []
  for x in last:
    for y in peer[x]:
      if clr[y[0]] == -1:
        now.append(y[0])
        clr[y[0]] = clr[x] ^ y[1]
for z in clr:
  print(z)

Measured memory_bytes: 41836
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  ll ans=0;
  ll sum=0;
  int right = 0;
  REP(left,n){
    while(right<n && (sum^a[right])==(sum+a[right])){ 
      sum += a[right];
      right++;
    }
    ans += right - left;
    if(left==right) right++;
    else sum -= a[left];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x = i;
		if (x % 3 == 0) {
			cout << " " << i;
		}
		else {
			for (int j = 0; j <= 5; j++) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
using namespace std;
int main(void){
  for(;;){
    int n, l, r;
    cin >> n >> l >> r;
    if(n == 0 && l == 0 && r == 0){return 0;}
    int A[n];
    for(int i = 0 ; i < n ; i++){
      cin >> A[i];
    }
    int cnt = 0;
    for(int year = l ; year <= r ; year++){
      bool find = false;
      for(int i = 0 ; i < n && find == false ; i++){
	if(year % A[i] == 0){
	  // cout << "rules for " << A[i] << endl;
	  find = true;
	  if(i % 2 == 0){cnt++;}
	}
      }
      if(find == false){
	if(n % 2 == 0){cnt++;} 
      }
    }
    cout << cnt << endl;
  }
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define int long long
#define double long double
const int INF = (int)1e18 + 18;
const int maxn = (int) 1e6 + 6; 
using namespace std;
 
int n, ans = 0;
signed main() {
  cin >> n;
  int a[n], b[n], c[n-1];
  
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }
  
  for(int i = 0; i < n-1; i++){
    cin >> c[i];
  }
  
  for(int i = 0; i < n; i++){
    if(i != n-1 && a[i] == a[i+1] - 1) ans += c[a[i] - 1];
    ans += b[a[i] - 1];
  }
  
  cout << ans;
  
  
  
  
  
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pr(s) cout<<s<<'\n'
#define in cin>>
#define tc(t) ll t;cin>>t;while(t--)
#define fr(i,n) for(ll i=0;i<n;i++)
#define mod 1e9+7
#define rt return
void lcs(string X, string Y, ll m, ll n ) 
{ 
   ll L[m+1][n+1],i,j; 
   for(i=0;i<=m;i++)
   { 
     for (j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
   ll index = L[m][n];
   char lcs[index+1]; 
   lcs[index] = '\0'; 
   i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; 
          i--; j--; index--;    
      } 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   }
   cout<<lcs;
   //pr(lcs);
}
int main()
{
    string s,t;
    in s;
    in t;
    ll m,n;
    m=s.length();
    n=t.length();
    lcs(s,t,m,n);
    rt 0;
}

Measured memory_bytes: 70656
a,b=map(int,input().split())
dic={1:3*10**5,2:2*10**5,3:1*10**5}
c=0
if a in dic and b in dic:
    if a==1 and b==1:
        c+=dic[a]+dic[b]+4*10**5
        print(c)
    else:
        c+=dic[a]+dic[b]
        print(c)

elif a in dic and b not in dic:
    c+=dic[a]
    print(c)


elif b in dic and a not in dic:
    c+=dic[b]
    print(c)

else:
    print(c)


Measured memory_bytes: 61932
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        k: usize
    };
    let mut i = 1;
    for _ in 0..n {
        i = std::cmp::min(i * 2, i + k);
    }
    println!("{}", i);
}


Measured memory_bytes: 2116
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	vector<string> vs;
	string s;
	ll k;
	cin >> s;
	cin >> k;

	rep(i, 0, s.size()) {
		ll jMax = min((ll)s.size(), k+i);
		rep(j, i, jMax) {
			vs.push_back(s.substr(i, j - i + 1));
		}
	}

	sort(vs.begin(), vs.end());
	vs.erase(unique(vs.begin(), vs.end()),vs.end());
	outn(vs[k - 1]);
	return 0;

}


Measured memory_bytes: 1660
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;
#define VI vector<int>

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

int map[21][21]={};
int X,Y;

using namespace std;
void check(char d,int l){
	if(d=='N'){
		for(int i=0;i<=l;i++)
			map[Y+i][X]=1;
		Y+=l;
	}
	if(d=='W'){
		for(int i=0;i<=l;i++)
			map[Y][X-i]=1;
		X-=l;
	}
	if(d=='S'){
		for(int i=0;i<=l;i++)
			map[Y-i][X]=1;
		Y-=l;
	}
	if(d=='E'){
		for(int i=0;i<=l;i++)
			map[Y][X+i]=1;
		X+=l;
	}
}

int main(){
	while(1){
		rep(i,21)rep(j,21)map[i][j]=0;
		X=Y=10;
		int m,n;
		cin>>n;
		if(n==0)break;
		rep(i,n){
			int x,y;
			cin>>x>>y;
			map[y][x]=3;
		}

		cin>>m;
		rep(i,m){
			char d;
			int l;
			cin>>d>>l;
			check(d,l);
		}
		int least=0;
		rep(i,21){
			rep(j,21){
				if(map[i][j]==3){
					least++;

				}
			}
		}
		if(least==0)cout<<"Yes"<<endl;
		else		cout<<"No"<<endl;
	}	
	return 0;
}

Measured memory_bytes: 1152
# -*- coding: utf-8 -*-
import sys

n, y = list(map(int,input().split()))
for i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        if(10000*i+5000*j+1000*k==y):
            print(str(i)+' '+str(j)+' '+str(k))
            sys.exit()
print('-1 -1 -1')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    string s;
    cin >> s;
    rep(i, 4) cout << s[i];
    cout << " ";
    rep(i, 8) cout << s[i+4];
    cout << endl;    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define debug(x) std::cout << #x << ": " << x << endl
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

ll solve(ll n, ll a, ll b)
{
    return a + (b - a - 1) / 2;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif

    ll n, a, b;
    cin >> n >> a >> b;
    if (a % 2 == b % 2)
    {
        cout << (b - a) / 2 << '\n';
        return 0;
    }    
    cout << min(solve(n, a, b), solve(n, n - b + 1, n - a + 1));

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N;
    vec p(N);
    rep(i,N) cin>>p.at(i);
    ll ans = 0;
    reps(i,2,N){
        if((p[i-2]<p[i-1])&&(p[i-1]<p[i])) ++ans;
        if((p[i-2]>p[i-1])&&(p[i-1]>p[i])) ++ans;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back 
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, a, b;
	cin >> n >> a >> b;
	cout << a * (n / (a + b)) + min(n % (a + b), a) << '\n'; 


}

Measured memory_bytes: 256