akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

inline void solve(){

    int n;
    cin >> n;
    vector<int> a(n);
    int n2 = 0, a4 = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i]%2!=0) n2++;

        if(a[i]%4==0) a4++;
    }

    if(n2 <= a4 + (n2+a4==n)) cout << "Yes\n";
    else cout << "No\n";
    
    
    
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <math.h>
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 500;
int a[N][N], td[N][N];
vector < pair < int, int > > g[N];
vector < pair < int, pair < int, int > > > b;
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            cin >> a[i][j];
            if (i < j){
                b.pb({a[i][j], {i, j}});
            }
        }
    }
    int ans = 0;
    sort(b.begin(), b.end());
    for (auto i: b){
        int s = i.S.F;
        int f = i.S.S;
        int t = 1;
        for (int l = 1; l <= n; l++){
            if (l != s && l != f && a[s][l] + a[l][f] == a[s][f]) t = 0;
        }
        if (t){
            g[s].pb({f, a[s][f]});
            g[f].pb({s, a[s][f]});
            ans += a[s][f];
        }
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            td[i][j] = 1e15;
        }
    }
    for (int i = 1; i <= n; i++) td[i][i] = 0;
    for (int i = 1; i <= n; i++){
        for (auto j: g[i]) td[i][j.F] = j.S;
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            for (int l = 1; l <= n; l++){
                td[j][l] = min(td[j][l], td[j][i] + td[i][l]);
            }
        }
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            if (td[i][j] != a[i][j]){
                cout << -1;
                return 0;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 6260
#include <stdio.h>
void solve(void)
{
	int w, h, n;
	int t, b, l, r;
	scanf("%d %d %d", &w, &h, &n);
	t=h; b=0; l=0; r=w;
	while(n-->0){
		int x,y,a;
		scanf("%d %d %d", &x, &y, &a);
		switch(a){
			case 1:
				l = (l>x?l:x);
				break;
			case 2:
				r = (r<x?r:x);
				break;
			case 3:
				b = (b>y?b:y);
				break;
			case 4:
				t = (t<y?t:y);
				break;
		}
	}
	if(l>r)
		l=r;
	if(b>t)
		b=t;
	printf("%d\n", (r-l)*(t-b));
}
int main(int argc, char **argv)
{
	solve();
	return 0;
}


Measured memory_bytes: 128
n = gets.chomp.to_i
arr = []
a = []
n.times do |i|
    w = gets.chomp
    # if i != 0
    #     arr << w
    #     if arr.include?(w)
    #         puts "No"
    #         exit
    #     end
    #     b = a.pop
    #     a << w
    #     if b[-1] != w[0]
    #         puts "No"
    #     end
    # elsif i == 0
    #     arr << w
    #     a << w
    # end
    arr << w
end

kizyun = arr.size
ato = arr.uniq
atosize = ato.size
while true
if atosize != kizyun
    puts "No"
    break
end
hatu = arr.shift
arr.each do |i|
    if hatu[-1] != i[0]
        puts "No"
        exit
    end
    hatu = i
end
puts "Yes"
break
end



Measured memory_bytes: 14300
import sys
input = sys.stdin.readline

def main():
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    mod=10**9+7
    """
    kを決めるかxを決めるか，
    kを決めればxが一意に決まり，N個試してO(N^2)
    xを決めればどうなるんだろう．
    ai全部にxorして，それをずらせばbになるならok．なんかもう少しうまくできそう．
    
    解説読んだ.
    全部のところに同じ操作をしている=>2箇所を使うことでうまく追加分を打ち消すことを考える．
    隣接2箇所を選びxorすれば xor xの部分が消える（もし+xなら2箇所選んで引けば良いというお話）
    
    shiftしたものが一致するか知る方法=>aとbなら，a*2の中にbがあるか探す．ここでKMP法やz-algoritmを使う
    
    
    """
    
    def Z(s):
        n=len(s)
        lcp=[0]*n
        lcp[0]=n
        L,R=0,0
        for i in range(1,n):
            if(i>=R): # 過去の結果の再利用が不可
                L=i
                R=i
                while(R<n and s[R-L]==s[R]):
                    R+=1
                lcp[i]=R-L
            elif(lcp[i-L]<R-i): # 過去の結果を再利用
                lcp[i]=lcp[i-L]
            else: # 過去の結果を一部再利用
                L=i
                while(R<n and s[R-L]==s[R]):
                    R+=1
                lcp[i]=R-L
        return lcp
    
    N=I()
    a=LI()
    b=LI()
    a+=[a[0]]
    b+=[b[0]]
    
    #隣接二項のxorがrotateしてることが必要
    a2=[0]*N
    b2=[0]*N
    for i in range(N):
        a2[i]=a[i+1]^a[i]
        b2[i]=b[i+1]^b[i]
        
    #a2*2の中にb2があるか見たい，abbに対してZしてi>=Nで，LCPがN以上の場所
    
    K=[]
    abb=a2+b2+b2
    L=Z(abb)
    
    for i in range(N,2*N,1):
        if L[i]>=N:
            K.append((2*N-i)%N)
            
    X=[]
    for k in K:
        x=b[0]^a[k]
        X.append(x)
    
    if K!=[]:
        K,X=zip(*sorted(zip(K,X)))
    else:
        exit()
        
    for i in range(len(K)):
        print(K[i],X[i])
        

    

main()


Measured memory_bytes: 169804
#include<stdio.h>

int main() {
	long long n, d, x, y;
	long long count = 0;
	
	scanf("%lld %lld", &n, &d);
	
	for (long long i = 0; i < n; i++)
	{
		scanf("%lld %lld", &x, &y);
		if (x * x + y * y <= d * d)
		{
			count++;
		}
	}
	printf("%lld", count);
	
	
	
	return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<string>
#include<sstream>
#include<stdio.h>
using namespace std;

int main(){
  int i,j;
  char a;
  char b[3][3];
  char t;
  
  string str;
 
  while(getline(cin,str)){
    istringstream iss(str);
 
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
	iss>>t;
	b[i][j]=t;
      }
    }
 
          if(b[0][0]==b[0][1]&&b[0][1]==b[0][2]&&b[0][0]!='s'){
      a=b[0][0];
    }else if(b[1][0]==b[1][1]&&b[1][1]==b[1][2]&&b[1][0]!='s'){
      a=b[1][0];
    }else if(b[2][0]==b[2][1]&&b[2][1]==b[2][2]&&b[2][0]!='s'){
      a=b[2][0];
    }else if(b[0][0]==b[1][0]&&b[1][0]==b[2][0]&&b[0][0]!='s'){
      a=b[0][0];
    }else if(b[0][1]==b[1][1]&&b[1][1]==b[2][1]&&b[0][1]!='s'){
      a=b[0][1];
    }else if(b[0][2]==b[1][2]&&b[1][2]==b[2][2]&&b[0][2]!='s'){
      a=b[0][2];
    }else if(b[0][0]==b[1][1]&&b[1][1]==b[2][2]&&b[0][0]!='s'){
      a=b[0][0];
    }else if(b[0][2]==b[1][1]&&b[1][1]==b[2][0]&&b[0][2]!='s'){
      a=b[0][2];
    }else{
      a='d';
    }
   printf("%c\n",a);
  }
}

Measured memory_bytes: 1204
#include <stdio.h>

#define MAX_N 50

int main(void) {
    int n;
    int score[MAX_N];

    scanf("%d\n", &n);

    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        score[i] = x;
    }

    int sum = 0;

    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            sum += score[i] * score[j];
        }
    }

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

    return 0;
}


Measured memory_bytes: 128
#include <math.h>
#include <stdio.h>

int
main()
{
	int i;
	int n;
	int s[1000];
	double avg, variance, standard_deviation;
	for (;;)
	{
		scanf("%d", &n);

		if (n == 0)
			break;

		for (i = 0; i < n; i++)
		{
			scanf("%d", &s[i]);
		}

		avg = 0.0;
		for (i = 0; i < n; i++)
		{
			avg += s[i];
		}
		avg /= n;

		variance = 0;
		for (i = 0; i < n; i++)
		{
			variance += pow(s[i]-avg, 2);
		}
		variance /= n;

		standard_deviation = sqrt(variance);
		printf("%f\n", standard_deviation);
	}

	return 0;
}

Measured memory_bytes: 636
l,r = gets.split.map(&:to_i)

min = 2018
l.upto([r-1, l + 2018].min) do |i|
  imod = i % 2019
  (i+1).upto([r, (i+1) + 2018].min) do |j|
    jmod = j % 2019
    tmp_min = imod * jmod % 2019
    if tmp_min < min
      min = tmp_min
    end
  end
end

puts min

Measured memory_bytes: 1788
IDENTIFICATION DIVISION.
PROGRAM-ID. 163B.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(60000).
*>
WORKING-STORAGE SECTION.
01 INW        PIC X(13).
01 N          PIC 9(7) COMP.
01 M          PIC 9(5) COMP.
01 V          PIC 9(9) COMP.
01 W          PIC 9(5) COMP.
01 I          PIC 9(5) COMP.
01 P1         PIC 9(5) COMP.
01 P2         PIC 9(5) COMP.
01 OUT        PIC -(7)9.
*>
PROCEDURE DIVISION.
  ACCEPT INW.
  UNSTRING INW DELIMITED BY ' '
      INTO N M.
*>
  OPEN INPUT STDIO.
  READ STDIO.
  CLOSE STDIO.
*>
  MOVE 0 TO V.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > M
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO W
    ADD W TO V
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  IF (N >= V)
    COMPUTE OUT = N - V
  ELSE
    MOVE -1 TO OUT
  END-IF.
*>
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


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

bool check(ll x, vector<ll> a){
  bool canDiv = true;
  ll N = a.size();
  for(int i = 0; i < N; i++){
    if(!(x % a[i] == 0 && ((x / a[i]) % 2 == 1))){
      canDiv = false;
      break;
    }
  }
  return canDiv;
}

int main() {
  ll N, M; cin >> N >> M;
  vector<ll> a(N, 0);

  ll ma = 0, ans = 0;
  for(int i = 0; i < N; i++){
    cin >> a[i];
    a[i] /= 2;
    ma = max(ma, a[i]);
  }
  
  ll minh = M+1;
  for(ll x = ma; x <= M; x += ma){
    bool canDiv = true;
    for(int i = 0; i < N; i++){
      if(!(x % a[i] == 0 && ((x / a[i]) % 2 == 1))){
        canDiv = false;
        break;
      }
    }
    if(canDiv){
      minh = x;
      break;
    }
  }
  cout << ((minh != M+1)?(M + minh) / (2 * minh):0) << endl;
}

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

int main(void) {
  int n, k, q; cin >> n >> k >> q;
  int *a = new int[n];
  for (int i = 0; i < n; i++) a[i] = k;
  for (int i = 0; i < q; i++) {
    int t; cin >> t;
    a[t-1]++;
  }
  for (int i = 0; i < n; i++) {
    a[i] -= q;
    if (a[i] <= 0) cout << "No\n";
    else cout << "Yes\n";
  }

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int k[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    while(cin>>n){
        cout<<k[n-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

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

    vector<ll> h(N);
    for(int i = 0;i < N;i++)
        cin >> h.at(i);

    int res = 0;
    while(true){
        if(*max_element(ALL(h)) == 0)
            break;
        
        int i = 0;
        while(i < N){
            if(h.at(i) == 0)
                i++;
            else{
                res++;
                while(i < N and h.at(i) > 0){
                    h[i]--;
                    i++;
                }
            }
        }
    }

    cout << res << endl;
    
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

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

	int n;
	cin >> n;
	int mx = -1;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		ans += max(mx, x) - x;
		mx = max(mx, x);
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    sort(p.begin(), p.end());
    int ans =0;
    for(int i = 0; i < n-1; i++) ans += p[i];
    ans += p[n-1]/2;
    cout << ans;
    
}


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

typedef long lint;
typedef long long llint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    int is, it, n;
    bool flg;
    n = s.size();
    for(int in=0;in<s.size();in++) {
        flg = true;
        for(int jn=0;jn<s.size();jn++) {
            is=jn;
            if(is>=n) is -= n;
            it=jn+in;
            if(it>=n) it -= n;
            if(s.at(is)==t.at(it)) continue;
            else flg = false;
        }
        if(flg) {
            cout << "Yes" << endl; 
            return 0;
        }
    }
    cout << "No" << endl; 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int v[24],c[24],n;
int main(){
	cin>>n;for(int i=1;i<=n;i++){cin>>v[i];}for(int i=1;i<=n;i++){cin>>c[i];}
  	int ans = 0;
  	for(int i=1;i<=n;i++){
    	ans += (v[i]>c[i])*(v[i]-c[i]);
    }
  	cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int v,b[100]={0},c=0;
	while(scanf("%d",&v)!=EOF){
		b[v-1]+=1;
	}
	for(int i=0;i<100;i++){
		if(b[i]>c){
			c=b[i];
		}
	}
	for(int i=0;i<100;i++){
		if(c==b[i]){
			printf("%d\n",i+1);
		}
	}
	return 0;
}

Measured memory_bytes: 2528
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  week = {'SUN':7, 'MON':6, 'TUE':5, 'WED':4, 'THU':3, 'FRI':2, 'SAT':1}
  print(week[input().strip()])

if __name__=='__main__':
  main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
#define int long long
#define MOD 1000000007
 
using namespace std;
 
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for (auto v : V)
        os << v << " ";
    os << "]";
    return os;
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
    os << "{ ";
    for (auto m : M)
        os << "(" << m.first << ":" << m.second << ") ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}

void solve() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int budget = 1000;
    bool buying = false;
    int stock, num;
    for(int i = 0; i < n - 1; i++) {
        // cout << budget << endl;
        if(!buying) {
            if(a[i] < a[i + 1]) {
                stock = a[i];
                num = budget / a[i];
                budget -= num * stock;
                buying = true;
            }
            
        }
        else {
            if(a[i] > a[i + 1]) {
                budget += num * a[i];
                buying = false;
            }
        }
    }
    if(buying) {
        budget += num * a[n - 1];
    }

    cout << budget << endl;
}
 
int32_t main() {
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    // cin >> t;
    // while(t--) {
    //     solve();
    // }
    return 0;
}

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

typedef pair<int, int> P;

int N, K;
vector<int> G[2000];
P E[2000];

int dfs(int s, int p, int d) {
  if (d == 0) return 1;
  int c = 1;
  for (int t : G[s]) {
    if (t == p) continue;
    c += dfs(t, s, d-1);
  }
  return c;
}

int main() {
  cin >> N >> K;
  for (int i=0; i<N-1; i++) {
    int a, b; cin >> a >> b;
    a--, b--;
    G[a].push_back(b), G[b].push_back(a);
    E[i] = P(a, b);
  }

  int s = 1;
  if (K % 2 == 0) {
    for (int i=0; i<N; i++) {
      s = max(s, dfs(i, -1, K/2));
    }
  }
  else {
    for (int i=0; i<N-1; i++) {
      int a = E[i].first, b = E[i].second;
      s = max(s, dfs(a, b, (K-1)/2) + dfs(b, a, (K-1)/2));
    }
  }
  cout << N - s << "\n";
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int Dsum(int a){
	string s = to_string(a) ;
	int res = 0 ;
	for(int i=0;i<s.size();i++) res += s.at(i)-'0' ;
	return res ;
}

int main(){
	int n ; cin >> n ;
	int ans = 10000 ;
	for(int i=1;i<n;i++){
		int a = i ;
		int b = n-i ;
		int sum = Dsum(a)+Dsum(b) ;
		if(ans>sum) ans = sum ;
	}
	cout << ans << endl ;
}


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

int main(void)
{
    int N;

    cin >> N;

    string c;

    cin >> c;

    int a = 0;
    int b = N-1;
    int ans = 0;
    while(1)
    {
        for(; a < N; ++a)
        {
            if(c[a] == 'W') break;
        }
        for(; b >= 0; --b)
        {
            if(c[b] == 'R') break;
        }
        if(b <= a) break;
        c[a] = 'R';
        c[b] = 'W';
        ++ans;
    }

    cout << ans << endl;

    return 0;
}



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

int main() {
  ll n;
  cin>>n;
  set<string> ans;
  rep(i,n){
    string s;
    cin>>s;
    ans.insert(s);
  }
  cout<<ans.size()<<endl;
}
    

Measured memory_bytes: 19196
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    ll n,k,l;cin >> n >> k >> l;
    UnionFind ufa(n),ufb(n);
    rep(i,k){
        ll a,b;cin >> a >> b;a--;b--;
        if(!ufa.same(a,b))ufa.merge(a,b);
    }
    rep(i,l){
        ll a,b;cin >> a >> b;a--;b--;
        if(!ufb.same(a,b))ufb.merge(a,b);
    }
    //cout << endl;
    //rep(i,n)cout << ufa.root(i) <<" " << ufb.root(i) <<endl;
    map<pl,ll> mp;
    rep(i,n)mp[{ufa.root(i),ufb.root(i)}]++;
    rep(i,n)cout << mp[{ufa.root(i),ufb.root(i)}] <<" ";cout << endl;
}   

Measured memory_bytes: 16096
n,a,b=map(int,input().split())
ans=[];L=[a]*b;x=a*b-n;ct=1
for i in range(b-1,0,-1):
  y=min(a-1,x);L[i]-=y;x-=y
for i in range(b):
  l=[]
  for j in range(L[i]):
    l.append(str(ct))
    ct+=1
  ans.append(' '.join(l))
ans.reverse()
print(-1 if a+b>n+1 or a*b<n else ' '.join(ans))

Measured memory_bytes: 98464
#include <stdio.h>

int linear_search(int s[], int n,  int key) {
  int i = 0;
  s[n] = key;
  while(s[i] != key)
    i++;
  return i != n;
}

int main(void) {
  int n ,q;
  int s[10001];
  int t[500];
  int i;
  int count = 0;
  
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &s[i]);
  scanf("%d", &q);
  for (i = 0; i < q; i++)
    scanf("%d", &t[i]);

  for (i = 0; i < q; i++) {
    count += linear_search(s, n, t[i]);
  }

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



Measured memory_bytes: 2104
N = int(input())
A = list(map(int,input().split()))


flag = False
for count in range(0,N):
    if A[count] % 2 == 0:
        if A[count] % 3 != 0 and A[count] % 5 != 0:
            flag = True

if flag == False:
    print("APPROVED")
else:
    print("DENIED")



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

const int N = 100000 + 10;
const int oo = 0x3f3f3f3f;

int n, k;
int aa[N];
vector<int> g[N];
int dp[N][2], dep[N], root;

void no() {
	printf( "No\n" );
	exit(0);
}
void dfs( int u, int fa, int odd ) {
	if( aa[u] != oo ) {
		dp[u][0] = dep[u] - aa[u];
		dp[u][1] = dep[u] + aa[u];
//		if( (aa[u] & 1) != odd ) no();
	} else {
		dp[u][0] = dp[u][1] = oo;
	}
	for( int t = 0; t < (int)g[u].size(); t++ ) {
		int v = g[u][t];
		if( v == fa ) continue;
		dep[v] = dep[u] + 1;
		dfs( v, u, odd ^ 1 );
		dp[u][0] = min( dp[u][0], dp[v][0] );
		dp[u][1] = min( dp[u][1], dp[v][1] );
	}
//	if( aa[u] != oo && (dp[u][0] < dep[u] - aa[u] || dp[u][1] < dep[u] + aa[u]) ) no();
}
void dfs2( int u, int fa ) {
	for( int t = 0; t < (int)g[u].size(); t++ ) {
		int v = g[u][t];
		if( v == fa ) continue;
		if( aa[v] == oo ) {
			if( dp[v][0] - (dep[u]-aa[u])  < dp[v][1] - (dep[u]+aa[u]) ) {
				aa[v] = aa[u] + 1;
			} else {
				aa[v] = aa[u] - 1;
			}
		}
		dfs2( v, u );
	}
}
int main() {
	scanf( "%d", &n );
	for( int i = 1; i < n; i++ ) {
		int u, v;
		scanf( "%d%d", &u, &v );
		g[u].push_back( v );
		g[v].push_back( u );
	}
	scanf( "%d", &k );
	memset( aa, 0x3f, sizeof(aa) );
	for( int i = 1; i <= k; i++ ) {
		int v, p;
		scanf( "%d%d", &v, &p );
		aa[v] = p;
		if( i == 1 ) root = v;
	}
	for( int i = 1; i <= n; i++ ) {
		dp[i][0] = dp[i][1] = oo;
	}
	dep[root] = 1;
	dfs( root, root, aa[root] & 1 );
	dfs2( root, root );
	for( int u = 1; u <= n; u++ ) {
		for( int t = 0; t < (int)g[u].size(); t++ ) {
			int v = g[u][t];
			if( aa[u] - aa[v] > 1 || aa[u] - aa[v] < -1 || aa[u] == aa[v] ) no();
		}
	}
	printf( "Yes\n" );
	for( int u = 1; u <= n; u++ ) {
		printf( "%d\n", aa[u] );
	}
}







Measured memory_bytes: 15744
#include <cstdio>

using namespace std;

int main() {
    int h, w;
    
    scanf("%d %d", &h, &w);
    
    if (h == 1 || w == 1) {
        puts("1");
    } else if (h % 2 == 0 || w % 2 == 0) {
        printf("%lld\n", (long long)h * w / 2);
    } else {
        printf("%lld\n", (long long)h * w / 2 + 1);
    }
    
    return 0;
}


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

string S[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

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

    string s;
    cin >> s;

    for(int i = 0; i < 7; i++) {
        if(S[i] == s) cout << 7 - i;
    }

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in(), h = in(), w = in();
	cout << (n - h + 1) * (n - w + 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    nitin;
    int n;
    cin>>n;
    int ans=0;
    int temp=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a==0)
        {
            ans+=temp/2;
            temp=0;
        }
        else{
            temp+=a;
        }
    }
    ans+=temp/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=55,p=1000000007,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int T,n,ans,deg[N],u[N],v[N],h[N][N],inq[N],fa[N];
struct tree{
	vector<int> e[N];
	void clear(){for (int i=1;i<=n;i++) e[i].clear();}
	void add(int u,int v){e[u].push_back(v);e[v].push_back(u);}
	void work(int x,int fath,int *fa){
		fa[x]=fath;
		for (auto y : e[x])
		if (y!=fath) work(y,x,fa);
	}
}a,b,c;
struct graph{
	int h[N];
	vector<int> e[N];
	void clear(){for (int i=1;i<=n;i++) e[i].clear();}
	void add(int u,int v){e[u].push_back(v);}
	bool work(int x){
		h[x]=1;
		for (auto y : e[x])
		if (h[y]<2){
			if (h[y]) return false;
			else if (!work(y)) return false;
		}
		h[x]=2;return true;
	}
	bool check(){
		memset(h,0,sizeof(h));
		for (int i=1;i<=n;i++)
		if ((!h[i])&&(!work(i))) return false;
		return true;
	}
}g;
int check(int root){
	a.clear();c.clear();g.clear();
	for (int i=1;i<n;i++){
		a.add(u[i],v[i]);
		if (h[u[i]][v[i]]) c.add(u[i],v[i]);
	}
	memset(inq,0,sizeof(inq));
	c.work(root,-1,inq);
	a.work(root,0,fa);
	for (int i=1;i<=n;i++)
	if ((!inq[i])&&(!inq[fa[i]])) g.add(i,fa[i]);
	b.work(root,0,fa);
	for (int i=1;i<=n;i++)
	if ((!inq[i])&&(!inq[fa[i]])) g.add(fa[i],i);
	if (!g.check()) return inf;
	int t=0;
	for (int i=1;i<=n;i++) t+=(inq[i]==0);
	return t;
}
int main(){
	T=read();
	while(T--){
		b.clear();
		memset(h,0,sizeof(h));
		memset(deg,0,sizeof(deg));
		n=read();
		for (int i=1;i<n;i++){
			u[i]=read();v[i]=read();
			deg[u[i]]++;deg[v[i]]++;
		}
		for (int i=1;i<n;i++){
			int u=read(),v=read();
			b.add(u,v);h[u][v]=h[v][u]=1;
		}
		ans=check(1);
		for (int i=1;i<n;i++){
			int tu=u[i],tv=v[i];
			if (deg[tu]==1){
				for (v[i]=1;v[i]<=n;v[i]++)
				if(v[i]!=tu) ans=min(ans,check(tu)+1);
				v[i]=tv;
			}
			if (deg[tv]==1){
				for (u[i]=1;u[i]<=n;u[i]++)
				if(u[i]!=tv) ans=min(ans,check(tv)+1);
				u[i]=tu;
			}
		}
		printf("%d\n",(ans<=n) ? ans : -1);
	}
	return 0;
}

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

unsigned long long memo[31];

int recursion(int n){
  if(n <= 0) return 1;
  if(memo[n] != 0) return memo[n];
  return memo[n] = recursion(n-3) + recursion(n-1) + recursion(n-2);
}

int main(){
  int n;
  while(cin >> n,n){
    memo[1] = 1;
    memo[2] = 2;
    memo[3] = 4;
    recursion(n);
    cout << ((memo[n]%3650 == 0)? memo[n]/3650 : memo[n]/3650 +1) << endl;
  }
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

#define lowbit(x) x & (-x)
#define lson left,mid,root << 1
#define rson mid+1,right,root << 1 | 1

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=998244353;
const ll inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=2e5+100;	

int vis[maxn];
int prime[maxn];
int a[maxn];
int num[maxn];
int p = 0;
int cnt = 0;
int g;
int n;

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


void getprime()
{
	for(int i = 2; i <= maxn; i ++)
		{
			if(!vis[i])
				prime[cnt ++] = i;
			for(int j = 0; prime[j] <= maxn / i; j ++)
				{
					vis[i * prime[j]] = 1;
					if(i % prime[j] == 0)
						break;
				}
		}
}

void div(int x)
{
	for(int i = 0; prime[i] <= x / prime[i]; i ++)
		{
			if(x % prime[i] == 0)
				{
					num[p ++] = prime[i];
					while(x % prime[i] == 0)
						x /= prime[i];
				}
		}
	if(x != 1)
		num[p ++] = x;
}


int main()
{
	scanf("%d",&n);
	getprime();
	
	for(int i = n; i >= 0; i --)
		{
		scanf("%d",&a[i]);
		g = gcd(g,a[i]);	
		}
	div(abs(g));
	
	
	for(int i = 0; prime[i] <= n; i ++)
		if(a[0] % prime[i] == 0)
			{
			bool f = 1;
			for(int j = 0; j <= prime[i] - 1; j ++)
				{
				int ans = 0;
				for(int t = j; t <= n; t += prime[i] - 1)
					(ans += a[t]) %= prime[i];
				if(ans)
					{
					f = 0;
					break;	
					}	
				}
			if(f)
				num[p ++] = prime[i];	
			}
	
	sort(num, num + p);
	p = unique(num , num + p ) - num;
	
	for(int i  = 0; i < p ; i ++)
		printf("%d\n",num[i]);
		
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#define io ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int N=2e5+10;
//char s[N];
int a[N];
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    ll ans=0;
    for(int i=2;i<=n;i++){
        if(a[i]<a[i-1]){
            ans+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<ans;
}
int main(){
    io;
    //int T;cin>>T;
    //while(T--)
        solve();
}


Measured memory_bytes: 3968
#include <stdio.h>

int main() {
    int A,B,C,X,a=0,b=0,c=0,count=0;
    scanf("%d%d%d%d",&A,&B,&C,&X);
    for(a=0;a<=A;a++)
    {
        for(b=0;b<=B;b++)
        {
            for(c=0;c<=C;c++)
            {
                if((500*a+100*b+50*c)==X)
                {
                    count++;
                }
            }
        }
    }
    printf("%d\n",count);
    return 0;
}


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

using namespace std;

using   ll=long long;
using   ld=long double;

#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define long long      int 
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define f              first
#define s              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323

int chk(ll mid,ll k)
{
    return (240-k-5*((mid*(mid+1))/2))>=0;
}

bool isPrime(int n) 
{ 
    // Corner case 
    if (n <= 1) 
        return false; 
  
    // Check from 2 to n-1 
    for (int i = 2; i < n; i++) 
        if (n % i == 0) 
            return false; 
  
    return true; 
} 
 
void solve()
{
    ll n;
    
    cin>>n;
    
    for(int i=n;i;i++)
    {
        if(isPrime(i))
        {
            cout<<i;
            return;
        }
    }
}
 
 
signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    while(1){
        ll N, M;
        cin >> N >> M;
        if(!N && !M) break;
        pair<ll, ll> po[N];
        ll ans = 0;
        for(ll i = 0; i < N; i++){
            cin >> po[i].first >> po[i].second;
            ans += po[i].first * po[i].second;
        }
        sort(po, po + N, [](auto a, auto b){return a.second > b.second;});
        for(ll i = 0; i < N; i++){
            ll num = min(M, po[i].first);
            ans -= po[i].second * num;
            M -= num;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <stack>

using namespace std;
typedef long long  ll;

const ll mod = 1000000007;


int main()
{
	ll N;
	cin >> N;
	vector<ll> h(N);
	for (ll i = 0; i < N; i++)
	{
		cin >> h[i];
	}
	ll dp[100000];
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for (ll i = 2; i < N; i++)
	{
		dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
	}
	cout << dp[N - 1] << endl;
	return 0;

}

Measured memory_bytes: 1792
arr_str = list(input())

zeros=''
zeros =zeros.zfill(26)
strs ="qwertyuiopasdfghjklzxcvbnm"
ret='Yes'
dic = dict(zip(strs, zeros))

for st in arr_str: 
    dic[st] = int(dic[st]) +  1

for it in dic.values():
    if( int(it) % 2 == 1):
        ret =  'No'
        break
    
print(ret)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

vector<vector<int>> g;
vector<vector<ll>> dp;

ll dfs(int v,int c,int p=-1){//c=0:白,c=1:黒
	if(dp[v][c]>1){
		return dp[v][c];
	}
	for (auto x : g[v])
	{
		if(x!=p){
			if(c==0){
				dp[v][c]*=(dfs(x,0,v)+dfs(x,1,v))%mod;
				dp[v][c] %= mod;
			}
			else {
				dp[v][c] *= dfs(x, 0, v);
				dp[v][c] %= mod;
			}
		}
	}
	return dp[v][c];
}
void solve()
{
	int n;
	cin >> n;
	g.resize(n);
	dp.resize(n + 5, vector<ll>(2,1));
	vector<int> cnt(n);
	rep(i, n - 1)
	{
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		g[x].pb(y);
		g[y].pb(x);
		cnt[x]++;
		cnt[y]++;
	}
	int root = 0;
	int minv = 3 * n;
	rep(i, n)
	{
		if(chmin(minv,cnt[i])){
			root = i;
		}
	}
	ll ans = 0;
	ans+=dfs(root, 0);
	ans %= mod;
	ans += dfs(root, 1);
	cout << ans % mod << "\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 20992
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var csf = new CSF[n];
			for (int i = 0; i < n - 1; i++) {
				var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				csf[i] = new CSF { C = temp[0], S = temp[1], F = temp[2] };
			}

			var sb = new StringBuilder();
			for (int i = 0; i < n; i++) {
				int time = 0;
				for (int j = i; j < n - 1; j++) {
					if (time <= csf[j].S) {
						time = csf[j].S + csf[j].C;
					} else {
						time = (time + csf[j].F - 1) / csf[j].F * csf[j].F + csf[j].C;
					}
				}

				sb.AppendLine(time.ToString());
			}

			Console.WriteLine(sb.ToString());
		}

		public struct CSF
		{
			public int C { get; set; }
			public int S { get; set; }
			public int F { get; set; }
		}
	}
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
ll minthis(ll a, ll b){
if(a < b){
return a;
}
return b;
}
ll maxthis(ll a, ll b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
	 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return temp * temp;  
    else
    {  
        if(y > 0)  
            return x * temp * temp;  
        else
            return (temp * temp) / x;  
    }  
} 
bool sortbysec(const pair<int, int>& a, 
               const pair<int, int>& b) 
{ 
    return (a.second < b.second); 
} 


void solve(){
	int n , m;
	cin >> n >> m;
	for(int i = 0; i <= n;i++){
		if((4*i)+(2*(n-i)) == m || ((4*(n-i))+(2*(i))) == m){
			cout << "Yes" << "\n";return;
		}
	}
	cout << "No" << "\n";
}

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




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

int main()
{
	int l,r,d;
	int k=0;
	scanf("%d%d%d",&l,&r,&d);
	for(int i=l;i<=r;i++){
		if(i%d==0)
		    k++;
	}
	printf("%d\n",k);
	return 0;
} 

Measured memory_bytes: 3820
//・X ≡ a[i] / 2 (mod a[i])
//lcm / 2 + n * lcm (n = 0,1,2…)
//lcm > 2 * Mなら0個.
//lcm / 2が解にならない場合（例：a = {2, 4}), 0個.
//そうでないなら, (M + (lcm / 2)) / lcm個.

#include <iostream>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, m;
int a[100000];

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

signed main() {
	int i;
	
	cin >> n >> m;
	rep(i, n) cin >> a[i];
	
	int l = 1;
	rep(i, n) {
		l = lcm(l, a[i]);
		if (l > 2 * m) { cout << 0 << endl; return 0; }
	}
	
	rep(i, n) {
		if ((l / 2) % a[i] != a[i] / 2) { cout << 0 << endl; return 0; }
	}
	
	cout << (m + l / 2) / l << endl;
	return 0;
}

Measured memory_bytes: 1152
import sys
readline = sys.stdin.readline
write = sys.stdout.write
from collections import deque
INF = 10**9
def bfs(N, G, s):
    dist = [INF]*N
    *lb, = range(N)
    dist[s] = 0
    que = deque([s])
    while que:
        v = que.popleft()
        d = dist[v] + 1
        l = lb[v]
        for w in G[v]:
            if dist[w] == INF:
                dist[w] = d
                lb[w] = min(l, lb[w])
                que.append(w)
            elif dist[w] == d:
                lb[w] = min(l, lb[w])
    return dist, lb
def solve():
    N, A, B, C = map(int, readline().split())
    *LS, = range(N)
    *LA, = map(int, readline().split())
    ga = min(LA)-1
    for i in LA:
        LS[i-1] = ga
    *LB, = map(int, readline().split())
    gb = min(LB)-1
    for i in LB:
        LS[i-1] = gb
    *LC, = map(int, readline().split())
    gc = min(LC)-1
    for i in LC:
        LS[i-1] = gc
    G = [set() for i in range(N)]
    M = int(readline())
    for i in range(M):
        x, y = map(int, readline().split())
        lx = LS[x-1]; ly = LS[y-1]
        G[lx].add(ly); G[ly].add(lx)
    da, la = bfs(N, G, ga)
    db, lb = bfs(N, G, gb)
    dc, lc = bfs(N, G, gc)
    ans = INF; k = -1
    for i in range(N):
        d = da[i] + db[i] + dc[i]
        if d <= ans:
            l = min(la[i], lb[i], lc[i])
            if d < ans:
                ans = d
                k = l
            else:
                k = min(l, k)
    write("%d %d\n" % (ans, k+1))
solve()


Measured memory_bytes: 38388
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	int arr[50],k,n;
	cin >> n >> k;
	for(int i=0 ; i<n ; i++)
		cin >> arr[i];

	sort(arr , arr+n);
    reverse(arr , arr+n);
    
	int sum = 0;
	for(int i=0 ; i<k ; i++)
		sum += arr[i];

	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 305;
int a[maxN][maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> a[i][j];
        }
    }
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (a[i][k] + a[k][j] < a[i][j]) {
                    cout << -1 << '\n';
                    return 0;
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;
            bool ok = true;
            for (int k = 1; k <= n; k++) {
                if (a[i][k] < a[i][j] && a[j][k] < a[i][j] && a[i][k] + a[k][j] == a[i][j]) {
                    ok = false;
                    break;
                }
            }
            if (ok) ans += a[i][j];
        }
    }
    cout << ans / 2;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

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

        do{
            int a = scan.nextInt();
            int b = scan.nextInt();

            if (a == 0 && b == 0)
                break;
    
            if (a > b){
                int tmp = a;
                a = b;
                b = tmp;
            }

            System.out.println(a + " " + b);
        }while(true);
    }
}

    

Measured memory_bytes: 35052
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb emplace_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
const int N = 3e3+5, inf = 1e9+7;
int n, k, i, j;
int dp[N][N], p[N][N];
string s, t;

int dfs(int a, int b){
    if(a==0 || b==0) return 0;
    if(dp[a][b]!=-1) return dp[a][b];
    if(s[a-1]==t[b-1]) {
        dp[a][b] = dfs(a-1, b-1)+1;
        p[a][b] = 2;
    }
    else if(dfs(a-1, b) > dfs(a, b-1)){
        dp[a][b] = dfs(a-1, b);
        p[a][b] = 1;
    }
    else dp[a][b] = dfs(a, b-1);
    return dp[a][b];
}
string find(int a, int b){
    if(a==0 || b==0) return "";
    if(p[a][b]==2) return find(a-1, b-1)+s[a-1];
    else if(p[a][b]) return find(a-1, b);
    return find(a, b-1);
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int i, j, a, b, ans = 0;
    cin>>s>>t;
    memset(dp, -1, sizeof dp);
    dfs(sz(s), sz(t));
    cout<<find(sz(s), sz(t));
}

Measured memory_bytes: 141696