akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 


int main() {
 

  int64_t n;
  cin>>n;

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

  int64_t sum_sunuke=0;
  int64_t sum_raccoon=sum;
  int64_t min_diff=10000000000;
  for(int i=0;i<n-1;i++){
    sum_sunuke+=a.at(i);
    sum_raccoon-=a.at(i);
    min_diff = min(min_diff,abs(sum_raccoon-sum_sunuke));
  }

  cout<<min_diff<<endl;

	return 0;
}



Measured memory_bytes: 4828
#include<bits/stdc++.h>
using namespace std;
int n,m,fa[100005],a[100005],b[100005],t,x,y;
long long s;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int find(int r){return fa[r]?fa[r]=find(fa[r]):r;}
int main(){
	n=read(),m=read();
	if(m==n-1) return 0*puts("0");
	for(int i=1;i<=n;++i) a[i]=read(),s+=a[i];
	for(int i=1;i<=m;++i){
		x=read(),y=read();
		x=find(x+1),y=find(y+1);
		s-=max(a[x],a[y]);
		b[++t]=max(a[x],a[y]);
		if(a[x]>a[y]) fa[x]=y;else fa[y]=x;
	}
	if(t<n-m-2) return 0*puts("Impossible");
	sort(b+1,b+t+1);
	for(int i=1;i<=n-m-2;++i) s+=b[i];
	printf("%lld",s);
}

Measured memory_bytes: 1408
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,X,T=nm()
if(N%X==0):
    ans=(N//X)*T
else:
    ans=(N//X+1)*T

print(ans)

Measured memory_bytes: 10456
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

//*
//遅延セグ木ここから
//↓ここを変える
typedef struct sayouso{ll k;}sayouso;
typedef struct atai{ll a;}atai;
//↑ここを変える

typedef struct node{sayouso T;atai x;}node;
node *lsegN,*lseg;
ll lsegNUM;

//↓ここから変える
sayouso sid={1};
atai aid={0};
atai xx(atai x,atai y){
	atai ret;
	ret.a=x.a|y.a;
	return ret;
}
atai Tx(sayouso T,atai x){
	atai ret;
	ret.a=T.k*x.a;
	return ret;
}
sayouso TT(sayouso S,sayouso T){
	sayouso ret;
	ret.k=S.k*T.k;
	return ret;
}
//↑ここまで変える

//要素数(2ベキ)でこれを呼ぶ
void lseguse(ll n){
	lsegN=(node*)calloc(2*n,sizeof(node));
	lsegNUM=n;
	lseg=lsegN+lsegNUM;
	rep(i,0,lsegNUM){
		lseg[i].x=aid;
		lseg[i].T=sid;
	}
	for(int i=lsegNUM-1;i>0;i--){
		lsegN[i].x=xx(lsegN[2*i].x,lsegN[2*i+1].x);
		lsegN[i].T=sid;
	}
}
//lseg[i].xに値を与えてから初期化
void lseginit(){
	for(int i=lsegNUM-1;i>0;i--)lsegN[i].x=xx(lsegN[2*i].x,lsegN[2*i+1].x);
}
void lsegupdatesub(ll l,ll r,sayouso T,ll i,ll cl,ll cr){
	if(l>=r)return;
	//disjointなとき
	if(cr<=l||r<=cl)return;
	//完全に含むとき
	if(l<=cl&&cr<=r){
		lsegN[i].T=TT(T,lsegN[i].T);
		return;
	}
	//どちらでもないとき
	//遅延伝播
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	//再帰的に更新
	ll cm=(cl+cr)/2;
	lsegupdatesub(l,r,T,2*i  ,cl,cm);
	lsegupdatesub(l,r,T,2*i+1,cm,cr);
	//自身のnodeを更新
	lsegN[i].x=xx(Tx(lsegN[2*i].T,lsegN[2*i].x),Tx(lsegN[2*i+1].T,lsegN[2*i+1].x));
	lsegN[i].T=sid;
}
void lsegupdate(ll l,ll r,sayouso T){lsegupdatesub(l,r,T,1,0,lsegNUM);}
atai lsegcalcsub(ll l,ll r,ll i,ll cl,ll cr){
	if(l>=r)return aid;
	//完全に含むとき
	if(l<=cl&&cr<=r)return Tx(lsegN[i].T,lsegN[i].x);

	ll cm=(cl+cr)/2;
	//遅延伝播(変更はないので配るだけで良い)
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	lsegN[i].x=Tx(lsegN[i].T,lsegN[i].x);
	lsegN[i].T=sid;

	//左側だけ
	if(r<=cm)return lsegcalcsub(l,r,2*i  ,cl,cm);
	//右側だけ
	if(cm<=l)return lsegcalcsub(l,r,2*i+1,cm,cr);
	//両方
	return xx(lsegcalcsub(l,r,2*i,cl,cm),lsegcalcsub(l,r,2*i+1,cm,cr));
}
atai lsegcalc(ll l,ll r){return lsegcalcsub(l,r,1,0,lsegNUM);}
//遅延セグ木ここまで
//*/


int a[200010],x[200010],y[200010];
int idx[200010];
int ans[200010];
int cmp(const void*p,const void*q){
	if(a[*(int*)p]<a[*(int*)q])return -1;
	return 1;
}

int main(){
	int n,m,q;
	scanf("%d%d%d",&n,&m,&q);
	for(int i=0;i<m  ;i++)scanf("%d%d%d",a+i,x+i,y+i),a[i]=a[i]*2+1;
	for(int i=m;i<m+q;i++)scanf("%d%d%d",a+i,x+i,y+i),a[i]=a[i]*2;
	for(int i=0;i<m+q;i++)idx[i]=i;
	qsort(idx,q+m,sizeof(int),cmp);
	lseguse(1<<17);
	//seg[i]= i,i+1階間が移動できなければ1
	for(int i=1;i<n;i++)lseg[i].x.a=1;
	lseginit();
	
	for(int ii=0;ii<m+q;ii++){
		int i=idx[ii];
		if(a[i]%2){
			//設置クエリ
			sayouso T={0};
			lsegupdate(x[i],y[i],T);
		}else{
			//質問クエリ
			ans[i]=!lsegcalc(x[i],y[i]).a;
		}
	}
	for(int i=0;i<m+q;i++)if(a[i]%2==0)puts(ans[i]?"Yes":"No");
}


Measured memory_bytes: 9408
//Skip

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,x,a) ll n,x;cin>>n>>x;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int n,x;cin>>n>>x;
    vector<int>a;
    rep(i,0,n){
        int t;cin>>t;
        t=abs(t-x);
        a.pb(t);
    }
    if(n==1){cout<<a[0];return 0;}
    int k=gcd(a[0],a[1]);
    rep(i,2,n){
        k=gcd(k,a[i]);
    }
    cout<<k<<nnn;
    return 0;
}

Measured memory_bytes: 892
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int min = int.MaxValue;
        for (int i = 1; i <= n - 1; i++)
        {
            int sum = i.ToString().Select(x => x - '0').Sum() + (n - i).ToString().Select(x => x - '0').Sum();
            min = Min(min, sum);
        }
        Console.WriteLine(min);
    }
}

Measured memory_bytes: 17472
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d.items()

    def sowa(self, n):
        r = 1
        for k,v in self.division(n):
            t = 1
            for i in range(1,v+1):
                t += math.pow(k, i)
            r *= t
        return r

def main():
    n = I()
    pr = Prime((55555*5) ** 2)
    prs = [c for c in range(2,55555) if pr.is_prime(c) and c%5==2]
    return ' '.join(map(str, prs[:n]))



print(main())



Measured memory_bytes: 7640
//agc012_a.cpp
//Sat Oct 27 12:31:50 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll a[3*n];
	for (int i=0;i<3*n;i++){
		cin >> a[i];
	}
	sort(a,a+3*n,greater<>());

	ll ans = 0;
	for (int i=0;i<n;i++){
		ans += a[2*i+1];
	}

	cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++)
    cin >> V.at(i);
  
  int count = 0;
  for (int j = 0; j < N; j++) {
    for (int k = j + 1; k < N; k++) {
      for (int l = k + 1; l < N; l++) {
        if (V.at(j) != V.at(k) &&
            V.at(k) != V.at(l) &&
            V.at(l) != V.at(j) &&
            V.at(j) < V.at(k) + V.at(l) &&
            V.at(k) < V.at(j) + V.at(l) &&
            V.at(l) < V.at(k) + V.at(j) )
          count++;
      }
    }
  }
  cout << count << endl;
}


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

int main() {
    string s;
    cin >> s;

    string k = "keyence";
    for (int i = 0; i <= s.size()-7; i++) {
        for (int j = 0; j < s.size()-max(1,i); j++) {
            string t = s;
            t.erase (j, i);
            if (t == k) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 3556
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(Math.max(0,Math.abs(b-a)-w));
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
    
    public void close() throws Exception{
        this.reader.close();
        return;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 25144
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto n = lread();
    auto a = aryread();
    // writeln(a);
    auto s = new long[](n + 1);
    s[1] = a[0];
    foreach (i; 1 .. n)
    {
        s[i + 1] = s[i] + a[i];
    }
    // writeln("s:", s);
    long ans = long.max;
    foreach (i; 0 .. n - 1)
    {
        // writeln(a[0 .. i + 1], a[i + 1 .. $]);
        //sを使って左と右の長さを求める
        // s[i + 1].writeln(); //左
        // (s[$ - 1] - s[i + 1]).writeln(); //右
        ans = min(ans, abs(s[i + 1] - (s[$ - 1] - s[i + 1])));
    }
    writeln(ans);

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 12460
N = int(input())

chars = "Xabcdefghijklmnopqrstuvwxyz"
result = ""
n_1 = N

while True:
    x = n_1 % 26

    if x == 0:
        x = 26

    result += chars[x]
    n_1 -= x
    if n_1 == 0:
        break

    n_1 //= 26

print(result[::-1])



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

using namespace std;

const int N = 100005;
const int P = 20;

int n, d[N], fa[N][P];
long long dis[N][P];
vector<pair<int, int>> g[N];

void dfs(int u, int f, int w) {
  d[u] = d[f] + 1;
  dis[u][0] = w;
  fa[u][0] = f;
  for (int i = 1; i < P; ++i) {
    fa[u][i] = fa[fa[u][i - 1]][i - 1];
    dis[u][i] = dis[u][i - 1] + dis[fa[u][i - 1]][i - 1];
  }
  for (auto &go : g[u]) {
    if (go.first != f) {
      dfs(go.first, u, go.second);
    }
  }
}

long long query(int u, int v) {
  long long res = 0;
  if (d[u] < d[v]) {
    swap(u, v);
  }
  int del = d[u] - d[v];
  for (int i = P - 1; i >= 0 && del; --i) {
    if (del & (1 << i)) {
      res += dis[u][i];
      u = fa[u][i];
    }
  }
  for (int i = P - 1; i >= 0; --i) {
    if (fa[u][i] != fa[v][i]) {
      res += dis[u][i] + dis[v][i];
      u = fa[u][i];
      v = fa[v][i];
    }
  }
  if (u != v) {
    res += dis[u][0] + dis[v][0];
  }
  return res;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  dfs(1, 1, 0);
  int q, k;
  scanf("%d %d", &q, &k);
  while (q--) {
    int x, y;
    scanf("%d %d", &x, &y);
    cout << query(x, k) + query(y, k) << endl;
  }
  return 0;
}


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

  int nagasa,n,x,y,i,color;

  scanf("%d %d",&nagasa,&n);
  
  for(i = 0; i < n; i++){

    scanf("%d %d",&x,&y);

    if(x >= nagasa/2+1) x=nagasa-x+1;
    if(y >= nagasa/2+1) y=nagasa-y+1;

    //printf("%d %d",x,y);

    if(x > y){

      x=y;

    } else {

      y=x;

    }

    x %= 3;
    
    if(x == 0) x += 3;
    
    printf("%d\n",x);

  }

  return 0;

}
    

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ll x;
    cin >> x;
    ll ans = 0;
    ans += x/500*1000;
    x %= 500;
    ans += x/5*5;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007



int main() {
    int N; cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));

    int k = lower_bound(all(A), 0) - A.begin(); //1-origin
    if (k % 2 == 0) {
        rep(i, k) {
            A[i] = (-1) * A[i];
        }
    }
    else {
        rep(i, k - 1) {
            A[i] = (-1) * A[i];
        }
        if (k < N ) {
            if (A[k - 1] + A[k] < 0) {
                A[k - 1] = (-1) * A[k - 1];
                A[k] = (-1) * A[k];
            }
        }
    }
    
    ll ans = 0;
    rep(i,N) ans += A[i]; 
    cout << ans << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Guidebook | diff Guidebook.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Guidebook.cpp && ./a.out

/*
 
 5/26/2019
 
 5:02-5:05
 
 */

const int MAX_N=1e3+1;
tuple<string,int,int> A[MAX_N];
int N;

void solve() {
  sort(A,A+N);
  REP(i,N) cout<<get<2>(A[i])<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) {
    string s; int p; cin>>s>>p;
    A[i]=make_tuple(s,-p,i+1);
  }
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  
  int64_t cur = 1;
  for (size_t n = 0; n < N; ++n) {
    int64_t A;
    cin >> A;
    if (A == cur) {
      ++cur;
    }
  }
  if (cur == 1) {
    cout << -1 << endl;
  } else {
    cout << (N - cur + 1) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int a[1000];
int main()
{
	int n,m,x;
	cin>>n>>m>>x;
	for(int i=0;i<m;i++)cin>>a[i];
	int sum1,sum2;
	int y=0;
	for(int i=0;i<x;i++)if(i==a[y])y++;
	sum1=y;
	int z=y;
	for(int i=x;i<=n;i++)if(i==a[z])z++;
	sum2=z-y;
	if(sum1>sum2)cout<<sum2;
	else cout<<sum1;
	return 0;
 } 
 

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

func main() {
	n := readInt()
	a := make([]int, n+1)
	for i := range a {
		a[i] = readInt()
	}

	ans := 0
	for i := 0; i < n; i++ {
		b := readInt()
		if b > a[i] {
			ans += a[i]
			b -= a[i]
		} else {
			ans += b
			b = 0
		}

		if b > a[i+1] {
			ans += a[i+1]
			b -= a[i+1]
			a[i+1] = 0
		} else {
			ans += b
			a[i+1] -= b
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 4608
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>

int main()
{
	int counter = 0,flag = 0;
	int a[200],n;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}

	for(;;)
	{
		for (int i = 0; i < n; i++)
		{
			if (a[i] % 2 == 0)
			{
				a[i] /= 2;
			}
			else
			{
				flag = 1;
			}
		}
		if (flag == 1) break;
		++counter;
	}

	printf("%d", counter);
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll A, B, K; cin >> A >> B >> K;
  ll res = A + B - K;
  if(res <= 0){
    cout << 0 << " " << 0 << endl;
  }else if(A > K){
    cout << A - K << " " << B << endl;
  }else{
    cout << 0 << " " << res << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int MAX = 2 * pow(10, 5);

int main()
{
  int N, min = MAX, cnt = 0;
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    int p;
    cin >> p;
    if (p <= min)
    {
      min = p;
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,a[100005];
int main() {
	cin>>n;
	for (int i=1;i<=n;++i)cin>>a[i];
	sort(a+1,a+n+1,greater<int>());
	int p=1;while(p<n&&a[p+1]>=p+1)++p;
	int q=p;while(q<n&&a[q+1]==p)++q;
	puts((q-p&1)||(a[p]-p&1)?"First":"Second");
}

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

using Int = long long int;
using UInt = unsigned long long int;


int main(void) {
    Int a, b, c;
    cin >> a >> b >> c;
    Int pay = min(a+b, b+c);
    pay = min(pay, c+a);
    cout << pay << endl;
    return 0;
}


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

int h,w,K;
string in[1001];
int J[1001][1001];
int O[1001][1001];
int I[1001][1001];

int get(int x,int y,int kind) {
  if (kind == 0) return J[y][x];
  else if(kind == 1) return O[y][x];
  else return I[y][x];
}

// (x1,y1) - (x2,y2)
// x1 <= x2, y1 <= y2
int query(int x1,int y1,int x2,int y2,int kind) {
  x1--, y1--;
  int ret = get(x2,y2,kind);;
  if (x1 >= 0 && y1 >= 0) ret += get(x1,y1,kind);
  if (x1 >= 0) ret -= get(x1,y2,kind);
  if (y1 >= 0) ret -= get(x2,y1,kind);
  return ret;
}

int main() {
  cin>>h>>w>>K;
  for (int i=0; i<h; ++i) cin>>in[i];

  memset(J, 0, sizeof(J));
  memset(O, 0, sizeof(O));
  memset(I, 0, sizeof(I));
  for (int i=0; i<h; ++i) {
    for (int j=0; j<w; ++j) {
      int jv = 0, ov = 0, iv = 0;
      switch(in[i][j]) {
      case 'J' :
        jv++;
        break;
      case 'O':
        ov++;
        break;
      case 'I':
        iv++;
        break;
      }
      if (i>0) {
        jv += J[i-1][j];
        ov += O[i-1][j];
        iv += I[i-1][j];
      }
      if (j>0) {
        jv += J[i][j-1];
        ov += O[i][j-1];
        iv += I[i][j-1];
      }
      if (i>0 && j>0) {
        jv -= J[i-1][j-1];
        ov -= O[i-1][j-1];
        iv -= I[i-1][j-1];
      }
      J[i][j] = jv, I[i][j] = iv, O[i][j] = ov;
    }
  }

  int x1,y1,x2,y2;
  for (int i=0; i<K; ++i) {
    cin>>y1>>x1>>y2>>x2;
    x1--,y1--,x2--,y2--;
    cout<<query(x1,y1,x2,y2,0)<<" "<<query(x1,y1,x2,y2,1)<<" "<<query(x1,y1,x2,y2,2)<<endl;
  }
}

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

typedef long long LL;


inline int index(const vector<int> &v, int x){
	return lower_bound(v.begin(), v.end(), x) - v.begin();
}

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
vector<vector<LL> > fl;

void dfs(int x, int y, LL c){
	fl[x][y] = -1;
	for(int i = 0; i < 4; ++i){
		int nx = x + dx[i], ny = y + dy[i];
		if(nx < fl.size() && ny < fl[0].size() && fl[nx][ny] == c){
			dfs(nx, ny, c);
		}
	}
}


int main(){

	int n;
	while(scanf("%d", &n), n){
		vector<int> ls(n), ts(n), rs(n), bs(n), xs, ys;
		for(int i = 0; i < n; ++i){
			scanf("%d%d%d%d", &ls[i], &ts[i], &rs[i], &bs[i]);
			
			for(int j = 0; j < 2; ++j){
				xs.push_back(ls[i] - j);
				xs.push_back(rs[i] - j);
				ys.push_back(bs[i] - j);
				ys.push_back(ts[i] - j);
			}
		}

		sort(xs.begin(), xs.end());
		sort(ys.begin(), ys.end());
		xs.erase(unique(xs.begin(), xs.end()), xs.end());
		ys.erase(unique(ys.begin(), ys.end()), ys.end());

		fl.assign(xs.size(), vector<LL>(ys.size()));
		for(int i = 0; i < n; ++i)
		for(int j = index(xs, ls[i]); xs[j] < rs[i]; ++j)
		for(int k = index(ys, bs[i]); ys[k] < ts[i]; ++k){
			fl[j][k] |= 1LL << i;
		}

		int ans = 0;
		for(int i = 0; i < xs.size(); ++i)
		for(int j = 0; j < ys.size(); ++j){
			if(fl[i][j] != -1){
				++ans;
				dfs(i, j, fl[i][j]);
			}
		}
		
		printf("%d\n", ans);
	}
}

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

typedef long long LL;

const int N=500;

int mod;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n;

void into(){
  scanf("%d%d",&n,&mod);
}

int l[N+9],r[N+9];
struct position{
  int p,id;
}a[N+9];

bool cmp(const position &a,const position &b){return a.p<b.p||a.p==b.p&&a.id>b.id;}

void Get_a(){
  for (int i=0;i<n<<1;++i){
	r[i]=min((int)floor(sqrt(4*n*n-i*i)),2*n-1);
	l[i]=max((int)ceil(sqrt(n*n-i*i)),0);
	a[i].id=i;
	a[i].p=i<n?l[i]-1:r[i];
  }
  sort(a,a+n*2,cmp);
}

int dp[N+9][N+9],ans;

void Get_dp(int c){
  int cnt=0;
  for (int i=0;i<=n<<1;++i)
	for (int j=0;j<=n<<1;++j) dp[i][j]=0;
  dp[0][0]=1;
  for (int i=1;i<=n<<1;++i){
	position t=a[i-1];
	if (t.id<n) ++cnt;
	for (int j=0;j<=c&&j<=cnt;++j)
	  if (t.id<n){
		dp[i][j]=mul(dp[i-1][j],r[t.id]+1-(n*2-1-t.id+c-j));
		if (j>0) sadd(dp[i][j],mul(dp[i-1][j-1],t.p+1-(i-1-cnt+j)));
	  }else dp[i][j]=mul(dp[i-1][j],t.p+1-(i-1-cnt+j));
  }
  c&1?ssub(ans,dp[n<<1][c]):sadd(ans,dp[n<<1][c]);
}

void Get_dp(){
  for (int i=0;i<=n;++i) Get_dp(i);
}

void work(){
  Get_a();
  Get_dp();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 4756
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>

int main(){
	int n;
	scanf("%i", &n);
	if(n % 1000 == 0){
		puts("0");
		return 0;
	}else{
		printf("%i\n", 1000 - (n % 1000));
		return 0;
	}

	return 0;
}


Measured memory_bytes: 1732
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        UnionFind uf = new UnionFind(n);
        
        int[][] xy = new int[m][2];
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            xy[i][0] = x;
            xy[i][1] = y;
        }
        
        long[] answer = new long[m];
        answer[m - 1] = (long)n * (n - 1) / 2;
        
        for (int i = m - 1; i > 0 ; i--) {
            int x = xy[i][0];
            int y = xy[i][1];
            if (uf.same(x, y)) {
                answer[i - 1] = answer[i];
                continue;
            }
            
            int rx = uf.root(x);
            int ry = uf.root(y);
            answer[i - 1] = answer[i] - uf.size[rx] * uf.size[ry];
            uf.unite(x, y);
        }
        
        for (long a : answer) {
            System.out.println(a);
        }
    }
    
    public static class UnionFind {
        int[] par;  // 自身の親
        int[] size; // 自身の属するグループの要素数
        int connectedComponent;
    
        UnionFind(int n) {
            par = new int[n];
            size = new int[n];
            Arrays.fill(size, 1);
            connectedComponent = n;
            for (int i = 0; i < n; i++) {
                par[i] = i;
            }
        }
    
        int root(int x) {
            if (par[x] == x) return x;
            return par[x] = root(par[x]);
            // 1-2-4の場合、4の親=2を4の根=1に繋ぎ変えた上で親を返す
            // ↑根まで辿る深さを減らす為
            // return a = b;とは、aにbを代入し、aを返すという意味
        }
    
        void unite(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            if (rx != ry) {
                par[ry] = rx;
                connectedComponent--;
                int resize = size[rx] + size[ry];
                size[rx] = resize;
                size[ry] = resize;
            }
        }
    
        boolean same(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            return rx == ry;
        }
        
        void printPar() {
            System.out.println(Arrays.toString(par));
        }
    }
} 

Measured memory_bytes: 97028
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s :String = read();
    let t :String = read();
    let mut ans = 0;
    let mut current = 0;
    while current + t.len() <= s.len() {
        let mut counter = 0;
        let mut max = 0;
        for mat in t.chars() {
            let n = s.chars().nth(current + counter).unwrap();
            if n == mat {
                max += 1;
            }
            if ans < max {
                ans = max;
            }
            counter+=1;
        }
        current += 1;
    }
    print!("{}", t.len() -ans);
}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
char ans [100] [100] ;
int main()
{
	int n , m , a , b;
	cin >> n >> m ;
	a = max (n , m) ;
	for (b = 0 ; b * b <= a ; b ++ )
	{
		a ;
	}
	n -- ;
	m -- ;
	b += 2 ;
	b = b * 4 - 1 ;
	
	for (int i = 0 ; i <= b ; i ++ )
	{
		
		for (int j =  0 ; j < b / 2; j ++ )
		{
			 if (n > 0  && i % 2 == 0)
			{
				if (j % 2 == 0)
				{
					ans [i] [j] = '.' ;
					n -- ;
				}
				else
				ans [i] [j] = '#' ;
			}
			else
			ans [i] [j] = '#' ;
		}
	}
	for (int i = 0 ; i <= b ; i ++ )
	{
		ans [i] [b / 2] = '#' ;
		ans [i] [b / 2 + 1] = '.' ;
	}
	for (int i = 0 ; i <= b ; i ++ )
	{
		
		for (int j = b / 2 + 2 ; j <= b ; j ++ )
		{
			 if (m > 0  && i % 2 == 0)
			{
				if (j % 2 == 0)
				{
					ans [i] [j] = '#' ;
					m -- ;
				}
				else
				ans [i] [j] = '.' ;
			}
			else
			ans [i] [j] = '.' ;
		}
	}
	cout << b + 1 << ' ' << b + 1<< endl ;
	for (int i =  0 ; i <= b ; i ++ )
	{for (int j = 0 ; j <= b ;  j ++ )
	cout << ans [i] [j] ;
	cout << endl ;
	}
}



Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int n;
	while(cin >> n)
	{
		if(!n)
		{
			break;
		}

		int a, mx = 0, age[256] = { 0 };
		for(int i = 0; i < n; i++)
		{
			cin >> a;
			age[a]++;
			mx = max(a, mx);
		}

		int sum = 0;
		for(int i = 0; i <= mx; i++)
		{
			if( i <= 60 && i > 0&& i % 10 == 0)
			{
				cout << sum << endl;
				sum = 0;
			}
			sum += age[i];
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1160
#C - Vacation

n=int(input())
a=[]
b=[]
c=[]
for i in range(n):
    ak,bk,ck=map(int,input().split())
    a.append(ak)
    b.append(bk)
    c.append(ck)
hy=[]
for i in range(n):
    hy.append([0,0,0])
#hy[n-1]まで埋める
#0日目を埋めておく
hy[0][0]=a[0]
hy[0][1]=b[0]
hy[0][2]=c[0]

    
for i in range(1,n):
#    hy.append([])
    hy[i][0] = max(hy[i-1][1]+a[i],hy[i-1][2]+a[i])#hy[i][a]を求める
    hy[i][1] = max(hy[i-1][0]+b[i],hy[i-1][2]+b[i])#hy[i][a]を求める
    hy[i][2] = max(hy[i-1][0]+c[i],hy[i-1][1]+c[i])#hy[i][a]を求める

print(max(hy[n-1]))

Measured memory_bytes: 80216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
using vi=vector<ll>;
using vvi=vector<vi>;
using vp=vector<P>;
const ll inf=1001001001001001001;
const ll mod=1000000007;
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;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
ll modpow(ll a,ll b){
    a%=mod;
    if(b==0)return 1;
    if(b&1)return a*modpow(a,b-1)%mod;
    ll k=modpow(a,b/2);
    return k*k%mod;
}
ll v[405][405];
int main(){
    ll n,c;cin>>n>>c;
    vi a(n),b(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    vi dp(c+1);
    dp[0]=1;
    rep(i,405){
        v[1][i]=1;
        REP(k,2,405)v[k][i]=(v[k-1][i]+modpow(k,i))%mod;
    }
    rep(i,n){
        vi ndp(c+1);
        rep(j,c+1)REP(k,j,c+1){
            ndp[k]+=dp[j]*(v[b[i]][k-j]-v[a[i]-1][k-j]+mod)%mod;
            ndp[k]%=mod;
        }
        dp=ndp;
    }
    out(dp[c]);
}

Measured memory_bytes: 1536
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
count = 0
for i in range(N):
  ABsum = 0
  A = list(map(int,input().split()))
  for j in range(M):
    ABsum += A[j] * B[j]
  if (ABsum + C) > 0:
    count +=1
print(count)

Measured memory_bytes: 3060
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int n;
vector<int> a;

void input(){
    cin >> n;
    a.resize(n);
    REP(i, n){
        cin >> a[i];
    }
    return;
}

void solve(){
    int right = 0;
    lint ans = 0;
    int sum = 0;
    for (int left = 0; left < n; ++left){
        while(right < n && (sum & a[right]) == 0){
            sum += a[right];
            right++;
        }
        ans += right - left;
        if(left == right){
            right++;
        }
        else {
            sum -= a[left];
        }
    }
    cout << ans << endl;
    return;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 1024
if __name__ == '__main__':
    # ??????????????\???
    word = input()
    texts = []
    while True:
        raw_input = input()
        if raw_input == 'END_OF_TEXT':
            break
        texts.append(raw_input.lower())

    # ?????????????¨??????°???????????????
    match_count = 0
    for line in texts:
        for w in line.split(' '):
            if w == word.lower():
                match_count += 1

    # ???????????????
    print(match_count)

Measured memory_bytes: 7464
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int out[2020];
void lin(int x){
	rep(i,x) out[i+1]+=x-i;
}
void cir(int z){
	rep(i,z/2) out[i+1]+=z;
	if(z%2==0) out[z/2]-=z/2;
}
void lc(int x,int z){
	REP(i,1,x+1) REP(j,1,z){
		out[i+min(j,z-j)]++;
	}
}
void ll(int x,int y){
	REP(i,1,x+1) REP(j,1,y+1){
		out[i+j+1]++;
	}
}
int main()
{
	memset(out,0,sizeof(out));
	int n,a,b;cin>>n>>a>>b;
	int x=a-1,y=n-b,z=b-a;
	//cout<<x<<y<<z<<endl;
	lin(x);lin(y);cir(z+1);lc(x,z+1);lc(y,z+1);ll(x,y);
	REP(i,1,n) cout<<out[i]<<endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ATherefore solver = new ATherefore();
        solver.solve(1, in, out);
        out.close();
    }

    static class ATherefore {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int n = s.nextInt();
            int d = n % 10;
            if (d == 0 || d == 1 || d == 6 || d == 8)
                w.println("pon");
            else if (d == 3)
                w.println("bon");
            else
                w.println("hon");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 32560
import sys

def list2mat(V, n):
    M = [[0] * (n) for _ in range(n)]
    for i in range(1, n + 1):
        for v in V[i]:
            M[i - 1][v - 1] = 1
    return M

lines = sys.stdin.readlines()
n = int(lines[0])
V = [[0] for _ in range(n + 1)]

for i in range(1, n + 1):
    v = map(int, lines[i].split())
    V[v[0]] = v[2:]

M = list2mat(V, n)
for m in M:
    print " ".join(map(str, m))

Measured memory_bytes: 6504
A,B = list(map(int,input().split()))
if A == 1 and B == 1:
    print("Draw")
elif A == 1:
    print("Alice")
elif B == 1:
    print("Bob")
elif A == B:
    print("Draw")
elif A > B:
    print("Alice")
else:
    print("Bob")

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; double w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 100;

int h, w, s;
int u[32][32], sum[33][33];
int num[33][33][33][33], cap[33][33][33][33];

void f(int u, int d, int l, int r) {
	if (num[u][d][l][r] != -1) return;
	int z = sum[d][r] - sum[d][l] - sum[u][r] + sum[u][l];
	int x = 1, y = s - (sum[h][w] - z);
	for (int j = l + 1; j <= r - 1; j++) {
		f(u, d, l, j); f(u, d, j, r);
		int _x = num[u][d][l][j] + num[u][d][j][r];
		int _y = min(cap[u][d][l][j], cap[u][d][j][r]);
		if (_y >= 0 && (_x > x || (_x == x && _y > y))) {
			x = _x; y = _y;
		}
	}
	for (int i = u + 1; i <= d - 1; i++) {
		f(u, i, l, r); f(i, d, l, r);
		int _x = num[u][i][l][r] + num[i][d][l][r];
		int _y = min(cap[u][i][l][r], cap[i][d][l][r]);
		if (_y >= 0 && (_x > x || (_x == x && _y > y))) {
			x = _x; y = _y;
		}
	}
	num[u][d][l][r] = x; cap[u][d][l][r] = y;
}

int main() {
	for (;;) {
		cin >> h >> w >> s;
		if (h == 0) break;
		fill_n((int*)sum, 33*33, 0);
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++) {
				cin >> u[i][j];
				sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + u[i][j];
			}
		fill_n((int*)num, 33*33*33*33, -1);
		fill_n((int*)cap, 33*33*33*33, -1);
		f(0, h, 0, w);
		cout << num[0][h][0][w] << ' ' << cap[0][h][0][w] << endl;
	}
}

Measured memory_bytes: 10444
let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( -^ ) x y = x +^ (m - y)
let ( *^ ) x y = (x * y) mod m

module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n%d %d\n" @@ fun n m s t ->
  let uvds = Array.init m @@ fun _ ->
    Scanf.scanf "%d %d %d\n" @@ fun u v d -> u - 1, v - 1, d in
  let es = Array.make n [] in
  Array.iter (fun (u, v, d) ->
    es.(u) <- (v, d) :: es.(u);
    es.(v) <- (u, d) :: es.(v)) uvds;
  let rec dijkstra d p q =
    match IntMap.min_binding q with
    | exception Not_found -> ()
    | (w, us) ->
        dijkstra d p @@ List.fold_left (fun q u ->
          if d.(u) < w
          then q
          else List.fold_left (fun q (v, c) ->
            match compare d.(v) (w + c) with
            | -1 -> q
            | 0  -> p.(v) <- p.(u) +^ p.(v); q
            | 1  -> p.(v) <- p.(u); d.(v) <- w + c; IntMap.add (w + c) (v :: try IntMap.find (w + c) q with Not_found -> []) q)
          q es.(u)) (IntMap.remove w q) us in
  let [(dt, pt); (da, pa)] = List.map (fun s ->
    let d = Array.make n max_int in
    let p = Array.make n 0 in
    d.(s) <- 0;
    p.(s) <- 1;
    dijkstra d p (IntMap.singleton 0 [s]);
    (d, p)) [s - 1; t - 1] in
  Printf.printf "%d\n" @@
  Array.fold_right (fun v acc ->
    if dt.(v) = da.(v) then acc -^ pt.(v) *^ pa.(v) *^ pt.(v) *^ pa.(v) else acc)
  (Array.init n @@ fun v -> v) @@
  Array.fold_left (fun acc (u, v, d) ->
    if
      dt.(t - 1) < d + min (dt.(u) + da.(v)) (da.(u) + dt.(v)) ||
      max dt.(u) dt.(v) <= min da.(u) da.(v) ||
      max da.(u) da.(v) <= min dt.(u) dt.(v)
    then acc
    else
      if dt.(u) < dt.(v)
      then acc -^ pt.(u) *^ pa.(v) *^ pt.(u) *^ pa.(v)
      else acc -^ pa.(u) *^ pt.(v) *^ pa.(u) *^ pt.(v)) (pt.(t - 1) *^ pa.(s - 1)) uvds


Measured memory_bytes: 68984