akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <set>

int V, E;
const int vmax = 100005;
const int NIL = -1;
std::array<std::vector<int>, vmax> adjlist;
std::array<bool, vmax> visited;
std::array<int, vmax> prenum;
std::array<int, vmax> lowest;
std::array<int, vmax> parent;
// std::array<std::vector<int>, vmax> backedge;

void dfs(int u, int& timer){
  visited[u] = true;
  prenum[u] = timer;
  lowest[u] = timer;

  for (int i=0; i<adjlist[u].size(); ++i)
    {
      auto v = adjlist[u][i];
      if (!visited[v])
        {
          parent[v] = u;
          dfs(v, ++timer);
          if (lowest[v] < lowest[u]){
            lowest[u] = lowest[v];
          }
        }
      else if (v != parent[u])
        {
          if (prenum[v] < lowest[u]){
            lowest[u] = prenum[v];
          }
        }
    }
}

void solve(std::set<int> &ans) {
  visited.fill(false);
  prenum.fill(0);
  parent.fill(NIL);

  int timer = 1;
  dfs(0, timer);

  auto num_root_child = 0;
  for (int u=1; u<V; ++u)
    {
      auto p = parent[u];
      if (p == 0) num_root_child++;
      else if (prenum[p] <= lowest[u]){
        ans.insert(p);
      }
    }
  if (num_root_child >= 2){
    ans.insert(0);
  }
}

int main ()
{
  std::cin >> V >> E;
  int s, t;
  for (int i=0; i<E; ++i)
    {
      std::cin >> s >> t;
      adjlist[s].push_back(t);
      adjlist[t].push_back(s);
    }

  std::set<int> ans;
  solve(ans);
  //std::sort(ans.begin(), ans.end());
  std::for_each(ans.begin(), ans.end(), [](auto x){std::cout << x << std::endl;});
}



Measured memory_bytes: 7828
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i =0; i < n ;i++)
using namespace std;
int a[102][2][30];

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans =0;
    
    rep(i, N){
        int temp=0;
        for(int j= 0 ;j<i; j++){
            a[i][0][S[j]-'a']++;
        }
        for(int j= i ;j<N; j++){
            a[i][1][S[j]-'a']++;
        }
        rep(j, 27){
            if((a[i][0][j]>0) & (a[i][1][j]>0)) temp++;
        }
        ans = max(temp, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,k,q;
int a[200000],p[200000];
signed main(){
    cin>>n>>k>>q;
    rep(i,q){
        cin>>a[i];
        p[a[i]]++;
    }
    rep(i,n){
        if(p[i+1]>q-k)puts("Yes");
        else puts("No");
    }
    return 0;
}





Measured memory_bytes: 2176
import java.util.*;
class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int w = Integer.parseInt(sc.next());
      int h = Integer.parseInt(sc.next());
      int x = Integer.parseInt(sc.next());
      int y = Integer.parseInt(sc.next());
      
      double half = (double)w*h / 2; 
      
      double centerX = (double)w / 2;
      double centerY = (double)h / 2;
      
      
      
      if (x == centerX && y == centerY) {
        System.out.print(half);
        System.out.print(' ');
        System.out.print(1);
      } else {
        System.out.println(half);
        System.out.print(' ');
        System.out.print(0);
      }
    }
      
}

Measured memory_bytes: 23124
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int d = scanner.nextInt(), g = scanner.nextInt();
        int[] p = new int[d], c = new int[d];
        for (int i = 0; i < d; i++) {
            p[i] = scanner.nextInt();
            c[i] = scanner.nextInt();
        }

        int ans = 10000;
        for (int i = 0; i < 1 << d; i++) {
            int sum = 0, count = 0, zero = 0;
            for (int j = 0; j < d; j++) {
                if ((1 << j & i) != 0) {
                    sum += (j + 1) * 100 * p[j] + c[j];
                    count += p[j];
                } else {
                    zero = j;
                }
            }
            if (sum < g) {
                int t = (int)Math.ceil((g - sum) / ((zero + 1) * 100F));
                if (p[zero] < t)
                    continue;
                count += Math.ceil((g - sum) / ((zero + 1) * 100F));
            }
            ans = Math.min(ans, count);
        }
        System.out.println(ans);
    }
}

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

int main() {
  long long N,A,B;
  cin >> N >> A >> B;
  if(A>B){
    long long b;
    b = B;
    B = A;
    A = b;
  }
  if((B-A)%2 == 0){
    cout << (B-A)/2 << endl;
  }
  else{
    if(A+B-1 <= N){
      cout << (A+B-1)/2 << endl;
    }
    else{
      cout << N-((A+B-1)/2) << endl;
    }
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
#define P pair<int, int>
using namespace std;

int main(){
    ll n, d, cnt = 0;
    cin >> n >> d;
    rep(i, n){
        ll x, y;
        cin >> x >> y;
        long double dist = (long double)sqrt(x*x + y*y);
        if(dist <= (long double)d) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3676
using System;
using System.Linq;
using System.Collections.Generic;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var a = int.Parse(_[0]);
            var b = int.Parse(_[1]);
            var c = int.Parse(_[2]);
            var d = int.Parse(_[3]);

            var i = 1;
            while(true){
                if(i % 2 != 0){
                    c -= b;
                }else{
                    a -= d;
                }

                if(a <= 0){
                    Console.WriteLine("No");
                    break;
                }else if(c <= 0){
                    Console.WriteLine("Yes");
                    break;
                }

                i++;
            }
        }
    }
}


Measured memory_bytes: 27380
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int keta(int a){
	int num=0;
	while(a){
		a/=10;
		num++;
	}
	return num; 
}

int main(){
	int n,ans=0;
	cin >> n;
	for(int i=1;i<=n;i++){
		if(keta(i)%2==1)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
void WF(ll d[310][310],ll n){
    rep(k,n){
        rep(i,n){
            rep(j,n){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
          //cout<<d[i][j]<<' ';
        }
      //cout<<endl;
    }
}
int main(){
  ll n,m,l;
    cin>>n>>m>>l;
    ll d[310][310];
    rep(i,n)rep(j,n)d[i][j]=inf;
  rep(i,n)d[i][i]=0;
    rep(i,m){
        ll a,b,c;cin>>a>>b>>c;
        a--;b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    WF(d,n);
    ll dd[310][310];
    rep(i,n)rep(j,n){
        if(i==j)dd[i][j]=0;
        else if(d[i][j]<=l)dd[i][j]=1;
        else dd[i][j]=inf;
    }
    WF(dd,n);
    ll q;cin>>q;
    ll s,t;
    while(q){
        q--;
      cin>>s>>t;
        s--;t--;
        if(dd[s][t]>=inf)cout<<-1<<endl;
        else cout<<max(0LL,dd[s][t]-1)<<endl;
    }
}

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

using namespace std;

typedef long long LL;
#define N 300000
#define INF 0x3f3f3f3f3f3f3f3fLL

LL n,ans,ls[N][2],rs[N][2],sz[N];
struct node{
	LL x,y;
	node(LL x=0,LL y=0):x(x),y(y){}
	bool operator < (const node &p) const{return x<p.x;}
};
vector<node> f[N];

LL qry(LL x,LL len){
	LL l=0,r=(LL)f[x].size()-1,ret=INF;
	while (l<=r){
		LL mid=(l+r)>>1;
		if (f[x][mid].x<=len){ret=f[x][mid].y; l=mid+1;}
		else r=mid-1;
	}
	return ret;
}

bool solve(LL t){
	for (LL i=n;i;--i){
		sz[i]=1;
		f[i].clear();
		if (!ls[i][0]) f[i].push_back(node(0,0));
		else{
			sz[i]+=sz[ls[i][0]]+sz[rs[i][0]];
			if (sz[ls[i][0]]>sz[rs[i][0]]){
				swap(ls[i][0],rs[i][0]);
				swap(ls[i][1],rs[i][1]);
			}
			LL l1=ls[i][1],l2=rs[i][1];
			vector<node> g;
			for (node j:f[ls[i][0]]){
				if (j.y+l1+l2<=t){
					LL p=qry(rs[i][0],t-(j.y+l1+l2))+l2;
					if (p<INF){
						g.push_back(node(j.x+l1,p));
						g.push_back(node(p,j.x+l1));
					}
				}
			}
			sort(g.begin(),g.end());
			LL lst=INF;
			for (node j:g) if (j.y<lst){f[i].push_back(j); lst=j.y;}
		}
	}
	return f[1].size()>0;
}

int main(){
	scanf("%lld",&n);
	for (LL i=2;i<=n;++i){
		LL x,y; scanf("%lld%lld",&x,&y);
		if (!ls[x][0]){ls[x][0]=i; ls[x][1]=y;}
		else{rs[x][0]=i; rs[x][1]=y;}
	}
	LL l=0,r=n<<20;
	while (l<=r){
		LL mid=(l+r)>>1;
		if (solve(mid)){ans=mid; r=mid-1;}
		else l=mid+1;
	}
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 43396
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

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

	int res = 0;

	if (k >= a)
	{
		res += a;
		k -= a;
	}
	else
	{
		cout << k << endl;
		return 0;
	}

	if (k >= b)
	{
		k -= b;
	}
	else
	{
		cout << res << endl;
		return 0;
	}

	if (k >= c)
	{
		res -= c;
		cout << res << endl;
	}
	else
	{
		res -= k;
		cout << res << endl;
	}
	

	return 0;
}

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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

std::string s;
int main()
{
	std::cin >> s;

	auto n = s.size();
	if (((n % 2 == 0 ? 1 : 0) ^ (s[0] == s[n - 1] ? 1 : 0)) == 1)
		std::cout << "Second" << std::endl;
	else
		std::cout << "First" << std::endl;
	return 0;
}


Measured memory_bytes: 512
/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair<int,int>

typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl pi = acos(-1);
const ll inf = 1LL<<30;
const dbl eps = 1e-9;
const ll mod = 1e9+7;

/** /////////// ** Code ** /////////// **/

const int N=0;

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

    if(sum%9 == 0) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
int d(int x)
{
  if(x==0)return 1;
  int ret=0;
  while(x)
  {
    ret++;x/=10;
  }
  return ret;
}
int th(int x,int i)
{
  if(x==0)return 0;
  vector<int>v;
  while(x)
  {
    v.push_back(x%10);x/=10;
  }
  reverse(v.begin(),v.end());
  return v[i-1];
}
int aa[N+2],bb[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n,m;cin>>n>>m;
  for(int i=1;i<=m;i++)
    cin>>aa[i]>>bb[i];

  for(int i=0;i<=10000;i++)
  {
    if(d(i)!=n)continue;

    int f=0;
    for(int j=1;j<=m;j++)
    {
      if(th(i,aa[j])!=bb[j])f=1;
    }
    if(!f)cout<<i<<endl,exit(0);
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 2304
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Abc168B
    {
        public static void Main()
        {
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            if (s.Length > k)
                s = s.Substring(0, k) + "...";
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 27544
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long n,k,ans=0;
vector<long long> a;
int main(){
	long long i,j,x;
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		cin>>x;
		a.push_back(x);
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(a[i]>a[j])
			{
				if(i>j)
				{
					ans=(ans+k*(k-1)/2)%MOD;
				}
				else
				{
					ans=(ans+(k+1)*k/2)%MOD;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
string s;
int main(){
    ios::sync_with_stdio(0);
    cin>>s;
    while(s.length()>0){
        if (s.size()>=7 && s.substr(s.size()-7,7) == "dreamer"){
            s.erase(s.size()-7,7);
        }
        else if (s.size()>=5 && s.substr(s.size()-5,5) == "dream"){
            s.erase(s.size()-5,5);
        }
        else if (s.size()>=6 && s.substr(s.size()-6,6) == "eraser"){
            s.erase(s.size()-6,6);
        }
        else if (s.size()>=5 && s.substr(s.size()-5,5) == "erase"){
            s.erase(s.size()-5,5);
        }
        else break;
    }
    if (s.length()==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3760
package main

import (
	"fmt"
	"strings"
)

func main() {
	var a string
	fmt.Scan(&a)

	n := strings.Split(a, "")

	count := 0
	for i := 0; i < 3; i++ {
		if n[i] == n[i+1] {
			count++
		}
	}

	if count == 0 {
		fmt.Println("Good")
	} else {
		fmt.Println("Bad")
	}

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,x,y;
    cin>>a>>b>>c>>d;
    if(a<=c)
        x=c;
    else
        x=a;
    if(b<=d)
        y=b;
    else
        y=d;
    if((y-x)> 0)
        cout<<y-x;
    else
        cout<<0;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;

  
     signed main(){
     int n;
     cin>>n;
     if(n%10==3){
          cout<<"bon"<<endl;
          return 0;
     }
     if(n%10==0||n%10==1||n%10==6||n%10==8){
          cout<<"pon"<<endl;
     }else cout<<"hon"<<endl;

      }

        

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

using namespace std;

int n;
map <int, int> cnt;
int a[100005];
vector <int> val;

void del(int x) {
    if (cnt.find(x) == cnt.end()) {
        cout << "No" << endl;
        exit(0);
    }
    --cnt[x];
    if (cnt[x] == 0) cnt.erase(cnt.find(x));
}

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ++cnt[x];
    }
    for (auto x: cnt) val.push_back(x.first);
    if (val.size() == 1) {
        if (val[0] == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    a[0] = val[0], a[1] = val[1];
    del(val[0]), del(val[1]);
    for (int i = 2; i < n; ++i) {
        a[i] = a[i-1] ^ a[i-2];
        del(a[i]);
    }
    if ((a[n-1] ^ a[0]) == a[1] && (a[n-2] ^ a[n-1]) == a[0]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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


int main(){
  ll a,v,b,w;
  ll t;
  cin >> a >> v;
  cin >> b >> w;
  cin >> t;
  if(a<b){
    ll ka=v*t+a;
    ll kb=w*t+b;
    if(kb>ka){
      cout << "NO" << endl;
    }else{
      cout << "YES" << endl;
    }
  }else{
    ll ka=a-(v*t);
    ll kb=b-(w*t);
    if(kb<ka){
      cout << "NO" << endl;
    }else{
      cout << "YES" << endl;
    }
  }
  return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int a,b,c; cin>>a>>b>>c;
  vector<int> d(101, 0);
  int s=a;
  while(true) {
    int t = s%b;
    if (t==c) {
      cout << "YES" << endl;
      return;
    }
    if (d[t]==1) {
      cout << "NO" << endl;
      return;
    }
    d[t]=1;
    s+=a;
  }
}

int main()
{
  solve();
  return 0;
}


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

#include <cmath>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

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

    vector<int> hs(N, 0.0);
    for (int i = 0; i < N; i++) {
        cin >> hs[i];
    }

    int cand = INT_MAX;
    int idx = -1;
    for (int i = 0; i < N; i++) {
        double v = abs((1000 * T - hs[i] * 6) - 1000 * A);
        if (v < cand) {
            idx = i;
            cand = v;
        }
    }
    cout << idx + 1 << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const ld INF = 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector< vector<int> > g(n);
    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        g[s].push_back(t);
    }

    vector<ld> dp(n, INF);
    dp[n - 1] = 0;

    for (int i = n - 2; i >= 0; i--) {
        ld sum0 = 0; 
        for (int j : g[i]) {
            sum0 += dp[j];
        }

        dp[i] = sum0 / g[i].size() + 1;
    }

    ld ans = dp[0];
    for (int i = n - 2; i >= 0; i--) {
        vector<ld> dp2 = dp;

        if (g[i].size() > 1) {
            ld sum = 0;
            ld maxv = 0;
            for (int j : g[i]) {
                sum += dp2[j];
                maxv = max(maxv, dp2[j]);
            }
            dp2[i] = min(dp2[i], (sum - maxv) / (g[i].size() - 1) + 1);
        }

        for (int j = i - 1; j >= 0; j--) {
            ld sum = 0;
            for (int k : g[j]) {
                sum += dp2[k];
            }
            dp2[j] = sum / g[j].size() + 1;
        }
        ans = min(ans, dp2[0]);
    }
    cout << fixed << setprecision(20) << ans << "\n";
    return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] ss = line.split(" ");
		int a = Integer.parseInt(ss[0]);
		int b = Integer.parseInt(ss[1]);
		int c = Integer.parseInt(ss[2]);
		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26148
package main
 
import (
  "fmt"
)

func main() {
  var a, b, x int
  fmt.Scan(&a, &b, &x)

  ans := 0
  if a == 0 {
    ans = b/x
    ans++
  }else{
    ans = b/x - (a-1)/x
  }
  fmt.Printf("%d\n", ans)
}

Measured memory_bytes: 1836
#include <iostream>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
  if(a==0)return b;
  else return gcd(b%a,a);
}

int main(){
  ll A,B,C,D,lcm,p;
  cin >> A >> B >> C >> D;
  lcm=C*D/gcd(C,D);
  p=((B/C)-((A-1)/C))+((B/D)-((A-1)/D))-((B/lcm)-(A-1)/lcm);
  cout << B-A+1-p << endl;
  return 0;
}

Measured memory_bytes: 256
// 0280
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	while(1){
		int N, turn=0, table = 0;
		string str;
		vector<int> card;

		cin>>N;
		if(N == 0)
			break;

		for(int i=0;i<N;i++){
			card.push_back(0);
		}

		cin>>str;
		for(int i=0;i<str.length();i++){
			if(str[i] == 'M'){
				card[turn]++;
			}else if(str[i] == 'S'){
				table += card[turn]+1;
				card[turn] = 0;
			}else if(str[i] == 'L'){
				card[turn] += table+1;
				table = 0;
			}

			turn++;
			if(turn == N)
				turn = 0;
		}

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

		for(int i=0;i<N;i++)
			cout<<card[i]<<" ";
		cout<<table<<endl;
	}
	return 0;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    int num[10]={0,2,5,5,4,5,6,3,7,6};
    int dp[n+1];
    dp[0]=0;
    for(int i=1;i<=n;i++){
        dp[i]=-100000000;
        for(int j=0;j<m;j++){
            if(i-num[a[j]]>=0){
                dp[i]=max(dp[i],dp[i-num[a[j]]]+1);
            }
        }
    }

    string ans="";
    sort(a,a+m);
    reverse(a,a+m);
    

    while(n){
        for(int i=0;i<m;i++){
            if(n-num[a[i]]>-1 && dp[n-num[a[i]]]==dp[n]-1){
                ans+=(char)'0'+a[i];
                n-=num[a[i]];
                break;
            }
        }
    }

    cout<<ans<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    LL n,dist,query,lim;
    vector<LL> d,ans,mini,pos;
    Problem(LL n):n(n),d(n),ans(n),mini(n+1),pos(n+1){};

    void solve(){
        cin >> dist;
        lim=LINF;
        pos[0]=dist;
        for(int i=0; i<n; ++i){
            cin >> d[i];
        }
        for(LL i=0; i<n; ++i){
            dist=min(abs(dist-d[i]),dist);
            pos[i+1]=dist;
            if(pos[i+1]==0){
                lim=i;
                break;
            }
        }
        mini[n-1]=1;
        for(LL i=n-1; i>0; --i){
            if(d[i]<mini[i]*2)mini[i-1]=mini[i]+d[i];
            else mini[i-1]=mini[i];
        }
        cin >> query;
        for(LL i=0; i<query; ++i){
            LL tmp;
            cin >> tmp;
            tmp--;
            DBG(tmp,lim,mini[tmp],pos[tmp])
            cout << ((lim==LINF or(tmp<=lim and mini[tmp]<=pos[tmp]))?"YES":"NO") <<"\n";
        }

    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 17536
#include <stdio.h>
#include <math.h>
#include <string.h>


int main(){
    
    
    int i;
    char str[210];
    gets(str);
    
    for (i=0; i<strlen(str); i++) {
        if(str[i]>='a' && str[i]<='z')
            str[i] =str[i]-32;
    }
    printf("%s\n",str);
    
    
    return 0;
    
}

Measured memory_bytes: 524
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

	string S, T;
	cin >> S >> T;

	int ans = 0;

	rep(i, 3) {
		if (S[i] == T[i]) ans++;
	}

	cout << ans;

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


Measured memory_bytes: 760
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 27 02:20:18 2020

@author: liang
"""

N = int(input())
A = [int(x) for x in input().split()]

c0 = 0
c4 = 0
for a in A:
    if a%2 == 1:
        c0 += 1
    elif a%4 == 0:
        c4 += 1

if c0 <= c4:
    print("Yes")
else:
    if c0 + c4 == N and c0 == c4 + 1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 19836
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
using namespace std;

int n,ans,ans2;
int a,b,c,d,e,f;

//最大公約数
ll gcd(ll a,ll b){
    
    if(a==0 || b==0)return 0;
    if(a<b){
        ll sw;
        sw=a;
        a=b;
        b=sw;
    }
    
    ll r;
    while((r=a%b)!=0){
        a=b;
        b=r;
    }
    return b;
}
//最小公倍数
ll lcm(ll a,ll b){


    if(a==0 || b==0)return 0;

    return a/gcd(a,b)*b;

}

signed main(){
    cin>>a>>b>>c>>d>>e>>f;
    
    int GCD=gcd(100,e);
    e/=GCD;
    int g=100/GCD;
    double noud=0;
    for(int i=1;i<=f;i++){
    	int answ=a*100,anss=0;
    	double lim=double(i)/double(g+e)*double(e);
    	for(int k=0;k<=(int)lim;k++){
    		int flag=0,flag2=0;
    		int water=i-k;
    		int sugar=k;
    		for(int j=0;j*a*100<=water;j++){
    			if((water-j*a*100)%(b*100)==0)flag=1;
    		}
    		for(int j=0;j*c<=sugar;j++){
    			if((sugar-j*c)%d==0)flag2=1;
    		}
    		
    		if(flag&&flag2){
    			answ=water;
    			anss=sugar;
    		}
    	}
    	if(double(anss)/double(anss+answ)>=noud){
    		ans=answ+anss;ans2=anss;
    		noud=double(anss)/double(anss+answ);
    	}
    }
    //cout<<noud<<endl;
    cout<<ans<<" "<<ans2<<endl;
}


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






#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define pii                 pair<int,int>
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define pbp(a,b)            push_back({a,b})
#define db                  double
#define ft                  float
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define ff                  first
#define ss                  second
#define sz(x)               x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define N                   200005
#define inf                 100000008
#define mod                 1000000007

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


ll x[N];


ll bs(ll a,ll n)
{
    ll h=n,l=1,mid=(h+l)/2;
    while(l<=h)
    {
        mid=(h+l)/2;
        //cout<<l<<" "<<h<<" "<<mid<<endl;
        if(x[mid]>a)
            h=mid-1;
        else if(x[mid]<a)
            l=mid+1;
        else
            break;
    }
    return mid;
}


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
































Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def dfs(v):
    vs.append(v)
    useds[v] = True
    for v2 in adjL[v]:
        if not useds[v2]:
            dfs(v2)

N = int(input())
adjL = [[] for _ in range(N)]
ABs = []
for _ in range(N-1):
    a, b = map(int, input().split())
    adjL[a-1].append(b-1)
    adjL[b-1].append(a-1)
    ABs.append((a-1, b-1))
cs = list(map(int, input().split()))

cs.sort(reverse=True)

vs = []
useds = [False] * N
dfs(0)

anss = [0] * N
for v, c in zip(vs, cs):
    anss[v] = c

score = 0
for A, B in ABs:
    score += min(anss[A], anss[B])

print(score)
print(*anss)


Measured memory_bytes: 14940
N = gets.to_i
ss = []
ret_char = Hash.new
('a'..'z').each do |c|
  ret_char[c] = 50
end
N.times do |i|
  str = gets.each_char.to_a
  ss[i] = Hash.new
  ('a'..'z').each do |c|
    ss[i][c] = str.count(c)
    if ret_char[c] > ss[i][c]
      ret_char[c] = ss[i][c]
    end
  end
end

ret = ""
('a'..'z').each do |c|
  ret += c * ret_char[c]
end

puts ret

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define int long long
using namespace std;

const int P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
  cout << fixed << setprecision(10);
  int N, M;
  cin >> N >> M;
  vector<int> vec(M);
  int sum=0;
  for(int i=0;i<M;i++)
  {
    cin >> vec[i];
  }
  for(int i=0;i<M;i++)
  {
    sum += vec[i];
  }
  if(N<sum)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << N-sum << endl;
  }
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
// define
// #define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
// const int INF = 1e18+7;
const int mod = 1e9+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

int A,B,C,X,Y;

signed main()
{
    cin >> A >> B >> C >> X >> Y;

    int ans=inf;

    for(int i=0;i<=100000;i++)
    {
        ans=min(ans,i*2*C+max(0,X-i)*A+max(0,Y-i)*B);
    }

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

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define ceil(a,b) ((a+b-1)/b)
int gcd(int a, int b) // assuming a,b >= 1
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    if (a % b == 0)
        return b;
    return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
    return  a * b / gcd(a, b);
}
using namespace std;
#pragma endregion
signed main() {
    int A;
    cin >> A;
    if (A < 1000)
        cout << "ABC";
    else
        cout << "ABD";
}

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

#define deb(x) cout << #x << "=" << x << endl;
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fo1(i, n) for (ll i = 1; i <= n; i++)
#define sn(x) cin >> x;
#define pn(x) cout << x << "\n"
#define ps(x) cout << x << " ";
#define pb() cout << "\n";
#define sort(x) sort(x.rbegin(), x.rend());
// #define reverse_sort(x) sort(x.rbegin(), x.rend());
// #define reverse(x) reverse(x.rbegin(), x.rend());

typedef long long ll;

using namespace std;


void solve()
{

	ll n;
	cin >> n;

	vector<ll>v(n);

	fo(i,n) sn(v[i]);

	ll sum = 0;

	ll mx = INT_MIN;

	for (ll i = 0; i < n; i++)
	{
		if(v[i]<mx)
			sum+=mx-v[i];
		else 
			mx = v[i];
	}

	cout << sum << endl;
	



}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("err.txt", "w", stderr);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// return 0;

	ll t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
		// cout << ans;
	}
	return 0;
}


Measured memory_bytes: 4752
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
vector<int> G[200005];
int col[200005];
int cnt[2];
int ans[200005];

void dfs(int v,int c){
	col[v]=c;
	for(int i=0;i<G[v].size();i++){
		if(col[G[v][i]]==-1){
			dfs(G[v][i],1-c);
		}
	}
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	memset(col,-1,sizeof(col));
	dfs(0,0);
	for(int i=0;i<n;i++){
		cnt[col[i]]++;
	}
	if(cnt[0]<cnt[1]){
		swap(cnt[0],cnt[1]);
		for(int i=0;i<n;i++){
			col[i]=1-col[i];
		}
	}
	int th=n/3;
	int fi=(n+2)/3;
	int sc=(n+1)/3;
	int ma=cnt[0];
	int mi=cnt[1];
	if(ma>th+fi && mi>th){
		assert(false);
		printf("-1\n");
		return 0;
	}
	int cur=1;
	int cur2=2;
	int cur3=3;
	if(mi<=th){
		for(int i=0;i<n;i++){
			if(col[i]==0){
				if(fi>0){
					fi--;
					ans[i]=cur;
					cur+=3;
				}else if(sc>0){
					sc--;
					ans[i]=cur2;
					cur2+=3;
				}else if(fi==0 && sc==0){
					ans[i]=cur3;
					cur3+=3;
				}
			}else{
				ans[i]=cur3;
				cur3+=3;
			}
		}
	}else{
		for(int i=0;i<n;i++){
			if(col[i]==0){
				if(fi>0){
					fi--;
					ans[i]=cur;
					cur+=3;
				}else{
					ans[i]=cur3;
					cur3+=3;
				}
			}else{
				if(sc>0){
					sc--;
					ans[i]=cur2;
					cur2+=3;
				}else{
					ans[i]=cur3;
					cur3+=3;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		printf("%d%c",ans[i],i+1==n?'\n':' ');
	}
	return 0;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  int t = 1;
  for(int i = 0; i < N;++i){
    if((t * 2) >= ( t + K)){
      t += K;
    }else{
      t *= 2;
    }
  }
  cout << t << endl;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto s = readln.chomp.to!(char[]);
    if (s[0] == s[$-1] && s.length%2 == 0 || s[0] != s[$-1] && s.length%2 == 1) {
        writeln("First");
    } else {
        writeln("Second");
    }
}

Measured memory_bytes: 2584
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();	//枚数
		int Y = sc.nextInt();	//金額
		int M = 0;				//諭吉の枚数
		int G = 0;				//一葉の枚数
		int S = 0;				//英世の枚数
		int chek = 0;			//0の時不可能　-1 -1 -1

		loop: for(int i = 0; i <= N; i++) {
			if(i == 0 && N * 10000 == Y) {	// 10000 * 枚数 = 金額なら即終了
				M = N;
				chek = 1;
				break loop ;
			}
			if(i == 0 && N * 5000 == Y) {	// 5000 * 枚数 = 金額なら即終了
				G = N;
				chek = 1;
				break loop ;
			}
			if(i == 0 && N * 1000 == Y) {	// 1000 * 枚数 = 金額なら即終了
				S = N;
				chek = 1;
				break loop ;
			}
			if(Y >= i * 10000 && Y <= N * 10000) {	//諭吉カウンター
				M = i;
			}
			for(int j = 0; j <= N - M; j++) {		//一葉カウンター
				G = j;
				if(M + G == N && M * 10000 + G * 5000 == Y) {	//諭吉 + 一葉 = 枚数　かつ　諭吉 + 一葉 = 金額なら終了
					chek = 1;
					break loop;
				}
				if((Y - (M * 10000 + G * 5000)) / 1000 == N - M - G) {	//金額 - 諭吉 - 一葉 = 英世の倍数　かつ　英世 = 残り枚数なら終了
					S = (Y - (M * 10000 + G * 5000)) / 1000;
					chek = 1;
					break loop;
				}
			}
		}
		if(chek == 0) {
			M = -1;
			G = -1;
			S = -1;
		}
		System.out.print(M + " " + G + " " + S);
	}
}

Measured memory_bytes: 21844
<?php

$n = trim(fgets(STDIN));

$m = trim(fgets(STDIN));
$arr = explode(" ",$m);

$sum = 1;
$max = 10 ** 18;

foreach($arr as $a) {
    if($a == 0) {
       $sum = 0;
      break;
    } else {
      $sum *= $a; 
    }
 	
}

/*
print $max . "\n";
print $sum . "\n";

print strlen($max) . "\n";
print strlen($sum) . "\n";
*/

if($n > 0) {
  if($sum > $max) {
  		print -1;
  } else {
  		print $sum;
  } 
  
} else {
   print 0;
}




?>

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

int main(){
  int N;
  cin >> N;
  int c[N-1],s[N-1],f[N-1];
  rep(i,N-1){
    cin >> c[i] >> s[i] >> f[i];
  }
  rep(i,N){
    int st=0;
    for(int j=i;j<N-1;j++){
      if(s[j]>=st) st=s[j];
      else{
	if((st-s[j])%f[j]==0){}
	else {
	  st=s[j]+((st-s[j])/f[j]+1)*f[j];
	}
      }
	st+=c[j];
	//	cout << st << " ";     
    }
    cout << st << endl;
  }

  return 0;

}


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

using i64 = int64_t;

i64 dp[3003][3003]={};

int main(){
    int n, t, s;
    cin >> n >> t >> s;
    vector<i64> a, b;
    for(int i=0;i<n;++i){
        i64 x, y;
        cin >> x >> y;
        a.push_back(x);
        b.push_back(y);
    }
    for(int j=0;j<=t;++j){
        for(int k=0;k<=n;++k){
            dp[j][k] = -1;
        }
    }
    dp[0][0] = 0;
    for(int i=0;i<=t;++i){
        for(int j=1;j<=n;++j){
            dp[i][j] = max(dp[i][j], dp[i][j-1]);
            if(i < s && i+b[j-1] > s){
                dp[s][j] = max(dp[s][j], dp[i][j-1]);
            }else if(i+b[j-1] <= t){
                dp[i+b[j-1]][j] = max(dp[i+b[j-1]][j], dp[i][j-1]+a[j-1]);
            }
        }
    }
    i64 ans = 0;
    for(int i=0;i<=t;++i)ans = max(ans, dp[i][n]);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 73656
#define rep(i,n) for (int i=0;i<(n);i++)
#define repr(i,n) for (int i=(n)-1;i>=0;i--)

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>

#define all(a) (a).begin(),(a).end()
#define range(a,i) (a).begin(),(a).begin()+i

#define sint(a) int a; scanf("%d",&a);
#define sint2(a,b) int a,b; scanf("%d %d",&a,&b);
#define sint3(a,b,c) int a,b,c; scanf("%d %d %d",&a,&b,&c);
#define sint4(a,b,c,d) int a,b,c,d; scanf("%d %d %d %d",&a,&b,&c,&d);
#define sint5(a,b,c,d,e) int a,b,c,d,e; scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
#define sll(a) ll a; scanf("%lld",&a);
#define sll2(a,b) ll a,b; scanf("%lld %lld",&a,&b);
#define sll3(a,b,c) ll a,b,c; scanf("%lld %lld %lld",&a,&b,&c);
#define sll4(a,b,c,d) ll a,b,c,d; scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
#define sll5(a,b,c,d,e) ll a,b,c,d,e; scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e);
#define svi(v,n) vector<int> v(n); rep(i,n) scanf("%d", &v[i]);
#define svll(v,n) vector<ll> v(n); rep(i,n) scanf("%lld", &v[i]);
#define sdouble(x) double x; scanf("%lf",&x);
#define svd(v,n) vector<double> v(n); rep(i,n) scanf("%lf", &v[i]);
#define schar(x) char x; scanf(" %c", &x);
#define sstring(x) string x; cin >> x;

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <climits>
#include <set>
#include <map>

using namespace std;




int main(int argc, char** argv) {
	sint(N);
	svi(a, 3 * N);

	vi left(N), right(2 * N);
	copy(range(a, N), left.begin());
	copy(a.begin() + N, a.end(), right.begin());
	sort(all(left));
	sort(all(right));

	ll leftSum = accumulate(all(left), (ll)0);
	ll rightSum = accumulate(range(right, N), (ll)0);
	ll max = leftSum - rightSum;
	int leftOffset = 0;
	int rightOffset = 0;
	rep(i, N) {
		int m = a[N + i];
		if (m > left[leftOffset]) {
			leftSum = leftSum - left[leftOffset] + m;
			left.insert(lower_bound(left.begin() + leftOffset, left.end(), m), m);
			leftOffset++;
		}
		if (m < right[N + rightOffset]) {
			rightSum = rightSum - m + right[N + rightOffset];
			rightOffset++;
		}
		else {
			right.erase(lower_bound(right.begin() + N + rightOffset, right.end(), m));
		}
		ll score = leftSum - rightSum;
		if (max < score) {
			max = score;
		}
	}
	printf("%lld\n", max);
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> A_vec(N), B_vec(N);
    for (int i = 0; i < N; ++i)
        cin >> A_vec.at(i);
    for (int i = 0; i < N; ++i)
        cin >> B_vec.at(i);
    vector<int> cumcnt_A(N + 1, 0), cumcnt_B(N + 1, 0);
    for (int i = 0; i < N; ++i) {
        ++cumcnt_A.at(A_vec.at(i));
        ++cumcnt_B.at(B_vec.at(i));
    }
    for (int i = 1; i <= N; ++i) {
        int cnt = cumcnt_A.at(i) + cumcnt_B.at(i);
        if (cnt > N) {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = 0; i < N; ++i) {
        cumcnt_A.at(i + 1) += cumcnt_A.at(i);
        cumcnt_B.at(i + 1) += cumcnt_B.at(i);
    }
    int max_diff = - N - 1;
    for (int i = 0; i < N; ++i) {
        int diff = cumcnt_A.at(i + 1) - cumcnt_B.at(i);
        if (max_diff < diff)
            max_diff = diff;
    }
    cout << "Yes" << endl;
    cout << B_vec.at((-max_diff + N) % N);
    for (int i = 1; i < N; ++i)
        cout << " " << B_vec.at((i - max_diff + N) % N);
    cout << endl;
}



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

#define MAX_INT (2147483647)

int main(void)
{
	int iWidth, iHeight;	// 横幅と縦幅
	int aiResident[25][25];	// 交差点付近の住人の数
	int iDistCol, iDistRow;	// 縦・横の幹線道路までの距離
	int iAns;				// 近い方の幹線道路への距離の総和
	
	int iCnt1, iCnt2, iCnt3, iCnt4;
	int iTmp, iMin;
	
	// 入力：縦幅、横幅
	scanf("%d%d", &iHeight, &iWidth);
	
	// 入力：交差点付近の住人の数
	for(iCnt1 = 0; iCnt1 < iHeight; iCnt1++)
	{
		for(iCnt2 = 0; iCnt2 < iWidth; iCnt2++)
		{
			scanf("%d", &aiResident[iCnt1][iCnt2]);
		}
	}
	
	// 総当り
	iAns = MAX_INT;
	for(iCnt1 = 0; iCnt1 < iHeight; iCnt1++)
	{
		for(iCnt2 = 0; iCnt2 < iWidth; iCnt2++)
		{
			// iColNum = iCnt1;
			// iRowNum = iCnt2;
			
			iTmp = 0;
			// 幹線道路を引いた場合の距離の総和を計算
			for(iCnt3 = 0; iCnt3 < iHeight; iCnt3++)
			{
				for(iCnt4 = 0; iCnt4 < iWidth; iCnt4++)
				{
					// 縦・横の幹線道路までの距離を求める
					iDistCol = iCnt1 - iCnt3;
					if(iDistCol < 0)
					{
						iDistCol *= -1;
					}
					iDistRow = iCnt2 - iCnt4;
					if(iDistRow < 0)
					{
						iDistRow *= -1;
					}
					
					// 縦横どちらの幹線道路に近いか？
					if(iDistCol < iDistRow)
					{
						iTmp += aiResident[iCnt3][iCnt4] * iDistCol;
					}
					else
					{
						iTmp += aiResident[iCnt3][iCnt4] * iDistRow;
					}
				}
			}
			
			// 最小なら更新
			if(iTmp < iAns)
			{
				iAns = iTmp;
			}
		}
	}
	
	
	// 出力：距離の総和の最小
	printf("%d\n", iAns);
	
	return(0);
}


Measured memory_bytes: 2036
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        String S = sc.next();
        
        if(S.length()<=K){
            System.out.println(S);
        }
        
        else{
            for(int i=0; i<K; i++){
            System.out.print(S.charAt(i));
            }
            System.out.print("...");
        }
    }
}


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

int N;
int h[200009];
int a[200009];

// BIT (1-indexed)
long long bit[200009];

void update(int a, long long k) {
    for(; a <= N; a += a & -a)
        if(bit[a] < k) bit[a] = k;
}

long long query(int a) {
    long long res = 0;
    for(; a > 0; a -= a & -a)
        if(res < bit[a]) res = bit[a];
    return res;
}

int main() {
    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> h[i];
    for(int i = 0; i < N; i++)
        cin >> a[i];

    for(int i = 0; i < N; i++)
        update(h[i], query(h[i]) + a[i]);

    cout << query(N) << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int x;
    cin >> x;
    
    for(int i=x; i<=1000000; i++) {
        bool isPrime = true;
        for(int j=2; j<=sqrt(i); j++) {
            if(i%j==0) {
                isPrime = false;
            }
        }
        if(isPrime) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N,i,j,x=4,y=7,a=0,flag=0;
	scanf("%d",&N);
	for(i = 1; i < 101; i++){ //極限値1から101までをiでfor文で回す
		for(j = 1; j < 101; j++){ //極限値1から101までをjでfor文を回す
			a= (x * i) + (y * j); //aにjから順に回して左記の式に入れていく
			
			if(N % 4 == 0){ //Nが4で割り切れるなら、括弧内の処理を実行
				flag = 1; //flagを1する
			}
			else if(N % 7 == 0){ //Nが7で割り切れるなら、括弧内の処理を実行
				flag = 1; //flagを1する
			}
			else if(N % a == 0){ //Nをaの式で割りきれる場合、括弧内を実行
				flag = 1; //flagを1する
			}
			else{ //それ以外ならflagは0のまま
			}
		}
	}
	flag ? printf("Yes\n") : printf("No\n"); //flagを1か0かでYesかNoを判定する
	return 0;
}


Measured memory_bytes: 128