akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] a = sc.next().toCharArray();
        int[] r = new int[n];
        int[] g = new int[n];
        int[] b = new int[n];
        if(a[0] == 'R') r[0]++;
        if(a[0] == 'G') g[0]++;
        if(a[0] == 'B') b[0]++;
        for (int i = 1; i < n; i++) {
            r[i] = r[i-1];
            g[i] = g[i-1];
            b[i] = b[i-1];
            if(a[i] == 'R') r[i]++;
            if(a[i] == 'G') g[i]++;
            if(a[i] == 'B') b[i]++;
        }
        long ans = 0L;
        for (int i = 0; i < n-2; i++) {
            for (int j = i+1; j < n-1; j++) {
                if(a[i] == a[j]) continue;
                int d = j-i;
                int ng = j+d;
                int x = 0;
                if(a[i] != 'R' && a[j] != 'R') {
                    x = r[n-1]-r[j];
                    if(ng <= n-1 &&  a[ng] == 'R') x--;
                }else if(a[i] != 'G' && a[j] != 'G'){
                    x = g[n-1]-g[j];
                    if(ng <= n-1 &&  a[ng] == 'G') x--;
                }else if(a[i] != 'B' && a[j] != 'B'){
                    x = b[n-1]-b[j];
                    if(ng <= n-1 &&  a[ng] == 'B') x--;
                }
                ans += x;
            }
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 37008
#include <iostream>
using namespace std;
int main() {
    int n, t, min, max; long long sum;
    cin >> n >> t;
    min = max = sum = t;
    for(int i = 1; i < n; ++i) {
        cin >> t;
        if(t < min) min = t;
        if(t > max) max = t;
        sum += t;
    }
    cout << min << " " << max << " ";
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3092
_h = gets.chomp.to_i
kokuban = gets.chomp.split.map(&:to_i)
ans = 0;breakfg = false
loop do
  kokuban.map! do | i |
    if i % 2 ==1
      breakfg = true
      break
    end
    i / 2
  end
  break if breakfg == true
  ans += 1
end
puts ans

Measured memory_bytes: 1788
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long int min(long long int a, long long int b)
{
       	return a < b ? a: b;
}
int main(){  
  	int N;
	scanf("%d", &N);    
        int h[N];
	long long int dp[N];
	memset(dp, 0, sizeof(dp));
	for(int i = 0; i < N; i++)scanf("%d", &h[i]);
//	dp[j] is the minimum cost way of reaching jth stone from 1st stone
	dp[0] = 0;
	dp[1] =llabs(h[1]-h[0]);
	for(int i = 2; i < N; i++){
		dp[i] = min(dp[i-1] + llabs(h[i] - h[i-1]), dp[i-2] + llabs(h[i] - h[i-2]));
	//	printf("%d %lld \n", i, dp[i]);
	}
	printf("%lld", dp[N-1]);
	return 0;

}


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

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second

using vint = vector<int>;
using pint = pair<int, int>;
using vpint = vector<pint>;

template <typename A, typename B>
inline void chmin(A& a, B b) {
    if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A& a, B b) {
    if (a < b) a = b;
}

template <class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p) {
    ost << "{" << p.first << "," << p.second << "}";
    return ost;
}

template <class T>
ostream& operator<<(ostream& ost, const vector<T>& v) {
    ost << "{";
    for (int i = 0; i < v.size(); i++) {
        if (i) ost << ",";
        ost << v[i];
    }
    ost << "}";
    return ost;
}

inline int topbit(unsigned long long x) {
    return x ? 63 - __builtin_clzll(x) : -1;
}

inline int popcount(unsigned long long x) {
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x) {
    return __builtin_parity(x);
}

long long gcd(long long a, long long b) {
    while (b) {
        swap(a %= b, b);
    }
    return a;
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b;
}

const int LIM = 1000000;
bool isprime[LIM + 1];
vint facts[LIM + 1];

signed main() {
    fill_n(isprime, LIM + 1, true);
    isprime[0] = isprime[1] = false;
    for (int i = 2; i <= LIM; i++) {
        if (!isprime[i]) continue;
        for (int j = i; j <= LIM; j += i) {
            facts[j].pb(i);
            if (i != j) isprime[j] = false;
        }
    }

    int N;
    cin >> N;
    vint A(N);
    rep(i, N) cin >> A[i];

    int g = 0;
    rep(i, N) g = gcd(g, A[i]);
    if (g != 1) {
        cout << "not coprime" << endl;
        return 0;
    }

    set<int> s;
    rep(i, N) {
        for (auto f : facts[A[i]]) {
            if (s.find(f) != s.end()) {
                cout << "setwise coprime" << endl;
                return 0;
            }
            s.insert(f);
        }
    }

    cout << "pairwise coprime" << endl;
    return 0;
}

Measured memory_bytes: 82192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count=0;
		int R = sc.nextInt();
		int G = sc.nextInt();
		int B = sc.nextInt();
		int N = sc.nextInt();
		for (int i=0;i<=N/R;i++) {
			for (int j=0;j<=(N-i*R)/G;j++) {
				if ((N-i*R-j*G)%B==0) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 35768
n, m ,l = map(int, input().split())
A = []
B = []

for i in range(n):
    a = list(map(int, input().split()))
    A.append(a)

for i in range(m):
    b = list(map(int, input().split()))
    B.append(b)

C = [[0]*l for i in range(n)]

for x in range(n):
    for y in range(l):
        for z in range(m):
            C[x][y] += A[x][z]* B[z][y]

for row in range(n):
    print(C[row][0], end='')
    for col in range(1, l):
        print(' {}'.format(C[row][col]), end='')
    print()


Measured memory_bytes: 7052
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int n;
    cin >> n;
    if(n>=30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;        
    }

}


Measured memory_bytes: 3560
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if true
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

ss = inputs[0][0]

# body
if $debugFlag
end

sl = ss.length
cnt = 0
ss.length.times do |i|
  cnt += 1 if ss[i..i] == 'o'
end
pd cnt
pd 15 - sl
if 8 - cnt <= 15 - sl
  puts "YES"
else
  puts "NO"
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define maxi 300005
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define ll long long
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define TRACE
#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#else
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
#endif
#define gc getchar
#define REP(i,j,n)               for( i=j;i<n;i++)
#define PER(i,j,n)               for( i=n-1;i>=j;i--)
ll mpow(ll a, ll n,ll mod){
	ll ret=1;ll b=a;
	while(n) {
		if(n&1)
			ret=(ret*b)%mod;
		b=(b*b)%mod;
		n>>=1;
	}
	return (ll)ret;
}
ll gcd(ll a, ll b)
{
    if (a == 0 || b == 0)
       return 0;
    if (a == b)
        return a;
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
inline void read(int &x){
	x=0;
	register char c=gc();
	for(;c<'0' || c>'9';c=gc());
	for(;c>='0' && c<='9';c=gc())
		x=(x<<3)+(x<<1)+(c-'0');
}
inline void write(int x){
	register char buffor[35];
	register int i=0;
	do{
		buffor[i++]=(x%10)+'0';
		x/=10;
	} while(x);
	i--;
	while(i>=0) putchar(buffor[i--]);
	putchar('\n');
}
inline int in() { int x; read(x); return x; }
void solve();
int dbg=1;
using namespace std;
int main(){
	int t=1;
	//read(t);
	for(int i=0;i<t;i++){
		//printf("Case #%d:\n",i);
		solve();
	}
	return 0;
}
void solve() {
	ll n,m,i,j,k,p[15],l,q,ans=0;
	vector<ll> v[15];
	cin>>n>>m;
	REP(i,0,m){
		cin>>j;
		REP(k,0,j){
			cin>>l;
			v[i].pb(l-1);
		}
	}
	REP(i,0,m)
		cin>>p[i];
	REP(i,0,1<<n){
		REP(j,0,m){
			l=0;
			REP(k,0,v[j].size()){
				q=v[j][k];
				if((i>>q)&1)
					l^=1;
			}
			if(l!=p[j])
				goto f;
		}
		ans++;
		f:;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
	int n,p,d1,d2,maxp,maxv;
	while(stdIn.hasNextInt()){
	    n = stdIn.nextInt();
	    if(n == 0) break;
	    maxp = maxv = 0;
	    for(int i = 0;i < n;i++){
		p = stdIn.nextInt();
		d1 = stdIn.nextInt();
		d2 = stdIn.nextInt();
		if(maxv < d1+d2){
		    maxp = p;
		    maxv = d1 + d2;
		}
	    }
	    System.out.printf("%d %d\n",maxp,maxv);
	}
    }
}

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

using namespace std;

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

    int x;
    cin >> x;
    if (x >= 30)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 3624
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
from functools import lru_cache
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())


n,k = inpl()
h = inpl()
dp = [INF] * (n)
dp[0] = 0
for i in range(min(n,k)):
    dp[i] = abs(h[i] - h[0])
for i in range(n - k):
    option=[dp[i+j]+abs(h[i+k]-h[i+j]) for j in range(k)]
    dp[i + k] = min(option)
print(dp[n - 1])

Measured memory_bytes: 57244
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
#define pii pair<int, int>
#define pt(xx) cout << "\n" \
                    << xx << "\n"
#define debugv(x, n)               \
    cout << "\n"                   \
         << #x << ": ";            \
    rep(i, n) cout << x[i] << " "; \
    cout << endl
#define debug2d(x, m, n)            \
    cout << "\n"                    \
         << #x << " is: \n";        \
    for (int i = 0; i < m; ++i)     \
    {                               \
        for (int j = 0; j < n; ++j) \
        {                           \
            cout << x[i][j] << " "; \
        }                           \
        cout << endl;               \
    }
#define nl cout << endl

#define MOD 1000000007
template <class T> inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

int N, M, K;
int ans;

signed main()
{
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //==============================================
    cin >> N >> M;

    vector<vector<pii>> pref(N);
    int a,b,c;
    vector<pair<int,vector<int>>> bd(N);
    vector<pair<int,int>> l(M);
    rep(i,M){
        cin>>a>>b;
        --a;
  //      city[i] = make_pair(a,b);
        pref[a].push_back(make_pair(b,i));

        l[i]=(make_pair(a,b));
    }


    int tmp;
    pair<int,int> id[M];
    rep(i,N){
        sort(pref[i].begin(),pref[i].end());
        rep(j,pref[i].size()){
            id[pref[i][j].second] = make_pair(i+1,j+1); 
        }
    }
    
    rep(i,M){
       // cout<<id[i].first<< " " << id[i].second<<endl;
        printf("%06ld%06ld\n",id[i].first,id[i].second);
    }

    return 0;
}

Measured memory_bytes: 13184
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_061_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(14).
    01 A      PIC S9(3).
    01 B      PIC S9(3).
    01 C      PIC S9(3).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO A B C.

    IF A <= C AND C <= B THEN
        DISPLAY "Yes"
    ELSE
        DISPLAY "No"
    END-IF.

    STOP RUN.


Measured memory_bytes: 764
M, D = map(int, input().split())
ans = 0
for m in range(1, M + 1):
    for d in range(1, D + 1):
        if d < 10:
            continue
        d1 = int(str(d)[1])
        d2 = int(str(d)[0])
        if d1 >= 2 and d2 >= 2 and d1 * d2 ==m:
            ans += 1
            
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

/////////////         qsortのラッピング

int qsort_int_compare_ascend(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
int qsort_int_compare_descend(const void* a, const void* b) {
	return *(int*)b - *(int*)a;
}
void ascendOrder(int size, int* array) {//昇順
	qsort(array, size, sizeof(int), qsort_int_compare_ascend);
}
void descendOrder(int size, int* array) {//降順
	qsort(array, size, sizeof(int), qsort_int_compare_descend);
}

int main() {
	int N; cin >> N;
	int* v = new int[N];

	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}

	descendOrder(N, v);

	double sum = 0;
	double p = 0.5;
	for (int i = 0; i < N; i++) {
		sum += (double)v[i] * p;
		if (i != N - 2) { p *= 0.5; }
	}

	printf("%.9f\n", sum);

	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 999999999999999;
const ll MOD = 998244353;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, ans = 0, w, l;
vl A, B, C;
void input() {
	cin >> n >> k;
}
void solve() {
	a = (2 * k + 3 * n - 1) * (3 * n) / 2;
	b = (2 * k + 2 * n - 1) * (2 * n) / 2;
	if (b * 2 > a) {
		cout << -1 << endl;
		return;
	}

	A = vl(n);
	B = vl(n);
	C = vl(n);

	x = k;
	y = k + n;
	z = k + 2 * n;
	rep(i, n) {
		C[i] = z + i;
	}
	rep(i, (n+1) / 2) {
		A[i * 2] = x;
		x++;
	}

	rep(i, n / 2) {
		B[i * 2 + 1] = y;
		y++;
	}

	rep(i, (n + 1) / 2) {
		B[i * 2] = y;
		y++;
	}

	rep(i, n / 2) {
		A[i * 2 + 1] = x;
		x++;
	}

	rep(i, n) {
		cout << A[i] << " " << B[i] << " " << C[i] << endl;
	}
}

int main() {
	input();
	solve();
}

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

public class Main{

	public static void main(String[] args){
		solve();
	}

	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int t = sc.nextInt();
		int[] time = new int[10010];
		int ans = 0;
		for(int i=0;i<n;i++){
			time[sc.nextInt()]=1;
		}
		int now = 0;
		for(int i=0;i<t;i++){
			if(time[i]!=0){
				if(now==0){
					ans += Math.max(0,i-m);
					now = i;
				}
				else{
					ans += Math.max(0,i-now-2*m);
					now = i;
				}
			}
		}
		ans += Math.max(0,t-now-m);
		System.out.println(ans);
	}
}

Measured memory_bytes: 26268
#include<bits/stdc++.h>;
using namespace std;
//#define LOCAL
typedef long long ll;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
int main(){
#ifdef LOCAL
     freopen("in.txt", "r", stdin);
     //freopen("out.txt", "w", stdout);
#else
 fastIO;
#endif
//***************************//**************************//******************************
    string n;
    cin>>n;
    char p = n[n.size()-1];
    if(p=='2' || p=='4' || p=='5' || p=='7' || p=='9'){
        cout<<"hon"<<endl;
    }else if(p=='0' || p=='1' || p=='6' || p=='8'){
        cout<<"pon"<<endl;
    }else if(p=='3'){
        cout<<"bon"<<endl;
    }

}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main(void) {
	int N, A;
	cin >> N;
	if (N == 1) {
		cin >> A;
		int sum = A;
		cin >> A;
		sum += A;
		cout << sum << endl;
		exit(0);
	}

	int start, goal;
	cin >> start;
	vector<int> n1(N - 1);
	vector<int> n2(N - 1);
	for (int i = 0; i < N - 1; ++i) cin >> n1[i];
	for (int i = 0; i < N - 1; ++i) cin >> n2[i];
	cin >> goal;
	int max_ans = 0;
	int sum_n1 = 0;
	for (int i = 0; i < N - 1; ++i) {
		sum_n1 += n1[i];
		int ans = sum_n1;
		for (int j = i + 1; j < N - 1; ++j) {
			ans += n2[j];
		}
		max_ans = max(max_ans, ans);
	}
	//全部n2が抜けてる
	int sum_n2 = accumulate(n2.begin(), n2.end(), 0);
	max_ans = max(max_ans, sum_n2);

	max_ans += start;
	max_ans += goal;
	cout << max_ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    money = 0
    for _ in range(N):
        x, u = input().split()
        if u == "JPY": money += int(x)
        else: money += float(x) * 380000
    print(money)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define inf 1000000007
#define mod 1000000007
using namespace std;
template <typename T> T Max(T x,T y){return x>y?x:y;}
template <typename T> T Min(T x,T y){return x<y?x:y;}
template <typename T> void chmax(T &x,T y){x=x>y?x:y;return;}
template <typename T> void chmin(T &x,T y){x=x<y?x:y;return;}

int x;

int main()
{
	cin>>x;
	cout<<1-x<<endl;
	return 0;
}

Measured memory_bytes: 3632
N = int(input())
src = list(map(int,input().split()))
dic = {}
for n in range(N):
  if dic.get(src[n]) == None:
    dic[src[n]] = 1
  else:
    dic[src[n]] += 1
a = 0
for key, value in dic.items():
  a += value*(value-1)//2
ans = []
for s in src:
  ans.append(a - dic[s]*(dic[s]-1)//2 + (dic[s]-1)*(dic[s]-2)//2)
for b in ans:
  print(b)

Measured memory_bytes: 27408
import java.util.Scanner;


public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        long a = nextLong();
        long v = nextLong();
        long b = nextLong();
        long w = nextLong();
        long t = nextLong();
        if((v-w)*t-(Math.abs(a-b))>=0){
            System.out.println("YES");
        }
        else System.out.println("NO");
    }

    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }

    //print
    public static void print(Object a){
        System.out.println(a);
    }


    //gcd
    public static int gcd (int a, int b){
        int tmp;
        while((tmp = a%b) != 0){
            a = b;
            b = tmp;
        }
        return b;
    }


    //lcm
    public static int lcm(int a,int b){
        int tmp;
        long c = a;
        c *= b;
        while((tmp = a%b) != 0){
            a = b;
            b = tmp;
        }
        return (int)(c/b);
    }
}

Measured memory_bytes: 35696
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  
  cin >> N;
int sum = 0;
  vector<int>  W(N);
  for(int a = 0;a < N;a++){
    cin >> W[a];
    sum += W[a];
  }
  int k = 0;
  
  int result = 1000000;
  for(int a = 0;a < N;a++){
    k += W[a];
    if(abs(sum - k - k) < result)result = abs(sum - k - k);
    
  }
  cout << result << endl;
}


Measured memory_bytes: 3576
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
	fastio;
	set<char> st;
	int a = 0;
	string s;
	cin >> s;
	for(int i = 0; i < len(s); i++){
		if(st.count(s[i])) a++;
		st.insert(s[i]);
	}
	if(len(st) == 2 and a == 2) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
def DFS(num):
    if 3<=len(num)<=m:
        if len(set(list(num)))==3:
            A.append(int(num))
    if len(num)<=m:
        for i in ["3","5","7"]:
            DFS(num+i)


n=input()
m=len(n)
A=[]
for i in ["3","5","7"]:
    DFS(i)

cnt=0
for i in A:
    if i<=int(n):
        cnt +=1
print(cnt)

Measured memory_bytes: 60380
//https://atcoder.jp/contests/agc026/tasks/agc026_b

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

int t;
long long a, b, c, d;

void solve(){
    cin >> a >> b >> c >> d;
    if (a > c) a = c + 1 + (a - c - 1) % b;
    if (a < b) return void(cout << "No\n");
    if (b > d) return void(cout << "No\n");
    if (b <= c+1) return void(cout << "Yes\n");
    long long x = __gcd(d, b);
    a -= b;
    a = a + (c - a + x) / x * x;
    if (a < b) return void(cout << "No\n");
    cout << "Yes\n";
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> t;
    while (t--) solve();
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    long long n,k;
    cin>>n>>k;
    long long a[n];
    long long sum[n+1];
    sum[0]=0;
    rep(i,n)cin>>a[i];

    rep(i,n)sum[i+1]=sum[i]+a[i];
    
    long long second[45];
    second[0]=1;
    rep(i,44)second[i+1]=second[i]*2;

    long long ans=0;
    long long SIZE=(n*(n+1))/2;
    vector<long long>part_sum(SIZE);
    long long now=0;
    for(int i=0;i<n;i++){
        for(int l=i+1;l<=n;l++){
            part_sum[now++]=sum[l]-sum[i];
        }
    }
    for(int i=44;i>-1;i--){
        int cnt=0;
        bool select[SIZE]={};

        rep(l,SIZE){
            if(part_sum[l]<0)continue;

            if(second[i]&part_sum[l]){
                select[l]=true;
                cnt++;
            }
        }

        if(cnt>=k){
            ans|=second[i];
            rep(l,SIZE){
                if(!select[l]){
                part_sum[l]=-1;
                }
            }
        }
    }
    //cout<<second[44]<<endl;
    cout<<ans<<endl;
    return 0;

}
/*


*/


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

int main() {
    long long n, x, t;
    cin >> n >> x >> t;
    long long sum = 0, sol = 0;
    while(sum < n) {
        sum += x;
        sol += t;
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 3620
/********************/
                    /*user -> tushar284*/
                    /******************/
#include<bits/stdc++.h>
                                                    /*********/            
using namespace std;                             /*   __   __   */
#define  f              first                    /*   @ ) ( @   */
#define  s              second                   /*     / \     */            
#define  mp             make_pair                /*  __  -  __  */
#define  loop(i,s,e)    for(int i=s;i<e;i++)     /*    ..^..    */
#define  rev(i,s,e)     for(int i=s;i>=e;i--)     /*     |     */
#define  mod            1000000007                  /*   |   */
#define  pb             push_back                      /***/
#define  start	        int main()                     
#define  fast           ios_base::sync_with_stdio(false);cin.tie(0);
#define  test           fast int t; cin>>t;while(t--)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
int no_of_fact(int num){
    int cnt =0;
    loop(i,1,int(sqrt(num))+1){
        if(num%i==0){
            cnt++;
            if(num/i != i)cnt++;
        }
    }
    return cnt;
}

start
{   
    map<int,int>ans;
    int n;
    cin>>n;
    loop(i,1,n){
        int boss;
        cin>>boss;
        ans[boss]++;
    }
    loop(i,1,n+1)cout<<ans[i]<<"\n";
    return 0;
}


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

const int mod = 1e9 + 7;
int dp[100005][2];

int main() {
	string s; cin >> s;
	int n = s.size();
	dp[0][0] = 1;

	for (int i = 0; i < n; i++) {
		{// a+b=0
			if (s[i] == '0') {
				dp[i + 1][0] = dp[i][0];
				dp[i + 1][1] = dp[i][1];
			}
			else {
				dp[i + 1][1] = (dp[i][0] + dp[i][1]) % mod;
			}
		}
		{//a+b=1
			if (s[i] == '0') {
				(dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
			}
			else {
				(dp[i + 1][0] += dp[i][0] * 2 % mod) % mod;
				(dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
			}
		}
	}
	int ans = (dp[n][0] + dp[n][1]) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1280
# coding: utf-8
# Your code here!
import math

n = int(input())
r = []
p = list(map(int, input().split()))
q = list(map(int, input().split()))
for i in range(n):
    r.append(i+1)

count =0
a=1
b=1
while(count<n):
    for i in r:
        if p[count] ==i :
            count+=1
            r.remove(i)
            break;
        else:
            a+=math.factorial(n-count-1)
r = [] 
for i in range(n):
    r.append(i+1)
count = 0
while(count<n):
    for i in r:
        if q[count] ==i :
            count+=1
            r.remove(i)
            break;
        else:
            b+=math.factorial(n-count-1)           
print(abs(a-b))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>

int main() {
	int h, w;
	std::cin >> h >> w;
	std::string s[100];
	for (int i = 0;i < h;i++) {
		std::cin >> s[i];
	}
	for (int i = 0;i < w + 2;i++) {
		std::cout << '#';
	}
	std::cout << std::endl;
	for (int i = 0;i < h;i++) {
		std::cout << '#' << s[i] << '#' << std::endl;
	}
	for (int i = 0;i < w + 2;i++) {
		std::cout << '#';
	}
	std::cout << std::endl;
	return 0;
}
	


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int S,h,m,s;
    scanf("%d",&S);

    h = S / 3600;
    m = (S - h*3600)/60;
    s = S - h*3600 - m*60;

    printf("%d:%d:%d\n", h ,m ,s);
  return 0;
}

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

signed main(){
    long long R, G, B, N;
    cin >> R >> G >> B >> N;

    int count = 0;
    for(int i = 0; i <= N/R; i++){
        for(int j = 0; j <= N/G; j++){
            if(N - R*i - G*j >= 0 && (N - R*i - G*j) % B == 0){
                count++;
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	long long n, m, d;
	double ans;
	cin >> n >> m >> d;
	ans = ((double)m - 1.0) / (double)(n * n);
	if (d == 0)
		ans *= (double)n;
	else
		ans *= (double)((n - d) << 1);
	printf("%.9lf\n", ans);
	return 0;
}

Measured memory_bytes: 256
package main

import (
        "fmt"
)

func main() {
        var n int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt := 0
                for a := 0; a < 10; a++ {
                        for b := 0; b < 10; b++ {
                                for c := 0; c < 10; c++ {
                                        for d := 0; d < 10; d++ {
                                                if a+b+c+d == n {
                                                        cnt++
                                                }
                                        }
                                }
                        }
                }
                fmt.Printf("%d\n", cnt)
        }
}



Measured memory_bytes: 1132
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin>>s>>t;
	string ans = "|";
	for(int i = 0; i<=int(s.length())-int(t.length()); i++)
	{
		bool f = 1;
		string t2;
		for(int j = 0; j<t.length(); j++)
		{
			if(s[i+j]!=t[j] && s[i+j]!='?') f = 0;
		}
		if(f)
		{
			t2 = s;
			replace(t2.begin(),t2.end(),'?','a');
			t2 = t2.substr(0,i)+t+t2.substr(i+t.length());
			ans = min(ans,t2);
		}
	}
	if(ans=="|")
		cout<<"UNRESTORABLE"<<endl;
	else
		cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

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

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    cin >> com;
    if ( com == "insert") {
      scanf("%d", &x);
      insert(x);
    } else if (com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 26748
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 998244353;

int main() {
    int n, s;
    cin >> n >> s;
    vector<ll> dp(s + 1);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        vector<ll> after(s + 1);
        for (int j = 0; j <= s; j++) {
            if (j + a <= s) after[j + a] += dp[j], after[j + a] %= MOD;
            after[j] += dp[j] * 2, after[j] %= MOD;
        }
        dp = after;
    }

    cout << dp[s] << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,k;
  cin >> n >> k;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];
  REP(i,n-k) { Yes(a[i+k] > a[i]); }
  return 0;
}


Measured memory_bytes: 4744
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

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

class CHAndV {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
int h,w,k;
cin>>h>>w>>k;
        vector<vector<bool>> mat(h, vector<bool>(w,false));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                char c;
                cin>>c;
                if (c=='#') mat[i][j]=true;
            }
        }
        int ans=0;
        for (int i = 0; i < 1<<h; i++) {
            for (int j = 0; j < 1<<w; j++) {
                vector<vector<bool>> tmp(mat);
                for (int l = 0; l < h; l++) {
                    for (int m = 0; m < w; m++) {
                        if (i&(1<<l)){
                            for (int n = 0; n < w; n++) {
                                tmp[l][n]=false;
                            }
                        }
                        if (j&(1<<m)){
                            for (int n = 0; n < h; n++) {
                                tmp[n][m]=false;
                            }
                        }
                    }
                }
                int cnt=0;
                for (int i1 = 0; i1 < h; i1++) {
                    for (int n = 0; n < w; n++) {
                        if (tmp[i1][n]) cnt++;
                    }
                }
                if (cnt==k) ans++;
            }
        }
        cout<<ans;
	}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    CHAndV solver;
    solver.solve(in, out);
}


Measured memory_bytes: 3656
A, B, C = map(int, input().split())

if A == B == C and A%2==0:
    print(-1)
else:
    cnt = 0
    while A%2 == B%2 == C%2 == 0:
        x = (B+C)//2
        y = (A+C)//2
        z = (A+B)//2
        A = x
        B = y
        C = z
        cnt += 1
    print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
const int maxn=2e3+10;
const int mod=1e9+7;
int a[maxn];
int l[maxn];
int sum[maxn];
using namespace std;
main(){
    int n,k;
    cin>>n>>k;
    memset(l,0ll,sizeof(l));
    memset(sum,0ll,sizeof(sum));
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            if(j==i)continue;
            if(a[j]>a[i]){
                if(j<i)
                    l[i]++;
                sum[i]++;
            }
        }
    }
    int s=0;
    int tmp=(k-1)*k/2%mod;
    for(int i=1;i<=n;++i){
        s=(s+((sum[i]*tmp)%mod))%mod;
        s=(s+((l[i]*k)%mod))%mod;
    }
    printf("%lld\n",s);
}


Measured memory_bytes: 256
#include <stdio.h> 
int i,j; 
int count=0; 

 
void Process(int A[ ], int n){ 
 for(i=0;i<n-1;i++) 
  printf("%d ",A[i]); 
 printf("%d\n",A[i]); 
} 

 
void BubbleSort(int A[ ], int n){ 
 int j,temp; 
  for(i = 0; i < n-1; i++){ 
   for(j = n-1; j > i; j--) 
   if(A[j-1] > A[j]){ 
    temp = A[j-1]; 
    A[j-1] = A[j]; 
    A[j] = temp; 
    count++; 
   }   
 } 
} 

 
int main(void){ 
 int N; 
 scanf("%d",&N); 
 int A[100]; 
 for(i=0;i<N;i++) 
  scanf("%d",&A[i]); 
  
 BubbleSort(A, N); 
 Process(A, N); 

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

Measured memory_bytes: 1828
s = gets.chomp
ss = s.chars

count1 = 0
ss.each.with_index do |c, i|
  if i % 2 == 0
    if c == "0"
      count1 += 1
    end
  else
    if c == "1"
      count1 += 1
    end
  end
end

count2 = 0
ss.each.with_index do |c, i|
  if i % 2 == 0
    if c == "1"
      count2 += 1
    end
  else
    if c == "0"
      count2 += 1
    end
  end
end

puts [count1, count2].min


Measured memory_bytes: 9468
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

int main() {
  int n, x; std::cin >> n >> x;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  std::sort(a.begin(), a.end());

  int count = 0;
  for (int i = 0; i < n-1; i++) {
    if (a[i] > x) break;
    x -= a[i];
    count++;
  }

  if (a[n-1] == x) count++;
  std::cout << count << std::endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc050/tasks/abc050_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    char c;
    cin >> a >> c >> b;
    if (c == '+') {
        cout << a + b << endl;
    } else {
        cout << a - b << endl;
    }
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep1(i,n) for(int i = 1; i < (int)(n); i++)

using ll = long long;

int main(){
    int n,m;
    cin >> n >> m;
    ll ans = 0;
    ans = (1900*m+100*(n-m))*pow(2,m);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
A, B, C, D, E, F = map(int, input().split())
V = 0
ans = ()
for i in range(F//(A*100)+1):
  for j in range(F//(B*100)+1):
    m = A*i + B*j
    m = m*100
    if m>F or m==0:
      continue
    lim = min(m*E//100, F-m)
    
    l = lim
    w = 0
    z = 0
    for x in range(lim//C+1):
      for y in range(lim//D+1):
        n = x*C+y*D
        if n>lim:
          continue
        if lim-n<l:
          l = lim-n
          w = x
          z = y
    s = w*C+z*D
    v = 100*s/(m+s)
    if v>=V:
      ans = (m+s,s)
      V = v
print(*ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int x,y,x1,y1,sum;
//	while(cin>>x>>y)
//	{sum=0;
	scanf("%d%d",&x,&y);
	if(x==y) {printf("0\n");return 0;}
	if(x!=0&&y!=0)
	{
		x1=abs(x);y1=abs(y);
		sum=abs(y1-x1);
		if((x<0&&y>0)||(x>0&&y<0)) sum++;
		if(x<0&&y<0&&x>y) sum+=2;
		if(x>0&&y>0&&x>y) sum+=2;
	}
	if(x==0)
	{
		if(y<0) sum=x-y+1;
		if(y>0) sum=y-x;
	}
	if(y==0)
	{
		if(x>0) sum=x-y+1;
		if(x<0) sum=y-x;
	}
	printf("%d\n",sum);
//	}
	return 0;
}

Measured memory_bytes: 256
use std::io;
 
fn main() {
	let stdin = io::stdin();
    let mut buf = String::new();
    
    stdin.read_line(&mut buf).unwrap();
    let xab: Vec<isize> = buf.split_whitespace().map(|n| n.parse().unwrap()).collect();

    if -xab[0] <= xab[1] - xab[2]  {
        if xab[1] - xab[2] >= 0 {
            println!("delicious");
        } else {
    	    println!("safe");
    	}
    } else {
    	println!("dangerous");
    }
}

Measured memory_bytes: 4352
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N=intput()
L=[]
ans=[]
for _ in range(N-1):
    L.append(lint())
for i in range(N):
    tmp = 0
    for j in range(i,N-1):
        c,s,f=L[j]
        tmp = max(((tmp-1)//f+1)*f,s)+c
    ans.append(tmp)
lprint(ans)

Measured memory_bytes: 75276
#include<bits/stdc++.h>
using namespace std;
const int maxm=2e6+5;
char s[maxm];
int n;
struct SAM{
    int ch[maxm][26];
    int fa[maxm],l[maxm];//l[]是等价类的最长字符串长度len
    int last=1,tot=1;//tot是节点数量
    //
    int lc[maxm],rc[maxm];
    int cnt[maxm];
    int idx[maxm];
    int solve(){
        //基数排序
        for(int i=0;i<=tot;i++)cnt[i]=0;
        for(int i=1;i<=tot;i++)cnt[l[i]]++;
        for(int i=1;i<=tot;i++)cnt[i]+=cnt[i-1];
        for(int i=1;i<=tot;i++)idx[cnt[l[i]]--]=i;
        //逆向拓扑
        for(int i=tot;i>=1;i--){
            int x=idx[i];
            if(!lc[fa[x]]||lc[x]<lc[fa[x]]){
                lc[fa[x]]=lc[x];
            }
            if(!rc[fa[x]]||rc[x]>rc[fa[x]]){
                rc[fa[x]]=rc[x];
            }
        }
        //
        int ans=0;
        for(int i=1;i<=tot;i++){
            if(rc[i]-lc[i]>=l[i]){
                ans=max(ans,l[i]);
            }else{
                ans=max(ans,rc[i]-lc[i]);
            }
        }
        return ans;
    }
    //
    void add(int c,int pos){//传入s[i]-'a'而不是s[i]
        int p=last,np=++tot;last=np;l[np]=l[p]+1;
        for(;p&&!ch[p][c];p=fa[p])ch[p][c]=np;
        if(!p)fa[np]=1;
        else{
            int q=ch[p][c];
            if(l[p]+1==l[q])fa[np]=q;
            else{
                int nq=++tot;l[nq]=l[p]+1;
                memcpy(ch[nq],ch[q],sizeof ch[q]);
                fa[nq]=fa[q];fa[q]=fa[np]=nq;
                for(;ch[p][c]==q;p=fa[p])ch[p][c]=nq;
            }
        }
        //记录最左和最右位置
        lc[np]=rc[np]=pos;
    }
    void init(){
        for(int i=1;i<=tot;i++){
            memset(ch[i],0,sizeof ch[i]);
            fa[i]=l[i]=0;
        }
        last=tot=1;
    }
}S;
signed main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    S.init();
    for(int i=1;i<=n;i++){
        S.add(s[i]-'a',i);
    }
    int ans=S.solve();
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4876
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  
  if(s.at(0) == s.at(1) || s.at(0) == s.at(2) || s.at(1) == s.at(2)) cout << "No" <<endl;
  else cout <<"Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1)*a%MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1)*a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b,a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size()>n) return kaijo_memo[n];
  if(kaijo_memo.size()==0) kaijo_memo.push_back(1);
  while(kaijo_memo.size()<=n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1]*kaijo_memo.size()%MOD);
  return kaijo_memo[n];
}

signed main(){
	int n; cin>>n;
	VI t;
	int ans=0;
	rep(i,n){
		int s; cin>>s;
		ans+=s;
		if(s%10) t.PB(s);
	}
	if(ans%10==0){
		if(t.size()){
			sort(ALL(t));
			cout<<ans-t[0]<<endl;
		}else{
			cout<<0<<endl;
		}
	}else{
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce

def main():
    N = int(input())
    h = list(map(int, input().split()))

    ans = 0
    while h != [0] * N:
        if h[0] != 0:
            ans += 1
        for i in range(1, N):
            if h[i - 1] == 0 and h[i] != 0:
                ans += 1
        for i in range(N):
            if h[i] > 0:
                h[i] -= 1
    print(ans)


def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b

if __name__ == '__main__':
    main()


Measured memory_bytes: 77592
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        boolean bool = true;
        if(n % 2 != 0){
            System.out.println("No");
            return;
        }
        for(int i = 0; i < n/2; i++){
            if(s.charAt(i) != s.charAt(n/2+i)){
                bool = false;
                break;
            }
        }
        if(bool){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}



Measured memory_bytes: 21716
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>


int main(){
  int N;
  scanf("%d", &N);
  int n = (N+999)/1000;
  int ans = n*1000-N;
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 3256