akhauriyash/Code-Regression huggingface dataset:
import string
H, W = map(int, input().split())
table = [input().split() for _ in range(H)]
for h in range(H):
    for w in range(W):
        if table[h][w] == "snuke":
            c1 = string.ascii_uppercase[w]
            print(c1 + str(h + 1))
            exit()


Measured memory_bytes: 4020
#include <bits/stdc++.h>
#define N 100006
using namespace std;
int n,c[N],a[N],b[N];long long ans,s[N];
inline int read()
{
	int x=0,c=getchar(),f=1;while(c<'0'||c>'9')f=(c=='-'?-f:f),c=getchar();
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+c-48,c=getchar();return f>0?x:-x;
}
void print(long long x)
{
	if(x>9)print(x/10);putchar(x%10+48);
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)b[i]=read();sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)c[i]=read();sort(c+1,c+n+1);
	for(int i=n,h=n;i>0;i--){
		while(c[h]>b[i])h--;
		s[i]=s[i+1]+n-h;
	}
	for(int i=n,h=n;i>0;i--){
		while(b[h]>a[i])h--;
		ans+=s[h+1];
	}
	print(ans);puts("");
}

Measured memory_bytes: 2304
using System;

class IntroductionD
{
    static void Main()
    {
        var s = int.Parse( Console.ReadLine() );
        var h = s / 3600;
        var m = s % 3600 / 60;
        Console.WriteLine( "{0}:{1}:{2}", h, m, s % 60 );
    }
}

Measured memory_bytes: 19900
#include <bits/stdc++.h>
#define ll long long
#define all(x) begin(x), end(x)
#define range(x) begin(x), begin(x)
#define what(x) cout << #x << ": " << x << '\n'
#define print(x) for (auto &el: x) cout << el << ' '; cout << '\n'
using namespace std;
 
template<typename S, typename T>
ostream& operator <<(ostream &os, pair<S, T> &m) { 
    os << '[' << m.first << " " << m.second << ']'; 
    return os; 
}

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

    ll n;
    cin >> n;

    string res = "";
    while(n > 0) {
        n--;
        res += 'a' + n % 26;
        n /= 26;
    }
    reverse(all(res));
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

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

  bool ok = true;
  int skip = min_element(a.begin(), a.end()) - a.begin();
  int small = *min_element(a.begin(), a.end());
  while (ok) {
    ok = false;
    int div = small;
    int pre_skip = skip;
    for (int i = 0; i < a.size(); i++) {
      if (i == pre_skip) continue;
      a[i] %= div;
      if (a[i] != 0 && small > a[i]) {
        ok = true;
        small = a[i];
        skip = i;
      }
    }
  }

  cout << accumulate(a.begin(), a.end(), 0) << endl;
  return 0;
}


Measured memory_bytes: 3668
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N, K;
	cin >> N >> K;
	int res = K;
	REP(i, N - 1) res *= K - 1;
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = inf;
    rep(c, 200001) {
        int a = max(0, X - c / 2);
        int b = max(0, Y - c / 2);
        chmin(ans, A * a + B * b + C * c);
    }
    out(ans);
}


Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
u = set(s) | set(t)
l = []

for i in u:
    cnt = 0
    for j in s:
        if i == j:
            cnt += 1
    for k in t:
        if i == k:
            cnt -= 1
    l.append(cnt)
print(max(0, max(l)))

Measured memory_bytes: 3064
# n = int(input())
in_data = [int(x) for x in input().split(' ')]
x = in_data[0]
y = in_data[1]
result = 'No'

patterns = []

for i in range(x+1):
  patterns.append(2*i + 4*(x-i))
    

if y in patterns:
  result = 'Yes'
    
print(result)

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

int main() {
    int N;
    int A[101];
    cin >>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]%2==0){
            if((A[i]%3!=0)&&(A[i]%5!=0)){
                cout <<"DENIED";
                return 0;
            }
        }
    }
    cout << "APPROVED";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
struct team{int i, u, a, p;team(int,int,int,int);};
team::team(int _i, int _u, int _a, int _p)
	:i(_i), u(_u), a(_a), p(_p) {}

bool tsort(const team& l, const team& r){
	if(l.a == r.a){
		if(l.p == r.p)return l.i < r.i;
		return l.p < r.p;
	}
	return l.a > r.a;
}

int main(){
	int n;
	while(std::cin >> n, n){
		int i, u, a, p;
		std::vector<team> v;
		while(n--){
			std::cin >> i >> u >> a >> p;
			team t = team(i, u, a, p);
			v.push_back(t);
		}
		
		std::sort(v.begin(), v.end(), tsort);
		
		int steam = 0;
		std::map<int, int> m;
		std::vector<team>::iterator it = v.begin();
		while(it != v.end()){
			if(steam < 10){
				if(m[(*it).u] < 3){
					std::cout << (*it).i << std::endl;
					steam++, m[(*it).u]++;
				}
			}
			else if(steam < 20){
				if(m[(*it).u] < 2){
					std::cout << (*it).i << std::endl;
					steam++, m[(*it).u]++;
				}
			}
			else if(steam < 26){
				if(!m[(*it).u]){
					std::cout << (*it).i << std::endl;
					steam++, m[(*it).u]++;
				}
			}
			it++;
		}
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt();
		long ans = 0;
		sc.close();
		if(m > 2 && n > 2)ans += (long)(n - 2) * (long)(m - 2);
		if(n <= 1 && m > 2)ans += (long)m - 2;
		if(n > 2 && m <= 1)ans += (long)n - 2;
		if(n == 1 && m == 1)ans = 1;
		System.out.println(ans);
	}

}


Measured memory_bytes: 22740
#include <stdio.h>

int main ( void ) {
	int height[10] , max[3] = {0} , i , j;
	
	for ( i = 0; i < 10; i++ )
		scanf("%d",&height[i]);
	
	for ( i = 0; i < 10; i++ ) {
		if ( max[0] < height[i] ) {
			max[2] = max[1];
			max[1] = max[0];
			max[0] = height[i];
		} else if ( max[1] < height[i] ) {
			max[2] = max[1];
			max[1] = height[i];
		}else if ( max[2] < height[i] )
			max[2] = height[i];
	}
	printf("%d\n%d\n%d\n",max[0],max[1],max[2]);
	return 0;
}

Measured memory_bytes: 0
fun main(args: Array<String>) {
    abc063b()
}

fun abc063b() {
    val s = readLine()!!.toCharArray()

    val answer = s.groupBy { it }.maxBy { it.value.size }?.value
        ?.let { if (it.size > 1) "no" else "yes" }

    println(answer)
}


Measured memory_bytes: 29864
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	int N, a, b, c, d; cin >> N;
	int floor[4][3][10] = {};
	rep(i, N) {
		cin >> a >> b >> c >> d;
		floor[a - 1][b - 1][c - 1] += d;
	}
	rep(i, 4) {
		rep(j, 3) {
			rep(k, 10) cout << " " << floor[i][j][k];
			cout << endl;
		}
		if (i != 3)cout << "####################" << endl;
	}
	cin >> N;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)

using namespace std;
typedef long long ll;
const int N = 102;

int n, a[N], b[N];

int main(){
    ios_base::sync_with_stdio(0);

    cin >> n;
    f1(i, n) cin >> a[i];
    f1(i, n) b[i] = a[i];

    int res = 0;
    for(int i = 1; i <= n; i++){
        if(b[i]==b[i + 1]){
            res++;
            i++;
        }
    }
    cout << res;
}



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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(A==B) {
    cout <<  C;
  }
  else if(B==C) {
    cout << A;
  }
  else{
    cout << B;
  }
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

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

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;

int dfs (int v, int par) {
	int left = k-1-(par>0);
	ll res = 1;
	for (auto to : g[v]) if (to != par) {
		res *= dfs(to, v);
		res %= mod;
		res *= left;
		res %= mod;
		--left;
	}          
	return res;
}

int main () {
	SpeedForce;
	setIO();
	cin >> n >> k;
	for(int i = 1, a, b; i < n; ++i) {
		cin >> a >> b;
		g[a].pb(b);
		g[b].pb(a);
	}
	for(int i = 1; i <= n; ++i) if(g[i].size() > k) {
		cout << 0 << endl;
		return 0;
	}
	cout << dfs(1, 0) * (ll)k % mod << endl;

	return Accepted;
}

// B...a

Measured memory_bytes: 25352
#関数リスト
import sys
input = sys.stdin.readline

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))


n = I()
a = 0
b = 0
c = 0
d = 0

for i in range(n):
    temp = input().rstrip()
    if temp == "AC":
        a+=1
    elif temp == "WA":
        b+=1
    elif temp == "TLE":
        c+=1
    elif temp == "RE":
        d+=1
        
print("AC x "+str(a))
print("WA x "+str(b))
print("TLE x "+str(c))
print("RE x "+str(d))

Measured memory_bytes: 73752
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const string MINUSINF = "-";

void chmax(string &a, string b) {
    if (a == MINUSINF) a = b;
    else if (a.size() < b.size()) a = b;
    else if (a.size() == b.size()) {
        if (a < b) a = b;
    }
}

long long match[10] = {2,5,5,4,5,6,3,7,6};
string dp[11000];

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

    // 初期化
    for (int i = 0; i < 11000; ++i) dp[i] = MINUSINF;

    // 初期条件
    dp[0] = "";

    // DP ループ
    for (int i = 0; i <= N; ++i) {
        if (dp[i] == MINUSINF) continue;
        for (auto a : A)  chmax(dp[i+match[a-1]], dp[i] + (char)('0' + a));
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 43776
#include <cstdio>
#include <vector>

using namespace std;

const int MAX_N = 100005;

int main() {
    int n, l;
    long long max_time = 0;
    vector<int> lens(MAX_N, 0);
    vector<int> valleys;

    scanf("%d %d", &n, &l);
    for (int i = 1; i <= n; i++) {
        int ai;
        scanf("%d", &ai);
        lens[i] = ai;
    }

    valleys.push_back(1);
    for (int i = 2; i <= n - 1; i++) {
        if (lens[i] < lens[i - 1] && lens[i] < lens[i + 1]) {
            valleys.push_back(i);
        }
    }
    valleys.push_back(n);

    for (auto& pos: valleys) {
        auto left_time = l - lens[pos], right_time = l - lens[pos];
        auto left_peak = pos;
        while (lens[left_peak - 1] > lens[left_peak]) {
            left_time += l - lens[--left_peak];
        }
        auto right_peak = pos;
        while (lens[right_peak + 1] > lens[right_peak]) {
            right_time += l - lens[++right_peak];
        }
        if (left_time > max_time) { max_time = left_time; }
        if (right_time > max_time) { max_time = right_time; }
    }

    printf("%lld\n", max_time);

    return 0;
}

Measured memory_bytes: 3160
N,X = map(int,input().split(' '))

'''
N = 2
X = 7
'''

def ban(n):
	if n == 0:
		return 'P'
	return 'B'+ban(n-1)+'P'+ban(n-1)+'B'

def ans(n,x):
	if x <= 0:
		return 0
	if n == 0:
		return 1
	s = 2**(n+2) - 3
	a = (s-3)//2
	if x < 2+a:
		return ans(n-1,x-1)
	if x == 2+a:
		return ans(n-1,x-1)+1
	p = 2**(n)-1
	return p + 1+ans(n-1,x-2-a)

print(ans(N,X))

#ans = ban(N)[0:X]
#print(ans.count('P'))



Measured memory_bytes: 3064
N = int(input())
A = [int(v) for v in input().split()]


def gcd(a, b):
    if a > b:
        a, b = b, a

    if a == 0: return b
    return gcd(a, b % a)


L = [0 for _ in range(N + 2)]
R = [0 for _ in range(N + 2)]

for i, a in enumerate(A):
    L[i + 1] = gcd(A[i], L[i])
    R[N-i] = gcd(A[N-i-1], R[N-i+1])

# print(L)
# print(R)

res = -2
for i in range(1, N+1):
    res = max(res, gcd(L[i-1], R[i+1]))
print(res)


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

int main() {
	long long n,k,q,i,t;
	cin >> n >> k >> q;
	vector<long long> a(n,0);
	for(i=0; i<q; i++){
		cin >> t;
		a[t-1]++;
	}
	for(i=0; i<n; i++){
		a[i]=k-q+a[i];
		if(a[i]>0){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
}

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

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

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

  int N;
  cin >> N;

  vector<int> A(N);

  for(int i=0; i<N; ++i){
    cin >> A[i];
  }
  sort(A.begin(), A.end());

  bool own = true;

  for(int i=0; i<N-1; ++i){
    if(A[i] == A[i+1]) own = false;
  }

  if(own) cout << "YES" << '\n';
  else cout << "NO" << '\n';

  return 0;
}

Measured memory_bytes: 1024
H, W = map(int, input().split())

room = [[True if c == "." else False for c in input()] for _ in range(H)]

count = []

for i in range(H):
    count.append([0] * W)

for row in range(H):
    start = 0
    for col in range(W):
        if not room[row][col]:
            if col != 0:
                plus = col - start
                for i in range(start, col):
                    count[row][i] += plus
            start = col + 1
    if room[row][W - 1]:
        plus = W - start
        for i in range(start, W):
            count [row][i] += plus

for col in range(W):
    start = 0
    for row in range(H):
        if not room[row][col]:
            if row != 0:
                plus = row - start
                for i in range(start, row):
                    count[i][col] += plus
            start = row + 1
    if room[H - 1][col]:
        plus = H - start
        for i in range(start, H):
            count[i][col] += plus

ans = 0

for rowline in count:
    ans = max(max(rowline), ans)

print((ans - 1))

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,m;
  cin >> n >> m;
  vector<int64> a(n);
  REP(i,n)cin >> a[i];
  vector<int64> asum(n+1);
  asum[0] = 0;
  REP(i,n)asum[i+1] = (asum[i] + a[i]) % m;
  map<int64,int64> cnt;
  REP(i,n+1){
    cnt[asum[i]]++;
  }
  int64 ans = 0;
  for(pll x : cnt){
    ans += x.second * (x.second - 1) / 2;
  }
  ANS(ans);
  return 0;
}

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

using namespace std;

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

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
typedef unsigned long long ul;

ul gcd(ul x, ul y){
	if(y == 0)
		return x;
	else
		return gcd(y, x%y);
}

int main(){
	int n;
	vector<ul> a;

	cin>>n;
	for(int i=0;i<n;i++){
		ul temp;
		cin>>temp;
		a.push_back(temp);
	}

	for(int i=0;i<n-1;i++){
		a[i+1] = a[i] * a[i+1] / gcd(a[i], a[i+1]);
	}

	cout<<a[n-1]<<endl;
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> a(n),c(n+1);
  int i=0,j=0;
  rep(i,n)cin>>a[i];
  rep(i,n){
      j=a.at(i);
      c[j]++;}
  for(i=1;i<n+1;i++)cout<<c[i]<<endl;
    
  return 0;
}

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

using namespace std;

#define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
#define dbg(x) cerr << (#x) << " --> " << (x) << endl

#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)

#define type(x) __typeof(x.begin())

#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)

#define pb push_back
#define mp make_pair

#define nd second
#define st first

#define endl '\n'

typedef pair < int ,int > pii;

typedef long long ll;

const long long linf = 1e18+5;
int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9 + 9;
const int N = 2e5 + 5;

int n, m, x, y, z, t, k, q, dp[N], a[N];
vector< int > v[N];
int ans;

int solve(int node, int root, int got) {
    if(got < 0) return 0;
    int mx1 = 0, mx2 = 0;
    int sum = 1;
    foreach(it, v[node])
        if(*it != root) {
            sum += solve(*it, node, got - 1);
        }
    return sum;
}

int get(int x) {
    if( k % 2 == 0 ) return solve(x, 0, k / 2);
    int ans = solve(x, 0, k / 2), s2 = 0;
    foreach(it, v[x]) {
        s2 = max(s2, solve(*it, x, k / 2) - solve(*it, x, k / 2 - 1));
    }
    return ans + s2;
}

int main() {
    scanf("%d %d", &n, &k);
    FOR(i, 2, n) {
        scanf("%d %d", &x, &y);
        v[x].pb(y);
        v[y].pb(x);
    }
    int a = 0;
    FOR(i, 1, n) {
        ans = 0;
        a = max(a, get(i));
    }
    cout << n - a << endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
using namespace std;
typedef long long ll;
const ll INF = 1e15;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }
  ll ans = 0;
  REP(i, n) {
    ans += a[i] / 2;
    a[i] = a[i] % 2;
    if (i != n - 1 && a[i + 1] > 0) {
      ans += a[i];
      a[i + 1] -= a[i];
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 5000001
#define NIL -1

int key[MAX],n,count = 0;

int parent(int p){
  return p/2;
}

int right(int p){
  return 2*p+1;
}

int left(int p){
  return 2*p;
}

void maxHeapify(int p){
  int l,r,largest=NIL,temp;
  l = left(p);
  r = right(p);

  if(l <= count && key[l]>key[p]) largest = l;
  else largest = p;
  if(r<= count && key[r]>key[largest]) largest = r;
  if(largest != p){
    temp = key[p];
    key[p] = key[largest];
    key[largest] = temp;
    maxHeapify(largest);
  }

}

void buildMaxHeap(){
  int i;
  for(i = count/2; i > 0; i--){
    maxHeapify(i);
  }
}

void heapIncreaseKey(int p,int in){
  int temp,i;

  if(in < key[p]){
    exit(1);
  }

  key[p] = in;

  while(p > 1 && key[parent(p)] < key[p]){
    temp = key[p];
    key[p] = key[parent(p)];
    key[parent(p)] = temp;

    p = parent(p);
  } 
}

void maxHeapInsert(int in){
  int i;
  count++;
  key[count] = NIL;
  heapIncreaseKey(count,in);
}


int heapExtractMax(){
  int max;
  if(count < 1){
    exit(1);
  }

  max = key[1];
  key[1] = key[count];
  count--;

  maxHeapify(1);

  return max;
}


int main(){
  int i,v,max;
  char com[20];


  for ( i = 0; i < MAX; i++ ){
    key[i] = NIL;
  }

  while(strcmp(com,"end") != 0){
    scanf("%s",com);
    if(com[0] == 'i'){
      scanf("%d" ,&v);
      maxHeapInsert(v);
    }
    else if(com[1] == 'x'){
      max = heapExtractMax();
      printf("%d\n",max);
    }
  }
  return 0;
}

Measured memory_bytes: 20132
#include <iostream>
using namespace std;
 
int main(){
    //入力を受け取る
    int K,A,B;
    cin >> K >> A >> B;

  if (K + A + B <= 21) {
    cout << "win" << endl;
  }
  else if (K + A + B >= 22) {
    cout << "bust" << endl;
  }
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
    int a, b;
    while (scanf("%d %d", &a, &b) != EOF) {
        int temp = a + b;
        int dig = (int)log10((double)temp) + 1;
        cout << dig << endl;
    }
}

Measured memory_bytes: 1252
s = input()
if (s == "SSS"):
  print("0")
elif (s == "SSR"):
  print("1")
elif (s == "SRS"):
  print("1")
elif (s == "RSS"):
  print("1")
elif (s == "SRR"):
  print("2")
elif (s == "RSR"):
  print("1")
elif (s == "RRS"):
  print("2")
else:
  print("3")

Measured memory_bytes: 9116
using System;
using System.Collections.Generic;

class Program
{
	public class Data
	{
		public string name;
		public int time;

		public Data(string name, int time)
		{
			this.name = name;
			this.time = time;
		}
	};

	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int q = int.Parse(input[1]);

		List<Data> data = new List<Data>();

		for(int i=0; i<n; i++)
		{
			string[] str = Console.ReadLine().Split(' ');
			string name = str[0];
			int time = int.Parse(str[1]);
			data.Add(new Data(name, time));
		}

		int total = 0;
		while(data.Count > 0)
		{
			if(data[0].time - q <= 0)
			{
				total += data[0].time;
				Console.WriteLine(data[0].name + " " + total);			
			}
			else
			{
				total += q;
				data[0].time -= q;
				data.Add(new Data(data[0].name, data[0].time));
			}
			data.RemoveAt(0);
		}
 	}
}

Measured memory_bytes: 15640
n = int(input())
h = list(map(int, input().split()))


can = True
for i in range(n-1, 1, -1):
  if n == 1:
    break
  elif h[i-1] <= h[i]:
    continue
  elif (h[i-1] - 1) <= h[i]:
    h[i-1] -= 1
    continue
  else:
    can = False
    break

if can == True:
  print('Yes')
else:
  print('No')

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

int main(){
  string s[3];
  rep(i,3) cin >> s[i];
  cout << s[0][0] << s[1][1] << s[2][2] << endl;
  return 0; 
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

a, b = MAP()
if a >= 13:
    print(b)
elif 6 <= a <= 12:
    print(b // 2)
elif 5 >= a:
    print(0)

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 105;
string ar;
int k, n;
ll dp[N + 2][2][5];
ll F(int pos, int choto, int dis){
  if (dis > k){
    return 0;
  }
  if (pos >= n){
    if (dis == k){
      return 1;
    } 
    return 0;
  }
  if (dp[pos][choto][dis] != -1){
    return dp[pos][choto][dis];
  }
  ll sum = 0;
  if (choto){
    for (int i = 0; i < 10; i++){
      sum += F(pos + 1, choto, dis + (i != 0));
    }
  } else {
    int d = ar[pos] - '0';
    for (int i = 0; i <= d; i++){
      sum += F(pos + 1, i < d, dis + (i != 0));
    }
  }
  return dp[pos][choto][dis] = sum;
}

int main(){
  FASTER;
  memset(dp, -1, sizeof dp);
  cin >> ar;
  n = ar.size();
  cin >> k;
  cout << F(0, 0, 0) << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

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

	int M, D;
	cin >> M >> D;
	int answer = 0;
	FOR(m, 1, M)
		FOR(d, 1, D)
			if(9 < d and d < 100) {
				int d1 = d % 10,
					d10 = (d - d1) / 10;
				if(d1 >= 2 and d10 >= 2 and d1 * d10 == m)
					++answer;
			}
	cout << answer << '\n';
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int N;
    cin >> N;
    set<string> st;
    string a, b;
    cin >> a;
    auto r = st.insert(a);
    bool res = true;
    REP(i, N-1){
        cin >> b;
        r = st.insert(b);
        if(a[a.length()-1]!=b[0] || r.second==false){
            res = false;
            break;
        }
        a = b;
    }
    cout << (res ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	int N;
	cin >> N;
	string s;
	cin >> s;
	s = " " + s;

	vector<ll> lb(N + 2, 0);
	vector<ll> rw(N + 2, 0);
	for (int i = 1; i <= N + 1; ++i) {
		lb[i] += lb[i - 1];
		if (s[i] == '#') { ++lb[i]; }
	}
	for (int i = N; i >= 0; --i) {
		rw[i] += rw[i + 1];
		if (s[i] == '.') { ++rw[i]; }
	}

	int res = N;
	for (int i = 0; i <= N; ++i) {
		int tmp = lb[i] + rw[i + 1];
		res = min(res, tmp);
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<pair<ll, ll>> b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = {a[i], i};
    }
    sort(b.rbegin(), b.rend());
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1));
    for (int z = 1; z <= n; z++) {
        for (int x = 0; x <= z; x++) {
            int y = z - x;
            if (x) dp[x][y] = max(dp[x][y], dp[x - 1][y] + b[z - 1].first * (b[z - 1].second - x + 1));
            if (y) dp[x][y] = max(dp[x][y], dp[x][y - 1] + b[z - 1].first * (n - y - b[z - 1].second));
        }
    }
    ll ans = 0;
    for (int i = 0; i <= n; i++) {
        ans = max(ans, dp[i][n - i]);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 34564
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)

int main()
{
    lli a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*c,max(b*d,max(a*d,b*c)))<<endl;
}


Measured memory_bytes: 3632
x, y = map(int, input().split())
l = [1, 3, 5, 7, 8, 10, 12]
m = [4, 6, 9, 11]
n = [2]
if l.count(x) == l.count(y) != 0 or m.count(x) == m.count(y) != 0 or x == y == 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
using System;
class A
{
    static void Main()
    {
        while (true)
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 0) { break; }
            string a = Console.ReadLine();
            for (int i = 0; i < n; i++)
            {
                string UI = "";
                int j = 0;
                int continuing = 1;
                for (j=1; j < a.Length; j++)
                {
                    if (a[j - 1] == a[j]) { continuing++; }
                    else { UI += continuing.ToString() + a[j - 1]; continuing = 1; }
                }
                UI += continuing.ToString() + a[j - 1];
                a = UI;
            }Console.WriteLine(a);
        }
    }
}

Measured memory_bytes: 10292
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> query;
typedef vector<vector<ll>> matrix;

int n;
int l[100005];
const int MOD = 1000000007;
void solve() {
  cin >> n;
  int i = 0;
  ll ret = 1;
  for(int qq = 0; qq < n; qq++) {
    cin >> l[i];
    if(i) {
      l[i] = min(l[i], l[i-1] + 2);
    }
    else {
      l[i] = min(1, l[i]);
    }
    if(i && l[i] == l[i-1]+1) {
      ret *= i+1;
      ret %= MOD;
    }
    else {
      i++;
    }
  }
  while(i > 1) {
    ret *= i--;
    ret %= MOD;
  }
  cout << ret << "\n";
}

void casesolve() {
  int t;
  cin >> t; cin.ignore();
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

class element{
private:
    string name;
    bool end;
    int time;
public:
    element(){}
    element(string n, int t) {
        name = n;
        time = t;
        end  = false;
    }
    int processing(int q) {
        if (time > q) {
            time -= q;
            return q;
        }
        int ret = time;
        time = 0;
        end = true;
        return ret;
    }
    string get_name() {
        return name;
    }
    int get_time() {
        return time;
    }
    bool get_end() {
        return end;
    }
};

class table{
private:
    element* e;
    int n;
    int process_time;
    int head;
    int tail;
    int total_time;
    bool is_empty;

    element de_que() {
        if (head == tail) is_empty = true;
        element ret = e[head];
        if (head < n - 1) {
            head++;
        } else {
            head = 0;
        }
        return ret;
    }

    void processing() {
        element e1 = de_que();
        total_time += e1.processing(process_time);
        if (e1.get_end()) {
            cout << e1.get_name() << " " << total_time << endl;
            return;
        }
        en_que(e1);
    }
public:
    table(int n_in, int p_in) {
        n = n_in;
        e = new element[n];
        process_time = p_in;
        head =  0;
        tail = -1;
        total_time = 0;
        is_empty = true;
    }
    void en_que(element input_element) {
        if (tail < n - 1) {
            tail++;
        } else {
            tail = 0;
        }
        if (is_empty) is_empty = false;
        e[tail] = input_element;
    }
    void all_processing() {
        while(!is_empty) {
            processing();
        }
    }
};


int main(void)
{
    int n, p_time;
    cin >> n >> p_time;
    table t(n, p_time);
    for (int i = 0; i < n; i++) {
        string name;
        int time;
        cin >> name >> time;
        element e(name, time);
        t.en_que(e);
    }
    t.all_processing();
    return 0;
}

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

int main()
{
    int x, n;
    cin >> x >> n;
    int a[n];
    int ans = INT_MAX;
    map<int, int> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        m[a[i]]++;
    }
    int i = 0;
    while (1)
    {
        if (m[x - i] == 0)
        {
            ans = x - i;
            break;
        }
        else if (m[x + i] == 0)
        {
            ans = x + i;
            break;
        }
        i++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n&&n){
    vector<int> d(n);
    for(int i=0;i<n;++i) cin>>d[i];
    sort(d.begin(),d.end());
    int s=d[1]-d[0];
    for(int i=1;i<n-1;++i)
      if(s>d[i+1]-d[i]) s=d[i+1]-d[i];
    cout<<s<<endl;
  }
  return 0;
}



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

int main() {
	ll n, k;
	cin >> n >> k;
	ll r, s, p;
	cin >> r >> s >> p;
	string t;
	cin >> t;
	ll ans = 0;
	vector<bool> win(n, true);
	for (ll i = 0; i < k; ++i) {
		if (t[i] == 'r')ans += p;
		else if (t[i] == 's')ans += r;
		else ans += s;
		cerr << i << ":" << ans << endl;
	}
	for (ll i = k; i < n; ++i) {
		if (t[i] != t[i - k] || (!win[i - k])) {
			if (t[i] == 'r')ans += p;
			else if (t[i] == 's')ans += r;
			else ans += s;
		}
		else {
			win[i] = false;
		}
		cerr << i << ":" << ans << endl;
	}
	cout << ans << endl;
}


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

// dfs（深さ優先探索）
// https://qiita.com/drken/items/4a7869c5e304883f539b

void dfs(vector<vector<pair<int, int>>> &g, vector<int> &c, int v, int p, int pc) {
	int now = 1;
	for(auto t: g[v]) {
		int nv = t.first;
		int nc = t.second;
		if(nv == p) continue;
		if (pc == now) now++;
		c[nc] = now;
		dfs(g, c, nv, v, now);
		now++;
	}
}

int main() {
	int n, k = 0;
	cin >> n;
	vector<vector<pair<int, int>>> g(n);
	vector<pair<int, int>> e(n-1);
	rep(i, n-1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(make_pair(b, i));
		g[b].push_back(make_pair(a, i));
	}
	vector<int> c(n-1);
	dfs(g, c, 0, -1, 0);
	rep(i, n) {
		k = max(k, (int) g[i].size());
	}
	cout << k << endl;
	rep(i, n-1) cout << c[i] << endl;
	return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A<C) {
        cout << max(min(B, D)-C, 0) << endl;
    } else {
        cout << max(min(B, D)-A, 0) << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
using ll = long long;



int main() {
	int x,a=0,b=0;
	cin >> x;
	a = x / 500;
	x %= 500;
	b = x / 5;
	cout << a * 1000 + b * 5 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

lint n, a[100005], dp[100005];
lint sum[100005];
int nxt[100005];
string s[100005];

lint getsum(int ss, int e){
	return sum[e] - sum[ss-1];
}

lint getcost(int x){
	lint ret = 0;
	int w = nxt[x];
	return -getsum(x, w-1) + getsum(w, n);
}

int main(){
	scanf("%lld %lld",&n, &a[1]);
	sum[1] = a[1];
	for(int i=2; i<=n; i++){
		cin >> s[i] >> a[i];
		sum[i] = sum[i-1] + a[i];
	}
	nxt[n+1] = n+1;
	for(int i=n; i>=2; i--){
		if(s[i] == "+"){
			nxt[i] = nxt[i+1];
			dp[i] = dp[i+1] + a[i];
		}
		else{
			nxt[i] = i;
			dp[i] = max(dp[i+1] - a[i], getcost(i+1) - a[i]);
		}
	}
	cout << dp[2] + a[1] << endl;
}



Measured memory_bytes: 8448
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();
		int ans = 0;
		if(B <= C || D <= A) {
			ans = 0;
		} else if(C <= A && A <= D && D <= B){
			ans = D - A;
		} else if(C <= A && B <= D) {
			ans = B - A;
		} else if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
import glob
import numpy as np
import collections


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\134\\C'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class C(Common):

    def resolve(self):

        seq_len = int(self.input_data())
        seq = np.zeros(seq_len, dtype=np.int)
        for i in range(seq_len):
            seq[i] = int(self.input_data())

        max_num = np.max(seq)
        times = collections.Counter(seq)[max_num]

        if times >= 2:
            for i in range(seq_len):
                print(str(max_num))
        else:
            for i in range(seq_len):
                if seq[i] != max_num:
                    print(str(max_num))
                else:
                    print(np.max(np.hstack((seq[0:i], seq[i+1:seq_len]))))


solver = C(REL_PATH)
solver.exec_resolve()


Measured memory_bytes: 25924
a,b,x = map(int,input().split())
import numpy as np
S = x/a
if S <= a*b/2:
    theta = np.rad2deg(np.arctan(b*b/(2*S)))
else:
    S = a*b-S
    theta = np.rad2deg(np.arctan(2*S/(a*a)))
print(theta)

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






int main() {
  int N;cin>>N;
  int min1=10000000;
  int max1=0;
  rep(i, N){
    int x;cin>>x;;
    max1=max(x,max1);
    min1=min(x,min1);
  }
  cout<<max1-min1<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int t[500000];
void add(int i,int x){
  while(i<500000){
    t[i]+=x;
    i += i&-i;
  }
}

int sum(int i){
  int res=0;
  while(i){
    res+=t[i];
    i -= i&-i;
  }
  return res;
}

map<int,int> mp;
set<P> s;
int q,lim;
int a,b,c;

int main(){

  
  while(1){
    memset(t,0,sizeof(t));
    scanf("%d %d",&q,&lim);
    if(q==0&&lim==0)break;
    mp.clear();
    s.clear();
    c=1;
    while(q--){
      scanf("%d %d",&a,&b);
      if(a==0){
        s.insert(P(c,b));
        add( c , 1 );
        mp[b]=c++;
        if((int)s.size()>lim){
          add( s.begin()->first , -1 );
          s.erase(s.begin());
        }
      }else if(a==1){
        int L=1,R=c-1,M;
        while(L<R){
          M=(L+R)/2;
          if(sum(M)<b)L=M+1;
          else R=M;
        }
        s.erase( s.lower_bound(P(L,0)) );
        add( L , -1 );
      }else if(a==2){
        int L=1,R=c-1,M;
        while(L<R){
          M=(L+R)/2;
          if(sum(M)<b)L=M+1;
          else R=M;
        }

        P target = *s.lower_bound(P(L,0));
        printf("%d\n",target.second);
        
      }else{
        add( mp[b], -1 );
        s.erase( P(mp[b],b) );        
      }
      
    }
    printf("end\n");
  }
  return 0;
}

Measured memory_bytes: 24980
#include <iostream>
#include <vector>
#include <bitset>
#include <set>
#include <algorithm>
#include <map>
 
 
using namespace std;
 
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pll, int> para;
const ll inf = 2e18 + 7;
const int maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;
 
int n, arr[maxN], arr2[maxN], cnt2[maxN], cnt[maxN];
vector<pii> v1, v2;
 
int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	REP(i, n / 2) {
		cin >> arr[i];
		cnt[arr[i]]++;
		cin >> arr2[i];
		cnt2[arr2[i]]++;
	}
	REP(i, maxN - 1) {
		if (cnt[i] > 0) v1.pb(pii(cnt[i], i));
		if (cnt2[i] > 0) v2.pb(pii(cnt2[i], i));
	}
	v2.pb(pii(0, -100));
	v1.pb(pii(0, -100));
	sort(v1.begin(), v1.end(), greater<pii>());
	sort(v2.begin(), v2.end(), greater<pii>());
	int ans = 0;
	//cout << v1[0].st << " " << v1[0].nd << " " << v1[1].st << " " << v1[1].nd << endl;
	//	cout << v2[0].st << " " << v2[0].nd << " " << v2[1].st << " " << v2[1].nd << endl;
	if (v1[0].nd == v2[0].nd) {
		ans = min(n - v1[0].st - v2[1].st, n - v1[1].st - v2[0].st);
		ans = max(ans, 0);
	} else {
		ans = n - v1[0].st - v2[0].st;
	}
	cout << ans << endl;
	return 0;
}


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

vector<vector<int>> al;

void dist(int r, int i, vector<int> &d) {
  d[i] = r;
  for(int n : al[i]) {
    if(d[n] != -1) continue;
    dist(r+1, n, d);
  }
}

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

  al = vector<vector<int>>(n, vector<int>(0));
  rep(i,n-1) {
    int s,t;
    scanf("%d %d", &s, &t);
    al[s-1].push_back(t-1);
    al[t-1].push_back(s-1);
  }

  vector<int> fd(n, -1), sd(n, -1);
  fd[0] = 0;
  sd[n-1] = 0;
  dist(0, 0, fd);
  dist(0, n-1, sd);

  int fs = 0, ss = 0;
  rep(i,n) {
    if(fd[i] <= sd[i]) {
      fs++;
    } else {
      ss++;
    }
  }

  if(fs > ss) {
    printf("Fennec\n");
  } else {
    printf("Snuke\n");
  }

  return 0;
}


Measured memory_bytes: 11136
import java.util.Scanner;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	private static int[] mcxi = {
	        1000, 100, 10, 1
	};
	private static char[] s = {
	        'm', 'c', 'x', 'i'
	};
	static Pattern pt = Pattern.compile("(([2-9]?)m)?(([2-9]?)c)?(([2-9]?)x)?((\\d?)i)?");
	static Matcher mc = pt.matcher("");

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < 2; j++) {
				mc.reset(in.next()).matches();
				sum += val(mc);
			}
			sb.setLength(0);
			for (int j = 0; j < 4; j++) {
				int mn = sum / mcxi[j];
				sum %= mcxi[j];
				if (mn > 0) {
					if (mn > 1) {
						sb.append(mn);
					}
					sb.append(s[j]);
				}
			}
			System.out.println(sb);
		}
	}

	static int val(MatchResult mr) {
		int result = 0;
		for (int i = 0; i < 4; i++) {
			if (mr.group(i * 2 + 1) != null) {
				result += mcxi[i] * ((!mr.group(i * 2 + 2).isEmpty()) ? Integer.parseInt(mr.group(i * 2 + 2)) : 1);
			}
		}
		return result;
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <list>
#include <string.h>
using namespace std;

#define M 1046527
#define MIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
	if( ch == 'A' ) return 1;
	else if ( ch == 'C' ) return 2;
	else if ( ch == 'G' ) return 3;
	else if ( ch == 'T' ) return 4;
	else return 0;
}

long long getKey(char str[]) {
	long long sum = 0, p=1, i;
	for( i = 0; i < strlen(str); i++) {
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key) {return key % M; }
int h2(int key) {return 1 + (key % (M-1));}

int find(char str[]) {
	long long key, i, h;
	key = getKey(str);
	for( i = 0;; i++) {
		h = (h1(key) + i*h2(key)) % M;
		if( strcmp(H[h], str) == 0 ) return 1;
		else if( strlen(H[h]) == 0 ) return 0;
	}
	return 0;
}

int insert(char str[]) {
	long long key, i, h;
	key = getKey(str);
	for( i = 0;; i++) {
		h = (h1(key) + i*h2(key)) % M;
		if(strcmp(H[h], str) == 0) return 1;
		else if( strlen(H[h]) == 0) {
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main() {
	int n;
	char com[6], str[4];
	cin >> n;
	for(int i = 0; i < M; i++) H[i][0] = '\0';
	for(int i = 0; i < n; i++) {
		scanf("%s %s", com, str);
		if( com[0] == 'i' ) {
			insert(str);
		} else if( com[0] == 'f' ) {
			if( find(str) ) {
				printf("yes\n");
			} else printf("no\n");
		}
	}
	return 0;
}

Measured memory_bytes: 15472