akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstdlib>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1010;
const int EPS = 1e-9;
const ll MOD = 1e9 + 7;

char ans[N][N];

void solve2(int n) {
	for (int i = 0; i < n; i += 2) {
		ans[i][i] = ans[i + 1][i] = 'a';
		ans[i][i + 1] = ans[i + 1][i + 1] = 'b';
		ans[i][(i + 2) % n] = ans[i][(i + 3) % n] = 'c';
		ans[i + 1][(i + 2) % n] = ans[i + 1][(i + 3) % n] = 'd';
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << ans[i][j];
		}
		cout << "\n";
	}
}

void solve3(int n) {
	for (int i = 0; i < n; i += 3) {
		ans[i][i] = ans[i + 1][i] = 'a';
		ans[i][i + 1] = ans[i][i + 2] = 'b';
		ans[i + 2][i] = ans[i + 2][i + 1] = 'c';
		ans[i + 2][i + 2] = ans[i + 1][i + 2] = 'd';
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << ans[i][j];
		}
		cout << "\n";
	}
}

vector<string> s5 = {
"aabdd",
"ccb.e",
"..fge",
"..fgi",
"jjhhi"
};

vector<string> s7 = {
"abcc...",
"abdd...",
"ff.h.ii",
"...hjjk",
"pp..m.k",
"..o.m.l",
"..o.nnl"
};

void solve57(int n) {
	int st = 5;
	if ((n - 5) % 4 == 0) {
		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 5; j++) {
				ans[i][j] = s5[i][j];
			}
		}
	}
	else {
		for (int i = 0; i < 7; i++) {
			for (int j = 0; j < 7; j++) {
				ans[i][j] = s7[i][j];
			}
		}
		st = 7;
	}

	for (int i = st; i < n; i += 4) {
		ans[i][i] = ans[i + 1][i] = 'a';
		ans[i][i + 1] = ans[i + 1][i + 1] = 'b';
		ans[i][(i + 2) % n] = ans[i][(i + 3) % n] = 'c';
		ans[i + 1][(i + 2) % n] = ans[i + 1][(i + 3) % n] = 'd';

		ans[i + 2][i + 2] = ans[i + 3][i + 2] = 'e';
		ans[i + 2][i + 3] = ans[i + 3][i + 3] = 'f';
		ans[i + 2][i] = ans[i + 2][i + 1] = 'j';
		ans[i + 3][i] = ans[i + 3][i + 1] = 'k';
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << ans[i][j];
		}
		cout << "\n";
	}
}

void solve() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		fill(ans[i], ans[i] + n, '.');
	}
	if (n <= 2) {
		cout << -1;
		return;
	}
	if (n % 3 == 0) {
		solve3(n);
	}
	else if (n % 2 == 0) {
		solve2(n);
	}
	else {
		solve57(n);
	}
}


int main() {
//	auto trash = freopen("a.in", "r", stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long x,s=100;
	cin>>x;
	for(int i=1;;i++){
		s+=floor(s*0.01);
		if(s>=x){
			cout<<i;
			break;
		}
	}
	return 0;
} 

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

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

    long long n;
    cin >> n;
    string s;
    cin >> s;
    vector<long long> A(26);
    for(long long i = 0; i < n; i++){
        A[(long long )(s[i] - 'a')]++;
    }

    long long mod = 1e9 + 7, ans = 1;
    for(long long i = 0; i < 26; i++){
        if(A[i] > 0) ans = (ans * (A[i] + 1)) % mod;
    }
    ans--;

    cout << ans % mod << endl;

    return 0;
}

Measured memory_bytes: 512
n, r = map(int, raw_input().split())
P = [map(int, raw_input().split()) for i in xrange(n)]

from math import sqrt, atan2

def intersection01(cx, cy, r, x1, y1, x2, y2):
    xd = x2 - x1; yd = y2 - y1
    X = x1 - cx; Y = y1 - cy
    a = xd**2 + yd**2
    b = xd * X + yd * Y
    c = X**2 + Y**2 - r**2
    D = b**2 - a*c
    result = []
    if D > 0:
        d = sqrt(D)
        if 0 < -b - d < a:
            s = (-b - d) / a
            result.append((x1 + xd*s, y1 + yd*s))
        if 0 < -b + d < a:
            s = (-b + d) / a
            result.append((x1 + xd*s, y1 + yd*s))
    elif D == 0:
        if 0 < -b < a:
            s = -b / float(a)
            result.append((x1 + xd*s, y1 + yd*s))
    return result

def calc(x0, y0, x1, y1, rr):
    if x0**2 + y0**2 - rr <= 1e-8 and x1**2 + y1**2 - rr <= 1e-8:
        return (x0 * y1 - x1 * y0) / 2.
    theta = atan2(x0*y1 - x1*y0, x0*x1 + y0*y1)
    return theta*rr/2.

rr = r**2
ans = 0
for i in xrange(n):
    (x0, y0) = P[i-1]; (x1, y1) = P[i]

    result = intersection01(0, 0, r, x0, y0, x1, y1)
    px = x0; py = y0
    for x, y in result:
        ans += calc(px, py, x, y, rr)
        px = x; py = y
    ans += calc(px, py, x1, y1, rr)
print "%.08f" % ans

Measured memory_bytes: 6836
import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
options = [None] * N
for i in range(N):
    options[i] = tuple(int(x) for x in readline().split())


def solve():
    da, db, dc = 0, 0, 0
    for i in range(N):
        xa, xb, xc = options[i]
        xa += da
        xb += db
        xc += dc
        da, db, dc = max(xb, xc), max(xa, xc), max(xa, xb)
    print(max(da, db, dc))


if __name__ == "__main__":
    solve()


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

int main() {
	  long long N;
    cin >> N;
  
  	vector<long long> A(N);
  	for (long long i=0; i<N; ++i) {
      	cin >> A[i];
    }
    vector<long long> S(N+1, 0);
    for (long long i=0; i<N; ++i) {
        S[i+1] = S[i] + A[i];
    }

  	long long ans=0;
  	for (long long i=0; i<N; ++i) {
        long long llbuff = (S[N]-S[i+1])%(long long)1000000007;
        ans += (A[i]*llbuff)%(long long)1000000007;
    }
  	
  	cout << ans%(long long)1000000007 << endl;
    return 0;
}

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

int gcd_th(int a, int b, int c){
  return gcd(a, gcd(b, c));
}


int main(void){
  int K;
  cin >> K;
  long long sum = 0;
  for(int a = 1; a <= K; a++){
    for(int b = 1; b <= K; b++){
      for(int c = 1; c <= K; c++){
        sum += gcd_th(a, b, c);
      }
    }
  }
  cout << sum;
  
  return 0;
}

Measured memory_bytes: 3604
n,c,k=map(int,input().split())
o=sorted(int(input()) for _ in range(n))
cnt=0
l=0
r=0

while l<n:
  while r<n and o[r]<=o[l]+k and r-l+1<=c:
    r+=1
  cnt+=1
  l=r

print(cnt)

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

int main() {
    ll n, a, b;
    cin>>n>>a>>b;
    if((b-a) % 2 == 0){
        cout<<"Alice"<<endl;
    } else {
        cout<<"Borys"<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

void bubbleSort(int x[], int N)
{
	int i, j, tmp;
	int cnt=0;
	for(i=0; i<N-1; i++){
		for(j=N-1; j>i; j--){
			if(x[j] < x[j-1])
			{
				tmp = x[j];
				x[j] = x[j-1];
				x[j-1] = tmp;
				cnt++;
			}
		}
	}
	for(i=0; i<N; i++){
		if(i != N-1)
		{
			printf("%d ", x[i]);
		}
		else printf("%d", x[i]);
	}
	printf("\n");
	printf("%d\n", cnt);
}


int main(void)
{
	int n;
	scanf("%d", &n);
	
	int i, x[n];
	for(i=0; i<n; i++){
		scanf("%d", &x[i]);
	}
	bubbleSort(x, n);
	
	return 0;
}


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

int main(){
    ll n,m,ans;
    cin>>n>>m;
    ans=(1900*m+100*(n-m))*pow(2,m);
    cout<<ans<<endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;

    vector<vector<int>> S(M, vector<int>(N));
    vector<int> P(M);

    REP(i, M){
        ll K;
        cin >> K;
        REP(j, K){
            ll k;
            cin >> k;
            S[i].push_back(k-1);
        }
    }
    REP(i, M){
        cin >> P[i];
    }

    ll ans = 0;
    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<N); ++bit) {
        bool sw = true;
        // 電球の数だけ繰り返す
        for (int i = 0; i < M; ++i) {
            //各ボタンの状態
            int botton = 0;
            // 電球がつながっているスイッチを取り出す
            for(auto v: S[i]){
                // スイッチが押されている状態なら
                if (bit & (1<<v)) botton++;
            }
            // もしも条件と一致していないならfalseに
            if(botton%2 != P[i]) sw = false;
        }
        if (sw == true) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long LL;

#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define LEN(a) int((a).size())
#define SORT(a) sort((a).begin(), (a).end())
#define CLR(a) memset((a), 0, sizeof(a))

const double EPS = 1e-10;
const double PI = acos(-1.0);

bool comp(tuple<string, int, int> a, tuple<string, int, int> b) {
    if (get<0>(a) == get<0>(b)) {
        return get<1>(a) > get<1>(b);
    } else {
        return get<0>(a) < get<0>(b);
    }
}

int main() {
    int n;
    cin >> n;
    vector<tuple<string, int, int>> v(n);
    for (int i = 0; i < n; i++) {
        string s;
        int a;
        cin >> s >> a;
        v[i] = make_tuple(s, a, i + 1);
    }
    sort(v.begin(), v.end(), comp);
    for (int i = 0; i < n; i++) {
        cout << get<2>(v[i]) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*  ex4_2
    hangan2020 */

#include <stdio.h>
#include <math.h>
#define _USE_MATH_DEFINES

//プロトタイプ宣言
double ClockHandsDistance(double LHLength, double SHLength, double Hour, double Minute);

int main(void){
    double lhlength, shlength, hour, minute;
    double distance;
    //入力 
    scanf("%lf %lf %lf %lf", &lhlength, &shlength, &hour, &minute);
    //離れる距離を計算する関数の実施
    distance = ClockHandsDistance(lhlength, shlength, hour, minute);
    //小数点15位まで出力
    printf("%0.15lf\n", distance);
    return 0;
}

//関数定義
double ClockHandsDistance(double LHLength, double SHLength, double Hour, double Minute){
    double handsangle, hands_distance;
    //ちょうどHour時間になるときの角度
    handsangle = 30*Hour;
    //そのMinute分後の角度 
    handsangle = handsangle - 5.5*Minute;
    //ラジアンに変換
    handsangle = handsangle*(M_PI/180);
    //距離の2畳を計算
    hands_distance = pow(LHLength, 2) + pow(SHLength, 2) - 2*LHLength*SHLength*cos(handsangle);
    //平方根で最終結果の距離を出す
    hands_distance = sqrt(hands_distance);
    return(hands_distance);
}

Measured memory_bytes: 2524
#include <cstdio>
#include <math.h>
using namespace std;

int q;
double x, x3, e;

int main(){
	while (scanf("%d", &q), q != -1) {
		e = 0.00001*q;
		x = q / 2.0;
		x3 = pow(x, 3);
		while (!(x3 - q < e && x3 - q > -e)) {
			x = x - (x3 - q) / (3 * pow(x, 2));
			x3 = pow(x, 3);
		}
		printf("%.6f\n", x);
	}


	return 0;
}

Measured memory_bytes: 2796
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

const double eps = 1e-8;

class P {
public:
	double x, y, z;
	P(){};
	P(double x, double y, double z) : x(x), y(y), z(z) {};
	P operator+(const P &p) {
		return P(x + p.x, y + p.y, z + p.z);
	}
	P operator-(const P &p) {
		return P(x - p.x, y - p.y, z - p.z);
	}
	P operator*(const double &n) {
		return P(x * n, y * n, z * n);
	}
	P operator/(const double &n) {
		return P(x / n, y / n, z / n);
	}
};

double dot(const P &a, const P &b) {
	return a.x * b.x + a.y * b.y + a.z * b.z;
}

P cross(const P &a, const P &b) {
	return P(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}

int main() {
	P p[5];
	for (int i=0; i<5; ++i) cin >> p[i].x >> p[i].y >> p[i].z;

	P z = cross(p[3] - p[2], p[4] - p[2]);
	double a = dot(p[2] - p[0], z);
	double b = dot(p[1] - p[0], z);
	double c = abs(a);
	double d = abs(b) - c;

	if (abs(a) < eps || (b < -eps && eps < a) || (a < -eps && eps < b) || d < -eps) {
		cout << "HIT" << endl;
		return 0;
	}

	P i = (p[0] * d + p[1] * c) / (c + d);

	int plus = 0;
	if (-eps < dot(z, cross(p[3] - p[2], i - p[2]))) ++plus;
	if (-eps < dot(z, cross(p[4] - p[3], i - p[3]))) ++plus;
	if (-eps < dot(z, cross(p[2] - p[4], i - p[4]))) ++plus;
	int minus = 0;
	if (eps > dot(z, cross(p[3] - p[2], i - p[2]))) ++minus;
	if (eps > dot(z, cross(p[4] - p[3], i - p[3]))) ++minus;
	if (eps > dot(z, cross(p[2] - p[4], i - p[4]))) ++minus;

	if (plus == 3 || minus == 3) {
		cout << "MISS" << endl;
	} else {
		cout << "HIT" << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    int[] numb = new int[N];
    int[] numw = new int[N];
    int countb = 0;
    for (int i = 0; i < N; i++) {
      numb[i] = countb;
      if (s[i] == '#') {
        countb++;
      }
    }
    int countw = N - countb;
    int min = Math.min(countb, countw);
    for (int i = 0; i < N; i++) {
      numw[i] = countw;
      if (s[i] == '.') {
        countw--;
      }
    }

    for (int i = 0; i < N; i++) {
      min = Math.min(min, numb[i] + numw[i]);
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 30628
#include<queue>
#include<queue>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;

int n, dd[101], f[101], tmap[101][101];
int color[101], t = 0;
queue<int> Q;


void a(){
	while (!Q.empty()){
		int d = Q.front();
		Q.pop();
		for (int i = 1; i <= n; i++){
			if (color[i] == 0 && tmap[d][i] == 1){
				Q.push(i);
				color[i] = 1;
				dd[i] = dd[d] + 1;
			}
		}
	}
}


int main(){
	cin >> n;
	for (int i = 0; i < 100; i++){
		f[i] = color[i] = 0;
		dd[i] = -1;
		for (int j = 0; j < 100; j++){
			tmap[i][j] = 0;
		}
	}

	int u, k, v;

	for (int i = 0; i < n; i++){
		cin >> u >> k;
		for (int j = 0; j < k; j++){
			cin >> v;
			tmap[u][v] = 1;
		}
	}
	color[1] = 1;
	Q.push(1);
	dd[1] = t;
	a();
	for (int i = 1; i <= n; i++){
		cout << i << " " << dd[i] << endl;
	}
	return 0;
}

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

int main(){
  string S,T,U;
  int s,t;
  cin>>S>>T>>s>>t>>U;
  if(S==U){
    s--;
  }
  if(T==U){
    t--;
  }
  cout<<s<<' '<<t<<endl;
}

Measured memory_bytes: 256
fun main() {
    val (h, w, k) = nextIntList()
    val mat = (0 until h).map {
        next()
    }
    var res = 0
    val rowSelection = sizedArray(h, false)
    val columnSelection = sizedArray(w, false)

    fun calcW(index: Int, selecH: Array<Int>, selecW: List<Boolean>) {
        if (index == w) {
            // calc result
            if (selecH.filterIndexed { indx, _ -> selecW[indx] }.sum() == k) {
                res++
            }
            return
        }
        // true
        calcW(index + 1, selecH, selecW + true)
        // false
        calcW(index + 1, selecH, selecW + false)
    }

    fun calcH(index: Int, selec: Array<Int>) {
        if (index == h) {
            calcW(0, selec, listOf())
            return
        }
        // true
        val row = mat[index]
        calcH(index + 1, selec.mapIndexed { indx, i -> i + (if (row[indx] == '#') 1 else 0) }.toTypedArray())
        // false
        calcH(index + 1, selec)
    }

    calcH(0, sizedArray(w, 0))
    println(res)
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

Measured memory_bytes: 41276
#include <stdio.h>

#define ull unsigned long long

#define RIGHT_N_BIT_OFF(b, n) ((b) & ((ull)(-1) << (n)))
#define REMAIN_RIGHT_N_BIT(b, n) ((b) & (((ull)(1) << (n)) - 1))

int main()
{
	int i, j;
	int n;
	
	ull k;
	ull a;
	ull best = 0;
	ull x;
	ull count_each_bit[42] = {};
	ull sum = 0;
	ull sum_max = 0;
	
	scanf("%d %llu ", &n, &k);
	
	for(i = 0; i < n; ++i){
		scanf("%llu ", &a);
		for(j = 0; j < 42; ++j)
			count_each_bit[j] += (a>>j) & 1;
	}
	
	for(i = 0; i < 42; ++i)
		if(count_each_bit[i] * 2 < n)
			best += ((ull)1 << i);
	
	for(i = 0; i < 42; ++i)
		if(((k+1) >> i) & 1){
			x = RIGHT_N_BIT_OFF(k, i+1);
			x |= REMAIN_RIGHT_N_BIT(best, i);
			
			sum = 0;
			for(j = 0; j < 42; ++j){
				if(((x >> j) & 1) == 0)
					sum += (count_each_bit[j] << j);
				else
					sum += ((n - count_each_bit[j]) << j);
			}
			
			if(sum_max < sum)
				sum_max = sum;
		}
	
	printf("%llu", sum_max);
	
	return 0;
}


Measured memory_bytes: 128
X,Y,A,B,C=map(int,input().split())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
R=list(map(int,input().split()))

P_new=sorted(P,reverse=True)[:X]
Q_new=sorted(Q,reverse=True)[:Y]

S=sorted(P_new+Q_new+R,reverse=True)[:X+Y]

print(sum(S))

Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main(void) {
    int m; cin >> m;
    cout << (24-m) + 24;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int a,b;
    cin>>a>>b;
    for(int i=1;i<2000;i++)
    {
        int x=i*0.08;
        int y=i*0.1;
        if(x==a && y==b)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve() {
		int n = in.nextInt();
		if (n == 0) return false;

		String[] names = new String[n];
		double[][] a = new double[n][2];
		for (int i=0; i<n; i++) {
			names[i] = in.next();
			int p = in.nextInt();
			int t1 = in.nextInt();
			int t2 = in.nextInt();
			int t3 = in.nextInt();
			int t4 = in.nextInt();
			int t5 = in.nextInt();
			int f = in.nextInt();
			int s = in.nextInt();
			int m = in.nextInt();
			int v = f*s*m;

			a[i][0] = i;
			a[i][1] = (double)(v - p)/(t1 + t2 + t3 + (t4 + t5)*m);
		}

		Arrays.sort(a, new Comparator<double[]>(){
			public int compare(double[] a, double[] b) {
				if (a[1] != b[1]) return Double.compare(b[1], a[1]);
				return names[(int)a[0]].compareTo(names[(int)b[0]]);
			}
		});

		for (int i=0; i<n; i++) {
			out.println(names[(int)a[i][0]]);
		}
		out.println("#");

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 47712
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k,x,s=0;
  cin >> n >> k;
  for (int i=0; i<n; i++) {
    cin >> x;
    if (x>k/2) {
      s+=(k-x)*2;
    } else {
      s+=x*2;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 3584
N = input()
Nreverse = N[::-1]
for i in range(len(N)):
    if N[i] == "A":
        Initial = i+1
        break
for j in range(len(Nreverse)):
    if Nreverse[j] == "Z":
        Final = len(N)-j
        break

print(Final - Initial +1)


Measured memory_bytes: 41584
use std::cmp::max;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s = read::<String>().as_bytes().to_vec();

    let mut dp = vec![0u64; s.len() + 1];

    for (i, c) in s.iter().enumerate() {
        if *c == b'<' {
            dp[i + 1] = max(dp[i + 1], dp[i] + 1);
        }
    }

    for (i, c) in s.iter().enumerate().rev() {
        if *c == b'>' {
            dp[i] = max(dp[i], dp[i + 1] + 1);
        }
    }

    println!("{}", dp.iter().sum::<u64>());
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 8444
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<functional>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
LL N,M;

int main(){
    cin>>N;

    cout<<(N-30)/2<<endl;
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>

using namespace std;

int main(){
 int d,n;
  
  cin >> d >> n;
  
  if(n == 100)n++;
  
  int wk;
  if(d == 0){
    wk = 1;
  }else if(d == 1){
    wk = 100;
  }else{
    wk = 10000;
  }
  
  cout << n * wk << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w = readInts()
S = ""
for i in range(h):
    S += input()
LIST = Counter(S)
#print(LIST)
if h%2 == 0 and w%2 == 0:
    for k,v in LIST.items():
        if v%4:
            print('No')
            exit()
elif (h%2 == 0 and w%2) or (h%2 and w%2 == 0):
    two = 0
    for k,v in LIST.items():
        if v%2 or v%4 == 3:
            print('No')
            exit()
        if v%4 == 2:
            two += 1
    if h%2 == 0:
        if two > h//2:
            print('No')
            exit()
    else:
        if two > w//2:
            print('No')
            exit()
else:
    odd = 0
    two = 0
    for k,v in LIST.items():
        if v%4 == 1:
            odd += 1
        if v%4 == 2:
            two += 1
        if v%4 == 3:
            print('No')
            exit()
    if odd != 1:
        print('No')
        exit()
    if two > ((h-1)//2 + (w-1)//2):
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 10432
class DroppingInk
  def initialize
    init_stage
    init_ink
  end

  def drop(x, y, size)
    if size == 1 || size == 2
      3.times do |i|
        3.times do |j|
          next if 0 > (j + x - 1) || (j + x - 1) > 9 || 0 > (i + y - 1 ) || (i + y - 1) > 9
          @stage[j + x - 1][i + y - 1] += size == 1 ? @small[j][i] : @medium[j][i]
        end
      end
    elsif size == 3
      5.times do |i|
        5.times do|j|
        next if 0 > (j + x - 2) || (j + x - 2) > 9 || 0 > (i + y - 2) || (i + y - 2) > 9
        @stage[j + x - 2][i + y - 2] += @large[j][i]
        end
      end
    end
  end

  def stage_info
    max = -1
    empty = 0
    10.times do |i|
      10.times do |j|
        if @stage[i][j] == 0
          empty += 1
        elsif @stage[i][j] > max
          max = @stage[i][j]
        end
      end
    end
    [max, empty]
  end

  def init_stage
    @stage = Array.new(10){Array.new(10, 0)}
  end

  def init_ink
    @large = Array.new(5){Array.new(5, 1)}
    @large[0][0] = @large[1][0] = @large[3][0] = @large[4][0] = 0
    @large[0][1] = @large[4][1] = 0
    @large[0][3] = @large[4][3] = 0
    @large[0][4] = @large[1][4] = @large[3][4] = @large[4][4] = 0

    @medium = Array.new(3){Array.new(3, 1)}

    @small = Array.new(3){Array.new(3, 1)}
    @small[0][0] = @small[2][0] = 0
    @small[0][2] = @small[2][2] = 0
  end
end

dropping_ink = DroppingInk.new

while line = gets do
  x, y, size = line.chomp.split(",").map(&:to_i)
  dropping_ink.drop(x, y, size)
end
max, empty = dropping_ink.stage_info
puts empty
puts max

Measured memory_bytes: 8732
n=int(input())
a=list(map(int,input().split()))

counts=[0 for _ in range(n)]

for i in a:
  counts[i-1] +=1

total=0
for i in counts:
  if i>=2:
    total += i*(i-1)//2

for i in a:
  c=counts[i-1]
  if c>=2:
  	minus=c*(c-1)//2 - (c-1)*(c-2)//2
  else:
    minus=0
  print(total-minus)

Measured memory_bytes: 25716
import sys
input = sys.stdin.readline

def func():
    N = int(input())
    A = [int(i) for i in input().split()]

    dp = [[0] * (N+1) for i in range(N+1)]
    for i in range(N):
        dp[i][i+1] = A[i]

    for s in range(2, N+1):
        for l in range(N-s+1):
            r = l + s
            dp[l][r] = max(A[l]-dp[l+1][r], A[r-1]-dp[l][r-1])
                            
    return dp[0][N]

print(func())

Measured memory_bytes: 111836
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int a[61], b[61], c[61], d[61];
int N, M, Q;
int ans = 0;
vector<vector<int>> G;
vector<int >V;
void dfs(int d) {
	if (d >= N) {
		G.push_back(V);
		return;
	}
	else {
		if (V.empty()) {
			for (int i = 0; i < M; i++) {
				V.push_back(i);
				dfs(d + 1);
				V.pop_back();
			}
		}
		else {
			for (int i = V.back(); i < M; i++) {
				V.push_back(i);
				dfs(d + 1);
				V.pop_back();
			}
		}
	}
}

int main()
{
	cin >> N >> M >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}
	dfs(0);
	for (vector<int> A : G) {
		int sum = 0;
		for (int i = 0; i < Q; i++) {
			if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 9824
#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>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ma = max({a, b, c});
  for (int i = 0; i < k; i++) {
    ma *= 2;
  }
  cout << a + b + c + ma - max({a, b, c}) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,M;
     cin>>N>>M;
    int A[M],i,s=0;
    for(i=0;i<M;i++){
       scanf("%d",&A[i]);
       s+=A[i];
        }
     int h=N-s;
    if(N>s){
     cout<<h<<endl;}
    else if(N<s){
      cout<<"-1"<<endl; }
    else{
       cout<<"0"<<endl;}
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
const long long INF = (1LL<<32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

static const int MAX = 100;
ll d[MAX][MAX];

void floyd()
{
    REP(k, n)
    {
        REP(i, n)
        {
            if (d[i][k] == INF)
            {
                continue;
            }
            REP(j, n)
            {
                if (d[k][j] == INF)
                {
                    continue;
                }
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main()
{
    ll e, u, v, c;
    cin >> n >> e;
    REP(i, n)
    {
        REP(j, n)
        {
            d[i][j] = ((i == j) ? 0 : INF);
        }
    }
    REP(i, e)
    {
        cin >> u >> v >> c;
        d[u][v] = c;
    }

    floyd();

    bool negative = false;
    REP(i, n)
    {
        if (d[i][i] < 0)
        {
            negative = true;
        }
    }
    if (negative)
    {
        cout << "NEGATIVE CYCLE" << endl;
    }
    else
    {
        REP(i, n)
        {
            REP(j, n)
            {
                if (j)
                {
                    cout << " ";
                }
                if (d[i][j] == INF)
                {
                    cout << "INF";
                }
                else
                {
                    cout << d[i][j];
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N;
    cin >> N;

    string S;
    cin >> S;

    ll totalW = 0;
    ll totalE = 0;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'W')
        {
            totalW++;
        }
        else
        {
            totalE++;
        }
    }

    ll soFarW = 0;
    ll soFarE = 0;
    ll sum;
    ll ans = INF;
    for (int i = 0; i < N; i++)
    {
        char current = S[i];
        if (current == 'E')
        {
            soFarE++;
            sum = soFarW + (totalE - soFarE);
            // printf("%d: leftW = %d, rightE = %d\n", i + 1, soFarW, totalE - soFarE);
        }
        else
        {
            sum = soFarW + (totalE - soFarE);
            // printf("%d: leftW = %d, rightE = %d\n", i + 1, soFarW, totalE - soFarE);
        }
        ans = min(ans, sum);

        if (current == 'W')
        {
            soFarW++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3888
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	s := readString()
	var ans = 700
	for _, r := range s {
		if r == 'o' {
			ans += 100
		}
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi= vector<vi>;
using vs = vector<string>;
using pl = pair<ll,ll>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  mp(a,b)  make_pair(a,b)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;

const int M=10000;

int main(int argc,char* argv[])
{
    double t,x;
    cin>>t>>x;
    cout<<t/x<<endl;
    
    return 0;
}




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

using namespace std;

int main()
{
	string s,month,day;
	cin >> s;
	for (long long i = 5; i < 7; i++)
		month.push_back(s[i]);

	if (month == "01" || month == "02" || month == "03" || month == "04")
		cout << "Heisei" << endl;
	else
		cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define MAX 10000000000
//#define MOD 1000000003
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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


void search(vector<bool> &GF, vl &G, vvl D, ll S, ll T, ll N, ll len) {
	queue<ll> Q;
	GF[N] = true;
	G[N] = 0;
	Q.push(N);
	while (!Q.empty()) {
		ll n = Q.front();
		Q.pop();

		rep(i, D[n].size()) {
			if (GF[D[n][i]])continue;
			GF[D[n][i]] = true;
			chmin(G[D[n][i]], G[n] + 1);
			Q.push(D[n][i]);
		}
	}
}


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

	ll N, M;
	ll S, T;
	cin >> N >> M;
	vvl D(N*3);
	vector<bool> GF(N * 3, false);
	vl G(N * 3, MAX);

	vl U(M), V(M);
	rep(i, M) {
		cin >> U[i] >> V[i];
		D[(U[i] - 1)*3].push_back((V[i] - 1)*3+1);
		D[(U[i] - 1)*3+1].push_back((V[i] - 1)*3+2);
		D[(U[i] - 1)*3+2].push_back((V[i] - 1)*3);
	}
	cin >> S >> T;
	S--;
	T--;
	S *= 3;
	T *= 3;


	search(GF, G, D, S, T, S, 0);


	if (G[T] == MAX) {
		cout << -1 << endl;
	}
	else {
		cout << G[T] / 3 << endl;
	}


	return 0;
	
}



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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e6+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    int n,a[BIG],b[BIG],occ[BIG],ans;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    cin >>n;
    for (int i=0; i<n; i++) {
        cin >>a[i];
        if (occ[a[i]]) {
            b[a[i]] = 1;
            continue;
        }
        for (int j=2*a[i]; j <= BIG && !b[a[i]] && !occ[a[i]]; j += a[i]) {
            b[j] = 1;
        }
        occ[a[i]] = 1;
    }
    for (int i=0; i<n; i++) {
        if (!b[a[i]])
            ans++;
    }
    cout <<ans;



    return 0;
}


Measured memory_bytes: 12124
import java.util.*;
 
class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
	     long a = sc.nextInt();
        long b = sc.nextInt();
      long c = sc.nextInt();
      long d = sc.nextInt();
      long ac = a*c;
      long bd = b*d;
      long ad = a*d;
      long bc = b*c;
      System.out.println(Math.max(Math.max(ac,bd),Math.max(ad,bc)));
		
	}
}

Measured memory_bytes: 35684
package main
import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)
var in = NewScanner(os.Stdin, 0)
/* this is port of top c++ answer to test go performance */
func main(){
	n, m := in.Int(), in.Int()
	a, b := in.ArrayIntx(n, n+1), in.ArrayIntx(m, m+1)
	a.SortR()
	b.SortR()
	ans, c := 1, 0
	for i, j, k := n*m, 0, 0; i > 0; i--{
		if a[j] == i && b[k] == i{
			c += j + k
			j++
			k++
		} else if a[j] == i{
			ans = ans * k % M7
			c += k - 1
			j++
		} else if b[k] == i{
			ans = ans * j % M7
			c += j - 1
			k++
		} else{
			ans = ans * c % M7
			c--
		}
	}
	Pln(ans)
}
const M7 = 1000000007
type Scanner struct{
	*bufio.Scanner
}
func NewScanner(r io.Reader, x int) *Scanner{
	s := bufio.NewScanner(r)
	s.Split(scanWords)
	if x <= 0{
		x = 1048576
	}
	s.Buffer([]byte{}, x)
	return &Scanner{s}
}
func (s *Scanner) Int() int{
	s.Scan()
	i, e := strconv.ParseInt(s.Text(), 10, 64)
	if e != nil{
		panic(e)
	}
	return int(i)
}
func (s *Scanner) ArrayIntx(n, m int) IntSlice{
	r := make(IntSlice, m)
	for i := 0; i < n; i++{
		r[i] = s.Int()
	}
	return r
}
func isSpace(b byte) bool{
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(d []byte, e bool) (int, []byte, error){
	s := 0
	for s < len(d) && isSpace(d[s]){
		s++
	}
	for i := s; i < len(d); i++{
		if isSpace(d[i]){
			return i + 1, d[s:i], nil
		}
	}
	if e && len(d) > s{
		return len(d), d[s:], nil
	}
	return s, nil, nil
}
func Pln(s ...interface{}){
	fmt.Println(s...)
}
type ByteSlice []byte
type IntSlice []int
func (p IntSlice) Len() int{ return len(p) }
func (p IntSlice) Less(i, j int) bool{ return p[i] < p[j] }
func (p IntSlice) Swap(i, j int){ p[i], p[j] = p[j], p[i] }
func (p IntSlice) SortR(){ sort.Sort(sort.Reverse(p)) }


Measured memory_bytes: 640
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<deque>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(double i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int const INF = 1000000;
int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    deque<ll> s;
    s.push_front(a[0]);
    bool f=true;
    if(n%2==0){
        f=false;
    }
    for(int i=1;i<n;i++){
        if(f){
            s.push_back(a[i]);
        }else{
            s.push_front(a[i]);
        }
        f=!f;
    }
    for(auto itr=s.begin();itr!=s.end();itr++){
        cout<<*itr<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 5376
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String p = sc.nextLine();
        String xa = s + s;
        if(xa.contains(p)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 26256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }
    vvi G(n);
    rep(i, n-1) {
        int j, k;
        cin >> j >> k;
        --j; --k;
        G[j].push_back(k);
        G[k].push_back(j);
    }

    vi lis(n, INT_MAX);
    lis[0] = a[0];
    vi ans(n);
    function<void(int, int)> dfs = [&](int i, int j) {
        ans[i] = distance(lis.begin(), lower_bound(all(lis), INT_MAX));
        for(int ne:G[i]) {
            if(ne == j) continue;
            vi::iterator itr = lower_bound(all(lis), a[ne]);
            int num = *itr;
            *itr = a[ne];
            dfs(ne, i);
            *itr = num;
        }
    };

    dfs(0, -1);

    rep(i, n) {
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 33640
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
template<typename T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#endif 


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

    ll N, W; cin >> N >> W;
    vl w(N + 1, 0); vl v(N + 1, 0);
    ll wMin = LINF;
    FOR(i, 1, N + 1) {
        cin >> w[i] >> v[i];
        wMin = min(wMin, w[i]);
    }

    vi dw(N + 1, 0);
    FOR(i, 1, N + 1) dw[i] = w[i] - wMin;
    ll dwMax = 3;

    auto dp = vector<vector<map<ll, ll>>>(N + 2, vector<map<ll, ll>>(N + 2, map<ll, ll>()));

    FOR(i, 1, N + 1) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= dwMax * i; k++) {
                if (k + dw[i] <= dwMax * i) {
                    chmax(dp[i + 1][j + 1][k + dw[i]], dp[i][j][k] + v[i]);
                }

                chmax(dp[i + 1][j][k], dp[i][j][k]);
            }
        }
    }

    ll ans = 0;
    for (int j = 0; j <= N; j++) {
        for (int k = 0; k <= dwMax * N; k++) {
            ll w = wMin * j + k;
            if (w <= W) {
                ans = max(ans, dp[N + 1][j][k]);
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

string max_num(string l, string r) {
    if (l.size() != r.size()) {
        if (l.size() < r.size()) return r;
        return l;
    }
    if (l < r) return r;
    return l;
}

int main() {
    int W, H;
    while (cin >> W >> H, W) {
        vector<string> mat(H);
        for (int i = 0; i < H; ++i) { cin >> mat[i]; }

        string secret = "";
        vector<vector<string>> dp(H + 1, vector<string>(W + 1, ""));
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                if (isalpha(mat[i][j])) continue;

                string t = string(1, mat[i][j]);
                if (dp[i][j + 1] != "0") {
                    t = max_num(t, dp[i][j + 1] + string(1, mat[i][j]));
                }
                if (dp[i + 1][j] != "0") {
                    t = max_num(t, dp[i + 1][j] + string(1, mat[i][j]));
                }
                dp[i + 1][j + 1] = t;
                secret = max_num(secret, t);
            }
        }
        cout << secret << endl;
    }
    return 0;
}


Measured memory_bytes: 3128
# snuke 君は自転車を買いに来ました。
# snuke 君はすでに買う自転車を決めたのですが、
# その自転車にはベルが付いていないため、
# 自転車とは別にベルも買う必要があります。
# snuke 君は安全意識が高いので、
# ベルをどちらの手でも鳴らせるよう、
# 両方のハンドルに 1 つずつ 付けることにしました。
# お店にあるベルは 3 種類で、それぞれ a円、 b円、 c円です。
# この 3 つのうち、異なる 2 つのベルを選んで買うときの、
# 値段の合計の最小値を求めて下さい。

input_line = gets.chomp.split
a = input_line[0].to_i
b = input_line[1].to_i
c = input_line[2].to_i

sum_a_b = a + b
sum_a_c = a + c
sum_b_c = b + c

min = sum_a_b

if min > sum_a_c
  min = sum_a_c
end

if min > sum_b_c
  min = sum_b_c
end

puts min


Measured memory_bytes: 1788
#!/usr/bin/perl
  
use Data::Dumper;

$in = <>;
$in =~ s/[\r\n]+$//g;
@n = split //,$in;
@r = ();
$max = 0;

for($i=0;$i<@n;$i++) {
        $m = &r(\@n,$i);
        $max = ($m>=$max)?$m:$max;
}
$m = 0;
for($i=0;$i<@n;$i++) {
        $m += $n[$i];
}
$max = ($m>$max)?$m:$max;

print $max;

sub r($$) {
$ref = shift;
$x   = shift;
my $ret = 0;
my $f = 1;
for(my $i=0;$i<@{$ref};$i++) {
        if($i==$x) {
                if(${$ref}[$i]==0) {
                        $f = 0;
                        next;
                }
                $ret += ${$ref}[$i]-1;
        } elsif($i<$x) {
                $ret += ${$ref}[$i];
        } elsif($f) {
                $ret += 9;
        } else {
                $ret += ${$ref}[$i];
        }
}
return $ret;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, W;
  cin >> n >> W;
  
  vector<int> w(n), v(n);
  for(int i = 0; i < n; i++) cin >> w.at(i) >> v.at(i);
  
  vector<vector<long long>> dp(n, vector<long long>(W + 1, 0));
  dp.at(0).at(w.at(0)) = v.at(0);
  for(int i = 1; i < n; i++){
    for(int j = 0; j <= W; j++){
      if(j >= w.at(i)) dp.at(i).at(j) = max(dp.at(i - 1).at(j - w.at(i)) + v.at(i), dp.at(i - 1).at(j));
      else dp.at(i).at(j) = dp.at(i - 1).at(j);
    }
  }
  
  long long ans = 0;
  for(int i = 0; i <= W; i++) ans = max<long long>(ans, dp.at(n - 1).at(i));
  cout << ans << '\n';
}

Measured memory_bytes: 79488
/*
	*#*#*#* Author GaryMr *#*#*#*
########################################################################
	是否可以简化问题：
	抓住数据范围哪里小
	dfs or bfs
	是否可以化具体为抽象
	字符串问题是否可以用数学模拟递归过程（取c[i]或不取来算结果）
	二分？左闭右开？
	long long？
	逆向思维？
	dp？
	贪心？
	匹配括号 左减右>=0
	多组数据清空？
	dp优化用g？
	线段树：大小为n的8倍
	线段树：左闭右开！
	线段树：find： if(l>=b||r<=a) return 0x3f3f3f3f; if(r<=b&&l>=a) return tree[k];
	线段树：满二叉树 
	循环跳出条件 
	代数设出每个值寻找关系？
	优先队列：priority_queue<类型> q;   
	priority_queue<类,vector<类>, less<类> > pq1; 　　　 // 使用递减	
	priority_queue<类，vector<类>, greater<类> > pq2; 　　// 使用递增
	判断括号，判断是否长度为偶数
	1<<ceil(log2(double(n)))
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;a++)
#define rl(a,b,c) for(int a=b;a>=c;a--)
#define niv vector<int>
#define LL long long
#define IT iterator
#define FIR first
#define SEC second
using namespace std;
const int MAX=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
pair<int,mp > dp[3001][3001];
string s=" ",t=" ",tmp1,tmp2;
void dfs_printer(int i,int j){
	if(i&&j){
		dfs_printer(dp[i][j].SEC.FIR,dp[i][j].SEC.SEC);
		if(dp[i][j].SEC.FIR==i-1&&dp[i][j].SEC.SEC==j-1){
			printf("%c",s[i]);
		}
	}
}
int main(){
	cin>>tmp1;s+=tmp1;
	cin>>tmp2;t+=tmp2;
	int len1=s.length(),len2=t.length();
	len1-=1;len2-=1;
	rb(i,1,len1){
		rb(j,1,len2){
			if(s[i]==t[j]){
				dp[i][j].FIR=dp[i-1][j-1].FIR+1;
				dp[i][j].SEC.FIR=i-1;dp[i][j].SEC.SEC=j-1;
			}
			else{
				if(dp[i][j-1].FIR>dp[i-1][j].FIR){
					dp[i][j].FIR=dp[i][j-1].FIR;
					dp[i][j].SEC.FIR=i;dp[i][j].SEC.SEC=j-1;
				}
				else{
					dp[i][j].FIR=dp[i-1][j].FIR;
					dp[i][j].SEC.FIR=i-1;dp[i][j].SEC.SEC=j;
				}
			}
//			cout<<dp[i][j]<<" ";
		}//cout<<endl;
	}
	dfs_printer(len1,len2);
	return 0;
}

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

int kindmax=-1,i,j,k;

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

    int vec[n][n];

    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            vec[i][j]=-1;//証言無し
        }
    }

    for(i=0;i<n;i++){//証人の番号
        int a;cin>>a;//証言の個数
        for(j=0;j<a;j++){
            int x,y;
            cin>>x>>y;x--;
            vec[i][x]=y;
        }
    }

    
    
    for(i=0;i<(1<<n);i++){//iはn人の人が正直か不親切かを割り当てる
        int num=0;//正直者の人数    
        bool AC=true;//全体で矛盾がないか

        for(j=0;j<n;j++){//j人目の証言について
            if((i>>j)&1){//honestの時のみ調べる
                for(k=0;k<n;k++){
                    if(vec[j][k]==-1){continue;}//-1は証言無し
                    if(vec[j][k]!=((i>>k)&1)){AC=false;}//証言が間違い->矛盾
                }
                num++;
            }
        }
        if(AC){if(kindmax<num){kindmax=num;}}
    }

    cout<<kindmax<<endl;
    return 0;
}


Measured memory_bytes: 256