akhauriyash/Code-Regression huggingface dataset:
n=gets.to_i
we=gets.chomp
w=[0,0]
e=[0,0]

(0...n).each do |i|
  w[i+1]=w[i]
  e[i+1]=e[i]
  w[i+1]+=1 if we[i]==?W
  e[i+1]+=1 if we[i]==?E
end
e.shift
e << e[-1]
ans = Float::INFINITY
(0..n).each do |i|
  ans = [ans,w[i]+e[-1]-e[i]].min
end
p ans

Measured memory_bytes: 20352
import itertools
n = int(input())
p =[int(i) for i in input().split()]
q =[int(i) for i in input().split()]
a = 0
b = 0
cnt = 0
p1= p.copy()
p1.sort()
n_list = list(itertools.permutations(p1))
for i in n_list:
    if list(i)==p:
        a = cnt +1
    if list(i)==q:
        b = cnt +1
    cnt += 1
        
print(abs(a-b))
    

Measured memory_bytes: 8052
while (line = gets) do
  catch (:done) do
    h, w = line.split.map(&:to_i)
    break if h == 0 && w == 0

    diag = h*h + w*w
    start = h + 1
    while true do
      (start..diag).each do |e|
        v = Math.sqrt(diag - e*e)
        break if e >= v
        if v.to_i == v
          puts [e, v.to_i].join ' '
          throw :done
        end
      end
      diag += 1
      start = 1
    end
  end
end

Measured memory_bytes: 6128
import java.util.*;

public class Main {
    static Scanner sc=new Scanner(System.in);
    static int W;     //風呂敷が耐えられる重さ
    static int N;     //お宝の個数
    static int[] sw;  //各お宝の重さ
    static int[] sv;  //各お宝の価値
    static int[][] dp;//dp[i][j]:i番目の荷物まで見て重さの合計がjになる時の合計の価値の最大値
    public static void main(String[] args){
        int C=1;    //何ケース目か
        while(true){
            W=Integer.parseInt(sc.nextLine());
            if(W==0)break;  //W=0で終了
            N=Integer.parseInt(sc.nextLine());
            sw=new int[N+1];
            sv=new int[N+1];
            dp=new int[N+1][W+1];
            for(int i=1;i<=N;i++){
                String[] s=sc.nextLine().split(",");
                sv[i]=Integer.parseInt(s[0]);
                sw[i]=Integer.parseInt(s[1]);
            }
            solve(C);
            C++;
        }
        
    }
    static void solve(int C){
        int ans1=0;//価値の最大値
        int ans2=0;//価値が最大値を取るときの重さの合計の最小値
        for(int i=0;i<N;i++){
            for(int j=0;j<=W;j++){
                dp[i+1][j]=Math.max(dp[i][j], dp[i+1][j]);  //dp[i+1][j]の更新
                if(j+sw[i+1]<=W){
                    if(dp[i+1][j+sw[i+1]]<dp[i][j]+sv[i+1]){//i番目の荷物をぶちこむかどうか
                        dp[i+1][j+sw[i+1]]=dp[i][j]+sv[i+1];    //ぶちこむ
                        if(ans1<dp[i+1][j+sw[i+1]]){        //ans1を更新するか
                            ans1=dp[i+1][j+sw[i+1]];            //ans1の更新
                            ans2=j+sw[i+1];                     //ans2の更新
                        }else if(ans1==dp[i+1][j+sw[i+1]]){ //ans1が等しい場合
                            ans2=Math.min(ans2, j+sw[i+1]);     //ans2の更新
                        }
                    }
                }
            }
        }
        System.out.println("Case "+C+":");
        System.out.println(ans1);
        System.out.println(ans2);
    }
}

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

const int MOD = 1e9+7;
int add(int a, int b){return ((ll)a + (ll)b)%MOD;}
int mul(int a, int b){return ((ll)a * (ll)b)%MOD;}

void solve(){
  int n, m;
  cin >> n >> m;
  int taken = 0;
  for(int i = 0; i < m; i++){
    int a; cin >> a;
    taken += a;
  }

  if(n-taken >= 0){
    cout << n-taken << endl;
  }
  else{
    cout << -1 << endl;
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
typedef long long LL;
using namespace std;
LL n, a[10];
int main()
{
	scanf("%lld%lld%lld%lld", &a[1], &a[2], &a[3], &a[4]);
	scanf("%lld", &n);
	LL Min = min(a[1] * 4, min(a[2] * 2, a[3]));
	bool ok = 0;
	if(Min * 2 <= a[4]) ok = 1;
	if(n & 1){
		if(ok) printf("%lld\n", n * Min);
		else printf("%lld\n", ((n - 1) / 2) * a[4] + Min);
	}
	else {
		if(ok) printf("%lld\n", n * Min);
		else printf("%lld\n", (n / 2) * a[4]);
	}
}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
   int n;
   cin >> n;
   queue<string>que;
   que.push("a");
   int p = 2;
   rep(i, 2, n+1){
       rep(j, 1, p){
           string s = que.front();
           que.pop();
           int i2 = 0;
           rep(k, 0, s.size()){
               i2 = max(i2,s[k]-'a');
           }
           rep(k, 0, i2+2){
               char temp = k + 'a';
               que.push(s+temp);
           } 
       }
       p = que.size()+1;
   }
   while(!que.empty()){
       cout << que.front() << endl;
       que.pop();
   }
   return 0;
}

Measured memory_bytes: 7376
#include <stdio.h>
int main(void){
    long long int i,j,n,k,q,a[1000000],p[1000000];
    scanf("%lld", &n);
    scanf("%lld", &k);
    scanf("%lld", &q);
    for(i = 0;i < q;i ++){
        scanf("%lld", &a[i]);
    }
    for(i = 0;i < q;i ++){
        p[a[i] - 1] = p[a[i] - 1] + 1;
    }
    for(i = 0;i < n;i ++){
        if(q - p[i] < k){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    }
    return 0;
}

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

int main(void){
    int i,n,x[100],y[100];
    double p_1=0,p_2=0,p_3=0,p_0=0;

    scanf("%d",&n);
    
    for(i=0;i<n;i++)
        scanf("%d",&x[i]);
    for(i=0;i<n;i++)
        scanf("%d",&y[i]);
    
    for(i=0;i<n;i++){
        
    //p=1
        p_1 += abs(x[i]-y[i]);
    
    //p=2
        p_2 += pow(fabs((double)x[i]-y[i]),2.0);
    
    //p=3
        p_3 += pow(fabs((double)x[i]-y[i]),3.0);
    
    //p=endless
        if(p_0 < abs(x[i]-y[i])) p_0 = abs(x[i]-y[i]);
        
    }
    
    printf("%lf\n%lf\n%lf\n%lf\n", p_1, pow(p_2,1.0/2), pow(p_3,1.0/3), p_0);
    
    
    return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m ;
  
  vector<int> a(m);
  rep(i,m){
    cin >> a[i];
  }

  
  rep(i,m) {
    n = n - a[i];
  }

  if(n<0) {
    cout << -1 << endl;
  } else {
    cout << n << endl;
  }
  


}


Measured memory_bytes: 3668
# -*- coding: utf-8 -*-

import sys
import os
import math
import itertools

for s in sys.stdin:
    w = float(s)

    if w <= 48:
        print('light fly')
    elif w <= 51:
        print('fly')
    elif w <= 54:
        print('bantam')
    elif w <= 57:
        print('feather')
    elif w <= 60:
        print('light')
    elif w <= 64:
        print('light welter')
    elif w <= 69:
        print('welter')
    elif w <= 75:
        print('light middle')
    elif w <= 81:
        print('middle')
    elif w <= 91:
        print('light heavy')
    else:
        print('heavy')

Measured memory_bytes: 7564
#include <cstdio>

using namespace std;
long long n,m,x;
int main()
{
    scanf ("%lld %lld", &n, &m);
    if ((1LL*n*2)>=m)
        printf ("%lld", (1LL*m/2));
    else
    {
        x=0LL+m+1LL*2*n;
        x=1LL*x/4;
        printf ("%lld", x);
    }
    return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<int> A(N);
	map<LL, LL> m;
	REP(i, N){
		int a;
		cin >> a;
		A[i] = a;
		m[a - i]++;
	}

	LL ret = 0;
	REP(i, N){
		ret += m[-A[i] - i];
	}
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 26224
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
int n, a[123456], b[123456], c[123456];
int dp[10][123456];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[1][0] = a[0];
	dp[2][0] = b[0];
	dp[3][0] = c[0];
	for (int i = 1; i < n; i++) {
		dp[1][i] = max(dp[2][i - 1], dp[3][i - 1]) + a[i];
		dp[2][i] = max(dp[3][i - 1], dp[1][i - 1]) + b[i];
		dp[3][i] = max(dp[1][i - 1], dp[2][i - 1]) + c[i];
	}
	cout << max(dp[1][n - 1], max(dp[2][n - 1], dp[3][n - 1])) << endl;
}

Measured memory_bytes: 7424
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int w = sc.nextInt();
		int h = sc.nextInt();
		while(w != 0 && h != 0){
			int sx = -1;
			int sy = -1;
			int[][] tile = new int[h][w];
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					tile[i][j] = sc.nextInt();
					if(tile[i][j] == 2){
						sy = i;
						sx = j;
					}
				}
			}
			System.out.println(func(tile, sx, sy, 1));
			w = sc.nextInt();
			h = sc.nextInt();
		}
		
		sc.close();
	}
	static int func(int[][] tile, int x, int y, int n){
		if(n > 10){
			return -1;
		}
		int[] mx = {0, 0, 1,-1};
		int[] my = {1,-1, 0, 0};
		int res = -1;
		for(int i = 0; i < 4; i++){
			int tx = x + mx[i];
			int ty = y + my[i];
			if(tx >= 0 && tx < tile[0].length && ty >= 0 && ty < tile.length && tile[ty][tx] != 1){
				while(tx >= 0 && tx < tile[0].length && ty >= 0 && ty < tile.length){
					if(tile[ty][tx] == 3){
						return n;
					}
					if(tile[ty][tx] == 1){
						tile[ty][tx] = 0;
						int tmp = func(tile, tx - mx[i], ty - my[i], n + 1);
						if(res == -1 || res > tmp && tmp != -1){
							res = tmp;
						}
						tile[ty][tx] = 1;
						break;
					}
					tx = tx + mx[i];
					ty = ty + my[i];
				}
			}
		}
		return res;
	}
}

Measured memory_bytes: 62308
N = input().split()

A = int(N[0])
B = int(N[1])
T = int(N[2])

count = T // A
 # T / A だと小数点まで求めてしまうため、この問題では使いにくい。
 # //を使うことで小数点以下を切り捨てることができる

ans = count * B

if ans == 0:
    print("0")
else:
    print(ans)

Measured memory_bytes: 3060
/*
[tenka1-2018] E - Equilateral
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int N = 300;

int H, W;
bool s[N][N];
int cnt[2][3 * N + 1][3 * N + 1];

bool is_in(int i, int j) { return 0 <= i && i < H && 0 <= j && j < W; }

ll solve() {
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (!s[i][j]) {
                continue;
            }
            for (int d = 1; is_in(i + d, j + d); d++) {
                if (!s[i + d][j + d]) {
                    continue;
                }
                cnt[0][i + d + 1 + N][j - d + 1 + N]++;
                cnt[0][i + 2 * d + N][j + N]--;
                cnt[0][i - d + 1 + N][j + d + 1 + N]++;
                cnt[0][i + N][j + 2 * d + N]--;
            }
            for (int d = 1; is_in(i - d, j + d); d++) {
                if (!s[i - d][j + d]) {
                    continue;
                }
                cnt[1][i + d + N][j + d + N]++;
                cnt[1][i - 1 + N][j + 2 * d + 1 + N]--;
                cnt[1][i - d + N][j - d + N]++;
                cnt[1][i - 2 * d - 1 + N][j + 1 + N]--;
            }
        }
    }

    for (int i = 1; i < 3 * N; i++) {
        for (int j = 1; j < 3 * N; j++) {
            cnt[0][i][j] += cnt[0][i - 1][j - 1];
        }
    }
    for (int i = 3 * N - 2; i >= 0; i--) {
        for (int j = 1; j < 3 * N; j++) {
            cnt[1][i][j] += cnt[1][i + 1][j - 1];
        }
    }

    ll ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j]) {
                ans += cnt[0][i + N][j + N] + cnt[1][i + N][j + N];
            }
        }
    }

    return ans;
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        string row;
        cin >> row;
        for (int j = 0; j < W; j++) {
            s[i][j] = (row[j] == '#');
        }
    }

    cout << solve() << endl;

    return 0;
}


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

signed main() {
    int N, K;

    cin >> N >> K;
    vector<int>A(N);
    rep (i, N) {
        cin >> A[i];
    }

    rep (k, K) {
        vector<int>B(N+1);
        rep (i, N) {
            int s = max(0, i-A[i]);
            int l = min(i + A[i] + 1, N);
            B[s]++; B[l]--;
        }
        rep (i, N) B[i+1] += B[i];
        B.pop_back();
        if (A == B) break;
        A = B;
    }
    rep (i, N) {
        cout << A[i];
        if (i != N) cout << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 4824
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine().Split().Select(int.Parse).ToArray();

        WriteLine(Max(0, Abs(n[1] - n[2]) - n[0]));
    }
}


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

int A, B, T;

int main(){
  cin >> A >> B >> T;
  cout << (T / A) * B << endl;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    bool ans = false;
    double check = double(sum) / (4*double(m));

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int cnt = 0;

    for(int i=0; i<m; i++) {
        if(a[i] >= check) cnt++;
    }

    if(cnt == m) ans = true;

    if(ans) puts("Yes");
    else puts("No");
}

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

class Cube {
  public:
    int f[6];
    Cube() {}
    void roll_z() { roll(1, 2, 4, 3); }
    void roll_y() { roll(0, 2, 5, 3); }
    void roll_x() { roll(0, 1, 5, 4); }
    void roll(int i, int j, int k, int l) {
        int t = f[i];
        f[i] = f[j];
        f[j] = f[k];
        f[k] = f[l];
        f[l] = t;
    }
};

int getRight(Cube c1, int f1, int f2) {
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 4; j++) {
            if (c1.f[0] == f1 && c1.f[1] == f2) {
                return c1.f[2];
            }
            c1.roll_z();
        }
        if (i % 2 == 0) {
            c1.roll_y();
        } else {
            c1.roll_x();
        }
    }
    return -1;
}

int main(int argc, char const *argv[]) {
    Cube c;
    int f1, f2;

    for (int i = 0; i < 6; i++) {
        cin >> c.f[i];
    }
    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        cin >> f1 >> f2;
        cout << getRight(c, f1, f2) << endl;
    }

    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define ll long long
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;


int main()
{
    FAST
    ll n;cin>>n;
    cout<<(1000-n%1000)%1000<<endl;
}


Measured memory_bytes: 3648
def myAnswer(S:list)->str:
   if(S.pop(0) !="A"): return "WA"
   flag = False
   for n,s in enumerate(S):
      if(n>=1 and n <= len(S)-2 and flag==False and s=="C"):
         flag = True
      else:
         if(s.isupper()):
            return "WA"
   return "WA" if(flag==False) else "AC"


def modelAnswer():
   tmp=1
def main():
   S = list(input())
   print(myAnswer(S))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    L=[0,1,2,3,4,5,6,7,8,9,'A', 'B', 'C','D','E','F']

    x,y=map(str,input().split())
    if L.index(x)==L.index(y):
        print('=')
    elif L.index(x)>L.index(y):
        print('>')
    else:
        print('<')

    
resolve()

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

int main() {
  int A, B;
  cin >> A >> B;

  cout << A*B << endl;
  return 0;
}


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

int main(){
    /*
    D:距離
    T:時間
    S:速さ

    移動時間t = D/S
    */

   double D;
   double T;
   double S;

   cin >> D >> T >> S;

   double t = D / S;

   //cout << t << endl;

   if (t < T)
   {
       cout << "Yes" << endl;
   }
   else if (t == T)
   {
       cout << "Yes" << endl;
   }
   else
   {
       cout << "No" << endl;
   }
   
   
   
   
   
}

Measured memory_bytes: 3624
#include<iostream>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=10000000000000LL;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,M,K=1,C;
ll A,B,W;
ll T,a,b;
double v[55],D[55],Q,l,r;
ll ans=0;
//bool D[100005];
ll S[50][50]={};
string str1[55],str2="abcdefghijklmnopqrstuvwxyz";
map<string,int> m;

int main(){
	cin>>N;

	while(1){
		ans+=K;
		if(ans>=N)break;
		K++;
	}
	cout<<K<<endl;
	return 0;
}


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


def main():
    # Failed to predict input format
    sp = input()
    t = input()
    ans = "~" * len(sp)
    for i in range(len(sp) - len(t) + 1):
        is_ok = True
        for k in range(len(t)):
            if sp[i + k] != "?" and t[k] != sp[i + k]:
                is_ok = False
                break
        if not is_ok:
            continue
        s = list(sp)
        s[i:i + len(t)] = list(t)
        ans = min(ans, "".join(sc if sc != "?" else "a" for sc in s))
    if ans[0] == "~":
        print("UNRESTORABLE")
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int a, b, c;
int main() {
	cin >> a >> b >> c;
	cout << (2 * b == a + c ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
// Problem : C - ThREE
// Contest : AtCoder - Social Infrastructure Information Systems Division, Hitachi Programming Contest 2020
// URL : https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long
#define N 2000005

int n, col[N], ans[N];
vi g[N], one, two, zero;

void dfs(int u, int par){
    for(auto i : g[u]){
        if(i != par && col[i] == -1){
            col[i] = col[u]^1;
            dfs(i,u);
        }
    }
}

void solve(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    for(int i=1;i<=n;i++){
        if(i%3 == 1) one.pb(i);
        else if(i%3 == 2) two.pb(i);
        else zero.pb(i);
    }
    memset(col,-1,sizeof(col));
    col[1] = 0;
    dfs(1,0);
    int x = n/3, w=0, b=0;
    for(int i=1;i<=n;i++){
        if(col[i]) w++;
        else b++;
    }
    if(b>w){
        swap(b,w);
        for(int i=1;i<=n;i++) col[i] ^= 1;
    }
    if(b<=x){
        for(int i=1;i<=n;i++){
            if(col[i] == 0) ans[i] = zero.back(), zero.pop_back();
            else{
                if(!one.empty()) ans[i] = one.back(), one.pop_back();
                else if(!two.empty()) ans[i] = two.back(), two.pop_back();
                else ans[i] = zero.back(), zero.pop_back();
            }
        }
    } else {
        for(int i=1;i<=n;i++){
            if(col[i] == 0 && !one.empty()) ans[i] = one.back(), one.pop_back();
            else if(col[i] == 1 && !two.empty()) ans[i] = two.back(), two.pop_back();
            else ans[i] = zero.back(), zero.pop_back();
        }
    }
    for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int t;
    //cin>>t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 80492
#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<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define rep(i, n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) cout << setfill('0') << setw(len) << right << a << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

signed main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int dx = x2 - x1, dy = y2 - y1;
    int x3, y3, x4, y4;
    x3 = x2 - dy;
    y3 = y2 + dx;
    x4 = x1 - dy;
    y4 = y1 + dx;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int a[n],i,j,k;
    for(i=0;i<n;i++) cin>>a[i];
    k=abs(a[1]-a[0]);
    for(i=0;i<n;i++)
      for(j=i+1;j<n;j++)
	k=min(k,abs(a[i]-a[j]));
    cout<<k<<endl;
  }
  return 0;
}

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

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() {
    int s, before = -1;
    cin >> s;
    map<int, int> mii;
    while (mii.size() != before) {
        before = mii.size();
        mii[s]++;
        s = s % 2 == 0 ? (s / 2) : (3 * s + 1);
    }
    cout << mii.size() + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    int dx[]={-1,-1,0,1,1,1,0,-1};
    int dy[]={0,1,1,1,0,-1,-1,-1};

    class P{
	int x,y;
	P(int y,int x){
	    this.x=x;
	    this.y=y;
	}
    }
    void run(){
	Scanner sc=new Scanner(System.in);
	int w,h;
	int [][] map;
	while(true){
	    LinkedList<P> queue=new LinkedList<P>();
	    w=sc.nextInt();
	    h=sc.nextInt();
	    if((w|h)==0)break;
	    map=new int[h+2][w+2];
	    for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
		    map[i][j]=sc.nextInt();
		}
	    }
	    int ans=0;
	    for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
		
		    if(map[i][j]==1){
			queue.offer(new P(i,j));
			map[i][j]=0;
			ans++;
		    }
		    while(!queue.isEmpty()){
			P p=queue.poll();    
			for(int k=0;k<8;k++){
			    int ny=p.y+dy[k];
			    int nx=p.x+dx[k];
			    if(map[ny][nx]==1){
				queue.offer(new P(ny,nx));
				map[ny][nx]=0;
			    }
			}
		    }
		}
	    }
	    System.out.println(ans);
	}
    }
    public static void main(String[] args){
	new Main().run();
    }
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  int S, W;
  cin >> S >> W;
  
  if( S <= W ) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

Measured memory_bytes: 3556
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		if(M%2==1){
			Console.WriteLine("-1");
		} else {
			int[,]A = new int[M,2];
			var list = new List<int>[N];
			var listN = new List<int>[N];
			var listT = new List<int>[N];
			int[]P = new int[N];
			int[]PN = new int[N];
			for(var i=0;i<N;i++){
				list[i] = new List<int>();
				listN[i] = new List<int>();
				listT[i] = new List<int>();
			}
			int[]F = new int[M];
			int[]C = new int[N];
			for(var i=0;i<M;i++){
				string[] str2 = Console.ReadLine().Split();
				A[i,0] = int.Parse(str2[0]);
				A[i,1] = int.Parse(str2[1]);
				list[A[i,0]-1].Add(A[i,1]-1);
				list[A[i,1]-1].Add(A[i,0]-1);
				listN[A[i,0]-1].Add(i);
				listN[A[i,1]-1].Add(i);
			}
          	for(var i=0;i<M;i++){
				C[A[i,0]-1]++;
            }
			var listi = new List<int>();
			int[]FC = new int[N];
			listi.Add(0);
			FC[0] = 1;
			P[0] = -1;
			PN[0] = -1;
			while(listi.Count>0){
				var list2 = new List<int>(listi);
				listi.Clear();
				for(var i=0;i<list2.Count;i++){
					var i1 = list2[i];
					for(var j=0;j<list[i1].Count;j++){
						var j1 = list[i1][j];
						if(FC[j1]==0){
							listT[i1].Add(j1);
							P[j1] = i1;
							PN[j1] = listN[i1][j];
							FC[j1]=1;
                          	listi.Add(j1);
						}
					}
				}
			}
			var listd = new List<int>();
			for(var i=0;i<N;i++){
				if(listT[i].Count==0){
					listd.Add(i);
				}
			}
            //for(var i=0;i<listd.Count;i++){
            //  	Console.Error.Write(listd[i]+" ");
            //}
			int[]FD = new int[N];
			while(listd.Count>0){
				var list2 = new List<int>(listd);
				listd.Clear();
				for(var i=0;i<list2.Count;i++){
					var i1 = list2[i];
					if(P[i1] >= 0){
                      	//if(A[PN[i1],0]==i1){
                       // if(C[i1]%2==1){
						//	F[PN[i1]]=1;
                        //  	C[PN[i1]++;
						//}
                        //} else {
						if(C[i1]%2==1){
							F[PN[i1]]=1;
                          	C[P[i1]]++;
                          	C[i1]--;
						}
                        //}
						int pi = P[list2[i]];
						FD[pi]++;
						if(FD[pi]==listT[pi].Count){
							listd.Add(pi);
						}
					}
				}
			}
            //for(var i=0;i<M;i++){
            //  	Console.Error.Write(F[i]+" ");
            //}
			for(var i=0;i<M;i++){
				if(F[i]==1){
					Console.WriteLine(A[i,1]+" "+A[i,0]);
				} else {
					Console.WriteLine(A[i,0]+" "+A[i,1]);
				}
			}
		}
	}
}

Measured memory_bytes: 52284
#include<stdio.h>
int main(){
 int s,m,h;
 m = 0;
 h = 0;
 int i = 0;
 int j = 0;
 scanf("%d",&s);
 while (s>=60) {
   s-=60;
   i+=1;
  }
 m=i;
 while (m>=60) {
  m-=60;
  j+=1;
 }
 h=j;
 printf("%d:%d:%d\n",h,m,s);
 return 0;
}


Measured memory_bytes: 2676
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;



int main(){
  int N,M; cin>>N>>M;
  vector <int> num(N+1);

  if(N==1 and M==0){
    cout<<0<<endl;
    return 0;
  }


  for(int i=1;i<=N;i++) num[i] = 10;

   num[1] = 11;

  for(int i=1;i<=M;i++){
    int s,c; cin>>s>>c;

    if(num[s] > 9){

      num[s] = c;

      continue;

    }  

    if(num[s] == c) continue;
    
    
    else {

      cout<<-1<<endl;
      return 0;
    }

  }

  
  
  
  if(num[1] == 0 and N==1) {
    cout<<0<<endl;
    return 0;
  }




  if(num[1] == 0) {
    cout<<-1<<endl;
      return 0;

  }






  for(int i=1;i<=N;i++){
    if(num[i] ==11){
      num[i] = 1;
      continue;
    }
    if(num[i] > 9){
      num[i] = 0;
    }
  }





  for(int i=1;i<=N;i++){
    cout<<num[i];
  }
  cout<<endl;

  return 0;
 



}


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

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	const int m = n * 3;
	vector<ll> a(m);
	for(int i = 0; i < m; ++i){ cin >> a[i]; }
	sort(a.begin(), a.end());
	ll sum = 0;
	for(int i = n; i < m; i += 2){
		sum += a[i];
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
using namespace std;
int n;
char x;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
	    cin>>x;
		if(x=='Y') 
		{
			cout<<"Four";
			return 0;
		}
	}
	cout<<"Three";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr(a,b,c) for(int a=b;a<c;a++)
using namespace std;
typedef long long ll;

string board[301];
int can[301];
int n;
int main(){
	cin>>n;
	int ans=0;
	fr(i,0,n)cin>>board[i];
	fr(DI,0,n){
		fr(dt,0,n){
			//if(board[(dt+i)%n][dt])
			can[dt]=n;
			fr(tr,0,n){
				if(board[(tr+dt+DI)%n][(dt)%n]!=board[(dt+DI)%n][(tr+dt)%n]){
					can[dt]=tr;
					break;
				}	
			}
		}
		
		fr(dt,0,n){
			//if(board[(dt+i)%n][dt])
			int rnd = 1;
			fr(tr,0,n){
				if(can[(dt+tr)%n]<n-tr)rnd=0;
			}
			ans+=rnd;
		}
	}
	cout<<ans<<endl;
}

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

int main(){
  int n, p;
  string s;
  cin >> n >> p >> s;

  if (10 % p == 0) {
    ll res = 0;
    for (int i = 0; i < n; i++) {
      if ((s[i] - '0') % p == 0) res += i + 1;
    }
    cout << res << endl;
    return 0;
  }

  vector<int> cum(n+1,0);
  int now = 1;
  for (int i = n-1; i >= 0; i--) {
    int d = s[i] - '0';
    (d *= now) %= p;
    (cum[i] = cum[i + 1] + d) %= p;
    (now *= 10) %= p;
  }

  ll res = 0;

  vector<int> cnt(p,0);

  for (int i = n; i >= 0; i--) {
    res += cnt[cum[i]];
    cnt[cum[i]]++;
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 1412
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
using namespace std;

using ll = long long;
int main() {

	ll K;
	cin >> K;
	for (int n = 50; n >= 2; n--) {
		vector<ll> ans(n);
		for (int i = 0; i < n; i++) {
			ans[i] = n - 1+ -K + (n + 1) * (K / n);
		}
		for (int i = 0; i < K%n; i++) {
			ans[i] += n + 1;
		}
		bool ok = true;
		for (int i = 0; i < n; i++)if (ans[i] < 0)ok = false;
		if (!ok)continue;
		cout << n << endl;
		for (int i = 0; i < n; i++) {
			cout << ans[i] << " ";
		}
		cout << endl;
		return 0;
	}
}



Measured memory_bytes: 256
n=int(input())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
dp=[[0 for i in range(3)] for j in range(n+1)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if k ==j:continue
            dp[i+1][j]=max(dp[i][k]+a[i][j],dp[i+1][j])
ans=max(dp[n][i] for i in range(3))
print(ans)


Measured memory_bytes: 47320
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  string s;cin>>s;
  int n=s.size();
  
  int ans=0;
  int i=0;
  while(i+1<s.size()){
    if(s[i]!=s[i+1]){
      s.erase(s.begin()+i+1);
      s.erase(s.begin()+i);
      ans++;
      if(i>0)i--;
    }else{
      i++;
    }
  }
  cout(ans*2);
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  char c[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << c[i][j];
    }
    cout << '\n';
    for (int j = 0; j < w; j++) {
      cout << c[i][j];
    }
    cout << '\n';
  }
  return 0;
}


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

using ll = long long int;


int main(){
    ll n, T;
    cin >> n >> T;
    vector<ll> t(n);
    for(int i=0;i<n;i++){
        cin >> t[i];
    }
    t.push_back(1LL<<31);
    ll ans = 0;
    for(int i=0;i<n;i++){
        ans += min(t[i+1]-t[i], T);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

const int mod = 1e9 + 7;

int n;
vector<vector<int>> arr, dp;


int solve(int idx, int mask){
    if(idx == n - 1){
        int cnt = 0;
        for(int i = 0; i < n; i++){
            if((mask & (1 << i)) && arr[idx][i]){
                cnt++;
            }
        }
        return cnt;
    }
    if(dp[idx][mask] != -1) return dp[idx][mask];
    int res = 0;
    for(int i = 0; i < n; i++){
        if((mask & (1 << i)) && arr[idx][i]){
            res = (res + solve(idx+1, mask ^ (1 << i))) % mod;
        }
    }
    return dp[idx][mask] = res;
}

int main(){
    cin>>n;
    arr.resize(n, vector<int>(n, 0));
    dp.resize(n, vector<int>(1 << n, -1));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin>>arr[i][j];
        }
    }
    int mask = (1 << n) - 1;
    int res = solve(0, mask);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 180608
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
ll h[110000];
ll dp[110000];
//-----------------------------------------
int main(void){
    ll N,K;cin>>N>>K;
    REP(i,110000)dp[i]=INF;dp[0]=0;
    REP(i,N)cin>>h[i];
    REP(i,N){
        FORS(j,i+1,i+K){
            dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
        }
    }
    cout<<dp[N-1]<<"\n";
}

Measured memory_bytes: 5236
#include <iostream>
#include <cstdio>
#include <math.h>

using namespace std;

int main(void){
    int n;
    int x;
    cin>>n;
    for(int i=1;i<=n;i++){
        x=i;
        if(i%3==0){
            cout<<" "<<i;
        }
        else{
            while(1){
                if(x==0){
                    break;
                }
                else if(x%10==3){
                    cout<<" "<<i;
                    break;
                }
                x/=10;
            }
        }

    }
    cout<<endl;
   
    return 0;
}


Measured memory_bytes: 3116
N = int(input())
D = list(map(int, input().split()))
M = [0]*N
for d in D: M[d]+=1

if D[0]!=0 or M[0]!=1:
    print(0)
    exit()

ans = 1
mod = 998244353
for i in range(1,N):
    ans *= (M[i-1]**M[i])
    ans %= mod

print(ans)

Measured memory_bytes: 14396
def pnj(a):
    i = 2
    while i*i <= a:
        if a%i == 0:
            return False
        i += 1
    return True

n = int(input())
i, c = 0, 0

while n > i:
    a = int(input())
    if pnj(a):
        c += 1
    i += 1

print(c)



Measured memory_bytes: 5612
class MaxHeap:
    def __init__(self):
        self.heap = []
        self.length = 0

    def __str__(self):
        return " " + " ".join(str(n) for n in self.heap)

    def up_insert(self, key):
        self.heap.append(key)
        self._upheap()
        self.length += 1

    def down_insert(self, key):
        self.heap.append(key)
        self.length += 1
        for i in range(self.length // 2, -1, -1):
            self._downheap(i)

    def down_many_insert(self, key):
        self.heap.extend(key)
        self.length += len(key)
        for i in range(self.length // 2, -1, -1):
            self._downheap(i)


    def _upheap(self):
        index = self.length - 1
        while True:
            parent_index = (index - 1) // 2
            if parent_index < 0 or self.heap[parent_index] >= self.heap[index]:
                break
            self.heap[parent_index], self.heap[index] = self.heap[index], self.heap[parent_index]
            index = parent_index

    def _downheap(self, index):
        while True:
            child_index_left, child_index_right = index * 2 + 1, index * 2 + 2
            # print(index, child_index_left, child_index_right)
            if child_index_left >= self.length:
                break
            elif (child_index_right >= self.length or self.heap[child_index_left] > self.heap[child_index_right]) and self.heap[index] < self.heap[child_index_left]:
                self.heap[index], self.heap[child_index_left] = self.heap[child_index_left], self.heap[index]
                index = child_index_left
            elif (child_index_right < self.length and self.heap[child_index_left] < self.heap[child_index_right]) and self.heap[index] < self.heap[child_index_right]:
                self.heap[index], self.heap[child_index_right] = self.heap[child_index_right], self.heap[index]
                index = child_index_right
            else:
                break



a = MaxHeap()
length = int(input())
t = [int(n) for n in input().split(" ")]
a.down_many_insert(t)
print(a)



Measured memory_bytes: 67596
n = int(input())
R_list = [int(input()) for i in range(n)]

R_i = 10**10
R_t = -10**10
for R_j in R_list:
    R_t = max(R_t, R_j - R_i)
    if R_j < R_i:
        R_i = R_j
print(R_t)


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

int main(){
    int N;
    int K;

    int i;
    int di;
    int r;
    int dk;
    int result = 0;

    int flag[101] = {0};


    cin >> N >> K;
    for(i=0; i<K; i++){
        cin >> di;
        for(r=0; r<di; r++){
            cin >> dk;
            flag[dk] = 1;
        }
    }
    for(i=1; i<N+1; i++){
        if(flag[i] == 0){
            //cout << i << endl;
            result ++;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(1 << N);
	
	int res = 0;
	for (int i = 0; i < (1 << N); i++) {
		cin >> A[i];
	}
	vector<int> dp1(1 << N, A[0]);
	vector<int> dp2(1 << N, -1);
	for (int mask = 0; mask < (1 << N); mask++) {
		for (int i = mask; i > 0; i = (i - 1)&mask) {
			if (dp1[mask] < A[i]) {
				dp2[mask] = dp1[mask];
				dp1[mask] = A[i];
			}
			else {
				if (dp2[mask] < A[i]) {
					dp2[mask] = A[i];
				}
			}
		}
	}
	res = 0;
	for (int i = 1; i < (1 << N); i++) {
		res = max(res, (dp1[i] + dp2[i]));
		cout << res << endl;
	}
}

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

int c(long a, long b){
  int r = 0, cnt = 0;
  while(a){
    r++;
    a /= 10;
  }
  while(b){
    cnt++;
    b /= 10;
  }
  return max(r, cnt);
}

int main(){
  long n;  cin >> n;
  int ans = 1e9;
  long start = 1;
  while(start*start <= n)  start++;

  while(start--){
    if(n % start == 0){
      ans = min(ans, c(start, n/start));
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3504
// skyrim belongs to the nords
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back 
#define sz(a) ((int)(a).size())
#define rep(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define dec(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end() 
#define LOGN 18
#define EPS 1e-8
#define fcin ios_base::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

bool loc[100005];
int main(){
	fcin;
	cin.tie(0);
	int N, l, r, ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> l >> r;
		for (int j = l; j <= r; j++) {
			if (!loc[j]) ans++;
			loc[j] = true;
		}
	}
	cout << ans;
	return 0;
}
 

Measured memory_bytes: 384
#include<string>
#include<iostream>
#include<deque>
#include<cstdlib>
#include<algorithm>
using namespace std;
using ulli = long long int;

int main() {
    int n, m;
    cin >> n >> m;
    deque<ulli> cards;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        cards.push_back(temp);
    }
    sort(cards.begin(), cards.end());
    deque<pair<int, ulli>> bc;
    for (int i = 0; i < m; i++) {
        int b;
        ulli c;
        cin >> b >> c;
        bc.emplace_back(make_pair(b, c));
    }
    sort(bc.begin(), bc.end(), [](auto const& lhs, auto const& rhs) { return lhs.second > rhs.second; });
    ulli res = 0;
    deque<ulli>::iterator p=cards.begin();

    while (!bc.empty() && bc.front().second > *p && p!=cards.end()) {
        *p = bc.front().second;
        bc.front().first--;
        p++;
        if (bc.front().first == 0) {
            bc.pop_front();
        }
    }
    while (!cards.empty()) {
        res += cards.front();
        cards.pop_front();
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5632
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}	
double x[10],y[10];
int order[10];	
signed main(){
	ic(n)
	rep(0,i,n)cin>>x[i]>>y[i];
	rep(0,i,n)order[i]=i;
	double ans=0;
	int sum=0;
	do{
		rep(1,i,n){
			ans+=sqrt(pow(x[order[i]]-x[order[i-1]],2)+pow(y[order[i]]-y[order[i-1]],2));
		}	
		sum++;
	}while(next_permutation(order,order+n));
	double d=ans/sum;
	printf("%.12f\n",d);
}	

Measured memory_bytes: 256
n = int(input())
l = []
for i in range(n):
  l.append(input())
if len(l) != len(set(l)):
  print("No")
  exit()
hip = l[0][-1]
for i in range(1,n):
  if hip != l[i][0]:
    print("No")
    exit()
  else:
    hip = l[i][-1]
print("Yes")

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

int main() {
  int cnt;
  string color;
  bool yflg = false;
  
  cin >> cnt;
  for(int i = 0; i < cnt; i++) {
    cin >> color;
    if(color == "Y") {
		yflg = true;
    }
  }
  if(yflg) {
    cout << "Four" << endl;
  }
  else {
  	cout << "Three" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pr pair<int,int>
#define mp make_pair
#define pb push_back
const int MAXN =1e6 + 5;
const ll INF = 0x3f3f3f3f3f3f3f;
const ll mod =1e9 + 7;
int main()
{
    int n;
    cin>>n;
    int ans = 0;
    for(int m = 1;m <=n;m+=2)
    {
        int tmp = 0;
        for(int i = 1;i<=m;i++)
        {
            if(m % i == 0) tmp++;
        }
        if(tmp == 8) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n, m, l = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
B = [list(map(int, input().split())) for _ in range(m)]

for i in range(n):
    ans = [str(sum([A[i][k] * B[k][j] for k in range(m)])) for j in range(l)]
    print(' '.join(ans))



Measured memory_bytes: 6304
#include <iostream>

using namespace std;
int main()
{
int waktu_skrg, waktu_nambah, total;
cin>>waktu_skrg;
cin>>waktu_nambah;

if (0<=waktu_skrg<=23 && 0<=waktu_nambah<=23){
total = (waktu_skrg + waktu_nambah)%24;
cout<<total<<endl;
}



return 0;
}


Measured memory_bytes: 256