akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {

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

        while (true){
            String action = in.next();
            int num = 0;
            if(action.equals("insert")){
                num = in.nextInt();
            }


            if(action.equals("insert")){
                heap.insert(num);
            } else if(action.equals("extract")){
                int popped = heap.extractMax();
                System.out.println(popped);
            } else{
                break;
            }
        }
    }
}

class Heap {
    private int [] heap;
    private int size;
    public Heap(){
        heap = new int[2000001];
        size = 0;
    }

    private int parent(int pos){
        if(pos == 1){
            return 1;
        }
        return pos/2;
    }

    private int leftChild(int pos){
            return (pos * 2);
    }

    private int rightChild(int pos){
        return (pos * 2)+1;
    }

    private boolean isLeaf(int pos) {
        if (pos>1 && pos >= (size / 2) && heap[pos*2] == 0 && heap[(pos*2)+1]==0) {
            return true;
        }
        return false;
    }
    //ta funcionando
    private void swap(int fpos, int spos){
        int tmp;
        tmp = this.heap[fpos];
        this.heap[fpos] = this.heap[spos];
        this.heap[spos] = tmp;

    }

    private void maxHeapify(int pos){
        if(pos*2<heap.length && (pos*2)+1<heap.length) {
            if (heap[pos * 2] != 0 || heap[(pos * 2) + 1] != 0) {
                if (heap[pos] < heap[leftChild(pos)] || heap[pos] < heap[rightChild(pos)]) {
                    if (heap[leftChild(pos)] > heap[rightChild(pos)]) {
                        swap(pos, leftChild(pos));
                        maxHeapify(leftChild(pos));
                    } else {
                        swap(pos, rightChild(pos));
                        maxHeapify(rightChild(pos));
                    }
                }
            }
        }
        return;
    }

    public void insert(int k){

        heap[size+1] = k;
        size++;

        int current = size;


        while (current>1 && heap[current]>heap[parent(current)]){
            swap(current, parent(current));
            current = parent(current);
        }


    }

    public int extractMax(){
        int popped = heap[1];
        heap[1] = heap[size];
        heap[size] = 0;
        size--;
        maxHeapify(1);
        return popped;
    }
}


Measured memory_bytes: 556888
#include<cstdio>
#include<iostream>

using namespace std;

int x,y;
int ans;

int main()
{
	scanf("%d %d",&x,&y);
	if(y%2 == 0){
		ans = x + y/2;
		cout<< ans <<endl;
	}
	else {
		float anss = x + float(y)/2;
		cout<< anss <<endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    string S;
    cin >> S;
    vector<int> stops = {-1};
    REP(i, S.size() - 1) {
        if (S[i] != S[i + 1]) stops.push_back(i);
    }
    stops.push_back(S.size() - 1);

    for (int i = 0; i < stops.size() - 1; i += 2) {
        int r = stops[i + 1] - stops[i];
        int l = stops[i + 2] - stops[i + 1];
        REP(i, r - 1) cout << "0 ";
        cout << (r + 1) / 2 + l / 2 << " " << r / 2 + (l + 1) / 2 << " ";
        REP(i, l - 1) cout << "0 ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1144
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var s string
	if sc.Scan() {
		s = sc.Text()
	}

	sei := strings.Split(s, " ")

	k, _:= strconv.Atoi(sei[0])
	x, _:= strconv.Atoi(sei[1])
	nums := []int{x}

	m := x
	p := x

	for i := 1; i < k; i++ {
		m ++
		nums = append(nums,m)
		p--
		nums = append([]int{p}, nums...)
	}

	for i := 0; i < len(nums); i++{
		fmt.Print(nums[i])
		fmt.Print(" ")
	}
}

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

template <class T>
void chmax(T &x,T y)
{
    x=max(x,y);
}

main()
{
    int n,m,k; cin>>n>>m>>k;
    i64 ap[202020]={};
    for(int i=0; i<n; i++)
    {
        int x; cin>>x;
        ap[i+1]=ap[i]+x;
    }
    int p=0;
    while(p<n and ap[1+p]<=k) p++;
    int ans=p;
    i64 sum=0;
    for(int i=1; i<=m; i++)
    {
        int x; cin>>x; sum+=x;
        while(p>=0 and ap[p]+sum>k) p--;
        if(p<0) break;
        chmax(ans,i+p);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 5196
from itertools import product

abcd = input()

ops = ["+", "-"]

for pat in product(ops, repeat=3):
    eq = ""
    for num, op in zip(abcd, pat):
        eq += num + op
    eq += abcd[-1]
    ev = eval(eq)
    if ev == 7:
        break

ans = eq + "=7"
print(ans)


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

int dp[101][10010];
int val[100], wei[100];

int main(){
    int n, w;
    cin >> n >> w;
    for(int i = 0; i < n; i++){
        cin >> val[i] >> wei[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= w; j++){
            if(j < wei[i]){
                dp[i+1][j] = dp[i][j];
            }
            else{
                dp[i+1][j] = max(dp[i][j-wei[i]] + val[i], dp[i][j]);
            }
        }
    }
    cout << dp[n][w] << endl;
}


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

int main() {
  int a,b,x;
  float c,d,y,z,e,f,PI=3.141592653589793;
  cin >> a >> b >> x ;
  c=a;
  d=b;
  y=x;

  if(2*y<a*a*b){
    e=2*y/c/d;
    z=atan2(b,e);
    f=z*180.0/PI;
   cout << fixed << f << endl;
  }
  else{
  e=2.0*d-2.0*y/(c*c);
  z=atan2(e,c);
  f=z*180.0/PI;
  cout << fixed << f << endl;
  }
}

Measured memory_bytes: 256
while (input = STDIN.gets)!=nil do
  
    if input == "\n"
        break
    end
 
    data = [0.000,0.000,0.000,0.000,0.000,0.000]
     
    input = input.split(" ")
 
    for i in 0..5 
        data[i] = input[i].to_f
    end
         
    num = (data[0]*data[4]) - (data[1]*data[3])
 
    x = ( data[4]    *data[2] + (data[1]*-1)*data[5])/num + 0
    y = ((data[3]*-1)*data[2] +  data[0]    *data[5])/num + 0
     
    print sprintf("%.3f %.3f\n",x ,y )
     
end

Measured memory_bytes: 6140
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int Figure(ll x){
	return to_string(x).size();
}

bool f(int x){
	int S=Figure(x),k=1;
	for(int i=0;i<S-1;i++){
		if(x/k%10!=x/(k*10)%10+1) return 0;
		k*=10;
	}
	return 1;
}

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(int i=0;i<n;i++) cin>>a[i];
	int ans=-1;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(i!=j){
		int b=a[i]*a[j];
		if(f(b)) ans=max(ans,b);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3292
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main(int argc, char *argv[])
{
  int64_t n = 0;
  int64_t m = 0;

  std::cin >> n;
  std::cin >> m;

  std::vector<int64_t> a(m);

  std::cin >> a[0];
  for(int64_t i = 1; i < m; i++)
  {
    std::cin >> a[i];
    if((a[i] - 1) == a[i - 1])
    {
      std::cout << '0' << std::endl;
      return 0;
    }
  }

  int64_t s[] = {1, 0};
  int64_t j = 0;
  for(int64_t i = 1; i <= n; i++)
  {
    if((j < m) && (i == a[j]))
    {
      s[1] = s[0];
      s[0] = 0;
      j++;
    }
    else
    {
      int64_t t = s[0] + s[1];
      s[1] = s[0];
      s[0] = (t > 1'000'000'007) ? (t - 1'000'000'007) : t;
    }
  }

  std::cout << s[0] << std::endl;

  return 0;
}


Measured memory_bytes: 1024
from collections import Counter

class UnionFind():
  def __init__(self,n):
    self.parents=[-1]*n
  
  def find(self,x):
    if self.parents[x]<0:
      return x
    
    self.parents[x]=self.find(self.parents[x])
    return self.parents[x]
  
  def union(self,x,y):
    x=self.find(x)
    y=self.find(y)
    
    if x==y:
      return
    
    if self.parents[x]>self.parents[y]:
      x,y=y,x
      
    self.parents[x]+=self.parents[y]
    self.parents[y]=x
    
  def size(self,x):
    return abs(self.parents[self.find(x)])
  

N,K,L=map(int,input().split())
uf_road=UnionFind(N+1)
uf_train=UnionFind(N+1)
road_dict=dict()
train_dict=dict()

for _ in range(K):
  p,q=map(int,input().split())
  uf_road.union(p,q)

for _ in range(L):
  r,s=map(int,input().split())
  uf_train.union(r,s)

set_id_pairs = [(uf_road.find(i), uf_train.find(i)) for i in range(1,N+1)]
counter = Counter(set_id_pairs)
counts = [counter[set_id_pairs[i]] for i in range(N)]
print(' '.join(str(c) for c in counts))
  

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

int calc(int node,int node_from,vector<vector<int>> &tree,vector<int> &xsum,vector<int64_t> &psum);

int main()
{
	int n,q;
	cin >> n >> q;
	vector<int> a(n),b(n);
	vector<int> p(q+1),x(q+1);
	for (int i=1;i<n;++i)
	{
		cin >> a[i] >> b[i];
	}
	for (int i=1;i<=q;++i)
	{
		cin >> p[i] >> x[i];
	}

	vector<vector<int>> tree(n+1,vector<int>());
	for (int i=1;i<n;++i)
	{
		tree[a[i]].push_back(b[i]);
		tree[b[i]].push_back(a[i]);
	}

	vector<int> xsum(n+1);
	for (int i=1;i<=q;++i)
	{
		xsum[p[i]]+=x[i];
	}

	vector<int64_t> psum(n+1);
	psum[0]=0;
	calc(1,0,tree,xsum,psum);

	bool initial=true;
	for (int i=1;i<=n;++i)
	{
		if (initial!=false)
		{
			initial=false;
		}
		else
		{
			cout << " ";
		}
		cout << psum[i];
	}
	cout << endl;


}

int calc(int node,int node_from,vector<vector<int>> &tree,vector<int> &xsum,vector<int64_t> &psum)
{
	psum[node]=psum[node_from]+xsum[node];
	for (int i=0;i<tree[node].size();++i)
	{
		if (tree[node][i]==node_from)
		{
			continue;
		}
		calc(tree[node][i],node,tree,xsum,psum);
	}
	return 0;
}









Measured memory_bytes: 35124
import math

#n = int(input())
n, k = [int(i) for i in input().split()]
#table = [[i for i in input().split()] for n in range(h)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#s = input()
#list = list(s)

#s = [int(input()) for i in range(m)] #m行1列入力

if (k == 1) :
    kotae = 0
else :
    kotae = n - k

print(kotae)

Measured memory_bytes: 2940
import Data.List.Split
import Data.List

getMultipleInt :: IO [Int]
getMultipleInt = getLine >>= \x -> (return . (map read)) $ splitOn " " x

ans :: Int -> [Int] -> Int
ans s [] = 0
ans s [d] = if s == d then 1 else 0
ans s d@(z:zs) = if s >= x then 1 + (ans (s-x) xs) else 0
    where
        sorted@(x:xs) = sort d

main = do
    first <- getMultipleInt
    dat <- getMultipleInt
    putStrLn . show $ ans (first !! 1) dat

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

	int x[101], y[101], a[101];
	scanf("%d%d%d", &x[0], &y[0], &a[0]); //初期値
	int xs = 0, ys = 0, xf = x[0], yf = y[0];
    int f=0;

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

		if (a[i] == 1 && xs < x[i]) xs = x[i];
		else if (a[i] == 2 && xf > x[i]) xf = x[i];
		else  if (a[i] == 3 && ys < y[i]) ys = y[i];
		else if (a[i] == 4 && yf > y[i]) yf = y[i];
	}
	int safe_area = (xf - xs) * (yf - ys);
    if((xf - xs)>0&&(yf - ys)>0) f=1;
	if(safe_area>0&&f==1) printf("%d\n", safe_area);
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v;
  v.resize(m + 1, 0);
  for (int y = 0; y < n; ++y) {
    int k;
    cin >> k;
    for (int x = 0; x < k; ++x) {
      int f;
      cin >> f;
      v[f]++;
    }
  }
  int ret = count_if(v.begin(), v.end(), [n](int v) { return v == n; });
  cout << ret << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(N):
  if A[i] == 1:
    loc = i
    break
#print(loc) #locは0index

left = loc
right = N-(loc+1)

ans = left//(K-1) + right//(K-1)
nokori = left%(K-1) + 1 + right%(K-1)
#print(ans,nokori)
if nokori == 1:
  ans += 0
elif nokori <= K:
  ans += 1
else:
  ans += 2
print(ans) 


Measured memory_bytes: 83116
#include<stdio.h>
typedef long long int int64;
const int mod=1000000007;
int comb(int n,int k){
  int res=1;
  int inv[31];
  inv[1]=1;
  int i;
  for(i=1;i<=k;i++){
    if(i>=2) inv[i]=mod-(int64)(mod/i)*inv[mod%i]%mod;
    res=(int64)res*(n+1-i)%mod*inv[i]%mod;
  }
  return res;
}
void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int ans=1;
  int k;
  for(k=2;k*k<=m;k++){
    if(m%k==0){
      int c=0;
      while(m%k==0){
	c++;
	m/=k;
      }
      ans=(int64)ans*comb(n-1+c,c)%mod;
    }
  }
  if(m>1) ans=(int64)ans*comb(n-1+1,1)%mod;
  printf("%d\n",ans);
}
int main(void){
  run();
  return 0;
}

Measured memory_bytes: 1708
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,x;
    int cnt=0;
    cin>>a>>b>>c>>x;
    for(int i=a;i>=0;i--)
        for(int j=b;j>=0;j--)
            for(int k=c;k>=0;k--)
                if(x==(i*500+j*100+k*50))cnt++;

    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
monster_num = int(input())
monster_hp_list = list(map(int, input().split(' ')))

while True:
    min_val = min(monster_hp_list)
    monster_hp_list = [i % min_val for i in monster_hp_list if i % min_val != 0]
    monster_hp_list.append(min_val)
    if len(monster_hp_list) == 1:
        break

print(monster_hp_list[0])


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

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

Measured memory_bytes: 256
sx, sy, tx, ty = map(int,input().split())

print("U"*(ty-sy) + "R"*(tx-sx) + "D"*(ty-sy) + "L"*(tx-sx) + "L" + "U"*(ty-sy+1) + "R"*(tx-sx+1) + "D" + "R" + "D"*(ty-sy+1) + "L"*(tx-sx+1) + "U")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int n,a,b,c,x;
	int arry[1024];
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a >> b >> c;

		if(a > c){
			x = c;
			c = a;
			a = x;
		}
		if(b > c){
			x = c;
			c = b;
			b = x;
		}

		if(a*a + b*b == c*c){
			arry[i] = 1; 
			}
		else
			arry[i] = 0;
	}
	for(int i=0;i<n;i++){
		if(arry[i]==1){
			cout << "YES" << endl;
		}
		else if(arry[i]==0)
			cout << "NO" << endl;
		}

	return 0;
}

Measured memory_bytes: 0
import math
n,d=map(int,input().split())
count=0
for i in range(n):
  x,y=map(int,input().split())
  p=math.ceil(math.pow(x,2)+math.pow(y,2))
  r=math.ceil(math.sqrt(p))
  if(r<=d):
    count+=1
print(count)


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

int main(void) {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    ll n, m;
    cin >> n >> m;
    vector<ll> arr (n);
    ll sum = 0;
    for (ll i = 0; i < n; i++) {
        cin >> arr[i];
        sum = sum + arr[i];
    }

    double th = ((double)sum)/(4.0 * m);

    ll count = 0;
    for (auto &x: arr) {
        if (x >= th) {
            count++;
        }
    }

    if (count >= m) {
        cout << "Yes";
    } else {
        cout << "No";
    }



    
    return 0;
}

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

int x[90001],y[90001];
int ans[90001];

inline int my_abs(int input){
    if(input < 0){
        input = -input;
    }
    return input;
}

int main() {

    int h,w,d;

    cin >> h >> w >> d;

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            int a;
            cin >> a;
            x[a] = j; y[a] = i;
        }
    }

    for(int i=d+1; i<=h*w; i++){
        ans[i] = ans[i-d] + my_abs(x[i] - x[i-d]) + my_abs(y[i] - y[i-d]);
    }

    int q;

    cin >> q;

    while(q--){
        int l,r;

        cin >> l >> r;

        cout << ans[r] - ans[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

const int S = 5000;
int dp[S+10][S+10];

ll mod_pow(ll x, ll n) {
    if(n == 0) return 1;
    ll res = mod_pow((x * x) % MOD, n / 2);
    if(n & 1) res = (res * x) % MOD;
    return res;
}

signed main() {
    int N; cin >> N;
    string s; cin >> s;
    int len = s.length();

    dp[0][0] = 1;
    rep(i,0,N) repq(j,0,S) {
        // add
        (dp[i+1][j+1] += dp[i][j] * 2) %= MOD;

        // delete
        (dp[i+1][max(0LL, j-1)] += dp[i][j]) %= MOD;
    }

    int pw = mod_pow(2, len);
    cout << ( dp[N][len] * mod_pow(pw, MOD-2) ) % MOD << endl;
    return 0;
}

Measured memory_bytes: 195968
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define mod (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int gcd(int A,int B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
  ld l;
  cin>>l;
  cout<<fixed<<setprecision(16);
  cout<<(l/3)*(l/3)*(l/3);
  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
//#define int long long
#define mod 1000000007
#define fi first
#define se second
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll ;
typedef vector<int>vi ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
int main()
{
	fast;
	ll k;
	cin>>k;
	scan();
	vi v;
	ll sum=0;
	for(ll i=0;i<n-1;i++)
	{
		v.pb(a[i+1]-a[i]);
		
	}
	v.pb(k-a[n-1]+a[0]);
	
	ll max=0;
	for(ll i=0;i<v.size();i++){
		if(v[i]>max)
			max=v[i];
	}
	cout<<k-max;
	
	return 0;
}

Measured memory_bytes: 2168
#include <stdio.h>

int main(void){
	int x, y;
	while(1){
		scanf("%d %d", &x, &y);
		if (x == 0 && y == 0) break;
		if (y < x) printf("%d %d\n", y, x);
		else printf("%d %d\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    int n,k,i,j,ans,co;
    co=0;
    cin>>n>>k;
    char a[n];
    rep(i,n){
      cin>>a[i];
    }
    ans=0;
   rep(i,n-1){
     if(a[i]=='R'&&a[i+1]=='R'){
         ans++;
     }
   }
   for(i=n-1;i>0;i--){
     if(a[i]=='L'&&a[i-1]=='L'){
         ans++;
     }
   }
   for(i=0;i<n-1;i++){
       if(a[i]=='L'&&a[i+1]=='R'){
        co++;
       }
       if(a[i]=='R'&&a[i+1]=='L'){
        co++;
       }
   }
   cout<<min(n-1,ans+2*k)<<endl;
}


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

int main(){
	int x,y;
	cin >> x >> y;
	
	while(x > 0 || y > 0){
	  if(x < y){
	      cout << x << " " << y << endl;
	  }else if(x > y){
	      cout << y << " " << x << endl;
	  }else if(x == y){
          cout << x << " " << y << endl;
      }
      cin >> x >> y;  
	}
	return 0;
}


Measured memory_bytes: 3004
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
char s1[1111];
int s[4];
int i, j, k, l;
int main()
{
	while (~scanf("%s", s1))
	{
		memset(s, 0, sizeof(s));
		l = strlen(s1);
		for (int i = 0; i < l; i++)
		{
			if (s1[i] == 'N'&&s[1] == 0)
				s[1] = 1;
			if (s1[i] == 'S'&&s[1] == 0)
				s[1] = 2;
			if (s1[i] == 'N'&&s[1] == 2)
				s[1] = 3;
			if (s1[i] == 'S'&&s[1] == 1)
				s[1] = 3;
			if (s1[i] == 'E'&&s[2] == 0)
				s[2] = 1;
			if (s1[i] == 'W'&&s[2] == 0)
				s[2] = 2;
			if (s1[i] == 'E'&&s[2] == 2)
				s[2] = 3;
			if (s1[i] == 'W'&&s[2] == 1)
				s[2] = 3;
		}
		if ((s[1] == 3 || s[1] == 0) && (s[2] == 3 || s[2] == 0))
			puts("Yes");
		else
			puts("No");

	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define rep(i, n) for(int i = 0;i < (int)(n); i++)

using namespace std;


int main() {
    int a,b;
    cin >> a >> b;
    if(a % 3 == 0 || b %3 == 0 || (a + b)%3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
package main

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

const INFINITY = math.MaxInt64/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	m := stdin.ReadInt()
	a := stdin.ReadIntSlice(m)

	sum := 0
	for _, v := range a {
		sum += v
	}

	if sum <= n {
		stdout.Println(n - sum)
	} else {
		stdout.Println(-1)
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}


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

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String[] args){
        int N;
        long X;
        {long[] a = in.ll(); N = (int)a[0]; X = a[1];}
        
        out.println(count(N, X));
        out.flush();
    }

    static long count(int n, long x){
        long b1 = 1L<<n;
        long b2 = b1<<1;
        
        //out.printf("count(%d, %d)\n", n, x);
        
        return n == 0 ? 1 :
               x == 1 ? 0 : 
               x < b2-1 ? count(n-1, x-1) :
               x == b2-1 ? b1 :
               count(n-1, x+1-b2)+b1;
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 21332
#include<stdio.h>
int main(){
  int x,y;
  int n;
  for(n = 0;n < 3000;n++){
    scanf("%d %d",&x, &y);
    if (x == 0 && y == 0) break;
    else if (x < y){
      printf("%d %d\n",x, y);
    }else if(x > y){
      printf("%d %d\n",y, x);
    }else if(x == y){
      printf("%d %d\n",x, y);
    }
  }
  return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  string s;
  cin >> s;
  string t = "";
  rep(i,(int)s.length()-1) {
    if (s[i] == 'B' && s[i+1] == 'C') {
      t += "D";
      i++;
    }
    else t += s[i];
  }
  debug(t);
  ll ans = 0, cnt = 0;
  for (int i = t.length()-1; i >= 0; --i) {
    if (t[i] == 'D') cnt++;
    else if (t[i] == 'A') { //右にあるDの数だけ移動できる。
      ans += cnt;
    }
    else cnt = 0; //B,Cならカウンタをリセット
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 916
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <numeric>
using namespace std;

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

	vector<int> score(n,0);
	
	for (int i = 0; i < n-1; i++)
	{
		int p;
		cin >> p;
		score[p-1]++;
	}
	
	for (auto a : score)
	{
		cout << a << endl;
	}

	return 0;
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
using namespace std;
constexpr int MAXN = 1e5 + 7;
inline long long read()
{
	char c=getchar();long long flag=1,ans=0;;
	while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return (ans*flag);
}
int mark[MAXN];
int main() {
    int n = read(), m = read();
    memset(mark, 0, sizeof(mark));
    int AC = 0, WA = 0;
    for(int i = 0; i < m; ++ i) {
        int input = read();
        string str;
        cin >> str;
        if(str == "AC") {
            if(mark[input] != -1) {
                WA += mark[input];
                AC ++;
                mark[input] = -1;
            } 
        } else if(str == "WA") {
            if(mark[input] != -1) {
                mark[input] ++;
            }
        }
    }
    cout << AC << " " << WA << endl;
    // system("pause");
}

Measured memory_bytes: 640
//Edit distance

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

#define MAX 1000

string s,t;
int dp[MAX+1][MAX+1];

int d(int i,int j){
	if(s[i]==t[j]) return 0;
	else return 1;
}

int main(){
	cin>>s>>t;
	for(int i=0;i<=s.size();++i) for(int j=0;j<=t.size();++j){
		if(i==0||j==0){
			dp[i][j]=max(i,j);
			continue;
		}
		dp[i][j]=min(min(dp[i-1][j],dp[i][j-1])+1,dp[i-1][j-1]+d(i-1,j-1));
	}
	cout<<dp[s.size()][t.size()]<<endl;
}

Measured memory_bytes: 7056
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int N=1e6;
int n,q,sum=0;
int a[N+10],fa[N*2+10];
int Getf(int x) {
    return (fa[x]==x)?x:fa[x]=Getf(fa[x]);
}
int main() {
    scanf("%d",&n);
    for (int i=1;i<n;i++) scanf("%d",&a[i]);
    for (int i=0;i<=N*2;i++) fa[i]=i;
    for (int i=n-1;i>=3;sum+=a[i],i--)
        for (int j=sum;j<sum+a[i];j++)
            fa[Getf(j)]=Getf((sum+a[i])*2-j);
    scanf("%d",&q);
    while (q--) {
        int x;
        scanf("%d",&x);
        printf("%d ",(x<=sum?Getf(x):x)-sum+a[1]-a[2]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int main(){
    ll n,m; cin >> n >> m;
    ll num = m/n;
    ll ans;
    while(num!=0){
        if(m%num==0){
            ans = num;
            break;
        }
        num--;
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
 
#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)
 
#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)
 
typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)
 
#define S_RTN(S)  s_cout(S);return 0
 
 
#define _itoa(A,N) sprintf(A, "%d", N);
 
int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);
 
int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);
 
 
int s_asorts(const void* a, const void* b);
 
//昇順
int s_asorts(const void* a, const void* b) {
    return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
    return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
    return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
    int i;
    rept(i, 0, n) {
        l_cin2(*(a + i), *(b + i));
    }
    return 0;
}
int i_cins(int n, int* a) {
    int i;
    for (i = 0; i < n; i++) {
        i_cin(*(a + i));
    }
 
    return 0;
}
int _gcd(int a, int b) {
    int r, tmp;
    if (a < b) { tmp = a; a = b; b = tmp; }
    r = a % b;
    while (r) {
        if (!r) break;
        a = b; b = r;
        r = a % b;
    }
    return(b);
}
 
long _max(long a, long b) {
    return a > b ? a : b;
}
long _min(long a, long b) {
    return a < b ? a : b;
}
int _swp(int* a, int* b)
{
    int tmp;
    tmp = *b; *b = *a; *a = tmp;
    return 0;
}


int main(){
    
    int N;
    int min=200001;
    i_cin(N);
    int a[N];
    int cnt=0;
    rept(i,0,N){
        i_cin(a[i]);
    }
    rept(j,0,N){
        if(a[j]<min){
            cnt++;
            min=a[j];
        }
    }
    i_cout(cnt);
    
    
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[100],n,x=1;
	a[0]=2;
    cin>>n;
    for(int i=1;i<100;i++)
    	a[i]=a[i-1]*2;
    if(n==1)
    	cout<<x<<endl;
    for(int i=0;i<100;i++)
    {
    	if(a[i]<=n && a[i+1]>n)
    	{
    		cout<<a[i]<<endl;
    		break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
x = int(input())
for a in range(1000):
    for b in range(1000):
        if a ** 5 + b ** 5 == x:
            print('{} {}'.format(a, -b))
            exit()
        elif a ** 5 - b ** 5 == x:
            print('{} {}'.format(a, b))
            exit()

Measured memory_bytes: 9176
#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a, &b, &c);
	if(a<=b){
		if(b<=c)
			printf("%d %d %d\n",a ,b ,c);
		else if(a<=c)
			printf("%d %d %d\n",a ,c ,b);
		else
			printf("%d %d %d\n",c ,a ,b);
	}
	else{
		if(c<=b)
			printf("%d %d %d\n",c ,b ,a);
		else if(c<=a)
			printf("%d %d %d\n",b, c, a);
		else
			printf("%d %d %d\n",b ,a ,c);
	}
	return 0;
}

Measured memory_bytes: 596
<?php
fscanf(STDIN, "%d %d %d %d", $a, $b, $c, $d);
$e = lcm($c, $d);
$x1 = intdiv($b, $e);
$x2 = intdiv($b, $c);
$x3 = intdiv($b, $d);
$y1 = intdiv($a - 1, $e);
$y2 = intdiv($a - 1, $c);
$y3 = intdiv($a - 1, $d);
$ans = $b - ($a - 1) - ($x2 + $x3 - $x1 - ($y2 + $y3 - $y1));
echo $ans;

//最大公約数
function gcd($m, $n){
    if($n > $m) list($m, $n) = array($n, $m);
     
    while($n !== 0){
        $tmp_n = $n;
        $n = $m % $n;
        $m = $tmp_n;
    }
    return $m;
}
 
//最小公倍数
function lcm($m, $n){
    return $m * $n / gcd($m, $n);
}


Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define pb push_back
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fst first
#define snd second
#define mset(a,v) memset((a),(v),sizeof(a))
using namespace std;
typedef long long ll;
const int N=200500;
vector<int> g[N];
const ll mod=1e9+7;
int sum(int a, int b){
	a+=b;
	if(a>=mod)a-=mod;
	return a;
}
ll mul(ll a, ll b){
	return (a*b)%mod;
}
int dp[N][2],n;
int f(int x, int p, int c){
	if(SZ(g[x])==1&&g[x][0]==p)return 1;
	int &r=dp[x][c];
	if(r!=-1)return r;
	r=1;
	for(int y:g[x]){
		if(y==p)continue;
		int s=f(y,x,0);
		if(c==0)s=sum(s,f(y,x,1));
		r=mul(r,s);
	}
	return r;
}
int main(){FIN;
	cin>>n;
	fore(i,1,n){
		int x,y;cin>>x>>y;
		x--;y--;
		g[x].pb(y);
		g[y].pb(x);
	}
	memset(dp,-1,sizeof dp);
	cout<<sum(f(0,-1,0),f(0,-1,1))<<"\n";
}

Measured memory_bytes: 16640
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let s = sc.chars();
    let mut r: i64 = 0;
    let mut g: i64 = 0;
    let mut b: i64 = 0;
    for i in 0..n {
        match s[i] {
            'R' => r += 1,
            'G' => g += 1,
            'B' => b += 1,
            _ => {}
        }
    }
    let mut ex: i64 = 0;
    for i in 0..n {
        for j in i + 1..n {
            let k = 2 * j - i;
            if k >= n {
                continue;
            }
            let mut v: Vec<char> = vec![s[i], s[j], s[k]];
            v.sort();
            if v == vec!['B', 'G', 'R'] {
                ex += 1;
            }
        }
    }
    println!("{}", r * g * b - ex);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 2172
import java.util.*;

public class Main {
	static long sum=0;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		// String→long 変換
		long n = Long.parseLong(s);
		
		// nの桁数を求める
		int digit = String.valueOf(n).length();
		
		calc(n,digit,0);
		
		System.out.println(sum);
	}
	
	static void calc(long n, int digit, long tmp_sum) {
		if(digit==1) {
			sum += (tmp_sum + n);
			return;
		}
		
		int real_digit = String.valueOf(n).length();
		
		calc((long)(n/Math.pow(10,(real_digit-digit+1))),
				digit-1,(long)(tmp_sum+n%Math.pow(10,(real_digit-digit+1))));
		calc(n,digit-1,tmp_sum);
	}
	
}


Measured memory_bytes: 21204
S = input()
T = input()

def count_string(strInput):
    tmp = {}
    for s in strInput:
        if s in tmp:
            tmp[s] += 1
        else:
            tmp[s] = 1
    
    re = [tmp[a] for a in tmp]
    re = sorted(re)
    return re

S_count = count_string(S)
T_count = count_string(T)

if S_count == T_count:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3632
from collections import deque, defaultdict
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(M)]
Q = int(input())
vdc = [list(map(int,input().split())) for i in range(Q)]
g = defaultdict(set)

for a,b in ab:
    g[a].add(b)
    g[b].add(a)
'''
from random import randint as ri
import networkx as nx
N,M = 10**5,10**5
g = nx.gnm_random_graph(N,M)
g = nx.to_dict_of_lists(g)
g = {v+1:[nv+1 for nv in g[v]] for v in g}
Q = 20**3
vdc = [[ri(1,N),ri(0,10),ri(1,10**5)] for i in range(Q)]
'''

def dpinit(ps, val=0):
    import copy
    res = [val for i in [0]*ps[-1]]
    for i in ps[:-1][::-1]:
        res = [copy.deepcopy(res) for k in [0]*i]
    return res

ans = [0]*(N+1)
visited = dpinit([N+1,11],False)

for v,d,c in vdc[::-1]:
    if visited[v][d]:
        continue
    for t in range(d+1):
        visited[v][t] = True
    if ans[v] == 0:
        ans[v] = c 
    vs = [v]
    for i in range(d-1,-1,-1):
        temp = []
        for pv in vs:
            for nv in g[pv]:
                if not visited[nv][i]:
                    for t in range(i+1):
                        visited[nv][t] = True
                    if ans[nv] == 0:
                        ans[nv] = c
                    temp.append(nv)
        vs = temp
 
for a in ans[1:]:
    print(a)


Measured memory_bytes: 176316
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        boolean ans = false;
        if(s.equals("hi")) ans = true;
        if(s.equals("hihi")) ans = true;
        if(s.equals("hihihi")) ans = true;
        if(s.equals("hihihihi")) ans = true;
        if(s.equals("hihihihihi")) ans = true;
        System.out.println(ans ? "Yes" : "No");
        sc.close();

    }

}


Measured memory_bytes: 23764
import itertools

n = int(input())
l = sorted(list(itertools.permutations([i for i in range(1,n+1)])))

al = tuple([int(i) for i in input().split()])
bl = tuple([int(i) for i in input().split()])


a,b = 0,0


if al == bl:
    print(0)
else:
    for idx,i in enumerate(l):
        if i == al:
            a = idx
        elif i == bl:
            b = idx
        else:
            pass
        
    print(abs(a-b))

Measured memory_bytes: 8308
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    string S;
    cin >> S;
    int now = 0;
    int ans = 0;
    for(auto e:S){
        if(e=='R')++now;
        else now = 0;

        ans=max(ans,now);
    }
    cout << ans << '\n';
}


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

int main() {
  
  string s;
  cin>>s;
  if(s.at(2)==s.at(3)&&s.at(4)==s.at(5)){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
  
 // cout << a+b+c <<" "<<s<< endl;
 // cout<<s;
}


Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c;
    
    cin >> a >> b >> c;
    if (a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if (c <= a && a <= b)
        cout << b << " " << a << " " << c << endl;
    else if (b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if(c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
    else
        cout << c << " " << b << " " << a << endl;
}
 


Measured memory_bytes: 3100
def N(a): #階乗 n!
    ans = 1
    for i in range(1,a+1):
        ans *= i
    return ans

def C(n,k): #組み合わせ nCk
    memo1 = N(n)
    memo2 = N(k)
    memo3 = N(n-k)
    return (memo1)//(memo2*memo3)


n = int(input())
a = list(map(int,input().split()))
a.sort()

ans = 0
aim = a[n-1]//2

if a[n-1]%2!=0:
    aim2 = a[n-1]//2+1
else:
    aim2 = a[n-1]//2

memo = abs(a[0]-aim)
memo2 = 0
for i in range(n-1):
    if abs(memo) > abs(a[i]-aim):
        memo = abs(a[i]-aim)
        memo2 = a[i]

memo = abs(a[0]-aim2)
memo3 = 0
for i in range(n-1):
    if abs(memo) > abs(a[i]-aim2):
        memo = abs(a[i]-aim2)
        memo3 = a[i]

if abs(memo2-aim) > abs(memo3-aim2):
    ans = memo3
else:
    ans = memo2



print(a[n-1],ans)

Measured memory_bytes: 14428
#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.at(i);
  }

  for ( int i = 0; i < W + 2; i++ ){
    cout << "#";
  }
  cout << endl;

  for ( int i = 0; i < H; i++ ){
    cout << "#" << vec.at(i) << "#" << endl;
  }
  
  for ( int i = 0; i < W + 2; i++ ){
    cout << "#";
  }
  
}

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

vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


signed main() {
	int n;
	cin >> n;

	vector<int> a(n);

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

	sort(a.begin(), a.end());
	vector<int> checkList = enum_div(a[0]);
	checkList.push_back(a[0]);
	vector<int> checkList2 = enum_div(a[1]);
	checkList.push_back(a[1]);

	checkList.insert(checkList.end(), checkList2.begin(), checkList2.end());

	int ans = -1;

	for (auto e : checkList) {
		int cnt = 0;
		for (int i = 0; i < n; ++i) {
			if (a[i] % e != 0) cnt++;
		}
		if (cnt <= 1) {
			ans = max(ans, e);
		}
	}

	cout << ans << endl;
}

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

int main(){
  int n;
  long int result = 0;
  
  cin >> n;
  vector<int> di(n);
  for(int i = 0; i < n; i++){
    cin >> di.at(i);
  }
  
  for(int i = 0; i < n; i++){
   for(int j = i+1; j < n; j++){
    result += di.at(i) * di.at(j); 
   }
  }
  
  cout << result << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int length = S.length();
        long sum = 0;
        for(int i=0;i<length;i++){
            for(int j=i+1;j<length+1;j++){
                int sum1 = 0;
                int sum2 = 0;
                if(j==length){
                    sum1=1;
                }else{
                    for(int k=0;k<length-j;k++){
                        sum1 += Kumi(length-j-1,k);
                    }
                }
                if(i==0){
                    sum2=1;
                }else{
                    for(int k=0;k<i;k++){
                        sum2 += Kumi(i-1,k);
                    }
                }
                sum += Long.parseLong(S.substring(i,j))*(sum1*sum2);
            }
        }
        
        System.out.println(sum);
    }
    static int Kumi(int n,int m){
        if(n==-1||n==0||m==0){
            return 1;
        }else{
            return factorial(n)/factorial(n-m)/factorial(m);
        }
    }
    
    
    static int factorial(int n){
        int fact = 1;
        if (n == 0)
            return  fact;
        else { // in case of n > 0
            for (int i = n; i > 0; i--)
                fact *= i;
            return fact;
        }
    }
}


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

using namespace std;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256