akhauriyash/Code-Regression huggingface dataset:
n = int(input())
li = list(map(int, input().split()))
result = 0
mae = li[0]
for i in range(n):
    if mae > li[i]:
        result += mae - li[i]
        mae = li[i] + (mae - li[i])
    else:
        mae = li[i]
print(result)


Measured memory_bytes: 32380
#include <iostream>

using namespace std;

typedef long long ll;

int main(){
    int N;
    ll C;
    ll ans;
    ll x[100000], v[100000];
    ll pos_max[100000], pos_diff[100000], neg_max[100000], neg_diff[100000];
    cin >> N >> C;
    for(int i = 0; i < N;i++){
        cin >> x[i] >> v[i];
    }
    pos_diff[0] = v[0] - x[0];
    pos_max[0] = pos_diff[0];
    for(int i = 1; i < N;i++){
        pos_diff[i] = pos_diff[i-1] + v[i] - (x[i] - x[i-1]);
        pos_max[i] = max(pos_max[i-1], pos_diff[i]);
    }
    neg_diff[N-1] = v[N-1] - (C-x[N-1]);
    neg_max[N-1] = neg_diff[N-1];
    for(int i = N-2; i >= 0;i--){
        neg_diff[i] = neg_diff[i+1] + v[i] - ((C-x[i]) - (C-x[i+1]));
        neg_max[i] = max(neg_max[i+1], neg_diff[i]);
    }
    ans = max(pos_max[N-1], neg_max[0]);
    ans = max((ll)0, ans);
    for(int i = 0; i < N-1; i++){
        ans = max(ans, pos_max[i] - x[i] + neg_max[i+1]);
    }
    for(int i = N-1; i > 0;i--){
        ans = max(ans, neg_max[i] - (C-x[i]) + pos_max[i-1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
    if(x>y)return x;
    else return y;
}
ll min(ll x,ll y){
    if(x<y)return x;
    else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    int n;cin >> n;
    vector<ll> t(n);
    rep(i,n)cin >> t[i];
    ll l=1;
    rep(i,n)l=l/__gcd(l,t[i]) *t[i];
    cout << l << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll N;
  cin>>N;
  vector<ll> d(N);
  for(ll i=0;i<N;i++) {
cin>>d[i];
  }
  sort(all(d));
  ll i=N/2;
  cout<<d[i]-d[i-1]<<endl;
}

  

  
  


Measured memory_bytes: 4036
#include "bits/stdc++.h"
 
#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
 
const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };
 
 
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r, g, b;
	cin >> r >> g >> b;
	if ((g * 10 + b) % 4 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
//
// Created by user on 3/9/2020.
//
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    for (int i = 1; i <= 10000; ++i) {
        cerr << i << " " << (int)(i * 0.08) << " " << (int)(i * 0.1) << endl;
        if ( (int)(i * 0.08) == a and (int)(i * 0.1) == b) {
            cout << i;
            return 0;
        }
    }
    cout << -1;

}

Measured memory_bytes: 256
#python3
from collections import deque         
INF = int(1e9)
dd = [(-1, 0), (1, 0), (0, 1), (0, -1)]

def main():
    h, w = map(int, input().split())
    maze = [input() for _ in range(h)]
    ans = -1 
    
    for i in range(h):
        for j in range(w):
            if maze[i][j] == '#':
                continue
            g = [[INF for _ in range(w)] for _ in range(h)] 
            q = deque()
            q.append((i, j))
            g[i][j] = 0
            while len(q) > 0:
                pi, pj = q.popleft()
                for dx, dy in dd:
                    x = pi + dx
                    y = pj + dy
                    if (x < 0) | (y < 0) | (x >= h) | (y >= w): 
                        continue
                    if maze[x][y] == '#':
                        continue
                    if g[x][y] != INF:
                        continue
                    q.append((x, y))
                    g[x][y] = g[pi][pj]+1 
            

            for k in range(h):
                for l in range(w):
                    if g[k][l] == INF:
                        continue
                    ans = max(ans, g[k][l])
    print(ans)
main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define endl '\n'

int32_t  main()
{
    IOS;    
    int k,a,b;
    cin>>k>>a>>b;
    int hv=b/k-a/k;
    if(a%k==0)
        hv++;
    if(hv>0)
        cout<<"OK";
    else
        cout<<"NG";
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n,count=0;
    cin>>n;
    Vi a(n);
    REP(i,0,n){
        cin>>a[i];
        if(a[i]%2==1) count++;
    }

    YESNO(count%2==0);
    return 0;
}


Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()
	_ = nextInt()
	k := nextInt()

	ans := a - b
	if k%2 == 1 {
		ans = b - a
	}

	if abs(ans) > pow(10, 18) {
		fmt.Println("Unfair")
		return
	}

	fmt.Println(ans)

}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func pow(a, b int) int {
	var ret int = 1
	for b > 0 {
		if (b & 1) == 1 {
			ret *= a
		}
		a *= a
		b >>= 1
	}
	return ret
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

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

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

fastio _fast_io;

int n;

int main() {
    cin >> n;
    unordered_set<int> seen;
    int i = 1;
    while (1) {
        if (seen.count(n)) break;
        seen.insert(n);
        ++i;
        if (n & 1) n = n * 3 + 1;
        else  n = n / 2;
    }
    cout << i << endl;
    return 0;
}


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

vector<int> a;
long long anum[200010];
long long int a_0[200010];
long long int a_1[200010];
long long int ans = 0;
int n = 0;

int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long int tmp = 0;
    cin >> tmp;
    a.push_back(tmp);
    anum[tmp]++;
  }

  //    cout << endl;
  //   for(int i=0; i<n; i++){
  //       cout << anum[i] << " " << endl;
  //   }
  //    cout << endl;

  for (int i = 0; i <= 200005; i++) {
    if ((anum[i] == 0) || (anum[i] == 1)) {
      a_0[i] = 0;
      a_1[i] = 0;
    }
    a_0[i] = (anum[i] * (anum[i] - 1)) / 2;
    if ((anum[i] == 0) || (anum[i] == 1) || (anum[i] == 2)) {
      a_1[i] = 0;
    }
    a_1[i] = ((anum[i] - 1) * (anum[i] - 2)) / 2;
  }

  for (int i = 0; i <= 200005; i++) {
    ans += a_0[i];
  }
  for (int i = 1; i <= n; i++) {
    long long int tmpans = ans;
    tmpans -= a_0[a[i - 1]];
    tmpans += a_1[a[i - 1]];
    cout << tmpans << endl;
  }

  return 0;
}


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

int main() {
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    for (int i=0; i<N; i++) cin >> T[i];
    sort(T.begin(), T.end());

    int ans = 0;
    int bus = 0; // <= C
    for (int i=0; i<N; i++) {
        int m = T[i] + K; // 空港にいる人で、最初に空港に到着した人が待てる時間の最大値
        bus++;
        while(T[i+1] <= m && bus < C) {
            i++;
            bus++;
        }

        ans++;
        bus = 0;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<string> s(n);
    for (auto &si: s) cin >> si;
    auto check = [&](vector<string> &s) {
        for (int i = 0; i < n; i++) for (int j = 0; j < i; j++) {
            if (s[i][j] != s[j][i]) return false;
        }
        return true;
    };
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        rotate(s.begin(), s.begin() + 1, s.end());
        cnt += check(s);
    }
    cout << cnt * n << endl;
    return 0;
}


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

int main(){
    string s;
    cin >> s;

    int begin, end = 0;

    for(int i = 0; i < s.size(); ++i){
        if(s[i] == 'A'){
            begin = i;
            break;
        }
    }
    for(int i = begin; i < s.size(); ++i){
        if(s[i] == 'Z' && end < i) end = i;
    }

    cout << end - begin + 1 << endl;

    return 0;
}


Measured memory_bytes: 832
import math

A, B, H, M = map(int, input().split())

h = math.pi*2/(12*60)
m = math.pi*2/60

angle_M = M * m
angle_H = (H * 60 + M) * h

angle = math.fabs(angle_M - angle_H)

length = math.sqrt(A * A + B * B - 2 * A * B * math.cos(angle))

print(length)

Measured memory_bytes: 9380
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#define LARGE_VAL 1e9+7

using namespace std;

int main(){
    int N, M, L;
    cin >> N >> M >> L;
    vector<vector<int>> dist(N, vector<int>(N, LARGE_VAL));
    for(int i=0;i<M;i++){
        int a, b, c;
        cin >> a >> b >> c;
        --a;--b;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    vector<vector<int>> mp(N, vector<int>(N, LARGE_VAL));
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                if(dist[i][j] <= L){
                    mp[i][j] = 1;
                }
            }
        }
    }

    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);
            }
        }
    }
    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        int s,t;
        cin >> s >> t;
        --s;--t;
        if(mp[s][t] == LARGE_VAL){
            cout << -1 << endl;
        }else{
            cout << mp[s][t]-1 << endl;
        }
    }
    

    return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>

int main(void){
    int w,h,x,y,r;
    scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
    if(x>=r&&y>=r&&x<=w-r&&y<=h-r) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int X, t;
    cin >> X >> t;
    cout << max(0, X-t) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    
    if((a==b && a!=c) || (a==c && b!=c) || (b==c && a!=b))
    cout<<"Yes";
    else
    cout<<"No";
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int X;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> X;
	if (400 <= X && X <= 599) cout << 8 << endl;
	if (600 <= X && X <= 799) cout << 7 << endl;
	if (800 <= X && X <= 999) cout << 6 << endl;
	if (1000 <= X && X <= 1199) cout << 5 << endl;
	if (1200 <= X && X <= 1399) cout << 4 << endl;
	if (1400 <= X && X <= 1599) cout << 3 << endl;
	if (1600 <= X && X <= 1799) cout << 2 << endl;
	if (1800 <= X && X <= 1999) cout << 1 << endl;
}







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

int main() {
    int k,l;
    string s;
    cin >> k >> s;
    l = s.size();
    if(l > k){
        s.replace(k, l, "...");
        cout << s << endl;
    } else {
        cout << s << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3624
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;



int main(){
	int c[4][4];
	for (int i = 1; i <= 3; ++i) {
		for (int j = 1; j <= 3; ++j)
			scanf("%d", &c[i][j]);
	}
	if(c[1][1] - c[1][3] - c[2][1] + c[2][3] == 0 && c[1][2] - c[1][3] - c[2][2] + c[2][3] == 0 && c[3][3] == c[3][2] - c[1][2] + c[1][3] && c[3][3] == c[3][1] - c[1][1] + c[1][3])
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <limits>
//auto std::numeric_limits<float>::infinity() { return __builtin_huge_valf(); }
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
//MAQ氏のもの
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
//#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(), (a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(), (a).end())
#define YN(a)                  \
    if (a)                     \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
        cout << "No" << endl; //条件によってYes、Noを出力する

int main()
{
    //A ?
    /*
    int K;
    string S;
    vector<int> p(32);
    S = "1 1 1 2 1 2 1 5 2 2 1 5 1 2 1 14 1 5 1 5 2 2 1 15 2 2 5 4 1 4 1 51";
    rep(i, 0, 31)
    {
        p[i] = int(S.at(3 * i) - '0');
    }
    rep(i,0,31) cout<<p[i]<<" ";
    cout<<endl;
    cin >> K;
    cout << p[K] << endl;
    */
    //B
    long long h, w;
    cin >> h >> w;
    if (h == 1 || w == 1)
        cout << 1 << endl;
    else if ((h * w) % 2 == 0)
        cout << h * w / 2 << endl;
    else
        cout << h * w / 2 + 1 << endl;
}

Measured memory_bytes: 256
n=int(input())
listat = []
listb = []
for i in range(n):
    a,b=map(int,input().split())
    listat.append(a)
    listb.append(b)

sb = sorted(range(len(listb)), key=lambda k: listb[k])

listb.sort()
lista = []
for i in range(n):
    ii = sb[i]
    lista.append(listat[ii])

#print(lista)
#print(listb)
time = 0
ans = "Yes"
for i in range(n):
    time+=lista[i]
    if time>listb[i]:
        ans = "No"
        break 
print(ans)

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

int main(){
	int r; cin >> r;
	double pi = 3.141592;
	cout << pi * r * 2 << endl;
}

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

using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
int n;
int counter = 0;
int current_digit = 1;
int dfs(int rest_digit, int current) {
  if(current == 0) {
    for(int i = 1; i < 10; ++i) {
      int ans = dfs(rest_digit-1, i);
      if(ans) return ans;
    }
    ++current_digit;
    return dfs(current_digit, 0);
  } else {
    if(rest_digit == 0) {
      ++counter;
      if(counter == n) return current;
      else return 0;
    } else {
      int last_d = current%10;
      if(last_d == 9) {
        for(int i = max(last_d-1, 0LL); i <= last_d; ++i) {
          int ans = dfs(rest_digit-1, current*10 + i);
          if(ans) return ans;
        }
        return 0;
      } else {
        for(int i = max(last_d-1, 0LL); i <= last_d+1; ++i) {
          int ans = dfs(rest_digit-1, current*10 + i);
          if(ans) return ans;
        }
        return 0;
      }
    }
  }
}
/***** MAIN *****/
signed main() {
  n = in();
  if(n < 10) {
    cout << n << endl;
    return 0;
  }
  int ans = dfs(current_digit, 0);
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,k;cin>>n>>k;
    vector<pair<ll,ll>> t(n);//to, cost
    vector<ll> p(n),c(n);
    rep(i,n)cin>>p[i];
    rep(i,n)cin>>c[i];
    rep(i,n){
        p[i]--;
        t[i]={p[i],c[i]};
    }
    
    ll res=-5e18;
    rep(i,n){
        vector<ll> f;
        ll buf=0,maxi=-5e18,cou=0,maxcou=0;
        bool ok=true;
        ll from=i,to=t[i].first;
        while(true){
            cou++;
            ll cost=t[from].second;
            buf+=cost;
            f.push_back(buf);
            if(chmax(maxi,buf))maxcou=cou;
            if(to==i)break;
            if(cou==k){
                ok=false;
                break;
            }
            from=to;to=t[from].first;
            //cout<<from<<" "<<to<<" "<<buf<<endl;
        }
        if(!ok){
            chmax(res,maxi);
            continue;
        }
        if(buf>0){
            ll rot=k/cou;
            ll buf2=buf;
            buf=buf2*rot;
            ll buf5=buf+(maxi-buf2);
            ll buf3=k%cou,buf4=0;
            rep(j,buf3){
                chmax(buf4,f[j]);
            }
            buf+=buf4;
            chmax(buf,buf5);
        }else buf=maxi;
        chmax(res,buf);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3852
# -*- coding: utf-8 -*-

from collections import Counter


class UnionFind:
    def __init__(self, n):
        self.ranks = [[0] * n, [0] * n]
        self.pars = [[i for i in range(n)], [i for i in range(n)]]
        self.n = n

    def find_set(self, node, idx):
        if self.pars[idx][node] == node:
            return node
        else:
            self.pars[idx][node] = self.find_set(self.pars[idx][node], idx)
            return self.pars[idx][node]

    def same_set(self, x, y, idx):
        return self.find_set(x, idx) == self.find_set(y, idx)

    def unite(self, x, y, idx):
        x = self.find_set(x, idx)
        y = self.find_set(y, idx)
        if x == y:
            return
        if self.ranks[idx][x] > self.ranks[idx][y]:
            self.pars[idx][y] = x
        else:
            self.pars[idx][x] = y
            if self.ranks[idx][x] == self.ranks[idx][y]:
                self.ranks[idx][y] += 1


def main():
    n, k, l = map(int, input().split())
    uf = UnionFind(n)
    road = 0
    train = 1

    for i in range(k):
        p, q = map(int, input().split())
        uf.unite(p-1, q-1, road)

    for i in range(l):
        r, s = map(int, input().split())
        uf.unite(r-1, s-1, train)

    roots = [(uf.find_set(i, road), uf.find_set(i, train)) for i in range(n)]
    c = Counter(roots)
    ans = []
    for root in roots:
        ans.append(c[root])

    print(*ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(a%2==0||b%2==0||c%2==0)cout<<0;
    else cout<<min({a*b,b*c,c*a});
}

Measured memory_bytes: 256
function A173(_input) {
    var lines = _input.split("\n");
    var num = parseInt(lines[0], 10);
    var r = num % 1000;

    if (r === 0) {
        console.log(0);
    } else {
        console.log(1000 - r);
    }
}
A173(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29684
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>
using namespace std;
#define INF 1<<20


struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int TO,int V,vector<vector<edge> > graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
for (int i = 0;i < graph[pos].size();i++) {
	int to = graph[pos][i].to;
	int cost = graph[pos][i].cost;
	if (d[pos] + cost < d[to]) {
		d[to] = d[pos] + cost;
		q.push(Node(to, d[to]));
	}

}
	}
	cout << d[TO] << endl;
}
int partition(int A[], int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q - 1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[], int n, int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >= 0) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n, int* v, int* ww) {
	int W[101][10001];
	for (int j = 0;j <= w;j++) {
		W[0][j] = 0;
	}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++) {
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int fib(int n) {
	vector<int> v(n + 1);
	v[0] = 1;
	v[1] = 1;
	for (int i = 2;i < n + 1;i++) {
		v[i] = v[i - 2] + v[i - 1];
	}
	return v[n];
}
int isPrime(int x) {
	if (x <= 1) return false;
	if (x > 2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}
int gnc(int a, int b) {
	while (b%a != 0) {
		if (a > b) swap(a, b);
		else {
			b = b%a;
		}
	}
	return a;
}
int calc(int a, long long int b, long long int m) {
	if (b == 0) return 1;
	else if (b % 2 == 0) {
		long long int d = calc(a, b / 2, m);
		return (d*d) % m;
	}
	else {
		long long int d = calc(a, b -1, m);
		return (d*a) % m;
	}
}


int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> A(H, vector<char>(W));
	for (int i = 0;i < H;i++) {
		for (int j = 0;j < W;j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0;i < H;i++) {
		for (int j = 0;j < W;j++) {
			cout << A[i][j];
		}
		cout << endl;
		for (int j = 0;j < W;j++) {
			cout << A[i][j];
		}
		cout << endl;


	}
	return 0;
	}




Measured memory_bytes: 256
#include <cstdio>

int main(){
    int A, B;
    scanf("%d %d", &A, &B);

    int ans1 = A + B;
    int ans2 = A - B;
    int ans3 = A * B;

    int max = ans1;
    if(max < ans2)
        max = ans2;
    if(max < ans3)
        max = ans3;

    printf("%d\n", max);

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

const int MAX = 1e3+10;
struct Node{
    int x, y, cnt;
    Node(){}
    Node(int _x, int _y, int _c):x(_x), y(_y), cnt(_c){}
    bool operator<(const Node& a)const{
        return cnt > a.cnt;
    }
};
char g[MAX][MAX];
int step[MAX][MAX];
int H, W, sx, sy, ex, ey;
int f[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};

int bfs(){
    memset(step, 0x3f, sizeof(step));
    priority_queue<Node> q;
    q.push(Node(sx-1, sy-1, 0));
    step[sx-1][sy-1] = 0;
    int ans = 0x3f3f3f3f;
    while (q.size()){
        Node now = q.top(); q.pop();
        if (now.x==ex-1 && now.y==ey-1) ans = min(now.cnt, ans);
        if (ans == 0) return 0;
        for (int i = 0; i < 4; i++){
            int nx = now.x + f[i][0];
            int ny = now.y + f[i][1];
            if (nx>=0&&nx<H&&ny>=0&&ny<W&&g[nx][ny]=='.'&&now.cnt<step[nx][ny]){
                step[nx][ny] = now.cnt;
                q.push(Node(nx, ny, now.cnt));
            }
        }
        for (int i = now.x-2; i <= now.x+2; i++){
            for (int j = now.y-2; j <= now.y+2; j++){
                if (now.x==i && now.y==j) continue;
                if (i>=0&&i<H&&j>=0&&j<W&&g[i][j]=='.'&&now.cnt+1<step[i][j]){
                    step[i][j] = now.cnt + 1;
                    q.push(Node(i, j, now.cnt+1));
                }
            }
        }
    }
    if (ans == 0x3f3f3f3f) return -1;
    return ans;
}

int main(){
    scanf("%d%d", &H, &W);
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    for (int i = 0; i < H; i++) scanf("%s", g[i]);
    printf("%d\n", bfs());
    return 0;
}


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

int function(int *a,int *dp,int n)
{
  	dp[0]=0;
  	dp[1]=abs(a[0]-a[1]);
    for(int i=2;i<n;i++)
  	dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	return dp[n-1];
}
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int dp[n]={0};
  cout<<function(a,dp,n);
  return 0;
}


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

const int N = 1e5 + 10;

int n, a[N];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    a[i]--;
  }
  bool ok = true;
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1])
      a[i]++;
    ok &= (a[i] >= a[i - 1]);
  }
  puts(ok ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 640
package main

import (
    "fmt"
)

func main() {
    var (
        n     int
        count int
    )
    fmt.Scan(&n)
    nums := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&nums[i])
    }

    flag := true
    
    for {
        for i := 0; i < n; i++ {
            if nums[i] % 2 == 1 {
                flag = false
                break
            } else {
                nums[i] = nums[i] / 2
            }
        }
        if !flag {
            break
        } 
        count++
    }
    
    
    fmt.Println(count)
}

Measured memory_bytes: 512
/*
[agc031] C - Differ by 1 Bit
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int N, A, B;

int count(int x) {
    int ret = 0;
    for (int i = 0; i < N; i++) {
        if (x & (1 << i)) {
            ret++;
        }
    }

    return ret;
}

void dfs(int a, int b, int s, int l, int mask, int pat, vector<int> &ans) {
    if (l == 1) {
        ans[s] = a | pat;
        ans[s + 1] = b | pat;
        return;
    }

    int p = -(a ^ b) & (a ^ b);
    int m = mask ^ p;
    int v = -m & m;

    dfs((a & m), (a & m) ^ v, s, l - 1, m, pat | (a & p), ans);
    dfs((a & m) ^ v, (b & m), s + (1 << (l - 1)), l - 1, m, pat | (b & p), ans);
}

void solve() {
    if (count(A) % 2 == count(B) % 2) {
        cout << "NO" << endl;
        return;
    }
    cout << "YES" << endl;

    vector<int> ans(1 << N);
    dfs(A, B, 0, N, (1 << N) - 1, 0, ans);

    for (int i = 0; i < (1 << N); i++) {
        cout << ans[i];
        if (i == (1 << N) - 1) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

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

    int n; cin >> n;
    vector<int> a(n+5), b(n+5), c(n+5);
    for(int i=1; i<=n; ++i) cin >> a[i] >> b[i] >> c[i];

    vector< vector<int> > dp(n+5, vector<int>(3, 0));
    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];

    for(int i=2; i<=n; ++i){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }

    int ans = 0;
    for(int i=0; i<3; ++i) chmax(ans, dp[n][i]);
    cout << ans << endl;

	return 0;
}


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

using namespace std;

int main(){
int m, n, res1, res2, ans;
  
cin >> n >> m;

res1 = m*(m-1) / 2;
res2 = n*(n-1) / 2;
ans = res1 + res2;
  
cout << ans;
return 0;
}

Measured memory_bytes: 256
N, k = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

ans = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            if i > j:
                ans += k*(k-1)//2
            elif i < j:
                ans += k*(k+1)//2
            ans %= MOD

print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll> PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

ll n;
string s;
int table[1000]={0};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>s; int a,b,c;//abc
    bool flag = false; rep(i,1000)table[i]=0;
    rep(i,1000){
        flag = false;
        a = i/100;
        b = (i%100)/10;
        c = i%10;
        rep(j,s.size()){
            if(flag)break;
            if((s.at(j) - '0')== a){
                for(ll k = j+1;k<s.size() && !flag ;k++){
                    if((s.at(k) - '0')==b){
                        for(ll l = k+1;l<s.size() && !flag ;l++){
                            if((s.at(l) - '0')== c){
                                flag = true;
                                break;
                            }
                        }
                        break;
                    }
                }
                break;
            }
        }
        if(flag)table[i]=1;
    }
    ll ans = 0;
    rep(i,1000)if(table[i]==1)ans++;
    print(ans);
    return 0;
}

Measured memory_bytes: 384
N, T = input().split()
all_list = []
for i in range(int(N)):
    for j in input().split():
        all_list.append(int(j))

all_pattern_list = sorted(list(zip(*[iter(all_list)]*2)))

for pattern in all_pattern_list:
    if pattern[1] <= int(T):
        print(pattern[0])
        break
    elif pattern == all_pattern_list[-1]:
        print('TLE')

Measured memory_bytes: 9108
defmodule Main do
  def main do
    s =
      IO.read(:line)
      |> String.trim |> String.to_charlist
    t =
      IO.read(:line)
      |> String.trim |> String.to_charlist
    [_shead | stail] = s
    [_thead | ttail] = t
	if List.first(s) == List.last(t) and List.last(s) == List.first(t) and List.first(stail) == List.first(ttail) do
    	IO.puts("YES")
    else
    	IO.puts("NO")
    end
    
  end
end


Measured memory_bytes: 30688
n = int(input())
a = list(map(int, input().split()))

ar = list(reversed(a))
#print(ar)
com = [ar[0]]
for i in range(n):
    com.append(com[i] + ar[i+1])
#print(com)
com.reverse()
ans = 0
val = 1
for i in range(n+1):

    ans += min(val,com[i])
    val -= a[i]
    if (i < n and val <= 0) or (i == n and val < 0) or (i == n and a[i] == 0):
        print(-1)
        exit()
    val *= 2
print(ans)


Measured memory_bytes: 84688
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const long long INF = 1LL << 60;
ll MOD = 1e9+7;

int main() {
    double A,B,H,M; cin>>A>>B>>H>>M;
    double tyosin, tansin;
    tyosin = H / 12 + (M / 60 / 12);
    tansin = M / 60;

    double thita = min((abs(tyosin-tansin)*360),abs((abs(tyosin-tansin)*360 - 360)));
    double ans = sqrt(A*A+B*B - 2*A*B*cos(M_PI*(thita/180) ));
    
    printf("%.10lf", ans);
}

Measured memory_bytes: 4200
n,m,x=map(int,input().split(" "))
li=list(input().split(" "))
for g in range(m):
    li[g]=int(li[g])
br=0
br2=0
k=x
pp=x
for i in range(pp):
    x-=1
    for z in range(m):
        if x==li[z]:
            br+=1
for i in range(n-pp):
    k+=1
    for z in range(m):
        if k==li[z]:
            br2+=1
print(min(br,br2))

Measured memory_bytes: 3064
// VALUE THE SACRIFICES..
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define int long long
#define out_of_reach ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define mod 1000000007
int par[150001],siize[1000005];
// -----------------------------------------------------------------
signed  main()
{
    int t;
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
        cout<<"Yes";
    else    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using v  = vector<int>;
using vv = vector<v>;

int main(){
    int r,g,b,n; cin >>r>>g>>b>> n;
    ll ans = 0;
    for(int i=0; i*r<=n; i++){
        for(int j=0; i*r+j*g<=n; j++){
            if((n-(i*r+j*g))%b==0)
                ans ++;
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

int main() {
  long long int n, k, ans = 0, mod = 1000000007;
  cin >> n >> k;

  for (long long int i = k; i <= n + 1; i++) {
    ans += (n * i - i * (i - 1) + 1) % mod;
  }
  cout << ans % mod << endl;
}

Measured memory_bytes: 3560
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;


string S;

signed main()
{
	cin>>S;
	int ans=0;
	for(int i=0; i<S.length(); i++)
	{
		for(int j=0; i+j<S.length(); j++)
		{
			if(i+j==S.length()-1)
			{
				ans+=(S[i]-'0')*pow(10,j)*pow(2,S.length()-j-1);
			}
			else
			{
				ans+=(S[i]-'0')*pow(10,j)*pow(2,S.length()-j-2);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
#define int long long

const int N = 3e5 + 233;
int n, vis[N], rem[N], ans[N];
map <int, int> alive;
pair <int, int> a[N];

#define GG (puts("No"), exit(0))

signed main(void) {
	read(n);
	rep (i, n) {
		read(a[i].first), a[i].second = i;
		if (vis[a[i].first]) GG;
		vis[a[i].first] = i;
	}
	sort(a + 1, a + n + 1);
	rep (i, n) rem[a[i].second] = a[i].second - 1;
	int pos = 1;
	for (int i = 1; i <= n * n; i++) {
		if (vis[i]) {
			if (rem[vis[i]]) GG;
			ans[i] = vis[i];
			if (vis[i] != n) alive[vis[i]] = n - vis[i];
		}
		else {
			while (pos <= n && !rem[a[pos].second]) ++pos;
			if (pos <= n) {
				--rem[a[pos].second]; ans[i] = a[pos].second;
			} else {
				auto it = alive.begin();
				if (it == alive.end()) GG;
				ans[i] = it->first;
				if (--it->second == 0) alive.erase(it);
			}
		}
	}
	cout << "Yes\n";
	rep (i, n * n) cout << ans[i] << " "; cout << "\n";
}


Measured memory_bytes: 8064
#include <stdio.h>

int main() {
  short age, original_price, final_price = 0;
  scanf("%hd %hd", &age, &original_price);

  if (age >= 13) {
    final_price = original_price;
  } else {
    if (age >= 6) {
      final_price = original_price / 2;
    }
  }

  printf("%hd\n", final_price);

  return 0;
}


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

int main()
{
    int a, b, c;

    cin >> a >> b >> c;
    if (a >= b && a >= c)
    {
        cout << a * 10 + b + c << endl;
    }
    else if (b >= a && b >= c)
    {
        cout << a + b * 10 + c << endl;
    }
    else if (c >= a && c >= b)
    {
        cout << a + b + c * 10 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    long double w, h, x, y;
    cin >> w >> h >> x >> y;
    long double res = w*h/2;
    cout << fixed << setprecision(10) << res << " ";
    if(2*x==w && 2*y==h){cout << 1 << endl;}
    else{cout << 0 << endl;}
    return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[300005];
ll P[100];

int main() {
    ll N;
    cin >> N;
    memset(P, 0, sizeof(P));
    REP(i, N) {
        cin >> A[i];
        REP(j, 61) {
            if (((A[i] >> j) & 1) == 1)
                P[j]++;
        }
    }

    ll ans = 0;
    ll p = 1;
    REP(i, 61) {
        ans += (((p * P[i]) % MOD) * (N - P[i])) % MOD;
        p = (p * 2LL) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)

ans = 0
backet = Hash.new(0)
n.times do |i|
  backet[a[i] + i] += 1
end
n.times do |j|
  if j - a[j] >= 0
    ans += backet[j - a[j]]
  end
end

puts ans

Measured memory_bytes: 38508
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
   int coin;
   int b,r,g,c,s,t;
   while(cin>>b>>r>>g>>c>>s>>t,b+r+g+c+s+t){
       coin=100;
       coin+=15*(b+r)+13*(b*5+r*3)+7*g+2*c-(t-5*b-3*r-s)*3;
       cout<<coin<<endl;
   }
    return 0;
}


Measured memory_bytes: 5340
import math

K=int(input())
count = 0
for a in range(1,K+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            _z=math.gcd(a,b)
            if a==b and b==c:
                k=1
            elif a==b or b==c or c==a:
                k=3
            else:
                k=6
            count += k * math.gcd(_z,c)
print(count)

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

using namespace std;
using ll = long long;
using ld = long double;
const ll MOD=1e9+7;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    vector<bool> dom;
    for(int i = 0; i < n; i++) {
        if(s[i]==t[i]) dom.emplace_back(true);
        else{
            dom.emplace_back(false);
            i++;
        }
    }
    ll ans;
    if(dom[0]==1) ans=3;
    else ans=6;
    for(int i = 1; i < dom.size(); i++) {
        if(dom[i-1]==true && dom[i]==true)       ans=(ans*2)%MOD;
        else if(dom[i-1]==true && dom[i]==false) ans=(ans*2)%MOD;
        else if(dom[i-1]==false && dom[i]==true) ans%=MOD;
        else ans=(ans*3)%MOD;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256