akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

LL n, m;
multiset<LL, greater<LL>> ms;

int main() {
	cin >> n >> m;
	inc(i, n) {
		LL a; cin >> a;
		ms.insert(a);
	}
	
	inc(i, m) {
		LL v = * ms.begin();
		ms.erase(ms.begin());
		ms.insert(v / 2);
	}
	
	LL ans = 0;
	RF(e, ms) { ans += e; }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4992
import java.math.BigInteger;
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while(sc.hasNext()){
			String str=sc.nextLine();
			char[] c=str.toCharArray();
			for(int al=0;al<26;al++){
				for(int i=0;i<c.length;i++){
					if('a'<=c[i]&& c[i]<='z')c[i]=(char)((c[i]-'a'+1)%26+'a');
				}
				String s=String.copyValueOf(c);
				if(s.contains("the")|| s.contains("this") || s.contains("that")){
					break;
				}
			}
			ln(String.copyValueOf(c));
		}
	}

	public static String join(double[] array, String separator) {
		StringBuilder str = new StringBuilder(array[0] + "");
		for (int i = 1; i < array.length; i++) {
			str.append(separator).append(array[i] + "");
		}
		return str.toString();
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define EARTH_HANKEI 6378.1
 
int main(void) {
    double a,b,c,d;
    double ax1,ay1,ax2,ay2;
    double x1,y1,z1,x2,y2,z2;
    double cosine;
    double result;
    while(1) {
        scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
        if(a==-1 && b==-1 && c==-1 && d==-1)
			break;
        ax1=b*M_PI/180;
		ay1=a*M_PI/180;
        ax2=d*M_PI/180;
		ay2=c*M_PI/180;
        y1=cos(ay1);
		z1=sin(ay1);
        x1=y1*sin(ax1);
		y1=y1*cos(ax1);
        y2=cos(ay2);
		z2=sin(ay2);
        x2=y2*sin(ax2);
		y2=y2*cos(ax2);
        cosine=x1*x2+y1*y2+z1*z2;
        result=EARTH_HANKEI*acos(cosine);
        printf("%d\n",(int)floor(result+0.5));
    }
    return 0;
}

Measured memory_bytes: 1108
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int tp1=n;
    int tp2=m;
    string s,ss;
    for(int i=0; i<tp1; i++)
    {
        s.push_back(m+'0');
    }
    for(int i=0; i<tp2; i++)
    {
        ss.push_back(n+'0');
    }
    if(s<ss)
        cout<<s<<endl;
    else
        cout<<ss<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<ll> A(N);
  map<ll, int> amap;
  for(int i=0;i<N;++i) {
    cin>>A[i];
    amap[A[i]]++;
  }
  sort(A.begin(), A.end(), greater<ll>());
  int ans = 0;
  ll two;
  for(int i=0;i<N;++i) {
    if(amap[A[i]]==0) continue;
    for(int j=30;j>=0;--j) {
      if((A[i]&(1<<j))!=0) {
        two = (1<<(j+1));
        break;
      }
    }
    if(A[i]==two-A[i]) {
      if(amap[A[i]]>=2) {
        ans++;
        amap[A[i]] -= 2;
      }
    }
    else {
      if(amap[two-A[i]]>=1) {
        ans++;
        amap[A[i]]--;
        amap[two-A[i]]--;
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 29884
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    char c;
    REP(i, 3) {
        cin >> c;
        if (c == '1') cout << 9;
        else          cout << 1;
    }
    cout << endl;
    return 0;
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	string s;
	int a=0,b=0,c=0,d=0;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s=="AC"){
			a++;
		}
		if(s=="WA"){
			b++;
		}
		if(s=="TLE"){
			c++;
		}
		if(s=="RE"){
			d++;
		}
	}
	cout<<"AC x "<<a<<"\n";
cout<<"WA x "<<b<<"\n";
cout<<"TLE x "<<c<<"\n";
cout<<"RE x "<<d<<"\n";
	return 0;
}

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

int main() {
    int ans = 0;
    int N;
    cin >> N;
    int count = 0;
    while(N > 0) {
        int x = log10(N);
        if(x % 2 == 0) {
            ans++;
        }
        N--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3904
import fractions
a,b = map(int,input().split())

def prime_factorize(n):
	L = []
	while n % 2 == 0:
		L.append(2)
		n //= 2
	f = 3
	while f * f <= n:
		if n % f == 0:
			L.append(f)
			n //= f
		else:
			f += 2
	if n != 1:
		L.append(n)
	return L

print(len(set(prime_factorize(fractions.gcd(a,b))))+1)

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define rep(i,N) for(int i=0; i < (N); i++)
#define all(v) (v).begin(),(v).end()

int main(){
	string S;
	cin >> S;
	if (S[2]==S[3] && S[4]==S[5]) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

using namespace std;

int main (){
	
	//freopen("t.txt","r",stdin);
	int n,W ;
	long long dp[105][MAXN], v[MAXN], w[MAXN];
	
	cin>>n>>W;
	for (int i=1;i<=n;i++){
		cin>>w[i]>>v[i];
	}
	
	for (int i=1;i<=n;i++){
		for (int j=1;j<=W;j++){
			if (j>=w[i]){
				dp[i][j] = max ( dp[i-1][j], dp[i-1][j-w[i]] +v[i] );
			} 
			else  dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][W];
	/*
	for (int i=1;i<=n;i++){
		for (int j=1;j<=W;j++){
			cout<<dp[i][j] <<" ";
		}
		cout<<endl;
	}*/	
	return 0;
}

Measured memory_bytes: 82176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ans=0;
  cin >> n;
  vector<long> a(n); 
  for(long i=0;i<n;i++) cin >> a[i];
  for(long i=0;i<n;i++) {
    while(a[i]%2==0) a[i]/=2,ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

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

	int n;
	cin >> n;
	set<int> s;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		s.insert(x);
	}
	if ((int)s.size() == n) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
typedef tuple<double,ll,ll>T;
#define PI 3.14159265358979
#define MOD 1000000007

int main(){
  ll X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  vector<ll>A(X);
  vector<ll>B(Y);
  vector<ll>C(Z);
  rep(i,X){cin>>A[i];}
  rep(i,Y){cin>>B[i];}
  rep(i,Z){cin>>C[i];}
  priority_queue<ll>dai;
  rep(i,X){
    rep(j,Y){
      ll p=A[i]+B[j];
      dai.push(p);
    }
  }
  vector<ll>F;
  int g=0;
  while(!dai.empty()){
    ll q=dai.top();dai.pop();
    F.push_back(q);
    g++;
    if(g==K){break;}
  }
  priority_queue<ll>sum;
  rep(i,F.size()){
  	rep(j,Z){
      ll r=F[i]+C[j];
      sum.push(r);
    }
  }
  ll ans=0;
  rep(i,K){
  	ll s=sum.top();sum.pop();
    cout<<s<<endl;
  }  
  
}

Measured memory_bytes: 43144
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e2 + 2;
ll n,i,ans;
ll a[N], b[N], c[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,1,n + 1) cin>>a[i];
    rep(i,1,n + 1) cin>>b[i];
    rep(i,1,n) cin>>c[i];
    rep(i,1,n + 1){
        ans += b[a[i]];
        if(i > 1 && a[i - 1] + 1 == a[i])
            ans += c[a[i] - 1];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int n, n1, n2, n3;
   n1 = 0;
   n2 = 0;
   n3 = 0;
   for(int i = 0; i < 10; i++){
       cin >> n;
       if(n > n1){
           n3 = n2;
           n2 = n1;
           n1 = n;
       }
       else if(n > n2){
           n3 = n2;
           n2 = n;
       }
       else if(n > n3){
           n3 = n;
       } 
   }
   cout << n1 << endl << n2 << endl << n3 << endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;
int main(void) {
  lld n, h, p1 = 0, p2 = 0;
  cin >> n;
  vector<lld> c(n);
  for (lld i = 0; i < n; i++) {
    cin >> h;
    if (i == 0) {
      c[i] = 0;
    } else if (i == 1) {
      c[i] = abs(p1 - h);
    } else {
      c[i] = min(abs(p1 - h) + c[i - 1], abs(p2 - h) + c[i - 2]);
    }
    p2 = p1;
    p1 = h;
  }

  cout << c[n - 1] << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <atcoder/all>
using namespace std;using z=long long;int main(){z N,Q;cin>>N>>Q;atcoder::fenwick_tree<z> b(N);for(z i=0;i<N;i++){z a;cin>>a;b.add(i,a);}for(z i=0;i<Q;i++){z w,e,r;cin>>w>>e>>r;if(w)cout<<b.sum(e,r)<<endl;else b.add(e,r);}}

Measured memory_bytes: 8232
#include <iostream>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  char mp[n][m];
  for(int i = 0; n > i; i++){
    for(int j = 0; m > j; j++){
      cin>>mp[i][j];
    }
  }
  
  int ans = n*m;
  for(int i = 1; n-1 > i; i++){
    for(int j = i+1; n > j; j++){
      int tmp = 0;
      for(int k = 0; n > k; k++){
        for(int l = 0; m > l; l++){
          if(k < i){
            //white
            if(mp[k][l] != 'W')tmp++;
          }else if(k < j){
            //blue
            if(mp[k][l] != 'B')tmp++;
          }else{
            //red
            if(mp[k][l] != 'R')tmp++;
          }
        }
      }
      ans = min(ans,tmp);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3076
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    char str[105];
    int l,flg = 0;
    scanf("%s",str);
    l = strlen(str);
    for(int i = 0;i < l;i++){
       if( (i + 1) % 2 == 0){
          if(str[i] != 'L' && str[i] != 'U' && str[i] != 'D'){
            flg = 1;
          }
       }else if( (i + 1) % 2 != 0){
          if(str[i] != 'R' && str[i] != 'U' && str[i] != 'D'){
            flg = 1;
          }
       }
    }
    if(flg < 1){
       printf("Yes\n");
    }else{
       printf("No\n");
    }
    return(0);
}


Measured memory_bytes: 256
import copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *
from collections import deque


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# a_list = [0] * a
sys.setrecursionlimit(10 ** 6)

def main():
    start = time.time()

    n, x, t = get_int_multi()

    a = n // x
    if n % x != 0 :
        a += 1

    print(a * t)




    #print(ans)

    #print(time.time() - start)


if __name__ == '__main__':
    main()

Measured memory_bytes: 11080
def dfs(tree, v, tv, p, es):
    if v == tv:
        return True
    for e in tree[v]:
        if e[0] == p:
            continue
        if dfs(tree, e[0], tv, v, es):
            es.append(e[1])
            return True
    return False

def main():
    n = int(input())
    tree = [[] for i in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        tree[a].append((b, i))
        tree[b].append((a, i))
    m = int(input())
    eset = [0]*m
    for i in range(m):
        u, v = map(int, input().split())
        es = []
        dfs(tree, u-1, v-1, -1, es)
        for e in es:
            eset[i] |= 1 << e

    ans = 0
    for i in range(1 << m):
        mask = 0
        for j in range(m):
            if i >> j & 1:
                mask |= eset[j]
        white = bin(mask).count('1')
        now = 1 << (n-1-white)
        if bin(i).count('1') % 2 == 0:
            ans += now
        else:
            ans -= now
    print(ans)


main()


Measured memory_bytes: 43772
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	bool is_visited = false;
} node;
typedef struct {
	int to;
	int cost;
	P <int, int> change;
} edge;
int main( void ){
	int N, T; cin >> N >> T;
	vector <int> vec( T );
	rep( i, 0, T ){
		cin >> vec[ i ];
	}
	int sum = 0;
	rep( i, 0, T ){
		if (vec[ i ] * 2 - N > 0){
			cout << vec[ i ] * 2 - N-1 <<endl;
			return 0;
		}
	}
	cout << "0\n";
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int k, n; cin >> k >> n;
    vector<int> a(n);
    rep(i,n)  cin >> a[i];
    sort(a.begin(), a.end());
    int mx = 0;
    rep(i, n-1) {
        mx = max(mx,abs(a[i]-a[i+1]));
    }
    mx = max(mx,k-a[n-1]+a[0]);
    cout << -mx + k;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<typename F> long long discrete_binary_search(long long ok, long long ng, F is_ok) {
    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        (is_ok(mid) ? ok : ng) = mid;
    }
    return ok;
}

int N, M, K;
int A[220000], B[220000];
int Acc[220000], Bcc[220000];
signed main() {
    cin >> N >> M >> K;
    rep(i, N) { cin >> A[i]; }
    rep(i, M) { cin >> B[i]; }
    rep(i, N) { Acc[i + 1] = Acc[i] + A[i]; }
    rep(i, M) { Bcc[i + 1] = Bcc[i] + B[i]; }
    int ans = 0;
    rep(i, N + 1) {
        if (Acc[i] > K) { continue; }
        chmax(ans, i + discrete_binary_search(0, M + 1, [&](int x) {
            return Acc[i] + Bcc[x] <= K;
        }));
    }
    cout << ans << endl;

}

Measured memory_bytes: 9884
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

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

	int ret =0;
	REP(i,2){
		if(a>b){
			ret+=a;
			a--;
		}else{
			ret+= b;
			b--;
		}
	}
	println(ret);

	return 0;
}


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

using namespace std;
typedef long long ll;
int a[300001];
int b[300001];
map<int,vector<int>> ma;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int h,w,m; cin>> h >> w >> m;

    
    
    for(int i=0; i<m; i++){
        int x,y; cin>> x >> y;
        ma[x].push_back(y);    
        a[x] += 1; b[y] += 1;        
    }

    int cnt = 0;
    for(int i=1; i<=w; i++){
        cnt = max(cnt, b[i]);
    }

    int mc = 0;
    for(int i=1;i<=w;i++){
        if(cnt == b[i])mc += 1;
    }


    int ans = 0;
    for(int i=1; i<=h; i++){
        int ret= 0 ;

        for(int j=0; j<ma[i].size(); j++){
            if(b[ma[i][j]] == cnt)ret += 1;
        }

        if(ret == mc){
            ans = max(ans , a[i] + cnt - 1);
        }else{
            ans = max(ans , a[i] + cnt);
        }
    }

    cout << ans <<'\n';
    






}


Measured memory_bytes: 38824
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,m,l=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        if(c>l): continue
        a-=1; b-=1
        E[a].append((b,c))
        E[b].append((a,c))

    # 各頂点を始点としたDijkstra
    A=[None]*n
    for s in range(n):
        dist=[(INF,INF)]*n
        dist[s]=(0,0)
        visited=[0]*n
        for _ in range(n-1):
            v=min((dist[v],v) for v in range(n) if(not visited[v]))[1]
            visited[v]=1
            for nv,w in E[v]:
                a,b=dist[v]
                if(b+w<=l): na,nb=a,b+w
                else: na,nb=a+1,w
                if(dist[nv]>(na,nb)):
                    dist[nv]=(na,nb)
        A[s]=dist

    for _ in range(int(input())):
        s,t=map(int,input().split())
        s-=1; t-=1
        print(A[s][t][0] if(A[s][t][0]!=INF) else -1)
resolve()

Measured memory_bytes: 78812
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}
const int N=7;
char s[N][N];
int n,m,k;
int a[N][N],r[N],l[N],len,ans,tot,vis[N][N];
void dfs(int now)
{

    if(now>len){
        return ;
    }
    int s1=0,s2=0;
    //printf("now:%d\n",now);
    memset(vis,0,sizeof(vis));

    for(int i=0;i<n+m;++i){
        if(now&(1<<i)){
            if(i<n) {
                for(int j=1;j<=m;++j){
                    if(vis[i+1][j]) continue;
                    vis[i+1][j]=1;
                    s1+=a[i+1][j];
                }
            }
            else {
                for(int j=1;j<=n;++j){
                    if(vis[j][i-n+1]==0) s2+=a[j][i-n+1],vis[j][i-n+1]=1;
                }
            }
        }
    }
    if(tot-(s1+s2)==k) ans++;

    //printf("now:%d s1:%d s2:%d\n",now,s1,s2);
    dfs(now+1);

}
int main()
{
    n=read(),m=read(),k=read();
    rep(i,1,n) cin>>s[i]+1;
    rep(i,1,n)
    {
        rep(j,1,m){
            if(s[i][j]=='#') {
                a[i][j]=1;
                l[j]++;
                r[i]++;
                tot++;
            }
        }
    }
    //rep(i,1,n) printf("%d\n",r[i]);

   //printf("tot:%d\n",tot);

    len=(1<<(n+m))-1;

    dfs(0);
    printf("%d\n",ans);




}


Measured memory_bytes: 3684
#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
const lli MOD = 1000000007;
int a[100005];
string s;
int main()
{
    int n;
    cin >> n;
    rep(i, n) cin >> a[i];
    int ans = 0;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }

    int b = 2;
    ans = 1;
    int cnt = 0;
    while (cnt + 1 < n) {
        //cout << cnt << endl;
        if (b == 2) {
            if (a[cnt] == a[cnt + 1]) {
                cnt++;
                continue;
            }
            b = (a[cnt] > a[cnt + 1]);
            cnt++;
        } else if (b == 1) {
            if (a[cnt] >= a[cnt + 1]) {
                cnt++;
            } else {
                b = 2;
                ans++;
                cnt++;
                continue;
            }
        } else if (b == 0) {
            if (a[cnt] <= a[cnt + 1]) {
                cnt++;
            } else {
                b = 2;
                ans++;
                cnt++;
                continue;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
# coding: utf-8
# Your code here!
bef = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
aft = "DEFGHIJKLMNOPQRSTUVWXYZABC"

s = list(input())
for i in range(len(s)):
   for j in range(len(aft)):
      if s[i] == aft[j]:
         #print("@", aft[j], bef[j])
         s[i] = bef[j]
         print(s[i], end = "")
         break
print("")



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

lst_1 = input().split()
T = float(lst_1[0])
A = float(lst_1[1])

lst_A = input().split()

tem_dif_min = 99999999.0


for i in range(N):

    tem_dif = abs(A - (T - float(lst_A[i]) * 0.006))

    if tem_dif < tem_dif_min:

        tem_dif_min = tem_dif
        ans = i + 1


print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int num_bottun;
  	cin >> num_bottun;
  	int to;
	vector<int> mto(num_bottun);
  	for(int i = 0; i < num_bottun;i++){
    	cin >> mto.at(i);
    }
  	
  	int from = 0;
  	
  	for(int i = 0;i < num_bottun;i++){
    	from = mto.at(from)-1;
      	if(from == 1){
        	cout << i+1 << endl;
          	return 0;
        }
    }
  	cout << -1 << endl;
}

Measured memory_bytes: 640
program main
      implicit none
      integer(8) :: x, i, j, cnt

      read *, x
      cnt = 1
      i = 100
      do
        i = i + i/100
        if ( i >= x ) then
          print *, cnt
          stop
        else
          cnt = cnt + 1
        end if
      end do

end program main


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

int main()
{
	char S[10001];
	int i, N;

	scanf("%d", &N);
	scanf("%s", S);
	for(i = 0; i < strlen(S); i++)
		S[i] = 'A' + ((S[i] - 'A' + N) % 26);

	printf("%s\n", S);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#include <map>
#include <climits>
#include <vector>
#include <set>
#include <string>
#include <numeric>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define flood(arr, c, size) for (int i=0; i<size; i++) arr[i] = c
//#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
const int N = 1e5 + 2;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;
int a[N], vis[N];
int cnt;

int solve(int x) {
    if (vis[x] == 1) return -1;
    if (x == 1) {
        cnt++;
        cout << cnt;
        exit(0);
    }
    vis[x] = 1;
    cnt++;
    return solve(a[x]);
}

int32_t main() {
    FAST_IO;
    int n;
    cin >> n;
    flood(vis, 0, N);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    cnt = 0;
    vis[0] = 1;
    cout << solve(a[0]);
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

		long x=sc.nextLong();
		long y=sc.nextLong();

		if(y==0) {
			if(x==0) {
				System.out.println(0);
			}
			else if(x<0) {
				System.out.println(Math.abs(x));
			}
			else if(x>0) {
				System.out.println(Math.abs(x)+1);
			}
		}
		else if(x==0) {
			if(y==0) {
				System.out.println(0);
			}

			else if(y<0) {
				System.out.println(Math.abs(y)+1);
			}
			else if(y>0) {
				System.out.println(Math.abs(y));
			}
		}
		else {
			if(x<0 && y<0) {
				if(x<=y) {
					System.out.println(y-x);
				}
				else if(x>y) {
					System.out.println(x-y+2);
				}
			}

			else if(x>0 && y<0) {
				if(x>=(y*-1)) {
					System.out.println(x+y+1);
				}

				else if(x<(y*-1)) {
					System.out.println(-x-y+1);
				}
			}

			else if(x<0 && y>0) {
				if(-x<=y) {
					System.out.println(Math.min(y-x, y+x+1));
				}

				else if(-x>y) {
					System.out.println(Math.min(y-x, -x-y+1));
				}
			}

			else if(x>0 && y>0) {
				if(x<=y) {
					System.out.println(y-x);
				}

				else if(x>y) {
					System.out.println(x-y+2);
				}
			}
		}
	}
}

Measured memory_bytes: 23636
#include "bits/stdc++.h"
using namespace std;

#define say(obj) (cout << obj << endl)
#define endline (cout << endl)
#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to, cost;
	edge_(ll to, ll cost) : to(to), cost(cost) {}
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr int		INF = (int)1e7;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template <typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template <typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template <typename T>
ostream& operator << (ostream& os, const vector<vector<T>>& mat) {
	for (const vector<T>& m : mat) os << m << endl;
	return os;
}

template <typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template <typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template <typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	int K, T;
	cin >> K >> T;
	vi a(T);
	cin >> a;
	sort(all(a), greater<int>());

	say(max(a[0] - 1 - (K - a[0]), 0));

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int sq(int n)
{
    int t=sqrt(n);
    if(t*t==n)
    {
        return 1;
    }
    else
    {
        return 0;

    }
}
int main()
{
    int i,j,k=0;
    char a[10],b[5];
    cin>>a>>b;
    strcat(a,b);//cout<<a<<endl;

    int ara[strlen(a)];
    for(i=0;i<strlen(a);i++)
    {
        ara[i]=a[i]-'0';
    }

    for(i=strlen(a)-1,j=1;i>=0;i--)
    {
       k=k+ara[i]*j;
       j*=10;
    }
    //cout<<k;
    if(sq(k)==1)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int x;
    int a;
    int b;
    scanf("%d %d %d",&x,&a,&b);
    if(abs(b-x)>abs(a-x))
    {
        printf("A");
    }
    else
    {
        printf("B");
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,cnt;
set <ll> se;
int main()
{
    se.insert(0);
    se.insert(1000000010);
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a;
        if(*se.lower_bound(a)==a)
        {
            cout<<"NO"<<endl;
            break;
        }
        else
        {
            se.insert(a);
            cnt++;
        }
    }
    if(cnt==n)
    {
        cout<<"YES"<<endl;
    }
}


Measured memory_bytes: 9600
n = int(input())
p = input().split()
count = 0
for i in range(0,n):
    p[i] = int(p[i])

for i in range(0,n-2):
    p1 = p[i]
    p2 = p[i+1]
    p3 = p[i+2]
    
    if not(p1>p2 and p3>p2):
        if not(p1<p2 and p3<p2):
            count += 1
print(count)   

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

const ll MAX = 1000000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  // 前処理
  COMinit();
  
  ll X,Y;
  cin >> X >> Y;
  if ( (X+Y) % 3 != 0 ) {
    cout << "0" << endl;
    return 0;
  }
  ll cnt = (X+Y) / 3;
  X -= cnt;
  Y -= cnt;
  if ( (X < 0) || ( Y < 0) ) {
    cout << "0" << endl;
    return 0;
  }

  cout << COM(X+Y,Y) << endl;
}


Measured memory_bytes: 23808
#include "bits/stdc++.h"
using namespace std;

const int maxn = 3000;
double a[maxn];
double dp[maxn];

int main(int argc, char const *argv[])
{
//	freopen("in.txt", "r", stdin);
	int n;
	cin >> n; 
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	dp[0] = 1; 
	for(int i=0; i<n; i++){
		for(int coins = i+1; coins >= 0; coins--){
			dp[coins] = (coins == 0 ? 0 : dp[coins-1]*a[i]) + dp[coins]*(1 - a[i]);
		}
	}
	double ans = 0;
	for(int h = 1; h <= n; h++){
		int t = n - h; 
		if(h > t){
			ans += dp[h];
		}
	}
	printf("%.10lf\n", ans);

	return 0;
}

Measured memory_bytes: 512
k = int(input())

l = []
for i in range(17):
    ten = 10**i
    for j in range(1,1000):
        a = ten
        b = j
        n = a*b-1
        if n == 0:
            continue
        s = sum(map(int,str(n)))
        l.append([n/s,n])
l.sort()
now = 0
count = 0
i = 0
while count < k:
    if l[i][1] > now:
        now = l[i][1]
        count += 1
        print(l[i][1])
    i += 1

Measured memory_bytes: 5868
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <random>
#include <fstream>
#include <string>
#include <tuple>
#include <deque>

#define REP(i, N) for(int i = 0; i< N; i++)
using namespace std;
#define ll long long
const int INF = 1 << 29;
const ll llINF = 1 << 50;

const int MOD = 1000000007;


int dp[20][1010];
int p[20];
int c[20];
int allgreen(){
    int D, G;
    cin >> D >> G;
    G /= 100;
    int mondaisuu = 0;
    REP(i, D){
        int cc;
        cin >> p[i] >> cc;
        c[i] = cc / 100;
    }
    
    REP(i, D){
        REP(j, p[i]){
            mondaisuu ++;
            for(int k = mondaisuu; k > j; k --){
                int bonasu = 0;
                if(j + 1 == p[i]){bonasu = c[i];}
                dp[i + 1][k] = max(dp[i][k], dp[i][k - j - 1] + (i + 1) * (j + 1) + bonasu);
            }
        }
    }
    int saishoumondaisuu = 0;
    REP(i, mondaisuu + 1){
        if(dp[D][i] >= G){
            saishoumondaisuu = i;
            break;
        }
    }
    
    return saishoumondaisuu;
}

int main(){
    
    
   /* char S[20];
    int i = 0;
    bool mitasu = true;
    while((S[i] = getchar()) != '\n'){
        i++;
    }
    
    if(S[0] != 'A')mitasu = false;
    bool is_C = false;
    for(int j = 2; j < i - 1; j++){
        if(S[j] == 'C'){
            is_C = true;
            S[j] = 'c';
            break;
        }
    }
    if(!is_C)mitasu = false;
    bool komoji = true;
    for(int j = 1;j < i; j++){
        if(S[j] >= 'a' && S[j] <= 'z'){
        }else{
            komoji = false;
            break;
        }
    }
    if(!komoji)mitasu = false;
    if(mitasu)printf("AC\n");
    else {printf("WA\n");}
    */
    printf("%d\n", allgreen());
}


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

using namespace std;

int main() {
  int n, d, ans = 0;
  cin >> n >> d;
  int i = 1 + d;
  while (i <= n) {
    ans++;
    int x = i + (2 * d + 1);
    int y = i + d + 1;
    if (x <= n) {
      i = x;
    } else if (y <= n) {
      i = y;
    } else {
      break;
    }
  }
  if (!ans) ans++;
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
//ll const mod=998244353;
ll const mod = 1e9 + 7;
const ll MAX = 1000005;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }

vector<tuple<int, int, int, int>>v;
int ans = 0;
int n, m;
void dfs(vi s) {
    if (s.size() == n + 1) {
        int res = 0;
        int a, b, c, d;
        for (auto x : v) {
            tie(a, b, c, d) = x;
            if (s[b] - s[a] == c)res += d;
        }
        chmax(ans, res);
        return;
    }

    while (s.back() <= m) {
        s.push_back(s.back());
        dfs(s);
        s.pop_back();
        s.back()++;
    }

}

int main() {
    int q;
    cin >> n >> m >> q;
    v.resize(q);
    rep(i, q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--;
        v[i] = tie(a, b, c, d);
    }
    vi s;
    s.push_back(1);
    dfs(s);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const int INF=1e9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
ll w,weight[110],value[110];
ll dp[110][100100]={};


int main(int argc, char const *argv[]) {
  std::cin >> n >> w;
  rep(i,n) std::cin >> weight[i] >> value[i];

  for(int i=0; i<n; i++){
    for(int sum_w=0; sum_w<=w; sum_w++ ){
      if(sum_w-weight[i]>=0) chmax(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i]);
      chmax(dp[i+1][sum_w],dp[i][sum_w]);
    }
  }

  std::cout << dp[n][w] << '\n';

  return 0;
}


Measured memory_bytes: 79360
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

T = int(input())

for _ in range(T):
    A, B, C, D = map(int, input().split())

    if B > A:
        print('No')
    elif B > D:
        print('No')
    elif C >= B:
        print('Yes')
    elif A % B > C:
        print('No')
    else:
        s = A % B
        g = gcd(B, D)
        if s + (B-1-s)//g*g > C:
            print('No')
        else:
            print('Yes')


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n),b(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i) >>b.at(i);
    }
    long long c,s = 0,p = 0;
    int x;
    vector<pair<long long,long long>> ab(n);

    for(int i = 0;i < n;i ++){
        ab.at(i) = make_pair(a.at(i),b.at(i));
    }

        sort (ab.begin(),ab.end());
    int i = 0;
    while(s < m){
        s += ab.at(i).second;
        p += ab.at(i).first * ab.at(i).second;
        i ++;
    }
    
    p -= ab.at(i-1).first * (s-m);

    cout << p << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <map>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

const int MOD = 1000000007;

int main(){
  // int a, b, c, d;
  // cin >> a >> b >> c >> d;
  string s;
  cin >> s;
  int a, b, c, d;
  a = s[0] - '0';
  b = s[1] - '0';
  c = s[2] - '0';
  d = s[3] - '0';
  if(a+b+c+d == 7){
    cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
  }else if(a+b+c-d == 7){
    cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
  }else if(a+b-c+d == 7){
    cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
  }else if(a-b+c+d == 7){
    cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
  }else if(a+b-c-d == 7){
    cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
  }else if(a-b+c-d == 7){
    cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
  }else if(a-b-c+d == 7){
    cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
  }else if(a-b-c-d == 7){
    cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
  }
}



Measured memory_bytes: 256
N = int(input())
A = []
for i in range(N):
    a = input()
    b = a.split(".")
    if len(b)==1:
        A.append(int(a)*(10**9))
    else:
        A.append(int(b[0] + b[1] + (9-len(b[1]))*"0"))

B = [[0]*50 for i in range(50)]
ans1 = 0
for i in range(N):
    a = A[i]
    count1 = 0
    while a%2==0:
        a//=2
        count1+=1
    count2 = 0
    while a%5==0:
        a//=5
        count2+=1
    #print(count1,count2,A[i])
    B[count1][count2] += 1
    if count1>=9 and count2>=9:
        ans1+=1

C = [[0]*51 for i in range(51)]

for i in range(50):
    for j in range(50):
        C[i+1][j+1] = B[i][j] + C[i+1][j] + C[i][j+1] - C[i][j]

#print(*C,sep="\n")
ans = 0
for i in range(50):
    for j in range(50):
        k,l = min(18,i),min(18,j)
        #if B[i][j]>0:
        #    print(B[i][j],C[21][21] + C[18-k][18-l] - C[21][18-l] - C[18-k][21],i,j)
        ans += B[i][j] * (C[50][50] + C[18-k][18-l] - C[50][18-l] - C[18-k][50])

print((ans-ans1)//2)


Measured memory_bytes: 87908
# include <bits/stdc++.h>
using namespace std;
# define int long long
# define ll long long
const int MAXN=2e6+1;

int read()
{
	int s=0,w=1;
	char ch;
	ch=getchar();
	while (ch<'0' || ch>'9'){
		if (ch=='-'){
		   w=-1;
		}
		ch=getchar();
	}
	while (ch>='0' && ch<='9'){
		s=s*10+ch-'0';
		ch=getchar();
	}
	return s*w;
}

ll n,a[MAXN],r[MAXN],l[MAXN],stac[MAXN],top,ans;

signed main()
{
	n=read();
	for (int i=1;i<=n;i++){
		a[i]=read();
	}
	for (int i=1;i<=n;i++){
		l[i]=0;
		r[i]=n+1;
	}
	for (int i=1;i<=n;i++){
		while (top && a[stac[top]]>a[i]){
			r[stac[top--]]=i;
		}
		l[i]=stac[top];
		stac[++top]=i;
	}
	for (int i=1;i<=n;i++){
		ans+=1ll*(r[i]-i)*(i-l[i])*a[i];
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 14080
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextInt();
        var W = sc.ArrayInt(N);
        var ans = new List<int>();
        for (int t = 1; t < N; t++) {
            var s1 = 0;
            var s2 = 0;
            for (int i = 0; i < N; i++) {
                
                if (i+1 <= t) {
                    s1 += W[i];
                } else {
                    s2 += W[i];
                }

            }
            ans.Add(Math.Abs(s1 - s2));
        }

        WriteLine(ans.Min());
    }
}


class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13268