akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
    int n;
    int i;
    int a[100];

    scanf("%d",&n);

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

    for(i = n-1; i >= 0; i--){
        printf("%d",a[i]);
        if(i != 0){
            printf(" ");
        }else{
            printf("\n");
        }
    }

    return 0;
}


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

int main(){
  int n;
  string s, t;

  cin >> n >> s >> t;
  int maxLen = 0;
  for(int i=1; i<=n; i++){
    if(s.substr(n-i) == t.substr(0,i))
      maxLen = max(maxLen, i);
  }

  cout << 2*n - maxLen << endl;
  return 0;
}

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

int main() {
	int thynumb,c = 0;
	cin >> thynumb;
	int noofseq = 0;
	cin>> noofseq;
	        vector <int> vect;
	for(int i=0;i<noofseq;i++){
	    //store all these numbers in a array
						cin>> c;
            vect.push_back(c);
	}

	int deco = thynumb;
	int inco = thynumb;
	while ( find(vect.begin(),vect.end(),inco) != vect.end() ) 
		inco++;
	while ( find(vect.begin(),vect.end(),deco) != vect.end() ) 
		deco--;


    if((inco-thynumb)<(thynumb-deco))
        cout<< inco;
    else if ((thynumb-deco)<(inco-thynumb))
        cout<< deco;
	else if ((inco-thynumb)==thynumb-deco)
	    cout<< deco;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> p, q, a;
    for (int i = 1; i <= n; i++)
    {
        a.push_back(i);
        int r;
        cin >> r;
        p.push_back(r);
    }
    for (int i = 1; i <= n; i++)
    {
        int r;
        cin >> r;
        q.push_back(r);
    }
    int a1 = -1, b = -1;
    int j = 1;
    while (true)
    {
        if (a1 == -1)
        {
            int c = 0;
            for (int i = 0; i < n; i++)
                if (a[i] != p[i])
                {
                    c = 1;
                    break;
                }
            if (c == 0)
                a1 = j;
        }
        if (b == -1)
        {
            int c = 0;
            for (int i = 0; i < n; i++)
                if (a[i] != q[i])
                {
                    c = 1;
                    break;
                }
            if (c == 0)
                b = j;
        }
        // for (auto it : a)
        //     cout << it;
        // cout << "\n";
        if (!next_permutation(a.begin(), a.end()))
            break;
        j++;
    }
    // cout<<b<<" "<<a1<<" ";
    cout << abs(a1 - b);
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    N = 10**6
    f = [1]*(N+1)
    a.sort()
    cnt = [0]*(N+1)
    for i in a:
        cnt[i] += 1
    for i in range(N+1):
        if cnt[i] > 1:
            f[i] = 0
            x = i
            while x <= N:
                f[x] = 0
                x += i
    ans = 0
    for i in a:
        if f[i]:
            ans += 1
            x = i
            while x <= N:
                f[x] = 0
                x += i
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 104268
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll gcd(ll n1,ll n2)
{
ll r;
   while(n2!=0)
   {
       r=n1%n2;
       n1=n2;
       n2=r;
   }
  return n1;

}

int main()
{
    ll t,i,j,k=0,q,p,x,y,n;
   cin>>n;
   if(n==1)
    cout<<0<<endl;
   else
    cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define cost first
#define from second.first
#define to second.second
#define MOD (1000000007ll)
#define l_ength size

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

int main(void){
	int n,a,h[9],i,ans=0;
	fill(h,h+9,0);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a;
		h[min(8,a/400)]++;
	}
	for(i=0; i<8; i++){
		if(h[i]){
			ans++;
		}
	}
	cout << (max(ans,1)) << " " << (ans+h[8]) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a[3][3], h, i, j, n, b;
    for(i=0;i<3;i++){
        scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
    }
    scanf("%d",&n);
    for(h=0;h<n;h++){
        scanf("%d",&b);
        for(i=0;i<3;i++){
            for(j=0;j<3;j++){
                if(a[i][j]==b){ a[i][j] = -1; }
            }
        }
    }
    if(a[0][0]==-1&&a[0][1]==-1&&a[0][2]==-1||
            a[1][0]==-1&&a[1][1]==-1&&a[1][2]==-1||
            a[2][0]==-1&&a[2][1]==-1&&a[2][2]==-1||
            a[0][0]==-1&&a[1][0]==-1&&a[2][0]==-1||
            a[0][1]==-1&&a[1][1]==-1&&a[2][1]==-1||
            a[0][2]==-1&&a[1][2]==-1&&a[2][2]==-1||
            a[0][0]==-1&&a[1][1]==-1&&a[2][2]==-1||
            a[0][2]==-1&&a[1][1]==-1&&a[2][0]==-1){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
from itertools import permutations

BLANK = 0
Q = 1
WALL = 2

def to_board_pos(x, y):
    return x * 10 + y

def place_queen(pos, board):
    assert board[pos] != WALL
    if board[pos] == Q:
        return False, None

    board[pos] = Q
    directions = [-10, -9, 1, 11, 10, 9, -1, -11]
    for d in directions:
        restrict_board(pos, d, board)
    
    return True, board

def restrict_board(pos, direction, board):
    cur = pos+direction
    while board[cur] != WALL:
        board[cur] = Q
        cur += direction

def check(pattern, board):
    b = board[:]
    for i, p in enumerate(pattern):
        ok, b = place_queen(to_board_pos(i+1, p), b)
        if not ok:
            return False

    return True

def print_board(board):
    for i in range(10):
        for j in range(10):
            pos = to_board_pos(i, j)
            print(str(board[pos]) + " ", end="")
        print("")

    
n = int(input())
initial_queens = [(0, 0) for i in range(n)]
for i in range(n):
    x, y = map(int, input().split())
    initial_queens[i] = (x, y)

board = [BLANK] * 100
for i, _ in enumerate(board):
    if 0 <= i <= 9 or 90 <= i <= 99:
        board[i] = WALL
        continue

    if i % 10 == 0 or i % 10 == 9:
        board[i] = WALL
        continue

perm_seed = [i+1 for i in range(8)]
patterns = permutations(perm_seed)

ans = [0] * 8
for pattern in patterns:
    init_ok = True
    for iq in initial_queens:
        if pattern[iq[0]] != iq[1] + 1:
            init_ok = False
            break

    if init_ok:
        if check(pattern, board):
            ans = pattern
            break

for i, a in enumerate(ans):
    board[to_board_pos(i+1, a)] = Q

for i in range(1, 9):
    for j in range(1, 9):
        pos = to_board_pos(i, j)
        if board[pos] == BLANK:
            print(".", end="")
        elif board[pos] == Q:
            print("Q", end="")
    print("")


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

const int MP = 999983;
int sv[MP+1], ac[MP+1];

int main() {
	sv[0] = sv[1] = 1;
	for (int i=2; i*i<=MP; ++i) {
		if ( ! sv[i]) {
			for (int j=i*i; j<=MP; j+=i) {
				sv[j] = 1;
			}
		}
	}
	ac[0] = 0;
	for (int i=1; i<=MP; ++i) {
		ac[i] = ac[i-1] + 1 - sv[i];
	}
	int n, p, m;
	while (cin >> n, n) {
		int ret = 0, X;
		for (int i=0; i<n; ++i) {
			cin >> p >> m;
			ret += ac[min(MP, p+m)] - ac[max(0, p-m-1)] - 1;
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 8972
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    for (int i=1; i<=50000; i++) {
        int price = i * 1.08;
        if (price == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CMaximumVolume {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        double L;
        cin >> L;
        double a = L / 3.0f;
        fcout << a * a * a << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CMaximumVolume solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
      	int target = sc.nextInt();
      	boolean isExist = false;
      	for(int i = 0; i <= 25; i++) {
        	for(int j = 0; j <= 14; j++) {
           		int total = 4 * i + 7 * j;
              	if(total == target) isExist = true;
            }
        }
      	if(isExist) {
          System.out.println("Yes");
        } else {
        	System.out.println("No");  
        }
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c, x, cnt;
	cin>>a>>b>>c>>x;
	cnt = 0;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; ++j){
			for(int k = 0; k <= c; ++k){
				if(i * 500 + j * 100 + k * 50 == x)cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,a,b;
	cin>>n>>a>>b;
	cout<<min(n*a,b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 3005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, k;
  cin >> n >> k;

  ll res = 0;
  for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (x >= k)
      res++;
  }
  cout << res << en;
  return 0;
}

Measured memory_bytes: 256
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
# ... 最小側の制約も確認した？
# ... オーバーフローしない？
s = input()
ans = ""
for x in s:
    if x=='B':
        if ans!="": ans = ans[:-1]
    else: ans+=x
print(ans)

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

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main (){
    int n;
    int ans;
    cin >> n;
    rep(i,n){
        int a;
        cin >> a;
        if(i==0)ans=a;
        else ans=gcd(ans,a);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int

struct edge
{
  int to, cost;
};
typedef std::vector<std::vector<edge>> graph;
const ll MOD = 1000000007;
using namespace std;

int main()
{
  double r;
  cin >> r;
  cout << fixed << setprecision(7) << r * r * M_PI << " ";
  cout << fixed << setprecision(7) << 2 * r * M_PI << endl;
}



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

int main() {
  long int n,x;
  cin>>n>>x;
  vector<long int> a(n+1);
  for(int i=0;i<n;i++) cin>>a.at(i);
  a.at(n)=x;
  
  sort(a.begin(),a.end());
  x=a.at(1)-a.at(0);
  for(int i=0;i<n;i++){
    x=__gcd(x,(a.at(i+1)-a.at(i)));
  }
  cout<<x<<endl;
}


Measured memory_bytes: 1024
a,b,k = map(int,input().split())

n=b-a+1

if (k-1>=n-k):
    for i in range(a,b+1): print(i)

else:
    for i in range(a,a+k): print(i)
    for i in range(b-k+1,b+1): print(i)


Measured memory_bytes: 3060
// Aizu 2049: Headstrong Student
// 2017.9.24 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 1000000
int tbl[MAX+2];

char buf[20], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int x, y, p, q, r;

	while (fgets(bp=buf, 20, stdin) && *buf != '0') {
		x = getint(), bp++, y = getint();
		memset(tbl, -1, sizeof(tbl));
		tbl[x] = 0, p = q = 0, r = 1;
		while (1) {
			x = ((x<<3)+(x<<1)) % y;
			if (!x) { p = r; break; }
			if (tbl[x] == -1) tbl[x] = r++;
			else { p = tbl[x], q = r - tbl[x]; break; }
		}
		printf("%d %d\n", p, q);
	}
	return 0;
}

Measured memory_bytes: 5568
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

if sum(A) < sum(B):
    print(-1)
else:
    a = []
    b = []
    for x, y in zip(A, B):
        if x >= y:
            a.append(x-y)
        else:
            b.append(y-x)
    a.sort(reverse=True)
    c = sum(b)
    ans = len(b)
    ind = 0
    while c > 0:
        c = c-a[ind]
        ind += 1
        ans += 1
    print(ans)

Measured memory_bytes: 19068
import math
from collections import defaultdict
import itertools
def input_as_int():
    return tuple(map(int,input().split()))

N,M  = input_as_int()

path = defaultdict(lambda  :defaultdict(lambda :False))
for i in range(M):
    a,b = input_as_int()
    path[a][b] = path[b][a] = True

ans = 0
roots = itertools.permutations(list(range(2,N+1)))
for root in roots:
    fr = 1
    flag = True
    for to in root:
        if path[fr][to]:
            fr = to
        else:
            flag = False
            break
    if flag:
        ans += 1
print(ans)




Measured memory_bytes: 3568
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

int N, A[200000];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N;
    REP(i, N) cin >> A[i];

    int ans = 0;
    REP(i, N)
    {
        ans += A[i] / 2;
        if (A[i] & 1 && i < N-1 && A[i+1] > 0) 
        {
            ans++;
            A[i+1]--;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin >> S >> T;
  int A,B;
  cin >> A >> B;
  string U;
  cin >> U;
  if(U == S){
    A--;
  }
  if(U == T){
    B--;
  }
  cout << A << ' ' << B;
}

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

using namespace std;

static const int INF = 1e9 + 7;

void hawawa()
{
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    if (str == "A") {
      cnt++;
    } else {
      if (!cnt) {
        cout << "NO\n";
        return;
      }
      cnt--;
    }
  }
  if (cnt) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  hawawa();
}

Measured memory_bytes: 3224
while True:
    r = input()
    a = r.split(' ')
    if a[1] == '+':
        b = int(a[0])+int(a[2])
        print(b)
    elif a[1] == '-':
        c = int(a[0])-int(a[2])
        print(c)
    elif a[1] == '*':
        d = int(a[0])*int(a[2])
        print(d)
    elif a[1] == '/':
        e = int(a[0])//int(a[2])
        print(e)
    else:
        break
      

Measured memory_bytes: 7676
n = int(input())
t, a = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))

best_i = 0
best_diff = 1e9

for i in range(n):
    h = hs[i]
    temp = t - 0.006 * h
    diff = abs(a - temp)
    if diff < best_diff:
        best_i = i
        best_diff = diff

print(best_i + 1)


Measured memory_bytes: 3060
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
d=[[a[i]*f[i],f[i]] for i in range(n)]
r=max([di[0] for di in d])+1
l=0
x=(l+r)//2
while r-l>1:
  if r-l==2:
    cnt=0
    for di,fi in d:
      cnt+=max(0,(di-l+fi-1)//fi)
    if cnt<=k:
      x=l
    else:
      x=l+1
    break
  cnt=0
  for di,fi in d:
    cnt+=max(0,(di-x+fi-1)//fi)
  if cnt>k:
    l,r=x,r
  else:
    l,r=l,x+1
  x=(l+r)//2
if r-l==2:
  if cnt>k:
    x=l+1
  else:
    x=l

print(x)


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

using namespace std;
typedef  long long ll;
typedef unsigned long long ull;
const int inf_int=1e8;
const ll inf_ll=1e16;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double dbl;
#define pb push_back
const double pi=3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;

const int MAXN = 4e6+10;
const int LOG = 20;
const int mod =1e9+7;

int get(int x){
     int res  = 0;
     while(x>0)
     {
         res+=x%10;
         x=x/10;
     }
     return res;
}
void solve(){
    int n;
    cin >> n;
    int ans = inf_int;
    for(int a=1;a<=n-1;++a){
        ans = min(ans, get(a) + get(n-a));
    }
    cout << ans;

}

signed main()
{
        #ifdef taow
           freopen("input.txt","r",stdin);
         //   freopen("output.txt","w",stdout);
        #else
        #endif // taow
        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
        cout.setf(ios::fixed);
        cout.precision(20);



        int t = 1;
        while(t--)
            solve();
}


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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

template<class T,class U> void chmax(T& a, U b) {if(a<b)a=b;}
template<class T,class U> void chmin(T& a ,U b) {if(b<a)a=b;}

vector<int> es[100100];

int dista[100100], distt[100100], distt2[100100];

int rec(int u, int d) {
    if (dista[u] >= 0) return dista[u];
    dista[u] = d;

    for(auto v : es[u]) {
        rec(v, d + 1);
    }

    return dista[u];
}

int rec2(int u, int d) {
    if (distt[u] >= 0) return distt[u];
    distt[u] = d;

    for(auto v : es[u]) {
        rec2(v, d + 1);
    }

    return distt[u];
}

bool canuse[100100];

int rec3(int u, int d) {
    if (distt2[u] >= 0) return distt2[u];
    distt2[u] = d;

    for(auto v : es[u]) {
        if (canuse[v]) rec3(v, d + 1);
    }

    return distt2[u];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, u, v;
    cin >> n >> u >> v;
    u--; v--;
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        es[a].push_back(b);
        es[b].push_back(a);
    }

    rep(i, n) dista[i] = distt[i] = distt2[i] = -1;
    
    rec(v, 0);
    rec2(u, 0);

    rep(i, n) {
        // cout << i + 1 << " : " << dista[i] << " " << distt[i] << endl;
        if (dista[i] < distt[i]) canuse[i] = false;
        else canuse[i] = true;
    }
    rec3(u, 0);

    ll ans = 0;
    rep(i, n) {
        if (distt2[i] < 0) continue;
        ll tmp = dista[i] - 1;
        // if (ans < tmp) {
        //     cout << tmp << " " << i + 1 << endl;
        // }
        chmax(ans, tmp);
    }

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


Measured memory_bytes: 10880
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N,M;
ll p[100010];
ll x[100010];
ll y[100010];
vector<ll>work[100010];

ll P[100010],W[100010];
void init(ll N){
    for (ll i=0; i<N; ++i) {
        P[i] = i;
        W[i] = 1;
    }
}

ll root(ll a){
    if (P[a] == a) return a;
    return (P[a] = root(P[a]));
}

bool is_same_set(ll a, ll b){
    return root(a) == root(b);
}

ll size(ll a){
    return W[root(a)];
}

void unite(ll a, ll b){
    ll temp = size(a) + size(b);
    if (!is_same_set(a,b)) {
        P[root(a)]= root(b);
        W[root(a)] = temp;
    }
    else P[root(a)] = root(b);
}

int main() {
    cin >> N >> M;
    rep(i,N) cin >> p[i];
    rep(i,M) cin >> x[i] >> y[i];
    init(N);
    rep(i,M){
        unite(x[i]-1,y[i]-1);
    }
    rep(i,N){
        ll t = root(p[i]-1);
        work[t].push_back(i);
    }
    
    ll ans = 0;
    rep(i,N){
        ll s = root(p[i]-1);
        ll left = 0;
        ll right = work[s].size();
        while(left + 1 <right){
            ll mid = (left+right)/2;
            if (work[s][mid] > p[i]-1) right = mid;
            else left = mid;
        }
        if (work[s][left] == p[i]-1) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

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

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

template <typename T>
inline T gcd(T a, T b) {
    for (; b; a %= b, swap(a, b));
    return a; 
}

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

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

    int N; cin >> N;
    vi arr(N+1);
    for (int i = 0; i < N-1; i++) {
        int a; cin >> a;
        arr[a]++;
    }

    for (int i = 1; i <= N; i++) {
        cout << arr[i] << "\n";
    }
}

Measured memory_bytes: 3988
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	int cnt[4] = {},turn = 0,Bturn;
	char s[4][101] = {}, win[4] = { 'A','B','C' };
	for (int i = 0; i < 3; i++)	cin >> s[i];
	for (int i = 0; i < sizeof(s); i++) {
		Bturn = turn;
		if (s[turn][cnt[turn]] == 'a') 
			turn = 0;
		else if (s[turn][cnt[turn]] == 'b') 
			turn = 1;
		else if (s[turn][cnt[turn]] == 'c') 
			turn = 2;
		else if (s[turn][cnt[turn]] == NULL) 
			break;
		cnt[Bturn]++;
	}
	cout << win[turn] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    ll r=0, b=0, g=0;
    for(int i=0; i<N; i++){
        if(S.at(i) == 'R'){
            r++;
        }
        else if(S.at(i) == 'G'){
            g++;
        }
        else{
            b++;
        }
    }
    ll minus = 0;

    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++){
            if(j + (j-i) < N){
                if(S.at(i) != S.at(j) and S.at(i) != S.at(j + (j-i)) and S.at(j) != S.at(j + (j-i))){
                    minus++;
                }
            }
        }
    }
    cout << r*g*b - minus << endl;
}


Measured memory_bytes: 3108
n = int(input())
H = list(map(int, input().split()))
for i in range(n-1, 1, -1):
    if H[i - 1] - H[i] > 1:
        print('No')
        exit()
    elif H[i - 1] > H[i]:
        H[i - 1] -= 1
print('Yes')

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

using namespace std;

int main() {
    long long n, k, *h; cin >> n >> k;
    h = new long long[n];
    for (int i = 0; i < n; i++)
        cin >> h[i];

    sort(h, h+n);
    long long ans = 0;
    for (int i = 0; i < n-k; i++)
        ans += h[i];

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

Measured memory_bytes: 5204
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main()
{
  double a,b,h,m;
  double r,sq;
  cin >> a >> b >> h >> m;

  r=(h*60+m)/2-m*6;
  if(r<0)r*=-1;
  if(r>180)r=360-r;
  r=r/180*M_PI;
  sq=a*a+b*b-2*a*b*cos(r);
  double ans = pow(sq,0.5);

  cout << fixed << setprecision(10) << ans << endl;

  return 0;
}

Measured memory_bytes: 4248
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << 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; }

class C
{
public:
    ll n;
    int c3;
    int c5;
    int c7;

    C(ll n, int c3, int c5, int c7)
    {
        this->n  = n;
        this->c3 = c3;
        this->c5 = c5;
        this->c7 = c7;
    }
};

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    ll N;
    in1(N);

    queue<C> q;
    q.emplace(0, 0, 0, 0);

    ll count = 0;

    while (true)
    {
        auto p = q.front(); q.pop();

        if (p.n > N) break;
        if (p.c3 > 0 && p.c5 > 0 && p.c7 > 0) count++;

        q.emplace(10 * p.n + 3, p.c3 + 1, p.c5    , p.c7    );
        q.emplace(10 * p.n + 5, p.c3    , p.c5 + 1, p.c7    );
        q.emplace(10 * p.n + 7, p.c3    , p.c5    , p.c7 + 1);
    }

    outl(count);

    return 0;
}


Measured memory_bytes: 4852
// Created by Nikolay Budin

#ifdef LOCAL
#  define _GLIBCXX_DEBUG
#else
#  define cerr __get_ce
#endif
#include <bits/stdc++.h>
#define ff first
#define ss second
#define szof(x) ((int)x.size())

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
#ifdef LOCAL
	mt19937 tw(9450189);
#else
	mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }


void solve() {
	int n, m;
	cin >> n >> m;
	vector<vector<pii>> graph(n);
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		graph[a].push_back({b, i});
		graph[b].push_back({a, i});
	}

	for (int i = 0; i < n; ++i) {
		if (szof(graph[i]) % 2) {
			cout << "No\n";
			return;
		}
	}

	for (int i = 0; i < n; ++i) {
		if (szof(graph[i]) > 4) {
			cout << "Yes\n";
			return;
		}
	}

	vector<int> order;
	vector<int> vcnt(n);
	vector<bool> used(m);
	function<void(int)> dfs = [&](int v) {
		while (vcnt[v] < szof(graph[v])) {
			pii to = graph[v][vcnt[v]];
			++vcnt[v];
			if (used[to.ss]) {
				continue;
			}
			used[to.ss] = true;
			dfs(to.ff);
		}
		order.push_back(v);
	};

	dfs(0);
	order.pop_back();

	// for (int v : order) {
	// 	cerr << v + 1 << " ";
	// }
	// cerr << endl;

	vector<vector<int>> where(n);
	for (int i = 0; i < szof(order); ++i) {
		where[order[i]].push_back(i);
	}

	vector<int> st(n);
	set<pii> have;
	bool removed = false;
	for (int i = 0; i < szof(order); ++i) {
		if (szof(where[order[i]]) == 2) {
			if (st[order[i]]) {
				if (have.begin()->ss != order[i]) {
					cout << "Yes\n";
					return;
				}
				have.erase(have.begin());
				removed = true;
			} else {
				if (removed) {
					cout << "Yes\n";
					return;
				}
				have.insert({i, order[i]});
			}
			st[order[i]] ^= 1;
		}
	}
	cout << "No\n";
}


int main() {
#ifdef LOCAL
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test_count = 1;
	// cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}
	
#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}


Measured memory_bytes: 15356
#include<cstdio>
#include<algorithm>
using namespace std;
int n,dl[100005],len,a[100005];
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	len=1;
	dl[1]=a[n];
	for(int i=n-1; i>=1; i--) {
		int k=upper_bound(dl+1,dl+1+len,a[i])-dl;
		if(k>len) dl[++len]=a[i];
		if(dl[k]>a[i]) dl[k]=a[i];
	}
	printf("%d",len);
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main(){
  int N,M;
  cin >> N;
  cin >> M;

  vector<uint64_t> H(N);
  vector<bool> Good(N, true);

  for(int i = 0;i < N;i++){
    cin >> H[i];
  }

  for(int i = 0;i < M;i++){
    uint64_t a,b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    if(H[a] == H[b]){
      Good[a] = false;
      Good[b] = false;
    }else{
      Good[H[a] < H[b] ? a : b] = false;
    }
  }

  int count = 0;
  for(int i = 0;i < N;i++){
    if(Good[i])
      count++;
  }  

  std::cout << count << std::endl;
}


Measured memory_bytes: 4040
import heapq
N, M = map(int, input().split())
A = [-int(i) for i in input().split()]
heapq.heapify(A)
for i in range(M):
    a = -int(heapq.heappop(A) / 2)
    heapq.heappush(A, -a)
print(-sum(A))

Measured memory_bytes: 14184
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\ALDS1_3_C-in10.txt"));
		// while (scan.hasNext()) {

		int n = scan.nextInt();
		Slist s = new Slist(n);
		for (int i = 0; i < n; i++)
			s.add(scan.nextInt());
		int q = scan.nextInt();
		int cnt = 0;
		for (int i = 0; i < q; i++)
			if (s.isExist(scan.nextInt()))
				cnt++;
		System.out.println(cnt);
		scan.close();
		System.exit(0);
	}
}

class Slist {
	List<Integer> list = new ArrayList<Integer>();
	boolean sorted = false;

	public Slist(int n) {
		// TODO Auto-generated constructor stub
	}

	public boolean isExist(int e) {
		if (!sorted) {
			Collections.sort(list, null);
			sorted = true;
		}
		return this.bsearch(e, 0, list.size() - 1);
	}

	private boolean bsearch(int e, int min, int max) {
		if (min > max)
			return false;
		int mid = (max + min) / 2;
		if (list.get(mid) > e)
			return bsearch(e, min, mid - 1);
		else if (list.get(mid) == e)
			return true;
		else
			return bsearch(e, mid + 1, max);
	}

	public void add(int e) {
		list.add(e);
	}

}

Measured memory_bytes: 81964
#include <stdio.h>
    #include <string.h>
    #include <queue>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int maxn=10050;
    const int maxe=40414;
    const int INF=0x3f3f3f3f;
    struct note
    {
        int v;
        int w;
        int c;
        int next;
    };
    note edge[maxe];
    int head[maxn];
    int cnt;
    void init()
    {
        memset(head,-1,sizeof(head));
        cnt=0;
    }
    void addedge(int u,int v,int w,int c)
    {
        edge[cnt].v=v;
        edge[cnt].c=c;
        edge[cnt].w=w;
        edge[cnt].next=head[u];
        head[u]=cnt++;
    }
    int cost[maxn];
    int dis[maxn];
    bool vis[maxn];
    queue<int>q;
    void spfa(int s,int n)
    {
        while(!q.empty())q.pop();
        for(int i=1;i<=n;i++)
            cost[i]=dis[i]=INF;
        memset(vis,false,sizeof(vis));
        dis[s]=0;
        cost[s]=0;
        vis[s]=true;
        q.push(s);
        while(!q.empty())
        {
            int u=q.front();
            q.pop();
            vis[u]=false;
            for(int i=head[u];i!=-1;i=edge[i].next)
            {
                int v=edge[i].v;
                int val=edge[i].w;
                if(dis[v]>dis[u]+val||(dis[v]==dis[u]+val&&cost[v]>edge[i].c))//有多条最短路时，取花费最小的
                {
                    dis[v]=dis[u]+val;
                    cost[v]=edge[i].c;
                    if(!vis[v])
                    {
                        q.push(v);
                        vis[v]=true;
                    }
                }
            }
        }
    }
    int main()
    {
        int n,m;
        int u,v,w,c;
        while(~scanf("%d%d",&n,&m))
        {
            if(n==0&&m==0) break;
            init();
            for(int i=0;i<m;i++)
            {
                scanf("%d%d%d%d",&u,&v,&c,&w);
                addedge(u,v,c,w);
                addedge(v,u,c,w);
            }
            spfa(1,n);
            int ans=0;
            for(int i=1;i<=n;i++)
                ans+=cost[i];
            printf("%d\n",ans);
        }
        return 0;
    }



Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int N = 2e5 + 5, MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s;

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

    cin>>s;
    if(s.size() == 1)   cout<<1<<endl;
    else{
        int n = s.size(), cnt = 1, ans = 1;
        s += '?';
        //cout<<n<<endl;
        for(int i = 1; i < n; i++){
            //cout<<i<<" "<<ans<<endl;
            if((s[i] == s[i - 1]) and (i != (n - 1))){
                ans += 2;
                i += 2;
                if(i == n){
                    ans--;
                    break;
                }
            }
            else if(s[i] != s[i - 1])   ans++;
            else if(i == (n - 1))   break;
            else                    ans++;
        }
        cout<<ans;
    }




    return 0;
}


Measured memory_bytes: 720
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
total = sum(a)
tmp = 1 / (4 * M)
cnt = 0
for i in a:
    if i >= total * tmp:
        cnt += 1
    else:
        break
if cnt >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int w,h,n;
	cin>>w>>h>>n;
	int x[n],y[n],a[n],b[w][h];
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>y[i]>>a[i];
	}
	for(int i=0;i<w;i++)
	{
		for(int j=0;j<h;j++)
		{
			b[i][j]=0;
		}
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]==1)
		{
			for(int j=0;j<x[i];j++)
			{
				for(int l=0;l<h;l++)
				{
					b[j][l]=1;
				}
			}
		}
		if(a[i]==2)
		{
			for(int j=w-1;j>=x[i];j--)
			{
				for(int l=0;l<h;l++)
				{
					b[j][l]=1;
				}
			}
		}
		if(a[i]==3)
		{
			for(int j=0;j<y[i];j++)
			{
				for(int l=0;l<w;l++)
				{
					b[l][j]=1;
				}
			}
		}
		if(a[i]==4)
		{
			for(int j=h-1;j>=y[i];j--)
			{
				for(int l=0;l<w;l++)
				{
					b[l][j]=1;
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<w;i++)
	{
		for(int j=0;j<h;j++)
		{
			if(b[i][j]==0)
			{
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}

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

int cmp(const void* x,const void* y) {
	if(*((int*)x)<*((int*)y))return 1;
	if(*((int*)x)>*((int*)y))return -1;
	return 0;
}

int main(void) {
	int w[10];
	int k[10];
	int i;
	for(i=0;i<10;i++)scanf("%d",&w[i]);
	for(i=0;i<10;i++)scanf("%d",&k[i]);
	qsort(w,10,sizeof(int),cmp);
	qsort(k,10,sizeof(int),cmp);
	printf("%d %d\n",w[0]+w[1]+w[2],k[0]+k[1]+k[2]);
	return 0;
}

Measured memory_bytes: 0
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    x, y = map(int, input().split())
    if y % 2 != 0:
        print('No')
    elif y // 2 - x < 0 or y > 4 * x:
        print('No')
    else:
        print('Yes')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 61792
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/23.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
#define ll long long
using namespace std;



int main()
{
    int i;
    
    
    int v;
    int N;
    int maxev=0,maxev2=0,maxod=0,maxod2=0;
    int valev,valev2,valod,valod2;
    cin >> N;
    
    vector<int> ch_odd(pow(10,5)), ch_even(pow(10,5));
    
    for(i=0;i<N/2;i++){
        cin >> v;
        ch_even[v]++;
        if(maxev < ch_even[v]) {
            maxev = ch_even[v];
            valev = v;
        } else if(maxev2 < ch_even[v]) {
            maxev2 = ch_even[v];
            valev2 = v;
        }
        
        cin >> v;
        ch_odd[v]++;
        if(maxod < ch_odd[v]) {
            maxod = ch_odd[v];
            valod = v;
        } else if(maxod2 < ch_odd[v]) {
            maxod2 = ch_odd[v];
            valod2 = v;
        }
        
    }
    
    if(valev != valod) {
        cout << N - maxev - maxod << endl;
    } else {
        cout << min(N - maxev2 - maxod , N - maxev - maxod2) << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int S = sc.nextInt();
    int ans = 0;
    int sum = 0;
    
    for(int i=0; i<=K; i++){
      for(int j=0; j<=K; j++){
        sum = S-(i+j);
        if(0 <= sum && sum <= K){
          ans++;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35540
<?php

// $n = $a + $b ????????£????????\
$y = array_fill(0, 2001, 0);
for($b = 0; $b <= 1000; $b++){
	for($a = 0; $a <= 1000; $a++){
		$y[$a + $b]++;
	}
}
$x = $y;	// ????\???¨????????????


// $n = $a + $b + $c ?????¨???????????£????????\
$y = array_fill(0, 3001, 0);
for($c = 0; $c <= 1000; $c++){
	for($i = 0; $i <= 2000; $i++){
		$y[$i + $c] += $x[$i];
	}
}
$x = $y;	// ????\???¨????????????


// $n = $a + $b + $c + $d ?????¨???????????£????????\
$y = array_fill(0, 4001, 0);
for($d = 0; $d <= 1000; $d++){
	for($i = 0; $i <= 3000; $i++){
		$y[$i + $d] += $x[$i];
	}
}


while($line = fgets(STDIN)){
	$n = intval($line);
	echo $y[$n]."\n";
}

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

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> vec(n);
    rep(i,n) cin >> vec[i];
    ll ans=0,ans2=0;
    for(ll i=0;i<n;i++){
        ll total=0;
        for(ll j=0;j<n;j++){
            if(j==i){
                ans+=total;
                continue;
            }
            if(vec[j]>vec[i]) total++;
        }
        ans2+=total;
    }
    ll now=0;
    if((k-1)%2==0) now=(k%mod)*(k/2)%mod;
    else now=(k*(k/2-1)+k/2)%mod;
    ll ans3=0;
    ans3+=ans*k%mod;
    ans3+=now*ans2%mod;
    ans3=ans3%mod;
    cout << ans3 << endl;

    return 0;
}








Measured memory_bytes: 256
#include<bits/stdc++.h>
  
using namespace std;
  
#define MAX_N 20
#define MAX_C 10001
#define INF 1e9
#define EPS 1e-9
#define equal(a,b) (fabs(a-b) < EPS)
#define lt(a,b) (a-b < -EPS)
#define le(a,b) (equal(a,b) || lt(a,b))
#define PI acos(-1)
  
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y) : x(x),y(y) {}
    
    Point operator + (const Point &p)const{
	return Point(x+p.x,y+p.y);
    }
    Point operator - (const Point &p)const{
	return Point(x-p.x,y-p.y);
    }
    Point operator * (double k)const{
	return Point(x*k,y*k);
    }
};
  
istream &operator >> (istream &is,Point &p){
    return is >> p.x >> p.y;
}
  
struct State{
    double d;
    int v,p,c;
    
    State(double d,int v,int p,int c) : 
	d(d),v(v),p(p),c(c) {}
    
    bool operator < (const State &s)const{
	return d > s.d;
    }
};
  
double dot(const Point &a,const Point &b){
    return a.x*b.x+a.y*b.y;
}
  
double norm(const Point &p){
    return dot(p,p);
}
  
double abs(const Point &p){
    return sqrt(norm(p));
}
  
typedef Point Vector;
  
inline double getAngle(const Vector &a,const Vector &b){
    return acos(dot(a,b)/abs(a)/abs(b))*180/PI;
}
  
double dist(const Point &a,const Point &b){
    return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
  
int N;
double r,th,d2[MAX_N][MAX_N];
bool can[MAX_N][MAX_N][MAX_N];
double d[MAX_N][MAX_N][MAX_C];
  
int solve(const vector<Point> &vec){
    for(int i = 0 ; i < N ; i++){
	for(int j = 0 ; j < N ; j++){
	    for(int k = 0 ; k < MAX_C ; k++){
		d[i][j][k] = INF;
	    }
	}
    }
    priority_queue<State> Q;
    for(int i = 1 ; i < N ; i++){
	Q.push(State(dist(vec[0],vec[i]),i,0,1));
	d[i][0][1] = dist(vec[0],vec[i]);
    }
    while(!Q.empty()){
	State s = Q.top(); Q.pop();
	int v = s.v,p = s.p,c = s.c;
	if(lt(d[v][p][c],s.d)) continue;
	if(lt(r,s.d)) continue;
	for(int i = 0 ; i < N ; i++){
	    if(i == v || i == p) continue;
	    if(!can[p][v][i]) continue;
	    if(c+1 < MAX_C && lt(d[v][p][c]+d2[v][i],d[i][v][c+1])){
		d[i][v][c+1] = d[v][p][c]+d2[v][i];
		Q.push(State(d[i][v][c+1],i,v,c+1));
	    }
	}
    }
    int ans = 0;
    for(int i = 0 ; i < N ; i++){
	for(int j = 0 ; j < N ; j++){
	    if(i == j) continue; 
	    for(int k = MAX_C-1 ; k > 0 ; k--){
		if(le(d[i][j][k],r)){
		    ans = max(ans,k);
		    break;
		}
	    }
	}
    }
    return ans;
}
  
int main(){
    cin >> N >> r >> th;
    vector<Point> v(N);
    for(int i = 0 ; i < N ; i++){
	cin >> v[i];
    }
    memset(can,false,sizeof(can));
    for(int i = 0 ; i < N ; i++){
	for(int j = 0 ; j < N ; j++){
	    if(i == j) continue; 
	    for(int k = 0 ; k < N ; k++){
		if(i == k || j == k) continue;
		Vector a = v[j]-v[i];
		Vector b = v[k]-v[j];
		double angle = getAngle(a,b);
		if(le(angle,th)){
		    can[i][j][k] = true;
		}
	    }
	}
    }
    for(int i = 0 ; i < N ; i++){
	for(int j = 0 ; j < N ; j++){
	    d2[i][j] = dist(v[i],v[j]);
	}
    }
    cout << solve(v) << endl;
    return 0;
}

Measured memory_bytes: 34904
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int n = 0;
        for(int i=1; i<=N-1; i++){
            n += i;
}
        int m = 0;
        for(int i=1; i<=M-1; i++){
            m += i;
}
                System.out.println(n+m);            
            }
}

Measured memory_bytes: 21844
<?php

while ($line = fgets(STDIN)) {
   $stdin[] = trim($line);
}

$N = $stdin[0];
$A = explode(" ", $stdin[1]);
$B = explode(" ", $stdin[2]);
$C = explode(" ", $stdin[3]);

$total = 0;

for ($i = 0; $i < $N; $i++) {

      $total += $B[$A[$i] - 1];

             if ($i !== 0) {

                     if ($A[$i] - $A[$i - 1] === 1) {

                             $total += $C[$A[$i - 1] - 1];

           }

  }

}

echo $total;
      
?>

Measured memory_bytes: 3828