akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 998244353;
static const int SIZE = 3005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

// i番目まで見て
// 要素の和がjで
// k = 0 : Lを決めていない
// k = 1 : Lを決めたが、Rを決めていない
// k = 2 : Rを決めた
LL dp[SIZE][SIZE * 2][3];

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

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

    }

    dp[0][0][0] = 1;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j <= S; ++j) {
            dp[i + 1][j][0] += dp[i][j][0];
            dp[i + 1][j][1] += (dp[i][j][0] + dp[i][j][1]) % MOD; dp[i + 1][j][1] %= MOD;
            dp[i + 1][j][2] += (dp[i][j][0] + dp[i][j][1] + dp[i][j][2]) % MOD; dp[i + 1][j][2] %= MOD;

            dp[i + 1][j + v[i]][1] = (dp[i + 1][j + v[i]][1] + dp[i][j][0] + dp[i][j][1]) % MOD;
            dp[i + 1][j + v[i]][2] = (dp[i + 1][j + v[i]][2] + dp[i][j][0] + dp[i][j][1]) % MOD;

        }
    }
    cout << dp[N][S][2] << endl;

    return 0;
}



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

using namespace std;

long long dp[100100];
int w[100100], v[100100];
int N, W;

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

Measured memory_bytes: 1024
N = int(input())

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

a = num2alpha(N)
print(a.lower())

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

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

  int min_cost=10000;
  for (int i=0; i<N; i++) {
    int c, t;
    cin >> c >> t;

    if (T>=t && c<min_cost) min_cost=c;
  }

  if (min_cost==10000) {
    cout << "TLE";
  } else {
    cout << min_cost;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n,t;
  int a[200000];
  ll ans=0,lim;
  cin>>n>>t;
  rep(i,n){
    cin>>a[i];
  }
  lim=a[0]+t;
  repi(i,1,n){
    ans+=min(a[i]-a[i-1],t);
  }
  cout<<ans+t<<endl;
  return 0;
}




Measured memory_bytes: 1024
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int main(){
	int n,c,m1,s1,m2,s2,m3,s3,m4,s4;
	while(cin>>n,n){
		vector<pair<int,int> > r;
		for(int i=0;i<n;i++){
			cin>>c>>m1>>s1>>m2>>s2>>m3>>s3>>m4>>s4;
			r.push_back(make_pair( ((m1+m2+m3+m4)*60+s1+s2+s3+s4),c) );
		}
		sort(r.begin(),r.end());
		cout<<r[0].second<<endl<<r[1].second<<endl<<r[r.size()-2].second<<endl;
	}
	return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    vector<int> dp(n);

    for(int &el : a)
        cin >> el;

    dp[0] = 0;
    for(int i = 1; i < n; i++) {
        dp[i] = dp[i-1] + abs(a[i]-a[i-1]);
        for(int j = min(k, i); j > 0; j--) {
            dp[i] = min(dp[i], dp[i-j] + abs(a[i]-a[i-j]));
        }
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
const static int MAX_S = 200000;

int main(){
	string S;
	cin >> S;
	int N = S.size();
	int digit[N];
	for (int i = 0; i < N; ++i) digit[i] = S[i] - '0';
	ll answer = 0;
	int ten = 1, r[N];
	r[N-1] = digit[N-1] % 2019;
	for (int i = N - 2; i >= 0; --i){
		ten = ten*10 % 2019;
		r[i] = (r[i+1] + ten*digit[i]) % 2019;
	}
	sort(r, r + N);
	answer += distance(r, upper_bound(r, r + N, 0));
	int *it = r;
	while(it != r + N){
		ll same = distance(it, upper_bound(r, r + N, *it));
		answer += same*(same - 1) >> 1;
		it = upper_bound(r, r + N, *it);
	}
	printf("%lld\n", answer);
	return 0;
}

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

 
int main() {
   int n,l;
   cin>>n>>l;

   int ans=n*l-n+(1+n)*n/2;
   if(l+n-1<0)cout<<ans-(l+n-1)<<endl;
   else if(0<l)cout<<ans-l<<endl;
   else cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
char a[4];

int main(){
  cin >> a;

  for(int i=0;i<8;i++){
    int ans=(a[0]-48);
    int x=i;
    for(int j=1;j<=3;j++){
      if(x%2==1)ans+=(a[j]-48);
      else ans-=(a[j]-48);
      x/=2;
    }
    if(ans==7){
      cout << a[0];
      x=i;
      for(int j=1;j<=3;j++){
	if(x%2==1){cout << '+' << a[j];}
	else {cout << '-' << a[j];}
	x/=2;
    }
      cout << "=7" << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;cin>>a>>b;print(a*b);
  return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>a(100000);
    int owari=0;
    for(int i=0;i<100000;i++){
        cin >> a[i];
        if(a[i]==0){
            owari=i;
            break;
        }
    }
    for(int i=0;i<owari;i++){
        cout << "Case" << " " << i+1 << ":" << " " << a[i] << endl;
    }
}


Measured memory_bytes: 3096
import sys
sys.setrecursionlimit(10000000)


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

INF=float("inf")

DP=[INF]*(N+1)

def rec(n):
    if DP[n]<INF: return DP[n]
    if n==0:
        return 0
    ans=INF
    ans=min(ans,rec(n-1)+abs(h[n]-h[n-1]))
    if n>1:
        ans=min(ans,rec(n-2)+abs(h[n]-h[n-2]))
    DP[n]=ans

    return DP[n]

ans=rec(N-1)
print(ans)


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

int N; long long a;
int A[200010][20] = {0};
int CSbB[200010][20] = {0};  //Cumulative Sum by Bit

/*部分累積和が2進数表記であるか否か*/
bool is_BinaryN(int l, int r){
  for(int i = 0; i < 20; i++){
    if(CSbB[r][i] - CSbB[l][i] > 1) return false;
  }
  return true;
}

/*問題解決関数*/
long long solve(){
  long long cn = 0;
  int l = 0; int r = 0;

  /*lがrを抜くこと無し：CSbBの性質から明らか*/
  while(l < N && r <= N){
    while(r < N && is_BinaryN(l, r+1)) ++r;
    cn += (r-l);
    ++l;
  }
  
  return cn;
}

/*aを2進数20bit表記のreverse状態に変形する*/
void conbit(long long a, int n){
  for(int i = 0; i < 20; i++){ if((a >> i) & 1) A[n][i] = 1; }
}


int main(){
  cin >> N;

  /*以下、各値を2進数に変換しAに格納*/
  for(int j = 0; j < N; j++){ cin >> a; conbit(a, j); }
  for(int j = 1; j <= N; j++){
    for(int k = 0; k < 20; k++) 
      CSbB[j][k] = CSbB[j-1][k] + A[j-1][k];  //CSbB:j番目まで
  }
  
  cout << solve() << endl;

}

Measured memory_bytes: 31488
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    
    cout << max(a + b, max(a - b, a * b));
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

long long calc(long long a,long long b,long long x){
	long long answer;
	answer=((a*x)-(a*x%b))/b-a*((x-(x%b))/b);
	return answer;
}

int main(){
	long long a,b,n;
	cin >> a >> b >> n;
	long long X=min(n,b-1);
	cout << calc(a,b,X) << endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,a,b; cin>>x>>a>>b;
    x-=a;
    cout<<(x%b)<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int s=sc.nextInt();
	
		int l=s/100;
		int r=s%100;
		String ans="NA";


		if(0<l&&l<13&&0<r&&r<13)ans="AMBIGUOUS";
		if(0<l&&l<13&&(r<1||12<r))ans="MMYY";
		if((l<1||12<l)&&0<r&&r<13)ans="YYMM";
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
 
int main ()
{
  int N ,T ,A ;
 
cin >> N >>T >> A ;
  vector<int> H (N+10);
int res =0;
int cc = 1 << 30;
for ( int i =1; i <= N ; i ++)
{
cin >> H.at(i);
int d =( T *1000 - H.at(i) *6) - A *1000;
if (d <0) d = - d ;
if ( cc > d ) cc =d , res = i ;
}
cout << res << endl;
 
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> x(m);
    rep(i,m)cin >> x[i];
    sort(x.begin(),x.end());
    if(n >= m){
        cout << 0 << endl;
        return 0;
    }
    vector<int> d(m-1);
    rep(i,m-1)d[i] = x[i+1] - x[i];
    sort(d.begin(),d.end());
    int ans = 0;
    rep(i,m-n) ans += d[i];
    cout << ans << endl;
}

Measured memory_bytes: 1024
k = int(input())
a = list(map(int, input().split()))

def solve(num, checker):
    return checker*(num//checker)

max_A = max(a)

left, right = 0, k*max_A + 1
while left < right:
    middle = (left+right)//2
    num = middle
    for i in a:
        num = solve(num, i)
    if num >= 2:
        right = middle
    else:
        left = middle + 1
x = right

left, right = 0, k*max_A + 1
while left < right:
    middle = -((-left-right)//2)
    #print(left, right, middle, num)
    num = middle
    
    for i in a:
        num = solve(num, i)
    if num <= 2:
        left = middle
    else:
        right = middle - 1
        
y = right

if y < x:
    print(-1)
else:
    print(x, y)


Measured memory_bytes: 20656
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        boolean ok = false;
        for (int i = 0; i < N; i++) {
            String s = sc.next();
            if(s.equals("Y"))ok=true;
        }
        System.out.println(ok?"Four":"Three");
    }

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


Measured memory_bytes: 22996
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

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

    std::string D = "[^";
    for (size_t i = 0; i < K; ++i) {
        char t;
        std::cin >> t;
        D += t;
    }
    D += "]+";

    std::cerr << D << std::endl;
    std::regex re(D);

    int ans = N;


    for (;;) {
        std::smatch match;
        std::string S = boost::lexical_cast<std::string>(ans);

        if(std::regex_match(S, match, re)) {
            std::cout << S << std::endl;
            return 0;
        }
        ans++;
    }


    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

int N;

void solve() {
    cin >> N;
    if (N == 1) cout << 1;
    else if (N % 2 == 0) cout << 0.5;
    else cout << (N - (N / 2)) / (double)N;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

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

    static class Ki {
        List<List<Integer>> graph;
        long[] cost;

        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            int q = in.nextInt();

            graph = new ArrayList<>();
            for (int i = 0; i <= n; i++) {
                graph.add(new ArrayList<>());
            }

            cost = new long[n + 1];

            for (int i = 1; i <= n - 1; i++) {
                int a = Integer.parseInt(in.next());
                int b = Integer.parseInt(in.next());
                graph.get(a).add(b);
                graph.get(b).add(a);
            }

            for (int i = 0; i < q; i++) {
                int p = Integer.parseInt(in.next());
                long x = Long.parseLong(in.next());
                cost[p] = cost[p] + x;
            }

            dfs(1, -1);
            for (int i = 1; i <= n; i++) {
                out.print(cost[i] + " ");
            }
        }

        public void dfs(int dst, int parent) {
            for (Integer num : graph.get(dst)) {
                if (num != parent) {
                    cost[num] += cost[dst];
                    dfs(num, dst);
                }
            }
        }

    }
}



Measured memory_bytes: 105136
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<sstream>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a*n, b) << endl;
	return 0;
}


Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    X = readInts()
    m = float('inf')
    # 端だけ保存してあげればよい
    #left = []
    #right = []
    for i in range(n-k+1):
        l = X[i]
        r = X[k+i-1]
        m = min(m,min(abs(l),abs(r)) + r - l)
    print(m)
if __name__ == '__main__':
  main()


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  int K,A,B; cin>>K>>A>>B;
  for(int i=A;i<=B;i++){
    if(i%K==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;
}


Measured memory_bytes: 3620
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC168
{
    class A
    {
        static void Main(string[] args)
        {
            //var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            //var abcd = Enumerable.Repeat(0, (int)Q).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            var S = Console.ReadLine();

            if (S[S.Length - 1] == '2' || S[S.Length - 1] == '4' || S[S.Length - 1] == '5' || S[S.Length - 1] == '7' || S[S.Length - 1] == '9')
                Console.WriteLine("hon");
            else if (S[S.Length - 1] == '0' || S[S.Length - 1] == '1' || S[S.Length - 1] == '6' || S[S.Length - 1] == '8')
                Console.WriteLine("pon");
            else
                Console.WriteLine("bon");
        }
    }
}


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

typedef long long LL;
typedef pair<int, int> II;

int main() {
    #ifdef LOCAL
        freopen("Data.inp", "r", stdin);
        freopen("Data.out", "w", stdout);
    #endif

    int n; cin >> n;
    string S; cin >> S;
    string T; cin >> T;

    for (int i = 0; i < (int) S.size(); ++i) {
        string A = S.substr(i);
        if (T.substr(0, (int) A.size()) == A) {
            cout << 2 * n - (int) A.size();
            return 0;
        }
    }

    cout << 2 * n;
    return 0;
}


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


int main(){
    int r, c, t[101][101];

    cin >> r >> c;

    for (int i = 0; i < r; i++)
        for (int j =0; j < c; j++) cin >> t[i][j];

    for (int i = 0; i <= r; i++) t[i][c] = 0;
    for (int j = 0; j <= c; j++) t[r][j] = 0;

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

    for (int i = 0; i <= r; i++) {
        for (int j = 0; j <= c; j++){
            if (j) cout << " ";
            cout << t[i][j];
        }
        cout << endl;
    }
   
}


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

int main () {
    ll n, m;
    cin >> n >> m;
    if(n * 2 <= m) cout << n + (m - 2 * n) / 4 << endl;
    else cout << m / 2 << endl;
}

Measured memory_bytes: 3628
//
//  main.cpp
//  B - Minesweeper
//
//  Created by Charles on 2017/10/14.
//  Copyright © 2017年 Charles. All rights reserved.
//

#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn=55;
int n,m,d[8][2]={0,-1,-1,-1,-1,0,-1,1,0,1,1,1,1,0,1,-1,};
char map[maxn][maxn];
void cal(int x,int y){
    int k=0;
    for(int i=0;i<8;++i){
        int tx=x+d[i][0],ty=y+d[i][1];
        if(tx<0 || ty<0 || tx>=n || ty>=m) continue;
        if(map[tx][ty]=='#') k++;
    }
    map[x][y]=k+'0';
}
int main(int argc, const char * argv[]) {
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;++i) cin>>map[i];
    for(int i=0;i<n;++i)
        for(int j=0;j<m;++j)
            if(map[i][j]=='.')cal(i,j);
    for(int i=0;i<n;++i)
        cout<<map[i]<<endl;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100000), 100000000)
}

func main() {
	h, w, k := scanInt(), scanInt(), scanInt()
	c := make([]string, h)
	for i := range c {
		c[i] = scanString()
	}

	ans := 0
	for hi := 0; hi < 1<<uint(h); hi++ {
		hm := make(map[int]bool)
		for hj := 0; hj <= h; hj++ {
			if b := 1 << uint(hj); hi&b == b {
				hm[hj] = true
			}
		}

		for wi := 0; wi < 1<<uint(w); wi++ {
			wm := make(map[int]bool)
			for wj := 0; wj < w; wj++ {
				if b := 1 << uint(wj); wi&b == b {
					wm[wj] = true
				}
			}

			cnt := 0
			for ci := range c {
				if hm[ci] {
					continue
				}
				for cj := range c[ci] {
					if wm[cj] {
						continue
					}
					if c[ci][cj] == '#' {
						cnt++
					}
				}
			}
			if cnt == k {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1776
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

lst = sorted(ILI())
K = II()
ans = lst[-1]*2**K + sum(lst[:-1])
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if(n&1){
        cout << 0;
    }else{
        int cur = 5;
        int ans = 0;
        n/=2;
        while(1){
            if(n/cur == 0){
                break;
            }
            ans += n/cur;
            cur *= 5;
        }
        cout << ans;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>
#include<string>
#include<utility>
#include<queue>

using namespace std;

int main(){
    int p,q,r;
    cin >> p >> q >> r;
    cout << p+q+r-max(p,max(q,r)) << endl;
    return 0;
}

Measured memory_bytes: 3156
n=list(map(int,input().split()))
p=['2354','3146','2651','1562','1364','2453']
for _ in range(int(input())):
    t,m=map(int,input().split())
    t=n.index(t)
    m=str(n.index(m)+1)
    print(n[int(p[t][(p[t].index(m)+1)%4])-1])


Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define endl '\n'
#define ll unsigned long long

using namespace std;

ll n, ans, i;

int main() {
    ios_base::sync_with_stdio(0);
    

    cin >> n;
    ans = 100;
    while(ans < n) {
        ans = ans + (ans / 100);
        i++;
    }

    cout << i << endl;

    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a[200001],i,sum=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
        {
            sum+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
        else if(a[i]>a[i-1])
        {
            sum+=0;
        }
    }
    cout<<sum<<endl;
}

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

const int MAXN = 200001;

ll a[MAXN];

int main() {
#ifdef PAUNSVOKNO
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
    int n;
    cin >> n;

    ll cur = 2;

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

    if (a[n - 1] != 2) {
        cout << -1 << "\n";
        return 0;
    }

    ll l = 2, r = 3;

    for (int i = n - 2; i >= 0; --i) {
        if (r / a[i] == (l - 1) / a[i]) {
            cout << -1 << "\n";
            return 0;
        }

        r = r / a[i] * a[i];
        l = ((l - 1) / a[i] + 1) * a[i];
        r += a[i] - 1;
    }

    cout << l << " " << r << "\n";
}

Measured memory_bytes: 1024
N = int(input())
colors = {}
any_color = 0
for rate in list(map(int, input().split())):
    if rate < 400:
        colors['gray'] = True
    elif rate < 800:
        colors['brawn'] = True
    elif rate < 1200:
        colors['green'] = True
    elif rate < 1600:
        colors['water'] = True
    elif rate < 2000:
        colors['blue'] = True
    elif rate < 2400:
        colors['yellow'] = True
    elif rate < 2800:
        colors['orange'] = True
    elif rate < 3200:
        colors['red'] = True
    else:
        any_color += 1

min_color = max(len(colors.keys()), 1)
max_color = len(colors.keys()) + any_color
print(min_color, max_color)


Measured memory_bytes: 38256
import java.util.Scanner;

// B - ROT N
// https://atcoder.jp/contests/abc146/tasks/abc146_b
public class Main {

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

        int N = Integer.parseInt(scanner.next());
        char[] S = scanner.next().toCharArray();

        scanner.close();

        for (char c : S) {
            int number = c - 'A';
            System.out.print((char) ((number + N) % 26 + 'A'));
        }
        System.out.println();
    }
}


Measured memory_bytes: 27344
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var y=Arr.shift()-0;
   var S=[];
   var s=[];
   for(var i=0;i<n;i++){
      var brt=(Arr.shift()).split(" ").map(Number);
      var r=brt[1];
      var t=brt[2];
      var result;
      if(t==1)result=10000*(1+(y*(r/100)));
      if(t==2)result=10000*Math.pow((1+(r/100)),y);
      S.push(brt[0]);
      s.push(result);
   }
   var max=Math.max.apply(null,s);
   console.log(S[s.indexOf(max)]);
}

Measured memory_bytes: 10672
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    int x, a; cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
	return 0;
} 

Measured memory_bytes: 764
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int64_t solve(int64_t n, int64_t p) {
  std::vector<std::pair<int64_t, int64_t>> primes;
  while (p % 2 == 0) {
    if (primes.empty() || primes.back().first != 2) {
      primes.emplace_back(std::make_pair(2, 1));
    } else {
      primes.back().second++;
    }
    p /= 2;
  }
  auto const nn = static_cast<int64_t>(sqrt(p * 1.0));
  for (int64_t i = 3; i <= nn && p > 1; i += 2) {
    while (p % i == 0) {
      if (primes.empty() || primes.back().first != i) {
        primes.emplace_back(std::make_pair(i, 1));
      } else {
        primes.back().second++;
      }
      p /= i;
    }
  }
  if (p > 1) {
    primes.emplace_back(std::make_pair(p, 1));
  }
  int64_t ret = 1;
  for (auto& prime : primes) {
    while (prime.second >= n) {
      ret *= prime.first;
      prime.second -= n;
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  int64_t p;
  std::cin >> p;
  auto const res = solve(n, p);
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
import itertools
n = int(input()) 
l = [input()[0] for _ in range(n)]
l = [i for i in l if i in {'M','A','R','C','H'}]

if len(l) < 3:
    print(0)
else:
    c = Counter(l)
    cl = list(itertools.combinations(c,3))
    ans = 0
    for i in cl:
        ans += c[i[0]] * c[i[1]] * c[i[2]]
    print(ans)

Measured memory_bytes: 4984
import sys
class DSU:
    def __init__(self, n):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a, b):
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        x, y = self.leader(a), self.leader(b)
        if x == y: return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a, b):
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        return self.leader(a) == self.leader(b)

    def leader(self, a):
        assert 0 <= a < self._n
        if self.parent_or_size[a] < 0: return a
        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a):
        assert 0 <= a < self._n
        return -self.parent_or_size[self.leader(a)]

    def groups(self):
        leader_buf = [self.leader(i) for i in range(self._n)]
        result = [[] for _ in range(self._n)]
        for i in range(self._n): result[leader_buf[i]].append(i)
        return [r for r in result if r != []]

class Fenwick_Tree:
    def __init__(self, n):
        self._n = n
        self.data = [0] * n

    def add(self, p, x):
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)

    def _sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s
INF = float('inf')
def Bellmanford(n, edges, r): #r: 始点
    d = [INF] * n
    d[r] = 0
    
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n-1 and v == n-1:
                    return 'inf'
    
    return -d[n-1]
N, M = map(int, sys.stdin.readline().split())
Edges = [None] * M

for i in range(M):
    ai, bi, ci = map(int, sys.stdin.readline().split())
    Edges[i] = (ai-1, bi-1, -ci)
    
ans = Bellmanford(N, Edges, 0)

print(ans)  

Measured memory_bytes: 9412
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 10000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll n;cin>>n;
  vll sum(n+1,0);
  rep(i,0,n){
    ll a;cin>>a;
    sum[i+1]=sum[i]+a;
  }
  ll ans=MOD;
  rep(i,1,n){
    ans=min(ans,abs(sum[n]-sum[i]*2));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4848
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int H, N;
    cin >> H >> N;
    vector<vector<int> > AB(N,vector<int>(N,0));
    vector<int> dp(H+1,(int) MOD);
    dp[H]=0;

    for(auto &ab:AB){
        cin >> ab[0] >> ab[1];
    }

    for(int i=0; i<N; i++){
        for(int j=H; j>=-AB[i][0]; j--){
            if(j+AB[i][0]<=H){
                dp[max(0,j)]=min(dp[max(0,j)], dp[j+AB[i][0]]+AB[i][1]);
            }
        }
    }
    cout << dp[0] << endl;
}

Measured memory_bytes: 4224
#include <stdio.h>

void print(int a[], int N)
{
	for (int i = 0; i < N; i++)
	{
		printf("%d", a[i]);
		if (i != N - 1)
		{
			printf(" ");
		}
	}
	printf("\n");
}
int main()
{
	int a[100];
	int key;
	int N;
	scanf("%d", &N);

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


	print(a, N);

	int j;
	for (int i = 1; i < N; i++)
	{
		key = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > key)
		{
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = key;
		print(a, N);
	}

	return 0;
}


Measured memory_bytes: 1928
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC096C
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            var h = input[0];
            var w = input[1];

            var dummy = Enumerable.Repeat('.', w + 2).ToArray();

            var board = new List<char[]>();
            board.Add(dummy);
            for(int i = 0; i < h; i++)
            {
                board.Add($".{Console.ReadLine()}.".ToCharArray());
            }
            board.Add(dummy);

            for(int i = 1; i <= h; i++)
            {
                for(int j = 0; j <= w; j++)
                {
                    if(board[i][j] != '#')
                    {
                        continue;
                    }

                    if (board[i - 1][j] == '#')
                    {
                        continue;
                    }
                    if (board[i][j -1 ] == '#')
                    {
                        continue;
                    }
                    if (board[i + 1][j] == '#')
                    {
                        continue;
                    }
                    if (board[i][j + 1] == '#')
                    {
                        continue;
                    }

                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair< P , int > PP;
struct edge{int to,cost,type,id;};
int m,n,T,cnt,si,ti;
string str;
vector< edge > G[300005];
P d[300005];
int v[100005],w[100005];
edge p[200005];
map<string,int> mp;

int change(string &str){
  if(mp.count(str))return mp[str];
  else return mp[str]=mp.size();
}

int main(){
  cin>>m>>T;
  cin>>str;si=change(str);
  cin>>str;ti=change(str);
  for(int i=0;i<m;i++){
    cin>>n;
    for(int j=0;j<n;j++){
      cin>>str;
      v[j]=change(str);
    }
    for(int j=0;j+1<n;j++){
      cin>>w[j];
      G[v[j]].push_back((edge){v[j+1],w[j],i,++cnt});
      p[cnt]=G[v[j]].back();
    }
    for(int j=n-2;j>=0;j--){
      G[v[j+1]].push_back((edge){v[j],w[j],i,++cnt});
      p[cnt]=G[v[j+1]].back();
    }
  }
  int C=mp.size();
  fill(d,d+300005,P(1e9,1e9));
  d[0]=P(0,0);  
  priority_queue<PP,vector<PP>,greater<PP> > Q;
  Q.push(PP(P(-T,-1),1));
  P ans=P(-1,-1);
  while(!Q.empty()){
    PP q=Q.top();Q.pop();
    if(q.first>d[q.second])continue;
    P cost=q.first;
    int pos=q.second;
    if(pos==ti){
      ans=cost;
      break;
    }
    if(q.second<=C){
      for(int i=0;i<(int)G[pos].size();i++){
        edge e=G[pos][i];
        P ncost=cost;
        ncost.first+=(e.cost+T);
        ncost.second++;
        if(ncost<d[e.id+C]){
          d[e.id+C]=ncost;
          Q.push(PP(ncost,e.id+C));
        }
      }
    }else{
      edge f=p[pos-C];
      if(cost<d[f.to]){
        d[f.to]=cost;
        Q.push(PP(cost,f.to));
      }
      for(int i=-1;i<=1;i+=2){
        if(f.id+i<=0||cnt<f.id+i)continue;
        edge e=p[f.id+i];
        if(e.type!=f.type)continue;
        P ncost=cost;
        ncost.first+=e.cost;
        if(ncost<d[e.id+C]){
          d[e.id+C]=ncost;
          Q.push(PP(ncost,e.id+C));
        }
      }
    }
  }
  if(ans.first==-1)cout<<-1<<endl;
  else cout<<ans.first<<' '<<ans.second<<endl;
  return 0;
}

Measured memory_bytes: 26644
#include <bits/stdc++.h>
#include <sys/time.h>
#define IOS ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define deb(x) cout << #x << " " << x << endl;
#define fi(i,a,b) for(int i = a; i<b; i++)
#define ll long long int
#define pii pair<int, int>
#define F first
#define S second
#define vi vector<int>
#define N 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
using namespace std;
int getTime() {
	struct timeval start;
	gettimeofday(&start, NULL);
	return start.tv_sec * 1000000 + start.tv_usec;
}

//*************************************************************************************

void solve() {

	int k; cin >> k; string s; cin >> s;
	if (s.length() <= k) {cout << s;}
	else {cout << s.substr(0, k) << "...";}
}
int main() {

//#ifndef ONLINE_JUDGE
//	freopen("input1.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif

	IOS;

	int t = 1;
	fi(i, 0, t) {solve();}
	return 0 ;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  while (cin >> N) {
    vector<int> x(N);
    for (int i = 0; i < N; i++) {
      cin >> x[i];
    }
    int pre = 1, size = 1;
    ll res = 1;
    for (int i = 1; i < N; i++) {
      int cur = pre + 2;
      if (cur <= x[i]) {
        pre = cur;
        ++size;
        continue;
      }
      res = res * (size + 1) % MOD;
    }
    for (int i = 1; i <= size; i++) {
      res = res * i % MOD;
    }
    cout << res << endl;
  }
  return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vector<ll> x(N), y(M);
    rep (i, N) {
        cin >> x[i];
    }
    rep (i, M) {
        cin >> y[i];
    }

    sort(x.rbegin(), x.rend());
    sort(y.begin(), y.end());

    bool flag = false;
    for (ll i = X+1; i <= Y; i++) {
        if (x[0] < i && i <= y[0]) {
            flag = true;
        }
    }

    if (flag) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
    int N;
    cin >> N;
    int dig = to_string(N).size();
    int ans = dig % 2 ? N - pow(10, dig - 1) + 1 : 0;
    for (int i = 1; i < dig; i += 2) {
        auto t = 9 * pow(10, i - 1);
        ans += t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int n,D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p == NIL) printf("root, ");
  else if(T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");

}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r != NIL) calcDepth(T[u].r,p);
  if(T[u].l != NIL) calcDepth(T[u].l,p+1);
}

int main(){
  int i, j, k;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  
  for(i=0; i < n;i++)T[i].p = T[i].l = T[i].r = NIL;

  for(i=0; i < n;i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j < k;j++){
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i < n;i++){
    if(T[i].p == -1) root = i;
  }

  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

//出力 (output)
  for(i=0; i < n;i++){
    print(i);
  }

  return 0;
}



Measured memory_bytes: 6424
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

template <typename T>
constexpr bool chmin(
    T a, T b, function<bool(T, T)> f = [](T a, T b) { return a > b; }) {
  // when f is true, b is more 'smaller'
  if (f(a, b)) {
    swap(a, b);
    return true;
  }
  return false;
}
template <typename T> constexpr bool chmax(T a, T b) {
  return chmin(a, b, [](T a, T b) { return a < b; });
}
template <typename ite> void print_ite(ite start, ite end, char c = ' ') {
  for (auto i = start; i != end; i++)
    cout << *i << c;
  cout << endl;
}
template <typename ite> void scan_ite(ite start, ite end) {
  for (auto i = start; i != end; i++)
    cin >> (*i);
}
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

vector<ll> divisors(ll n) {
  vector<ll> res;
  ll i = 1;
  for (; i * i < n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      res.push_back(n / i);
    }
  }
  if (i * i == n)
    res.push_back(i);
  return res;
}

vector<pair<ll, int>> prime_div(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int count = 0;
      while (n % i == 0) {
        n /= i;
        count++;
      }
      res.push_back(make_pair(i, count));
    }
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}

ll ope1(ll n, ll k) {
  while (n % k == 0)
    n /= k;
  return n;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  auto v = prime_div(n - 1);
  ll d = 1;
  for (auto i : v) {
    d *= i.second + 1;
  }
  ans += --d;
  auto ve = divisors(n);
  for (auto i : ve) {
    if (i == 1)
      continue;
    ll t = ope1(n, i);
    if (t % i == 1)
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>

using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;

int main()
{
	int a, b;
	cin>>a;
	cin>>b;
	cout<<(a-1)*(b-1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){

int a,b,i,n;
while(1){
scanf("%d %d",&a,&b);
if(a == 0 && b == 0)break;
for(i = 0;i < a;i++){
for(n = 0;n<b;n++){
    printf("#");
    }
    printf("\n");
    }
    printf("\n");
    }
return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int ans=0;
    if(a-b>=2){
        ans=2*a-1;
        cout<< ans << endl;
    }
    else if(b-a>=2){
        ans = 2*b-1;
        cout << ans << endl;
    }
    else{
        ans = a+b;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define ll long long
    #define sz(a) int((a).size())
    #define fr(i,n) for(int i=0;i<n;i++) 
    #define rf(i,n) for(int i=1;i<=n;i++)
    #define jdb(i,v) for(__typeof(v.begin())i=v.begin(); i!=v.end();i++)
    #define present(c,a) (find(all(c),a) != c.end())
    #define spresent(c,a) (c.find(a)!=c.end())
    #define no(s,c) s.count(c)  
    #define pb push_back 
    #define eb emplace_back
    #define mp make_pair
    #define all(c) (c).begin(),(c).end()
    #define MAX INT_MAX 
    using namespace std;
    #define f first
    #define s second                                           
    int main() 
    { 
        double a,b;
        cin>>a>>b;
        cout<<fixed;
        cout<<setprecision(10)<<a/b<<endl;
        return 0; 
    }


Measured memory_bytes: 256
main = do
    [n, m] <- map read <$> words <$> getLine :: IO [Integer]
    a <- map read <$> words <$> getLine :: IO [Integer]
    let p = foldl1 lcm $ map (`div` 2) a
    print $ if ok a then (m + p) `div` (p * 2) else 0

ok a | all odd a  = True
     | all even a = ok $ map (`div` 2) a
     | otherwise  = False


Measured memory_bytes: 49952
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
  
    int count = scanner.nextInt();
    int[] scores = new int[count];
    int sum = 0;
    for (int ix = 0; ix < scores.length; ix++) {
      scores[ix] = scanner.nextInt();
      sum += scores[ix];
    }
  
    Arrays.sort(scores);
    for (int ix = 0; ix < scores.length; ix++) {
      if (sum % 10 != 0) break;
      if (scores[ix] % 10 != 0) {
        sum -= scores[ix];
      }
    }
    
    if (sum % 10 != 0) {
      System.out.println(sum);
    } else {
      System.out.println(0);
    }
  }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
bool vis[100003];
int n,dp[100003];
vector<int>v[100003];
long long dfs(int x){
	if(dp[x])return dp[x];
	vis[x]=1;
	long long ans1=1,ans2=1;
	for(int i=0;i<v[x].size();i++)
		if(!vis[v[x][i]]||dp[v[x][i]])
			ans1=ans1*dfs(v[x][i])%1000000007;
	for(int i=0;i<v[x].size();i++)
		if(!vis[v[x][i]]||dp[v[x][i]])
			for(int j=0;j<v[v[x][i]].size();j++)
				if(!vis[v[v[x][i]][j]]||dp[v[v[x][i]][j]])
					ans2=ans2*dfs(v[v[x][i]][j])%1000000007;
	dp[x]=(ans1+ans2)%1000000007;
	return (ans1+ans2)%1000000007;
}
int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		v[a-1].push_back(b-1);
		v[b-1].push_back(a-1);
	}
	cout<<dfs(0);
} 

Measured memory_bytes: 13184