akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>

#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--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
typedef pair<int, int>P;

int dx[4] = { 1,0,-1,0 };//D,R,U,L
int dy[4] = { 0,1,0,-1 };

int N, Q;
int a[100010], x[100010], cum2[100010];
vector<int>sum, bor, vec,cum;
signed main() {
	m0(cum2);
	cum.pb(0);
	cin >> N >> Q;
	REP(i, N) {
		cin >> a[i];
		cum2[i + 1] = a[i];
		if (N % 2 != i % 2) {
			cum.pb(a[i]);
			vec.pb(a[i]);
		}
	}
	REP(i, Q)cin >> x[i];
	REP(i, N) {
		cum2[i + 1] += cum2[i];
	}
	REP(i, (N + 1) / 2) {
		cum[i + 1] += cum[i];
	}
	bor.pb(-1 * INF); bor.pb(INF);
	int cnt = 0;
	while (cnt < (N - 1) / 2) {
		int r = N - 2 - cnt;
		int l = N - 3 - 2 * cnt;
		bor.pb((a[l] + a[r]) / 2);
		cnt++;
	}
	REP(i, (N + 1) / 2) {
		int res = cum[i] + cum2[N] - cum2[N - (N+1)/2+i];
		sum.pb(res);
	}
	VSORT(sum); VREVERSE(sum);
	VSORT(bor);

	REP(i, Q) {
		auto itr = lb(bor,x[i]);
		int it = itr - bor.begin();
		print(sum[it-1]);
	}

	/*for (auto y : bor) {
		pe(y);
	}cout << endl;
	for (auto y : sum) {
		pe(y);
	}cout << endl;
	REP(i, N)pe(cum2[i + 1]); cout << endl;
	REP(i, (N + 1) / 2)pe(cum[i + 1]); cout << endl;*/

}


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

int main(){
    int n,x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i,n) cin >> l.at(i);
    int d = 0;
    int ans = 1;
    rep(i,n){
        d += l.at(i);
        if(d > x)break;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
#define MAX_VAL 100
#define INF 12345678

int d[MAX_VAL][MAX_VAL];
int V = 0;

void warshall_floyd(){
	for(int k = 0; k < V; k++)
		for(int i = 0; i < V; i++)
			for(int j = 0; j < V; j++) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
}

int main(){
	int n, m, f, t, cost;
	
	while(true){
		int ans = INF, num = 0;
		cin>>n;
		
		if(!n) break;
	
	
		for(int i = 0; i < 10; i++)
			for(int j = 0; j < 10; j++)if(i==j)d[i][j]=INF;else d[i][j]=INF;
	
	
		V = 0;
	
		for(int i = 1; i <= n; i++){
			cin>>f>>t>>cost;
			d[f][t] = d[t][f] = cost;
			d[f][f] = d[t][t] = 0;
			V = max(V,max(f,t));
		}
		V++;
	
		warshall_floyd();
		
		for(int i = 0; i < V; i++){
			int sum = 0;
			for(int j = 0; j < V; j++){
				sum += d[i][j];
			}
			if(ans > sum){
				ans = sum;
				num = i;
			}
		}
		cout<<num<<" "<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll ctdigits(ll n)
{
    ll ct=0;
    while(n!=0)
    {
        n=n/10;
        ct++;
    }
    return ct;
}


int main()
{

      ll n;
      cin>>n;
      ll ans = n*n;
      cout<<ans<<endl;
}


Measured memory_bytes: 256
S = input()
ret = 0
for i in range(2**(len(S)-1)):
    #print("i:" + str(iå))
    s = S
    bin_i = format(i, 'b')
    bin_i =bin_i[::-1]
    #print(bin_i)
    for j in range(len(bin_i)):
        #print(bin_i[j])
        
        #print(bin_i)
        if bin_i[j] == "1":
            #print("入った")
            #s = s[:j + 1] + "+" + s[j + 1:]
            s = s[:-len(S) + j + 1] + "+" + s[-len(S) + j + 1:]
    #print(s)
    ret += eval(s)
print(ret)

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

int main() {
  ll n,m,c[50000];
  cin>>n>>m;

  ll dp[50001];
  fill(dp, dp + 50001, 50001);
  dp[0] = 0;
  for (ll i = 0; i < m; i++)
  {
    cin>>c[i];
    dp[c[i]]=1;
  }
  
  for (ll i = 1; i <= n; i++)
  {
    for (ll j = 0; j < m; j++)
    {
      if (i>=c[j]) {
        if (dp[i-c[j]]<50001) {
          dp[i]=min(dp[i],dp[i-c[j]]+1);
        }
      }
    }
    //cout<<dp[i]<<endl;
  }
  cout<<dp[n]<<endl;

  return 0;
}



Measured memory_bytes: 3512
def resolve():
    from collections import deque
    n = int(input())
    ans = 0
    num = deque([3,5,7])
    while num[0] <= n:
        test = num.popleft()
        num.append(test * 10 + 3)
        num.append(test * 10 + 5)
        num.append(test * 10 + 7)
        if list(set([int(x) for x in list(str(test))])) == [3,5,7]:
            ans += 1
    print(ans)

resolve()

Measured memory_bytes: 45148
#include <stdio.h>

int main(){
    
    int nums[234][3];
    int scores[234]={};
    int N;
    
    scanf("%d",&N);
    
    for(int i =0;i<N;i++){for(int j =0;j<3;j++){scanf("%d",&nums[i][j]);}}
    
    for(int g =0;g<3;g++){
        for(int i =0;i<N;i++){
            bool get = true;
            for(int j=0;j<N;j++){
                if(i!=j && nums[i][g]==nums[j][g]) get=false;
            }
            if(get) scores[i]+=nums[i][g];
        }
    }
    
    for(int i =0;i<N;i++){
        printf("%d\n",scores[i]);
    }
    
    return 0;
}

Measured memory_bytes: 2696
#c
x,n = map(int,input().split())
p_list = list(map(int,input().split()))

dis = 1000
for i in range(-100,102):
    if i not in p_list:
        sub = abs(x-i)
        dis = min(dis,sub)
            
if x-dis in p_list:
    print(x+dis)
else:
    print(x-dis)

Measured memory_bytes: 9156
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=998244353;
#define INF 2*1e9
#define N 600010
#define MAX_V 900010
using namespace std;
int visited[N],num[N];
int mem,p[N],s;
vector<int> G[N];
int dfs(int x){
    vector<int> v;
    rep(i,G[x].size()){
        if(G[x][i]==mem)continue;
        v.pb(dfs(G[x][i]));
    }
    sort(v.begin(),v.end());
    if(v.size()==0){
        return num[x]=0;
    }
    int a=-1;
    rep(i,v.size()){
        if(v[i]==a+1){a++;continue;}
        if(v[i]==a){continue;}
        break;
    }
    a++;
    return num[x]=a;
}
int dfs2(int x){
    vector<int> v;
    rep(i,G[x].size()){
        if(G[x][i]==mem)continue;
        v.pb(dfs2(G[x][i]));
    }
  if(x==p[mem])v.pb(s);
    sort(v.begin(),v.end());
    
    if(v.size()==0){
        return num[x]=0;
    }
    int a=-1;
    rep(i,v.size()){
        if(v[i]==a+1){a++;continue;}
        if(v[i]==a){continue;}
        break;
    }
    a++;
    return num[x]=a;
}
main(){
    int n;cin>>n;
    rep2(i,1,n){
        cin>>p[i];
        G[p[i]].pb(i);
    }
    int temp=1;
    visited[1]=1;
    while(1){
        if(visited[p[temp]])break;
        visited[p[temp]]=1;
        temp=p[temp];
    }
    mem=temp;
    if(dfs(temp)!=num[p[temp]]) {cout<<"POSSIBLE";return 0;}
    s=num[p[temp]];
    if(s==dfs2(temp)){cout<<"POSSIBLE";}
    else cout<<"IMPOSSIBLE";
    
}




Measured memory_bytes: 41984
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define _START_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _END_ return 0;

using namespace std;

int main()
{   
    _START_
    
    int ac = 0, wa = 0, tle = 0, re = 0;
    ll int T, tcase;
    cin >> T;
    for (tcase = 1; tcase <= T; tcase++)
    {
        string s;
        cin >> s;
        if (s == "AC")
            ++ac;
        else if (s == "WA")
            ++wa;
        else if (s == "TLE")
            ++tle;
        else
            ++re;
    }
    cout<< "AC x " << ac << endl
        << "WA x " << wa << endl
        << "TLE x " << tle << endl
        << "RE x " << re << endl;
    
    _END_
}

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

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mp[a]++;
  }
  int ans = 0;
  for (auto i : mp) {
    int a = i.first, b = i.second; //a:あるべき数　b:今の数
    if (a < b)
      ans += b - a;
    else if (b < a)
      ans += b;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4736
N = int(input())
A = list()
T = list()

for i in range(N):
    x, y = map(int, input().split())
    A.append(x)
    T.append(y)

x = T[0]
y = A[0]

for i in range(1, N):
    k1 = T[i] - x
    k2 = A[i] - y
    if k1 == 0 and k2 == 0:
        continue

    l = 0
    r = 1000000000000000000
    mid = 0
    t1 = k1
    t2 = k2
    while r - l > 1:
        mid = (r + l) // 2
        k1 = T[i] * mid - x
        k2 = A[i] * mid - y
        if k1 == 0 and k2 == 0:
            t1 = 0
            t2 = 0
            break
        if k1 >= 0 and k2 >= 0:
            t1 = k1
            t2 = k2
            r = mid
        else:
            l = mid
    x += t1
    y += t2
    # print("%d %d" % (x, y))

print(x + y)

Measured memory_bytes: 3064
#include<stdio.h>
int main() {
   int h, n;
   int a = 0;
	scanf("%d %d", &h, &n);
	int x[n];
   
	for(int i = 0; i < n; i++) {
		scanf("%d", &x[i]);
		a = a+x[i];
	}
   
	if(a >= h) {
		printf("Yes");
	}
	else {
      printf("No");
   }
   printf("\n");
	return 0;
}


Measured memory_bytes: 2112
n = int(input())
ab = [0] * n
for i in range(n):
  ab[i] = [int(j) for j in input().split()]
ab.sort(key=lambda x: x[1])
t = 0
for i in ab:
    t += i[0]
    if t > i[1]:
        print('No')
        exit()
print('Yes')


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

using namespace std;


int main()
{
    long long res = 0;
    int n;
    cin >> n;
    for(int i = 1; i <=n; i++){
        if(i%3 != 0 && i%5 != 0){
            res+=i;
        }
    }
    cout << res;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>

using namespace std;

int main() {
	string a;
	string b;
	int counter = 0;
	cin >> b;
	for (int i = 0; i < b.size(); i++) {
		if (isupper(b[i])) {
			b[i] = tolower(b[i]);
		}
	}
	while (cin >> a) {
		if (a == "END_OF_TEXT") {
			break;
		}
		for (int i = 0; i < a.size(); i++) {
			if (isupper(a[i])) {
				a[i] = tolower(a[i]);
			}
		}
		if (a == b) {
			counter++;
		}
	}
	cout << counter << endl;
	return 0;
}

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

int main() {
  int N, K, a, b, o;
  o = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i ++){
    a = o * 2;
    b = o + K;
    if (a < b){
      o = a;
    }else{
      o = b;
    }
  }
  cout << o << endl;
}

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

const int maxn = 100000 + 10;

int h[maxn];

int main()
{
	int n;
	cin >> n;
	
	int max = -1;
	int count = 0;
	int p = -1;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (h[i] > p) {
			if (count > max) max = count;
			count = 0;
		}
		else count++;

		p = h[i];
	}
	
	if (count > max) max = count;

	cout << max;

	return 0;
}

Measured memory_bytes: 640
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val s = (1..n).map { sc.next() }

  val map = mutableMapOf<Char, Long>()
  for (si in s) {
    val c = si[0]
    if (c == 'M' || c == 'A' || c == 'R' || c == 'C' || c == 'H') {
      val tmp = map.getOrElse(c) { 0 }
      map.put(c, tmp+1)
    }
  }

  val size = map.values.size
  if (size <= 2) {
    println(0)
    return
  }

  var ans = 0L
  val list = map.values.toList()
  for (i in 0 until size) {
    val si = list[i]
    for (j in i+1 until size) {
      val sj = list[j]
      for (k in j+1 until size) {
        val sk = list[k]
        ans += si * sj * sk
      }
    }
  }

  println(ans)

}

Measured memory_bytes: 64572
#include <iostream>
// #include <vector>
// #include <algorithm>
#include <string>

int main(){
	std::string s;
	std::cin >> s;
	for(int i=0; i<(int)s.size(); i++){
		if((i%2==1 and s[i]=='R') or (i%2==0 and s[i]=='L')){
			std::cout << "No" << std::endl;
			return 0;
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = [tuple(map(int, line.split())) for line in sys.stdin.buffer.readlines()]

for P, Q, R in zip(A, A[1:], A[2:]):
    if P[0] == P[1] and Q[0] == Q[1] and R[0] == R[1]:
        print('Yes')
        break
else:
    print('No')
    

Measured memory_bytes: 61904
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

using Table = vector< pair<int, int> >;
const pair<int, int> INIT(INF, 0);

int A[5010];
vector<int> G[5010];

Table merge(const Table &A, const Table &B) {
    int N = A.size(), M = B.size();
    Table res(N + M, INIT);
    for(int i=N-1; i>=0; i--) {
        for(int j=M-1; j>=0; j--) {
            // 和を考える
            chmin(res[i+j].first, A[i].first + B[j].first);
            if(B[j].first < 0 or B[j].second) chmin(res[i+j+1].first, A[i].first);

            // 全て正になるか考える
            res[i+j].second |= A[i].second & B[j].second;
            if(B[j].first < 0 or B[j].second) res[i+j+1].second |= A[i].second;
        }
    }
    return res;
}

Table solve(int cur, int par=-1) {
    Table res_dp(1);
    res_dp[0].first = A[cur];
    res_dp[0].second = (A[cur] > 0);
    for(auto to : G[cur]) {
        if(to == par) continue;
        Table child_dp = solve(to, cur);
        res_dp = merge(res_dp, child_dp);
    }
    return res_dp;
}

signed main() {
    int N; cin >> N;    
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }
    for(int i=0; i<N-1; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    auto dp = solve(0);
    int ans = INF;
    for(int i=0; i<N; i++) {
        if(dp[i].first < 0) ans = min(ans, i);
        if(dp[i].second == true) ans = min(ans, i);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  string a, b;
  cin >> a >> b;
  int ans = a.size();
  for (int i = 0; i + b.size() - 1 < a.size(); ++i) {
    int cnt = 0;
    for (int j = 0; j < b.size(); ++j) {
      cnt += a[i + j] != b[j];
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3640
import java.util.*;

class Main {
	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		long L;
		L = sc.nextLong();
		solve(L);
	}

	static void solve(long L) {
		StringBuilder sb = new StringBuilder();
		long n = 0;
		long a = 1;
		while (a <= L) {
			a *= 2;
			n++;
		}
		a /= 2;

		sb.append(n).append(" ");
		List<long[]> es = new ArrayList<>();
		int b = 1;
		for (long i = 1; i < n; i++) {
			es.add(new long[]{i, i + 1, 0});
			es.add(new long[]{i, i + 1, b});
			b *= 2;
		}

		long x = 1;
		long t = n - 1;
		for (int i = 0; i < t; i++) {
			x *= 2;
		}


		while (t >= 0) {
			if (L - x >= a) {
				es.add(new long[]{t + 1, n, L - x});
				L -= x;
			}
			x /= 2;
			t--;
		}

		sb.append(es.size()).append("\n");
		for (int i = 0; i < es.size(); i++) {
			sb.append(es.get(i)[0]).append(" ")
					.append(es.get(i)[1]).append(" ")
					.append(es.get(i)[2]).append("\n");
		}

		System.out.print(sb.toString());
	}
}


Measured memory_bytes: 21716
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int main()
{
	string s;
	cin >> s;
	cout << ((s[0] == s[2]) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n, i, R[200000];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &R[i]);
  }

  int minv = R[0], maxv = R[1] - minv;

  for(i = 1; i < n; i++){

    if(maxv < R[i] - minv){
      maxv = R[i] - minv;
    }
    else if(R[i] < minv){
      minv = R[i];
    }
  }
    printf("%d\n", maxv);
}



Measured memory_bytes: 2532
<?php

while (($line = trim(fgets(STDIN))) !== '') {
    sscanf($line, '%f', $v);
    $t = $v / 9.8;
    $y = 4.9 * pow($t, 2);
    $N = 1;
    while (($n = 5 * $N - 5) < $y) {
        $N++;
    }
    echo $N, PHP_EOL;
}

Measured memory_bytes: 6612
n,k,q = map(int,input().split())
ans_list =[]
point = []
for i in range(n):
  point.append(k)
#print(point)      
for j in range(q):
  ans_list.append(int(input()))
#print(ans_list)
for k in ans_list:
  point[k-1] += 1
#print(point)
for l in range(n):
  point[l] -= q
  if point[l]>0:
    print("Yes")
  else:
    print("No")
#print(point)

Measured memory_bytes: 11760
N = int(input())
l = [int(x) for x in input().split()]
ans = 1
if l.count(0) > 0:
    print(0)
    exit()
for i in range(N):
    ans = ans * l[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 21640
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

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

	if (A*N <= B) cout << A*N;
	else cout << B;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define int long long
#define INF 1e+9
using namespace std;

signed main(){
	string s;
	cin >> s;
	sort(s.begin(),s.end());
	if(s == "abc") cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

void func_c(int N) {
	vector<pair<int, int>> d(N);
	vector<int> input(N);
	if (N % 2 == 0) {
		for (int i = 0; i < N; i++) {
			cin >> input[i];
		}
		for (int i = 0; i < N; i++) {
			d[i] = make_pair(input[i], i);
		}
		sort(d.begin(), d.end());

		int K = (d[0].first + d[N - 1].first) / 2;


			int cnt = d[N / 2].first - d[N / 2 - 1].first;
			if (cnt)
				cout << cnt;
			else
				cout << 0;
		
	}
	else {
		cout << 0;
	}
}

int main()
{
	int N;
	cin >> N;
	func_c(N);
}

Measured memory_bytes: 1408
// https://atcoder.jp/contests/abc173/tasks/abc173_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll H, W, K;
  cin >> H >> W >> K;

  V<string> mat(H);
  rep(h, H) cin >> mat[h];

  ll res = 0;

  rep(col_bit, 1 << W) rep(row_bit, 1 << H) {
    ll black_ct = 0;

    rep(h, H) rep(w, W) {
      bool masked = (col_bit & (1 << w)) || (row_bit & (1 << h));
      if (masked) continue;

      if (mat[h][w] == '#') black_ct++;
    }

    if (black_ct == K) res++;
  }

  cout << res << "\n";
}


Measured memory_bytes: 3540
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = n * (n+1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;


const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main(){
  int X, A;
  cin >> X >> A;
  if(X < A) cout << 0 << endl;
  else cout << 10 << endl;
  return 0;
}


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

using namespace std;

int main() {
	int w, a, b;
	cin >> w >> a >> b;
	if (a <= b &&b <= a + w || b <= a &&a <= b + w)cout << 0 << endl;
	else cout << (abs(b - a + w) > abs(a - b + w) ? abs(a - b + w) : abs(b - a + w)) << endl;
}

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

void solve(long long N, string S){
	map<P, ll> m;
	for (ll i = 0; i < 1<<N; i++) {
		string s1 = "", s2 = "";
		for (ll j = 0; j < N; j++) {
			if (i>>j&1) s1 += S[j]; else s2 += S[j];
		}
		// cout << s1 << " " << s2 << "\n";
		m[P(make_pair(s1, s2))]++;
	}
	// cout << m[P(make_pair("c", "aba"))] << "\n";
	ll res = 0;
	for (ll i = 0; i < 1<<N; i++) {
		string s1 = "", s2 = "";
		for (ll j = 2*N-1; j >= N; j--) {
			if (i>>(2*N-1-j)&1) s1 += S[j]; else s2 += S[j];
		}
		// cout << s1 << " " << s2 << "\n";
		res += m[P(make_pair(s1, s2))];
	}
	cout << res << "\n";
}

int main(){
	string S;
	long long N;
	scanf("%lld",&N);
	cin >> S;
	solve(N, S);
	return 0;
}


Measured memory_bytes: 91904
#include <stdio.h>
int main () {
	
	int a,b,c, count = 0;
	int j;
	scanf("%d %d %d", &a, &b, &c);
	
	for (int i = a; i <= b; i = i + a){
		count++;
		if(count >= c){
			break;
		}
		//count++;
	}
	
	printf("%d", count);
	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  int ans = a + b;
  if (ans < 10)
    cout << ans << endl;
  else
    cout << "error";
  return 0;
}


Measured memory_bytes: 256
from sys import stdin

class LinkedList():
    def __init__(self):
        self.head = [None, None, None]
        self.head[1] = self.pos = self.tail = [self.head, None, None]

    def insert(self, x):
        temp = [self.pos[0], self.pos, x]
        self.pos[0][1] = self.pos[0] = self.pos = [self.pos[0], self.pos, x]

    def move_right(self, d):
        for _ in range(d):
            self.pos = self.pos[1]

    def move_left(self, d):
        for _ in range(d):
            self.pos = self.pos[0]

    def move(self, d):
        if d > 0:
            self.move_right(d)
        else:
            self.move_left(d * -1)

    def erase(self):
        self.pos[1][0] = self.pos[0]
        self.pos = self.pos[0][1] = self.pos[1]

    def to_list(self):
        index = self.head[1]
        out = []
        while(index[1] is not None):
            out.append(index[2])
            index = index[1]
        return out

n = stdin.readline()
queries = stdin.readlines()
ll = LinkedList()
#count = 0
for query in queries:
    #print(count)
    #count += 1
    query = query.split()
    if query[0] == '0':
        ll.insert(query[1])
    elif query[0] == '1':
        ll.move(int(query[1]))
    else:
        ll.erase()

print('\n'.join(ll.to_list()))




Measured memory_bytes: 110816
import java.util.Scanner;

public class Main {
	long day(int y, int m, int d) {
		long res = 0;
		for (int i = 1; i < y; i++) {
			if (i % 3 == 0) {
				res += 20 * 10;
			} else {
				res += 20 * 5 + 19 * 5;
			}
		}
		for (int i = 1; i < m; i++) {
			if (y % 3 == 0) {
				res += 20;
			} else {
				if (i % 2 == 0) {
					res += 19;
				} else {
					res += 20;
				}
			}
		}
		res += d;
		return res;
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		long m = day(1000, 1, 1);
		for (int T = sc.nextInt() - 1; 0 <= T; T--) {
			long a = day(sc.nextInt(), sc.nextInt(), sc.nextInt());
			System.out.println(m - a);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 20580
import sys
import numpy as np
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 1~1000の累計和
a = [i for i in range(1,1000)]
s = np.cumsum(a)
s_list=list(s)
N = int(read())
if N ==1:
  print(0)
  sys.exit()
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

arr = factorization(N)
ans = 0
for p in arr:
  index = bisect.bisect_right(s_list, p[1])
  ans += index
print(ans)

Measured memory_bytes: 27312
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    i64 ret = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        ret += a - 1;
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
n=int(input())
a,b,ab=0,0,0
ans=0
for i in range(n):
  s=input()
  if s[0]=="B":
    b+=1
  if s[len(s)-1]=="A":
    a+=1
  if s[0]=="B" and s[len(s)-1]=="A":
    ab+=1
  ans+=s.count("AB")
if a==0 and b==0:
  t=0
elif a-ab==0 and b-ab==0:
  ans+=ab-1
else:
  ans+=min(a,b)
print(ans)



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

int main() {
    string s;
    long long k;
    cin >> s >> k;
    int cnt1 = 0;
    for (int i = 0; i < (int) s.size(); i++) {
        if(s[i] == '1') cnt1++;
        else break;
    }

    if(k <= cnt1) puts("1");
    else printf("%c\n", s[cnt1]);
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;



struct Node{
    double v;
    ll orig;
    bool operator< (const Node &r) const{
        return v < r.v;
    }
};

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

    sort(a.begin(), a.end());
        

    vector<Node> b(n);
    double half = a[n-1]/2.0;
    rep(i, n)   b[i] = {abs(1.0*a[i] - half), a[i]};
    sort(b.begin(), b.end());

    cout << a[n-1] << " " << b[0].orig << endl;



    
    return 0;
}

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

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var hash = new HashSet<string>();
            for (int i = int.Parse(Console.ReadLine()); i > 0; --i) {
                var input = Console.ReadLine().Split();
                if(input[0] == "insert") {
                    hash.Add(input[1]);
                }
                else {
                    Console.WriteLine(hash.Contains(input[1]) ? "yes" : "no");
                }
            }
        }
    }
}

Measured memory_bytes: 37240
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		string S = GetString();
		bool ans = (S.Length >= 4) && (S.Substring(0, 4).Equals("YAKI"));
		Console.WriteLine(ans ? "Yes" : "No");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int N, M;
	cin >> N >> M;
	vector<vector<int>> s(M);
	for(int i = 0; i < M; i++){
		int k;
		cin >> k;
		s[i].resize(k);
		for(int j = 0; j < k; j++){
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	vector<int> p(M);
	for(int i = 0; i < M; i++){
		cin >> p[i];
	}

	int res = 0;
	for(int i = 0; i < 1<<N; i++){
		bool flag = true;
		for(int j = 0; j < M; j++){
			int num = 0;
			for(auto n: s[j]){
				if(i & 1<<n) num++;
			}
			if(num%2 != p[j]) flag = false;
		}
		if(flag) res++;
	}


	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
   public static void main(String[] args)
   {
      Scanner stdIn = new Scanner(System.in);
      int n = stdIn.nextInt();
      int ss = n%60;
      int mm = (n/60)%60;
      int hh = n/3600;
      System.out.println( hh + ":" + mm + ":" + ss );
   }
}

Measured memory_bytes: 25920
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
const long double eps = 1e-7;
ll Power(ll x, ll y) {
	ll res = 1;
	rep(i, y) {
		res *= x;
	}
	return res;
}
ll getnum(string s) {
	ll res = 0;
	for (int i = 0; i < s.size(); i++) {
		res = res * 10 + s[i] - '0';
	}
	return res;
}
int main() {
	ull a;
	cin >> a;
	string b;
	cin >> b;
	b.erase(b.begin() + 1);
	ll c = getnum(b);
	string s = to_string(a);
	string t = to_string(c);
	int n = s.size();
	int m = t.size();
	reverse(all(s));
	reverse(all(t));
	ll ans = 0;
	rep(i, m) {
		int d1 = t[i] - '0';
		ll mul1 = Power(10, i);
		rep(j, n) {
			ll d2 = s[j] - '0';
			ll mul2 = Power(10, j);
			ll tmp = d1 * d2 * mul1 * mul2;
			ans += tmp;
		}
	}
	cout << ans / 100 << endl;
	return 0;
}

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

string boin = "aiueo";
string shin = "ksthp";

bool isBoin(char c) {
  return (boin.find(c) != string::npos);
}

bool isShin(char c) {
  return (shin.find(c) != string::npos);
}

void out(string s) {
  int p = 0;
  while(!isBoin(s[p]) && s[p] != '\'') cout << s[p++];
  cout << '(' << s[p] << ')';
}

signed main(){
  string s;
  while(cin>>s,s!="#"){
    s += '\'';
    vector<string> v;
    int idx = 0;
    while(idx < s.size()){
      string hk = "";
      while(!isBoin(s[idx]) && s[idx] != '\'') {
	if(hk.size() && hk.back() == s[idx]) {
	  v.push_back(hk);
	  hk = "";
	} else if(hk.size() && hk[0] == 'n' && !isBoin(s[idx])) {
	  v.push_back(hk);
	  hk = "";
	}
	hk += s[idx];
	idx++;
      }
      v.push_back(hk+s[idx]);
      idx++;
    }
    string hoge = v.back();
    if(hoge.back() == '\'') {
      v.pop_back();
      hoge = hoge.substr(0, hoge.size()-1);
      if(hoge.size()) v.push_back(hoge);
    }
//for(string a : v) cout << a << endl;
    bool prev_b = false;
    for(int i = 0; i < v.size()-1; i++) {
      string hk = v[i];
      if(prev_b) {
	cout << hk;
	if(v[i-1].back() == 'i' || v[i-1].back() == 'u') {
	  if(!isShin(hk.back())) prev_b = false;
	} else {
	  prev_b = false;
	}
	continue;
      }
      if(hk.back() == 'i' || hk.back() == 'u') {
	if(isShin(hk[0]) && isShin(v[i+1][0])) {
	  out(hk);
	  prev_b = true;
	  continue;
	}
      }
      if(hk.back() == 'a' || hk.back() == 'o') {
	if(isShin(hk[0]) && isShin(v[i+1][0]) && v[i+1].back() == hk.back()) {
	  out(hk);
	  prev_b = true;
	  continue;
	}
      }
      cout << hk;
    }
    string piyo = v.back();
    if(!prev_b && isShin(piyo[0]) && (piyo.back() == 'i' || piyo.back() == 'u')) out(piyo);
    else cout << v.back();
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3148
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC083D_2
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            int min = int.MaxValue;
            for (int i = 0; i < S.Length - 1; i++)
            {
                if (S[i] != S[i + 1])
                {
                    int f = i + 1;
                    int t = S.Length - i - 1;
                    min = Math.Min(min, Math.Max(f, t));
                }
            }
            if (min == int.MaxValue) min = S.Length;

            Console.WriteLine(min);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] ReadLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


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

int main()
{
	ll n,t;
	cin >> n >> t;
	vector<ll> A(n);
	for(ll i = 0;i<n;i++)cin >> A[i];
	ll mn = INT_MAX;
	ll ri = 0;
	vector<ll> jj;
	for(ll i = 0;i<n;i++)
	{
		mn = min(A[i],mn);
		ri = max(A[i]-mn,ri);
	}
	mn = INT_MAX;
	for(ll i = 0;i<n;i++)
	{
		if(A[i]<mn)jj.push_back(A[i]),mn=A[i];
		if(A[i]-mn==ri)
		{
			jj.push_back(A[i]);
		}
	}
	ll cnt = 0;
	ll ans = 0;
	n = jj.size();
	for(ll i = 0;i<n-1;i++)
	{
		if(ri==jj[i+1]-jj[i])
		{cnt++;}
		else
		{cnt=0;}
		//cout<<cnt<<endl;
		ans += min(cnt*(cnt+1)/2,t*(t+1)/2);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2168
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;

int main() {
    string O, E;
    cin >> O >> E;
    int len = O.length() + E.length();
    vector<char> ans(len);
    for (int i = 0; i < len; i++) {
        if (i % 2 == 0) {
            ans[i] = O[i / 2];
        }
        else {
            ans[i] = E[i / 2];
        }
    }
    REP(i, len) {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
//import java.io.File;
import java.util.Scanner;

public class Main{
  public static void main(String[] args) throws Exception {
    //Scanner scan = new Scanner(new File("in.txt"));
    Scanner scan = new Scanner(System.in);

    int input1 = scan.nextInt();
    for(int datasets = 0; datasets < input1; datasets++) {
      int money = scan.nextInt();
      int year = scan.nextInt();

      int maxMoney = 0;

      int input2 = scan.nextInt();
      for(int howmany = 0; howmany < input2; howmany++) {
        int dummyMoney = money;
        boolean istan = scan.nextInt()==0?true:false;
        double rate = scan.nextDouble();
        int must = scan.nextInt();
        int bank = 0;

        for(int i = 0; i < year; i++) {
          int up = (int)(dummyMoney*rate);
          if(istan) bank+=up;
          else dummyMoney+=up;
          dummyMoney -= must;
        }
        dummyMoney += bank;

        if(maxMoney < dummyMoney) maxMoney = dummyMoney;
      }
      System.out.println(maxMoney);
    }
  }
}

Measured memory_bytes: 53200
def main():
  _map = map
  _range = range
  _int = int
  n, q = _map(_int, input().split())
  values = [0] * (n + 1)
  parents = [0] * (n + 1)
  results = [0] * (n + 1)
  for i in _range(n - 1):
    a, b = _map(_int, input().split())
    parents[b] = a
  for _ in _range(q):
    p, x = _map(_int, input().split())
    values[p] += x
  for i in _range(1, n + 1):
    results[i] = values[i]
    if parents[i] != 0:
      results[i] += results[parents[i]]
  print(*[results[i] for i in range(1, n + 1)])
main()


Measured memory_bytes: 31856
// https://atcoder.jp/contests/abc073/tasks/abc073_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll ans = 0;
    cin >> n;
    REP(i, n) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}


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

const int maxn=1e5+10;

int n;

int a[maxn];
int f[maxn];
int tot;

int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	tot++;
	f[tot]=a[1];
	for(register int i=2;i<=n;i++){
		if(a[i]<=f[tot])
			f[++tot]=a[i];
		else{
			int l=1,r=tot,mid;
			while(l<r){
				int mid=(l+r)>>1;
				if(a[i]>f[mid])
					r=mid;
				else
					l=mid+1;
			}
			f[l]=a[i];
		}
	}
	printf("%d\n",tot);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int h1,m1,h2,m2,k,h,m;
	cin>>h1>>m1>>h2>>m2>>k;
	h=h2-h1;
	m=m2-m1;
	if(m<0)
	{
		h--;
		m=60+m;
	}
	cout<<h*60+m-k;
	return 0;
}

Measured memory_bytes: 3592
/*
	Name: B-加法 
	Author: RoseKey
	Date: 14/02/19 16:50
	Description: 模拟+大胆猜测 
*/

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
#define LL long long
#define Rg register
#define RI register int
#define RC register char
#define ed puts("") 
#define pair pair<LL,LL>
#define space putchar(' ')
using namespace std;
    
template <typename tp> inline void read(tp & x)
{	
    x=0;
    RI f=1;
    RC c=getchar();
    while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar(); }
    while(c>='0' && c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();} 
 	x*=f;
} 	
    
template <typename Tp> inline void print(Tp x)
{		
    if(x<0) x=-x,putchar('-');
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

int n;
LL a[1000005];
LL buk[5];

int main()
{
	read(n);
	for(RI i=1;i<=n;++i)
	{
		read(a[i]);
		if(a[i]%2==0)//a[i]为偶数
		{
			buk[2]++;	
		} 
		else
			buk[1]++;
	}
	if(buk[2]%2==0 && buk[1]%2==0)//如果有偶数个偶数 且有偶数个奇数
	{
		printf("YES");
		return 0;
	} 
	if(buk[2]%2==0 && buk[1]%2==1)//如果有偶数个偶数 且有奇数个奇数
	{
		printf("NO");
		return 0;	
	} 
	if(buk[2]%2==1 && buk[1]%2==0)//如果有奇数个偶数 且有偶数个奇数
	{
		printf("YES");
		return 0;
	} 
	if(buk[2]%2==1 && buk[1]%2==1)//如果有奇数个偶数 且有奇数个奇数
	{
		printf("NO");
		return 0;	
	} 
	return 0;
}

Measured memory_bytes: 1024
import sys
readline = sys.stdin.readline

N = int(readline())
INF = 10 ** 10
dp = [INF] * (N + 1)
dp[0] = 0

for i in range(10,0,-1):
  for j in range(N + 1):
    if dp[j] != INF:
      if j + 6 ** i <= N:
        dp[j + 6 ** i] = min(dp[j + 6 ** i], dp[j] + 1)
      if j + 9 ** i <= N:
        dp[j + 9 ** i] = min(dp[j + 9 ** i], dp[j] + 1)

ans = INF
for i in range(len(dp) - 1, -1, -1):
  money = dp[i] + N - i
  if ans > money:
    ans = money
        
print(ans)

Measured memory_bytes: 9544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll l, r;
    cin >> l >> r;
    ll imn = min(r - 1, l + 2030);
    ll ans = INF;
    for (ll i = l; i <= imn; i++) {
        ll jmn = min(r, i + 2030);
        for (ll j = i + 1; j <= jmn; j++) {
            ll tmp = (i % 2019) * (j % 2019);
            ans = min(ans, tmp % 2019);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import threading
import sys
import time


def get_int(): return int(stdin.readline().strip())


def get_tuple(): return map(int, stdin.readline().split())


def get_list(): return list(map(int, stdin.readline().split()))

n = get_int()
ans = n-1
for i in range(2,n):
    temp = n//i
    if temp*i==n: temp -= 1
    ans += temp
print(ans)

Measured memory_bytes: 75208
#include<stdio.h>

int main()
{
    int N;
    char S[13],H[13],C[13],D[13];
    char e;
    int i,num;
    for(i=0;i<13;i++)
    {
        S[i]=0;H[i]=0;C[i]=0;D[i]=0;
    }
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf(" %c %d",&e,&num);
        if(e=='S')S[num-1]=1;
        else if(e=='H')H[num-1]=1;
        else if(e=='C')C[num-1]=1;
        else if(e=='D')D[num-1]=1;
    }
    for(i=0;i<13;i++)
    {
        if(S[i]==0)printf("S %d\n",i+1);
    }
    for(i=0;i<13;i++)
    {
        if(H[i]==0)printf("H %d\n",i+1);
    }
    for(i=0;i<13;i++)
    {
        if(C[i]==0)printf("C %d\n",i+1);
    }
    for(i=0;i<13;i++)
    {
        if(D[i]==0)printf("D %d\n",i+1);
    }   
    return 0;
}

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

int main(){
  int x,y,s,s1;
  while(1){
    int max=0;
    cin>>x>>y>>s;
    if((x+y+s)==0)break;
    for(int i=1;i<=s;i++)
      for(int j=1;j<=s;j++)
	if(s==i*(100+x)/100+j*(100+x)/100){
	  s1=i*(100+y)/100+j*(100+y)/100;
	  if(max<s1)max=s1;
	}
    cout<<max<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160