akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a_list = list(map(int, input().split()))

one, two, three = 0, 0, 0
for a in a_list:
    if a == 1:
        one += 1
    if a == 2:
        two += 1
    if a == 3:
        three += 1

dp = [[[0.0] * 301 for _ in range(301)] for _ in range(301)]
for k in range(three+1):
    for j in range(two+three+1-k):
        for i in range(one+two+three+1-k-j):
            if i == 0 and j == 0 and k == 0:
                continue
            tmp = N * 1.0
            if i != 0:
                tmp += i * dp[i - 1][j][k]
            if j != 0:
                tmp += j * dp[i + 1][j - 1][k]
            if k != 0:
                tmp += k * dp[i][j + 1][k - 1]

            dp[i][j][k] = tmp / (i + j + k)
print(dp[one][two][three])


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

int main() {
  int n;
  cin >> n;
  int total = 0;
  std::vector<int> A(n);
  std::vector<int> B(n);
  std::vector<int> C(n);
  rep(i,n) {
    int x;
    cin >> x;
    x--;
    A.at(i) = x;
  }
  rep(i,n) {
    cin >> B.at(i);
    total += B.at(i);
  }
  rep(i,n-1) cin >> C.at(i);

  rep(i,n-1) {
    if (A.at(i)+1 == A.at(i+1)) {
      total += C.at(A.at(i));
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int N,x=0;
    char a[110];
    int b[110];
    cin>>N;
    b[N]=0;
    for(int i=0;i<N;i++)
        cin>>a[i];
    for(int i=0;i<N;i++)
    {
        if(a[i]=='I') x++;
        else x--;
        b[i]=x;
    }
    sort(b,b+N+1);
    cout<<b[N];
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int K; cin >> K;
    int x = 7 % K; // 7777...をKで割ったあまり
    set<int> s;
    int i = 1;
    while (s.count(x) == 0){
        if (x == 0){
            cout << i << endl;
            return 0;
        }
        s.insert(x);
        x = (x * 10 + 7) % K;
        i++;
    }

    cout << -1 << endl;
    return 0;

}

Measured memory_bytes: 50444
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;

int main(){
	int q;
	long long a, b, c, d;
	long long k,x, y, z;

	scanf("%d", &q);
	for (int qq = 0; qq < q; qq++){
		scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
		k = (max(a, b) + min(a, b)) / (min(a, b) + 1);
		if (k == 1){
			if (a < b){
				for (int i = c; i <= d; i++){
					if (i % 2 == 1)printf("B");
					else printf("A");

				}
			}
			else{
				for (int i = c; i <= d; i++){
					if (i % 2 == 0)printf("B");
					else printf("A");

				}
			}
		}
else{
	x = ((a + 1)*k) - 1 - b;
	x = x / ((k*k) - 1);
	y = ((a + 1)*k) + 1 - b - (x*((k*k) - 1));
	y = (y + k - 1) / k;
	z = (x*(k + 1)) + y;
	for (int i = c; i <= d; i++){
		if (i < z){
			if (i % (k + 1) == 0)printf("B");
			else printf("A");
		}
		else{
			if ((a + b - i) % (k + 1) == k)printf("A");
			else printf("B");
		}
	}
}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cctype>
#include<stack>
using namespace std;
typedef long long ll;
string s[55];
int  sp[55][50];
string ansans;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<s[i].length();j++)
        {
            sp[i][s[i][j]-'a']++;
        }
    }
    for(int i=0;i<50;i++)
    {
        int ans=105;
        for(int j=1;j<=n;j++)
        {
            ans=min(ans,sp[j][i]);
        }
        for(int j=1;j<=ans;j++)
            ansans+=i+'a';
    }
    cout<<ansans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;




int main(){
    ll a,b;
    cin>>a>>b;
    if(a==1){a=14;}
    if(b==1){b=14;}
    if(a>b){cout<<"Alice"<<endl;}
    if(a<b){cout<<"Bob"<<endl;}
    if(a==b){cout<<"Draw"<<endl;}
    
    
    
    return 0;
}

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

using namespace std;

int main() {
    int n, j;
    string table[] = {".,!? ", "abc", "def", "ghi","jkl", "mno", "pqrs", "tuv", "wxyz"};

    cin >> n;

    while (n--) {
        string msg, ans, t;

        cin >> msg;

        ans = ""; j = 0; t = "";

        for (int i = 0; i < msg.size(); i++) {
            if (msg[i] == '0') {
                ans += t;
                j = 0; t = "";
            }
            else {
                t = table[msg[i]-'0'-1][j];
                j++;
                j %= table[msg[i]-'0'-1].size();
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3124
//Program.cpp
//Author : Aaryan Srivastava 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#define pb push_back
#define popb pop_back
#define ull unsigned long long  
#define beg begin
#define mp make_pair
#define pii pair<int, int>
#define piii pair<pii,int>
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second 
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using ll = long long;
#define int ll
const int N = 1e5 + 5 ;
const int mod = 1e9 + 5 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace std;
#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#define AaryanS 0 
#endif

#define debug(x) mycout << #x << " "  << x << endl ;

void solve()
{
	int n;
	cin >> n ;
	int dp[n+1][3] ;
	rep(i,n)
		rep(j,3)
			cin >> dp[i][j] ;
	repD(i,n-2,0){
		rep(j,3){
			int res = -inf ;
			rep(k,3){
				if(k == j)
					continue ;
				 res = max(res,dp[i+1][k]) ;
			}
			dp[i][j] += res ;
		}
	}
	cout << max(dp[0][0],max(dp[0][1],dp[0][2])) ;	
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
   // cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case " << t << ":\n" ;
        solve();
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 2560
program prob4
    implicit none
    integer::N, i, ans, cnt
    integer, allocatable::p(:)
    read(*,*) N
    allocate(p(N))
    read(*,*) p

    ans = 0
    cnt = 0
    do i = 1, N
        if(p(i) == i) then
            cnt = cnt + 1
        else
            ans = ans + (cnt+1)/2
            cnt = 0
        end if
    end do
    ans = ans + (cnt+1)/2
    write(*,*) ans
    deallocate(p)
    stop
end program

Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

signed main(){
   IOS;
   int a; cin >> a;
   long double b; cin >> b;
   long double c = a*b;
   cout << (int)floor(c) << "\n";  
}

Measured memory_bytes: 3740
#include <cstdio>
using namespace std;
inline int rd(){
	int x=0,p=1;
	char a=getchar();
	while((a<48||a>57)&&a!='-')a=getchar();
	if(a=='-')p=-p,a=getchar();
	while(a>47&&a<58)x=(x<<1)+(x<<3)+(a&15),a=getchar();
	return x*p;
}
int n,a,k,ans;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a),ans+=(a>=k);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
tmp_lst = input().split()
length_lst = []
#print(2*N)
for i in range(2*N):
#    print(tmp_lst[i])
    length_lst.append(int(tmp_lst[i]))
length_lst.sort()
 
output = 0
for i in range(0, 2*N, 2):
    output += length_lst[i]
 
print(output)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s1, s2, s3;
        cin >> s1 >> s2 >> s3;
        if(s1 == "-")
            return 0;

        int n = s1.size() + s2.size();

        int i = 0, j = 1, k = 0;
        char center = s2[0];
        string ret;
        while(--n > 0){
            if(k < s3.size() && center == s3[k]){
                ++ k;
                center = s1[i];
                ++ i;
            }else{
                ret += center;
                center = s2[j];
                ++ j;
            }
        }
        ret += center;
        cout << ret << endl;
    }
}

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

void solve()
{
	set<int> s;
	for (int i = 0; i < 5; ++i)
	{
		int k;
		cin>>k;
		s.insert(k);
	}
	for (int i = 0; i < 5; ++i)
	{
		if(s.find(i+1)==s.end())
		{
			cout<<i+1;break;
		}
	}
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3600
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        char[] S = Console.ReadLine().ToCharArray();
        int count = S.Count();
        int O = 0;

        for (int i = 0; i < count / 2; i++)
            if (S[i] != S[count - i - 1])
                O++;

        Console.WriteLine(O);
    }
}


Measured memory_bytes: 13268
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk)
{
  var x = chunk.split(" ");
  x[0] = Number(x[0])
  x[1] = Number(x[1])
  x[2] = Number(x[2])
  x.sort();
  console.log(x[0] + " " + x[1] + " " + x[2])
});

Measured memory_bytes: 15532
package main

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

func main() {
	X := nextInt()
	N := nextInt()

	ok := make([]bool, 102)
	for i := 0; i < len(ok); i++ {
		ok[i] = true
	}

	for i := 0; i < N; i++ {
		p := nextInt()
		ok[p] = false
	}

	m := 999
	k := -1

	for x := 0; x <= 101; x++ {
		if !ok[x] {
			continue
		}

		if abs(X-x) < m {
			m, k = abs(X-x), x
		}
	}

	fmt.Println(k)
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args)
}


Measured memory_bytes: 1784
N = int(input())
H = [int(X) for X in input().split()]
Count = 0
while True:
    if len(H)==1:
        Count += H[0]
        break
    else:
        MAXI = H.index(max(H))
        if MAXI==0:
            LR = MAXI+1
        elif MAXI==len(H)-1:
            LR=MAXI-1
        else:
            LR = H.index(max(H[MAXI-1],H[MAXI+1]))
        Count += H[MAXI]-H[LR]
        del H[MAXI]
print(Count)

Measured memory_bytes: 9136
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

X,Y = map(int,input().split())

flag = False
for i in range(101):
    for j in range(101):
        if i+j==X and 2*i+4*j==Y:
            flag = True
            break
    else:
        continue
    break

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9180
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int n;
int a;
deque<int> d;

int main() {
	scanf("%d ",&n);
	int mod = (n - 1)%2;
	FORI(0, n) {
		scanf("%d ", &a);
		if (mod != i % 2)
			d.push_back(a);
		else
			d.push_front(a);
	}

	for (int i = 0; i<n; i++, d.pop_front()) {
		int x = d.front();
		printf("%d%c", x, (i == n - 1) ? '\n' : ' ');
	}

	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int memo[1000][1000][2];

bool rec(int X, int Y, int turn){
    LL x = min(X, Y);
    LL y = max(X, Y);
    if(x==0 && y==0)return turn!=0;
    if(x==0 && y==1)return turn!=0;
    if(x==1 && y==1)return turn!=0;

    if(memo[x][y][turn]!=-1)return memo[x][y][turn];

    bool res = turn!=0;
    if(turn==0){
        for(int i=1; 2*i<=x; i++){
            if(rec(x-2*i, y+i, 1-turn)){
                res = true;
            }
        }
        for(int i=1; 2*i<=y; i++){
            if(rec(x+i, y-2*i, 1-turn)){
                res = true;
            }
        }
    }else{
        for(int i=1; 2*i<=x; i++){
            if(!rec(x-2*i, y+i, 1-turn)){
                res = false;
            }
        }
        for(int i=1; 2*i<=y; i++){
            if(!rec(x+i, y-2*i, 1-turn)){
                res = false;
            }
        }
    }

    memo[x][y][turn] = res;

    return res;
}

int main(){
    memset(memo, -1, sizeof(memo));
    //for(int x=10; x<=100; x++){
    //    for(int y=x-2; y<=x+2; y++){
    //    cout << x << " " << y << " " << rec(x, y, 0) << endl;
    //    }
    //}
    LL X, Y;
    cin >> X >> Y;

    bool res = true;
    if(X <= 500 && Y <= 500)res = rec(X, Y, 0);
    else{
        if(abs(X-Y)<=1)res = false;
    }
    cout << (res ? "Alice" : "Brown") << endl;
    return 0;
}


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

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h = I()
w = I()
n = I()
if h < w:
    for i in range(1,h+1):
        if i * w >= n:
            print(i)
            exit()
else:
    for i in range(1,w+1):
        if i*h >= n:
            print(i)
            exit()


Measured memory_bytes: 5140
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define printP(x) "(" << (x).first << ", " << (x).second << ")"
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n;
llint a[1000005];

llint calc()
{
	llint ret = 0;
	for(int i = 0; i < n; i++){
		if(a[i] && ((n-1)&i) == i) ret++;
	}
	return ret%2;
}

int main(void)
{
	cin >> n;
	char c;
	for(int i = 0; i < n; i++){
		cin >> c;
		a[i] = c-'0', a[i]--;
	}
	
	bool flag = false;
	for(int i = 0; i < n; i++){
		if(a[i] % 2) flag = true;
	}
	if(flag){
		for(int i = 0; i < n; i++) a[i] %= 2;
		cout << calc() << endl;
	}
	else{
		for(int i = 0; i < n; i++) a[i] /= 2;
		cout << calc()*2 << endl;
	}
	
	return 0;
}


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

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////

signed main() {
  int n,k;
  cin>>n>>k;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  vector<int>visited(n+1);
  vector<int>jun(0);
  int syokou=0,kousa=0;
  int next=0,time=0;
  while(kousa==0){
    if(visited[next]==0){
    visited[next]=time;
    jun.push_back(next+1);
  }
    else {
      kousa=time-visited[next];
      syokou=visited[next];
      jun.push_back(next+1);
    }
    next=a[next]-1;
    time++;
  }
  if(k>=syokou)cout<<jun[(k-syokou)%kousa+syokou]<<endl;
  else cout<<jun[k]<<endl;
}


Measured memory_bytes: 8492
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

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

		int n = Integer.parseInt(sc.next());
		ArrayList<Integer> aArrayList = new ArrayList<>();

		for (int i=0; i<n; i++){
			aArrayList.add(Integer.parseInt(sc.next()));
		}
		Collections.sort(aArrayList);

		System.out.println(Math.abs(aArrayList.get(0) - aArrayList.get(aArrayList.size()-1)));
	}
}

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


int main()
{
    int n;
    cin >> n;
    vector<int> h;
    rep(i, n){ int tmp; cin >> tmp; h.push_back(tmp);}

    int ans = 0;
    h[0]--;
    for (int i = 1; i < n; i++)
    {
        if(h[i] < h[i-1]){
            ans = 1;
            break;
        } else if (h[i] > h[i - 1]){
            h[i]--;
        }
    }
    cout << ((ans == 0)? "Yes": "No")<< endl;
}



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

int main(){
	string s;
	cin>>s;
	bool flag=false,flag2=false,flag3=false,flag4=false;
	for(int i=0;i<s.size();i++){
		if(s[i]=='S')flag=true;
		if(s[i]=='N')flag2=true;
		if(s[i]=='E')flag3=true;
		if(s[i]=='W')flag4=true;
	}
	if(flag&&flag2&&!flag3&&!flag4){
		cout<<"Yes"<<endl;
		return 0;
	}
	if(!flag&&!flag2&&flag3&&flag4){
		cout<<"Yes"<<endl;
		return 0;
	}
	if(flag&&flag2&&flag3&&flag4){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 1000000007
#define INF 1000000000000000000
using Graph=vector<vector<int>>;

pair<int,int> dfs(Graph &G,int v,int p){
  pair<int,int> ans=make_pair(0,v);
  for(auto nv:G.at(v)){
    if(nv==p){
      continue;
    }
    pair<int,int> p=dfs(G,nv,v);
    ans=max(ans,make_pair(p.first+1,p.second));
  }
  return ans;
}

int main(){
  int N;
  cin>>N;
  Graph G(N);
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }

  pair<int,int> p=dfs(G,0,-1);
  int v=p.second;
  p=dfs(G,v,-1);
  int n=p.first;
  if((n-1)%3==0){
    cout<<"Second"<<endl;
  }else{
    cout<<"First"<<endl;
  }

}


Measured memory_bytes: 23680
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct Node{ int p, l, r,t;};
struct Node T[MAX];
int n, H, D[MAX],h[MAX];

void getDepth(int u){
  // if(D[u]!=NIL) return ;
  int d=0;
  /*while(1){
    if(T[u].p==NIL){
      break;
    }
    else{
      d++;
      u = T[u].p;
  }
  return d;
  }*/
  if(T[u].r!=NIL){
    D[T[u].r]=D[u]+1;
    getDepth(T[u].r);
  }
  if(T[u].l!=NIL){ 
    D[T[u].l]=D[u]+1;
    getDepth(T[u].l);
  }
}

int getheight(int u){
  int a,s;
  a=s=0;
  if(T[u].r==NIL && T[u].l==NIL) return 0;
  if(T[u].l!=NIL){
    a=getheight(T[u].l)+1;
  }
  if(T[u].r!=NIL){
    s=getheight(T[u].r)+1;
  }
  if(a>s) return a;
  else return s;
}

void print(int u){
  printf("node %d: parent = %d,",u,T[u].p);
if(T[u].p==NIL)/*(T[T[u].p].l==NIL && T[T[u].p].r ==NIL) */printf(" sibling = -1, ");
  else if(T[T[u].p].r==u)  printf(" sibling = %d, ",T[T[u].p].l);
  else   if(T[T[u].p].l==u) printf(" sibling = %d, ",T[T[u].p].r);
  printf("degree = %d, ",T[u].t);
  printf("depth = %d, height = %d, ",D[u],h[u]);
  if(T[u].p==NIL) printf("root\n");
  else if(T[u].t==0) printf("leaf\n");
  else printf("internal node\n");
  /*
  printf("[");
  int a;
  a=u;
  if(T[a].l!=NIL){ 
    printf("%d",T[a].l);   
    if(T[T[a].l].r==NIL) printf("]\n");
    else printf(", ");
    a=T[a].l;
    while(T[a].r!=NIL){
      printf("%d",T[a].r);
      if(T[T[a].r].r==NIL) printf("]\n");
      else printf(", ");
      a=T[a].r;
    }
  }
  else puts("]");
  */
}

main(){
  int i,d, v, c, l,r;
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d%d%d", &v,&l,&r);
    if(l!=NIL){
      T[l].p=v;
    }
    if(r!=NIL){
      T[r].p=v;
    }
    T[v].l = l;
    T[v].r = r;
  }
  for ( i = 0; i < n; i++ ){
    if(T[i].l != -1){
      T[i].t++;
    }
    if(T[i].r != -1){
      T[i].t++;
    }
  }
  
  //v = children numbers
  /*for ( j = 0; j < d; j++ ){
    scanf("%d", &c);
      T[c].p=v;
      if(j>=1){T[r].r=c;}
      if(j==0){T[v].l=c;}
      r=c;
  */
  
  
  for ( i = 0; i < n; i++ ){
    if(T[i].p==NIL){D[i]=0; getDepth(i); break;}
  }
  for ( i = 0; i < n; i++ ){
    h[i]=getheight(i); 
  }

  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}

Measured memory_bytes: 620
/**
    __author__ : p4mf
    problems_ID:
*/

#include <cstdio>
#include <map>
#include <vector>
#include <cmath>

using namespace std;
#define sz(x)          (int)((x).size(x))
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define REP(i, y)  for (__typeof(x) i = 0; i < y; i++)
#define REPI(i, y)  for (__typeof(x) i = y; i > 0; i--)
typedef long long      ll;
typedef pair<int, int> P;
typedef pair<P, int>   PP;
typedef vector<int>    VV;
typedef vector<P>      VVP;
typedef vector<PP>     VVPP;
const   int            INF = 2<<20;
const   double         EPS = 1E-8;

int main() {
    sci(N);
    int ate = N*800;

    int y = ((int)floor(N/15))*200;
    printf("%d", ate-y);
}

Measured memory_bytes: 128
#include <cstdio>

using namespace std;

template<typename Type>
void Get_Val(Type &Ret)
{
	Ret = 0;
	char ch;
	while (ch = getchar(), ch > '9' || ch < '0')
		;
	do
	{
		(Ret *= 10) += ch - '0';
	}
	while (ch = getchar(), ch >= '0' && ch <= '9');
}

const int Max_N(100050);
const int Max_Q(100050);
typedef long long int LL;

int N, Q;
LL V[Max_Q];

void init()
{
	int _Q;
	Get_Val(N), Get_Val(_Q);
	V[++Q] = N * 1LL;
	while (_Q--)
	{
		Get_Val(V[++Q]);
		while (Q - 1 >= 1 && V[Q - 1] >= V[Q])
			V[Q - 1] = V[Q], --Q;
	}
}

//设S[i]表示进行前i次操作得到的答案
//solve(i, l)表示进行前i次操作，序列前l个数的答案
//S[i] = solve(i, V[i])
//solve(i, l) = S[i - 1] * (l / V[i - 1]) + solve(i - 1, l % V[i - 1])
//找到第一个l >= V[j - 1]
//考虑记录Cnt[i]表示S[i]在最终答案中出现了多少次，倒推计算Cnt[i] 
//对于i = 1，记录每个数在最终答案中出现了多少次 

LL Cnt[Max_Q], Ans[Max_N];

inline void insert(const int &l, const int &r, const LL &v)
{
	Ans[l] += v, Ans[r + 1] -= v;
}

void solve(const int &x, const LL &l, const LL &cnt)
{
	if (x == 1)
	{
		Cnt[1] += cnt * (l / V[1]);
		if (l % N)
			insert(1, static_cast<int>(l % V[1]), cnt);
	}
	else
	{
		Cnt[x - 1] += cnt * (l / V[x - 1]);
		if (l % V[x - 1] == 0LL)
			return;
		int up(1), down(x), mid;
		while (up < down)
		{
			mid = up + ((down - up) >> 1);
			if (l % V[x - 1] >= V[mid - 1])
				up = mid + 1;
			else
				down = mid;
		}
		solve(up - 1, l % V[x - 1], cnt);
	}
}

int main()
{
	init();
	Cnt[Q] = 1LL;
	for (int i = Q;i >= 2;--i)
		solve(i, V[i], Cnt[i]);
	insert(1, V[1], Cnt[1]);
	for (int i = 1;i <= N;++i)
		printf("%lld\n", Ans[i] += Ans[i - 1]);
	return 0;
}

Measured memory_bytes: 3968
a,b,c,x,y=map(int,input().split())
if a+b<=2*c:
    print(a*x+b*y)
else:
    if x>y:
        ans=2*c*y
        rem=x-y
        ans+=min(2*rem*c,rem*a)
    elif x<y:
        ans=2*c*x
        rem=y-x
        ans+=min(2*rem*c,rem*b)
    else:ans=2*c*x
    print(ans)

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

bool solve(int data[], int depth,int maxDepth, int num, int target) {
	
	if (maxDepth < depth)return false;
	int n = num + data[depth];
	if (n == target)return true;
	if (solve(data, depth + 1, maxDepth, num, target)
		|| solve(data, depth + 1, maxDepth, n, target))return true;
	return false;
}

int main() {
	int n;
	int m;
	int data[20];
	int array[200];
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> data[i];
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> array[i];
	}

	for (int i = 0; i < m; i++) {
		if (solve(data, 0, n - 1, 0, array[i])) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3100
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


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


def factorization(n: int):
    if n == 1:
        return []  # 1は素数ではない
    # 素因数分解
    arr = []
    temp = n
    for i in range(2, int(n**0.5) + 1):  # ここにバグがないか心配
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append((i, cnt))
            if temp == 1:
                break

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

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

    return arr


def can_factorization(n: int):
    if n == 1:
        return []  # 1は素数ではない
    # 素因数分解
    arr = []
    temp = n
    for i in range(2, int(n**0.5) + 1):  # ここにバグがないか心配
        if temp % i == 0:
            arr.append(i)

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

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

    return arr


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
import random
from math import gcd


N = a_int()
A = ints()
random.shuffle(A)

# setかはすぐわかる
# setでなければ not coprime
# pairは互いに素かをみればいいのか
# つまり因数分解して足してったときにすべての素数のべき数が1以下であれば良い

g_set = 0
cnt = defaultdict(lambda: 0)
flg = 1  # pairwiseであるフラグ
for a in A:
    g_set = gcd(g_set, a)
    if flg:
        for p, n in factorization(a):
            if cnt[p] != 0:
                flg = 0
            cnt[p] += n


# print(cnt)
# for v in cnt.values():
#     if v > 1:
#         flg = 0
#         break

if g_set > 1:
    print('not coprime')
elif flg:
    print('pairwise coprime')
else:
    print('setwise coprime')


Measured memory_bytes: 198216
import bisect

n = int(input())
v = [int(item) for item in input().split()]

a = sorted(v[::2])
b = sorted(v[1::2])	

def get_frequent_num(a):
  a_max = 0
  a_max_num = 0
  i=0
  prev_i = 0
  max_value, sec_value = 0, 0
  max_num, sec_num = 0, 0
  while i < len(a):
      i = bisect.bisect(a, a[i])
      num = (i - prev_i)
      if num > max_num:
        sec_num = max_num
        max_num = num
        sev_value = max_value
        max_value = a[i-1]
      elif num > sec_num:
        sec_num = num
        sec_value = a[i-1]
      prev_i = i
  return max_num, max_value, sec_num, sec_value

amn, amv, asn, asv = get_frequent_num(a)
bmn, bmv, bsn, bsv = get_frequent_num(b)

if amv != bmv:
  print(n-amn-bmn)
elif amv == bmv:
  if amn == asn or bmn == bsn:
    print(n-amn-bmn)
  elif asn < bsn:
    print(n-bsn-amn)
  else:
    print(n-bmn-asn)

Measured memory_bytes: 14204
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };

int n, a[10001], b[10001] = {};

int main()
{
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			b[i]++;
		}
	}
	int sum = 0;
	rep(i, n) {
		sum += b[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 384
S = input()
T = input()

"""
dp[s][t]: Sのs文字目までとTのt文字目までの解
"""

dp = [[0] * (len(T)+1) for _ in range(len(S)+1)]

for s in range(1, len(S)+1):
    for t in range(1, len(T)+1):
        if S[s-1] == T[t-1]:
            dp[s][t] = dp[s-1][t-1] + 1
        else:
            dp[s][t] = max(dp[s-1][t], dp[s][t-1])

result = ""
s = len(S)
t = len(T)
while s > 0 and t > 0:
    if dp[s][t] == dp[s-1][t]:
        s -= 1
    elif dp[s][t] == dp[s][t-1]:
        t -= 1
    elif dp[s][t] == dp[s-1][t-1] + 1:
        result = S[s-1] + result
        s -= 1
        t -= 1
print(result)


Measured memory_bytes: 112348
#include <bits/stdc++.h>    //vectorを使う
using namespace std;


int main(void){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0; i < n; ++i){
        cin >> h.at(i);
    }
    int max=0;
    int num=0;
    for(int i=0; i < n; ++i){
        if(h.at(i)>=max){
            num=num+1;
            max=h.at(i);
        }else{}
    }
    cout << num << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    double a,b,h,m; cin >> a >> b >> h >> m;
    int t=h*60+m;
    double pi=acos(-1.0);
    double p=(2*pi/(double)(12.0*60.0))*(double)t;
    double q=(2*pi/((double)60))*m;
    //cout << p << " " << q << endl;
    double x=a*sin(p),y=a*cos(p);
    double xx=b*sin(q),yy=b*cos(q);
    printf("%.9f\n",sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy)));
}


Measured memory_bytes: 4180
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let hw = read_vec::<i32>();
    let mut field = Vec::new();
    for _ in 0..hw[0]{
        let inp = read::<String>();
        field.push(inp.chars().collect::<Vec<char>>());
    }
    let mut ans = true;
    'outer: for i in 0..hw[0]{
      'inner:  for j in 0..hw[1] {
            let mut v = Vec::new();
            if j != 0{v.push(field[i as usize][(j-1) as usize])};
            if j != hw[1]- 1 {v.push(field[i as usize][(j+1) as usize])};
            if i != hw[0] -1 {v.push(field[(i+1) as usize][j as usize])};
            if i != 0{v.push(field[(i-1) as usize][j as usize])};
            v.push(field[i as usize][j as usize]);
            let check = v.into_iter().filter(|&x| x == '#').count();
            if field[i as usize][j as usize] == '#'{
                if check < 2 {
                    ans = false;
                    break 'outer;
                }
            }
        }
    }
    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}



Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();
            var dic = new Dictionary<long, long>();
            for (int i = 0; i < n; i++)
            {
                if (!dic.ContainsKey(s[i]))
                {
                    dic.Add(s[i], 1);
                }
                else
                {
                    dic[s[i]]++;
                }
            }
            var selected = dic.Where(x => x.Value >= 2).ToArray();
            var ans = selected.OrderByDescending(x => x.Key).ToArray();
            if (ans.Count() < 2) WriteLine(0);
            else
            {
                if (ans[0].Value>=4)
                {
                    WriteLine(ans[0].Key * ans[0].Key);
                }
                else
                {
                    WriteLine(ans[0].Key * ans[1].Key);
                }
            }
        }
    }
}

Measured memory_bytes: 28512
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i=0,j=0,k=0;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		char[] s = sc.next().toCharArray();
		sc.close();
		int l=0;
		int r=0;
		for (i = 0; i < s.length; i++) {
			if(s[i]=='(') {
				l++;
			} else if(s[i]==')') {
				if(l>0) {
					l--;
				} else {
					r++;
				}
			} 
		}
		PrintWriter pw = new PrintWriter(out);
		for (i = 0; i < r; i++) {
			pw.print('(');
		}
		pw.print(new String(s));
		for (i = 0; i < l; i++) {
			pw.print(')');
		}
		pw.println();
		pw.flush();
	}
}


Measured memory_bytes: 21844
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define st first
#define nd second

using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set =
	tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
#define shandom_ruffle random_shuffle
 
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(11);
	cerr << fixed << setprecision(6);

	int n, m, v, p;
	cin >> n >> m >> v >> p;

	vll scores(n);
	for (ll &x : scores) { cin >> x; }
	sort(ALL(scores), greater<ll>());
	debug() << imie(scores);

	auto CanHave = [&](int idx) {
		debug() << imie(idx);
		if (idx < p) { return true; }
		const ll idx_score = scores[idx] + m;
		const int always_take = (p-1) + (n-idx-1);
		const int L = p-1;
		const int R = idx-1;
		const int rem_others = v - always_take - 1;
		debug() << imie(idx_score) << imie(always_take) << imie(rem_others);
		debug() << imie(L) << imie(R) << imie(idx_score);
		ll total = 0;
		for (int i = L; i <= R; ++i) {
			const ll rem = idx_score - scores[i];
			if (rem < 0) { return false; }
			total += min<ll>(max<ll>(0, rem), m);
		}
		if (rem_others <= 0) { return true; }
		return total >= (ll)rem_others * m;
	};

	int lft = 0, rgt = n;
	while (rgt - lft > 1) {
		const int mid = (lft + rgt) / 2;
		if (CanHave(mid)) {
			lft = mid;
		} else {
			rgt = mid;
		}
	}

	cout << rgt << "\n";
}


Measured memory_bytes: 1024
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
const int maxn = 1<<20, mod = 924844033;
int n, a[maxn];
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	ll ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += a[i]/2;
		a[i] &= 1;
		if(a[i] && a[i+1]) ans++, a[i]--, a[i+1]--;
	}
	cout << ans;
}


Measured memory_bytes: 640
#include <iostream>
  #include <iomanip>
  #include <algorithm>
  #include <cmath>
  #include <queue>
  #include <list>
  #include <limits>
  #include <string>
  #include <vector>
  #include <stack>
  using namespace std;
  typedef unsigned long long ll;

  typedef pair<ll, ll> curr;
  const int MOD = 998244353;


  int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }

  ll calc(int a, int b, int p){
    if(b == 0) return 1;
    if(b % 2 == 0){
      ll d = calc(a, b/2, p);
      return (d*d)%p;
    }else{
      return (a*calc(a, b-1, p))%p;
    }

  }

bool comp(ll a, ll b){
  return a>b;
}

  int main(){
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    ll A[1000],B[1000],C[1000];
    vector<ll> vec;
    for(int i=0;i<X;i++) cin >> A[i]; sort(A,A+X,comp);
    for(int i=0;i<Y;i++) cin >> B[i]; sort(B,B+Y,comp);
    for(int i=0;i<Z;i++) cin >> C[i]; sort(C,C+Z,comp);
    for(int i=0;i<X;i++){
      for(int j=0;j<Y;j++){
        for(int k=0;k<Z;k++){
          if((i+1)*(j+1)*(k+1) <= K) vec.push_back(A[i]+B[j]+C[k]);
        }
      }
    }
    sort(vec.begin(),vec.end(),comp);
    for(int i=0;i<K;i++) cout << vec[i] << "\n";
  }



Measured memory_bytes: 1400
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#define f first
#define s second
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define rn return
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



ll gcd(ll x, ll y) {rn y%x ? gcd(y%x,x) : x;}


vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>> ans;
    for(ll i = 2; i*i <= n; i++){
        if (n%i) continue;
        ans.emplace_back(i,0);
        while(n%i == 0){
            n/=i;
            ans.back().second++;
        }
    }
    if (n!=1) ans.emplace_back(n,1);
    rn ans;
}

int main(){
    ll A,B; cin >> A >> B;
    ll g = gcd(A,B);
    auto f = factorize(g);
    ll ans =  1 + f.size();
    cout << ans;
    rn 0;
}


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

using namespace std;

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

int main(){
	int x,y;
	cin >> x >> y;

	for(int i=0;i<=x;i++){
		if(i*4+(x-i)*2==y){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
  int n,min=1e9,c=0,a;
  scanf("%d",&n);
  while(n--){
    scanf("%d",&a);
    if(min>=a)c++;
    if(min>a)min=a;
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main() {
  int A,B,C,D;
  scanf("%d %d %d %d", &A, &B, &C, &D);
  while (1)
  {
      C = C - B;
      if(C <= 0){
          printf("Yes");
          break;
      } 
      A = A - D;
      if(A <= 0){
          printf("No");
          break;
      } 
  }
  return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  ll sum = 0;
  rep(i,n) {
    cin >> a[i];
    mp[a[i]]++;
    sum += a[i];
  }
  
  int q;
  cin >> q;
  rep(i,q) {
      int s, t;
      cin >> s >> t;
      sum += (t-s) * mp[s];
      cout << sum << endl;
      mp[t] += mp[s];
      mp[s] = 0;
  }

  return 0;
}



Measured memory_bytes: 7920
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main(){
	int n;
	cin >> n;
	while (n--){
		unsigned int x, a[8] = {};
		rep(i, 8) scanf("%x", a+i);
		scanf("%x", &x);

		unsigned int key = 0;
		rep(i, 32){
			unsigned int sum = 0;
			rep(j, 8) sum += a[j] ^ key;
			key |= (1ll << i)*((sum&(1ll << i)) != (x&(1ll << i)));
		}

		printf("%x\n", key);
	}

	return 0;
}

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

int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;

    int l,r;
    l=a*60+b;
    r=c*60+d;

    cout<<r-e-l<<endl;


}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)cin >> a[i];

    sort(a, a+n, greater<int>());

    int alice = 0, bob = 0;
    for(int i=0;i<n;i++){
        if(i%2==0)alice += a[i];
        else bob += a[i];
    }

    cout << alice - bob << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    int L;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
        this.L = sc.nextInt();
    }
    
    //解答処理
    private int solve() {
    	int answer = 0;
    	int min = Integer.MAX_VALUE;
        
        int[] taste = new int[N];
        for (int i = 0; i < N; i++) {
        	taste[i] = L + (i+1) - 1;
        	answer += taste[i];
        	min = Math.min(Math.abs(taste[i]), min);
        }
        
        if (L + N - 1 < 0) {
        	answer += min;
        } else {
        	answer -= min;
        }
        return answer;
    }
    
    //出力
    public void show(int answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35804
n = int(input())
a = list(map(int, input().split()))
money = 1000
kabu = 0
for i in range(n-1):
    if a[i] < a[i+1] and money != 0:
        kabu += money // a[i]
        money -= a[i] * (money // a[i])
    elif a[i] > a[i+1] and kabu != 0:
        money += a[i] * kabu
        kabu = 0
print(money + a[-1] * kabu)

Measured memory_bytes: 8884
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, m, h, w, x, y, sum, k, q;
P p[ohara];

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

  cin >> n >> m;
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    p[i] = m_p(a[i], b[i]);
  }
  sort(p, p + m);
  rep(i, m) a[i] = p[i].fi, b[i] = p[i].se;

  ll le = -LINF, ri = LINF;
  rep(i, m) {
    if (p[i].fi < ri) {
      le = p[i].fi;
      ri = min(ri, p[i].se);
    } else {
      ans++;
      le = p[i].fi;
      ri = p[i].se;
    }
  }
  Cout(ans + 1);
  return 0;
}

Measured memory_bytes: 7936
#include<stdio.h>
int main(void)
{
	int a, b, c, x;
	scanf("%d %d %d", &a, &b, &c);
	if(a>b){
		x=a; 
		a=b;
		b=x;
	}
	if(a>c){
		x=a;
		a=c;
		c=x;
	}
	if(b>c){
		x=b;
		b=c;
		c=x;
	}
	
	printf("%d %d %d\n", a, b, c);
	
	return 0;
}

Measured memory_bytes: 596