akhauriyash/Code-Regression huggingface dataset:
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
a = a[::-1]
if N == 1:
    print(abs(a[0]-W))
elif abs(a[0]-a[1]) > abs(a[0] - W):
    print(abs(a[0]-a[1]))
else:
    print(abs(a[0] - W))

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;


int main() {
	double a, b, x;
	cin >> a >> b >> x;
	double water = x / a;
	//cout << "water:" << water << endl;

	double mid_angle = atan2(b , a);

	double ok = 0;
	double ng = M_PI / 2.0;

	while(fabs(ok - ng) > 0.000000000001) {
		double mid = (ok + ng) / 2;
		double cur;
		//cout << "mid:" << mid << " mid_angle:" << mid_angle << endl;
		if (mid < mid_angle) {
			cur = a * b - a *  a * tan(mid) / 2.0;
			//cout << "mid_angle < mid" << endl;
		} else {
			cur = b * b * tan(M_PI / 2.0 - mid) / 2.0;
			//cout << "mid_angle >= mid" << endl;

		}
		//cout << "ok:" << ok << " ng:" << ng << " cur:";
		//cout << cur << endl;
		if (cur >= water) {
			ok = mid;
		} else { 
			ng = mid;
		}
	}

	cout << fixed << setprecision(10) << ok  * 180.0 / M_PI << endl;
	return 0;
}


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

int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;int o=0;
  for(int i=0;i<k;i++){
    if(a>i)o++;
    else if(b+a<=i)o--;
  }cout<<o<<endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define double long double
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    int l,r;
    cin>>l>>r;
    int d;
    cin>>d;
    int i=2;int ans=0;
    while(d<=r)
    {
        if(d>=l)ans++;
        d/=(i-1);
        d*=i;i++;
    }
    cout<<ans<<endl;
    
}


return 0;
}





Measured memory_bytes: 3540
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 27 02:58:21 2020

@author: liang
"""

N, M = map(int,input().split())
MOD = 10**9 + 7

if abs(N-M) >= 2:
    ans = 0
else:
    ans = 1
    for i in range(1,N+1):
        ans *= i
        ans %= MOD

    for i in range(1,M+1):
        ans *= i
        ans %= MOD
    
    if N == M:
        ans *= 2
        ans %= MOD
print(ans)
    

Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << '\n'

using ll = long long;
using namespace std;

const int N = 1e5 + 1;
ll dp[2][N];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
#ifdef LOCAL_DEFINE
	freopen("in.txt", "r", stdin);
#endif

	int n, w;
	cin >> n >> w;

	for (int i = 0; i < n; ++i)
	{
		int weight, value;
		cin >> weight >> value;

		for (int j = 1; j <= w; ++j)
		{
			dp[1][j] = dp[0][j];
			if (j >= weight) {
				dp[1][j] = max(dp[1][j], dp[0][j - weight] + value);
			}
		}
		memcpy(dp[0], dp[1], sizeof(ll) * (w + 1));
	}

	cout << dp[1][w] << '\n';

	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <numeric>
#include <bitset>
#include <stack>
#include <cstring>
using namespace std;

const int INF = 1 << 30;
const double EPS = 1e-10;

int main()
{
  vector<long long> dp(2), l(2), h(2), n(2);
  dp[0] = l[0] = h[0] = n[0] = 0LL;
  dp[1] = 43LL;
  l[1] = 0LL;
  h[1] = 15LL;
  n[1] = 43LL;

  long long low = 15, high = 90, num = 48;
  while (dp.back() < 1000000000000000000LL) {
    // range
    l.push_back(low);
    h.push_back(high);
    n.push_back(num);
    dp.push_back(dp.back() + num*((high - low) / 15LL));

    // next
    l.push_back(high);
    h.push_back(high+15LL);
    num += 3LL;
    n.push_back(num);
    dp.push_back(dp.back() + num);

    // next
    low = high+15LL;
    high = high*10LL + 90LL;
    num += 5LL;
  }

  long long s;
  while (cin >> s) {
    unsigned int idx = 0;
    for (unsigned int i = 0; i < dp.size(); ++i) {
      if (s <= dp[i]) {
        idx = i;
        break;
      }
    }

    long long k = (s - (dp[idx-1] + 1LL)) / n[idx];
    long long kk = (s - (dp[idx-1] + 1LL)) % n[idx];
    long long begin = l[idx] + k*15LL + 1LL;
    stringstream ss;
    for (int i = 0; i < 30; ++i) {
      if ((begin+i)%15 == 0)
        ss << "FizzBuzz";
      else if ((begin+i)%3 == 0)
        ss << "Fizz";
      else if ((begin+i)%5 == 0)
        ss << "Buzz";
      else
        ss << (begin+i);
    }
    cout << ss.str().substr(kk, 20) << endl;
  }

  return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;

ll N, M;

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

  cin >> N >> M;

  if (N == 1 && M == 1) {
    cout << 1 << endl;
  } else if (N == 1) {
    cout << M-2 << endl;
  } else if (M == 1) {
    cout << N-2 << endl;
  } else {
    cout << (N-2)*(M-2) << endl;
  }

  return 0;
}


Measured memory_bytes: 384
import * as fs from 'fs'
import {debug} from '../../../util'

const input = fs.readFileSync('/dev/stdin', 'utf8').trim()

const output = (x: string | number | boolean): void => console.log(x)
const splitLine = (string: string): string[] => string.split('\n')
const splitBlank = (string: string): string[] => string.split(' ')
const toNumbers = (array: string[]): number[] => array.map(v => Number(v))
const range = (end: number, start :number = 0): number[] => [...Array(end - start)].map((v, i) => i + start)

// debug(input)

/* ここから */
let N = +input
let ans = ''
const alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'w', 'z']
//
// while (true) {
// 	let amari = N % 26
// 	if (amari === 0) {
// 		ans = alphabet[25] + ans
// 		N -= 26
// 		N /= 26
// 	} else {
// 		ans = alphabet[amari-1] + ans
// 		N -= amari
// 		N /= 26
// 	}
// 	if (N === 0) {
// 		break
// 	}
// }


while (N > 0) {
	N -= 1
	ans += String.fromCharCode('a'.charCodeAt(0) + N % 26)
	N = Math.floor(N / 26)
}
console.log(ans.split('').reverse().join(''))

Measured memory_bytes: 29644
import sys
input = sys.stdin.readline
def prime_factorize(n):
    res = []
    for i in range(2, int(n**0.5)+1):
        if n % i != 0:continue
        ex = 0
        while n % i == 0:
            ex += 1
            n = n//i
        res.append((i, ex))
    if n != 1:res.append((n, 1))
    return res
def main():
    N = int(input())
    p = prime_factorize(N)
    ans = 0
    for v, ex in p:
        current = 1
        while ex > 0:
            ex -= current
            if ex >= 0:
                ans += 1
                current += 1
            else:
                break
    print(ans)
if __name__ == "__main__":
    main()

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

int main()
{
    ll n, k; cin >> n >> k;

	ll ans = 0;

	for (ll i = k; i <= n + 1; i++) {

		ll minSum = i * (i - 1) / 2;
		ll maxSum = i * n - minSum;

		ans = (ans + (maxSum - minSum + 1) % mod) % mod;

	}

	cout << ans << endl;

    return 0;

}

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

int main(void)
{
    int a, b, c, d; cin >> a >> b >> c >> d;
    bool res;
    while (1)
    {
        c -= b;
        if (c <= 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if (a <= 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3612
import java.io.*;
import java.util.*;

public class Main {
    FastScanner in;
    PrintWriter out;

    void solve() {
        int more = 15;
        for (char c : in.next().toCharArray()) {
            if (c == 'x') {
                more--;
            }
        }
        out.println(more >= 8 ? "YES" : "NO");
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}


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



Measured memory_bytes: 2688
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a,b,c,d;
    a = n/1000;
    n = n%1000;
    b = n/100;
    n = n%100;
    c = n/10;
    n = n%10;
    d = n;
    if((a==b && b==c) || (b==c && c==d)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var S = ReadLine();
        var K = int.Parse(ReadLine());

        var ans = new List<string>();
        var stack = new Stack<(string str, List<int> idx)>(S.Select((c, i) => (c, i)).OrderByDescending(x => x.c).GroupBy(x => x.c).Select(g => (g.Key.ToString(), g.Select(x => x.i).ToList())));

        while(ans.Count < K)
        {
            var (str, idx) = stack.Pop();
            ans.Add(str);
            var next = new List<(string s, int i)>();
            foreach (var i in idx)
                if(i + 1 < S.Length)
                    next.Add((str + S[i + 1], i + 1));
            foreach (var (_str, _idx) in next.OrderByDescending(x => x.s).GroupBy(x => x.s).Select(g => (g.Key, g.Select(x => x.i).ToList())))
                stack.Push((_str, _idx));
        }


        WriteLine(ans[K - 1]);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,Q;
map<int,int> M;
ll sum=0;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x;
		M[x]++;
		sum+=x;
	}
	cin>>Q;
	while(Q--) {
		cin>>x>>y;
		sum-=1LL*M[x]*x;
		sum+=1LL*M[x]*y;
		M[y]+=M[x];
		M[x]=0;
		cout<<sum<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


map<pair<ll,ll>, ll> cnt;//座標,黒個数
vector<pair<ll,ll> > lst;//使用された座標
map<ll,ll> ans;//ans[0]~ans[9];

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


    ll H,W,N;
    cin >> H >> W >> N;
    
    rep(k,N){
        ll a, b ; cin >> a >> b;
        ll num = 0;
        rep(i,3){
            rep(j,3){
                ll x = a-i; ll y = b-j;
                if(x < 1) continue; if(x > H-2) continue;
                if(y < 1) continue; if(y > W-2) continue;
                cnt[mp(x,y)] ++;
                lst.pb(mp(x,y));
                num ++;
            }
        }
    }
    rmsame(lst);
    
    rep(i,10) ans[i] = 0;
    
    rep(i,lst.size()){
        ll num = cnt[lst[i]];
        ans[num]++;
    }

    ans[0] = (H-2)*(W-2);
    rep(i,10){
        if(i == 0) continue;
        ans[0]-=ans[i];
    }
    rep(i,10){
        cout << ans[i] << endl;
    }
    
    //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 72548
n = int(input())
a = [int(input()) for i in range(n)]
ans = 0
for i in range(n-1):
    if a[i]%2 and a[i+1]:
        a[i+1] -= 1
        ans += 1
    ans += a[i]//2
ans += a[-1]//2
print(ans)

Measured memory_bytes: 7072
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

const int dx[] = { 1, 0, -1, 0 };
const int dy[] = { 0, 1, 0, -1 };
const int dd[] = { 1, 0, 3, 2 };
const char ch[] = { 'E', 'S', 'W', 'N' };

class Trl {
public:
	int x,y,c,d;
	Trl(int x, int y, int d) : x(x), y(y), d(d) {}
};
typedef pair<int,int> PII;

int main()
{
	int X,Y;
	while (cin >> X >> Y, X||Y)
	{
		string stg[Y];
		for (int i=0; i<Y; i++)
			cin >> stg[i];

		vector<Trl> v;
		for (int y=0; y<Y; y++)
		for (int x=0; x<X; x++)
		{
			if (stg[y][x] == 'E')
				v.push_back(Trl(x,y,0));
			if (stg[y][x] == 'S')
				v.push_back(Trl(x,y,1));
			if (stg[y][x] == 'W')
				v.push_back(Trl(x,y,2));
			if (stg[y][x] == 'N')
				v.push_back(Trl(x,y,3));
		}

		int ans = 0;
		while (v.size() > 0 && ans <= 180)
		{
			int s = v.size();
			vector<Trl> upd;
			vector<int> nx(s,0), ny(s,0);
			for (int i=0; i<s; i++)
			{
				Trl t = v[i];
				bool f=1;
				for (int k=0; k<4; k++)
				{
					nx[i] = t.x + dx[(t.d+dd[k])%4];
					ny[i] = t.y + dy[(t.d+dd[k])%4];
					if (nx[i] < 0 || nx[i] >= X || ny[i] < 0 || ny[i] >= Y) continue;
					if (!(stg[ny[i]][nx[i]] == '.' || stg[ny[i]][nx[i]] == 'X')) continue;
					t.d = (t.d + dd[k]) % 4;
					f=0;
					break;
				}
				if (f) { nx[i] = t.x; ny[i] = t.y; }
				upd.push_back(t);
			}

			vector<int> cx, cy;
			for (int i=0; i<s-1; i++)
			{
				for (int k=i+1; k<s; k++)
				{
					if (nx[i] == nx[k] && ny[i] == ny[k])
					{
						if ((upd[i].d+1)%4 > (upd[k].d+1)%4)
						{
							nx[k] = v[k].x; ny[k] = v[k].y;
						}
						else
						{
							nx[i] = v[i].x; ny[i] = v[i].y;
						}
					}
				}
			}

			int p=0;
			for (int i=0; i<s; i++)
			{
				if (stg[ny[i]][nx[i]] == 'X')
				{
					stg[v[i].y][v[i].x] = '.';
					upd.erase(upd.begin()+p);
				}
				else
				{
					stg[v[i].y][v[i].x] = '.';
					stg[ny[i]][nx[i]] = ch[upd[p].d];
					upd[p].x = nx[i];
					upd[p].y = ny[i];
					p++;
				}
			}
			v = upd;
			ans++;
		}

		if (ans <= 180)
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  ll N; cin >> N;
  if (N % 2 == 0) cout << N << endl;
  else cout << 2 * N << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,a[SZ];
map<ll,int> ms;
pair<ll,int> ps[SZ]; int pn=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%lld",a+i),++ms[a[i]];
	for(auto g:ms)
		ps[++pn]=g;
	int ans=0;
	for(ll u=1073741824LL;u;u>>=1)
	{
		int j=pn;
		for(int i=1;i<=pn;++i)
		{
			while(i<=j&&ps[i].fi+(ll)ps[j].fi>u) --j;
			if(i<=j&&ps[i].fi+(ll)ps[j].fi==u)
			{
				if(i==j) ans+=ps[i].se/2,ps[i].se%=2;
				else
				{
					int u=min(ps[i].se,ps[j].se);
					ps[i].se-=u; ps[j].se-=u; ans+=u;
				}
			}
		}
	}
	cout<<ans<<"\n";
}


Measured memory_bytes: 18944
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int main() {
	int h, w;
	int a, b;

	std::cin >> h >> w;
	std::cin >> a >> b;

	std::cout << (h*w) + (a*b) -(a*w)-(b*h) << std::endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		char[] s = sc.next().toCharArray();
		int ans = 0;
		for(int i = 0; i < 3; i++) {
			if(s[i] == 'R') {
				ans++;
			}
		}
		if(s[1] == 'S' && ans == 2) {
			ans = 1;
		}
		System.out.println(ans);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 32652
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

llong dijkstra(llong start, llong end, vector<vector<pair<llong, llong>>> edge) {
    llong minCost[edge.size()];
    for (llong i = 0; i < edge.size(); i++) {
        minCost[i] = INF;
    }

    priority_queue<
        pair<llong, llong>,  // cost, index
        vector<pair<llong, llong>>,
        greater<pair<llong, llong>>
    > nodeHeap;

    nodeHeap.push(make_pair(0, start));

    while (!nodeHeap.empty()) {
        llong cost = nodeHeap.top().first;
        llong node = nodeHeap.top().second;
        nodeHeap.pop();

        if (minCost[node] <= cost) {
            continue;
        }

        minCost[node] = cost;

        for_each(edge[node].begin(), edge[node].end(), [&](pair<llong, llong> e){
            llong nextNode = e.first;
            llong newCost = cost + e.second;
            nodeHeap.push(make_pair(newCost, nextNode));
        });
    }

    return minCost[end];
}

int main(void) {
    llong N, M;
    cin >> N >> M;  // N頂点 M辺

    vector<vector<pair<llong, llong>>> edge(N*3);

    for (llong i = 0; i < M; i ++) {
        llong fromNode, toNode;
        llong cost = 1;
        cin >> fromNode >> toNode;
        fromNode--;
        toNode--;
        edge[fromNode*3].push_back(make_pair(toNode*3 + 1, cost));
        edge[fromNode*3 + 1].push_back(make_pair(toNode*3 + 2, cost));
        edge[fromNode*3 + 2].push_back(make_pair(toNode*3, cost));
    }

    llong start, end;
    cin >> start >> end;

    start--;
    end--;

    llong dist = dijkstra(start*3, end*3, edge);

    if (dist == INF) {
        cout << "-1" << endl;
    } else {
        cout << dist / 3 << endl;
    }


    return 0;
}



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

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

    int mn = a[0], mx = a[0];
    long long sum = 0;
    for (int i = 0;i<n;i++) {
         mn = min(mn,a[i]);
         mx = max(mx,a[i]);
         sum += a[i];
    }

    cout<<mn<<" " <<mx<<" "<<sum<<endl;
    
}
        
        


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

vector<ll> width = {1LL};

ll solve(ll s1, ll s2, ll l1, ll l2, int level){
    if (level == 0) return abs(l1-l2);
    ll w = width[level-1];
    if (s1/w != s2/w) {
        return abs(s1-s2) + abs(l1-l2);
    } else if (s1/w == 1 && abs(l1/w - l2/w) >= 2) {
        return min(s1%w + s2%w + 2, w*2 - s1%w - s2%w) + abs(l1-l2);
    } else {
        return solve(s1%w, s2%w, l1, l2, level-1);
    }
}

int main(void){
    rep(i,30){
        width.push_back(width.back() * 3LL);
    }
    int Q;
    cin >> Q;
    rep(q,Q){
        ll a,b,c,d;
        cin >> a >> b >> c >> d;
        a--,b--,c--,d--;
        if (abs(a-c) > abs(b-d)) {
            swap(a,b), swap(c,d);
        }
        cout << solve(a,c,b,d,30) << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define REV(v) reverse(v.begin(),v.end())
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
#define v1out(v) FOR(j,0,v.size()){cout<<v[j]; if(j!=(ll)v.size()-1)cout<<" ";else cout<<endl; }
#define v2out(v) FOR(i,0,v.size())v1out(v[i]);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> v(n);
    map<ll,ll> mp;
    FOR(i,0,n){
        cin>>v[i];
        mp[v[i]-i]++;
    }
    ll ans=0;
    FOR(i,0,n){
        ll t = v[i]+i;
        t = -t;
        ans += mp[t];
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 27488
def resolve():
    import math
    a, b, h, m = map(int, input().split())
    a_deg = h / 12 * 360 + m / 60 * 30
    b_deg = m / 60 * 360
    print(math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(min(360 - abs(a_deg - b_deg), abs(a_deg - b_deg))))))

resolve()

Measured memory_bytes: 9512
#pragma GCC optimize ("Ofast", "unroll-loops", "loop-nest-optimize")

#include <bits/stdc++.h>

#define REP(i, n) REPI(i, 0, n)
#define REP1(i, n) REPI(i, 1, n)
#define REPI(i, init, n) for(int i = init; i < n; i++)
#define MS(arr, val) memset(arr, val, sizeof(arr))
#define SZ(x) (x).size()
#define ALL(x) (x).begin(), (x).end()
#define EB emplace_back
#define UB upper_bound
#define LB lower_bound
#define FS first
#define SC second

#ifdef __WIN32__
inline size_t fread_unlocked(void *_buf, int _sz, int _cnt, FILE *_stream)
{
	return fread(_buf, _sz, _cnt, _stream);
}//fread_unlocked
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef long double LDB;
//typedef pair<int, int> P;

char buf[100000];

inline char gc()
{
	static char *st = buf, *ed = buf;

	if (st >= ed)
	{
		st = buf;
		ed = st + fread_unlocked(buf, 1, sizeof(buf), stdin);

		if (st == ed) return EOF;
	}//if

	return *(st++);
}//gc

template<class T>
inline bool rit(T &_a)
{
	char _c = gc();
	bool neg = false;
	for (; _c < '0' || _c > '9'; _c = gc())
	{
		if (_c == EOF) return false;
		if (_c == '-') neg = true;
	}//for

	for (_a = 0; _c >= '0' && _c <= '9'; _c = gc())
		_a = _a * 10 + _c - '0';

	if (neg) _a = -_a;

	return true;
}//rit

template<class S, class ...T>
inline bool rit(S &_a, T&... _b)
{
	if (!rit(_a)) return false;
	return rit(_b...);
}//rit

//============================================================================//

const int MAXN = 0 + 10;
//const int INF8 = 0x3f;
//const int INF32 = 0x3f3f3f3f;
//const int MOD = 1e9 + 7;
//const int MOD = 46337; //maximum prime int for multiplying
//const LL MOD = 2999999929; //maximum prime LL for multiplying
//const LL INF64 = 0x3f3f3f3f3f3f3f3f;
//const DB PI = acos(-1);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int N, A, B, ans = 0;
	
	rit(N, A, B);
	REP1(i, N + 1)
	{
		int t = i, sum = 0;
		
		while (t)
		{
			sum += t % 10;
			t /= 10;
		}//while
		
		if (A <= sum && sum <= B) ans += i;
	}//REP1 i
	
	cout << ans;
	
	return 0;
}//main


Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main {
  def main(args: Array[String]){
    val input = readLine().split(" ").map(_.toInt)
    val (w, h, x, y, r) = (input(0), input(1), input(2), input(3), input(4))
    val result = if(x - r < 0 || y - r < 0 || x + r > w || y + r > h) "No" else "Yes"

    println(result)
  }
}

Measured memory_bytes: 43832
import java.util.*;
import java.awt.geom.*;

public class Main{
	int INF = 1 << 29;
	
	class C implements Comparable<C>{
		int read, write;

		public C(int read, int write) {
			this.read = read;
			this.write = write;
		}

		@Override
		public int compareTo(C arg0) {
			return arg0.read - this.read;
		}

		@Override
		public String toString() {
			return "C [read=" + read + ", write=" + write + "]";
		}
		
	}

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			if(n == 0) break;
			C [] data = new C[n];
			int sumRead = 0, sumWrite = 0;
			for(int i = 0; i < n; i++){
				int read = sc.nextInt();
				int write = sc.nextInt();
				data[i] = new C(read, write);
				sumRead += read;
				sumWrite += write;
			}
			Arrays.sort(data);
			if(data[0].read > sumRead - data[0].read){
				int restTime = data[0].read - (sumRead - data[0].read);
				boolean [] dp = new boolean[restTime + 1];
				dp[0] = true;
				for(int i = 1; i < n; i++){
					for(int j = restTime; j >= 0 ; j--){
						if(! dp[j]) continue;
						int next = j + data[i].write;
						if(next > restTime) continue;
						dp[next] = true;
					}
				}
				
				int ind = -1;
				for(int i = 0; i <= restTime; i++){
					if(dp[i]){
						ind = i;
					}
				}
				System.out.println(sumRead + sumWrite + (restTime - ind));
			}
			else{
				System.out.println(sumRead + sumWrite);
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);
//----------------------------------------------------------------

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

ll tmp = 1;
ll sum = 1;
ll ans = 1;
ll N,M;

void dfs(vector<pair<long long, long long> > &F,int i) {
    if (F.size()==i) {
        //cout << tmp << " " << sum << endl;
        if (sum>=N) ans = max(ans,tmp);
    }
    else {
        rep(j,F[i].second+1) {
            ll t = pow(F[i].first,F[i].second-j);
            ll s = pow(F[i].first,j);
            tmp *= t;
            sum *= s;
            dfs(F,i+1);
            tmp /= t;
            sum /= s;
        }
    }
}

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

    auto F = prime_factorize(M);
    dfs(F,0);
    cout << ans << endl;
}


Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
#define ll long long
string s;
ll num,t=10,ans;
ll cnt[2200];
int main()
{
	cnt[0]=1;
	cin>>s;
	for(int i=s.size()-1;i>=0;i--)
	{
		num=(num+(s[i]-'0')*t)%2019;
		ans+=cnt[num];
		cnt[num]++;
		t=t*10%2019;
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 3776
h,w=map(int,input().split())
l=[]
for i in range(h):
  l.append(list(input()))
f=False
for i in range(h):
  for j in range(w):
    if i==0 and j==0 and l[i][j]=='#':
      if l[i][j+1]=='.' and l[i+1][j]=='.':
        f=True
    if i==0 and 0<j<w-1 and l[i][j]=='#':
      if l[i][j-1]=='.' and l[i][j+1]=='.' and l[i+1][j]=='.':
        f=True
    if i==0 and j==w-1 and l[i][j]=='#':
      if l[i][j-1]=='.' and l[i+1][j]=='.':
        f=True
    if 0<i<h-1 and j==0 and l[i][j]=='#':
      if l[i-1][j]=='.' and l[i][j+1]=='.' and l[i+1][j]=='.':
        f=True
    if 0<i<h-1 and 0<j<w-1 and l[i][j]=='#':
      if l[i][j-1]=='.' and l[i-1][j]=='.' and l[i][j+1]=='.' and l[i+1][j]=='.':
        f=True
    if 0<i<h-1 and j==w-1 and l[i][j]=='#':
      if l[i][j-1]=='.' and l[i-1][j]=='.' and l[i+1][j]=='.':
        f=True
    if i==h-1 and j==0 and l[i][j]=='#':
      if l[i-1][j]=='.' and l[i][j+1]=='.':
        f=True
    if i==h-1 and 0<j<w-1 and l[i][j]=='#':
      if l[i-1][j]=='.' and l[i][j-1]=='.' and l[i][j+1]=='.':
        f=True
    if i==h-1 and j==w-1 and l[i][j]=='#':
      if l[i][j-1]=='.' and l[i-1][j]=='.':
        f=True
if f:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 3192
n, k = gets.split.map(&:to_i)
p = []
n.times do
  p.push(gets.to_i)
end
p.sort!
ret = nil
(n - k + 1).times do |i|
  dif = p[i + k - 1] - p[i]
  ret = dif if ret.nil? || (dif < ret)
end
puts (ret)

Measured memory_bytes: 4016
N,mod=map(int,raw_input().split())
packs=map(int,raw_input().split())
odd=0
even=0

def nCk(n,k):
    result=1
    for i in range(n-k+1,n+1):
        result*=i
    for i in range(1,k+1):
        result/=i
    return result

for i in packs:
    if i%2==1:
        odd+=1
    else:
        even+=1

base=(2**even)
result=0
if mod==1:
    for i in range(1,odd+1,2):
        result+=base*nCk(odd,i)
elif mod==0:
    for i in range(0,odd+1,2):
        result+=base*nCk(odd,i)
print result

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
#define	rep(i,n)	for(int i=0;i<n;i++)
int main(){
  long long n,m;	cin >> n >> m;
  vector<vector<long long>>	data(n);
  rep(i,m){
    long long a,b;	cin >> a >> b;	a--;	b--;
    data[a].push_back(b);
    data[b].push_back(a);
  }
  
  vector<long long>	k(n,-1);
  k[0]=0;
  queue<long long>	p;
  p.push(0);

  while(!p.empty()){
    long long x=p.front();	p.pop();
    for(long long xi:data[x]){
      if(k[xi]!=-1)	continue;
      k[xi]=x;
      p.push(xi);
    }
  }
  
  for(long long x:k){
    if(x!=-1)	continue;
    cout << "No";
    return 0;
  }
  
  cout << "Yes" << endl;
  for(int i=1;i<n;i++){
    cout << k[i]+1 << endl;
  }
  
}

Measured memory_bytes: 12952
#include<bits/stdc++.h>
using namespace std;
int  main (){
  int a,b,c;
  cin>>a>>b>>c;
  if(b-c<0){
    if(a-abs(b-c)<0){
    cout<<"dangerous"<<"\n";
    return(0);
    }else{
      cout<<"safe"<<"\n";
      return(0);
    }
  }
  cout<<"delicious"<<"\n";
  return(0);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[])
{
    int a, b;

    scanf("%d%d", &a, &b);
    if (a < b)
        puts("a < b");
    else if (a > b)
        puts("a > b");
    else
        puts("a == b");

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n+2);
  for(int i = 1; i <= n; i++) cin >> a.at(i);
  
  long long sum = 0;
  for(int i = 0; i <= n; i++){
    sum += abs(a.at(i) - a.at(i+1));
  }
  
  for(int i = 1; i <= n; i++){
    cout << sum - abs(a.at(i) - a.at(i-1)) - abs(a.at(i) - a.at(i+1)) + abs(a.at(i-1) - a.at(i+1)) << endl;
  }
}

Measured memory_bytes: 3948
#include<stdio.h>

int main(){
  while(1){
    int m,f,r;
    char g;
    
    scanf("%d %d %d", &m,&f,&r);

    if(m+f+r == -3) break;
    
    int sum = m+f;

    if(m == -1 || f == -1){
      g = 'F';
    }else if(sum >= 80){
      g = 'A';
    }else if(sum >= 65){
      g = 'B';
    }else if(sum >= 50){
      g = 'C';
    }else if(sum >= 30 ){
      if(r >= 50)    g = 'C';
      else           g = 'D';
    }else{
      g = 'F';
    }

    printf("%c\n", g);
  }
  
  return 0;
}



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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1, -1);
    int s[10], c[10];
    for (int i = 1; i <= m; i++)
    {
        cin >> s[i] >> c[i];
    }
    int flag = 0;
    if (n == 1)
    {
        for (int i = 1; i <= m; i++)
        {
            if (a[s[i]] == -1)
            {
                a[s[i]] = c[i];
            }
            else
            {
                if (a[s[i]] != c[i])
                {
                    flag = 1;
                    break;
                }
            }
        }
        if (!flag)
        {
            if (a[1] > 0)
                cout << a[1] << "\n";
            else
                cout << 0 << "\n";
        }
        else
            cout << -1 << "\n";
    }
    else
    {
        for (int i = 1; i <= m; i++)
        {
            if (a[s[i]] == -1)
            {
                if (s[i] == 1 && c[i] == 0)
                {
                    flag = 1;
                    break;
                }
                a[s[i]] = c[i];
            }
            else
            {
                if (a[s[i]] != c[i])
                {
                    flag = 1;
                    break;
                }
            }
        }
        if (flag)
            cout << -1 << "\n";
        else
        {
            for (int i = 1; i <= n; i++)
            {
                if (i == 1 && a[i] == -1)
                    cout << 1;
                else if (i > 1 && a[i] == -1)
                    cout << 0;
                else
                    cout << a[i];
            }
            cout << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] button = new int[N];
		for(int i=0; i<N; i++) {
			button[i] = sc.nextInt();
		}

		int p = 0;
		boolean ans = false;
		for (int i = 0; i < N; i++ ) {
			int num = button[p];
			if(num == 2) {
				System.out.println(i+1);
				return;
			}
			p = num-1;
		}
		System.out.println(-1);
	}
}


Measured memory_bytes: 51328
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>


int main()
{
	ssd
	#define task "TASK"
	 //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    ll n,k,j;
    cin>>n>>k;
    long double sum=0;
    for(ll i=1;i<=n;i++)
    {
        j=0;
        while((i<<j)<k)
        {
            j++;
        }
      //  cout<<j<<" ";
        sum+=pow(0.5,j);
    }

  //  if(k<=n)
    //{
      //  sum+=(n-k+1);

    //}
    sum=sum/n;
    cout<<fixed<<setprecision(9)<<sum<<endl;
	return 0;
}


Measured memory_bytes: 4056
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,ans=0;
  cin >> n;
  ll a[n],ca[n];
  map<ll,bool> mp;
  for(int i=0;i<n;i++){
    cin >> a[i];
    ca[i]=a[i];
  }
  sort(ca,ca+n);
  for(int i=0;i<n;i++){
    mp[ca[i]]=(i%2==0);
  }
  for(int i=0;i<n;i++){
    if(mp[a[i]]^(i%2==0)){
      ans++;
    }
  }
  cout << ans/2<<endl;
}


Measured memory_bytes: 8064
#include <iostream>
#include <vector>

int main(){
	const int MAX = 20;
	const int MIN = 0;
	
	int num;
	std::cin >> num;

	std::vector< std::vector<long int> > equation((num - 1), std::vector<long int>((MAX + 1), 0));
	int value;
	std::cin >> value;
	equation[0][value] = 1;	//最初数字の等式の数を1とセットする．
	for(int i = 0; i < (num - 2); ++i){
		std::cin >> value;
		for(int j = 0; j <= MAX; ++j){
			if((j + value) <= MAX){
				equation[i + 1][j] += equation[i][j + value];
			}
			if((j - value) >= MIN){
				equation[i + 1][j] += equation[i][j - value];
			}
		}
	}
	std::cin >> value;
	std::cout << equation[num - 2][value] << std::endl;
	return 0;
}

Measured memory_bytes: 1228
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
for i in range(n+1):
    u = s[i:] + s[:i]
    if u == t:
        print('Yes')
        quit()
print('No')

Measured memory_bytes: 38256
import numpy as np

N,K,Q = map(int, input().split())
n = [0]*N
for _ in range(Q):
    n[int(input())-1] +=1

nn = np.array(n)
ans = K - Q + nn
for an in ans:
    if an > 0:
        print('Yes')
    else:
        print("No")

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

int main() {
	long long N, A, B;
	cin >> N >> A >> B;
	vector<long long> X(N);
	for (int i = 0; i < N; i++) cin >> X[i];
	long long ans = 0;
	for (int i = 1; i < N; i++) ans += min((X[i] - X[i-1])*A, B);
	cout << ans << endl;
}


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

int d,score,i,j,k,day,v,pscore,cscore,id;
int c[26],s[365][26],last[26],t[365];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> d;
  for(i=0;i<26;i++) {
    cin >> c[i];
  }
  for(i=0;i<d;i++) {
    for(j=0;j<26;j++) {
      cin >> s[i][j];
    }
  }
  for(i=0;i<d;i++) {
    for(j=0;j<26;j++) {
      int tscore=s[i][j];
      for(int k=0;k<26;k++) {
        if(k==j) continue;
        tscore-=c[k]*(i+1-last[k]);
      }
      if(j==0) score=tscore;
      else if(tscore>score) {
        score=tscore;
        t[i]=j;
      }
    }
    last[t[i]]=i+1;
  }
  int cnt=800000;
  while(cnt--) {
    day=rand()%d;
    v=rand()%26;
    if(t[day]==v) continue;
    int check[2]={v,t[day]};
    pscore=0;
    cscore=0;
    for(i=0;i<2;i++) last[check[i]]=0;
    for(i=0;i<d;i++) {
      pscore+=s[i][t[i]];
      last[t[i]]=i+1;
      for(j=0;j<2;j++) {
        int id=check[j];
        pscore-=c[id]*(i+1-last[id]);
      }
    }
    for(i=0;i<2;i++) last[check[i]]=0;
    for(i=0;i<d;i++) {
      if(day==i) {
        cscore+=s[i][v];
        last[v]=i+1;
      }
      else {
        cscore+=s[i][t[i]];
        last[t[i]]=i+1;
      }
      for(j=0;j<2;j++) {
        id=check[j];
        cscore-=c[id]*(i+1-last[id]);
      }
    }
    if(pscore<cscore) {
      t[day]=v;
    }
  }
  for(i=0;i<d;i++) {
    printf("%d\n",t[i]+1);
  }
}

Measured memory_bytes: 3832
#include <iostream>
#include <vector>

using namespace std;

long long int N;
int N_dig;
vector<long long int> seen;

long long int dfs(long long int cur_num, int c3, int c5, int c7, int cur) {
    if(cur==N_dig) {
        if(c3 && c5 && c7) {
            if(cur_num<=N) {
                for(int si=0; si<seen.size(); si++) {
                    if(seen[si]==cur_num) {
                        return 0;
                    }
                }
                seen.push_back(cur_num);
                return 1;
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }
    
    return dfs(cur_num, c3, c5, c7, cur+1)+\
           dfs(cur_num*10+3, c3+1, c5, c7, cur+1)+\
           dfs(cur_num*10+5, c3, c5+1, c7, cur+1)+\
           dfs(cur_num*10+7, c3, c5, c7+1, cur+1);
}

int main() {
    cin >> N;
    N_dig = 0;
    long long int n=N;
    while(n) {
        N_dig++;
        n/=10;
    }
    
    cout << dfs(0, 0, 0, 0, 0) << endl;

    return 0;
    
}

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

using namespace std;

int main(){
	int X;
	int J;
	int max=0;
	cin >> X;
	for(int i=31;i >= 1;i--){
		for(int j=2;j < 10;j++){
			J = pow(i,j);
			if(J>1000) break;
			else if(J <= X){
				if(max < J) max = J;
			}
		}
	}
	cout << max <<endl;
	return 0;
}

Measured memory_bytes: 256