akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) _OUTPUT_IMPL_(__VA_ARGS__)

int main() {
	in(string, a, b, c);
	YESNO(a.back() == b.front() && b.back() == c.front());
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
time_list = [int(input()) for i in range(5)]
amari = []

for i in range(5):
    amari.append([time_list[i] // 10, time_list[i] % 10])
    
small = 9
number = 0
for i in range(5):
    if amari[i][1] > 0 and amari[i][1] < small:
        small = amari[i][1]
        number = i
        
total_time = 0
for i in range(5):
    if i != number:
        if amari[i][1] == 0:
            total_time += amari[i][0] * 10
        else:
            total_time += amari[i][0] * 10 + 10
    else:
        total_time += time_list[i]
        
print(total_time)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(void){
    int n;cin>>n;
    vector<int>V(n);rep(i,n)cin>>V[i];
    if(n%2==1){
        int x=(n+1)/2-1;
        rep(i,n){
            if(i<=x)cout<<V[n-i*2-1]<<' ';
            else cout<<V[2*(i-x)-1]<<' ';
        }
    }
    else{
        int x=n/2-1;
        rep(i,n){
            if(i<=x)cout<<V[n-1-i*2]<<' ';
            else cout<<V[2*(i-x)-2]<<' ';
        }
    }
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  string N;
  cin >> N;
  long long sum = 0;
  for(int i = 0; i < N.size(); i++){
    sum += (int)(N[i] - '0');
  }
  if(sum % 9 == 0){
    cout << "Yes" <<endl;
  } else{
    cout << "No" <<endl;
  }
}


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

signed main(){
  int R,G;
  cin>>R>>G;
  cout<<G+(G-R)<<endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <unordered_map>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long int

using namespace std;

int main()
{
  string keyence = "keyence";
  string s;
  cin >> s;
  bool flag = false;

  if (s.substr(0, 7) == keyence)
    flag = true;
  if (s.substr(s.length() - 7, 7) == keyence)
    flag = true;

  int i = 0;
  while (s[i] == keyence[i])
  {
    i++;
  }
  while (s[s.length() - (7 - i)] == keyence[7 - (7 - i)] && i < 7)
  {
    i++;
  }

  if (i == 7)
    flag = true;

  if (flag)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>

/*
 *変数
 */
int a,b;

/*
 *解 
 */
void solve(){
    printf("%d",(a-1)*(b-1));
}

/*
 *入力 
 */
int main(){
       std::cin.tie(0);
       std::ios::sync_with_stdio(false);
       std::cin>>a>>b;
       solve();
       return 0;
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()

	ans := int64(math.Ceil((-1 + math.Sqrt(1+8*float64(N))) / 2))
	out(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long
#define int long long
#define ld long double
#define endl '\n'
const int mod= 1e9+7;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define trace(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
#define reset(x,val) memset(x,val,sizeof(x))
#define flush fflush(stdout)
#define sz(a) a.size()
#define pii pair<int,int>
using namespace std;
const int N=1e3+3;
int dp[N][N],n,m;
char g[N][N];
int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    cin>>g[i][j];
    
    dp[1][1]=1;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    {
     if(i==1 && j==1)continue;
     if(g[i][j]=='#')continue;
     dp[i][j]=(dp[i-1][j]+dp[i][j-1]);
     if(dp[i][j]>=mod)dp[i][j]-=mod;
    }
    cout<<dp[n][m]<<endl;
    return 0;
}



Measured memory_bytes: 9088
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int mod = 924844033;
const int N = 200005; 
using namespace std;

int m, lim, n, g, ig, p[105], cnt, f[N * 8], inv[2 * N], fac[2 * N], h[N * 8], sz[N], head[N], rev[N * 8];
struct edge { int to, nxt; } e[N << 1]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

inline void adde(int u, int v) { e[++cnt] = (edge) { v, head[u] }, head[u] = cnt; }

int fpow(int x, int y)
{
	int res = 1;
	for( ; y; y >>= 1, x = 1ll * x * x % mod)
		if(y & 1) res = 1ll * res * x % mod;
	return res; 
}

int getroot(int x)
{
	int rem = x - 1, tmp = x - 1;
	for(int i = 2; i * i <= rem; i++)
		if(!(tmp % i))
		{
			p[++cnt] = i;
			while(!(tmp % i)) tmp /= i; 
		}
	if(tmp > 1) p[++cnt] = tmp;
	for(int flag = 0, i = 2; i <= x; i++, flag = 0)
	{
		for(int j = 1; j <= cnt; j++)
			if(fpow(i, rem / p[j]) == 1) flag = 1;
		if(!flag) return i; 
	}
}

void pre()
{
	for(int i = (fac[0] = 1); i <= 2 * n; i++)
		fac[i] = 1ll * fac[i - 1] * i % mod; 
	inv[2 * n] = fpow(fac[2 * n], mod - 2); 
	for(int i = 2 * n - 1; i >= 0; i--)
		inv[i] = 1ll * inv[i + 1] * (i + 1) % mod; 
	for(int i = 1; i <= n; i++)
		h[i] = inv[n - i]; 
}

int C(int n, int m) { return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod; }

void dfs(int u, int fa)
{
	sz[u] = 1; 
	for(int v, i = head[u]; i; i = e[i].nxt)
	{
		v = e[i].to; if(v == fa) continue; 
		dfs(v, u), sz[u] += sz[v]; 
	}
	f[sz[u]]++, f[n - sz[u]]++; 
}

void ntt(int *p, int opt)
{
	for(int i = 0; i < n; i++)
		if(i < rev[i]) swap(p[i], p[rev[i]]);
	for(int i = 1; i < n; i <<= 1)
	{
		int rt = fpow(opt == 1 ? g : ig, (mod - 1) / (i << 1));
		for(int j = 0; j < n; j += (i << 1))
		{
			int w = 1;
			for(int k = j; k < j + i; k++, w = 1ll * w * rt % mod)
			{
				int x = p[k], y = 1ll * w * p[k + i] % mod;
				p[k] = (x + y) % mod, p[k + i] = (x - y + mod) % mod; 
			}
		}
	}
}

int main()
{
	n = read <int> (), g = getroot(mod), ig = fpow(g, mod - 2); 
	cnt = 0, pre(); 
	for(int u, v, i = 1; i < n; i++)
	{
		u = read <int> (), v = read <int> (); 
		adde(u, v), adde(v, u); 
	}
	dfs(1, 0); 
	for(m = 3 * n, n = 1; n <= m; n <<= 1, lim++); lim--; 
	for(int i = 0; i < n; i++)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << lim);
	f[m / 3]--;
	for(int i = 0; i < m / 3; i++)
		f[i] = 1ll * f[i] * fac[i] % mod; 
	ntt(f, 1), ntt(h, 1); 
	for(int i = 0; i < n; i++)
		f[i] = 1ll * f[i] * h[i] % mod; 
	ntt(f, -1); 
	int tmp = fpow(n, mod - 2); 
	for(int i = 0; i < n; i++)
		f[i] = 1ll * f[i] * tmp % mod; 
	m /= 3; 
	for(int i = 1; i <= m; i++)
		printf("%lld\n", (1ll * m * C(m, i) % mod - 1ll * inv[i] * f[m + i] % mod + mod) % mod); 
	return 0; 
}


Measured memory_bytes: 34688
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,ans=100000000000,etmp,wtmp;
  string s;
  cin >> n >> s;
  ll esum[n],wsum[n];
  fill(esum,esum+n,0);
  fill(wsum,wsum+n,0);
  for(int i=0;i<n;i++){
    if(i!=0) {
      esum[i]=esum[i-1];
      wsum[i]=wsum[i-1];
    }
    if(s[i]=='E'){
      esum[i]++;
    }else{
      wsum[i]++;
    }
  }
  for(int i=0;i<n;i++){
    etmp=wtmp=0;
    if(i!=0){
      etmp = wsum[i-1];
    }
    wtmp = esum[n-1]-esum[i];
    ans = min(ans,etmp+wtmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 5380
loop{
    h,w = gets.split.map(&:to_i)
    if h == 0 && w == 0
        break
    end
   puts "#" * w
   sum = h - 2
   sum.times{
       r = "#"
       dot = "."
       dod = w - 2
       puts "#{r}#{dot*dod}#{r}"
   }
   puts "#" * w
   puts ""
}


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

using namespace std;
using ll = long long;

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

  int n;
  cin >> n;
  vector<vector<vector<int>>> f(n, vector<vector<int>>(5, vector<int>(2)));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 5; j++)
      for (int k = 0; k < 2; k++)
        cin >> f[i][j][k];
  vector<vector<int>> p(n, vector<int>(11));
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= 10; j++)
      cin >> p[i][j];

  int ans = -1e9;
  for (int b = 1; b < (1 << 10); b++) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      int c = 0;
      for (int j = 0; j < 5; j++) {
        for (int k = 0; k < 2; k++) {
          if (!(b & (1 << (j * 2 + k)))) {
            continue;
          }
          if (f[i][j][k]) {
            c++;
          }
        }
      }
      sum += p[i][c];
    }
    ans = max(ans, sum);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3648
n, a, b, c, d = map(int, input().split())
a, b, c, d = a-1, b-1, c-1, d-1
s = input()

if c < d:
    if "##" in s[a:d]:
        print("No")
        exit()

    print("Yes")

else:
    for i in range(b, d+1):
        if s[i] != "#" and s[i-1] == "." and s[i+1] == ".":
            print("Yes")
            exit()

    print("No")

Measured memory_bytes: 3572
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Objects;
import java.lang.StringBuilder;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int K = sc.nextInt();

    StringBuilder S = new StringBuilder(sc.next());

    char lower = Character.toLowerCase(S.charAt(K - 1));
    S.setCharAt(K - 1, lower);
    System.out.println(S.toString());
  }
}


Measured memory_bytes: 21716
#include <iostream>
#include <cassert>
#include <string.h>
#include <vector>
#include <map>

using namespace std;

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

    vector< vector<int> > matrix;
    for (int i = 0; i < n; ++i)
    {
        vector<int> line;
        for (int j = 0; j < n; ++j)
        {
            line.push_back(0);
        }
        matrix.push_back(line);
    }

    for (int i = 0; i < n; ++i)
    {
        int vertex;
        int degree;

        cin >> vertex;
        cin >> degree;

        assert(vertex <= n);
        assert(degree <= n);

        for (int j = 0; j < degree; ++j)
        {
            int adj;
            cin >> adj;
            assert(adj <= n);
            matrix[vertex - 1][adj - 1] = 1;
        }
    }

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            string delim = (j == (n - 1)) ? "\n" : " ";
            cout << matrix[i][j] << delim;
        }
    }

    return 0;
}


Measured memory_bytes: 3236
N,M = map(int,input().split())
like = range(1,M+1)
if N == 1:
    A = list(map(int, input().split()))
    print(A[0])
else:
    for i in range(N):
        A = list(map(int, input().split()))
        like = set(like).intersection(A[1:])
        like = list(like)
    print(len(like))

Measured memory_bytes: 3060
def main():
    import sys
    import math
    s,t=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    if a[0]<b[0]:
        a,b=b,a
    x=(a[0]-b[0])*s
    y=(a[1]-b[1])*t

    if x+y>0:
        print(0)
        sys.exit()
    elif x+y==0:
        print('infinity')
        sys.exit()

    y=abs(y)
    if x%(y-x)==0: ans=(x//(y-x))*2
    else: ans=math.floor(x/(y-x))*2+1
    print(ans)


 
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define mor > muu & operator << (
#define R22(r) sim > typename \
  enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) {
sim > struct rge { c b, e; };
sim > rge<c> range(c h, c n) { return {h, n}; }
sim > auto dud(c* r) -> decltype(cerr << *r);
sim > char dud(...);
struct muu {
#ifdef LOCAL
stringstream a;
~muu() { cerr << a.str() << endl; }
R22(<) a << boolalpha << g; ris; }
R22(==) ris << range(begin(g), end(g)); }
sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; }
sim mor rge<c> u) {
  a << "[";
  for (c i = u.b; i != u.e; ++i)
    *this << ", " + 2 * (i == u.b) << *i;
  ris << "]";
}
#else
sim mor const c&) { ris; }
#endif
muu & operator()() { ris; }
};
#define imie(r...) "[" #r ": " << (r) << "] "
#define imask(r...) "[" #r ": " << bitset<8 * sizeof(r)>(r) << "] "
#define arr(a, i) "[" #a imie(i) ": " << a[i] << "] "
#define arr2(a, i, j) "[" #a imie(i) imie(j) ": " << a[i][j] << "] "
#define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")

const int N = 27;
int tab[N];
int n;
const int mod = 1e9 + 7;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int pp;
            scanf("%d", &pp);
            if (pp) tab[i] |= (1 << j);
        }
    }
    
    long long wynik = 0;
    for (int x = 0; x < (1 << n); ++x) {
        long long pom = 1;
        for (int i = 0; i < n; ++i) {
            int ile = __builtin_popcount(tab[i] & (~x));
            //~ for (int j = 0; j < n; ++j) {
                //~ if (tab[i][j] && ((x & (1 << j)) == 0)) ile++; 
            //~ }
            pom = (pom * ile) % mod;
        }
        if (__builtin_popcount(x) % 2 == 1) wynik -= pom;
        else wynik += pom;
    }
    
    wynik = (wynik % mod + mod) % mod;
    printf("%lld\n", wynik);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
        long long a, b, c;
        scanf("%lld %lld %lld", &a, &b, &c);
        if(c-a-b>=0 &&  4*a*b<(c-a-b)*(c-a-b)) puts("Yes");
        else puts("No");
        return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

 
    
    
int main()
{
   long int n=0,r=0,g=0,b=0,sum=0,dis=0;
   string s;
   cin>>n>>s;
   for ( int i = 0; i < n; i++)
   {
     switch ((int)s[i])
      {
      case 82:
        r++;
        break;
      case 71:
          g++;
        break;
      case 66:
          b++;
        break;
     }
   }
     sum=r*g*b;
     for (int i=0;i<n;i++)
     {
       for (int loop=1;i+2*loop<n;loop++)
       { 
         if ((int)s[i]+(int)s[i+loop]+(int)s[i+2*loop]==219)
         {
             sum--;
         }
       }
     }
   
   cout<<sum<<endl;
  
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };

int dp[1010][1010];
string s1, s2;

void chmin(int &a, int b) {
	if (a == -1)a = b;
	else if (a > b)a = b;
}

int main() {
	cin >> s1 >> s2;

	memset(dp, -1, sizeof(dp));
	rep(i, 0, 1010) {
		dp[0][i] = i;
		dp[i][0] = i;
	}

	rep(i, 0, s1.size()+1)rep(j, 0, s2.size()+1) {
		if (dp[i][j] == -1)continue;

		chmin(dp[i+1][j],dp[i][j]+1);
		chmin(dp[i][j+1],dp[i][j]+1);
		if (i != s1.size() && j != s2.size()) {
			int c = 1;
			if (s1[i] == s2[j])c = 0;
			chmin(dp[i + 1][j + 1], dp[i][j] + c);
		}
	}

	cout << dp[s1.size()][s2.size()] << endl;

	return 0;
}


Measured memory_bytes: 7144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int maxn = 1e5+5;
const int md = 1e9+7;
ll a[maxn];
ll mul(ll u,ll v)
{
	return (u*v)%md;
}
ll sum(ll u,ll v)
{
	return (u+v)%md;
}
int f[maxn],rf[maxn],re,n,k;
ll pww(ll u,ll v)
{
	ll re=1;
	for(int i=0;i<40;i++)
	{
		if(v&(1LL<<i))re=mul(re,u);
		u=mul(u,u);
	}
	return re;
}
ll mnn(ll u,ll v)
{
	return (u-v+md)%md;
}
int32_t main()
{
	cin>>n>>k;
	f[0]=1;
	for(int i=1;i<=n;i++)
	{
		f[i]=mul(i,f[i-1]);
	}
	rf[n]=pww(f[n],md-2);
	for(int i=n-1;i>=0;i--)
	{
		rf[i]=mul(i+1,rf[i+1]);
	}
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++)if(n-i>=k)
	{
		re=mnn(re,mul((a[i]+md)%md,mul(f[n-i-1],mul(rf[k-1],rf[n-i-k]))));
	}
	for(int i=n-1;i>=0;i--)if(i+1>=k)
	{
		re=sum(re,mul((a[i]+md)%md,mul(f[i],mul(rf[k-1],rf[i-k+1]))));
	}
	cout<<re;
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main(){
  int l,c,i;
  char s[100];
  scanf("%s",s);
  for(l=0;s[l];l++);
  for(i=c=0;i<l/2;i++){//printf("%c %c %d\n",s[i],s[l-i-1],c);
    if(s[i]+s[l-i-1]=='('+')')continue;
    if(s[i]=='('||s[i]==')'||s[i]-s[l-i-1])c++;
  }//printf("%d %d\n",c,l);
  if(l%2&&(s[i]=='('||s[i]==')'))c++;
  printf("%d\n",c);
  return 0;
}
		       

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

typedef long long ll;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	const int N = 1e5;
	int n,x;
	cin >> n >> x;
	int a[n];
	for(int i = 0;i < n; ++i){
		cin >> a[i];	
	}
	ll ans = 0;
	for(int i = 0; i < n-1; ++i){
		if(a[i] + a[i+1] > x){
			int rem = a[i] + a[i+1] - x;
			ans += rem;
			if(a[i+1] >= rem){
				a[i+1]-=rem;
				rem = 0;
			}
			else{
				rem -= a[i+1];
				a[i+1] = 0;
				a[i] -= rem;
				rem = 0;
			}
		}
	}
	cout << ans << '\n';
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    int n;
    ll ans = 0;
    cin >> n;
    for(ll i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3672
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner bala= new Scanner(System.in);
		while(bala.hasNext()) {
			int a = bala.nextInt();
			int b = bala.nextInt();
			int res = a + b;
			String cad = res + "";
			System.out.println(cad.length());
		}
	}
}

Measured memory_bytes: 12000
import java.util.*;
public class Main {
    public static void main(String[] args){

        long NUM=2019;
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int L=sc.nextInt();
        int R=(sc.nextInt()-L);
        if(R>=2019){
            System.out.println(0);
            return;

        }
        L=L%2019;
        R=R+L+1;
        int result=2019*2019;
        for(int i=L;i<R;i++){
            for(int j=i+1;j<R;j++){
                int a=(i*j)%2019;
                if(a<result){
                    result=a;
                }
            }
        }

        System.out.println(result);


    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
int main() {
  cout << fixed << setprecision(30);
string s,t;
  cin>>s>>t;
  putout(t+s);
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
import java.awt.Point;

class Main{

    public static class Pox{
	public int id,time,difficulty;
	Pox(){
	    id = time = difficulty = 0;
	}

	Pox(int a,int b,int c){
	    id = a;
	    time = b;
	    difficulty = c;
	}

    }

    public static void main(String args[])throws IOException{
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  
	while(true)
	      {
		  int n,m;
		  String line = in.readLine();
		
		  List<Integer> list = new ArrayList<Integer>();
		  List<Integer> list2 = new ArrayList<Integer>();

		  n = Integer.parseInt(line.substring(0,line.indexOf(" ")));
		  m = Integer.parseInt(line.substring(line.indexOf(" ")+1));
		  
		  if(n == 0 && m == 0)
		      break;		  

		  String[] elements = in.readLine().split(" ");    

		  for(int i=0;i<elements.length;i++)
		      {
			  list.add(Integer.parseInt(elements[i]));
		      }

		  int pre = m;
		  int men = 100000000;
		  List<Pox> list3 = new ArrayList<Pox>();

		  for(int i=0;i<list.size();i++)
		      {
			
			  if(pre >= m/list.get(i)*list.get(i))
			      {
				  list2.add(m/list.get(i)*list.get(i));
				  pre = m/list.get(i)*list.get(i);
				  men = Math.min(men,pre);
				  list3.add(new Pox(i,pre,list.get(i)));
			      }
			  else
			      {
				  int val = list.get(i);
				  int cnt = val;
				  while(val*cnt < pre)
				      {
					  cnt++;
				      }
			
				  list2.add(val*cnt);
				  pre = val*cnt;
				  men = Math.min(men,pre);
				  list3.add(new Pox(i,pre,val));
			      }
			 
		      }

		  Collections.sort(list3,new Comparator<Pox>(){

			  @Override
			      public int compare(Pox a,Pox b){
			      if(a.time != b.time)
				  {
				      if(a.time > b.time)
					  return 1;
				      else 
					  return -1;
				  }
			      if(a.difficulty != b.difficulty)
				  {
				      if(a.difficulty > b.difficulty)
					  return 1;
				      else
					  return -1;
				  }
			      return -1;
			  }
		      });

		  if(list3.get(0).time != list3.get(1).time)
		      {
			  System.out.println(list3.get(0).id+1);
		      }
		  else if(list3.get(0).difficulty != list3.get(1).difficulty)
		      {
			  System.out.println(list3.get(0).id+1);
		      }
		  else
		      {
			  System.out.println(n);
		      }


	      }
      }

}

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

using namespace std;

using ll = long long;

int main() {
  const int sqrtN = 512;
  const ll inf = (1LL<<31)-1;
  int n, q;
  cin >> n >> q;
  int bucket_sz = (n+sqrtN-1)/sqrtN;
  vector<ll> a(n, inf);
  vector<ll> bucketUp(bucket_sz, 0);
  vector<bool> bucketFlag(bucket_sz, false);
  auto push = [&](int k) {
    bucketFlag[k] = false;
    int l = k*sqrtN, r = (k+1)*sqrtN;
    for(int i = l; i < r; ++i) a[i] = bucketUp[k];
  };
  auto update = [&](int s, int t, int x) {
    for(int i = 0; i < bucket_sz; ++i) {
      int l = i*sqrtN, r = (i+1)*sqrtN;
      if(r <= s || t <= l) continue;
      if(s <= l && r <= t) {
	bucketUp[i] = x;
	bucketFlag[i] = true;
      } else {
	if(bucketFlag[i]) push(i);
	for(int j = max(s, l); j < min(t, r); ++j) {
	  a[j] = x;
	}
      }
    }
  };
  auto get = [&](int k)->ll{
    if(bucketFlag[k/sqrtN]) push(k/sqrtN);
    return a[k];
  };
  while(q--) {
    int t;
    cin >> t;
    if(t == 0) {
      ll s, t, x;
      cin >> s >> t >> x;
      update(s, t+1, x);
    } else {
      int k;
      cin >> k;
      cout << get(k) << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}
int sum[100010];
int b;

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[100010];
    fact();
    rep(i, N) cin >> a[i];
    rep(i, N) b = (b + a[i] )% mod;
    sum[0] = 1;
    rep(i, 100000) {
        sum[i + 1] += sum[i] + Div(1, i + 2);
    }
    int ans = 0;
    rep(i, N) {
        ans = (ans + Mul(F[N], Mul(a[i], sum[i] + sum[N - i - 1] - 1)) + mod) % mod;
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 18176
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
    int in, i;
    char line[256];

    for (i=1;; i++) {

        memset(line, 0, sizeof(line));
        if (!fgets(line, sizeof(line), stdin)) {
            // fprintf(stderr, "error input val\n");
            // return -1;
            ;
        }

        if (sscanf(line, "%d", &in) != 1) {
            //      fprintf(stderr, "error input format\n");
            //      return -1;
            ;
        }

        if (!in) {
            break;
        }
        printf("Case %d: %d\n", i, in);
    }

    return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;

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

int main(){
    int k;
    cin >> k;
    int ans = 0;
    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= k; j++){
            for(int l = 1; l <= k; l++){
                ans += gcd(gcd(i, j), l);
            }
        }
    }
    cout << ans << endl;
}






Measured memory_bytes: 3660
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

int main(int argc, char *argv[]) {
	int x;
	char s[100];
	stack<int> st;
	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			int t1 = st.top();
			st.pop();
			int t2 = st.top();
			st.pop();
			st.push(t1 + t2);
		}else if (s[0] == '-') {
			int t1 = st.top();
			st.pop();
			int t2 = st.top();
			st.pop();
			st.push(t2 - t1);
		}else if (s[0] == '*') {
			int t1 = st.top();
			st.pop();
			int t2 = st.top();
			st.pop();
			st.push(t1 * t2);
		}else {
			x = atoi(s);
			st.push(x);
		}
	}
	printf("%d\n", st.top());
	st.pop();
	return 0;
}


Measured memory_bytes: 3224
#include <stdio.h>
int main(void){
    int L,M[12],N[12];
    int i,tot;
    
    while(1){
        scanf("%d",&L);
        if(L==0){
            break;
        }
        tot=0;
        
        for(i=0;i<12;i++){
            scanf("%d %d",&M[i],&N[i]);
        }
        for(i=0;i<12;i++){
            tot+=M[i]-N[i];
            if(tot>=L){
                printf("%d\n",i+1);
                break;
            }
        }
        if(i==12){
            puts("NA");
        }
    }
    
    return 0;
}

Measured memory_bytes: 612
import java.util.Scanner;
public class Main{
	int x;
	public void solve(){
		Scanner sc = new Scanner(System.in);
		x=sc.nextInt();
		System.out.println(x*x*x);
	}
	public static void main (String[] args){
		Main obj = new Main();
		obj.solve();
	}
}

Measured memory_bytes: 17348
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

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

    ll ans=1e18;
    for(int bit = 0; bit<(1<<n-1); bit++){
        if(__builtin_popcount(bit) != k-1) continue;
        ll s=0;
        ll h=a[0];
        bool flag = true;

        for(int i=1; i<n; i++){
            if(((bit >> i-1) & 1)){
                if(a[i]>h){
                    h=a[i];
                } else {
                    s += h+1-a[i];
                    h += 1;
                }
            } else {
                if (a[i]>h) {
                    flag = false;
                    break;
                }
            }
        }
        if(flag) ans = min(ans,s);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  n=n%10;
  if(n==3){
    cout << "bon" << endl;
  }else if(n==0||n==1||n==6||n==8){
    cout << "pon" << endl;
  }else{
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll N, R;
  cin >> N >> R;

  if (N >= 10) {
    COUT(R);
  } else {
    ll rate = R + 100 * (10 - N);
    COUT(rate);
  }
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(S: str):
    N = len(S)
    # 0:文字列の総数 1:Aの数  2:ABの数 3:ABCの数
    ## dp[i][j] = i文字目まで見たときに状態jの数
    ## answer: dp[N][3]

    dp = [[0]*4 for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        for j in (0,1,2,3):
            if S[i] == "?":
                dp[i+1][j] += dp[i][j]*3
            else:
                dp[i+1][j] += dp[i][j]

            dp[i+1][j]%=MOD
            
        ## カウント進める場合
        if S[i] == "A" or S[i] == "?":
            dp[i+1][1] += dp[i][0]
            # dp[i+1][1] %= MOD
        
        if S[i] == "B" or S[i] == "?":
            dp[i+1][2] += dp[i][1]
            # dp[i+1][2] %= MOD

        if S[i] == "C" or S[i] == "?":
            dp[i+1][3] += dp[i][2]
            # dp[i+1][3] %= MOD

    print(dp[N][3]%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ll mod = 1000000007;

int main(void)
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<vector<int>> hist(10);
	rep(i, n) {
		int t = s[i] - '0';
		hist[t].push_back(i);
	}
	unordered_set<int> v;
	for (int i = 0; i < 1000; i++) {
		int ns[3];
		int c = i;
		for (int d = 0; d < 3; d++) {
			ns[3 - 1 - d] = c % 10;
			c /= 10;
		}
		int current = -1;
		bool ok = true;
		for (int j = 0; j < 3; j++) {
			auto& h = hist[ns[j]];
			auto p = upper_bound(h.begin(), h.end(), current);
			if (p == h.end()) {
				ok = false;
				break;
			}
			current = *p;
		}
		if (ok) {
			//cout << i << endl;
			v.insert(i);
		}
	}
	cout << v.size() << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-8;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}


int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n;cin>>n;
    ll a[n+1];
    rep(i,0,n+1)cin>>a[i];
    ll jou[n+1];
    fill(jou,jou+n+1,inf);
    jou[0]=1;
    rep(i,1,n+1){
        if(a[i-1]>=jou[i-1]){
            cout<<-1<<endl;
            return 0;
        }
        ll u=jou[i-1]-a[i-1];
        u*=2;
        jou[i]=u;
        if(jou[i]>=inf)break;
    }
    if(a[n]>jou[n]){
        cout<<-1<<endl;
        return 0;
    }
    ll now=a[n];
    ll ans=a[n];
    rrep(i,n-1,0){
        now+=a[i];
        if(now>jou[i])now=jou[i];
        ans+=now;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5152
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;


int main(){
    int n;
    scanf("%d", &n);
    vector<pair<int, int> > v;
    for(int i = 0 ; i < n ; ++i){
        int x, y;
        scanf("%d%d", &x, &y);
        v.emplace_back(y, -x);
    }
    sort(v.begin(), v.end());
    int nw = 0;
    for(auto p : v){
        int dead = p.first;
        int tim = -p.second;
        if(tim + nw > dead){
            puts("No");
            return 0;
        }
        nw += tim;
    }
    puts("Yes");
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
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; }
const ll INF = 1LL << 60;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};


//combination mod prime
//https://marycore.jp/prog/cpp/member-initializer-list/ メンバ初期化子

struct combination{
    vector<mint> fact, ifact;
    //メンバ初期化指定子
    combination(int n):fact(n+1),ifact(n+1){
        fact[0]=1;
        for(int i=1; i<=n; i++) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for(int i=n; i>=1; i--) ifact[i-1] = ifact[i]*i;
    }
    //関数呼び出し時の定義
    mint operator()(int n, int k) {
        if (k<0 || k>n) return 0;
        return fact[n]*ifact[n-k]*ifact[k];
    }
};
int main(){
    int x,y; cin >> x >> y;
    if((2*x-y)%3!=0 || (2*y-x)%3!=0){
        cout << 0 << endl;
        return 0;
    }
    int a = (2*y-x)/3;
    int b = (2*x-y)/3;

    combination c(a+b);
    mint ans = c(a+b,a);

    cout << ans.x << endl;

    return 0;
}

Measured memory_bytes: 10624
#include <stdio.h>

int main(void)
{
	int w, h, x, y, r;

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

	return 0;
}

Measured memory_bytes: 580
#include <iostream>

using namespace std;

int main() {

  int sum;
  int price[10];

  int rest;

  
  while(1) {

    cin >> sum;

    if(sum==0) break;

    for(int i=0;i<9;i++) cin >> price[i];

    rest=sum;

    for(int i=0;i<9;i++) rest-=price[i];

    cout << rest << endl;

  }

  return 0;

}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()
#define foreach(c,it) for(typeof(c.begin()) it=c.begin();it!=c.end();++it)

int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dy[] = {1, 1, 1, 0, 0, -1, -1, -1};
const int MAXH = 10, MAXW = 20;
char tile[MAXW][MAXH];
int checked[MAXW][MAXH];
typedef pair<int, string> p;
int main()
{
    int w, h;
    while(cin >> h >> w && h)
    {
        rep(j,h)rep(i,w){ cin >> tile[i][j];}
        
        vector<p> ans;
        rep(sx,w)rep(sy,h)rep(v,8)
        {
            memset(checked, 0, sizeof(checked));
            int x = sx, y = sy;
            string s;
            while(!checked[x][y])
            {
                //cout << x << " " << y << endl;
                s += tile[x][y];
                ans.push_back(p( -s.size(), s));
                checked[x][y] = 1;
                x += dx[v]; y += dy[v];
                if(x == w) x = 0;
                if(x == -1) x = w - 1;
                if(y == h) y = 0;
                if(y == -1) y = h - 1;

            }
        }
        sort(all(ans));
        int found = 0;
        for(int i = 0; i < ans.size() - 1; i++)if(ans[i] == ans[i + 1] && ans[i].first <= -2)
        {
            cout << ans[i].second << endl;
            found = 1;
            break;
        }
        if(!found) cout << 0 << endl;

    }
    return 0;
}

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

int main(){
    long long int K,N; cin>>K>>N;
    vector<long long int> A(N,0);
    vector<long long int> sa(N,0);
    long long ans=0;
    for(long long int i=0;i<N;i++){
        cin>>A[i];
    }
    for(long long int i=0;i<N-1;i++){
        sa[i]=A[i+1]-A[i];
        ans=ans+sa[i];
    }
    sa[N-1]=K-A[N-1]+A[0];
    ans=ans+sa[N-1];
    sort(sa.begin(),sa.end());
    ans=ans-sa[N-1];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
#define fs first
#define sc second
#define mp make_pair
#define L(x) (1<<x)
#define next Next
#define index Index
using namespace std;
const int inf=1e9+10;
const ll llinf=1e17+10;
const int maxn=2e5+10;
const int maxm=5e1+10;
const int maxk=29;
const int mod=1e9+7;
int n;
int A[maxn],B[maxn];
int num[maxm][maxn];
int solve(int temp[],int x)//返回数组中小于x的个数
{
    int pos=lower_bound(temp+1,temp+1+n,x)-temp;
    return pos-1;
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&A[i]);
        for(int i=1;i<=n;i++)
            scanf("%d",&B[i]);
        for(int i=0;i<=maxk;i++)
            for(int j=1;j<=n;j++)
            num[i][j]=B[j]%(L(i+1));
        for(int i=0;i<=maxk;i++)
            sort(num[i]+1,num[i]+1+n);
        int ans=0;
        for(int k=0;k<=maxk;k++)
        {
            ll c=0;
            for(int i=1;i<=n;i++)
            {
                int a=A[i]%(L(k+1));
                c+=solve(num[k],2*L(k)-a)-solve(num[k],L(k)-a);
                c+=solve(num[k],4*L(k)-a)-solve(num[k],3*L(k)-a);
            }
            if(c%2==1)
                ans+=L(k);
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 28160
package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	text := strings.Split(stdin.Text(), "")

	count1 := 0
	for _, data := range text {

		i, _ := strconv.Atoi(data)
		if i == 1 {
			count1++
		}
	}

	fmt.Println(count1)
}


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

int main()
{
	int n;
    cin>>n;
    int a[n],i,flag=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            if(a[i]%3!=0 and a[i]%5!=0)
            {
                flag=1;
                break;
            }
        }
    }
    if(flag==1)
    {
        cout<<"DENIED";
    }
    else
        cout<<"APPROVED";
	return 0;
}

Measured memory_bytes: 256
import math
n=int(input())
num=int(math.sqrt(n))
ans=[0]*(n+1)
for i in range(1,num+1):
    for j in range(1,num+1):
        for k in range(1,num+1):
            v=i*i+j*j+k*k+i*j+i*k+j*k
            if v<=n:
                ans[v]+=1
for i in range(n):
    print(ans[i+1])

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    map<int, int> p, q;
    rep(i,n/2) {
        int a, b;
        cin >> a >> b;
        p[a]++;
        q[b]++;
    }
    vector<P> g, h; 
    for(auto e : p){
        P s = make_pair(e.second, e.first);
        g.push_back(s);
    }
    for(auto e : q){
        P s = make_pair(e.second, e.first);
        h.push_back(s);
    }
    sort(g.rbegin(), g.rend());
    sort(h.rbegin(), h.rend());
    if(g[0].second!=h[0].second) cout << n-g[0].first-h[0].first;
    else cout << min(n-g[1].first-h[0].first, n-g[0].first-h[1].first);
}

Measured memory_bytes: 6136
while True:
    n, r = map(int, raw_input().split())
    if n == r == 0:
        break
    old = range(n, 0, -1)
    new = range(n, 0, -1)
    for shuffle in xrange(r):
        old = list(new)
        p, c = map(int, raw_input().split())
        if p >= 2:
            for i in xrange(c):
                new[i] = old[p-1+i]
            for i in xrange(p-1):
                new[c+i] = old[i]
    print new[0]

Measured memory_bytes: 6344