akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const int INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
//#define double long dounle

////////////////////////////////////////////////////////////////////
struct edge {
  int to, from, cost;
  edge(int to, int cost) : from(-1), to(to), cost(cost) {}
  edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
};
using edges = vector<edge>;
using graph = vector<edges>;
using matrix = vector<vector<int>>;
vector<int> dijkstra(int s, graph &g){
  vector<int> dist(g.size()+10, INF);dist[s] = 0;
  priority_queue<P, vector<P>, greater<P>> que;que.push(P(0,s));
  while(!que.empty()){
    P p = que.top();que.pop();
    int v = p.second;
    if(dist[v] < p.first)continue;
    rep(i, g[v].size()){
      edge e = g[v][i];
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        que.push(P(dist[e.to], e.to));
      }
    }
  }
  return dist;
}

vector<int> bellman(int s, graph &g){
  vector<int> dist(g.size()+10, INF);dist[s] = 0;
  while(true){
    bool update = false;
    rep(i,g.size()){
      edges es = g[i];
      rep(j,es.size()){
        edge e = es[j];
        if(dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost){
          dist[e.to] = dist[e.from] + e.cost;
          update = true;
        }
      }
    }
    if(!update)break;
  }
  return dist;
}

vector<vector<int>> warshall(matrix &g){
  vector<vector<int>> dist(g.size()+10);
  rep(i,g.size()+10){
    dist[i].resize(g.size()+10);
    rep(j,g.size()+10)dist[i][j] = (g[i][j] ? g[i][j] : (i==j ? 0 : INF));
  }
  rep(k,g.size()){
    rep(i,g.size()){
      rep(j,g.size()){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  return dist;
}
////////////////////////////////////////////////////////////////////

signed main(){
  int n, a[210000];cin>>n;rep(i,n)cin>>a[i];
  int len = 0;rep(i,n)len += a[i];
  int r = 0, l = 0;
  int ans = INF;
  rep(i,n){
    l += a[i];
    ans = min(ans, abs((len-l)-l));
  }
  cout << ans << endl;
}



Measured memory_bytes: 1792
#include<stdio.h>                                                    

int main(void)
{
   int a,b,c;
   scanf("%d %d",&a,&b);

   if((b%a)==0){
            c=b+a;
            printf("%d\n",c);}

   else {
         c=b-a;
         printf("%d\n",c);}

   return 0;
}


Measured memory_bytes: 128
from collections import Counter

S = input()

set_S = set(list(S))

if len(set_S) == 2:
    if set_S == set(['N', 'S']):
        print('Yes')
    elif set_S == set(['W', 'E']):
        print('Yes')
    else:
        print('No')
elif len(set_S) == 4:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

ll N, T;
vector<pll> v;
ll A[3001], B[3001];
ll dp[6001][6001];

ll solve(){
    REP(i, N){
        REP(t, T + 1){
            dp[i + 1][t] = max(dp[i + 1][t], dp[i][t]);
            if(t < T) dp[i + 1][min(t + A[i], T)] = max(dp[i + 1][min(t + A[i], T)], dp[i][t] + B[i]);
        }
    }
    ll ret = 0;
    REP(t, T + 1) ret = max(ret, dp[N][t]);
    return ret;
}

signed main(){
    cin >> N >> T;
    ll a, b;
    REP(i, N){
        cin >> a >> b;
        v.push_back(pll(a, -b));
    }
    sort(ALL(v));
    REP(i, N){
        A[i] = v[i].first;
        B[i] = -v[i].second;
    }
    PRINT(solve());
    return 0;
}

Measured memory_bytes: 86108
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int a;

	cin >> a;

	if (a % 2 == 0) {
		cout << 0.50000000 << endl;

	}
	else {
		cout << fixed << setprecision(15) << ((double)(a / 2) + 1.0) / (double)a << endl;
	}

	return 0;
}

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

int main(){
    int n, i;
    string s;
    cin >> n >> s;
    for(i=0; i<s.length(); i++){
        cout << (s[i]+n > 'Z' ? (char)('A' + s[i] - 'Z' + n-1) : (char)(s[i]+n));
    }
    return 0;
}

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

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

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
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;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,p[300000],dist[510][510];
bool b[510][510];
P pos[300010];
#define PP pair<int,P>
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n*n){
        cin>>p[i];
        p[i]--;
        pos[i]={i/n,i%n};
    }
    rep(i,n){
        rep(j,n){
            dist[i][j]=min({i,j,n-i-1,n-j-1});
        }
    }
    int ans=0;
    rep(i,n*n){
        int x=pos[p[i]].fi,y=pos[p[i]].se;
        ans+=dist[x][y];
        b[x][y]=true;
        priority_queue<PP,vector<PP>,greater<PP>>q;
        q.push({0,{x,y}});
        while(!q.empty()){
            PP pp=q.top();
            q.pop();
            x=pp.se.fi,y=pp.se.se;
            if(b[x][y]==false){
                rep(k,4){
                int X=x+dx[k],Y=y+dy[k];
                if(0<=X&&X<n&&0<=Y&&Y<n){
                    if(dist[X][Y]>dist[x][y]+1){
                        dist[X][Y]=dist[x][y]+1;
                        q.push({pp.fi+1,{X,Y}});
                    }
                }}
            }else{
            rep(k,4){
                int X=x+dx[k],Y=y+dy[k];
                if(0<=X&&X<n&&0<=Y&&Y<n){
                    if(dist[X][Y]>dist[x][y]){
                        dist[X][Y]=dist[x][y];
                        q.push({pp.fi+1,{X,Y}});
                    }
                }
            }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11764
#include <bits/stdc++.h>
using namespace std;
vector<int> g[1<<17];
int dp[1<<17] = {0};
int dfs(int u) {
  if (dp[u]) return dp[u];
  for (int v : g[u]) dp[u] = max(dfs(v) + 1, dp[u]);
  return dp[u];
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, m; cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v; cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) ans = max(dfs(i), ans);
  cout << ans << '\n';
}



Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
 
int main(){
  int N;
  cin>>N;
  vector<ll> x(N),y(N),h(N);
  for(int i=0;i<N;i++){
    cin>>x[i]>>y[i]>>h[i];
  }
  int H;
  for(int cx=0;cx<=100;cx++){
    for(int cy=0;cy<=100;cy++){
      //Hの特定
      for(int i=0;i<N;i++){
        if(h[i]==0) continue;
        H=h[i]+abs(x[i]-cx)+abs(y[i]-cy);
        break;
      }
 
      //整合性
      bool flag=true;
      for(int i=0;i<N;i++){
        if(max(H-abs(x[i]-cx)-abs(y[i]-cy),0LL)!=h[i]){
          flag=false;
          break;
        }
      }
      if(flag){
        cout<<cx<<" "<<cy<<" "<<H<<endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#define INF 100000000
using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> P2;

int main(){
  int w,h;
  char grid[100][50];
  int d[2][100][50];
  int dy[] = {-2,-1,0,1,2,-1,0,1,0} , dx[] = {1,1,1,1,1,2,2,2,3};

  while(cin >> w >> h , w||h){
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	scanf(" %c ",&grid[i][j]);

    priority_queue<P2,vector<P2>,greater<P2> > q;
    vector<P2> G[2][100][50];

    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	if(grid[i][j] == 'S'){
	  d[0][i][j] = d[1][i][j] = 0;
	  q.push(P2(P(0,0),P(i,j)));
	  q.push(P2(P(0,1),P(i,j)));
	}else d[0][i][j] = d[1][i][j] = INF;
      }
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	for(int k=0;k<9;k++){
	  int sy = i+dy[k], sx = j+dx[k];
	  if(sy<0 || sx<0 || h<=sy || w<=sx)continue;
	  if('1'<=grid[sy][sx] && grid[sy][sx]<='9')
	    G[0][i][j].push_back(P2(P(grid[sy][sx]-'0',1),P(sy,sx)));
	  if(grid[sy][sx] == 'T')
	    G[0][i][j].push_back(P2(P(0,1),P(sy,sx)));
	}
	for(int k=0;k<9;k++){
	  int sy = i+dy[k], sx = j-dx[k];
	  if(sy<0 || sx<0 || h<=sy || w<=sx)continue;
	  if('1'<=grid[sy][sx] && grid[sy][sx]<='9')
	    G[1][i][j].push_back(P2(P(grid[sy][sx]-'0',0),P(sy,sx)));
	  if(grid[sy][sx] == 'T')
	    G[1][i][j].push_back(P2(P(0,0),P(sy,sx)));
	}
      }
    }

    while(q.size()){
      P2 p = q.top();q.pop();
      
      int t = p.first.first, f = p.first.second;
      int y = p.second.first, x = p.second.second;

      if(grid[y][x] == 'T'){
	q.push(p);
	cout << t << endl;
	break;
      }

      for(int i=0;i<(int)G[f][y][x].size();i++){
	int tt = G[f][y][x][i].first.first, tf = G[f][y][x][i].first.second;
	int ty = G[f][y][x][i].second.first, tx = G[f][y][x][i].second.second;

	if(d[tf][ty][tx] > t + tt){
	  d[tf][ty][tx] = t+tt;
	  q.push(P2(P(t+tt,tf),P(ty,tx)));
	}
      }
    }
    if(q.empty())cout << -1 << endl;
  }
}

Measured memory_bytes: 0
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

def lcm(x, y):
    return (x * y) // gcd(x, y)


def main():
    a,b = mi()

    print(lcm(a, b))

    
main()


Measured memory_bytes: 5076
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()
    T = input().strip()

    if S == T[:len(S)] and len(T) - len(S) == 1:
        print("Yes")
    else:
        print("No")



if __name__ == '__main__':
    main()



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n=4;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];

  ll res=INF;
  rep(S,1<<n){
  	if(bcnt(S)!=2)continue;
  	ll x=0,y=0;
  	rep(i,n){
  		if((S>>i)&1)x+=a[i];
  		else y+=a[i];
  	}
  	minch(res,(ll)abs(x-y));
  }
  cout<<res<<endl;

  return 0;
}



Measured memory_bytes: 3184
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

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

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int x;
    cin >> x;
    if(x <= 599) cout << "8\n";
    else if(x <= 799) cout << "7\n";
    else if(x <= 999) cout << "6\n";
    else if(x <= 1199) cout << "5\n";
    else if(x <= 1399) cout << "4\n";
    else if(x <= 1599) cout << "3\n";
    else if(x <= 1799) cout << "2\n";
    else cout << "1\n";

    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
string alph("abcdefghijklmnopqrstuvwxyz");
int fi[2005][2005]={};
signed main(){
    int n;cin>>n;
    int fi[2][105]={};
    rep(i,0,2){
        rep(j,0,n){
            cin>>fi[i][j];
        }
    }
    rep(i,1,n){
        fi[0][i]+=fi[0][i-1];
    }
    fi[1][0]+=fi[0][0];
    rep(i,1,n){
        fi[1][i]+=max(fi[1][i-1],fi[0][i]);
    }
    cout<<fi[1][n-1]<<endl;
    return 0;
}



Measured memory_bytes: 2304
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");
        int n = Integer.valueOf(arr01[0]);
        String arr02[] = mylist.get(1).split(" ");
        String s = arr02[0];

        int cnt = 1;

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

            String stemp_before = s.substring(i - 1, i);
            String stemp = s.substring(i, i + 1);

            if (!stemp_before.equals(stemp)) {
                cnt += 1;
            }
            //            System.out.println(stemp_before + " " + stemp + " " + cnt);

        }

        System.out.println(cnt == 0 ? 1 : cnt);
    }

}


Measured memory_bytes: 33876
import math
n, m = map(int, input().split())
s = 0
p = [0.0]
k = 1
s_old = -1.0
while s - s_old >= 0.0000001:
    pr = (1 - sum(p)) / (2**m)
    p.append(pr)
    s_old = s
    s += (1900 * m + 100 * (n - m)) * k * pr
    k += 1
print(math.ceil(s))

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

using namespace std;

void solve(long N, unordered_map<long, long> A) {

  vector<long> candidates;

  for (const auto& kv : A) {
    auto& k = kv.first;
    auto& v = kv.second;
    if (v < 2)
      continue;
    else
      candidates.emplace_back(k);
    if (v >= 4)
      candidates.emplace_back(k);
  }
  if (candidates.size() < 2)
    cout << 0 << endl;
  else {
    sort(candidates.rbegin(), candidates.rend());
    cout << candidates[0] * candidates[1] << endl;
  }
  return;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  long N;
  cin >> N;

  long Ai;
  unordered_map<long, long> A;
  REP(i, N) {
    cin >> Ai;
    A[Ai]++;
  }

  solve(N, move(A));

  return 0;
}


Measured memory_bytes: 4388
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		String s;
		int[] alf=new int[26];
		while(scan.hasNext()){
			s=scan.next();
			for(int i=0;i<s.length();i++){
				if('A'<=s.charAt(i)&&s.charAt(i)<='Z'){
					alf[s.charAt(i)-'A']++;
				}else if('a'<=s.charAt(i)&&s.charAt(i)<='z'){
					alf[s.charAt(i)-'a']++;
				}else{
				}
			}
		}
		for(int i=0;i<26;i++){
			System.out.printf("%c : %d\n",(char)(i+'a'),alf[i]);
		}
		scan.close();
	}
}

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

int main(void){
   int m,f,r;
   while(true){
       cin >> m >> f >> r;
       char s;
       if(m==-1 && f==-1 && r==-1) {
           break;
       }
        if((m==-1||f==-1)||((m+f)<30)) {
            s = 'F';
        }
        else if((m+f)>=80) {
            s = 'A';
        }
        else if((m+f)>=65) {
            s = 'B';
        }
        else if((m+f)>=50) {
            s = 'C';
        }
        else if(((m+f)>=30)) {
            s = 'D';
            if(r>=50){
             s = 'C';
            }
        }
        cout << s << endl;
   }
}


Measured memory_bytes: 3096
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		char[] s = br.readLine().toCharArray();
		br.close();

		List<Integer> list = new ArrayList<>();
		int idx = n;
		while (idx > 0) {
			int bef = idx;
			for (int i = Math.max(idx - m, 0); i < idx; i++) {
				if (s[i] == '0') {
					list.add(idx - i);
					idx = i;
				}
			}
			if (bef == idx) {
				System.out.println(-1);
				return;
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = list.size() - 1; i >= 0; i--) {
			sb.append(list.get(i)).append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}
}


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

int main () {
    int time[100000];
    string name[100000];
    int n, q;
    
    cin >> n >> q;
    for (int i = 0; i < n; i++) cin >> name[i] >> time[i];
    
    int count = 0;
    int t = 0;
    
    while(count < n) {
        for (int i = 0; i < n; i++) {
            if (time[i] == 0) continue;
            else if(time[i] <= q) {
                t += time[i];
                time[i] = 0;
                count++;
                cout << name[i] << " " << t << endl;
            }
            else {
                t += q;
                time[i] -= q;
            }
        }
    }
    return 0;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) (v.begin(), v.end())
#define dump(v)              \
  cerr << #v ":[ ";          \
  for (auto macro_vi : v) {  \
    cerr << macro_vi << " "; \
  }                          \
  cerr << "]" << endl;
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

bool is_prime(const unsigned n) {
  switch (n) {
    case 0: // fall-through
    case 1:
      return false;
    case 2: // fall-through
    case 3:
      return true;
  } // n > 3 が保証された

  if (n % 2 == 0) return false;
  if (n % 3 == 0) return false;
  // 2と3の倍数でないので6の倍数ではないことが保証された

  if (n % 6 != 1 && n % 6 != 5) return false;
  // 6の倍数前後の数(素数かもしれない数)であることが保証された

  // 6の倍数前後の数を使って試し割りをする
  for (unsigned i = 5; i * i <= n; i += 6) {
    if (n % i == 0) return false;       // 6n-1
    if (n % (i + 2) == 0) return false; // 6n+1
  }

  return true;
}

int main() {
  unsigned x;
  cin >> x;
  unsigned a = x;
  while (true) {
    if (is_prime(a)) {
      cout << a << endl;
      return 0;
    }
    a++;
  }
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<char> s(n);
	rep(i, n) cin >> s[i];

	int ans = 1;
	rep(i, n-1) {
		if (s[i] != s[i+1]) {
			ans++;
		}

	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**7)
n,k=map(int,input().split())
mo=10**9+7
f=[0]*(1+n)
r=[0]*(1+n)

def fact(n):
    if n==0:
        f[0]=1
        return 1
    if f[n]!=0:
        return f[n]
    f[n]=n*fact(n-1)%mo
    return f[n]

r[n]=pow(fact(n),mo-2,mo)

def revfact(n):
    if r[n]!=0:
        return r[n]
    r[n]=( (n+1)*revfact(n+1) )%mo
    return r[n]
    
def comb(n,k):
    return fact(n)*revfact(n-k)*revfact(k)%mo

fact(n)
revfact(0)

for i in range(1,1+k):
    print((comb(n-k+1,i)*comb(k-1,i-1))%mo if n-k>=i-1 else 0)


Measured memory_bytes: 53360
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        boolean judge = b - a == c - b;
        String result = judge ? "YES" : "NO";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.ListIterator;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		int[] h = sc.nextIntArray(n);
		
		int sum = 0;
		while(isNotEmpty(h)) {
			int pointer = 0;
			while(pointer < n) {
				if(h[pointer] == 0) {
					pointer++;
					continue;
				}
				
				for(int i=pointer; i < n; i++) {
					if(h[i] == 0)
						break;	
					h[i]--;
				}
				
				sum++;				
			}
		}
		System.out.println(sum);
		
	}
	
	private static boolean isNotEmpty(int[] h ) {
		return Arrays.stream(h).anyMatch(i -> i != 0);
	}
}

class Scanner {
	private static final int SPACE = (int)' ';
	private static final int LINE_END_0 = 13;
	private static final int LINE_END_1 = 10;
	private static final int BEFORE = -1;
	private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public String next(){
		StringBuilder sb = new StringBuilder();
		
		int length = BEFORE;
		readLoop: while(true) {
			try {
				int value = br.read();
				switch(value) {
				case LINE_END_1:
					if(length == BEFORE)
						break;
					
					if((int)sb.charAt(length) == LINE_END_0)
						sb.deleteCharAt(length);
				case SPACE:
					break readLoop;
				}
				sb.append((char)value);
				length++;

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
	
	public String[] nextArray(int length) {
		String[] array = new String[length];
		for(int i = 0; i < length; i++)
			array[i] = next();
		return array;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	
	public double[] nextDoubleArray(int length) {
		double[] array = new double[length];
		for(int i = 0; i < length; i++)
			array[i] = nextDouble();
		return array;
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public int[] nextIntArray(int length) {
		int[] array = new int[length];
		for(int i = 0; i < length; i++)
			array[i] = nextInt();
		return array;
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public long[] nextLongArray(int length) {
		long[] array = new long[length];
		for(int i = 0; i < length; i++)
			array[i] = nextLong();
		return array;
	}
	
	public boolean ready() {
		try {
			return br.ready();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
}


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

int main(){
  int n; cin>>n;
  vector<int> alp(26,0);
  
  for(int i=0;i<n;i++){
    string s; cin>>s;
    vector<int> now(26);
    for(int j=0;j<(int)s.size();j++){
      now[s[j]-'a']++;
    }
    if(i==0){
      for(int j=0;j<26;j++){
      	alp[j]=now[j];
      }
    }else{
      for(int j=0;j<26;j++){
        alp[j]=min(alp[j],now[j]);
      }
    }
  }
  
  for(int i=0;i<26;i++){
    cout<<string(alp[i], (char)(i+'a'));
  }
  
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	string s;
	cin>>s;
	ll sum = 0;
	for(int i=0;i<(1<<((int)s.length()-1));i++) {
		vi pos;
		for(int j=0;j<(int)s.length()-1;j++) {
			if((i>>j)&1)
				pos.PUB(j+1);
		}
		pos.PUB((int)s.length());
		int last = 0;
		for(int j:pos) {
			sum+=stol(s.substr(last ,j-last));
			last=j;
		}
	}
	cout<<sum;
}//1 0 2 3 1
//1 1 3 6 7

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3616
import sys
input = sys.stdin.readline
from itertools import accumulate


N,M = map(int,input().split())
A = [0] + sorted(list(map(int,input().split())))
info = [list(map(int,input().split())) for _ in range(M)]

info = sorted(info, key=lambda x:-x[1])

BC = [0]
for B,C in info:
    BC += [C]*min(B,N+1-len(BC))

BC += [0]*(N+1-len(BC))

ans = 0
res = sum(A)

# 小さい方からi枚置き換える
for i in range(N+1):
    res -= A[i]
    res += BC[i]
    ans = max(ans,res)

print(ans)

Measured memory_bytes: 36884
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 31;
const int MAX_C = 1e6;
int n,x,cost[MAX];
bool dp[MAX_C+1],prime[MAX_C+1];

void is_prime(){
  fill(prime,prime+MAX_C,true);
  prime[0] = prime[1] = false;

  for(int i = 2 ; i*i <= MAX_C ; i++)
    if(prime[i])
      for(int j = i*i ; j <= MAX_C ; j+=i)
	prime[j] = false;
}

int main(){
  is_prime();
  while(cin >> n >> x ,n + x){
    fill(dp,dp+MAX_C,false); 
    fill(cost,cost+MAX,0);
    for(int i = 0 ; i < n ; i++){
      cin >> cost[i];
      dp[cost[i]] = true;
    }
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j <= x ; j++){
	if(dp[j] && j+cost[i] <= x){
	  dp[j+cost[i]] = true;
	}
      }
    }
    int ans = 0;
    for(int i = x ; i >= 0 ; i--){
      if(prime[i]&&dp[i]){
	ans = i;
	break;
      }
    }
    if(ans) cout << ans << endl;
    else cout << "NA" << endl;
  }

  return 0;
}

Measured memory_bytes: 3112
#include<iostream>
#include<vector>
#include<algorithm>
#include <functional>

using namespace std;

struct S{
	int h,w,hw;
};

bool operator<(S a,S b){
	return (a.hw<b.hw||(a.hw==b.hw&&a.h<b.h));
}

int main(){

	int h,w;
	vector<S> sq;
	S s;

	for(int i=1;i<=200;i++){
		for(int j=i+1;j<=200;j++){
			s.h=i,s.w=j,s.hw=i*i+j*j;
			sq.push_back(s);
		}
	}

	sort(sq.begin(),sq.end());

	while(1){
		cin>>h>>w;
		if(h==0&&w==0) break;
		for(int i=0;;i++){
			if(sq[i].h==h&&sq[i].w==w){
				cout<<sq[i+1].h<<" "<<sq[i+1].w<<endl;
				break;
			}
		}
	}

	return 0;
}

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

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

    cout << (n >= s ? n - s : -1) << "\n";
}



Measured memory_bytes: 3668
#include<stdio.h>

void trace(int A[], int N){
    for(int i = 0; i < N; i++){
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");

}

int bubbleSort(int A[], int N){
    int flag = 1;
    int count = 0;

    while(flag){
        flag = 0;
        for(int j = N -1; j > 0; j--){
            if(A[j] < A[j-1]){
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
                count++;
            }
        }
    }
    return count;

}

int main(){
    int A[100];
    int N;

    scanf("%d", &N);
    for(int i = 0; i < N; i++)scanf("%d",&A[i]);

    int count = bubbleSort(A,N);
    trace(A, N);

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

}

Measured memory_bytes: 2712
#include<bits/stdc++.h>
using namespace std;
const long long N=100005;
long long n;
long long a[N];
long long cnt[3],tot=0;
int main(){
    scanf("%lld",&n);
    for(long long i=1;i<=n;i++)scanf("%lld",&a[i]);
    sort(a+1,a+n+1);
    for(long long i=n;i>=1;i--)if(a[i]==a[i-1]){cnt[++tot]=a[i];i--;if(tot==2)break;}
    printf("%lld\n",cnt[1]*cnt[2]);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>
 
using namespace std;
 
void solve();
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
 
void solve() {
    int a,b;
    cin >> a >> b;
    if( a * b % 2 == 0) {
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }

    

}

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

#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct edge
{
	int s, t;
	double w;
	edge(int s, int t, double w) :s(s), w(w), t(t) {}
	edge() { s = -1, w = -1, t = -1; }
	bool operator<(const edge& e)const
	{
		return w < e.w;
	}
};

struct UnionFind
{
	vector<int> parent;
	vector<int> rank;

	UnionFind(int N) :parent(N, 0), rank(N, 0)
	{
		rep(i, 0, N)
		{
			parent[i] = i;
		}
	}

	int find(int x)
	{
		if (parent[x] == x)
		{
			return x;
		}
		else
		{
			return parent[x] = find(parent[x]);
		}
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (x == y)
		{
			return;
		}

		if (rank[x] < rank[y])
		{
			parent[x] = y;
		}
		else
		{
			parent[y] = x;
			if (rank[x] == rank[y])
			{
				rank[x]++;
			}
		}
	}

	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};

edge edges[100010];
pdd piles[10000];

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

	int N, M,a,b;
	double x, y;
	cin >> N >> M;
	rep(i, 0, N)
	{
		cin >> x >> y ;
		piles[i] = mp(x, y);
	}

	double ans = 0.0;
	rep(i, 0, M)
	{
		cin >> a >> b;
		a--, b--;
		edges[i] = edge(a, b, -sqrt((piles[a].first - piles[b].first)*(piles[a].first - piles[b].first) + (piles[a].second - piles[b].second)*(piles[a].second - piles[b].second)));
		ans += (-edges[i].w);
	}

	sort(edges, edges + M);
	UnionFind uf(N);

	rep(i, 0, M)
	{
		if (!uf.same(edges[i].s, edges[i].t))
		{
			ans += edges[i].w;
			uf.unite(edges[i].s, edges[i].t);
		}
	}

	printf("%.3lf\n", ans);

	return 0;
}


Measured memory_bytes: 5120
N=int(input())
ls=[int(s) for s in input().split()]
k=max(ls)
ls2=[0 for i in range(k+1)]
for e in ls:
  ls2[e]+=1
if ls2[0]!=1 or ls[0]!=0:
  print(0)
else:
  ans=1
  for i in range(1,k):
    for j in range(ls2[i+1]):
      ans=(ans*ls2[i])%998244353
  print(ans)


Measured memory_bytes: 56044
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;
//ここから

void solve(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  string t=s;
  int cnt=0;
  rep(i,n){
    if(s[i]=='(')++cnt;
    else {
      cnt--;
      if(cnt<0)t="("+t,cnt=0;
    }
  }
  cnt=0;
  for(int i=n-1;i>=0;--i){
    if(s[i]==')')++cnt;
    else {
      cnt--;
      if(cnt<0)t+=")",cnt=0;
    }
  }
  cout<<t;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int N,A,B,C,D;
    scanf("%d",&N); scanf("%d",&A); scanf("%d",&B); scanf("%d",&C); scanf("%d",&D);
    int X=0,Y=0,SUMX=0,SUMY=0;
    while (N>SUMX)
    {
        SUMX+=A;
        X+=B;
    }
    while (N>SUMY)
    {
        SUMY+=C;
        Y+=D;
    }
    if(X>Y) printf("%d\n",Y);
    else printf("%d\n",X);

    return(0);
    
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
ll ex(ll x) {
	ll res = x / 10;
	x /= 10;
	while (x > 0)
	{
		res += x / 5;
		x /= 5;
	}
	
	return res;
}


int main() {
	ll n;
	cin >> n;
	if (n % 2 != 0) {
		cout << 0 << endl;
		return 0;
	}

	cout << ex(n) << endl;
	
	return 0;
}

Measured memory_bytes: 3636
from sys import stdin, stdout
_write = stdout.write
_readline = stdin.readline

n = int(_readline())
d = dict()

for i, line in enumerate(stdin, 1):
  s, p = line.strip().split()
  k = s.ljust(10, ' ') + str(100 - int(p)).zfill(3)
  d[k] = i

for k in sorted(d.keys())[:n]:
  _write(str(d[k]) + '\n')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<climits>
using namespace std;
static const int MAX=100000;
static const long long INFTY = (1LL<<29);

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;
int indeg[MAX];
void bfs(int s)
{
  queue<int> q;
  q.push(s);
  V[s]=true;
  while(!q.empty())
    {
      int u=q.front();q.pop();
      out.push_back(u);
      for(int i=0;i<G[u].size();i++)
	{
	  int v = G[u][i];
	  indeg[v]--;
	  if(indeg[v] == 0 && !V[v])
	    {
	      V[v]=true;
	      q.push(v);
	    }
	}
    }
}

void tsort()
{
  for (int i=0;i<N;i++)
    {
      indeg[i]=0;
    }
  for(int u=0;u<N;u++)
    {
      for(int i=0;i< G[u].size();i++)
	{
	  int v=G[u][i];
	  indeg[v]++;
	}
    }
  for(int u=0;u<N;u++)
    if(indeg[u]==0 && !V[u])bfs(u);
  
  for(list<int>::iterator it = out.begin(); it != out.end();it++)
    {
      cout << *it << endl;
    }
}

int main()
{
  int s,t,M;
  cin >> N >> M;
  
  for(int i=0;i<N;i++) V[i]=false;
  for(int i=0;i<M;i++)
    {
      cin >> s >> t;
      G[s].push_back(t);
    }
  tsort();
  return 0;
}

Measured memory_bytes: 6168
#入力を受け取る
A = int(input()) #500円玉の枚数
B = int(input()) #100円玉の枚数
C = int(input()) #50円玉の枚数
X = int(input()) #合計金額

#通り数をインクリメントさせる変数
pattern = 0

#A,B,Cそれぞれ最大までfor文で3重に回す
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                pattern += 1

print(pattern)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const int md=1000000007;
int n,i,a[100100],b[100100],c[100100];
long long r;
int main() {
  scanf("%d",&n);
  for (i=0; i<n; i++) {
    scanf("%d",&a[i]);
    if (i==0 || a[i]!=a[i-1]) c[i]=a[i];
  }
  for (i=0; i<n; i++) {
    scanf("%d",&b[i]);
    if (i>0 && b[i-1]!=b[i]) {
      if (c[i-1]!=0 && c[i-1]!=b[i-1]) { puts("0"); return 0; }
      c[i-1]=b[i-1];
    }
    if (c[i]>b[i]) { puts("0"); return 0; }
  }
  if (c[n-1]!=0 && c[n-1]!=b[n-1]) { puts("0"); return 0; }
  c[n-1]=b[n-1];
  for (r=1, i=0; i<n; i++) if (c[i]==0) r=(r*min(a[i],b[i]))%md;
  printf("%d\n",int(r));
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
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 n; 
long long a[202020];

int main(){
  cin >> n;
  long long right = 0,  res = 1e18;
  rep(i, n){
    cin >> a[i];
    right += a[i];
  }
  long long left = 0;
  rep(i, n){
    //cerr << left << " " << right << " " << abs(right - left) << endl;
    chmin(res, abs(right - left));
    left += a[i];
    right-= a[i];
  }
  cout << res << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  int a,b;
  cin >>a>>b;
  
  cout << max(a-2*b,0) << endl; 
  
}


Measured memory_bytes: 256
N, K = map(int, input().split())
p = list(map(int, input().split()))

a = [0 for _ in range(N+1)]

for i in range(N):
    a[i+1] = (1+p[i])/2 + a[i]

ans = 0

for i in range(N-K+1):
    ans = max(ans, a[i+K]-a[i])

# print(a)
print(ans)

Measured memory_bytes: 24808
#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(){
  
  string s;
  cin >> s;
  
  int l = s.length();
  if(s[l-1] != 's') s += "s";
  else s += "es";
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <sstream>
#include <string>

using namespace std;

void solve() {
    int n;
    cin >> n;
    cin.ignore();
    vector<int> in, c;
    in.reserve(n);
    c.reserve(n);
    for (int i = 0; i < n; i++)
      c[i] = 0;

    string r;
    getline(cin, r);
    istringstream iss(r);

    for(int i=0; i<n-1; i++) {
      iss >> in[i];
      c[in[i] - 1]++;
    }

    for(int i=0; i<n; i++) cout << c[i] << endl;

}

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


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

const int N = 5e5 + 5, Sigma = 27, bzmax = 20; 

int n, q;
char s[N];
int nxt[N][Sigma], bz[N][bzmax];

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	scanf("%d", &q);
	fill(nxt[n + 1], nxt[n + 1] + Sigma, N);
	fill(bz[n + 1], bz[n + 1] + bzmax, N);
	for (int i = n; i; i--) {
		int c = s[i] - 'a';
		nxt[i][c] = i + 1;
		for (int j = c + 1; j < Sigma; j++) {
			nxt[i][j] = nxt[i][j - 1] == N ? N : nxt[nxt[i][j - 1]][j - 1];	
		}
		int p = nxt[i][26];
		for (int j = c; j--; ) {
			nxt[i][j] = p == N ? N : nxt[p][j];
		}
		bz[i][0] = p;
		for (int j = 1; j < bzmax; j++) {
			bz[i][j] = bz[i][j - 1] == N ? N : bz[bz[i][j - 1]][j - 1];
		}
	}
	int l, r;
	while (q--) {
		scanf("%d%d", &l, &r);
		++r;
		for (int i = bzmax; i--; ) {
			if (bz[l][i] <= r) {
				l = bz[l][i];
			}
		}
		puts(l == r ? "Yes" : "No");
	}
	return 0;
}


Measured memory_bytes: 92928
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

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

func scanInts(n int) []int {
	sl := make([]int, n)
	for i := range sl {
		sl[i] = scanInt()
	}
	return sl
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, x := scanInt(), scanInt()
	cs := scanInts(n)

	d := abs(cs[0] - x)
	for i := 1; i < n; i++ {
		d = gcd(d, abs(cs[i]-x))
	}

	fmt.Println(d)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


Measured memory_bytes: 4128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,K;
  cin >> A >> B >> C;
  cin >> K;
  for(int i = 0; i < K; i++){
    if(A >= B) B *= 2;
    else if(B >= C) C *= 2;
    if(A < B && B < C) break;
  }
  if(A < B && B < C) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>

using namespace std;
int main(void) {
    vector<char> vowels(5);
    vowels.at(0) = 'a';
    vowels.at(1) = 'e';
    vowels.at(2) = 'i';
    vowels.at(3) = 'u';
    vowels.at(4) = 'o';

    char c;
    cin >> c;

    for (char vowel : vowels) {
        if (vowel == c) {
            cout << "vowel" << endl;
            return 0;
        }
    }
    cout << "consonant" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    int N;
    int64_t D;
    cin >> N >> D;

    int ans = 0;
    while(N--) {
        int64_t X, Y;
        cin >> X >> Y;
        if(X*X + Y*Y <= D*D) ++ans;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>

void func(int *,int *,int);
int n,b[2000001],c[2000001];

int main(){
  int k=0,i,j;
  int a[2000001];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i+1]);
    if(k < a[i]) k = a[i];
  }

  func(a,b,k);

  return 0;
}

void func(int *a,int *b,int k){
  int i,j;
  for(i=0;i<=k;i++){
    c[i]=0;
  }
  for(j=1;j<=n;j++){
    c[a[j]]++;
  }
  for(i=1;i<=k;i++){
      c[i]=c[i]+c[i-1];
  }
  for(j=n;j>0;j--){
    b[c[a[j]]] = a[j];
    c[a[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i>1) printf(" ");
    printf("%d",b[i]);
  }
  printf("\n");
}



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

int main(){
    int A, B;
    cin >> A >> B;
    
    if ((A + B) % 2 == 0) {
        cout << (A + B) / 2 << '\n';
    } else {
        cout << "IMPOSSIBLE" << '\n';
    }
    return 0;
}

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

typedef long long int ll;


int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<pair<ll,ll>> cb(m);
    for(ll i = 0;i < n;i++){
       cin >> a[i];
    }
    for(ll i = 0;i < m;i++){
       cin >> cb[i].second >> cb[i].first;
    }

    sort(a.begin(), a.end());
    sort(cb.begin(), cb.end());

    ll ans = 0, t = cb.size() - 1;
    for(ll i = 0;i < n;i++){
        if(a[i] < cb[t].first && t != -1){
            ans += cb[t].first;
            cb[t].second--;
        }
        else{
            ans += a[i];
        }
        if(cb[t].second == 0){
            t--;
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 2560
from collections import deque
s = deque(input())
q = int(input())

flag = 1
for i in range(q):
  st = input().split()
  if int(st[0]) == 1:
    flag *= -1
  else:
    tmp = int(st[1])*flag
    if tmp == 1 or tmp == -2:
      s.appendleft(st[2])
    else:
      s.append(st[2])

if flag == -1:
  s.reverse()
print(''.join(s))

Measured memory_bytes: 74840
N = int(input())
A = int(input())

N_new = N%1000

if N_new<=A:
    print("Yes")
else:
    if N_new>=500:
        N_new -= 500
        if N_new<=A:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 2940
// ABC089
// A - Grouping 2

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

int N;

int main() {
    cin >> N;
    cout << N / 3 << endl;

    return 0;
}


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

int main(){
	int a,b;
  	cin >> a;
  	cin >> b;
  	int c = b-a+1;
  	for(int i=0;i<2*a-1;i++){
    	cout << c;
      	if(i!=2*a-2){cout << " ";}
      	c++;
    }
  	cout << endl;
  	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define A 2019
typedef long long ll;
int main(){
	int l,r,al,ar,t;
	ll ans=A;
	cin>>l>>r;
	al=l%A;
	ar=r%A;
	if((al==0)||(ar==0)||(r>=(l+A-al))){
		ans=0;
	}else{
		for(int i=l;i<r;i++){
			for(int k=i+1;k<=r;k++){
				t=((i%A)*(k%A))%A;
				if(t<ans){
					ans=t;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}	

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=500005,mod=998244353;
int n,m,d,ans,fact[N],inv[N],pwn[N],pwm[N];
inline void inc(int& x,CI y)
{
	if ((x+=y)>=mod) x-=mod;
}
inline void dec(int& x,CI y)
{
	if ((x-=y)<0) x+=mod;
}
inline int quick_pow(int x,int p=mod-2,int mul=1)
{
	for (;p;p>>=1,x=1LL*x*x%mod) if (p&1) mul=1LL*mul*x%mod; return mul;
}
inline void init(CI n,CI m)
{
	RI i; for (fact[0]=i=1;i<=m;++i) fact[i]=1LL*fact[i-1]*i%mod;
	for (inv[m]=quick_pow(fact[m]),i=m-1;~i;--i) inv[i]=1LL*inv[i+1]*(i+1)%mod;
	for (pwn[0]=i=1;i<=m;++i) pwn[i]=1LL*pwn[i-1]*(n+1)%mod;
	for (pwm[0]=i=1;i<=m;++i) pwm[i]=1LL*pwm[i-1]*(m+1)%mod;
}
inline int C(CI n,CI m)
{
	return 1LL*fact[n]*inv[m]%mod*inv[n-m]%mod;
}
inline int A(CI n,CI m)
{
	return 1LL*fact[n]*inv[n-m]%mod;
}
int main()
{
	scanf("%d%d",&n,&m); if (n>m) swap(n,m);
	init(n,m); for (RI i=0;i<=n;++i)
	{
		int d=1LL*C(n,i)*A(m,i)%mod*pwm[n-i]%mod*pwn[m-i]%mod;
		if (i&1) dec(ans,d); else inc(ans,d);
	}
	return printf("%d",ans),0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <float.h>
#include <stdlib.h>
#include <functional>
using namespace std;
int main(){
    int x,y,z;
    cin >>x >>y >>z;
    cout <<z << " " <<x << " " <<y;
}


Measured memory_bytes: 256