akhauriyash/Code-Regression huggingface dataset:
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
std::vector<int> graph[10050];//graph頂点数のsize
const int N=200010;
const int P=1000000007;
using ll = long long;
vector<ll> prime;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/


/*
	string s;
	s.size()
*/

/*
	char s[N];
	strlen(s)
*/
/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/


int main(){
	ll n;
	cin>>n;
  ll ans=0;
  ll kingaku=100;
  while(kingaku<n){
    kingaku=kingaku*1.01;
    ans++;
  }

	cout<<   ans     <<endl;





}


Measured memory_bytes: 3868
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n=100,x,ans=0,temp;
    cin>>x;
    while(n<x){
        temp=(1*n)/100;
        n+=temp;
        ans+=1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<string>
#define N 50010
using namespace std;
string str[10010], t, s[10010];
int main()
{
    ios::sync_with_stdio(false);
    int i, j, n, l, r;
    cin >> n;
    for(i = 1; i <= n; ++i)
    {
        cin >> str[i];
    }
    cin >> t;
    for(i = 1; i <= n; ++i)
    {
        s[i] = str[i];
        for(j = 0; s[i][j]; ++j)
            if(s[i][j] == '?') s[i][j] = 'a';
    }
    s[n + 1] = t;
    sort(s + 1, s + 2 + n);
    for(i = n + 1; i >= 1; --i)
    {
        if(s[i] == t)
        {
            r = i;
            break;
        }
    }
    for(i = 1; i <= n; ++i)
    {
        s[i] = str[i];
        for(j = 0; s[i][j]; ++j)
            if(s[i][j] == '?') s[i][j] = 'z';
    }
    s[n + 1] = t;
    sort(s + 1, s + 2 + n);
    for(i = 1; i <= n + 1; ++i)
    {
        if(s[i] == t)
        {
            l = i;
            break;
        }
    }
    for(i = l; i <= r; ++i)
    {
        cout << i;
        if(i != r)
            cout << " ";
        else
            cout << "\n";
    }
    return 0;
}
/*
1
?
a
*/


Measured memory_bytes: 1408
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    ans = 0
    for i in range(1, n + 1):
        if i % 3 != 0 and i % 5 != 0:
            ans += i
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 67460
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

struct mint {
    ll x;
    mint(ll x=0):x(x%MOD){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
};

int n, k;
mint ans = 1;
vint edge[100005];
vbool visit;
void dfs(int v, int depth, int p) {
    visit[v] = true;
    ans *= k-p;
    int count = 0;
    for (int u : edge[v]) {
        if (visit[u]) continue;
        dfs(u, depth+1, edge[v].size()+count);
        count--;
    }
}

int main() {
    cin >> n >> k;
    visit.resize(n, false);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    dfs(0, 0, 0);

    cout << ans.x << endl;
    return 0;
}

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

int main(){
    int n;
    double A[100];
    double B[100];
    double D_1=0,D_2=0,D_3=0,D_i=0;

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

    D_i=fabs(A[0]-B[0]);
    for(int i=0;i<n;i++){
        D_1+=pow(fabs(A[i]-B[i]),1);
        D_2+=pow(fabs(A[i]-B[i]),2);
        D_3+=pow(fabs(A[i]-B[i]),3);
        if(D_i<fabs(A[i]-B[i]))
            D_i=fabs(A[i]-B[i]);
    }

    printf("%f\n%f\n%f\n%f\n",D_1,sqrt(D_2),cbrt(D_3),D_i);
}


Measured memory_bytes: 2100
N,M = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
modulo = 10**9+7

x,y = 0,0
for i in range(N):
    x += X[i]*i - X[i]*(N-i-1)
for i in range(M):
    y += Y[i]*i - Y[i]*(M-i-1)

print(x*y%modulo)

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

int main(){
  int N;
  cin >> N;
  int sum = 0;
  int tmp = N;
  while(tmp > 0){
    sum += tmp % 10;
    tmp /= 10;
  }
  cout << (N % sum == 0 ? "Yes" : "No") << endl;
  return 0;
}


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

t, a = map(int,input().split())

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

for i in range(0,n):
    h_list[i] = abs(a-(t - h_list[i]*0.006))

MinH = min(h_list)
print(h_list.index(MinH)+1)


Measured memory_bytes: 3060
fun main(args: Array<String>) {
	val s = Array(3) { "" }

	for (i in 0..s.lastIndex) {
		s[i] = readLine()!!
	}

	var turn = 0

	while (s[turn] != "") {
		val pre = turn
		turn = s[turn][0] - 'a'

		s[pre] = s[pre].slice(1..s[pre].lastIndex)
	}

	println('A' + turn)
}


Measured memory_bytes: 37748
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	String a = sc.next();
      	String b = sc.next();
      	int ans = 0;
      	for(int i=0;i<a.length();i++){
          if( a.charAt(i) != b.charAt(i) ){
            ans++;
          }
        }
      	System.out.println(ans);
	}
}

Measured memory_bytes: 32064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>


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

    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if (A[i] < 0)cnt++;
    }
    long long ans = 0LL;
    if (cnt % 2 == 0)
    {
        for (int i = 0; i < N; i++)
        {
            ans += (long long)std::abs(A[i]);
        }
    }
    else
    {
        int min = std::abs(A[0]);
        ans += (long long)(min);
        for (int i = 1; i < N; i++)
        {
            int a = A[i];
            min = std::min(min, std::abs(a));
            if (a < 0)
            {
                a *= -1;
            }
            ans += (long long)a;
        }
        ans -= (long long)(min * 2);
    }

    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 640
W, H, N = map(int, input().split())

lstx = [[0], [W]]
lsty = [[0], [H]]

for i in range(N):
    x, y, a = map(int, input().split())
    if a==1 or a==2:
        lstx[a-1].append(x)
    else:
        lsty[a-3].append(y)

xmax = max(lstx[0])
xmin = min(lstx[1])
ymax = max(lsty[0])
ymin = min(lsty[1])

if xmax <= xmin and ymax <= ymin:
    print((xmax-xmin)*(ymax-ymin))
else: print(0)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }

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

    int N, A; cin >> N >> A;
    vei x(N); rep(i,N) cin >> x[i];
    ll dp[52][52][2505];
    ll sum = acc(all(x), 0LL);
    memset(dp, 0, sizeof(dp));
    dp[0][1][x[0]] = 1; dp[0][0][0] = 1;

    rep(i,N) rep(j,N+1) rep(k,sum+1){
        dp[i + 1][j][k] += dp[i][j][k];
        dp[i + 1][ j + 1 ][ k + x[ i + 1 ] ] += dp[i][j][k];
    }
    ll ans = 0;
    rep1(j, N + 1){
        int aim = j * A;
        if(aim <= sum) ans += dp[N - 1][j][aim];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 53248
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

s = int(input())

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for x in range(1, s):
    if s < 3*x: break
    ans+=cmb(s-3*x + x-1, s-3*x, mod)
    ans%=mod

print(ans)


Measured memory_bytes: 10412
#include <cstdio>
#include <algorithm>
#define MAX 31
using namespace std;

int main(){
	int n, array[MAX];
	fill(array, array + MAX, 0);
	array[0] = 1;
	array[1] = 2;
	array[2] = 4;
	for(int i = 3; i <= 30; i++) array[i] = array[i - 1] + array[i - 2] + array[i - 3];
	
	while(scanf("%d", &n)){
		if(n == 0) break;
		printf("%d\n", array[n - 1] / 10 / 365 + 1);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<stdio.h>
int main(){
  long long int a,b,n,i,j;
  while(scanf("%lld %lld",&a,&b)!=EOF){
    if(a>=b){
      n=b;
    }
    else{
      n=a;
    }
    i=a;
    j=b;

    while(1){
      /*   if(n<a){
	n=a%n;
      if(n==0){
	n=a;
	break;
      }
      }
      else if(n<b){
	n=b%n;
      if(n==0){
	n=b;
	break;
      }
      }*/

      n=a%b;
      if(n==0){
	n=b;
	break;
      }else{
	a=b;
	b=n;
      }

    }
    /*
    while(1){
      if(a*i==b*j){
	break;
      }
      else if(a*i<b*j){
	i++;
      }
     else if(a*i>b*j){
	j++;
	   }
	   }*/

    printf("%lld %.0f\n",n,(double)(i)*(double)(j)/(double)(n));
  }
  return (0);
}

Measured memory_bytes: 632
N,M = map(int, input().split())
A = [10]*N
for i in range(M):
    s,c = map(int, input().split())
    if A[s-1] == 10 or A[s-1] == c:
        A[s-1] = c
    else:
        print(-1)
        break
else:
    if A[0]==10:
        if len(A)!=1:
            A[0]=1
        else:
            A[0]=0
        
    if A[0]==0 and len(A)!=1:
        print(-1)
    else:
        for j in range(1,N):
            if A[j] ==10:
                A[j] = 0
        A = map(str,A)
        print(''.join(A))

Measured memory_bytes: 3064
def main():
    n = int(input())
    a = []
    sum = 0             #longの気持ち
    ans = 0             #long long の気持ち
    mod = 1_000_000_000 + 7
    x = list(map(int, input().split()))
    for i in range(n):
        sum += x[i]           
        a.append(x[i])
    
    for i in range(n):
        sum -= a[i]
        ans += sum * a[i]
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

    

Measured memory_bytes: 31436
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
int divideprime(long long n){
    long long i=2;
    for(i=2;i<=sqrt(n)+1;i++){
        while(n%i==0){
            n/=i;
            mp[i]++;
        }
    }
    if(n!=1) mp[n]++;
    return 0;
}
int main(){
   long long n, ans=0, cnt=1;
   cin >> n;
   divideprime(n);
   for(auto x : mp){
       while(1){
           if(x.second>=cnt){
               x.second-=cnt;
               ans++;
               cnt++;
            }
            else break;
        }
        cnt=1;
   }
   cout << ans <<endl;
   return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long> VLL;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    int n,m;cin>>n>>m;
    V k(n);
    V s(m);
    rep(i,n){
        cin>>k[i];
        int tmp=k[i];
        rep(j,tmp){
            int now;
            cin>>now;
            s[now-1]++;//0-index
        }
    }
    int ans=0;
    rep(i,m){
        if(s[i]==n)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;



int main() {
  int N;
  cin >> N;
  vector <int> prime_list;
  for(int i = 2; i <= N; i++) {
    bool np = false;
    for(int j = 2; j < i; j++) {
      if(i % 2 == 0) {
        np = true;
        break;
      }
    }
    if(!np) {
      prime_list.push_back(i);
    }
  }

  int pp[prime_list.size()];
  for(int i = 0; i < prime_list.size(); i++) {
    pp[i] = 0;
  }
  for(int i = 2; i <= N; i++) {
    int tmp = i;
    while(tmp != 1) {
      for(int j = 0; j < prime_list.size(); j++) {
        if(tmp % prime_list[j] == 0) {
          pp[j]++;
          tmp /= prime_list[j];
          break;
        }
      }
    }
  }
  long long int sum = 1;
  for(int i = 0; i < prime_list.size(); i++) {
    sum = (sum * (pp[i]+1)) % MOD;
  }
  cout << sum << endl;

}


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

#define FOR(i,n) for(int i=0;i<n;i++)
#define PRINT(a) cout<<a<<"\n"
 
int main(){

	int a,b,c,t=1;

	cin>>a>>b>>c;

	if(a+b==c||a+c==b||b+c==a)PRINT("Yes");
	else PRINT("No");


	return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll n;cin>>n;
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=0,buf=0;i<n;i++){
    buf+=a[i];
    if(i%2==0&&buf<=0){
      res+=1-buf;
      buf+=1-buf;
    }
    else if(i%2==1&buf>=0){
      res+=1+buf;
      buf+=-1-buf;
      
    }
    //cout<<buf spa res<<endl;
  }
  buf=0;
  for(i=0;i<n;i++){
    buf+=a[i];
    if(i%2==1&&buf<=0){
      res1+=1-buf;
      buf+=1-buf;
      
    }
    else if(i%2==0&buf>=0){
      res1+=1+buf;

      buf+=-1-buf;
    }
  }
  //cout<<res spa res1<<endl;
  cout<<min(res,res1)<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);

    REP(i, n)
    {
        cin >> p.at(i);
    }

    int ans = 0;
    FOR(i, 1, n - 1)
    {
        if ((p.at(i - 1) <= p.at(i)) && (p.at(i) < p.at(i + 1)))
        {
            ans++;
        }
        else if ((p.at(i - 1) >= p.at(i)) && (p.at(i) > p.at(i + 1)))
        {
            ans++;
        }
    }

    cout << ans << endl;
}

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

int main() {
	int N , K , x ;
    cin >> N >> K ;
    int sum = 0;
    for(int i = 0; i < N ; i++){
    	cin >> x;
        if(2 * x < (K - x) * 2){
        	sum += 2 * x;
        }else{
        	sum += (K - x) * 2;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef bitset<35> sta;
typedef long long LL;
using namespace std;
 
void read(int &v) {
    int k = 0, l = 1;
    char ch;
    ch = getchar();
    while (ch > '9' || ch < '0') {
	if (ch == '-')
	    l = -1;
	ch = getchar();
    }
    while (ch >= '0' && ch <= '9') k = k * 10 + ch - '0', ch = getchar();
    v = l * k;
}
void print(int v) {
    if (v < 0)
	putchar('-'), v = -v;
    if (v > 9)
	print(v / 10);
    putchar(v % 10 + '0');
}

int a[100005], b[100005];
int  n;

int main() {
	read(n);
	for (int i=1; i<=n; ++i) {
		scanf("%d",&a[i]);
		a[i]=-a[i];
	}
	int len=1;
	int ans=1;
	int k;
	b[len]=a[1];
	for (int i=2; i<=n; ++i) {
		k=upper_bound(b+1,b+len+1,a[i])-b;
		b[k]=a[i];  
		if (k>len)  {
		    ++ans;
			++len;
		}       
	}   
	print(ans);
	return 0;
}

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

int to_m2(int x){
    if(!x) return 0;
    int i=0;
    ll base = 1;
    while(x!=0){
        if(x%(base*2)!=0){
            ans.set(i,1);
            x-=base;
        }
        i++;
        base *= -2;        
    }
    return 0;
}

int main(){
    int n ; cin >> n;
    to_m2(n);
    bool flag = false;
    for(int i=31;i>=0;i--){
        if(ans.test(i)) flag = true;
        if(flag){
            cout << (int)(ans.test(i)) ;
        }
    }
    if(!n) cout << 0;
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
L = []
for _ in range(Q):
    L.append(tuple(map(int, input().split())))

ans = 0
_N = N
if N < M:
    _N = M

for A in combinations_with_replacement(range(1, M + 1), _N):
    tmp = 0
    for a, b, c, d in L:
        if a <= _N and b <= _N and A[b - 1] - A[a - 1] == c:
            tmp += d

    if tmp > ans:
        ans = tmp

print(ans)


Measured memory_bytes: 68084
#include<bits/stdc++.h>
using namespace std;
# define PI 3.1415926535
#define ll long long int
char a[1010][1010];
int dp[1010][1010];
int r,c;
#define mod 1000000007

int paths(int i, int j)
{
	if(i > r || j > c)
		return 0;
	if(i == r && j == c)
		return 1;
	if(dp[i][j] >= 0)
		return dp[i][j];
	int k1 = 0, k2 = 0;
	if(a[i+1][j] == '.')
		k1 = paths(i + 1, j) % mod;
	if(a[i][j+1] =='.')
		k2 = paths(i, j+1) % mod;
	dp[i][j] = (k1 + k2)%mod;
	return dp[i][j];		  
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> r >> c;
	for(int i=0; i < 1010; ++i)
		for(int j = 0; j < 1010; ++j)
			dp[i][j] = -1;
	for(int i=1; i <= r;++i)
	{
		for(int j=1; j <= c; ++j)
			cin >> a[i][j];
	}

	for(int i = 1; i <= c;++i)
	{
		dp[r+1][i] = 0;
	}
	for(int i = 0; i <= r; ++i)
		dp[i][c+1] = 0;

	// int k = paths(1, 1);
	int k1 = 0, k2 = 0;
	dp[r+1][c] = 1;
	dp[r][c] = 1;
	for(int i = r; i >=1 ;--i)
		for(int j = c; j >= 1; --j )
		{
			// k1 = 0, k2 = 0;
			if(a[i][j] != '.')
			{
				dp[i][j] = 0;
				continue;
			}
			dp[i][j] = (dp[i+1][j] + dp[i][j+1])%mod;
		}
	cout << dp[1][1] <<"\n";
	return 0;
}

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

int main(void) {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
}

Measured memory_bytes: 3620
taxed_price = int(input())
raw_price = taxed_price // 1.08

if int(raw_price * 1.08) == taxed_price:
    print(int(raw_price))
elif int((raw_price + 1) * 1.08) == taxed_price:
    print(int(raw_price + 1))
else:
    print(':(')


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

using namespace std;
using LL = long long int;

const int MAX_N = 8005;
const int GETA = 8000;

string S;
int N;
int X, Y;

vector<int> DX;
vector<int> DY;

bool dp[MAX_N][MAX_N*2];

int main()
{
  cin >> S; N = S.length();
  cin >> X >> Y;
  int cnt = 0; bool flag = false;
  for(int i = 0; i < N; i++) {
    if(S[i] == 'F') {
      cnt++;
    } else {
      if(!flag) {
        DX.push_back(cnt);
      } else {
        DY.push_back(cnt);
      }
      flag = !flag;
      cnt = 0;
    }
  }

  if(cnt > 0) {
    if(!flag) {
      DX.push_back(cnt);
    } else {
      DY.push_back(cnt);
    }
  }

  memset(dp, 0, sizeof(dp));
  dp[0][GETA] = true;
  for(unsigned int i = 0; i < DX.size(); i++) {
    for(int j = 0; j < 2*MAX_N; j++) {
      if(!dp[i][j]) {
        continue;
      }
      if(i==0) {
        dp[i+1][j+DX[i]] = true;
      } else {
        dp[i+1][j+DX[i]] = dp[i+1][j-DX[i]] = true;
      }
    }
  }

  if(!dp[DX.size()][X + GETA]) {
    cout << "No" << endl;
    return 0;
  }

  memset(dp, 0, sizeof(dp));
  dp[0][GETA] = true;
  for(unsigned int i = 0; i < DY.size(); i++) {
    for(int j = 0; j < 2*MAX_N; j++) {
      if(!dp[i][j]) {
        continue;
      }
      dp[i+1][j+DY[i]] = dp[i+1][j-DY[i]] = true;
    }
  }

  if(!dp[DY.size()][Y + GETA]) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 125440
from itertools import chain, permutations, dropwhile
from heapq import merge
from functools import wraps

def listify(fn):
  @wraps(fn)
  def wraper(*args, **kwargs):
    return list(fn(*args, **kwargs))
  return wraper

def comp_wild(a,b):
  return all(x==y or "?" in (x,y) for x,y in zip(a, b))

@listify
def includers(a,b):
  for i in range(len(a)-len(b)+1):
    if comp_wild(a[i:], b):
      yield i

@listify
def connectors(a,b):
  la = len(a)
  for i in range(max(la-len(b)+1, 1), la):
    if comp_wild(a[i-la:], b):
      yield i
  yield la

class c_int(int):
  def __new__(cls, *args, **kwargs):
    cond = kwargs.pop("cond", lambda:True)
    i = int.__new__(cls, *args, **kwargs)
    i.cond = cond
    return i

def iter_from(it, fm):
  return dropwhile(fm.__gt__, it)

def solve(a, b, c):
  keys = sorted((a,b,c), key=len, reverse=True)
  len_keys = list(map(len, keys))
  inc = { (i,j):includers(keys[i],keys[j]) for i,j in permutations(range(3), 2) }
  con = { (i,j):connectors(keys[i],keys[j]) for i,j in permutations(range(3), 2) }
  
  for i in inc[0,1]:
    for j in inc[0,2]:
      if (
        j+len_keys[2] <= i or i+len_keys[2] <= j or
        j-i in inc[1,2] or j-i in con[1,2] or i-j in con[2,1]
      ):
        return len_keys[0]
  
  def candicates(x,y,z):
    return chain(
      ( c_int(
          i+len_keys[z], 
          cond=lambda:(
            (inc[x,y] and inc[x,y][0]+len_keys[y] <= i) or 
            (inc[z,y] and len_keys[x] <= i+inc[z,y][-1]) or 
            any(
              (i-j in con[y,z] if i>j else j-i in inc[z,y])
               for j in iter_from(inc[x,y]+con[x,y], i-len_keys[y])
            )
          )
        ) for i in iter_from(con[x,z], len_keys[y]-len_keys[z]+1)
      ),
      ( c_int(
          min( i+next(iter_from(q, len_keys[x]-i+1))+len_keys[z] for i in p )
        ) for (p, q) in [sorted((con[x,y], con[y,z]), key=len)]
      ),
    )
  
  for c in merge(*( candicates(*xyz) for xyz in permutations(range(3), 3) )):
    if c.cond():
      return c
  
  return sum(len_keys)

print(solve(*(input() for _ in range(3))))


Measured memory_bytes: 3784
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,c;
ll d[31][31];
ll cc[510][510];
vector<vi> v ;
ll cal(int id,ll color){
    ll ans = 0;
    rep(i,v[id].size()){
        ans += d[i+1][color] * v[id][i+1];
    }
    return ans;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>c;
    v.resize(3);
    v[0].resize(c+1);
    v[1].resize(c+1);
    v[2].resize(c+1);
    rep(i,c)rep(j,c){
        cin>>d[i+1][j+1];
    }
    rep(j,n)rep(i,n){
        cin>>cc[i][j];
        v[(i+j+2)%3][cc[i][j]]++;
    }
    ll ans = INF;
    ll tmp;
    repi(i,1,c+1)repi(j,1,c+1)repi(k,1,c+1){
        if(i==j)continue;
        if(i==k)continue;
        if(j==k)continue;
        tmp = 0;
        tmp += cal(0,i);
        tmp += cal(1,j);
        tmp += cal(2,k);
        chmin(ans,tmp);
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 2304
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;


const long long int mod = 998244353;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int N,K,res=INF,x[60],y[60],tmp=0;

string S;

int main(){
    cout << fixed << setprecision(18);
    cin>>K>>S;
    if(S.size()<=K){cout<<S<<endl;}
    else{cout<<S.substr(0,K)+"..."<<endl;}
}




Measured memory_bytes: 3632
from itertools import *
N = int(input())
S = [input() for n in range(N)]
D = {"M":0,"A":0,"R":0,"C":0,"H":0}

for s in S:
  if s[0] in "MARCH":
    D[s[0]]+=1

print(sum(a*b*c for a,b,c in combinations(D.values(),3)))

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

using namespace std;

int maxtime(int number){
    return (number+9)/10*10;
}
int main(void){
    int A,B,C,D,E;
    cin>>A>>B>>C>>D>>E;
    vector<int> dish;
    dish.push_back(A%10);
    dish.push_back(B%10);
    dish.push_back(C%10);
    dish.push_back(D%10);
    dish.push_back(E%10);
    for(int i=0;i<dish.size();i++){
        if(dish[i]>0) dish[i]=10-dish[i];
    }
    sort(dish.begin(),dish.end());
    int ans=maxtime(A)+maxtime(B)+maxtime(C)+maxtime(D)+maxtime(E)-dish[dish.size()-1];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
char s[10];
int main()
{	
	scanf("%s",s);
	int sum=0;
	int l=0;
	//char a[10];
	int i, j;
	for(i=0;i<8;i++)
	{
		sum=s[0] - '0';
		//memset(a,0,sizeof(a));
		//itoa(i,a,2);
		for(j=0;j<3;j++)
		{
			if(i & (1 << j))
			sum+=s[j + 1]-'0';
			else
			sum-=s[j + 1]-'0';
		}
		if(sum==7)
		{
			l=i;
			break;
		}
	}
	//itoa(l,a,2);
//	printf("%d", l);
	
	for(i=0;i<4;i++)
	{	
	if(i != 0){
		
		if(l & (1 << (i - 1))){
				printf("+");
		}
		else
			printf("-");
		}
		//printf("%c",a[0]);
		printf("%c",s[i]);
	}
	printf("=7\n");
	return 0;
}

Measured memory_bytes: 128
K = int(input())
S = input()
N = len(S)

mod = 10**9+7

power25 = [1]*(K+1)
power26 = [1]*(K+1)

def mod_factorial(n, m):
    mod_factorials = [1] * (n + 1)
    for i in range(1, n+1):
        mod_factorials[i] = mod_factorials[i-1]*i
        mod_factorials[i] %= m
    return mod_factorials

# 1!,2!,3!,...,n! の逆元 (mod m)
def mod_inv_factorials2(n, m):
    mod_invs = [1] * (n + 1)
    invs = [1] * (n + 1)
    for i in range(2, n + 1):
        invs[i] = m - invs[m % i] * (m//i) % m

    for i in range(1, n+1):
        mod_invs[i] = invs[i]*mod_invs[i-1]
        mod_invs[i] %= m
    return mod_invs

factrials = mod_factorial(K+N,mod)
inv_factrials = mod_inv_factorials2(max(N,K+1),mod)

for i in range(1,K+1):
    power25[i] = (power25[i-1]*25)%mod
for i in range(1,K+1):
    power26[i] = (power26[i-1]*26)%mod

ans = 0
for i in range(K+1):
    rk = K-i
    ans += power25[rk]*factrials[rk+N-1]*inv_factrials[N-1]*inv_factrials[rk]*power26[i]
    ans %= mod

print(ans)



Measured memory_bytes: 138520
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  int  a, b, c, d, X, Y;
  //  double  c;
  int  A[103]={};
  int  flag[103]={};

//  long long  a, b, c, d, X, Y;
//char s[101][101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
//  int flag=0;
  int tmp=0;
  int min=1000;
  int len=0;
  int cnt=0;
  int num=0;
  double ans=1000;
  int max=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d", &a);
//  cnt = strlen(t);
  //printf("%d\n",cnt);

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

  for(i=0;i<a;){
//    printf("i=%d A[i]=%d\n",i,A[i]);

    min=1000;
    if(A[i]==0) i++;
    else {
      for(j=i;j<a+1;j++){
//      printf("j=%d min=%d A[j]=%d\n",j, min, A[j]);
        if(A[j]==0){
          num=j-1;
          break;
        }
        if(min>=A[j]){
          min=A[j];
        }
      }
      for(k=i;k<num+1;k++){
//      printf("k=%d num=%d cnt=%d A[k]=%d\n",k, num, cnt, A[k]);
        A[k]=A[k]-min;

      }
    cnt=cnt+min;
    }
  }

  
//  if(flag==0)   printf("TLE\n");
  printf("%d\n", cnt);
  
return 0;
}


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

int main() {
  long long A,B;
  cin>>A>>B;
  long long ans;
  ans=A;
  while(1){
    if(ans%B==0){
      cout<<ans<<endl;
      break;
    }
    else{
      ans+=A;
    }
  }
    
}


Measured memory_bytes: 256
def solve():
    [N, M] = [int(x) for x in input().split()]

    M, N = max(N, M), min(N, M)

    if abs(N - M) > 1:
        return 0

    Nfact = 1
    MOD = 10**9 + 7

    for i in range(1, N+1):
        Nfact = Nfact * i % MOD

    Nfact2 = Nfact * Nfact % MOD

    if N == M:
        return Nfact2 * 2 % MOD
    else:
        return (N+1) * Nfact2 % MOD


def main():
    print(solve())


if __name__ == '__main__':
    main()

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

int main() 
{
  string S;
  int a,b;
  cin >> a;
  cin >> S;
  cin >> b;

  int ans=0;
  
  // ここにプログラムを追記
  if (S=="+")
    ans = a + b;
  else
    ans = a - b;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int N,Q;
vector<int> g[200020];
vector<int> p,x;

ll val[200020];

ll ans[200020];

void dfs(int now,int par,ll v){
  ans[now]=v+val[now];
  for(auto nex:g[now]){
    if(nex==par) continue;
    dfs(nex,now,ans[now]);
  }
  return;
}



int main(){
  cin>>N>>Q;
  p.resize(Q);
  x.resize(Q);
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    g[a].push_back(b);
  }
  for(int i=0;i<Q;i++) cin>>p[i]>>x[i];

  for(int i=0;i<Q;i++) val[p[i]]+=x[i];

  dfs(1,-1,0);

  for(int i=1;i<=N;i++) cout<<ans[i]<<" ";
  cout<<endl;
  

  return 0;
}


Measured memory_bytes: 27264
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

struct Edge {
	int to, id;
};
vector<vector<Edge>> G;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
	int k = 1;
	rep(i, G[v].size()) {
		int u = G[v][i].to, ei = G[v][i].id;
		if(u==p) continue;

		if(k == c) k++;
		ans[ei] = k;
		k++;
		dfs(u, ans[ei], v);
	}
}

int main() {
	int N;
	cin >> N;
	G.resize(N);
	ans.resize(N-1);

	rep(i, N-1) {
		int a, b;
		cin >> a >> b;
		G[a-1].push_back((Edge){b-1, (int)i});
		G[b-1].push_back((Edge){a-1, (int)i});

	}

	dfs(0, -1, -1);

	int mx = 0;
	rep(i, N) mx = max(mx, int(G[i].size()));
	cout << mx << endl;

	rep(i, N-1) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 8320
n,c=map(int,input().split())
irohen=[list(map(int,input().split())) for i in range(c)]
grid=[list(map(int,input().split())) for i in range(n)]
rem0=[0]*c
rem1=[0]*c
rem2=[0]*c
for i in range(n):
    for j in range(n):
        if (i+j)%3==0:
            rem0[grid[i][j]-1]+=1
        elif (i+j)%3==1:
            rem1[grid[i][j]-1]+=1
        elif (i+j)%3==2:
            rem2[grid[i][j]-1]+=1
ans=10**10
for i in range(c):
    for j in range(c):
        for h in range(c):
            chk=0
            if i==j or i==h or j==h:
                continue
            for k in range(c):
                chk+=rem0[k]*irohen[k][i]+rem1[k]*irohen[k][j]+rem2[k]*irohen[k][h]
            if chk < ans:ans=chk
print(ans)


Measured memory_bytes: 5620
def twos_in_factorial(n):
    return n - bin(n).count('1')


def parity_of_nCr(n, i):
    """ if odd, return False. """
    f = twos_in_factorial
    return f(n) - f(n-i) - f(i) > 0


if __name__ == "__main__":
    n = int(input())
    nums = list(map(lambda x: int(x) - 1, input().strip()))
    no_one = False
    if 1 not in nums:
        nums = [num // 2 for num in nums]
        no_one = True

    is_odd = False
    for i, num in enumerate(nums):
        if not parity_of_nCr(n-1, i) and num & 1:
            is_odd ^= 1

    if not is_odd:
        print(0)
    else:
        print(1 << no_one)


Measured memory_bytes: 20580
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[105];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
        }
        int minn=1e9;

        for(int i=1; i<=n; i++)
        {
            int sum=0,num=0;
            for(int j=1; j<=n; j++)
            {
                if(j<=i)
                    sum+=a[j];
                else num+=a[j];
            }
            int b=abs(sum-num);
            minn=min(minn,b);
        }

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

    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;

int main(){
	int R[MAX],n;
	
	cin>>n;
	for(int i=0;i<n;i++)cin>>R[i];
	
	int maxv=-2000000000;
	int minv=R[0];
	
	for(int i=1;i<n;i++){
		maxv=max(maxv,R[i]-minv);
		minv=min(minv,R[i]);
	}
	
	cout<<maxv<<endl;
	
	return 0;
}

Measured memory_bytes: 3864
//Practice more and more
//learn for better
#define bn begin()
#define en end()
#define mx 5000010
#define pb push_back
#define PI (2.0*acos(0.0))
#define ALL(a) a.begin(),a.end()
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rep(a,b) for(int a=0;a<b;++a)
#define fastio ios::sync_with_stdio(false)
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int>  vi;
typedef vector<ll>   vll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
	int a,b,n,i,tmp;
	string s,t;
	cin>>s>>t;
	int cnt=0;
for(i=0;i<s.length();i++)
{
	if(s[i]!=t[i])
	cnt++;
}
cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3736
from collections import deque
from bisect import bisect_left

n = int(input())
a = [int(input()) for _ in range(n)]

dq = deque()
for e in a:
    i = bisect_left(dq, e)
    if i == 0:
        dq.appendleft(e)
    else:
        dq[i-1] = e

ans = len(dq)
print(ans)


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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  ll n,m,l;
  cin>>n>>m>>l;
  vector<vector<ll>> dist1 (n,vector<ll>(n,INF));
  vector<vector<ll>> dist2 (n,vector<ll>(n,INF));
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    chmin(dist1[a][b],c);
    chmin(dist1[b][a],c);
  }

  rep(k,n)rep(i,n)rep(j,n){
    chmin(dist1[i][j],dist1[i][k]+dist1[k][j]);
  }

  rep(i,n)rep(j,n){
    if(dist1[i][j]<=l)dist2[i][j]=1;
  }

  rep(k,n)rep(i,n)rep(j,n){
    chmin(dist2[i][j],dist2[i][k]+dist2[k][j]);
  }
  
    ll q;cin>>q;
    while(q--){
        ll s,t;cin>>s>>t;s--,t--;
        if(dist2[s][t]==INF) cout<<-1<<endl;
        else cout<<dist2[s][t]-1<<endl;
    }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;


int main() {
    int n;
    cin >> n;
    string s = to_string(n);
    int ans = 0;
    for(int i=0;i<s.size();i++){
        ans += n % 10;
        n /= 10;
    }
    if (s.at(0)=='1'&& ans == 1){
        ans = 10;
    }
    cout << ans << endl;
    
    return 0;
}

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

static const int INF=100000;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll N;
    cin >> N;
    vector<pair<ll,ll> > w(N);
    for(int i=0;i<N;i++){
        ll a,b;
        cin >> a >> b;
        w[i]=make_pair(b,a);
    }
    sort(w.begin(),w.end());
    ll tmp=0;
    for(int i=0;i<N;i++){
        if(tmp+w[i].second<=w[i].first){
            tmp+=w[i].second;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    //if(tmp>w[N-1].first) cout << "No" << endl;
    cout << "Yes" << endl;
}


Measured memory_bytes: 3328
import java.util.*;

public class Main{              
      public static void main(String[] args) {          
          
           Scanner sc = new Scanner(System.in);
       
           long N = sc.nextLong();           
           long K = sc.nextLong();
  
           long A[] = new long[100001];
           
           Arrays.fill(A,0);
           
           long sum = 0;
           
           for(int i = 0;i < N;i++){
               int a = sc.nextInt();
               long B = sc.nextLong();
               A[a] += B;
           }
           
           for(int i = 0;i < 100001;i++){
               sum += A[i];
               if(sum >= K){
                  System.out.println(i);   
                  break;
               }               
           }
           
    
           
  }   
}       


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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    H1, M1, H2, M2, K = readnums()
    H2 -= 1
    M2 += 60
    print((H2 - H1) * 60 + (M2 - M1) - K)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9188