akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll cal_score(vector<ll> &c, vector<vector<ll>> &s, vector<ll> v) {
	ll score = 0;
	ll n = v.size();
	vector<ll> now(26);
	REP(i, n){
		score += s[i][v[i]];
		REP(j, 26)now[j]++;
		now[v[i]] = 0;
		REP(j, 26)score -= c[j] * now[j];
	}
	return score;
}

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

	ll d;cin >> d;
	vector<ll> c(26);REP(i, 26)cin >> c[i];
	vector<vector<ll>> s(d, vector<ll>(26));
	REP(i, d)REP(j, 26)cin >> s[i][j];

	vector<pair<ll, vector<ll>>> lis;
	REP(i, 26)lis.EB(cal_score(c, s, {i}), vector<ll>(1, i));

	REP(i, d-1){
		sort(ALL(lis), greater<pair<ll, vector<ll>>>());
		lis.resize(min((ll)lis.size(), 5LL));
		vector<pair<ll, vector<ll>>> now;

		for(auto seica: lis){
			REP(i, 26){
				vector<ll> tmp = seica.SE;
				tmp.PB(i);
				now.EB(cal_score(c, s, tmp), tmp);
			}
		}

		lis = now;
	}

	sort(ALL(lis), greater<pair<ll, vector<ll>>>());
	REP(i, d){
		cout << (lis[0].SE[i]+1) << endl;
	}


	return 0;
}


Measured memory_bytes: 4576
n,h,w=map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
#print(ab)

ans=0

for i in range(n):
    if(ab[i][0]>=h and ab[i][1]>=w):
        ans+=1
print(ans)

Measured memory_bytes: 9336
n = gets.to_i
strs = []
n.times { strs << gets.chomp }

checks = []
strs.each do |str|
  checks << str.chars.sort.join('')
end

checks = checks.group_by { |i| i }.values

count = 0
checks.each do |check|
  count += check.size*(check.size-1)/2
end

puts count

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T INF = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T, typename U> istream& operator>>(istream& in, pair<T, U>& a) { cin >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& in, vector<T>& a) { for (T& x : a) cin >> x; }

void LOG(const int& x) { cerr << x << "\n"; }
void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }

int ceil(int a, int b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

class UnionFind { private: vector<int> par; vector<int> rnk; int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); } public: UnionFind(int size) { par.resize(size); rnk.resize(size); REP(i, size) par[i] = i, rnk[i] = 0; } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y) { return find(x) == find(y); } };

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

void moveX(int x) {
  if (x > 0) REP(_, x) cout << 'R';
  else REP(_, -x) cout << 'L';
}

void moveY(int y) {
  if (y > 0) REP(_, y) cout << 'U';
  else REP(_, -y) cout << 'D';
}

signed main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  moveX(tx - sx);
  moveY(ty - sy);
  moveX(sx - tx);
  moveY(sy - ty);
  moveX(-1);
  moveY(ty - sy + 1);
  moveX(tx - sx + 1);
  moveY(-1);
  moveX(1);
  moveY(sy - ty - 1);
  moveX(sx - tx - 1);
  moveY(1);
}

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

using namespace std;
using ll  = long long;
using ii  = pair < int , int >;
using pll = pair < ll , ll >;
using i3  = pair < int , ii >;
using vi  = vector < int >;
using vl  = vector < ll >;
using vii = vector < ii >;
using vi3 = vector < i3 >;

const int N = 1e5 + 5;
const ll INF = 1e12;
const double eps = 1e-9 , PI = acos(-1);

int n , m;
char s[N];

void solve(){
    scanf("%s" , s);

    if(s[0] == s[1]){
        printf("1 2\n");
        return;
    }

    for(int i = 1 ; s[i+1] ; i ++){
        if(s[i] == s[i-1]){
            printf("%d %d\n" , i , i+1);
            return;
        }

        if(s[i] == s[i+1]){
            printf("%d %d\n" , i+1 , i+2);
            return;
        }

        if(s[i-1] == s[i+1]){
            printf("%d %d\n" , i , i + 2);
            return;
        }
    }

    printf("-1 -1\n");
}

main(){
    int t = 1;
    //scanf("%d" , &t);

    while( t -- ){
            solve();
    }

    return 0;
}





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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return (lx<=x&&x<ux&&ly<=y&&y<uy);
}

void dfs(vector<vector<int>> &s,int w,int h,int x,int y){
	s[y][x]=0;
	repi(dx,-1,2){
		repi(dy,-1,2){
			if(valid(0,w,0,h,x+dx,y+dy)&&s[y+dy][x+dx]==1){
				dfs(s,w,h,x+dx,y+dy);
			}
		}
	}
}

int main()
{
	int w,h;
	while(cin>>w>>h,w!=0&&h!=0){
		vector<vector<int>> s(h,vector<int>(w,0));
		rep(y,h)rep(x,w)cin>>s[y][x];

		int ans=0;
		rep(y,h){
			rep(x,w){
				if(s[y][x]==1)ans++,dfs(s,w,h,x,y);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  int copy_N = N;
  int sum = 0;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }
  if (copy_N % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const ll maxn=100000;

ll mod=INF;
ll comb[maxn+41];
ll rcomb[maxn+41];

ll pow(ll x,ll y){
    if(y==0){
        return ll(1);
    }else if(y==1){
        return ll(x);
    }else if(y%2==0){
        ll a=pow(x,y/2);
        return (a*a)%mod;
    }else{
        ll a=pow(x,(y-1)/2);
        return a*a%mod*x%mod;
    }
}

int main(){
    
    comb[0]=1;
    rcomb[0]=1;
    ll ans=0;
    ll n,m;
    cin >> n>>m;
    
    for(ll i=1;i<=maxn+40;i++){
        comb[i]=(comb[i-1]*i)%mod;
    }
    
    rcomb[maxn+40]=pow(comb[maxn+40],INF-2);
    
    for(ll i=maxn+39;i>=0;i--){
        rcomb[i]=rcomb[i+1]*(i+1)%mod;
    }
    
    
    ll div=2;
    
    if(n==1||m==1){
        cout << 1<<endl;
        return 0;
    }
    
    while(div<=m){
        ll cnt=0;
        while(true){
            if(m%div==0){
                cnt++;
                m = m/div;
            }else{
                if(cnt==0)break;
                if(ans==0)ans=comb[n+cnt-1]*rcomb[cnt]%mod*rcomb[n-1]%mod;
                else ans=(ans*(comb[n+cnt-1]*rcomb[cnt]%mod*rcomb[n-1]%mod))%mod;
                
                break;
            }
        }
        div++;
    }
    
    cout << ans<<endl;
    
    return 0;
}


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

int main () {
  int n;
  cin>>n;
  
  int g[100001][3];
  for (int i=0;i<n;i++) {
    for (int j=0;j<3;j++) {
      cin>>g[i][j];
    }
  }
  
  int dp[100001][3]={0};
  dp[0][0]=0;
  dp[0][1]=0;
  dp[0][2]=0;
  
  for (int i=0;i<n;i++) {
    for (int j=0;j<3;j++) {
      for (int k=0;k<3;k++) {
        if (j==k) {
          continue;
        }
        else {
          dp[i+1][k]=max(dp[i][j]+g[i][k],dp[i+1][k]);
        }
      }
    }
  }
  cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
  
}

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

int main()
{
	int N;
	while (cin >> N) {
		int count = 0;
		for (int i = 0; i < 600 / N - 1; i++) {
			count += N * (N + i * N)*(N + i*N);
		}
		cout << count<<endl;
	}
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if (1 <= a && a <= 9 && 1 <= b && b <= 9) cout << a * b << endl;
	else cout << -1 << endl;
	return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; i++) cin >> h.at(i);
  int ans = 0;
  int tmp = 0;
  for (int i = 1; i < N; i++) {
    if (h.at(i) >= h.at(i-1)) continue;
    else {
      ans += h.at(i-1) - tmp;
      tmp = h.at(i);
    }
  }
  ans += h.at(N-1) - tmp;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

string text,in;
int cur,len;

int main()
{
	int CS, n;
	cin >> CS; cin.ignore();
	for (int cs = 0; cs < CS; cs++) {
		getline(cin,text);
		cin >> n; cin.ignore();
		len = text.size();
		cur = 0;
		for (int i = 0; i < n; i++) {
			getline(cin, in);
			if (in == "forward char")
				cur = min(cur+1,len);
			else if (in == "backward char")
				cur = max(cur-1,0);
			else if (in == "delete char") {
				if (cur >= text.size()) continue;
				text.erase(text.begin()+cur); len--;
			} else if (in.find("insert") != in.npos) {
				int s = in.find('"'), t = in.find('"',s+1);
				text = text.substr(0,cur) + in.substr(s+1,t-s-1) + text.substr(cur);
				cur += t-s-1; len += t-s-1;
			} else if (in == "forward word") {
				while (cur < len && text[cur] == ' ') cur++;
				while (cur < len && text[cur] != ' ') cur++;
			} else if (in == "backward word") {
				while (cur > 0 && text[cur-1] == ' ') cur--;
				while (cur > 0 && text[cur-1] != ' ') cur--;
			}
			else if (in == "delete word") {
				int s = cur, t;
				while (text[s] == ' ') s++;
				if (s >= len) continue;
				for(t = s; text[t] != ' ' && t < len; t++);
				text = text.substr(0,cur) + text.substr(t);
				len -= t-cur;
			}
		}
		cout << text.substr(0,cur) << "^" << text.substr(cur) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  string S,T,U;
  int a,b;
  cin >> S >> T;
  cin >> a >> b;
  cin >> U;
  if(S==U) a--;
  else b --;
  cout << a << ' ' << b << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int n,i;
    cin>>n>>i;
    if(n%i==0)cout << 0<< endl;
    else cout << 1<< endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main(void){
    int n, i;
    int t=0, h=0;
    char tarou[1100], hanako[1100];
    
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf("%s %s", &tarou, &hanako);
        if(strcmp(tarou, hanako) > 0) {
            t+=3;
        } else if(strcmp(tarou, hanako) < 0) {
            h+=3;
        } else {
            t++; h++;
        }   
    }
    printf("%d %d\n", t, h);
    return 0;
}


Measured memory_bytes: 2044
module StringMap = Map.Make (struct
  type t = string
  let compare = compare
end)

let () = Scanf.scanf "%d" @@ fun n ->
  let ss = Array.init n @@ fun _ ->
    Scanf.scanf " %s" @@ fun s ->
      let aa = Array.init (String.length s) (String.get s) in
      Array.sort compare aa;
      String.init (String.length s) (Array.get aa) in
  let strmap = Array.fold_left (fun m s ->
    StringMap.add s
      (1 + try StringMap.find s m with Not_found -> 0) m)
    StringMap.empty ss in
  let ans = StringMap.fold (fun _ n acc -> acc + n * (n - 1) / 2) strmap 0 in
  Printf.printf "%d\n" @@ ans

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

vector<int> ZAlgorithm(string s){
	vector<int> z(s.size());
	z[0] = s.size();
	int i = 1, j = 0;
	while (i < s.size()) {
		while (i+j < s.size() && s[j] == s[i+j]) ++j;
		z[i] = j;
		if (j == 0) { ++i; continue;}
		int k = 1;
		while (i+k < s.size() && k+z[k] < j) z[i+k] = z[k], ++k;
		i += k; j -= k;
	}
	return z;
}

class Solution {
public:
	void solve() {
		int n;
		string s;
		cin >> n >> s;
		int ret = 0;
		for(int i=0; i < n; i++){
			vector<int> z = ZAlgorithm(s.substr(i));
			for(int j=0; j < z.size(); j++)updmax(ret, min(z[j],j));
		}
		cout << ret << "\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 384
import math
a, b = map(int, input().split())
ans = []
for i in range(1010): #math.ceil(1009*0.1)=100
    p8 = math.floor(i * 0.08)
    p10 = math.floor(i * 0.1)
    if p8 == a and p10 == b:
        ans.append(i)

if len(ans) != 0:
    print(min(ans))
else:
    print(-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
//a^n modをO(logN)で計算
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    map<int,int> p;
    rep(i,n){
        cin>>a[i];
        p[a[i]]++;
    }
    bool exi = true;
    if(n%2==0){
        for(auto c:p){
            int cnt = c.second;
            if(cnt!=2){
                exi = false;
            }
        }
        if(exi){
            cout<<modpow(2,n/2,big);
        }
        else{
            cout<<0<<endl;
        }
    }
    else{
        for(auto c:p){
            int v = c.first;
            int cnt = c.second;
            if(v==0){
                if(cnt!=1){
                    exi = false;
                }
            }
            else{
                if(cnt!=2){
                    exi = false;
                }
            }
        }
        if(exi){
            cout<<modpow(2,n/2,big)<<endl;
        }
        else{
            cout<<0<<endl;
        }
    }

}

Measured memory_bytes: 3584
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools
from collections import defaultdict

N,K,*A = map(int,read().split())

A = [0] + [x-1 for x in A]

# 和が0となる場所を答えればよい

Acum = list(itertools.accumulate(A))
Acum = [x % K for x in Acum]

counter = defaultdict(int)
answer = 0
for i,x in enumerate(Acum):
    answer += counter[x]
    counter[x] += 1
    if i >= K-1:
        counter[Acum[i-K+1]] -= 1

print(answer)

Measured memory_bytes: 41416
# 解説AC
from fractions import gcd
def judge(A,B,C,D):
    if A < B: return False
    if D < B: return False
    if C >= B: return True
    
    g = gcd(B, D)

    return False if ((B - g + (A % g)) > C) else True

T = int(input())
for _ in range(T):
    A,B,C,D = map(int, input().split())
    if judge(A,B,C,D): print('Yes')
    else: print('No')

Measured memory_bytes: 5688
#include<bits/stdc++.h>
using namespace std;
int n,d,a;
long long ans=0;
struct node
{
	int x,h,hh;
}m[200005];
bool cmp(node u,node v)
{
	return u.x<v.x;
}
int main()
{
	cin>>n>>d>>a;
	for(int i=0;i<n;i++)
	{
		cin>>m[i].x>>m[i].h;
		m[i].h=(m[i].h+a-1)/a;
	}
	sort(m,m+n,cmp);
	int l=0,cnt=0;
	for(int i=0;i<n;i++)
	{
		while(m[i].x-m[l].x>d*2)
		{
			cnt-=m[l].h;
			l++;
		}
		ans+=max(0,m[i].h-cnt);
		m[i].h-=cnt;
		m[i].h=max(0,m[i].h);
		cnt+=m[i].h;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
int main(void){
    int n,m,a;
    while(cin>>n>>m>>a,n){
        map<int, set<int>> amida;
        rep(i,m){
            int h,p,q;
            cin>>h>>p>>q;
            if(amida.find(h)==amida.end()) amida[h]=set<int>();
            amida[h].insert(p);
        }
        for(int i=1000;i>0;i--){
            if(amida[i].count(a)==1) a++;
            else if(amida[i].count(a-1)==1) a--;
        }
        cout<<a<<endl;
    }
}

Measured memory_bytes: 3120
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1000000007;

int main() {
  ll n, d, a;
  cin >> n >> d >> a;

  d *= 2;

  vP lst(n);
  rep(i, n) {
    ll x, h;
    cin >> x >> h;
    lst[i] = P(x, (h + a - 1) / a);
  }
  Sort(lst);

  queue<P> q;
  ll ans = 0;
  ll tot = 0;
  rep(i, n) {
    ll x = lst[i].first;
    ll h = lst[i].second;
    while (q.size() && q.front().first < x) {
      tot -= q.front().second;
      q.pop();
    }
    h -= tot;
    if (h > 0) {
      ans += h;
      tot += h;
      q.emplace(x + d, h);
    }
  }  // i

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

ll toleft[111111][50], toright[111111][50];

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	ll n, l, q;
	cin >> n;
	vi x(n);
	REP(i, n) cin >> x[i];
	cin >> l;
	MS(toleft, 0);
	MS(toright, 0);
	REP(i, n)
	{
		ll lp = x[i] - l;
		if (lp <= x[0]) toleft[i][0] = 0;
		else
		{
			toleft[i][0] = lower_bound(ALL(x), lp) - x.begin();
		}
		ll rp = x[i] + l;
		if (rp >= x[n-1]) toright[i][0] = n-1;
		else
		{
			toright[i][0] = upper_bound(ALL(x), rp) - x.begin() - 1;
		}
	}
	FOR(j, 1, 50)REP(i, n)
	{
		toleft[i][j] = toleft[toleft[i][j - 1]][j - 1];
		toright[i][j] = toright[toright[i][j - 1]][j - 1];
	}
	cin >> q;
	while (q--)
	{
		ll a, b; cin >> a >> b;
		a--; b--;
		ll ans = 0, p = a;
		if (a < b)
		{
			while (p != b)
			{
				if (toright[p][0] >= b)
				{
					p = b;
					ans++;
				}
				else
				{
					for (int i = 32; i >= 0; i--)
					{
						if (toright[p][i] < b)
						{
							p = toright[p][i];
							ans += pow(2, i);
							break;
						}
					}
				}
			}
		}
		else
		{
			while (p != b)
			{
				if (toleft[p][0] <= b)
				{
					p = b;
					ans++;
				}
				else
				{
					for (int i = 32; i >= 0; i--)
					{
						if (toleft[p][i] > b)
						{
							p = toleft[p][i];
							ans += pow(2, i);
							break;
						}
						if (i == 0)
						{
							p = b;
							ans++;
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 88064
package main

import (
	"fmt"
	"regexp"
)

var pattern = regexp.MustCompile("((3+5+7+)|(3+7+5+)|(5+3+7+)|(5+7+3+)|(7+5+3+)|(7+3+5+))+")

func main() {
	var n int
	fmt.Scan(&n)
	fmt.Println(dfs(n, 0))
}

func dfs(max, data int) int {
	if data > max {
		return 0
	}
	var result int
	if pattern.MatchString(fmt.Sprint(data)) {
		result += 1
	}
	return dfs(max, data*10+3) + dfs(max, data*10+5) + dfs(max, data*10+7) + result
}


Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
using namespace std;

int main() {
	int n,m, ans;
	cin >> n;
	ans = 0;
	m = n / 100;
	if (m * 11 >= n % 100) {
		ans = m * 111;
	}
	else {
		ans = (m + 1) * 111;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

int main() {
    int n;
    cin >> n;
    cout << (n * n * n) << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

/*
void Foo() {
	// アドレスを出力
	int a;
	char b[10];
	cout << (size_t)&a  << endl;
	cout << (size_t)b   << endl; // 関数や配列は名前を書くだけ
	cout << (size_t)Foo << endl;
}

int main() {
	Foo();
}
*/

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a * c <= b) {
		cout << c << endl;
	} else {
		cout << b / a << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, N) for (int i=0; i<(int)N; i++)
#define rep1(i, N) for (int i=1; i<(int)N; i++)

using namespace std;

int N, M;

int main() {
  cin >> N >> M;
  int s[M], c[M];
  rep(i, M) {
    cin >> s[i] >> c[i];
  }
 
  int ans = -1;
  int count_correct;
  for (int i = pow(10, N-1); i < pow(10, N); i++) {
    count_correct = 0;
    rep(j, M) {
      int k = floor(i / pow(10, (N-s[j])));
      if (k%10 == c[j]) {
        count_correct++;
      }
    }
    if (count_correct == M) ans = i;
    if (ans != -1) break;
  }
  if(N==1 && c[0]==0) {
    ans = 0;
  }
  
  cout << ans;
}


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

int main() {
	vector<map<double,string>>t(0);
	while (1) {
		int k;
		cin >> k;
		if (k == 0)break;	
			map<double, string>s;
			auto c = 0.01;
			for (int b = 0; b < k; b++) {
				string d; double e, f, g;
				cin >> d >> e >> f >> g;
				s.insert(pair<double, string>((e * 3 + f * 0 + g * 1 + (1 - c)), d));
				c += 0.01;
			}
			t.push_back(s);
	}
	for (int u = 0; u < t.size(); u++) {
		auto y = t[u].end(); y--;
		for (;; y--) {
			cout << y->second << "," <<(int) y->first << endl;
			if (y == t[u].begin())break;
		}
		if (t.size() - 1 != u)cout << endl;
	}
}

Measured memory_bytes: 3260
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def divisors(n):
    S,T=[],[]
    for i in range(1,int(n**.5)+1):
        if n%i==0:
            S.append(i)
            T.append(n//i)
    T.reverse()
    return S+T if S[-1]!=T[0] else S+T[1:]

def resolve():
    n=int(input())
    ans=0
    for i in range(1,n+1,2):
        ans+=(len(divisors(i))==8)
    print(ans)
resolve()

Measured memory_bytes: 38480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b;cin >> a >> b;
	int ans=0;
	for(ll i=a;i<=b;i*=2){
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N, M; cin >> N >> M;
  vector<pair<int,int>> sc(M); rep(i,M) cin >> sc[i].first >> sc[i].second;
  int s,g;
  if(N==1) {
    s=0; g=9;
  }
  if(N==2){
    s=10; g=99;
  }
  if(N==3){
    s=100; g=999;
  }
  for(int i=s; i<=g; i++){
    string ss = to_string(i);
    int cnt = 0;
    rep(j,M){
      if(ss[sc[j].first-1]-'0' == sc[j].second) cnt++;
    }
    if(cnt == M){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstdlib>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    char s[n+1];
    scanf("%s",s);
    for(int i = 0; i < n; i++){
        if(i == k - 1){
            s[i] -= ( 'A' - 'a');
        }
    }
    for(int i = 0 ; i < n; i++){
        printf("%c", s[i]);
    }
    cout << endl;
    return 0;
}

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

int main() {
  string s,t;cin>>s>>t;
  int ans=1e9;
  rep(i,s.size()-t.size()+1){
    int cnt=0;
    rep(j,t.size()){
      if(s[i+j]!=t[j])cnt++;
    }
    ans=min(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3564
use std::io;
use std::cmp::Ordering;
use std::str::FromStr;

fn get_line() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).ok();
    line
}

fn get_vector() -> Vec<i32> {
    let line = get_line();
    let vec : Vec<i32> = line.split_whitespace().map(|x| i32::from_str(x).unwrap()).collect();
    return vec;
}

fn main() {
    let mut vec = get_vector();
    vec.sort();
    println!("{} {} {}", vec[0], vec[1], vec[2]);

}



Measured memory_bytes: 5036
#include<iostream>
using namespace std;
int main()
{
  int N,X,T,n,rem;
  std::cin>>N>>X>>T;
  n=N/X;
  rem=N-n*X;
  if(rem == 0)
  {
    std::cout<<n*T;
  }
  else
  {
  std::cout<<n*T+((rem/X)+1)*T<<endl;
  }
  return 0;
}


Measured memory_bytes: 3632
L, R = map(int, input().split())
MOD = 2019
l = L % MOD
r = R % MOD
ans = 2019

if l >= r or l == 0 or r == 0 or (R - L) >= 2019:
    ans = 0
else:
    for i in range(l, r):
        for j in range(l + 1, r + 1):
            if j <= i:
                continue
            else:
                ans = min(ans, i * j % MOD)

print(ans)


Measured memory_bytes: 3060
N = int(input())
b = list(map(int,input().split()))
ans = []
t = 0
while len(b) > 0:
    f = 1
    for k in range(len(b),-1,-1):
        if b[k-1]==k:
            f = 0
            b.pop(k-1)
            ans.append(k)
            break
    if f:
        print(-1)
        exit(0)
print(*ans[::-1], sep = "\n")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int main(){
        string a,b;
	cin>>a>>b;
	if(a[0]=='H'){
	   cout<<b<<endl;
	}else{
	   b[0]=b[0]-2*(b[0]-'F');
	   cout<<b<<endl;
	}
	return(0);
}

Measured memory_bytes: 256
for p in range(5):
    n, k = map(int, input().split())
    if n == 0 and k == 0:
        break
    a = []
    for i in range(n):
        a_ = int(input())
        a.append(a_)

    s = [0 for i in range(n+1)]
    for i in range(n):
        s[i+1] = s[i] + a[i]

    ans = -10*18
    for i in range(n-k+1):
        if s[i+k] - s[i] > ans:
            ans = s[i+k] - s[i]

    print(ans)


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

int main(){
  int n,k,s;
  cin >> n >> k >> s;
	for(int i=0; i<k; i++) cout << s << " ";
	for(int i=k; i<n; i++){
		if(s!=1000000000) cout << s+1 << " ";
		else cout << 1 << " ";
	}
	cout << endl;
	return 0;
}

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

int main() {
  int N, M;
  vector<int> p;
  vector<string> S;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int x;
    string y;
    cin >> x >> y;
    p.push_back(x);
    S.push_back(y);
  }

  int AC_SUM = 0, WA_SUM = 0;
  map<int, int> C;
  map<int, bool> AC;

  for (int i = 0; i < M; i++) {
    if (AC[p[i]]) {
      continue;
    }
    if (S[i] == "WA") {
      C[p[i]] += 1;
    } else if (S[i] == "AC") {
      WA_SUM += C[p[i]];
      AC_SUM += 1;
      AC[p[i]] = true;
    }
  }

  cout << AC_SUM << " " << WA_SUM << endl;
}


Measured memory_bytes: 15472
/*input
0 2 3 4 5
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long 
#define ld long double
#define pii pair<int,int>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e12;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1){
            res=(res*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=1e7+5;
const ll maxlg=__lg(maxn)+2;
int main(){
    REP(i,5){
        int x;
        cin>>x;
        if(x==0){
            cout<<i+1;
        }
    }
}


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

int main(){
    int a,b,x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    a=y2-y1;
    b=x2-x1;
    cout<<x2-a<<" "<<y2+b<<" "<<x1-a<<" "<<y1+b<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
  FIO
  
  int n,k;
  cin>>k>>n;
  int a[n];
  forn(i,n)cin>>a[i];
  int maxi=0;
  sort(a,a+n);
  int cnt=0;
  forn(i,n-1)
  {
    cnt+=a[i+1]-a[i];
    maxi=max(maxi,abs(a[i+1]-a[i]));
  }
  cnt+=k-a[n-1]+a[0];
  maxi=max(maxi,k-a[n-1]+a[0]);
  cout<<cnt-maxi;

  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

struct UnionFind{
  vector<int> par,s;
  UnionFind(int N):par(N),s(N){
    REP(i,N)par[i]=i;
    REP(i,N)s[i]=1;
  }
  int root(int x){
    if(par[x]==x)return x;
    return par[x]=root(par[x]);
  }
  lint tree_size(int x){
    return s[root(x)];
  }
  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry)return;
    par[rx]=ry;
    s[ry]=s[rx]+s[ry];
  }
};

int main(){
  lint N,M;
  cin>>N>>M;
  int A[M],B[M];
  REP(i,M){
    cin>>A[i]>>B[i];
    A[i]--;
    B[i]--;
  }
  lint ans[M];
  ans[M-1]=(N*(N-1))/2;
  UnionFind t(N);
  for(int i=M-1;i>0;i--){
    ans[i-1]=ans[i];
    if(t.root(A[i])!=t.root(B[i]))ans[i-1]-=t.tree_size(A[i])*t.tree_size(B[i]);
    t.unite(A[i],B[i]);
  }
  REP(i,M)cout<<ans[i]<<endl;

  return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>

int main(){
    int a,b,m,m1,m2;
    long x,y,x1=0,x2=1,y1=1,y2=0;
    scanf("%d %d",&a,&b);
    /*printf("a=%d,b=%d\n",a,b);*/
    m2 = a;
    m1 = b;
    m = a%b;
    x = 1;
    y = -(a/b);
    while(m){
        m2 = m1;
        m1 = m;
        m = m2%m1;
        x2 = x1;
        x1 = x;
        x = x2-(m2/m1)*x1;
        y2 = y1;
        y1 = y;
        y = y2-(m2/m1)*y1;
        /*printf("%d = %d*a + %d*b\n",m1,x1,y1);*/
    }
    printf("%d %d\n",x1,y1);
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	LL N;
	while (cin >> N) {
		if (N == 0) {
			cout << 0 << endl; continue;
		}

		int b = 0;
		LL p = 1;
		LL lb = 0;
		LL ub = 1;

		while (N < lb || ub <= N) {
			chmin(lb, lb + p);
			chmax(ub, ub + p);
			p *= -2;
			b++;
		}
		p /= -2;
		string ret;
		while (b > 0) {
			if (p > 0) {
				ub -= p;
			}
			else lb -= p;
			if (N < lb || ub <= N) {
				ret += '1';
				N -= p;
			}
			else ret += '0';
			b--;
			p /= -2;
		}
		cout << ret << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;

int main() {
	int n; cin >> n;
	int sum = 0;
	int t[100];
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		sum += t[i];
	}
	int m; cin >> m;
	int p[100], x[100];
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> x[i];
	}
	for (int i = 0; i < m; i++) {
		int sum1 = sum;
		sum1 -= t[p[i] - 1];
		sum1 += x[i];
		cout << sum1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	# define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
	#define endl "\n"
	#define all(v) v.begin(),v.end()
	#define mod 1000000007 ;
	typedef long long ll;

	void IO()
	{
		#ifndef ONLINE_JUDGE
				freopen("input.txt","r",stdin);
				freopen("output.txt","w",stdout);
		#endif 
	}


	vector<bool> used(200000);
	vector<int> adj[200000];
	vector<int> a,b;
	void bfs(int i)
	{	
	queue<int> q;
		q.push(i);
		used[i] = 1;
		a.push_back(i);
		while(!q.empty())
		{	i = q.front();
			q.pop();
			for(auto vertex:adj[i])
			{	
				if(used[vertex]==-1)
				{
					used[vertex] = used[i]^1;
					if(used[vertex]==1) a.push_back(vertex);
					else b.push_back(vertex);
					q.push(vertex);
				}
				if(used[vertex]==used[i]){
					cout<<-1;
					exit(0);
				}
				
				
			}


		}
	}

	int in[200000][4];
	int dp[200000][4] ;

	int n;
	int rec(int day,int prev)
	{
		if(day == n) return 0 ;
		
		if(dp[day][prev]!=-1) return dp[day][prev];

		int maxi = 0 ;

		if(prev == 0)
		{
			maxi = max(maxi , in[day][1] + rec(day+1,1));
			maxi = max(maxi , in[day][2] + rec(day+1,2));
			maxi = max(maxi , in[day][3] + rec(day+1,3));
		}
		else if(prev == 1)
		{	
			maxi = max(maxi, in[day][2] + rec(day+1,2));
			maxi = max(maxi , in[day][3] + rec(day+1,3));
		}
		else if(prev == 2)
		{
			maxi = max(maxi , in[day][1] + rec(day+1,1));
			maxi = max(maxi , in[day][3] + rec(day+1,3));
		}
		else {
			maxi = max(maxi , in[day][1] + rec(day+1,1));
			maxi = max(maxi , in[day][2] + rec(day+1,2));
		}
		return dp[day][prev] =  maxi ;
	}
		
	void solve()
	{
			cin>>n;
			for(int i = 0;i<n;i++)
			{
				cin>>in[i][1]>>in[i][2]>>in[i][3];
			}
			memset(dp,-1,sizeof(dp));
			cout<<rec(0,0);
	}
	int main()
	{
		IO();
		fast;

		// int t;cin>>t;while(t--)
		solve();

					

		return 0;
	}





Measured memory_bytes: 20740
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18 
 
using namespace std;
 
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int n,x,y,i,j;
    cin>>n>>x>>y;
    vi v(n);
    for(i=1;i<n;i++)
    {
        int ans=0;
        for(j=i+1;j<=n;j++)
        {
            int dis=j-i;
            dis=min(dis,abs(x-i)+abs(y-j)+1LL);
            v[dis]++;
        }
    }
    for(i=1;i<n;i++) cout<<v[i]<<endl;
}

Measured memory_bytes: 3600
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    s,c=MI()
    ans=min(s,c//2)
    s-=ans
    c-=ans*2
    ans+=c//4
    print(ans)

main()

Measured memory_bytes: 3064
'''     ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█  
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     '''


# [temp1.py] => [29-07-2020 @ 10:25:10] 
# Author & Template by : Udit "luctivud" Gupta
# https://www.linkedin.com/in/udit-gupta-1b7863135/


import math;   from collections import *
import sys;    from functools import reduce
import time;   from itertools import groupby

# sys.setrecursionlimit(10**6)

def input()         : return sys.stdin.readline()
def get_ints()      : return map(int, input().strip().split())
def get_list()      : return list(get_ints())
def get_string()    : return list(input().strip().split())
def printxsp(*args) : return print(*args, end="")
def printsp(*args)  : return print(*args, end=" ")


DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)] 
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1),\
              (+1, +1), (+1, +0), (+1, -1), (+0, +1)]


CAPS_ALPHABETS = {chr(i+ord('A')) : i for i in range(26)}
SMOL_ALPHABETS = {chr(i+ord('a')) : i for i in range(26)}
INF = float('inf')


# Custom input output is now piped through terminal commands.
# for _test_ in range(int(input())): 
n = int(input())
s = input().strip('\n')
k = int(input())
target = s[k-1]

for i in s:
	if i != target:
		printxsp('*')
	else:
		printxsp(target)





# print("Time Elapsed: {}".format(float(S34p-S34t)))


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


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

  char a;
  cin >> a;
  if(a-'a'>=0 && a-'a'<26){
    cout << "a" << endl;
  }
  else {
    cout <<"A" << endl;
  }
  return 0;
    

}


Measured memory_bytes: 3648
n = int(input())
a = list(map(int, input().split()))

b = []

for i in range(n-1, -1, -2):
	b.append(str(a[i]))

if n % 2 == 0:
	for i in range(0, n, 2):
		b.append(str(a[i]))
else:
	for i in range(1, n, 2):
		b.append(str(a[i]))

print(" ".join(b))

Measured memory_bytes: 31940
while 1:
    keisansiki = list(input().split())
    a,op,b = int(keisansiki[0]),keisansiki[1],int(keisansiki[2])
    if op == '?':
        break
    if op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '*':
        print(a*b)
    else:
        print(a//b)


Measured memory_bytes: 5600
a, b = map(int, input().split())
c = min(int(a/0.08), int(b/0.1))
while(1):
  if int(c*0.08)==a and int(c*0.1)==b:
    print(c)
    exit()
  else:
    c+=1
    if int(c*0.08)>a and int(c*0.1)>b:
      print(-1)
      exit()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 3010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];
int dp[MAXN][MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	for (int i=1; i<=n; i++) cin>>A[i];
	for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) dp[i][j]=(A[i]<A[j]);
	for (int t=1; t<=m; t++){
		cin>>x>>y;
		
		vector<piii> vec;
		vec.pb({{x, y}, (dp[x][y]+dp[y][x])*(mod+1ll)/2%mod});
		vec.pb({{y, x}, (dp[x][y]+dp[y][x])*(mod+1ll)/2%mod});
		
		for (int i=1; i<=n; i++) if (i!=x && i!=y){
			vec.pb({{x, i}, (dp[x][i] + dp[y][i])*(mod+1ll)/2%mod});		
			vec.pb({{i, x}, (dp[i][x] + dp[i][y])*(mod+1ll)/2%mod});		
			vec.pb({{y, i}, (dp[x][i] + dp[y][i])*(mod+1ll)/2%mod});
			vec.pb({{i, y}, (dp[i][x] + dp[i][y])*(mod+1ll)/2%mod});
		}
		for (piii p:vec) dp[p.first.first][p.first.second]=p.second;
		
	}
	for (int i=1; i<=n; i++) for (int j=1; j<i; j++) ans=(ans + dp[i][j])%mod;
	for (int i=0; i<m; i++) ans=ans*2%mod;
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 36016
A, B = map(int, input().split())

if B ==1:
  Answer = 0
elif B <= A:
  Answer = 1
elif (B -A) %(A-1)==0:
  Answer = 1 + (B-A)//(A-1)
else:
  Answer = 2 + (B-A)//(A-1)
  
print(Answer)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int n,i,j,c=1,a[100010];
  scanf("%d", &n);
  for(i=1;i<=n;i++)scanf("%d",&a[i]);
  for(j=a[1];j!=2;c++){
    j=a[j];
    if(c>n){
      printf("-1");return 0;
    }
  }
  printf("%d",c);return 0;}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)
bool valid(int n){
	if(n == 0 || n > 12) return false;
	return true;
}
int main()
{
	int n; cin>>n;
	int l=  n / 100;
	int r = n % 100;
	if(1 <= l && l <= 12){
		if(1 <= r && r <= 12){
			cout<<"AMBIGUOUS";
		}
		else cout<<"MMYY";
	}
	else {
		if(1 <= r && r <= 12){
			cout<<"YYMM";
			
		}
		else cout<<"NA";
	}
}


Measured memory_bytes: 256