akhauriyash/Code-Regression huggingface dataset:
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,m,i,j,cc=0,ans=1;
    cin>>n>>m;
    map<ll,ll>check;
    ll ara[m];
    ll k=mod;
    for(i=0;i<m;i++){
        cin>>ara[i];
        if(i==0)j=ara[i];
        else {
            if(j+1==ara[i])cc=1;
        }
        check[ara[i]]=1;
    }
    if(cc==1)cout<<0<<endl;
    else {
        vector<ll>dp(n+1);
        dp[0]=1;
        for(i=0;i<n;i++){
            for(j=i+1;j<=min(n,i+2);j++){
                if(check[i]==0){
                    dp[j]+=dp[i];
                    dp[j]%=mod;
                    //cout<<i<<spc<<j<<spc<<dp[j]<<endl;
                }
            }
        }
        cout<<dp[n]<<endl;
    }
return 0;
}


Measured memory_bytes: 12416
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
n=int(input())
if n==10**18:
    print(0,0,0,10**9,10**9,0)
    exit()
print(0,0,10**9,1,10**9-n%10**9,1+n//10**9)

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

int main() {
  int c[3][3], d[3][3], e[3][3];
  for(int i = 0;i < 3;i++) { cin >> c[i][0] >> c[i][1] >> c[i][2]; }

  for(int i = 0;i < 3;i++) {
    d[i][0] = c[i][1] - c[i][0]; d[i][1] = c[i][2] - c[i][1]; d[i][2] = c[i][0] - c[i][2];
  }
 
  for(int i = 0;i < 3;i++) {
    e[0][i] = c[1][i] - c[0][i];
    e[1][i] = c[2][i] - c[1][i];
    e[2][i] = c[0][i] - c[2][i];
  }

  for(int i = 0;i < 3;i++) {
    if( d[0][i] != d[1][i] || d[1][i] != d[2][i] || d[2][i] != d[0][i] ) {
      cout << "No\n";
      return 0;
    }
  }
  
  for(int i = 0;i < 3;i++) {
    if( e[i][0] != e[i][1] || e[i][1] != e[i][2] || e[i][2] != e[i][0] ) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";  
  return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	cout << 180*(n-2) << endl;

}



Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;
using LL = long long;
 
int main() {
	int l, a, b, c, d;
	cin >> l >> a >> b >> c >> d;
	int k = a / c + (a%c == 0 ? 0 : 1);
	int m = b / d + (b%d == 0 ? 0 : 1);
	cout << l - max(k, m) << endl;
}

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

int main() {
    int N, T;
    std::cin >> N >> T;

    std::vector<int> imos(T + 1, 0);
    for (int i = 0; i < N; ++i) {
        int l, r;
        std::cin >> l >> r;
        ++imos[l];
        --imos[r];
    }

    for (int t = 1; t <= T; ++t) imos[t] += imos[t - 1];

    std::cout << *std::max_element(imos.begin(), imos.end()) << std::endl;
    return 0;
}



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

int main() {
    
    int n;
    cin >> n;
    
    vector<int> card(n);
    
    for(int i = 0; i < n; i++)
    {
        cin >> card.at(i);
    }
    sort(card.begin(),card.end());
    reverse(card.begin(),card.end());
    int a = 0, b = 0;
    for(int i = 0; i < n; i++)
    {
        if(i % 2 == 0)
        {
            a += card.at(i);
        }
        else
        {
            b += card.at(i);
        }
    }
    
    cout << a - b << endl;
}


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

int main(void){
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    rep(i,n/2){
        if(s[i] != s[n-1-i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------
int main(void) {
  int n, m;
  cin >> n >> m;

  prt((1900*m+100*(n-m))*pow(2,m));
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  // 文字列
  int n,x;
  cin >> n;// 文字列変数を宣言 
   vector<int> vec(n);
 x=1;
       for (int i = 0; i < n; i++) 
  {
    cin >> vec.at(i);
  }
  // 配列
             for(int i=0;i<n;i++)
  {
  x=vec.at(x-1);
    if(x==2)
    {
      cout<<i+1<<endl;break;
    }
  }
  if(x!=2)
  {
    cout << -1 << endl; 
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    string s;
    ll k;
    cin >> s >> k;
    for (int i = 0; i < k; i++)
    {
        if (s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin>>a;
    cin>>b;
    cin>>c;
    if(a<=b&&b<=c){
        cout<<a;
        cout<<" ";
        cout<<b;
        cout<<" ";
        cout<<c<<endl;
    }
    else if(a<=c&&c<=b){
        cout<<a;
        cout<<" ";
        cout<<c;
        cout<<" ";
        cout<<b<<endl;
    }
    else if(b<=a&&a<=c){
        cout<<b;
        cout<<" ";
        cout<<a;
        cout<<" ";
        cout<<c<<endl;
    }
    else if(b<=c&&c<=a){
        cout<<b;
        cout<<" ";
        cout<<c;
        cout<<" ";
        cout<<a<<endl;
    }
    else if(c<=a&&a<=b){
        cout<<c;
        cout<<" ";
        cout<<a;
        cout<<" ";
        cout<<b<<endl;
    }
    else if(c<=b&&b<=a){
        cout<<c;
        cout<<" ";
        cout<<b;
        cout<<" ";
        cout<<a<<endl;
    }
}




Measured memory_bytes: 3080
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int cnt = 0;
    int M;
    if(N%2 == 0) M = N+1;
    else M = N;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j < i; j++){
            if((i+j) != M) cnt++;
        }
    }
    cout << cnt << endl;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j < i; j++){
            if((i+j) != M) cout << i << ' ' << j << endl;
        }
    }
}

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

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y,temp,i;
	for(i=1;i<10001;i++){
		cin >> x >> y;
		if(x==0){
			if(y==0)break;
		}
		if(x>y){
			temp=x;
			x=y;
			y=temp;
		}
		cout << x << " " << y << endl;	
	}
}


Measured memory_bytes: 3088
h, w = [int(x) for x in input().split()]

if h == 1 or w == 1:
    ans = 1
elif w % 2 == 0:
    ans = int((w // 2) * h)
else:
    ans = int(((w - 1) // 2) * h + (h + 1) // 2)

print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
  string s1, s2;
  cin >> s1 >> s2;
  
  if (s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    ll A, B, C;
    cin >> A >> B >> C;
    rep(i, 0, 1000000)
    {
        if (A % 2 || B % 2 || C % 2)
        {
            cout << i << endl;
            return 0;
        }
        ll A1 = B / 2 + C / 2, B1 = A / 2 + C / 2, C1 = A / 2 + B / 2;
        A = A1; B = B1; C = C1;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())
    if H % 3 == 0 or W % 3 == 0:
        return 0
    m = 10**9
    # case H
    m = min(H, m)
    # case W
    m = min(W, m)
    # case rei 2
    g = H * (W // 3)
    b = (W - (W // 3)) * (H // 2)
    r = H * W - g - b
    m = min(m, max(abs(g-b), abs(g-r), abs(b-r)))
    # case rei 2-2
    g = H * ((W // 3) + 1)
    b = (W - (W // 3) - 1) * (H // 2)
    r = H * W - g - b
    m = min(m, max(abs(g-b), abs(g-r), abs(b-r)))
    # case rei 3
    g = W * (H // 3)
    b = (H - (H // 3)) * (W // 2)
    r = H * W - g - b
    m = min(m, max(abs(g-b), abs(g-r), abs(b-r)))
    # case rei 3-2
    g = W * ((H // 3) + 1)
    b = (H - (H // 3)-1) * (W // 2)
    r = H * W - g - b
    m = min(m, max(abs(g-b), abs(g-r), abs(b-r)))
    return m
print(main())


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int n;
  cin >> n;
  
  int a = 0;
  for(int i = 2; i <= n; i++) {
    int t = i;
    int c = 0;
    for(int j = 0; j < 100; j++) {
      if(t % 2 == 1) break;
      else {
        t = t / 2;
        c++;
      }
    }
    a = max(a,c);
  }
  int ans = 1;
  for(int i = 0; i < a; i++) {
    ans = ans * 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define ll long long int
using namespace std;
ll k,n;
ll a[(ll) 2e5+5];
int main(){
	cin>>n>>k;
	for(ll i = 0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	ll ans = 0;
	for(ll i = n-1;i>=0;i--){
		if(k>0){
			k--;
		}else ans+=a[i];
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5+100;
char s[N];
int main()
{
    int n, A, B, C, D;
    scanf("%d%d%d%d%d",&n, &A, &B, &C, &D);
    scanf("%s", s+1);
    if( C == D )
        printf("No\n");
	else if(C < D)
	{
        int flag = 1 ;
        for(int i = A; i < C; i++)
		{
            if(s[i] == '#' && s[i+1] == '#')
			{
                flag = 0;
                break ;
            }
        }
        for(int i = B; i < D; i++)
		{
            if(s[i] == '#' && s[i+1] == '#')
			{
                flag = 0;
                break ;
            }
        }
        if(flag)
            printf("Yes\n");
		else
           printf("No\n");
    }
	else
	{
        int flag = 1 ;
        for(int i = B; i < D; i++)
		{
            if ( s[i] == '#' && s[i+1] == '#' )
			{
                flag = 0;
                break;
            }
        }
        for(int i = A; i < C; i++)
		{
            if((s[i] == '#' && s[i+1] == '#') || (s[i] == '#' && i+1 == D ) || (s[i+1] == '#' && i == D ))
			{
                flag = 0;
                break;
            }
        }
         
        int f = 0;
        for(int i = B; i <= D-1; i++)
		{
            if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.' )
			{
                f = 1;
                break;
            }
        }
        if(flag || f)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0 ;
}

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

#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--)

int dx[4]={1, -1, 0, 0};
int dy[4]={0, 0, 1, -1};

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((abs(a-b)<=d && abs(b-c)<=d) || abs(c-a)<=d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
   ll S;
   cin>>S;
   ll M=1e9;
ll x2,y2;
y2 = (S+M-1)/M;
x2 = M*y2-S;
  
     cout<<0<<" "<<0<<" "<<M<<" "<<1<<" "<<x2<<" "<<y2<<" "<<endl;
   




   

}

Measured memory_bytes: 256
array = []
while 1 :
    n = input()
    if n == "0 0":
        break
    array.append(n.split())
for i in range(len(array)):
    count = 0
    for i2 in range(1,int(array[i][0])+1):
        for i3 in range(i2+1,int(array[i][0])+1):
            number =int(array[i][1])-(i2+i3)
            if number > i3 and number <= int(array[i][0]):
                count += 1
    print(count)

Measured memory_bytes: 7676
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		N = N%10;
		
		if(N == 3) {
			System.out.println("bon");
		}else if(N ==0 || N == 1 || N == 6 || N == 8) {
			System.out.println("pon");
		}else {
			System.out.println("hon");
		}
	}
}


Measured memory_bytes: 35740
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)

    res = INF
    for S in s[b-1:b+1]:
        for T in t[d-1:d+1]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)


Measured memory_bytes: 13952
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
using namespace std;
int main(){ 
  double L;
  cin >>L;
  double ans =L*L*L/27.0;
  cout <<fixed<<setprecision(12)<<ans<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	fmt.Scanf("%s", &s)
	fmt.Scanf("%s", &t)

	_s := strings.Split(s, "")
	_t := strings.Split(t, "")

	ans := 0
	for i := 0; i < len(_s); i++ {
		if _s[i] == _t[i] {
			continue
		}
		ans = ans + 1
	}

	fmt.Println(ans)
}


Measured memory_bytes: 11092
#include<stdio.h>
static const int MAX = 400;
static const int INFTY = (1<<21);

int main(){
  int M[MAX][MAX];
  int f[MAX];
  int c[MAX];
  int n,i,j,s,u,v,m,a;

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

  for(i = 0;i < n;i++){
    scanf("%d %d",&u,&s);
    for(j = 0;j < s;j++){
      scanf("%d %d",&v,&a);
      M[u][v] = a;
    }
  }

  for(i = 0;i < n;i++){
    f[i] = INFTY;
    c[i] = 0;
  }

  f[0] = 0;
  while(1){
    m = INFTY;
    u = -1;
    for(i = 0;i < n;i++){
      if(m > f[i] && !c[i]){
	u = i;
	m = f[i];
      }
    }
    if(u == -1)break;
    c[u] = 1;
    for(i = 0;i < n;i++){
      if(!c[i] && M[u][i] != INFTY){
	if(f[i] > f[u] + M[u][i]){
	  f[i] = f[u] + M[u][i];
	}
      }
    }
  }

  for(i = 0;i < n;i++){
    printf("%d %d\n", i,(f[i]==INFTY?-1:f[i]));
  }

  return 0;
}



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

#define var auto
#define long long long
#define ll long
#define Max std::max
#define Min std::min
#define Abs std::abs

void Solve();

using namespace std;

int main() {
    while (true) {
        Solve();
    }
}

void Solve() {
    int n, r;
    cin >> n >> r;
    if (n == 0 && r == 0) exit(0);
    var pile = new vector<int>(n);
    iota(pile->begin(), pile->end(), 1);
    reverse(pile->begin(), pile->end());
    for (int i = 0; i < r; ++i) {
        var newPile = new vector<int>();
        int p, c;
        cin >> p >> c;
        for (int j = p - 1; j < p + c - 1; ++j) {
            newPile->push_back((*pile)[j]);
        }
        for (int j = 0; j < p - 1; ++j) {
            newPile->push_back((*pile)[j]);
        }
        for (int j = p + c - 1; j < n; ++j) {
            newPile->push_back((*pile)[j]);
        }
        pile = newPile;
    }
    cout << (*pile)[0] << endl;
}



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

int ans[223456],dp[223456],v[223456],n,INF=1e9+1,nowans;
vector<int>edge[223456];

void dfs(int parent,int idx){
  int l=0,r=n+1;
  while(r-l>1){
    int mid=(l+r)>>1;
    (dp[mid]<v[idx]?l:r)=mid;
  }
  int preidx=r,prevalue=dp[r];
  dp[r]=v[idx];
  if(nowans<r)nowans=r;
  ans[idx]=nowans;
  for(int q:edge[idx])if(q!=parent)dfs(idx,q);
  dp[preidx]=prevalue;
  while(dp[nowans]==INF)nowans--;
}

int main(){
  for(int i=1;i<223456;i++)dp[i]=INF;
  cin>>n;
  for(int i=0;i<n;i++)cin>>v[i];
  for(int i=1;i<n;i++){
    int a,b;cin>>a>>b;a--;b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  dfs(-1,0);
  for(int i=0;i<n;i++)cout<<ans[i]<<endl;
}


Measured memory_bytes: 31844
#include<bits/stdc++.h>
using namespace std;
#define INF (1LL<<30)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

struct Combination
{
  int mod;
  vector<int> mfact;
  vector<int> rfact;

  /*
    constructor : O(sz+log(mod))    
   */
  Combination(int sz, int mod) : mfact(sz+1), rfact(sz+1), mod(mod) {
    mfact[0] = 1;
    for ( int i = 1; i < (int)mfact.size(); i++ ) {
      mfact[i] = mfact[i-1]*i % mod;
    }
    rfact[sz] = inv(mfact[sz]);
    for ( int i = sz-1; i >= 0; i-- ) {
      rfact[i] = rfact[i+1]*(i+1) % mod;
    }
  }

  int fact(int k) const {
    return (mfact[k]);
  }

  int pow(int x, int n) const {
    int ret = 1;
    while ( n > 0 ) {
      if ( n & 1 ) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return (ret);
  }

  int inv(int x) const {
    return (pow(x, mod - 2));
  }

  /*
    permutation
   */
  int P(int n, int r) const {
    if ( r < 0 || n < r ) return (0);
    return (mfact[n]*rfact[n-r] % mod);
  }

  /*
    combination
   */
  int C(int n, int r) const {
    if ( r < 0 || n < r ) return (0);    
    return (mfact[n]*rfact[r]%mod * rfact[n-r] % mod);    
  }  

  /*
    combination with repetition
   */
  int H(int n, int r) const {
    if ( n < 0 || r < 0 ) return 0;
    if ( n == 0 && r == 0 ) return 1;
    return C(n+r-1, n);    
  }

  /*
    stirling number
   */
  int S(int n, int r) const {
    int ret;
    for ( int i = 1; i <= r; i++ ) {
      
    }
  }

  /*
    bell number
   */
  int B(int n, int r) const {

  }
};

signed main(){
 	Combination c(3000, DEKAI);
 	int n,k;
 	cin>>n>>k;
 	lp(i,k+1){
 		if(i==0) continue;
 		int ans=c.C(k-1,i-1);
 		int x=n-k;
 		if(x==0){
 			if(i==1)	cout<<1<<endl;
 			else cout<<0<<endl;
 			continue;
 		}
 		int ansc=c.C(x-1,i-2)+c.C(x-1,i-1)*2+c.C(x-1,i);
 		cout<<ans*ansc%DEKAI<<endl;
 	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      lld n, i;
      cin >> n;
      set <lld> dis;
      lld r;
      foi(i, n)
      {
      	cin >> r;
      	dis.insert(r);
      }
      if (dis.size() ==n)
      	cout << "YES";
      else
      	cout <<  "NO";
      return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =2e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
char s[MAXN];
int main()
{
	ll n;
	int tot=0;
	scanf("%lld",&n);
	ll sum=0;
	while(n>0)
	{
		int x=(n-1)%26+1;
		s[tot++]=x+'a'-1;
		n-=x;
		n/=26;
	}
	for(int i=tot-1;i>=0;i--) printf("%c",s[i]);
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x=INT_MAX,ans=0;
    for(int i=0; i<n; i++)
    {
        int a;
        cin>>a;
        if(x>=a)
        {
            ans++;
            x=a;
        }
    }
    cout<<ans<< endl;
}


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

int A[200];
int main() {
    int N;
    cin >> N;

    int count = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    while(1) {
        bool odd = false;
        for(int i = 0; i < N; i++) {
            if(A[i] % 2 == 1) {
                odd = true;
            }
        }
        if(odd) break;
        count++;
        for(int i = 0; i < N; i++) {
            A[i] /= 2;
        }
    }
    cout << count << endl;
}

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

int main(){
        int n,i;
        cin >> n;
        vector<int> d(n);
        for(i=0;i<n;++i) cin >> d.at(i);
        sort(d.begin(),d.end());
        cout << d.at(n/2)-d.at(n/2-1) << endl;
        return 0;
}

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,x;
  cin >> n >> x;
  while(n!=0||x!=0){
    int i,j,k;
    int o=0;
    for(i=1;i<=n;i++){
      for(j=i+1;j<=n;j++){
	for(k=j+1;k<=n;k++){
	  if(i+j+k==x) o++;
	}
      }
    }

    cout << o << endl;

    cin >> n >> x;
  }


  return 0;
}



Measured memory_bytes: 3132
fn main() {
 loop {
  let mut v:Vec<i32>={
   let mut b=String::new();
   let s=std::io::stdin();
   s.read_line(&mut b).unwrap();
   b.split_whitespace().flat_map(str::parse).collect()
  };
  if v==[0,0]{break;}
  v.sort();
  println!("{} {}", v[0],v[1]);
 }
}



Measured memory_bytes: 5032
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
int pos[555], sum[555];
int main(){
    int m, k, a = 0;
    scanf("%d%d", &m, &k);
    if(k == 0){
        for(int i=0;i<(1<<m);i++) printf("%d %d ", i, i);
        return 0;
    }
    if(m == 1 && k == 1){
        printf("-1\n");
        return 0;
    }
    if(k >= (1<<m)){
        printf("-1\n");
        return 0;
    }
    printf("%d %d %d ", 0, k, 0);
    for(int i=1;i<(1<<m);i++){
        if(i == k) continue;
        printf("%d ", i);
    }
    printf("%d ", k);
    for(int i=(1<<m)-1;i>=1;i--){
        if(i == k) continue;
        printf("%d ", i);
    }
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int a,b,c,d;
	cin >> a >> b >> c;
	d = min(a,b+c);
	cout << (b+c-d) << endl;
	return 0;
}


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

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;

int main() {
	ll X, Y;
	scanf("%lld %lld", &X, &Y);
	ll max = Y;
	ll tmp = X;
	int cnt = 0;
	while (max >= tmp) {
		cnt++;
		tmp *= 2;
	}
	PRINTD(cnt);
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
	int a,b,c,d,n;
	int i,j,k,l;
	int ans=0;

	while(scanf("%d",&n) != EOF){
		for(i=0;i<10;i++){
			for(j=0;j<10;j++){
				for(k=0;k<10;k++){
					for(l=0;l<10;l++){
						if(i+j+k+l == n)
							ans++;
					}
				}
			}
		}
		printf("%d\n",ans);
		ans = 0;
	}

	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

#define fr first
#define sc second

const int INF = 1000000000;

template <int N = 100010>
struct UF{
	int par[N],r[N];
	UF(){
		for(int i = 0 ; i < N ; i ++){
			par[i] = i;
			r[i] = 0;
		}
	}
	void init(){
		for(int i = 0 ; i < N ; i ++){
			par[i] = i;
			r[i] = 0;
		}
	}
	int find(int x){
		if(par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
	void unit(int x,int y){
		if(same(x,y))return;
		x = find(x);
		y = find(y);
		if(r[x] < r[y]){
			par[x] = y;
		}
		else {
			par[y] = x;
			if(r[x] == r[y]){
				r[x] ++;
			}
		}
	}
};

int n;
vector<int> G[702];
int color[702];
bool dfs(int v,int c){
	//cout<<v<<" "<<c<<endl;
	if(color[v]!=-1)return color[v]==c;
	color[v]=c;
	bool ret=true;
	for(int u: G[v]){
		ret&=dfs(u,c^1);
	}
	return ret;
}


int main(){
	static int n,m;
	static int ed[702][702];
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			ed[i][j]=0;
		}
	}
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		ed[a][b]=ed[b][a]=1;
	}
	
	UF<702> uf;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j)continue;
			if(ed[i][j]==0){
				uf.unit(i,j);
				G[i].push_back(j);
				//G[j].push_back(i);
			}
		}
	}
	for(int i=1;i<=n;i++){
		color[i]=-1;
	}
	for(int i=1;i<=n;i++){
		if(color[i]==-1){
			if(!dfs(i,0)){
				puts("-1");
				return 0;
			}
		}
	}
	
	int cnt[702][2]={};
	for(int i=1;i<=n;i++){
		cnt[uf.find(i)][color[i]]++;
	}
	vector<int> vec[2];
	vec[0].push_back(0);
	for(int i=1;i<=n;i++){
		if(uf.find(i)==i){
			int sz=vec[0].size();
			for(int j=0;j<sz;j++){
				vec[1].push_back(vec[0][j]+cnt[i][0]);
				vec[1].push_back(vec[0][j]+cnt[i][1]);
			}
			sort(vec[1].begin(),vec[1].end());
			vec[1].erase(unique(vec[1].begin(),vec[1].end()),vec[1].end());
			vec[0]=vec[1];
			vec[1].clear();
		}
	}
	
	int ret = INF;
	for(int i=0;i<vec[0].size();i++){
		ret=min(ret,vec[0][i]*(vec[0][i]-1)/2+(n-vec[0][i])*(n-vec[0][i]-1)/2);
	}
	cout << ret << endl;
}



Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string str,s;
  getline(cin,str);
  getline(cin,s);
  int t=s.length(),c=0;
  for(int i=0;i<t-2;i++)
  {
    
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
        {
          c++;
        }
  }
  cout<<c;
  return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

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

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll x; cin>>x;
  ll ans=lcm(360LL, x);
  cout<<ans/x<<endl;
  
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<string.h>
 
#define M 1000000
#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;
}
 
/* convert a string into an integer value */
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;
  int i ,point;

  key = getKey(str);

  for(i = 0; ; i++) {

    point = (h1(key) + i * h2(key)) % M;

    if((strcmp(H[point], str)) == 0)
      return 1;
    
    else if(H[point][0] == '\0')
      return 0;
    
  }
  return 0;
}
  
 
int insert(char str[]){
  long long key;
  int point,i;

  key=getKey(str);

  for(i=0; ;i++){

    point = (h1(key) + i * h2(key)) % M;

    if(H[point][0]=='\0'){

      strcpy(H[point],str);

      return 0;

    }

    else if((strcmp(H[point], str)) == 0)
      return 1;
  }
 
}
 
int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
     
    scanf("%d", &n);
     
    for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
     
    if ( com[0] == 'i' ){
        insert(str);
    } else {
        if (find(str)){
        printf("yes\n");
        } else {
        printf("no\n");
        }
    }
    }
 
    return 0;
}

Measured memory_bytes: 14280
from collections import defaultdict


n, m = map(int, input().split())
*a, = map(int, input().split())

b = 0
c = defaultdict(int)
c[0] = 1
cnt = 0
for a in a:
    b = (b + a) % m
    cnt += c[b]
    c[b] = c[b] + 1
print(cnt)

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

bool is_prime(int x) {
    if (x == 2) return true;

    if (x %2 == 0 || x < 2)
        return false;

    int i = 3;
    while (i <= sqrt(x)) {
        if (x % i == 0)
            return false;
        i += 2;
    }
    return true;
}
int main() {
    int n; cin >> n;
    int ans = 0;
    rep(i, n) {
        int x;
        cin >> x;
        if (is_prime(x))
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3100
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n, k;
        cin >> n >> k;
        vector<ll> v(n);
        for(i = 0; i < n; i++){
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        ll lo = 1, hi = v[n - 1], mid;
        ll ans = hi;
        while(lo <= hi){
            mid = (lo + hi) / 2;
            ll cnt = 0;
            for(i = 0; i < n; i++){
                ll val;
                if(v[i] % mid == 0){
                    val = (v[i] / mid) - 1;
                }
                else{
                    val = v[i] / mid;
                }
                cnt += val;
            }
            if(cnt <= k){
                ans = mid;
                hi = mid - 1;
            }
            else{
                lo = mid + 1;
            }
        } 
        cout << ans; 
    }
    return 0;
}

Measured memory_bytes: 4788
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
bool vis[15];
int n,k,x;
int check(int num){
	while(num){
		if(vis[num % 10]) return false;
		num /= 10;
	}
	return true;
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i = 1; i <= k; i++){
		scanf("%d",&x);
		vis[x] = 1;
	}
	int num = n;
	while(true){
		if(check(num)) break;
		else num++;
	}
	printf("%d\n",num);
}

Measured memory_bytes: 128
using System;
class Program{
	static int[] s;
	static void Main(){
		s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		long[][] arr=new long[2][];
		arr[0]=new long[s[0]];
		arr[1]=new long[s[0]];
		long ans=long.MaxValue;
		for(int i=0;i<s[0];i++){
			long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
			arr[0][i]=q[0];
			arr[1][i]=q[1];
		}
		int[,] w=new int[s[0]+1,s[0]+1];
		long[][] x=new long[s[0]+1][];
		long[][] y=new long[s[0]+1][];
		long[,] h=new long[s[0]+1,2];
		for(int i=1;i<=s[0];i++){
			x[i]=new long[]{arr[0][i-1],i};
			y[i]=new long[]{arr[1][i-1],i};
		}
		x[0]=new long[]{long.MinValue,0};
		y[0]=new long[]{long.MinValue,0};
		Array.Sort(x,ca);
		Array.Sort(y,ca);
		for(int i=1;i<=s[0];i++){
			h[x[i][1],0]=i;
			h[y[i][1],1]=i;
		}
		for(int i=1;i<=s[0];i++){w[h[i,0],h[i,1]]=1;}
		for(int i=1;i<=s[0];i++){
			for(int j=1;j<=s[0];j++){w[i,j]+=w[i,j-1];}
		}
		for(int i=1;i<=s[0];i++){
			for(int j=1;j<=s[0];j++){w[j,i]+=w[j-1,i];}
		}
		for(int i=1;i<s[0];i++){
			for(int j=i+1;j<=s[0];j++){
				for(int k=1;k<s[0];k++){
					for(int l=k+1;l<=s[0];l++){
						long a=Math.Min(h[i,0],h[j,0]);
						long b=Math.Min(h[k,1],h[l,1]);
						long c=Math.Max(h[i,0],h[j,0]);
						long d=Math.Max(h[k,1],h[l,1]);
						if(w[c,d]-w[a-1,d]-w[c,b-1]+w[a-1,b-1]>=s[1]){
							ans=Math.Min(ans,(x[c][0]-x[a][0])*(y[d][0]-y[b][0]));
						}
					}
				}
			}
		}
		Console.WriteLine("{0}",ans);
	}
	static int ca(long[] a,long[] b){
		if(a[0]>b[0]){return 1;}
		else if(a[0]<b[0]){return -1;}
		else{return 0;}
	}
}

Measured memory_bytes: 13396
#include <iostream>
#include <cmath>

using namespace std;

int sum (int num) {
    int sum {0};
    for (int i = 0; i < 5; i++) {
        sum += num % 10;
        num = (num - (num % 10)) / 10;
    }
    return sum;
}

int main() {
    int N;
    cin >> N;
    int A, B;
    int smallest {INT_MAX};
    
    for (int i {1}; i < N; ++i) {
        A = i;
        B = N - i;
        int total = sum(A) + sum(B);
        if (smallest > total) {
            smallest = total;
        }
    }
    cout << smallest << endl;
    
    return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s,t;
  cin >> s >> t;
  cout << t << s << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
	int n, m,l,r,i,lmax,rmin,cnt=0;
	cin >> n >> m;
	for (i = 0;i < m;i++) {
		cin >> l >> r;
		if (i == 0) {
			lmax = l;
			rmin = r;
		}
		if (lmax < l)
			lmax = l;
		if (rmin > r)
			rmin = r;
	}
	for (i = 1;i <= n;i++) {
		if (lmax <= i && rmin >= i)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

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

  int cnt=0;
  for (int i=a; i<=b; i++) {
    if (i == 0) {
      cnt = -1;
      break;
    } else if (i < 0) cnt++;
  }

  if (cnt == -1) cout << "Zero" << endl;
  else if (cnt % 2 == 0) cout << "Positive" << endl;
  else cout << "Negative" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node {
  int parent, left, right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
  if ( u == NIL ) return;
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if ( T[u].left != NIL )
    h1 = setHeight(T[u].left) + 1;
  if ( T[u].right != NIL )
    h2 = setHeight(T[u].right) + 1;
  return H[u] = ( h1 > h2 ? h1 : h2 );
}

int getSibling(int u) {
  if ( T[u].parent == NIL ) return NIL;
  if ( T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if ( T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if ( T[u].left != NIL ) deg++;
  if ( T[u].right != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if ( T[u].parent == NIL ) {
    printf("root\n");
} else if ( deg > 0 ) {
    printf("internal node\n");
  } else {
    printf("leaf\n");
  }
}

int main() {
  int v, l, r, root = 0;
  scanf("%d", &n);

  for ( int i = 0; i < n; i++ ) T[i].parent = NIL;

  for ( int i = 0; i < n; i++ ) {
    scanf("%d %d %d", &v, &l, &r);
    T[v].left = l;
    T[v].right = r;
    if ( l != NIL ) T[l].parent = v;
    if ( r != NIL ) T[r].parent = v;
  }

  for ( int i = 0; i < n; i++ ) if ( T[i].parent == NIL ) root = i;

  setDepth(root, 0);
  setHeight(root);

  for ( int i = 0; i < n; i++ ) print(i);

  return 0;
}

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



int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n;
	cin>> n;
	string s;
	map<string, int> mp;
	for(ll i=0; i<n; i++){
		cin>>s;
		sort(s.begin(),s.end());
		mp[s]++;
	}
	
	ll ans=0;
	auto it = mp.begin();
	while(it!=mp.end()){
		ll k=it -> second;
		ans+=(k*(k-1))/2;
		it++;
	}

	cout<<ans;

	return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

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

	int even[100200];
	int odd[100200];
	rep(i, 100010) {
		even[i] = 0;
		odd[i] = 0;
	}

	int maxev = 0, semaxev = 0;
	int maxod = 0, semaxod = 0;
	int numev, numod;

	//偶数入力
	for (int i = 1; i < n; i += 2) even[v[i]]++;
	//奇数入力
	for (int i = 0; i < n; i += 2) odd[v[i]]++;


	//偶数整理
	for (int i = 1; i < 100001; i++) {
		if (even[i] >= maxev) {
			semaxev = maxev;
			maxev = even[i];
			numev = i;
		}
		if (even[i] >= semaxev && even[i] < maxev) {
			semaxev = even[i];
		}
	}

	//奇数整理
	for (int i = 1; i < 100001; i++) {
		if (odd[i] >= maxod) {
			semaxod = maxod;
			maxod = odd[i];
			numod = i;
		}
		if (odd[i] >= semaxod && odd[i] < maxod) {
			semaxod = odd[i];
		}
	}

	//回答パート
	int ans;
	if (numev != numod) ans = n - maxev - maxod;

	else ans = min(n - maxev - semaxod, n - maxod - semaxev);

	cout << ans << endl;

}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
using namespace std;
typedef long long ll;   
typedef unsigned long long ull;
const int MAXN=2000;
inline long long read()//inline 加速读入
{
	long long x=0;char c=getchar();//x代表返回值，c代表读取的字符
	while (c<'0'||c>'9') c=getchar();//读取所有非数部分
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();//如果读取的字符为数，加入返回值
	return x;
}
ll n,k,t,aa[MAXN+10][MAXN+10];
struct hh{
	ll x;
	int y;
}a[MAXN+10];
int cmp(hh a,hh y)
{
	return a.x>y.x;
}
ll run(int l,int r){
	if(l>r)return 0;
	if(aa[l][r])return aa[l][r];
	int i=n-(r-l);
	return aa[l][r]=max(run(l,r-1)+a[i].x*abs(r-a[i].y),run(l+1,r)+a[i].x*abs(a[i].y-l)) ; 
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		a[i].x=read();a[i].y=i;
	}
	sort(a+1,a+n+1,cmp);
	run(1,n);
	cout<<aa[1][n]<<endl;
} 

Measured memory_bytes: 26364
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
      	String S = sc.next();
      	String[] ary = S.split("", 0);
      	int count = 0;
      
      	for(int i = 0; i < ary.length; i++) {
        	if(ary[i].equals("+")) {
            	count++;
            } else {
             	count--; 
            }
        }
      	System.out.println(count);
    }
}

Measured memory_bytes: 23764