akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 10000
#define NIL -1
struct Node { int p, l, r; };
struct Node T[MAX];
int n;
void preParse(int u){
  if(u==NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}
void inParse(int u){
  if(u==NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}
void postParse(int u){
  if(u==NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}
int main(){
  int i,v,l,r,root;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l != NIL) T[l].p=v;
    if(r != NIL) T[r].p=v;
  }
  for(i=0;i<n;i++) if(T[i].p==NIL) root=i;
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2056
#abc046_c

def f(n,d):
 if n%d==0:
  return n/d
 else:
  return n/d+1
 
n=int(raw_input())
t0,a0=map(int,raw_input().split())
for i in range(n-1):
 tt,aa=map(int,raw_input().split())
 m=max(f(t0,tt),f(a0,aa))
 t0=tt*m
 a0=aa*m
print t0+a0


Measured memory_bytes: 2568
#include <stdio.h>

#define DATA 10000

int main(void)
{
	int num[DATA];
	int i;

	for(i = 0;i < DATA;i++)
	{
		scanf("%d", &num[i]);
		if(num[i] == 0)
			break;
	}
	for(i = 0;num[i] != 0;i++)
		printf("Case %d: %d\n", i + 1, num[i]);

	return 0;
}

Measured memory_bytes: 632
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
	int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if(b < a*n) System.out.println(b);
    else System.out.println(a*n);

  }
}


Measured memory_bytes: 35644
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,i;
  cin >> a >> b;
  while(i<10){
    if((int)((10*b+i)*0.08)==a){
      cout << (int)(10*b+i) << endl;
      exit(0);
    }
    i++;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;

// keyence-string.rs --- KEYENCE String
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        s: chars,
    };

    let word = "keyence".chars().collect::<Vec<_>>();
    let ans = (0..8).any(|i| s.starts_with(&word[..i]) && s.ends_with(&word[i..]));
    println!("{}", if ans { "YES" } else { "NO" });
}


Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
	public static void main(String[] args) /*throws java.io.IOException*/ {
		Scanner scan = new Scanner(System.in);
		int Rhombus = 0;
		int Rectangle = 0;
		while(scan.hasNext()){
			String text = scan.next();
			String[] num = text.split(",", 0);
			int a = Integer.parseInt(num[0]);
			int b = Integer.parseInt(num[1]);
			int c = Integer.parseInt(num[2]);
			if(a*a + b*b == c*c){
				Rectangle++;
			}else if(a == b){
				Rhombus++;
			}
		}
		System.out.println(Rectangle);
		System.out.println(Rhombus);
	}
}

Measured memory_bytes: 25968
from math import ceil

N, K = map(int, input().split())
A = [*map(int, input().split())]

l_lb, l_min = 0, max(A)
while l_min - l_lb > 1:
  l_mid = (l_lb + l_min) // 2
  if sum(ceil(a/l_mid) for a in A) - N > K:
    l_lb = l_mid
  else:
    l_min = l_mid
print(l_min)

Measured memory_bytes: 31008
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n = int(input())
li = LI()
d = Counter(li)
q = I()
ans = sum(li)
for i in range(q):
    b,c = MI()
    ans += d[b]*(c-b)
    d[c] += d[b]
    d[b] = 0
    print(ans)

Measured memory_bytes: 24876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)
#define _overload4(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)
#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl


int main(){
    char s[11]={};
    int ptr=0;
    while(true){
        char c=getchar();
        
        switch (c)
        {
            case '1':
                s[ptr++]='1';
                break;
            case '0':
                s[ptr++]='0';
                break;
            case 'B':
                s[--ptr]=0;
            	ptr=ptr<0?0:ptr;
                break;
            default:
                cout<<s<<endl;
                return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bitset<4000010>f;
int n,a,sum;
int main()
{
	f[0]=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		f|=f<<a;
		sum+=a;
	}
	for(int i=(sum+1)>>1;i<=sum;i++)
		if(f[i])
		{
			printf("%d\n",i);
			return 0;
		}
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    int ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 405;
int dp[N][N], dp1[N][N];
int a[N], b[N];
void solve(){
	int n, c;
	cin >> n >> c;
	fr(i, 1, n){
		cin >> a[i];
	}
	fr(i, 1, n){
		cin >> b[i];
	}
	fr(j, 0, 400){
		fr(i, 1, 400){
			dp1[j][i] = (dp1[j][i - 1] + pwr(i, j, mod)) % mod;
		}
	}
	dp[0][0] = 1;
	fr(i, 0, n - 1){
		fr(j, 0, c){
			if(!dp[i][j]) continue;
			fr(k, 0, c - j){
				dp[i + 1][j + k] += (dp[i][j] * (dp1[k][b[i + 1]] - dp1[k][a[i + 1] - 1] + mod)) % mod;
				dp[i + 1][j + k] %= mod;
			}
		}
	}
	cout << dp[n][c];
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 100000007

const ll M=100000;
ll dp5[100001],dp3[100001];

ll calc(bool is5, ll len){
  ll res=0;
  if(is5){
    repl(l,1,len+1){
      if((len-l)%5==0){
        (res+=dp5[l])%=mod;
      }
    }
  }else{
    repl(l,1,len+1){
      if((len-l)%3==0){
        (res+=dp3[l])%=mod;
      }
    }
  }
  return res;
}

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

  dp5[0]=1;
  repl(i,1,M+1){
    repl(j,1,5+1){
      if(i-j>=0)(dp5[i]+=dp5[i-j])%=mod;
    }
  }
  dp3[0]=1;
  repl(i,1,M+1){
    repl(j,1,3+1){
      if(i-j>=0)(dp3[i]+=dp3[i-j])%=mod;
    }
  }

  while(1){
    string S;
    cin>>S;
    if(S=="#")break;
    ll N=S.size();
    ll res=1;
    ll i=0;
    while(i<N){
      ll j=i;
      while(j<N&&S[i]==S[j]){
        j++;
      }
      if(S[i]=='8'||S[i]=='0') (res*=calc(false,j-i))%=mod;
      else (res*=calc(true,j-i))%=mod;
      i=j;
    }
    cout<<res<<endl;
  }

  return 0;
}



Measured memory_bytes: 5016
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		char[] s = sc.next().toCharArray();
		int len = 0;
		for (int i = s.length - 2; i >= 2; i--) {
			if (i % 2 == 0) {
				boolean b = true;
				for (int j = 0; j <= i / 2 - 1; j++) {
					if (s[j] != s[i / 2 + j]) {
						b = false;
						break;
					}
				}
				if (b) {
					len = i;
					break;
				}
			}
		}
		System.out.println(len);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define int long long int
vector<vector<int>>adj;
int t[800005];
int lazy[800005];

void push(int v, int tl, int tr) {
	int tm=(tl+tr)/2;
    t[v*2] += lazy[v]*(tm-tl+1);
    lazy[v*2] += lazy[v];
    t[v*2+1] += lazy[v]*(tr-tm);
    lazy[v*2+1] += lazy[v];
    lazy[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int addend) {
    if (l > r) 
        return;
    if (l == tl && tr == r) {
        t[v] += addend*(tr-tl+1);
        lazy[v] += addend;
    } else {
        push(v, tl, tr);
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), addend);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, addend);
        t[v] = (t[v*2]+t[v*2+1]);
    }
}

int query(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return 0;
    if (l <= tl && tr <= r)
        return t[v];
    push(v, tl, tr);
    int tm = (tl + tr) / 2;
    return (query(v*2, tl, tm, l, min(r, tm))+ query(v*2+1, tm+1, tr, max(l, tm+1), r));
}


main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	adj.resize(n+1);


	for(int i=0; i<n-1; i++){
		int u, v;
		cin>>u>>v;
		if(u>v){
			swap(u, v);
		}
		adj[v].pb(u);
	}
	int ans=0;
	for(int i=1; i<=n; i++){
		for(auto u:adj[i]){
			update(1, 0, n, 1, u, 1);
		}
		int val=query(1, 0, n, 1, i);
		ans+=((i)*(i+1))/2;
		ans-=val;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 22432
# -*- coding: utf-8 -*-
# 学籍番号 17D8101029G 石塚 博之 ID: mcatpolo 言語: python3

N = int(input())
S = list(input())
cnt = int(0)
S.append('Z')
i = int(0)

while i<N:
    if S[i] == 'O' and S[i+1] == 'X':
        cnt+=1
        i+=2
    elif S[i] == 'X' and S[i+1] == 'O':
        cnt+=1
        i+=2
    else:
        i+=1

print(cnt)


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

using namespace std;

int N;

int main() {
	cin >> N;
	vector<int> A(N);
	int fir = 0;
	int sec = 1;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] > A[fir]) {
			sec = fir;
			fir = i;
		}
		else if (A[i] > A[sec] && i != fir) {
			sec = i;
		}
		//cout << fir << " " << sec << endl;
	}
	for (int i = 0; i < N; i++) {
		if (i == fir) {
			cout << A[sec] << endl;
		}
		else {
			cout << A[fir] << endl;
		}
	}
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (i / 10 == 0) {
      ans++;
    }
    else if (i / 100 != 0 && i / 1000 == 0) {
      ans++;
    }
    else if (i / 100 != 0 && i / 10000 != 0 && i / 100000 == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

#define right Right
typedef pair<ll,ll> pll;
const int N = 1e5 + 10 , M = 4;
int n , a , b;
ll x[N] , y[N];
int from[M][N] , to[M][N] , id[M][N] , rid[M][N] , fa[M][N] , vis[N];

void getGraph(int *from,int *to,int *id,int *rid,int *fa,ll D) {
  vector<pair<pll,int> > v(n);
  rep(i,0,n) v[i]=mp(mp(x[i],y[i]),i);
  sort(all(v));
  rep(i,0,n+1) fa[i] = i;
  rep(i,0,n) {
    ll x=v[i].fi.fi,y=v[i].fi.se;
    id[v[i].se]=i;
    rid[i]=v[i].se;
    int left=lower_bound(all(v),mp(mp(x+D,y-D),0))-v.begin();
    int right=lower_bound(all(v),mp(mp(x+D,y+D),0))-v.begin();
    from[i] = left , to[i] = right;
  }
  rid[n]=n;
}

int F(int x,int *fa,int *rid) {
  if(fa[x] == x) {
    if(!vis[rid[x]]) return x;
    return fa[x] = F(x + 1 , fa , rid);
  }
  return fa[x] = F(fa[x] , fa , rid);
}

int main(){
  scanf("%d%d%d",&n,&a,&b);
  --a;--b;
  rep(i,0,n) {
    scanf("%lld%lld",x+i,y+i);
    tie(x[i],y[i])=mp(x[i]-y[i],x[i]+y[i]);
  }
  ll D = max(abs(x[a]-x[b]),abs(y[a]-y[b]));
  rep(i,0,4) {
    getGraph(from[i] , to[i] , id[i] , rid[i] , fa[i] , D);
    rep(i,0,n) tie(x[i],y[i])=mp(y[i],-x[i]);
  }
  vi v;v.pb(a);vis[a]=true;
  ll ans = 0;
  rep(i,0,sz(v)) {
    int c = v[i];
    rep(d,0,4) {
      int *from=::from[d],*to=::to[d],*id=::id[d],*rid=::rid[d],*fa=::fa[d];
      int x = id[c];
      int l = from[x] , r = to[x];
      ans += r - l;
      while(l < r) {
        l = F(l , fa , rid);
        if(l < r) {
          vis[rid[l]] = true;
          v.pb(rid[l]);
        }
      }
    }
  }
  printf("%lld\n",ans / 2);
  return 0;
}


Measured memory_bytes: 13404
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String prev = "";
        String now = "";
        int ans = 0;
        for(int i = 0; i < s.length(); i++){
            now += s.substring(i,i+1);
            if(prev.equals(now)){
                continue;
            }else{
                ans++;
                prev = now;
                now = "";
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 46240
//
// Created by 李青坪 on 2018/11/3.
//

#include <cstdio>
#include <algorithm>
#include <queue>

#define MAXN 101
using namespace std;
int n;
int graph[MAXN][MAXN];
int dist[MAXN];
bool visited[MAXN];
queue<int > q;

void init(){
    fill(dist, dist+MAXN, -1);
    fill(visited, visited+MAXN, false);
    dist[1] = 0;
}

void bfs(int i){
    for (int j = 1; j <= n; ++j) {
        if (graph[i][j] == 1){
            if (visited[j]) continue;
            q.push(j);
            visited[j] = true;
            dist[j] = dist[j] >= 0 ? min(dist[j], dist[i] + 1): dist[i] + 1;
        }
    }
    while (!q.empty()){
        int next = q.front();
        q.pop();
        bfs(next);
    }
}

int main(){
    scanf("%d", &n);
    int u, k;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &u, &k);
        int node;
        for (int j = 0; j < k; ++j) {
            scanf("%d", &node);
            graph[u][node] = 1;
        }
    }
    init();
    bfs(1);
    for (int l = 1; l <= n; ++l) {
        printf("%d %d\n", l, dist[l]);
    }
}
/*
5
1 2 2 4
2 1 4
3 0
4 1 3
5 1 4
 */


Measured memory_bytes: 2752
from collections import defaultdict
def main():
    N = int( input())
    A = list( map( int, input().split()))
    d = defaultdict( int)
    e = defaultdict( int)
    ans = 0
    for i in range(N):
        a = A[i]
        ans += d[a+(i+1)]
        ans += e[a-(i+1)]
        d[(i+1)-a] += 1
        e[-a-(i+1)] += 1
    
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 94408
class Sieve:
    # Sieve of Eratosthenes
    def __init__(self, n):
        f = [0]*(n+1)
        primes = list()
        f[0] = f[1] = -1
        for i in range(2,n+1):
            if f[i]:
                continue
            primes.append(i)
            f[i]=i
            for j in range(i*i, n+1, i):
                if not f[j]:
                    f[j] = i
        self.f = f
        self.primes = primes
    def isPrime(self, x):
        return self.f[x] == x
    def factorList(self, x):
        res = list()
        while x > 1:
            res.append(self.f[x])
            x //= self.f[x]
        return res
    def factor(self, x):
        fl = self.factorList(x)
        if len(fl) == 0:
            return list()
        res = [[fl[0], 0]]
        for p in fl:
            if res[-1][0] == p:
                res[-1][1] += 1
            else:
                res.append([p, 1])
        return res

sv= Sieve(10000)

n=int(input())
ans=1
d=dict()
for i in range(2,n+1):
    f=sv.factor(i)

    for p,cnt in f:
        try:
            d[p]+=cnt
        except:
            d[p]=cnt

for p,cnt in d.items():
    ans*=(cnt+1)
    ans%=(10**9+7)

print(ans)




Measured memory_bytes: 42604
#include <iostream>
using namespace std;
int main(){
	int a[100001],i,n,count=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	
	for(i=1;i<=n;i++){
		if(a[i]>i){
			if(a[a[i]]==i)count++;
		}
	}

	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <bitset>
using namespace std;

typedef long long ll;
int main() {
    ll x, y;
    cin>>x>>y;
    if (x<y) {
        if ((x>=0 && y>=0)||(x<0 && y<0)||(x<0 && y==0)) 
            cout<<abs(abs(y)-abs(x))<<endl;
        else
            cout<<abs(abs(y)-abs(x))+1<<endl;
    } else {
        if ((x<0 && y>=0) || (x>=0 && y<0) || (x>0 && y==0))
            cout<<abs(abs(x)-abs(y))+1<<endl;
        else if ((x>=0 && y>=0)||(x<0 && y<0)) 
            cout<<abs(abs(x)-abs(y))+2<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import kotlin.math.PI

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main() {
    val (N, K) = readInts()
    val r = Array(N) {0}
    (1..K).forEach {
        readInt()
        readInts().forEach { r[it - 1] = 1 }
    }
    println(r.count { it == 0 })
}


Measured memory_bytes: 39200
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 45
#define mod 1000000007
using namespace std;

int n, x, y, z, f[N][(1 << 17) + 5], ans; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
	n = read <int> (), x = read <int> (), y = read <int> (), z = read <int> ();
	ans = 1; 
	for(int i = 1; i <= n; i++)
		ans = 1ll * ans * 10 % mod; 
	int sz = (1 << (x + y + z)) - 1, ck = (1 << (x + y + z - 1)) | (1 << (y + z - 1)) | (1 << (z - 1));
	f[0][0] = 1;
	for(int i = 1; i <= n; i++)
		for(int j = 0; j <= sz; j++)
			if(f[i - 1][j])
			{
				for(int k = 1; k <= 10; k++)
				{
					int tmp = (j << k) | (1 << (k - 1));
					tmp &= sz;
					if((tmp & ck) != ck) f[i][tmp] = (1ll * f[i][tmp] + f[i - 1][j]) % mod; 
				}
			}
	for(int j = 0; j <= sz; j++)
		ans = ((1ll * ans - f[n][j]) % mod + mod) % mod;
	printf("%d\n", ans); 
	return 0; 
}

Measured memory_bytes: 20864
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50

def bfs(MAZE, start, seen):
    queue = deque([start + (0 ,)])
    max_count = 0
    while queue:
        y,x,count = queue.popleft()
        max_count = max(max_count, count)
        if (y,x) in seen:
            continue
        seen.add((y, x))
        for i,j in ((0,1), (0,-1), (1,0), (-1, 0)):
            next_y, next_x = y + i, x + j
            #print(next_y, next_x)
            if not (next_y, next_x) in seen and MAZE[next_y][next_x] == '.':
                queue.append((next_y, next_x, count+1))
                #seen.add((next_y, next_x))
    return max_count


def run():
    H, W = map(int, input().split())
    MAZE = ['#' * (W+2)]
    for _ in range(H):
        s = input()
        s = '#' + s + '#'
        MAZE.append(s)
    MAZE.append('#' * (W+2))

    #for m in MAZE:
    #    print(m)

    ways = []
    for i in range(1, H+1):
        for j in range(1, W+1):
            if MAZE[i][j] == '.':
                ways.append((i, j))

    max_count = 0
    for s_i, s_j in ways:
        seen = set((s_i, s_j))
        min_count = bfs(MAZE, (s_i, s_j), seen)
        #print((s_i, s_j), '->', (g_i, g_j))
        #print(min_count)
        max_count = max(max_count, min_count)

    print(max_count)

if __name__ == "__main__":
    run()

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

int main() {
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < (int)s.size(); i++)
    {
        if (s.at(i) == 'o') cnt++;
    }
    
    if (15 - (int)s.size() + cnt >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    cin>>N;
    ll a[N];
    rep(i, 0, N)cin>>a[i];
    ll dp[N]={};
    dp[0]=1000;
    rep(i, 1, N) {
        dp[i]=dp[i-1];
        rep(j, 0, i) {
            dp[i]=max(dp[i], dp[j]+(a[i]-a[j])*(dp[j]/a[j]));
        }
    }
    cout<<dp[N-1]<<endl;
}

int main()
{
    func();
}

Measured memory_bytes: 3588
#include <stdio.h>

#define N 100000

int main() {
	static char cc[N + 1];
	static int kk[N];
	int n, n_, k, i, j, cnt, x, ans;

	scanf("%d%d%s", &n, &k, cc);
	n_ = 0;
	for (i = 0; i < n; i++) {
		if (n_ == 0 || cc[n_ - 1] != cc[i])
			cc[n_++] = cc[i];
		kk[n_ - 1]++;
	}
	n = n_;
	cnt = 0;
	for (i = 0; i < n; i++)
		if (cc[i] == '0')
			cnt++;
	for (i = 1; i < n; i++)
		kk[i] += kk[i - 1];
	ans = 0;
	for (j = 0; j < n; j++) {
		i = j - k * 2;
		if (cc[j] != '0')
			i--;
		x = kk[j] - (i >= 0 ? kk[i] : 0);
		if (ans < x)
			ans = x;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	a := make(map[int]bool, n)
	for i := 0; i < n; i++ {
		var num int
		fmt.Scan(&num)
		if a[num] {
			a[num] = false
		} else {
			a[num] = true
		}
	}

	var cnt int
	for _, v := range a {
		if v {
			cnt++
		}
	}
	fmt.Println(cnt)
}


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

char s[] = "CODEFESTIVAL2016";
char ss[100];
int main(void)
{
	int k = strlen(s);
	cin >> ss;
	int ans = 0;
	for(int i=0; i<k; ++i)
	{
		if(ss[i] != s[i])
			ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=998244353;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
ll N,A,B,K;
ll kai[300001];
ll gya[300001];
ll nck[300001];
//
ll pow(ll x,ll n,ll mod){
  ll res=1;
  if(n>0){
    res=pow(x,n/2,mod);
    if(n%2==0){
      res=(res*res)%mod;
    }else{
      res=(((res*res)%mod)*x)%mod;
    }
  }
  return res;
}
//
ll inv(ll n,ll mod){
  return pow(n,mod-2,mod);
}
//
void nCk(ll n,ll mod){
    kai[N]=N;
    ROF(i,1,N){
      (kai[i]=kai[i+1]*i)%=mod;
    }
    gya[1]=inv(1,mod);
    FOR(i,2,N+1){
        (gya[i]=gya[i-1]*inv(i,mod))%=mod;
    }
    FOR(i,1,N){
        (nck[i]=kai[N+1-i]*gya[i])%=mod;
    }
    nck[0]=1;nck[N]=1;
}
int main(){
  cin>>N>>A>>B>>K;
  nCk(N,mod);
  ll ans=0;
  FOR(i,0,N+1){
    if((K-A*i)%B==0&&(K-A*i)/B>=0&&(K-A*i)/B<=N){
      (ans+=nck[i]*nck[(K-A*i)/B])%=mod;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string S;
  cin>>S;
  
  
  int ans=0;
  
  for(int i=1;i<S.size()-1;i++){
    ans++;
  }
  
  cout<<S[0]<<ans<<S[S.size()-1]<<endl;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long z = sc.nextLong();
    long w = sc.nextLong();
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    long ans1 = Math.abs(a[n - 1] - w);
    long[] dp1 = new long[n];
    long[] dp2 = new long[n];
    for(int i = n - 1; i >= 0; i--) {
      long aite = w;
      if(i > 0) aite = a[i - 1]; 
      // dp1の更新
      long temp1 = Math.abs(aite - a[n - 1]);
      for(int j = i; j < n; j++) {
        if(j < n - 1) temp1 = Math.max(temp1, dp2[j + 1]);
      }
      dp1[i] = temp1;
 
      aite = z;
      if(i > 0) aite = a[i - 1];
      // dp2の更新
      long temp2 = Math.abs(aite - a[n - 1]);
      for(int j = i; j < n; j++) {
        if(j < n - 1) temp2 = Math.min(temp2, dp1[j + 1]);
      }
      dp2[i] = temp2;
      
    }
    long ans = Math.max(ans1, dp1[0]);
    System.out.println(ans);
  }
}

Measured memory_bytes: 28172
def examE(mod):
    N, X, Y, Z = LI()
    L = 2**(X+Y+Z-1)
    XYZ = (1 << (X + Y + Z - 1)) | (1 << (Y + Z - 1)) | (1 << (Z - 1))
    dp = [[0]*L for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        for j in range(L):
            for k in range(1,11):
                next = (j<<k)|(1<<(k-1))
                if next&XYZ==XYZ:
                    continue
                else:
                    dp[i+1][next%L] += dp[i][j]
                    dp[i + 1][next % L] %=mod
    ans = pow(10,N,mod)-sum(dp[-1])%mod
    if ans<0:
        ans +=mod
    print(ans)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examE(mod)


Measured memory_bytes: 62316
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;

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

int parent[MAX], Size[MAX];
ll ans[MAX];
vector<pii> vp;

int findSet(int x)
{
    if(parent[x] == x)
        return x;
    return parent[x] = findSet(parent[x]);
}

bool isSameSet(int i, int j)
{
    return findSet(i) == findSet(j);
}

ll unionSet(int i, int j)
{
    if(!isSameSet(i, j)){
        int x = findSet(i);
        int y = findSet(j);
        ll a = (1LL * Size[x] * (Size[x] - 1)) / 2;
        ll b = (1LL * Size[y] * (Size[y] - 1)) / 2;
        ll c = Size[x] + Size[y];
        ll ans = ((1LL * c * (c - 1)) / 2) - a - b;
        //cout<<"Size: "<<a<<" "<<b<<" "<<c<<endl;
        if(Size[x] >= Size[y]){
            Size[x] += Size[y];
            parent[y] = x;
        }
        else{
            Size[y] += Size[x];
            parent[x] = y;
        }
        return ans;
    }
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int n, m, u, v;

    cin>>n>>m;

    for(int i = 1; i <= n; i++){
        parent[i] = i;
        Size[i] = 1;
    }

    for(int i = 0; i < m; i++){
        cin>>u>>v;
        vp.push_back(make_pair(u, v));
    }

    ans[m-1] = (1LL * n * (n - 1)) / 2;
    for(int i = vp.size() - 1; i >= 1; i--){
        if(isSameSet(vp[i].first, vp[i].second)){
            ans[i-1] = ans[i];
        }
        else{
            ans[i-1] = ans[i] - unionSet(vp[i].first, vp[i].second);
        }
    }

    for(int i = 0; i < m; i++){
        cout<<ans[i]<<endl;
    }

    return 0;
}

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

using namespace std;

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

    string day;
    cin >> day;

    vector<string> days = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};

    vector<string>::iterator it;

    it = find(days.begin(), days.end(), day);
    if (it != days.end()) {
        int offset = it - days.begin() + 1;
        cout << offset;
    }

    return 0;
}


Measured memory_bytes: 256
def main():
    N = int( input())
    UV = [ tuple( map( int, input().split())) for _ in range(N-1)]
    ans = 0
    for i in range(1, N+1):
        ans += i*(N-i+1)
    for u, v in UV:
        if u > v:
            u, v = v, u
        ans -= u*(N-v+1)
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 36100
#!/usr/bin/env python3

from math import sqrt

N, M = map(int, input().split())
ans = 0

for k in range(1, int(sqrt(M)) + 1):
    if M % k == 0:
        if k <= M / N:
            ans = max(ans, k)
        if M/k <= M/N:
            ans = max(ans, M//k)
print(ans)

Measured memory_bytes: 3060
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn=new Scanner(System.in);
	int a=stdIn.nextInt();
	int b=stdIn.nextInt();
	int c=stdIn.nextInt();
	int i=b-a;
	int j=c-b;
	if(i==j){
	    System.out.println("YES");
	}else{
	    System.out.println("NO");
	}
    }
}
	


Measured memory_bytes: 22100
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int A,B,M;
  cin>>A>>B>>M;
  VI AA(A);
  VI BB(B);
  rep(i,A) cin>>AA[i];
  rep(i,B) cin>>BB[i];
  VI X(M),Y(M),C(M);
  rep(i,M) cin>>X[i]>>Y[i]>>C[i];
  int ans=100000000;
  rep(i,M){
    ans=min(ans,AA[X[i]-1]+BB[Y[i]-1]-C[i]);
  }
  sort(all(AA));
  sort(all(BB));
  cout<<min(ans,AA[0]+BB[0])<<endl;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;
    vl as(3 * n);
    cin>>as;
    
    priority_queue<ll, vector<ll>, greater<ll>> lq;
    vl ls(n + 1);
    rep(i, n) {
        lq.push(as[i]);
        ls[0] += as[i];
    }
    rep(i, n) {
        ll m = lq.top();
        ll s = ls[i];
        if (as[n + i] > m) {
            lq.pop();
            lq.push(as[n + i]);
            s += as[n + i] - m;
        }
        ls[i + 1] = s;
    }
    
    priority_queue<ll> rq;
    vl rs(n + 1);
    rep(i, n) {
        rq.push(as[3 * n - 1 - i]);
        rs[n] += as[3 * n - 1 - i];
    }
    rep(i, n) {
        ll m = rq.top();
        ll s = rs[n - i];
        if (as[2 * n - 1 - i] < m) {
            rq.pop();
            rq.push(as[2 * n - 1 - i]);
            s += as[2 * n - 1 - i] - m;
        }
        rs[n - i - 1] = s;
    }

    ll ans = -LINF;
    rep(i, n + 1) {
        chmax(ans, ls[i] - rs[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6516
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
//注意！nはllかもしれない？<-大丈夫そう
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
    ll n;
    ll k;
    cin >> n >> k;
    ll ans = 0;
    for (ll i = n; i >= 1; i--) {//i個の部屋に分かれる方法
        if (i >= n - k) {
            ans += COM(n - 1, i - 1)*COM(n,i);
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12160
N = int(input())
l = [int(i) for i in input().split()]

l1 = sorted(l, reverse = True)
Alice = 0
Bob = 0
for j in range(len(l)):
    if j % 2 == 0:
        Alice += l1[j]
    else:
        Bob += l1[j]
print(Alice - Bob)

Measured memory_bytes: 3060
def solve(n, k, t)
  return 1 if n == 0
  return 0 if k == 0
  ret = 0
  t.downto(t/k) do |x|
    ret += solve(v = n - x * x, k - 1, x * x < v ? x : Math.sqrt(v).to_i)
  end
  ret
end

while n = gets.to_i
  break if n == 0
  puts solve(n, 4, Math.sqrt(n).to_i)
end

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

int main() {	
	int a[105];
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int count=0;
	for(int i=0;i<n-1;i++){
		int minj=i;
		for(int j=i+1;j<n;j++){
			if(a[minj]>a[j]){
				minj=j;
			}
		}
		if(minj!=i){
			int temp = a[minj];
			a[minj]=a[i];
			a[i]=temp;
			count++;
		}
	}
	
	for(int i=0;i<n;i++){
		if(i>0) cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
	cout<<count<<endl;
	
	return 0;
}

Measured memory_bytes: 3100
N,K = map(int, input().split())
As = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)
for a in As:
    d[a] += 1

cnt = 0
numbers = []
for k in d.keys():
    cnt += 1
    numbers.append(d[k])
numbers.sort()
i = 0
ans = 0
while cnt > K:
    ans += numbers[i]
    cnt -= 1
    i += 1
print(ans)

Measured memory_bytes: 32440
#include <stdio.h>

int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int main() {
    int n, lcm, a, b;
    scanf("%d ", &n);
    scanf("%d %d ", &a, &b);
    lcm = a * b / gcd(a,b);
    n -= 2;
    while (n--) {
        scanf("%d ", &b);
        lcm = lcm * b / gcd(lcm, b);
    }
    printf("%d\n", lcm);
    return 0;
}



Measured memory_bytes: 2088
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const int N = 6000;
bool b[N][5];

void all_fall(int y){
  rep(j,5)b[y][j]=false;
  REP(i,y,N-1){
    rep(j,5)b[i][j]=b[i+1][j];
  }
  rep(j,5)b[N-1][j]=false;
}

int getmax(int l,int r){
  int ret=0;
  REP(j,l,r){    
    int tmp = N-1;
    for(int i=N-1;i>=0;i--){
      if (b[i][j])break;
      tmp=i;
    }
    ret=max(ret,tmp);
  }
  return ret;
}

void fall(){
  rep(i,N){
    if (b[i][0]&b[i][1]&b[i][2]&b[i][3]&b[i][4]){
      all_fall(i);
      i--;
    }
  }
}

main(){
  int n;
  while(cin>>n && n){
    rep(i,N)rep(j,5)b[i][j]=false;
    rep(i,n){
      int d,p,q;
      int wid=1,hei=1,pos;
      cin>>d>>p>>q;
      q--;
      if (d == 1){//yoko
	pos = getmax(q,q+p);	
	wid=p;
      }else if (d == 2){//tate
	pos = getmax(q,q+1);
	hei=p;
      }

      rep(i,hei){
	rep(j,wid){
	  b[pos+i][q+j]=true;
	}
      }
      fall();
    }

    cout << count(&b[0][0],&b[N][0],true) << endl;
  }
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
  	public static void main(String... args) {
      	Scanner sc = new Scanner(System.in);
      	int H = sc.nextInt();
      	int W = sc.nextInt();
      	int h = sc.nextInt();
      	int w = sc.nextInt();
      	System.out.println(H*W - H*w - h*W + h*w);
    }
}

Measured memory_bytes: 23764
"use strict"

const fs = require("fs");

function main(input) {
  const tmp = input.split("\n");
  const n = tmp[0];
  const xs = tmp[1].split(" ").map(v => parseInt(v));
  console.log(process(n, xs));
}

function process(n, xs) {
  let ret = 100000000;
  const min = Math.min(...xs);
  const max = Math.max(...xs);
  for (let p = min; p <= max; ++p) {
    const sum = xs.reduce((a, c) => a + Math.pow((c - p), 2), 0);
    if (ret > sum)
      ret = sum;
  }
  return ret;
}

main(fs.readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21576
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		//int a = sc.nextInt();
		// 文字列の入力
		String s = sc.next();
		// 出力
		s = s.replace("2017", "2018");
		System.out.println(s);
	}
}


Measured memory_bytes: 21204
<?php

class In {

	private $buf = [];
	private $count = 0;
	private $pointer = 0;

	public function nextLine() {
		$ret = '';
		if($this->hasNext()){
			while($this->hasNext()){
				$ret .= $this->next();
			}
		}else{
			$ret = trim(fgets(STDIN));
		}

		return $ret;
	}

	public function next() {
		if(!$this->hasNext()) {
			$str = trim(fgets(STDIN));
			$this->buf = explode(' ',$str);
			$this->count = count($this->buf);
			$this->pointer = 0;
		}

		return $this->buf[$this->pointer++];
	}

	public function hasNext() {
		return $this->pointer < $this->count;
	}

	public function nextInt() {
		return (int)$this->next();
	}

	public function nextDouble() {
		return (double)$this->next();
	}
}

class Out {
	public function println($str = '') {
		echo $str . PHP_EOL;
	}
}

$in = new In();
$out = new Out();

$A = $in->nextInt();

$out->println("ABC$A");

?>


Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main(){
    fastio;
    ll n, k;
    cin >> n >> k;
    if(k>n) k=n;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(),h.end());
    rep(i,k){
        h[n-1-i]=0;
    }
    ll ans = 0;
    rep(i,n) ans += h[i];
    cout << ans << "\n";
    #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Max(a, b) (a > b ? a : b)
#define Min(a, b) (a < b ? a : b)
#define ii pair<int, int>
#define fi first
#define se second
const int MAX = 200000; //2 * 10^5
const int MOD = 1000000007; //10^9 + 7
const int OO = 0x3f3f3f3f; // 0x3f3f3f3f;

int32_t main()
{
	int n;
	cin >> n;
	int ans = 0;
	
	for(int i = 1; i <= n; i++)
	{
		if(i % 5 == 0 or i % 3 == 0) continue;
		ans += i;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <complex>
#include <cmath>
using namespace std;


int main(int argc, char const *argv[]) {
    long long n;cin>>n;
    map<long long,long long> a,b;
    long long amax=-1,amax2=-2,bmax=-3,bmax2=-4;
    for(int i=0;i<n/2;++i){
        long long tmp1,tmp2;
        cin>>tmp1>>tmp2;
        a[tmp1]++;
        b[tmp2]++;
    }
    vector<pair<long long, long long>> as(0),bs(0);
    for(auto itr = a.begin();itr!=a.end();++itr)as.push_back(pair<long long, long long>(itr->second,itr->first));
    for(auto itr = b.begin();itr!=b.end();++itr)bs.push_back(pair<long long, long long>(itr->second,itr->first));
    int la = as.size(),lb = bs.size();
    sort(as.begin(),as.end());
    sort(bs.begin(),bs.end());
    if(as[la-1] != bs[lb-1]){
        cout<<n-as[la-1].first-bs[lb-1].first<<endl;
        return 0;
    }
    if(la == 1){
        if(lb == 1){
            cout<< n/2 <<endl;
            return 0;
        }
        else cout<< n/2 - bs[lb-2].first <<endl;
        return 0;
    }
    if(lb == 1){
        if(la == 1){
            cout<< n/2 <<endl;
            return 0;
        }
        else cout<< n/2 - as[la-2].first <<endl;
        return 0;
    }
    cout<<min(n-as[la-1].first-bs[lb-2].first,n-as[la-2].first-bs[lb-1].first)<<endl;
    return 0;
}

Measured memory_bytes: 8824
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
using namespace std;
 
class bitree;
int ite;
string str;
 
void error();
bitree *kaiseki();
bitree *add(bitree*,bitree*);
 
class bitree
{
public:
	unsigned int data;
	bitree *left;
	bitree *right;
public:
	bitree():data(0),left(NULL),right(NULL){}
	bitree(unsigned int dt):data(dt),left(NULL),right(NULL){}
	~bitree()
	{
		if(left != NULL)
			delete left;
		if(right != NULL)
			delete right;
	}
	string str()
	{
		string ret;
		char integer[5] = "";
		ret += "(";
		if(left != NULL)
			ret += left->str();
		ret += ")";
		ret += "[";
		sprintf(integer,"%u",data);
		ret += integer;
		ret += "]";
		ret += "(";
		if(right != NULL)
			ret += right->str();
		ret += ")";
		return ret;
	}
	bitree operator+(bitree a)
	{
		bitree ret;
		ret = *add(this,&a);
		return ret;
	}
};
 
void error()
{
	cout << "Error" << endl;
	exit(EXIT_FAILURE);
}
 
bitree *kaiseki()
{
	bitree *ret = new bitree();
	if(str[ite] == ')'){
		return NULL;
	}
	if(str[ite] != '(')
		error();
	ite++;
	ret->left = kaiseki();
	if(str[ite] != ')')
		error();
	ite++;
	if(str[ite] != '[')
		error();
	ite++;
	sscanf((str.substr(ite,4)).c_str(),"%u",&ret->data);
	while(str[ite] >= '0' && str[ite] <= '9')
		ite++;
	if(str[ite] != ']')
		error();
	ite++;
	if(str[ite] != '(')
		error();
	ite++;
	ret->right = kaiseki();
	if(str[ite] != ')')
		error();
	ite++;
	return ret;
}
 
bitree *add(bitree *a,bitree *b)
{
	if(a == NULL || b == NULL)
		return NULL;
	bitree *ret = new bitree(a->data + b->data);
	ret->left = add(a->left,b->left);
	ret->right = add(a->right,b->right);
	return ret;
}
 
int main()
{
	string sa,sb;
	cin >> sa;
	cin >> sb;
	ite = 0;
	str = sa;
	bitree *A = kaiseki();
	ite = 0;
	str = sb;
	bitree *B = kaiseki();
	cout << add(A,B)->str() << endl;
	return 0;
}

Measured memory_bytes: 3368
N, K = map(int, input().split())
S = list(input())
K -= 1
if S[K] == "A":
    S[K] = "a"
elif S[K] == "B":
    S[K] = "b"
elif S[K] == "C":
    S[K] = "c"


print("".join(S))


Measured memory_bytes: 38484