akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;}
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization

int main() {
    std::cout << std::fixed << std::setprecision(15);
    string s; cin >> s;

    ll ans = 0;
    rep(i, s.size()){
        ll num = (ll)(s[i]-48);
        ans += num;
    }
    if(ans % 9 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3744
//Utkarsh.25dec
#include <bits/stdc++.h>
#define ll long long int 
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    vl h;
    h.pb(0);
    rep(i,n)
    {
        ll c;
        cin>>c;
        h.pb(c);
    }
    ll dp[n+1];
    dp[1]=0;
    dp[2]=abs(h[1]-h[2]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
    }
    cout<<dp[n];
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
}

Measured memory_bytes: 13684
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

if N == 1 and M == 0:
	print(0)
	exit()

sc = [LIST() for _ in range(M)]

ans = [-1]*N
for s, c in sc:
	if N >= 2 and s == 1 and c == 0:
		print(-1)
		exit()
	if ans[s-1] != -1 and ans[s-1] != c:  # 既に値が入っている
		print(-1)
		exit()
	ans[s-1] = c
if ans[0] == -1:
	ans[0] = 1

for i in range(N):
	if ans[i] == -1:
		ans[i] = 0

for n in ans:
	print(n, end="")
print()


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

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

int main() {
	int h, w; cin >> h >> w;
	vector<string>s(h);
	for (int i = 0; i < h; i++) {
		string tmp; cin >> tmp;
		s[i] = tmp;
	}

	bool ok = true;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') {
				bool black = false;
				for (int k = 0; k < 4; k++) {
					int nx = dx[k] + i, ny = dy[k] + j;
					if (0 <= nx && nx < h && 0 <= ny && ny < w) {
						if (s[nx][ny] == '#')black = true;
					}
				}
				if (!black)ok = false;
			}
		}
	}
	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;

public class Main {
    private static final class FastInput {
        private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer st;

        private int nextInt() throws Exception {
            return Integer.parseInt(nextWord());
        }

        private long nextLong() throws Exception {
            return Long.parseLong(nextWord());
        }

        private String nextWord() throws Exception {
            if (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine(), " ");
            return st.nextToken();
        }

        private long[] lineToIntArr(int len) throws Exception {
            long[] arr = new long[len];
            for (int i = 0; i < arr.length; i++) arr[i] = nextLong();
            return arr;
        }
    }

    public static void main(String[] args) throws Exception {
        FastInput in = new FastInput();
        int n = in.nextInt();
        long[] a = in.lineToIntArr(n);
        long[] dp = new long[n+1];
        for(int i = 0; i <=n; ++i){
            dp[i] = 1000000007;
        }
        dp[0] = 0;
        for(int i = 0; i <n; ++i){
            if(i + 1 < n) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(a[i] - a[i+1]));
            if(i + 2 < n) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(a[i] - a[i+2]));
        }
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        bw.write(String.valueOf(dp[n - 1]));
        bw.flush();
    }
}


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

int main()
{
    int n,k;cin>>n>>k;
    vector<int> h(n);
    int i,ans;ans=0;
    for(i=0;i<n;i++)cin>>h.at(i);
    for(i=0;i<n;i++)
    {
        if(h.at(i)>=k)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (ll)4e18;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	vector<ll> a(x), b(y), c(z);
	rep(i, x) cin >> a[i];
	rep(i, y) cin >> b[i];
	rep(i, z) cin >> c[i];
	sort(all(a));
	sort(all(b));
	sort(all(c));
	vector<ll> sum;
	rep(i, x) {
		rep(j, y) {
			sum.push_back(a[i] + b[j]);
		}
	}
	sort(rall(sum));
	vector<ll> res;
	rep(i, z) {
		rep(j, min(k, (int)sum.size())) {
			res.push_back(c[i] + sum[j]);
		}
	}
	sort(rall(res));
	rep(i, k) cout << res[i] << endl;
	return 0;
}


Measured memory_bytes: 43240
#include<stdio.h>
int card[1000000],num[1000000];
char mark[1000000];

int quicksort(int,int);
int partition(int,int);

int main(void)
{
    int m,k,flg=0;

    scanf("%d",&m);
    for(k=0;k<m;k++) num[k]=k;
    for(k=0;k<m;k++){
        scanf(" %c",&mark[k]);
        scanf("%d",&card[k]);
    }
    quicksort(0,m-1);
    for(k=1;k<m;k++){
        if(card[k]==card[k-1]){
            if(num[k]<num[k-1]){
                flg=1;
            }
        }
    }
    if(flg==1) printf("Not stable\n");
    else       printf("Stable\n");
    for(k=0;k<m;k++){
        printf("%c %d\n",mark[k],card[k]);
    }
    return 0;
}

int partition(int j,int n){
    int i,x,tmpi;
    char tmpc;
    x=card[n];
    for(i=j;i<n;i++){
        if(card[i]<=x){
            tmpi=card[i];
            card[i]=card[j];
            card[j]=tmpi;
            tmpc=mark[i];
            mark[i]=mark[j];
            mark[j]=tmpc;
            tmpi=num[i];
            num[i]=num[j];
            num[j]=tmpi;
            j++;
        }
    }
    tmpi=card[n];
    card[n]=card[j];
    card[j]=tmpi;
    tmpc=mark[n];
    mark[n]=mark[j];
    mark[j]=tmpc;
    tmpi=num[n];
    num[n]=num[j];
    num[j]=tmpi;
    return j;
}

int quicksort(int p,int r){
    int q;
    if(p<r){
        q=partition(p,r);
        quicksort(p,q-1);
        quicksort(q+1,r);
    }
    return 0;
}

Measured memory_bytes: 5092
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair

using namespace std;


int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   pair<ll,ll> arr[n];
   for(ll i=0;i<n;i++)
   {
       cin>>arr[i].first;
       arr[i].second = i;
   }
   
   sort(arr,arr+n);
   
   map<ll,ll> ma;
   //ma[make_pair(arr[0].second, arr[i].first)] = 1;
   
   for(ll i=0;i<n;i++)
   {
       ll j;
       vector<pair<ll,ll>> hold;
       
       auto it1 = ma.lower_bound(arr[i].second);
       if(it1 == ma.begin())
           hold.pb(mp(arr[j].second,1));
       else{
       it1--;
       ll temp = it1->second;
       ma.erase(it1);
       hold.pb(mp(arr[i].second,temp+1));
       }
       
       for(j=i+1;j<n;j++)
       {
           if(arr[j].first != arr[i].first)
               break;
           if(ma.size() == 0)
           {
               hold.pb(mp(arr[j].second,1));
               continue;
           }
           
           auto it = ma.lower_bound(arr[j].second);
           if(it == ma.begin())
           {
               hold.pb(mp(arr[j].second,1));
               continue;
           }
           
           it--;
           ll temp = it->second;
           ma.erase(it);
           hold.pb(mp(arr[j].second,temp+1));
       }
       
       for(ll i1=0;i1<hold.size();i1++)
            ma[hold[i1].first] = hold[i1].second;
       
       i=j-1;
       
   }
   
   cout<<ma.size();
   
   return 0;
}

Measured memory_bytes: 9584
import java.util.Scanner;

class Main{
    static public void main(String[] av){
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	int y = sc.nextInt();
	if(x<y){
	    int tmp = x;
	    x = y;
	    y = tmp;
	}

	int r = x % y;
	while(r!=0){
	    x = y;
	    y = r;
	    r = x % y;
	}

	System.out.println(y);
    }
}



Measured memory_bytes: 26388
#include<stdio.h>
int main()
{
    int a,b,i,m=0,j,k;
    scanf("%d",&a);
    for(i=0,j=2; i<10000,j<=a; i++,j+=2)
    {
        if(j%2==0)
        {
            for(k=1; k<=a; k+=2)
            {
                m++;
            }
        }
    }
    printf("%d\n",m);
}


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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vpi;
typedef vector<string> vsi;
typedef map<ll, ll> mape;
#define rep(i, a, b) for(ll i=(ll)a;i<=(ll)b;i++)
#define per(i, a, b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define N 2100
#define MAX 1000000000001
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define MOD 1000000007

int main()
{
    fastio;

    clock_t tStart = clock();

    string s;
    cin >> s;
    ll q;
    cin >> q;
    ll rev = 0;
    while(q--){
        ll type;
        cin >> type;
        if(type == 1) rev++;
        else{
            ll f;
            char ch;
            cin >> f >> ch;
            if(f == 1){
                if(rev%2) s += ch;
                else {
                    string t = ch + s;
                    s = t;
                }
            }
            else{
                if(rev%2) {
                    string t = ch + s;
                    s = t;
                }
                else s += ch;
            }
        }
    }
    if(rev%2) reverse(s.begin(), s.end());
    cout << s << endl;

    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}


Measured memory_bytes: 4196
#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1000000000 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int q, h, s, d;
int n;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> q >> h >> s >> d;
    cin >> n;
    int q1 = q * 4;
    int h1 = h * 2;
    int mn1 = min({q1, h1, s});
    int q2 = q * 8;
    int h2 = h * 4;
    int s2 = s * 2;
    int mn2 = min({q2, h2, s2, d});
    if (n % 2 == 0) cout <<  (n / 2) * mn2 << endl;
    else cout << (n / 2) * mn2 + mn1 << endl;
}


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

#define LINEMAX 1025
char train[60];

typedef struct _two {
	int head;
	int tail;
} TWO_T;

TWO_T maketrain( char str[LINEMAX] )
{
	int medium_stat = 30;
	TWO_T tval;
	tval.head = 30; tval.tail = 30;
	char *p; p = str;

	// 一番最初の文字列が列車の最初の車両としてスタート, 
	// 左・右に進むにつれて列車の構成を変更していく
	while ( *p ) {
		if ( isalpha( *p ) ) {
			train[medium_stat] = *p;
			p++;
		} else { 
			if ( *p == '-' ) {
				medium_stat++;
				if ( medium_stat > tval.tail ) {
					tval.tail = medium_stat;
				}
			} else if ( *p == '<' ) {
				medium_stat--;
				if ( medium_stat < tval.head ) {
					tval.head = medium_stat;
				}
			}
			p += 2;
		}
	}
	return tval;
}


int main()
{
	char str[LINEMAX];
	int num, midium_stat = 30;
	TWO_T tval;

	scanf( "%d", &num );

	for ( int i = 0 ; i < num ; i++ ) {
		memset( train, '0', sizeof( train ) );
		scanf( "%s", str );
		tval = maketrain( str );
		for ( int j = tval.head ; j <= tval.tail ; j++ ) {
			printf( "%c", train[j] );
		}
		printf( "\n" );
	}
	return 0;
}



Measured memory_bytes: 2564
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

struct UnionFind {
	std::vector<int> data;
	
	UnionFind(int n) {
		data.assign(n, -1);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if(x == y) return false;
		if(data[x] > data[y]) std::swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	int find(int k) {
		if(data[k] < 0) return k;
		return data[k] = find(data[k]);
	}
};

int main() {
	int n, m; scanf("%d%d", &n, &m);
	UnionFind uf(n);
	for(int i = 0; i < m; i++) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		
		uf.unite(a - 1, b - 1);
	}
	
	std::set<int> st;
	for(int i = 0; i < n; i++) st.insert(uf.find(i));
	printf("%d\n", (int)st.size());
	return 0;
}


Measured memory_bytes: 5376
#include <iostream>

using namespace std;

int main()
{
    unsigned long long W, H, x, y;
    cin >> W >> H >> x >> y;
    int multi = 0;
    double s = W * H / 2.0;
    if (x * 2 == W && y * 2 == H) {
	// 最適な分割が複数ある。
	multi = 1;
    }
    cout << s << " " << multi << endl;
    return 0;
}


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


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

    cout<<n-i+1<<endl;


    return 0;
}



Measured memory_bytes: 256
/*
  AOJ 0614
  Title:Railroad Trip
  @kankichi573
*/
#include <stdio.h>
#define min(x,y) (((x)<(y))?(x):(y))

int M,N,P0,P1,A,B,C,jousha_times[100000];
unsigned long long fare_all,paper,ic;

main()
{
  int i,j,ret;
  
  scanf("%d %d",&N,&M);
  
  scanf("%d",&P0);
  for(i=0;i<M-1;i++)
    {
        scanf("%d",&P1);

	if(P0<P1)
	  for(j=P0;j<P1;j++)
	    jousha_times[j-1]++;
	else
	  for(j=P0-1;j>=P1;j--)
	    jousha_times[j-1]++;

	P0=P1;
    }

  fare_all=0;
  for(i=0;i<N;i++)
    {
      scanf("%d %d %d",&A,&B,&C);
      paper=(long long)A*jousha_times[i];
      ic   =(long long)B*jousha_times[i]+C;
      fare_all += min(paper,ic);
    }
  printf("%llu\n",fare_all);
  return(0);
}

Measured memory_bytes: 988
H,W = map(int,input().split())

S = [list(input()) for i in range(H)]

for i in range(H):
    for j in range(W):
        ans = 0
        if S[i][j]=='.':
            for h in range(max(0,i-1),min(H,i+2)):
                for w in range(max(0,j-1),min(W,j+2)):
                    if S[h][w]=='#':
                        ans += 1
            S[i][j] = str(ans)
        
for i in range(H):
    print(''.join(S[i]))

Measured memory_bytes: 9152
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=n-1;i>=0;i-=2){
    cout<<a[i]<<" ";
  }
  if(n%2==0){
    for(int i=0;i<n;i+=2){
      cout<<a[i]<<" ";
    }
  }else{
    for(int i=1;i<n;i+=2){
      cout<<a[i]<<" ";
    }
  }
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

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

int main()
{
    int n, k, mx= 0;
    cin >> n >> k;
    int gc;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == k){
            cout << "POSSIBLE" << endl;
            return 0;
        }
        mx = max(mx, a[i]);
    }
    if(n != 1) gc = gcd(a[0], a[1]);
    else if(n==1 && k % a[0] == 0){
        cout << "POSSIBLE" << endl;
        return 0;
    }else{
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    if(mx < k){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    for(int i = 0; i < n; i++){
        gc = gcd(gc, a[i]);
    }

    if(k % gc == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 3632
N, A, B, C = [int(x) for x in input().split()]
L = [int(input()) for _ in range(N)]
INF = 10**8
def dfs(cur, a, b, c):
    if (cur == N):
        return abs(A-a) + abs(B-b) + abs(C-c) - 30 if (min(a,b,c) > 0) else INF
    ret0 = dfs(cur+1, a, b, c)
    ret1 = dfs(cur+1, a+L[cur], b, c) + 10
    ret2 = dfs(cur+1, a, b+L[cur], c) + 10
    ret3 = dfs(cur+1, a, b, c+L[cur]) + 10
    return min(ret0, ret1, ret2, ret3)
ans = dfs(0, 0, 0, 0)
print(ans)


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

int main(void) {
	int N,W[101],min=200,L_Sum=0,R_Sum=0;
		cin >> N;
		for (int i = 0; i < N; i++)
		{
			cin >> W[i];
			R_Sum += W[i];
		}
		
		for (int i = 0; i < N; i++) {
			//cout << "L_Sum->" << L_Sum << ",R_Sum->" << R_Sum << "i>" << i<< endl;
			if(min>abs(L_Sum-R_Sum)){
				min = abs(L_Sum - R_Sum);
			}
			R_Sum -= W[i];
			L_Sum += W[i];
		}

		cout << min;
		system("pause");
	return 0;
}

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

using namespace std;

int main()
{   

    string s;
    cin>>s;
    int ans = 0;
    int suf = 0;
    vector<int> count_suf(2019);
    count_suf[suf]++;
    int big = 2019;
    int power = 1;
    for(int i = s.length()-1;i>=0;i--)
    {
        int digit = s[i]-'0';
        suf = (suf + digit * power) % big;
        power = power * 10 % big;
        ans += count_suf[suf];
        count_suf[suf]++;
    }

    cout<<ans;


    return 0;
}

Measured memory_bytes: 3724
package main

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

type Node struct {
	key int
	children []int
}

func count(i, n int, p []Node) {
	p[i].key += n
	for _, v := range p[i].children {
		count(v, p[i].key, p)
	}
}

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := bufio.NewScanner(stdin)

	/* 単語ごとに入力するならこれ */
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())

	nodes := make([]Node, n)

	for i := 1; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())

		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		nodes[a - 1].children = append(nodes[a - 1].children, b - 1)
	}

	for i := 0; i < q; i++ {
		sc.Scan()
		p, _ := strconv.Atoi(sc.Text())

		sc.Scan()
		x, _ := strconv.Atoi(sc.Text())
		nodes[p - 1].key += x
	}

	count(0, 0, nodes)

	for i := 0; i < n; i++ {
		_, _ = fmt.Fprintf(stdout, "%d", nodes[i].key)
		if i != n - 1 {
			_, _ = fmt.Fprintf(stdout, " ")
		}
	}
	_, _ = fmt.Fprintf(stdout, "\n")
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}

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

using namespace std;

int main()
{long double x;long long a1=0,b1=0,c1=0,d1=0;
    long long a,b,c,d;
    cin>>a>>b>>c>>d>>x;
   long long sum=0;
    while(x>0)
    {
        if(d/2<a/0.25&&d/2<b/0.5&&d/2<c&&x>=2)
        {  d1+=floor(x/2);x-=floor(x/2)*2;

        }
        else if(c<a/0.25&&c<b/0.5&&x>=1)
        {

        c1+=x;
        x-=x;
        }
            else if(b/0.5<a/0.25&&x>=0.5)
            {

        b1+=floor(2*x);x-=floor(2*x);
            }
            else
            {
                a1+=x*4;
                   x=0;
            }
    }long long p=a1*a+b1*b+c1*c+d1*d;
    cout<<p<<endl;
    return 0;
}


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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()
template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

int main(){
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int ans=0;
    for(int i=0; i<=n; ++i){
        for(int j=0; j<=n; ++j){
            if((n-r*i-g*j)/b >= 0 && (n-r*i-g*j)%b==0)
                ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3564
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MOD 531441
using namespace std;

int n;
int fie[366][4][4];
bool dp[2][81*81*81];
int rx[9]={0,1,2,0,1,2,0,1,2};
int ry[9]={0,0,0,1,1,1,2,2,2};
int data[81*81*81][4][4];
int data2[9][4][4];

bool check(int v,int bit,int next){
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(data2[next][j][i]==1 && fie[v][j][i]==1)return false;
			if(v>=6 && data[bit][j][i]+data2[next][j][i]==0)return false;
		}
	}
	return true;
}

int main(void){
	for(int i=0;i<81*81*81;i++){
		int ni=i;
		for(int j=0;j<6;j++){
			data[i][rx[ni%9]][ry[ni%9]]=1;
			data[i][rx[ni%9]+1][ry[ni%9]]=1;
			data[i][rx[ni%9]][ry[ni%9]+1]=1;
			data[i][rx[ni%9]+1][ry[ni%9]+1]=1;
			ni/=9;
		}
	}
	for(int i=0;i<9;i++){
		data2[i][rx[i]][ry[i]]=1;
		data2[i][rx[i]+1][ry[i]]=1;
		data2[i][rx[i]][ry[i]+1]=1;
		data2[i][rx[i]+1][ry[i]+1]=1;
	}
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			for(int j=0;j<4;j++){
				for(int k=0;k<4;k++){
					scanf("%d",&fie[i][k][j]);
				}
			}
		}
		memset(dp,false,sizeof(dp));
		int now=1,prev=0;
		if(fie[0][1][1]+fie[0][2][1]+fie[0][2][2]+fie[0][1][2]==0)dp[prev][4]=true;
		for(int i=1;i<n;i++){
			for(int j=0;j<81*81*81;j++){
				if(dp[prev][j]){
					for(int k=0;k<9;k++){
						if(rx[j%9]!=rx[k] && ry[j%9]!=ry[k])continue;
						if(check(i,j,k)){
							//printf("%d %d %d\n",i,j,k);
							dp[now][(j*9+k)%MOD]=true;
						}
					}
				}
			}
			swap(now,prev);
			memset(dp[now],false,sizeof(dp[now]));
		}
		int res=0;
		for(int i=0;i<81*81*81;i++){
			if(dp[prev][i])res=1;
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 35312
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
  while(1){
    int d,e;
    cin >> d >> e;
    if(d==0) break;

    double minimum=1e9;
    for(int i=0; i<d; i++){
      int j=d-i;
      double diff = fabs(e- sqrt(i*i+j*j));
      minimum = min(diff, minimum);
    }
    cout << fixed;
    cout << setprecision(10);
    cout << minimum << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3188
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second 
#define ull unsigned long long  
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif


void solve()
{
    int n , a , b;
    cin >> n >> a >> b ;
    int res = max(n - a , n - b) ;
    res = min(res , max(a - 1 , b - 1)) ;
    if( (b - a) % 2 == 0) res = min(res , abs(b - a) / 2);
    else{
        {
            int st = a  ; // a at 1 ;
            // b -= st + 1 ; // b goes to b - a + 1 - 1 => b - a 
            int tmp = st + (b - a - 1) / 2 ;
            res = min(res , tmp);             
        }
        {
            int st = n - b + 1;
            // a goes to a + n - b + 1 , b at n // diff parity 
            res = min(res , st + (n - (a + n - b + 1 ))/2 );
        }
    }
    cout << res ;
    

}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        //cout << endl ;
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

int X;
int N, M;
ll ans;

vector<int> C;
vector<vector<int>> A;
vector<int> total;

void dfs(vector<int> b, vector<int> t, ll p) {
  // cout << endl;
  // cout << "---" << endl;
  // for (int bb : b) {
  //   cout << bb << ",";
  // }
  // cout << endl;
  // cout << "p:" << p << endl;
  // cout << "---" << endl;

  if (b.size() > 0) {
    bool f = true;
    REP(i, M) {
      if (t.at(i) < X) {
        f = false;
        break;
      }
    }
    if (f) {
      ans = min(ans, p);
      return;
    }
  }

  if (b.size() == 0) {
    b.push_back(0);
  } else {
    b.push_back(b.back() + 1);
  }

  while (b.size() <= N && b.back() < N) {
    REP(i, M) { t.at(i) += A.at(b.back()).at(i); }
    dfs(b, t, p + C.at(b.back()));
    REP(i, M) { t.at(i) -= A.at(b.back()).at(i); }
    ++b.back();
  }
}

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

  ans = 1 << 29;
  cin >> N >> M;
  cin >> X;
  C = vector<int>(N);
  A = vector<vector<int>>(N);
  total = vector<int>(M);

  int a;
  REP(i, N) {
    cin >> C.at(i);
    REP(j, M) {
      cin >> a;
      A.at(i).push_back(a);
      total.at(j) += a;
    }
  }
  REP(i, M) {
    if (total.at(i) < X) {
      cout << -1 << endl;
      return 0;
    }
  }

  dfs({}, vector<int>(M, 0), 0);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3668
#include <iostream>

using namespace std;

void f(int a, int b) {
    int c = a + b;
    if (c >= 10) {
        cout << "error" << endl;
        return;
    }
    cout << c << endl;
}

int main() {

    int a, b;
    cin >> a >> b;

    f(a, b);

    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
#define per(i , j , n) for(long long i = j ; i >= n ; i--)
const ll N = 123456;

int a[123][123];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    set < int > res;

    rep(i , 1 , 10000) {
        res.insert(i * i);
    }

    int n;
    cin >> n;
    int d;
    cin >> d;

    rep(i , 1 , n) {
        rep(j , 1 , d) {
            cin >> a[i][j];
        }
    }

    int cnt = 0;

    rep(i , 1 , n) {
        rep(j , i + 1 , n) {
            int sum = 0;
            rep(k , 1 , d) {
                sum += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
            }

            if(res.find(sum) != res.end()) cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


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

int main(){
    int n = 0;
    cin >> n;
    int a[2][n],sum=0,MAX=0;
    int flag=0,p;
    int ans=0;

    for (int i = 0; i < n; i++)cin >> a[0][i];
    for (int i = 0; i < n; i++)cin >> a[1][i];

    for (int i = 0; i < n; i++){
        ans=0;
        for (int j = 0; j <= i; j++){
            ans += a[0][j];
        }
        for (int j = i; j < n; j++){
            ans += a[1][j];
        }
        
        MAX=max(ans,MAX);
    }
    ans=MAX;

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int ans = (x - a) % b;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//--- pB ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	public Solution () {
		reader = new Reader();
		while (reader.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		// String line = scanner.nextLine();
		// int N = Integer.parseInt(line.split("\\s+")[0]);
		// int K = Integer.parseInt(line.split("\\s+")[1]);
		int[][] grid = new int[3][3];
		for (int i=0; i<3; i++) {
			for (int j=0; j<3; j++) {
				grid[i][j] = ni();
			}
			// grid[i] = strToIntArray(scanner.nextLine());
		}

		boolean[][] choosen = new boolean[3][3];

		// String line = scanner.nextLine();
		// int N = Integer.parseInt(line.split("\\s+")[0]);
		int N = ni();
		for (int i=0; i<N; i++) {
			// int t = Integer.parseInt(scanner.nextLine());
			int t = ni();
			for (int u=0; u<3; u++) {
				for (int v=0; v<3; v++) {
					if (grid[u][v] == t) {
						choosen[u][v] = true;
					}
				}
			}
		}

		// Check
		for (int i=0; i<3; i++) {
			int cnt = 0;
			for (int j=0; j<3; j++) {
				if (choosen[i][j]) cnt++;
			}
			if (cnt == 3) {
				System.out.println("Yes");
				return;
			}
		}

		for (int i=0; i<3; i++) {
			int cnt = 0;
			for (int j=0; j<3; j++) {
				if (choosen[j][i]) cnt++;
			}
			if (cnt == 3) {
				System.out.println("Yes");
				return;
			}
		}

		int cnt = 0;
		for (int i=0; i<3; i++) {
			if (choosen[i][i]) cnt++;
		}
		if (cnt == 3) {
			System.out.println("Yes");
			return;
		}

		cnt = 0;
		for (int i=0; i<3; i++) {
			if (choosen[2-i][i]) cnt++;
		}
		if (cnt == 3) {
			System.out.println("Yes");
			return;
		}


		System.out.println("No");
		return;
	}
	private int ni() {return Integer.parseInt(reader.next());}
	private String ns() {return reader.next();}
}

class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
}


Measured memory_bytes: 21460
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;
 
int lcs(string X, string Y) {
    int c[N + 1][N + 1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 0; i <= m; i++)c[i][0] = 0;
    for (int j = 1; j <= n; j++)c[0][j] = 0;
 
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (X[i] == Y[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }
 
    return maxl;
}
 
int main() {
    string s1, s2;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
 
    return 0;
}


Measured memory_bytes: 7104
N, M = map(int, input().split())
Hs = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(M)]

ans = [True for _ in range(N)]

for a in arr:
    f, s = a
    H1 = Hs[f - 1]
    H2 = Hs[s - 1]
    if H1 == H2:
        ans[f - 1] = False
        ans[s - 1] = False
    elif H1 < H2:
        ans[f - 1] = False
    else:
        ans[s - 1] = False

print(len(list(filter(lambda x: x, ans))))

Measured memory_bytes: 32676
n,q = map(int, input().split())
a = []
t = 0
for i in range(n):
    a.append(input().split())
 
while len(a) != 0:
    A =  a.pop(0)
    if int(A[1]) <= q:
        t += int(A[1])
        print(A[0],t)
    else:
        t += q
        A[1] = int(A[1]) - q
        a.append(A)


Measured memory_bytes: 17112
N, M = map(int, input().split())
X_list = sorted(list(map(int, input().split())))
res = []
for idx, x in enumerate(X_list):
    if idx == M-1:
        break
    else:
        res.append(X_list[idx+1] - x)
        
res.insert(0, 0)
union = zip(res, [i for i in range(M)])
union = sorted(union, key=lambda x: x[0])[-1::-1]
res_, idx_list = zip(*union)
res_, idx_list

idx_list = list(idx_list)

setting_idx =  idx_list[:N-1]
setting_idx.append(0)
setting_idx = sorted(setting_idx)

ans = sum(res)
for idx in setting_idx:
    ans -= res[idx]
print(ans)

Measured memory_bytes: 26688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
int main()
{
    string n;
    int ans = 999;
    cin >> n;
    rep(i, n.size() - 2)
    {
        ans = min(ans, abs(753 - ctoi(n[i]) * 100 - ctoi(n[i + 1]) * 10 - ctoi(n[i + 2])));
    }

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

Measured memory_bytes: 256
import java.util.*;

public class Main {

	static void log(int i) {
		System.out.println(i);
	}
	static void log(String s) {
		System.out.println(s);
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int ary[] = new int[n];
		long total=0;
		
		for (int i=0; i<n; i++) {
			ary[i] = sc.nextInt();
			total+=ary[i];
		}
		
		int aryPick[] = new int[m];
				
		// loop for input data
		int ctr=0;
		for (int j =0; j<n && ctr < m ; j++) {
			if ( (4 * m * ary[j]) >= total) {
				aryPick[ctr]=ary[j];
				ctr++;
			}
		}
		
		sc.close();
		log( (ctr<m) ? "No" : "Yes");
	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 
int a[1100];

int main()
{
	//fastIO;
	int n,m;
	cin >> n >> m;
	int sum = 0;
	rep(i,0,n) cin >> a[i], sum += a[i];
	int tot = sum / (4 * m);
	if(sum % (4 * m)) tot++;
	int cnt = 0;
	rep(i,0,n) {
		if(a[i] >= tot) cnt++;
	}	
	if(cnt >= m) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
while 1:
	try:
		a=raw_input()
		cjoi=cioi=0
		for i in range(len(a)-2):
			if a[i:i+3]=="JOI":
				cjoi+=1
			if a[i:i+3]=="IOI":
				cioi+=1
		print cjoi
		print cioi
	except:
		break		

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  REP(i, H) cin >> S[i];
  vector<vector<int>> tate(H, vector<int>(W, 0)), yoko(H, vector<int>(W, 0));
  REP(i, H) {
    REP(j, W) {
      if (S[i][j] == '.') {
        if (j == 0) {
          yoko[i][j] = 1;
          continue;
        }
        yoko[i][j] = yoko[i][j - 1] + 1;
        continue;
      }
      if (j == 0) continue;
      for (int k = (j - 1); k >= 0; k--) {
        if (yoko[i][k] == 0) break;
        yoko[i][k] = yoko[i][j - 1];
      }
    }
    for (int k = W - 1; k >= 0; k--) {
      if (yoko[i][k] == 0) break;
      yoko[i][k] = yoko[i][W - 1];
    }
  }
  REP(i, W) {
    REP(j, H) {
      if (S[j][i] == '.') {
        if (j == 0) {
          tate[j][i] = 1;
          continue;
        }
        tate[j][i] = tate[j - 1][i] + 1;
        continue;
      }
      if (j == 0) continue;
      for (int k = j - 1; k >= 0; k--) {
        if (tate[k][i] == 0) break;
        tate[k][i] = tate[j - 1][i];
      }
    }
    for (int k = H - 1; k >= 0; k--) {
      if (tate[k][i] == 0) break;
      tate[k][i] = tate[H - 1][i];
    }
  }
  ll ans = 0;
  REP(i, H) REP(j, W) {
    ans = max(ans, (ll)tate[i][j] + (ll)yoko[i][j] - (ll)1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 42292
# -*- coding: utf-8 -*-
import logging
import time


class Solver:
    def __init__(self):
        self.n = 0

    # 入力
    def input_value(self):
        # self.n = int(input())
        # self.A, self.B = map(int, input().split())
        # self.A = list(map(int, input().split()))
        # self.a, self.b, self.c = map(int, [input() for i in range(4)])
        # self.t = [None] * self.n
        self.n = int(input())

    @staticmethod
    def can_buy(n):
        # logging.debug(input_str)
        for i in range(26):
            for j in range(16):
                if 4 * i + 7 * j == n:
                    return 'Yes'
        return 'No'

        # logging.debug(input_str)

    # def run(self):
    #     if self.n % self.k == 0:
    #         return 0
    #     return 1

    # @staticmethod
    def test(self):
        start_time = time.time()

        assert self.can_buy(11), 'Yes'
        assert self.can_buy(40), 'Yes'
        assert self.can_buy(3), 'No'

        elapsed_time = time.time() - start_time
        logging.debug('elapsed_time: {0}'.format(elapsed_time) + '[sec]')


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)

    solver = Solver()

    # solver.test()

    solver.input_value()
    ans = solver.can_buy(solver.n)
    # print(str(ans))
    print(ans)


Measured memory_bytes: 4212
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
#define MAX_T 5000
ll table[MAX_T][MAX_T]={},a[MAX_T][MAX_T]={};
signed main(){
  init_io();
  ll n,k;
  cin >> n >> k;
  ll x,y;
  vector<char> c(n);
  for(int i=0;i<n;i++){
    cin >> x >> y >> c[i];
    if(c[i]=='W'){
      y += k;
    }
    x %= 2*k;
    y %= 2*k;

    table[x][y]++;
    table[x+k][y+k]++;
    table[x+k][y]--;
    table[x][y+k]--;

    x += k;
    y += k;

    table[x][y]++;
    table[x+k][y+k]++;
    table[x+k][y]--;
    table[x][y+k]--;
  }
  for(int i=0;i<4*k;i++){
    for(int j=0;j<4*k;j++){
      if(i!=0){
        table[i][j] += table[i-1][j];
      }
      if(j!=0){
        table[i][j] += table[i][j-1];
      }
      if(i!=0&&j!=0){
        table[i][j] -= table[i-1][j-1];
      }
    }
  }
  ll ans = 0;
  for(int i=0;i<4*k;i++){
    for(int j=0;j<4*k;j++){
      ll ti = i%(2*k),tj = j%(2*k);
      a[ti][tj] += table[i][j];
      ans = max(ans,a[ti][tj]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 236928
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

    long long cnt;
    vector<int> G;
    int A[1000000];
    int n;
    int l;

void insertionSort(int A[],int n, int g){
    for(int i=g;i<n;++i){
        int v=A[i];
        int j=i-g;
        while(j>=0 && A[j] > v){
            A[j+g] = A[j];
            j=j-g;
            cnt++;
        }
        A[j+g]=v;
    }

}

void shellSort(int A[], int n){
    int cnt=0;
    for(int h=1; ;){
        if(h > n) break;
        G.push_back(h);
        h = 3*h+1;
    }
    for(int i=G.size()-1;i>=0;--i){
    insertionSort(A,n,G[i]);
    }

}

int main(){
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> A[i];
    }
    shellSort(A,n);
    cout << G.size() << endl;
    for(int i=G.size()-1 ;i>=0;--i){
        printf("%d", G[i]);
        if(i) printf(" ");
    } 
    printf("\n");
    cout << cnt << endl;
    for(int i=0;i<n;++i){
        printf("%d\n",A[i]);
    }
    return 0;
}



Measured memory_bytes: 7176
def main():
    #input data
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    N,A,B = map(int,input().split())
    mod=10**9+7
    #solve
    #二項係数の和=2**n
    #2**n-1-nCa-nCb
    
    def cmb(n, r, mod=10**9+7):
        c = 1
        m = 1
        r = min(n - r, r)
        for i in range(r):
            c = c * (n - i) % mod
            m = m * (i + 1) % mod
        return c * pow(m, mod - 2, mod) % mod
                
    ans = pow(2,N,mod)-1-cmb(N,A,mod)-cmb(N,B,mod)
    print(ans%mod)

if __name__=='__main__':
    main()

Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define ll long long
#define pp pair<int,int> 
const int INF = 1001001001;
//int 2×10の9乗

//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n){
    //rep(j,m) cin >> a[i][j]; 
  //}
 
int main() {
  int n;
  cin >> n;
   cout << n*n*n << endl;
}    

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:
// ABC 070 D

template <typename T> class Graph {
public:
	struct edge {
		int from;
		int to;
		T cost;
	};

	int n;
	vector<edge> edges;
	vector<vector<int>> graph;	

	Graph(int _n) : n(_n) {
		graph.resize(n);
	}

	int add_edge(bool undirected, int from, int to, T cost = 1){
		assert(0 <= from && from < n && 0 <= to && to < n);
		const int id = (int) edges.size();
		graph[from].push_back(id);
		if(undirected) graph[to].push_back(id);
		edges.push_back({from, to, cost});
		return id;
	}

	void dfs(int v,int p, T d);
};

const int nmax = 100010;
ll dist[nmax];

template <typename T> void Graph<T>::dfs(int v, int p, T d){
	cerr << v <<  " " << p << " " << d << endl;
		
	dist[v] = d;
	for(auto &id: graph[v]){
		const auto &e = edges[id];
		const int to = v ^ e.from ^ e.to;
		if(to == p) continue;
		Graph::dfs(to, v, d + e.cost);
	}
}

int main(void){
	int n;
	cin >> n;
	Graph<ll> graph(n);

	rep(i,n-1){
		ll a,b,c;
		cin >> a >> b >> c;
		a--,b--;
		graph.add_edge(true,a,b,c);
	}

	int q,k;
	cin >> q >> k;
	k--;

	graph.dfs(k, -1, 0LL);

	rep(loop,q){
		int x,y;
		cin >> x >> y;
		cout << dist[x-1] + dist[y-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 15856
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		long ans = 0;
		long end = 0;
		for (int i = 0; i < n; i++) {
			ans -= Math.max(end - a[i], 0);
			ans += t;
			end = a[i] + t;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 63896