akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int a[3][3];
  REP(i, 3) {
	REP(j, 3) {
	  cin >> a[i][j];
	}
  }
  bool flg[3][3] = { };
  int n;
  cin >> n;
  REP(k, n) {
	int b;
	cin >> b;
	REP(i, 3) {
	  REP(j, 3) {
		if (a[i][j] == b) {
			flg[i][j] = true;
		  }
	  }
	}
  }
  bool ans = false;
  REP(i, 3) {
	if (flg[i][0] && flg[i][1] && flg[i][2]) {
		ans = true;
	  }
  }
  REP(j, 3) {
	if (flg[0][j] && flg[1][j] && flg[2][j]) {
		ans = true;
	  }
  }
  if (flg[0][0] && flg[1][1] && flg[2][2]) {
	  ans = true;
	}
  if (flg[0][2] && flg[1][1] && flg[2][0]) {
	  ans = true;
	}
  if (ans) {
	  cout << "Yes" << endl;
	} else {
	  cout << "No" << endl;
	}
  return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

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

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

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;
    }
}


Measured memory_bytes: 256
N, M = map(int, input().split())

in_min = 1
in_max = N

for i in range(M):
	l, r = map(int, input().split())
	# 最小値(今の最小値と取得値のうち、大きいほう)
	in_min = max([in_min, l])
	# 最大値(今の最大値と取得値のうち、小さいほう)
	in_max = min([in_max, r])

# 個数を出力
if(in_max < in_min):
	# 最小値が大きくなった場合は、通らない
	print(0)
else:
	cnt = in_max - in_min +1
	print(cnt)

Measured memory_bytes: 3060
#include <stdio.h>
int main(){
	int n,m,l;
	int i,j,k;
	int a[110][110];
	int b[110][110];
	long long c[110][110]={0};
	scanf("%d %d %d",&n,&m,&l);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			scanf("%d",&b[i][j]);
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			for(k=0;k<m;k++){
				c[i][j]+=a[i][k]*b[k][j];
			}
			if(j!=0) printf(" ");
			printf("%ld",c[i][j]);
		}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll f(ll n) {return n * (n - 1) / 2;}
int main()
  {int N; cin >> N;
  vector<ll> A(N), cs(N + 1); for (auto &a: A) {cin >> a; ++cs[a];}
  ll s = 0; for (auto c : cs) s += f(c);
  for (auto a : A) cout << s - f(cs[a]) + f(cs[a] - 1) << endl;}

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

int main() {
  
  int n;
  cin >> n;
  vector<int> v(n);
  int ans = 0;
  
  for(int i=0;i<n;i++){
    cin >> v.at(i);
    ans +=v.at(i);
  }
  
  sort(v.begin(),v.end());
  int i=0;
  while(ans % 10 ==0  && i<n){
    if(v.at(i) % 10 != 0)
      ans-= v.at(i);
    i++;
  }
  
  if(i==n)
    cout << 0;
  else 
   cout << ans;
    
}


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

const int MAX = 1000000;
const int MOD = 1000000007;

vector<int64_t> fac(MAX), finv(MAX), inv(MAX);

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


int64_t COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit();
  int X,Y;
  cin>>X>>Y;
  int s,t;
  if(2*X-Y<0 || 2*Y-X<0 || (2*X-Y)%3!=0 || (2*Y-X)%3!=0) cout<<0<<endl;
  else{
    s=(2*X-Y)/3,t=(2*Y-X)/3;
    cout<<COM(s+t,s)%MOD<<endl;
  }
}

Measured memory_bytes: 25728
//=====================================================================================================================================//
//Al_Qatil 
#include <bits/stdc++.h>
//g++ code.cpp -o /x
using namespace std;
#define ll long long
using ii=tuple<ll, ll>;
#define pb push_back
#define For(i,n) for(ll  i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(a,b,c) for(ll a=b;a<c;a++)
#define M 1000000007
#define vi vector<ll> 
#define vvi vector<vi>
#define int long long
#define rl(t) ll t;cin>>t;
#define rs(t) string t;cin>>t;

//=====================================================================================================================================//
//set <ll> :: iterator itr;
// if (b.find(a[i]) != b.end())
//Multiset
//multiset<int, greater<int>> h;
//auto it = h.lower_bound(x);
//if (it == h.end()) cout << "-1\n";
// priority queue .. queue in des order  :-> priority_queue<tuple<int, bool>> q;
const int N = 2e5 + 10, inf = 1e9 + 42;
//=====================================================================================================================================//
int knapSack(int W, int wt[], int val[], int n) 
{ 
   int i, w; 
   int K[n+1][W+1]; 
  
   // Build table K[][] in bottom up manner 
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 
signed main() 
{   
    fast;
    ll n,w;
    cin>>n>>w;
    ll a[n],v[n];
    For(i,n)cin>>a[i]>>v[i];
    cout<<knapSack(w,a,v,n)<<endl;
}

//======================================================================================================================================//

Measured memory_bytes: 79232
#include<stdio.h>

#define MAX 2001

int n,res;

int solve(int i, int m, int *A) {
  

  if( m  == 0 ) {
    return 1;
  }
  if( i >= n ) {
    return 0;
  }
  
  res = solve( i+1 , m, A) || solve( i+1 , m - A[i] ,A);
  return res;
}

int main(char args[]){
  
  int q,A[MAX],m[MAX],i;
  
  // input
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);   
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);   
  }
  
  // compute
  for(i=0;i<q;i++){
    res = solve(0 ,m[i],A);
    if(res) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

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

int main() {
	string s;
	cin >> s;
	if (s[0] == s[1])cout << "Bad" << endl;
	else if (s[1] == s[2])cout << "Bad" << endl;
	else if (s[2] == s[3])cout << "Bad" << endl;
	else cout << "Good" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		sc.close();

		int area1 = A * B;
		int area2 = C * D;

		System.out.println((area1 > area2)? area1 : area2);
	}

}


Measured memory_bytes: 23764
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int contestNumber = sc.nextInt();
        int mod = contestNumber % 111;
        if(mod == 0){
            System.out.println(contestNumber);
            return ;
        }
        int n = contestNumber / 111;
        System.out.println(111 * (n + 1));
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    c -= b;
    while (a > 0 && c > 0) {
        a -= d;
        c -= b;
    }
    if (a <= 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
import numpy as np
n, m, q = [int(item) for item in input().split(" ")]
# n, m, q = [int(item) for item in lines[0].split(" ")]

end = np.zeros((m,2),dtype=int)
query = np.zeros((q,2),dtype=int)
for i in range(m):
    end[i] = [int(item) for item in input().split(" ")]
#     end[i] = [int(item) for item in lines[1+i].split(" ")]

for i in range(q):
    query[i] = [int(item) for item in input().split(" ")]
#     query[i] = [int(item) for item in lines[1+m+i].split(" ")]

a = np.zeros((n,n), dtype=int)
np.add.at(a, [end[:,0]-1,end[:,1]-1], 1)
b = np.cumsum(a[::-1,:], axis=0)[::-1,:]
c = np.cumsum(b, axis=1)

result = c[query[:,0]-1, query[:,1]-1]
for i in range(q):
    print(result[i])
# for item in query:
#     print(c[item[0]-1, item[1]-1])
    # print(np.sum(a[(item[0]-1):, :item[1]]))

Measured memory_bytes: 25764
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
b = 0
for i in a:
    b ^= i

for i in range(n):
    a[i] ^= b

print(*a)

Measured memory_bytes: 31296
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vi a(n);
    double mean = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        mean += a[i];
    }
    mean /= n;
    double mini = INF;
    int ret     = 0;
    for (int i = n; i >= 0; --i) {
        if (mini >= abs(mean - a[i])) {
            mini = abs(mean - a[i]);
            ret  = i;
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
# AOJ 0066 Tic Tac Toe
# Python3 2018.6.15 bal4u

arr = [[0 for r in range(3)] for c in range(3)]
koma = { 'o':1, 'x':-1, 's':0 }

while True:
	try: a = list(input())
	except: break
	for i in range(len(a)): arr[i//3][i%3] = koma[a[i]]

	end = False
	for r in range(3):
		d = 0;
		for c in range(3): d += arr[r][c]
		if d == 3 or d == -3:
			end = True
			break
	
	if not end:
		for c in range(3):
			d = 0;
			for r in range(3): d += arr[r][c];
			if d == 3 or d == -3:
				end = True
				break

	if not end:
		d = arr[0][0]+arr[1][1]+arr[2][2]
		if d == 3 or d == -3: end = True
	if not end:
		d = arr[0][2]+arr[1][1]+arr[2][0]

	if d == 3: print('o')
	elif d == -3: print('x')
	else: print('d')


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

class RangeAddQuery {
public:
	vector<long long>bit; int size__;

	void initialize(int size_) {
		size__ = size_;
		bit.resize(size_ + 4, 0);
	}
	int size() {
		return size__;
	}
	void Add(int p, int x) {
		p++;
		while (p < size__ + 4) { bit[p] += x; p += (p&-p); }
	}
	long long Sum(int p) {
		long long s = 0; p++;
		while (p >= 1) { s += bit[p]; p -= (p&-p); }
		return s;
	}
	void add(int l, int r, int x) {
		// Add x in range [l, r)
		Add(l, x); Add(r, -x);
	}
	long long get(int pos) {
		return Sum(pos);
	}
};

long long N, Q, a[200009], b[200009], c[200009];
int main() {
	cin >> N >> Q;
	RangeAddQuery R1, R2; R1.initialize(N + 1); R2.initialize(N + 1);
	for (int i = 1; i <= N; i++) { R1.add(i, i + 1, i); R2.add(i, i + 1, i); }
	for (int i = 1; i <= Q; i++) { cin >> a[i] >> b[i] >> c[i]; }
	for (int i = Q; i >= 1; i--) {
		if (b[i] == 1) {
			int L = 1, R = N + 1, M, maxn = -1;
			for (int j = 0; j < 20; j++) {
				M = (L + R) / 2;
				if (R1.get(M) <= a[i]) { maxn = max(maxn, M); L = M; }
				else { R = M; }
			}
			R2.add(1, maxn + 1, -c[i] * 2);
		}
		else {
			int L = 1, R = N + 1, M, maxn = 999999;
			for (int j = 0; j < 20; j++) {
				M = (L + R) / 2;
				if (R2.get(M) > a[i]) { maxn = min(maxn, M); R = M; }
				else { L = M; }
			}
			R1.add(maxn, N + 1, c[i] * 2);
		}
		//for (int i = 1; i <= N; i++)cout << (R1.get(i) - R2.get(i)) / 2 << " "; cout << endl;
	}
	for (int i = 1; i <= N; i++)cout << (R1.get(i) - R2.get(i)) / 2 << endl;
	return 0;
}

Measured memory_bytes: 10760
n = int(input())
a = [-1] + list(map(int, input().split()))

# dp[i] = (i+1)日目終了時点での金額の最大値
# dp[i+1] = max(dp[i], {dp[j] % a[k] + (dp[j] // a[k]) * a[l] | j<k<l<=i})
dp = [0] * (n + 1)
dp[0] = dp[1] = 1000
dp[2] = max(dp[0] % a[1] + (dp[0] // a[1]) * a[2], dp[1])

# print(a)
# print(dp)

for i in range(1, n + 1):
    cand = dp[i - 1]
    for j in range(i):
        for k in range(j + 1, i):
            for l in range(k + 1, i + 1):
                cand = max(cand, dp[j] % a[k] + (dp[j] // a[k]) * a[l])
    dp[i] = cand

print(dp[n])


Measured memory_bytes: 73288
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        x: usize,
        t: usize
    };

    let y = n % x;
    let mut m = n / x;
    if y != 0 {
        m += 1;
    }

    println!("{}", m * t);
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define PB push_back
#define MP make_pair
// #define F first
// #define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

vector<ll> fac(200005); //n!(mod M)
vector<ll> ifac(200005); //k!^{M-2} (mod M)


ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll n, ll a){ //aCb(mod M)
    if(n == 0 && a == 0)return 1;
    if(n < a || n < 0)return 0;
    ll tmp = ifac[a-1]* fac[a] % MOD;
    return tmp;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    fac[0] = 1;
    ifac[0] = n;
    FOR(i,0,200005) {
        fac[i+1] = fac[i]*mpow(i+1, MOD-2) % MOD;
        ifac[i+1] = ifac[i]*(n-i-1) % MOD;
    }

    ll ans = (mpow(2,n)-1)%MOD;
    ans = (ans-comb(n,a)+MOD) % MOD;
    ans = (ans-comb(n,b)+MOD) % MOD;
    cout << ans << endl;

    // ll ans = ((mpow(2,n) - comb(n,a))%MOD - comb(n,b) - 1)%MOD;
    // if (ans < 0) cout << MOD-ans << endl;
    // else cout << ans << endl;
}

Measured memory_bytes: 3328
def main():
    rc = S.count("R")
    gc = S.count("G")
    bc = S.count("B")
    ns = 0
    for i in range(N-2):
        for k in range(i+2, N):
            if (i+k)%2 == 0 and S[i] != S[k]:
                j = (i+k)//2
                ns += 1 if S[j] != S[i] and S[j] != S[k] else 0
    print(rc*gc*bc - ns)


if __name__ == "__main__":
    N = int(input())
    S = input()
    main()


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

using namespace std;

int main() {
    int k,n;
    cin>>k>>n;
    int* arr=new int[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int ans=arr[n-1]-arr[0];
    for(int i=1;i<n;i++){
        int tans=k-arr[i];
        tans=tans+arr[i-1];
        if(tans<ans){
            ans=tans;
        }
    }
    cout<<ans;
    return 0;
}

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

using namespace std;
#define int long long

const int N = 2e5 + 5;
int a[N], n;
 
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n; 
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector <int> b(n + 1);
    for(int i = 1; i <= n; i++)
        b[i] = b[i-1] + a[i-1];
    int r = 1e18;
    for(int i = 2; i <= n - 2; i++) {
        int ls = b[i], rs = b[n] - b[i];
        for(int lls : {
                *prev(upper_bound(b.begin(), b.begin()+i+1, ls/2)),
                *lower_bound(b.begin(), b.begin()+i+1, ls/2),
                })
        for(int rls : {
                *prev(upper_bound(b.begin()+i+1, b.end(), ls + rs/2)) - ls,
                *lower_bound(b.begin()+i+1, b.end(), ls + rs/2) - ls,
                }) {
            int lrs = ls - lls;
            int rrs = rs - rls;
 
            int mx = max(max(lls, lrs), max(rls, rrs));
            int mn = min(min(lls, lrs), min(rls, rrs));
 
            r = min(r, mx-mn);
        }
    }
    cout << r << endl;
    return 0;
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> vec(M);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        vec[i] = {a, b};
    }
    sort(vec.begin(), vec.end(), [](pair<int, int> a, pair<int, int> b){
        return a.second < b.second;
    });

    int ans = 0;
    int cur = 0;
    for (int i = 0; i < M; i++) {
        if (vec[i].first < cur) continue;
        ans ++;
        cur = vec[i].second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n,Y = map(int, input().split())

for x in range(n+1):
  for y in range(n+1):
    z = n-x-y
    if z < 0: continue
    if 10000*x + 5000*y + 1000*z == Y:
      print(x,y,z)
      exit()
print(-1,-1,-1)

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

int main(){
  int n;
  cin >> n;
  
  vector<int> a(n);
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  
  int max_length = *max_element(a.begin(), a.end());
  if(max_length < sum - max_length)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[100][100];

int prim(void);

int main() {
	int i, j, e;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &e);
			if (e == -1) {
				M[i][j] = INT_MAX;
			}
			else {
				M[i][j] = e;
			}
		}
	}
	printf("%d\n", prim());
	return 0;
}

int prim(void) {
	int u, minv, i, v, sum = 0;
	int d[100], p[100], color[100];
	for (i = 0; i < 100; i++) {
		d[i] = INT_MAX;
		p[i] = -1;
		color[i] = WHITE;
	}
	d[0] = 0;
	while (1) {
		minv = INT_MAX;
		u = -1;
		for (i = 0; i < n; i++) {
			if (minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
		if (u == -1) {
			break;
		}
		color[u] = BLACK;
		for (v = 0; v < n; v++) {
			if (color[v] != BLACK && M[u][v] != INT_MAX) {
				if (d[v] > M[u][v]) {
					d[v] = M[u][v];
					p[v] = u;
					color[v] = GRAY;
				}
			}
		}
	}
	for (i = 0; i < n; i++) {
		if (p[i] != -1) {
			sum += M[i][p[i]];
		}
	}
	return sum;
}



Measured memory_bytes: 2048
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))

heapq.heapify(A)

for _ in range(M):
    p = -heapq.heappop(A)
    tmp = p // 2
    heapq.heappush(A, -tmp)

print(-sum(A))


Measured memory_bytes: 20484
k,n = input().split()
k = int(k)
n = int(n)

l = list(map(int, input().split()))
m = [0]*n
count = 0

for i in range(n-1):
    m[count] = l[i+1] - l[i]
    count+=1
m[n-1] = k - l[n-1]+ l[0]

print(k - max(m))


Measured memory_bytes: 26444
import sys, heapq, math

input = sys.stdin.readline
N = int(input())
SC = []
for _ in range(N):
    S, C = input().split()
    SC.append((S, int(C)))

nodes = dict()
nodes['S'] = []
for s, c in SC:
    for i in range(len(s)+1):
        nodes['L'+s[i:]] = []
        nodes['R'+s[-i::-1]] = []
for node in nodes.keys():
    for s, c in SC:
        if node[0] == 'L':
            if s[::-1].startswith(node[1:]):
                nodes[node].append(('R' + s[-len(node)::-1], c))
            elif node[1:].startswith(s[::-1]):
                nodes[node].append(('L' + node[1 + len(s):], c))
        elif node[0] == 'R':
            if s.startswith(node[1:]):
                nodes[node].append(('L' + s[len(node)-1:], c))
            elif node[1:].startswith(s):
                nodes[node].append(('R' + node[1 + len(s):], c))
for s, c in SC:
    nodes['S'].append(('L' + s, c))
    nodes['S'].append(('R' + s[::-1], c))
nodes['L'] = [('G', 0)]
nodes['R'] = [('G', 0)]
for node in nodes.keys():
    if len(node) != 1 and node[1:]==node[1:][::-1]:
        nodes[node].append(('G', 0))

HQ = [(0, 'S')]
heapq.heapify(HQ)
ans = -1
while len(HQ)>0:
    c, node = heapq.heappop(HQ)
    if node == 'G':
        ans = c
        break
    for node_, c_ in nodes[node]:
        heapq.heappush(HQ, (c+c_, node_))
    nodes[node] = []

print(ans)

Measured memory_bytes: 74628
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(v)";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  return solve(n,a);
}

function solve(n,a){
  var cost = xArray(0,n,n);
  for(var i = 0; i < n; i++)cost[0][i] = a[i];
  for(var i = 1; i < n; i++)for(var j = 0; j < n-i; j++){
    cost[i][j] = cost[i-1][j] + cost[0][i+j];
  }
  var dp = xArray(1e15,n,n);
  dp[0] = xArray(0,n);
  for(var i = 1; i < n; i++)
  for(var j = 0; j < n-i; j++)
  for(var k = 1; k <= i; k++){
    var t = dp[i-k][j] + dp[k-1][i-k+j+1] + cost[i][j];
    if(t < dp[i][j])dp[i][j] = t;
  }
  return dp[n-1][0];
}

Measured memory_bytes: 21192
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

using namespace std;

int main()
{
    int N, K;
    if (scanf("%d%d", &N, &K) < 2) return 0;

    int now = 1;

    for (int i = 0; i < N; i++)
    {
        if (2 * now < now + K) now = 2 * now;
        else now = now + K;
    }

    printf("%d\n", now);
    return 0;
}


Measured memory_bytes: 128
A, B, M = map(int, input().split())

alist = list(map(int, input().split()))
blist = list(map(int, input().split()))

#print(alist, blist)

mymin = (min(alist)+min(blist))
for m in range(M):
    x, y, c = map(int, input().split())
    if alist[x-1] + blist[y-1] - c < mymin:
        mymin = alist[x-1] + blist[y-1] - c
print(mymin)
    

Measured memory_bytes: 18736
import math
A, B, C, D = map(int, input().split())

rad = 2 * math.pi * (((C / 12)+((5 / 60)*(D / 60))) - (D /60))

if math.cos(rad) == 1:
    print(abs(A - B))
elif math.cos(rad) == -1:
    print(A + B)
else:
    print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(rad)))

Measured memory_bytes: 9500
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<bitset>

using namespace std;

#define ll long long
const int MOD = 1e9+7;
const int N = 3*1e5+7;

ll n;
ll data[65][2],a[N],maxx = -1,ans = 0;

ll maxn(ll a,ll b){
	if(a >= b) return a;
	return b;
}

void in(){
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
		maxx = maxn(maxx,a[i]);
	}
	for(int i = 1; i <= n; i++){
		ll cnt = 1,o=0;
		while(cnt <= maxx){
			if((a[i] ^ cnt) > a[i]) data[o][0]++;
			else data[o][1]++;
			cnt *= 2;
			o++;
		}
	}
	ll cnt = 1, o = 0;
	while(cnt <= maxx){
		ans += (cnt % MOD) *(data[o][0] * data[o][1] % MOD);
		ans %= MOD;
		cnt *= 2;
		o++;
	}
	cout << ans % MOD;
}

int main(){
	in();
}

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

#define MAX_DATA 200000
void MergeSort(int x[ ], int left, int right);

int main (void){
        /* ソートされるデータ */
        int x[200000];
        int y[200000];
        int N,A,M;
        int max,min,ans;
        scanf("%d\n",&M );
        scanf("%d\n",&N );
        for (int i = 0; i < N; i++) {
          scanf("%d\n",&A );
          x[i]=A;
        }
        MergeSort(x, 0, N-1);
        min=x[0];
        max=x[N-1];
        for (int i = 0; i < N-1; i++) {
          y[i]=x[i+1]-x[i];
        }
      MergeSort(y, 0, N-2);
      ans=max-min;
      for (int i = 0; i < M-1&&i<N; i++) {
        ans-=y[(N-2)-i];
      }
      printf("%d\n",ans );
  return 0;
}







int temp[MAX_DATA];    /* 最小でも配列と同じサイズの領域が必要 */

  /* 配列 x[ ] の left から right の要素のマージソートを行う */
void MergeSort(int x[ ], int left, int right)
{
    int mid, i, j, k;

    if (left >= right)              /* 配列の要素がひとつなら */
        return;                     /* 何もしないで戻る */

                                    /* ここでは分割しているだけ */
    mid = (left + right) / 2;       /* 中央の値より */
    MergeSort(x, left, mid);        /* 左を再帰呼び出し */
    MergeSort(x, mid + 1, right);   /* 右を再帰呼び出し */

      /* x[left] から x[mid] を作業領域にコピー */
    for (i = left; i <= mid; i++)
        temp[i] = x[i];

      /* x[mid + 1] から x[right] は逆順にコピー */
    for (i = mid + 1, j = right; i <= right; i++, j--)
        temp[i] = x[j];

    i = left;         /* i とj は作業領域のデーターを */
    j = right;        /* k は配列の要素を指している */

    for (k = left; k <= right; k++)    /* 小さい方から配列に戻す */
        if (temp[i] <= temp[j])        /* ここでソートされる */
            x[k] = temp[i++];
        else
            x[k] = temp[j--];
}


Measured memory_bytes: 1280
#include<stdio.h>
int main()
{
	int i,N,v[50],a,j;
	float sum=0.0;
	scanf("\n%d",&N);
	for (i=0;i<N;i++)
	{
		scanf("%d",&v[i]);
	}


	for (i=0;i<N-1;i++) 
	{
		for(j=0;j<N-i-1;j++)
		{
			if( v[j]>v[j+1] )
			{	a=v[j];
				v[j] = v[j+1];
				v[j+1]=a;
			}
		}
	}

        sum= (float) v[0]/2+(float)v[1]/2;
	if(N>2)
	{
	for(i=2;i<N;i++)
	{
		sum = sum/2 + (float)v[i]/2;
	}
	}
	printf("\n%f",sum);
	return 0;
}




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

using Float = double;
using Point = complex<Float>;
struct Line{ Point a,b; };
struct Circle{ Point center; Float r; };

const Float EPS = 1e-8;

inline bool eq(Float a,Float b) { return abs(a - b) < EPS; }
inline Float dot(const Point &p1,const Point &p2){ return real(conj(p1) * p2); }
inline Float cross(const Point &p1,const Point &p2){ return imag(conj(p1) * p2); }

namespace std{
	bool operator<(const Point &p1,const Point &p2){
		return eq(real(p1),real(p2)) ? imag(p1) < imag(p2) : real(p1) < real(p2);
	}
}

Point projection(const Line &l,const Point &p){
	Float t = dot(l.b - l.a,p - l.a) / norm(l.b - l.a);
	return l.a + (l.b - l.a) * t;
}

vector<Point> crosspoint(const Circle &c,const Line &l){
	vector<Point> ret;
	Point p = projection(l,c.center),vect = (l.b - l.a) / abs(l.b - l.a);
	if(abs(p - c.center) > c.r) return ret;
	Float d = sqrt(c.r * c.r - norm(p - c.center));
	ret.push_back(p + vect * d);
	if(!eq(abs(p - c.center),c.r)) ret.push_back(p - vect * d);
	return ret;
}

signed main(){
	Float cx,cy,r;
	cin >> cx >> cy >> r;
	Circle c = {Point(cx,cy),r};
	int q;
	cin >> q;
	for(int i = 0;i < q;i++){
		Float x1,x2,y1,y2;
		cin >> x1 >> y1 >> x2 >> y2;
		vector<Point> ps = crosspoint(c,{Point(x1,y1),Point(x2,y2)});
		if(ps.size() == 1) ps.push_back(ps[0]);
		if(ps[1] < ps[0]) swap(ps[0],ps[1]);
		printf("%.15lf %.15lf %.15lf %.15lf\n",real(ps[0]),imag(ps[0]),real(ps[1]),imag(ps[1]));
	}
}


Measured memory_bytes: 3312
#include<stdio.h>
#include<math.h>
#include<string.h>


int main()
{
	int n;
	scanf("%d\n", &n);
	char t[101], h[101];
	int i, taro=0, hanako=0;
	for (i = 0; i < n; i++)
	{

		scanf("%s %s\n", t,h);
		if (strcmp(t, h) > 0)
		{
			taro += 3;
		}
		else if (strcmp(t, h) == 0)
		{
			taro++;
			hanako++;
		}
		else
		{
			hanako += 3;
		}
	}
	printf("%d %d\n", taro, hanako);
	return 0;
}

Measured memory_bytes: 1036
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 101
/*グローバル変数*/
int top;
int a[MAX];

/*スタックが空かどうか*/
int isEmpty(int top) {
	if (top == 0) {
		return 1;
	}
	else {
		return 0;
	}
}
/*スタックが満杯かどうか*/
int isFull(int top) {
	if (top >= MAX - 1) {
		return 1;
	}
	else {
		return 0;
	}
}
/*配列に数字を入れる*/
void push(int ope) {
	if (!(isFull(top))) {
		a[top] = ope;
		top++;
	}
}
/*配列から数字を取り出す*/
int pop() {
	if (!(isEmpty(top))) {
		top--;
		return a[top];
	}
}

int main() {
	int x, y;	/*計算用変数*/
	char s[400];	/*数式*/
	top = 0;
	int i = 0;

	scanf("%[^\n]", s);

	while ( s[i] != '\0') {
		/*足し算*/
		if (s[i] == '+') {
			y = pop();
			x = pop();
			x = x + y;
			push(x);
		}
		/*引き算*/
		else if (s[i] == '-') {
			y = pop();
			x = pop();
			x = x - y;
			push(x);
		}
		/*掛け算*/
		else if (s[i] == '*') {
			y = pop();
			x = pop();
			x = x * y;
			push(x);
		}
		/*数字を配列に挿入*/
		else if(s[i] != ' '){
			x = 0;

			while (1) {
				if (s[i] == ' ') {
					break;
				}
				else {
					x = x * 10 + s[i] - 48;
					i++;
				}
			}
			push(x);
		}
		i++;
	}
	/*出力*/
	printf("%d\n", a[0]);
	return 0;
}



Measured memory_bytes: 2132
#include<bits/stdc++.h>
#define w cout
#define e endl

using namespace std;

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

	int arr[n + 10] = {}, pre[n + 10] = {} , suff[n + 10] = {};
	for(int i = 1 ; i <= n ; i ++ ) {
		cin >> arr[i];
	}
	
	for(int i = 1; i <= n ; i ++ ) {
		pre[i] = __gcd(pre[i - 1] , arr[i]);
		suff[n - i + 1] = __gcd(suff[n - i + 2] , arr[n - i + 1]);
	}
	
	int ans = 0;
	
	ans = pre[n];
	
	for(int i = 1 ; i <= n ; i ++ ) {
		ans = max(ans , __gcd(pre[i - 1] , suff[i + 1]));
	}
	w << ans;
	
}


Measured memory_bytes: 1408
N = int(input())

cnt = 0
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    if a == b:
        cnt += 1
        ans = ans if ans > cnt else cnt
    else:
        cnt = 0
if ans >= 3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9168
#include<bits/stdc++.h>
/*
#include<iostream>
#include<iomanip>
#include<math.h>
#include<string.h>
*/

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define INF 1000000007
#define ull unsigned long long
#define PI 3.141592653589793238
#define pb push_back
#define max3(x, y, z) Max(x, Max(y, z))
#define min3(x, y, z) Min(x, Min(y, z))
#define mp make_pair
#define pre(a,b) cout << fixed << setprecision(a) << b  //a for precision b for answer
#define MAX 1e18
#define all(x) (x).begin(), (x).end()
#define lb lower_bound //lower_bound(first_iterator, last_iterator, x) – returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘x’.
#define ub upper_bound //upper_bound(first_iterator, last_iterator, x) – returns an iterator pointing to the first element in the range [first,last) which has a value greater than ‘x’.
#define maxe *max_element
#define mine *min_element
#define acc(x) accumulate(x.begin(), x.end(), 0)
#define dst distance
#define sz(x) (int)x.size()

template <typename T>
inline T const& Max (T const& a, T const& b)
{ 
	return a < b ? b:a; 
}

template <typename T>
inline T const& Min (T const& a, T const& b) { 
   return a < b ? a:b; 
}

ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
}

ll SieveOfEratosthenes(int n) 
{  
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    {  
        if (prime[p] == true) 
        {   
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    /*for (int p=2; p<=n; p++) 
       if (prime[p]) 
          cout << p << " "; */
    return prime[n + 1];
}

int main()
{
	IOS;
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }	
    int dp[n] = {};
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1] << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"

using namespace std;
typedef long long ll;

int main()
{
  ll x,y;
  cin >> x>>y;
  int i=0;
  while (true) {
    if (x<=y) {
      x*=2;
      i++;
    }
    else
     {
       break;
     }
  }
  cout<< i << "\n";
}

Measured memory_bytes: 256
N,M = map(int,input().split())
def yakusu(n):
    ans=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            ans.append(i)
            if n!=i**2:
                ans.append(n//i)
    return ans

y = yakusu(M)
print(max(k for k in y if k*N<=M))

Measured memory_bytes: 64196
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { char a, b;
  cin >> a >> b;
  if(a=='H'){
    if(b=='H'){
      puts("H");
    }else{
      puts("D");
    }
  }else{
    if (b != 'H') {
      puts("H");
    } else {
      puts("D");
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int N, M, L, R, s[50003], t[50003], e[50003], c[10003]; long long d[10003];
int main() {
	scanf("%d%d", &N, &M);
	while(true) {
		scanf("%d%d%d", s + R, t + R, e + R); s[R]--, t[R]--;
		if (!e[R]) break; R++;
	}
	scanf("%d", &L);
	for (int i = 0; i < L; i++) {
		for (int j = 0; j < M; j++) scanf("%d", &c[j]);
		for (int j = 0; j < R; j++) d[s[j]] += c[t[j]] * e[j];
		for (int j = 0; j < N; j++) printf(j ? " %d" : "%d", d[j]), d[j] = 0;
		printf("\n");
	}
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll INF = 100000007;

int main() {
  IN(ll, X);
  ll money = 100;
  ll money_10 = 100; 
  ll ans = 0;
  for(ll i = 10; money < X; i += 10){
    money_10 = money;
    money = money * 1.01;
    money = money * 1.01;
    money = money * 1.01;
    money = money * 1.01;
    money = money * 1.01;
    money = money * 1.01;
    money = money * 1.01;
    money = money * 1.01;
    money = money * 1.01;
    money = money * 1.01;
    ans = i - 10;
  }
  money = money_10;
  for(ll i = ans+1; money < X; i++){
    money = money * 1.01;
    ans = i;
  }
  OUT(ans);
}





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

using namespace std;
#define ll long long 
#define lf long double
#define F first
#define S second
typedef vector <ll> vi;
typedef vector <pair <ll,ll> > vii;
int main() 
{
	ll n,k;
	cin>>n;
	vii a(n);
	for(ll i=0;i<n;i++)
	{
		cin>>a[i].F;
		a[i].S=i+1;
	}
	sort(a.begin(),a.end());
	for(ll i=0;i<n;i++)
	{
		cout<<a[i].S<<" ";
	}
	cout<<endl;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())
 
int main()
{
    int n,m;
    cin >> n >> m;
    vector<int > h(n+1);
    rep(i,n){
      int high;
      cin >> high;
      h.at(i+1) = high;
    }

    vector<int > ans(n+1);
    rep(i,n){
      ans.at(i+1) = i+1;
    }

    rep(i, m){
      int a,b;
      cin >> a >> b;
      int ah, bh;
      ah = h.at(a);
      bh = h.at(b);

      if(ah>=bh) ans.at(b)=0;
      if(bh>=ah) ans.at(a)=0; 
    }
    
    int cnt=0;
    for(int i=1; i<=n; i++){
      if(ans.at(i)!=0) cnt++;
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    char x;
  	cin >> x;
  	if(x - 'A' <= 26) cout << "A";
  	else cout << "a";
    return 0;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define int long long
signed main() {
	int n;
	cin>>n;
	vector<double> v;
	for(int i=0;i<n;i++){
	    int x;
	    cin>>x;
	    v.push_back(x);
	}
	double mx=0.00;
	sort(v.begin(),v.end());
	for(int i=0;i<n-1;i++){
	    v[i+1]=(double)v[i]+(double)(v[i+1]-v[i])/2;
	}
	mx=v[n-1];
	cout<<mx;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

typedef std::vector<std::vector<pair<int, pair<int, int>>>> graph;

int dfs(int s, int par, int paredge, graph &g) {
  int k = 1;
  REP(i, g[s].size()) {
    if (g[s][i].first == par)
      continue;
    if (k == paredge)
      k++;
    g[s][i].second.second = k;
    dfs(g[s][i].first, s, k, g);
    k++;
  }
}

int main() {
  int n;
  cin >> n;
  graph g(n);
  REP(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(make_pair(b, make_pair(i, 0)));
    g[b].push_back(make_pair(a, make_pair(i, 0)));
  }

  int k = 0;
  REP(i, n) { k = max(k, (int)g[i].size()); }

  dfs(0, -1, -1, g);

  vi ans(n - 1);
  REP(i, g.size()) {
    for (auto e : g[i]) {
      if (e.second.second == 0)
        continue;
      ans[e.second.first] = e.second.second;
    }
  }

  cout << k << endl;
  REP(i, n - 1) { cout << ans[i] << endl; }
}


Measured memory_bytes: 8320
use std::io::Read;

fn main(){
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    let s: String = iter.next().unwrap().parse().unwrap();

    let mut ans = false;

    if n % 2 == 0 {        
        let a = &s[0..n/2];
        let b = &s[n/2..];
        if a == b {
            ans = true;
        }
    }

    println!("{}", if ans { "Yes" } else { "No" });
}

Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program
{
    public static Scanner cin;
    static void Main()
    {

        cin = new Scanner();
        long n = cin.inputInt();
        long[] aArray = cin.arrayLong();
        long ans = aArray[0];
        for (long a = 0; a < n - 1; a++)
        {
            ans = GCD(ans, aArray[a + 1]);
        }
        WriteLine(ans);

    }
    static long GCD(long a, long b)
    {
        long m = a % b;
        if (m == 0)
        {
            return b;
        }
        else
        {
            return GCD(b, m);
        }

    }
}





class Scanner
{

    public Scanner()
    {
    }

    public string input()
    {
        return ReadLine();
    }
    public string[] array()
    {
        return ReadLine().Split();
    }
    public int inputInt()
    {
        return int.Parse(ReadLine());
    }
    public int[] arrayInt()
    {
        return ReadLine().Split().Select(i => int.Parse(i)).ToArray();
    }
    public long inputLong()
    {
        return long.Parse(ReadLine());
    }
    public long[] arrayLong()
    {
        return ReadLine().Split().Select(i => long.Parse(i)).ToArray();
    }
    public double inputDouble()
    {
        return double.Parse(ReadLine());
    }
    public double[] arrayDouble()
    {
        return ReadLine().Split().Select(i => double.Parse(i)).ToArray();
    }
}

Measured memory_bytes: 20832
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	while (n > 0) {
		int c = n % 10;
		if (c == 7) {
			cout << "Yes";
			return 0;
		}
		n /= 10;
	}
	cout << "No";
}

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

int main(){
  int n,a,b,ac=0,abc=0,bc=0;
  cin>>n>>a>>b;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    if(x<=a) ac++;
    else if(b<x) bc++;
    else abc++;
  }
  int minnum=min(ac,bc);
  minnum=min(minnum,abc);
  cout<<minnum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<bool> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17

vector<ll>divisor(int n){
    vector<ll>res;
    for(ll i=1;i*i<=n;++i){
        if(n%i==0){
            res.push_back(i);
            if(i!=n/i)res.push_back(n/i);
        }
    }
    sort(ALL(res));
    return res;
}
int main(){
    ll n,m;cin>>n>>m;
    VI s=divisor(m);
    ll ans;
    for(auto b:s){
        if(m/b>=n)ans=b;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int h, w;
  cin >> h >> w;
  MAT<char> m = MATINIT(char, h + 2, w + 2, '#');
  REP(i, 0, h) {
    REP(j, 0, w) { cin >> m[i + 1][j + 1]; }
  }
  REP(i, 0, h + 2) {
    REP(j, 0, w + 2) { cout << m[i][j] ; }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int main() {
	int a,b,n;
	cin >>n>> a >> b;
	PRI(min(a*n,b));
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    /*
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    */
    cout << a*b << endl; 
    return 0;
}

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

bool IsPrime(int num)
{
    if (num < 2) 
    {
      return false;
    }
    else if (num == 2) 
    {
      return true ;
    }
    else if (num % 2 == 0)
    {
      return false; 
    }
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

int main()
{
  int n ;
  cin >> n ;
  while(true)
  {
    if(IsPrime(n)) 
    {
      cout << n << endl ;
      return 0 ;
    }
    n++ ;
  }
}


Measured memory_bytes: 256
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
    win_lose[win].add(lose)
s1 = [1]
s2 = []
while s1:
    a = s1.pop()
    s2 += [a]
    for b in win_lose[a]:
        s1 += [b]
dp = [0] * (N + 1)
for x in s2[::-1]:
    if win_lose[x] == set():
        dp[x] = 0
    else:
        dp[x] = max(
            i + v + 1
            for i, v in enumerate(sorted(dp[y] for y in win_lose[x])[::-1]))
print(dp[1])


Measured memory_bytes: 52916
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,ans=1;
    string s;
    cin>>n>>s;
    char a=s[0];
    rep2(i,1,n){
        if(s[i]!=s[i-1]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512