akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
int main(){
    int h,w;cin>>h>>w;
    int a[h][w];
    vector<pair<int,int>>b,c;
    rep(i,h)rep(j,w)cin>>a[i][j];
    int cnt=0;
    rep(i,h){
        if(i%2==0){
            rep(j,w){
                if(a[i][j]%2==0)continue;
                else if(j!=w-1){
                    b.push_back(make_pair(i,j));
                    c.push_back(make_pair(i,j+1));
                    cnt++;a[i][j+1]++;
                }
                else if(i!=h-1){
                    b.push_back(make_pair(i,j));
                    c.push_back(make_pair(i+1,j));
                    cnt++;a[i+1][j]++;
                }
            }
        }
        else{
            for (int j = w-1; j>=0; j--)
            {
                if(a[i][j]%2==0)continue;
                else if(j!=0){
                    b.push_back(make_pair(i,j));
                    c.push_back(make_pair(i,j-1));
                    cnt++;a[i][j-1]++;
                }
                else if(i!=h-1){
                    b.push_back(make_pair(i,j));
                    c.push_back(make_pair(i+1,j));
                    cnt++;a[i+1][j]++;
                }
            }
        }
    }
    cout<<cnt<<endl;
    rep(i,cnt){
        printf("%d %d %d %d\n",b[i].first+1,b[i].second+1,c[i].first+1,c[i].second+1);
    }
    return 0;
}

Measured memory_bytes: 5228
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vll a(n);
    REP(i,n) cin >> a[i];
    sort(ALL(a));
    ll cnt = 0;
    REP(i,n-1){
        if(a[i]==a[i+1]) cnt++;
    }
    ll ans = n-((cnt+1)/2)*2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3984
from operator import itemgetter


def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab)] * 2), key=itemgetter(1))
    past = 0
    for a, b in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 52096
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>

#define MODULE 
#define RAND(min,max) (rand()%(max-min+1)+min)
#define LOGI(log) //printf("\n%ld\n",log);
#define LOGS(log) printf("\n%s\n",log);
#define DEBUG() {printf("\nDEBUG %d\n",num_debug);num_debug++;}
char num_debug = 0;

int main(void) {
	srand((unsigned)time(NULL));

	unsigned long int N;
	unsigned long int m, k;

	scanf("%lu", &N);
	
	int i;
	unsigned long int g = 0;
	for (i = 1; 1; i++) {

		 LOGI(N);
		LOGI(g)
		N -= g;
		g = pow(26, i);
		if (N <= g) {

			break;
		}
	}
	LOGI(N)
	int syou;
	unsigned long int n;
	for (int j = 0; j < i;j++) {
		for (int k = 0; k < 27; k++) {
			if (N > pow(26, i-j-1)) {
				N -= pow(26, i-j-1);
				//printf("%d %d\n", N, pow(26, i-j-1));
			}
			else {
				LOGI(N);
				LOGI(k);
				printf("%c", 'a' + k);
				break;
			}
		}

		

	}
	

	return 0;
}



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

int main(){
      int n,m;
      cin >> n >> m;
      int l[m],r[m];
      int min = 100000+1;
      int max = 0;
      for(int i = 0; i < m; i++){
          cin >> l[i] >> r[i];
          if(min > r[i]){
              min = r[i];
          }
          if(max < l[i]){
              max = l[i];
          }
      }
    if(max <= min){
        cout << min - max + 1 << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
h, w, k = gets.strip.split.map(&:to_i)
MOD = 10**9+7

dp = Array.new(h+1) { Array.new(w, 0) }
dp[0][0]=1

h.times do |ch|
  (0 ... 1 << (w-1)).each do |bit|
    invalid_amida = ("%0#{w}b" % bit).split('').map(&:to_i).each_cons(2).map {|l, r| l==1 && r==1 }.any?
    next if invalid_amida

    w.times do |cw|
      if cw != w-1 && bit[cw]==1
        next_target = cw+1
      elsif cw != 0 && bit[cw-1]==1
        next_target = cw-1
      else
        next_target = cw
      end
      dp[ch+1][next_target] = (dp[ch+1][next_target] + dp[ch][cw]) % MOD
    end
  end
end

#p dp
p dp[h][k-1]


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

using namespace std;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    int n;
    cin >> n;

    set<int> st;
    for (int i = 0 ;i < n ;i++) {
        int x;
        cin >> x;
        st.insert(x);
    }

    cout << (st.size() == n ? "YES" : "NO");
}

Measured memory_bytes: 12904
n = int(input())
s = input()
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a = s.find(str(i))
            if a < 0:
                continue
            b = s.find(str(j), a + 1)
            if b < 0:
                continue
            c = s.find(str(k), b + 1)
            if c > -1:
                cnt += 1
print(cnt)


Measured memory_bytes: 3064
s = input()
s = s.replace('BC','x')

a_flag = False
ans = 0
last_a = 0
for si in s:
    if si == 'A':
        a_flag = True
        last_a += 1
    elif si == 'x' and a_flag:
        ans += last_a
    else:
        a_flag = False
        last_a = 0

print(ans)


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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'

int parent(int i, int n){
    return (i-1)/ n;
}

int n, q;
VI v;


signed main()
{
    cin >> n >> q;
    if (n == 1){
        REP(i, q){
            int a , b;
            cin >> a >> b;
            cout << min(a, b) << endl;
        }
        return 0;
    }
    REP(i, q){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        while (a != b){
            if (a < b){ 
                b = parent(b, n);

            } else {
                int temp = b;
                b = a;
                a = temp;
            }
                //  DEBUG(a);
                // DEBUG(b);
                       }
        cout << a+1 <<endl;
    }



    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

    vector<long long> a(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }

    long long res = 0;

    map<long long, int> m;
    m[0]++;
    for (int i = 1, j = 1 - k; i <= n; i++, j++) {
        if (j >= 0) {
            m[(a[j] - j) % k]--;
        }
        res += m[(a[i] - i) % k];
        m[(a[i] - i) % k]++;
    }

    cout << res << endl;
}


Measured memory_bytes: 14336
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    a = input()
    if ord("A") <= ord(a) <= ord("Z"):
        print("A")
    else:
        print("a")


if __name__ == "__main__":
    main()


Measured memory_bytes: 8812
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
       mut an:[usize;3],
    }
    an.sort();
    let mut ans = 0;
    while an[1] != an[2] {
        an[0] += 1;
        an[1] += 1;
        ans += 1;
    }
    while an[0] < an[1] {
        an[0] += 2;
        ans += 1;
    }
    if an[0] > an[1] {
        ans += 1;
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{	
	int i, j;
	
	for(i=1; i<10; i++){
		for(j=1; j<10; j++){
			printf("%dx%d=%d\n",i, j, i*j);
			
		}
	}
	
	
	
	

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

ll N, K;
P sushi[101000];
bool used[101000];
priority_queue<P, vector<P>, greater<P> > q;
ll g[101000];


int main(){
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        ll t, d;
        cin >> t >> d;
        t--;
        sushi[i] = P(d, t);
    }
    sort(sushi, sushi+N);
    reverse(sushi, sushi+N);
    fill(used, used+N, false);

    ll kind = 0;
    ll p_sum = 0;
    for(int i = 0; i < K; i++){
        p_sum += sushi[i].first;
        if(!used[sushi[i].second]){
            used[sushi[i].second] = true;
            kind++;
        }
        else{
            q.push(sushi[i]);
        }
    }

    fill(g, g+N, 0);
    g[kind] = p_sum + kind*kind;
    for(int i = K; i < N; i++){
        if(q.empty()){
            break;
        }
        if(used[sushi[i].second]){
            continue;
        }
        used[sushi[i].second] = true;
        p_sum += sushi[i].first;

        P x = q.top();
        q.pop();
        p_sum -= x.first;
        kind++;
        g[kind] = p_sum + kind*kind;
    }

    ll res = 0;
    for(int i = 1; i <= N; i++){
        res = max(res, g[i]);
    }

    cout << res << endl;

    return 0;

}


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define pll pair <ll,ll>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<=(ll)n;i++)
#define rep(i,x,y) for(ll i=(ll)x;i<=(ll)y;i++)
#define reprev(i,n) for(ll i=(ll)n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

// FOR DEBUGGING
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", ";
	else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

const int mod = 1e9+7;
const long double pi = acos(-1);
const ll INF = 1e15;

ll power(ll x, ll y){
	x %= mod;
	ll ans = 1;
	while(y){
		if(y&1) ans = (ans*x)%mod;
		y /= 2;
		x = (x*x)%mod;
	}
	return ans;
}

void solve(){

	char c;
	cin >> c;
	if(c<='z' && c>='a') cout << 'a';
	else cout << 'A';

	return;
}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::string s;
    int q;
    std::cin >> s >> q;

    std::deque<char> ret(s.begin(), s.end());
    bool r = false;

    while (q--) {
        int t;
        std::cin >> t;
        if (t == 1) {
            r = !r;
            continue;
        }
        int f;
        char c;
        std::cin >> f >> c;
        if ((f == 1) ^ r) ret.push_front(c);
        else ret.push_back(c);
    }

    if (r) std::reverse(ret.begin(), ret.end());

    for (auto c : ret) std::cout << c;
    std::cout << std::endl;

    return 0;
}


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

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> A(n);
	for(int i = 0; i<n;i++) cin>>A[i]; 
	vector<int> dp(n,INT_MAX);
	dp[0] = 0;
	dp[1] = abs(A[1] - A[0]);
	for(int i = 2; i <n;i++) {
		dp[i] = min(dp[i - 1] + abs(A[i] - A[i-1]), dp[i-2] + abs(A[i] - A[i-2]));
	}
	//for(auto i : dp) cout<<i<<'\n';
	cout<<dp[n-1]<<'\n';
	return 0;
}

Measured memory_bytes: 1024
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
public class Main {
    
	public static void main (String[] args) {
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		HashSet<String>hs=new HashSet<>();
		for(int i=0;i<n;i++)
		{hs.add(s.next());}
		System.out.println(hs.size());
	}
}
		
		
		   

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

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> Cij(H, vector<char>(W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> Cij[i][j];
        }
    }

    for(int i=0; i<2*H; i++){
        for(int j=0; j<W-1; j++){
            cout << Cij[(int)((i)/2)][j]; 
        }
        cout << Cij[(int)((i)/2)][W-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3644
#入力
S_prime = str(input())
T = str(input())
ans = []

if len(S_prime) >= len(T):
    times = len(S_prime) - len(T) + 1
    for i in range(times):
        count = 0
        for j in range(len(T)):
            if S_prime[i+j] == '?':
                count = count + 1
            elif S_prime[i+j] != T[j]:
                continue
            else:
                count = count + 1
            
        if count == len(T):
            S = S_prime[:i] + T + S_prime[(i+len(T)):]
            S = S.replace('?', 'a')
            ans.append(S)


if len(ans) != 0:
    print(min(ans))
else:
    print('UNRESTORABLE')

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

vector<vector<int>> G;
vector<int> V;
int ans;

void dfs(int v) {
  V.at(v) = 1;
  if (accumulate(V.begin(), V.end(), 0) == V.size()) {
    ans++;
    V.at(v) = 0;
    return;
  }
  for (auto g : G.at(v)) {
    if (V.at(g)) continue;
    dfs(g);
  }
  V.at(v) = 0;
}

int main() {
  int N, M;
  cin >> N >> M;
  G.resize(N);
  V.resize(N);
  for (int i = 0, a, b; cin >> a >> b; i++) {
    G.at(--a).push_back(--b), G.at(b).push_back(a);
  }
  dfs(0);
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;

ll h[N] , dp[N] ;
int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll n , k ;
    cin >> n >> k ;
    for (int i = 1;  i <=  n ; i ++) cin >> h[i] ;
    memset(dp , 63 , sizeof(dp)) ;
    dp[1] = 0 ;
    for (ll i = 2 ; i <= n ; i ++) {
    	ll res = 1e18 ;
    	for (ll j = i - 1; j >= max(0ll , i - k) ; j --) {
    		res = min(res , dp[j] + abs(h[i] - h[j])) ;
		}
		dp[i]=  res ;
	}
	cout << dp[n] ;
    return (0) ;
}

Measured memory_bytes: 2560
import sys
 
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


from collections import deque

def main():

  n,q=map(int,input().split())

  li=[[] for i in range(n+1)]
  ans=[0]*(n+1)

  for i in range(n-1):
    a,b=map(int,input().split())
    li[a].append(b)
    li[b].append(a)

  for i in range(q):
    p,x=map(int,input().split())
    ans[p]+=x

  Q=deque([1])
  sumi=set([1])

  while Q:
  #  print(Q)
    now=Q.pop()
    for i in li[now]:
      if i in sumi:
        continue
      else:
        sumi.add(i)
        Q.append(i)
        ans[i]+=ans[now]
  print(*ans[1:])
      
if __name__ == "__main__":
  main()     

Measured memory_bytes: 99652
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();


        if(a == 7 || a==5 || a==3){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
        
    }

}


Measured memory_bytes: 21716
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

struct Solver {
    N: usize,
    G: Vec<Vec<(usize, i64)>>,
    color: Vec<bool>,
    done: Vec<bool>,
}

impl Solver {
    fn dfs(&mut self, u: usize, W: i64) {
        if self.done[u] {
            return;
        }
        self.done[u] = true;
        self.color[u] = W % 2 == 0;

        for i in 0..self.G[u].len() {
            let (v, w) = self.G[u][i];
            self.dfs(v, W + w);
        }
    }

    fn solve(mut self) {
        self.dfs(0, 0);

        for i in 0..self.N {
            println!("{}", if self.color[i] { '0' } else { '1' })
        }
    }
}

fn main() {
    let N = read!(usize);
    let T = read![usize, usize, i64; N - 1];
    let mut G = vec![vec![]; N];
    for (u, v, w) in T {
        G[u - 1].push((v - 1, w));
        G[v - 1].push((u - 1, w));
    }
    Solver {
        N: N,
        G: G,
        done: vec![false; N],
        color: vec![false; N],
    }
    .solve()
}


Measured memory_bytes: 18684
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vll l(n);
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(ALL(l));
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[i] == l[j] || l[j] == l[k]) continue;
                if (l[i] + l[j] > l[k]) ans++;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3660
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;

int main(void){
    int s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe"<<endl;
    }else{
        cout<<"safe"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3624
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

ll N=40;

signed main() {
    vector<PLL> range(N); // {min,max}
    range[0]={0,1};
    for (ll i=1,x=-2; i<N; i++, x*=-2) {
        range[i] = range[i-1];
        if (x<0) {
            range[i].first += x;
        } else {
            range[i].second += x;
        }
    }

    // rep(i,0,6){
    //     cout<<range[i].first <<"~ " <<range[i].second<<endl;
    // }
    // cout<<range[N-1].first <<"~ " <<range[N-1].second<<endl;
     

    vector<ll> ans(N);
    ll n, x=1;
    cin>>n;
    if (n==0) {
        cout<<0<<endl;
        return 0;
    }
    rep(i,0,N-1) { x*=-2; }
    for (ll i=N-1; i>0; i--) {
        if (n < range[i-1].first || n > range[i-1].second) {
            ans[i] = 1;
            n -= x;
        }
        x /= -2;
    }
    ans[0] = n;

    bool showZ = false;
    for (int i=N-1; i>=0; i--) {
        if (showZ || ans[i]==1) {
            cout<<ans[i];
            showZ = true;
        }
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF (1e17)
#define N 100005
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
 
ll n,m,x,h[N];
vector<P> G[N];
priority_queue<P1,vector<P1>,greater<P1> > q;
P d[N];
 
ll dijkstra(){
 
  for(int i=0;i<n;i++)d[i]=P(INF,INF);
   
  d[0]=P(0,-x);
  q.push(P1(0,P(0,-x)));
   
  while(!q.empty()){
    P1 temp=q.top(); q.pop();
    ll cost=temp.first;
    ll node=temp.second.first;
    ll a=-temp.second.second;
    
    if(node==n-1)return cost;
    
    if(d[node]<P(cost,-a))continue;
    
    for(int i=0;i<G[node].size();i++){
      ll nnode=G[node][i].first;
      ll t=G[node][i].second;
      ll h1=h[node],h2=h[nnode];
      ll ncost,na;
       
      if(a-t<0){
	ncost=cost+(t+(t-a));
	if(t>h1)continue;
	else na=0;
      }
      else if(a-t>h2){
	ncost=cost+(t+(a-(h2+t)));
	na=h2;
      }else{      
	ncost=cost+t;
	na=a-t;
      }
       
      if(nnode==n-1){
	ncost+=abs(h2-na);
	na=h2;
      }
      
      if(d[nnode]>P(ncost,-na)){
	d[nnode]=P(ncost,-na);
	q.push(P1(ncost,P(nnode,-na)));
      }      
 
    }
     
  }
  return INF;
}
 
int main(){
   
  cin>>n>>m>>x;
   
  for(int i=0;i<n;i++)scanf("%lld",&h[i]);
 
  ll a,b,c;
  for(int i=0;i<m;i++){
    scanf("%lld%lld%lld",&a,&b,&c);
    a--,b--;
    G[a].push_back(P(b,c));
    G[b].push_back(P(a,c));
  }
 
  ll ans=dijkstra();
  if(ans==INF)cout<<-1<<endl;
  else cout<<ans<<endl;
   
  return 0;
}

Measured memory_bytes: 25052
from  collections import Counter
n=int(input())
S=[input() for _ in range(n)]
# M = {s:0 for s in S}
# for s in S: M[s]+=1
M = Counter(S)
mx = max(M.values())
L = sorted(M.items())
for k,v in L:
    if mx==v: print(k)

Measured memory_bytes: 48320
h,w,n = map(int, input().split())
sr,sc = map(int, input().split())
s = input()
t = input()
r=sr-1
for i in range(len(s)):
    if s[i] =="U":
        r-=1
    if r<0:
        print("NO")
        exit()
    if t[i] == "D" and r < h-1:
        r+=1
r=sr-1
for i in range(len(s)):
    if s[i] =="D":
        r+=1
    if h<=r:
        print("NO")
        exit()
    if t[i] == "U" and 0<r:
        r-=1
c=sc-1
for i in range(len(s)):
    if s[i] =="L":
        c-=1
    if c<0:
        print("NO")
        exit()
    if t[i] == "R" and c<w-1:
        c+=1
c=sc-1
for i in range(len(s)):
    if s[i] =="R":
        c+=1
    if c>=w:
        print("NO")
        exit()
    if t[i] == "L" and 0 < c:
        c-=1
print("YES")

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(){

  int N, Q;
  cin >> N >> Q;

  vector<int> values(N, 0);

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

  rep(i, Q){
    int p, v;
    cin >> p >> v;
    p--;
    values[p] += v;
  }


  vector<bool> visited(N, false);
  queue<int> q;

  q.push(0);
  visited[0] = true;

  while(!q.empty()){
    int node = q.front(); q.pop();
    for(int next_node: adjacent_list[node]){
      if(visited[next_node]) continue;

      visited[next_node] = true;
      values[next_node] += values[node];
      q.push(next_node);
      
    }
  }

  rep(i, values.size()){
    if(i != 0) cout << " ";
    cout << values[i];
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 15604
//#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)

void solve(){
  int n;cin >> n;
  int ans = 0, ab = 98765432, aa=98765432;
  FOR(i,0,n-1){
    int b; cin >> b;
    ab = min(ab, b);
    aa = min(aa, b);
    ans += ab;
    swap(aa,ab);
    aa = 98765432;
  }
  ans += ab;
  cout << ans;
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val ab = readLine()
  val multiAB = ab?.let {
    val arr = it.split(" ").map { num -> Integer.parseInt(num)  }
    arr[0] * arr[1]
  } ?: 0
  if ((multiAB % 2) == 0) {
    println("Even")
  } else {
    println("Odd")
  }
}

Measured memory_bytes: 35956
#include<stdio.h>
#include<iostream>
using namespace std;
int main (){
    string s;
    cin >> s;
    int x = 1;
    for(int i=0; i<s.length(); i++){
        for(int j=0; j<s.length(); j++){
            if ( i == j ) {
        } else if ( s[i] == s[j] ) {
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

struct P {
  int y, x;
  P() {}
  P(int y, int x) : y(y), x(x) {}
};

int h, w;
vector<string> s;
P start, goal;
vector<P> demons;
int dy[] = {-1, 0, 0, 1}, dx[] = {0, -1, 1, 0};

void bfs(vector<vector<int>>& d, vector<P> v) {
  queue<pair<P, int>> que;
  for (int i = 0; i < v.size(); i++) {
    d[v[i].y][v[i].x] = 0;
    que.push({v[i], 0});
  }
  while (que.size()) {
    auto p = que.front(); que.pop();
    int py = p.first.y, px = p.first.x;
    for (int i = 0; i < 4; i++) {
      int ny = py + dy[i], nx = px + dx[i];
      if (ny >= 0 && ny < h && nx >= 0 && nx < w && s[ny][nx] != '#' && d[ny][nx] > d[py][px] + 1) {
        d[ny][nx] = d[py][px] + 1;
        que.push({{ny, nx}, d[ny][nx]});
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  cin >> h >> w;
  s.resize(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '@') start = {i, j};
      else if (s[i][j] == '%') goal = {i, j};
      else if (s[i][j] == '$') demons.emplace_back(i, j);
    }
  }

  vector<vector<int>> d1(h, vector<int>(w, 1 << 30)), d2 = d1;
  vector<P> tmp(1, start);
  bfs(d1, tmp);
  bfs(d2, demons);
  cout << (d1[goal.y][goal.x] < d2[goal.y][goal.x] ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 4168
#include<iostream>
using namespace std;
using namespace std;
int main()
{
    int n,sum=0,d1,d2,s1=0,s2=0;
    int a[105];
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    d1=sum/n;
    d2=sum/n+1;//对称点可能不为整数，所以比较起两边
    for(int i=1;i<=n;i++){
        s1+=(d1-a[i])*(d1-a[i]);
        s2+=(d2-a[i])*(d2-a[i]);
    }
    cout<<min(s1,s2);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int N, ans = 1;
    double T, A, H, diff, diff_min = 300, rate = 0.006;

    cin >> N >> T >> A;
    for (int i = 0; i < N; i++) {
        cin >> H;
        diff = abs(A - (T - H * rate));
        if (diff_min > diff) {
            diff_min = diff;
            ans = i + 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int nmax=1005;
struct edge{int to;long double cost;};
vector<edge> tree[nmax];
long double d[nmax];
int n;
void dijkstra(int s){
  priority_queue<pair<long double,int>,vector<pair<long double,int>>,greater<pair<long double,int>>> pq;
  d[s]=0;
  pq.push(make_pair(0,s));
  while(!pq.empty()){
    pair<long double,int> p=pq.top();
    pq.pop();
    int v=p.second;
    if(d[v]<p.first){
      continue;
    }
    for(auto x:tree[v]){
      edge e=x;
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        pq.push(make_pair(d[e.to],e.to));
      }
    }
  }
}
int main(){
  long double xs,ys,xt,yt;cin >> xs >> ys >> xt >> yt;
  int n;cin >> n;
  vector<long double> x(n+2),y(n+2),r(n+2);
  x[0]=xs,y[0]=ys,x[n+1]=xt,y[n+1]=yt;
  r[0]=0,r[n+1]=0;
  for(int i=1;i<=n;i++){
    cin >> x[i] >> y[i] >> r[i];
  }
  for(int i=0;i<=n+1;i++){
    d[i]=1e15;
  }
  for(int i=0;i<=n;i++){
    for(int j=i+1;j<=n+1;j++){
      long double dis=max((long double)0,sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j]);
      tree[i].push_back(edge{j,dis});
      tree[j].push_back(edge{i,dis});
    }
  }
  dijkstra(0);
  cout << fixed << setprecision(15) << d[n+1] << endl;
}


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

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

    int n;
    cin>>n;

    vector<pair<int, int>>  edges;

    bool b = n%2;
    n -= b;

    for (int i=1; i<=n; i++)
        for (int j=i+1; j<=n; j++)
            if (i+j!=n+1)
                edges.push_back({i, j});

    if (b) {
        for (int i=1; i<=n; i++)    edges.push_back({i, n+1});
    }
    cout<<edges.size()<<endl;
    for (auto pr: edges)
        cout<<pr.first<<" "<<pr.second<<"\n";

}


Measured memory_bytes: 384
s=list(input())
cnt=100
for i in range(26):
    x=chr(97+i)
    if x not in s:
        continue
    tmp=0
    dummy=s+[]
    while len(set(dummy))>1:
        tmp+=1
        newdum=[]
        for j in range(len(dummy)-1):
            if dummy[j]==x or dummy[j+1]==x:
                newdum.append(x)
            else:
                newdum.append(dummy[j])
        dummy=[]+newdum
    cnt=min(cnt,tmp)
print(cnt)


Measured memory_bytes: 3188
/*
 *  Created on: 5 / 8 / 2020
 *  Author:     Eslam Waheed
 */

#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO

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

#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)
#define test(t)      while(t--)

//ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ld PI = acos(-1);
//const ll mod = 1e9 + 7;
//const ld EPS = 1e-8;
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
	//stp(0)
	Eslam__Waheed;
	ll n; cin >> n;
	vector<ll>v(n);
	for (auto& it : v)
	{
		cin >> it;
	}
	ll ans = 0;
	for (int i = 0; i < n; i += 2)
	{
		if (v[i] & 1)ans++;
	}
	cout << ans;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
   int r;
   scanf("%d",&r);
   if (r<1200)
   {
   printf("ABC\n");
   }else if (r<2800)
   {
   printf("ARC\n");
   }else if (r<=4208)
   {
   printf("AGC\n");
   }
return 0;
}


Measured memory_bytes: 128
extern crate proconio;

use proconio::*;

fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize; m]
    }

    let s = a.into_iter().sum();
    if n < s {
        println!("-1");
    } else {
        println!("{}", n - s);
    }
}


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

int x[20][20],y[20][20];

int main(){ 
    int n;
    cin>>n;
    int c[n];
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        for(int j=0;j<a[i];j++){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int ans=0;
    for(int i=0;i<(1<<n);i++){
        int tmp=__builtin_popcount(i);
        int flag=0;
        for(int j=0;j<n;j++){
            if(i&(1<<j))c[j]=1;
            else c[j]=0;
        }
        for(int i=0;i<n;i++){
            if(c[i]==1){
                for(int j=0;j<a[i];j++){
                    if(c[x[i][j]]==0 && y[i][j]==1)flag++;
                    else if(c[x[i][j]]==1 && y[i][j]==0)flag++;
            }}
        }
        if(flag==0)ans=max(ans,tmp);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, x, y = map(int, read().split())
ans = [0] * n
for k in range(1, n):
    for i in range(k + 1, n + 1):
        ans[min(i - k, abs(y - i) + abs(x - k) + 1)] += 1
print('\n'.join(map(str, ans[1:])))


Measured memory_bytes: 3316
S = list(input())

r_stack = [0, 0]
l = len(S)
res = [1] * l

rl_idx = None
i = -1
while i < l - 1:
    i += 1
    s = S[i]

    if s == 'R' and i < l - 1:
        if S[i + 1] == 'L':
            rl_idx = i

            res[i] += r_stack[0]
            res[i + 1] += r_stack[1]
            r_stack = [0, 0]
            i += 1
            continue

    if s == 'R':
        r_stack[0] += 1
    else:
        res[(i - rl_idx) % 2 + rl_idx] += 1
    res[i] = 0

    r_stack[0], r_stack[1] = r_stack[1], r_stack[0]

print(*res)


Measured memory_bytes: 7092
#include <iostream>
#include <cmath>

using namespace std;
int l,r,i,j;
int flag=1<<30;
int main(){
	cin>>l>>r;
	if(r-l>=2018){
		cout<<0;
		return 0;
	}
	for(int i=l;i<=r;i++){
		for(int j=i+1;j<=r;j++){
			if(flag>((i%2019)*(j%2019))%2019) ///////////////////////////////////////////////////////dsssssdgay5abreh5b4eynb6y5a4yb5r
				flag=((i%2019)*(j%2019))%2019; ///////////////////////////////////////////////////////////y6r
		}
	}
	//两个最小的不一定乘出来就是答案！！！！！！！！！！！！ 
	cout<<flag; 
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.InputMismatchException;

public class Main {
	int cnt;
	int[][] p;
	int[][] f;

	void bt(int x, int y) {
		if (4 <= y) {
			cnt++;
			return;
		}
		int nx = x + 1;
		int ny = y;
		if (4 <= nx) {
			nx = 0;
			ny++;
		}

		if (f[y][x] == 0) {
			for (int i = 0; i < 4; i++) {
				int px = x + p[i][0];
				int py = y + p[i][1];
				if (px < 0 || 4 <= px) continue;
				if (py < 0 || 4 <= py) continue;
				if (f[py][px] == 1) continue;
				f[y][x] = f[py][px] = 1;
				bt(nx, ny);
				f[y][x] = f[py][px] = 0;
			}
		} else {
			bt(nx, ny);
		}
	}

	void run() {
		MyScanner sc = new MyScanner();

		p = new int[4][2];
		f = new int[4][4];
		while (true) {
			for (int i = 0; i < 4; i++) {
				for (int j = 0; j < 2; j++) {
					p[i][j] = sc.nextInt();
					if (4 < p[i][j]) {
						return;
					}
				}
			}
			cnt = 0;
			bt(0, 0);
			System.out.println(cnt);
		}
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}

}

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

int main() {
    ll K, N;
    cin >> K >> N;

    ll A[N], d[N];
    for(ll i = 0; i < N; i++) {
        cin >> A[i];
        if(i >= 1) {
            d[i] = A[i] - A[i - 1];
        }
    }
    d[0] = (K - A[N - 1]) + A[0];

    ll max = d[0];
    for(ll i = 1; i < N; i++) {
        if(max < d[i]) {
            max = d[i];
        }
    }
    cout << K - max << endl;
    
    return 0;
}

Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ii,jj=1000001;
  cin>>n;
  bool b=false;
  for(int i=1;i<1000001;i++){
    if(i>n/i)break;
    if(n%i==0){
      ii=i;jj=n/i;
    }
  }
  cout<<ii+jj-2;
}

Measured memory_bytes: 256
package main

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

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

// sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) map[int]int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
	}
	return result
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	for i := 2; i*i <= x; i++ {
		if i == x {
			continue
		}
		if x%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	for i := 0; i < 5; i++ {
		x := readInt()
		if x == 0 {
			fmt.Println(i + 1)
			return
		}
	}
}


Measured memory_bytes: 1760
import math

def input_li():
    return list(map(int, input().split()))


def input_int():
    return int(input())


N = input_int()
ans = len(str(N))
for i in range(1, math.ceil(N ** 0.5) + 1):
    if (N / i).is_integer():
        ans = min(ans, max(len(str(i)), len(str(N // i))))
print(ans)


Measured memory_bytes: 65496
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N,M,m[30]={0},r=0;
	cin>>N>>M;
	for(int i=0;i<N;i++)
	{
		int k,a;
		cin>>k;
		for(int j=0;j<k;j++)
		{
			cin>>a;
			m[a-1]++;
		}
	}

	for(int i=0;i<M;i++)
	{
		if(m[i]==N)
		{
			r++;
		}
	}
	cout<<r<<endl;
}


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

int main() {
  int H,W;
  cin >> H>>W;
  vector<string> vec(H);
  for(int i=0;i<H;i++){
    cin >> vec[i];
  }
   for(int i=0;i<W+2;i++){
    cout << '#';
     if(i==W+1){cout <<endl;}
  }
  for(int i=0;i<H;i++){
    cout << '#'<<vec[i] << '#'<<endl;
  }
  for(int i=0;i<W+2;i++){
    cout << '#';
     if(i==W+1){cout <<endl;}
  }
 
}


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

public class Main {
	
	public static void main(String[] args){
		
		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
		//?????????????????????char[]?????¬????????§??????????´????????????????list??????
		ArrayList<char[]> list = new ArrayList<char[]>();
		
		try {
			boolean isContinue = true;
			while(isContinue){
				
				String strLine = insBR.readLine();
				if(!"0".equals(strLine)){
					//?????§???????????°???char[]???????§£??????list???????´?
					char[] ary = strLine.toCharArray(); 
					list.add(ary);
				}else{
					isContinue = false;
				}
			}
		} catch (IOException e) {
			// TODO ????????????????????? catch ????????????
			e.printStackTrace();
		}
		
		//char[]???int[]?????\?????´???
		
		for(int i = 0; i < list.size(); i++){
			//?????????????¨?????????\???????????°
			int intSumNum = 0;
					
			char[] ary = list.get(i);
			for(int j = 0; j < ary.length; j++){
				//char??????int??????????????????????????????
				int intNum = 0;
				intNum = Character.getNumericValue(ary[j]);
				intSumNum += intNum;
			}
			//??????
			System.out.println(intSumNum);
		}
		
	}
}

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

int main(){
  int n,d; cin>>n>>d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i=0; i<n; i++){
    for (int j=0; j<d; j++) cin>>x[i][j];
  }
  
  int cnt=0;
  for (int i=0; i<n-1; i++){
    for (int j=i+1; j<n; j++){
      double dis=0.0;
      for (int k=0; k<d; k++){
        dis+=pow(x[i][k]-x[j][k],2);
      }
      dis=pow(dis,0.5);
      if (dis==(int)dis) cnt+=1;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256