akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 0) {
      if (a[i] % 3 != 0 && a[i] % 5 != 0) {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
def mod_pow(n, k):
    ans = 1
    while k > 0:
        ans = ans * n % mod
        k -= 1
    return ans
if n % 2 == 0:
    a.sort()
    for i in range(n//2):
        if a[2 * i] != a[2 * i + 1] or a[2 * i] != 2 * i + 1:
            print(0)
            exit()
else:
    a.sort()
    if a[0] != 0:
        print(0)
        exit()
    else:
        a = a[1:]
        for i in range(n//2):
            if a[2*i] != a[2 * i + 1] or a[2 * i] != 2*i + 2:
                print(0)
                exit()
print(mod_pow(2, n//2))

Measured memory_bytes: 14008
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

N = int(input())


def answer(info, ans):
    if max(ans) > N:
        return ans
    info2 = []
    for i in info:
        for l in ["3", "5", "7"]:
            info2.append(int(str(i) + l))
    ans += info2
    return answer(info2, ans)


a = sorted(list(set(answer([3, 5, 7], [3, 5, 7]))))
num = 0
for i in range(len(a)):
    if a[i] > N:
        print(num)
        break
    elif all(str(a[i]).count(d) > 0 for d in "753"):
        num += 1


Measured memory_bytes: 15572
// Bismillahirrahmanirrahim
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> vec;

int arr[300];


signed main() {
  int th = 100000, sc = 200000, fr = 300000;

  arr[1] = fr;
  arr[2] = sc;
  arr[3] = th;
  int a, b;cin >> a >> b;

  int res = arr[a]+arr[b];
  if(a == 1 and b == 1) {
      res += 400000;
    }
  cout << res << endl;


}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((a*100+b*10+c)%4==0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
s=gets.chomp
ary=s.scan(/R+L+/)
res=[]
ary.each do |str|
  rnum=str[/R+/].size
  lnum=str.size-rnum
  n=rnum/2 + lnum/2
  if rnum.odd?
    rres=n+1
    # 0000n+1n+10000
  else
    rres=n
  end
  if lnum.odd?
    lres=n+1
    # 0000n+1n+10000
  else
    lres=n
  end
  
  (2..rnum).each{|i| res<<0}
  res << rres
  res << lres
  (2..lnum).each{|i| res<<0}
end
puts res.join(' ')

Measured memory_bytes: 9076
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int n;

void solve(){
    string s[101];
    for(int i=0;i<n;i++){
        string ss; cin >> ss;
        string name = "";
        name.push_back(ss[0]);
        for(int j=1;j<ss.size();j++){
            if(ss[j-1] == 'a' or ss[j-1] == 'i' or ss[j-1] == 'u' or ss[j-1] == 'e' or ss[j-1] == 'o'){
                name.push_back(ss[j]);
            }
        }
        s[i] = name;
        //cerr << s[i] << endl;
    }

    for(int k=1;k<=50;k++){
        set<string> st;
        for(int i=0;i<n;i++){
            string ss = s[i];
            if(ss.size() >= k){
                ss = ss.substr(0,k);
            }
            st.insert(ss);
        }
        if(st.size() == n){
            cout << k << endl;
            return;
        }
    }
    cout << -1 << endl;
}

int main(){
    while(1){
        cin >> n;
        if(n==0) break;
        solve();
    }
}



Measured memory_bytes: 3168
#include<iostream>
#include<cstdio>
#include<cmath>
typedef long long ll;
const int N=305;
int h,w,d,row[N*N],col[N*N],a[N][N];
ll dp[N*N];
int main() {
    scanf("%d%d%d",&h,&w,&d);
    for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) scanf("%d",a[i]+j),row[a[i][j]]=i,col[a[i][j]]=j;
    for(int i=1;i<=h*w;i++) if(i<=d) dp[i]=0;else dp[i]=dp[i-d]+abs(row[i]-row[i-d])+abs(col[i]-col[i-d]);
    int q,l,r;scanf("%d",&q);
    while(q--) {
        scanf("%d%d",&l,&r);
        printf("%lld\n",dp[r]-dp[l]);
    }
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,k,m,i;
	for(;cin>>n>>k,n;){
		vector<int>vec(n);
		for(m=k,i=0;i<n;i++)vec[i]=i+1;
		i=(m-1)%vec.size();
		vec.erase(vec.begin()+i);
		for(;vec.size()>1;vec.erase(vec.begin()+i))if(i+=(k-1)%vec.size(),i>=vec.size())i-=vec.size();
		cout<<vec[0]<<endl;
	}
}

Measured memory_bytes: 1216
def main():
    N = int(input())
    zoro = []

    for i in range(N):
        a, b = map(int, input().split())
        if a == b:
            zoro.append(1)
            if i >= 2:
                if zoro[i-2] == zoro[i-1] and zoro[i-1] == zoro[i]:
                    print('Yes')
                    return
        else:
            zoro.append(0)

    print('No')


main()


Measured memory_bytes: 9112
n = int(input())

total = 0

remain = 0
c = 0
for i in range(n):
    m = int(input())
    if i > c + 1:
        remain = 0
    all_ = remain + m
    total += all_//2
    if all_ % 2 != 0 and all_//2 > 0:
        remain = all_ % 2
        c = i
print(total)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll X;
  while (cin >> X) {
    int res = 0;
    ll upper = 0;
    while (upper < X) {
      ++res;
      upper += res;
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    #define LONGMAX 1e14
    #define dd double
    #define MOD 998244353  
    # define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
    #define nl cout<<endl
    #define fill(a,val) memset(a,val,sizeof(a))
    #define rt ll Q[100005]={0}
    #define mp make_pair
    #define endl "\n"
    #define test() ll t;cin>>t;while(t--)
    #define pb push_back
    #define ff first    
    #define ss second
    #define all(v) v.begin(),v.end()
    #define s(ar,n) sort(ar,ar+n)
    #define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
    #define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
    #define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
    #define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
    #define maxa(ar,N) *max_element(ar,ar+N)
    #define mina(ar,N) *min_element(ar,ar+N)
    #define INF 1e15
    #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
    #define printclock cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
    ll power(ll x, ll y){ll res=1;while(y>0){if(y&1)res = (res*x);y = y>>1;x = (x*x);}return res;}  
    ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
    void ceilsearch(ll ar[],ll low,ll high,ll x,ll &y){if(low>high)return;ll mid=(low+high)/2;if(ar[mid]>=x){y=mid;ceilsearch(ar,low,mid-1,x,y);}else{ceilsearch(ar,mid+1,high,x,y);}}
    signed main()   
    {
        fastio();  
        string s;
        cin>>s;
        string x="";
        string y="";
        ll N=s.size();
        for(ll i=0;i<N/2;i++)
            x+=s[i];
        for(ll i=N/2+1;i<N;i++)
            y+=s[i];
        string rev="";
        for(ll i=x.size()-1;i>=0;i--)
            rev+=x[i];
        if(rev==x&&x==y)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }   

Measured memory_bytes: 384
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int b, f, r, v;;
    int house[5][4][11];
    int i, n;
 
    for (b = 1; b <= 4; b++) {
        for (f = 1; f <= 3; f++) {
            for (r = 1; r <= 10; r++) house[b][f][r] = 0;
        }
    }
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d%d%d%d", &b, &f, &r, &v);
        house[b][f][r] += v;
    }
 
    for (b = 1; b <= 4; b++) {
        for (f = 1; f <= 3; f++) {
            for (r = 1; r <= 10; r++) printf(" %d", house[b][f][r]);
            putchar('\n');
        }
        if (b < 4) puts("####################");
    }
    return 0;
}


Measured memory_bytes: 2044
#include <algorithm> // std::sort(begin,end), std::min, std::max
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

template <typename T> // 0<1<2<3<4
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
template <typename T> // 0>1>2>3>4
using pq_dsc = priority_queue<T>;

int main(int argc, char const *argv[]) {
  int a, b;
  cin >> a >> b;

  if (a < 10 && b < 10) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
void find(vector<int>&v,int flag,map<int,int>mp,int &a,int &b){
	int n=v.size();
	if(flag==0){
		int ma=0,val1=-1,val2=-1;
		for(int i=0;i<n;i+=2){
			if(mp[v[i]]>ma){
				ma=mp[v[i]];
				val1=v[i];
			}
		}
		ma=0;
		//int ma=0,val1=-1,val2=-1;
		for(int i=0;i<n;i+=2){
			if(mp[v[i]]>ma&&v[i]!=val1){
				ma=mp[v[i]];
				val2=v[i];
			}
		}
		a=val1,b=val2;
	}
	else{
		int ma=0,val1=-1,val2=-1;
		for(int i=1;i<n;i+=2){
			if(mp[v[i]]>ma){
				ma=mp[v[i]];
				val1=v[i];
			}
		}
		ma=0;
		//int ma=0,val1=-1,val2=-1;
		for(int i=1;i<n;i+=2){
			if(mp[v[i]]>ma&&v[i]!=val1){
				ma=mp[v[i]];
				val2=v[i];
			}
		}
		a=val1,b=val2;
	}
}
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
    int n;
    cin>>n;
    vector<int>v(n);
    map<int,int>mp1,mp2;
    for(int i=0;i<n;i++){
    	cin>>v[i];
    	if(i%2==0){
    		mp1[v[i]]++;
    	}
    	else{
    		mp2[v[i]]++;
    	}
    }
    // for(int i=0;i<n;i++){
    // 	if()
    // }
    int firstmax1,firstmax2,secondmax1,secondmax2;
    find(v,0,mp1,firstmax1,secondmax1);
    find(v,1,mp2,firstmax2,secondmax2);
   // cout<<firstmax1<<" "<<secondmax1<<" "<<firstmax2<<" "<<secondmax2<<endl;
    if(firstmax1!=firstmax2){
    	cout<<n-mp1[firstmax1]-mp2[firstmax2]<<endl;
    }
    else{
    	cout<<n-max(mp1[firstmax1]+mp2[secondmax2],mp1[secondmax1]+mp2[firstmax2])<<endl;
    }
}

Measured memory_bytes: 7680
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
b = -1
for a in A:
        ans += B[a - 1]
        if b + 1 == a:
                ans += C[a -2]
        b = a
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll k;
  cin>>k;
  ll n=50;
  ll a[n+1]={};
  cout<<n<<endl;
  if(k<=n){
    for(int i=1;i<=k;i++){
      cout<<n<<" ";
    }
    for(int i=k+1;i<=n;i++){
      cout<<0<<" ";
    }
    cout<<endl;
    return 0;
  }

  for(int i=1;i<=k%n;i++){
    a[i]=2*50+(k-n)/n-k%n+1;
  }
  for(int i=k%n+1;i<=n;i++){
    a[i]=50+(k-n)/n-k%n;
  }

  for(int i=1;i<=n;i++){
    cout<<a[i]<<" ";
  }
  cout<<endl;

  return 0;
}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

ll a ;

int main(){
  int n ;
  ll x = 1;
  scanf("%d", &n) ;

  for(int i = 0 ;i<n ;i++){
    scanf("%lld", &a) ;
    ll y = __gcd(x, a) ;
    x/=y ;
    x*=a;
  }
  cout <<x << endl ;
  
  return 0 ;
}

Measured memory_bytes: 256
X = int(input())

def multiple_year(n): #n円預けてた時、一年後の預金額
    money = int(n * 101 / 100)
    return money

money = 100 #最初百円
year = 0
while X > money :
    money = multiple_year(money)
    year = year + 1
print(year)

Measured memory_bytes: 9104
a,b=map(int,input().split())

c=[]
for i in range(b):
    d,e=map(str,input().split())
    c.append([int(d),e])

acans=0
waans=0
ac=[0]*(a+1)
wa=[0]*(a+1)
for i in range(b):
    if c[i][1]=="AC":
        if ac[c[i][0]-1]==0:
            acans+=1
            ac[c[i][0]-1]+=1
            waans+=wa[c[i][0]-1]
    else:
        wa[c[i][0]-1]+=1
#print(ac)
#print(wa)
print(acans,waans)

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int n,m,x;
int a[15][15], c[15];

void input(){
	cin>>n>>m>>x;
	rep(i,n){
		cin>>c[i];
		rep(j,m)cin>>a[i][j];
	}
}

int solve(){
	int ret=INF;
	rep(bit, (1<<n)){
		int buy[15]={};
		int tmp=0;
		rep(i,n){
			if(bit & (1<<i)){
				rep(j,m)buy[j]+=a[i][j];
				tmp+=c[i];
			}
		}
		rep(j,m){
			if(buy[j]<x) tmp = INF;
		}
		ret = min(ret, tmp);
	}
	return ret;
}

int main()
{
	input();
	int ans=solve();
	cout<<(ans<INF?ans:-1)<<endl;
	return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

ll d[13][100001]={};
int h[100000];
int main() {
	int n;
	cin>>n;
	rep(i,n)cin>>h[i];
	bool flg=true;
	if(n==1){
		cout<<"Yes"<<endl;
		return 0;
	}
	rep(i,n-1){
		if(h[i]<h[i+1]){
			h[i+1]--;
		}else if(h[i]>h[i+1]){
			flg=false;
		}
	}
	if(flg){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

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

        long long n, k, cnt = 0;
        cin >> n >> k;

        vector<int> h(n);
        for (auto &x : h) cin >> x;
        sort(h.begin(), h.end(), greater<long>());
        if (k >= n) {
                cout << 0 << endl;
        } else {
                for (int i = k; i < n; i++) cnt += h[i];
                cout << cnt << endl;
        }
        return 0;
}

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

#define vecc vector<vector<ll>>
#define LM LLONG_MAX
#define int long long int
 
#define ff first
#define ss second
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

#define M 1000020
#define MOD 1000000007

signed main()
{
        FAST;
        
        ll n,d;
        cin>>n>>d;
        
        ll ans=ceil((ld)n/((2*d)+1));
        
        cout<<ans;
        
        
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 500*i + 100*j + 50*k == x:
                cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,m;
char ch[188][188];
int sum[188][188];
int dp[2][188][188][188];
bool eq(int x1,int y1,int x2,int y2)
{
    int siz=(x2-x1+1)*(y2-y1+1);
    int c1=sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1];
    return c1==siz||c1==0;
}
void init()
{
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            sum[i][j]+=sum[i][j-1];
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            sum[i][j]+=sum[i-1][j];
    for(int i=1;i<=n;++i)
        for(int j=i;j<=n;++j)
            for(int l=1,r;l<=m;l=r)
            {
                r=l;
                while(eq(i,l,j,r)&&r<=m)r++;
                for(int p=l;p<r;++p)dp[0][i][j][p]=r-1;
//                if(i!=j) cout<<"i: "<<i<<" j: "<<j<<" l: "<<l<<" r: "<<r<<endl;
                if(l==r)dp[0][i][j][l]=l-1,r++;
            }
}
int find(int c,int u,int d,int L)
{
    int l=u,r=d-1,mid;
    int res=0;
    int v1,v2;
    while(l<=r)
    {
        mid=(l+r)/2;
        v1=dp[c][u][mid][L];
        v2=dp[c][mid+1][d][L];
        res=max(res,min(v1,v2));
        if(v1<v2)r=mid-1;
        else l=mid+1;
    }
    return res;
}
void DP(int c)
{
    int nv,lv;
    for(int i=1;i<=n;++i)
        for(int j=i;j<=n;++j)
            for(int l=1;l<=m;++l)
            {
                lv=dp[c^1][i][j][l];
                if(lv!=m)
                {
                    nv=dp[c^1][i][j][dp[c^1][i][j][l]+1];
                    nv=max(nv,find(c^1,i,j,l));
                }
                else nv=m;
                dp[c][i][j][l]=nv;
            }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
    {
        scanf("%s",ch[i]+1);
        for(int j=1;j<=m;++j)
            if(ch[i][j]=='#')sum[i][j]=1;
    }
//    cout<<"inited\n";
    init();
    int ans=0;
    for(int i=1;dp[(i&1)^1][1][n][1]<m;++i)
    {
        DP(i&1),ans=i;
//        cout<<"i: "<<i<<" dp: "<<dp[i&1][1][n][1]<<endl;
    }
    printf("%d\n",ans);
    return 0;
}


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

int main() {
	// your code goes here
	int n,d; cin >> n >> d;
	d=2*d+1;
	if(n%d==0) cout << n/d << endl;
	else cout << (n-n%d)/d+1 << endl;
	return 0;
}

Measured memory_bytes: 256
# coding=utf-8

if __name__ == '__main__':
    N, Y = map(int, input().split())

    for i in range(N + 1):
        for j in range(N  - i + 1):
            k = (N - i - j)

            if 10 * i + 5 * j + k == Y / 1000:
                print(i, j, k)
                exit()

    print('-1', '-1', '-1')

Measured memory_bytes: 3060
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define repd(z, x, y) for(int z=x;z>=y;--z)
#define com bool operator<(const node &b)const
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int maxn = (ll) 3e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;
int a[1005][1005];
char s[1005][1005];
const int dirx[] = {1, -1, 0, 0};
const int diry[] = {0, 0, 1, -1};

void solve() {
    int h, w;
    cin >> h >> w;
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    rep(i, 1, h)cin >> (s[i] + 1);
    a[sx][sy] = 1;
    queue<pii > qcan, q;
    q.push({sx, sy});
    while (true) {
        while (!q.empty()) {
            pii now = q.front();
            q.pop();
            qcan.push(now);
            rep(i, 0, 3) {
                int x = now.first + dirx[i];
                int y = now.second + diry[i];
                if (x >= 1 && x <= h && y >= 1 && y <= w && a[x][y] == 0 && s[x][y] == '.') {
                    a[x][y] = a[now.first][now.second];
                    q.push(pii{x, y});
                }
            }
        }
        while (!qcan.empty()) {
            pii now = qcan.front();
            qcan.pop();
            rep(i, -2, 2)rep(j, -2, 2) {
                    int x = now.first + i;
                    int y = now.second + j;
                    if (x >= 1 && x <= h && y >= 1 && y <= w && a[x][y] == 0 && s[x][y] == '.') {
                        a[x][y] = a[now.first][now.second] + 1;
                        q.push(pii{x, y});
                    }
                }
        }
        if (q.empty())
            break;
    }
    cout << a[tx][ty] - 1;
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 12560
n,m=map(int,input().split())
dp=[0 for i in range(n+1)]
dp[0]=1
for i in range(m):
    dp[int(input())]="b"
for i in range(1,n+1):
    if(dp[i]=="b"):
        dp[i]=0
    else:
        dp[i]=(dp[i-1]+dp[i-2])%1000000007
print(dp[n])

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

int main () {
  int K;
  string S;
  cin >> K >> S;
  
  if (S.size()>K) {
    for(int i=0;i<K;i++) {
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
  
  else {
    cout << S << endl;
  }
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstring>
#define N 100000
#define B 40
using namespace std;
typedef long long LL;
LL a[N+1];
LL count[B][2];
LL solve(LL bit_max) //only consider up to bit_max bits, but otherwise we can pick any k we want
{
	LL ans = 0;
	for(LL b = 0; b < bit_max; b++)
		ans += (1LL<<b)*max(count[b][0],count[b][1]);
	return ans;
}
LL solve()
{
	int n; LL k; cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	memset(count,0,sizeof count);
	for(LL b = 0; b < B; b++)
		for(int i = 0; i < n; i++)
			count[b][(a[i]&(1LL<<b))>0]++;

	LL best = 0; //initialize it to choosing 0, always possible
	for(LL b = 0; b < B; b++)
		best += (1LL<<b)*count[b][1]; 

	LL partial = 0;
	for(LL b = B-1; b >= 0; b--)
		if(k&(1LL<<b)) //1
		{
			best = max(best,partial+(1LL<<b)*count[b][1]+solve(b)); //we choose 0 and everything is free
			partial += (1LL<<b)*count[b][0]; //we choose 1, and we are still locked, but we got this benefit
		}
		else
			partial += (1LL<<b)*count[b][1]; //we are forced to choose 0
	best = max(best,partial);

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

	cout<<solve()<<endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayDeque;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
  	ArrayDeque<Integer> a = new ArrayDeque<Integer>();
  	Scanner sc = new Scanner(System.in);
  	
  	while(sc.hasNext()){
  		if(sc.hasNextInt()){
			a.push(sc.nextInt());
  		}else{
  			int o1 = a.pop();
  			int o2 = a.pop();
  			switch(sc.next().charAt(0)){
	  			case '+':
		  			a.push(o1 + o2);
		  			break;
		  		case '-':
		  			a.push(o2 - o1);
		  			break;
		  		case '*':
		  			a.push(o1 * o2);
		  			break;
		  		default:
		  			break;
  			}
  		}
  	}
  	System.out.println(a.pop());

  }
  
}

Measured memory_bytes: 26652
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int Sosuu_hantei(int N) {
	if (N==1) {return false;}
	int M = sqrt(N) +1;
	for(int i=2; i<M; i ++ ){
		if(( N % i ) == 0 ) {return false;}
	}
	return true;
};

int main() {
	int a=0, d=0, n=0, Num=0;
	while(1){
		scanf("%d%d%d", &a, &d, &n);
		if (a == 0 && d == 0 && n == 0) break;
		Num = a;
		if (Sosuu_hantei(Num)) {n--;}
		while (n!=0) {
			Num +=d;
			if (Sosuu_hantei(Num)) {n--;}
		}
		printf("%d\n", Num);
	}
}

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

using namespace std;

typedef long long ll;

ll arr[(int)2e5+10];

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

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

    for(int i=0; i<n; i++) cin >> arr[i];
    sort(arr,arr+n);

    ll sol = 0;
    for(int i=0; i<n; i++){
        if(n-i<=k) break;
        else sol+=arr[i];
    }

    cout << sol << "\n";

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,k;
    cin >> n >> k;
    if(n>=10)cout << k << endl;
    else cout << k + 100*(10-n) << endl;
}

Measured memory_bytes: 892
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

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

    int N;
    cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }

    ll ave1 = sum / N, ave2 = sum / N + 1, ave3 = sum / N - 1;
    ll tmp1 = 0, tmp2 = 0, tmp3 = 0;
    rep(i, N) {
        tmp1 += (A[i] - ave1) * (A[i] - ave1);
        tmp2 += (A[i] - ave2) * (A[i] - ave2);
        tmp3 += (A[i] - ave3) * (A[i] - ave3);
    }

    cout << min(tmp1, min(tmp2, tmp3)) << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define vct vector<ll>
#define umap map<ll,ll>
 
int main()
{
   
    ll n;cin>>n;
    ll ar[n];
    for(ll i=0;i<n;i++)cin>>ar[i];
    ll flg=1;
    ll mx=ar[n-1];
    for(ll i=n-2;i>=0;i--)
    {
        ll cur=ar[i];
        if(cur>mx)
        {
            if((cur-mx)>1)
            {
                flg=0;
                break;
            }
        }
        else
        {
            mx=cur;
        }
    }
    if(flg)cout<<"Yes";
    else cout<<"No";
    
}

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

long long dp[101][100001];

long long int knap(int wt[],int val[],int w,int n){
    if(n==0 || w==0)
    return 0;
    
    if(dp[n][w]!=-1)
    return dp[n][w];
    
    if(wt[n-1]<=w){
        return dp[n][w]= max(val[n-1]+knap(wt,val,w-wt[n-1],n-1),knap(wt,val,w,n-1));
    }
    else{
        return dp[n][w]=knap(wt,val,w,n-1);
    }
}

int main() {
	// your code goes here
	memset(dp,-1,sizeof(dp));
	int n,w;
	cin>>n>>w;
	int wt[n],val[n];
	for(int i=0;i<n;i++)
	cin>>wt[i]>>val[i];
	
	long long int ans=knap(wt,val,w,n);
	cout<<ans;
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

struct Edge{
    ll from, to, cost;
};

using Edges = vector<Edge>;

bool bellman_ford(Edges &Es, int V, int s, vector<ll>& dis){
    dis.resize(V,LINF);
    dis[s] = 0;
    int cnt = 0;
    while(cnt < V){
        bool end = true;
        for(auto e: Es){
            if(dis[e.from] != LINF && dis[e.from]+e.cost < dis[e.to]){
                dis[e.to] = dis[e.from] + e.cost;
                end = false;
            }
        }
        if(end) return false;
        cnt++;
    }
    return (cnt==V);
}

bool bellman2(Edges &Es, int V, int s, vector<ll>& dis, vector<bool>& negative){
    int cnt = 0;
    while(cnt <= V){
        for(auto e: Es){
            if(negative[e.from] == true) negative[e.to] = true;//値の更新が起きなくても負経路に入ることあり
            if(dis[e.from] != LINF && dis[e.from]+e.cost < dis[e.to]){
                dis[e.to] = dis[e.from] + e.cost;
                negative[e.to] = true;
            }
        }
        cnt++;
    }
    return (negative[V-1]);
}

int main() {
    int N,M; cin >> N >> M;

    Edges Es(M);
    REP(i,M){
        int a,b,c; cin >> a >> b >> c;
        a--;b--;
        Es[i] = {a,b,-c};
    }

    vector<ll> dis;
    bellman_ford(Es, N, 0, dis);
    
    vector<bool> negative(N,false);
    if(bellman2(Es, N, 0, dis, negative)) cout << "inf" << endl;
    else  cout << -dis[N-1] << endl;

    




    return 0;
}

Measured memory_bytes: 3680
while True:
    N=int(input())
    A=0
    B=0
    C=0
    D=0
    E=0
    F=0
    G=0
    H=0
    I=0
    J=0
    i=0
    j=0
    L=[]
    if N==0:
        break
    else:
        L=[int(input()) for _ in range (N)]
        for i in range (N):
            if L[i]==0:
                A+=1
            elif L[i]==1:
                B+=1
            elif L[i]==2:
                C+=1
            elif L[i]==3:
                D+=1
            elif L[i]==4:
                E+=1
            elif L[i]==5:
                F+=1
            elif L[i]==6:
                G+=1
            elif L[i]==7:
                H+=1
            elif L[i]==8:
                I+=1
            else:
                J+=1
        S=[A,B,C,D,E,F,G,H,I,J]
        
        
        for j in range(10):
            T=S[j]
            if T==0:
                print("-")
            else:
                k=0
                print("*"*T)
                
    



Measured memory_bytes: 5720
#include <bits/stdc++.h>
using namespace std;
// To give an input string after a integer or double is taken input
//cin.ignore();			// better to use 2 times getline(cin,s);
// g++ iterator.cpp -std=c++17
#define pb push_back
#define mk make_pair
#define siz size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast()
   {
   	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);
   }


int main(void)
{
	fast();
	int n;
	cin>>n;
	if(n%2==0)
	{
	    cout<<n/2<<endl;
	}
	else
	{
	    cout<<(n/2)+1<<endl;
	}
}

Measured memory_bytes: 256
import bisect
while 1:
    n,m=map(int,input().split())
    if n==0:break
    s=[]
    a=[0]+sorted([int(input()) for _ in range(n)])
    for i in range(n+1):
        for j in a[i:]:
            if a[i]+j>m:break
            s+=[a[i]+j]
    s.sort()
    print(max(i+s[bisect.bisect_right(s,m-i)-1]for i in s))

Measured memory_bytes: 28904
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 

    int n,k,c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    bool ok[n]={};
    for(int i=0;i<n;i++){
        if(s[i]=='x')continue;
        ok[i] = 1;
    }
    bool use[n]={};
    int cnt = 0;
    int now = 0;
    while(now < n){
        if(ok[now]){
            use[now] = 1;
            now += c;
            cnt++;
        }
        now++;
    }
    if(cnt > k)return 0;
    vector<int> ans;
    now = n-1;
    while(now >= 0){
        if(ok[now]){
            if(use[now])ans.push_back(now);
            now -= c;
        }
        now--;
    }
    if(ans.size())sort(ans.begin(),ans.end());
    for(auto i:ans){
        cout << i +1 << "\n";
    }
}

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

using namespace std;

int main()
{
    bool ok=false;
   int x;
   cin>>x;
   for(int i=1;i<=9;i++)
   {
      for(int j=1;j<=9;j++)
      {
          if(i*j==x ) ok=true;
          
      }
   }
   if(ok==true) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
  
  
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int ll;
typedef  long double ld;
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; i++)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define mp make_pair
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}

int main()
{
    fast;
    int x,y;
    cin>>x>>y;
    bool yes=false;
    for(int i=0;i<=y/4;i++)
    {
        if(((y-4*i)%2==0)&&(i+((y-4*i)/2))==x)
        {
            yes=true;
            break;
        }
    }
    if(yes==true)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}   

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

int main(){
        int n,i,j,ans=0;
        cin >> n;
        vector<int> l(n);
        for(i=0;i<n;++i) cin >> l.at(i);
        sort(l.begin(),l.end());
        for(i=0;i<n-1;++i){
                for(j=i+1;j<n;++j){
                        auto iter = lower_bound(l.begin(),l.end(),l.at(i)+l.at(j));
                        size_t dist = distance(l.begin(),iter);
                        ans += dist - j - 1;
                }
        }
        cout << ans << endl;
        return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int res = 0;
  for (int i = 1; i < N / 2 + 1; i++) {
    if (i != N - i) res++;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
T = [a, b, c, d, e]
for t in T:
    if t - a > k or e -t > k:
        print(':(')
        exit(0)
print('Yay!')


Measured memory_bytes: 9000
from sys import stdin
from itertools import groupby

a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

if b < c or d < a:
    print(0)
elif b >= d and c >= a:
    print(d-c)
elif a >= c and b <= d:
    print(b-a)
elif a >= c:
    print(d-a)
elif c > a:
    print(b-c)

Measured memory_bytes: 3060
#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 MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  ll N,M,L;
  cin >> N >> M >> L;
  ll d[N][N];
  REP(i,N)REP(j,N)d[i][j]=INF;

  REP(i,M){
    int a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    d[a][b] = c;
    d[b][a] = c;
  }

//  REP(i,N)REP(j,N)cout << i << " " << j << " " << d[i][j] << endl;

  REP(k,N)REP(i,N)REP(j,N){
    if(i==j)continue;
    if(d[i][j] > d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j];
  }  

  REP(i,N)REP(j,N){
    if(d[i][j]<=L){
      d[i][j]=1;
    }else{
      d[i][j]=INF;
    }
  }

  REP(k,N)REP(i,N)REP(j,N){
    if(i==j)continue;
    if(d[i][j] > d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j];
  }  

  int Q;
  cin >> Q;
  REP(i,Q){
    int s,t;
    cin >> s >> t;
    s--;t--;
    if(d[s][t] < INF){
      cout << d[s][t] - 1 << endl;
    }else{
      cout << -1 << endl;
    }
  }

}



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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;


vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

vector<pair<long long, long long> > ps;
int N,M,mi=infi;
void func(int i, int a){
    if(i==ps.size()){
        if(a>=N)mi = min(mi, a);
        return;
    }
    for(int j = 0; j <= ps[i].second; j++){
        func(i+1, a);
        a*=ps[i].first;
    }
}

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    cin  >> N >> M;
    ps = prime_factorize(M);
    func(0, 1);
    cout << M/mi << "\n";

    return 0;
}

Measured memory_bytes: 256
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll int n;
		cin>>n;
		ll int arr[n+1];
		ll int sm=0;
		for(ll int i=1;i<=n;i++) 
		{
			cin>>arr[i];
			sm+=arr[i];
		}
		ll int mini=1e18;
		ll int p=0;
 		for(ll int i=1;i<n;i++)
		{
			p+=arr[i];
			ll int q=sm-p;
			mini=min(mini,abs(p-q));
		}
		cout<<mini;
	}
	return 0;
}

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

const int N = 2005;

int a[N][N];
int ps[N][N];
int b[N][N];
int ps2[N][N];
int c[N][N];
int ps3[N][N];

int main() {
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			char c;
			cin >> c;
			a[i][j] = c - '0';
			ps[i][j] = ps[i - 1][j] + ps[i][j - 1] + a[i][j] - ps[i - 1][j - 1];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			b[i][j] = a[i][j] && a[i + 1][j];
			c[i][j] = a[i][j] && a[i][j + 1];
			ps2[i][j] = ps2[i - 1][j] + ps2[i][j - 1] + b[i][j] - ps2[i - 1][j - 1];
			ps3[i][j] = ps3[i - 1][j] + ps3[i][j - 1] + c[i][j] - ps3[i - 1][j - 1];
	//		cout << i << " " << j << " " << ps3[i][j] << endl;
		}
	}
	for (int i = 0; i < q; i++) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int ans = ps[x2][y2] - ps[x1 - 1][y2] - ps[x2][y1 - 1] + ps[x1 - 1][y1 - 1];
	//	cout << ans << endl;
		int x = ps2[x2 - 1][y2] - ps2[x1 - 1][y2] - ps2[x2 - 1][y1 - 1] + ps2[x1 - 1][y1 - 1];
		int y = ps3[x2][y2 - 1] - ps3[x1 - 1][y2 - 1] - ps3[x2][y1 - 1] + ps3[x1 - 1][y1 - 1];
	//	cout << ans << " " << x << " " << y << " " << ans - x - y << endl;c
		cout << ans - x - y << endl;
	}
	return 0;
}


Measured memory_bytes: 96000
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;

#define ll long long

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if(A != B){
        if(B == C){
            cout << A << endl; 
        }else{
            cout << B << endl;
        }
    }else{
        cout << C << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int j,N,R[200000],maxv,minv;

  scanf("%d",&N);
  for(j=0;j<N;j++){
    scanf("%d",&R[j]);
  }
  minv=R[0];
  maxv=R[1]-R[0];
  for(j=1;j<N;j++)
    {      
      if(maxv<R[j]-minv)
	{
	  maxv=R[j]-minv;
	}
	  
      if(minv>R[j])
	{
	  minv=R[j];
	}
    }
    
  printf("%d\n",maxv);
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 2e5 + 5;
int a[N];
int n;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n, greater<int>());
    priority_queue<int> que;
    que.push(a[0]);
    ll res = 0;
    for (int i = 1; i < n; ++i) {
        int m = que.top();
        que.pop();
        res += m;
        que.push(a[i]);
        que.push(a[i]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    string s;
    cin>>s;
    for(int i=0;i<s.size();i+=2){
        cout<<s[i];
    }
    return 0;
}


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

class dist_unionfind {
 private:
  vector<pair<int, int>> tree;  // parent, (w_parent-w_this)
  pair<int, int> getR(int a) {  //
    if (tree[a].first == -1) {
      return make_pair(a, 0);
    } else {
      return tree[a] = make_pair(getR(tree[a].first).first,
                                 getR(tree[a].first).second + tree[a].second);
    }
  }

 public:
  dist_unionfind(int size) {
    tree = vector<pair<int, int>>(size, make_pair(-1, 0));
  }
  pair<bool, int> check(int a, int b) {
    pair<int, int> ra = getR(a), rb = getR(b);
    return make_pair(ra.first == rb.first, ra.second - rb.second);
  }
  void unite(int a, int b, int dist) {  // dist = w_b-w_a
    pair<int, int> ra = getR(a), rb = getR(b);
    if (ra.first == rb.first) return;
    tree[ra.first].first = rb.first;
    tree[ra.first].second = dist - ra.second + rb.second;
  }
};

int main() {
  int n, m;
  while (cin >> n >> m, n > 0) {
    int a, b, w;
    char s;
    dist_unionfind DU = dist_unionfind(n);
    pair<bool, int> ret;
    for (int i = 0; i < m; i++) {
      cin >> s;
      if (s == '!') {
        cin >> a >> b >> w;
        DU.unite(--a, --b, w);
      } else {
        cin >> a >> b;
        ret = DU.check(--a, --b);
        if (ret.first)
          cout << ret.second << endl;
        else
          cout << "UNKNOWN" << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 5396
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int a,b,x;
	int c=0;

	cin>>a>>b>>x;

	if(a+b<x){
		c=1;
	}
	if(a>x){
		c=1;
	}

	if(c==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}

	return 0;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;



ll A, B, C, D;

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

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

ll ans(ll num){
    if(num == 0) return 0;

    ll c = num / C;
    ll d = num / D;
    ll cd = num / lcm(C, D);
    
    return num - c - d + cd;
}


int main(){
    
    cin >> A >> B >> C >> D;
    cout << ans(B) - ans(A - 1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>

using namespace std;


//ユークリッドの互除法　a,bは最大公約数を求めたい２つの数
long long int gcd(long long int a, long long int b) {
             long long int tmp;
             long long int r = 1;
             if (b > a) {
                           tmp = a;
                           a = b;
                           b = tmp;
             }
             r = a % b;
             while (r != 0) {
 
 
                           a = b;
                           b = r;
                           r = a % b;
 
             }
             return b;
}

const long long int mod=1000000007;
int main(){
	long long int n=0;
	string str,str2="CODEFESTIVAL2016";
	cin>>str;
	for(int i=0;i<str.length();i++){
		if(str[i]=='C'&&n==0){n++;}
		if(str[i]=='F'&&n==1){n++;}
	}
	if(n==2){cout<<"Yes"<<endl;}
	else{cout<<"No"<<endl;}
}


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


def solve(S: str):
    s = S
    weather_list = ["Sunny", "Cloudy", "Rainy"]

    index = weather_list.index(s)
    if index != 2:
        print(weather_list[index + 1])
    elif index == 2:
        print(weather_list[0])

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060