akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> P;
typedef pair<lint, lint> Plint;
 
const int MOD = 1e9+7;
const int INF = 1<<18;
const lint INFLINT = 1LL<<60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T&a,const T&b){if(b<a){a=b;return true;}return false;}

// Union-Find-Tree
class UnionFind {
	vector<int> par;
	UnionFind(int n):par(n){rep(i,n)par[i]=i;}
	int root(int x){if(par[x]==x)return x;return par[x]=root(par[x]);}
	void unite(int x,int y){int rx=root(x);int ry=root(y);if(rx==ry)return;par[rx]=ry;}
	bool same(int x,int y){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    
    rep(i, n) {
        cin >> s[i];
    }
    
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    
    cout << s.size();
    
    return 0;
}


Measured memory_bytes: 9544
#include <cstdio>
using namespace std;
int w, h;

void print(char &x, char &y) {
    printf("%c", x);
    for (int j = 1; j < w-1; j++) printf("%c", y);
    printf("%c\n", x);
}

void printmid(char &x, char &y, char &m) {
    printf("%c", x);
    for (int j = 1; j < w/2; j++) printf("%c", y);
    printf("%c", m);
    for (int j = w/2+1; j < w-1; j++) printf("%c", y);
    printf("%c\n", x);
}

int main() {

    int i;
    char pl ='+', l = '-', p = '.', f='|';
    char m;
    scanf("%d %d %c", &w, &h, &m);
    print(pl, l);
    for (i = 1; i < h/2; i++) print(f, p);
    printmid(f, p, m); i++;
    for (; i < h-1; i++) print(f, p);
    print(pl, l);
    return 0;
}



Measured memory_bytes: 2716
K = int(input())
A, B = map(int,input().split())
number = A
count = 0
while(1):
 if(number%K == 0):
  count +=1
 number += 1  
 if(number > B):
  if(count >0):
    print("OK")
  else:
    print("NG")
  break;

Measured memory_bytes: 9204
require 'prime'

class Integer
  def my_divisor_list
    return [1] if self == 1
    Prime.prime_division(self).map do |e|
      Array.new(e[1]+1).map.with_index do |element, i|
        e[0]**i
      end
    end.inject{|p,q| p.product(q)}.map do |a|
      [a].flatten.inject(&:*)
    end.sort
  end
end

n = gets.strip.to_i
f = n.my_divisor_list
len = n - 1

(0..f.length-1).each do |i|
  x = f[i]
  y = n / f[i]
  d = x + y - 2
  len = d if d < len
end

puts len

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	int ans = 0, n = 1;
	while(1){
		if(n >= b) break;
		n += a-1;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
P = LIST()

tmp = P[0]
ans = 1
for i in range(1, N):
	if P[i] <= tmp:
		ans += 1
		tmp = P[i]

print(ans)

Measured memory_bytes: 27192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();
            int iN = int.Parse(sS);
            sS = Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iX = 0;
            List<int> lstRst = new List<int>();
            lstRst.Add(iX);
            for (int i = 0; i < sS.Length; i++)
            {
                string sD = sS.Substring(i, 1);
                if (sD == "I") { iX += 1; }
                else { iX -= 1; }
                lstRst.Add(iX);
            }
            
            //出力
            Console.WriteLine("{0}", lstRst.Max().ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
ll ans[200000]={};
bool checked[200000]={};
map<int,vector<int>> m;
void dfs(int now){
    REP(i,m[now].size()){
        if(!checked[m[now][i]-1]){
            ans[m[now][i]-1]+=ans[now-1];
            checked[m[now][i]-1]=true;
            dfs(m[now][i]);
        }
    }
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int Q=in();
    int a,b;
    REP(i,N-1){
        cin>>a>>b;
        m[a].pb(b);
        m[b].pb(a);
    }
    ll _p,x;
    REP(i,Q){
        cin>>_p>>x;
        ans[_p-1]+=x;
    } 
    checked[0]=true;
    dfs(1);
    REP(i,N-1){
        cout<<ans[i]<<" ";
    }
    cout<<ans[N-1]<<endl;
    return 0;
}


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

int main() {
int N;
cin>>N;
if(N%10==3){
    cout<<"bon"<<endl;
}else if(N%10==0||N%10==1||N%10==6||N%10==8){
    cout<<"pon"<<endl;
}else{
    cout<<"hon"<<endl;
}
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  for (ll i = 0; i < 6; i++) {
    if (s[i] == '1') ans++;
  }
  cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0;i < N; i++){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  cout << A.at(0) << " ";
  reverse(A.begin(), A.end());
  cout << A.at(0) << " ";
  long long sum = 0;
  for(int i = 0; i < N; i++){
    sum += A.at(i);
  }
  cout << sum << endl;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define MAX 100005
#define MOD 1e9
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define endl '\n'
using namespace std;
/* ----------------------------------------------------------------------------------- */

#define fastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define scan(a) scanf("%d", &a)
#define scanll(a) scanf("%lld", &a)
#define scanD(a) scanf("%lf", &a)
#define print(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printD(a) printf("%lf\n", a)
#define printTwo(a) printf("%.2lf\n", a);
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

/* ----------------------------------------------------------------------------------- */

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)
#define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';

#define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
#define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
#define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}

/* ----------------------------------------------------------------------------------- */

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

struct debugger {
	typedef string::iterator si;
	static void call(si it, si ed) {}
	template<typename T, typename ... aT>
	static void call(si it, si ed, T a, aT... rest) {
		string b;
		for(; *it!=','; ++it)
			if(*it!=' ')
				b+=*it;
		cout << b << "=" << a << " ";
		call(++it, ed, rest...);
	}
};

/* ----------------------------------------------------------------------------------- */


void solve() {
	ll a, b;
	scanll(a), scanll(b);

	rep(i, 1, 1e4) {
		int c = floor(i * 0.08);
		int d = floor(i * 0.1);
		if(a == c && b == d) {
			print(i);
			return;
		}
	}
	print(-1);
}

int main() {
#ifdef Niloy
	read("input.txt");
	write("output.txt");
#endif

	solve();

	// __test {
	// 	solve();
	// }

	showTime;
	return 0;
}




Measured memory_bytes: 3792
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
     
    public static final int MAX = 1000;
     
    public static final int[] coins = new int[]{500, 100, 50, 10, 5, 1};
    public static final int[] maxs  = new int[]{
		Integer.MAX_VALUE,
		Integer.MAX_VALUE,
		Integer.MAX_VALUE,
		Integer.MAX_VALUE,
		Integer.MAX_VALUE,
		Integer.MAX_VALUE
    };
    
    public static final int ret_coin(int P, int[] coin_nums){
        int ret = 0;
         
        for(int i = 0; i < coins.length; i++){
            final int p_use = P / coins[i];
            final int can_use = Math.min(p_use, coin_nums[i]);
            
            ret += can_use;
            
            P -= coins[i] * can_use;
        }
         
        return ret;
    }
     
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         
        while(true){
            final int P = sc.nextInt();
             
            if(P == 0){
                break;
            }
             
            int[] coin_nums = new int[6];
            int sum = 0;
            for(int i = 0; i < 6; i++){
                coin_nums[5 - i] = sc.nextInt();
                sum += coin_nums[5 - i] * coins[5 - i];
            }
             
            final int max = Math.min(sum, P + 500);
            
            int min = Integer.MAX_VALUE;
            for(int i = P; i <= max; i++){
            	//System.out.println((i - P) + " " + ret_coin(i - P, maxs));
            	min = Math.min(min, ret_coin(i, coin_nums) + ret_coin(i - P, maxs));
            }
            
            System.out.println(min);
            
        }
         
        sc.close();
    }
}

Measured memory_bytes: 21728
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>
const long long INF=1e18;

using namespace std;

int main(void) {
    int A;

    for(int i=1;i<=5;i++){
        cin>>A;

        if(A==0){
            cout<<i<<endl;
            return 0;
        }
    }
}


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

int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	if ((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3]))
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

ans=[0]*(n+1)
xn=0
for i in range(n):
    if i!=n-1:
        xn=xn-a[i]*(-1)**i
    else:
        xn=xn+a[i]
ans[-1]=xn
ans[0]=xn
for i in range(n):
    temp=2*a[i-1]-ans[i]
    ans[i+1]=temp

print(*ans[1:])

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

int main(){
	string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s) cout<<a-1<<" "<<b;
    else cout<<a<<" "<<b-1;
}

Measured memory_bytes: 3584
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int intpow(int a, int n) {
	// a^nのint ver
	rep(i, n - 1)
		a *= a;
	return a;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1)) % mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	//約数の数（だっけ？）
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	//1桁目切り上げ
	return (n + 9) / 10 * 10;
}
int DIGIT(int n, int k) {
	//nのk桁目
	rep(i, k - 1)
		n /= 10;
	return n % 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	//nをkで何回割れるか的な
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int binary(int n) {
	//10進数→2進数
	int ans = 0;
	for (int i = 0; n > 0; i++) {
		ans += n % 2 * intpow(10, i);
		n /= 2;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool between(int x, int min, int max) {
	if (min < x && x < max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N,cou=0,ans=0;
	string x;
	cin >> N;
	vector<string>s(N);
	vector<int>t(N);
	rep(i, N)
		cin >> s[i] >> t[i];
	cin >> x;
	rep(i, N) {
		if (cou > 0)
			ans += t[i];
		if (x == s[i])
			cou++;
	}
	cout << ans << endl;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n,d=MI()
co=[]
for i in range(n):
    co.append(LI())
#print(co)
ans=0
for i in range(n):
    for j in range(n):
        l2=0
        for k in range(d):
            l2+=(co[j][k]-co[i][k])**2
        l=math.sqrt(l2)
        if l-int(l)==0:
            ans+=1
trans=(ans-n)//2
print(trans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;

for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}


Measured memory_bytes: 4452
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, m;
    cin >> n >> m;
    int a;
    int sum = 0;
    rep (i, m)
    {
        cin >> a;
        sum += a;
    }

    int ans = (n < sum ? -1 : n - sum);

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3652
# -*- coding: utf-8 -*-
import sys

X,Y = list(map(int, input().rstrip().split()))
#-----
crane = (4*X - Y) / 2
tortoise = (-2*X + Y) / 2

if (crane == tortoise == 0) or \
   (crane % 1 != 0) or (tortoise % 1 != 0):
    print("No")
    sys.exit()

if (0 <= crane <= 100) and (0 <= tortoise <= 100):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
string s;
bool b=true;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>s;
map<char,int>mp;
for(auto ss:s)mp[ss]++;
if(mp['N']==0&&mp['S']!=0)b=false;
if(mp['S']==0&&mp['N']!=0)b=false;
if(mp['W']==0&&mp['E']!=0)b=false;
if(mp['E']==0&&mp['W']!=0)b=false;
if(b)cout<<"Yes";
else cout<<"No";
return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 2000005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
ll r,c;
ll cost(ll x,ll y){
    if (x == 0) return y;
    if (y == c) return c+x;
    if (x == r) return c+r+abs(y-c);
    if (y == 0) return 2*c+r+abs(x-r);
    return -1;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> r >> c >> n;
    vector<P> ok;
    ll x1,x2,y1,y2;
    rep(i,n){
        cin >> x1 >> y1 >> x2 >> y2;
        ll c1 = cost(x1,y1),c2 = cost(x2,y2);
        if (c1 == -1 || c2 == -1) continue;
        ok.push_back(P(c1,i));
        ok.push_back(P(c2,i));
    }
    SORT(ok);
    stack<ll> s;
    rep(i,ok.size()){
        s.push(ok[i].second);
        while(s.size() > 1){
            ll s1 = s.top();s.pop();
            ll s2 = s.top();s.pop();
            if (s1 != s2){
                s.push(s2);
                s.push(s1);
                break;
            }
        }
    }
    if (s.size() == 0) PRINT("YES");
    else PRINT("NO");
}


Measured memory_bytes: 7428
program name
    implicit none
    character(4):: s
    logical:: fh, sh

    read'(a)', s

    fh = can_be_month(s(1:2))
    sh = can_be_month(s(3:4))

    if (fh .and. sh) print*, 'AMBIGUOUS'
    if ((.not. fh) .and. sh) print*, 'YYMM'
    if (fh .and. (.not. sh)) print*, 'MMYY'
    if ((.not. fh) .and. (.not. sh)) print*, 'NA'


contains
function can_be_month(str) result(ret)
    character(2):: str
    integer(4):: num
    logical:: ret

    read(str,*) num

    ret = (1 <= num .and. num <= 12)

end function
end program name

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

//使用する配列の最大要素数
#define MAX_SIZE_N 100000
//使用する変数の宣言と初期化
int N=0,K=0;
int h[MAX_SIZE_N]={0};
int result=0;

int main()
{
  cin >> N >> K;
  for(int i=0;i<N;++i) cin >> h[i];

  //処理
  sort(h, h + N, greater<int>());
  for(int i=0;i<N;++i){
    if(h[i]>=K) result++;
  }
  
  cout << result;
    
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=55;
double a[N];
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lf",&a[i]);
    sort(a+1,a+1+n);
    for(int i=2;i<=n;i++)
        a[i]=(a[i-1]+a[i])/2;
    printf("%f\n",a[n]);
}


Measured memory_bytes: 256
import java.util.Scanner;

class Run{
	public int m = 50;
	public int e = 50;
	public int r = 100;
}
	

class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int sum;
	  	String gra;
	  	
	  	Run runs = new Run();
	  	
	  	while(true) {
	  		runs.m = scanner.nextInt();
	  		runs.e = scanner.nextInt();
	  		runs.r = scanner.nextInt();
		  	
		  	if( runs.m == -1 && runs.e == -1 && runs.r == -1 )
		  		break;
		  	
	  		sum = runs.m + runs.e;
	  		
	  		
		  	if(sum >= 80)
		  		gra = "A";
		  	else if( sum >= 65 )
		  		gra = "B";
		  	else if( sum >= 50)
		  		gra = "C";
		  	else if( sum >= 30 && runs.r >= 50 )
		  		gra = "C";
		  	else if( sum >= 30)
		  		gra = "D";
		  	else
		  		gra = "F";
		  		
		  	if( runs.m == -1 || runs.e == -1 )
		  		gra = "F";
		  	
		  	switch(gra){
		  	case "A":
		  		System.out.println("A");
		  		break;
		  	case "B":
		  		System.out.println("B");
		  		break;
		  	case "C":
		  		System.out.println("C");
		  		break;
		  	case "D":
		  		System.out.println("D");
		  		break;
		  	case "F":
		  		System.out.println("F");
		  	}
		  	
  		}
        scanner.close();
  }
}


Measured memory_bytes: 26284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,k;
   cin>>a>>b>>k;
   if(k<=a)
   cout<<a-k<<" "<<b;
   else if(k>a)
   {
       ll m=k-a;
       ll n=b-m;
       if(n>0)
       {
           cout<<"0"<<" "<<n<<endl;
       }
       else if(n<=0)
       {
           cout<<"0"<<" "<<"0"<<endl;
       }
   }
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;

int constexpr N = 200005;
int n, a[N], b[N];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    vector<int> ans;
    for(int i = n; i >= 1; --i) {
        int cnt = 0;
        for(int j = i + i; j <= n; j += i) {
            cnt += b[j];
            cnt %= 2;
        }
        b[i] = cnt ^ a[i];
        if(b[i])
            ans.push_back(i);
    }
    cout << ans.size() << '\n';
    for(auto i : ans)
        cout << i << ' ';
    cout << '\n';
}

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

using namespace std;


int W,H;

pair<int,int> move(int x,int y,int dir,vector<vector<int>> &field){
  pair<int,int> ret = make_pair(-1,-1);
  if(dir==0){// ↑
    if(y-1<0 || field[y-1][x]==1)return ret;
    while(y-1>=0&&field[y-1][x]!=1){
      y--;
      if(field[y][x]==3)return make_pair(x,y);
    }
    if(y==0)return ret;
    return make_pair(x,y);
  }else if(dir==1){// ↓
    if(y+1>=H || field[y+1][x]==1)return ret;
    while(y+1<H&&field[y+1][x]!=1){
      y++;
      if(field[y][x]==3)return make_pair(x,y);
    }
    if(y==H-1)return ret;
    return make_pair(x,y);
  }else if(dir==2){// ←
    if(x-1<0 || field[y][x-1]==1)return ret;
    while(x-1>=0&&field[y][x-1]!=1){
      x--;
      if(field[y][x]==3)return make_pair(x,y);
    }
    if(x==0)return ret;
    return make_pair(x,y);
  }else{// →
    if(x+1>=W || field[y][x+1]==1)return ret;
    while(x+1<W&&field[y][x+1]!=1){
      x++;
      if(field[y][x]==3)return make_pair(x,y);
    }
    if(x==W-1)return ret;
    return make_pair(x,y);
  }
}

int dfs(int x,int y,int d,vector<vector<int>> &field){
  int ret = 1000;
  if(field[y][x]==3)return d;
  if(d==10)return 1000;
  for(int i=0;i<4;i++){
    auto p = move(x,y,i,field);
    int nx = p.first,ny = p.second;
    if(nx==-1)continue;
    if(field[ny][nx]==3){
      ret = min(dfs(nx,ny,d+1,field),ret);
      continue;
    }
    // こわす
    if(i==0){
      field[ny-1][nx] = 0;
    }else if(i==1){
      field[ny+1][nx] = 0;
    }else if(i==2){
      field[ny][nx-1] = 0;
    }else{
      field[ny][nx+1] = 0;
    }
    ret = min(dfs(nx,ny,d+1,field),ret);
    // もどす
    if(i==0){
      field[ny-1][nx] = 1;
    }else if(i==1){
      field[ny+1][nx] = 1;
    }else if(i==2){
      field[ny][nx-1] = 1;
    }else{
      field[ny][nx+1] = 1;
    }
  }
  return ret;
}



int main(){
  while(cin >> W >> H,W|H){
    vector<vector<int>> field(H,vector<int>(W));
    int sx,sy;
    //cerr << 'a' << endl;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        cin >> field[i][j];
        if(field[i][j]==2){
          sx = j,sy=i;
        }      
      }
    }
    int res = dfs(sx, sy, 0, field);
    cout << (res == 1000 ? -1 : res) << endl;
  }
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

int d[100010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k = -1;
    for(int i = 1; i * i <= 2 * n; i++){
        if(i * (i + 1) == 2 * n){
            k = i + 1; break;
        }
    }
    if(k == -1){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    cout << k << endl;
    int now = 1;
    vector<vector<int> > ans(k, vector<int>());
    rep(i, 0, k){
        rep(j, 0, i){
            ans[i].push_back(d[j]);
            d[j]++;
        }
        d[i] = now;
        rep(j, 0, k - 1 - i){
            ans[i].push_back(now);
            now++;
        }
    }
    rep(i, 0, ans.size()){
        cout << k - 1 << " ";
        for(int ii = 0; ii < ans[i].size(); ii++){
            if(ii) cout << ' ';
            cout << ans[i][ii];
        }
        cout << endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int prev = -1;
  int ans = 0;
  for (int x : A) {
    if (x == prev) {
      ans += 1;
      prev = -1;
    } else {
      prev = x;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>

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

using namespace std;
typedef long long ll;

int H, N;
int A[1001], B[1001];

ll dp[1001][10001];

ll INF = 1ll<<60;

int main() {
    cin >> H >> N;
    rep(i, N) cin >> A[i] >> B[i];

    dp[0][0] = 0;
    for (int n = 0; n < N; n ++) {
        for(int hp = 1; hp <= H; hp ++) {
            ll a = hp - A[n] < 0 ? B[n] : dp[n][hp - A[n]] + B[n];
            ll b = n == 0 ? INF : dp[n-1][hp];
            dp[n][hp] = min(a, b);
        }
    }
    cout << dp[N-1][H] << endl;
    return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;
 
typedef long long ll;

const int P=998244353,N=101;
 
int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }

string str;

struct S{
	bitset<N> s;
	int len;
	bool operator<(const S &r) const {
		int x=min(len,r.len);
		lop(i,0,x){
			if(s[i]<r.s[i])return true;
			else if(s[i]>r.s[i])return false;
		}
		return len<r.len;
	}	
};

map<S,int> f;

int dp(S cur){
	if(f.count(cur))return f[cur];
	if(cur.len==0)return 1;
	int &res=f[cur];res=0;
	S nxt,nnxt;
	nxt=(S){cur.s>>1,cur.len-1};
	res=add(res,mul(dp(nxt),1+(cur.s[0])));
	rep(a,1,cur.len)for(int k=2;a*k<=cur.len;++k){
		nxt=cur;
		for(int i=a;i<a*k;i+=a){
			lop(j,0,a){
				nxt.s[j]=nxt.s[j]&nxt.s[i+j];
			}
		}
		nxt.len=a;
		for(int i=a*k;i<cur.len;++i)nnxt.s[i-a*k]=cur.s[i];
		nnxt.len=cur.len-a*k;
		res=add(res,mul(dp(nxt),dp(nnxt)));
	}
	return res;
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	freopen("my.out","w",stdout);
#endif	
	cin>>str;
	S init;
	lop(i,0,(int)str.length())init.s[i]=str[i]-'0';
	init.len=str.length();
	cout<<dp(init)<<endl;
	return 0;
}


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

using namespace std;

int main(){

  while(1){
	int n;
	
	cin >> n;
	
	if(n == 0)
	  break;
	
	vector<int> pm(n);
	vector<int> pe(n);
	vector<int> pj(n);
	
	for(int i=0;i<n;++i){
	  int sum=0;
	  cin >> pm[i] >> pe[i] >> pj[i];

	  sum = pm[i] + pe[i] + pj[i];
	  
	  if(pm[i] == 100 || pe[i] == 100 || pj[i] == 100)
		cout << "A" << endl;

	  else if(pm[i] + pe[i] >= 180)
		cout << "A" << endl;

	  else if(pm[i] + pe[i] + pj[i] >= 240)
		cout << "A" << endl;

	  else if(pm[i] + pe[i] + pj[i] >= 210)
		cout << "B" << endl;

	  else if((pm[i] + pe[i] + pj[i] >= 150) && (pm[i] >= 80 || pe[i] >= 80))
		cout << "B" << endl;
	  
	  else
		cout << "C" << endl;
	}
  
  }

}



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

int main(void) {
	int n,i;
	char s[101],t[101];
	
	scanf("%d %s %s",&n,s,t);
	
	for (i = n;i >= 0;i--) {
		if (strncmp(s+(n-i),t,i) == 0) {
			break;
		}
	}
	
	printf("%d\n", n*2-i);
	
	return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val (a,b) = listOfInt()

    val range = (1..12)
    val to = Date(2018, a, b)
    val size = range.mapNotNull {
        val takahashi = Date(2018, it, it)
        if(to >= takahashi) takahashi else null
    }.size
    println(size)
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
            .filter { value % it == 0L }
            .map { listOf(it, value / it) }
            .flatten()
            .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 34084
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] d = new int[n];
		int ans = 0;

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

		Arrays.sort(d);
		if(d.length%2==0) {
			ans = d[d.length/2]-d[d.length/2-1];
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 49692
"""
BIT
区間[L,R]にxを加える。
座標Xでの値を求める。
"""
import sys
input=sys.stdin.readline

def bit_add(i,x):
    while i<=M:
        tree[i]+=x
        i+=i&(-i)

def bit_sum(i):
    s=0
    while i>0:
        s+=tree[i]
        i-=i&(-i)
    return s

N,M=map(int,input().split())

data=[]
for i in range(N):
    l,r=map(int,input().split())
    data.append([r-l, l, r])
data.sort()

k=0
tree=[0]*(M+1)
for d in range(1,M+1):
    
    #間隔の長さがd以下の区間だけ考えれば良い。
    while k<N and data[k][0]<d:
        bit_add(data[k][1],1)
        bit_add(data[k][2]+1,-1)
        k+=1
    
    ans=0
    for j in range(1,M//d+1):
        ans+=bit_sum(d*j)
    
    print(ans+N-k)

Measured memory_bytes: 104540
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define dec(i,j,k) for(re int i=j;i>=k;i--) 
using namespace std;
const int N=405;
const int M=1e5+5;
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,m,a[M],b[M],ans;
bool dp[N][N],die[N];
int main(){
	n=read(),m=read();
	inc(i,1,m) a[i]=read(),b[i]=read();
	inc(i,1,n){
		dp[i][i]=1;
		dec(j,m,1){
			bool x=dp[i][a[j]],y=dp[i][b[j]];
			if(x&&y){die[i]=1;break;}
			if(x) dp[i][b[j]]=1;
			if(y) dp[i][a[j]]=1;
		}
	}
	inc(i,1,n){
		if(die[i]) continue;
		inc(j,i+1,n){
			if(die[j]) continue;
			ans++;
			inc(k,1,n){
				if(dp[i][k]&&dp[j][k]){
					ans--;
					break;
				}
			} 
		}
	}
	printf("%d\n",ans);
}

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

for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        exchenge = a // 2
        a -= exchenge
        b += exchenge 
    if i % 2 == 1:
        if b % 2 == 1:
            b -= 1
        exchenge = b // 2
        b -= exchenge
        a += exchenge   
print(f'{a} {b}')

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <cstring>

int main(int argc, char *argv[])
{
    std::array<char, 5> c;
    std::string s;
    
    std::cin >> s;
    std::strcpy(c.begin(), s.c_str());

    std::sort(c.begin(), c.begin() + 4);

    if (c[0] == c[1] && c[2] == c[3] && c[0] != c[2]) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

string s;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
        a[i]--;
    }
    int now = 0;
    REP(i,n){
        if(now==1){
            put(i);
            return 0;
        }
        now = a[now];
    }
    put(-1);
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>

int main(){
  int w,n;
  scanf("%d %d",&w,&n);
  int a[w];
  for(int i=0; i<w; i++) a[i]=i+1;
  while(n--){
    int b,c,e;
    scanf("%d,%d",&b,&c);
    e=a[b-1];
    a[b-1]=a[c-1];
    a[c-1]=e;
  }
  for(int i=0; i<w; i++)
    printf("%d\n",a[i]);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define BeatMeScanf ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
const int mod=1e9+7;
ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}

ll solve(vector<ll>v){
    ll sum=0,cnt0,cnt1;

    for(int i=0;i<=60;i++){
        cnt0=0,cnt1=0;
        for(int j=0;j<v.size();j++){
            ll x=v[j]%2;
            v[j]/=2;
            if(x%2==0) cnt0++;
            else cnt1++;
        }
        sum=(sum+((cnt0*cnt1)%mod)*qpow(2,i))%mod;
    }
    return sum;
}

int main(){
    BeatMeScanf;
    int n;
    while(cin>>n){
        vector<ll>v(n);
        for(int i=0;i<n;i++) cin>>v[i];
        ll ans=solve(v);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 4992
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n,m = IL()
    a = np.array(list(IL()))
    b = np.cumsum(a,axis=0)
    if n<b[-1]:
        print(-1)
    else:
        print(n-b[-1])
if __name__=='__main__':
    Main()

Measured memory_bytes: 27756
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for (int i=0,_n=(int)(n); i < _n; i++)
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
 
typedef long long ll;

const int MAX_N = 100000;
vector<int> g[MAX_N];
int ans[MAX_N];

int f(int v) {
  int cur = (int)g[v].size();
  if (cur > 0) {
    vector<int> t;
    for (int c : g[v]) {
      int s = f(c);
      t.push_back(s);
    }
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    for (int i = 0; i < (int)t.size(); i++) {
      cur = max(cur, (t[i] + i + 1));
    }
  }
  return ans[v] = cur;
}

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

  REP(i, N) g[i].clear();
  for (int i = 1; i < N; i++) {
    int x; cin >> x;
    g[x-1].push_back(i);
  }
  f(0);
  cout << ans[0] << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}

Measured memory_bytes: 15488
from collections import deque
from copy import copy,deepcopy
from itertools import permutations,combinations
from pprint import pprint

def myinput():
    return map(int,input().split())

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

n,k = myinput()

r = n%k
r2 = abs(r-k)

ans = min(r,r2)

print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

int main(void)
{
	int N; cin >> N;
	vector<lli> A(N); rep(i, 0, N)cin >> A[i];

	int ans = 0;
	while(true) {
		bool flag = true;
		rep(j, 0, N) { 
			if (A[j] % 2 != 0)flag = false; 
			else A[j] /= 2;
		}
		if (flag)ans++;
		else break;
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int L, R, d;
  cin >> L >> R >>d;

  int ans = 0;

  for(int i = L; i <= R; i++){
    if(i%d == 0){
      ans++;
      }
    }

  cout << ans << endl;

}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  int n,c;cin>>n>>c;
  int D[c+10][c+10]={};
  for(int i=0;i<c;i++)
    for(int j=0;j<c;j++)
      cin>>D[i][j];
  int color[10][35]={};
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
      int cn;cin>>cn;
      color[(i+j)%3][cn-1]++;
    }
  int ans1=INF,ans2=INF,ans3=INF;
  for(int i=0;i<c;i++){
    for(int j=0;j<c;j++){
      for(int k=0;k<c;k++){
	if(i==j||j==k||i==k)continue;
	int cnt=0;
	for(int l=0;l<c;l++){
	  cnt+=color[0][l]*D[l][i];
	}
	for(int l=0;l<c;l++){
	  cnt+=color[1][l]*D[l][j];
	}
	for(int l=0;l<c;l++){
	  cnt+=color[2][l]*D[l][k];
	}
	ans1=min(ans1,cnt);
      }
    }
  }
  cout<<ans1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
    int a,b,c;
    std::scanf("%d %d %d",&a,&b,&c);

    if(a <= b && b <= c){
        std::printf("%d %d %d\n",a,b,c);
    }
    
    else if(a <= c && c <= b){
        std::printf("%d %d %d\n",a,c,b);
    }
    else if(b <= a && a <= c){
        std::printf("%d %d %d\n",b,a,c);
    }
    else if(b <= c && c <= a){
        std::printf("%d %d %d\n",b,c,a);
    }
    else if(c <= a && a <= b){
        std::printf("%d %d %d\n",c,a,b);
    }
    else if(c <= b && b <= a){
        std::printf("%d %d %d\n",c,b,a);
    }

return 0;
}


Measured memory_bytes: 2740
#include <bits/stdc++.h>
#include <iomanip>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<char> VB;
 
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
 
const LD eps=1e-5;
//const long long INF=(LL)(1e9)*(LL)(1e9);
const int INF=1e9;
 
template<class T>
void chmin(T& a, const T& b)
{
	if(a>b)
		a=b;
}
template<class T>
void chmax(T& a, const T& b)
{
	if(a<b)
		a=b;
}
 
const LL pow(const LL p, const LL q)
{
	LL t=1;
	REP(i,q)
		t*=p;
	return t;
}

//print for container
/*
template<typename Iterator>
void print(const Iterator& first, const Iterator& last)
{
	auto&& back=prev(last);
	for(auto e=first; e!=last; e=next(e))
		cout<<*e<<" \n"[e==back];
}*/

template<typename Head>
void print(const Head& head)
{
	cout<<head<<endl;
}

template<typename Head, typename... Tail>
void print(const Head& head, const Tail&... tail)
{
	cout<<head<<" ";
	print(tail...);
}

void io_speedup()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}

template<typename T>
T read()
{
	T t;
	cin>>t;
	return t;
}

int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	vector<int> t(n);
	int cnt=0;
	REP(i,n)
	{
		int t=read<int>();
		if(!(a<=t&&t<b))
			cnt++;
	}
	cout<<cnt<<endl;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>

using namespace std;

int main()
{
    int h=1,w=1;

    while(1){
        cin >> h >> w;
        if(h==0&&w==0){
            return 0;
        };
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cout<<'#';
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3076
#include<iostream>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;

#define mod 998244353
#define inf 0x7f7f7f7f
#define maxn 500005
#define N 300005
typedef long long ll;
typedef struct{
    int u,v, next;
}Edge;
Edge e[2*maxn];

int cnt,head[300005];

inline void add(int u,int v){
    e[cnt].u=u;
    e[cnt].v=v;
    //e[cnt].w=w;
    //e[cnt].f=f;
    e[cnt].next=head[u];
    head[u]=cnt++;
    e[cnt].u=v;
    e[cnt].v=u;
    //e[cnt].w=0;
    //e[cnt].f=-f;
    e[cnt].next=head[v];
    head[v]=cnt++;
}

inline ll quick_pow(int a, int b) {
    ll ans = 1;
    while (b) {
        if (b & 1) ans = (ans * a) % mod;
        a = (1ll * a * a) % mod;
        b >>= 1;
    }
    return ans;
}
inline int read()
{
    int x = 0;
    int f = 1;
    char c = getchar();
    while (c<'0' || c>'9')
    {    
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (c >= '0'&&c <= '9')
    {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x*f;
}

//_scc[u]存u点所在强连通分量的标号,out[x]存标号为x的强连通分量的出度,
//cot[x]存标号为x的连通量的点的数目
int n;

int main() {
    cin >> n;
    printf("%.6lf\n", 1- 1.0 * (n / 2) / n);
    return 0;
}   

Measured memory_bytes: 256