akhauriyash/Code-Regression huggingface dataset:
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)
#define ull_cin(X) scanf("%llu", &X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)

#define  ll_cout(X) printf("%lld\n",X)
#define  ull_cout(X) printf("%llu\n",X)



typedef long long  ll;
typedef unsigned long long  ull;

#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion


int  main(void) {
	int  i,len;
	char s[101], t[201];


	s_cin(s); len=strlen(s);
	s_cin(t); memcpy(&t[len], t, len);

	for (i = 0; i < len; i++) {
		if (!memcmp(s, &t[i], len)) {
			S_RTN("Yes");
		}
	}
	S_RTN("No");

	return 0;
}
//
//int main(void)
//{
//	ull    a, b, n;
//	ull    y;
//
//	ull_cin(a);	ull_cin(b); ull_cin(n);
//
//	if (n == b||n == a) n--;
//	y = (a * n) / b - a * (n / b);
//
//	ull_cout(y);
//	return 0;
//}

//#define _N 1000000000

//int main(void)
//{
//
//	int  n,i;
//	ull   tmp=1;
//
//	i_cin(n);
//
//	for (i = 1; i <= n; i++) {
//		if (!(tmp % ((ull)_N + 7)))
//			tmp = 1;
//		tmp *= (ull)i;
//	}
//	tmp %= ((ull)_N + 7);
//		
//	ull_cout(tmp);
//	return 0;
//}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int N;
	int ans = 0;
	cin >> N;

	for (int ni = 1; ni <= N; ni++){
		if (ni < 10 
		   || (100 <= ni && ni < 1000) 
		   || (10000 <= ni && ni < 100000) 
		   ){
			   ans++;
		   }
	}


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


	return 0;
}



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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(string s;cin>>s;){
		bool res=false;
		rep(i,10){
			string t(3,'0'+i);
			res|=s.find(t)!=-1;
		}
		cout<<(res?"Yes":"No")<<endl;
	}
}


Measured memory_bytes: 256
h,w = map(int,input().split())
s = []
for i in range(h):
    s.append(input())

ans = [[0 for x in range(w+2)] for y in range(h+2)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ans[i][j] += 1
            ans[i+1][j] += 1
            ans[i+2][j] += 1
            ans[i][j+1] += 1
            ans[i+2][j+1] += 1
            ans[i][j+2] += 1
            ans[i+1][j+2] += 1
            ans[i+2][j+2] += 1

for i in range(h):
    a = ""
    for j in range(w):
        if s[i][j] == "#":
            a+="#"
        else:
            a+=str(ans[i+1][j+1])
    print(a)

Measured memory_bytes: 40304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<ll>a(n);
    ll ans = 0;
    int count = 0;
    rep(i, 0, n){
        cin >> a[i];
        if(a[i] < 0){
            a[i]*=(-1);
            count ++;
        }
        ans += a[i];
    }
    if(count%2 == 0)cout << ans << endl;
    else{
        sort(a.begin(), a.end());
        cout << ans-2*(a[0]) << endl;
    } 
}

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

using namespace std;

int main() {
  string n;
  cin >> n;
  int r = 0;
  for (char d : n) {
    r = (r + d - '0') % 9;
  }
  cout << (r == 0 ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3688
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()

    val ps = Array(N) { readLine()!!.split(" ").map { it.toLong() } }
        .sortedWith(Comparator { a, b ->
            val c = if (a[1] == b[1]) b[0] - a[0] else a[1] - b[1]
            when {
                c < 0 -> -1
                c > 0 -> 1
                else -> 0
            }
        })

    val ll = ArrayList<Long>()
    val lr = ArrayList<Long>()

    func(ll, lr, ps)

    val rl = ArrayList<Long>()
    val rr = ArrayList<Long>()

    func(rl, rr, ps.reversed())

    rl.reverse()
    rr.reverse()

    var res = 0L

    for (i in 1 until N - 1) {
        val v0 = Math.max(lr[i] - ll[i] + 1, 0L)
        val v1 = Math.max(rr[i] - rl[i] + 1, 0L)

        res = Math.max(
            res,
            v0 + v1
        )
    }

    for (i in 0 until N) {
        val t = Math.min(lr[i], rr[i + 1]) - Math.max(ll[i], rl[i + 1]) + 1
        res = Math.max(
            res,
            ps[i][1] - ps[i][0] + 1 + Math.max(t, 0L)
        )
    }

    println(res)
}

private fun func(
    left: ArrayList<Long>,
    right: ArrayList<Long>,
    ps: List<List<Long>>
) {
    left.add(1)
    right.add(1e9.toLong())

    for (l in ps) {
        left.add(Math.max(left.last(), l[0]))
        right.add(Math.min(right.last(), l[1]))
    }
}

private fun slow(N: Int, ps: List<List<Long>>): Long {
    var res = 0L
    for (i in 1 until (1 shl N) - 1) {
        val a = ps.filterIndexed { index, list -> (i shr index) and 1 == 1 }
        val b = ps.filterIndexed { index, list -> (i shr index) and 1 == 0 }

        val v0 = Math.max(a.map { it[1] }.min()!! - a.map { it[0] }.max()!! + 1, 0L)
        val v1 = Math.max(b.map { it[1] }.min()!! - b.map { it[0] }.max()!! + 1, 0L)

        res = Math.max(res, v0 + v1)

        if (v0 + v1 == 540049931L) {
            System.out.printf("%x\n", i)
        }
    }
    return res
}


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

int main() {
    vector<int>v;
    int k,x;
    cin>>k>>x;
    int i,res=k-1;
    i=x;
    while(res--){
            --i;
        v.push_back(i);
    }
    v.push_back(x);
    res=k-1;
    i=x;
    while(res--){
        i++;
        v.push_back(i);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";
	return 0;
}


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

typedef long long ll;
int ans = 0;
int N;

void check(ll x) {
  int a = 0,b = 0,c = 0;
  while(x>0) {
  if ( x%10 == 7) a = 1;
  else if ( x%10 == 5) b = 1;
  else if ( x%10 == 3) c = 1;
  x/=10;
  }
  ans += a*b*c;
}

void dfs(ll x) {
  if(x>N)return;
    check(x);
    dfs(10*x+3);
    dfs(10*x+5);
    dfs(10*x+7);    

}

int main() {
  cin >> N;
  dfs(0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000) 
input=sys.stdin.readline

N,M = map(int,input().split())
ans=[0]*N
a = [list(map(int, input().split())) for _ in range(N-1)]

for _ in range(M):
    e,f = list(map(int, input().split()))
    ans[e-1] += f

trees = {}
for word in a:
    trees.setdefault(word[0], []).append(word[1])
    trees.setdefault(word[1], []).append(word[0])
    

def sumup(ne,parent):
    global ans
    if ne in trees:    
        for k in trees[ne]:
            if k != parent:
                ans[k-1] += ans[ne-1]
                sumup(k,ne)

sumup(1,0)
for i in ans:
    print(i)


Measured memory_bytes: 265312
#include<iostream>
using namespace std ;
int main()
	{
	int n=1 ,m ,tmp ;
	cin>>tmp ;
	if(tmp==1)
		{
		cout<<"Yes"<<endl ;
		return 0 ;
		}
	m=tmp ;
	while(n<m)
		{
		m=tmp/n ;
		if(n*m==tmp&&m<=9)
			{
			cout<<"Yes"<<endl ;
			return 0 ;
			}
		n++ ;
		}
	cout<<"No"<<endl ;
	}

Measured memory_bytes: 256
def solve():
    from sys import stdin
    f_i = stdin
    
    ans = ''
    
    while True:
        n, m = map(int, f_i.readline().split())
        
        if n == 0 and m == 0:
            break
        
        chairs = '#' * n
        
        for i in range(m):
            a = f_i.readline().rstrip()
            if a == 'A':
                chairs = chairs.replace('#', 'A', 1)
            elif a == 'B':
                chairs = chairs[::-1]
                idx = chairs.find('#')
                while idx != -1:
                    if idx > 0:
                        if chairs[idx-1] == 'A':
                            idx = chairs.find('#', idx + 1)
                            continue
                    if idx < n - 1:
                        if chairs[idx+1] == 'A':
                            idx = chairs.find('#', idx + 1)
                            continue
                    chairs = chairs[:idx] + 'B' + chairs[idx+1:]
                    chairs = chairs[::-1]
                    break
                else:
                    chairs = chairs[::-1]
                    chairs = chairs.replace('#', 'B', 1)
            elif a == 'C':
                if chairs.count('#') == n:
                    idx = n // 2
                    chairs = chairs[:idx] + 'C' + chairs[idx+1:]
                else:
                    idx = n
                    for c in 'ABCD':
                        i = chairs.find(c)
                        if i != -1:
                            idx = min(idx, i)
                    if idx == 0:
                        idx = chairs.find('#', idx + 1)
                    else:
                        if chairs[idx+1] == '#':
                            idx += 1
                        else:
                            idx -= 1
                    chairs = chairs[:idx] + 'C' + chairs[idx+1:]
            else:
                if chairs.count('#') == n:
                    chairs = 'D' + chairs[1:]
                else:
                    dist1 = [0] * n
                    d = n
                    for i, c in enumerate(chairs):
                        if c == '#':
                            d += 1
                            dist1[i] = d
                        else:
                            d = 0
                            dist1[i] = d
                    
                    dist2 = [0] * n
                    d = n
                    for i, c in enumerate(chairs[::-1], 1):
                        if c == '#':
                            d += 1
                            dist2[-i] = d
                        else:
                            d = 0
                            dist2[-i] = d
                    
                    dist = []
                    for d1, d2 in zip(dist1, dist2):
                        dist.append(min(d1, d2))
                    
                    idx = dist.index(max(dist))
                    
                    chairs = chairs[:idx] + 'D' + chairs[idx+1:]
        
        ans += chairs
        ans += '\n'
    
    print(ans, end='')

solve()


Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

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

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

int main() 
{
    string s, t;

    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if(s < t) {
        cout << "Yes" << endl; 
    } else {
        cout << "No" << endl; 
    }

    return 0;
}
    



Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/
#include<bits/stdc++.h>
#define mem(a) memset(a,0,sizeof(a))
#define INF 0x3f3f3f3f
#define Min 1e-6
#define lowbit(x) ((x)&(-x))
#define ls rt<<1
#define rs rt<<1|1
#define ll long long

using namespace std;

const int N = 2e5 + 7;
const int M = 1e9 + 7;
const ll Mod = 1e9 + 7;

ll i,j,n,m,t,T,p,l,r,q,len,len1,v,u,k,w,st,res,cnt,ans,tmp,nex,a[N];
double b;
map<ll,ll> mp;

int main()
{
    ios::sync_with_stdio(false);
    mem(a);
    ans = 0;
    cin >> n;
    for(i = 1;i <= n;i++) cin >> a[i];
    for(i = 1;i <= n;i++){
        ans += mp[a[i]];
        mp[a[i]]++;
    }
    for(i = 1;i <= n;i++){
        cout << ans-mp[a[i]]+1 << endl;
    }
    return 0;
}



Measured memory_bytes: 11776
// inputに入力データ全体が入る
function Main(input) {
	var N = Number(input.split('\n')[0].split(' ')[0]);
	var H = Number(input.split('\n')[0].split(' ')[1]);
	var W = Number(input.split('\n')[0].split(' ')[2]);
	var A = input.split('\n');
	A.shift();
	A = A.map(v => Number(v.split(' ')[0]));
	var B = input.split('\n');
	B.shift();
	B = B.map(v => Number(v.split(' ')[1]));
	var count = 0;
	for (var i = 0; i < N; i++) {
		if (H <= A[i]) {
			if (W <= B[i]) {
				count++;
			}
		}
	}
	console.log(count);
}

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

const int maxn = 1e3 + 20;
int vis[maxn],n;
double x[maxn],y[maxn],r[maxn],dist[maxn],mp[maxn][maxn];

void spfa()
{
    queue<int>q;
    for(int i = 1;i <= n;i++) dist[i] = 1e10;
    memset(vis,0,sizeof(vis));
    while(!q.empty()) q.pop();
    dist[1] = 0;
    vis[1] = 1;
    q.push(1);
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        vis[v] = 0;
        for(int i = 1;i <= n;i++)
        {
            if(dist[i] > dist[v] + mp[v][i])
            {
                dist[i] = dist[v] + mp[v][i];
                if(!vis[i])
                {
                    q.push(i);
                    vis[i] = 1;
                }
            }
        }
    }
}

int main()
{
    while(scanf("%lf%lf%lf%lf",&x[1],&y[1],&x[2],&y[2]) != EOF)
    {
        scanf("%d",&n);
        n += 2;
        r[1] = r[2] = 0;
        mp[1][2] = mp[2][1] = sqrt((x[1] - x[2]) * (x[1] - x[2]) + (y[1] - y[2]) * (y[1] - y[2]));
        for(int i = 3;i <= n;i++)
        {
            scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
        }
        for(int i = 1;i <= n;i++)
        {
            for(int j = 1;j <= n;j++)
            {
                mp[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
                mp[i][j] -= r[i] + r[j];
                if(mp[i][j] < 0)
                {
                    mp[i][j] = 0;
                }
            }
        }
        spfa();
        printf("%.10f\n",dist[2]);
    }
    return 0;
}

Measured memory_bytes: 8320
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int main(void)
{
	int N;
	cin >> N;
	vector<int> L(N);
	for(int i = 0; i < N; i++){
		cin >> L[i];
	}
	int max = *max_element(L.begin(), L.end());
	int sum = accumulate(L.begin(), L.end(), 0);
	sum -= max;
	if(sum > max){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;


}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
ans = 0
sum_A = [0]*N
for j in range(N-1, 0, -1):
    sum_A[j] = A[j]+sum_A[(j+1) % N]
for i in range(N-1):
    ans += A[i]*sum_A[i+1]
    ans %= 10**9+7
print(ans)

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

long long gcd(long long a, long long b);
long long abc131c(long long n, long long nc, long long nd);

long long abc131c(long long n, long long nc, long long nd){
    long long n_nc, n_nd, n_gcd, n_ncnd;

// Cで割り切れる数の個数
    n_nc = n / nc;

    // Dで割り切れる数の個数
    n_nd = n / nd;

    // CでもDでも割り切れる数の個数
    n_gcd = nc * nd / gcd(nc, nd);
    n_ncnd = n / n_gcd;

    return n - n_nc - n_nd + n_ncnd;
}

long long gcd(long long a, long long b){
    if(a < b) {
        long long tmp = b;
        b = a;
        a = tmp;
    }

    long long r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(){
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long num1 = abc131c(b, c, d);
    long long num2 = abc131c(a-1, c, d);

    cout << num1 - num2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=505;
int C[MAXN],S[MAXN],F[MAXN];

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n-1;i++)
        {
            scanf("%d%d%d",&C[i],&S[i],&F[i]);
        }
        for(int i=0;i<n;i++)
        {
            int t=0;
            for(int j=i;j<n-1;j++)
            {
                if(t<S[j])       t=S[j];
                else if(t%F[j])  t=t+F[j]-t%F[j];
                t+=C[j];
            }
            printf("%d\n",t);
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
//*
// シンプルな構文解析用
typedef string::const_iterator State;
class ParseError {};
//*/
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int N;
Graph G;

vd dp;


void dfs1(int pos, int par) {
	if (pos != 0 && G[pos].size() == 1) return;
	for (auto edge : G[pos]) {
		if (edge.to == par)continue;
		dfs1(edge.to, pos);
		dp[pos] += dp[edge.to];
	}
	if (pos == 0) {
		dp[pos] /= G[pos].size();
	}
	else {
		dp[pos] /= (G[pos].size() - 1);
	}
	dp[pos] += 1;
}

void dfs2(int pos, int par, double add) {
	if (pos != 0) {
		dp[pos] = (dp[pos] * (G[pos].size() - 1) + add) / G[pos].size();
	}
	for (auto edge : G[pos]) {
		if (edge.to == par)continue;
		if (G[pos].size() == 1) {
			dfs2(edge.to, pos, 1.0);
		}
		else {
			dfs2(edge.to, pos, 1+(G[pos].size()*dp[pos]-(1+dp[edge.to]))/(G[pos].size()-1));
		}
	}
}

int main(void) {
	cin >> N;
	G = Graph(N);
	dp = vd(N, 0);
	rep(i, N - 1) {
		int s, t;
		cin >> s >> t;
		s--; t--;
		G[s].push_back(Edge{ s,t,1 });
		G[t].push_back(Edge{ t,s,1 });
	}
	dfs1(0, -1);
	dfs2(0, -1, 0);

	cout << fixed << setprecision(14);
	rep(i, N) {
		cout << dp[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 20352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007

ll sheet[300][300];
bool er = 0;
void err() {
	cout << -1 << endl;
	er = 1;
}

int main() {
	int N;
	ll ans = 0;
	cin >> N;
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < N;j++) {
			cin >> sheet[i][j];
			ans += sheet[i][j];
		}
	}
	ans /= 2;
	ll x, y, z, a, b;
	map<pair<ll, ll>, ll> A;
	for (int i = 0;i < N;i++) {
		for (int j = i + 1;j < N;j++) {
			for (int k = j + 1;k < N;k++) {
				x = sheet[i][j];
				y = sheet[j][k];
				z = sheet[k][i];
				if (x >= y) {
					if (z >= x) {
						if (z == x + y)
							A.insert({ {i,k},z });
						if (z > x + y)
							err();
					}
					else {
						if (x == y + z)
							A.insert({ {i,j},x });
						if (x > y + z)
							err();
					}
				}
				else {
					if (z >= y) {
						if (z == x + y)
							A.insert({ {i,k},z });
						if (z > x + y)
							err();
					}
					else {
						if (y == x + z)
							A.insert({ {j,k},y });
						if (y > x + z)
							err();
					}
				}

				if (er)return 0;
			}
		}
	}
	for (auto i : A) {
		ans -= i.second;
	}
	cout << ans << endl;
}

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


int main(){
	string s;
	cin >> s;
	int n=s.size();
	int ans =0;
	int f=0;
	for(int i=0;i<n;i++){
		if(s.at(i)=='T'){
			if(f==0){
				ans++;
			}else{
				ans--;
				f--;
			}
		}else{
			f++;
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
m = list(input())
n = list("keyence")

a=0
for i in range(len(n)):
    if m[i]==n[i]:
        a += 1
    else:
        break

for i in range(1,len(n)):
    if m[-i]==n[-i]:
        a += 1
    else:
        break    

if a >= 7:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 21292
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	string d = "FESTIVAL";
	LL k;
	cin >> k;
	string ans;
	LL cur = 1;
	for(int i = 0; i < 7; i++) ans += d[i];
	if(k > 0 && (k & cur) ){
		k -= cur;
		ans += d[7];
	}
	for(int i = 0; i < 7; i++){
		for(int j = 0; j < 9; j++){
			for(int r = 6; r > i; r--){
				ans += d[r];
			}
			for(int z = 0; z < (1<<j); z++){
				ans += d[i];
			}
			cur *= 2;
			if(k > 0 && (k & cur) ){
				k -= cur;
				ans += d[7];
			}
		}
	}
	while(k > 0){
		k -= cur;
		ans += d[7];
	}
	cout << ans << endl;
}


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



long long mod = 1000000007;



bool one[10];
bool two[100];
bool three[1000];
int main(){
	//freopen("i.txt","r",stdin);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	for(int i = 0;i < n;i++){
		int x = (s[i] - '0');
		
		
		for(int j = 0;j < 100;j++){
			if(two[j]){
				three[j*10+x] = true;
			}
		}
		
		for(int j = 0;j < 10;j++){
			if(one[j]){
				two[j*10+x] = true;
			}
		}
		
		one[x] = true;
	} 
	int ans = 0;
	for(int i = 0;i < 1000;i++){
		if(three[i]) ans++;
	}
	cout << ans;
	
}


Measured memory_bytes: 384
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        int C = int.Parse(input[2]);
        int K = int.Parse(Console.ReadLine());

        while (B <= A && K > 0)
        {
            B *= 2;
            K--;
        }
        while (C <= B && K > 0)
        {
            C *= 2;
            K--;
        }
        if (A < B && B < C)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}

Measured memory_bytes: 27508
import java.util.*;

import java.io.*;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static long mod = 1000000007;
	static int inf = (int) 1e15;
	static ArrayList<Integer>[] adL, adH;
	static int n, q;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int ans=0;
        while(n>0) {
        	ans++;
        	n/=k;
        }
        out.print(ans);
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#define int long long
using namespace std;

#define fin(i,n) for (int i = 0; i < n; i++)
#define fin2(i,a,b) for (int i = a; i < b; i++)
#define ford(i,n) for (int i = n-1; i >= 0; i--)
#define ford2(i,a,b) for (int i = a-1; i >= b; i--)
 
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define mod 1000000007
#define PI 3.1415926535897932384626
#define EXP1 2.718281828459045
#define BIG 1000000000000000000

#define sl(n) scanf("%lld", &n)
#define sll(n,m) scanf("%lld %lld", &n, &m)
#define slll(n,m,k) scanf("%lld %lld %lld", &n, &m, &k)
#define sllll(n,m,k,o) scanf("%lld %lld %lld %lld", &n, &m, &k, &o)
#define sd(n) scanf("%lf", &n)
#define sdd(n,m) scanf("%lf %lf", &n, &m)
#define sddd(n,m,k) scanf("%lf %lf %lf", &n, &m, &k)
#define sc(c) scanf(" %c", &c)
#define ss(s) scanf("%s", s)
#define sal(t,n) fin(iz,n) { scanf("%lld", &t[iz]); }
#define sad(t,n) fin(iz,n) { scanf("%lf", &t[iz]); }
#define gl(t) scanf(" %[^\n]", t);

#define pc(n) printf("%c\n", n)
#define ps(s) printf("%s\n", s)
#define pss(s) printf("%s\n", s.c_str())
#define pl(n) printf("%lld\n", n)
#define pll(n,m) printf("%lld %lld\n", n, m)
#define plll(n,m,k) printf("%lld %lld %lld\n", n, m, k)
#define pd(n) printf("%lf\n", n)
#define pdd(n,m) printf("%lf %lf\n", n, m)
#define pal(t,n) fin(rz,n) { printf("%lld ", t[rz]); } printf("\n")
#define pad(t,n) fin(rz,n) { printf("%lf ", t[rz]); } printf("\n")

#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
 
#define OK ps("OK")
#define OK1 ps("OK1")
#define OK2 ps("OK2")

#define ll int
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>

#define dll pair<ll, ll>
#define vdll vector<dll>
#define vvdll vector<vdll>

#define vb vector<bool>
#define vvb vector<vb>
#define vd vector<double>
#define vvd vector<vd>
#define vc vector<char>
#define vvc vector<vc>

#define all(v) v.begin(), v.end()
#define vlen(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second

const int bb = (int)(1e5) + 5;
int dp[bb][2];
int par[bb];
vl adj[bb];
int n;

int dfs(int nod, int mode)
{
    int &rr = dp[nod][mode];
    if (rr != -1) return rr;
    rr = 1;
    for (int vo : adj[nod]) if (vo != par[nod]) {
        par[vo] = nod;
        int sa = dfs(vo, 0);
        if (mode != 1) sa += dfs(vo, 1);
        sa %= mod;
        rr *= sa;
        rr %= mod;
    }
    return rr;
}

signed main()
{
    sl(n);
    fin(i, (n-1)) {
        int x, y;
        sll(x, y);
        adj[x].pb(y);
        adj[y].pb(x);
    }
    fill_n(&dp[0][0], bb*2, -1);
    pl((dfs(1, 0) + dfs(1, 1)) % mod);
}

Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,n;cin >> h >> n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  vector<int> dp(h+1,1e9);
  dp[0]=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<n;j++){
      dp[min(h,i+a[j])]=min(dp[min(h,i+a[j])],dp[i]+b[j]);
    }
  }
  cout << dp[h] << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	Scanner sc;
	
	private void calc() {
		sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		StringBuilder s = new StringBuilder();
		for (int i = 0; i < N; i++) {
			s.append(S.charAt(i));
			s.append(T.charAt(i));
		}
		System.out.println(s);
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
char S[5050];

ll ln[5050];
ll i, j, k, ans;

ll calc(ll b){
    ll i = 1;
    ll j = 0;
    ll ret = 0;
    ll k = 0;
    while(i+b<N){
        //printf("%lld%lld\n", b,i);
        if(i+ln[i-j]<j+ln[j]){
            ln[i] = ln[i - j];
        }else{
            k = j + ln[j] - i > 0 ? j + ln[j] - i : 0;
            while(i+k+b<N&&S[k+b]==S[i+k+b])
                k++;
            ln[i] = k;
            j = i;
        }
        ll a = min(i, ln[i]);
        if(ret<a){
            ret = a;
        }
        i++;
    }
    return ret;
}
int main(){
    scanf("%lld%s", &N, S);
    fornum(i,0,N){
        ll a = calc(i);
        //printf("%lld:%lld\n", i, a);
        if(ans<a)
            ans = a;
        fornum(j,0,N){
            ln[j] = 0;
        }
    }
    printf("%lld", ans);
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007ll
#define INF (1 << 28)    // for x <= 10^9
#define INFL (1ll << 60) // for x <=10^19
#define EPS (1e-10)

using namespace std;

using ll = long long;

struct Cake {
  ll x;
  ll y;
  ll z;
};

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

  vector<Cake> cakes;
  rep(i, N) {
    ll x, y, z;
    cin >> x >> y >> z;
    cakes.push_back({x, y, z});
  }

  int numOfBit = 3;
  int numOfPatterns = 1 << numOfBit;
  ll ans = 0;
  for (int i = 0; i < numOfPatterns; i++) {
    int b1 = ((i >> 0) & 1) ? 1 : -1;
    int b2 = ((i >> 1) & 1) ? 1 : -1;
    int b3 = ((i >> 2) & 1) ? 1 : -1;

    sort(cakes.begin(), cakes.end(), [b1, b2, b3](const Cake x, const Cake y) {
      ll xValue = b1 * x.x + b2 * x.y + b3 * x.z;
      ll yValue = b1 * y.x + b2 * y.y + b3 * y.z;

      return xValue > yValue;
    });

    ll tmp = 0;
    rep(j, M) { tmp += b1 * cakes[j].x + b2 * cakes[j].y + b3 * cakes[j].z; }
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    V vec(s.size());
    rep(i,s.size()){
        vec[i] = s[i] - 'a';
    }
    ll res1 = 1e18;
    rep(i,26){
        ll res = 0;
        ll temp = 0;
        rep(j,vec.size()){
            if(vec[j]==i){
                chmax(res, temp);
                temp = 0;
            }else{
                temp++;
            }
        }
        chmax(res, temp);
        chmin(res1, res);
    }
    cout << res1 << endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


long long a;
/*
vector <long long> divs;
vector <long long> ans;

long long dup(long long x, long long y)
{
	return (x + y - 1) / y;
}
*/
long long mpw(long long x, int k)
{
	long long ans = 1;
	for (int i = 0; i < k; i++)
		ans *= x;
	return ans;
}

int main(int,  char **)
{
#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif


	long long n;
	scanf("%lld%lld", &n, &a);

	long long ans = n;
	long long x = (int) 1e6 + 10;
	for (int cnt = 2; cnt <= 40; cnt++)
	{
		while (mpw(x, cnt) > n)
			x--;
	
		int cntxp = 0;
//		eprintf("%lld ^ %d = %lld\n", x, cnt, mpw(x, cnt) );
		while (mpw(x, cnt - cntxp) * mpw(x + 1, cntxp) < n)
			cntxp++;

//		eprintf("cnt = %d, x = %lld, cntxp = %d\n", cnt, x, cntxp);
		long long cur = (cnt - 1) * a + cnt * x + cntxp;
		ans = min(ans, cur);
	}
	printf("%lld\n", ans);

/*
	for (long long i = 1; i * i <= n; i++)
	{
		divs.push_back(i);
		divs.push_back( (n + i - 1) / i);
	}
	sort(divs.begin(), divs.end() );
	divs.resize(unique(divs.begin(), divs.end() ) - divs.begin() );
	ans.resize((int) divs.size() );

	int bst = 0, pbst = 0;
	for (int i = 0; i < (int) divs.size(); i++)
	{
		long long x = divs[i];
		ans[i] = x;
		for (int j = max(0, pbst - 50); j < min(pbst + 50, i); j++)
		{
			long long cur = ans[j] + a + dup(x, divs[j] );
			if (cur <= ans[i] )
			{
				bst = j;
				ans[i] = cur;
			}
		}
		pbst = bst;
	}
	printf("%lld\n", ans.back() );
*/
	return 0;
}



Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
string S;
int main() {
	cin>>S;

	S[3]='8';
	cout<<S<<endl;
 	return 0;
}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N) { cin >> a[i]; }
	int ans = -1;
	rep(i, 0, N)rep(j, 0, N) {
		if (i == j)continue;
		int tmp = a[i] * a[j];
		string s = to_string(tmp);
		bool flag = true;
		rep(i, 1, s.size()) {
			if (s[i - 1] + 1 != s[i]) {
				flag = false;
				break;
			}
		}
		if (flag)ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3240
import java.util.*;

public class Main {


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

        int n = sc.nextInt();
        int m = sc.nextInt();



         System.out.println((n*(n-1)/2) + (m*(m-1)/2));

        sc.close();
    }


}

Measured memory_bytes: 21716
n,l=map(int,input().split())
A=list(map(int,input().split()))
for i in range(n-1):
    if A[i]+A[i+1]>=l:
        print('Possible')
        t=i+1
        break
else:
    print('Impossible')
    exit()
for i in range(1,t):
    print(i)
for i in range(n-1,t,-1):
    print(i)
print(t)

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

int main(){
  int N, x;
  cin >> N >> x;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  int now=0;
  int k=0;
  while(now<=x && k<=N-1){
    now+=A.at(k);
    k++;
  }
  if(k==N && now==x){
    k++;
  }
  cout << k-1 << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{

	
	public static void main(String[] args){

		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int[] H = new int[N];

		for(int i = 0;i < N;i++){
			H[i] = stdIn.nextInt();
		}

		int ans = 0;
		int temp = 0;

		boolean isChange = true;

		for(int i = 0;i < N - 1;i++){
			if(H[i] >= H[i + 1]){
				temp++;
				if(ans < temp){
					isChange = true;
				}
				
			}
			else{
				if(isChange){
					ans = temp;
				}
				temp = 0;
				isChange = false;
			}
			//System.out.println(temp + " " + ans);
		}
		if(isChange){
			ans = temp;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 50472
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }


int main(){
    string s , t;
    cin >> s >> t;

    sort(s.begin() ,s.end());
    sort(t.begin() ,t.end(),greater<char>());

    if(s == t){
        cout << "No" << endl;
        return 0;
    }

    vector<string> S(2);
    S[0] = s,S[1] = t;
    sort(S.begin(),S.end());

    if(S[0] == s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


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

int main(){
  while(1){
    int word[5]={5,7,5,7,7},n;
  cin>>n;
  if(n==0) break;
  string str[41];
  for(int i=1;i<=n;i++)
    cin>>str[i];
  for(int i=1;i<n;i++){
    int x=0,cnt=str[i].size();
    if(cnt==word[x])x++,cnt=0;
    for(int j=i+1;j<=n;j++){
      cnt+=str[j].size();
      if(cnt==word[x])x++,cnt=0;
      if(x==5) break;
    }
      if(x==5){cout<<i<<endl;break;}
  }
  }
  return 0;
}
    

Measured memory_bytes: 1204
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();

    let s = {
        let mut input = String::new();
        stdin.read_line(&mut input).unwrap();
        input.trim().to_string()
    };

    let a = s[0..2].parse::<i32>().unwrap();
    let b = s[2..4].parse::<i32>().unwrap();

    match ( is_mounth(a), is_mounth(b) ) {
        (true, true) => println!("AMBIGUOUS"),
        (true, false) => println!("MMYY"),
        (false, true) => println!("YYMM"),
        (false, false) => println!("NA"),
    }
}

fn is_mounth( n: i32 ) -> bool {
    n > 0 && n < 13
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

int main() {
    ull A, C;
    string B;

    cin >> A >> B;
    string S = "000";
    S[0] = B[0];
    S[1] = B[2];
    S[2] = B[3];
    C = stoi(S);
    cout << A * C / 100 << endl;
}

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

int main(){

    string S;
    cin >> S;

    vector<int> v;
    for (size_t i = 0; i < S.length(); i++)
    {
        v.emplace_back(S[i]-'0');
    }
    

    for (int bit = 0; bit < (1<<3); bit++)
    {
        vector<int> s = v;
        for(int i=0;i<3;++i){
           if(bit & (1<<i)){
               s[i+1]*=-1;
           }
        }
        int ans=0;
        for(auto temp:s){
            ans+=temp;
        }
        /*
        cout << s[0];
        for(int i=1;i<4;i++){
            cout << (s[i]>=0?"+":"") << s[i];
        }
        cout << endl;
        */
        if(ans==7){
            cout << s[0];
            for(int i=1;i<4;i++){
                cout << (s[i]>=0?"+":"") << s[i];
            }
            cout <<"=7"<<endl;
            return 0;
        }
    }
    

    return 0;
}

Measured memory_bytes: 256
p = 10 ** 9 + 7
n,a,b = map(int,input().split())
k=max(a,b)
def nCr(n, r, mod):
  ret = [1]*(r+1)
  for i in range(1, r+1):
    ret[i] = (ret[i-1] * (n-i+1) * pow(i,mod-2,mod)) % mod
  return ret
nCrl = nCr(n, k, p)
print((pow(2,n,p)-1-nCrl[a]-nCrl[b])%p)

Measured memory_bytes: 10944
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()

list_ = list(map(int, input().split()))

cnt = 0
while True:
    if cnt == 0 and x not in list_:
        print(x)
        break

    if x - cnt not in list_:
        print(x - cnt)
        break

    if x + cnt not in list_:
        print(x + cnt)
        break

    cnt += 1


Measured memory_bytes: 9192
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    ll N, K;
    cin >> N >> K;
    ll pow = 1;
    ll x = 0;
    while (!(pow <= N && N < pow * K)) {
        pow *= K;
        x++;
    }
    cout << x + 1 << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <limits>

int main() {
  std::int_fast64_t n, k;
  std::cin >> n >> k;
  std::vector<std::int_fast64_t> positive;
  std::vector<std::int_fast64_t> negative;
  std::int_fast64_t zero = 0;
  for (std::int_fast64_t i = 0; i < n; ++i) {
    std::int_fast64_t x_i;
    std::cin >> x_i;
    if (x_i > 0) {
      positive.push_back(x_i);
    } else if (x_i < 0) {
      negative.push_back(-x_i);
    } else {
      ++zero;
    }
  }
  k -= zero;
  std::sort(positive.begin(), positive.end());
  std::sort(negative.begin(), negative.end());
  std::int_fast64_t result;
  if (k == 0) {
    result = 0;
  } else {
    result = std::numeric_limits<std::int_fast64_t>::max();
    if (k - 1 < static_cast<std::int_fast64_t>(positive.size())) result = std::min(result, positive[k - 1]);
    if (k - 1 < static_cast<std::int_fast64_t>(negative.size())) result = std::min(result, negative[k - 1]);
    for (std::int_fast64_t i = 1; i < k; ++i) {
      if (i - 1 < static_cast<std::int_fast64_t>(positive.size()) && k - i - 1 < static_cast<std::int_fast64_t>(negative.size())) {
        result = std::min(result, 2 * positive[i - 1] + negative[k - i - 1]);
      }
      if (i - 1 < static_cast<std::int_fast64_t>(negative.size()) && k - i - 1 < static_cast<std::int_fast64_t>(positive.size())) {
        result = std::min(result, 2 * negative[i - 1] + positive[k - i - 1]);
      }
    }
  }
  std::cout << result << std::endl;
  return 0;
}

Measured memory_bytes: 1656
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	
	int N, K;
	cin >> N >> K;
	
	long long int num, pre, ans = N;
	cin >> pre;
	
	vector<long long int> v;
	for(int i = 1; i < N; i++){
		cin >> num;
		v.push_back(num - pre - 1);
		pre = num;
	}
	sort(v.begin(), v.end());
	
	for(int i = 0; i < N - K; i++){
		ans += v[i];
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3900
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long LL;

LL n,ans = 0;
LL a[200005],b[200005];
LL c[200005],d[200005];

int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(LL i = 1;i <= n;i ++){
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b + 1,b + 1 + n);
	for(LL i = 1;i <= n;i ++) a[i] = lower_bound(b + 1,b + 1 + n,a[i]) - b;
	
	for(LL i = 1;i <= n;i ++) if((a[i] & 1) != (i & 1)) ans ++;
	ans >>= 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4352