akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vpl vector<pair<long long,long long>>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
long long MOD = 1000000007;
const long double pi = 3.1415926535897932;
#define pb push_back
#define mp make_pair
#define mt make_tuple
using Grid = vector<vector<char>>;
#define vc vector<char>
//(mod m)でのaの逆元を計算する
//a/b(mod m)=a(mod m)*modinv(b,m)
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//UF
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N,K,L;
    cin>>N>>K>>L;
    UnionFind road(N);
    UnionFind rail(N);
    rep(i,K){
        ll a,b;
        cin>>a>>b;
        a--; b--;
        road.merge(a,b);
    }
    rep(i,L){
        ll a,b;
        cin>>a>>b;
        a--; b--;
        rail.merge(a,b);
    }
    map<pll,ll> m;
    rep(i,N){
        pll p=mp(road.root(i),rail.root(i));
        m[p]++;
    }
    rep(i,N){
        pll p=mp(road.root(i),rail.root(i));
        cout<<m[p];
        if(i==N-1)cout<<endl;
        else cout<<' ';
    }
    return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	int n,m;
	cin>>n>>m;
	
	vi v;
	for(int i=1;i*i<=m;++i){
		if(m%i==0){
			v.push_back(i);
			v.push_back(m/i);
		}
	}
	sort(all(v));
	
	auto itr=upper_bound(all(v),m/n);
	itr--;
	
	cout<<*itr<<endl;
}//refering to exp.

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

int main(){
    long long ans = 0, n;
    cin >> n;
    
    vector<int> score(40);
    int num = 1, point = 1;
    while (num < 40) {
        for (int i = 1; i <= point + 1; i++) {
            score[num] = point;
            num++;
        }
        point++;
    }
    
    for (long long i = 2; (i*i) <= n; i++) {
        int count = 0;
        while (n % i == 0 && n != 1) {
            n /= i;
            count++;
        }
        ans += score[count];
    }
    
    // -------------------------
    // 割っていった結果が素数なら1
    // -------------------------
    if (n != 1) {
        ans++;
    }
    // -------------------------
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	     //  #ifndef ONLINE_JUDGE
      //  // for getting input from input.txt
      //  freopen("input.txt", "r", stdin);
      //  // for writing output to output.txt
      //  freopen("output.txt", "w", stdout);
      // #endif
	string s;
	cin>>s;
	
	if(count(s.begin(),s.end(),s.at(0)) == 2 && count(s.begin(),s.end(),s.at(1)) == 2
		&& count(s.begin(),s.end(),s.at(2)) == 2 && count(s.begin(),s.end(),s.at(3)) == 2)
	{ cout<<"Yes"<<"\n"; return 0; }
	cout<<"No"<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans=0;
    for (int i=a; i<=b; i++){
        if (c%i ==0){
            ans++;
        }
    }
    cout << ans << endl;
}


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


int main()
{
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int x=tx-sx,y=ty-sy;
  string s;
  auto move=[&](string c,int num){
    for (int i = 0; i < num; ++i)
    {
      s+=c;
    }
  };
  move("R",x);
  move("U",y);
  move("L",x);
  move("D",y);
  s+="L";
  move("U",y+1);
  move("R",x+1);
  s+="DR";
  move("D",y+1);
  move("L",x+1);
  s+="U";
  cout<<s<<endl;
}

Measured memory_bytes: 256
H, W, A, B = gets.chomp.split.map(&:to_i)

def solve
  if (A == 0) && (B == 0)  # OK
    0.upto(H-1).each do
      print W.times.map { 0 }.join("") + "\n"
    end
    return
  end

  # OK
  if (A == 0)  # B >= 1
    0.upto(H-1).each do |h|
      if (h <= B-1)
        print W.times.map { 1 }.join("") + "\n"
      else
        print W.times.map { 0 }.join("") + "\n"
      end
    end
    return
  end
  # OK
  if (B == 0)  # A >= 1
    0.upto(H-1).each do |h|
      row = []
      0.upto(W-1).each do |w|
        if (w <= A-1)
          row << 1
        else
          row << 0
        end
      end
      print row.join("") + "\n"
    end
    return
  end

  # OK
  0.upto(H-1).each do |h|
    row = []
    0.upto(W-1).each do |w|
      if (w <= A-1) && (h <= B-1)
        row << 1
      elsif (w > A-1) && (h <= B-1)
        row << 0
      elsif (w <= A-1) && (h > B-1)
        row << 0
      else # w > A-1 && h > B-1
        row << 1
      end
    end
    print row.join("") + "\n"
  end
end

solve


Measured memory_bytes: 4988
#include<bits/stdc++.h>
#define ll long long
#define INF 1000000000ll
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;
signed main(){
  ll h,w;
  cin>>h>>w;
  if(h==1 || w==1){
    cout<<"1\n";
  }else if((h*w)%2==0){
    cout<<(h*w)/2<<"\n";
  }else{
    cout<<(h*w)/2+1<<"\n";
  }
}


Measured memory_bytes: 256
s = input()
t = input()

table = [[0 for i in range(26)] for j in range(26)]
for i in range(len(s)):
  table[ord(t[i])-ord('a')][ord(s[i])-ord('a')] += 1
for t_row in table:
  counter = 0
  for v in t_row:
    if v != 0:
      counter += 1
  if counter >= 2:
    break
else:
  for i in range(26):
    counter = 0
    for j in range(26):
      if table[j][i] != 0:
        counter += 1
    if counter >= 2:
      break
  else:
    print('Yes')
    exit(0)
print('No')

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

int main()
{
	ll k,n,ans(0),i;
	string s;
	cin>>n>>s;
	for(i=0;i<s.size()-2;i++)
	{
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
		{
			ans++;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 3584
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		String t= sc.next();
		//int n = sc.nextInt();
		//int m = sc.nextInt();
		//int k = sc.nextInt();
		long count=0;
		long count1=0;
		int[] array = new int[3];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		Arrays.sort(array);

		for(int i=0;i<3;i++) {
			if(s.substring(i,i+1).equals(t.substring(i,i+1))) {
				count++;
			}
		}

		/*if(count>2||count1>=2) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}*/

		System.out.println(count);
	}
}




Measured memory_bytes: 23124
def main():
    v = [int(input()) for _ in 5*[0]]
    ans = 0
    if v[0] < 0:
        ans += abs(v[0]) * v[2]
        v[0] = 0
    if v[0] == 0:
        ans += v[3]
    ans += abs(v[1]-v[0]) * v[4]
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 7656
#include<stdio.h>
int main()
{
	double a,b,c,d,e,f,x,y;
	while(1)
	{
	if((scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)) ==EOF) break;
	x = (c*e-f*b)/(a*e-b*d);y=(c*d-f*a)/(b*d-a*e);
	if(-0.0005<x && x<0.0005) x = 0;
	if(-0.0005<y && y<0.0005) y = 0;
	printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

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

const int INF = 1 << 30;

int N;
int h[100010];

int dp[100010];

int main() {
    cin >> N;
    for(int i = 1; i <= N; i++)
        cin >> h[i];

    // DP テーブルは無限大で初期化しておく
    for(int i = 0; i < 100010; i++)
        dp[i] = INF;

    dp[1] = 0;
    for(int i = 2; i <= N; i++) {
        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if(i - 2 >= 1) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 1024
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hopes the code can get more points.

	Algorithm: 

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define ra read_alpha()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline char read_alpha() { char c = ge; while(!isalpha(c) && c != EOF) c = ge; return c; }
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

inline int SG(int x, int k) {
	if(x < k) return 0;
	if(x % k == 0) return x / k;
	int t = x / k, p = k * t;
	int tim = (x - p - 1) / (t + 1) + 1;
	return SG(x - tim * (t + 1), k);
}

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int Xor = 0, n = ri;
	for(int i = 1; i <= n; i++) {
		int x = ri, k = ri;
		Xor ^= SG(x, k);
	} puts(Xor ? "Takahashi" : "Aoki");
	return 0;
}

Measured memory_bytes: 256
// Problem: A - Kyu in AtCoder
// Contest: AtCoder - M-SOLUTIONS Programming Contest 2020
// URL: https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define y1 y114514
#define elif else if
#define y2 y1919810
typedef pair <int, int> PII;
typedef vector <int> VI;
//#define int long long
#define all(x) x.begin(),  x.end()
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int i = 1; i <= (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define range(i, s, t)  for (int i = s; i <= (int)t; i++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
long long qread() {
    char c = getchar();
    int neg = 1;
    long long val = 0;
    while (c != '-' && !isdigit(c)) c = getchar();
    if (c == '-') c = getchar(), neg = -1;
    while (isdigit(c)) val = (val << 3) + (val << 1) + c - '0', c = getchar();
    return neg * val;
}
void solve() {
    int x = qread();
    int ans;
    if (x >= 400 && x <= 599) ans = 8;
    elif (x >= 600 && x <= 799) ans = 7;
    elif (x >= 800 && x <= 999) ans = 6;
    elif (x >= 1000 && x <= 1199) ans = 5;
    elif (x >= 1200 && x <= 1399) ans = 4;
    elif (x >= 1400 && x <= 1599) ans = 3;
    elif (x >= 1600 && x <= 1799) ans = 2;
    elif (x >= 1800 && x <= 1999) ans = 1;
    printf("%d\n", ans);
}
int main() {
    int T = 1;
    //T = qread();
    while (T--) solve();
    return 0;
}


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

using namespace std;

vector<vector<int>> edges;
vector<bool> visited;

int diameter_d = 0;
int last = 0;
void dfs(int now, int d){
    if(diameter_d < d){
        diameter_d = d;
        last = now;
    }
	int l=edges[now].size();
    for(int i=0; i<l; i++){
        if(!visited[edges[now][i]]){
            visited[edges[now][i]]=true;
            dfs(edges[now][i], d+1);
        }
    }
}



int main(){
    long N;
    cin>>N;
    int a, b;
    edges = vector<vector<int> >(N);
    for(int i=0; i<N-1; ++i){
        cin>>a>>b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }

    visited = vector<bool>(N, false);
    visited[0] = true;
    dfs(0, 0);

    diameter_d = 0;
    visited = vector<bool>(N, false);
    visited[last] = true;
    dfs(last, 0);


    if(diameter_d % 3 == 1){
        cout<<"Second"<<endl;
    }else{
        cout<<"First"<<endl;
    }

    return 0;
}


Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;

int main() {
    int m, n;
    cin >> n >> m;
    if (n == m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int inf = (int) 1e9;
const int mod = (int) 1e9 + 7;

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

template<class T>
bool chmin(T &a, const T &b) {
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	int b[n];
	rep(i, n) {
		int a;
		cin >> a;
		b[i] = a - (i + 1);
	}
	
	sort(b, b + n);
	
	if (n % 2 == 1) {
		int mid = b[n / 2];
		ll sum = 0;
		rep(i, n) sum += abs(b[i] - mid);
		cout << sum << endl;
	} else {
		int mid1 = b[n / 2 - 1];
		ll sum1 = 0;
		rep(i, n) sum1 += abs(b[i] - mid1);
		
		int mid2 = b[n / 2];
		ll sum2 = 0;
		rep(i, n) sum2 += abs(b[i] - mid2);
		
		cout << min(sum1, sum2) << endl;
	}
	
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if(a == 1)
        a = 14;
    if(b == 1)
        b = 14;
    string ans = "Draw";
    if(a > b)
        ans = "Alice";
    else if(a < b)
        ans = "Bob";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int n, b0, b = 0;
  long long ans = 0;
  cin >> n;
  cin >> b0;
  b = b0;
  ans += b0;
  for (int i = 1; i < n - 1; ++i) {
    cin >> b;
    ans += min(b0, b);
    b0 = b;
  }
  ans += b;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#include<cassert>

using namespace std;

template< typename T>
struct edge { 
   int from, to; 
   T cost; 
   edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template< typename T>
using EDGE = vector< edge< T > >;

template< typename T>
vector< T > bellman_ford(EDGE< T > &es, int V, int s) {
   const auto INF = numeric_limits< T >::max();
   vector< T > dist(V, INF);
   dist[s] = 0;
   for (int i = 0; i < V - 1; i++) {
      for (auto &e : es) {
         if (dist[e.from] == INF) continue;
         dist[e.to] = min(dist[e.to], dist[e.from] + e.cost);
      }
   }
   for (auto & e : es) {
      if (dist[e.from] == INF) continue;
      if (dist[e.from] + e.cost < dist[e.to]) return vector< T >();
   }
   return dist;
}

const int MAXN = 2501;
bool used1[MAXN];
bool used2[MAXN];
vector<int> G1[MAXN], G2[MAXN];

void bfs1(int s) {
   used1[s] = true;
   queue<int> q;
   q.push(s);
   while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (auto &g : G1[cur]) {
         if (used1[g]) continue;
         used1[g] = true;
         q.push(g);
      }
   }
}

void bfs2(int s) {
   used2[s] = true;
   queue<int> q;
   q.push(s);
   while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (auto &g : G2[cur]) {
         if (used2[g]) continue;
         used2[g] = true;
         q.push(g);
      }
   }
}

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int N, M, P;
   cin >> N >> M >> P;
   int A[M], B[M], C[M];
   for (int i = 0; i < M; i++) {
      cin >> A[i] >> B[i] >> C[i];
      A[i]--;
      B[i]--;
      C[i] = -1 * (C[i] - P);
      G1[A[i]].push_back(B[i]);
      G2[B[i]].push_back(A[i]);
   }
   memset(used1, false, sizeof(used1)); 
   memset(used2, false, sizeof(used2)); 

   bfs1(0);
   bfs2(N - 1);
   /*
   for (int i = 0; i < N; i++) {
      cout << i << " " << used1[i] << " " << used2[i] << endl;
   }
   */
   EDGE< int > edges;
   
   for (int i = 0; i < M; i++) {
      if (!used1[A[i]]) continue;
      if (!used1[B[i]]) continue;
      if (!used2[A[i]]) continue;
      if (!used2[B[i]]) continue;
      // cout << A[i] << " " << B[i] << " " << C[i] << endl;
      if (A[i] == B[i] && C[i] < 0) {
         cout << "-1" << endl;
         return 0;
      }
      edges.emplace_back(A[i], B[i], C[i]);
   }
   
   auto res = bellman_ford(edges, N, 0);
   if (res.empty()) cout << "-1" << endl;
   else {
      assert(res[N - 1] != numeric_limits<int>::max());
      cout << max(0, -1 * res[N - 1]) << endl;
   }
   return 0;
}


Measured memory_bytes: 768
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		Integer[] a = new Integer[n];
		Integer[] f = new Integer[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 0; i < n; i++) {
			f[i] = sc.nextInt();
		}

		Arrays.sort(a);
		Arrays.sort(f, Comparator.reverseOrder());

		long l = -1;
		long r = Math.max(a[n - 1], f[0]);
		r *= r;
		while (r - l > 1) {
			long m = (l + r) / 2;
			long remain = k;

			for (int i = 0; i < n; i++) {
				remain -= Math.max(a[i] - m / f[i], 0);
				if (remain < 0) break;
			}

			if (remain >= 0) {
				r = m;
			} else {
				l = m;
			}
		}

		System.out.println(r);
	}

}


Measured memory_bytes: 111288
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	time := getNextInt(scanner)

	min := 1 << 30
	ans := "TLE"
	for i := 0; i < n; i++ {
		c := getNextInt(scanner)
		t := getNextInt(scanner)
		if time < t {
			continue
		}
		if min > c {
			min = c
			ans = ""
		}
	}
	if ans == "" {
		ans = fmt.Sprintf("%d", min)
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 640
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;


// https://github.com/ADJA/algos/blob/master/DP/ConvexHullTrick.cpp

struct ConvexHullTrick {
   struct Line {
      llong m;  // m is slope
      llong b;  // b is y-intercept
      Line(int _m, llong _b) : m(_m), b(_b) {}
      llong eval(int x) const {
         return m*x + b;
      }
   };

   void add_line(int m, llong b) {
      Line nxt(m, b);
      while ( int( dq.size() ) >= 2 ) {
         Line prv = dq[ int(dq.size()) - 2 ];
         Line cur = dq[ int(dq.size()) - 1 ];
         if (relevant(prv, cur, nxt))
            break;
         dq.pop_back();
      }
      dq.push_back(nxt);
   }

   llong min(int x) {
      while ( dq.size() >= 2 ) {
         Line cur = dq[0];
         Line nxt = dq[1];
         if (nxt.eval(x) > cur.eval(x))
            break;
         dq.pop_front();
      }
      return dq[0].eval(x);
   }


private:
   deque<Line> dq;

   static bool relevant(Line prv, Line cur, Line nxt) {
      return (prv.b - nxt.b) * (cur.m - prv.m) >= 
             (prv.b - cur.b) * (nxt.m - prv.m);
   }

};

llong sqr(llong x) {
   return x*x;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int N;
   llong C;
   cin >> N >> C;
   vector<int> H(N);
   REP(i, N)
      cin >> H[i];

   ConvexHullTrick ch;

   vector<llong> DP(N);

   REP(i, N) {
      if (i > 0)
         DP[i] = C + sqr(H[i]) + ch.min( H[i] );
      ch.add_line( -2*H[i], DP[i] + sqr(H[i]) );
   }
   
   cout << DP[N-1] << '\n';

   return 0;
}


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

int main(){
  int n;
  cin>>n;
  int d[n];
  for (int i = 0; i < n; i++) {
    cin>>d[i];
  }
  sort(d,d+n);
  int ans=1;
  for (int i = 1; i < n; i++) {
    if (d[i-1]!=d[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK\n";
			return 0;
		}
	}
	cout<<"NG\n";
	return 0;
}

Measured memory_bytes: 3648
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  string s,t;  cin >> s >> t;
  sort(all(s));
  sort(all(t),greater<char>());
  if(s < t) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
if H == 1 or W == 1:
    answer = 1
elif H % 2 == 0:
    answer = H//2 * W
elif W % 2 == 0:
    answer = W//2 * H
else:
    #どちらも奇数
    #下一段を別に数える
    answer = H//2 * W
    answer += (W+1) // 2
print(answer)


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

int main() {
    int a, b;
    char op;

    for (int i = 0; i < 20000; i++) {
        cin >> a >> op >> b;
    
        if (op == '+') cout << a + b << endl;
        if (op == '-') cout << a - b << endl;
        if (op == '*') cout << a * b << endl;
        if (op == '/') cout << a / b << endl;
        if (op == '?') break;
    }
}



Measured memory_bytes: 3092
/*	ex2_3
	suzuto	*/


#include <stdio.h>

int main(void) {
  int n; int a; int sum; int black;  /*変数の宣言*/

  scanf("%d", &n);  /*一辺あたりのマス数nを入力*/
  scanf("%d", &a);  /*白に塗るマス数aを入力*/

  sum = n * n;  /*マス目の総数をsumに代入*/
  black = sum - a;  /*黒に塗るマス数をblackに代入*/

  printf("%d\n",black); /*黒に塗るマス数を出力*/

  return 0;
}


Measured memory_bytes: 128
def main():
	K,S = map(int,input().split())
	ans = 0
	ListK = [i for i in range(K+1)]
	for x in ListK:
		for y in ListK:
			if 0 <= S - (x + y) <= K:
				ans += 1
	print(ans)

if __name__ == '__main__':
	main()

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

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define VI vector<int>
#define PII pair<int, int>
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
///////////////////

const int MX = 10;
int a[MX][MX];
bool visited[MX];

int dfs(int s, int n, bool* visited){
    bool av =  true;
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(visited[i] == false){
            av = false;
            break;
        }
    }
    if(av){
        return 1;
    }

    for(int i=1;i<=n;i++){
        if(a[s][i] == 1 && visited[i] == false){
            visited[i] = true;
            ans += dfs(i,n,visited);
            visited[i] = false;
        }
    }
    return ans;
}

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

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

    visited[1] = true;
    cout << dfs(1, n, visited);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
// const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;

const long MAX = 510000;
const long 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 (long 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(long n, long 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() {long N, M;
cin >> N >> M;
// 前処理
    COMinit();
long ans = 1; long a = 2;
while(M >= a*a){
    long x = 0;
    while(M % a == 0){
        x++;
        M /= a;
    }
    ans = ans * COM(x+N-1, N-1) % MOD;
    a++;
}
if(M != 1) ans = ans * COM(1+N-1, N-1) % MOD;



show(ans);
  return 0;
 
}



Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
// const int MOD = 1e9+7;
const ll LINF = 1LL<<60;

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

const int MAXN = 2005;
const int MAXM = 2005;

mint dp0[MAXN+1][MAXM+1];
mint dp1[MAXN+1][MAXM+1];

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<int> s(n+1, 0), t(m+1, 0);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];

    dp0[0][0] = 1;
    rep(i, n + 1) {
        rep(j, m + 1) {
            dp0[i+1][j] += dp0[i][j];
            dp1[i][j] += dp0[i][j];
            dp1[i][j+1] += dp1[i][j];
            if (s[i] == t[j]) dp0[i+1][j+1] += dp1[i][j];
        }
    }

    mint ans = dp1[n][m];
    cout << ans.val << endl;
    return 0;
}

Measured memory_bytes: 63104
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int main(){
    string s,x;
    while(getline(cin,x)){
        if(x=="end")break;
        s=x;
    string a="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
    string b[]={"00000","00001","00010","00011","00100","00101","00110","00111","01000","01001","01010","01011","01100","01101","01110","01111","10000","10001","10010","10011","10100","10101","10110","10111","11000","11001","11010","11011","11100","11101","11110","11111"};
    string c=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string d[]={"101","000000","000011","10010001","010001","000001","100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
    map<string,char> mpb;
    map<char,string> mpa;
    rep(i,a.size()){
        mpb[b[i]]=a[i];
    }
    rep(i,c.size()){
        mpa[c[i]]=d[i];
    }
    
    string str="";
    rep(i,s.size()){
        str+=mpa[s[i]];
    }
    int len=str.size();
    str+=string((5-(len%5))%5,'0');
    string sx="";
    len=str.size();
    rep(i,len/5){
        sx+=mpb[str.substr(5*i,5)];
    }
    cout<<sx<<endl;
    }
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using vl = vector<long long>;
using P = pair<long long,long long>;

struct UnionFind{
	vl d;
	UnionFind(int n): d(n,-1){};
	ll root(int x){
		if(d[x] < 0)return x;
		return d[x] = root(d[x]);
	}
	bool unite(int x, int y){
		x = root(x); y = root(y);
		if(x == y)return false;
		if(d[x] > d[y])swap(x,y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x,int y){return root(x) == root(y);}
	ll size(int x){return -d[root(x)];}
};

int main(){
	ll n,m,k; cin >> n >> m >> k;
	vl ff(n,0),blo(n,0);
	UnionFind uf(n);
	rep(i,m){
		ll a,b; cin >> a >> b;
		--a; --b;
		uf.unite(a,b);
		++ff[a]; ++ff[b];
	}
	rep(i,k){
		ll c,d; cin >> c >> d;
		--c; --d;
		if(uf.same(c,d)){
			++blo[c]; ++blo[d];
		}
	}
	rep(i,n){
		cout << uf.size(i) - ff[i] - blo[i] - 1 << endl;
	}

}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
    using namespace std;
    int a[101],b[101];
    int sua[101],sub[101];
    int main()
    {
        int n;
        while(cin>>n){
            for(int i=0;i<n;i++){
                cin>>a[i];
            }
            for(int i=0;i<n;i++){
                cin>>b[i]; 
            }
            sua[0]=a[0];sub[0]=b[0];
            for(int i=1;i<n;i++)
{
                sua[i]=sua[i-1]+a[i];
                sub[i]=sub[i-1]+b[i];
            }
            int maxn=sua[0]+sub[n-1];
            for(int i=1;i<n;i++)
{
                int sum=sua[i]+sub[n-1]-sub[i-1];
                maxn=max(maxn,sum);
            }
            cout<<maxn<<endl;
        }
        return 0;
    }


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

int main() {  
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
  	cin >> a[i];
  }
  vector<int> b(n,0);
  for (int i = n-1; i >= 0; i--) {
    int sum = 0;
  	for (int j = 2*i + 1; j < n; j += i+1) {
    	sum += b[j];
    }
   if(sum % 2 == a[i]) b[i] = 0;
   else b[i] = 1;
  }
  vector<int> ans;
  for (int i = 0; i < n; i++){
  	if(b[i] == 1){
    	ans.push_back(i+1);
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
  	cout << ans[i] << ' ';
  }
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 2005
#define ba 47
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
char s[MAXN];
struct node {
    int to,next;
}E[MAXN * 2];
int head[MAXN],sumE,dis[MAXN],sum[MAXN],dp[MAXN],cnt[MAXN];
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void dfs(int u,int fa) {
    sum[u] = 0;cnt[u] = 0;
    if(s[u] == '1') {cnt[u]++;}
    int p = 0;
    for(int i = head[u] ; i; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    dis[v] = dis[u] + 1;
	    dfs(v,u);
	    if(sum[v] + cnt[v] > sum[p] + cnt[p]) p = v;
	    sum[u] += sum[v] + cnt[v];
	    cnt[u] += cnt[v];
	}
    }
    dp[u] = 0;
    int a = sum[p] + cnt[p];
    if(a <= sum[u] / 2) dp[u] = sum[u] / 2 * 2;
    else if(a - dp[p] <= (sum[u] - dp[p]) / 2) dp[u] = sum[u] / 2 * 2;
    else {
	dp[u] = (sum[u] - a) * 2 + dp[p];
    }
    
}
void Solve() {
    read(N);
    scanf("%s",s + 1);
    int a,b;
    for(int i = 1 ; i < N ; ++i) {
	read(a);read(b);
	add(a,b);add(b,a);
    }
    int ans = -1;
    for(int i = 1 ; i <= N ; ++i) {
	dis[i] = 0;
	dfs(i,0);
	if(dp[i] == sum[i]) {
	    if(ans == -1) ans = sum[i] / 2;
	    else ans = min(ans,sum[i] / 2);
	}
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}



Measured memory_bytes: 384
import sys

f = sys.stdin
res = [0]*26

for l in f:
    line = l.lower()
    for i in range(26):
        res[i]+=line.count(chr(ord('a')+i))

for i in range(26):
    c = str(chr(ord('a')+i))
    print (c+" : ",end='')
    print (res[i])




Measured memory_bytes: 5568
#include <iostream>

using namespace std;

long long u[100010], v[100010], w[100010];

int main()
{
	int n, a[100010];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	u[0] = 1;
	int mod = 1000000007;
	for (int i = 1; i <= n; i++) {
		u[i] = u[i - 1] * i;
		u[i] %= mod;
	}

	v[0] = 1;
	for (int i = 1; i < n - 1; i++) {
		v[i] = v[i - 1] * (i + 1) + u[i];
		v[i] %= mod;
	}

	w[n - 1] = 1;
	for (int i = n - 2; i >= 0; i--) {
		w[i] = w[i + 1] * (i + 1);
		w[i] %= mod;
	}

	long long ans = 0;
	long long t;
	for (int i = 0; i < n - 1; i++) {
		t = (a[i + 1] - a[i]) * w[i + 1];
		t %= mod;
		t *= v[i];
		t %= mod;
		ans += t;
		ans %= mod;
	} 
	cout << ans << endl;

	return 0;
}

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

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

  vector<int64_t> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  int64_t ans= 0;
  int64_t cummax= data.at(0);
  for(int i=0; i<N; i++){
    ans+= max(cummax- data.at(i), int64_t(0));
    cummax= max(cummax, data.at(i));
  }
  
  cout << ans << endl;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mod = 1e9 + 7;

int f[2005];

int main() {
	int S;
	scanf("%d", &S);
	f[0] = 1;
	rep(i, S) rep(j, S - i + 1) if (j >= 3) (f[i + j] += f[i]) %= mod;
	printf("%d\n", f[S]);
	return 0;
}


Measured memory_bytes: 3760
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
using namespace std;

int n;
int A[1 << 20];

ll H[1 << 20];



int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	scanf("%d", &n);
	loop(i, n+1) scanf("%d", A + i);
	
	H[n] = 0;
	for(int i = n; i > 0; i--)
		H[i-1] = H[i] + A[i];
	
	ll high = 1;
	loop(i, n+1){
		if(A[i] > high){
			cout << "-1" << endl;
			return 0;
		}
		high -= A[i];
		high = H[i] = min(H[i], high);
		high <<= 1;
	}
	
	loop(i, n) {
		ll low = H[i], high = low << 1;
		ll x = A[i+1] + H[i+1];
		assert(low <= x && x <= high);
	}

	ll ans = 0;
//	prArr(H, n+1, ll);
//	prArr(A, n+1, int);
	loop(i, n+1) ans += H[i] + A[i];
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4936
n, k = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7

n_min = sum([i for i in range(0, k-1)])
n_max = sum([n - i for i in range(0, k-1)])

for i in range(k-1, n+1):
  n_min += i
  n_max += n - i
  ans += n_max - n_min + 1
    
print(ans % mod)

Measured memory_bytes: 16964
#include<stdio.h>

int nextInt();
void sort(int *a, int size);

int N, i;
int A, B, C[100000];
long long int a, b;

int main(){
	N=nextInt();
	for(i=0; i<N; i++){
		A=nextInt();
		B=nextInt();
		C[i] = A + B;
		b += B;
	}
	sort(C, N);
	for(i=0; i<N; i+=2){
		a += C[i];
	}
	printf("%lld\n", a-b);
	return 0;
}

int nextInt(){
	int f=0; char c=getchar();
	while((c<'0')||('9'<c)){c=getchar();}
	while((c>='0')&&(c<='9')){f=f*10+(c-'0'); c=getchar();}
	return f;
}

char compare(int *x, int *y){
	return *x > *y;
}

int* med3(int *x, int *y, int *z){
	if(compare(x, y)){
		if (compare(y, z)){return y;}else if(compare(z, x)){return x;}else{return z;}
	} else {
		if (compare(z, y)){return y;}else if(compare(x, z)){return x;}else{return z;}
	}
}

void quickSort(int *left, int *right){
	if(left >= right){return;}
	int *pivot = med3(left, left+(right-left)/2, right);
	int *l=left, *r=right;
	int t;
	while(1){
		while (compare(l, pivot)){l++;}
		while (compare(pivot, r)){r--;}
		if(l>=r){break;}
		t=*l; *l=*r; *r=t;
		if(pivot == l){
			pivot = r;
		}else if(pivot == r){
			pivot = l;
		}
		l++; r--;
	}
	quickSort(left, l-1);
	quickSort(r+1, right);
}

void sort(int *a, int size){
	quickSort(a, a+size-1);
}


Measured memory_bytes: 512
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[0]*8
legend=0
for i in range(n):
    if a[i]<=3199:
        b[a[i]//400]=1
    else:
        legend+=1
if b.count(1)==0:
    print(1,legend)
elif b.count(1):
    print(b.count(1),b.count(1)+legend)

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long
typedef pair<int, int> P;

int main(){
  ll A, B, C;
  cin >> A >> B >> C;
  ll ans = 0;
  while (true) {
    if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
      break;
    }
    ll tmpa = A, tmpb = B, tmpc = C;
    A = tmpb/2 + tmpc/2;
    B = tmpa/2 + tmpc/2;
    C = tmpb/2 + tmpa/2;
    ans += 1;
    if (ans >= 1000) {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int N,M;
  int bc = 0;
  int max = -100;                                       //どうあがいても最低値
  int rc = 0;
  vector<string> gabage(0);                    //調査済みの文字列情報の保管
  bool detect = false;                              //調査済みの文字列と検索予定の文字列が一致するか
  cin >> N;
  vector<string> bCard(N);

  for(int i = 0; i < N; i++)
    cin >> bCard.at(i);                              //ここまで青のカードの情報取得

  cin >> M;
  vector<string> rCard(M);

  for(int j = 0; j < M; j++)
    cin >> rCard.at(j);                               //ここまで赤のカードの情報取得
  

  //最大値を求める問題なので、青のカードを軸に考える
  for(int i = 0; i < N; i++){
    for(int j = 0; j < gabage.size(); j++){
      if(bCard.at(i) == gabage.at(j)){               //過去に調査した文字であった
        detect = true;                                                //検知マークをtrueに
        break;         
      }
    }
    
    if(detect){                                                              //検知済みなのでbCard(i)の文字については終
      detect = false;                                                   //次に備えて検知オフ
      continue;
    }

    for(int j = i; j < N; j++){                                 //検知済みでないということはi未満のカードとは異なる
      if(bCard.at(i) == bCard.at(j))
         bc++;
    }
    for(int j = 0; j < M; j++){                              //青のカードの方で重複は除外されているので...
      if(rCard.at(j) == bCard.at(i))
        rc++;
    }
    if(max < (bc - rc) )
      max = (bc - rc);
    gabage.push_back(bCard.at(i));
    bc = rc = 0;
  }
  
  if(max < 0)                                 //max < 0が最終結果なら、どっちの群にも所属しない言葉がいい
    max = 0;                                   //もちろんそれは0
  cout << max << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,arr[100],i,sum=0,j,t,flag=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        sum=sum+arr[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(arr[i]>arr[j])
            {
                t=arr[i];arr[i]=arr[j];arr[j]=t;
            }
        }
    }
    if(sum%10==0)
    {
        for(i=0;i<n;i++)
        {
            if(arr[i]%10!=0)
            {
                flag=1;
                break;
            }
        }
        if(flag==1) sum-=arr[i];
        else sum=0;
    }
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	int n;
	cin >> n;
	map<int,int> m;
	rep(i,n){
		int a;
		cin >> a;
		m[i+1] = a;
	}
	int pos = 1,count = 0;
	while(pos != 2){

		if(count  == 100100){
			P(-1);
			return;
		}
		pos = m[pos];
		count++;

	}
	P(count);
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 4992
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 
const ll MOD = (ll)1e9 + 7 ;
int main(){
    fastio
    ll n ; 
    cin >> n ; 
    multiset<ll> ms ; 
    for(ll i=0;i<n;i++){
    	ll x ; 
    	cin >> x ; 
    	ms.insert(x) ; 
    }
    if ( n % 2 == 0 ){
    	multiset<ll> tmp ; 
    	for(ll i=1;i<n;i+=2){
    		tmp.insert(i) ;
    		tmp.insert(i) ;
    	}
    	if ( tmp != ms ){
    		return cout << 0 << endl , 0 ; 
    	}
    }
    else{
    	multiset<ll> tmp ; 
    	tmp.insert(0) ; 
    	for(ll i=2;i<n;i+=2){
    		tmp.insert(i) ;
    		tmp.insert(i) ;
    	}
    	if ( tmp != ms ){
    		return cout << 0 << endl , 0 ; 
    	}
    }

    ll ans = 1; 
    for(ll i=0;i<n/2;i++){
    	ans = (ans % MOD * 2 ) % MOD ; 
    }
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 9600