akhauriyash/Code-Regression huggingface dataset:
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ON			1										// 汎用フラグ - ON
#define D_OFF			0										// 汎用フラグ - OFF
#define D_VAL_MAX		1000005									// 最大値

// 内部変数
static FILE *szpFpI;											// 入力
static char sc1Done[D_VAL_MAX];									// 処理済フラグ

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// データ - 初期化
	memset(sc1Done, D_OFF, sizeof(sc1Done));

	// K - 取得
	int liK;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &liK);

	// 判定
	int liVal = 0;
	for (i = 1; ; i++) {

		// 処理済フラグ
		if (sc1Done[liVal] != D_OFF) {
			return -1;
		}
		sc1Done[liVal] = D_ON;

		// 値加算
		liVal = liVal * 10 + 7;

		// 余り
		int liMod = liVal % liK;
		if (liMod == 0) {
			return i;
		}

		// 値更新
		liVal = liMod;
	}

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	if (liRet == 0) {
		sprintf(lc1Buf, "Yes\n");
	}
	else {
		sprintf(lc1Buf, "No\n");
	}
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 2752
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    int i, j;
    int a, b;
    int s[200005], g[200005];
    int ns, ng;
    ns = ng = 0;
    for (i = 0; i < m; i++)
    {
        scanf("%d %d", &a, &b);
        if (a == 1)
        {
            s[ns] = b;
            ns++;
        }
        else if (b == n)
        {
            g[ng] = a;
            ng++;
        }
    }
    qsort(s, ns, sizeof(int), asc);
    qsort(g, ng, sizeof(int), asc);
    i = j = 0;
    while (s[i] != g[j] && i < ns && j < ng)
    {
        if (s[i] < g[j])i++;
        else j++;
    }
    if (s[i] == g[j])
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 1404
//Love and Freedom.
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#define inf 20021225
#define ll long long
#define N 100010
using namespace std;
int read()
{
	int f=1,s=0; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9')	s=s*10+ch-'0',ch=getchar();
	return f*s;
}
struct edge{int to,lt;}e[N<<1];
int in[N],cnt,leaf[N],del[N],d[N];
void add(int x,int y)
{
	e[++cnt].to=y; e[cnt].lt=in[x]; in[x]=cnt; d[x]++; if(d[x]>1)	leaf[x]=0;
	e[++cnt].to=x; e[cnt].lt=in[y]; in[y]=cnt; d[y]++; if(d[y]>1)	leaf[y]=0;
}
int win;
void dfs(int x,int fr)
{
	if(win)	return; int lf=0,all=0,de=0;
	for(int i=in[x];i;i=e[i].lt)
	{
		int y=e[i].to; if(y==fr)	continue;
		dfs(y,x); all++; lf+=leaf[y]; de+=del[y];
		if(win)	return;
	}
	if(lf>=2)	win=1;
	if(lf==1)	del[x]=1;
	else	leaf[x]=1;
}
int rt;
int main()
{
	int n=read();
	for(int i=1;i<n;i++)	add(read(),read());
	if(n==2)	return puts("Second"),0;
	for(int i=1;i<=n;i++)	rt=d[i]>=2?i:rt;
	dfs(rt,0); puts(win?"First":"Second");
	return 0;
}

Measured memory_bytes: 3328
/*input
14
99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int arr[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	REP(i,n){
		cin>>arr[i];
	}
	sort(arr,arr+n);
	cout<<arr[n/2]-arr[n/2-1];
}

Measured memory_bytes: 640
n = int(input())
ls = list(map(int,input().split()))
di = [100]*(n+1)
di[0] = 0
for i in range(n):
    N = n - i
    num = int(n/N)
    fi = []
    for j in range(num):
        fi.append(N*(j+1))
    p = 0
    for k in fi:
        p += di[k]
    if (p - 100)%2 == ls[fi[0]-1]:
        di[fi[0]] = 0
    else:
        di[fi[0]] = 1
print(sum(di))
for e in range(1,len(di)):
    if di[e] == 1:
        print(e,end=" ")

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

int main() {
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if (S == U) {
        cout << A - 1 << " " << B << endl;
    } else {
        cout << A << " " << B - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(a+b==c||b+c==a||c+a==b){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc138/tasks/abc138_d
//
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::fmt::*;
use std::io::*;
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn dfs(now: usize, par: usize, g: &Vec<Vec<usize>>, w: &Vec<i64>, score: &mut Vec<i64>, mut add: i64) {
    add += w[now];
    score[now] += add;
    for &to in &g[now] {
        if to == par {
            continue;
        }
        dfs(to, now, g, w, score, add);
    }
}

fn main() {
    input! {
        n: usize, q: usize,
        edges: [(usize1, usize1); n-1],
        queries: [(usize1, i64); q]
    };

    let mut g = vec![vec![]; n];
    for (u, v) in edges {
        g[u].push(v);
        g[v].push(u);
    }

    let mut weight = vec![0; n];
    for (i, v) in queries {
        weight[i] += v;
    }

    let mut score = vec![0; n];
    dfs(0, n, &g, &weight, &mut score, 0);

    println!("{}", score.into_iter().map(|s| s.to_string()).collect::<Vec<_>>().join(" "));
}


Measured memory_bytes: 54776
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n ; cin >> n;
    vector<ll> e(3),o(3);
    cin >> e[0] >> e[1] >> e[2];
    for(int i=1;i<=n-1;i++){
        ll a,b,c; cin >> a >> b >> c;
        if(i%2){
            o[0] = max(e[1],e[2])+a;
            o[1] = max(e[0],e[2])+b;
            o[2] = max(e[0],e[1])+c;
        }else{
            e[0] = max(o[1],o[2])+a;
            e[1] = max(o[0],o[2])+b;
            e[2] = max(o[0],o[1])+c;
        }
    }
    cout << max(max(max(e[0],e[1]),e[2]),max(o[0],max(o[1],o[2]))) << endl;

}

Measured memory_bytes: 256
n = int(input())
c,s,f = [0]*n , [0]*n , [0]*n
for i in range(n-1):
    c[i] ,s[i] ,f[i] = map(int, input().split())
    
for i in range(n):
    ans = 0
    for j in range(i , n-1):
        if ans < s[j]:
            ans = s[j] + c[j]
            continue
        
        elif ans % f[j] == 0:
            ans += c[j]
        
        else:
            ans = (ans // f[j] + 1 ) * f[j] + c[j]
    print(ans)

Measured memory_bytes: 42092
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int X[]=new int[6];
    	int ans=0;
    	for(int i=1;i<=5;i++){
    		X[i]=sc.nextInt();
    	}
    	for(int j=1;j<=5;j++){
    		if (X[j]==0) {
    			ans=j;
    		}
    	}
		System.out.println(ans);
		//System.out.print(ans);
		

    }
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

const int maxn = 2e5 + 5;
int dp[maxn][2];
string T;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> T;
    int n = T.length();
    for(int i = 0;i < n;i++){
        if(T[i] == '?'){
            T[i] = 'D';
        }
    }
    cout << T << endl;
    //memset(dp, -1, sizeof(dp));
    //dp[0][0] = 0;
    //for(int i = 0;i < n;i++){
    //    for(int j = 0;j < 2;j++){
    //        if(dp[i][j] == -1)
    //            continue;
    //        if(T[i] == 'P' or T[i] == '?'){
    //            dp[i + 1][1] = max(dp[i + 1][1], dp[i][j]);
    //        }
    //        if(T[i] == 'D' or T[i] == '?'){
    //            if(j == 0){
    //                dp[i + 1][0] = max(dp[i + 1][0], dp[i][j] + 1);
    //            }else{
    //                dp[i + 1][0] = max(dp[i + 1][0], dp[i][j] + 2);
    //            }
    //        }
    //    }
    //}
    //cout << max(dp[n][0], dp[n][1]) << endl;
    return 0;
}


Measured memory_bytes: 3740
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int X=sc.nextInt();
		int costmin=Integer.MAX_VALUE;
		for(int i=0; i<=100; i++) {
			for(int j=0; j<=100; j++) {
				if(1000*i+500*j>=X) {
					costmin=Math.min(costmin, A*i+B*j);
				}
			}
		}
		pl(costmin);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}


Measured memory_bytes: 24508
from collections import deque
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
DP = [[10000]*w for _ in range(h)]
DP[0][0] = 0 if S[0][0]=='.' else 1

directs = [[0,1], [1,0]]
for hi in range(h):
    for wi in range(w):
        for dh,dw in directs:
            if not (0<=hi+dh<h and 0<=wi+dw<w): continue
            if S[hi][wi]=='.' and S[hi+dh][wi+dw]=='#':
                DP[hi+dh][wi+dw] = min(DP[hi+dh][wi+dw], DP[hi][wi]+1)
            else:
                DP[hi+dh][wi+dw] = min(DP[hi+dh][wi+dw], DP[hi][wi])
print(DP[-1][-1])

Measured memory_bytes: 9520
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>

using namespace std;

vector < vector < int > > graph;
int n, m, q, state[100050], color[100050], vis[100050];

int id = 1;

struct query
{
    int v, d, c;
}A[100050];

//void dfs(int node, int c, int dep)
//{
//    if(!color[node])
//        color[node] = c;
//    vis[node] = id;
//
//    if(dep == 0)    return;
//
//    for(int i = 0;i < graph[node].size();++i)
//    {
//        int to = graph[node][i];
//        if(vis[to] != id)
//        {
//            dfs(to, c, dep - 1);
//        }
//    }
//}

void bfs(int node, int c, int dep)
{
    queue < pair < int, int > > q;
    q.push({node, dep});
    vis[node] = id;
    while(!q.empty())
    {
        int v = q.front().first;
        int depth = q.front().second;
        q.pop();

        if(!color[v])       color[v] = c;
        if(depth == 0)      continue;

        if(state[v] >= depth)     continue;

        state[v] = depth;

        for(int i = 0;i < graph[v].size();++i)
        {
            int to = graph[v][i];
            if(vis[to] != id)
            {
                vis[v] = id;
                q.push(make_pair(to, depth - 1));
            }
        }
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    graph.resize(n + 5);
    for(int i = 0;i < m;++i)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        --a;--b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    scanf("%d", &q);
    for(int i = 0;i < q;++i)
    {
        scanf("%d%d%d", &A[i].v, &A[i].d, &A[i].c);
        --A[i].v;
    }
    memset(state, 0xff, sizeof(state));
    for(int i = q - 1;i > -1;--i)
    {
        ++id;
//        if(state[A[i].v] >= A[i].d)     continue;

//        state[A[i].v] = A[i].d;
        bfs(A[i].v, A[i].c, A[i].d);
    }

    for(int i = 0;i < n;++i)
    {
        printf("%d\n", color[i]);
    }
    return 0;
}


Measured memory_bytes: 8984
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};


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

    int H, W; cin >> H >> W;
    char A[1010][1010];
    int d[1010][1010] = {1000000};
    int grid = 0;
    queue<P> que;
    rep(i, H) {
        rep(j, W) {
            cin >> A[i][j];
            if (A[i][j] == '#') {
                d[i][j] = 0;
                grid ++;
                que.push(P(i, j));
            }
        }
    }

    while(que.size()) {
        P p = que.front(); que.pop();
        rep(i, 4) {
            int nx = p.first + dx[i], ny = p.second + dy[i];

            if(0 <= nx && nx < H && 0 <= ny && ny < W && A[nx][ny] == '.' ) {
                que.push(P(nx, ny)) ;
                d[nx][ny] = d[p.first][p.second] + 1;
                A[nx][ny] = '#';
                grid ++;
            }
        }

        if (grid == H * W) break;
    }

      int ans = 0;
      rep(i, H) {
          rep(j, W) {
              ans = max(ans, d[i][j]);
          }
      }

      cout << ans << endl;


 

    return 0;
}

Measured memory_bytes: 13456
#include<iostream>
using namespace std;
int main(){
	int a[10];
	int n,l;
	
	while(cin>>n,n!=0){
		for(int i=0;i<10;i++)a[i]=0;
		for(int i=0;i<n;i++){
			cin>>l;
			a[l]++;
		}
		for(int i=0;i<10;i++){
			if(a[i]==0)cout<<"-";
			else for(int j=0;j<a[i];j++){
				cout<<"*";
			}
			cout<<endl;
		}
	}


}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 int main() {
	int x,a,b;
   cin>>x>>a>>b;
   if(abs(x-a)>abs(x-b)){cout<<"B";}
   else{cout<<"A";}
   }
	

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

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, int num=0){
  if(num == 0) num = (int)v.size();
  if(is_reverse) for(int i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
  else for(int i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  cout << endl;
  for(int i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
}


template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

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

	vector<ll> C(N-1), S(N-1), F(N-1);
	for(int i=0; i<N-1; i++) cin >> C[i] >> S[i] >> F[i];
	S.push_back(0);

	for(int i=0; i<N; i++){
		ll time = 0;
		for(int now=i; now<N-1; now++){
			ll num = max(time-S[now], (ll)0);
			ll start_time = S[now] + (num + F[now] - 1)/F[now]*F[now];
			// cout << "  i: " << i << " now: " << now << "  time: " << time << "  F[now]: " << F[now] << " time/S[now]*F[now]: " << time/S[now]*F[now] << "  S[now]: " << S[now] <<  "   start_time : " <<  start_time << "    C[now]: " << C[now] <<endl;
			time = start_time + C[now];
			
		}
		cout << time << endl;
		// cout << "  ------------------" << endl;
	}
	

	return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
const int MOD = 1000000007;

long long mod(long long a) {
	a %= MOD;
	return a >= 0 ? a : a+MOD;
}

int main() {
	long long h, w, k;
	cin >> h >> w >> k;
	vector<bitset<8>> L;
	for (int bits = 0; bits < (1<<(w-1)); bits++) {
		bitset<8> t(bits);
		bool ok = true;
		for (int i = 0; i < w-2; i++) {
			if (t[i] == 1 && t[i+1] == 1) ok = false;
		}
		if (ok) L.push_back(t);
	}
	vector<long long> dp(w, 0);
	dp[0] = 1;
	for (int i = 0; i < h; i++) {
		vector<long long> next_dp(w, 0);
		for (auto t : L) {
			for (int j = 0; j < w; j++) {
				if (t[j]) next_dp[j+1] = mod(next_dp[j+1] + dp[j]);
				else if (j > 0 && t[j-1]) next_dp[j-1] = mod(next_dp[j-1] + dp[j]);
				else next_dp[j] = mod(next_dp[j] + dp[j]);
			}
		}
		dp = move(next_dp);
	}
	long long ans = dp[k-1];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long t = 0;
		long ans = 0;
		if (k % 2 == 0) {
			t = n / k;
			ans += (t * t * t);
			t = ((n*2) / k +1)/2;
			ans += (t * t * t);
		} else {
			t = n / k;
			ans += (t * t * t);
		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll a,b,c,d,x;
  cin >> a >> b >> c >> d >> x;
  c=min(c,a*4);
  c=min(c,b*2);
  ll ans=0;
  if(x%2) {
    ans+=c;
    x--;
  }
  pr(ans+min(x*c,x/2*d));
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int n;
	std::cin >> n;
	string str;
	std::cin >> str;
	std::vector<int> east(n,-1);
	std::vector<int> west(n,-1);
	if (str[0] == 'E') {
		east[0] = 1;
		west[0] = 0;
	}
	else {
		east[0] = 0;
		west[0] = 1;
	}
	for (size_t i = 1; i < str.size(); i++) {
		if (str[i] == 'E') {
			east[i] = east[i-1] + 1;
			west[i] = west[i-1];
		}
		else {
			east[i] = east[i-1];
			west[i] = west[i-1] + 1;
		}
	}

	int ans = n;
	for (size_t i = 0; i < n; i++) {
		if (i == 0) {
			ans = min(ans, east[n-1] - east[0]);
		}
		else if (i == n-1) {
			ans = min(ans, west[n-2]);
		}
		else {
			ans = min(ans, west[i-1] + east[n-1] - east[i]);
		}
	}

	std::cout << ans << '\n';
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n;cin>>n;
  ll a[n];rep(i,0,n)cin>>a[i];

  ll ma=*max_element(a,a+n);
  sort(a,a+n);
  ll mi=INF;
  ll sb=0;
  rep(i,0,n){
    if(a[i]==ma)continue;
    if(abs(ma/2-a[i])<=mi){mi=ma/2-a[i],sb=a[i];}
  }

  out(ma<<" "<<sb);

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> wit[n];
    rep(i,n){
        int a;
        cin >> a;
        rep(j,a){
            int x,y;
            cin >> x >> y;
            wit[i].push_back(make_pair(x,y));
        }
    }
    int ans = 0;
    int fact[n];
    for(int i = 0;i<pow(2,n);i++){
        int tmp = i;
        bool flag = true;
        rep(j,n){
            fact[j]=tmp%2;
            tmp/=2;
        }
        rep(j,n){
            if(fact[j]==1){
                rep(k,wit[j].size()){
                    int a = wit[j][k].first;
                    int b = wit[j][k].second;
                    if(fact[a-1]!=b) flag = false;
                }               
            }
        }
        if(flag){
            int p = 0;
            rep(i,n) p+=fact[i];
            ans = max(ans,p);
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

vvl dp;
vvl graph;
vb visited;
ll mod = 1000000007;


void compute(ll node){
  visited[node] = true;

  for(ll next : graph[node]){
    if(visited[next]) continue;
    compute(next);
    dp[node][0] = (dp[node][0]*dp[next][1])%mod;
    dp[node][1] = (dp[node][1]*((dp[next][0]+dp[next][1])%mod))%mod;
  }

}

int main(){
  ios_base::sync_with_stdio (false);
  cin.tie(NULL);

  ll N;

  cin >> N;

  dp = vvl(N, vl(2, 1));
  graph = vvl(N, vl());
  visited = vb(N, false);

  FOR(i, 0, N-1){
    ll x, y;

    cin >> x >> y;
    graph[x-1].pb(y-1);
    graph[y-1].pb(x-1);
  }

  compute(0);

  cout << (dp[0][0]+dp[0][1])%mod << endl;

}


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

using namespace std;

int main(){

  string s;
  cin>>s;
  long long int ans=0;

  for(int i=0; i<s.size(); i++){
    if(i<int(s.size()/2) and s[i]=='g') ans+=1;
    else if(i>=int(s.size()/2) and s[i]=='p') ans-=1;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 3744
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <array>
#include <bitset>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator >> (istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif
int N;
LL A[200000];
int main() {
	cin >> N;
	LL sum = 0;
	REP(i, 0, N) {
		LL a;
		cin >> a;
		A[i] = sum + a;
		sum += a;
	}

	LL m = INFLL;
	REP(i, 0, N - 1) {
		m = min(m, abs(sum - 2 * A[i]));
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int linearSearch(int *,int );
int n,q;

int main(){
int s[10000],t[50000];
int i,j,key;
int count=0;
  
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  
  scanf("%d",&q);
  
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }

for(i=0;i<q;i++){
key = linearSearch(s,t[i]);

if(key == 1){
count++;
}

}
  
  printf("%d\n",count);
  return 0;
}


int linearSearch(int *S,int T){
int i=0;

S[n] = T;
while(S[i] != T){
i++;
}

      if(i == n) return -1;
      else return 1;
}

Measured memory_bytes: 640
import sys,os,math
from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import Queue


# sys.stdin = open('input')
# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())


def main():
    n, k = map(int, raw_input().split())
    ans = []
    if k > (n-1)*(n-2)/2:
        print -1
        return
    for i in range(1, n):
        ans.append((n, i))
    k -= (n-1)*(n-2)/2
    for i in range(1, n):
        for j in range(i+1, n):
            if k>=0:
                continue
            k += 1
            ans.append((i, j))
    print len(ans)
    print '\n'.join(map(lambda a:"%s %s"% (a[0],a[-1]), ans))
        


main()


Measured memory_bytes: 32792
/// b.cpp
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < decltype(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < pll >
# define pb push_back
# define pdd pair < db , db >
# define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    fi>>n;
    static int s[1 << 20];
    static int was[1 << 20];
    for (int i = 1;i <= n + 1;++i)
        fi>>s[i],++was[s[i]];
    int cnt = max_element(was + 1,was + 1 + n) - was;
    int a = -1,b = -1;
    for (int i = 1;i <= n + 1;++i)
    {
        if (cnt == s[i])
        {
            if (a == -1)
                a = i;
            else
                b = i;
        }
    }
    static int f[1 << 20];
    static int c[1 << 20];
    const int mod = 1e9 + 7;
    auto pow = [&](int a,int b,int mod)
    {
        int ans = 1;
        while (b)
        {
            if (b & 1)
                ans = (1ll * ans * a) % mod;
            a = (1ll * a * a) % mod;
            b /= 2;
        }
        return ans;
    };
    f[0] = c[0] = 1;
    for (int i = 1;i <= 1e6;++i)
    {
        f[i] = (1ll * f[i - 1] * i) % mod;
        c[i] = pow(f[i],mod - 2,mod);
    }
    auto C = [&](int n,int k)
    {
        if (!(0 <= k && k <= n))
            return 0;
        int ans = f[n];
        ans = (1ll * ans * c[k]) % mod;
        ans = (1ll * ans * c[n - k]) % mod;
        return ans;
    };
    for (int i = 1;i <= n + 1;++i)
    {
        int ans = 0;
        (ans += C(n + 1,i)) %= mod;
        (ans += mod - C(n + a - b,i - 1)) %= mod;
        fo << ans << '\n';
    }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


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

// 3
// 1 2 3
int main() {
  int N;
  cin >> N;

  // 奇数 + 奇数 => 偶数
  // 偶数 + 偶数 => 偶数
  int odd_count = 0;
  for (int i = 0; i < N; i++) {
    int n;
    cin >> n;
    if (n % 2 == 1) {
      odd_count++;
    }
  }

  // 「奇数」が偶数個あれば、消し込むことが可能
  // 「奇数」が奇数個あれば、1つ消し込めない
  if (odd_count % 2 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int A, B; cin >> A >> B;
    if (A <= 5){
        cout << 0 << endl;
    }else if (6 <= A && A <= 12){
        cout << (int)(B/2) << endl;
    }else{
        cout << B << endl;
    }

}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

typedef pair<int,int> p;

vector<p> dic;

int main(){ _;
  int N;
  int t,b,l,r,n,d;
  while(cin>>N,N!=0){
    t=b=l=r=0;
    dic=vector<p>(N);
    dic[0]=make_pair(0,0);
    for(int i=1;i<N;i++){
      cin>>n>>d;
      dic[i]=make_pair(d==0?dic[n].first-1:d==2?dic[n].first+1:dic[n].first,
		       d==1?dic[n].second+1:d==3?dic[n].second-1:dic[n].second);
      r=max(r,dic[i].first);
      l=min(l,dic[i].first);
      b=max(b,dic[i].second);
      t=min(t,dic[i].second);
    }
    cout<<(r-l+1)<<" "<<(b-t+1)<<endl;
  }
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

void solve(){
  int n; cin >> n;
  vector<ll> h(n);
  RPT(i,0,n) cin >> h[i];
  vector<int> ds(n,0); int tmp = 0, d=0;
  for(;d<n-1;){
    int cnt=0;
    while(d<n-1){
      ++d;
      if(h[d-1]<h[d]) break;
      cnt++;
    }
    ds[tmp] = cnt;
    tmp++;
    cnt = 0;
  }
  cout << *max_element(ALL(ds)) << endl;
}

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

Measured memory_bytes: 1408
import java.util.*
import kotlin.*


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val k = sc.nextInt()
        val q = sc.nextInt()
        val a = sc.intArray()
        var ans = Int.MAX_VALUE

        for (i in 0 until n) {
            val pq = PriorityQueue<Int>(16)
            var tmp = PriorityQueue<Int>(16)
            var f = false
            for (j in 0 until n) {
                if (a[i] <= a[j]) {
                    if (!f) {
                        f = true
                        tmp = PriorityQueue<Int>(16)
                    }
                    tmp.add(a[j])
                } else {
                    if (f) {
                        while (tmp.size >= k) {
                            pq.add(tmp.poll())
                        }
                        f = false
                    }
                }
            }
            if(f){
                while (tmp.size >= k) {
                    pq.add(tmp.poll())
                }
            }
            if (pq.size >= q) {
                val min = pq.peek()
                for (j in 0 until q - 1) pq.poll()
                val max = pq.peek()
                ans = Math.min(ans, max - min)
            }
        }
        println(ans)
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 82260
#include <stdio.h>

int main (void)
{
  int N=0;
  
  scanf("%d",&N);
 
  if(N%2==0)
  {
    printf("%d",N/2);
  }
  
   if(N%2==1)
  {
     N=N/2+1;
    printf("%d",N);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

const int MAX = 100005;

int min(int x, int y)
{
  return x < y ? x : y;
}

int main()
{
  int na, nb, m, mina = MAX, minb = MAX, minab;
  int a[MAX];
  int b[MAX];
  
  cin >> na >> nb >> m;
  
  for (int i = 1; i <= na; i++) {
    cin >> a[i];
    mina = min(mina, a[i]);
  }
    
  
  for (int i = 1; i <= nb; i++) {
    cin >> b[i];
    minb = min(minb, b[i]);
  }
  
  minab = mina + minb;
  
  int x, y, c;
  while (m--) {
    cin >> x >> y >> c;
    minab = min(minab, a[x] + b[y] - c);
  }
  
  printf("%d", minab);
  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    cout << ((s=="ABC") ? "ARC" : "ABC") << endl;
    return 0;
}


Measured memory_bytes: 3612
N = int(input())
H = list(map(int, input().split()))
ans = 0
curr = 0
for i in range(N-1):
  if H[i] >= H[i+1]:
    curr += 1
  else:
    ans = max(ans, curr)
    curr = 0
else:
  ans = max(ans, curr)
  
print(ans)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(a) (lld)((a).size())
#define all(c) (c).begin(),(c).end()             
typedef long double ldb;
typedef long long lld;
const lld MOD = 1e9+7;
const lld INF = 1011111111;
const lld LLINF = 1000111000111000111LL;
const ldb EPS = 1e-10;
const ldb PI = 3.14159265358979323;
using namespace std;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
const lld N = 1000005;

map<lld,char> mm;
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s,t;
    lld n,m;
    cin>>n>>m;
    cin>>s>>t;
    lld poss = (n*m)/__gcd(n,m);
    rep(i,0,n) mm[i*poss/n] = s[i];
    rep(i,0,m) { //Stupid nigga rises again
        if(mm.find(i*poss/m) != mm.end()) {
            if(mm[i*poss/m] != t[i]) {
                cout<<-1;
                return 0;
            }
        }
    }
    cout<<poss;
    return 0;
}

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

constexpr int MAX_H = 50;
constexpr int MAX_W = 50;

int H, W;
char grid[MAX_H][MAX_W + 1];

//#define OCTAS
#ifdef OCTAS
constexpr int dh[]{-1, -1, -1, 0, 0, +1, +1, +1};
constexpr int dw[]{-1, 0, +1, -1, +1, -1, 0, +1};
#else
constexpr int dh[]{-1, 0, 0, +1};
constexpr int dw[]{0, -1, +1, 0};
#endif

bool draw(int h, int w) {
  for (int i{}; i < sizeof(dh) / sizeof(int); ++i) {
    int nh = h + dh[i];
    if (nh < 0 || nh >= H)
      continue;
    int nw = w + dw[i];
    if (nw < 0 || nw >= W)
      continue;
    if (grid[nh][nw] == '#') {
      return true;
    }
  }

  return false;
}

int main() {
  scanf("%d%d", &H, &W);
  for (int h{}; h < H; ++h) {
    scanf("%50s", &grid[h][0]);
  }

  bool judge{true};
  for (int h{}; h < H; ++h) {
    for (int w{}; w < W; ++w) {
      if (grid[h][w] == '.') {
        continue;
      }
      if (!(judge = draw(h, w))) {
        judge = false;
        goto END;
      }
    }
  }
END:
  printf("%s\n", judge ? "Yes" : "No");
  return 0;
}


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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    vector<int> r(8,0);
    int ans1 = 0;
    rep(i,n){
        int a;cin>>a;
        if(a>=3200)ans1++;
        else r[a/400]++;
    }
    int ans2 = 0;
    rep(i,8){
        if(r[i]!=0)ans2++;
    }
    int m;
    if(ans2>0) m=ans2;
    else m=1;

    cout<<m<<" "<<ans1+ans2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX=6005;

int dp[MAX][2];
int main(){
    int N,T;
    cin >> N >> T;
    int i,j;
    int ans=0;
    int tmp;
    int a,b;
    for(i=0;i<N;i++){
        cin >> a >> b;
        for(j=T-1;j>=0;j--){
            if(j+a<=T-1){
                dp[j+a][0]=max(dp[j+a][0],dp[j][0]+b);
                dp[j+a][1]=max(dp[j+a][1],dp[j][1]+b);
                }
            dp[j][1]=max(dp[j][1],dp[j][0]+b);
            }
        }
    for(i=0;i<MAX;i++)if(dp[i][1]>ans)ans=dp[i][1];
    cout << ans << endl;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.regex.Matcher;
import java.util.Scanner;
import java.util.regex.Pattern;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AtCoder solver = new AtCoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class AtCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String pronaun = in.next();
            Pattern p = Pattern.compile("[aeiou]");
            if (p.matcher(pronaun).find()) {
                out.println("vowel");
            } else {
                out.println("consonant");
            }
        }
    }
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    queue<ll> q;
    int n;
    cin>>n;
    int num=0;
    ll ans;
	for(int i=1;i<=9;i++) q.push(i);
	while(!q.empty()){
		ll p=q.front();
		q.pop();
        num++;
		if(num==n){ans=p;break;}
		int f=p%10;
		if(f==0){
			q.push(p*10);
			q.push(p*10+1);
		}
		else if(f==9){
            q.push(p*10+8);
            q.push(p*10+9);
		}
		else{
			q.push(p*10+f-1);
			q.push(p*10+f);
			q.push(p*10+f+1);
		}
	}
	cout<<ans;
    return 0;
}


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

int main(){
    int l[10];
    int v[2];
    while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1],
                &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v[0], &v[1]) != EOF){
        double sum = 0.0;
        int i;
        for(i=0; i<10; ++i) sum += l[i];
        double l1 = sum * v[0] / (v[0] + v[1]);
        sum = 0.0;
        for(i=0; i<10; ++i){
            sum += l[i];
            if(l1 <= sum) break;
        }
        cout << i+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int h,n; cin >> h >> n;
    vector<int> a(n),b(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i) >> b.at(i);
    }

    vector<int> ans(h+1);

    for(int i = 1;i < h+1;i ++){

        int dame_ji = 100000000000;
        for(int j = 0;j < n;j ++){
            if(a.at(j) > i){
                dame_ji = min(dame_ji,b.at(j));
            }else{
                dame_ji = min(dame_ji,b.at(j) + ans.at(i-a.at(j)));
            }
        }

        ans.at(i) = dame_ji;
    }

    cout << ans.at(h) << endl;
}







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


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define PB push_back
vector<vint> vv;
vint vis;

int dfs(int a,int b){
	// cout<<a<<endl;
	int ret=0;
	rep(i,vv[a].size()){
		if(vis[vv[a][i]]) continue;
		vis[a]=1;
		int next=vv[a][i];
		ret=max(ret,dfs(next,b));
		vis[a]=0;
	}
	return ret+1;
}
// int solve2(int st){
        // int ret = 0;
        // rep(i,edge[st].size()){
            // int next = edge[st][i];
            // if(visit[next]==0){
                // visit[next]=1;
                // ret = max(solve2(next)+1, ret);
                // visit[next]=0;
            // }
        // }
        // return ret;
    // }
void mainmain(){
	int n;
	while(cin>>n,n){
		// cout<<n<<endl;
		vv=vector<vint>(100);
		vis=vint(100,0);
		rep(i,n){
			int a,b;
			cin>>a>>b;
			a--;
			b--;
			// cout<<a<<" "<<b<<endl;
			vv[a].PB(b);
			vv[b].PB(a);
		}
		int ans=0;
		rep(i,100) vis[i]=0;
		rep(i,100){
			// cout<<"i "<<i<<endl;
			int t=dfs(i,0);
			// cout<<i<<" "<<t<<endl;
			ans=max(ans,t);
		}
		cout<<ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1224