akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

const int64_t MOD = 1e9 + 7;

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

    vector<int> t(n), a(n);
    rep(i, n)
    {
        cin >> t[i];
    }
    rep(i, n)
    {
        cin >> a[i];
    }

    vector<int> ub(n), lb(n);
    fill(ub.begin(), ub.end(), numeric_limits<int>::max());
    fill(lb.begin(), lb.end(), 1);

    rep(i, n)
    {
        if (i == 0) {
            ub[i] = lb[i] = t[i];
        } else {
            ub[i] = min(ub[i], t[i]);
            if (t[i] > t[i - 1]) {
                lb[i] = max(lb[i], t[i]);
            }
        }
    }
    rrep(i, n)
    {
        if (i == n - 1) {
            ub[i] = min(ub[i], a[i]);
            lb[i] = max(lb[i], a[i]);
        } else {
            ub[i] = min(ub[i], a[i]);
            if (a[i] > a[i + 1]) {
                lb[i] = max(lb[i], a[i]);
            }
        }
    }

    int64_t result = 1;
    rep(i, n)
    {
        int64_t x = max(0, ub[i] - lb[i] + 1);
        x %= MOD;
        result *= x;
        result %= MOD;
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
#include <algorithm>
#define pb push_back
#define ll long long
#define lson son[x][0]
#define rson son[x][1]
#define size(x) ((int)p[x].size())
#define rep(i,j,k) for (i=j;i<=k;i++)
#define down(i,j,k) for (i=j;i>=k;i--)
using namespace std;
const int N=2e5+5;
const ll INF=1e15;
int n,i,fa[N],lf[N],son[N][2],z[N],cnt[N],dgr[N],v[N],q[N];
ll l,r,mid;
struct arr{
	ll a,b;
};
bool cmp_a(const arr &A,const arr &B) {return A.a<B.a;}
bool cmp_b(const arr &A,const arr &B) {return A.b<B.b;}
vector<arr> p[N];
bool judge()
{
	int l,r,x,i,j,F;
	ll Min;
	l=1; r=0;
	rep(i,1,n)
		if (lf[i]!=-1) {
			q[++r]=i; cnt[x]=1;
			p[i].clear();
			p[i].pb((arr){v[i],v[i]});
		}
		else dgr[i]=2,cnt[i]=z[i]=0;
//	printf("\n#Mid=%d\n",mid);
	while (l<=r)
	{
		x=q[l];
		if (lf[x]==-1)
		{
			p[x].clear();
			if (cnt[lson]>cnt[rson]) swap(lson,rson);
			sort(p[lson].begin(),p[lson].end(),cmp_b);
			sort(p[rson].begin(),p[rson].end(),cmp_a);
			j=-1; Min=INF;
			down(i,size(lson)-1,0)
			{
				while (j<size(rson)-1 && p[rson][j+1].a<=mid-p[lson][i].b)
				{
					j++;
					Min=min(Min,p[rson][j].b);
				}
				if (Min!=INF) p[x].pb((arr){p[lson][i].a+v[x],Min+v[x]});
			}
			
			sort(p[lson].begin(),p[lson].end(),cmp_a);
			sort(p[rson].begin(),p[rson].end(),cmp_b);
			j=-1; Min=INF;
			down(i,size(lson)-1,0)
			{
				while (j<size(rson)-1 && p[rson][j+1].b<=mid-p[lson][i].a)
				{
					j++;
					Min=min(Min,p[rson][j].a);
				}
				if (Min!=INF) p[x].pb((arr){Min+v[x],p[lson][i].b+v[x]});
			}
	/*		printf("p[%d]=",x);
			rep(i,0,size(x)-1) printf("(%lld,%lld) ",p[x][i].a,p[x][i].b);
			printf("\n");
	*/
		}
		if (x==1) break;
		F=fa[x];
		son[F][z[F]]=x; z[F]++;
		dgr[F]--; cnt[F]+=cnt[x];
		if (!dgr[F]) q[++r]=F;
		l++;
	}
	if (!p[1].empty()) return 1;
	return 0;
}
int main()
{
	//freopen("journey.in","r",stdin);
	//freopen("journey.out","w",stdout);
	scanf("%d",&n);
	rep(i,2,n) {
		scanf("%d%d",&fa[i],&v[i]);
		lf[fa[i]]=-1;
		r+=v[i];
	}
	while (l<r)
	{
		mid=(l+r)>>1;
		if (judge()) r=mid;
		else l=mid+1;
	}
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 33184
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
#include <stack>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int n;
  stack<int> st;
  while(cin>>n){
    if(n)st.push(n);
    else{
      n = st.top(); st.pop();
      cout<<n<<endl;
    }
  }
}

Measured memory_bytes: 1200
n = int(input())
arr = [int(x) for x in input().split()]
dp = [0]*(n+1)
dp[2] = abs(arr[1]-arr[0])
for x in range(3,n+1):
    dp[x] = min(dp[x-1] + abs(arr[x-1]-arr[x-2]),dp[x-2] + abs(arr[x-1] - arr[x-3]))
print(dp[n])

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acos(-1);

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

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

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	ld n; cin >> n;
	vector<ld> a(5);
	rep(i, 5) cin >> a[i];

	ld mini = INFLL;
	rep(i, 5) chmin(mini, a[i]);

	cout << (ll)ceil(n / mini) + 4 << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 1000005


ll fact[SIZE],inv_fact[SIZE];
ll A[100005],table[100005];


ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}

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

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

ll nCk(ll n,ll k){

	if(k > n)return 0;

	ll ret = fact[n]*inv_fact[k];
	ret %= MOD;
	ret *= inv_fact[n-k];

	return ret%MOD;
}



int main(){

	fact[0] = 1;
	for(ll i = 1; i < SIZE; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}
	inv_fact[SIZE-1] = mod_inverse(fact[SIZE-1],MOD);
	for(ll i = SIZE-1; i >= 1; i--){

		inv_fact[i-1] = inv_fact[i]*i;
		inv_fact[i-1] %= MOD;
	}

	ll N;
	scanf("%lld",&N);

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

		table[i] = 0;
	}

	int base = -1;

	for(ll i = 0; i < N+1; i++){

		scanf("%lld",&A[i]);
		table[A[i]]++;
		if(table[A[i]] == 2){

			base = A[i];
		}
	}

	ll L = -1, R = -1;

	for(ll i = 0; i < N+1; i++){
		if(A[i] != base)continue;

		if(L == -1){

			L = i;
		}else{

			R = i;
		}
	}

	ll pre = L;
	ll mid = R-(L+1); //LとRの間にある数
	ll tail = N-(R+1)+1;

	//printf("pre:%lld mid:%lld tail:%lld\n",pre,mid,tail);


	printf("%lld\n",N); //1
	for(ll num = 2; num <= N; num++){

		//printf("\n\nnum:%lld\n",num);

		//baseを含まない
		ll tmp = nCk(N-1,num);
		//printf("tmp:%lld\n",tmp);

		//baseを1つ含む
		//区間midにデータなし(L,Rが区別されない)
		ll no_mid = nCk(pre+tail,num-1);
		//printf("no_mid:%lld\n",no_mid);

		//区間midにデータあり(L,Rが区別される)
		//printf("nCk(N-1,num-1):%lld -nCk(pre+tail,num-1):%lld\n",nCk(N-1,num-1),nCk(pre+tail,num-1));

	 	ll yes_mid = 2*(nCk(N-1,num-1)-nCk(pre+tail,num-1));
		//printf("yes_mid:%lld\n",yes_mid);

		tmp += (no_mid+yes_mid)%MOD;
		tmp %= MOD;

		//baseを2つ含む
		ll num_two = nCk(N-1,num-2);
		//printf("num_two:%lld\n",num_two);

		tmp += num_two;
		tmp %= MOD;

		//printf("%lld\n",tmp);
		tmp = nCk(N+1,num);
		tmp -= nCk(pre+tail,num-1);
		if(tmp < 0){

			tmp += MOD;
		}
		printf("%lld\n",tmp);
	}
	printf("1\n");

	return 0;
}


Measured memory_bytes: 21012
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */
vector<string> s(50);
bool visited[50][50] = {false};
int dist[50][50] = {1};
int d[4] = {-1, 0, 1, 0};
int H, W;
struct Grid{
  int x, y;
  Grid(int x, int y) : x(x), y(y) {} 
};

int main() {
  cin >> H >> W;
  int dot = 0; // . の数
  REP(i, H){
    cin >> s[i];
    REP(j, W) if(s[i][j] == '.') dot++;
  }

  dist[H-1][W-1] = -1;
  
  queue<Grid>  q;
  q.push(Grid(0,0));

  while(!q.empty()){
    auto from = q.front();
    q.pop();

    REP(i, 4){
      int x = from.x + d[i];
      int y = from.y + d[i^1];
      if(x < 0 || x >= H || y < 0 || y >= W || s[x][y] == '#' || visited[x][y]) continue;
      visited[x][y] = true;
      dist[x][y] = dist[from.x][from.y] + 1;
      q.push(Grid{x,y});
    }
  }


  //dot - 最短路において通るマスの数 が答え
  if(dist[H-1][W-1] != -1){
    cout << dot - dist[H-1][W-1] << endl;
  }else{
    cout << -1 << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl "\n"
#define pii pair<int,int>
#define pll pair<ll,ll>
typedef long long ll;
#define loop() for(int i=0; i<(); i++)
const int MOD=1e9+7;
int modpow(int x, int n, int m)
{
    if(n==0) return 1;
    ll ans=1;
    while(n>0)
    {
        if(n%2==1) ans=(ans*x)%m;
        x=(x*x)%m;
        n/=2;
    }
    return ans;
}

void solve()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0; i<n; i++) cin>>a[i];
    vector<vector<int>>dp(n+1,vector<int>(k+1,0));
   // fill(dp[1].begin(),dp[1].end(),1);
    for(int i=0; i<=n; i++) dp[i][0]=1;
    
    for(int i=1; i<=n; i++)
    {
        int sum[k+1];
        sum[0]=1;
        for(int j=1; j<=k; j++) sum[j]=(sum[j-1]+dp[i-1][j])%MOD;
        for(int j=1; j<=k; j++)
        {
            int r=min(a[i-1],j);
            dp[i][j]=((sum[j]-sum[j-r]+MOD)%MOD+dp[i-1][j-r])%MOD;
        }
    }
    cout<<dp[n][k]<<endl;

}   

int main(){
	fast
	int t=1;
	//cin>>t;
	while(t--) solve();

}


Measured memory_bytes: 43316
//RatedforMe.java
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int r=sc.nextInt();
        
        if(r<1200){
            System.out.println("ABC");
        }
        else if(r>=1200&&r<2800){
            System.out.println("ARC");
        }
        else{
            System.out.println("AGC");
        }
        sc.close();
    }
}

Measured memory_bytes: 23764
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = not True
R = 1000000007
def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = c = g = t = 1
ac = ag = at = 0
ga  = 0
agg = agt = atg = 0

for i in range(n-1):
    xatg = at
    xagg = ag
    xagt = ag
    xat = a
    xag = a
    xac = a - ga
    xga = g
    xa = a + c + g + t
    xc = a + c + g + t - ga - ag - atg - agg - agt
    xg = a + c + g + t - ac
    xt = a + c + g + t
    a = xa % R
    c = xc % R
    g = xg % R
    t = xt % R
    ac = xac % R
    ag = xag % R
    at = xat % R
    ga = xga % R
    agg = xagg % R
    agt = xagt % R
    atg = xatg % R
    ddprint("i {}: a {} c {} g {} t {} ".format(i,xa,xc,xg,xt))
    ddprint("     ac {} ag {} at {} ga {} ".format(xac,xag,xat,xga))
    ddprint("     agg {} agt {} atg {} ".format(xagg,xagt,xatg))

print((a+c+g+t)%R)


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	printf("%d\n",m>=n?0:n-m);
	return 0;
}

Measured memory_bytes: 256
/*
        Author  : Malisetti Samrat
        Date    : 09-02-2020  
        Problem : HARD CASH ("FEB LONG CHALLENGE")
*/

#pragma GCC optimize ("O3")

#pragma GCC optimize("Ofast")

/*
   *********************************************************
    Code_Blooded Human == @{{ samrat_12   [  0_0  ^_^  ] }}
   *********************************************************
*/
#include   <bits/stdc++.h>
#include   <algorithm>
#include   <queue>
#include   <list>
#include   <map>
#include   <math.h>
#include   <numeric>
#include   <iomanip>
using      namespace        std;
#define    endl             '\n'
#define    FAST             ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define    ipfile           ifstream cin ("input.txt");std::cin.rdbuf(std::cin.rdbuf())
#define    pb(x)            push_back(x)
#define    int              long long int
#define    ull              unsigned long long int
#define    db               long double
#define    mod              1000000007
#define    vll              vector<int>
#define    all(v)           v.begin(),v.end()
#define    GCD(m,n)         __gcd(m,n)
#define    LCM(m,n)         m*(n/GCD(m,n))
#define    REVVEC(v)        reverse(v.begin(),v.end())
#define    REVARR(a)        reverse(a,a+n)
#define    maxc(v)          max_element(all(v))
#define    minc(v)          min_element(all(v))
#define    inputarr(a,n)    for(int xxx=0;xxx<n;++xxx) cin>>a[xxx]
#define    outputarr(a,n)   for(int xxx=0;xxx<n;xxx++) cout<<a[xxx]<<" "
#define    rep(i,m, n)      for(int i = m; i < (n); ++i)
#define    sp               setprecison(10)
#define    sz(v)            v.size()

clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}

void TestCase2()
{
    
}

void TestCase3()
{
    
    string s,t;
    cin>>s;
    int len=s.length();
    rep(i,0,len)
    cout<<"x";
    cout<<endl;
    
}

signed main() {
	    
	 FAST
    
   // int T; cin>>T; while(T -- > 0){
    
    TestCase3();
    
    //TestCase2();
    
    //}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const int MAXN = 101024;

int a[MAXN];
int d[MAXN];

int main() {
    int n; cin>>n;
    fill(a, a+MAXN, 0);
    fill(d, d+MAXN, 0);
    for(int i = 1; i <= n; ++i) {
        cin>>a[i];
    }
    int sum = 0;
    for(int i = 1; i <= n+1; ++i) {
        sum += abs(a[i-1] - a[i]);
    }
    for(int i = 1; i <= n; ++i) {
        if((a[i-1] - a[i]) * (a[i+1] - a[i]) > 0) {
            d[i] = 2 * min(abs(a[i-1] - a[i]), abs(a[i+1] - a[i]));
        }
        else {
            d[i] = 0;
        }
    }
    for(int i = 1; i <= n; ++i) {
        cout << sum - d[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <stack>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		stack<pii> stk;
		for(int i = 0; i < n; i++){
			int color;
			cin >> color;
			if(stk.empty()){
				stk.push(pii(color, 1));
			}else if(stk.top().first == color){
				stk.top().second++;
			}else if(i % 2 == 1){
				pii item = stk.top();
				stk.pop();
				if(!stk.empty()){
					stk.top().second += item.second + 1;
				}else{
					stk.push(pii(color, item.second + 1));
				}
			}else{
				stk.push(pii(color, 1));
			}
		}
		int answer = 0;
		while(!stk.empty()){
			if(stk.top().first == 0){ answer += stk.top().second; }
			stk.pop();
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

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

  int N;
  cin >> N;

  if (N / 10 == 9 || N % 10 == 9) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int T;
long long A, B, C, D;

long long gcd(long long int m, long long int n)
{
	// ユークリッドの方法
	while (m != 0 && n != 0)
	{
		if (m > n) m %= n;
		else       n %= m;
	}
	return max(m, n);
}//gcd

bool is_endless() {
	if (A < B) {
		return false;
	}
	else {
		if (C >= B - 1) {
			if (D < B) {
				return false;
			}
			else {
				return true;
			}
		}
		else {
			long long a = A % B;
			if (a > C) {
				return false;
			}
			else {
				if (D < B) {
					return false;
				}
				else if (D == B) {
					return true;
				}
				else {
					long long g = gcd(B, D);
					long long M = a + (B - 1 - a) / g * g;
					if (M > C) {
						return false;
					}
					else {
						return true;
					}
				}
			}
		}
	}
}

void solve() {
	cin >> T;
	for (int i = 0; i < T; i++)
	{
		cin >> A >> B >> C >> D;
		if (is_endless()) {
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
	}

}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define X first
#define Y second
using namespace std;
bool f[20000];
int n,m;
pair<int,pair<int,int> >t[20000];
int main(){
	while(cin>>n>>m&&n+m){
	for(int i=1;i<n;i++)f[i]=0;
	f[0]=1;
	for(int i=0;i<m;i++){
		cin>>t[i].X>>t[i].Y.X>>t[i].Y.Y;
		t[i].Y.X--,t[i].Y.Y--;
	}
	sort(t,t+m);
	for(int i=0;i<m;i++){
		if(f[t[i].Y.X])f[t[i].Y.Y]=1;
	}
	int ans=0;
	for(int i=0;i<n;i++)ans+=f[i];
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3248
h,w=map(int,raw_input().split())
n=int(raw_input())
a=map(int,raw_input().split())
b=[]
for j,x in enumerate(a) :
    for i in range(x) :
        b.append(j+1)
for i in range(h) :
    s=b[0+i*w:w+i*w]
    if i%2==0 :
        print ' '.join(['%i'%j for j in s])
    else :
        print ' '.join(['%i'%j for j in reversed(s)])

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

class Int
{
    int x;
public:
    Int()
    {
        std::cin >> x;
    }
    operator int() const { return x; }
    friend constexpr int operator+(int a, const Int &x) { return a + x; }
    friend constexpr int operator-(int a, const Int &x) { return a - x; }
    friend constexpr int operator*(int a, const Int &x) { return a * x; }
    friend constexpr int operator/(int a, const Int &x) { return a / x; }
    constexpr Int &operator+=(const Int &x) { this->x += x.x; return *this; }
    constexpr Int &operator-=(const Int &x) { this->x -= x.x; return *this; }
    constexpr Int &operator*=(const Int &x) { this->x *= x.x; return *this; }
    constexpr Int &operator/=(const Int &x) { this->x /= x.x; return *this; }
};

int main()
{
    Int A, B, C, D;
    while (true)
    {
        C -= B;
        if (C <= 0)
        {
            puts("Yes");
            break;
        }
        A -= D;
        if (A <= 0)
        {
            puts("No");
            break;
        }
    }
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int h,a,i;
  int cnt =0;
  cin>>h>>a;
  
  for(i=0;i<=h;i++)
  {
          i = a *cnt;
          cnt++;
  }
      cout<<"\n"<<cnt -1;
  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int dp[1<<16][16],n;
int main() {
  while(cin >> n && n) {
    string s,s2;cin>>s>>s2;
    int r=0;
    for(int t=0;t<(1<<n);t++)for(int i=0;i<n;i++)dp[t][i]=1<<29;
    for(int i=0;i<n;i++)if(s[i]==s2[i]) r|=1<<i;
    for(int i=0;i<n;i++)dp[r][i]=0;
    for(int t=0;t<(1<<n);t++) {
      for(int i=0;i<n;i++) {
        if(dp[t][i]==1<<29) continue;
        for(int j=0;j<n;j++) {
          if(t&(1<<j)) continue;
          for(int k=j+1;k<n;k++) {
            if(t&(1<<k)||s[j]==s[k]) continue;
            dp[t|(1<<j)|(1<<k)][j]=min(dp[t|(1<<j)|(1<<k)][j],dp[t][i]+abs(i-k)+abs(k-j));
            dp[t|(1<<j)|(1<<k)][k]=min(dp[t|(1<<j)|(1<<k)][k],dp[t][i]+abs(i-j)+abs(j-k));
          }
        }
      }
    }
    int ans=1<<29;
    for(int i=0;i<n;i++)ans=min(ans,dp[(1<<n)-1][i]);
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 7092
#n=int(input())
n,m,q=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

al=[0]*q
bl=[0]*q
cl=[0]*q
dl=[0]*q

for i in range(q):
    al[i],bl[i],cl[i],dl[i]=map(int,input().split())

def score_calc(seq):
    res=0
    for a,b,c,d in zip(al,bl,cl,dl):
        if seq[b-1]-seq[a-1]==c:
            res+=d
    return res
score_list=[]
def dfs(seq):
    if len(seq)==n:
        score_list.append(score_calc(seq))
        return 
    lastone=seq[-1] if len(seq)>0 else 1
    for v in range(lastone,m+1):
        seq.append(v)
        dfs(seq)
        seq.pop()

dfs([])
print(max(score_list))

Measured memory_bytes: 12720
from operator import itemgetter

n = int(input())
sp = [list(map(str, input().split())) for i in range(n)]

for i in range(n):
    sp[i].append(i + 1)
    sp[i][1] = int(sp[i][1])

sp.sort()

t = []

t.append(sp[0])

for i in range(n - 1):
    i += 1
    if sp[i][0] == sp[i - 1][0]:
        t.append(sp[i])
    else:
        t.sort(key=lambda t: t[1], reverse=True)
        for j in t:
            print(j[2])
        t = []
        t.append(sp[i])

t.sort(key=lambda t: t[1], reverse=True)
for j in t:
    print(j[2])


Measured memory_bytes: 3064
while 1:
    n = int(input())
    if n == 0:
        break

    infos = []
    for _ in range(n):
        info = list(map(int, input().split()))
        tmp = info.pop(0)
        infos.append(info)

    target = list(map(int, input().split()))
    tmp = target.pop(0)

    flag = False
    for i, info in enumerate(infos):
        for t in target:
            if t not in info:
                break
        else:
            if flag:
                print(-1)
                break
            else:
                ans = i + 1
                flag = True
    else:
        if flag:
            print(ans)
        else:
            print(-1)


Measured memory_bytes: 5668
#include<bits/stdc++.h>
using namespace std;
int main(){
  char c[10][10];
  scanf("%s %s %s",&c[0], &c[1], &c[2]);
  printf("%c%c%c",c[0][0], c[1][1], c[2][2]);
  return 0;
}
  
  

Measured memory_bytes: 256
# input
n = int(input())
bs_input = tuple(int(i) for i in input().split())


# imposibility check
# any integer's index > i
def valid(list_):
    return all(i >= l - 1 for i, l in enumerate(list_))


def can_remove(list_, i):
    # index and number doesn't match
    if list_[i - 1] != i:
        return False

    # doesn't affect validity by removing
    if not valid(list_[:(i - 1)] + list_[i:]):
        return False

    return True


def remove(list_, i):
    return list_[:(i - 1)] + list_[i:]

reconstruct = []

bs = list(bs_input)
for i in range(n):
    if not valid(bs):
        reconstruct = []
        break
    for j in range(n - i):
        if can_remove(bs, bs[j]):
            reconstruct.insert(0, bs[j])
            bs = remove(bs, bs[j])
            break


if reconstruct == [] or len(reconstruct) != n:
    print(-1)
else:
    print('\n'.join(str(i) for i in reconstruct))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    
    int root(int x) {
        if (par[x] < 0) {
            return x;
        }
        
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        
        if (rx == ry) {
            return false;
        }
        
        if (par[rx] > par[ry]) {
            swap(rx, ry);
        }
        
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    UnionFind uf(n);
    vector<ll> ans(m);
    ll ret = 0;
    
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    
    rrep(i, m) {
        ans[i] = 1LL * n * (n - 1) / 2 - ret;
        
        if (uf.root(a[i]) != uf.root(b[i])) {
            ret += 1LL * uf.size(a[i]) * uf.size(b[i]);
            uf.merge(a[i], b[i]);
        }
    }
    
    rep(i, m) {
        cout << ans[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3328
iS = input()
kigou = ['+','-']

for i in range(len(kigou)):
  for j in range(len(kigou)):
    for k in range(len(kigou)):
      result = iS[0]+kigou[i]+iS[1]+kigou[j]+iS[2]+kigou[k]+iS[3]
      if eval(result) == 7:
        print(result+'=7')
        exit(0)


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

int dislike(int n,int* d,int k){
  int i,j,p,m=n,digit=0;
  while(m!=0){
    m/=10;
    digit++;
  }
  for(i=0;i<k;i++){
    p=n;
    for(j=0;j<digit;j++){
      if(p%10==d[i])return 1;
      p/=10;
    }
  }
  return 0;
}

int main(){
  int i,j,cnt;
  int n,k;
  cin>>n>>k;
  int d[k];
  for(i=0;i<k;i++)cin>>d[i];
  for(i=0;i<100000;i++){
    if(n<=i && !dislike(i,d,k)){
      cout<<i;
      return 0;
    }
  }
}

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

int main() {
  int a, b;
  
  cin >> a >> b;
  
  for(int i = 1; i < 1000000000; i += 1){
    if ((int)(i * 0.08) == a && (int)(i * 0.10) == b){
       cout << i << endl;
       return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 384
def main():
    n = int(input())
    d = list(map(int,input().split()))
    d0 = d[0]
    d = sorted(d)
    l = [0]*(d[-1]+1)
    for i in d:
        l[i] += 1
    ans = 0
    if (not 0 in l) and d[1] > 0 and d0 == 0:
        ans = 1
        for i in range(1,len(l)):
            ans = ans*(l[i-1]**l[i])%998244353
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 53172
#include<cstdio>

inline int Max(const int&x,const int&y){return x>y?x:y;}

#define Fast register
char BUF[16384],*S=BUF,*T=BUF;
inline char Getchar(){return(S==T)&&(T=(S=BUF)+fread(BUF,1,16384,stdin),S==T)?EOF:*S++;}
inline int Getint(){
	Fast int s=0;Fast char c;
	while(c=Getchar(),c<48||c>57);
	while(s=s*10+c-48,c=Getchar(),c>47&&c<58);
	return s;
}

int A[2][101];
int Sum[2][101];

int main(){
	Fast int N=Getint();
	for(Fast int i=1;i<=N;++i)Sum[0][i]=Sum[0][i-1]+(A[0][i]=Getint());
	for(Fast int i=1;i<=N;++i)Sum[1][i]=A[1][i]=Getint();
	for(Fast int i=N-1;i;--i)Sum[1][i]+=Sum[1][i+1];
	Fast int Maximum=0;
	for(Fast int i=1;i<=N;++i)Maximum=Max(Maximum,Sum[0][i]+Sum[1][i]);
	printf("%d",Maximum);
	return 0;
}

Measured memory_bytes: 128
N=int(input())
A=[0]+sorted(map(int,input().split()))
l=0
r=N
while l+1<r:
    i = (l+r)//2
    a = sum(A[:i+1])
    for j in range(i+1,N):
        if a*2<A[j]: l = i;break
        a += A[j]
    else:
        r = i
print(N-r+1)

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

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    set <int> s;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        s.insert(x);
    }
    int t = (int) s.size();
    if (t == n) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 10368
n = int(input())
S = [int(x) for x in input()]
all_num = 0

all_dict = {}
for i in range(len(S)-2):
  s_0 = S[i]
  if s_0 in all_dict.keys():
    pass
  else:
    all_dict[s_0] = dict()
    for j in range(i+1, len(S)-1):
      s_1 = S[j]
      if s_1 in all_dict[s_0].keys():
        pass
      else:
        all_dict[s_0][s_1] = len(set(S[j+1:]))
        all_num += len(set(S[j+1:]))
        
print(all_num)


        
  

Measured memory_bytes: 9556
using System;

namespace abc147_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] A123 = Console.ReadLine().Split(" ");
            int sum = int.Parse(A123[0]) + int.Parse(A123[1]) + int.Parse(A123[2]);

            string str;
            if(sum >= 22)
            {
                str = "bust";
            }
            else
            {
                str = "win";
            }
            Console.WriteLine(str);
        }
    }
}


Measured memory_bytes: 27508
#include <stdio.h>

int main(void)
{
	int $S$,$h$,$m$,$s$;

	scanf("%d",&$S$);

	$h$ = $S$ / 3600;
	$m$ = ($S$ - ($h$ * 3600))/60;
	$s$ = ($S$ - ($h$ * 3600 + $m$ * 60));
	printf("%d:%d:%d\n",$h$,$m$,$s$);

	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<int64_t MOD> struct Mint {
    int64_t v;
    Mint() { v = 0; }
    Mint(int64_t x) { v = x % MOD; if(v < 0)  v += MOD; }

    Mint operator-() { return Mint{-v}; };
    Mint operator+(Mint x) { return Mint(v + x.v); };
    Mint operator-(Mint x) { return Mint(v - x.v); };
    Mint operator*(Mint x) { return Mint(v * x.v); };
    Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

    Mint& operator+=(Mint x) { return *this = (*this + x); };
    Mint& operator-=(Mint x) { return *this = (*this - x); };
    Mint& operator*=(Mint x) { return *this = (*this * x); };
    Mint& operator/=(Mint x) { return *this = (*this / x); };

    static Mint pow(Mint base, int64_t exp) {
        if(exp == 0)  return Mint(1);
        return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
    }

    friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

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

    vector<lint> a(n);
    for(lint i=0; i<n; i++)  cin >> a[i];

    lint color[3] = {};
    vector<lint> cands;
    for(auto e : a) {
        lint cand = 0;
        for(lint i=0; i<3; i++) {
            if(color[i] == e) {
                if(!cand)  color[i]++;
                cand++;
            }
        }
        cands.push_back(cand);
    }

    mint ans = 1;
    for(auto e : cands)  ans *= mint(e);

    cout << ans << endl;
}

Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            String S = sc.next();

            char[] C = S.toCharArray();
            for (int i = 0; i < C.length; i++) {
                int c = (int) (C[i]) + N;
                if (c > 90) {
                    c -= 26;
                }
                C[i] = (char) c;
            }

            System.out.println(String.valueOf(C));
        }
    }

}


Measured memory_bytes: 23380
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] s = br.readLine().toCharArray();
		br.close();

		long ans = 0;
		int bc = 0;
		boolean c = false;
		for (int i = s.length - 1; i >= 0; i--) {
			if (s[i] == 'A') {
				if (c) {
					bc = 0;
				} else {
					ans += bc;
				}
				c = false;

			} else if (s[i] == 'B') {
				if (c) {
					bc++;
				} else {
					bc = 0;
				}
				c = false;

			} else if (s[i] == 'C') {
				if (c) {
					bc = 0;
				}
				c = true;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 27220
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;


int main() {
    int  a, b,c;
    cin >> a >> b>>c;
    if (a <= c && b >= c)cout << "Yes" << endl;
    else cout << "No" << endl;
  
 
    
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        r: usize,
    }

    println!("{}", r*r);

}

Measured memory_bytes: 4352
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	b := readString()
	m := make(map[string]string)
	m["A"] = "T"
	m["C"] = "G"
	m["G"] = "C"
	m["T"] = "A"
	println(m[b])
}

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long n,a[100001][4],mem[100001][4];
long long dp(long long i,long long j){
    if(n==i) return 0;
    if(mem[i][j]) return mem[i][j] ;
    for (int k=0;k<3;k++)
    {
        if(k!=j)
            mem[i][j]=max(a[i][k]+dp(i+1,k),mem[i][j]);
    }
return mem[i][j];
}
int main(){
    cin>>n;
for(int i=0;i<n;i++)
    for(int j=0;j<3;j++)
        cin>>a[i][j];
cout<<dp(0,3);
}


Measured memory_bytes: 14336
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] array = new long[n][2];
        for (int i = 0; i < n; i++) {
            array[i][0] = sc.nextLong();
            array[i][1] = sc.nextLong();
        }
        
        Arrays.sort(array, (a, b) -> Long.compare(a[1], b[1]));
        // for (long[] a : array) {
        //     System.out.println(Arrays.toString(a));
        // }
        
        
        boolean ok = true;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            if (sum + array[i][0] <= array[i][1]) {
                sum += array[i][0];
            } else {
                ok = false;
                break;
            }
        }
        
        if (ok) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    // public static void main(String[] args) throws Exception {
    //     // Your code here!
    //     Scanner sc = new Scanner(System.in);
    //     int n = sc.nextInt();
    //     long[][] array = new long[n][3];
    //     for (int i = 0; i < n; i++) {
    //         array[i][0] = sc.nextLong();
    //         array[i][1] = sc.nextLong();
    //         array[i][2] = array[i][1] - array[i][0];
    //     }
        
    //     Arrays.sort(array, (a, b) -> Long.compare(b[2], a[2]));
    //     for (long[] a : array) {
    //         System.out.println(Arrays.toString(a));
    //     }
        
        
    //     long now = array[0][2];
    //     boolean ok = true;
    //     for (int i = 1; i < n; i++) {
    //         if (now - array[i][0] <= array[i][2]) {
    //             now -= array[i][0];
    //         } else {
    //             now = array[i][2];
    //         }
            
    //         if (now < 0) {
    //                 ok = false;
    //                 break;
    //         }
    //     }
        
    //     if (ok) {
    //         System.out.println("Yes");
    //     } else {
    //         System.out.println("No");
    //     }
    // }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int ma;
    cin>>ma;
    int mi=ma;
    for(int i=1;i<n;i++)
    {
        int x;
        cin>>x;
        mi=min(mi,x);
        ma=max(ma,x);
    }
    cout<<ma-mi<<"\n";
    return 0;
}
/**

**/


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

int main() {
    std::string S, T;
    std::cin >> S >> T;

    if (S.size() == (T.size() - 1) && T.substr(0, T.size() - 1) == S) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

struct SegmentTree {
  //10^6要素まで対応
  vector<ll> d;
  int size = 1;
  SegmentTree(): d(1<<21, 0) {} //addなので0初期化

  //functions
  //OPERATION: ADD
  //init
  void init_SegmemtTree(vector<ll>&original) {
    int n = original.size();
    while (size < n) size *= 2;
    if (size > (1<<20)) cout << "Too Many Elements" << endl; //error
    for (int i = 0; i < n; i++) d[size+i] = original[i];
    for (int i = size-1; i > 0; i--) d[i] = d[2*i] + d[2*i+1]; //add
  }

  //update: k番目にa加算
  void update(int k, ll a) {
    k += size;
    ll temp = 0;
    while(k > 0) {
      d[k] += a - temp;
      k /= 2;
    }
  }

  //query: [a, b)の区間の総和(add)
  ll query(int a, int b, int k=1, int l=0, int r=-1) {
    if (r == -1) r = size;
    //範囲がまったく重ならないとき(add)
    if ((r <= a) || (b <= l)) return 0;
    //範囲に含まれるとき
    if ((a <= l) && (r <= b)) return d[k];
    //一部重なるとき(add)
    else return query(a, b, 2*k, l, (l+r)/2) + query(a, b, 2*k+1, (l+r)/2, r);
  }
};

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

  ll n, d, a;
  cin >> n >> d >> a;
  vector<pll> monster(n);
  for (int i = 0; i < n; i++) cin >> monster[i].first >> monster[i].second;
  sort(monster.begin(), monster.end());

  vector<int> effindex(n);
  //i番目が巻き込まれるときの左端
  int l = n-1;
  for (int r = n-1; r >= 0; r--) {
    while ((l >= 0) && (monster[r].first - monster[l].first <= 2 * d)) l--;
    effindex[r] = l+1;
  }
  //for (int i = 0; i < n; i++) cout << effindex[i] << " ";
  //cout << endl;

  vector<ll> zeros(n, 0);
  SegmentTree st;
  st.init_SegmemtTree(zeros);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll cnt;
    if (i == 0) {
      cnt = (monster[i].second - 1) / a + 1;
      st.update(i, cnt);
    }
    else {
      cnt = (monster[i].second - a * st.query(effindex[i], i) <= 0) ? 0 : (monster[i].second - a * st.query(effindex[i], i) - 1) / a + 1;
      st.update(i, cnt);
    }
    ans += cnt;
  }
  cout << ans << endl;
}


Measured memory_bytes: 25092
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=4005;
int n,pre[MN],suf[MN];
char ch[MN];
inline ll solve(char a,char b,char c){
	reg ll Ans=0;
	for(reg int i=1;i<=n;i++)
		pre[i]=pre[i-1]+(ch[i]==a);
	for(reg int i=n;i;i--)
		suf[i]=suf[i+1]+(ch[i]==c);
	for(reg int i=1;i<=n;i++)
		if(ch[i]==b)Ans+=pre[i]*suf[i];
	for(reg int i=1;i<=n;i++){
		if(ch[i]!=a)continue;
		for(reg int j=i+1;2*j-i<=n;j++)
			Ans-=(ch[j]==b&&ch[2*j-i]==c);
	}
	return Ans;
}
int main(){
	scanf("%d",&n);
	scanf("%s",ch+1);
	reg ll Ans=0;
	Ans+=solve('R','G','B');
	Ans+=solve('B','G','R');
	Ans+=solve('R','B','G');
	Ans+=solve('G','B','R');
	Ans+=solve('G','R','B');
	Ans+=solve('B','R','G');
	printf("%lld\n",Ans);
	return 0;
}

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

int main() {
  int a, c, d;
  string b;
  cin >> a >> b >> c;
  if (b == "+"){
    d = a + c;
  }
  else if (b == "-"){
    d = a - c;
  }
  cout << d << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():

    ##########################################
    import heapq
    class Dijkstra():
        """
        ・有向 / 無向は問わない(無向の場合は，逆向きの辺もたす)
        ・負のコストがない場合のみ
        ・計算量はO(E log|V|)　
        ・heapを使うことで頂点を走査する必要がなくなる（代わりに，距離更新したものは確定でなくともqueに入れておく）
        ・復元なし
        """

        #最短のpathをたす


        class Edge():
            #重み付き有向辺

            def __init__(self, _to, _cost):
                self.to =_to
                self.cost = _cost

        def __init__(self, V):
            #引数Vは頂点数
            self.inf=10**20
            self.G = [[] for _ in range(V)] #隣接リストG[u][i]が頂点uのi番目の辺
            self. _E = 0 #辺の数
            self._V = V #頂点数

        #proparty - 辺の数
        def E(self):
            return self._E

        #proparty - 頂点数
        def V(self):
            return self._V

        def add(self, _from, _to, _cost):
            #2頂点と辺のコストを追加
            self.G[_from].append(self.Edge(_to,_cost))
            self._E +=1

        def add2(self, _from, _to, _cost):
            #2頂点と辺のコスト（無向）を追加
            self.G[_from].append(self.Edge(_to, _cost))
            self.G[_to].append(self.Edge(_from, _cost))
            self._E +=2

        def shortest_path(self,s):#,g):
            #始点sから頂点iまでの最短経路長のリストを返す
            que = [] #priority queue
            d = [self.inf] * self.V()

            #prev = [None]*self.V() #prev[j]は，sからjへ最短経路で行くときのjの一つ前の場所
            #復元で使う

            d[s] = 0
            heapq.heappush(que,(0,s)) #始点の距離と頂点番号をヒープに追加

            while len(que)!=0:
                #キューに格納されてある中で一番コストが小さい頂点を取り出す
                cost,v = heapq.heappop(que)

                #キューに格納された最短経路長候補がdの距離よりも大きい場合に処理をスキップ
                if d[v] < cost:
                    continue

                #頂点vに隣接する各頂点iに対して，vを経由した場合の距離を計算して，これがd[i]よりも小さい場合に更新
                for i in range(len(self.G[v])):
                    e = self.G[v][i] #vのi個目の隣接辺
                    if d[e.to] > d[v] + e.cost:
                        d[e.to] = d[v] + e.cost #更新

                        #prev[e.to] = v
                        #復元で使う

                        heapq.heappush(que,(d[e.to],e.to)) #queに新たな最短経路長候補を追加

            """#sからgまでの最短経路
            path = []
            pos = g #今いる場所，ゴールで初期化
            for _ in range(self.V()+1):
                path.append(pos)
                if pos == s:
                    break
                #print("pos:",format(pos))
                pos = prev[pos]
            path.reverse()
            #print(path)"""

            return d#,path
    ########################
    mod=10**9+7
    N,M=MI()
    djk=Dijkstra(3*N)
    for _ in range(M):
        u,v=MI()
        u-=1
        v-=1
        djk.add(u,v+N,1)
        djk.add(u+N,v+2*N,1)
        djk.add(u+2*N,v,1)
    S,T=MI()
    S-=1
    T-=1
    D=djk.shortest_path(S)
    ans=D[T] //3
    
    if ans>10**7:
        ans=-1
        
    print(ans)
        
    


main()


Measured memory_bytes: 136636
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
    string S;
    cin >> S;
    int N = S.size();

    vector< vector < long > > dp(N+1, vector<long>(13,0));
    dp[0][0] = 1;

    long mod = 1000000007;

    for(int i=1; i <= N; i++){
        for(int j = 0; j < 13; j++){
            if(S[i-1] == '?'){
                for(int y = 0; y < 10; y++){
                    dp[i][(10*j + y)%13] += dp[i-1][j];
                    dp[i][(10*j + y)%13] %= mod;
                }
            }
            else{
                dp[i][(10*j + (int)(S[i-1] - '0'))%13] += dp[i-1][j];
                dp[i][(10*j + (int)(S[i-1] - '0'))%13] %= mod;
            }
        }
    }

    cout << dp[N][5] << endl;

    return 0;

}

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

#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pie;
const int MOD = 1e9 + 7;

int n;

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	cout << n * (n - 1) / 2 - n / 2 << endl;
	if (n % 2) {
		for (int i = 1; i < n; i++)
			for (int j = i + 1; j <= n; j++)
				if (i + j != n)
					cout << i << ' ' << j << endl;
	}
	else {
		for (int i = 1; i < n; i++)
			for (int j = i + 1; j <= n; j++)
				if (i + j != n + 1)
					cout << i << ' ' << j << endl;
	}
}



Measured memory_bytes: 256
# 4棟3階建て10フロアの配列
building = Array.new(4){ Array.new(3){ Array.new(10, 0)}}

N = gets.chomp.to_i

for i in  1..N
	imput = gets.chomp.split("\s")
	
	# imputされた文字列をintegerに変換
	for k in 0..3
		imput[k] = imput[k].to_i
	end
	
	# 数値の代入
	building[imput[0] - 1][imput[1] - 1][imput[2] - 1] += imput[3]
end

# 出力

# aa棟bb階の状態を出力する
for aa in 0..3
	for bb in 0..2
		print("\s", building[aa][bb].join("\s"), "\n")
	end
	
	# 最後の段以外は仕切りを入れる
	if aa != 3
		puts "#" * 20
	end
end

Measured memory_bytes: 6112
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    s = s.replace("7","");
    if(s.length() != 3){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 35648