akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i,0,n)

int dy[]={-1,-1,-1,0,1,1,1,0};
int dx[]={-1,0,1,1,1,0,-1,-1};
int main(){
  int h,w;
  while(cin>>h>>w,h|w){
    vs f(h);
    REP(i,h){
      cin>>f[i];
    }
    string ans;
    map<string,int> cnt;
    REP(i,h){
      REP(j,w){
        REP(d,8){
          int y=i,x=j;
          string tmp;
          do{
            tmp+=f[y][x];
            if(tmp.size()>=2){
              cnt[tmp]++;
              if(cnt[tmp]>=2){
                if(ans.size()<tmp.size()||(ans.size()==tmp.size()&&ans>tmp)){
                  ans=tmp;
                }
              }
            }
            y+=dy[d];
            x+=dx[d];
            if(y<0)y=h-1;
            if(x<0)x=w-1;
            if(y>=h)y=0;
            if(x>=w)x=0;
          }while(y!=i||x!=j);
        }
      }
    }
    if(ans.size()){
      cout<<ans<<endl;
    }else{
      cout<<0<<endl;
    }
  }
}

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

int main() {
	int64_t x,k,d;
	cin >> x >> k >> d;
	if(x < 0){
		x *= -1;
	}
	int64_t a = x / d;
	if(a > k){
		cout << x - (d * k) << endl;
	}
	else{
		if(k % 2 == 0){
		int64_t b,c,e;
		e = x / (2 * d);

		b = x - (e * 2 * d);
		c = b - (2 * d);
		c *= -1;
		if(b < c){
			cout << b << endl;
		}
		else{
			cout << c << endl;
		}
	}
	else{
		int64_t b,c,e;
		e = (x + d) / (2 * d);

		b = x + d - (e * 2 * d);
		c = b - (2 * d);
		c *= -1;
		if(b < c){
			cout << b << endl;
		}
		else{
			cout << c << endl;
		}

	}
	}

}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){
   int n;
   cin >> n;
   string ss;
   cin >> ss;
   vector<char> s;
   int num = ss.size();
   rep(i,num) {
       char test = ss[i];
       s.push_back(test);
   }

   rep(j,n)rep(i,num){
       if(s[i]=='Z'){
           s[i] = 'A';
           continue;
       }
       s[i]++;
   }
   rep(i,num) cout << s[i];

    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ws = set()
ws.add(s)
last = s[-1]
for _ in range(n-1):
    s = input()
    if s in ws or s[0] != last:
        print('No')
        break
    else:
        ws.add(s)
        last = s[-1]
else:
    print('Yes')

Measured memory_bytes: 9108
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)

int main()
{
	int a[4],n;
	cin >> n;
	REP(i, n)
	{
		cin >> a[0] >> a[1] >> a[2];
		sort(a, a + 3);
		if (a[2] >= a[0] + a[1]) cout << "NO" << endl;
		else if (a[2] * a[2] == a[0] * a[0] + a[1] * a[1])cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<iostream>
#include<vector>
#include <fstream>
#include<math.h>
#include <numeric>
#include<algorithm>
#include <stdlib.h>
# include <map>

using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.length() -2 ;i++){
        if(abs(753 - ans)> abs(753-((s[i]-'0')*100 +(s[i+1]-'0')*10 + (s[i+2]-'0')))){
            ans = (s[i]-'0')*100 +(s[i+1]-'0')*10 + (s[i+2]-'0') ;
        }
    }
    cout << abs(753 - ans) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int n,m;
    scanf("%d %d",&n,&m);
    if(n%m==0){
        printf("%d",m/n);
        return 0;
    }
    int s = m/n+1;
    while(1){
        s = s-1;
        if(m%s == 0){
            printf("%d",s);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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


int main()
{

	int n; cin >> n;
	string s; cin >> s;

	if (n % 2 != 0)	{
		cout << "No";
		return 0;
	}


	int i = n/2;
	for (int j = 0; j < (n/2); j++) {
		if (s[j] != s[i]) {
			cout << "No";
			return 0;
		}
		i++;
	}

	cout << "Yes";


	return 0;

}

Measured memory_bytes: 3604
import java.util.*;

class Main {
        public static void main(String args[]) {
                try(Scanner sc = new Scanner(System.in)){
                        int A = sc.nextInt(),
                            B = sc.nextInt(),
                            C = sc.nextInt(),
                            D = sc.nextInt(),
                            E = sc.nextInt();
                        int ans = 0;
                        for(int i = A; i < B; i++){
                                if(i < 0){
                                        ans += C;
                                } else {
                                        ans +=E;
                                }
                        }
                        if(A < 0 && 0 < B){
                                ans += D;
                        }
                        System.out.println(ans);
                }
        }
}

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

int main(){
    int a, b, ans;
    string op;
    
    while(1){
        cin >> a >> op >> b;
        if(op == "+"){
            ans = a + b;
            cout << ans << endl;
        }
        else if(op == "-"){
            ans = a - b;
            cout << ans << endl;
        }
        else if(op == "*"){
            ans = a * b;
            cout << ans << endl;
        }
        else if(op == "/"){
            ans = a / b;
            cout << ans << endl;
        }
        else if(op == "?"){
            break;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k,c,a;
    int e=0;
    cin>>n>>k;
    vector<int> d(n);
    for(int i=0;i<k;i++){
        cin>>a;
       for(int j=0;j<a;j++) {
           cin>>c;
           c-=1;
           d.at(c)=1;
        
       }
    }
    for(int i=0;i<n;i++){
        if(d.at(i)==0){
            e+=1;
        }
    }cout<<e;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
vector < Pii > data;
int N,M;
int memo[1280][1280];
int solve(int dep,int prev1,int prev2){
	if(dep == N+M){
		return 0;
	}
	if(memo[prev1][prev2])return memo[prev1][prev2];
	int ret = 0;
	reps(i,dep,N+M){
		if(prev1 < data[i].fi && prev2 < data[i].se){
			ret = max(ret ,1 + solve(i+1,data[i].fi,data[i].se));
		}
	}
	return memo[prev1][prev2] = ret;
}
int main(){
	while(scanf("%d",&N),N){
		data.clear();
		memset(memo,0,sizeof(memo));
		rep(i,N){
			int a,b;
			scanf("%d%d",&a,&b);
			data.PB(Pii(a,b));
		}
		scanf("%d",&M);
		rep(i,M){
			int a,b;
			scanf("%d%d",&a,&b);
			data.PB(Pii(a,b));
		}
		sort(data.begin(),data.end());
		printf("%d\n",solve(0,0,0));
	}

    return 0;
}

Measured memory_bytes: 7616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class Program
{
    static void Cut(int[] parents, List<int>[] children, int i, int n)
    {
        int j = -1;
        while (n-- > 0)
        {
            j = i;
            i = parents[j];
        }
        while (i >= 0)
        {
            children[i] = new List<int> { j };
            j = i;
            i = parents[j];
        }
    }

    const int INF = int.MaxValue / 2;

    static int[] Depth(List<int>[] children, int i)
    {
        int N = children.Length;
        var d = Enumerable.Repeat(INF, N).ToArray();
        var q = new Queue<int>();
        d[i] = 0;
        q.Enqueue(i);
        while (q.Count > 0)
        {
            int u = q.Dequeue();
            foreach (int v in children[u])
            {
                if (d[u] + 1 < d[v])
                {
                    d[v] = d[u] + 1;
                    q.Enqueue(v);
                }
            }
        }
        return d;
    }

    static int Solve(int[] parents, List<int>[] children, int u, int v)
    {
        int d = Depth(children, v)[u];
        Cut(parents, children, u, (d + 1) / 2);
        return Depth(children, v).Where(n => n < int.MaxValue / 2).Max() - 1;
    }

    static void Main(string[] args)
    {
        var V1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int N = V1[0], u = V1[1] - 1, v = V1[2] - 1;
        var parents = new int[N];
        var children = new List<int>[N];
        var edges = new List<int>[N];
        for (int i = 0; i < N; ++i)
        {
            parents[i] = -1;
            children[i] = new List<int>();
            edges[i] = new List<int>();
        }
        for (int i = 0; i < N - 1; ++i)
        {
            var V2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int a = V2[0] - 1, b = V2[1] - 1;
            edges[a].Add(b);
            edges[b].Add(a);
        }
        var visited = new bool[N];
        var queue = new Queue<int>();
        visited[v] = true;
        queue.Enqueue(v);
        while (queue.Count > 0)
        {
            int a = queue.Dequeue();
            foreach (int b in edges[a])
            {
                if (!visited[b])
                {
                    parents[b] = a;
                    children[a].Add(b);
                    visited[b] = true;
                    queue.Enqueue(b);
                }
            }
        }
        Console.WriteLine(Solve(parents, children, u, v));
    }
}


Measured memory_bytes: 37520
#include <string>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
map<string, vector<pair<string,int> > >m; //no direction graph

char b1[99],b2[99];
void main2(int n){
	m.clear();
	string s1,s2;
	for(;n;n--){
		int d;
		scanf(" 1 %s = 10^%d %s",b1,&d,b2);
		s1=b1,s2=b2;
		m[s1].push_back(make_pair(s2,d));
		m[s2].push_back(make_pair(s1,-d));
	}
	for(;!m.empty();){
		string s=m.begin()->first;
		vector<pair<string,int> >st={{s,0}};
		map<string,int>memo={{s,0}};
		for(;!st.empty();){
			auto p=*st.rbegin();st.pop_back();
			string cur=p.first;int d=p.second;
			memo[cur]=d;
			for(auto &e:m[cur]){
				if(memo.find(e.first)==memo.end()){
					st.emplace_back(e.first,d+e.second);
				}else if(memo[e.first]!=d+e.second){
					puts("No");
					return;
				}
			}
		}
		for(auto &e:memo)m.erase(m.find(e.first));
	}
	puts("Yes");
}
int main(){int n;for(;~scanf("%d",&n)&&n;)main2(n);}

Measured memory_bytes: 2744
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
h,w = gets.chomp.split.map(&:to_i)
h.times do |i|
  strs = gets.chomp.split
  index = strs.index("snuke")
  if !index.nil?
    puts 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[index] + (i+1).to_s
    exit
  end
end

Measured memory_bytes: 2172
N = int(input())
S = 0

for j in range(N + 1):
    count = 0
    if j % 2 == 1:
        for i in range(1, j + 1):
            if j % i == 0:
                count += 1
        if count == 8:
            #print(j)
            S += 1           
print(S)

Measured memory_bytes: 2940
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
    string s;
    cin>>s;

    if(s[1]=='R') cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;

}

Measured memory_bytes: 3004
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}
/**
* @fn
* 指定した値との差の絶対値が最小のvectorの番号を返します。
*/
long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

//ここまでライブラリ
//ここから本文

long long int tpabsmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b) && a.at(i) >= b) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


int main() {
	int n,m,x,y;
	cin >> n >> m;
	cin >> x >> y;
	vector<int> a(n+1);
	vector<int> b(m+1);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	for (int i = 0; i < m; i++) {
		cin >> b.at(i);
	}
	a.at(n) = x;
	b.at(m) = y;
	if (imax(a) < imin(b)) {
		cout << "No War" << endl;
	}
	else {
		cout << "War" << endl;
	}
}


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

signed main() {
int n,k;
cin>>n>>k;
int h[n];
for(int i=0;i<n;i++)cin>>h[i];
int ans=0;
for(int i=0;i<n;i++)if(h[i]>=k)ans++;
cout<<ans;





return 0;
}


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

using namespace std;

#define pb			push_back
#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define hastr(s, c)		((s).find(c) != string::npos)
#define FOR(i,a,b) 		for (int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll n, m;
    cin >> n >> m;
    int a[1000];
    int s = 0;
    int cnt = 0;
    for(int i = 0; i < n; ++i) {
    	cin >> a[i];
    	s += a[i];
    }
    for(int i = 0; i < n; ++i) {
    	if(a[i] >= (s + 4 * m - 1) / (4 * m))
    		cnt++;
    }
    if(cnt >= m)
    	cout << "Yes";
    else
    	cout << "No";
    return 0;
}


Measured memory_bytes: 256
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n

INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                w = cmt + ': ' + str(x)
            else:
                w = str(x)
            print(w)
        return x

def prob():
    d = Debug()
    d.off()
    X, T = getIntList()
    return max(X-T, 0)


ans = prob()
print(ans)

Measured memory_bytes: 3064
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int A_oneCost;
		int B_haveMoney;
		int C_manzokuCount;

		A_oneCost = scan.nextInt();
		B_haveMoney = scan.nextInt();
		C_manzokuCount = scan.nextInt();

		int enableCount = B_haveMoney / A_oneCost;

		if (enableCount > C_manzokuCount) {
			System.out.println(C_manzokuCount);
		} else {
			System.out.println(enableCount);
		}
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
inline int read(){
    int x=0,f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
int n;
string s;
void check(char c1,char c2){
	string t="";
	t+=c1;
	t+=c2;
	for(int i=1;i<s.size()-1;i++){
		if(s[i]=='o'&&t[i]=='S'){
			t+=t[i-1];
		}
		if(s[i]=='o'&&t[i]=='W'){
			if(t[i-1]=='W')t+='S';
			if(t[i-1]=='S')t+='W';
		}
		if(s[i]=='x'&&t[i]=='S'){
			if(t[i-1]=='W')t+='S';
			if(t[i-1]=='S')t+='W';
		}
		if(s[i]=='x'&&t[i]=='W'){
			t+=t[i-1];
		}
	}
	for(int i=0;i<t.size();i++){
		int k=i-1,p=i+1;
		if(k<0)k=n-1;
		if(p==n)p=0;
		if(t[i]=='W'){
			if(s[i]=='o'){
				if(t[k]==t[p])return ;
			}
			if(s[i]=='x'){
				if(t[k]!=t[p])return ;
			}
		}
		if(t[i]=='S'){
			if(s[i]=='o'){
				if(t[k]!=t[p])return ;
			}
			if(s[i]=='x'){
				if(t[k]==t[p])return ;
			}
		}
	}
	cout<<t<<endl;
	exit(0);
}
int main(){
	cin>>n>>s;
	check('S','W');
	check('S','S');
	check('W','S');
	check('W','W');
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char const* argv[])
{
	int n,m;
	int place[1000];

	while( cin >> n >> m && n != 0 ){
		for( int i = 0;i < 1000;i++ ) place[i] = 0;

		for( int i = 0;i < n;i++ ) cin >> place[i];
		sort( place, place + n, greater<int>() );

		for( int i = 1;i * m - 1 < n;i++ ) place[i * m - 1] = 0;
		
		int answer = 0;
		for( int i = 0;i < n;i++ ) answer += place[i];

		cout << answer << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int MAX = 1000000;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  map<int, int> mp;
  for (int i = 0; i < N; i++){
    mp[A[i]]++;
  }
  vector<int> cnt(MAX + 1, 0);
  for (auto P : mp){
    for (int i = P.first; i <= MAX; i += P.first){
      cnt[i] += P.second;
    }
  }
  int ans = 0;
  for (auto P : mp){
    if (cnt[P.first] == 1){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 17196
#include <stdio.h>

int main()
{
  int n, i, x, z;
 
  	if(scanf("%d", &n)== 1);
 
  if (n <= 81)  {
  	for( i=1; i<=9; ++i ){
  		if( n%i ==0 ){
          z = n/i;
          if(z <= 9){
    	 	++x;
            }
          
  		}
  	}
  }

    if(x >= 1){
      printf("Yes");
    }else{
      printf("No");
    }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define All(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(int, x);

  for (int i = 0; i <= x; ++i) {
    int sum = 0;
    for (int j = 0; j <= i; ++j) sum += j;
    if (sum >= x) {
      cout << i << endl;
      return;
    }
  }
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
def modPow(a, n, mod):
  if n == 1:
    return a % mod
  if n%2 == 1:
    return (a * modPow(a, n - 1, mod)) % mod
  t = modPow(a, n / 2, mod)
  return (t * t) % mod

def comb(n, r, mod):
  r = min(r, n-r)
  x = 1
  y = 1
  for i in range(1, r+1):
    x = x * (n+1-i) % mod
    y = y * i % mod
  return x * modPow(y, mod-2, mod) % mod

  
n, a, b = map(int, input().split())
mod = 10**9+7
ans = modPow(2, n, mod)-1
aa = comb(n, a, mod)
bb = comb(n, b, mod)

print((ans-aa-bb)%mod)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
void Solve_Case()
{
    int N,M,X,Y;
    cin >> N  >> M >> X >> Y;
    vector<int> A(N),B(M);
    for(auto & i : A) cin >> i;
    for(auto &i : B) cin >> i;
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    int Z = B[0];
    if(Z > A[N-1] && Z <= Y && Z > X)
        cout << "No War";
    else cout << "War";

}
int main()
{
    int TestCases = 1;
    //cin >>  TestCases;
   while(TestCases--)
   {
       Solve_Case();
   }
}


Measured memory_bytes: 764
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int32_t nextfint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while(c=='.' || '0'<=c && c<='9'){ if(c!='.') x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int main(void){
	long a=nextlong();
	int b=nextfint();
	printf("%ld\n", a*b/100);
}


Measured memory_bytes: 1600
import sys
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    N=ii()
    if N%2:
        print('No')
        exit()
    S=list(input())
    s1=S[:N//2]
    s2=S[N//2:]
    for i in range(N//2):
        if s1[i]!=s2[i]:
            print('No')
            exit()
    print('Yes')


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
int main()
{
    int n,ans=0;
  	string istr;
    cin>>n;
    for(int i=1;i<=n;i++){
      istr=to_string(i);
      if(((istr.length())%2)==1){
            ans++;
        }
    }
    cout << ans;
    return 0;
}

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

int mod = 1000000007;

vector<long long> arr(100005);

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

  vector<int> answer(n);
  for(int i = 0; i < n; ++i) {
      cin >> arr[i];
      answer[arr[i] - 1] = i + 1;
  }
    
  for(int i = 0; i < n; ++i) {
    cout << answer[i] << " ";
  }
}



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

#define ALL(a) a.begin(),a.end()

using namespace std;

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

  for ( int i = 0; i < n; i++ ) {
    vector<int> v;
    int t;
    for ( int j = 0; j < 3; j++ ) {
      cin >> t;
      v.push_back( t );
    }
    sort(ALL(v));

    if ( v[0] * v[0] + v[1] * v[1] == v[2] * v[2] )
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }

  return 0;
}

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

namespace AtCoder0802
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            long K = long.Parse(Console.ReadLine());
            long seven = 7;
            long ans = 1;
            if (K % 2 != 0)
            {
                for (var i = 1; i < 1000000; i++)
                {
                    if (seven % K == 0)
                    {
                        break;
                    }
                    else
                    {
                        seven = seven * 10 + 7;
                        if (seven > K) { seven %= K; }
                        ans++;
                    }
                    //}
                }
            }
            if (ans > K || K %2==0)
            {
                Console.WriteLine("-1");
            }
            else
            {
                var test = seven % K;
                Console.WriteLine(ans);
            }
        }
    }
}


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

int main()
{
	while( 1 ) {
		int W, H;
		cin >> H >> W;
		if( W == 0 && H == 0 ) {
			break;
		}
		for( int i = 0; i < H; i++ ) {
			for( int j = 0; j < W; j++ ) {
				if( i != 0 && i != H - 1 && j != 0 && j != W - 1 ) {
					cout << '.';
				}
				else {
					cout << '#';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}



Measured memory_bytes: 3112
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <time.h>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b){
	if(a<b){
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b){
	if(a>b){
		a = b;
		return true;
	}
	return false;
}

template<typename T>
std::vector<T> vec(int len, T elem) {return std::vector<T>(len, elem);}

template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i] <<std:: endl;
		else std::cout << da[i] << ' ';
	}
}
template<typename T>
void vvdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
}

using namespace std;

int main(){
	int n,k;cin >> n >> k;
	vector<int> da(n);
	rip(i,n,0) cin >> da[i];
	vector<int> dp(n,INT_MAX);
	dp[0] = 0;
	rip(i,n,1){
		rip(j,k+1,1){
			if(i-j<0) break;
			chmin(dp[i], dp[i-j]+abs(da[i]-da[i-j]));
		}
	}
	cout << dp.back() << endl;
}


Measured memory_bytes: 1024
//AtCoder Beginner Contest 066 A
#include <iostream>

using namespace std;

int main() {
	int bell[3];
	
	for (int i = 0; i < 3; i++) {
		cin >> bell[i];
	}

	//////////////////////sort/////////////////////////
	int tmp = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = 2; j > i; j--) {
			if (bell[j - 1] > bell[j]) {
				tmp = bell[j - 1];
				bell[j - 1] = bell[j];
				bell[j] = tmp;
			}
		}
	}

	cout << (bell[0]+bell[1]) << endl;
	
	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,a;
  scanf("%d",&n);
  a = (int)(n/1.08);
  if((int)(a*1.08)==n){printf("%d\n",a);}
  else if((int)((a+1)*1.08)==n){printf("%d\n",a+1);}
  else{printf(":(\n");}
  return 0;
}

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

using namespace std;

int main()
{
   int R;
   cin>>R;
   if(R<1200)
   {
       cout<<"ABC"<<endl;
   }
   else if(R<2800)
   {
       cout<<"ARC"<<endl;
   }
   else
   {
       cout<<"AGC"<<endl;
   }
   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000

//aのb乗
int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
	int catalan(int n){
		return mod(combination(2*n,n)*gyakugen(n+1));
	}
	
};

int main() {
	
	int N,M;
	cin>>N>>M;
	
	combi C(3000000);
	
	int ans = C.junretsu(3*M,N-1);
	
	{
		int temp = 0;
		
		for(int i=2*M+1;i<=3*M;i++){
			temp = mod(temp + C.junretsu(3*M-i,N-2));
		}
		
		temp = mod(temp * N);
		
		ans = mod(ans - temp);
	}
	
	{
		int temp = 0;
		for(int i=M+1;i<=min(3*M,N);i++){
			if((3*M-i)%2==1)continue;
			int t = C.combination(N,i);
			t = mod(t * C.junretsu(N-1,(3*M-i)/2));
			temp = mod(temp + t);
		}
		
		ans = mod(ans - temp);
	}
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 24848
n, k = map(int, input().split())
h_list = []
for i in range(n):
    h_list.append(int(input()))
h_list = sorted(h_list)
diff_h = [h_list[i+k-1] - h_list[i] for i in range(len(h_list) - k + 1)]
print(min(diff_h))

Measured memory_bytes: 10892
import sys
from itertools import combinations

input = sys.stdin.readline
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(int(input())):
    a = input()
    if a[0] in "MARCH":
        d[a[0]] += 1

l = [i for i in d.values() if i != 0]
print(sum(i * j * k for i, j, k in combinations(l, 3)))


Measured memory_bytes: 9048
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e3 + 2;
string a[N];
 
int main() {
	int h, w; cin >> h >> w;
	int sh, sw, eh, ew; 
	cin >> sh >> sw >> eh >> ew;
	--sh; --sw; --eh; --ew;
	for (int i = 0; i < h; ++i) cin >> a[i];
	
	deque<pair<int, int> > q;
	q.push_front({sh, sw});
	vector<vector<int> > dist(h, vector<int> (w, 1e7));
	dist[sh][sw] = 0;
	while (!q.empty()) {
		auto top = q.front(); q.pop_front();
		int x = top.second, y = top.first;
		for (int i = y - 2; i <= y + 2; ++i) {
			for (int j = x - 2; j <= x + 2; ++j) {
				if (i < 0 || i >= h || j < 0 || j >= w) continue;
				if (i == y && j == x) continue;
				if (a[i][j] == '#') continue;
				int w = 1;
				if ((abs(y - i) == 1 && !(x - j))|| abs(x - j) == 1 && !(y - i)) w = 0;
				if (dist[i][j] > dist[y][x] + w) {
					dist[i][j] = w + dist[y][x];
					if (w) q.push_back({i, j});
					else q.push_front({i, j});
				}
			}
		}
	}
	if (dist[eh][ew] == (int)1e7) cout << -1;
	else cout << dist[eh][ew];
}

Measured memory_bytes: 9536
import java.awt.geom.Point2D;
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			Point2D.Double[] p = new Point2D.Double[n];
			for(int i=0;i<n;i++){
				String[] s = sc.next().split(",");
				double u = Double.valueOf(s[0]);
				double v = Double.valueOf(s[1]);
				p[i] = new Point2D.Double(u,v);
			}
			
			int max = 1;
			for(int i=0;i<n;i++){
				for(int j=i+1;j<n;j++){
					if(p[i].distance(p[j])<=2.00001){
						double a, b, c, A, B, C;
						double xa = p[i].x;
						double ya = p[i].y;
						double xb = p[j].x;
						double yb = p[j].y;
						double[] x = new double[2];
						double[] y = new double[2];

						A = xa-xb;
						B = ya-yb;
						C = (A*xa+A*xb+B*ya+B*yb)/2;
						if(A==0){
							c = (C/B-ya)*(C/B-ya)+xa*xa-1;
							x[0] = xa+Math.sqrt(xa*xa-c);
							x[1] = xa-Math.sqrt(xa*xa-c);
							y[0] = C/B;
							y[1] = C/B;
						}else if(B==0){
							c = (C/A-xa)*(C/A-xa)+ya*ya-1;
							y[0] = ya+Math.sqrt(ya*ya-c);
							y[1] = ya-Math.sqrt(ya*ya-c);
							x[0] = C/A;
							x[1] = C/A;
						}else{
							a = 1+(A*A)/(B*B);
							b = (2*A*ya*B-2*A*C-2*xa*B*B)/(B*B);
							c = (C/B-ya)*(C/B-ya)+xa*xa-1;
							x[0] = (-b+Math.sqrt(b*b-4*a*c))/(2*a);
							x[1] = (-b-Math.sqrt(b*b-4*a*c))/(2*a);
							y[0] = (C-A*x[0])/B;
							y[1] = (C-A*x[1])/B;
						}
						
						for(int s=0;s<2;s++){
							int cnt = 0;
							for(int t=0;t<n;t++){
								if(p[t].distance(x[s],y[s])<=1.00001) cnt++;
							}
							max = Math.max(max, cnt);
						}
					}
				}
			}
			System.out.println(max);
		}
	}	
}

Measured memory_bytes: 24268
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;

    vector<ll> a(N);
    ll sum = 0;
    rep(i, N) {
        cin >> a[i];
        sum += a[i];
    }

    ll amin = INF;
    ll tmp = 0;
    rep(i, N - 1) {
        tmp += a[i];
        amin = min(amin, abs((tmp - (sum - tmp))));
    }

    cout << amin << endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
b = [int(i) for i in input().split()]
a = [0]*n
b.reverse()
a[0] = b[0]
for i in range(1,n-1,1):
	if b[i] >= b[i-1]:
		a[i] = b[i-1]
	else:
		a[i] = b[i]
a[n-1] = b[n-2]
print("%d" % sum(a))

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

int main(){
  int n,k,a;
  cin >> n >> k;
  vector<int> vec(n);
  for(int i=0;i<n;i++)
    cin >> vec.at(i);
  a=0;
  
  for(int i=0;i<n;i++){
    a+=2*min(k-vec.at(i),vec.at(i));
  }
  cout << a << endl;
}
  


Measured memory_bytes: 256
N, M, K = map(int, input().split())
dp = [0]*(K+1)
P = 998244353
dp[0] = pow(M-1, N-1, P) * M % P

inv_t = [0]*(2*10**5+1)
inv_t[1] = 1
for i in range(2,2*10**5+1):
  inv_t[i] = inv_t[P % i] * (P - int(P / i)) % P

if M == 1 and K == N-1:
    print(1)
else:
    for i in range(1, K+1):
        temp = dp[i-1]*(N-i)
        temp %= P
        temp *= inv_t[i]
        temp %= P
        temp *= inv_t[M-1]
        temp %= P
        dp[i] = temp

    ans = 0
    for i in range(K+1):
        ans += dp[i]
        ans %= P

    print(ans)


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

int main(){
  long long N;
  cin >>N;
  long long A[N];
  long long sum=0;
  for (long long i=0;i<N;i++){
    cin>>A[i];
    sum=sum+A[i];
  }
  long long temp=0;
  long long tempB;
  for (long long i=0;i<N;i++){
    temp=temp+A[i];
    if(temp>=sum/2){
      tempB=temp-A[i];
      break;
    }
  }
  cout<<min(abs(sum-temp*2),abs(sum-tempB*2))<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
//http://tsutaj.hatenablog.com/entry/2017/03/30/224339
typedef ll SegT;
const SegT defvalue=0;
struct LSTree{
public:
	int n;
	vector<SegT>node,lazy;
	SegT combine(SegT a,SegT b){return a+b;}
	LSTree(const vector<SegT> &v) {
		n=1;
		while(n<v.size())n<<=1;
		node=vector<SegT>(2*n,defvalue);
		lazy=vector<SegT>(2*n,defvalue);
		for(int i=n-1+v.size()-1;i>=0;i--){
			if(n-1<=i)node[i]=v[i-(n-1)];
			else node[i]=combine(node[i*2+1],node[i*2+2]);
		}
	}
	void eval(int k,int l,int r) {
		if(lazy[k]!= 0){
			node[k]+=lazy[k];
			if(r-l>1) {
				lazy[2*k+1]+=lazy[k]/2;
				lazy[2*k+2]+=lazy[k]/2;
			}
			lazy[k]=0;
		}
	}
	void update(int a,int b,SegT x,int k=0,int l=0,int r=-1){
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return;
		if(a<=l&&r<=b){
			lazy[k]+=(r-l)*x;
			eval(k,l,r);
		}else{
			update(a,b,x,2*k+1,l,(l+r)/2);
			update(a,b,x,2*k+2,(l+r)/2,r);
			node[k]=combine(node[2*k+1],node[2*k+2]);
		}
	}
	SegT query(int a,int b,int k=0,int l=0,int r=-1){
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return 0;
		if(a<=l&&r<=b)return node[k];
		else return combine(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
	}
	void tmp(){
		rep(i,node.size())cout<<" "<<node[i];cout<<endl;
		rep(i,node.size())cout<<" "<<lazy[i];cout<<endl;
		cout<<endl;
	}
};
int main() {
	int n,q;
	cin>>n>>q;
    LSTree st(vector<ll>(n,0));
	while(q--){
		int a,s,t,x;
		cin>>a>>s;
		if(!a)cin>>t>>x;
		if(!a)st.update(s-1,t,x);
		else cout<<st.query(s-1,s)<<endl;
	}
}

Measured memory_bytes: 9756
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<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 ans = 0;
		for (int j = i; j < n - 1; j++) {
			if (ans < s[j]) ans = s[j];
			else if (ans % f[j] == 0);
			else ans = ans + f[j] - ans % f[j];
			ans += c[j];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func fnMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var count1, count0 int
	var s string
	fmt.Scan(&s)
	for i := 0; i < len(s); i++ {
		if i%2 == 0 {
			if s[i] == 48 {
				count0++
			} else {
				count1++
			}
		} else {
			if s[i] == 49 {
				count0++
			} else {
				count1++
			}
		}
	}
	fmt.Println(fnMin(count0, count1))
}


Measured memory_bytes: 1280
from collections import deque
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def isprime(n):
  for i in range(2,int(n**0.5)+1):
    if n%i == 0:
      return False
  return True


def solve():
  n = int(input())
  a = (n+1)//2
  print(a/n)
solve()


Measured memory_bytes: 3316
import java.util.Scanner;
import java.util.Vector;

class Main{
  public static void main(String[] av){
    Scanner sc = new Scanner(System.in);

    Vector<Integer> vec = new Vector<Integer>();
    while(sc.hasNextInt()){
      vec.add( sc.nextInt() );
    }
    int M = 1000000;
    boolean [] e = new boolean[M];
    e[0] = e[1] = true;
    for ( int i = 2; i < Math.sqrt(M); i++ ){
      if ( e[i] == false && isPrime(i) ){
        for ( int f = i*2; f < M; f += i ){
          e[f] = true;
        }
      }
    }
      
    for ( Integer x: vec ){
      int cnt = 0;
      for ( int i=2; i <= x; i++ ){
        if ( e[i] == false ){
          cnt++;
        }
      }
      System.out.println( cnt );
    }
  }
  static boolean isPrime( int x ){
    for ( int i = 2; i <= Math.sqrt(x); i++ ){
      if ( x % i == 0 ){
        return false;
      }
    }
    return true;
  }
}

Measured memory_bytes: 22288
#include <stdio.h>
int main() {
	int a, b, c, k;
	int cnt = 0;
	scanf("%d%d%d%d", &a, &b, &c, &k);
	while (b <= a) {
		b *= 2;
		cnt++;
	}
	while (c <= b) {
		c *= 2;
		cnt++;
	}
	if (cnt <= k) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1660
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final int N = Integer.parseInt(sc.next());
        final int M = Integer.parseInt(sc.next());
        int[] ar = new int[M];
        int[] br = new int[M];
        for (int i = 0; i < M; i++) {
            ar[i] = Integer.parseInt(sc.next());
            br[i] = Integer.parseInt(sc.next());
        }
        
        for (int i = 1; i <= N; i++) {
            int cnt = 0;
            for (int j = 0; j < M; j++) {
                if (ar[j] == i || br[j] == i) {
                    cnt++;
                }
            }
            out.println(cnt);
        }
        
        out.flush();
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n;
	cin>>n;
	vector<ll> a(n);
	ll a_sum=0;
	vector<ll> b(n);
	ll b_sum=0;
	REP(i,n)cin>>a[i];
	REP(i,n)a_sum+=a[i];
	REP(i,n)cin>>b[i];
	REP(i,n)b_sum+=b[i];
	ll ans=b_sum-a_sum;
	ll a_cnt=0,b_cnt=0;
	REP(i,n){
		if(a[i]<b[i]){
			a_cnt+=(b[i]-a[i]+1)/2;
			a[i]+=((b[i]-a[i]+1)/2)*2;
		}
		b_cnt+=a[i]-b[i];
	}
	//cout<<a_cnt<<"/"<<b_cnt<<"/"<<ans<<endl;
	if(b_cnt<=ans && a_cnt<=ans){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main()
{
  int n;
  std::cin >> n;

  std::string s;
  std::cin >> s;

  std::vector<int> wn;
  {
  int t = 0;
  for (int i = 0; i < n; ++i)
  {
    if (s[i] == 'W')
    {
      ++t;
    }
    wn.push_back(t);
  }
  }

  std::vector<int> en;
  {
  int t = 0;
  for (int i = 0; i < n; ++i)
  {
    if (s[n - i - 1] == 'E')
    {
      ++t;
    }
    en.push_back(t);
  }
  }
  std::reverse(en.begin(), en.end());

  std::vector<int> sn;
  for (int i = 0; i < n; ++i)
  {
    sn.push_back(en[i] + wn[i]);
  }
  auto m = std::min_element(sn.begin(), sn.end());
  std::cout << (*m - 1) << std::endl;
}



Measured memory_bytes: 7920
import java.util.*;
import java.util.Scanner;

class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        System.out.println(Math.max(0, C - (A - B)));
    }
}

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

typedef long long ll;
typedef long double ld;

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

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    string a, b, c;

    cin >> a >> b >> c;

    cout << a[0] << b[1] << c[2] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  int k,s;
  cin >> k >> s;

  int ans = 0;
  rep(x,k+1)rep(y,k+1){
    int z = s-x-y;
    if(0<=z and z<=k) ans++;
  }
  cout << ans << endl;
}


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

int main(){
	int a[3],b[3];
	for(int i=0;i<3;i++){
		cin>>a[i]; cin>>b[i];
	}

	int flag=0,av[3],bv[3];


	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			if(i==j)continue;
			if(a[i]==a[j]){
				if(av[i]==1||av[j]==1)continue;
				flag++;
				av[i]=1;
				av[j]=1;
			}else if(a[i]==b[j]){
				if(av[i]==1||bv[j]==1)continue;
				flag++;
				av[i]=1;
				bv[j]=1;
			}else if(b[i]==b[j]){
				if(bv[i]==1||bv[j]==1)continue;
				flag++;
				bv[i]=1;
				bv[j]=1;
			}
		}
	}

	if(flag>=2){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		// 数値
		out(3 * r * r);

	}

	/*
	 * 以下メソッド集
	 */
	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}
}


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

int main(){ 
    int H,W;
    cin >> H >> W;
    while(H!=0 || W!=0){
        for(int i=1; i<=H; ++i){
        	for(int j=1; j<=W; ++j){
        		if(i==1 || i==H || j==1 || j==W){
        			cout << "#";
				}else{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
	}
}


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

int main(void){
    int N, M;
    cin >> N >> M;
    int H[N], G[N];
    int sum = 0;
    
    for(int i = 0; i < N; i++){
        int h;
        cin >> h;
        
        H[i] = h;
        G[i] = 1;
    }
    
    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        
        if(H[A-1] > H[B-1] & G[A-1] == 1){
            G[A-1] = 1;
            G[B-1] = 0;
        }
        else if(H[A-1] < H[B-1] & G[B-1] == 1){
            G[A-1] = 0;
            G[B-1] = 1;
        }
        else{
            G[A-1] = 0;
            G[B-1] = 0;
        }
    }
    
    for(int i = 0; i < N; i++){
        if(G[i] == 1) sum++;
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 4404