akhauriyash/Code-Regression huggingface dataset:
#import sys
#input = sys.stdin.readline
import random
import bisect
#from statistics import mean, median, variance, stdev

#template input

def IT(): #整数1個
    return int(input())
def IL(): #整数複数
    return [int(_) for _ in input().split()]
def IS(): #文字列複数
    return [_ for _ in input().split()]
def ILS(n): #整数1つ　縦にズラーってなってるやつ
    return [int(input()) for _ in range(n)]
def SLS(n): #文字列　縦にズラーってなってるやつ
    return [input() for _ in range(n)]
def ILSS(n): #整数複数　縦にズラーってなってるやつ
    return [[int(_) for _ in input().split()] for j in range(n)]

#template technique
def bit_full_search(ss):
    n = len(ss)
    for i in range(1 << n):
        s = ""
        for j in range(n + 1):
            if ((1 & i >> j) == 1):
                s += ss[j]
        print(s)
def bit_full_search2(A):
    #https://blog.rossywhite.com/2018/08/06/bit-search/
    value = []
    for i in range(1 << len(A)):
        output = []

        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                #output.append(A[j])
                output.append(A[j])
        value.append([format(i, 'b').zfill(16), sum(output)])

    value.sort(key=lambda x:x[1])
    bin = [value[k][0] for k in range(len(value))]
    val = [value[k][1] for k in range(len(value))]
    return bin, val
def matching_bisect(list1_val, list2_val, n):
    #2分探索
    j = 0
    for i in range(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val):
            if list1_val[i] + list2_val[j] == n:
                #ans = list2_bin[j] + list1_bin[i]
                break
    return j

"""ここからメインコード"""


def main():
    s = input()
    year = int(s[0:4])
    month = int(s[5:7])
    day = int(s[8:10])

    if year < 2019:
        print("Heisei")
    elif year > 2019:
        print("TBD")
    else:
        if month <= 4:
            print("Heisei")
        else:
            print("TBD")



main()


Measured memory_bytes: 39280
N,M,X,Y = map(int, input().split())
List_x = [int(x) for x in input().split()]
List_y = [int(y) for y in input().split()]

max_x = max(List_x)
min_y = min(List_y)
if max(X,max_x)+1 <= min(Y,min_y):
    print("No War")
else:
    print("War")

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main()
{
	long long int m,n;
	int i;
	while(scanf("%lld %lld",&m,&n) != EOF)
	{
		m += n;
		i = 0;
		while(m)
		{
			i++;
			m /= 10;
		}
		printf("%d\n",i);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    int M=0;
    int L=0;
    cin>>N;
    vector<long long>vec(N);
    for(int X=0;X<N;X++){
        cin>>vec.at(X);
        if(X>0 && vec.at(X)<=vec.at(X-1)){
            M++;
        }
        else if(X>0 && vec.at(X)>vec.at(X-1)){
            if(M>=L){
                L=M;
            }
            M = 0;
        }
    }
    cout<<max(L,M)<<endl;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
#define L "\n"
#define S " "
#define ll long long
#define pb push_back
#define mp make_pair
#define vi std::vector<int>
#define si std::set<int>
#define vl std::vector<long long>
#define qi std::queue<int>
#define de(a) cout << #a << "  ------>  " << a << "\n"
#define SIZE 100002
#define INF INT_MAX
#define FOR(i, n) for (i = 1; i <= n; i++)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;
ll n, p[SIZE], w[SIZE];
ll dp[103][SIZE];
bool flag[103][SIZE];

ll f(ll i, ll weight)
{
    ll prof1, prof2, unc = weight;
    flag[i][unc] = 1;

    if (i == n)
    {
        if (w[i] <= weight)
            return dp[i][weight] = p[i];
        else
            return dp[i][weight] = 0;
    }
    if (flag[i + 1][weight])
    {
        prof1 = dp[i + 1][weight];
    }
    else
        prof1 = f(i + 1, weight);
    weight -= w[i];
    if(weight < 0) return dp[i][unc] = prof1;
    if (flag[i + 1][weight])
    {
        prof2 = p[i] + dp[i + 1][weight];
    }
    else
        prof2 = p[i] + f(i + 1, weight);
    return dp[i][unc] = max(prof1, prof2);
}

void solve()
{
    ll i, W;
    cin >> n >> W;
    FOR(i, n)
    {
        cin >> w[i];
        cin >> p[i];
    }
    cout << f(1, W) << L;
}
int main()
{
    FASTIO;
    // #ifndef ONLINE_JUDGE
    //     freopen("in.txt", "r", stdin);
    // #endif
    int t;
    // cin >> t;
    // while (t--)
    solve();
    return 0;
}

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


int main()
{
    ll n;
    cin>>n;
    string s;
    while(n>0LL){
        int i=n%26LL;
        if(i==0){
            s+='z';
            n-=26;
        }
        else s+=char(i-1+'a');
        n/=26LL;
    }
    reverse(s.begin(),s.end());
    cout<<s;
}


Measured memory_bytes: 3620
def cal_f(n):
    if n%2 == 0:
        return int(n/2)
    else:
        return int(3*n + 1)


def main():
    s = int(input())
    a_list = [s]
    counter = 2
    while True:
        s = cal_f(s)
        if s in a_list:
            print(counter)
            break
        else:
            a_list.append(s)
            counter += 1

main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15



int main() {
	int n, m;
	cin >> n >> m;
	cout << (1900*m+100*(n-m)) * pow(2, m) << endl;
	return 0;
}






Measured memory_bytes: 256
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
t = []
t.append(A);t.append(B);t.append(C)
N = int(input()) 
num = [(int(input())) for x in range(N)]
for i in range(3):
  if t[i][0] in num and t[i][1] in num and t[i][2] in num:
    print('Yes')
    exit()
  if t[0][i] in num and t[1][i] in num and t[2][i] in num:
    print('Yes')
    exit()
if (t[0][0] in num and t[1][1] in num and t[2][2] in num) or (t[0][2] in num and t[1][1] in num and t[2][0] in num):
  print('Yes')
  exit()
print('No')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define de printf("hgsgdh\n");
using namespace std;
int main()
{

    long long s=0;
    int n,k,h[200006],i;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>h[i];
        s+=h[i];
    }
    if(k==0)
    {
        cout<<s<<endl;
        return 0;
    }

    if(n<=k)
    {


        cout<<"0"<<endl;
        return 0;
    }
    else{

        sort(h+1,h+n+1);

    for(int j=n;;j--,k--)
    {
        

		if(k==0)
		{
			break;
		}
        s-=h[j];

        //cout<<s<<endl;
    }
    cout<<s<<endl;

    return 0;
    }

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	string st;
	cin >> st;
	string a[3]={"Sunny", "Cloudy", "Rainy"};
	for(int i=0;i<3;i++){
		if(a[i]==st){
			cout << a[(i+1)%3] << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i < n; i++)
using namespace std;
using ll = long long;
int main(void){
    int n,y;
    cin>>n>>y;
    int a,b,c;
    for(a=0;a<=n;a++){
        for(b=0;b<=n;b++){
            c=n-a-b;
            int money=10000*a+5000*b+1000*c;
            if(money==y&&c>=0){
                cout<<a<<" "<<b<<" "<<c<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;

    return 0;
}

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

int main(){
    ll n, m;
    cin >> n >> m;
    if(abs(n - m) > 1){
        cout << 0 << endl;
        return 0;
    }
    ll mx = max(n, m);
    ll mn = min(n, m);
    ll ans = 1;
    constexpr ll mod = 1e9 + 7;
    rep(i, 1, mx+1){
        ans *= i;
        ans %= mod;
    }
    rep(i, 1, mn+1){
        ans *= i;
        ans %= mod;
    }
    if(mx - mn == 1) cout << ans << endl;
    else cout << (2 * ans) % mod << endl;
    return 0;
}

Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
char s[200111];
int n;
int cnt[256];
int main()
{
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<n;i++)
	{
		cnt[s[i]]++;
	}
	ll tot=1ll*n*(n+1)/2;
	for(int i=0;i<256;i++)
	{
		tot-=1ll*cnt[i]*(cnt[i]+1)/2;
	}
	putsi(tot+1);
	return 0;
}

Measured memory_bytes: 384
from collections import defaultdict
n = int(input())
l1, l2 = [], []
l3 = []
d = defaultdict(dict)

for i in range(n):
    s,  p = (x for x in input().split())
    p = int(p)
    d[s][i] = p

s_sorted = sorted(d.items(), key=lambda x:x[0])

for i in s_sorted :
    s = sorted(i[1].values(), reverse = True)
    l3.append(s)


for i in range(len(s_sorted)) :
    for k, v in sorted(s_sorted[i][1].items(), key=lambda x: -x[1]) :
        print(k + 1)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int a, b;
	cin >> a >> b;
	if ((a <= 8) && (b <= 8)) cout << "Yay!\n";
	else cout << ":(\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int n = in.nextInt(), ans = 0;
            for(int a = 0; a < 10; a++){
                for(int b = 0; b < 10; b++){
                    for(int c = 0; c < 10; c++){
                        for(int d = 0; d < 10; d++){
                            if(a + b + c + d == n) ++ans;
                        }
                    }
                }
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 19300
S = str(input())
le = len(S)
s = []

for i in range(le):
    s.append(S[i])

r = s.count("R")

if r == 0:
    print(0)
elif r == 1:
    print(1)
elif r == 2:
    if s[1] == "S":
        print(1)
    else:
        print(2)
elif r == 3:
    print(3)


Measured memory_bytes: 9024
"use strict";
    
const main = arg => {
    const N = parseInt(arg.split("\n")[0].split(" ")[0]);
    const M = parseInt(arg.split("\n")[0].split(" ")[1]);
    const temp = arg.split("\n").slice(1, N+1);
    
    let obj = [];
    
    for(let i in temp) {
        obj[i] = {};
        obj[i].price = temp[i].split(" ")[0];
        obj[i].stock = temp[i].split(" ")[1];
    }
    
    //小さい順から買っていく
    obj.sort((a,b)=>(a.price - b.price));
    
    let done = 0;
    let need = M;
    let ans  = 0;
    
    for(let i in obj) {
        if(obj[i].stock < need) {
            ans += parseInt(obj[i].price * obj[i].stock);
            done += parseInt(obj[i].stock);
            need -= parseInt(obj[i].stock);
        } else {
            ans += parseInt(obj[i].price * need);
            done += parseInt(need);
            console.log(ans);
            return;
        }
        if(done>=M) {
            console.log(ans);
            return;
        }
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 69656
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
	int n, t, a, ans = 0;
	double d = 10000000.0;
	cin >> n >> t >> a;
	vector<double> h(n);
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	for(int i = 0; i < n; i++){
		double x = abs(a - (t - h[i] * 0.006));
		if(d > x){
			d = x;
			ans = i;
		}
	}
	ans++;
	cout << ans << endl;
	return 0;
}

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

using ll = long long;

int main() {
    string s[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string S;
    cin >> S;
    rep(i, 7) {
        if (S == s[i]) {
            cout << 7 - i << endl;
            break;
        }
    }
}

Measured memory_bytes: 768
a,b,c=[int(x) for x in input().split()]
k=int(input())
while k > 0 and a>=b:
  b*=2
  k-=1
while k>0 and b>=c:
  c*=2
  k-=1
if a<b and b<c:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9180
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in)
							.useDelimiter("[,\\s]+");

	public static void main(String[] args){
		
		int[] l = new int[10];
		while(scan.hasNext()){
			int sum = 0;
			for(int i = 0; i < 10; i++){
				l[i] = scan.nextInt();
				sum += l[i];
			}
			int v1 = scan.nextInt();
			int v2 = scan.nextInt();
			double time = 0, xD = 0;
			time = (double) sum / (double)(v2 + v1);
			xD =(double) v1 * time;
			sum = 0;
			for(int i = 0; i < 10; i++){
				sum += l[i];
				if(xD <= sum){
					System.out.printf("%d\n", i+1);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 26508
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	vi a(m);
	rep(i, m) cin >> a[i];
	sort(all(a));
	if(n >= m){
		cout << 0 << endl;
		return 0;
	}
	vi d(m - 1);
	rep(i, m - 1){
		d[i] = a[i + 1] - a[i];
	}
	sort(all(d));
	ll ans = 0;
	rep(i, m - n){
		ans += d[i];
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
#define newline std::cout<<'\n';
#define newlinedx(num) for(int i=0;i<num;i++)std::cout<<'\n';
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ui = uint64_t;

//----------------library in this time--------------------------------
template <class T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <class T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <class T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}

long long squareTwo(const long long a,const long long b) {
    return (b == 1) ? a : squareTwo(a * 2, b - 1);
}

template <class T>
inline T Max(const T a,const T b) {
    return (a >= b) ? a : b;
}

template <class T>
inline T Min(const T a,const T b) {
    return (a <= b) ? a : b;
}

template <class T>
inline void show(T a) {
    cout << a << endl;
}

typedef struct{
    ll x;
    ll y;
}idx;


//------------------------main function-------------------------------
void Main(){
    float n;
    cin >> n;
    float a = n  / 108 * 100;
    float b = (n+1) / 108 * 100;
    float c = ceil(a);
    if(c >= a && c < b){
        cout << static_cast<int>(c) << endl;
    }else{
        cout << ":(" << endl;
    }
}
//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
     
    Main();
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Globalization;

class Program
 {
    static void Main(string[] args)
    {
        string nyuryoku;
        string[] x,y;
        int number ,total;
        double d1 = 0,d2 = 0 ,d3 = 0, d = 0;
        var final = new List<double>();

        nyuryoku = Console.ReadLine();
        number = int.Parse(nyuryoku);
 
        x = new string[number];
        y = new string[number];
        nyuryoku = Console.ReadLine();
        x = nyuryoku.Split(' ');
        nyuryoku = Console.ReadLine();
        y = nyuryoku.Split(' ');
        total = 0;
        for (int i = 0; i < number; i++)
        {
            total = Math.Abs(int.Parse(x[i]) - int.Parse(y[i]));
            d1 += total;
            d2 += Math.Pow(total, 2);
            d3 += Math.Pow(total, 3);
            if (total > d)
                d = total;
        }
        d2 = Math.Sqrt(d2);
        d3 = Math.Pow(d3, 1.0 / 3.0);


        Console.WriteLine("{0}\n{1}\n{2}\n{3}", d1, d2, d3, d);

    }
 }



Measured memory_bytes: 18036
loop do
    n, m = gets.split.map(&:to_i)
    break if n == 0 && m == 0
    d = m.times.map{gets.split.map(&:to_i)}
    d = d.sort
    inf = Array.new(n+1,false)
    inf[1] = true
    count = 1
    d.each do |dd|
        if inf[dd[1]] && !inf[dd[2]]
            inf[dd[2]] = true
            count += 1
        end
    end
    puts count
end

Measured memory_bytes: 8508
#include <iostream>

int main()
{
    using namespace std;
    string s;
    cin >> s;
    
    int32_t len = s.length();
    
    for (auto j = len - 1; j > 0; --j) {
        if (j % 2 == 0) {
            auto k = j / 2;
            if (s.substr(0,k) == s.substr(k,k)) {
                cout << j << endl;
                break;
            }
        }
    }
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z -> key < x -> key) 
      x = x -> left;
    else
      x = x -> right;

    z -> parent = y;
  }
    if(y == NIL)
      root = z;
    else if(z -> key < y -> key)
      y -> left = z;
    else
      y -> right = z;
}


void inorder(Node u){
  if(u ==  NIL) return;
  inorder(u -> left);
  printf(" %d",u -> key);
  inorder(u -> right);
}

void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u -> key);
  preorder(u -> left);
  preorder(u -> right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }
  return 0;
}

Measured memory_bytes: 24040
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rank = [0]*(n+1)

    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
            
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        elif self.rank[x] > self.rank[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def isSame(self, x, y):
        return self.find(x) == self.find(y) or x==y
        
def solve():
    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    ids = [0] * (n+1)
    for i in range(n):
        ids[p[i]] = i+1
    uf=UnionFind(n)
    for _ in range(m):
        x, y = map(int, input().split())
        uf.unite(x,y)

    print(sum(uf.isSame(i,ids[i])for i in range(1,n+1)))
    
if __name__=="__main__":
    solve()


Measured memory_bytes: 14688
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn main(){
    let n : i32 = read_as_vec()[0];
    let mut guides: Vec<(String, i32, i32)> = Vec::new();
    for i in 0..n{
        let line_str = read_as_string();
        let mut it = line_str.split_whitespace();
        let name: String = it.next().unwrap().to_string();
        let score: i32 = it.next().unwrap().parse().unwrap();
        guides.push((name, -score, i+1));
    }

    guides.sort();
    for elem in guides{
        println!("{}", elem.2);
    }

}


Measured memory_bytes: 4352
#include <stdio.h>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long Int;

Int f(int n) {
    Int r = 1;
    rep (i, n) r *= i+1;
    return r;
}

int main() {
    int n;
    scanf("%d", &n);
    cout << f(n) << endl;
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    vector<int> A(N); for (auto& a : A) cin >> a;
    set<int> S;
    for (int i = 0; i < N; i += 2) S.insert(A[i]);
    sort(begin(A), end(A));
    int ans = 0;
    for (int i = 1; i < N; i += 2) ans += S.count(A[i]);
    cout << ans << '\n';
    return 0;
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N, K;
vector<int> x, y, xa, ya;
ll ans = 2*1e9*2*1e9 + 1;
int main(){
  cin >> N >> K;
  x.resize(N), y.resize(N), xa.resize(N), ya.resize(N);
  REP(i, N){
    cin >> x[i] >> y[i];
    xa[i] = x[i];
    ya[i] = y[i];
  }
  sort(xa.begin(), xa.end());
  sort(ya.begin(), ya.end());
  
  REP(i, N){
    FOR(j, i+1, N){
      REP(k, N){
        FOR(l, k+1, N){
          int cnt = 0;
          REP(h, N){
            if(xa[i] <= x[h] && x[h] <= xa[j] && ya[k] <= y[h] && y[h] <= ya[l]){
              cnt++;
            }
          }
          if(cnt >= K){
            ans = min(ans, (ll)(xa[j] - xa[i])*(ll)(ya[l]-ya[k]));
          }
        }
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    csf = [list(map(int, input().split())) for i in range(N-1)]
    for start in range(N):
        now = 0
        for i in range(start, N-1):
            c, s, f = csf[i]
            if now <= s:
                now = s
            else:
                if now%f != 0:# 待ち時間が発生するパターン
                    now += f - now % f
            # print("出発{} time:{}".format(i, now))
            now += c
            # print("到着{} time:{}".format(i+1, now))
        print(now)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long N;cin>>N;
    vector<long long>A(N);
    for(long long i=0;i<N;i++){
        cin>>A[i];
    }
    long long ans=0,tmp=0;
    for(long long i=1;i<N;i++){
        if(A[i]<A[i-1]+tmp){
            ans+=A[i-1]+tmp-A[i];
            tmp=A[i-1]+tmp-A[i];
        }
        else{
            tmp=0;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4800
#include <iostream>
#include <cstdio>
#include <math.h>

using namespace std;

int main() {
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	double dis = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	
	printf("%.8f\n", dis);
	return 0;
}


Measured memory_bytes: 3292
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

struct arm{
  ll l;
  ll r;
};

int main(){
  int N;
  cin >> N;
  vector<arm> x(N);

  for(int i=0;i<N;i++){
    ll a,b;
    cin >> a >> b;
    x[i].l=a-b;
    x[i].r=a+b;
  }

  sort(x.begin(), x.end(), [](arm al,arm ar){
      if(al.r!=ar.r) return al.r<ar.r;
      else return al.l<ar.l;
    });

  int ans=0;
  ll cur=-2e9;
  for(int i=0;i<N;i++){
    if(cur<=x[i].l){
      ans++; cur=x[i].r;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
	using namespace std;
	#define int long long
	#define sync ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#define MOD  1000000007 
	int powm(int base,int exp,int mod=MOD) {int ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
	int32_t main()
	{
		int a,b,c;
		cin>>a>>b>>c;
		if(a+b+c>=22)
			cout<<"bust"<<endl;
		else
			cout<<"win"<<endl;

	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int t[n+1],x[n+1],y[n+1];t[0]=0;x[0]=0;y[0]=0;
	for(int i=1;i<=n;i++) cin>>t[i]>>x[i]>>y[i];
	bool chk=1;

	for(int i=0;i<n&&chk;i++){
		int dx=abs(x[i+1]-x[i]),dy=abs(y[i+1]-y[i]),dt=t[i+1]-t[i];
		if(dt%2==0){
			if((dx+dy)%2==0&&dx+dy<=dt) continue;
			else chk=0;
			}
		else{
			if((dx+dy)%2==1&&dx+dy<=dt) continue;
			else chk=0;
		}
	}
	if(chk) cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
}

Measured memory_bytes: 1408
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<long long,long long>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a);}
                a=(a*a);
                b>>=1;
        }
    return ans;
        
}
int divisor(int x){
    int ans=1;
    for(int i=2;i*i<=x;i++){
        if(x%i==0){
            ans++;
            if(x/i!=i)ans++;
        }
    }
    return ans;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(0));
    int n;
    cin>>n;
    if(n==2){
        cout<<1<<endl;
        return 0;
    }
    int ans=divisor(n-1)+1;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            //if(n%(i+1)%==0)ans++;
            int x=n;
            while(x%i==0)x/=i;
            if(x%i==1)ans++;
            if(n/i!=i){
                int j=n/i;
                x=n;
                while(x%j==0)x/=j;
                if(x%j==1)ans++;
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 384
A, B, K = map(int, input().split())
C = [A, B]
eat, given = 0, 1
for i in range(K):
    if C[eat]%2 == 1:
        C[eat] -= 1
    C[given] += C[eat]//2
    C[eat] = C[eat] // 2
    eat, given = given, eat
print(C[0], C[1])

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

using namespace std;

using ll = long long;

const ll MOD = 998244353;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

vector<int> divisor(int n) {
    vector<int> res;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != n / i) res.emplace_back(n / i);
        }
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string x;
    cin >> x;

    ll rest = 0;
    for (int i = 0; i < n; i++) {
        rest = (rest * 2 + (x[i] - '0')) % MOD;
    }
    (rest += 1) %= MOD;

    vector<int> ds = divisor(2 * n);
    sort(ds.begin(), ds.end());
    ds.pop_back();
    ll ans = 0;
    map<int, ll> memo;

    for (int d : ds) {
        if (d == n) continue;

        int g = __gcd(d, n - d);
        if ((n - d) / g % 2 == 0) {
            continue;
        }

        if (d / g % 2 == 1) {
            continue;
        }

        /*
        vector<int> foo(n, -1);
        for (int i = 0; i < n; i++) {
            if (foo[i] == -1) {
                foo[i] = 0;
                g++;
            }

            if (i + n - d < n) {
                if (foo[i + n - d] == -1) {
                    foo[i + n - d] = !foo[i];
                } else if (foo[i + n - d] == foo[i]) {
                    g = 0;
                    break;
                }
            }

            if (i + d < n) {
                if (foo[i + d] == -1) {
                    foo[i + d] = foo[i];
                } else if (foo[i + d] == !foo[i]) {
                    g = 0;
                    break;
                }        
            }
        }
        if (g == 0) continue;*/

        ll hoge = 0;
        for (int i = 0; i < g; i++) {
            hoge = (hoge * 2 + (x[i] - '0')) % MOD;
        }
        (hoge += 1) %= MOD;

        string x2 = x;
        for (int i = 0; i < g; i++) {
            char c = x[i];
            for (int j = i; j < n; j += g) {
                x2[j] = c;
                c = (c == '0' ? '1' : '0');
            }
        }

        for (int i = 0; i < n; i++) {
            if (x[i] == '1' && x2[i] == '0') {
                break;
            }
            if (x[i] == '0' && x2[i] == '1') {
                hoge = (hoge + MOD - 1) % MOD;
                break;
            }
        }

        for (auto& p : memo) {
            if (g % p.first == 0) {
                hoge = (hoge + MOD - p.second) % MOD;
            }
        }
        memo[g] = hoge;

        (ans += hoge * d % MOD) %= MOD;
        rest = (rest + MOD - hoge) % MOD;
    }
    //cerr << rest << endl;

    (ans += rest * n % MOD * 2 % MOD) %= MOD;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 788
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int n,m;
    cin>>n;
    vector<pair<int,int> >v,u;
    pair<int,int>p;
    for(int i=0;i<n;i++)
    {
        cin>>m;
        p.first=m;
        p.second=i+1;
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
    {
        cout<<v[i].second<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define int long long
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string
int digitsum(int a){
  int b=0;
  while(a){
    b+=a%10;
    a/=10;
  }
  return b;
}
signed main(){
  int N,M,O,P=0,c=0,co=1,cou=0,minN=mod;
  double D,Do;
  char C,Ca;
  str S,T,U;
  cin>>N;
  vint A(N);rep(0,N)cin>>A[i];
  sort(all(A));
  rep(0,N-1)if(A[i]==A[i+1])c++;
  c>0?cout<<"NO"<<endl:cout<<"YES"<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll>P;

const ll MOD = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()


int main() {
	int a[4] = {0}, ans = 0;
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] % 2 == a[1] % 2 && a[1] % 2 == a[2] % 2 && a[0] % 2 == a[2] % 2) {
		ans = (a[2] - a[1]) / 2 + (a[2] - a[0]) / 2;
	}
	else {
		a[0] += (a[2] - a[1]);
		ans += (a[2] - a[1]);
		if (a[0] % 2 == a[2] % 2)ans +=(a[2] - a[0])/2;
		else ans += (a[2] - a[0] + 1) / 2 + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n, l = gets.split.map(&:to_i)
apples = Array.new
n.times do |i|
  apples[i] = l + i
end
min = 0
if apples.max < 0
  min = apples.max 
elsif apples.min > 0
  min = apples.min
else
  min = 0
end
puts (apples.inject(:+) - min)

Measured memory_bytes: 1788
from collections import Counter
from itertools import accumulate
import bisect

printRows = lambda x:print('\n'.join(map(str,x)))

n = int(input())
a = list(map(int, input().split()))
b = sorted(Counter(a).values())
exist = len(b)
b = [0]*(n-exist)+b
c = list(accumulate([0]+b))

ans = [n]
for k in range(2,n+1):
    l = 0
    r = n//k+1
    while r-l>1:
        x = (r+l)//2
        i = bisect.bisect_left(b,x)
        if c[i]+(n-i)*x>=x*k:
            l = x
        else:
            r = x
    ans.append(l)

printRows(ans)

Measured memory_bytes: 128360
import java.util.Scanner;

/**
 * <p>ClassName:  </p>
 * <p>Description: </p>
 * <p>Company: </p>
 *
 * @author zhangyong
 * @version 1.0.0
 * @date 2019/10/22 7:40
 */
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String str = in.next();
        if (n % 2 != 0) {
            System.out.println("No");
            return;
        }
        for (int i = 0; i < n / 2; ++i) {
            if (str.charAt(i) != str.charAt(i + n / 2)) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	char  c = cin.get();
	auto s = string("aeiou");
	cout <<
		(any_of(s.begin(), s.end(), [c](char cc) {return c == cc; }) ? "vowel" : "consonant")
		<< endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

 /* Coding Space*/
int main(){
  ll n,a,b,c,d; cin >> n >> a >> b >> c >> d;
  rep(i,n){
    ll min_v = a - i*d + (n-i-1)*c;
    ll max_v = a - i*c + (n-i-1)*d;
    //SHOW(max_v,min_v);
    if(max_v >= b && min_v <= b){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 384
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//おまじない



int main() {

	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b)*h / 2 << endl;

	return 0;
}


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

using namespace std;

main(){
  int n, m, ax[200], ay[200], bx[1000], by[1000];
  while(cin >> m && m){
    for(int i=0;i<m;i++) cin >> ax[i] >> ay[i];
    cin >> n;
    for(int i=0;i<n;i++) cin >> bx[i] >> by[i];
    for(int i=0;i<n;i++){
      int dy = by[i] - ay[0];
      int dx = bx[i] - ax[0];
      bool f;
      for(int j=0;j<m;j++){
        f = false;
        for(int k=0;k<n;k++){
          if(ay[j] + dy == by[k] && ax[j] + dx == bx[k]){
            f = true;
            break;
          }
        }
        if(!f) break;
      }
      if(f){
        cout << dx << ' ' << dy << endl;
        break;
      }
    }
  }
}

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

#define rep(i, a) for (int i = 0; i < (a); i++ )

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    cin >> N;
    vector<int> A,B;
    rep(i,N) {
        int a,b;
        cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    
    int ans = 0;

    if (N%2==1) {
        int a,b;
        a = A[N/2];
        b = B[N/2];
        ans = b-a+1;
    }
    else {
        int a = A[N/2] + A[N/2-1];
        int b = B[N/2] + B[N/2-1];
        ans = b-a+1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5028
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<29
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
int d[201][201];
int N,M,R,r[9];
int res;
bool used[9];
void dfs(int cnt,int las,int dist){
	if(cnt==R){
		res=min(dist,res);
		return;
	}
	rep(i,R){
		if(!used[i]){
			used[i]=true;
			if(las==-1)//初めなら
				dfs(cnt+1,i,0);
			else{
				dfs(cnt+1,i,dist+d[r[las]][r[i]]);
			}
				used[i]=false;
		}
	}


}
int main(){
	cin>>N>>M>>R;
	rep(i,R){
		cin>>r[i];
		r[i]--;
	}
	rep(i,N)
		rep(j,N)
			d[i][j]=INF;
	rep(i,N)
		d[i][i]=0;
	rep(i,M){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		d[a][b]=d[b][a]=c;
	}

			rep(k,N){
	rep(i,N){
		rep(j,N){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	//rep(i,N)rep(j,N)
	//	cout<<d[i][j]<<endl;
	res=INF;
//	dfs(0,-1,0);
	sort(r,r+R);
	do{
		int t=0;
		rep(i,R-1){
			t+=d[r[i]][r[i+1]];
		}
		res=min(res,t);
	}while(next_permutation(r,r+R));
	cout<<res<<endl;
		
	return 0;
}



Measured memory_bytes: 384
D,G=list(map(int,input().split()))
pc = [[int(i) for i in input().split()] for m in range(D)]

#print(pc)
minn=10000
flug=[]
def func(D,G,pc,flug,i=0,summ=0,num=0):
    global minn
    if i==D:
        #print(flug,summ,num)
        if summ>=G:
            minn=min(minn,num)
            return 0
        else:
            for j,bit in enumerate(reversed(flug)):
                if bit==0:
                    for k in range(pc[D-1-j][0]):
                        summ+=(D-j)*100
                        num+=1
                        if summ>=G:
                            minn=min(minn,num)
        return 0

    return func(D,G,pc,flug+[1],i+1,summ+pc[i][0]*100*(i+1)+pc[i][1],num+pc[i][0]) + func(D,G,pc,flug+[0],i+1,summ,num)


func(D,G,pc,flug)
print(minn)

Measured memory_bytes: 42476
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt() - 1;
		}

		UnionFind uf = new UnionFind(n);
		for (int i = 0; i < m; i++) {
			uf.union(sc.nextInt() - 1, sc.nextInt() - 1);
		}

		int answer = 0;
		for (int i = 0; i < n; i++) {
			if (uf.connected(i, a[i])) answer++;
		}

		System.out.println(answer);
	}

	private static class UnionFind {
		int[] parent;

		public UnionFind(int n) {
			parent = new int[n];
			for (int i = 0; i < n; i++) {
				parent[i] = i;
			}
		}

		public boolean connected(int x, int y) {
			return root(x) == root(y);
		}

		public void union(int x, int y) {
			parent[root(x)] = parent[root(y)];
		}

		private int root(int x) {
			while (parent[x] != parent[parent[x]]) {
				parent[x] = parent[parent[x]];
			}

			return parent[x];
		}
	}
}


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

vector<int> V[100100];
deque<int> ans;
bool vis[100100];

bool ok(int X)
{
	for(int i=0;i<V[X].size();i++)
	{
		if(!vis[ V[X][i] ]) return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	
	int N,M; cin>>N>>M;
	for(int i=1;i<=M;i++)
	{
		int t1,t2; cin>>t1>>t2;
		V[t1].push_back(t2);
		V[t2].push_back(t1);
	}
	
	ans.push_back(1); vis[1]=true;
	ans.push_back(V[1][0]); vis[V[1][0]]=true;
	
	while(!ok(ans.front()))
	{
		for(int i=0;i<V[ans.front()].size();i++)
		{
			if(!vis[ V[ans.front()][i] ])
			{
				vis[ V[ans.front()][i] ]=true;
				ans.push_front(V[ans.front()][i]);
				break;
			}
		}
	}
	
	while(!ok(ans.back()))
	{
		for(int i=0;i<V[ans.back()].size();i++)
		{
			if(!vis[ V[ans.back()][i] ])
			{
				vis[ V[ans.back()][i] ]=true;
				ans.push_back(V[ans.back()][i]);
				break;
			}
		}
	}
	
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++)
	{
		cout<<ans[i]<<" ";
	}
	
	return 0;
}


Measured memory_bytes: 6784
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long n = long.Parse(Console.ReadLine());
        int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();

        //出力
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
        {
            ans[i] = i+1;
        }

        Array.Sort(numbers, ans);


        for (int i = 0; i < n; i++)
        {
            Console.Write(ans[i] + " ");
        }


    }
}

Measured memory_bytes: 28120
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solver();
	}

	static void solver() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();// modify the graphs to the one whose diameter is
		// equal or shorter than k.
		ArrayList<Integer>[] e = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			e[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < n - 1; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			e[a].add(b);
			e[b].add(a);
		}
		depth = new int[n];
		if (k % 2 == 0) {
			int ans = Integer.MAX_VALUE / 4;
			for (int i = 0; i < n; i++) {
				Arrays.fill(depth, 0);
				bfs(i, -1, 0, e);
				int count = 0;
				for (int j = 0; j < n; j++) {
					if (depth[j] > k / 2)
						count++;
				}
				ans = Math.min(ans, count);
			}
			System.out.println(ans);
		} else if (k % 2 == 1) {
			int ans = Integer.MAX_VALUE / 4;
			for (int i = 0; i < n; i++) {
				Arrays.fill(depth, 0);
				bfs(i, -1, 0, e);
				int[] depth1 = Arrays.copyOf(depth, depth.length);
				for (int v : e[i]) {

					Arrays.fill(depth, 0);
					bfs(v, -1, 0, e);

					int[] depth2 = Arrays.copyOf(depth, depth.length);
					int count = 0;
					for (int j = 0; j < n; j++) {
						if (depth1[j] > k / 2 && depth2[j] > k / 2) {
							count++;
						}
					}
					ans = Math.min(ans, count);
				}
			}
			System.out.println(ans);
		}
	}

	static int[] depth;

	static void bfs(int v, int p, int d, ArrayList<Integer>[] e) {
		ArrayDeque<P> q = new ArrayDeque<P>();
		q.add(new P(v, p, d));
		while (!q.isEmpty()) {
			P u = q.poll();
			depth[u.me] = u.depth;
			for (int i = 0; i < e[u.me].size(); i++) {
				if (e[u.me].get(i) != u.parent)
					q.add(new P(e[u.me].get(i), u.me, u.depth + 1));
			}
		}
	}

	static class P {
		int parent;
		int me;
		int depth;

		P(int me, int parent, int depth) {
			this.me = me;
			this.parent = parent;
			this.depth = depth;
		}
	}

}


Measured memory_bytes: 22064
S = input()
l = len(S)
T = input()
if S == T:
    print('Yes')
else:
    for i in range(l-1):
        if S[l-i-1] == T[0]:
            newS = S[l-i-1:] + S[0:l-i-1]
            if T == newS:
                print('Yes')
                break
    else:
        print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

// struct edge{
//     int to, cost;
//     edge(int to, int cost):to(to), cost(cost){}
// };

int n, m, q;
vector<int> G[100010];
int v[100010], d[100010], c[100010];
int color[100010];
int f[100010];

// void dfs(int now, int dist, int cl, int pre){
//     if(dist < 0) return;
//     f[now] = true;
//     color[now] = cl;
//     rep(i, 0, G[now].size()){
//         int next = G[now][i];
//         if(next == pre) continue;
//         dfs(next, dist - 1, cl, now);
//     }
// }

void bfs(int now, int dist, int cl){
    queue<int> q;
    if(color[now] == 0) color[now] = cl;
    f[now] = dist;
    q.push(now);
    while(!q.empty()){
        int e = q.front(); q.pop();
        rep(i, 0, G[e].size()){
            int next = G[e][i];
            int nr = f[e] - 1;
            if(nr < 0) continue;
            if(color[next] == 0) color[next] = cl;
            if(f[next] >= nr) continue;
            f[next] = nr;
            q.push(next);
        }
    }
}

signed main(){
    cin >> n >> m;
    memset(color, 0, sizeof(color));
    // assert(n <= 2000 && m <= 2000 && q <= 2000);
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a]. push_back(b);
        G[b]. push_back(a);
    }
    cin >> q;
    rep(i, 0, q){
        cin >> v[i] >> d[i] >> c[i];
        v[i]--;
    }
    repb(i, q - 1, 0){
        // memset(f, 0, sizeof(f));
        // dfs(v[i], d[i], c[i], -1);
        bfs(v[i], d[i], c[i]);
    }
    rep(i, 0, n){
        cout << color[i] << endl;
    }
}

Measured memory_bytes: 11636