akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

int dp[100010];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	dp[0] = 0;
	dp[1] = 1;
	REP(n, N+1 ) {
		dp[n] = n;
		int power = 1;
		while (power <= n) {
			dp[n] = min(dp[n], dp[n - power] + 1);
			power *= 6;
		}
		power = 9;
		while (power <= n) {
			dp[n] = min(dp[n], dp[n - power] + 1);
			power *= 9;
		}
	}
	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int t=0,n=0,s=0,f=0,st=0;

	while(sc.hasNext()){
	    st = 0;

	    t = sc.nextInt();

	    if(t==0) break;

	    n = sc.nextInt();

	    for(int i = 0;i<n;i++){
		s = sc.nextInt();
		f = sc.nextInt();
		st += f-s;
	    }

	    if(st>=t){
		System.out.println("OK");
	    }else{
		System.out.println(t-st);
	    }
	}
    }
}

Measured memory_bytes: 23612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int A[1];
int size=1;
int m=2;
#define N 101
#define mod 1000000007
#define f(i,n) for(int i=0;i<n;i++)


int main()
{
   
  int x,y;
  cin>>x>>y;
  int a,b;
  a=(4*x-y)/2;
  b=(y-2*x)/2;

  if(a+b==x&&a>=0&&b>=0)
      cout<<"Yes";
  else
      cout<<"No";
}


Measured memory_bytes: 3592
#include <stdio.h>

int main() {
  int in;
  int buffer[100];
  int p;

  p = -1;
  while(scanf("%d", &in) != EOF) {
    if(in == 0) {
      printf("%d\n", buffer[p--]);
    } else {
      buffer[++p] = in;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<ll,ll> pint;

const int MAX_N=1<<17;
const ll INF=(1ll<<31)-1;
class Lz_segtree{
public:
    int n;
    ll e=0;
    ll init=0;
    vector<ll> dat,lz;
    Lz_segtree(int n_):n(n_){
        n=1;
        while(n<n_) n*=2;
        dat.resize(n*2,e);
        lz.resize(n*2,init);
    }
    void update_f(ll& d,ll x,int len){
        if(len>0&&x==1)d=len-d;
        else if(len==0) d^=x;
    }
    ll dat_propergate(ll l,ll r){
        return l+r;
    }
    void lz_propergate(ll& l,ll& r,ll x){
        l^=x,r^=x;
    }
    void eval(int len,int k){
        if(lz[k]!=init) update_f(dat[k],lz[k],len);
        if(len>1){
            if(lz[k]!=init)lz_propergate(lz[k*2+1],lz[k*2+2],lz[k]);
        }
        lz[k]=init;
    }
    //range [a,b)
    void update(int a,int b,int k,int l,int r,ll x){
        eval(r-l,k);
        if(r<=a||b<=l) return;
        if(a<=l&&r<=b){
            update_f(lz[k],x,0);
            eval(r-l,k);
        }
        else{
            update(a,b,k*2+1,l,(l+r)/2,x);
            update(a,b,k*2+2,(l+r)/2,r,x);
            dat[k]=dat_propergate(dat[2*k+1],dat[2*k+2]);
        }
    }
    //range [a,b)
    ll query(int a,int b,int k,int l,int r){
        eval(r-l,k);
        if(r<=a||b<=l) return e;
        if(a<=l&&r<=b) return dat[k];
        else{
            ll vl=query(a,b,k*2+1,l,(l+r)/2);
            ll vr=query(a,b,k*2+2,(l+r)/2,r);
            return dat_propergate(vl,vr);
        }
    }
    void update(int a,int b,ll x){
        return update(a,b,0,0,n,x);
    }
    ll query(int a,int b){
        return query(a,b,0,0,n);
    }
};
vector<int> g[100001];
int l[100001],r[100001];
int cur;
void dfs(int v,int par){
    l[v]=cur++;
    rep(i,g[v].size())if(g[v][i]!=par) dfs(g[v][i],v);
    r[v]=cur;
}
int main(){
    int n,q,pi;
    cin>>n>>q;
    FOR(i,2,n+1){
        cin>>pi;
        g[i].pb(pi);
        g[pi].pb(i);
    }
    cur=0;
    dfs(1,-1);
    Lz_segtree seg(n+1);
    char c;
    rep(i,n){
        cin>>c;
        if(c=='G') seg.update(l[i+1],l[i+1]+1,1);
    }
    int vi;
    rep(i,q){
        cin>>vi;
        seg.update(l[vi],r[vi],1);
        int cnt=seg.query(0,n);
        if(cnt*2>=n) cout<<"broccoli"<<endl;
        else cout<<"cauliflower"<<endl;
    }
    return 0;
}


Measured memory_bytes: 19460
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

//#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

Int mod;
Int L,A,B;

typedef struct M {
    Int data[3][3];
}Matrix;

Matrix create(Int op, Int b) {
    Matrix a;
    a.data[0][0] = op%mod;
    a.data[0][1] = a.data[0][2] = 0;
    a.data[1][0] = 1;
    a.data[1][1] = 1;
    a.data[1][2] = 0;
    a.data[2][0] = 0;
    a.data[2][1] = b%mod;
    a.data[2][2] = 1;

    return a;
}

Matrix operator * (Matrix a, Matrix b) {
    Matrix c;
    for(int i = 0;i < 3;i++) {
        for(int j = 0;j < 3;j++) {
            c.data[i][j] = 0;
            for(int k = 0;k < 3;k++) {
                c.data[i][j] += (a.data[i][k]*b.data[k][j])%mod;
                c.data[i][j] %= mod;
            }
        }
    }

    return c;
}

Matrix pow(Matrix a, Int n) {
    if(n == 0) {
        Matrix d;
        for(int i = 0;i < 3;i++) {
            for(int j = 0;j < 3;j++) {
                d.data[i][j] = 0;
            }
        }
        d.data[0][0] = d.data[1][1] = d.data[2][2] = 1;
        return d;
    }

    Matrix ret;
    ret = pow(a*a, n/2);
    if(n&1)
        ret = ret*a;

    return ret;
}

int main(void) {
    cin>>L>>A>>B>>mod;

    Int prev = 0;
    Int op = 10;
    Int X = 0;
    L--;
    for(int d = 1;d < 19;d++) { //digit
        Int l = prev;
        Int r = L;
        Int curr = -1;
        while(l <= r) {
            Int mid = (l+r)/2;
            Int c = A+B*mid;
            if(c < op) {
                curr = mid;
                l = mid+1;
            } else {
                r = mid-1;
            }
        }
        if(curr != -1) {
            Matrix M = create(op,B);
            M = pow(M, curr+1-prev);
            Int s = (A+B*prev%mod)%mod;
            X = (X*M.data[0][0]%mod+s*M.data[1][0]%mod+M.data[2][0])%mod;
            prev = curr+1;
        }
        
        op *= 10;
    }

    cout<<X<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back
 
using namespace std;
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
 
int main(){
	ios::sync_with_stdio(false);
    string s;
    int K;
    cin>>s>>K;
    int i=0;
    while(i<s.size()){
        if(s[i] == 'a')
            i++;
        else{
            if('z'-s[i]<K){
                K=K-('z'-s[i]+1);
                s[i]='a';
                // if(s[i] == 'z'){
                //     s[i] = 'a';
                //     K--;
                //     i++;
                // }
                // else{
                //     s[i]=(char)(s[i]+1);
                //     K--;
                // }
 
            }
            else{
                i++;
            }
        }
    }
    i=0;
    K=K%26;
    while(i<K){
        if(s[i] == 'z'){
            s[i] = 'a';
            i++;
        }
        else{
            s[s.size()-1]=(char)(s[s.size()-1]+1);
            i++;
        }
    }
    cout<<s<<endl;
 
    return 0;
}

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

const ll logx=30;
const ll N=1e5+5;
const ll M=1e3+5;
const ll mod=1e9+7;
const ll INF=1e18+5;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#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
#define trace7(a, b, c, d, e, f, g) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<" | "<<#g<< ": "<<g<<endl

ll n,m,a[N],b[N],arr[N],dp[1005][(1<<12)];

ll F(ll idx,ll mask)
{
  ll mini=INF;
  if(mask==(1<<n)-1){return 0;}
  if(idx==m){return INF;}
  if(dp[idx][mask]!=-1){return dp[idx][mask];}
  mini=min(mini,a[idx]+F(idx+1,mask|arr[idx]));
  mini=min(mini,F(idx+1,mask));
  return dp[idx][mask]=mini;
}

int main()
{
  ms(dp,-1);
  cin>>n>>m;
  for(ll i=0;i<m;i++)
  {
    cin>>a[i]>>b[i];
    for(ll j=0;j<b[i];j++)
    {
      ll x;
      cin>>x;
      x--;
      arr[i]|=(1<<x);
    }
  }
  ll ans=F(0,0);
  if(ans==INF){ans=-1;}
  cout<<ans<<endl;
}


Measured memory_bytes: 33024
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] W = new int[N];
        for (int i = 0; i < N; i++) {
            W[i] = sc.nextInt();
        }

        int S1 = W[0];
        int S2 = 0;
        for (int i = 1; i < N; i++) {
            S2 += W[i];
        }
        int minDiff = Math.abs(S1 - S2);

        for (int T = 1; T < N - 1; T++) {
            S1 += W[T];
            S2 -= W[T];
            minDiff = Math.min(minDiff, Math.abs(S1 - S2));
        }

        System.out.println(minDiff);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }

}


Measured memory_bytes: 23508
import java.util.Scanner;

class Main {
  public static void main(String args[]){
    String str;
    Scanner scan = new Scanner(System.in);
    str = scan.nextLine();
    scan.close();
    if(str.equals("abc") || str.equals("acb") || str.equals("bac") || str.equals("bca") || str.equals("cab") || str.equals("cba")){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
      }
  }
}


Measured memory_bytes: 23764
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        if(A==B) System.out.println("Draw");
        else if(A==1 || (A>B && B!=1)) System.out.println("Alice");
        else System.out.println("Bob");
    }
}

Measured memory_bytes: 23636
#include <stdio.h>

int main(){
	int n,i;
	float p[8];
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%f %f %f %f %f %f %f %f",&p[0],&p[1],&p[2],&p[3],&p[4],&p[5],&p[6],&p[7]);
		if((p[3] - p[1]) * (p[6] - p[4]) - (p[2] - p[0]) * (p[7] - p[5]) == 0) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 616
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<pi> vpi;

#define debugone(x) cout << #x << " " << x << endl;
#define debugtwo(x) cout << #x << "-------------" << endl;for(auto &it: x) cout << it << " ";cout << endl;
#define debugthree(x, i, j) cout << #x << "------------" << endl;cout << "from " << i << " to " << j << endl;for(int k=i; k<=j; k++) cout << x[k] << " ";cout << endl;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

	int mini = int(1e9);
	for(int t = 1; t < n; t++){
		int s1 = 0, s2 = 0;
		for(int i=0; i<n; i++){
			if(i+1 <= t) s1+= a[i];
			else s2+= a[i];
		}
		int diff = abs(s1 - s2);
		mini = min(mini, diff);
	}	

	cout << mini << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void){
        int N;
        int x;
        int y;
        int ans = 0;
        scanf("%d", &N);
        for (int i = 0; i < N; i++) {
                scanf("%d %d", &x,&y);
                ans += y - x + 1 ;
        }
        printf("%d\n", ans);
        return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
const double PI = acos(-1.0);
const string ALP = "abcdefghijklmnopqrstuvwxyz";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  string a,b,c;
  cin >> a >> b >> c;
  puts((a.back()==b.front()&&b.back()==c.front())?"YES":"NO");
  return 0;
}

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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int n,x,ans;
string s;

main() {
    cin >> n >> s;
    rep(i,n) {
        if (s[i] == 'I') x++;
        else x--;
        ans = max(ans,x);
    }
    ct(ans)
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long l = Integer.parseInt(sc.next());
		long r = Integer.parseInt(sc.next());

		long min = Integer.MAX_VALUE;

		for (long i = l; i < r; i++) {
			for (long j = i + 1; j <= r; j++) {
				long mod = (i % 2019 * j % 2019) % 2019;
				if (mod == 0) {
					System.out.println(0);
					System.exit(0);
				} else if (mod < min) {
					min = mod;
				}
			}
		}
		System.out.println(min);
	}
}

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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
//#define int long long
//#define double long double

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

    int n, k;
    cin >> n >> k;

    set<int> s;
    for (int i = 1; i <= n; i++)
        s.insert(i);

    while (k--)
    {
        int d, t;
        cin >> d;
        while (d--)
            cin >> t, s.erase(t);
    }

    cout << s.size() << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *
//     *   *  *      **  *  *   *
//    *****  *****  * * *  *   *
//   *   *      *  *  **  *   *
//  *   *  *****  *   *   ***

//      ***** ***** *   * *     ***** *   * ***** *****
//        *  *   * *   * *       *   **  *   *   *   *
//       *  *   * ***** *       *   * * *   *   *****
//   *  *  *   *   *   *       *   *  **   *   *
//  ****  *****   *   ***** ***** *   *   *   *


Measured memory_bytes: 3660
from collections import defaultdict
import sys
sys.setrecursionlimit(150000)

n,m,k = map(int, input().split())
f_G = defaultdict(lambda:[])
b_G = defaultdict(lambda:[])

for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    f_G[a].append(b)
    f_G[b].append(a)

for i in range(k):
    c,d = map(int, input().split())
    c -= 1
    d -= 1
    b_G[c].append(d)
    b_G[d].append(c)

def dfs(graph,v,cnt,list):
    global node
    seen[v] = True
    node += 1

    for nv in f_G[v]:
        if seen[nv]:
            continue
        dfs(graph,nv,cnt,list)

    list[v] = cnt

d = [0]
list = [0] * n
seen = [False] * n
cnt = 0
for i in range(n):
    if seen[i]:
        continue
    cnt += 1
    node = 0
    dfs(f_G,i,cnt,list)
    d.append(node)

ans = [0] * n
for i in range(n):
    a = d[list[i]]
    a -= (len(f_G[i]) + 1)

    for j in (b_G[i]):
        if list[i] == list[j]:
            a -= 1

    ans[i] = a

print(*ans)


Measured memory_bytes: 66888
N = int(input())
A = list(map(int,input().split()))

cap = [1]*(N+1)#0-N

if A[0] > 1 or (A[0]==1 and N !=0):
    print(-1)
    exit()

for i in range(1,N+1,1):#1-N
    cap[i]=cap[i-1]*2 - A[i]
    if cap[i] < 0 or (cap[i]==0 and i!=N):
        print(-1)
        exit()

T = [0]*(N+1)
T[N]=A[N]#ここのキャパオーバーは上ではじけるはず
for i in range(N-1,-1,-1):
    T[i]=A[i]+min(T[i+1],cap[i])

print(sum(T))




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

using namespace std;
const int N=2e5+5;
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,m;cin>>n>>m;
    int total=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        total+=a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    for(int i=0;i<m;i++)
    {
        if(a[i]*4*m>=total) continue;
        return 0*puts("No");
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    // int answer;
    vector<int> ans(201);
    for(int j=0;j<201;j++){
        ans[j] = 0;
        for(int i=0;i<N;i++){
        ans[j]+=pow((a[i]-j+100),2);
    }    
    }
    // answer = ans[-100];
    sort(ans.begin(),ans.end());
    // cout << ans[49] << endl;
    cout << ans[0] << endl;
    return 0;
}

Measured memory_bytes: 256
A,B = map(int,input().split())
#%%
H,W = 100,100
S = [[0]*H for _ in range(W)]
f = True
if A>B:
    A,B = B,A
    f = False
def change(r,c,state):
    for i in range(r,r+3):
        for j in range(c,c+3):
            S[i][j] = 1
    
    if state==0:
        S[r+1][c+1] = 0    
        return
    elif state==1:
        S[r+1][c+1] = 0
        for i in range(3):
            S[r+3][c+i] = 1
            S[r+i][c+3] = 1
        S[r+3][c+3] = 1
        if c+4==W:
            for i in range(4):
                S[r+i][c+3] = 0
            
        return
    elif state==2:     
        return
    


r,c = 0,0
white = 1
black = 0
while white!=A or black!=B:
    if white<A and black<B-1:
        change(r,c,0)
        white += 1
        black += 1
        
    elif white<A:
        change(r,c,1)
        white += 1
        
    elif black<B:
        change(r,c,2)
        black += 1
        
    else:
        break
    if c+4==W:
        c = 0
        r += 4
    else:
        c += 4

if f:
    T = [['.']*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j]==1:
                T[i][j]='#'
else:
    T = [['#']*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j]==1:
                T[i][j]='.'
print(H,W)
for t in T:
    print(''.join(t))

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    string s;
    string t;
    cin >> s >> t;

    vector<vector<ll>> charindex(26);

    ll ssize = s.size();

    rep(i, ssize){
        int charn = s[i] - 'a';

        charindex[charn].pback(i + 1);
    }

    vector<int> each_char_next(26,0);

    rep(i, 26){
        if(charindex[i].size() == 0) charindex[i].pback(-1);
    }

    ll ans = 0;
    ll index = 0;
    
    rep(i, t.size()){

        int charnum = t[i] - 'a';
        ll preindex = index;

        auto itr = lower_bound(ALL(charindex[charnum]), preindex + 1);

        if(itr == charindex[charnum].end()){
            itr = lower_bound(ALL(charindex[charnum]), 0);
        }

        if(itr == charindex[charnum].end()){
            ans = -1;
            break;
        }else{
            index = (*itr);

            //cerr << preindex << " " << index << endl;

            if(preindex < index){
                ans += index - preindex;
            }else{
                ans += (ssize - preindex) + index;
            }
        }

    }

    cout << ans << endl;

}


Measured memory_bytes: 1724
A,B = map(int,input().split())
ans = 0
for i in range(A,B+1):
    i = str(i)
    if i[0] == i[4]:
        if i[1] == i[3]:
            ans += 1
        else:
            ans += 0
    else:
        ans += 0
print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
 
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{
	fastio;
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	ll n;
	cin>>n;
	set<ll> s1;
	for (int i = 0; i < n; ++i)
	{
		ll a;
		cin>>a;
		s1.insert(a);
	}
	if(s1.size()==n){
		cout<<"YES";
	}
	else{
		cout<<"NO";
	}


	return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
int n, m, i, j, k;
char s[10];
int main(){
	scanf("%s", s);
	for(i=1; i<2; i++){
		if(s[i] == 'B') printf("ARC\n");
		else printf("ABC\n");
	}
	return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>

int main(void){
  int n, k;
  
  scanf("%d %d", &n, &k);
  
  if(n % 2 == 0){
    if(n / 2 >= k){
      printf("YES\n");
      return 0;
    } else {
      printf("NO\n");
      return 0;
    }
  } else {
    if((n + 1) / 2 >= k){
      printf("YES\n");
      return 0;
    } else {
      printf("NO\n");
      return 0;
    }
  }
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
using namespace std;

int hash[244140625];
char s[13];

int getchar(char ch) {
    if(ch == 'A') {
        return 1;
    } else if (ch == 'C') {
        return 2;
    } else if (ch == 'G') {
        return 3;
    } else if (ch == 'T') {
        return 4;
    }
}

int key() {
    int sum = 0, p = 1;
    for (int i = 0; i < strlen(s); i++) {
        sum += p * (getchar(s[i]));
        p *= 5;
    }
    return sum;
}

int main() {
    int n;
    char c[7];
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s %s", c, s);
        
        if(c[0] == 'i') {
            hash[key()] = 1;
        } if(c[0] == 'f') {
            if(hash[key()]) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 20180
# AOJ 00035: Is it Convex?
# Python3 2018.6.17 bal4u

EPS = 0.0001

# a, b, はラインの同一側にあるか。　-1, 0, 1
def atSameSide(a, b, line):
	sa = (line[1].real-line[0].real)*(a.imag-line[0].imag) \
		 + (line[1].imag-line[0].imag)*(line[0].real-a.real);
	sb = (line[1].real-line[0].real)*(b.imag-line[0].imag) \
		 + (line[1].imag-line[0].imag)*(line[0].real-b.real);
	if -EPS <= sa and sa <= EPS: return 0 		 # a in line
	if -EPS <= sb and sb <= EPS: return 0 		 # b in line
	if sa*sb >= 0: return 1           # a,b at same side
	return -1;

while True:
	try: p = list(map(float, input().split(',')))
	except: break
	
	p1 = complex(p[0], p[1])
	p2 = complex(p[2], p[3])
	p3 = complex(p[4], p[5])
	p4 = complex(p[6], p[7])
	if atSameSide(p2, p4, [p1, p3]) == -1 and \
	   atSameSide(p1, p3, [p2, p4]) == -1: print('YES')
	else: print('NO')


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

using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    int sum = 0;
    for(int i=0;i<n;i++){
        if(a[i] > b[i]) sum+=(a[i]- b[i]);
    }
    cout<<sum<<"\n";
    return 0;
}

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

int main() {
    while (true){
  string s1,s2;
  int u=-1,t=0,v=0;
  cin >> s1 >> s2;
  if (s1==".") break;
  vector<string> a(0),b(0);
  string y1="",y2="";
  for (int i=0;i<s1.size();i++){
    if (s1.at(i)=='"') {
      a.push_back("");
      u++;
      i++;
      while (true){
        if (s1.at(i)=='"') break;
        else a.at(u)=a.at(u)+s1.at(i);
        i++;
      }
    }
    y1=y1+s1.at(i);
  }
  u=-1;
  for (int i=0;i<s2.size();i++){
    if (s2.at(i)=='"') {
      b.push_back("");
      u++;
      i++;
      while (true){
        if (s2.at(i)=='"') break;
        else b.at(u)=b.at(u)+s2.at(i);
        i++;
      }
    }
    y2=y2+s2.at(i);
  }
  if (y1!=y2) {cout << "DIFFERENT" << endl;t=1;}
  for (int i=0;i<min(a.size(),b.size());i++){
    if (a.at(i)!=b.at(i)) v++;
  }
  if (v==0 && t==0) cout << "IDENTICAL" << endl;
  if (v==1 && t==0) cout << "CLOSE" << endl;
  if (v>1 && t==0) cout << "DIFFERENT" << endl;
}
}


Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    for(int i = 0; i < N; i++)  cin >> v[i];
    vector<int> v_copy(N);
    copy(v.begin(), v.end(), v_copy.begin());
    sort(v.begin(), v.end());
    int max = v[N-1];
    int second = v[N-2];
    for(int i = 0; i < N; i++){
        if(v_copy[i] != max){
            cout << max << endl;
        }
        else{
            cout << second << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3200
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] arr = new int[3];
		for (int i = 0; i < 3; i++) {
		    arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		System.out.println(arr[0] + " " + arr[2]);
	}
}



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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    string ans;
    if (a < b){
        ans = ((a + v * t >= b + w * t)? "YES" : "NO");
    }else{
        ans = ((a - v * t <= b - w * t)? "YES" : "NO");
    }
    cout << ans << endl;
    return 0;
}


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

#define FOR(i, a, b) for (int (i) = (a); (i) < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cerr << #x << " " << x << endl
#define eb emplace_back
#define _ << " " <<
typedef long long ll;
typedef std::pair<int, int> ii;
#define X first
#define Y second
#define double long double
typedef double db;
using namespace std;

const int MaxN = 200100;
const int Mod = 1e9 + 7;

ll A,B,C, K;

void solve() {

}

void load() {
  cin>>A>>B>>C>>K;
  if ((K % 2) == 0) cout<< A - B;
  else cout<<B-A;
}

int main(){
//  ios_base::sync_with_stdio(false);
  load();	
  solve();
  return 0;
}



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

long long int N;

void solve(int N){
  long long int res1, res2, res3;
  for(long long int h = 1; h <= 3500; h++){
    for(long long int n = 1; n <= 3500; n++){
      long long int a = N * h * n;
      long long int b = 4*h*n - N*n - N*h;
      if(b <= 0){
        continue;
      }
      if(a % b == 0){
        res1 = h;
        res2 = n;
        res3 = a / b;
        cout << res1 <<" "<< res2 <<" "<< res3 << endl;
        return;
      }
    }
  }
  return;
}

int main(){
  cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())

a = list(map(int,input().split()))

s = [0]
q = []
r = [0] * 41

for i in range(N):

    s.append(s[-1] + a[i])

ans = 0

for i in range(N+1):

    for j in range(i):

        now = s[i]-s[j]
        q.append(now)

q.sort()
ans = 0

for i in range(41):

    i = 40 - i

    nq = []

    for j in range(len(q)):
        if q[j] & (2 ** i) > 0:
            nq.append(q[j])

    if len(nq) >= K:
        q = []
        ans += 2 ** i
        for i in nq:
            q.append(i)

print (ans)

Measured memory_bytes: 72428
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int n,k;
  cin >> n >> k;
  cout << n-k+1 << "\n";
}


Measured memory_bytes: 256
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main (){
    int a,b,c,d;
    cin >> a>> b>> c>> d;
    cout <<c+b-d<<" " <<d+c-a <<" "<<a-d+b<<" " << b+c-a<< endl;
    return 0;
}

Measured memory_bytes: 256
#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[i];

    sort(v.begin(),v.end());

    for(int i = 0; i < n - 1; ++i){
        if(v[i] == v[i + 1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

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

int ground[52][52];

int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      char c;
      cin >> c;
      if (c == '#') {
        ground[i][j] += 9;
        for (int d = 0; d < 8; ++d) ground[i + dy[d]][j + dx[d]]++;
      }
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) cout << char(ground[i][j] < 9 ? ground[i][j] + '0' : '#');
    cout << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;//溢出会变成负值 
typedef long double ldb;
typedef unsigned long long ull;//自动取模2^64
const double pi=acos(-1.0);
const int mod = 1e9+7; // 998244353;
const int inf = 0x7fffffff;//2^31-1
const ll INF = 0x7fffffffffffffff;
const int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
//ll begin_time=clock();    ll end_time=clock();  cout<<"time = "<<end_time-begin_time<<" ms!"<<endl;
//bool operator < (const mmp &a) const{return x<a.x||x==a.x&&y<a.y;}       //map<int,map<int,int> >z;
//map<int,int>::iterator it;for(it=z.begin();it!=z.end();it++)printf("%d %d\n",it->first,it->second);
//ll poww(ll a,ll b){ll s=1;while(b){if(b&1)s=(s*a)%mod;a=(a*a)%mod;b>>=1;}return s%mod;}  //快速幂取模 
//lower_bound(begin,end,num); 第一个>=num的数字  upper_bound(begin,end,num); 第一个>num的数字 返回地址 
//freopen("input.in","r",stdin);     freopen("output.out","w",stdout);      //文件读写提交 
//reverse(s.begin(),s.end());   //反转字符串        floor(); 向下取整  ceil(); 向上取证 
//数轴上n个点移动到同一位置，移动到该组数字的中位数的总距离最短 
bool isPrime(int n){if(n==2||n==3)return 1;if(n%6!=1&&n%6!=5)return 0;
int t=sqrt(n);for(int i=5;i<=t;i+=6)if(n%i==0||n%(i+2)==0)return 0;return 1;}//判断素数 


int x[200005];
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	ll a,b,c,d,e,f,g,T;  
//	cin>>T;
	//while(T--)
	{
		cin>>a;
		b=0;
		for(int i=0;i<a;i++)
		{
			cin>>x[i];
			b^=x[i];
		}
		for(int i=0;i<a-1;i++)
		{
			cout<<ll(b^x[i]);
			cout<<" ";
		}
		cout<<ll(b^x[a-1])<<endl;
		
	}
	
}



Measured memory_bytes: 4348
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
struct Node
{
    int key;
    Node *right,*left,*parent;
};
Node *root,*NIL;
Node * treeMinimum(Node *x)
{
    while(x->left!=NIL) x=x->left;
    return x;
}
Node * find(Node *u,int k)
{
    while(u!=NIL&&k!=u->key)
    {
        if(k<u->key) u=u->left;
        else u=u->right;
    }
    return u;
}
Node * treeSuccessor(Node *x)
{
  if(x->right!=NIL) return treeMinimum(x->right);
  Node *y=x->parent;
  while(y!=NIL&&x==y->right)
  {
      x=y;
      y=y->parent;
  }
  return y;
}
void treeDelete(Node *z)
{
    Node *y;
    Node *x;
    if(z->left==NIL||z->right==NIL) y=z;
    else y=treeSuccessor(z);
    if(y->left!=NIL)
    {
        x=y->left;
    }else
    {
        x=y->right;
    }
    if(x!=NIL)
    {
        x->parent=y->parent;
    }
    if(y->parent==NIL)
    {
        root=x;
    } else
    {
        if(y==y->parent->left)
        {
            y->parent->left=x;
        }
        else
        {
            y->parent->right=x;
        }
    }
    if(y!=z)
    {
        z->key=y->key;
    }
    free(y);
}
void insert(int k)
{
        Node *y=NIL;
    Node *x=root;
    Node *z;
    z=(Node*)malloc(sizeof(Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;
    while(x!=NIL)
    {
        y=x;
        if(z->key<x->key)
        {
            x=x->left;
        }else
        {
            x=x->right;
        }
    }
    z->parent=y;
    if(y==NIL)
    {
        root=z;
    }
    else
    {
        if(z->key<y->key)
        {
            y->left=z;
        }
        else
        {
            y->right=z;
        }
    }
}
void inorder(Node *u)
{
      if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u)
{
        if(u==NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
int main()
{
    int n,i,x;
    string com;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        cin>>com;
        if(com[0]=='f')
        {
            scanf("%d",&x);
            Node *t=find(root,x);
            if(t!=NIL) printf("yes\n");
            else printf("no\n");
        } else if(com=="insert")
        {
            scanf("%d",&x);
            insert(x);
        }
        else if (com=="print")
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if (com=="delete")
        {
            scanf("%d",&x);
            treeDelete(find(root,x));
        }
    }
    return 0;
}

Measured memory_bytes: 22012
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 10000000
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type node struct {
	ID     int
	Height int
	Neigh  []*node
}

func dfs(nodes []*node, index int, visited map[*node]bool) int {
	if visited[nodes[index]] {
		return 0
	}

	nd := nodes[index]
	visited[nd] = true
	for _, ng := range nd.Neigh {
		if ng.Height >= nd.Height {
			return dfs(nodes, ng.ID, visited)
		}
	}
	return 1
}

func main() {
	n, m := nextInt(), nextInt()
	nodes := make([]*node, n)
	for i := 0; i < n; i++ {
		nodes[i] = &node{i, nextInt(), nil}
	}

	for i := 0; i < m; i++ {
		a, b := nextInt()-1, nextInt()-1
		nodes[a].Neigh = append(nodes[a].Neigh, nodes[b])
		nodes[b].Neigh = append(nodes[b].Neigh, nodes[a])
	}

	visited := make(map[*node]bool)
	ans := 0
	for i := 0; i < n; i++ {
		ans += dfs(nodes, i, visited)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 17216
#include<cstdio>

int partition(int A[], int p, int r){
    int x = A[r];
    int i=p-1;
    for(int j=p; j<r; j++){
        if(A[j] <= x){
            i++;
            int temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
    }
    int temp = A[i+1];
    A[i+1] =A[r];
    A[r] =temp;
    return i+1;
}

void quickSort(int A[], int p, int r){
    if(p<r){
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q+1, r);
    }
}

int main(int argc, char const *argv[])
{
    int H[10];
    for(int i=0; i<10; i++) scanf("%d", &H[i]);

    quickSort(H, 0,10-1);
    for(int i=0; i<3; i++) printf("%d\n", H[9-i]);
    return 0;
}



Measured memory_bytes: 2648
s = gets.chomp

ans = s.to_i
(1..(s.size - 1)).each do |i|
  (1..s.size - 1).to_a.combination(i) do |x|
    expr = s.chars.join(' ')
    x.each do |p|
      expr[p * 2 - 1] = '+'
    end
    ans += eval(expr.gsub(' ', ''))
  end
end

puts ans


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

int main(){
	string s ; cin >> s ;
	int n = s.size()-7 ;
	string ans = "keyence" ;
	for(int i=0;i<8;i++){
		bool check = true ;
		for(int j=0;j<i;j++){
			if(s.at(j)!=ans.at(j)){
				check = false ;
				break ;
			}
		}
		if(!check) continue ;
		for(int j=0;j<7-i;j++){
			if(s.at(i+n+j)!=ans.at(i+j)){
				check = false ;
				break ;
			}
		}
		if(check){
			cout << "YES" << endl ;
			return 0 ;
		}
	}
	cout << "NO" << endl ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define all(x) (x).begin(), (x).end()
#define v(T) vector<T>
#define vv(T) vector<v(T)>
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main()
{
    int n, k;
    cin >> n >> k;
    vv(mint) dp(n+1, v(mint)(k+1));
    vv(mint) dps(n+1, v(mint)(k+1));
    vi a(n);
    repran(i, 1, n+1) cin >> a[i];
    dp[0][0] = 1;
    rep(i, k+1) dps[0][i] = 1;
    repran(i, 1, n+1){
        rep(j, k+1){
            dp[i][j] = dps[i-1][j];
            if (j-a[i]-1>=0) dp[i][j] -= dps[i-1][j-a[i]-1];
            dps[i][j] = dp[i][j];
            if (j > 0) dps[i][j] += dps[i][j-1];
        }
    }
    cout << dp[n][k] << endl;
}

Measured memory_bytes: 162064
module mod_convex_score
  implicit none
  integer(8), parameter :: md = 998244353_8
contains
  integer(8) function score(k)
    implicit none
    integer, intent(in) :: k
    score = mod(pow(2_8,k)+md-mod(int(k+1,8),md),md)
    return
  end function score
  recursive function pow(a,b) result(p)
    implicit none
    integer(8), intent(in) :: a
    integer, intent(in) :: b
    integer(8) :: p
    p = 1_8
    if (b.eq.0) return
    if (mod(b,2).eq.0) then
      p = pow(a,b/2)
      p = mod(p*p,md)
      return
    end if
    p = mod(a*pow(a,b-1),md)
    return
  end function pow
  function inv(n) result(y)
    implicit none
    integer(8), intent(in) :: n
    integer(8) :: a, b, x, y, t, q
    a = mod(n,md)
    b = md
    x = 0
    y = 1
    do while(b.ne.0_8)
      q = a/b
      t = b
      b = mod(a,b)
      a = t
      t = y
      y = x
      x = t-q*x
    end do
    do while (y.lt.0_8)
      y = y+md
    end do
    y = mod(y,md)
    return
  end function inv
end module mod_convex_score
program convex_score
  use mod_convex_score
  implicit none
  integer :: n, x(200), y(200), a, b, c, i, j, k, s
  integer(8) :: m, p
  x = 0
  y = 0
  read(*,*) n
  do i = 1, n
    read(*,*) x(i), y(i)
  end do
  m = score(n)
  do i = 1, n-1
    do j = i+1, n
      a = y(j)-y(i)
      b = -x(j)+x(i)
      c = x(j)*y(i)-x(i)*y(j)
      s = 0
      do k = 1, n
        if (a*x(k)+b*y(k)+c.eq.0) s = s+1
      end do
      p = score(s)
      p = mod(p*inv(int(s,8)*int(s-1,8)/2_8),md)
      m = mod(m+md-p,md)
    end do
  end do
  write(*,'(i0)') m
  stop
end program convex_score

Measured memory_bytes: 256
#include<stdio.h>

int n, A[50];

int solve (int i, int m) {
    if ( m == 0 ) return 1;
    if ( i >= n ) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main() {
    int q, M, i;

    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
    scanf("%d", &q);
    for ( i = 0; i < q; i++ ) {
        scanf("%d", &M);
        if ( solve(0, M) ) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}

Measured memory_bytes: 580
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return

#B
def B():
    n = II()
    s = S()
    ans = 0
    for i in range(n + 1):
        s1 = list(set(s[i:]))
        s2 = list(set(s[:i]))
        b = 0
        for si in s1:
            b += si in s2
        ans = max(ans, b)
    print(ans)
    return

#C
def C():
    n = II()
    s = S()
    dp = [0 for i in range(n)]
    for num,si in enumerate(s):
        if si == "E":
            dp[num] = dp[num-1]+1
        else:
            dp[num] = dp[num - 1]
    ans = float("INF")
    a = max(dp)
    for i in range(n):
        ans = min(ans,  a - dp[i] + i - dp[i] + (s[i] == "E"))
    
    print(ans)
    return

#D
def D():
    n = II()
    a = LI()
    bitlength = len(bin(max(a))) - 2
    a = list(map(lambda x: bin(x)[:1:-1], a))
    cumulativebit = [[0] * bitlength for i in range(n)]
    for i in range(n):
        for bi in range(bitlength):
            cumulativebit[i][bi] += cumulativebit[i - 1][bi] + (0 if len(a[i]) <= bi else 1 if int(a[i][bi]) else 0)
    r = 0
    ans = 0
    for l in range(n):
        f = False
        cumulativebitl = cumulativebit[l]
        al = a[l]
        for r in range(r, n):
            cumulativebitr = cumulativebit[r]
            ar = a[r]
            for bi in range(bitlength):
                if cumulativebitr[bi] - cumulativebitl[bi] >= 2 or (l != r and len(ar) > bi and len(al) > bi and int(ar[bi]) and int(al[bi])):
                    f = True
                    break
            if f:
                break
        if f:
            ans += r - l
        else:
            ans += r - l + 1
    print(ans)
    return



#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 131588
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c, x, y, z, ans = 0;
    scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
    if (a + b > c + c) {
        z = min(x, y);
        x -= z, y -= z;
        ans += 2 * z * c;
        if (a * x + b * y > 2 * c * (x + y)) {
            ans += 2 * c * (x + y);
            x = 0, y = 0;
        }
    }
    ans += a * x + b * y;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
min = 0
max = 0
a_list = []
b_list = []
n.times do |i|
    a, b = gets.chomp.split.map(&:to_i)
    a_list << a
    b_list << b
end

a_list.sort!
b_list.sort!
ans = 0

if (n % 2) == 0
    a_num = a_list[(a_list.size / 2) - 1] + a_list[a_list.size / 2]
    b_num = b_list[(b_list.size / 2) - 1] + b_list[b_list.size / 2]
    ans = b_num - a_num + 1
else
    a_num = a_list[a_list.size / 2]
    b_num = b_list[b_list.size / 2]
    ans = b_num - a_num + 1
end
puts ans


Measured memory_bytes: 20432
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define KDNGU ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define S second
#define F first

using namespace std;

typedef long long LL;
typedef long double LD;

const int N = 1e5 + 9, M = 1e5 + 9, OO = 0x3f3f3f, MOD = 10000007;

int heights[N], ans[N];

int main(){
    memset(ans, OO, sizeof ans);
    KDNGU
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) cin >> heights[i];
    ans[0] = 0;
    for (int i = 1; i < k; ++i)
        ans[i] = abs(heights[i] - heights[0]);
    for (int i = k; i < n; ++i){
        for (int j = 1; j <= k; ++j)
            ans[i] = min(ans[i], abs(heights[i - j] - heights[i]) + ans[i - j]);
    }
    cout << ans[n - 1];
}
/*
    GOOD LUCK :*
*/


Measured memory_bytes: 1024
import bisect

N = int(input())
L = list(map(int, input().split()))

L.sort()

ans = 0
for i in range(N-2):
  for j in range(i + 1, N-1):
    idx = bisect.bisect_left(L, L[i] + L[j]) - 1
    ans += idx - j

print(ans)

Measured memory_bytes: 3316