akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#include<math.h>
using namespace std;

#define ll long long
#define vecint vector<int>
#define listint list<int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

int ans=0;
bool passed_vertex[8];

bool checkpass(bool passed_vertex[],int V){
  rep(i,V){
    if(passed_vertex[i]==false) return false;
  }
  return true;
}

void solve(int v,bool path[8][8],int V){
  rep(i,V){
    if(path[v][i]==true){
      bool array[8][8];
      rep(i,V){
        rep(j,V){
          array[i][j]=path[i][j];
        }
      }
      rep(j,V){
        path[j][i]=false;
      }
      passed_vertex[i]=true;
      solve(i,path,V);
      passed_vertex[i]=false;
      rep(j,V){
        path[j][i]=array[j][i];
      }
    }
  }
  if(checkpass(passed_vertex,V)) {
    ans++;
  }
  return;
}

int main(){
  int V,E;
  bool path[8][8];

  cin >> V >> E;
  rep(i,8){
    rep(j,8){
      path[i][j]=false;
    }
  }
  rep(i,E){
    int x,y;
    cin >> x >> y;
    path[x-1][y-1]=true;
    path[y-1][x-1]=true;
  }
  rep(i,8){
    passed_vertex[i]=false;
  }
  rep(i,V){
    path[i][0]=false;
  }
  passed_vertex[0]=true;
  solve(0,path,V);
  print(ans);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		N = N % 10;
		String ret = "hon";
		if(N == 3){
			ret = "bon";
		}else if(N == 0 || N == 1 || N == 6 || N == 8){
			ret = "pon";
		}
		System.out.println(ret);
	}
}


Measured memory_bytes: 27036
/*
    When you are not practicing someone else is,
    and the day u meet them u will Lose.

    So, all you need is Practice, Practice and Practice.
*/
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,a,b)       for(i=a;i<=b;i++)
#define FOR(i,a,b)      for(i=a;i>=b;i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define sz(v)           (int)v.size()
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p) {int ans=1;x%=mod;while(p>0){if(p&1)ans=(ans*x)%mod;p=p>>1;x=(x*x)%mod;}return ans;}
int inv(int x){return po(x,mod-2)%mod;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
/**********************************************************************************/



const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r,f,q;








void sol()
{   string s;
    cin>>n>>s;
    c=0;
    FO(i,0,n-3)
    {
        string x=s.substr(i,3);
        if(x=="ABC")c++;
    }
    
    
    
    cout<<  c<<endl;
}





int32_t main()
{   
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //pre();
    //sp(10);
    // w(t)
    sol();
    return 0;
}


Measured memory_bytes: 3588
N = int(input())

S = []
P = []
for i in range(N):
    sp = input().split()
    S.append(sp[0])
    P.append(int(sp[1]))

SP = list(zip(range(1,N+1),S,P))

SP.sort(reverse = True, key = lambda x : x[2])
SP.sort(key = lambda x : x[1])

for i in SP:
    print(i[0])

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

a, b, c, d = list(map(int, input().split()))

e = a+b
f = c+d
if e > f:
    print("Left")
if e == f:
    print("Balanced")
if e < f:
    print("Right")


Measured memory_bytes: 9028
using System;


namespace ConsoleApplication43
{
    class Program
    {
        static void Main(string[] args)
        {
            string w = Console.ReadLine();
            int sum = 0;            
            while (true)
            {
                string[] T = Console.ReadLine().Split(' ');

                if (T[0] == "END_OF_TEXT")
                {
                     break;
                }
                

                for(int i = 0 ; i < T.Length; i++)
                {

                    if (string.Equals(w, T[i], StringComparison.OrdinalIgnoreCase)) 
                    {
                        sum = sum + 1;
                    } 
                }
                                       
            }
            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 9276
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s;
 	int n = s.l_ength();
	int l = 0, r = n-1;
	int a = 0, b = n;
	while( l < r ){
		if( s[l] != s[l+1] ) a = l+1;
		if( s[r-1] != s[r] ) b = r;
		++l; --r;
	}
	cout << min( n-a, b ) << endl;
}

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

int main() {
  int x,y;
  cin>>x>>y;
  for(int c=0;c<=x;c++){
    int t=x-c;
    int asi=c*2+t*4;
    if(asi==y){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3640
def scoring(d, t, k=10):
    arr = [l for l in last]
    arr[t] = d
    score = S[d][t] -  sum((d - l) * c for l, c in zip(arr, C))
    for i in range(d + 1, min(d + k, D)):
        score -= sum((i - l) * c for l, c in zip(arr, C))
    return score

D = int(input())
C = list(map(int, input().split()))
S = []
for _ in range(D):
    s = list(map(int, input().split()))
    S.append(s)
last = [-1] * 26
ans = []
for i in range(D):
    res = -10 ** 6
    idx = -1
    for j in range(26):
        tmp = scoring(i, j)
        if tmp > res:
            res = tmp
            idx = j
    last[idx] = i
    ans.append(idx+1)
print(*ans, sep='\n')

Measured memory_bytes: 9484
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
    int a;
    bool ans = false;
    cin >> a;
    FOR(i,0,3) {
        if(a % 10 == 7){
            ans = true;
                    }
        a/=10;
    }
    if(ans == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
  

    return 0;
}


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

const int maxn = 5e5+10;

long long f[maxn];
long long f1[maxn];

int rv[maxn];

typedef pair<int,int> II;
typedef pair<int,II> III;

III a[maxn];


void update(long long *f, int x, int val) {
	x ++ ;
	while (x < maxn) {
		f[x] += val;
		x += x & -x;
	}
}

long long get(long long * f, int x) {
	x ++;
	long long res = 0;
	while (x ) {
		res += f[x];
		x -= x & -x;
	}

	return res;
}

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



	map<int,int> id;
	int cnt = 0;

	vector<int> vt;
	for(int i=0;i<n;i++) {
		cin >> a[i].first;
		if (a[i].first == 1) {
			cin >> a[i].second.first >> a[i].second.second;
			if (!id.count(a[i].second.first)) {
				vt.push_back(a[i].second.first);
			}
		} else {

		}
	}

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

	vt.erase(unique(vt.begin(), vt.end()), vt.end());

	for(int i=0; i < vt.size();i++) {
		id[vt[i]] = i;
	}

	int m = (int) vt.size();

	long long totalb = 0;
	long long total = 0;
	cnt = 0;
	for(int i=0;i<n;i++) {
		if (a[i].first == 1) {
			totalb += a[i].second.second;	
			//cerr << id[a[i].second.first] << endl;	
			update(f, id[a[i].second.first], a[i].second.first);
			update(f1, id[a[i].second.first], 1);
			total += a[i].second.first;
			cnt++;	
		} else {
			if (cnt == 0) {
				cout << 0 << " " << 0 << endl;
				continue;
			}	
			int l = 0;
			int r = m;
			int res = 0;

			while  (l <= r) {
				int g = (l+r) >>1;
				if (get(f1, g) >= (cnt+1) / 2) {
					res = g;
					r = g - 1;
				} else {
					l = g + 1;
				}
			}

			long long tmp = get(f1, res);

			long long t = get(f, res);
			
			res = vt[res];

			long long ans = tmp * res - t + (total - t) - res * (cnt - tmp);

			cout << res<<" " << ans + totalb << endl;	
		}	
	}
	return 0;
}


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

int gcc(int m, int n){
	if(n == 0) return m;
	return gcc(n, m%n);
}

int main(void){
	int x, y;
	cin >> x >> y;
	int g = gcc(x, y);
	int res = x+y;
	res = res - g + 1;
	cout << res << endl;  
	return 0;
}


Measured memory_bytes: 3112
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
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

X, Y = MAP()

x, y = 0, 0
while (X!=0 or Y!=0):
	if X * 2 == Y:
		x += X
		break

	elif Y * 2 == X:
		y += Y
		break

	elif X >= 3 and Y >= 3:
		x += 1
		y += 1
		X -= 3
		Y -= 3
	else:
		if X-1 == 0 and Y-2==0:
			y += 1
			break
		elif X-2 == 0 and Y-4==0:
			y += 2
			break

		elif X-2==0 and Y-1==0:
			x += 1
			break
		elif X-4==0 and Y-2==0:
			x += 2
			break
		else:
			print(0)
			sys.exit()

H = 10**6//2
W = 10**6//2
factorial = [1]
for i in range(1, H+W):
	factorial.append(factorial[i-1] * i % mod)


def power(x, y):
	if y == 0:
		return 1
	elif y == 1:
		return x % mod
	elif y % 2 == 0:
		return power(x, int(y/2)) ** 2 % mod
	else:
		return power(x, int((y-1)/2)) ** 2 * x % mod
def C(n, r):
	return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod

x_inv = [0] * (H+W)
x_inv[-1] = power(factorial[-1], mod-2)
for i in range(H+W-2, -1, -1):
	x_inv[i] = x_inv[i+1] * (i+1) % mod

# print(x, y)
if x == 0 or y == 0:
	print(1)
else:
	print(C(x+y, y))


Measured memory_bytes: 143440
def main():
  while True:
    n = int(input())
    if n == 0:
      break
    mp = ["0" + input() + "0" for _ in range(n)]
    mp.insert(0, "0" * (n + 2))
    mp.append("0" * (n + 2))
    score = [[[0] * 4 for _ in range(n + 2)] for _ in range(n + 2)]
    max_score = 0
    for i in range(1, n + 1):
      for j in range(1, n + 1):
        if mp[i][j] == "1":
          score[i][j][0] = score[i - 1][j][0] + 1
          score[i][j][1] = score[i][j - 1][1] + 1
          score[i][j][2] = score[i - 1][j - 1][2] + 1
          score[i][j][3] = score[i - 1][j + 1][3] + 1
          max_score = max(max_score, score[i][j][0], score[i][j][1], score[i][j][2], score[i][j][3])
        else:
          for k in range(4):
            score[i][j][k] = 0
    print(max_score)

main()


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

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

Measured memory_bytes: 3632
N = int(input())
x = []
y = []
h = []

for _ in range(N):
    tmp, tmp2, tmp3 = map(int, input().split())
    x.append(tmp)
    y.append(tmp2)
    h.append(tmp3)
    
# Cx, Cyについて全探索し、Hが一意に定まるかどうかを確かめる
# h_i == 0のとき、Hの最大値についての情報を記録する

for Cx in range(101):
    for Cy in range(101):
        H_tmp = []
        max_h_tmp = float("inf")
        
        for i in range(N):
            if h[i] == 0:
                max_h_tmp = min(max_h_tmp, abs(x[i]-Cx) + abs(y[i]-Cy))
            else:
                H_tmp.append(h[i] + abs(x[i]-Cx) + abs(y[i]-Cy))
        
        H_tmp = set(H_tmp)
        if max(H_tmp) <= max_h_tmp and len(H_tmp) == 1:
            print(Cx, Cy, list(H_tmp)[0])
            exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
int main() {
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<int> len(n);
  rep(i,n) cin >> len[i];
  
  auto dfs = [&](auto& f, int x = 0, int y = 0, int z = 0, int i = 0)->int{
    if (i == n) {
      if (!x || !y || !z) return INF;
      return abs(a - x) + abs(b - y) + abs(z - c);
    }
    int res = f(f, x, y, z, i + 1);
    res = min(res, f(f, x + len[i], y, z, i + 1) + (x ? 10 : 0));
    res = min(res, f(f, x, y + len[i], z, i + 1) + (y ? 10 : 0));
    res = min(res, f(f, x, y, z + len[i], i + 1) + (z ? 10 : 0));
    return res;
  };

  cout << dfs(dfs) << endl;
  return 0;
} 

Measured memory_bytes: 3592
h,w,k=map(int,input().split())
g=[list(input()) for _ in range(h)]
c=0
ans=[[0]*w for _ in range(h)]
for i in range(h):
    cc=0
    for j in range(w):
        if g[i][j]=="#":
            c+=1
            cc=c
            ans[i][j]=cc
        else:
            ans[i][j]=cc
for i in range(h-1,-1,-1):
    for j in range(w-1,-1,-1):
        if 0<=i<h and 0<=j<w-1 and ans[i][j]==0:
            ans[i][j]=ans[i][j+1]
for i in range(1,h):
    if ans[i].count(0)==w:
        ans[i]=ans[i-1]
for i in range(h-1,-1,-1):
    if ans[i].count(0)==w:
        ans[i]=ans[i+1]



for i in range(h):
    print(*ans[i])


Measured memory_bytes: 49756
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> txy(3 * N);
  for(int i = 0; i < 3 * N; i++) {
    cin >> txy.at(i);
  }
  int over = txy.at(0) - (abs(txy.at(1)) + abs(txy.at(2)));
  if(over < 0 || over % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  for(int i = 0; i < N - 1 ; i++) {
    over = txy.at((i+1) * 3) - txy.at(i * 3) - (abs(txy.at((i + 1) * 3 + 1) - txy.at((i) * 3 + 1)) + abs(txy.at((i + 1) * 3 + 2) - txy.at((i) * 3 + 2)));
    if(over >= 0 && over % 2 == 0) {
 
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

#define int long long
#define INF 1e18

signed main() {
    string s; cin >> s;
    string t = "abcdefghijklmnopqrstuvwxyz";

    for(int i = 0; i < t.size(); i++) {
        if((int)s.find(t[i]) == -1) {
            cout << t[i] << endl;
            return 0;
        }
    }

    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
void shuffle(char *str, int n, int size){
    char ho[402]="";int i;
    strcat(ho,str);strcat(ho,str);
    for(i=n;i<n+size;i++) str[i-n]=ho[i];
}
int main(void){
    char target[10][201];
    int m,i,len,sh,cnt=0;
    while (1){
        scanf("%s",target[cnt]);
        if (target[cnt][0]=='-') break; 
        scanf("%d",&m);
        len=strlen(target[cnt]);   
        for(i=0;i<m;i++){scanf("%d",&sh);shuffle(target[cnt],sh,len);}
        cnt++;
    }   
    for(i=0;i<cnt;i++) printf("%s\n",target[i]);
    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, M;
vector<int> g[112345];
int dist[112345][3];
int S, T;

int main() {
	cin >> N >> M;
	REP(i, M) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		g[a].emplace_back(b);
	}
	cin >> S >> T;
	S--; T--;
	
	fill(dist[0], dist[N], INF);
	priority_queue<pii, vector<pii>, greater<pii> > pq;
	pq.push(pii(0, S));
	
	while (!pq.empty()) {
		int u, curd;
		tie(curd, u) = pq.top(); pq.pop();
		if (!chmin(dist[u][curd % 3], curd)) continue;
		
		for (int v : g[u]) {
			int nexd = curd + 1;
			if (dist[v][nexd % 3] > nexd) pq.push(pii(nexd, v));
		}
	}
	
	int ans = dist[T][0];
	if (ans == INF) ans = -1;
	else ans /= 3;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 7168
#include <iostream>
//#include <iomanip>

using namespace std;
//#define

int main() {
	int h, w;

	while(1){
		cin >> h >> w;
		if(h==0 && w==0) break;

		for(int i=1;i<=h;i++){
			for(int k=1;k<=w;k++){
				if((i%2 != 0 && k%2 != 0) || (i%2 == 0 && k%2 == 0)){
					cout << '#';
				} else {
					cout << '.';
				}
			}
			cout << "\n";
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 1120
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=110000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  ll n;
  cin >> n;
  map<ll,ll>mp;
  rep(i,n){
    ll x;
    cin >> x;
    mp[x]++;
  }
  ll cnt=0;
  for(auto p:mp){
    if(p.second>=2)cnt+=p.second-1;
  }
  if(cnt%2==1)cnt++;
  cout << n-cnt << endl;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <assert.h>
int n,i,j,x,a[10][10],list[200][3],size;
void push(int x,int y,int s){list[size][0]=i;list[size][1]=j;list[size][2]=s;size++;}

int check(int x,int y,int s){
	int d;
	if(s<3 && (x<1 || x>9 || y<1 || y>9)) return 0;
	if(s==3 && (x<2 || x>8 || y<2 || y>8)) return 0;
	d=a[x][y];
	if(a[x-1][y]<d)d=a[x-1][y];
	if(a[x+1][y]<d)d=a[x+1][y];
	if(a[x][y-1]<d)d=a[x][y-1];
	if(a[x][y+1]<d)d=a[x][y+1];
	if(s==1 || d==0)return d;
	if(a[x-1][y-1]<d)d=a[x-1][y-1];
	if(a[x+1][y+1]<d)d=a[x+1][y+1];
	if(a[x+1][y-1]<d)d=a[x+1][y-1];
	if(a[x-1][y+1]<d)d=a[x-1][y+1];
	if(s==2 || d==0)return d;
	if(a[x-2][y]<d)d=a[x-2][y];
	if(a[x+2][y]<d)d=a[x+2][y];
	if(a[x][y-2]<d)d=a[x][y-2];
	if(a[x][y+2]<d)d=a[x][y+2];
	return d;
}

void draw(int x,int y,int s,int d){
	if(size==3 && (x<2 || x>8 || y<2 || y>8)) return;
	a[x][y]+=d;
	a[x-1][y]+=d;
	a[x+1][y]+=d;
	a[x][y-1]+=d;
	a[x][y+1]+=d;
	if(s==1)return;
	a[x-1][y-1]+=d;
	a[x+1][y+1]+=d;
	a[x+1][y-1]+=d;
	a[x-1][y+1]+=d;
	if(s==2)return;
	a[x-2][y]+=d;
	a[x+2][y]+=d;
	a[x][y-2]+=d;
	a[x][y+2]+=d;
}

int search(int nn,int from){
	int i,x,y,s,t;
	for(i=from;i>=0;i--){
		x=list[i][0];y=list[i][1];s=list[i][2];
		//if(a[x][y]==0 && a[x+1][y]>0)return 0;
		if(x<8){
		if(s<3 && a[x+2][y]>0)return 0;
		//if(y==1 && a[x+2][y-1]>0)return 0;
		}
		//if(y==1 && s<2 && a[x+1][y-1]>0)return 0;
        //if(y==8 && s<2 && a[x+1][y+1]>0)return 0;
		t=check(x,y,s);
		if(t>0){
			draw(x,y,s,-t);
			for(;t>0;t--){
				if(s==1 && a[x+1][y+1]>0 && check(x-1,y+1,3)==0){draw(x,y,s,+1); if(t>1)continue; else return 0;}
				if(nn-t>0){
					if(search(nn-t,i-1)>0){goto answer;}
				}else{
					int p,q;
					for(p=0;p<10;p++)for(q=0;q<10;q++){{if(a[p][q]!=0)goto miss;}}
					goto answer;
					miss:;
				}
				draw(x,y,s,+1);
			}
		}
	}
	return 0;

	answer:
	for(;t>0;t--)printf("%d %d %d\n",y,x,s);
	return 1;
}

int main(void){
	scanf("%d",&n);size=0;
	for(i=0;i<10;i++){for(j=0;j<10;j++){scanf("%d",&a[i][j]);}}
	for(i=1;i<9;i++){
		for(j=1;j<9;j++){
			x=check(i,j,1); if(x==0)continue; push(i,j,1);
			x=check(i,j,2); if(x==0)continue; push(i,j,2);
			x=check(i,j,3); if(x==0)continue; push(i,j,3);
		}
	}
	search(n,size-1);
	return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<vector<ll>> g(n);
  vector<ll> mark(n, -1);
  for (ll i = 0; i < n-1; ++i) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  function<void(ll, ll)> solve;
  solve = [&] (ll pos, ll color) {
    ll next_color = color ? 0 : 1;
    each (i, g[pos]) {
      if (mark[i] >= 0) continue;
      mark[i] = next_color;
      solve(i, next_color);
    }
  };

  solve(0, 0);

  ll wc = 0; // white
  ll bc = 0; // black
  for (ll i = 0; i < n; ++i) {
    if (mark[i] == 0) wc++;
    else bc++;
  }

  vector<ll> v(n, 0);
  if (wc > n/3 && bc > n/3) {
    ll ai = 0, bi = 0, ci = 1;
    for (ll i = 0; i < n; ++i) {
      ll p;
      if (mark[i] == 0) {
        p = ai*3+1;
        ai++;
      } else {
        p = bi*3+2;
        bi++;
      }
      if (p > n) {
        p = ci*3;
        ci++;
      }
      v[i] = p;
    }
  } else {
    ll small = (wc <= n/3) ? 0 : 1;
    ll ai = 0, bi = 0, ci = 1;
    for (ll i = 0; i < n; ++i) {
      ll p;
      if (mark[i] == small) {
        p = ci*3;
        ci++;
      } else {
        p = ai*3+1;
        ai++;
        if (p > n) {
          p = bi*3+2;
          bi++;
        }
        if (p > n) {
          p = ci*3;
          ci++;
        }
      }
      v[i] = p;
    }
  }

  for (ll i = 0; i < n; ++i) {
    cout << v[i];
    if (i == n-1) cout << endl;
    else cout << " ";
  }

  return 0;
}

Measured memory_bytes: 21504
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
	
	public static int dfs(int node, final int n, boolean[] visited, boolean[][] adj, int time, int[] arrival_time, int[] end_time){
		visited[node] = true;
		arrival_time[node] = time;
		
		for(int next = 0; next < n; next++){
			if(!adj[node][next]){
				continue;
			}else if(visited[next]){
				continue;
			}
			
			time = dfs(next, n, visited, adj, time + 1, arrival_time, end_time);
		}
		
		end_time[node] = time + 1;
		return end_time[node];
	}
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		
		boolean[][] adj = new boolean[n][n];
		
		for(int i = 0; i < n; i++){
			final int u = sc.nextInt() - 1;
			final int k = sc.nextInt();
			
			for(int j = 0; j < k; j++){
				final int v = sc.nextInt() - 1;
				
				adj[u][v] = true;
			}
		}
		
		int time = 1;
		boolean[] visited = new boolean[n];
		int[] arrival_time = new int[n];
		int[] end_time = new int[n];
		for(int i = 0; i < n; i++){
			if(!visited[i]){
				time = dfs(i, n, visited, adj, time, arrival_time, end_time) + 1;
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.println((i + 1) + " " + arrival_time[i] + " " + end_time[i]);
		}
	}

	public static class Scanner {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public void close() throws IOException {
			br.close();
		}
	}

}

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

double calc_t(int h, int T) {
    return T - h * 0.006;
}

int main() {
    int N, T, A;
    cin >> N >> T >> A;

    int min_i = 1;
    double min_diff = INFINITY;
    int h;
    for (int i = 1; i <= N; i++)
    {
        cin >> h;
        if (min_diff > abs(A - calc_t(h, T))){
            min_diff = abs(A - calc_t(h, T));
            min_i = i;
        }
    }
    cout << min_i << endl;
}

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

vector<int>to[200005];
vector<int>ans;
void dfs(int v, int p = -1){
  for(auto u:to[v]){
    if(u == p) continue;
    ans[u] += ans[v];
    dfs(u, v);
  }
}
  

int main() {
  int n, q;
  cin >> n >> q;
  int a, b;
  rep(i,n-1){
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  int p, x;
  rep(i,q){
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n) cout << ans[i] << endl;
  
  return 0;
}


Measured memory_bytes: 23424
// Problem : F - LCS
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define ll long long 
#define ull unsigned long long
const int INF = 1e9 + 5;
#define pb push_back
#define eb emplace_back
#define vll vector<long long int>
#define vi vector<int>
#define loop(i, a, b) for(long long int i = a; i < b; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pii pair<ll, ll>
#define vpair vector<pii>
#define vbool vector<bool>
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define sec second
#define fir first
#define br '\n'
#define permute next_permutation
#define pqua priority_queue<ll>
#define pqud priority_queue<ll, vector<ll>, greater<ll> >
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define maxi *max_element
#define pi acos(-1)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(10)

vector<long long int> sieve(long long int n){
 	vector<long long int> primes;
 	bool isPrime[n+1] = {false};
 	isPrime[1] = isPrime[0] = false;
 	for(long long int i = 2;i<=n;i++)
 	{
 		isPrime[i] = true;
 	}
 	for(long long int i = 2;i*i<=n;i++)
 	{
 		if(isPrime[i])
 		{
 			for(long long int j = i*i;j<=n;j+=i)
 			{
 				isPrime[j] = false;
 			}
 		}
 	}
 	for(long long int i = 2;i<=n;i++)
 	{
 		if(isPrime[i])
 		{
 			primes.push_back(i);
 		}
 	}
 	return primes;
}

void print_vector2(vector<vector<ll> >v) {
    for(ll i=0;i<v.size();i++){
        for(ll j=0;j< v[i].size();j++){
            cout<<v[i][j]<<" ";
        }cout<<"\n";
    }
}

void print_vector1(vector<ll> v) {
    for(ll i=0; i<v.size();i++){
        cout<<v[i]<<" ";
    }cout<<"\n";
}

ll gcd(ll a, ll b) {
    return __gcd(a, b);
}

// v.back()
// v.erase(v.begin(), v.brgin + k)
// v.insert(at which place v.bigin() + 1 implines at i = 1, no. of times, value)
// v.insert(position, copy.begin(), copy.end())
// v1.swap(v2)
// v.clear() to clear v.empty() to check empty
// map assending order and set descending order 
// stringstream ss(str) Used for breaking words

int main(){
    FastIO;
    PRECISION;
	string a, b;
	cin>>a>>b;
	ll dp[a.size() + 1][b.size() + 1];
	for(ll i = 0; i <= a.size(); i++){
		for(ll j = 0; j <= b.size(); j++){
			if(i == 0 || j == 0){
				dp[i][j] = 0;
			}
			else if(a[i - 1] == b[j - 1]){
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	
	string s;
	ll i = a.size(), j = b.size();
	while(i > 0 && j > 0){
		if(a[i - 1] == b[j - 1]){
			s.pb(a[i - 1]);
			i--;
			j--;
		}
		else{
			if(dp[i - 1][j] >= dp[i][j - 1]){
				i--;
			}
			else{
				j--;
			}
		}
	}
	
	reverse(s.begin(), s.end());
	
	cout<<s;
    
    return 0;
}

Measured memory_bytes: 73952
x1,y1,x2,y2 = [int(x) for x in input().split()]


vx = x2-x1
vy = y2-y1

vx2,vy2 = (-vy,vx)
x3 = x2 + vx2
y3 = y2 + vy2
vx3,vy3 = (-vy2,vx2)
x4 = x3 + vx3
y4 = y3 + vy3

print(x3,y3,x4,y4)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    string s,X="ABC";
    cin>>s;
    if(s==X)
    cout<<"ARC";
    else
    cout<<"ABC";
    return 0;
}

Measured memory_bytes: 3608
//-------------------------------------------
//-               Train Fare                -
//-                                         -
//-       autumn_eel niha katemasen!        -
//-------------------------------------------
#include<iostream>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
int n, m, q, a[200001], b[200001], c[200001], d[200001], e[100001], dist[100001], E[200001];
vector<pair<int, int>>z[100001]; vector<int> x[100001];
vector<int>D[100001];
void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (true) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
int main() {
	reader(&n); reader(&m); reader(&q);
	fill(d, d + m + 1, 1 << 30);
	for (int i = 1; i <= m; i++) reader(&a[i]), reader(&b[i]);
	for (int i = 1; i <= q; i++) reader(&c[i]), d[c[i]] = i;
	for (int i = 1; i <= m; i++) {
		x[a[i]].push_back(b[i]);
		x[b[i]].push_back(a[i]);
	}
	fill(dist, dist + n + 1, -1); dist[1] = 0;
	queue<int> Q1; Q1.push(1);
	while (!Q1.empty()) {
		int a1 = Q1.front(); Q1.pop();
		for (int i : x[a1]) {
			if (dist[i] == -1) {
				dist[i] = dist[a1] + 1;
				Q1.push(i);
			}
		}
	}
	for (int i = 1; i <= m; i++) {
		if (dist[a[i]] > dist[b[i]])z[a[i]].push_back(make_pair(b[i], d[i]));
		if (dist[b[i]] > dist[a[i]])z[b[i]].push_back(make_pair(a[i], d[i]));
	}
	for (int i = 1; i <= n; i++) {
		D[dist[i]].push_back(i);
	}
	e[1] = (1 << 30);
	for (int i = 1; i < n; i++) {
		for (int j : D[i]) {
			for (pair<int, int>k : z[j]) {
				e[j] = max(e[j], min(e[k.first], k.second));
			}
		}
	}
	for (int i = 2; i <= n; i++) { if (e[i] < 300000)E[e[i]]++; }
	for (int i = 1; i <= q; i++)E[i] += E[i - 1];
	for (int i = 1; i <= q; i++) {
		printf("%d\n", E[i]);
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<ll> a(n+1),limit(n);
  rep(i, n+1)cin>>a[i];

  if(n==0){
    if(a[0]==1)cout<<1<<endl;
    else cout<<-1<<endl;
    return 0;
  }

  limit[n-1]=a[n]+a[n-1];
  rrep(i, n-1){
//cout<<limit[i+1]<<' '<<a[i]<<endl;
    limit[i] = limit[i+1]+a[i];
  }
  limit.push_back(a.back());

//  for(auto c:limit)cout<<c<<' ';cout<<endl;

  ll result = 1;
  ll l=1;

  if(a[0]==1 && n>0) { cout<<-1<<endl; return 0; }

  rep(i, n){
    ll c=a[i];

    ll nl = min<ll>((l-c)*2, limit[i+1]);
    if(l-c<0 || nl-a[i+1]<0) { 
//cout<<nl<<'-'<<a[i+1]<<endl;
cout<<-1<<endl; return 0;}
    if(l==0 && a[i]>0) { cout<<-1<<endl; return 0;}

    if(i<n-1)result += nl;
//cout<<l<<' '<<c<<' '<<l-c<<' '<<nl<<' '<<result<<endl;
    swap(l, nl);
  }
//cout<<l<<endl;
  if(a.back()>limit.back() || a.back()>l) { cout<<-1<<endl; return 0; }

  cout<<result+a.back()<<endl;

  return 0;
}


Measured memory_bytes: 5500
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    vector<long> x;

    cin >> n;

    int in;
    for (int i = 0; i < n; i++) {
        cin >> in;
        x.push_back(in);
    }

    vector<long> y = x;

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

    for (int i = 0; i < n; i++) {
        if (x[i] <= y[n/2 - 1]) {
            cout << y[n/2] << endl;
        } else {
            cout << y[n/2 - 1] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 5488
#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 dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	rep(i, n) {
		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0 && a[i] % 5 != 0) {
				puts("DENIED");
				return 0;
			}
		}
	}
	puts("APPROVED");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm> 
#include <cstring>
using namespace std;
int main (){
	int a,b,c,d,e;
	cin>>a>>b>>c;
	if(a>b){
		d=a-b;}
		else if(a<b){
			d=b-a;
		
	}
	if(a>c){
		e=a-c;}
		else if(a<c){
			e=c-a;
		}
	
	if(d>e){
		cout<<"B";}
		else if(d<e){
		cout<<"A"	;
		}
	
}

Measured memory_bytes: 256
def resolve():
    N, Y = list(map(int, input().split(" ")))
    for i in range(N+1):
        for j in range(N-i+1):
            k = N - i - j
            total = 10000*i + 5000*j + 1000*k
            if total == Y:
                print("{} {} {}".format(i, j, k))
                return
    print("-1 -1 -1")



if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38896
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
#define int long long

signed main(){
    int r,g,b;
    cin >> r >> g >> b;
    
    int ans = 0;
    ans = r*100+g*10+b;

    if(ans%4==0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a int
	fmt.Scan(&a)
	n := a%10
	if n==3 {
		fmt.Println("bon")
	} else if(n == 0 || n == 1 || n == 6 || n == 8) {
		fmt.Println("pon")
	} else {
		fmt.Println("hon")
	}
}

Measured memory_bytes: 1752
#include <stdio.h>

void put_hash(int n)
{
    while (n-- > 0)
        putchar('#');
}

void put_rectangle(int H, int W)
{

    for (int i = 0; i < H; i++)
    {
        put_hash(W);
        printf("\n");
    }
}

int main(void)
{
    while (1)
    {
        int H, W;
        scanf("%d %d", &H, &W);
        if (W == 0, H == 0)
        {
            break;
        }

        /*#を横にW個並べて改行をH回繰り返す*/

        // for (int i = 0; i < H; i++)
        // {
        //     put_hash(W);
        //     printf("\n");
        // }
        // printf("\n");

        put_rectangle(H, W);
        printf("\n");
    }
    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

constexpr int64 mod = 1e9+7;

int64 dp[112345][13];
string S;

int64 dfs(int64 d=0, int64 m=0) {
    assert(m < 13);
    int64 &res = dp[d][m];
    if (~res) return res;
    if (d >= S.size()) {
        if (m == 5) return res = 1;
        return 0;
    }
    res = 0;
    if (S[d] == '?') {
        REP(i, 10) {
            res += dfs(d+1, (m*10+i)%13);
            res %= mod;
        }
    } else {
        res += dfs(d+1, (m*10+S[d]-'0')%13);
        res %= mod;
    }
    return res%mod;
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> S;
	memset(dp, -1, sizeof dp);
	cout << dfs() << endl;
}


Measured memory_bytes: 18128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mo 1000000007
#define mems(a,x) memset(a,x,sizeof(a))
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}



int main() 
{ 
	ll n;
	cin>>n;
	ll a[n],b[n],c[n];
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	ll dp[n][3];
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	for(int i=1;i<n;i++)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];

	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	
	

} 

Measured memory_bytes: 4992
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.ReadLine();
            var numsS = Array.ConvertAll(Console.ReadLine().TrimEnd().Split(), int.Parse);
            Console.ReadLine();
            var numsT = Array.ConvertAll(Console.ReadLine().TrimEnd().Split(), int.Parse);
            int ans = 0;

            for (int i = 0; i < numsT.Length; i++)
            {
                var right = numsS.Length;
                var left = 0;
                var mid = numsS.Length / 2;

                while (left < right)
                {
                    if (numsT[i] < numsS[mid])
                    {
                        right = mid;
                        mid = (right - left) / 2 + left;
                    }
                    else if (numsT[i] > numsS[mid])
                    {
                        left = mid + 1;
                        mid = (right - left) / 2 + left;
                    }
                    else
                    {
                        ans++;
                        break;
                    }
                }
            }

            Console.WriteLine(ans);
        }
    }
}

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

int main()
{
    int h, w;

    while (true) {
        cin >> h >> w;

        if (h == 0 && w == 0) {
            return 0;
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main(){
	int K, S, res=0; cin>>K>>S;
  	for(int X=0;X<=K;X++)for(int Y=0;Y<=K;Y++){
      int Z=S-(X+Y);
      if(0<=Z&&Z<=K)res++;
    }
  	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
typedef long long ll;

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  ll c =n%(a+b);
  ll sum = (n/(a+b))*a+min(c,a);
  cout << sum << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
		
	ll A,B,C;
	cin>>A>>B>>C;
	if(A%2==0||B%2==0||C%2==0){
		ce(0)
	}else{
		ce(min({A*B,A*C,B*C}))
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <algorithm>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> cnt(N + 1, 0);
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    std::cin >> a;
    if (a > N) {
      ++ans;
    } else {
      ++cnt[a];
    }
  }
  for (int i = 0; i <= N; ++i) {
    if (cnt[i] < i) {
      ans += cnt[i];
    } else {
      ans += cnt[i] - i;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;
const int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

int main(int argc, char **argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    vll two(60); two[0] = 1; for(ll i = 1; i < 60; ++i) two[i] = (two[i-1]*2)%MOD;

    int N; cin >> N;
    vll A(N); for(auto &x: A) cin >> x;
    vll B(60);

    ll ans = 0;

    for(ll i = 0; i < N; ++i){
        ll s = A[i];
        for(ll j = 0; j < 60; ++j){
            B[j] += s%2;
            s >>= 1;
        }
    }
    for(ll i = 0; i < N-1; ++i){
        ll s = A[i];
        for(ll j = 0; j < 60; ++j){
            B[j] -= s % 2;
            s >>= 1;
        }
        s = A[i];
        ll kalan = N - 1 - i;
        for(int j = 0; j < 60; ++j){
            if(s % 2){
                ans += (two[j]*(kalan-B[j]))%MOD;
                ans %= MOD;
            }
            else{
                ans += (two[j]*B[j])%MOD;
                ans %= MOD;
            }
            s >>= 1;
        }
    }
    ans %= MOD;

    cout << ans << endl;

    return 0;
}

//cikisir



Measured memory_bytes: 2560
from math import *

n, d, a = map(int, input().split())
damage_diff = [0] * n
damage = 0
p = sorted(tuple(map(int, input().split())) for _ in range(n))

j = 0
c = 0

for i in range(n):
  damage -= damage_diff[i]
  
  x, h = p[i]
  h -= damage
  if h <= 0: continue
  m = ceil(h/a)
  c += m
  m = m*a
  while j < n and p[j][0] - x <= 2 * d:
    j += 1

  if j < n:
    damage_diff[j] += m
  damage += m
print(c)

Measured memory_bytes: 38020
function isPrime(num) {
    if (num == 2 || num == 3) return true;
    if (num < 2 || num % 2 == 0 || num % 3 == 0) return false;
    var limit = Math.round(Math.sqrt(num));
 
    var i = 1;
    while(i * 6 - 1 <= limit) {
        if (num % (i * 6 - 1) == 0 || num % (i * 6 + 1) == 0) return false;
        i++;
    }
    return true;
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.trim().split('\n');
 
var line;
while (line = lines.shift()) {
    var num = +line;

    var mp;
    var lp;

    if (num == 3)
        mp = 2;

    var i = 3;
    while (true) {
        if (isPrime(i) && i < num) {
            mp = i;
        }
        if (isPrime(i) && i > num) {
            lp = i;
            break;
        }
        i += 2;
    }
    console.log(mp, lp);
}

Measured memory_bytes: 8912