akhauriyash/Code-Regression huggingface dataset:
//بسم الله الرحمن الرحيم
// In the name of Allah.
//Ya ALLAH,  We're nothing and you're everything.

#include <bits/stdc++.h>
#define FF(x,z,y) for(long long x=z;x<y;x++)
#define FB(x,y,z) for(long long x=y;x>z;x--)
#define asc(x) x.begin(),x.end()
#define dsc(x) x.begin(),x.end(),greater<>()
#define pb(x) push_back(x)
#define mxll   LONG_LONG_MAX
#define mnll   LONG_LONG_MIN
#define mxi INT_MAX
#define mni  INT_MIN
#define NL cout<<endl;

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<long long> vll;
typedef vector<int> vin;
typedef vector<vll> vllll;
typedef vector<bool> vebu;
typedef vector<vebu> vebubu;
typedef vector<string> VS;
typedef set <long long> sl;
typedef map<long long,long long> mpl;
typedef map<ll,ll,greater <ll> > mp_des;
//typedef MII::iterator iMII;

//direc     d  u   r  l
int fx4[]={+1,-1,+0,+0};
int fy4[]={+0,+0,+1,-1};
//direc    l  r   d  u  tr br tl bl
int fx8[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy8[]={-1,+1,+0,+0,+1,+1,-1,-1};
const int mxx = 1e5+1;
void  cal(){
      ll a,b,c,d;
      cin>>a>>b>>c>>d;
      ll r1 = a*c;
      ll r2 = a*d;
      ll r3 = b*c;
      ll r4 = b*d;
      cout<<max(r1,max(r2,max(r3,r4)))<<endl;
 }
void solve(){
    ll t=1;
   // cin>>t;
    while(t--)cal();
}
//#define ALLAHU_KHALIQ 1
int main(){
  solve();

        return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (4 * m * a[i] >= sum) {
      cnt++;
    }
  }
  string res;
  if (cnt >= m) {
    res = "Yes";
  } else {
    res = "No";
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<limits>
#include<queue>
#include<tuple>

using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)

template<typename T>
struct Edge{
  int to;
  T cost;
};

template<typename T>
vector<T> dijkstra(vector<vector<Edge<T>>> &g, int s){
  const auto inf=numeric_limits<T>::max();
  vector<T> dist(g.size(), inf);
  dist[s]=0;
  priority_queue<pair<T, int>> q;
  q.push({-dist[s], s});
  while(q.size()>0){
    T cost; int u;
    tie(cost, u)=q.top(); q.pop();
    cost*=-1;
    for(auto e: g[u]){
      if(cost+e.cost<dist[e.to]){
        dist[e.to]=cost+e.cost;
        q.push({-dist[e.to], e.to});
      }
    }
  }
  return dist;
}

int main(){

  int n, m, s; cin>> n>> m>> s;
  using edge=Edge<int>;
  vector<vector<edge>> g(n);
  rep(_, m){
    int a, b, c; cin>> a>> b>> c;
    g[a].push_back(edge{b, c});
  }

  auto dist=dijkstra(g, s);
  for(auto d: dist){
    if(d==numeric_limits<int>::max()) cout<< "INF"<< endl;
    else cout<< d<< endl;
  }

  return 0;
}



Measured memory_bytes: 12948
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
mod = 10**9+7
ans = 1
for i in range(1, N+1):
    ans *= i
    ans %= mod
print(ans)

Measured memory_bytes: 62628
s = input()
ans = 0
U = [0 for i in range(2019)]
mod = 2019
sum_i_to_n = 0
for i in range(len(s)-1,-1,-1):
    sum_i_to_n += int(s[i])* pow(10,len(s)-i-1,mod)
    sum_i_to_n %= mod
    if sum_i_to_n % mod == 0:
        ans += 1
    ans += U[sum_i_to_n]
    U[sum_i_to_n] += 1
print(ans)


Measured memory_bytes: 68752
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

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; }

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

void solve() {
    ll n, k; cin >> n >> k;
    ll ans = 0;
    Rep(b, k+1, n){  // N = pb + r (0 <= r < b)
        ll p, r;
        p = (n+1)/b;
        r = (n+1)%b;
        ans += p*(b-k) + max(0LL, r-k);
    }
    if(k == 0) ans -= n;
    cout << ans << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;




int main() {
    char s[100005],t[100005];
    int q;
    scanf("%s %s",s,t);
    int ss[100005],tt[100005];
    ss[0]=0;
    tt[0]=0;
    for(int i=0;i<=100005-1;i++){
        if(s[i]=='A')ss[i+1]=ss[i]+1;
        else ss[i+1]=ss[i]+2;
    }
    for(int i=0;i<=100005-1;i++){
        if(t[i]=='A')tt[i+1]=tt[i]+1;
        else tt[i+1]=tt[i]+2;
    }
    
    scanf("%d",&q);
    for(int i=1;i<=q;i++){
        int a,b,c,d;
        scanf("%d %d %d %d",&a,&b,&c,&d);
        if(((ss[b]-ss[a-1])-(tt[d]-tt[c-1]))%3==0)printf("YES\n");
        else printf("NO\n");
    }
    
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int a,b;
  cin >> a >> b;
  long long int t;  
  long long int x,y;
  x = max(a,b);
  y = min(a,b);
  while (true){
    if(x%y == 0) {
      t=y;
      break;
    }
    else {
      x = x%y;
      swap(x,y);
    }
  }
  long long int ans=1;
  for(long long int i=2; i*i<=t; i++){
    if(t%i == 0){
      ans++;
      while(t%i==0){
        t = t/i;
      }
    }
  }
  if(t != 1) ans++;
  cout << ans;
}


Measured memory_bytes: 256
import collections
n = int(input())
tmp = []
for i in range(n):
    s = list(str(input()))
    s.sort()
    tmpstr = "".join(s)
    tmp.append(tmpstr)
ans = 0
c = collections.Counter(tmp)
for i in c.keys():
    if c[i] >= 2:
        ans += (c[i]  - 1 )*(c[i] )//2
print(ans)

Measured memory_bytes: 19732
// ALPC-D.cpp
// MaxFlow

#include <iostream>
#include <atcoder/maxflow.hpp>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    rep(i, n) {
        cin >> s.at(i);
    }
    mf_graph<int> g(n* m + 2); // MaxFlow Graph
    int start = n * m; // start
    int goal = n * m + 1; // goal
    // start -> 偶数頂点 奇数頂点 -> goal
    rep(i, n) {
        rep(j, m) {
            if (s.at(i).at(j) == '#') continue;
            int v = i * m + j; // vertex頂点
            if ((i + j) % 2 == 0) {
                g.add_edge(start, v, 1); // 偶数頂点
            }else{
                g.add_edge(v, goal, 1); // 奇数頂点
            }
        }
    }
    // 偶数頂点 -> 奇数頂点を連結する
    rep(i, n) {
        rep(j, m) {
            if ((i + j) % 2 == 1 || s.at(i).at(j) == '#') continue;
            int v0 = i * m + j;
            if (i > 0 && s.at(i).at(j) == '.') {
                int v1 = (i - 1) * m + j;
                g.add_edge(v0, v1, 1);
            }
            if (j > 0 && s.at(i).at(j - 1) == '.') {
                int v1 = i * m + (j - 1);
                g.add_edge(v0, v1, 1);
            }
            if (i + 1 < n && s.at(i + 1).at(j) == '.') {
                int v1 = (i + 1) * m + j;
                g.add_edge(v0, v1, 1);
            }
            if (j + 1 < m && s.at(i).at(j + 1) == '.') {
                int v1 = i * m + (j + 1);
                g.add_edge(v0, v1, 1);
            }
        }
    }
    cout << g.flow(start, goal) << endl;

    auto edges = g.edges();
    for (auto x : edges) {
        if (x.from == start || x.to == goal || x.flow == 0)continue;
        int i0 = x.from / m;
        int j0 = x.from % m;
        int i1 = x.to / m;
        int j1 = x.to % m;
        if (i0 == i1 + 1) {
            s.at(i1).at(j1) = 'v';
            s.at(i0).at(j0) = '^';
        }
        else if(j0==j1+1){
            s.at(i1).at(j1) = '>';
            s.at(i0).at(j0) = '<';
        }
        else if (i0 == i1 - 1) {
            s.at(i1).at(j1) = '^';
            s.at(i0).at(j0) = 'v';
        }
        else {
            s.at(i1).at(j1) = '<';
            s.at(i0).at(j0) = '>';
        }
    }
    rep(i, n) {
        cout << s.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 5240
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;


public class Main {
	static int N, M;
	static ArrayList<Integer[]> Sink;
	static ArrayList<Integer[]> Bridge;
	
	static int[] uf;
	
	static private void union(int a, int b)
	{
		if(uf[a] == uf[b]) return;
		
		if(uf[a] < uf[b])
		{
			int modify = uf[b];
			for (int i = 1; i <= N; i++) {
				if(uf[i] == modify) uf[i] = uf[a];
			}
		}
		else {
			int modify = uf[a];
			for (int i = 1; i <= N; i++) {
				if(uf[i] == modify) uf[i] = uf[b];
			}
		}
	}
	
	static private void solve()
	{
		uf = new int[N+1];
		for (int i = 1; i <= N; i++) {
			uf[i] = i;
		}
		
		boolean init = true;
		HashSet<Integer> hs = new HashSet<Integer>();
		for (int i = 0; i < N; i++) {
			
			Integer[] island = Sink.get(i);
			hs.add(island[0]);
			
			for (int j = i+1; j < N; j++) {
				Integer[] tmp = Sink.get(j);
				if(tmp[1].intValue() == island[1].intValue())
				{
					hs.add(tmp[0]);
					i++;
				}
				else {
					break;
				}
			}
			
			if(init)
			{
				for (int j = 1; j <= N; j++) {
					uf[j] = j;
				}
				
				for (Integer[] b : Bridge) {
					b[3] = 0;
				}
			}
			
			for (Integer[] b : Bridge) {
				if(b[3].intValue() == 1) continue;
				if(!hs.contains(b[0]) || !hs.contains(b[1])) continue;
				if(uf[b[0]] == uf[b[1]]) continue;
				
				b[3] = 1;
				union(b[0], b[1]);
			}
			
			int index = -1;
			boolean preinit = false;
			for (Integer tmp : hs) {
				if(index < 0)
				{
					index = uf[tmp];
				}
				
				if(index != uf[tmp]) preinit = true;
			}
			init = preinit;
			
			//System.err.println("break");
		}
		
		int index = uf[1];
		for (int i = 2; i <= N; i++) {
			if(uf[i] != index)
			{
				System.out.println("0");
				return;
			}
		}
		
		int cost = 0;
		for (Integer[] i : Bridge) {
			if(i[3] == 1) cost += i[2];
		}
		
		System.out.println(cost);
	}
	
	static public void main(String[] args)
	{
		Scanner sca = new Scanner(System.in);
		
		while(true)
		{
			
			N = sca.nextInt();
			M = sca.nextInt();
			if(N == 0) break;
			
			Sink = new ArrayList<Integer[]>();
			for (int i = 0; i < N; i++) {
				Sink.add(new Integer[]{i+1, sca.nextInt()});
			}
			
			Collections.sort(Sink, new Comparator<Integer[]>() {
				public int compare(Integer[] a, Integer[] b) {
					int t = a[1] - b[1];
					if(t > 0) return -1;
					else if(t == 0) return 0;
					else return 1;
				}
			});
			
			Bridge = new ArrayList<Integer[]>();
			for (int i = 0; i < M; i++) {
				Bridge.add(new Integer[]{sca.nextInt(), sca.nextInt(), sca.nextInt(), 0});
			}
			
			Collections.sort(Bridge, new Comparator<Integer[]>() {
				public int compare(Integer[] a, Integer[] b) {
					int t = a[2] - b[2];
					if(t > 0) return 1;
					else if(t == 0) return 0;
					else return -1;
				}
			});
			
			solve();
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int d=0;
  for(int i=0;i<n;i++){
    if(s.at(i)=='C'&&s.at(i-1)=='B'&&s.at(i-2)=='A'){
      d++;
    }
  }
  cout << d << endl;
}

Measured memory_bytes: 256
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	while (true) {
		LL n = -1, k = -1;
		cin >> n >> k;
		if (n <= 0) break;
		vector<pair<LL, LL>> v(n);
		for (LL i = 0; i < n; ++i) {
			cin >> v[i].first >> v[i].second;
		}
		sort(v.begin(), v.end());
		for (LL i = 0; i < n; ++i) {
			if (k <= v[i].second) {
				cout << v[i].first << endl;
				break;
			}
			k -= v[i].second;
		}
	}
	return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            long K = long.Parse(input[1]);
            
            var data = new long[int.Parse(Math.Pow(10, 5).ToString()) + 1];
            for(var i = 0;i < int.Parse(Math.Pow(10, 5).ToString()) + 1; i++)
            {
                data[i] = 0;
            }


            for (var i = 0; i < N; i++)
            {
                input = Console.ReadLine().Split(' ');
                int a = int.Parse(input[0]);
                int b = int.Parse(input[1]);

                data[a] = data[a] + b;
            }

            long p = 0;
            int r = 0;
            for (var i = 0; i < int.Parse(Math.Pow(10, 5).ToString()) + 1; i++)
            {
                p = p + data[i];
                if(p >= K)
                {
                    r = i;
                    break;
                }
            }

            Console.WriteLine(r);

            //Console.ReadKey();
        }
    }
}


Measured memory_bytes: 15836
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ll n;
  cin>>n;
  vector <ll> a(n+1,0);
  for(ll i=1;i<=n;i++)
  {
    cin>>a[i];
  }
  vector <ll> ans(n+1,0);
  ans[n]=a[n];
  ll flag=1;
  for(ll i=n-1;i>=1;i--)
  {
    ans[n]+=flag*a[i];
    if(flag==1)
      flag=-1;
    else
      flag=1;
  }
  ans[1]=2*a[n]-ans[n];
  for(ll i=2;i<n;i++)
  {
    ans[i]=2*a[i-1]-ans[i-1];
  }
  for(ll i=1;i<=n;i++)
  {
    cout<<ans[i]<<" ";
  }
  cout<<endl;
}




Measured memory_bytes: 2944
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
template<class T, class... U> void DEBUG(const T &head, const U &... tail) { 
#ifdef HOME
    _W('#'); _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);
#endif
}
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;

int main(){
    char s[24];
    RS(s);
    int n=LEN(s);
    int now=0;
    int an=0;
    REP(i,n){
        now+=s[i]-'0';
        an=max(an,now-1+9*(n-i-1));
    }
    an=max(an,now);
    W(an);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define loop(s, n) for(int i=s; i<n; i++)
#define rloop(s, n) for(int j=s-1; i>=n; j--)
using namespace std;

int main() {
    int n;
    cin>>n;
    int a[n], b[n], c[n], dp[n][3];
    loop(0,n)
        cin>>a[i]>>b[i]>>c[i];
    dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];
    loop(1,n){
        dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][1], dp[i-1][0]);
    }
    cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});

    return 0;
}


Measured memory_bytes: 5964
S = input()

N = len(S) + 1
L = []
counter = 0

for n in range(N-2):
    counter += 1
    if S[n]!=S[n+1]:
        L.append(counter)
        counter = 0
            
L.append(counter+1)

if S[0]=='<':
    K = len(L)//2
    for k in range(K):
        if L[2*k] <= L[2*k+1]:
            L[2*k] -= 1
        else:
            L[2*k+1] -= 1

else:
    K = (len(L)-1)//2
    for k in range(K):
        if L[2*k+1] <= L[2*k+2]:
            L[2*k+1] -= 1
        else:
            L[2*k+2] -= 1
        
print(sum([l*(l+1)//2 for l in L]))

Measured memory_bytes: 8224
A,B,M = map(int, input().split())

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

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

d = [list(map(int, input().split())) for i in range(M)]

z=[0]*M

p=min(a)+min(b)

for i in range(M):
    z[i]=a[d[i][0]-1]+b[d[i][1]-1]-d[i][2]

q=min(z)


print(min(p,q))


Measured memory_bytes: 42412
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int N;
  std::cin >> N;
  std::vector<int> W(N);
  for (int i = 0; i < N; ++i)
    std::cin >> W[i];

  // Main
  std::vector<int> lSum(N + 1, 0);
  for (int i = 0; i < N; ++i)
    lSum[i + 1] = lSum[i] + W[i];

  int sum = 0;
  for (auto v : W)
    sum += v;

  int res = IINF;
  for (int r = 0; r <= N; ++r)
    chmin(res, std::abs(lSum[r] - (sum - lSum[r])));

  std::cout << res << std::endl;

// // Construct cumulative sum
// std::vector<int> sum(ARRAY_SIZE + 1, 0);
// for (int i = 0; i < ARRAY_SIZE; ++i)
//   sum[i + 1] = sum[i] + ARRAY[i];

// // Query for [left, right)
// int tmp = sum[left] - sum[right];


  // Output

  return 0;
}


Measured memory_bytes: 256
# a〜z
l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

# 入力
w=input()

for x in l:
  if w.count(x)%2!=0:
    print('No')
    exit()

# 出力
print('Yes')

Measured memory_bytes: 3060
A,B,C,X,Y=map(int,input().split())
n=max(X,Y)
a=A*X+B*Y
for i in range(1,n+1):
    t=2*C*i
    if X-i>0:
        t+=(X-i)*A
    if Y-i>0:
        t+=(Y-i)*B
    a=min(a,t)
print(a)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
B - 754

"""
import sys

def solve(s):
    return min([abs(int(a + b + c) - 753) for a, b, c in zip(s, s[1:], s[2:])])


def main(args):
    s = input()
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
from collections import Counter
n,k=map(int,input().split())

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

l=len(set(A))

mycounter=Counter(A)
X=mycounter.most_common()[::-1]
cnt=0
if l<=k:
    print(0)
else:
    for i in range(l-k):
        cnt+=X[i][1]
    print(cnt)

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

#A
def A():
    a, b, c = LI()
    if a + b >= c:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    s = SR(n)
    m = II()
    t = SR(m)
    ans = 0
    for si in s:
        ans = max(ans, s.count(si) - t.count(si))
    print(ans)
    return

#C
def C():
    n = II()
    ab = LIR(n)
    cd = LIR(n)
    ab.sort()
    cd.sort()
    check = [0 for i in range(n)]
    ans = 0
    for _, c in enumerate(cd):
        d = c[1]
        c = c[0]
        maxy = -1
        x = -1
        for k, a in enumerate(ab):
            b = a[1]
            a = a[0]
            if maxy < b and c > a and check[k] == 0 and d > b:
                maxy = b
                x = k
        if x != -1:
            ans += 1
            check[x] += 1
    print(ans)


    return

#D
def D():
    N = II()
    a = LI()
    b = LI()
    ans = 0
    t = 1
    for i in range(29):
        a2 = [A & ((t << 1) - 1) for A in a]
        b2 = [B & ((t << 1) - 1) for B in b]
        a2.sort(reverse=True)
        b2.sort()
        ansb = 0
        r1 = r2 = r3 = 0
        for A in a2:
            while r1 < N and A + b2[r1] < t:
                r1 += 1
            while r2 < N and A + b2[r2] < 2*t:
                r2 += 1
            while r3 < N and A + b2[r3] < 3*t:
                r3 += 1
            ansb += r2 ^ r1 ^ N ^ r3
            ansb = ansb & 1
        ans += (ansb << i)
        t = t << 1
    print(ans)
    return

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


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

int main(){
    ll n,k;
    cin >> n >> k;
    ll res = n%k;

    cout << min(res, abs(res-k)) << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<int> a(n);
    for(auto &x:a)cin >> x;

    int even=0,odd=0;
    for(int i=0;i<n;i++){
        a[i]%2==0?even++:odd++;
    }

    int all=1;
    for(int i=0;i<n;i++){
        all*=3;
    }
    int noteven=1;
    for(int i=0;i<even;i++){
        noteven*=2;
    }

    cout << all-noteven << endl;

    return 0;
}


Measured memory_bytes: 3564
using System;
using System.Collections.Generic;

class MainClass
{
   
    public static void Main(string[] args)
    {
        var _ = LnInts();
        var N = _[0];
        var M = _[1];
        var ivoaivn = LnInts();
        var day = 0;
        for (int i = 0; i < M;i++){
            day += ivoaivn[i];
        }
        Console.WriteLine(N - day < 0 ? -1 : N - day);
    }

   
    public static int[] LnInts()
    {
        var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        var ins = new int[vs.Length];
        for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]);
        return ins;
    }

    public static int LnInt()
    {
        var vs = Console.ReadLine().Trim();
        return int.Parse(vs);
    }

    public static string[] LnStrs()
    {
        var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        return vs;
    }
    public static string LnStr()
    {
        var vs = Console.ReadLine().Trim();
        return vs;
    }
}

Measured memory_bytes: 19244
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	int n;
	cin >> n;
	if (!cin) return false;

	bool p = true;
	for (int i = 0; i < n; ++i) {
		int n;
		cin >> n;

		if (n % 2 == 0) {
			if (n % 3 == 0 || n % 5 == 0) {}
			else p = false;
		}
	}

	if (p) cout << "APPROVED\n";
	else cout << "DENIED\n";

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 256
def main():
  array = []
  
  size = int(input())
  for i in range(size):
    array.append(int(input()))
    
  array.sort(reverse=True)
  
  result = 1
  for i in range(len(array)-1):
    if array[i] != array[i+1]:
      result+=1
  
  print(result)
    
    
main()

Measured memory_bytes: 3060
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

// int MOD = 998244353;
int MOD = 1000000007;

ll dp[41][401][401] = {0};

//----------------------------------------------------------------
signed main(){

	ll n,ma,mb;
	cin >> n >> ma >> mb;
	vll a(n),b(n),c(n);
	rep(i,n)cin >> a[i] >> b[i] >> c[i];

	rep(i,n+1) rep(j,401) rep(k,401) dp[i][j][k] = INF;
	rep(i,n+1) dp[i][0][0] = 0;

	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= 400;j++){
			for(int k = 1;k <= 400;k++){
				dp[i][j][k] = dp[i-1][j][k];
				if(j-a[i-1] >= 0 && k-b[i-1] >= 0) dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j-a[i-1]][k-b[i-1]]+c[i-1]);
				//cerr << i << " " << j << " " << k << " : " << dp[i][j][k] << endl;
			}
		}
	}

	ll ans = INF;
	ll x = ma,y = mb;
	while(x <= 400 && y <= 400){
		ans = min(ans,dp[n][x][y]);
		x += ma;
		y += mb; 
	}

	if(ans == INF)cout << -1 << endl;
	else cout << ans << endl;

	
	

	return 0;
}

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

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://dp.contest.atcoder.jp/tasks/dp_a
// rm -r -f test;oj dl https://abc054.contest.atcoder.jp/tasks/abc054_d

Measured memory_bytes: 51712
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

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

long long com(long long n,long long k){
	
}
long long getDigit(long long n){
	if(n==1)return 1;
	else return log10(n)+1;
}
class G{
	long long node;
	long long w;
	
};
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	vector<pair<int,int>>G[N+1];
	for(int i=0;i<N-1;i++){
		int a,b,w;
		cin>>a>>b>>w;
		G[a].push_back(make_pair(b,w));
		G[b].push_back(make_pair(a,w));
	}
	vector<long long>dp(N+1,INF);
	stack<int>que;
	que.push(1);
	dp[1]=0;
	while(!que.empty()){
		int u=que.top();
		que.pop();
		int s=G[u].size();
		for(int i=0;i<s;i++){
			int k=G[u][i].first;
			if(dp[k]!=INF){
				continue;
			}
			dp[k]=dp[u]+G[u][i].second;
			que.push(k);
		}
	}
	for(int i=1;i<=N;i++){
		if(dp[i]%2==1)cout<<1<<endl;
		else cout<<0<<endl;
	}
}


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

int main(){

    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int N;
    int ans = 0;

    cin >> N ;

    for(int i = 1; i <= N; i++){

        int k;
        cin >> k;

        if (i % 2 && k % 2) ans++;

    }

    cout << ans;

}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <unordered_set>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
#include <boost/multiprecision/cpp_int.hpp>
#endif

#define p std::pair
#define ll long long
#define ull unsigned long long
#define pi (acos(-1))
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
constexpr ll mod=1000000000+7;

int main()
{
	int s,w;cin>>s>>w;
	if(w>=s){
cout<<"unsafe"<<endl;return 0;
	}
	cout<<"safe"<<endl;
	return 0;
}

ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}



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

int main() {
	while (true) {
		int H, W;
		cin >> H >> W;

		if (H == 0 && W == 0)	break;

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                  1000000007
#define eps         0.00000000000000001
#define endl                       '\n'

using namespace std;

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

vector<int> adj[300010];
vector<int> par(300010,-1);
vector<int> disco(300010,-1);
vector<int> finis(300010,-1);
vector<int> typ(300010,0);
vector<int> vis(300010,0);
vector<int> dis(300010,0);
vector<int> val;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int n;
    cin>>n;
    string s;
    cin>>s;
    int i=0;
    while(i<s.length()&&s[i]=='.')
    {
        i++;
    }
    while(!s.empty()&&s.back()=='#')
    {
        s.pop_back();
    }
    vector<int> bl,wh;
    bl.pb(0);
    while(i<s.length())
    {
        int cnt=0;
        while(i<s.length()&&s[i]=='#')
        {
            i++;
            cnt++;
        }
        bl.pb(cnt);
        cnt=0;
        while(i<s.length()&&s[i]=='.')
        {
            i++;
            cnt++;
        }
        wh.pb(cnt);
    }
    wh.pb(0);
    for(int i=1;i<bl.size();i++)
    {
        bl[i]=bl[i]+bl[i-1];
    }
    for(int i=(int)wh.size()-2;i>=0;i--)
    {
        wh[i]=wh[i]+wh[i+1];
    }
    int ans=inf;
    for(int i=0;i<bl.size();i++)
    {
        ans=min(ans,bl[i]+wh[i]);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 15632
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define pfd(n) printf("%d", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")

#define PI 3.1415926 

using namespace std;

int main() {
	int n;
	cin >> n;
	int a[n+1];
	int f[n+1];
	a[0] = 0;
	f[0] = 0;
	for( int i=1; i<=n; i++ ) {
		cin >> a[i];
		f[i] = 0;
	}
	f[1] = 1;
	int l = 1, d = 1, re = 0;
	while( 1 ) {
		if( l==2 ) {
			break;
		}
		l = a[l];
		f[l]++;
		re++;
//		l = a[d];
		if( f[l]>1 ) {
			re = -1;
			break;
		}
	}
	cout << re << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N, M;
    cin>> N >> M;
    int A[M];
    for(int i=0; i<M; i++)
        cin >> A[i];
        
    int sum = 0;
    for(int i=0; i<M; i++)
        sum += A[i];
    int day_to_play = N - sum;
    
    if(day_to_play >= 0)
        cout << day_to_play << endl;
    else
        cout << -1 << endl;
    
}


Measured memory_bytes: 3632
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int n = Integer.parseInt(br.readLine());
    
    long[] a = new long[n];
    
    for (int i=0; i<n; i++){
      a[i] = Long.parseLong(br.readLine());
    }
    long temp = a[0];
    for (long l : a){
      temp = gcm(temp, l);
    }
    System.out.println(temp);
  }
  
  static long gcm(long a, long b){
    return a*(b/lcm(a, b));
  }
  
  static long lcm(long a, long b){
    if (a < b){
      long temp = a;
      a = b;
      b = temp;
    }
    if (a%b==0) return b;
    else return lcm(b, a%b);
  }
}


Measured memory_bytes: 23252
n, k = map(int, input().split())
ps = list(map(int, input().split()))
cs = list(map(int, input().split()))
ps = [p-1 for p in ps]
visited = [False] * n
from collections import deque
ds = []
sums = []
for i in range(n):
    if visited[i]: continue
    q = deque([])
    q.append(i)
    s = cs[i]
    d = [i]
    while len(q) > 0:
        u = q.popleft()
        visited[u] = True
        nx = ps[u]
        if visited[nx]: continue
        d.append(nx)
        q.append(nx)
        s += cs[nx]
    sums.append(s)
    ds.append(d)

# print(ds,sums)
from itertools import accumulate
def calcmax(d,s,k,cs):
    cnt = 0
    l = len(d)
    div, rest_ = divmod(k-1, l)
    rest_ += 1
    if s > 0:
        cnt += div*s
    d2 = d*2
    c_ = [cs[j] for j in d2]
    acc = list(accumulate(c_))
    mx = - 1<<50
    if s < 0:
        for rest in range(1,l+1):
            for i in range(rest,l*2):
                c = acc[i] - acc[i-rest]
                mx = max(mx,c)
        return mx
    for rest in range(1,rest_+1):
        for i in range(rest,l*2):
            c = acc[i] - acc[i-rest]
            # print(i,rest,c,"debug")
            mx = max(mx, c)
    # print(d,cnt,mx)
    return cnt + mx

ans = -1 << 50
for d,s in zip(ds,sums):
    # print("aaa",d,s)
    c = calcmax(d,s,k,cs)
    ans = max(ans,c)
print(ans)

Measured memory_bytes: 69992
import sys
from collections import defaultdict, deque
from functools import reduce
import math

input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    count = 0
    for b in range(K+1, N+1):
        count += max((b - K), 0) * (N // b) + max(N % b - K + 1, 0)
    if K == 0:
        count = N*N
    print(count)

if __name__ == '__main__':
    main()


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

using namespace std;

const int maxn = 100000;

int a[maxn],n;

bool check(int l,int r) {
    return ((r-l)%2==0 && (a[l]!=a[r])) || ((r-l)%2==1 && (a[l]==a[r]));
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    string sex;
    cout<<0<<endl; cin>>sex; a[0] = (sex=="Male");
    if (sex == "Vacant") return 1;
    cout<<n-1<<endl; cin>>sex; a[n-1] = (sex=="Male");
    if (sex == "Vacant") return 1;
    int l,r;
    l=0; r=n-1;
    while (true) {
        int mid = (l+r)/2;
        cout<<mid<<endl; cin>>sex;
        fflush(stdout);
        a[mid] = (sex=="Male");
        if (sex == "Vacant") return 1;
        if (check(l,mid)) r=mid;
        else l=mid;
    }
}


Measured memory_bytes: 852
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  int n; cin>>n;
  bool flag = false;
  for (int i=0;i<n;i++){
      char s; cin>>s;
      if (s=='Y') flag=true;
  }
  if (flag) cout <<"Four"<<endl;
  else cout << "Three"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
	double sum=0,sum2=0,temp;
	int n;
	while(1) {
		cin >> n;
		if(n==0) break;
		sum=0.0;
		sum2=0.0;
		for(int i=0;i<n;++i) {
			cin >> temp;
			sum+=temp;
			sum2+=temp*temp;
		}
		cout << fixed << setprecision(8);
		cout << pow(sum2/(double)n - (sum/(double)n)*(sum/(double)n),0.5) << endl;
	}
	return 0;
}

Measured memory_bytes: 3396
#include <stdio.h>
#include <algorithm>

int main(void)
{
	int n;
	int mon = 100000;
	int i;
	
	scanf("%d", &n);
	
	for (i =0; i < n; i++){
		mon = mon + mon * 0.05;
		
		if (mon % 1000 > 0){
			mon -= mon % 1000;
			mon += 1000;
		}
	}
	
	printf("%d\n", mon);
	
	return (0);
}

Measured memory_bytes: 1020
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)

ng = -1
ok = 10**12 + 1

def is_ok(m):
    FF = [m//f for f in F]
    p = 0
    for i in range(len(A)):
        p += max(0, A[i] - FF[i])
    if K >= p:
        return True
    else:
        return False

while (abs(ok-ng)>1):
    mid = (ng + ok) // 2
    if is_ok(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Measured memory_bytes: 222252
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }

}

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

    rep(i, N) {
        if (A[i] * 4 * M >= sum) {
            ans += 1;
        }
    }
    yesno(ans >= M);

}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		double x = sc.nextDouble();
		double y = sc.nextDouble();
      
      if(x==0){
        if(y==0){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
      }else{
        if(y%2==0){
          if((y/2) >= x && (y/4) <= x){
            System.out.println("Yes");
          }else{
            System.out.println("No");
                  }
        }else{
          System.out.println("No");
        }
      }
		
	}
}

Measured memory_bytes: 37540
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

cnt = 0

for i in range(n):
    for j in range(i+1, n):
        if 2 * j - i < n:
            if s[i] != s[j] and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
                cnt += 1

print(r * g * b - cnt)


Measured memory_bytes: 9216
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,m;
vector<pair<int,int> >a;
main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int A,B;cin>>A>>B;
		a.push_back(make_pair(B,A));
	}
	sort(a.begin(),a.end());
	int cnt=0;
	int p=0;
	for(int i=0;i<m;i++)
	{
		if(p<a[i].second)cnt++,p=a[i].first-1;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define ll long long int
#define i(a,n) int a=n;
#define l(a,n) ll a=n;
#define d(a,n) double a=n;
#define s(a) string a;
#define c(a) ll a; cin>>a;a
#define cd(a) double a; cin>>a;
#define cs(a) string a; cin>>a;
#define ci(a) cin>>a;
#define co(a) cout<<a;
#define cos(a) cout<<a<<" ";
#define con(a) cout<<a<<endl;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define nl cout<<endl;
#define ca(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
#define f0(i,a,n) for(ll i=a;i>=n;i--)
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,a,n) for(ll i=a;i<n;i++)
#define T ll t=1; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define r return
using namespace std;

int main()
{
    fast;
    int n;
    cin>>n;
    if(n>=400 && n<=599) cout<<"8"<<endl;
    if(n>=600 && n<=799) cout<<"7"<<endl;
    if(n>=800 && n<=999) cout<<"6"<<endl;
    if(n>=1000 && n<=1199) cout<<"5"<<endl;
    if(n>=1200 && n<=1399) cout<<"4"<<endl;
    if(n>=1400 && n<=1599) cout<<"3"<<endl;
    if(n>=1600 && n<=1799) cout<<"2"<<endl;
    if(n>=1800 && n<=1999) cout<<"1"<<endl;

    return 0;
}

/*It's not who I am underneath, but what I do that defines me

MMMMMMMMMMMMMMMMMMMMM.                             MMMMMMMMMMMMMMMMMMMMM
 `MMMMMMMMMMMMMMMMMMMM           M\  /M           MMMMMMMMMMMMMMMMMMMM'
   `MMMMMMMMMMMMMMMMMMM          MMMMMM          MMMMMMMMMMMMMMMMMMM'
     MMMMMMMMMMMMMMMMMMM-_______MMMMMMMM_______-MMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
     .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM.
    MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
                   `MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
                          `MMMMMMMMMMMMMMMMMM'
                              `MMMMMMMMMM'
                                 MMMMMM 
                                  MMMM
                                   MM
*/


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    int a[100010], b[100010], c[100010];
    long long int ans = 0;
    int pre = -1000;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n-1; i++) {
        cin >> c[i];
    }

    for (int i = 0; i < n; i++) {
        ans += b[a[i]-1];
        if (pre+1 == a[i]-1) {
            ans += c[pre];
        }
        pre = a[i]-1;
    }

    cout << ans << endl;


}


Measured memory_bytes: 256
import os
import sys

def main():
    H , A = map(int , input().split())
    list = [s for s in input().split()]
    c = sum(int(i) for i in list)
    if c >= H :
        print ('Yes')
    else :
        print ('No')
    #print (str(X))

if __name__ == '__main__':
    main()

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

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n ;
	cin >> n ;

	string s ;
	map<string, int> cnt ;

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

	cout << "AC x " << cnt["AC"] << endl ;
	cout << "WA x " << cnt["WA"] << endl ;
	cout << "TLE x " << cnt["TLE"] << endl ;
	cout << "RE x " << cnt["RE"] << endl ;

	return 0;
}

Measured memory_bytes: 3660
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

type job struct {
	a int
	b int
}

type jobs []job

func (a jobs) Len() int           { return len(a) }
func (a jobs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a jobs) Less(i, j int) bool { return a[i].b < a[j].b }

func main() {
	sc.Split(bufio.ScanWords)
	
	n := scanInt()
	j := make(jobs, n)

	for i := 0; i < n; i++ {
		j[i].a, j[i].b = scanInt(),scanInt()
	}

	sort.Sort(j)

	t := 0
	f := true

	for i := 0; i < n; i++ {
		t += j[i].a
		if t > j[i].b {
			f = false
		}
	}

	if f {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


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

using namespace std;

int main(){
    long long N,A,B;
    cin >> N >> A >> B;
    if(N<A){
        cout << N << endl;
    }else if(N<A+B){
        cout << A << endl;
    }else if(A==0){
        cout << 0 << endl;
    }else{
        cout << A*(N/(A+B)) + min(A,N%(A+B))<< endl;
    }
}

Measured memory_bytes: 256
a = int(input())
flag = 0
for i in range(9):
  if (flag == 1):
    break
  elif (a == 81):
    print('Yes')
    break
  for j in range(9):
    if (a == (i+1)*(j+1)):
      print('Yes')
      flag = 1
      break
else:
  print('No')


Measured memory_bytes: 2940
<?php
fscanf(STDIN, "%d%d", $N, $K);
define("MOD", 10**9+7);
for($i = 1; $i**2 <= $N; $i++){
  $map[$i] = true;
  $map[$N/$i] = true;
}
ksort($map);
$prev = 0;
foreach($map as $k=>$_){
  $dp[1][$k] = $k - $prev;
  $prev = $k;
}
ksort($dp[1]);
for($i = 2; $i <= $K; $i++){
  $sum = 0;
  foreach($dp[$i-1] as $k => $c){
    $sum+=$c;
    $sum2[] = $sum;
  }
  foreach($dp[$i-1] as $k => $c){
    $dp[$i][$k] = array_pop($sum2)*$dp[1][$k] % MOD;
  }
}
printf("%d", array_sum($dp[$K])%MOD);


Measured memory_bytes: 475880