akhauriyash/Code-Regression huggingface dataset:
#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()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int T;
  cin >> T;
  REP(t,T) {
    int N, D;
    cin >> N >> D;

    int res = 127 * (N - 1);
    if(N % 2 == 1) {
      res += D;
    }else{
      res += (D ^ 127);
    }

    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 100000000
using namespace std;
using ll = long long;
using p = pair <int, int>;

int		main(void){
	ll		x, y;
	cin >> x >> y;
	ll		i;
	i = 1;
	while (x * 2 <= y){
		i++;
		x *= 2;
	}
	cout << i;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int x, y;
	for (int i = 1;; i++){
		cin >> x>>y;
		if (x == 0 && y == 0)break;
		if (x < y||x==y){
			cout << x << " " << y << endl;
		}
		else if(x > y){
			cout << y << " " << x << endl;
		}
	}
	
	return 0;
	}

Measured memory_bytes: 3000
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define mem(x,y) for(int i=0;i<x.size()i++){ x[i]=y; }
#define fo(i, l, r)  for((i) = (l); (i) < (r); (i)++)
#define fok(i,r,k)  for((i) = 0; (i) < (r); (i)=i+(k))
#define prnt(a,n)  { for(int i=0;i<n;i++){ cout<<a[i]<<" "; } cout<<endl; } 
#define mp make_pair
#define pb push_back
#define pi pair<int,int> 
#define pll pair<long long,long long>
#define vi vector<int> 
#define vl vector<long long>
#define vpl vector<pair<long long,long long>> 
#define vpi vector<pair<int,int>> 
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define br cout<<endl;
#define io { freopen("input.txt","r",stdin);  freopen("output.txt","w",stdout); }
ll modexpo(ll x,ll y,ll m){    x=x%m;if(y==0){return 1;}if(y%2==0){return modexpo(x*x,y/2,m); }else{    return  (x*modexpo(x*x,y/2,m))%m; }}
const int mod  = 1e9+7;
const int maxn = 1e5 + 10;

string s;int d = 0; 
int main()
{
fastio; 
cin>>s;
int i,j;
fo(i,0,s.size())
{
    d += (s[i]-'0');
}
int x = stoi(s);
if(x%d==0){ cout<<"Yes";}
else cout<<"No";
return 0;
}
//g++ -g a.cpp -o a.exe

Measured memory_bytes: 256
use proconio::input;
use std::collections::BTreeMap;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut map = BTreeMap::new();

    for a_i in a.iter() {
        map.entry(a_i).and_modify(|e| *e += 1).or_insert(1);
    }

    let sum: i64 = map.values().map(|v| (v - 1) * v / 2).sum();

    for a_i in a.iter() {
        let t = map[a_i];
        let ans = sum - (t - 1) * t / 2 + (t - 2) * (t - 1) / 2;
        println!("{}", ans);
    }
}


Measured memory_bytes: 8460
/*
 * itikara.cpp
 *
 *  Created on: 2018/05/30
 *      Author: J01003
 */
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int k,b,n,c,r;
	cin>>r>>c;
int hyou[116][116];
for(k=1;k<=r;k++){
for(b=1;b<=c;b++){
		cin>>n;
		hyou[k][b] += n;
		hyou[r+1][b]+= n;
		hyou[k][c+1]+= n;
		hyou[r+1][c+1]+= n;
}}
for(k=1;k<=r+1;k++){
for(b=1;b<=c+1;b++){
	cout<<hyou[k][b];
	if(b>c){
		break;
	}
	cout<<" ";
}
cout<<endl;
}
	return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>
#include <algorithm>

using namespace std;
typedef long long int ll;

int main() {
	ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

	ll ans = numeric_limits<ll>::max();

	ans = min(ans, X*A + Y*B);

	if(X>Y) {
		ans = min(ans, Y*C*2 + (X-Y)*A);
	} else {
		ans = min(ans, X*C*2 + (Y-X)*B);
	}

	ans = min(ans, C * max(X,Y) * 2);

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define MP make_pair
#define all(s) (s).begin(), (s).end()
#define rev(s) (s).rbegin(), (s).rend()
#define X first
#define Y second

using namespace std;

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


const int DIV = 1000000007;
ll f[100001];

int main(){
	//freopen("test.txt", "r", stdin);
	f[0] = 1;
	for(ll i = 1; i < 100001; i++){
		f[i] = i*(f[i-1])%DIV;
	}

	int N;
	while(cin >> N, N){
		int R;
		cin >> R;
		vector<int> v(N);
		rep(i, N)v[i] = i;

		rep(i, R){
			int s, t;
			cin >> s >> t;
			swap(v[s-1], v[t-1]);
		}

		vector<int> checked;

		ll ans = 0;
		rep(i, N){
			vector<int>::iterator ins = lower_bound(all(checked), v[i]);
			ll cnt = ins - checked.begin();

			ans = (ans+(v[i]-cnt)*f[N-1-i])%DIV;
			checked.insert(ins, v[i]);
		}
		cout << ans%DIV << endl;
	}

	return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rALL(x) x.rbegin(),x.rend()

using namespace std;
using ll=long long;


int main(){
  ll n,d;cin>>n>>d;
  ll d2=d*d;
  ll ans=0;
  rep(i,n){
    ll x,y;cin>>x>>y;
    if(x*x+y*y<=d2)ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 3604
"""N冊の参考書 M個のアルゴリズム 理解度X"""
N, M, X = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(N)]

bit =[]
for i in range(2 ** N):
    tmp = [0]*N
    for k in range(N):
        if 1 & i>>k:
            tmp[k] = 1
    bit.append(tmp)

ans = float('inf')
for list in bit:
        money =0
        rikai = [0]*M
        for i in range(N):
            if list[i] == 1:
                money += arr[i][0]
                for j in range(M):
                    rikai[j] += arr[i][j+1]
        if min(rikai)>=X:
            ans = min(ans, money)

if ans == float('inf'):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 69264
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n = int(readline())
p = tuple(map(int, readline().split()))
q = tuple(map(int, readline().split()))
ans = list(itertools.permutations([(i + 1) for i in range(n)]))
print(abs(ans.index(p) - ans.index(q)))


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

typedef long long ll;
typedef pair<ll, ll> pll;
const int LOG = 60;

ll l, r;

ll hi_bit(ll x) {
	for (int i = LOG; ~i; i--)
		if (x >> i & 1)
			return i;
}

ll f(ll l, ll r) { // []
	if (l == r)
		return 1;
	ll a, b;
	while ((a = hi_bit(l)) == (b = hi_bit(r))) {
		l ^= 1LL << a;
		r ^= 1LL << b;
	}
	ll c = (__builtin_popcountll(r) == 1? 0: 1 + hi_bit(r ^ (1LL << b)));
	return (((1LL << b) - l) + (1LL << c) + ((1LL << b) - max((1LL << c), l)));
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> l >> r;
	cout << f(l, r) << '\n';
}


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

namespace AtTest.Aising_2020
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();

            int[] cnts = new int[n + 1];
            for(int x = 1; x <= 100; x++)
            {
                for(int y = 1; y <= 100; y++)
                {
                    for(int z = 1; z <= 100; z++)
                    {
                        int val = x * x + y * y + z * z + x * y + y * z + z * x;
                        if (val <= n)
                        {
                            cnts[val]++;
                        }
                    }
                }
            }

            for(int i = 1; i <= n; i++)
            {
                WriteLine(cnts[i]);
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27376
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
    fast_io
    ll t,i,j,n,m,x,y;
    cin>>x;
    if(x>=1800)
        cout<<"1"<<endl;
   else if(x>=1600)
        cout<<"2"<<endl;
   else if(x>=1400)
        cout<<"3"<<endl;
   else if(x>=1200)
        cout<<"4"<<endl;
   else if(x>=1000)
        cout<<"5"<<endl;
   else if(x>=800)
        cout<<"6"<<endl;
   else if(x>=600)
        cout<<"7"<<endl;
   else if(x>=400)
        cout<<"8"<<endl;


    return 0;
}





Measured memory_bytes: 3644
def codef(S):
    # 条件に合う文字列か判別
    s_tmp = S.replace("x", "")
    for i, j in zip(s_tmp, s_tmp[::-1]):
        if i != j:
            return -1

    cnt = 0
    x_cnt = []
    for s in S:
        if s == "x":
            cnt += 1
        else:
            x_cnt.append(cnt)
            cnt = 0
    x_cnt.append(cnt)

    res = sum(abs(x-y) for x, y in zip(x_cnt, x_cnt[::-1])) // 2
    return res


if __name__ == "__main__":
    s = input()
    ans = codef(s)
    print(ans)


Measured memory_bytes: 4852
use std::iter;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (h, w) = scan!(usize, usize);
    let lines = scan!(;;h);

    println!("{}", iter::repeat("#").take(w + 2).collect::<String>());
    for l in lines.iter() {
        print!("#");
        print!("{}", l);
        println!("#");
    }
    println!("{}", iter::repeat("#").take(w + 2).collect::<String>());
}


Measured memory_bytes: 4352
#154d
N,K = map(int, input().split())
p_list = list(map(int, input().split()))

#各サイコロの期待値算出
exp_value_list = list()
for i in range(N):
    exp_value_list.append(((p_list[i])+1)/2)

#初項の期待値算出
ans = 0
for i in range(K):
    ans += exp_value_list[i]

#1個ずつずらして、最大値を求める。
selected = ans
for i in range(0,N-K):
    selected -= exp_value_list[i]
    selected += exp_value_list[i+K]
    ans = max(ans,selected)
    
print(ans)

Measured memory_bytes: 25060
#pragma region GNUC
//以下を参考にした
//https://yukicoder.me/wiki/auto_vectorization
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#pragma endregion

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;
#pragma region Math
// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}

// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}

template<class T>
T pow(T x,int n){
	T mul = x;
	T ans = (T)1;
	while(n){
		if(n&1){
			ans *= mul;
		}
		mul *= mul;
		n >>= 1;
	}
	return ans;
}
#pragma endregion //math

void solve(){
	int N;
	cin >> N;
	cout << (N+1)*N/2;
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数点以下の桁数を指定
	
	solve();
}


Measured memory_bytes: 256
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    q = deque()
    for i in range(len(s)):
        if s[i] == "0": q.append("0")
        elif s[i] == "1": q.append("1")
        else:
            if q: q.pop()
    print("".join(map(str, q)))

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3316
#include <iostream>

using namespace std;

long long exponent(long long n, long long x)
{
    long long answer = 0;
    
    while(n)
    {
        answer += n/x;
        
        n /= x;
    }
    
    return answer;
}

int main()
{
    long long n;
    cin >> n;
    
    cout << (n%2 == 0 ? exponent(n/2, 5) : 0) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){

	vector<int> a(3,-1);
	for(int i=0;i<3;i++){
		cin>> a[i];
	}
	sort(a.begin(), a.end());
	if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]){
		cout<< "YES"<< endl;
	}else{
		cout<< "NO"<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	int n;
	cin>> n;
	for(int i=0;i<n;i++){
		solve();
	}

	return 0;
}

 

Measured memory_bytes: 1204
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func isMatch(i, n int, s, t string) bool {
	for j := i; j < n; j++ {
		if s[j] != t[j-i] {
			return false
		}
	}
	return true
}

func main() {
	n, _ := strconv.Atoi(input())
	s := input()
	t := input()

	ans := 2 * n
	for i := 0; i < n; i++ {
		if isMatch(i, n, s, t) {
			ans = n + i
			break
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
s = readline.chomp
i1 = s[0..1].to_i
i2 = s[2..3].to_i
if i1 >= 1 and i1 <= 12
  if i2 >= 1 and i2 <= 12
    puts 'AMBIGUOUS'
  else
    puts 'MMYY'
  end
else
  if i2 >= 1 and i2 <= 12
    puts 'YYMM'
  else
    puts 'NA'
  end
end



Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

constexpr int MAX_N = 12,
              MAX_M = 12;

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

    int n, m, x;
    cin >> n >> m >> x;

    vector<int> c(n);
    int a[MAX_N][MAX_M];
    for (int i = 0; i < n; i++) {
        cin >> c[i];

        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    int ans = -1;
    for (int mask = 0; mask < (1 << n); mask++) {
        vector<int> points(m, 0);
        int score = 0;
        for (int i = 0; i < n; i++) {
            if ((mask >> i) & 1) {
                score += c[i];
                for (int j = 0; j < m; j++) {
                    points[j] += a[i][j];
                }
            }
        }
        bool flag = true;
        for (int i = 0; i < m; i++) {
            if (points[i] < x) {
                flag = false;
            }
        }
        if (flag && (ans < 0 || ans > score)) {
            ans = score;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3200
def p_f():
    S = input()
    T = input()
    s_n = len(S)
    t_n = len(T)
    dp = [[0] * (s_n + 1) for _ in range(t_n + 1)]

    for i in range(1, t_n + 1):
        f = False
        for j in range(1, s_n + 1):
            if S[j - 1] == T[i - 1]:
                f = True
                dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i - 1][j])
                continue

            if f:
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j])
            else:
                dp[i][j] = dp[i - 1][j]

    ans = ""
    while s_n > 0 and t_n > 0:
        if dp[t_n - 1][s_n] == dp[t_n][s_n]:
            t_n -= 1

        if dp[t_n][s_n - 1] == dp[t_n][s_n]:
            s_n -= 1

        if dp[t_n - 1][s_n] != dp[t_n][s_n] and dp[t_n][s_n - 1] != dp[t_n][s_n]:
            ans = S[s_n - 1] + ans
            s_n -= 1
            t_n -= 1

    print(ans)


if __name__ == '__main__':
    p_f()


Measured memory_bytes: 112220
s = input()
s = [int(s[:2]),int(s[2:])] 
if 0<s[0]<13 and 0<s[1]<13:
  print('AMBIGUOUS')
elif 0<s[0]<13:
  print('MMYY')
elif 0<s[1]<13:
  print('YYMM')
else:
  print('NA')

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    static long total = 0;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		long count = 0;
		int prev = sc.nextInt();
		if (prev > x) {
		    count += prev - x;
		    prev = x;
		}
		for (int i = 1; i < n; i++) {
		    int a = sc.nextInt();
		    if (prev + a > x) {
		        int sub = prev + a - x;
		        count += sub;
		        a -= sub;
		    }
		    prev = a;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 48296
use std::io::stdin;
use std::io::Error;
use std::io::Read;

#[derive(Debug)]
struct Input {
    a: Vec<u32>,
}

fn handle_input(input_str: String) -> Result<Input, Error> {
    let mut iter = input_str.split_whitespace();
    let a: u32 = iter.next().unwrap().parse().unwrap();
    let b: u32 = iter.next().unwrap().parse().unwrap();
    let c: u32 = iter.next().unwrap().parse().unwrap();
    let d: u32 = iter.next().unwrap().parse().unwrap();
    let e: u32 = iter.next().unwrap().parse().unwrap();
    let input = Input {
        a: vec![a, b, c, d, e],
    };
    Ok(input)
}

fn handle_output(input: Input) -> Result<String, Error> {
    let mut others = input
        .a
        .iter()
        .filter(|&a| a % 10 != 0)
        .collect::<Vec<&u32>>();
    others.sort_by(|&a, &b| (a % 10).partial_cmp(&(b % 10)).unwrap());
    let mut iter = others.iter();
    let mut sum = input.a.iter().filter(|&a| a % 10 == 0).sum::<u32>();
    if let Some(&&first) = iter.next() {
        sum += first;
    }
    sum += iter.map(|&a| (a / 10 + 1) * 10).sum::<u32>();
    Ok(format!("{}", sum))
}

fn main() {
    let mut input_str = String::new();
    let stdin = stdin();
    stdin.lock().read_to_string(&mut input_str).unwrap();
    let input = handle_input(input_str).unwrap();
    let output = handle_output(input).unwrap();
    println!("{}", output);
}

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

double solve() {
    ll A, B, X;
    cin >> A >> B >> X;
    if ( A*A*B/2 <= X ) {
        double s = (double)A*B - X/(double)A;
        double t = atan(2*s/(A*A));
        return t / acos(0) * 90;
    } else {
        double s = X/(double)A;
        double t = acos(0) - atan(2*s/(B*B));
        return t / acos(0) * 90;
    }
}

int main() {
    cout.precision(15);
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;


namespace aizu
{
	public class EntryPoint
	{
		public static string[] Split(string line)
		{
			return Regex.Split(line, " ");
		}
		public static int[] SplitToInts(string line)
		{
			return Regex.Split(line, " ").Select(x => int.Parse(x)).ToArray();
		}
		public static double[] SplitToDoubles(string line)
		{
			return Regex.Split(line, " ").Select(x => double.Parse(x)).ToArray();
		}
		public static long[] SplitToLongs(string line)
		{
			return Regex.Split(line, " ").Select(x => long.Parse(x)).ToArray();
		}
		public static void Main()
		{
			string line = null;
			while (null != (line = Console.ReadLine()))
			{
				var values = SplitToInts(line);
				if (0 == values[0] && 0 == values[1])
				{
					break;
				}
				
				var h = values[0];
				var w = values[1];
				
				for (int i = 0; i < h; i++)
				{
					Console.WriteLine(new string('#', w));
				}
				Console.WriteLine("");
			}
			
		}
	}


}

Measured memory_bytes: 7132
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main(){
    int A, B;
    string S;
    cin >> A >> B >> S;

    bool output = true;
    if(S[A] != '-') output = false;
    for (int i = 0; i < (A+B+1); i++)
    {
        if(S[i] == '-'){
            if(i == (A+1)-1){
                continue;
            }else{
                output = false;
            }
        }
    }
    if(output == true) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
# def calc(n):
#     return "plus" if n > 0 else "minus"
# 
# n =int(input())
# 
# array = [int(x) for x in input().split()]
# tmp = calc(array[0])
# tmp2 = 0
# res = 0
# 
# for x in range(len(array)-1):
#     tmp2 = (array[x] - array[x+1])
#     if tmp == calc(tmp2):
#         if tmp2 == "minus":
#             tmp2 = 1
#             res += (1 - tmp2)
#         else:
#             tmp2 = -1
#             res += (1 - tmp2)
# print(res)


n = int(input())
s = list()
for i in range(n):
    s.append(input())

res = ""
for c in "abcdefghijklmnopqrstuvwxyz":
    c_min = list()
    for j in s:
        cnt = 0
        for k in j:
            if k == c:
                cnt += 1
        c_min.append(cnt)
    res += c * min(c_min)

print(res)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int N=3e5+5;
const int MOD=1e9+7;
int a[N];
int b[N];
int v[N][2];
int cmp(int a,int b)
{
    return a>b;
}
int hh[N];
int ww[N];
map<int,map<int,int> >mp;
int main()
{
    int h,w,m;
    cin>>h>>w>>m;
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        mp[x][y]=1;
        a[x]++;
        b[y]++;
    }
    int MAXX=0;
    int ans=0;
    int x,y;

    for(int i=1;i<=h;i++){

        MAXX=max(a[i],MAXX);
    }
    int cou1=0;
    for(int i=1;i<=h;i++){
        if(a[i]==MAXX){
            hh[cou1++]=i;
            //cout<<i<<endl;
        }
    }
   // cout<<x<<endl;
    ans=MAXX;
    MAXX=0;
    int cou2=0;
    for(int i=1;i<=w;i++){

        MAXX=max(b[i],MAXX);
    }
    for(int i=1;i<=w;i++){
        if(b[i]==MAXX){
            ww[cou2++]=i;
            //cout<<i<<endl;
        }
    }
    //for(int i=0;i<cou1;i++) cout<<hh[i]<<endl;
    //for(int i=0;i<cou2;i++) cout<<ww[i]<<endl;
    ans+=MAXX;
    int flag=0;
    for(int i=0;i<cou1;i++){
        for(int j=0;j<cou2;j++){
            //cout<<hh[i]<<" "<<ww[j]<<endl;
            if(mp[hh[i]][ww[j]]==0){
                //cout<<hh[cou1]<<" "<<ww[cou2]<<endl;
                flag=1;
                break;
            }
        }
        if(flag) break;
    }
    if(flag)
    cout<<ans<<endl;
    else cout<<ans-1<<endl;


}






Measured memory_bytes: 50476
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 2e5;
int n, depth[N];
V<int> e[N];
void dfs(int a, int p, int d){
  depth[a] = d;
  for(int b:e[a]) if(p!=b) dfs(b, a, d+1);
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    e[a].pb(b);
    e[b].pb(a);
  }
  dfs(0, -1, 0);
  int ma = -1, s = -1;
  FOR(i, 0, n) if(ma < depth[i]){
    ma = depth[i];
    s = i;
  }
  dfs(s, -1, 0);
  ma = -1;
  FOR(i, 0, n) maxs(ma, depth[i]);
  if(ma%3==1){
    cout << "Second" << endl;
  }else{
    cout << "First" << endl;
  }
}

Measured memory_bytes: 21376
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod=1e9+7;
static const ll INF=1LL<<50;
using namespace std;

int main() {
int x,a;
  cin>>x>>a;
  if(x<a)cout<<"0"<<endl;
  else cout<<"10"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int x,y,i;
	for(i = 1; 1 ;i++){
		
		scanf("%d %d",&x,&y);
		if(x > y){
			printf("%d %d\n",y,x);
		}else if(x < y){
			printf("%d %d\n",x,y);
		}else if(x = y){
			printf("%d %d\n",x,y);
        }else{
            if(x == 0 && y == 0)
                return 0;
                }
        }
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int N;
int dp[100010];

int rec(int x) {
    if (x < 0) return INF;
    if (dp[x] >= 0) return dp[x];
    if (x == 0) return 0;
    int res = INF;
    for (int p = 1; p <= x; p *= 6) {
        CHMIN(res, rec(x - p) + 1);
    }
    for (int p = 1; p <= x; p *= 9) {
        CHMIN(res, rec(x - p) + 1);
    }
    return dp[x] = res;
}

void _main() {
    cin >> N;
    MINUS(dp);
    cout << rec(N) << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 4224
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string s,t;
    cin>>s>>t;
    t.pop_back();
    if(s==t){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
}


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int mxn=2e5+5;
ll a[mxn];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	for(int i=1; i<=n; i++){
		cin >> a[i];
	}
	sort(a+1,a+n+1);
	for(int i=1; i<=n; i++)a[i]+=a[i-1];
	int m = n/2;
	ll ans = 0;
	if(n%2){
		ans = a[n]-a[m+1] + a[n-1]-a[m];
	}else{
		ans = a[n]-a[m] + a[n-1]-a[m];
	}
	cout << ans << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 5176
N = int(input())
A = [int(a) for a in input().split()]
z = {}

for n in A:
  if n in z:
    z[n] += 1
  else:
    z[n] = 1

cnt_even = 0
for key, val in z.items():
  if val % 2 == 0: #even
    cnt_even += 1
  
cnt_odd = len(z) - cnt_even

tot = cnt_odd + cnt_even - (cnt_even % 2)
print(tot)

  

Measured memory_bytes: 21600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fl(i,a,b) for(int i=a;i<b;i++)
#define rfl(i,a,b) for(int i=a;i>b;i--)
#define cases() ll t;cin>>t;while(t--)
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    fl(i,0,n)
        cin>>a[i];
    ll flag=0,z=1;
    fl(i,0,n)
    {
        if(a[i]==z)
        {
            z++;
        }
    }
    if(z==1)
        cout<<-1;
    else
        cout<<n-z+1;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    StringBuilder s = new StringBuilder(sc.next());
    StringBuilder t = new StringBuilder(sc.next());
    int len = t.length();
    t = t.deleteCharAt(len - 1);
    String ss = s.toString();
    String tt = t.toString();
    if (ss.equals(tt)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 35552
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	string S,a1,b;
	int a;
	cin >> S;
	a = S.length();
	a1 = S.substr(0, a / 2);
	b = S.substr(a / 2 + 1, a / 2);
	if (a1==b) {
		cout << "Yes" << endl;
		}
	else {
		cout << "No" << endl;
	}
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

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

  vector<int> a(N), b(N);
  rep(i, N) { cin >> a[i]; }
  rep(i, N) { cin >> b[i]; }

  vector<int> c(N);
  rep(i, N) { c[i] = a[i] - b[i]; }
  sort(c.begin(), c.end());

  int cnt = 0;
  int64_t r = 0;
  rep(i, N) {
    if (c[i] < 0) {
      cnt++;
      r -= c[i];
    }
  }

  rrep(i, N) {
    if (r > 0) {
      r -= min((int64_t)c[i], r);
      cnt++;
    }
  }

  cout << (r > 0 ? -1 : cnt) << endl;
  return 0;
}

Measured memory_bytes: 4512
#include<iostream>

using namespace std;
int main(){
        long long a, b, c,w,d,da;
        cin >> a >> b >> c;
        w = c / (a*7+b);
        d = c % (a*7+b);
        da = d % a;
        d = d / a;
        if (da != 0) d++;
        if (d > 7) d = 7;
        cout << (w*7 + d) << endl;
        return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

 
void solve()
{
    int n;cin>>n;
    vector<pair<int,int> >ab(n);
    REP(i,n)
    {
        int x;cin>>x;
        ab[i]=mp(x,i+1);
    }
    sort(ALL(ab));
    REP(i,n)
    {
        cout<<ab[i].second<<" ";
    }cout<<endl;
}

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

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;

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

//Ctrl+Aを使わない

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

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

Measured memory_bytes: 256
INF = 10 ** 10
N = 100
n, T = map(int, raw_input().split())

stores = []
zs = []
for i in xrange(n):
    a, b = map(int, raw_input().split())
    if a == 0:
        zs.append(b)
    else:
        stores.append((a, b))

def mycmp(s1, s2):
    a1, b1 = s1
    a2, b2 = s2
    v1 = a2 + a2 * b1
    v2 = a1 + a1 * b2
    return cmp(v1, v2)

stores.sort(cmp=mycmp)
stores.append((INF, INF))
zs.sort()

m = len(zs)

for i in xrange(1, m):
    zs[i] += zs[i - 1]

dp = [ [INF for i in xrange(N)] for j in xrange(2) ]
dp[0][0] = 0
res = 0

n = len(stores)

p = 0
for i in xrange(n):
    q = p ^ 1
    dp[q] = [INF for j in xrange(N)]

    a, b = stores[i]
    for j in xrange(N):
        dp[q][j] = min(dp[q][j], dp[p][j])
        if dp[p][j] == -INF:
            continue
        if j + 1 < N:
            t = dp[p][j] + 1
            dp[q][j + 1] = min(dp[q][j + 1], dp[p][j] + 1 + a * t + b)
            if dp[q][j + 1] <= T:
                res = max(res, j + 1)
    for j in xrange(N):
        if dp[q][j] > T:
            continue
        rem = T - dp[q][j] - 1
        l, r = 0, m - 1
        while l <= r:
            mid = (l + r) / 2
            if zs[mid] + mid <= rem:
                res = max(res, j + mid + 1)
                l = mid + 1
            else:
                r = mid - 1
    p = q
print res



Measured memory_bytes: 54580
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
using namespace std;
int a[100010];
bool s[100010];
int main(){
    int n;
    while(~scanf("%d",&n)){
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            s[i]=true;
        }
        int key=a[1];
        int flag=0;
        int ans=0;
        s[1]=false;
        while(key!=2){
                //printf("\n%d ",key);
            if(!s[key]){
                flag=1;
                break;
            }
            s[key]=false;
            key=a[key];
            ans++;
        }
        if(flag) printf("-1\n");
        else printf("%d\n",ans+1);
    }
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

ll N;
vector<ll> A, B;

int main () {
  cin >> N;
  A.resize(N+1), B.resize(N);
  rep(i,N+1) cin >> A[i];
  rep(i,N) cin >> B[i];

  ll ans = 0;
  ll c = A[0];
  rep(i,N) {
    int d = min(c, B[i]);
    ans += d;
    B[i] -= d;
    c = A[i+1];
    if(B[i] > 0) {
      int d = min(c, B[i]);
      ans += d;
      c -= d;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int cnt[50][26] = {};
  for (int i = 0; i < n; i++) {
    string S;
    cin >> S;
    for (int j = 0; j < S.size(); j++) {
      cnt[i][S[j] - 'a']++;
    }
  }
  for (int i = 0; i < 26; i++) {
    int tmp = 50;
    for (int j = 0; j < n; j++) {
      tmp = min(tmp, cnt[j][i]);
    }
    for (int j = 0; j < tmp; j++) cout << (char)('a' + i);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K, Q;
	cin >> N >> K >> Q;
	vi S(N);
	REP(i, Q) {
		int a;
		cin >> a;
		a--;
		S[a]++;
	}
	REP(i, N) {
		if (K - Q + S[i] <= 0)cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const mod = 1e9 + 7;
ll n, k, i;
ll ans = 0;
ll nhan(ll a,ll b)
{
    if (b == 0)
        return 0;
    ll t;
    t = nhan(a, b/2) % mod;
    t = t % mod + t % mod;
    if (b % 2 == 0)
        return t % mod;
    else return (t % mod + a % mod) % mod;
}

ll mu(ll a, ll b)
{
    if (b == 0)
        return 1;
    ll t;
    t = mu(a, b/2) % mod;
    t = nhan(t, t) % mod;
    if (b % 2 == 0)
        return t % mod;
    else
        return nhan(t,a) % mod;
}

int main()
{
    cin >> n >> k;
    for(i=k; i<=n + 1; i++)
		ans = (ans + nhan(i, n-i+1) + 1) % mod;
		cout << ans % mod;
}


Measured memory_bytes: 3636
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
#define clr0(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,-1,sizeof(a))
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
main()
{
    timesave;
    ll n,a,b;
    ll sum=0;
    cin>>n;
    map<ll,ll>mp;
    for(ll i=1; i<=n; i++)
    {
        cin>>a;
        mp[a]++;
        sum+=a;
    }
    ll q;
    cin>>q;
    for(ll i=1; i<=q; i++)
    {
        cin>>a>>b;
        ll x=mp[a];
        if(x>0)
        {
            sum-=(x*a);
            mp[a]=0;
            mp[b]+=x;
            sum+=(x*b);
        }
        cout<<sum<<endl;

    }
}



Measured memory_bytes: 9292
#include <iostream>
#include <vector>
 
using namespace std;
 
int main() {
    int N, K; cin >> N >> K;
    vector<int> nums;
    int p;
    for (int i = 0 ; i < N; ++i) {
        cin >> p;
        nums.push_back(p);
    }

    sort(nums.begin(), nums.end());
    int res = 0;
    for (int i = 0; i < K; ++i) {
        res += nums[i];
    }    
	cout << res << endl;
}

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

int main() {
    long long n; cin >> n;
    vector<int long long> a(n+1); for (int i=0; i<n+1; ++i) cin >> a[i];
    vector<int long long> b(n); for (int i=0; i<n; ++i) cin >> b[i];
    int long long num=min(a[0],b[0]), prev_num, next_num;
    int long long ans = 0;
    for (int i=0; i<n; ++i) {
        if (i>0) num = min(a[i]-prev_num, b[i]);
        next_num = min(a[i+1], b[i]-num);
        prev_num = next_num;
        ans += num + next_num;
    }
    cout << ans << endl;
}

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

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;
  int ans=A*X+B*Y;
  for (int k=1; k<=100000; k++) {
    ans=min(ans,2*C*k+max(X-k,0)*A+max(Y-k,0)*B);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256