akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,ans;
int main(){
	n=read();
	if(n%2)return puts("0"),0;
	for(ll i=10;i<=1e18;i*=5)
		ans+=n/i;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

V = sum(v)
# dp[i][j]:i番目までの品物から価値がj以上になるよう選んだときの重さの総和の最小値
dp = [[float("inf")] * (V + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
	for j in range(V + 1):
		# i+1番目を選ぶ場合
		if j - v[i] >= 0:
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i])
		# i+1番目を選ばない場合
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

# dp[N][j]がW以下であるようなjの最大値が答えになる
ans = 0
for j in range(V + 1):
	if dp[N][j] <= W:
		ans = j

print(ans)


Measured memory_bytes: 311888
#include<stdio.h>
int main(void){
	int mon,day,moon[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
	char *week[7]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
	while(1){
		scanf("%d%d",&mon,&day);
		if(mon==0)break;
		while(mon--){day+=moon[mon];}
		printf("%s\n",week[day%7]);
	}
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

int N,A,B,C;
int take[8];
int INF = ~(1<<31);
int think(int a, int b, int c, int now){
  if(now == N){
    if(a < 1 || b < 1 || c < 1){
      return INF - 30;
    }
    return (abs(A-a)+abs(B-b)+abs(C-c)) - 30;
  }
  return min(
    min(
      10 + think(a + take[now], b, c, now+1),
      10 + think(a, b + take[now], c, now+1)
    ),
    min(
      10 + think(a, b, c + take[now], now+1),
      think(a, b, c, now+1)
    )
  );
}
int main(){
  cin >> N >> A >> B >> C;
  for(int i=0;i<N;i++){
    cin >> take[i];
  }
  cout << think(0,0,0,0) << endl;
}



Measured memory_bytes: 256
void main() {
	auto X = ri;
	ulong res;
	while(X >= 500) {
		res += 1000;
		X -= 500;
	}
	res += (X / 5) * 5;
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll x;cin>>x;
  ll d=x/11;
  x%=11;
  if(x==0)cout<<2*d<<endl;
  else if(x<=6)cout<<2*d+1<<endl;
  else cout<<2*d+2<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int res = 0;
  for (int i = 1; i <= N; i += 2){
    int f = 0;
    for (int j = 1; j <= i; j++){
      if (i % j == 0) f++;
    }
    if (f == 8) res++;
  }
  cout << res;
}

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

int main(void) {
    u_int m, n;

    std::cin >> n >> m;
    for (; m != 0 && n != 0; std::cin >> n >> m) {
        std::priority_queue<u_int> p;
        for (u_int i = 0; i < n; ++i) {
            u_int tmp;
            std::cin >> tmp;
            p.push(std::move(tmp));
        }

        u_int sum = 0;
        for (u_int i = 1; i <= n; ++i) {
            if (i % m) {
                sum += p.top();
                p.pop();
            } else {  // 袋が一杯のとき
                if (!p.empty()) p.pop();
            }
        }

        std::cout << sum << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1220
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextInt();
        var M = sc.nextInt();
        var K = new int[N];
        var A = new int[N][];
        for (int i = 0; i < N; i++) {
            K[i] = sc.nextInt();
            A[i] = sc.ArrayInt(K[i]);
        }
        var ans = new Dictionary<int, int>();
        for (int i = 1; i <= M; i++) {
            ans.Add(i, 0);
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < K[i]; j++) {
                ans[A[i][j]]++;
            }
        }
        WriteLine(ans.Where(kvp => kvp.Value == N).Count());
    }
}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13524
def main():
    n = int(input())
    _list = list(range(1,n+1))
    for x in _list:
        if x % 3 == 0 or any(list(map(lambda x: x == 3, list(map(int,list(str(x))))))):
            print(' %d' %  x, end = '')
    print()
    

main()

Measured memory_bytes: 8368
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  ll x,k,d;
  cin >> x >> k >> d;
  x = abs(x);
 
  ll k1 = min(k,x/d);
  k -= k1;
  x -= k1 * d;
  if(k % 2 == 0){
      cout << x << endl;
  }
  else{
      cout << d-x << endl;
  }
  
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
char s[200005];
LL ans = 0;
int main(){
    scanf("%s", s+1);   
    int n = strlen(s+1);
    int cnt = 0;
    for(int i=1;i<=n-1;i++){
        if(s[i] == 'A') cnt++;
        else if(cnt > 0 && s[i] == 'B' && s[i+1] == 'C'){
            i++;
            ans+=cnt;
        }
        else cnt = 0;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 384
#include<stdio.h>
int cal(int,int);
int main(){
  int a,b,ans;
  scanf("%d%d",&a,&b);
  if(a>b){
   ans= cal(a,b);
  }
  else if(a<=b){
     ans=cal(b,a);
    }
  printf("%d\n",ans);
}
int cal(int num ,int num2){
  int r;
  r=num%num2;
  while(r!=0){
    num=num2;
    num2=r;
    r=num%num2;
  }
  return num2;
}



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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  
  vector<vector<int>> v(n, vector<int>(m+1));
  for(int i=0; i<n; i++) for(int j=0; j<m+1; j++) cin >> v[i][j];
  
  int ans = 10000000;
  vector<int> data(m, 0);
  for(int bit=0; bit<(1<<n); bit++) {
    int sum = 0;
    for(int i=0; i<n; i++) {
      if(bit & (1<<i)) {
        sum += v[i][0];
        for(int j=0; j<m; j++) {
          data[j] += v[i][j+1];
        }
      }  
    }
    
    bool check = true;
    for(int i=0; i<m; i++) if(data[i]<x) check = false;
    if(check && sum<ans) ans = sum;
    
    for(int i=0; i<m; i++) data[i] = 0;
  }
  
  if(ans==10000000) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
def f1(n):
    max_p = int(n ** 0.5)
    p = 0  # 素数
    pl = []  # 素数リスト
    el = [i for i in range(2, n + 1)]  # 探索リスト
    D = [i for i in range(n + 1)]
    while p <= max_p:
        nxt = []
        p = el[0]
        pl.append(p)
        for e in el:
            if e % p == 0:
                D[e] = p
            else:
                nxt.append(e)
        el = nxt
    for e in el:
        D[e] = e
    pl.extend(el)
    return D, pl


def f2(n, D):
    s = set()
    x = n
    while x > 1:
        p = D[x]
        s.add(p)
        x = x // p
    return s


from math import gcd


def is_nc(n, al):
    g = al[0]
    for i, a in enumerate(al):
        if i == 0:
            continue
        else:
            g = gcd(g, a)
            if g == 1:
                return False
    return True


def is_sc(n, al):
    max_al = max(al)
    if max_al == 1:
        return False
    D, pl = f1(max_al)
    count = {p: 0 for p in pl}
    for a in al:
        p_s = f2(a, D)
        for p in p_s:
            if count[p] == 1:
                return True
            else:
                count[p] += 1
    return False


n = int(input())
al = list(map(int, input().split()))
if is_nc(n, al):
    print('not coprime')
elif is_sc(n, al):
    print('setwise coprime')
else:
    print('pairwise coprime')

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

int n, m, k;

int main(){
  cin >> n >> m >> k;
  string res = "No";
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= m; j++){
      if(i * m + j * n - 2 * i * j == k){
        res = "Yes";
        //cerr << i << " " << j << endl;
      }
    }
  }
  cout << res << endl;
  return 0;
}

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

int main() {
      int N; cin >> N;
      int A[N+10]; rep(i,N) cin >> A[i];
      sort(A,A+N);
      cout << A[N/2]-A[N/2-1] << endl;

      return 0;
}

Measured memory_bytes: 640
n = int(input())

a = []
x = [[] for _ in range(n)]

for i in range(n):
    
    k = int(input())
    a.append(k)
    
    for j in range(k):
        x[i].append(list(map(int,input().split())))

# print(x)
ans = 0
for i in range(1<<n):
    
    cnt = bin(i).count("1")
    if ans > cnt:
        continue
    flag = True
    for j in range(n):
        # if i==3:
        #     print(i,j,i>>j&1,cnt)
        if i>>j & 1:
            # True if 1
            # if i==3:
                # print(i,j)
            for t in x[j]:
                # 証言:testimony
                # if i == 3:
                    # print(i,t[0]-1, i>>t[0]-1, t[1])
                if (i>>(t[0]-1) &1 ) != t[1]:
                    flag = False
                    break
    # if flag == False:
    #     break
    if flag == True:
        # print(i) # 0 000
        ans = cnt

print(ans)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node{int parent, left, right;};

Node Tree[MAX];
int n, Depth[MAX], Degree[MAX], Height[MAX];

void print(int index){
    int i, child;
    int parent = Tree[index].parent;
    int sibling;

    if(NIL == Tree[index].parent) sibling = NIL;
    else sibling = ((Tree[parent].left==index) ? Tree[parent].right : Tree[parent].left);

    cout << "node " << index << ": ";
    cout << "parent = " << parent << ", ";
    cout << "sibling = " << sibling << ", ";
    cout << "degree = " <<  Degree[index] << ", ";
    cout << "depth = " <<  Depth[index] << ", ";
    cout << "height = " <<  Height[index] << ", ";

    if(Tree[index].parent == NIL) cout << "root" << endl;
    else if(Tree[index].left == NIL && Tree[index].right == NIL) cout << "leaf" << endl;
    else cout << "internal node" << endl;
}

void setDepth(int index, int currentDepth){
    Depth[index] = currentDepth;
    if(Tree[index].right != NIL) setDepth(Tree[index].right, currentDepth+1);
    if(Tree[index].left != NIL) setDepth(Tree[index].left, currentDepth+1);
}

void setDegree(int index){
    Degree[index] = 0;
    if(NIL != Tree[index].left) Degree[index]++;
    if(NIL != Tree[index].right) Degree[index]++;
}

int setHeight(int* Height , int index){
    int heightLeft = 0; int heightRight = 0;

    if(NIL != Tree[index].left) heightLeft = setHeight(Height, Tree[index].left)+1;
    if(NIL != Tree[index].right) heightRight = setHeight(Height, Tree[index].right)+1;

    Height[index] = ((heightLeft<heightRight)? heightRight : heightLeft);
    return Height[index];
}

int main(void){
    int node, left, right, root;
    cin >> n;
    for(int i=0;i<n;i++) Tree[i].parent = Tree[i].left = Tree[i].right = NIL;

    for(int i=0;i<n;i++){
        cin >> node >> left >> right;
        if(NIL != left){
            Tree[node].left = left;
            Tree[left].parent = node;
        }
        if(NIL != right){
            Tree[node].right = right;
            Tree[right].parent = node;
        }
    }

    for(int i=0;i<n;i++){
        if(Tree[i].parent == NIL) root=i;
        setDegree(i);
    }
    setDepth(root, 0);
    setHeight(Height, root);

    for(int i=0;i<n;i++) print(i);

    return 0;
}



Measured memory_bytes: 3108
#include<cstdio>
using  namespace  std;
int  n;
double  a;
int  main()
{
	scanf("%d",&n);
	if(n&1)printf("%lf\n",(n/2+1)*1.0/n);
	else  printf("%lf\n",(n/2)*1.0/n);
	return  0;
}

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

using namespace std;

#define int long long
#define INF 21000000000

signed main(){
                int n;
                cin >> n;
                if(n%2 == 0) cout << (float)1 / 2 << endl;
                else cout << (float)(n/2+1) / n << endl;
}


Measured memory_bytes: 256
// AOJ 3128 Auction
// 2020.1.14 bal4u

#include <stdio.h>

#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int main()
{
	int N, a, A, mi, ma;
	
	N = in();
	ma = N, mi = 0, a = 1000000001;
	while (N--) {
		A = in();
		if (A <= a) ++mi;
		a = A;
	}
	printf("%d\n%d\n", mi, ma);
	return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define pb push_back
using namespace std;

const int N = 1e6 + 6,mod = 998244353 ;

inline void test_case(){
        ll n,m;
        cin >> n >> m;
        cout << n*m << endl;
}
int main(){
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

        int T = 1;
        //cin >> T;
        while(T--){
                test_case();
        }
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ull = unsigned long long;

int main(){
  int n, W, w, v;
  cin>>n>>W;
  vector<ull> dp(W+1, 0);
  for(int i = 0; i < n; i++){
    cin>>w>>v;
    for(int j = W; j >= 0; j--){
      if(j >= w)
        dp[j] = max(dp[j], v+dp[j-w]);
    }
  }
  cout<<dp[W]<<"\n";
  return 0;
}


Measured memory_bytes: 1152
#include<iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int B[N-1];
  for (int i=0; i<N-1; i++) {
    cin >> B[i];
  }
  
  int sum = 0;
  sum += B[0];
  for (int i=0; i<N-2; i++) {
    if (B[i] > B[i+1]) {
      sum += B[i+1];
    } else {
      sum += B[i];
    }
  }
  sum += B[N-2];
  
  cout << sum << endl;
}

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

int main() {
    int64_t N, K;
    std::cin >> N >> K;

    int64_t A[N];
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
        --A[i];
    }

    if (K <= N) {
        int64_t cur = 0;
        for (int i = 0; i < K; ++i) {
            cur = A[cur];
        }
        std::cout << cur + 1 << std::endl;
        return 0;
    }

    bool visited[N] = {false};
    visited[0] = true;
    int64_t cur = 0, last = 0;
    while (true) {
        const int64_t next = A[cur];
        if (visited[next]) {
            last = next;
            break;
        } else {
            visited[next] = true;
            cur = next;
        }
    }

    int64_t cnt1 = 0, cnt2 = 0;
    cur = 0;
    bool once = false;
    while (true) {
        if (cur == last) {
            if (once == false) {
                once = true;
            } else {
                break;
            }
        } 

        const int64_t next = A[cur];
        
        if (once == false) {
            ++cnt1;
        } else {
            ++cnt2;
        }

        cur = next;
    }

    K -= cnt1;
    K %= cnt2;
    int64_t pos = last;
    for (int64_t i = 0; i < K; ++i) {
        pos = A[pos];
    }

    std::cout << pos + 1 << std::endl;

    return 0;
}


Measured memory_bytes: 5380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second
#define print(a) cout << a << endl;

int main(void){
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n-1);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];
    int ans = b[a[0]-1];
    rep(i,n-1){
        ans += b[a[i+1]-1];
        if(a[i+1] == a[i]+1) ans += c[a[i]-1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

//
// solution 
//

#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        b: chars
    }
    let b = b[0];
    let ans = match b {
        'A' => 'T',
        'T' => 'A',
        'G' => 'C',
        'C' => 'G',
        _   => panic!(),
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
#define printd(x) printf("%.12f\n", ans);
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using P = pair<int, int>;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

int main(void) {

    ios::sync_with_stdio(false); cin.tie(0);

    int n;
    cin >> n;
    V<ll> a(n);
    rep (i, n) cin >> a[i];

    V<ll> sum(n + 1, 0);
    sort(rng(a));
    for (int i = 1; i <= n; i++) {
        sum[i] = sum[i - 1] + a[i - 1];
    }

    sort(rrng(a));

    int ans = 1;

    

    for (int i = 1; i < n; i++) {
        if (sum[n - i]  * 2 >= a[i - 1]) ans++;
        else break;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int ans=0;
  for(int i=0; i<50000; i++){
    int a=i*1.08;
    if(a==N){ans=i;break;}
  }
  if(ans==0){
  	cout << ":(" << endl;
  }else{
  	cout << ans << endl;
  }
}

Measured memory_bytes: 256
// Code by Nguyen Huu Lam
#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 long long LL;

#define y0 Sword_Art_Online
#define y1 Your_lie_in_April
#define yn Darling_in_the_Franxx
#define tm Plastic_Memories
#define lr Charlotte
#define norm Weathering_with_you
#define left Violet_Evergarden
#define have Date_a_live
#define ends Your_name
#define prev Five_centimeters_per_second
#define hash Silent_voice
#define endl "\n"

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

LL Rand(LL l, LL h){
    return uniform_int_distribution<LL>(l, h)(rng);
}

template <typename T> void read(T &t){
    t = 0; char ch = getchar(); int f = 1;
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    do { (t *= 10) += ch - '0'; ch = getchar(); } while (isdigit(ch)); t *= f;
}

const LL MaxN = 1 + 2e5;

LL n, a[MaxN], vis[MaxN], ans, cnt, m;
vector<LL> adj[MaxN];

void DFS(LL u){
    cnt++;
    vis[u] = 1;
    for(int v : adj[u])
    if(!vis[v]) DFS(v);
} 

void InOut(){
    #define TASK "ABC"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
}

int main(){
    // InOut();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 0 ; i < m ; ++i){
        LL x, y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    for(int i = 1 ; i <= n ; ++i)
    if(!vis[i]){
        cnt = 0;
        DFS(i);
        ans = max(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 22364
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    int N = S.size();
    S = "#" + S;
    if(S[1]=='0' or S[N]=='1'){
        cout << -1 << "\n";
        return 0;
    }
    for(int i=1; i<=N/2; i++){
        if(S[i] != S[N-i]){
            cout << -1 << "\n";
            return 0;
        }
    }
    S[N] = '1';
    queue<int> que;
    for(int i=1; i<=N; i++){
        if(S[i] == '1'){
            while(que.size()){
                cout << que.front() << " " << i << "\n";
                que.pop();
            }
        }
        que.emplace(i);
    }
    return 0;
}

Measured memory_bytes: 1900
#include <iostream>
#include <string>
using namespace std;
int main(){
    int a,b;
    cin >> a;
    cin >> b;
    int n = b - a;
    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += i;
    }
    cout << sum - a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll r=0;
    ll g=0;
    ll b=0;
    rep(i,n){
        if(s[i]=='R')r++;
        else if(s[i]=='G')g++;
        else b++;
    }
    ll sum=r*g*b;
    rep(i,n){
        for(int j=1;j<=min(i,n-i-1);j++){
            if(s[i]!=s[i-j] && s[i]!=s[i+j] && s[i-j]!=s[i+j]){
              sum--;
            }
        }
    }
    cout << sum;


}

/*



 */



Measured memory_bytes: 3632
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int min = 1000000;
    for(int i = 0; i < N; i++){
      int n = Integer.parseInt(sc.next());
      int count = 0;
      while(n%2 == 0){
        n /= 2;
        count++;
      }
      min = min > count ? count : min;
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 21716
import java.util.*;
import static java.lang.System.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		long A = 0, B = 0;
		long[] scores = new long[n];
		scores[0] = sc.nextLong();
		A = scores[0];
		for(int i = 1; i < n; i++) {
			scores[i] = sc.nextLong();
			B += scores[i];
		}
		long ans = Math.abs(A - B);
		for(int i = 1; i < n - 1; i++) {
			A += scores[i];
			B -= scores[i];
			ans = Math.min(ans, Math.abs(A - B));
		}
		out.println(ans);
		
		out.close();
	}

	

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}


Measured memory_bytes: 26744
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;

	const ll MAX = 1e5L + 10;

	vector<ll> adj[MAX];
	ll dp[MAX] = {0}, vis[MAX] = {0}, N,M;

	ll lpath(ll u) {
		if(vis[u]) {
			return dp[u];
		}

		vis[u] = 1;
		ll best = 0;
		for(ll i=0; i<adj[u].size(); i++) {
			best = max(best, 1 + lpath(adj[u][i]));	
		}

		return dp[u] = best;
		
	}
	
	int main()
	{
		std::ios::sync_with_stdio(false);

		cin>>N>>M;

		for(ll i=0; i<M; i++) {
			ll u,v;
			cin>>u>>v;
			adj[u].push_back(v);
		}

		ll best = 0;

		for(ll i=1; i<=N; i++) {
			best = max(best, lpath(i));
		}

		cout<<best<<endl;

		return 0;
	}


Measured memory_bytes: 12652
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
int INF=1e9;
int MOD=1000000007;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
double EPS = 1e-5;
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))return 0;
	return a+b;
}
struct P{
	double x,y;
	P(){}
	P(double x,double y):x(x),y(y){}
	P operator + (P p){
		return P(add(x,p.x),add(y,p.y));
	}
	P operator - (P p){
		return P(add(x,p.x),add(y,-p.y));
	}
	P operator * (P p){
		return P(x*p.x,y*p.y);
	}
};
double dist(P a,P b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int cnt(P pos,vector<P> dat){
	int res=0;
	REP(i,dat.size()){
		if(dist(pos,dat[i])<=1.0+EPS)res++;
	}
	return res;
}
int main(){
	int n;
	double x,y;
	while(scanf("%d",&n)&&n){
		vector<P> dat;
		REP(i,n){
			cin>>x>>y;
			dat.PB(P(x,y));
		}
		int ans=1;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				P a=dat[i],b=dat[j];
				P mid=P((a.x+b.x)/2.0,(a.y+b.y)/2.0);
				double dx=a.y-b.y,dy=b.x-a.x;
				double d=dist(a,b);
				if(d>2)continue;
				double dd=sqrt(dx*dx+dy*dy);
				double ddd=sqrt(1-d*d/4);
				dx=dx*ddd/dd;dy=dy*ddd/dd;
				ans=max(ans,cnt(P(mid.x+dx,mid.y+dy),dat));
				ans=max(ans,cnt(P(mid.x-dx,mid.y-dy),dat));
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1272
/*
    In the name of
        "ALLAH"
    And say "AL-HAM-DU-LILLAH"
*/

#include<bits/stdc++.h>
#define ll long long
#define llu unsigned long long

int take() {
    int n;
    scanf("%d",&n);
    return n;

}
double ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define Int take()
#define Dnt ttake()
#define LL takes()
#define done {return 0;}
#define fr(n) for(int i=1;i<=n;i++)
#define FR(a,b,x) for(int i=(a);i<=(b);i+=(x))
#define rfr(n) for(int i=n;i>=1;i--)
int cas;
#define print printf("Case %d:",++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int,int>
#define vii vector<pii>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mk  make_pair
#define fill(x,v) memset(x,v,sizeof x)

using namespace std;

bool approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define STR {struct info}
#define dbg(x) {cout<<"ekhane"<<x<<endl;}
#define  SS second
#define  FF first
#define PQ priority_queue
#define great greatest
#define less lesser
#define mii map<int,int>
#define mil map<int,ll>
#define mll map<ll,ll>
#define msb map<string,bool>
#define M 100005
//////////////////////////////////////////


int main(){

   int a=Int,b=Int;

   if((a*b)%2==0) printf("Even");
   else printf("Odd");

    done;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 214748364700
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif

signed main(){
	
	int n,a[1111];
	cin>>n;
	int sum=0;
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	sum=round(double(sum)/double(n));
	//cout<<sum;
	int ans=0;
	rep(i,n){
		ans+=(a[i]-sum)*(a[i]-sum);
	}
	cout<<ans<<endl;
	

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
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; }
const long long INF = 1LL << 60;
const int mod = 1000000007;

ll dp[100100];
int main() {
   int n;
   cin >> n;
   vector<ll> a(3*n);
   rep(i,3*n) cin >>a[i];
   ll ans =0;
   sort(a.begin(),a.end(),greater<ll>());
   for(int i = 1 ; i<2*n;i+=2){
       ans +=a[i];
   }
   cout << ans <<endl;
}

Measured memory_bytes: 5544
s = input().strip()

s1 = int(s[:2])
s2 = int(s[2:])

s1_is_month = 1 <= s1 <= 12
s2_is_month = 1 <= s2 <= 12

if s1_is_month and s2_is_month:
    print('AMBIGUOUS')
elif s1_is_month:
    print('MMYY')
elif s2_is_month:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 2940
m[99],a[99],b[],i,j,M,B;main(n){for(;scanf("%d",&n)*n;puts(B?"NG":"OK")){for(i=n;i--;B=0)scanf("%d%d%d",m+i,a+i,b+i);for(i=n;i--;B|=M>150)for(M=0,j=n;j--;)M+=a[i]>=a[j]&a[i]<b[j]?m[j]:0;}}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;
 
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}

ll lcd(ll a, ll b){
    ll g = gcd(a, b);
    return a / g * b;
}
 
int main()
{
    //FILE* fp_in = freopen("input.txt","r",stdin);
    int n;
    vl t;
    cin >> n;
    t.resize(n);
    rep(i,n) cin >> t[i];

    if(n == 1){
        cout << t[0] << endl;
    }
    else if(n == 2){
        cout << lcd(t[0], t[1]) << endl;
    }
    else{
        ll l = lcd(t[0], t[1]);
        for(int i = 2; i < n; i++){
            l = lcd(l, t[i]);
        }
        cout << l << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<int> lstRet = new List<int>();
            lstRet.Add((int)Math.Truncate((decimal)iA / 0.08M));
            lstRet.Add((int)Math.Truncate((decimal)iB / 0.10M));
            lstRet.Sort();
            int iS = lstRet[0];
            int iM = lstRet[lstRet.Count - 1];
            for (int i = iS + 1; i < iM; i++)
            {
                lstRet.Add(i);
            }
            lstRet.Add(iS - 1);
            lstRet.Add(iM + 1);
            lstRet.Sort();
            List<int> lstOut = new List<int>();
            for (int i = 0; i < lstRet.Count; i++)
            {
                if (((int)Math.Truncate((decimal)lstRet[i] * 0.08M) == iA) &&
                    ((int)Math.Truncate((decimal)lstRet[i] * 0.10M) == iB))
                { lstOut.Add(lstRet[i]); }
            }
            int iOut = -1;
            if (lstOut.Count > 1) { lstOut.Sort(); iOut = lstOut[0]; }
            else if (lstOut.Count == 1) { iOut = lstOut[0]; }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString("0").Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
import java.util.Scanner;

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

        int a = sc.nextInt();
        String op = sc.next(); 
        int b = sc.nextInt();

        if(op.equals("?")){
            break;
        }

        int ans = 0;

        switch(op){
        case "+":
            ans = a+b;
            break;
        case "-":
            ans = a-b;
            break;
        case "*":
            ans = a*b;
            break;
        case "/":
            ans = a/b;
            break;

        }
        System.out.println(ans);
        }
    }    
}


Measured memory_bytes: 26300
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007LL, INF=mod * 10000;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n+1), b(n+1);
    b[0] = 1LL;
    ll ans = 0LL;
    bool cnt = true;
    for(ll i=0LL;i<=n;i++){
    	cin >> a[i];
    	if(cnt){
    	    if(i == 0LL) b[i] -= a[i];
    	    else b[i] = b[i-1] * 2LL - a[i];
    	    if(b[i] < 0LL){
    		    cout << -1 << endl;
    		    return 0;
    	    }
    	    if(b[i] > INF) cnt = false;
        }else b[i] = INF;
    }
    ll now = a[n];
    ans += now;
    for(ll i=n-1;i>=0;i--){
    	now = min(now, b[i]) + a[i];
    	ans += now;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4676
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
 ll n ;
 cin>>n ;
 string s ;
 cin>>s ;
 ll r=0 ;
 ll b=0 ;
 rep(i,n) {
  if(s.at(i)=='R') 
r++ ;
else 
b++ ;
 }
if(r>b)
cout<<"Yes"<<endl ;
else
  cout <<"No"<<endl ; 
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	int n;
	cin >> n;
	if (n == 1) {
		cout << 0 << endl;
		return 0;
	}
	V a(n - 1);
	V b(n - 1);
	V c(n - 1);
	rep(i, n - 1) {
		cin >> a[i] >> b[i] >> c[i];
	}
	VL ans(n, 0);
	rep(i, n - 1) {
		int res = 0;
		for (int j = i; j < n - 1; j++) {
			int tmp = max(0, b[j] - res); // 初出発まで待つ
			res += tmp;
			int T = res % c[j]; // 次に来るまで待つ
			int tmp2 = (!T) ? T : c[j] - T;
			res += tmp2;
			res += a[j]; // 電車に乗る
		}
		ans[i] = res;
	}
	rep(i, n) cout << ans[i] << endl;
	return 0;
}

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

using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvvi = std::vector<vvi>;

int f(const std::string& N, int K, int max_K)
{
	vvvi dp(N.size(), vvi(max_K+1, vi(2, 0)));
	int d0 = N[0] - '0';
	dp[0][0][0] = 1;
	dp[0][0][1] = 0;
	dp[0][1][0] = d0 - 1;
	dp[0][1][1] = 1;

	for (size_t i = 1; i < N.size(); i++)
	{
		int d = N[i] - '0';
		dp[i][0][0] = 1;
		dp[i][0][1] = 0;

		for (size_t j = 1; j <= max_K; j++)
		{
			if (d > 0)
			{
				dp[i][j][0] = dp[i-1][j-1][0]*9 + dp[i-1][j][0] + dp[i-1][j-1][1]*(d-1) + dp[i-1][j][1];
				dp[i][j][1] = dp[i-1][j-1][1];
			}
			else
			{
				dp[i][j][0] = dp[i-1][j-1][0]*9 + dp[i-1][j][0];
				dp[i][j][1] = dp[i-1][j][1];
			}
		}
	}

	return dp[N.size()-1][K][0] + dp[N.size()-1][K][1];
}

int main()
{
	std::string N;
	int K;
	std::cin >> N >> K;

	int ans = f(N, K, 3);

	std::cout << ans;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    int N, A, B; cin >> N >> A >> B;
    if(A > B || (N == 1 && A != B)){
        cout << 0 << endl;
        return 0;
    }
    ll mn(A+B), mx(A+B);
    if(N == 1) mn = mx = A;
    REP(i, N-2){
        mn += A;
        mx += B;
    }
    cout << mx - mn + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int A,B;
cin>>A>>B;

if(A==B){
    cout<<"Draw";
}
else if(A!=1&&A<B){
    cout<<"Bob";
}
else if(B==1&&A>B){
cout<<"Bob";
}
else if (A>B&&B!=1){
   cout<<"Alice";
}
else if(A==1&&A<B){
    cout<<"Alice";
}
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
class fastin{
	private: int _ch,_f;
	public: template<typename _Tp> inline fastin& operator>>(_Tp&_x){
		_x=0; while(!isdigit(_ch)) _f|=(_ch==45),_ch=getchar();
		while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
		_f&&(_x=-_x,_f=0); return *this;}
	fastin() {_ch=_f=0;}
}fin;
class fastout{
	private: int _num[32],_head;
	public: int SUF; template<typename _Tp> inline fastout& operator<<(_Tp _x){
		_Tp _k; if(_x==0) {putchar('0'),putchar(SUF);return *this;} if(_x<0) putchar('-'),_x=-_x;
		while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
		while(_head>0) putchar(_num[_head]),--_head; putchar(SUF); return *this;}
	fastout() {_head=0,SUF=' ';}
}fout;
// ----------------------------
#define int ll
// using namespace std;
const int maxn=200004;
const int mod=998244353,inf=1000000007;

int a[maxn];
int cnt[maxn];

signed main()
{
	fout.SUF='\n';
	int n;
	ll ansall=0;
	fin>>n;
	for(rgi i=1;i<=n;++i) fin>>a[i],++cnt[a[i]];
	for(rgi i=1;i<=n;++i) ansall+=(ll)cnt[i]*(cnt[i]-1)/2;
	for(rgi i=1;i<=n;++i)
		fout<<(ansall-(ll)cnt[a[i]]*(cnt[a[i]]-1)/2+(ll)(cnt[a[i]]-1)*(cnt[a[i]]-2)/2);
	return 0;
}
// ----------------------------
// by imzzy


Measured memory_bytes: 4736
const main = stdin => {
  const input = stdin.trim().split('\n')

  const [A, B] = input[0].split(' ').map(x => parseInt(x))

  if (A <= 5) {
    console.log(0)
  } else if (A <= 12) {
    console.log(B / 2)
  } else {
    console.log(B)
  }

}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1), B(N + 1), C(N);
    for (int i = 1; i <= N; i++)
        cin >> A[i];
    for (int i = 1; i <= N; i++)
        cin >> B[i];
    for (int i = 1; i <= N - 1; i++)
        cin >> C[i];

    int res = 0, pre = -1;
    for (int i = 1; i <= N; i++) {
        res += B[A[i]];
        if (pre == A[i] - 1) res += C[pre];
        pre = A[i];
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256