akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<utility>
#include<functional>
#include<algorithm>
#include<bitset>
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	vector<int>v;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(),v.end());
	cout<<v[0]+v[1];
	return 0;
}

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

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

//prime factorization
vector<int> factorize(ll n) {
    vector<int> res;
    for (ll i = 2; i*i <= n; i++) {
        if (n%i) continue;
        res.emplace_back(i);
        while (n%i == 0) {
            n /= i;
        }
    }
    if (n != 1) res.emplace_back(n);
    return res;
}


int main() {
    ll a, b;
    cin >> a >> b;
    ll n = gcd(a, b);
    auto f = factorize(n);
    int ans = f.size() + 1;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 384
n = int(input())
list1 = []

chinpo = 1

if n == 0:
    print(0)
    exit()

while True:
    if n==0:
        break
    if n%2 != 0:
        n -=1
        list1.append(1)
    else:
        list1.append(0)
    n /= -2

list1.reverse()
print("".join(map(str,list1)))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = s.size();
    ll cnt = 0;
    for (int i = 1; i < n; i++) {
        if (s[i-1] != s[i]) {
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int k, s;
    cin >> k >> s;
    
    int ans = 0;
    REP(i,k+1) {
        if (i > s) break;
        REP(j,k+1) {
            if (i+j > s) break;
            if (s-(i+j) <= k) ans++;
        }
    }

    cout << ans << '\n';

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    
    int keta1;
    keta1 = N%10;
    
    if(keta1==2 || keta1==4 || keta1==5 || keta1==7 || keta1==9){
        cout << "hon" << endl;
    }else if(keta1==0 || keta1==1 || keta1==6 || keta1==8){
        cout << "pon" << endl;
    }else if(keta1==3){
        cout << "bon" << endl;
    }

}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		long k = sc.nextLong();
		System.out.println((a-b) * (k % 2 == 0 ? 1 : -1));
	}

}


Measured memory_bytes: 21844
import java.util.*;

class Main {

    String s;
    String t;

    private void run() {

        Scanner sc = new Scanner(System.in);
        s = sc.next();
        t = sc.next();

        int S = s.length();
        int T = t.length();

        int[][] dp = new int[S+1][T+1];
        int[][] dpstr = new int[S+1][T+1];
        // 0 is diagonal
        // 1 is up
        // 2 is left

        for (int i = 0; i <= S; i++) {
            for (int j = 0; j <= T; j++) {
                if (i == 0 || j == 0) dp[i][j] = 0;
                else if (s.charAt(i-1) == t.charAt(j-1)) {
                    dpstr[i][j] = 0;
                    dp[i][j] = dp[i-1][j-1] + 1;
                } else if (dp[i-1][j] > dp[i][j-1]) {
                    dpstr[i][j] = 1;
                    dp[i][j] = dp[i-1][j];
                } else {
                    dpstr[i][j] = 2;
                    dp[i][j] = dp[i][j-1];
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        int i = S, j = T;
        while (i != 0 && j != 0) {
            if (dpstr[i][j] == 0) {
                sb.append(s.charAt(i-1));
                i--;
                j--;
            } else if (dpstr[i][j] == 1)
                i--;
            else
                j--;
        }

        System.out.println(sb.reverse());
    }


    public static void main(String[] args) {
        Main solver = new Main();
        solver.run();
    }
}


Measured memory_bytes: 129356
// no proof is included. may have unused libraries. may have unused variables. possibly dirty code - contest mode

#include <iostream> // std::cin, std::cout
#include <cstring> // std::memset()
#include <algorithm> // std::max_element(), std::min_element(), std::reverse(), std::sort(), std::__gcd()

using namespace std;

bool debug = true;

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

    int k, x;
    cin >> k >> x;

    cout << (500 * k >= x ? "Yes" : "No") << "\n";

    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn read_mat<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let v = read_vec::<usize>();
    let (n,m) = (v[0],v[1]);
    let d = read_mat::<usize>(m);
    let c = read_mat::<usize>(n);
    let mut min3: Vec<Vec<(usize,usize)>> = vec![vec![(usize::max_value(),0);3];3];
    for col in 0..m {
        let mut tv: Vec<usize> = vec![0;3];
        for i in 0..n {
            for j in 0..n {
                tv[(i+j)%3] += d[c[i][j]-1][col];
            }
        }
        min3[0].push((tv[0],col));
        min3[0].sort_by(|a,b| a.0.cmp(&b.0));
        min3[0].remove(3);
        min3[1].push((tv[1],col));
        min3[1].sort_by(|a,b| a.0.cmp(&b.0));
        min3[1].remove(3);
        min3[2].push((tv[2],col));
        min3[2].sort_by(|a,b| a.0.cmp(&b.0));
        min3[2].remove(3);
    }
    let mut ans = usize::max_value();
    for i in 0..3 {
        for j in 0..3 {
            for k in 0..3 {
                if min3[0][i].1 != min3[1][j].1 && min3[1][j].1 != min3[2][k].1 && min3[0][i].1 != min3[2][k].1 {
                    ans = cmp::min(ans,min3[0][i].0 + min3[1][j].0 + min3[2][k].0);
                }
            }
        }
    }
    println!("{}",ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97 '0'=0x30=48
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int h,w,k,ans=0;
  cin>>h>>w>>k;
  char c;
  veci yoko(h);
  veci tate(w);
  vector<veci> M(h);
  int all=0;
  rep(i,h){
    rep(j,w){
      cin>>c;
      if(c=='#'){yoko[i]++;tate[j]++;all++;M[i].push_back(1);}
      else M[i].push_back(0);
    }
  }//ok
  int temp,ttt;
  for(int bit=0;bit<(1<<h);bit++)
  {
     temp=all;veci vs={};
    for(int j=0;j<h;j++){
       if (bit & (1<<j)){temp-=yoko[j];
      vs.push_back(j);}
    }ttt=temp;
    for(int bitl=0;bitl<(1<<w);bitl++){
      temp=ttt;
      for (int ip=0;ip<w;ip++){
        if (bitl & (1<<ip)){temp-=tate[ip];
        for(int ij=0;ij<vs.size();ij++){
        temp+=(bool)(M[vs[ij]][ip]);
        }}}
      if(temp<0)temp=0;
      if(temp==k)ans++;cerr<<temp<<" "<<bit<<bitl<<endl;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
const int mod = (int)1e9+7;
int add(int a, int b) { return (a += b) >= mod? a -= mod : a; }
int mul(int a, int b) { return int(1LL * a * b % mod); }
int pow(int a, int n) {
    if (n == 0) return 1;
    if (a <= 1) return a;
    int r(1);
    while (n) {
        if (n & 1) r = mul(r,a);
        a = mul(a,a); n >>= 1;
    }
    return r;
}
int inv(int a) { return pow(a,mod-2); }
const int NMAX = 500500;
int fact[NMAX];
int C(int n, int k) {
    if (k < 0 || k > n) return 0;
    return mul(fact[n], inv(mul(fact[k], fact[n-k])));
}
int main() {
    fact[0] = 1;
    for (int i = 1; i < NMAX; i++) fact[i] = mul(i,fact[i-1]);
    int n, m; std::cin >> n >> m;
    int a = mul(C(m,n),fact[n]);
    int b = 0;
    for (int i = 0; i <= n; i++) {
        int curr = mul(C(n,i), mul(C(m-i,n-i),fact[n-i]));
        if (i % 2 == 0) b = add(b, curr);
        else b = add(b,mod-curr);
    }
    std::cout << mul(a,b) << std::endl;
    return 0;
}

Measured memory_bytes: 5552
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

int main(){
	long long D, N;
	cin >> D >> N;

	if (N == 100) N++;
	cout << fixed << setprecision(0);
	cout << N * pow(100, D) << endl;
}

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

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			int n = Integer.parseInt(br.readLine());
			if(n == 0) break;

			HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
			int ans = -1;
			StringTokenizer st = new StringTokenizer(br.readLine());
			int div = n / 2;
			int max = 0;

			for(int i=0;i<n;i++){
				if(div - max > n - i) break;
				int x = Integer.parseInt(st.nextToken());
				if(map.get(x) == null){
					if(i>div) continue;
					else map.put(x,0);
				}
				int time = map.get(x) + 1;
				if(time > max){
					max = time;
					ans = x;
					if(div<time) break;
				}
				map.put(x,time);
			}

			System.out.println(max<=div ? "NO COLOR" : ans);
		}
	}
}

Measured memory_bytes: 38000
n,h=map(int,input().split())
ab=[]
for i in range(n):
    ab.append([int(j) for j in input().split()])

from operator import itemgetter
ab.sort(key=itemgetter(0))
nm=ab[-1][0] 

ab.sort(key=itemgetter(1)) 
ab.reverse()

ans=0
for i in range(n):
    if ab[i][1]>=nm:
        h-=ab[i][1]
        ans+=1
    if h<=0:
        print(ans)
        import sys
        sys.exit()
import math
ans+=math.ceil(h/nm)
print(ans)

Measured memory_bytes: 22768
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int **Adj,*v;
  int n,i,j,k,u;

  scanf("%d",&n);
  Adj=(int **)malloc(sizeof(int *)*n+1);
  for(i=1;i<n+1;i++)
    Adj[i]=(int *)malloc(sizeof(int)*n+1);

  

  for(i=1;i<n+1;i++)
    {
      scanf("%d",&u);
      scanf("%d",&k);
      v=(int *)malloc(sizeof(int)*k+1);
      for(j=1;j<k+1;j++)scanf("%d",&v[j]);
      
      for(j=1;j<k+1;j++) Adj[u][v[j]]=1;
      free(v);
    }

  for(i=1;i<n+1;i++)
    {
      for(j=1;j<n;j++)
	{
	  if(Adj[i][j]!=1) printf("%d ",0);
	  else printf("%d ",1);
	}
      if(Adj[i][n]!=1) printf("%d\n",0);
      else printf("%d\n",1);
    }

  for(i=1;i<n+1;i++)
    free(Adj[i]);
  free(Adj);


  return 0;
}



Measured memory_bytes: 2072
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <queue>

using namespace std; 

typedef pair<int,int> P;

int W,H;

bool pass[900][900];

//スタートからの距離
int d[50][50];

//上下左右
const int dw[4]={0,0,-1,1};
const int dh[4]={-1,1,0,0};

const int INF=10000;


void bfs(){
	queue<P> que;
	for(int i=0;i<50;i++){
		for(int j=0;j<50;j++){
			d[i][j]=INF;
		}
	}
	que.push(P(0,0));
	d[0][0]=1;

	while(!que.empty()){
		int h,w;
		h=que.front().first;
		w=que.front().second;
		que.pop();
		if(h==H-1 && w==W-1) break;


		for(int i=0;i<4;i++){
			//隣の座標
			int nh=h+dh[i];
			int nw=w+dw[i];

			//現在，次の頂点番号
			int n=W*h+w;
			int m=W*nh+nw;

			if(0<=nh && nh<H && 0<=nw && nw<W && pass[n][m] && d[nh][nw]==INF){
				que.push(P(nh,nw));
				d[nh][nw]=d[h][w]+1;
			}

		}

	}

}


int main(){



	while(cin>>W>>H,W){

		for(int i=0;i<900;i++)
			for(int j=0;j<900;j++) pass[i][j]=false;



		//マップ読み込み
		for(int i=0;i<2*H-1;i++){
			//右に移動が可能か
			if(i%2==0){
				for(int j=0;j<W-1;j++){
					int c;
					cin>>c;

					int h=i/2,w=j;
					if(c==0){
						 pass[W*h+w][W*h+(w+1)]=pass[W*h+(w+1)][W*h+w]=true;
					}
				}
			}//下に移動が可能か
			else{
				for(int j=0;j<W;j++){
					int c;
					cin>>c;

					int h=i/2,w=j;
					if(c==0){
						 pass[W*h+w][W*(h+1)+w]=pass[W*(h+1)+w][W*h+w]=true;
					}
				}
			}
		}


		bfs();
		if(d[H-1][W-1]==INF) d[H-1][W-1]=0;
		cout<<d[H-1][W-1]<<endl;

	}

	return 0;
}

Measured memory_bytes: 2016
import math
n=int(input())
hyoujunhensa=[]

while n!=0:
    tokuten=list(map(int,input().split()))

    average=sum(tokuten)/n
    a2=0

    for i in range(n):
        a2=a2+pow(tokuten[i]-average,2)
    a2=math.sqrt(a2/n)
    hyoujunhensa.append(a2)
    n=int(input())

for j in range(len(hyoujunhensa)):
    print(hyoujunhensa[j])



Measured memory_bytes: 5704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;

  if(S == U){
    A = A - 1;
  }else {
    B = B - 1;
  }

  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import Counter

def main():
    n = int(input())
    v = list(map(int, input().split()))

    c_even = sorted(Counter(v[::2]).items(), key=lambda x: x[1],reverse=True)
    c_odd  = sorted(Counter(v[1::2]).items(), key=lambda x: x[1],reverse=True)
    if c_even[0][0] == c_odd[0][0]:
        if len(c_even) == 1:
            print(n//2)
        else:
            a = n - c_even[0][1] - c_odd[1][1]
            b = n - c_even[1][1] - c_odd[0][1]
            print(min(a,b))
    else:
        print(n - c_even[0][1] - c_odd[0][1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 20692
import math

n = int(input())

cnt = 0
x = 0
y = 0
r = 0

while True:
    cnt += 1
    x += round(math.cos(math.radians(r)), 6)
    y += round(math.sin(math.radians(r)), 6)
    r += n
    
    if x <= 0.00000001 and y <= 0.00000001:
        break

print(cnt)

Measured memory_bytes: 9456
def even(n):
  return n//2
def odd(n):
  return 3*n+1
s=input()
if s in"124":
  print(4)
  exit()
s=int(s)
c=0
while 1:
  if s%2==0:
    s=even(s)
  else:
    s=odd(s)
  c+=1
  if s==4:
    print(c+4)
    exit()

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 987654321
#define IINF 2987654321987654321
#define MOD 998244353

int main() {
	int n, k; scanf("%d%d", &n, &k);
	int cnt = 0;
	while(n--) {
		int t; scanf("%d", &t);
		if(t >= k) cnt++;
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
using namespace std;

int main()
{
    string s,t;
    int count=0;

    cin>>s;
    cin>>t;  

    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
        {
            count++;
        }
    }

    cout<<count;
}

Measured memory_bytes: 3924
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	int k, s;
	int ans = 0;
	cin >> k >> s;

	roop(x,0, k+1) {
		roop(y,0,k+1) {
			int z = s - x - y;
			if (z >= 0 && z <= k) {
				ans++;
			}
		}
	}

	cout << ans << endl;


	return 0;
}


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

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

VI e[100000];

int dfs(int now, int past){
	int ret = 0;
	for (int next : e[now]){
		if (next == past) continue;
		ret ^= (dfs(next, now) + 1);
	}
	return ret;
}

int main() {
	int n;
	cin >> n;
	REP(i,n-1){
		int u, v;
		scanf("%d %d", &u, &v);
		u--;
		v--;
		e[u].push_back(v);
		e[v].push_back(u);
	}

	cout << (dfs(0, -1) > 0 ? "Alice" : "Bob") << endl;

	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
using namespace std;
int main(){
	int N1;
	int h[101];
	int m[101];
	cin>>N1;
	for(int i=0;i<N1;i++)
		cin>>h[i]>>m[i];	
	h[N1]=24; m[N1]=0;
	int N2;
	int k[101];
	int g[101];
	cin>>N2;
	for(int i=0;i<N2;i++)
		cin>>k[i]>>g[i];
	k[N2]=24; g[N2]=0;
	for(int i=0,j=0;i<N1 || j<N2;){
		if(h[i]==k[j]&& m[i]==g[j]){
			cout<<h[i]<<':'<<m[i]/10<<m[i]%10;
			i++; j++;
		}
		else if(h[i]<k[j]||(h[i]==k[j] && m[i]<g[j])){
			cout<<h[i]<<':'<<m[i]/10<<m[i]%10;
			i++;
		}
		else{
			cout<<k[j]<<':'<<g[j]/10<<g[j]%10;
			j++;
		}
		if(i==N1&&j==N2)
			cout<<endl;
		else
			cout<<' ';
	}
	return 0;
}

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

int main()
{
	int n,x,l[100];
	cin>>n>>x;
    for(int i=0;i<n;i++) cin>>l[i];
	
	int d[101]={},v;
    for(v=1;v<=n;v++){
        d[v]=d[v-1]+l[v-1];
        if(x<d[v]) break;
    }

    cout<<v<<endl;

	return 0;
}


Measured memory_bytes: 256
s=require('fs').readFileSync('/dev/stdin','utf8').split('\n');
[n,k]=s[0].split(' ').map(n=>n|0)
s.shift()
s=s.map(n=>n|0).sort((a,b)=>b-a)
console.log(Math.min(...Array(n-k+1).fill().map((_,i)=>s[i]-s[i+k-1])))

Measured memory_bytes: 29476
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)cin>>in[i];
	vi out(n,0);
	rep(i,m){
		int a;
		cin>>a;
		rep(j,n)if(a>=in[j]){
			out[j]++;
			break;
		}
	}
	int ma=-1;
	rep(i,n)ma=max(ma,out[i]);
	rep(i,n)if(ma==out[i])cout<<i+1<<endl;
	
	}

Measured memory_bytes: 1200
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int t = 1, s = 0;
  for(int i = 1; i <= N; ++i){
    s += i;
    if(s >= N){
      t = i;
      break;
    }
  }
  for(int i = 1; i <= t; ++i){
    if(i != s - N) cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
   
   
    const int mod=998244353.;
    const int N=1e6+5; 
   
    bool sortbysec(const pair<pair<ll,ll>,ll> &a, 
                      const pair<pair<ll,ll>,ll> &b) 
        { 
            return (a.second > b.second); 
        } 
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }
       
        bool isprime(int n) 
        { 
            if (n <= 1)  return false; 
            if (n <= 3)  return true; 
            if (n%2 == 0 || n%3 == 0) return false; 
            for (int i=5; i*i<=n; i=i+6) 
                if (n%i == 0 || n%(i+2) == 0) 
                   return false; 
           return true; 
    
        }
    
    int main()
    {
        FAST;
        string s;
        cin>>s;
        if(s=="BBB" || s=="AAA")
        cout<<"No"<<"\n";
        else
        cout<<"Yes"<<"\n";
           
        return 0;
    }

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

long long gcd(long long x,long long y){
	if(y==0)return x;
	return gcd(y,x%y);
}

int main(){
	ios::sync_with_stdio(0);
	long long n,a,b,c,d;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a>>b>>c>>d;
		if(a<b||b>d){
			cout<<"No\n";
			continue;
		}
		if(b<=c+1){
			cout<<"Yes\n";
			continue;
		}
		long long g=gcd(b,d);
		if((a%g)+b-g>c)cout<<"No\n";
		else cout<<"Yes\n";
	}
	return 0;
}

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

using namespace std;

int power(int a, int b)
{
	int x = 1;

	for (int i = 0; i < b; i++)
	{
		x *= a;
	}

	return x;
}

int main()
{
	int R, C;

	while (true)
	{
		cin >> R >> C;

		if (R == 0 && C == 0) { break; }

		vector<vector<int> > a(R, vector<int>(C));

		for (int i = 0; i < R; i++)
			for (int j = 0; j < C; j++)
				cin >> a[i][j];

		vector<vector<int> > a2;

		int sum, sum2, max_ = 0;

		for (int i = 0; i < power(2, R); i++)
		{
			sum = 0;

			a2 = a;

			for (int j = 0; j < R; j++)
			{
				if ((i / power(2, j)) % 2 == 1)
				{
					for (int k = 0; k < C; k++)
					{
						if (a2[j][k] == 0)
						{
							a2[j][k] = 1;
						}
						else if (a2[j][k] == 1)
						{
							a2[j][k] = 0;
						}
					}
				}
			}

			for (int j = 0; j < C; j++)
			{
				sum2 = 0;

				for (int k = 0; k < R; k++)
				{
					if (a2[k][j] == 0)
					{
						sum2++;
					}
				}

				sum2 = max(sum2, R - sum2);

				sum += sum2;
			}

			max_ = max(max_, sum);
		}

		cout << max_ << endl;
	}

	return 0;
}

// Time : O ( 2 ^ (R + 1) * R * C )

Measured memory_bytes: 1864
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int prime[1000000];
bool is_prime[1000001];
int main(){
    int n;
    while(cin >> n){
        int p = 0;
        rep(i, n + 1) is_prime[i] = true;
        is_prime[0] = is_prime[1] = false;
        REP(i, 2, n + 1){
            if(is_prime[i]){
                prime[p++] = i;
                for(int j = i * 2; j <= n; j += i)
                  is_prime[j] = false;
            }
        }
        cout << p <<endl;
    }
    return 0;
}

Measured memory_bytes: 2444
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    if(K==0){
        print(N*N)
        return 0;
    }
    ll ans=0;
    for(ll i=K+1;i<=N;i++){
        ll x=N/i;
        ans+=x*(i-K);
        ans+=max(N-x*i-K+1,0LL);
    }
    print(ans)


    return 0;
}


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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = 998244353;
const int INF = 2147483647;
const ll linf = 1e18;
const ld pi = acos(-1);
const ld EPS = 1e-10;

int n, q, pref[N];
string s;
int main (){
    cin >> n >> q >> s;
    for (int i = 1; i < n; ++i){
        if (s[i] == 'C' && s[i - 1] == 'A'){
            pref[i] = 1;
        }
        pref[i] += pref[i - 1];
    }
    for (int i = 1; i <= q; ++i){
        int l, r;
        cin >> l >> r;
        int ans = pref[r - 1] - pref[l - 2];
        if (s[l - 1] == 'C' && s[l - 2] == 'A') ans--;
        cout << ans << "\n";
    }
    return 0;
}

/*
Adilet - 1
Ildar - 10
Bekzat - 31
Rayimbek - 73
Meyrlan - 9
*/


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

vector<int> Match(const vector<vector<int>> &g) {
    int n = g.size();
    vector<int> match(n, -1), used(n);

    function<bool(int)> Dfs = [&](int x) {
        for (int u : g[x]) {
            if (used[u]++) continue;
            if (match[u] == -1 || Dfs(match[u])) {
                match[u] = x;
                return true;
            }
        }
        return false;
    };

    for (int i = 0; i < n; ++i) {
        fill(used.begin(), used.end(), 0);
        Dfs(i);
    }
    return match;
}

int main() {
    int n, m; scanf("%d%d", &n, &m);
    vector<vector<int>> a(n, vector<int>(m));
    vector<vector<vector<int>>> cnt(n, vector<vector<int>>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            scanf("%d", &a[i][j]);
            a[i][j]--;
            cnt[i][a[i][j] / m].push_back(a[i][j]);
        }
    }
    vector<vector<int>> b(n, vector<int>(m, -1));
    for (int i = 0; i < m; ++i) {
        vector<vector<int>> g(n);
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < n; ++k) {
                if (!cnt[j][k].empty()) g[j].push_back(k);
            }
        }
        auto mk = Match(g);
        for (int j = 0; j < n; ++j) {
            b[mk[j]][i] = cnt[mk[j]][j].back();
            cnt[mk[j]][j].pop_back();
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) printf("%d ", b[i][j] + 1);
        puts("");
    }
    vector<vector<int>> c(n, vector<int>(m, -1));
    for (int i = 0; i < m; ++i) {
        vector<int> w(n, -1);
        for (int j = 0; j < n; ++j) w[b[j][i] / m] = b[j][i];
        for (int j = 0; j < n; ++j) c[j][i] = w[j];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) printf("%d ", c[i][j] + 1);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 1024
// Crt. 2020-01-11  21:41:06
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define PII pair<int, int>
#define mk make_pair
#define fi first
#define se second
#define N 600005
using namespace std;
typedef long long ll;

int n, W, H;
PII p[N];

int mx[N << 2], tag[N << 2];

void add(int pos, int w) {
    mx[pos] += w, tag[pos] += w;
}

void pushdown(int pos) {
    if (!tag[pos]) return ;
    add(pos << 1, tag[pos]);
    add(pos << 1 | 1, tag[pos]);
    tag[pos] = 0;
}

void Modify(int l, int r, int L, int R, int w, int pos) {
    if (L <= l && r <= R) return add(pos, w);
    int mid = (l + r) >> 1;
    pushdown(pos);
    if (L <= mid) Modify(l, mid, L, R, w, pos << 1);
    if (mid < R) Modify(mid + 1, r, L, R, w, pos << 1 | 1);
    mx[pos] = max(mx[pos << 1], mx[pos << 1 | 1]);
}

PII sl[N], sr[N];

int solve() {
    memset(mx, 0, sizeof mx);
    memset(tag, 0, sizeof tag);
    int res = 0;
    sort(p + 1, p + n + 1);
    int tl = 0, tr = 0;
    for (int i = 1; i < n; ++i) {
        if (p[i].se <= H / 2) {
            int r = i - 1;
            while (tl && sl[tl].fi <= p[i].se) {
                Modify(1, n, sl[tl].se, r, sl[tl].fi - p[i].se, 1);
                r = sl[tl].se - 1, --tl;
            } if (r + 1 < i) sl[++tl] = mk(p[i].se, r + 1);
        } else {
            int r = i - 1;
            while (tr && sr[tr].fi >= p[i].se) {
                Modify(1, n, sr[tr].se, r, p[i].se - sr[tr].fi, 1);
                r = sr[tr].se - 1, --tr;
            } if (r + 1 < i) sr[++tr] = mk(p[i].se, r + 1);
        }
        sl[++tl] = mk(0, i);
        sr[++tr] = mk(H, i);
        Modify(1, n, i, i, H - p[i].fi, 1);
        res = max(res, mx[1] + p[i + 1].fi);
    }
     return res << 1;
};

int main(){
    cin >> W >> H;

    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%d%d", &p[i].fi, &p[i].se);
    p[++n] = mk(0, 0), p[++n] = mk(W, H);

    int ans = solve();

    swap(W, H);
    for (int i = 1; i <= n; ++i)
        swap(p[i].fi, p[i].se);

    ans = max(ans, solve());

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 33152
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=998244353;
constexpr int N=200000;
mt19937 mt;

int D,c[26],s[200000][26],t[200000],T[200000],v,V,l[26];

int main(){
	scanf("%d",&D);
	for(int i=0;i<26;i++){
		scanf("%d",&c[i]);
	}
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++){
			scanf("%d",&s[i][j]);
		}
	}
	for(int i=0;i<D;i++){
		t[i]=uniform_int_distribution<int>(0,25)(mt);
	}
	for(int i=0;i<26;i++){
		l[i]=-1;
	}
	for(int i=0;i<D;i++){
		l[t[i]]=i;
		v+=s[i][t[i]];
		for(int j=0;j<26;j++){
			v-=c[j]*(i-l[j]);
		}
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<D;j++){
			if(uniform_int_distribution<int>(0,N*50)(mt)<=N-i){
				T[j]=uniform_int_distribution<int>(0,25)(mt);
			}
			else{
				T[j]=t[j];
			}
		}
		for(int j=0;j<26;j++){
			l[j]=-1;
		}
		V=0;
		for(int j=0;j<D;j++){
			V-=c[T[j]]*(j-l[T[j]]-1)*(j-l[T[j]])/2;
			l[T[j]]=j;
			V+=s[j][T[j]];
		}
		for(int j=0;j<26;j++){
			V-=c[j]*(D-l[j]-1)*(D-l[j])/2;
		}
		if(V>v){
			v=V;
			for(int j=0;j<D;j++){
				t[j]=T[j];
			}
		}
	}
	for(int i=0;i<D;i++){
		printf("%d\n",t[i]+1);
	}
}


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

int main(){
  ll N,x,y;
  cin >> N;
  if(N==1){
    cout << "1" << endl;
  }else{
    ll num,x=2,y=1;
    for(ll i=2;i<=N;++i){
      num = x + y;
      x = y;
      y = num;
    }
    cout << num << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

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

Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>
 
struct Point { double x,y;};
 
void koch(int n, Point a,Point b){
    if(n==0)return;
     
    Point s,t,u;
    double th=M_PI*60.0/180.0;
     
    s.x=(2.0*a.x+1.0*b.x)/3.0;
    s.y=(2.0*a.y+1.0*b.y)/3.0;
    t.x=(1.0*a.x+2.0*b.x)/3.0;
    t.y=(1.0*a.y+2.0*b.y)/3.0;
    u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
    u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
     
    koch(n-1,a,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,b);
}
 
int main(){
    Point a,b;
    int n;
    scanf("%d",&n);
     
    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;
     
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
     
    return 0;
}

Measured memory_bytes: 2652
#include <iostream>
#include <cmath>
#define MOD 1000000007
using namespace std;

int sx, sy, tx, ty;

int main() {
    cin >> sx >> sy >> tx >> ty;
    int dy = ty - sy, dx = tx - sx;
    for (int i = 0; i < dy; i++) cout << 'U';
    for (int i = 0; i < dx; i++) cout << 'R';
    for (int i = 0; i < dy; i++) cout << 'D';
    for (int i = 0; i < dx; i++) cout << 'L';
    cout << 'L';
    for (int i = 0; i < dy+1; i++) cout << 'U';
    for (int i = 0; i < dx+1; i++) cout << 'R';
    cout << 'D' << 'R';
    for (int i = 0; i < dy+1; i++) cout << 'D';
    for (int i = 0; i < dx+1; i++) cout << 'L';
    cout << 'U' << endl;
}

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

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

void dfs(const Graph &G, int v, int p, vector<ll> &cnt){
	for(auto nv : G[v]) {
		if(nv==p) {
			continue;
			//cnt[nv] += cnt[p];
		} else {
			cnt[nv] += cnt[v]; // 子に自分の値を渡す．
			dfs(G, nv, v, cnt);
		}
	}
}

int main() {
	ll N, Q;
	cin >> N >> Q;
	Graph tree(N);
	rep(i, N-1) {
		ll a, b;
		cin >> a >> b;
		tree[a-1].push_back(b-1);
		tree[b-1].push_back(a-1);
	}
	// vector<ll> p(N), x(N);
	vector<ll> cnt(N, 0);
	rep(i, Q) {
		ll p, x;
		cin >> p >> x;
		cnt[p-1] += x;
	}

	dfs(tree, 0, -1, cnt);

	rep(i, N) {
		cout << cnt[i] << ' ';
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 30464
//vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  double t,a;
  cin >> t >>a;
  vector<double> h(n);
  rep(i,n) cin >> h.at(i);
  double num=1000000;
  int num2;
  rep(i,n){
    if(num >abs(a-(t-h.at(i)*0.006))){
      num = abs(a-(t-h.at(i)*0.006));
      num2 = i;
    }
  }
  cout << num2+1 <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int team[1000], p[1000], rank[1000], i = 0, j, k, num, point, flag, f, l;

  for(i = 0;;i++){
    scanf("%d,%d", &team[i], &p[i]);
    if(!team[i] && !p[i]) break;
  }
  for(f = 1, i = 30;i >= 0;i--){
    flag = 0;
    for(l = 0;;l++){
      if(!team[l] && !p[l]) break;
      else if(p[l] == i){
	rank[l] = f;
	flag++;
      }
    }
    if(flag != 0) f++;
  }

  while(scanf("%d", &f) != EOF){
    for(i = 0;;i++){
      if(f == team[i]){
	printf("%d\n", rank[i]);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 608
N = int(input())
S = input().strip()

M = [[0] * 3 for _ in range(N+1)]

for i in range(N-1, -1, -1):
    for j in range(3):
        M[i][j] = M[i+1][j]
    if S[i] == "R":
        M[i][0] += 1
    elif S[i] == "G":
        M[i][1] += 1
    else:
        M[i][2] += 1

ans = 0

T = "RGB"


for i in range(N-2):
    for j in range(i+1, N-1):
        m = [0, 0, 0]
        if S[i] == "R":
            m[0] += 1
        elif S[i] == "G":
            m[1] += 1
        else:
            m[2] += 1

        k = j + (j-i)
        if S[j] == "R":
            if m[0] == 0:
                m[0] += 1
                idx = m.index(0)
                ans += M[j+1][idx]
                if k < N and S[k] == T[idx]:
                    ans -= 1
            else:
                continue
        elif S[j] == "G":
            if m[1] == 0:
                m[1] += 1
                idx = m.index(0)
                ans += M[j+1][idx]
                if k < N and S[k] == T[idx]:
                    ans -= 1
            else:
                continue
        else:
            if m[2] == 0:
                m[2] += 1
                idx = m.index(0)
                ans += M[j+1][idx]
                if k < N and S[k] == T[idx]:
                    ans -= 1
            else:
                continue

print(ans)


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

using namespace std;

int n, a, c[100009];
int main() {
	cin >> n;
	
    for (int i = 0; i < n; i++) {
        cin >> a, c[a]++;
    }
	
    int ret = 0;
	for (int i = 0; i <= 100000; i++) {
        ret = max(ret, c[i] + c[i + 1] + c[i + 2]);
    }
    cout << ret << endl;
	return 0;
}

Measured memory_bytes: 640
# https://atcoder.jp/contests/abc134/tasks/abc134_e

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
from collections import deque
from bisect import bisect_left

N = INT()
A = []

for _ in range(N):
    A.append(INT())

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

print(len(t))


Measured memory_bytes: 54616
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ptn = 0
for i in range(0, a + 1):
    for j in range(0, b + 1):
        for k in range(0, c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                ptn += 1

print(ptn)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int n,m;
vector<pii> g[500];
int cnt[500], cri[500];

int main(){
  cin >> n >> m;
  for(int i=0;i<m;i++){
    int a,b,c;
    cin >> a >> b >> c;
    cnt[b]++;
    g[a].push_back(pii(b,c));
  }

  queue<int> v0;
  v0.push(0);

  while(v0.size()){
    int v = v0.front(); v0.pop();

    for(int i=0;i<(int)g[v].size();i++){
      int u = g[v][i].first, t = g[v][i].second;
      if(cri[u] < cri[v] + t)cri[u] = cri[v] + t;

      cnt[u]--;
      if(cnt[u] == 0)v0.push(u);
    }
  }
  cout << cri[n-1] << endl;
}

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

int main(){
	long long N, K;
	cin >> N >> K;
	vector<long long> A;
	long long MAX = 0;
	for(int i=0;i<N;i++){
		long long X;
		cin >> X;
		A.push_back(X);
		MAX = max(X, MAX);
	}
	long long r = MAX, l = 1;
	while(l < r){
		long long mid = (l + r) / 2;
		long long tmp = 0;
		for(int i=0;i<N;i++){
			tmp += (A[i] - 1) / mid;
		}
		if(tmp <= K){
			r = mid;
		}
		else{
			l = mid + 1;
		}
	}
	cout << l << endl;
}


Measured memory_bytes: 5352
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        String str = sc.next();
        int length = str.length();
        
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < length - 2; i++){
            int tmp = Integer.parseInt(str.substring(i,i+3));
            min = Math.min(min, Math.abs(753 - tmp));
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 21332
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _001_FindingMissingCards
{


    class Program
    {
        static void Main()
        {
            var n = Convert.ToInt32(Console.ReadLine());
            var a = Array.ConvertAll(Console.ReadLine().Split(' '), i=>Int32.Parse(i));

            var count = 0;
            var minj = 0;
            for (int i = 0; i < n; i++)
            {
                minj = i;
                for (int j = i; j < n; j++)
                {
                    if (a[j] < a[minj]) minj = j;
                }
                if (i != minj)
                {
                    count++;
                    var tmp = a[i];
                    a[i] = a[minj];
                    a[minj] = tmp;
                }


            }


            for (int i = 0; i < n - 1; i++)
            {
                Console.Write("{0} ", a[i]);
            }
            Console.WriteLine("{0}", a[n - 1]);

            Console.WriteLine(count);
            
        }
    }
}

Measured memory_bytes: 9184
let f (xl, xu, yl, yu) (x, y, a) =
  match a with
  | 1 -> (max xl x, xu, yl, yu)
  | 2 -> (xl, min xu x, yl, yu)
  | 3 -> (xl, xu, max yl y, yu)
  | _ -> (xl, xu, yl, min yu y)
let () =
  let xl, xu, yl, yu =
    Scanf.scanf "%d %d %d" (fun w h n ->
      Array.init n (fun _ -> Scanf.scanf " %d %d %d" (fun x y a -> x, y, a))
    |> Array.fold_left f (0, w, 0, h)) in
  max 0 (xu-xl)* max 0 (yu-yl) |> Printf.printf "%d\n"
    


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';

int main(){
	string s;
	cin >> s;
	ll n = s.size();
	if(s[n-1] == 's'){
		s = s+"es";
	}else{
		s = s+"s";
	}cout << s << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,m;
    cin>>n>>m;
    if(n==m)
    {
        string p = "";
        for(int i = 0;i<n;i++)
        {
            p = p+char(n+'0');
        }
        cout<<p;
    }
    else
    {
        if(n>m)
        {
            string l = "";
            for(int i = 0;i<n;i++)
            {
                l = l+char(m+'0');
            }
            cout<<l;
        }
        else
        {
            string l = "";
            for(int i = 0;i<m;i++)
            {
                l = l+char(n+'0');
            }
            cout<<l;

        }

    }
}


Measured memory_bytes: 256
/***************************************************************************
                                AUTHOR: SPARSH SINHA
            **************************************************************************/


#include <bits/stdc++.h>
using namespace std;
#define si(N) scanf("%d",&N);
#define sll(N) scanf("%lld",&N);
#define ss(s) scanf("%s",s);
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i = a; i<=b;i++)
#define fori(i,n) for(int i = 0 ; i < n; i++)
#define umapii unordered_map<int,int>
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define debug(x)       cerr<< #x <<" : "<<x<<endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
const int INF = 1e9 + 7;
bool isAnagram(string s1 , string s2){
            vector<int> cnt1(26 , 0);
            vector<int> cnt2(26 , 0);
            for(int i = 0; i < s1.length() ; i++){
                cnt1[s1[i] - 'a']++; cnt2[s2[i] - 'a']++;
            }
            for(int i = 0; i < 26 ; i++){
                 if(cnt1[i] != cnt2[i]) return false;
            }
            return true;
}
int main()
{
                 int N; 
                 cin >> N;
                 vector<string> v(N);
                 for(int i =0; i < N; i++){
                        cin >> v[i];
                       sort(v[i].begin() , v[i].end());
                    //    cout << v[i] << endl;
                 }
                  sort(v.begin() , v.end());
                  ll cnt = 0;
                  ll answer = 0;
                  int s = 0 , e = 0;
                  while(s < N){
                       e = s;
                       while(e < N && v[e] == v[s]){
                           e++;
                       }
                       //e will become N or e will become not equal to s
                       //from s to e - 1 is anagramic string
                       answer = e - s;
                       cnt = cnt + (answer - 1)*answer/2;

                       s = e; //start from e
                  }
                  cout << cnt << endl;
                
}


Measured memory_bytes: 7296
import queue
import sys

input = sys.stdin.readline

N, M = map(int, input().split())
path = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    path[A-1].append(B-1)
    path[B-1].append(A-1)

parent = [-1] * (N)
parent[0] = 0

found = [False] * N
found[0] = True

depth = [10 ** 9] * N
depth[0] = 0

q = queue.Queue()
q.put(0)
while not q.empty():
    pos = q.get()
    possible_parent = []
    for next_room in path[pos]:
        if parent[next_room] == -1:
            if not found[next_room]:
                q.put(next_room)
                found[next_room] = True
                depth[next_room] = min(depth[next_room], depth[pos] + 1)
        else:
            possible_parent.append(next_room)

    for p1 in possible_parent:
        for p2 in possible_parent:
            if depth[p1] > depth[p2]:
                break
        else:
            parent[pos] = p1
            break

if -1 in parent:
    print("No")
else:
    print("Yes")
    for elem in parent[1:]:
        print(elem + 1)

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	
  	int3(a, b, c);
  	int sum = a + b + c;
  	if (sum % 2) cout << "No" << endl;
  	else {
      if (a == sum / 2 || b == sum / 2 || c == sum / 2)
        cout << "Yes" << endl;
      else 
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main (String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		
		while ((line = br.readLine()) != null) {
			String[] numbers = line.split(" ");
			int sum = 0;
            int a = Integer.parseInt(numbers[0]);
            int b = Integer.parseInt(numbers[1]);
            sum = a + b;
            
            int ans = 1;
            while((sum /= 10) > 0){
            	ans++;
            }
            System.out.println(ans);
        }
	}
}

Measured memory_bytes: 16984