akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
//#include<vector>
#include<algorithm>


#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;
const int MAXN=1005;
int K,S;


int main(){
	#ifdef L_JUDGE
		freopen("in.txt","r",stdin);
//		freopen("out.txt","w",stdout);
	#endif
    scanf("%d%d",&K,&S);
    int ans=0;
    for(int ai=0;ai<=K;ai++){
        if(ai+2*K<S)continue;
        for(int bi=0;bi<=K;bi++){
            int ci=S-ai-bi;
            if(ci>K)continue;
            if(ci<0)break;
            ans++;
        }
    }
    printf("%d\n",ans);

	#ifdef L_JUDGE
		fclose(stdin);
		fclose(stdout);
//		system("out.txt");
	#endif

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
set<char> st;
string s;
int a,b,x;
int main(int argc,char const* argv[])
{
  cin >> a >> b >> x;
  if(a>x)
    {
      cout <<"NO" << endl;
      return 0;
    }
  else
    {
      if(x-a>b)
	{
	  cout << "NO" << endl;
	  return 0;
	}
      else
	{
	  cout << "YES" << endl;
	  return 0;
	}
    }
  return 0;
}


Measured memory_bytes: 256
s = input().split(" ")
N, K = int(s[0]), int(s[1])

s = input().split(" ")
p = []
for S in s:
    p.append(int(S))

sum = 0
for i in range(K):
    n = p.index(min(p))
    sum += p[n] 
    p.pop(n)

print(sum)



Measured memory_bytes: 9120
n=int(input())
d=[]
for i in [0]*n:
    d.append([int(x) for x in input().split()])
from itertools import product
ans=0
for i,j in product(range(n),range(n)):
    flag=0
    for k in range(n):
        if d[i][j]>d[i][k]+d[k][j]:
            print(-1)
            import sys
            sys.exit()
        if d[i][j]==d[i][k]+d[k][j] and (k!=i and k!=j and i!=j ):
            flag=1
    if flag==0:
        ans+=d[i][j]
print(ans//2)

Measured memory_bytes: 45832
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N, M;
  cin >> N >> M;
  long ans = 0;

  long first_scc = min(N, M/2);
  ans += first_scc;

  N -= first_scc;
  M -= first_scc * 2;

  ans += M / 4;

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

int main() {
  int N, Y;
  cin >> N >> Y;
  int resA = -1, resB = -1, resC = -1;
  for (int a = 0; a <= N; a++) {
    for (int b = 0; b+a <= N; b++) {
      int c = N - a - b;
      int total = a * 10000 + b * 5000 + c * 1000;
      if (total == Y) {
        resA = a;
        resB = b;
        resC = c;
      }
    }
  }
  cout << resA << " " <<  resB << " " << resC;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
using namespace std;
main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if(x%2==1)
        {
            cout<<"first";
            return 0;
        }
    }
    cout<<"second";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5; int n;
int a[maxN]; lli cnt[maxN + 1];

int main()
{
  int t = 0;
  while (scanf("%d", &n) != EOF)
  {
    if (t++) printf("--------\n");
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; i++)
    {
      scanf("%d", &a[i]);
      cnt[a[i]]++;
    }

    lli ans = 0;
    for (int i = 1; i <= n; i++)
      ans += cnt[i] * (cnt[i] - 1) >> 1LL;

    for (int i = 0; i < n; i++)
    {
      lli rem = cnt[a[i]] * (cnt[a[i]] - 1) >> 1LL;
      lli add = (cnt[a[i]] - 1) * (cnt[a[i]] - 2) >> 1LL;
      printf("%lld\n", ans - rem + add);
    }
  }
  return 0;
}

Measured memory_bytes: 4864
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        boolean judge = x < 1200;
        String result = judge ? "ABC" : "ARC";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll n;
    cin >> n;
    if (n%2 == 0) {
        cout << n << endl;
    } else {
        cout << n * 2 << endl;
    }
}


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

int isPalindrome(int n) 
{ 
    // Find reverse of n 
    int rev = 0; 
    for (int i = n; i > 0; i /= 10) 
        rev = rev*10 + i%10; 
  
    // If n and rev are same, then n is palindrome 
    return (n==rev); 
} 
  
// prints palindrome between min and max 
int countPal(int min, int max) 
{ 
    int c=0;
    for (int i = min; i <= max; i++) 
        if (isPalindrome(i)) 
          c++;
  
    return c;
} 

int main()
{
  int l,r;
  cin>>l>>r;
  cout<<countPal(l,r);
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
void SRAND(){auto duration = std::chrono::system_clock::now().time_since_epoch();auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();srand(millis);}

ll n,p[N],dp[2][13],k;
string s;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	p[0]=1;
	REP1(i,N)p[i]=p[i-1]*10%13;
	cin>>s;
	dp[1][0]=1;
	REP(i,SZ(s)){
		if(s[i]=='?'){
			REP(j,13)dp[i%2][j]=0;
			REP(j,10){
				k=(13-j*p[SZ(s)-i-1]%13)%13;
				REP(t,13){
					dp[i%2][t]+=dp[(i+1)%2][(t+k)%13];
				}
			}
		}else{
			k=(13-(s[i]-'0')*p[SZ(s)-i-1]%13)%13;
			REP(j,13){
				dp[(i%2)][j]=dp[(i+1)%2][(j+k)%13];
			}
		}
		REP(j,13)dp[i%2][j]%=MOD;
	}
	cout<<dp[(SZ(s)-1)%2][5]<<"\n";
	return 0;
}



Measured memory_bytes: 2048
sx, sy, tx, ty = map(int, input().split())
lst = []
lst.append('U' * (ty - sy))
lst.append('R' * (tx - sx))
lst.append('D' * (ty - sy))
lst.append('L' * (tx - sx))
lst.append('L')
lst.append('U' * (ty - sy + 1))
lst.append('R' * (tx - sx + 1))
lst.append('D')
lst.append('R')
lst.append('D' * (ty - sy + 1))
lst.append('L' * (tx - sx + 1))
lst.append('U')
ans = ''.join(lst)
print(ans)




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,X;cin>>N>>M>>X;
  vector<vector<int>>V(N,vector<int>(M));
  vector<int>D(N);
  for(int L=0;L<N;L++){
    cin>>D[L];
    for(int R=0;R<M;R++){
      cin>>V[L][R];
    }
  }
  long long P=200000000000ll;;bool bre=false;
  for (int bit = 0; bit < (1 << N); bit++) {
    long long sum = 0;bool K=true;
    vector<int>E(M);
    for (int i = 0; i < N; i++) {
      if (bit & (1 << i)){
        sum += D[i];
        for(int L=0;L<M;L++)E[L]+=V[i][L];
      }
    }
    for(int L=0;L<M;L++){
      if(E[L]<X){
        K=false;break;
      }
    }
    if(K&&P>sum){
      P=min(P,sum);
      bre=true;
    }
  }
  if(bre)cout<<P<<endl;
  else cout<<-1<<endl;
}


Measured memory_bytes: 3616
#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 n,k,ans = 0;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n){
        cin >> p.at(i);
    }
    sort(p.begin(), p.end());
    rep(i,k){
        ans += p.at(i);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3596
N, M = map(int, input().split())
from_one = []
to_n = []
for _ in range(M):
  a, b = map(lambda x:int(x)-1, input().split())
  if a == 0:
    from_one += [b]
  elif b == 0:
    from_one += [a]
  elif a == N-1:
    to_n += [b]
  elif b == N-1:
    to_n += [a]

from_one = set(from_one)
to_n = set(to_n)
if len(from_one & to_n) >= 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")


Measured memory_bytes: 26856
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */

#define MAXN (2000)
#define MOD (1000000007)

int a[MAXN];

int main(void)
{
    int n,bc,ac;
    uint64_t ans,k,kk;
    scanf("%d %ld",&n, &k);

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

    bc = 0;
    ac = 0;
    for(int i=0;i<n;i++)
    {
        
        for(int j=0;j<i;j++)
        {
            if(a[j] < a[i])
            {
                bc++;
            }
        }

        for(int j=i+1;j<n;j++)
        {
           if(a[j] < a[i])
            {
                ac++;
            }            
        }
    }

    ans = 0;
    kk = k%2==0? (((k/(uint64_t)2)%MOD)*(k-(uint64_t)1))%MOD : ((((k-(uint64_t)1)/(uint64_t)2)%MOD)*k)%MOD;
    ans = (kk * bc)%MOD;
    kk = k%2==0? (((k/2)%MOD)*(k+1))%MOD : ((((k+1)/2)%MOD)*k)%MOD;
    ans = (ans + (kk*ac))%MOD;


    printf("%ld\n", ans);

    return 0;
}





Measured memory_bytes: 128
"""
参考(真似させてもらいました)
https://atcoder.jp/contests/agc044/submissions/13546510
"""


##再帰する.割り切れないなら割り切れる近くの数について考える.
import sys
sys.setrecursionlimit(int(1e6))

def solve(N_,A,B,C,D):
    num = {}
    def saiki(N):
        ##なんであれN*Dは移動できる
        res = N*D
        if N == 0:
            return 0
        elif N == 1:
            return D
        if N in num:
            return num[N]
        
        if N%2 == 0:
            res = min(res,saiki(N//2)+A)
        else:##割り切れないとき,近い割り切れる数へと移動し,割り切る.
            res = min(res,saiki((N+1)//2)+A+D,saiki((N-1)//2)+A+D)
        
        if N%3 == 0:
            res = min(res,saiki(N//3)+B)
        else:
            res = min(res,saiki(N//3)+D*(N%3)+B,saiki(N//3+1)+D*(3-N%3)+B)
        
        if N%5 == 0:
            res = min(res,saiki(N//5)+C)
        else:
            res = min(res,saiki(N//5)+D*(N%5)+C,saiki(N//5+1)+D*(5-N%5)+C)
        
        ##メモ化
        num[N] = res

        return res
    
    print(saiki(N))

for _ in range(int(input())):
    N,A,B,C,D = map(int,input().split())
    solve(N,A,B,C,D)

Measured memory_bytes: 20424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge{ll to,cost;};
#define MAX 2005
ll inf = 20000000;
ll INF = inf*3000LL;

int N,M,K;
vector<edge> G[MAX];

ll DP[MAX][MAX];
ll dp[MAX][MAX][2];
ll V[MAX];

bool visited[MAX];
vector<ll> A,B;

void calc(bool flg){
  int size=A.size();
  dp[0][1-flg][1-flg]=-INF;  
  dp[0][flg][flg]=0;
  for(int i=1;i<size;i++){
    for(int j=0;j<=size;j++){
      dp[i][j][0]=max(dp[i-1][j][1],dp[i-1][j][0]);
      V[j]=max(V[j],dp[i][j][0]);
      if(j==0)continue;
      ll cost=max(dp[i-1][j-1][0],dp[i-1][j-1][1]+B[i-1]);
      if(i+1==size&&A.size()==B.size()&&flg){
        cost+=B[i];
      }
      dp[i][j][1]=cost;
      V[j]=max(V[j],dp[i][j][1]);
    }
  }

}

void dfs(int pos,int prev){
  if(visited[pos])return;
  visited[pos]=true;
  A.push_back(pos);
  for(int i=0;i<(int)G[pos].size();i++){
    if(G[pos][i].to==prev)continue;
    B.push_back(G[pos][i].cost);
    dfs(G[pos][i].to,pos);
    break;
  }
}

int search(int p){
  map<int,bool> mp;
  while(!mp[p]){
    mp[p]=true;
    for(int i=0;i<(int)G[p].size();i++){
      edge e=G[p][i];
      if(!mp[e.to]){
        p=e.to;
        break;
      }
    }
  }
  return p;
}

int main(){
  cin>>N>>M>>K;
  for(int i=0;i<M;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    if(c==0)c=-INF;
    G[a].push_back((edge){b,c});
    G[b].push_back((edge){a,c});
  }
  
  for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
      DP[i][j]=dp[i][j][0]=dp[i][j][1]=-INF;
  
  DP[0][0]=0;

  int C=0;
  for(int i=1;i<=N;i++){
    if(visited[i])continue;
    A.clear();
    B.clear();
    dfs( search(i) ,0);
    int size=A.size();
    for(int i=0;i<=size;i++)V[i]=-INF;
    V[0]=V[1]=0;
    calc(true);
    calc(false);
    C++; 
    for(int j=0;j<=K;j++)
      for(int k=0;k<=min(j,size);k++)
        DP[C][j]=max(DP[C][j],DP[C-1][j-k]+V[k]);
  }
 
  if(DP[C][K] < -inf) cout << "Impossible" << endl;
  else cout << DP[C][K] << endl;
  return 0;
}

Measured memory_bytes: 95820
#include<iostream>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    int a[10000]={0};
    int days(n);
    for(int i(0);i<m;i++){
        cin>>a[i];
        days -= a[i];
    }
    if(days>=0)cout<<days<<endl;
    else cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct point {
  int x, y, id;
};
struct edge {
  int u, v, w;
  edge(int a, int b, int c) {
    u = a; v = b; w = c;
  }
};
bool cmp1(point p1, point p2) {
  return p1.x < p2.x;
}
bool cmp2(point p1, point p2) {
  return p1.y < p2.y;
}
bool cmp3(edge e1, edge e2) {
  return e1.w < e2.w;
}
vector<int> f;
int getf(int i) {
  if (i == f[i]) {
    return i;
  } else {
    return f[i] = getf(f[i]);
  }
}
int main(void) {
  int n;
  cin >> n;
  vector<edge> e;
  vector<point> t(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i].x >> t[i].y;
    t[i].id = i;
  }
  sort(t.begin(), t.end(), cmp1);
  for (int i = 0; i < n - 1; i++) {
    e.push_back(edge(t[i].id, t[i + 1].id, t[i + 1].x - t[i].x));
  }
  sort(t.begin(), t.end(), cmp2);
  for (int i = 0; i < n - 1; i++) {
    e.push_back(edge(t[i].id, t[i + 1].id, t[i + 1].y - t[i].y));
  }
  for (int i = 0; i < n; i++) {
    f.push_back(i);
  }
  sort(e.begin(), e.end(), cmp3);
  int answer = 0;
  for (int i = 0; i < e.size(); i++) {
    if (getf(e[i].u) != getf(e[i].v)) {
      answer += e[i].w;
      f[getf(e[i].u)] = getf(e[i].v);
    }
  }
  cout << answer << endl;
  return 0;
}

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

int main() {
  long long N;
  cin >> N;
  int con = 1;
  for (int i = 2; i <= sqrt(N); i++) {
    if (N % i == 0 && i < N/2) con = i;
  }
  if (con == 1) cout << N - 1 << endl;
  else cout << (N / con - 1) + (con - 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int p[25];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> p[i];

	int ans = 0;
	for (int i = 1; i < n - 1; i++) {
		int a = p[i - 1];
		int b = p[i];
		int c = p[i + 1];
		if (a > b && b > c) ans++;
		else if (a < b && b < c) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int getnum(double avg[], int A, int N){
    int num = 0;

    double min = abs(avg[0] - (double)A);
    for (int i = 1; i < N; i++) {
        if (abs(avg[i] - (double)A) < min) {
            num = i;
            min = abs(avg[i] - (double)A);
        }
    }

    return num + 1;
}

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

    cin >> N >> T >> A;
    int H[N];
    double avg[N];
    for (int i = 0; i < N; i++) {
        cin >> H[i];
        avg[i] = (double)T - (double)H[i] * 0.006;
    }

    int num = getnum(avg, A, N);

    cout << num << endl;

    return 0;
}

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

int dp[20][1000][2][2];
string s;

int dfs(int idx,int p,bool tight=true,bool ok=false){
    if(idx==s.size())return ok;
    int &res=dp[idx][p][tight][ok];
    if(~res)return res;
    res=0;
    int x=s[idx]-'0';
    int r=(tight?x:9);
    for(int i=0;i<=r;i++){
        int nxt=(p*10+i)%1000;
        res+=dfs(idx+1,nxt,tight&&i==r,ok||((p/10)==51&&i==3));
    }
    return res;
}

signed main(){
    memset(dp,-1,sizeof(dp));
    cin>>s;
    cout<<dfs(0,0)<<endl;
}


Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n;

int getbit(int s,int k){
    return (s >> k) & 1;
}


int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    
    vector<vector<ii>> g(n);
    for (int i = 0; i < n; i++){
        int Ai;
        cin >> Ai;
        for (int j = 0; j < Ai; j++){
            int x, y;
            cin >> x >> y;
            x--;
            g[i].emplace_back(ii(x,y));
        }
    }


    int maxmask = (1 << n);
    int ans = 0;
    for (int msk = 0; msk < maxmask; msk++){
        int cnt = 0;
        bool ok = true;
        for (int i = 0; i < n; i++)
            if (getbit(msk,i)){
                cnt++;
                for (auto v: g[i])
                    if ((getbit(msk,v.first)) ^ v.second) ok = false;
            }        
        if (ok) ans = max(ans,cnt);            
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(void)
{
    int a, b;
    scanf("%d%d", &a, &b);

    if (a + b == 15)
        puts("+");
    else if (a * b == 15)
        puts("*");
    else
        puts("x");
    return 0;
}

Measured memory_bytes: 760
#conding utf-8
A=[int(input()) for i in range(5)]
B=[0 for i in range(5)]
C=[0 for i in range(5)]

tmp=10
m=0
for i in range(5):
  if A[i]%10 !=0:
    if A[i]%10<tmp:
      m=i
      tmp=A[i]%10

for i in range(5):
  if A[i]%10 !=0:
    if i != m:
      B[i]=int(A[i]/10)*10+10
    else:
      B[i]=A[i]
  else:
    B[i]=A[i]

print(sum(B))

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

int main() {
    int N, K; cin >> N >> K;
    vector<long long> H(N);
    for(int i=0; i<N; ++i) cin >> H[i];
    sort(begin(H), end(H), greater<long long>());

    long long res = 0;
    for(int i=K; i<N; ++i) res += H[i];
    cout << res << '\n';
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

int main(){
    int N;
    cin >> N;
    if(N%2==0) cout << fixed << setprecision(10) << (double)(N/2.0)/N << endl;
    else cout << fixed << setprecision(10) << (double)(N+1)/2/N << endl;
    return 0;

}

Measured memory_bytes: 3252
w = input()
W = []
for i in range(len(w)):
    W.append(w[i])

W.sort()

if len(w) % 2 == 1:
    print("No")
    exit()

for i in range(len(w)//2):
    if not W[2*i] == W[2*i+1]:
        print("No")
        exit()
print("Yes")

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

#define pan(i,n) for(ll i=0;i<n;i++)
#define pans(i,n,a) for(ll i=a;i<n;i++)
#define ll long long int
#define vi vector<ll>
#define vl vector<ll>
#define pb push_back
#define INF 1000000007
#define PI 3.141592653
#define inf 100007
#define P pair<ll,ll>

using namespace std; 


int main(){
    ll n,k;
    cin>>n>>k;
    ll sum;
    sum=0;
    ll a=0,b=0;
    ll ans=0;
    int f=n-k+1,g=k-1;
    for(int i=n;i>=f;i--){
        a+=i;
    }
    for(int i=0;i<k;i++){
        b+=i;   
    }
    for(int i=k;i<=n+1;i++){
        // cout<<"a : "<<a<<" b : "<<b<<endl;
        ans+=a-b+1;
        f--,g++;
        a+=f;
        b+=g;
        
    }
    cout<<ans%INF;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
struct edge { LL to, cost; };

const LL inf = 11234567890123456;
std::vector<LL>dist;
std::vector<std::vector<edge>>G;
bool bellman_ford(LL n, LL s, LL t)
{
	std::fill(dist.begin(), dist.end(), inf);
	dist[s] = 0;
	rep(i, 2 * n)
	{
		for (LL v = 1; v <= n; ++v)
		{
			for (auto e : G[v])
			{
				if (dist[v] != inf && dist[e.to] > dist[v] + e.cost)
				{
					dist[e.to] = dist[v] + e.cost;
					if (i >= n - 1 && e.to == t) return true;
				}
			}
		}
	}
	return false;
}

int main()
{
	LL N, M;
	in >> N >> M;
	std::vector<LL>a(M), b(M), c(M);
	rep(i, M) in >> a[i] >> b[i] >> c[i];

	dist.resize(N + 1); G.resize(N + 1);
	rep(i, M) G[a[i]].push_back({ b[i],-c[i] });
	if (bellman_ford(N, 1, N)) out << "inf" << std::endl;
	else out << -dist[N] << std::endl;
}


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

int main()
{
	constexpr int max_N = 100011;
	int X = 0;
	cin >> X;
	int dp[max_N] {0};
	for (int i = 0; i <= 5; i++)
		dp[100 + i] = 1;
	
	// dynamic programming
	for (int i = 200; i < X + 10; i++)
		for (int j = 0; j <= 5; j++)
			if (dp[i - j - 100] == 1)
				dp[i] = 1;
			
	if (dp[X] == 1)
		cout << 1;
	else cout << 0;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int sum = 0;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		cout << sum - a[x - 1] + y << endl;
	}
}

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

using namespace std;
int a[100005];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	int ans=1e9;
	for(int i=0;i<n-k+1;i++)ans=min(ans,a[i+k-1]-a[i]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int i, j, k, n, array[100];

	scanf("%d", &n);
	for(i = 0; i < n; i++)  scanf("%d", &array[i]);  
	for(i = 0; i < n; i++){
		j = i;
		while(j > 0 && array[j] < array[j-1]){
			k = array[j];
			array[j] = array[j-1];
			array[j-1] = k;
			j--;
		}
		for(j = 0; j < n-1; j++)  printf("%d ", array[j]);
		printf("%d\n", array[n-1]);
	}
	
	return 0;
}

Measured memory_bytes: 600
# include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;

int main(){
  ll N;
  cin >> N;
  ll A[N+10];
  rep(i,1,N+1) cin >> A[i];
  ll res=1000;
  ll stock=0;
  ll diff;
  for(int i=2;i<=N;i++){
    if(A[i]>A[i-1]){
      diff =  A[i] - A[i-1];
      stock = res / A[i-1];
      res = res + diff*stock;
    }
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 3548
/*
ID: your_id_here
PROG: test
LANG: C++11
*/
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
//double pi=3.1415926535898;
//double pi=acos(-1.0);
#define scarr(a,s,e) for(int i=s;i<=int(e);i++) scanf("%d ",&a[i]);
#define prarr(a,s,e) for(int i=s;i<=int(e);i++) printf("%d ",a[i]);
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define rng(i,a,b) for(int i=a;i>=int(b);i--)
#define rep(i,a,b) for(int i=a;i<=int(b);++i)
#define lop(i,n)   for(int i=0;i<int(n);i++)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define mkp        make_pair
#define sc(x)      scanf("%d",&x)
#define scl(x)     scanf("%lld",&x)
#define pr(x)      printf("%d ",x)
#define prl(x)     printf("%lld ",x)
#define prln(x)    printf("%d\n",x)
#define prlln(x)   printf("%lld\n",x)
#define r0         return 0;
#define CC         continue;
#define scd(x)     scanf("%lf",&x)
#define prd(x)     printf("%.10f\n",x)
#define bb(x)      cerr<< x <<endl;
#define pii        pair<int,int>
#define pis        pair<int,string>
#define vi         vector<int>
#define x         first
#define y         second
//#define max(a,b) a<b?b:a __builtin_popcount;
//#define min(a,b) a<b?a:b
const ll M  = 1e9+7 ;
const int N = 100100;
//////////////////////    Hi    ^_^  hack me if you can :P

int main()
{
    //freopen("output.txt","w",stdout),freopen("input.txt","r",stdin);
    //speed;
    string a,b,c;
    cin>>a>>b>>c;
    cout<<a[0]<<b[0]<<c[0];
    r0;
}

/*

freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);

ll pwmod(ll a, ll n, ll mod) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ret;
}
Wj0944296025*
http://ideone.com/KrXO2S
*/
/*
for (int i=0;i<n;i++)            Hi    ^_^  hack me if you can :P
int mx[]= {0,0,1,-1, 1,1,-1,-1};
int my[]= {1,-1,0,0, 1,-1,1,-1};
bool inside (int i,int j) {return (i>=0 && i<n && j>=0 && j<m);}

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void gcd(LL n,LL m,LL &d,LL &xx,LL &yy){
    if(!m) {d=n; xx=1; yy=0;}
    else {gcd(m,n%m,d,yy,xx); yy-=xx*(n/m);}
}

int getm(int l,int r)
{
    if(l>r)
        return N;
    if(l==r)
        return 0;
    if(l==r-1)
        return s[l] != s[r];
    if(s[l]==s[r])
        return getm(l+1,r-1);
    else
        return 1+min(getm(l+1,r),getm(l,r-1));
}

int BIT[si], a[si], n;
void update(int x, int delta)
{
    for(; x <= N; x += x&-x)
        BIT[x] += delta;
}
int query(int x)
{
    int sum = 0;
    for(; x > 0; x -= x&-x)
        sum += BIT[x];
    return sum;
}

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

*/


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 20;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

ll n,a[200005];

int main() {
    cin >> n;
    REP(i,n)cin >> a[i];
    ll l=0,r=0, sum = 0, ans = 0;
    while(r<n){
        if((sum+a[r]) == (sum^a[r])){
            ans += r-l+1;
            sum ^= a[r];
            r++;
        }
        else{
            sum -= a[l];
            l++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
s = input()
s = s[::-1]
hoge = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
j = 0
while i < len(s):
    ans = ''
    while j < len(s):
        ans += s[j]
        if len(ans) > 7:
            print('NO')
            quit()
        if ans in hoge:
            break
        else:
            j += 1
    j += 1
    i = j
print('YES')


Measured memory_bytes: 3188
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll W, H, x, y;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> W >> H >> x >> y;

  double ans = 0.0;
  bool multi = false;
  if (W * y == H * x) {
    multi = true;
  }
  if (x == 0 && y == 0) {
    multi = false;
  }
  if (W == x && H == y) {
    multi = false;
  }
  ans = (double)W * (double)H / (double)2;

  cout << fixed << setprecision(10) << ans << " ";
  if (multi) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
bool check(int x){
	if (x==2) return true;
	else if(x<2||x%2==0)return false;
	int i=3;
	while(i <= sqrt(x)){
	if(x%i==0)return false;
	i=i+2;
	}
	return true;
}	//T???F??????????????°check()????????????if????????§?´???¨??§?????????



int main(){
	int n,x,count=0;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x;
		if(check(x))count++;

	}
	cout << count << endl;
}

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

int main(){
  int a,b,c,d,e,f,x,y,water,sugar;
  double tmp=0;
  cin >> a >> b >> c >> d >> e >> f;
  for(int i=0;100*i<=f;i++){
    for(int j=0;100*j<=f;j++){
       x = a*i+b*j;
      for(int k=0;k<=min(f-100*x,e*x);k++){
        for(int l=0;l<=min(f-100*x,e*x);l++){
          y=c*k+d*l;
          if(tmp<=double(y)/double(100*x+y)&&0<=y&&y<=min(f-100*x,e*x)){
          	tmp=double(y)/double(100*x+y);
          	water=100*x;
          	sugar=y;
          }
        }
      }
    }
  }
  cout << water+sugar << ' ' << sugar << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <climits>
#include <string.h>
#include <algorithm>

using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define pb push_back
#define sz(s) (int)s.size()
#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)

typedef long long ll;
typedef pair<ll, ll> pll;
const int N = (int)2e5 + 7;
//const ll inf = 1e16;

ll n,m,k,x,y,a[N];

int main(){
    cin>>n>>m;
    for1(i,n) cin>>a[i];
    for1(i,n-1){
        if(a[i]+a[i+1]>=m) k=i;
    }
    if(k==0) return cout<<"Impossible"<<endl, 0;
    cout<<"Possible\n";
    x=1;
    while(x<k) cout<<x<<endl,x++;
    x=n-1;
    while(x>k) cout<<x<<endl,x--;
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
				
int32_t main() {
	fast_cin();  
	int n; cin >> n;
	int a, b; cin >> a >> b;
	int s = a + b, x = 0;
	for (int i = 2; i < n; ++i) {
		int ai; cin >> ai;
		x ^= ai;
	}
	if (s - x < 0 or ((s - x) & 1)) {
		cout << -1 << endl;
		return 0;
	}
	int andd = (s - x) / 2;
	if (andd & x) {
		cout << -1;
		return 0;
	}
	int a1 = andd;
	for (int bit = 59; bit >= 0; --bit) {
		if (andd & (1LL << bit)) {
			continue;
		} else if (x & (1LL << bit)) {
			if ((a1 + (1LL << bit)) <= a) {
				a1 += (1LL << bit);
			} 
		}
	} 
	if (a1 == 0 or a1 > a) {
		cout << -1;
	} else {
		cout << a - a1 << endl;
	}
	return 0;
}

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

long long f(int h, int w){
	long long ret=LLONG_MAX;
	for (int i=1;i<w;i++){
		long long x=1ll*i*h;
		long long y=h/2;
		long long z=h-y;
		y*=(w-i);
		z*=(w-i);
		ret=min(ret,max(max(x,y),z)-
		min(min(x,y),z));
		int l=1,r=w-1;
		while (l<=r){
			int mid=(l+r)>>1;
			if (1ll*mid*(w-i)>=i*h){
				y=mid;
				r=mid-1;
			}else{
				l=mid+1;
			}
		}
		if (1ll*y*(w-i)>=i*h){
			z=h-y;
			y*=(w-i);
			z*=(w-i);
			ret=min(ret,max(max(x,y),z)-
			min(min(x,y),z));
		}
		y=(w-i)/2;
		z=w-i-y;
		y*=h;
		z*=h;
		ret=min(ret,max(max(x,y),z)-
		min(min(x,y),z));
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h,w;
	cin >> h >> w;
	long long ans=f(h,w);
	swap(h,w);
	ans=min(ans,f(h,w));
	cout << ans << "\n";
}

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

using namespace std;

int Pyt(int nr)
{
    cout << nr << endl;
    string x;
    cin >> x;
    if (x == "Vacant")
        return 0;
    if (x == "Male")
        return 1;
    if (x == "Female")
        return 2;
}

int main()
{
    int n;
    cin >> n;
    int zero = Pyt(0);
    if (zero == 0)
        return 0;
    int l = 1, p = n - 1, s;
    while (l <= p)
    {
        s = (l + p) / 2;
        int odp = Pyt(s);
        if (odp == 0)
            return 0;
        if ((s % 2 == 0 && zero == odp) || (s % 2 == 1 && zero != odp))
            l = s + 1;
        else
            p = s - 1;
    }
    return 0;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    string s; cin >> s;
    int a = s[0]-'0'; int b = s[1]-'0';int c = s[2]-'0';int d = s[3]-'0';
    if(a+b+c+d == 7) cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    else if(a+b+c-d == 7) cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    else if(a+b-c+d == 7) cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    else if(a+b-c-d == 7) cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
    else if(a-b+c+d == 7) cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    else if(a-b+c-d == 7) cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    else if(a-b-c+d == 7) cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    else if(a-b-c-d == 7) cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int n,a;
vector<int> v;
long long dp[51][51][2501];
long long calc(int i, int d, int s){
	if(i==n && d>0 && s%d==0 && s/d == a) return 1;
	else if(i==n)return 0;
	if(dp[i][d][s]!=-1)return dp[i][d][s];
	long long x=calc(i+1, d+1, s+v[i]);
	long long y=calc(i+1, d, s);
	return dp[i][d][s] = x+y;
}
int main() {
	for(int i=0; i<51; ++i)
		for(int j=0; j<51; ++j)
			for(int k=0; k<2501; ++k)
				dp[i][j][k]=-1;
	cin>>n>>a;
	v.resize(n);
	for(int i=0; i<n; ++i)
		scanf("%d",&v[i]);
	long long ans = calc(0,0,0);
	cout<<ans;
}

Measured memory_bytes: 51072
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int moneySet[] = { 500 , 100 , 50 , 10 , 5 , 1 } ;
    int money = 0 ;
    int Count = 0 ;
    while(1)
    {
        cin >> money ;
        if ( money == 0 ) break ;
        money = 1000 - money ;

        for (int i = 0 ; i < 6 ; i++ )
        {
            while( money >= moneySet[i] )
            {
                Count++ ;
                money -= moneySet[i] ;
            }
        }

        cout << Count << endl ;
        Count = 0 ;
    }

    return 0 ;
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


class FactorialMod{
    void calc_inverse(){
        inverse[0] = 0;
        inverse[1] = 1;
        for(int i=2; i<=max_num; i++){
            inverse[i] = md-((md/i)*inverse[md%i]%md);
        }
    }

    void calc_factorial_inverse(){
        factorial[0] = factorial_inverse[0] = 1;
        for (int i=1; i<=max_num; i++) {
            factorial[i] = (factorial[i-1]*i)%md;
            factorial_inverse[i] = (factorial_inverse[i-1]*inverse[i])%md;
        }
    }

    public:
        ll max_num, md;
        vector<ll> inverse; 
        vector<ll> factorial;
        vector<ll> factorial_inverse;
        FactorialMod(ll _max_num, ll _md=MOD){
            max_num = _max_num;
            md = _md;
            inverse = vector<ll>(max_num+1);
            factorial = vector<ll>(max_num+1);
            factorial_inverse = vector<ll>(max_num+1);
            calc_inverse();
            calc_factorial_inverse();
        }

        ll combination(int n, int k){
            return (((factorial[n]*factorial_inverse[k])%md)*factorial_inverse[n-k])%md;
        }

        ll multiChoose(int n, int k){
            return combination(n+k-1, k);
        }
};

ll modpow(ll x, ll n, ll md=MOD){
    ll res=1, dig=x;
    while(n){
        if(n&1) res = res*dig%md;
        dig = dig*dig%md;
        n /= 2;
    }
    return res;
}

int main(){
    ll n, m, k; cin >> n >> m >> k;
    //重複組み合わせは(n+k)にする
    ll mod = 998244353, res=0;
    FactorialMod calc_mod(n, mod);
    rep(i, k+1){
        res += m*calc_mod.combination(n-1, i)%mod*modpow(m-1, n-1-i, mod)%mod;
        res %= mod;
    }   
    cout << res << endl; 
    

}

Measured memory_bytes: 7948
//#pragma GCC target ("avx2,sse2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree <pair <ll, int>, null_type, less <pair <ll, int> >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"

#define left fsdsdfoisf
#define sum dpsdfioppsf
#define assign xcvjlkdjfio
#define trie fksdfkjkfnjuiv
#define next sidlfjsfkl
#define merge sdfksdkfsldf

//#define int long long

using namespace std;

void dout() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 3007;
int a, b, dp[N][N];
pii p[N][N];
string s, t, ans;

pii mx(pii x, pii y) {
    if (dp[x.fi][x.se] > dp[y.fi][y.se]) {
        return x;
    }
    return y;
}

void getans(pii x) {
    if (x == mp(0, 0)) {
        return;
    }
    if (s[x.fi - 1] == t[x.se - 1]) {
        ans += s[x.fi - 1];
    }
    getans(p[x.fi][x.se]);
}

void solve(int tc) {
    // check for (int i = 0; i < n; j++)
    cin >> s >> t;
    a = sz(s), b = sz(t);
    for (int i = 1; i <= a; i++) {
        pii h = {0, 0};
        for (int j = 1; j <= b; j++) {
            dp[i][j] = dp[h.fi][h.se] + (s[i - 1] == t[j - 1]);
            if (dp[i][j] >= dp[i - 1][j]) {
                p[i][j] = h;
            }   else {
                dp[i][j] = dp[i - 1][j];
                p[i][j] = {i - 1, j};
            }
            h = mx(h, mp(i - 1, j));
        }
    }
    pii res = {0, 0};
    for (int i = 1; i <= b; i++) {
        res = mx(res, mp(a, i));
    }
    getans(res);
    reverse(all(ans));
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}


Measured memory_bytes: 106112
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,c,d;
    cin>> a >> b >> c >> d;
    if(abs(a-c)<=d){
        cout << "Yes" << endl;
        return 0;
    }


    if(abs(a-b)<=d&&abs(b-c)<=d){
        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout << "No" << endl;
        return 0;
    }


    return 0;
}


Measured memory_bytes: 384
#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>
#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 pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  sort(all(s));
  if(s=="abc") cout << "Yes" << endl;
  else cout << "No"<< endl;
  return 0;
}


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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> vector1(n);
    for (int i = 0; i < n; i++){
        cin >> vector1.at(i);
    }
    vector<int> vector2(n + 1);
    vector2.at(0) = 0;
    for (int j = 1; j <= n; j++){
        vector2.at(j) = vector2.at(j - 1) + vector1.at(j - 1);
    }
    int count = 0;
    for (int i = 0; i < n + 1; i++){
        if (vector2.at(i) <= x){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	public static void main(String[] args){
		String[] str = new String[2];
		int sum=0,ave=0,count=0,n,m;
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()){
			str = sc.nextLine().split(",");
			n = Integer.valueOf(str[0]);
			m = Integer.valueOf(str[1]);
			sum += n*m;
			ave += m;
			count++;
		}
		ave = (int)Math.round((double)ave/count);
		System.out.println(sum);
		System.out.println(ave);
	}
}

Measured memory_bytes: 17336
#include <string>
#include <iostream>


using namespace std;
typedef pair<int ,int > P;

struct Node {
    int value;
    Node *next;
    Node *prev;
};
Node *nil;

void init() {
    nil = new Node();
    nil->next = nil;
    nil->prev = nil;
}

void insert_node(int x) {
    Node *p = new Node;
    p->value = x;

    p->next = nil->next;
    nil->next->prev=p;
    nil->next=p;
    p->prev=nil;
}

Node* search_node(int x) {
    Node *cur = nil->next;
    while(cur != nil && cur->value != x) cur = cur->next;
    return cur;
}

void delete_node(Node *p) {
    if(p == nil) return;
    p->prev->next=p->next;
    p->next->prev=p->prev;
    delete p;
}
void delete_first_node() {
    delete_node(nil->next);
}
void delete_last_node() {
    delete_node(nil->prev);
}
void delete_key_node(int x) {
    delete_node(search_node(x));
}

int main() {
    ios::sync_with_stdio(false);
    init();
    int n;
    string q;
    cin>>n;
    while(n--) {
        int x;
        cin>>q;
        if(q=="insert") {
            cin>>x;
            insert_node(x);
        }
        else if(q=="delete") {
            cin>>x;
            delete_key_node(x);
        }
        else if(q=="deleteFirst") {
            delete_first_node();
        }
        else if(q=="deleteLast") {
            delete_last_node();
        }
    }
    int t=0;
    Node *cur = nil->next;
    while(cur != nil) {
        if(t++) cout<<" ";
        cout<<cur->value;
        cur=cur->next;
    }
    cout<<endl;
    
    return 0;
}

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

int main(void)
{
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  int sum = 0;
  for(int i=0; i<N; i+=2)
    sum += a[i];
  for(int i=1; i<N; i+=2)
    sum -= a[i];
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N, C[100], V[100];
int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> V[i];
    }
    for(int i = 0; i < N; i++){
        cin >> C[i];
    }
    int result = 0;
    for(int i = 0; i < N; i++){
        result += max(0, V[i] - C[i]);
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF long long int(1e18+1)
#define MAX 200001
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;
	
int main() {
	int n;
	cin >> n;
	if (n == 1)cout << 0 << endl;
	else cout << 1 << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> A(M);
  vector<int> B(M);
  for(int i=0;i<M;i++){
  	cin >> A.at(i) >> B.at(i);
  }
  vector<int> C(N);
  for(int j=0;j<N;j++){
    for(int k=0;k<M;k++){
    	if(A.at(k)==j+1 || B.at(k)==j+1) C.at(j)++;
    }
  }
  for(int l=0;l<N;l++){
  	cout << C.at(l) <<endl;
  }
}  

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,c,n) for(int i=c;i<n;i++)
#define debug(x) cerr << #x << ": " << x << endl;
using namespace std;

struct hoge {
  int id;
  int p;
  int y;
};

int main(){
  int n,m;
  cin >> n >> m;
  struct hoge h[m];
  vector<vector<int>> pl (n, vector<int>(0));
  
  r(i,m){
    h[i].id = i;
    cin >> h[i].p >> h[i].y;
    pl[h[i].p-1].push_back(h[i].y);
  }

  vector<map<int,int>> px (n, map<int,int>{});
  r(i,n){
    sort(pl[i].begin(),pl[i].end());
    r(j,pl[i].size()){
      px[i].emplace(pl[i][j],j);
    }
  }

  r(i,m){
    cout << setfill('0') << setw(6) << right;
    cout << h[i].p;
    cout << setfill('0') << setw(6) << right;
    cout << px[h[i].p-1].at(h[i].y) + 1;
    cout << endl;
  }

  return 0;
}

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

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

    vector<int> num(N);

    for(int i=0;i<N;i++)
    {
        cin >> num.at(i);
    }

    stable_sort(num.begin(),num.end());
    int A = 0;
    int B = 0;
    int last = num.size() - 1;

    while(true)
    {
       A += num.at(last);
       num.pop_back();
       last--;
       if(last<0) break;
       B += num.at(last);
       num.pop_back();
       last--;
       if(last<0) break;
    }

    cout << A - B;

    return 0;
}


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

int main()
{
    string s1,s2;
    cin>>s1;
    cin>>s2;

    int c = 0;

    for(int i = 0,j=0;i<s1.length(),j<s2.length();i++,j++){
        if(s1[i] != s2[j]){
            c++;
        }
    }
    cout<<c;
}


Measured memory_bytes: 3920
def examA():
    C1 = SI()
    C2 = SI()
    ans = "YES"
    if C1[0]!=C2[2] or C1[1]!=C2[1] or C1[2]!=C2[0]:
        ans = "NO"
    print(ans)
    return

def examB():
    A, B, C, X, Y = LI()
    loop = max(X,Y)
    ans = inf
    for i in range(loop+1):
        cost = i*2*C
        if X>i:
            cost += A*(X-i)
        if Y>i:
            cost += B*(Y-i)
        ans = min(ans,cost)
    print(ans)
    return

def examC():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    N, x = LI()
    X = LI()
    if N==1:
        print(abs(X[0]-x))
        return
    for i in range(N):
        X[i] = abs(X[i]-x)
    now = gcd(X[0],X[1])
    for i in range(2,N):
        now = gcd(now,X[i])
    ans = now
    print(ans)
    return

def examD():
    N = I()
    C = [LI()for _ in range(N-1)]
    ans = [inf]*N
    for i in range(N):
        cur = 0
        for j in range(i,N-1):
            c, s, f = C[j]
            next = 0
            if cur<=s:
                cur = s+c
            else:
                cur = (1+(cur-1)//f)*f + c
        ans[i] = cur
    for v in ans:
        print(v)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 6756