akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 4005; 

ll pre[N][3];

int main(){
	fast;
	ll n; cin >> n;
	string s; cin >> s;

	s = '.' + s;
	
	ll ans = 0;
	
	rep(i,1,n){
	    rep(j,0,2){
	        pre[i][j] = pre[i-1][j];
	    }
	    
	    if(s[i] == 'R') pre[i][0]++;
	    if(s[i] == 'G') pre[i][1]++;
	    if(s[i] == 'B') pre[i][2]++;
	}

	rep(i,1,n){
	    rep(j,i+3,n){
    	    set<char> st{'R','G','B'};
    	    st.erase(s[i]);
	        st.erase(s[j]);
	        char ch = 'A';
	        
	        if(st.size() == 1){
    	        for(auto x : st){
    	            ch = x;
    	            break;
    	        }
	        }
	        
	        if(ch == 'R'){
	            if((i + j) & 1){
	                ans += pre[j][0] - pre[i][0];
	            }
	            else{
	                ans += pre[j][0] - pre[i][0];
	                if(s[(i+j) / 2] == 'R') ans--;
	            }
	        }
	        if(ch == 'G'){
	            if((i + j) & 1){
	                ans += pre[j][1] - pre[i][1];
	            }
	            else{
	                ans += pre[j][1] - pre[i][1];
	                if(s[(i+j) / 2] == 'G') ans--;
	            }
	        }
	        if(ch == 'B'){
	            if((i + j) & 1){
	                ans += pre[j][2] - pre[i][2];
	            }
	            else{
	                ans += pre[j][2] - pre[i][2];
	                if(s[(i+j) / 2] == 'B') ans--;
	            }
	        }
	    }
	}
	
	cout << ans << endl;
}

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

int main(){
  int a, b, c, x, y, ans;
  cin >> a >> b >> c;
  x = max(max(a,b),c);
  y = 3*x-a-b-c;
  if(!(y%2)) ans = y/2;
  else ans = y/2 + 2;
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

  int result = max(a - 2 * b, 0);

  cout << result << endl;

  return 0;
}


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

int N;
int nextNum[114514];
int* nexts[114514];
int* henIndice[114514];

int answer[114514];

void asumikana(int idx, int pidx, int pcolor) {
	int i;
	int nextColor = 1;
	for (i = 0; i < nextNum[idx]; i++) {
		if (nexts[idx][i] == pidx) continue;
        int color;
        if (nextColor == pcolor) nextColor++;
        color = nextColor++;
        answer[henIndice[idx][i]] = color;
        asumikana(nexts[idx][i], idx, color);
	}
}

int main() {
  int i,K;
  if(scanf("%d",&N)!=1)return 1;
  for(i=1;i<N;i++){
    int a,b;
    if(scanf("%d%d",&a,&b)!=2)return 1;

    nexts[a] = realloc(nexts[a], sizeof(int) * (nextNum[a] + 1));
		nexts[a][nextNum[a]] = b;
		henIndice[a] = realloc(henIndice[a], sizeof(int) * (nextNum[a] + 1));
		henIndice[a][nextNum[a]] = i;
		nextNum[a]++;

    nexts[b] = realloc(nexts[b],sizeof(int)*(nextNum[b]+1));
    nexts[b][nextNum[b]]=a;
    henIndice[b]=realloc(henIndice[b],sizeof(int)*(nextNum[b]+1));
    henIndice[b][nextNum[b]]=i;
    nextNum[b]++;
  }
  K=0;
  for(i=1;i<=N;i++){
    if(nextNum[i]>K)K=nextNum[i];
  }
  asumikana(1,0,0);

  printf("%d\n",K);
  for(i=1;i<N;i++){
    printf("%d\n",answer[i] );
  }

  for(i=1;i<=N;i++){
    free(nexts[i]);
    free(henIndice[i]);
  }
  return 0;
}


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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const long long mod = 1000000007;
// auto mod int
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main(){
    int n;
    cin >> n;
    map<pll, pii> mp;
    int zero = 0;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        if (a==0 && b==0) {
            ++zero;
            continue;
        }
        ll g = gcd(a, b);
        a /= g, b /= g;
        if (b<0 || (b==0 && a<0)) a = -a, b = -b;
        bool rot = (a <= 0);
        if (rot) {
            ll tmp = a;
            a = b, b = -tmp;
        }
        if (rot) mp[{a, b}].second++;
        else mp[{a, b}].first++;
    }
    mint ans = 1;
    for (auto p : mp) {
        mint now = 1;
        now += mint(2).pow(p.second.first) - 1;
        now += mint(2).pow(p.second.second) - 1;
        ans *= now;
    }
    ans += zero - 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16108
#include<stdio.h>
#include<string.h>
int main(){
  int i;
  char s[1024];
  char *p;
  fgets(s,1024,stdin);
  while((p=strstr(s,"apple"))!=NULL){
    for(i=0;i<5;i++)
      s[p-s+i]='.';
  }
  while((p=strstr(s,"peach"))!=NULL){
      s[p-s+0]='a';
      s[p-s+1]='p';
      s[p-s+2]='p';
      s[p-s+3]='l';
      s[p-s+4]='e';
  }
  while((p=strstr(s,"....."))!=NULL){
      s[p-s+0]='p';
      s[p-s+1]='e';
      s[p-s+2]='a';
      s[p-s+3]='c';
      s[p-s+4]='h';
  }
  printf("%s",s);
  return 0;
}

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

void Main(){
    
}

int main () {
    int a, b, z, total = 0;
	cin >> a >> b >> z;
	for (int i=a ; i<=b ; i++){
		if(z%i == 0){
		
		total++;
		}	
	}
	cout << total << endl;
}


Measured memory_bytes: 3112
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int main()
{
 ll r;
  cin>>r;
  cout<<r*r;
}

Measured memory_bytes: 3596
#include<cstdio>
#include<vector>
using namespace std;

#define MAXN 500
#define PII pair<int,int>
int A[MAXN+5][MAXN+5];
vector<PII> S,T;

int main(){
    int H,W;
    scanf("%d%d",&H,&W);
    for(int i=1;i<=H;i++)
        for(int j=1;j<=W;j++)
            scanf("%d",A[i]+j);
    for(int i=1;i<=H;i++)
        for(int j=1;j<W;j++)
            if(A[i][j]&1){
                S.push_back(make_pair(i,j));
                T.push_back(make_pair(i,j+1));
                A[i][j]--,A[i][j+1]++;
            }
    for(int i=1;i<H;i++)
        if(A[i][W]&1){
            S.push_back(make_pair(i,W));
            T.push_back(make_pair(i+1,W));
            A[i][W]--,A[i+1][W]++;
        }
    printf("%d",S.size());
    for(int i=0;i<int(S.size());i++)
        printf("\n%d %d %d %d",S[i].first,S[i].second,T[i].first,T[i].second);
}


Measured memory_bytes: 5228
#include<stdio.h>

int main(void)
{
long int  n, T, t[200001], i, sum, rm;

scanf("%ld %ld", &n, &T);
for(i = 1; i <= n; i++){
 scanf("%ld", &t[i]);
}

sum = 0;
for(i = 1; i <= n; i++){
if(t[i]-t[i-1]<T){
sum+=t[i]-t[i-1];
}else{
sum+=T;
}
}
sum+=T;
printf("%ld\n", sum);

return 0;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    if((S.at(0)==S.at(1)&&S.at(1)==S.at(2))||S.at(1)==S.at(2)&&S.at(2)==S.at(3)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
 int main(void)
 {
     int A,B,K,i,j=0,C[100];

     scanf("%d%d%d",&A,&B,&K);

     for(i=1;i<=100;i++){
       if((A%i==0)&&(B%i==0)){
          C[j]=i; j++;
       }
     }
     printf("%d\n",C[j-K]);

     return 0;
 }



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
string a,b,c;
  int d,e;
  cin>>a>>b>>d>>e>>c;
  if(c==a)
 cout<<(d-1)<<" "<<e<<endl;
  else cout<<d<<" "<<(e-1)<<endl;
  
}

Measured memory_bytes: 256
#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;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
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;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void in(T&t){cin>>t;}
template<class T,class... Ts>inline void in(T&t,Ts&...ts){cin>>t;in(ts...);}
template<class T>inline void out(T t){cout<<t<<endl;}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill(T&t,const V&v){for(auto &e:t)fill(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int K,X;
	in(K,X);
	if(K*500>=X)out("Yes");
	else out("No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const ll mod=1e9+7;
ll powmod(ll a,ll b)
{
    ll res=1;
    for(;b;b>>=1){
        if(b&1) res=res*a%mod;
        a=a*a%mod;
    }
    return res;
}
map<pair<ll,ll>, ll>mp;
int n;
void solve()
{
    scanf("%d",&n);
    ll sum=0,ans=1;
    rep(i,1,n)
    {
        ll fz,fm;
        scanf("%lld%lld",&fz,&fm);
        ll gc=gcd(fz,fm);
        if(gc==0){sum++;continue;}

        fz/=gc,fm/=gc;
        if(fz<0) fm=-fm,fz=-fz;
        mp[{fz,fm}]++;

    }

    
    
    
    for(auto now:mp){
        if(now.second==0) continue;
        ll fz=now.first.first,fm=now.first.second;
        ll d=powmod(2,now.second);

        fm=-fm;
        if(fm<0) fz=-fz,fm=-fm;
        if(mp[{fm,fz}]){
            d=(d+powmod(2,mp[{fm,fz}])-1)%mod;
            mp[{fm,fz}]=0;
        }
        ans=ans*d%mod;
    }
    ans=(ans+sum-1+mod)%mod;
    printf("%lld\n",ans);
























//    sort(G.begin(),G.end());
//    G.erase(unique(G.begin(),G.end()),G.end());
//    //for(auto now:G) printf("now.r:%lld s:%lld mp:%lld\n",now.first,now.second,mp[now]);
//
//
//    for(auto now:G)
//    {
//        if(mp[now]==0) continue;
//        ll fz=now.first,fm=now.second;
//
//        ll d=powmod(2,mp[now]);
//
//        fm=-fm;
//        if(fz<0) fz=-fz,fm=-fm;
//
//        if(mp[{fm,fz}]){
//            //printf("fm:%lld fz:%lld d:%lld mp:%lld\n",fm,fz,d,mp[{fm,fz}]);
//
//            add(d,powmod(2,mp[{fm,fz}])-1);
//            //printf("d:%lld\n",d);
//            mp[{fm,fz}]=0;
//        }
//        mp[now]=0;
//
//        ans=ans*d%mod;
//    }
//    add(ans,sum-1);
//    printf("%lld\n",ans);
}
int main()
{
	solve();
}
/*
3
1 2
-1 1
2 -1

*/


Measured memory_bytes: 28824
import sys

# sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    s = read_str()
    l = s.split(',')
    res = ' '.join(l)
    print(res)


main()


Measured memory_bytes: 2940
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    ll n, k;
    cin >> n >> k;

    vector<int> A(n);
    map<int, bool> mp2;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        if (!mp2[A[i]]) {
            mp2[A[i]] = true;
            mp[A[i]] = i;
        }
    }

    vector<int> nxt(n); // 次に同じ文字が現れる最初のindex
    for (int i = n - 1; i >= 0; i--) {
        nxt[i] = mp[A[i]];
        mp[A[i]] = i;
    }

    ll count = 1;
    int idx = 0;
    while (true) {
        if (nxt[idx] <= idx) count++;
        idx = (nxt[idx] + 1) % n;
        if (idx == 0) break;
    }

    k = (k + count - 1) % count;
    if (k == count - 1) return 0;

    idx = 0;
    while (true) {
        if (k <= 0) break;
        if (nxt[idx] <= idx) k--;
        idx = (nxt[idx] + 1) % n;
    }

    while (true) {
        if (idx >= n) break;
        if (nxt[idx] <= idx) {
            cout << A[idx] << " ";
            idx++;
        } else {
            idx = nxt[idx] + 1;
        }
    }

    return 0;
}

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

int main() {
  
  int n;
  cin >> n;
  
  bool arr[100000] = {0};
  for(int i = 0; i < n; i++) {
    int start, end;
    cin >> start >> end;
    for(int j = start - 1; j < end; j++) {
      arr[j] = true;
    }
  }
  
  int n_people = accumulate(&arr[0], &arr[100000], 0L);
  cout << n_people << endl;
}


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

#define SENTINEL 1000000001

void Merge(int*,int,int,int);
void Merge_sort(int*,int,int);

int cnt=0;

int main(void){
  int n;
  int i;
  int *S;

  scanf("%d",&n);

  S=(int*)malloc(sizeof(int)*n);

  for(i=0;i<n;i++)scanf("%d",&S[i]);

  Merge_sort(S,0,n);

  printf("%d",S[0]);
  for(i=1;i<n;i++)printf(" %d",S[i]);
  printf("\n%d\n",cnt);

  free(S);

  return 0;
}


void Merge(int A[],int left,int mid,int right){
  int n1,n2;
  int *L,*R;
  int i,j,k;

  n1=mid-left;
  n2=right-mid;

  L=(int*)malloc(sizeof(int)*(n1+1));
  R=(int*)malloc(sizeof(int)*(n2+1));

  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];

  L[n1]=SENTINEL;
  R[n2]=SENTINEL;

  i=0;
  j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
    cnt++;
  }
}


void Merge_sort(int A[],int left,int right){
  int mid;

  if(left+1<right){
    mid=(left+right)/2;
    Merge_sort(A,left,mid);
    Merge_sort(A,mid,right);
    Merge(A,left,mid,right);
  }
}

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

typedef vector<int> VI;

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

	VI B(N);
	for (int i = 0; i < (N - 1); ++i) {
		int a;
		cin >> a;
		assert(1 <= a && a <= N);
		B[a - 1]++;
	}

	for (int i = 0; i < B.size(); ++i)
		cout << B[i] << endl;

	return 0;
}


Measured memory_bytes: 3620
from collections import defaultdict

n=int(input())
l=[]
for i in range(n):
    s=input()
    l.append(s)

d=defaultdict(int)

for ls in l:
    d[ls]+=1

fg=0
th=list(d.values())

gh=list(d.keys())

for i in range(len(th)):
    fg=max(fg,th[i])

ans=[]
for i in range(len(gh)):
    if th[i]==fg:
        ans.append(gh[i])

ans.sort()
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 36464
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

int n, u, v;
vi graph[500000];
int dp[500000], w[500000];

int dfs(int v)
{
    w[v] = 1;
    int emp = 0, sum = 0;
    for (auto u : graph[v])
        if (w[u] == 0)
    {
        dfs(u);
        if (dp[u] == 0) emp++;
        sum += dp[u];
    }
    if (emp == 0) dp[v] = sum;
    else dp[v] = sum + emp - 1;
}

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    F(i, n - 1) cin >> v >> u, graph[v].push_back(u), graph[u].push_back(v);
    v = -1;
    F(i, n) if (graph[i].size() >= 3) v = i;
    if (v == -1) cout << 1, exit(0);
    dfs(v);
    cout << dp[v];
}


Measured memory_bytes: 25088
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

void print_vector(vector<int> v){
  rep(i, sz(v)){
    cout << v[i] << " ";
  }
  cout << endl;
  return;
}

int main(){
  ll N, K;
  cin >> N >> K;
  vector<int> A(N+1);
  rep(i, N){
    cin >> A[i+1];
  }
  deque<int> visit_pattern;
  map<int, int> visited_node;

  int now = 1;
  visit_pattern.push_back(now);
  visited_node[now]++;

  while(1){
    int next = A[now];
    if(visited_node[next] == 2){
      break;
    }
    visit_pattern.push_back(next);
    visited_node[next]++;
    now = next;
  }

  // for(int num: visit_pattern){
  //   cout << num << " ";
  // }
  // cout << endl;
  // cout << "pupi:" << visit_pattern.size() << endl;


  if(K <= visit_pattern.size()){
    cout << visit_pattern[K] << endl;
    return 0;
  }

  ll one_cnt = 0;
  rep(i, visit_pattern.size()){
    if(visited_node[visit_pattern[i]] != 1){
      break;
    }
    one_cnt++;
  }
  K -= one_cnt;

  rep(i, one_cnt){
    visit_pattern.pop_front();
  }

  int amari = K % sz(visit_pattern);
  cout << visit_pattern[amari] << endl;

  // print_vector(visit_pattern);




 
  return 0;
}


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

// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

// あるブロックに書き込まれる整数は, そのブロックの左下, 真下, 右下のブロックの中央値である
// 一番上のブロックがxの時, 存在するN段目の並びを求めよ(1, ..., 2N-1とする)
//   x
// i x j (i<=x, x<=j)
// xが(1)or(2N-1)の時は無理
// 2の時は?
//     2
//   2 2 4
// 1 3 2 4 5

// 4, 4
//       4
//     3 4 5
//   2 3 4 5 6
// 1 2 3 4 5 6 7

// 一般化すると,
// 同じ数字が2個並べば良い
// x-1, x, x+1, x-2とすれば良いらしい
// ただし, x=2の時は+-を逆にすれば良い
// x+1, x, x-1, x+2

signed main() {
  INIT;
	VAR(int, n, x);

	if (n==2){
		if (x==2) {
			OUT("Yes")BR;
			OUT(1)BR;
			OUT(2)BR;
			OUT(3)BR;
		} else {
			OUT("No")BR;
		}
		return 0;
	}
	
	if (x==1 || x==2*n-1){
	  OUT("No")BR;
		return 0;
	}
	OUT("Yes")BR;
	vector<int> ans(2*n-1);
	int cnt = 1;
  if (x==2){
		ans[n-2] = x+1;
		ans[n-1] = x;
		ans[n] = x-1;
		ans[n+1] = x+2;
		REP(i,2*n-1){
			if (n-2 <= i && i<= n+1) continue;
			while (x-1 <= cnt && cnt <= x+2) ++cnt;
			ans[i] = cnt++;
		}
		EACH(ai,ans) {
			OUT(ai)BR;
		}
		return 0;
	}
	ans[n-2] = x-1;
	ans[n-1] = x;
	ans[n] = x+1;
	ans[n+1] = x-2;
	REP(i,2*n-1){
		if (n-2 <= i && i<= n+1) continue;
		while (x-2 <= cnt && cnt <= x+1) ++cnt;
		ans[i] = cnt++;
	}
	EACH(ai,ans) {
		OUT(ai)BR;
	}
	
  
  return 0;
}


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

void solve(long long A, long long B){
	long long x = A + B;
	long long y = A - B;
	long long z = A * B;

	long long ans = max(x, y);
	ans = max(z, ans);

	cout << ans << endl;
}

int main(){	
	long long A;
	long long B;
	scanf("%lld",&A);
	scanf("%lld",&B);
	solve(A, B);
	return 0;
}



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


void solve(long long A, long long B, long long C, long long K){
if(A>=K)cout<< K <<endl;
else if((A+B>=K)&&(A<K))cout<< A <<endl;
else if((A+B+C>=K)&&(A+B<K))cout<< A-(K-B-A) <<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}


Measured memory_bytes: 3604
#include <cstring>
#include <cstdlib>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)<0?(-(a)):(a))
#define CS while(cases())
#define I(n) int n = gi()
#define II(n) n = gi()
#define L(n) ll n = gli()
#define LL(n) n = gli()
#define F0(i, n) for (int i = 0; i < n; i++)
#define F1(i, n) for (int i = 1; i < n; i++)
#define Fi(n, a) for (int i = 0; i < n; i++) a[i] = gi()
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

template<class T>
T gcd(T a, T b) {
    return (b == 0 ? a : gcd(b, a%b));
}

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int cases() {
    static int t = gi();
    return t--;
}

#define N 10000000
int p[N+1], ispr[N+1];
int c(int a) {
    int r = 1;
    while (a > 1) {
        int pp = p[a];
        int cc = 1;
        while (a%pp == 0) {
            a /= pp;
            cc++;
        }
        r *= cc;
    }
    return r;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    memset(ispr, 1, sizeof(ispr));
    for (int i = 2; i <= n; i++)
        if (ispr[i]) {
            for (int j = i; j <= n; j+=i) {
                p[j] = i;
                ispr[j] = 0;
            }
        }

    ll r = 0;
    for (int i = 1; i <= n; i++) {
        ll C = c(i);
        ll X = i;
        r += C*X;
    }
    cout << r << endl;

    return 0;
}


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

int main()
{
int X;
int A;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> X;
	cin >> A;

	if( X < A )
		cout << 0 << endl;
	else
		cout << 10 << endl;

	return 0;
}


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

int n, m[2], p[2][200010];
map<int, int> mp[200010];

int fnd(int t, int x){ return p[t][x] = (p[t][x] == x ? x : fnd(t, p[t][x])); }
void uni(int t, int x, int y){ p[t][fnd(t, y)] = fnd(t, x); }

int main(){
	scanf("%d%d%d", &n, m, m + 1);
	for(int t = 0; t < 2; t++){
		iota(p[t] + 1, p[t] + n + 1, 1);
		for(int i = 0, x, y; i < m[t]; i++){
			scanf("%d%d", &x, &y);
			uni(t, x, y);
		}
	}
	for(int i = 1; i <= n; i++) mp[fnd(0, i)][fnd(1, i)]++;
	for(int i = 1; i <= n; i++) printf("%d\n", mp[fnd(0, i)][fnd(1, i)]);
}

Measured memory_bytes: 20096
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;

int x, y;

int main(){
	cin >> x >> y;
	if(x <= y){
		int ret= y-x;
		if(x < 0 && y > 0){
			ret = min(ret, abs(abs(y) - abs(x)) + 1);
		}
		cout << ret;
		return 0;
	}
	else{
		if(x < 0 || y > 0){
			cout << x - y + 2;
			return 0;
		}
		cout << min(x-y+2, abs(abs(x) - abs(y)) + 1);
	}
}



Measured memory_bytes: 256
import fractions


class Solution:
    def solve(self, a: int, b: int) -> int:

        return a * b // fractions.gcd(a, b)


if __name__ == '__main__':

    # standard input
    a, b = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(a, b))


Measured memory_bytes: 5432
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int n, sum;
    for (; ; ) {
        scanf("%d", &n);
        if (n == -1) break;
        sum = 1150;
        if (n > 30) sum += (n - 30) * 160, n-= n-30;
        if (n > 20) sum += (n - 20) * 140, n -= n-20;
        if (n > 10) sum += (n - 10) * 125, n -= n-10;
        printf("%d\n", 4280-sum);
    }
    return 0;
}



Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000;
const int MOD = (int)1e9 + 7;

signed main()
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << "\n";
}

Measured memory_bytes: 256
/*
Author : Gaurav Singh
*/
#include<bits/stdc++.h>
using namespace std;
#define N 200005
#define MOD 1000000007
#define ll long long
#define ld long double
#define ull unsigned long long
#define li long int
#define str string
#define vll vector<ll>
#define pb push_back
#define frn(i,n) for(ll (i) = 0; (i) <(n) ; (i)=(i+1))
#define fr(i,n) for(ll (i) = 1; (i) <=(n) ; (i)=(i+1))
#define frev(i,n) for(ll (i) = n-1; (i) >=(0) ; (i)--)
#define fr1(j,a,b,c) for(ll (j) = a; (j) <c ; (i)=(i+b))
#define w(t) while(t--)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
void solve(){
    ll n,k,a,mi=N,s=0,i;
    cin>>n>>k;
    frn(i,n){
        cin>>a;
        mi=min(a,mi);
        s=s+a;
    }
    cout<<n+(k-s)/mi;
}
int main()
{   
   fast;
   int t=1;
    w(t){
        solve();
    }
   return 0;
}   

Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

vs = []
for i in range(n):
    vs.append(v[i]-c[i])

ans=0
for i in range(n):
    if vs[i] > 0:
        ans += vs[i]
        
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

template<class X> X gcd(X a, X b) {return b ? gcd(b,a%b):a;}

int main(){
    int N;
    cin >> N;
    vector<ull> T(N);
    for(int i = 0; i < N; i++) cin >> T[i];
    ull lcm_v = T[0];
    for(int i = 1; i < N; i++){
        ull gcd_v = gcd(lcm_v, T[i]);
        lcm_v = T[i] / gcd_v * lcm_v;
    }
    cout << lcm_v << endl;
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

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



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

using namespace std;

int N;

int main() {
	double x, h, dMax, t;

	dMax = -1;
	cin >> N >> t;
	for (int i = 0; i < N; ++i) {
		cin >> x >> h;
		dMax = max(dMax, h/x);
	}
	cout << fixed << setprecision(4) << dMax*t << endl;

	return 0;
}


Measured memory_bytes: 3268
# 幅優先探索
from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]

links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)

result = [-1] * (N + 1)
q = deque([1])
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
print('Yes')
print(*result[2:], sep='\n')


Measured memory_bytes: 106420
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

string change(string s,int a,int b){
	string ret(s);
	rep(i,0,ret.size()){
		int y=ret[i]-'a';
		if(y>=0 && y<26){
			y=(a*y+b)%26;
			ret[i]='a'+y;
		}
	}
	return ret;
}

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

int main(){
	int n;
	//cin>>n;
	string tt;
	getline(cin,tt);
	n = atoi(tt.c_str());
	//cout<<n<<" "<<tt<<endl;
	//cin.ignore();
	string str[2]={"that","this"};
	rep(i,0,n){
		string s;
		bool f=0;
		getline(cin,s);
		//o(s);
		rep(a,0,26){
			if(gcd(a,26)!=1) continue;
			rep(b,0,26){
				string t;
				t=change(s,a,b);
				//o(t);
				rep(j,0,2){
					if(t.find(str[j]) != string::npos){
						o(t); f=1; break;
					}
				}
				if(f) break;
			}
			if(f) break;
		}

	}
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,T;
  int res=1100;
  cin >> N >> T;
  vector<int> A(N),B(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i) >> B.at(i);
  } 
  
  for (int i = 0; i < N; i++){
    if(B.at(i) <= T){
        if(A.at(i) < res) res = A.at(i);
    }
  }

  if(res==1100) cout << "TLE" << endl;
  else cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	string S;
	cin >> S;

	for (int i = 0; i < 3; i++) {
		cout << S[i];
	}
	cout << endl;

}






Measured memory_bytes: 3540
h,w,k=map(int,input().split())
c=[list(input()) for _ in range(h)]
ans=0

for paint_h in range(2**h):
  for paint_w in range(2**w):
    cut=0
    for i in range(h):
      for j in range(w):
        if (paint_h>>i)&1==0 and (paint_w>>j)&1==0:
          if c[i][j]=='#':
            cut+=1
    if cut==k:
      ans+=1
print(ans)

Measured memory_bytes: 9104
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#define debug(...) (cerr<<"'"<<__FUNCTION__<<"': "),fprintf(stderr,__VA_ARGS__)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
ll k;
ll a[55];
int main()
{
	cin>>k;
	int n=50;
	for(int i=1;i<=n;i++)a[i]=n-1;
	ll x=k/50,y=k%50;
	for(int i=1;i<=n;i++)a[i]+=x;
	for(int i=1;i<=y;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i==j)a[j]+=n;
			else a[j]--;
		}
	}
	cout<<n<<endl;
	for(int i=1;i<=n;i++)cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using iii = pair<ii, ll>;
#define vt vector
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const ll MOD = 1e9 + 7;
const ll INF = 2e9;
const ll N = 1e2 + 5;

int n, ans;
int a[N], b[N];

void solve() {
    cin >> n;
    for(int i = 1; i < n; i++) {
        cin >> b[i];
    }
    a[1] = b[1];
    for(int i = 2; i <= n; i++) {
        a[i] = b[i - 1];
        if(b[i] < b[i - 1]) a[i] = b[i];
    }
    a[n] = b[n - 1];
    for(int i = 1; i <= n; i++) {
        ans += a[i];
    }
    cout << ans << "\n";
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 3624
#include <iostream>

int main(int argc, char const *argv[])
{
    using namespace std;

    int a, b, c;
    int cnt=0;
    cin >> a >> b >> c;

    for (int i = a; i <= b; i++)
    {
        if (c % i == 0)
        {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3112
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
l_o = l[::2]
l_g = l[1::2]
a = list(Counter(l_o).most_common())+[(0,0)]
c = list(Counter(l_g).most_common())+[(0,0)]

if a[0][0]==c[0][0]:
  s = a[0][1]+c[1][1]
  t = a[1][1]+c[0][1]
  x = max(s,t)
  print(n-x)
  
  
else:
  print(n-a[0][1]-c[0][1])

Measured memory_bytes: 25584
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()

        For i As Integer = 1 To N
            If Not Judge(i + 1, N) Then
                WriteLine(i * i)
                Exit For
            End If
        Next

    End Sub

    Function Judge(i As Integer, n As Integer) As Boolean
        If i * i <= n Then Return True
        Return False
    End Function

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 20560
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main()
{
	int32_t N;
	cin >> N;
	N--;

	vector<int32_t> duration(N), start(N), interval(N);
	for (int32_t i = 0; i < N; i++) {
		cin >> duration[i] >> start[i] >> interval[i];
	}

	for (int32_t start_station = 0; start_station < N; start_station++) {
		int32_t _time = 0;
		for (int32_t i = start_station; i < N; i++) {
			if (_time > start[i]) {
				int32_t _mul = _time / interval[i];
				if (_time % interval[i] != 0) {
					_mul++;
				}
				_time = _mul * interval[i];
			} else {
				_time = start[i];
			}
			_time += duration[i];
		}
		cout << _time << endl;
	}
	cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
    int n,a[200000];
    int sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    sum+=abs(a[0]);
    for(int i=1;i<n;i++){
        sum+=abs(a[i]-a[i-1]);
    }
    sum+=abs(a[n-1]);
    //printf("%d\n",sum);

    for(int i=0;i<n;i++){
        if(i==0){
            printf("%d\n",sum-abs(a[0])-abs(a[1]-a[0])+abs(a[1]-0));
        }else if(i==n-1){
            printf("%d\n",sum-abs(a[n-1])-abs(a[n-1]-a[n-2])+abs(a[n-2]-0));
        }else{
            printf("%d\n",sum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]));
        }
    }
    return 0;
}

Measured memory_bytes: 1536
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;


vector<ll> A;
vector<ll> nck;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
   ll N,K;
   cin>>N>>K;
   A.resize(N);
   nck.resize(N+1);
   rep(i,0,N) cin>>A[i];
   sort(A.begin(),A.end());

   // rep(i,0,N+1) {
   //    if (i<K) nck[i] = 0;
   //    else if (i==K) nck[i] = 1;
   //    else nck[i] = nck[i-1] * i / (i-K);
   //    // cout<<i<<" "<<nck[i]<<endl;
   // }
   COMinit();
   ll ans = 0;
   rep(i,1,N+1) {
      ans += A[i-1] * (COM(i-1,K-1));
      ans -= A[i-1] * (COM(N-i,K-1));
      ans %= MOD;
   }
   cout<<(ans+MOD)%MOD<<endl;





   return 0;
}

Measured memory_bytes: 4096
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
 
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n,a,b;
    cin >> n >> a >> b;
    if((b-a)%2){
        cout << "Borys" << endl;
    }else{
        cout << "Alice" << endl;
    }
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, x = LI()
    A = LI()
    cnt = 0
    for i in range(N-1):
        l = A[i]
        r = A[i+1]
        extra = l + r - x
        if extra <= 0:
            continue
        if extra <= r:
            A[i+1] = r - extra
        else:
            r = 0
            l = l - (extra - r)
            A[i+1] = r
            A[i] = l
        cnt += extra
    print(cnt)
main()



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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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


int main() {
    string S;
    cin >> S;
    int Q;
    cin >> Q;

    bool flag = true;
    string S_p, S_l;

    rep(i, Q){
        int T,F;
        char c;
        cin >> T;
        if(T == 1) flag = !flag;
        else {
            cin >> F >> c;
            if(F == 2) {
                if(flag)
                    S_l += c;
                else
                    S_p += c;
            } else {
                if(!flag)
                    S_l += c;
                else
                    S_p += c;
            }
        }
    }

    string ans;
    if(flag){
        reverse(S_p.begin(), S_p.end());
        ans += S_p;
        ans += S;
        ans += S_l;
    } else {
        reverse(S.begin(), S.end());
        reverse(S_l.begin(), S_l.end());
        ans += S_l;
        ans += S;
        ans += S_p;
    }

    //string ans = ( flag ? "OK":"NG");
    cout << ans;
    //printf("%.8lf", ans);
    cout << "\n";
    return 0;
}


Measured memory_bytes: 1348
x1,y1,x2,y2 = map(int,input().split())

x3 = x2 + y1 - y2
y3 = y2 + x2 - x1

x4 = x3 + y2 - y3
y4 = y3 + x3 - x2

print("{} {} {} {}".format(x3,y3,x4,y4))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
#define gcd(a,b) __gcd(a,b)
#define MEM(a,x) memset(a,x,sizeof(a))
#define VI vector<int>
#define PII pair<int,int>
#define ull unsigned long long
#define ll long long
#define fi first
#define se second
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int k,f[205][205];
int main(){
    cin>>k;
    int ans=0;
    rep(i,1,k)rep(j,1,k)f[i][j]=gcd(i,j);
    rep(i,1,k)rep(j,1,k)rep(l,1,k)ans+=f[f[i][j]][l];
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<vector<int>> vii;
typedef vector<int> vi;
typedef vector<string> vs;


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


int main(){
    int n;
    cin >> n;
  
    pair<pair<string, int>, int> res[110];
    rep(i, n){
        string s;
        int p;

        cin >> s >> p;
        res[i] = make_pair(make_pair(s, -p), i+1);
    }

    sort(res, res+n);

    rep(i, n) {
        cout << res[i].second << endl;
    }
}

Measured memory_bytes: 256
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
mod = 10**9+7



def main():
  w,a,b = map(int,input().split())
  if a > b:
    a,b = b,a
  if a+w >=b:
    print(0)
  else:
    print(abs(a+w-b))
  
if __name__ == '__main__':
  main()

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

#define F(i, a, b) for(int i=a; i<b; i++)
#define mem(arr, val) memset(arr, val, sizeof(arr))
#define rev(a) reverse(a.begin(), a.end())
#define UPPER(a) transform(a.begin(), a.end(), a.begin(), ::toupper)
#define LOWER(a) transform(a.begin(), a.end(), a.begin(), ::tolower)
#define INF 1000000000000001
#define epsilon 1e-15

typedef long long int ll;
typedef unsigned long long int ull;

ll p = 1000000007;
const int MAX = 500001;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("OUTPUT.txt", "w", stdout);
    #endif

    string S;
    cin >> S;
    int sum = 0;
    for(int i=0; i<S.length(); i++){
    	sum = sum + (S[i] - '0');
    }

    if(sum%9==0) cout << "Yes";
    else cout << "No\n";

    return 0;
}

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

int n;

int main() {
    cin >> n;
    if(n%2==0) {
        cout << (n/2)*(n/2) <<endl;
    }else{
        cout << ((n-1)/2)*((n+1)/2) << endl;
    }
}

Measured memory_bytes: 3624