akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endl '\n'
#define forn(i, n) for(int i=0;i<n;i++)
#define lli long long int
#define pii pair<int,int>
#define fi first
#define se second
#define psi pair<int,pii>
#define pb push_back
#define vi vector<int>
#define vii vector< vi >

using namespace std;

const int MAXN = 1000001;

// чтение и перевод это будет пустой тратой времени
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,a,b;
	cin>>n>>a>>b;
	if(!((b - a) & 1)) cout<<"Alice"<<endl;
	else cout<<"Borys"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

const std::int64_t max_value = 1000'000'000;

bool check(int N, std::vector<std::int64_t>const& poly, std::int64_t p)
{
	auto mp = (max_value / p + 1) * p;
	auto max = (mp + poly[N]) % p;
	for (int i = 1; i < p; ++i)
	{
		std::int64_t v = 0;
		for (int k = i; k <= N; k += p - 1)
		{
			v += (mp + poly[N - k]);
			v %= p;
		}
		max = std::max(max, v);
	}
	return max == 0;
}

std::vector<std::int64_t> answer(int N, std::vector<std::int64_t>const& poly, std::vector<std::int64_t>const& primes)
{
	std::vector<std::int64_t> ret;
	for (auto p : primes)
	{
		if (check(N, poly, p))
		{
			ret.emplace_back(p);
		}
	}
	return ret;
}

std::vector<std::int64_t> run(int N, std::vector<std::int64_t>const& vec)
{
	std::vector<std::int64_t> prime_factor;
	auto val = std::abs(vec[0]);
	std::vector<unsigned char> sieve(100001);
	for (int p = 2; p <= 100000; ++p)
	{
		if (sieve[p])
		{
			continue;
		}
		if (p <= N || val % p == 0)
		{
			prime_factor.emplace_back(p);
			while (val % p == 0)
			{
				val /= p;
			}
		}
		for (int k = p; k <= 100000; k += p)
		{
			sieve[k] = true;
		}
	}
	if (val != 1)
	{
		prime_factor.emplace_back(val);
	}
	return answer(N, vec, prime_factor);
}

void Main()
{
	int N;
	std::cin >> N;
	std::vector<std::int64_t> vec(N + 1);	
	for (auto& v : vec)
	{
		std::cin >> v;
	}
	for (auto const& v : run(N, vec))
	{
		std::cout << v << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int q = Integer.parseInt(br.readLine());
		PriorityQueue<Integer> que1 = new PriorityQueue<>((o1, o2) -> o2 - o1);
		PriorityQueue<Integer> que2 = new PriorityQueue<>();
		String[] sa = br.readLine().split(" ");
		int x = Integer.parseInt(sa[1]);
		que1.add(x);
		long y = Integer.parseInt(sa[2]);
		int cnt = 1;
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 1; i < q; i++) {
			sa = br.readLine().split(" ");
			if (sa[0].equals("1")) {
				int a = Integer.parseInt(sa[1]);
				int o = 0;
				if (cnt % 2 == 1) {
					o = que1.poll();
				} else {
					o = que2.poll();
				}
				que1.add(Math.min(o, a));
				que2.add(Math.max(o, a));
				cnt++;
				int nx = que1.peek();
				if (cnt % 2 == 1) {
					y += Math.abs(a - nx);
				} else {
					y += Math.abs(a - x);
				}
				x = nx;
				y += Integer.parseInt(sa[2]);
			} else {
				pw.println(x + " " + y);
			}
		}
		pw.flush();
		br.close();
	}
}


Measured memory_bytes: 64900
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
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/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  int a;
  cin>>a;
  out(a+a*a+a*a*a);
}

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


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

int main() {
  int p, n;
  int sumP = 0;
  int sumN = 0;
  int kind = 0;
  while(scanf("%d,%d", &p, &n) != EOF) {
    sumP += p*n;
    sumN += n;
    kind++;
  }
  cout << sumP << endl;
  cout << (int)((double)sumN/kind+0.5) << endl;
  return 0;
}

Measured memory_bytes: 0
n, a, b = map(int, input().split())
s = input()

pss = a + b

cnt_all = 0
cnt_oss = 0

for i in range(n):
    if s[i] == "a":
        if cnt_all < pss:
            print("Yes")
            cnt_all += 1
        else:
            print("No")
    elif s[i] == "b":
        if cnt_all < pss and cnt_oss < b:
            print("Yes")
            cnt_all += 1
            cnt_oss += 1
        else:
            print("No")
    elif s[i] == "c":
        print("No")

Measured memory_bytes: 4016
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
vector<int> Slide_Min(vector<int> a,int n,int k){
  deque<int> deq;
  vector<int> b(0);
  rep(i,k){
    while((!deq.empty()) && a[*(deq.end()-1)] >= a[i]) deq.pop_back();
    deq.push_back(i);
  }

  b.push_back(*deq.begin());
  if(*deq.begin()==0) deq.pop_front();

  rep(i,n-k){
    while((!deq.empty()) && a[*(deq.end()-1)] >= a[i+k]) deq.pop_back();
    deq.push_back(i+k);
    //    while(*deq.begin() < i+1) deq.pop_front();
    b.push_back(*deq.begin());
    if(*deq.begin() == i+1) deq.pop_front();
  }
  return b;
}
vector<int> Slide_Max(vector<int> a,int n,int k){
  deque<int> deq;
  vector<int> b(0);
  rep(i,k){
    while((!deq.empty()) && a[*(deq.end()-1)] <= a[i]) deq.pop_back();
    deq.push_back(i);
  }

  b.push_back(*deq.begin());
  if(*deq.begin()==0) deq.pop_front();

  rep(i,n-k){
    while((!deq.empty()) && a[*(deq.end()-1)] <= a[i+k]) deq.pop_back();
    deq.push_back(i+k);
    //    while(*deq.begin() < i+1) deq.pop_front();
    b.push_back(*deq.begin());
    if(*deq.begin() == i+1) deq.pop_front();
  }
  return b;
}

int main()
{
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];

  vector<int> smin = Slide_Min(p,n,k);
  vector<int> smax = Slide_Max(p,n,k);  

  vector<int> rle(0);
  int cnt = 1;
  rep(i,n-1){
    if(p[i]<p[i+1]) cnt++;
    else{
      rle.push_back(cnt);
      cnt = 1;
    }
  }
  rle.push_back(cnt);

  vector<int> len(0);
  rep(i,rle.size()){
    while(rle[i]>0){
      len.push_back(rle[i]);
      rle[i]--;
    }
  }

  bool f = false;
  if(len[n-k]>=k) f =true;

  int res = 1;
  rep(i,n-k){
    if(len[i] >= k){
      if(!f){
	res++;
	f =true;
      }
      continue;
    }
    if(!(smin[i]==i&&smax[i+1]==i+k)) res++;
  }

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


Measured memory_bytes: 4820
from collections import Counter

n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
    exit()
for i in range(1, n):
    if d[i] == 0:
        print(0)
        exit()
d.sort()
for i in range(n-1):
    if d[i+1] - d[i] > 1:
        print(0)
        exit()

c = sorted(Counter(d).items())
ans = 1

for i in range(len(c)-1):
    if c[i][0] == 0: continue
    ans *= c[i][1] ** c[i+1][1]

print(ans % 998244353)


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


public class Main {


    static void solve() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++) {
            arr[i] = scan.nextInt();
        }

        Arrays.sort(arr);
        int sum = 0;
        for(int i=0;i<k;i++) {
            sum+=arr[i];
        }
        System.out.println(sum);
//        for (int i = 0; i < t; i++) {
//            int a = scan.nextInt();
//            scase();
//        }
    }


//    static void solveCase(int t, int x, String s) {
//
//    }

    static void scase() {

    }


    public static void main(String[] args) {

        solve();
        //        Main m = new Main();
        //        Scanner scan = new Scanner(System.in);

        //        long n = scan.nextLong();
        //        long r = scan.nextLong();
        //        List<Long> list = new ArrayList<>();
        ////        int[] arr = new int[n];
        //        for (long i=0;i<n;i++){
        //            list.add(scan.nextLong());
        //        }
//            System.out.println(ch);
        //        solve(n, arr);
        //        scan.close();
    }


//
//    class Counter extends HashMap<Integer, Integer> {
//        public int get(int k) {
//            return containsKey(k) ? super.get(k) : 0;
//        }
//
//        public void add(int k, int v) {
//            put(k, get(k) + v);
//        }
//    }


//    static class TreeNode {
//        int val;
//        TreeNode left;
//        TreeNode right;
//
//        TreeNode(int x) {
//            val = x;
//        }
//    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

}

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

const int MAX = 20010;

int main()
{
  string str;
  getline(cin, str);

  stack<int> stk;
  vector< pair< pair<int, int>, int > > sub;
  int ans = 0;
  for (int i = 0; i < str.size(); i++) {
    char c = str[i];
    if (c == '\\') {
      stk.push(i);
    } else if (c == '/' && stk.size() > 0) {
      int j = stk.top(); stk.pop();
      ans += i - j;
      sub.push_back(make_pair(make_pair(j, i), i-j));
    }
  }

  cout << ans << endl;

  vector<int> areas;
  vector<bool> done = vector<bool>(MAX, false);
  sort(sub.begin(), sub.end());
  for (int k = 0; k < sub.size(); k++) {
    int i, j, a;
    i = sub[k].first.first;
    j = sub[k].first.second;
    a = sub[k].second;
    if (done[i]) continue;

    int sum = a;
    for (int kp = k+1; kp < sub.size(); kp++) {
      int ip, jp, ap;
      ip = sub[kp].first.first;
      jp = sub[kp].first.second;
      ap = sub[kp].second;
      if (!(i < ip && jp < j))
        break;
      sum += ap;
    }
    fill(done.begin()+i, done.begin()+j+1, true);
    areas.push_back(sum);
  }

  cout << areas.size();
  for (int i = 0; i < areas.size(); i++)
    cout << " " << areas[i];
  cout << endl;

  return EXIT_SUCCESS;
}



Measured memory_bytes: 3352
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n;
    char a[110000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0;
    for(int i=0;i<n-2;i++){
        if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C'){
            ans++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

typedef long long ll ; 
typedef long double ld ; 
typedef pair<int,int> pii ; 
typedef pair<ll,ll> pll ;

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}



vt<pii> dir =  {{-1,0} , {1, 0} , {0,-1} , {0,1}} ; 

// ==========Start Here==============

const int N = 2e5+1; 
vt<int> adj[N] ; 
vt<ll> val(N) ; 

void dfs(int u, int par) {
    val[u] += val[par] ;
    for(int x : adj[u]) {
        if(x == par) 
            continue ; 
        dfs(x, u) ; 
    }   
}

int main() 
{ 
	int n , q ; 
    cin >> n >> q ; 
    int x , y ; 
    rep(i,0,n-1) {
        cin >> x >> y ; 
        adj[x].pb(y) ; 
        adj[y].pb(x) ; 
    }
    ll u,v ; 
    while(q--) {
        cin >> u >> v ; 
        val[u] += v ; 
    }

    dfs(1,0) ; 
    rep(i,1,n+1) {
        cout << val[i] << " " ; 
    }
    return 0; 
} 

Measured memory_bytes: 25088
Takahashi, Aoki, count = input().split()

tk = int(Takahashi)
ak = int(Aoki)
c = int(count)

t = 0


if tk >= c:
    tk = tk - c

else:
    c = c - tk
    tk = 0
    if ak >= c:
        ak = ak - c
    else:
        ak = 0

print(tk, ak)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_b(pair<int, long long> a, pair<int, long long> b) {
    if(a.second != b.second) {
        return a.second > b.second;
    } else {
        return a.first > b.first;
    }
}

struct UnionFind {
    vector<int> par;
    vector<int> sizes;

    UnionFind(int N) : par(N), sizes(N, 1) {
        for(int i = 0; i < N; i++) {
            par[i] = i;
        }
    }
    int root(int x) {
        if(par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }
    int size(int x) { return sizes[root(x)]; }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) {
            return;
        }
        par[ry] = rx;
        sizes[rx] += sizes[ry];
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main() {
    int N, M, K;
    cin>>N>>M>>K;
    vector<int> ff(N);
    UnionFind tree(N);
    rep(i, 0, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree.unite(a, b);
        ff[a]++;
        ff[b]++;
    }
    rep(i, 0, K) {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        if(tree.same(c, d)) {
            ff[c]++;
            ff[d]++;
        }
    }
    rep(i, 0, N) {
        cout << tree.size(i)-ff[i]-1;
        if(i != N - 1) {
            cout << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 2304
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e7+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
void solve()
{
    ll n,m;
    cin>>n>>m;
    string s[n];
    vector<bool>r(n,0),c(m,0);
    for(int i=0;i<n;i++)
        cin>>s[i];
    for(int i=0;i<n;i++)
    {bool flag=0;
        for(int j=0;j<m;j++)
        {
            if(s[i][j]=='#')
            {
                flag=1;break;
            }
        }
        if(!flag)
            r[i]=1;
    }
    for(int i=0;i<m;i++)
    {
        bool flag=0;
        for(int j=0;j<n;j++)
        {
            if(s[j][i]=='#')
            {
                flag=1;break;
            }
        }
        if(!flag)
            c[i]=1;
    }
    for(int i=0;i<n;i++)
    {
        if(!r[i])
        {
            for(int j=0;j<m;j++)
            {
                if(!c[j])
                    cout<<s[i][j];
            }
            cout<<endl;
        }
    }
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;for(int te=1;te<=t;te++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>
#define MOD 1000000007
#define MAXE9 1000000000
 
int i, j, k, l;

int main(){
    int max = 0;
    int min = MAXE9;
    int R[200010];
    int n;
    
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &R[i]);
    }

    max = R[1] - R[0];
    min = R[0];
    for(i=1;i<n;i++){
        if(max <= R[i] - min) max = R[i] - min;
        if(min >= R[i]) min = R[i];
    }
    printf("%d\n", max);
    
}



Measured memory_bytes: 2496
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cins(int, 5, a);
    sort(Range(a), [](auto l, auto r){ return (l+9) % 10 < (r+9) % 10; });
    for(int i = 1; i < 5; i ++){
        while(a[i] % 10) a[i] ++;
    }
    Cout(a[0] + a[1] + a[2] + a[3] + a[4]);
}


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

using namespace std;
typedef long long ll;
int N, P;
int A[51];
// 偶数ならtrue, 奇数ならfalse
int gusu = 0;
int kisu = 0;

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

    cin >> N >> P;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] % 2 == 0) gusu++;
        else kisu ++;
    }

    ll ans = 0;
    if(P == 0){
        ll num = 1;
        for(int i = 0; i <= kisu; i += 2){
            if(i == 0){
                num = 1;
            }
            else {
                num *= (kisu - i + 2);
                num *= (kisu - i + 1);
                num /= i;
                num /= i - 1;
            }
            ans += num;
        }
        ans = ans * pow(2, gusu);
        cout << ans << endl;
    }
    else{
        ll num = 1;
        for(int i = 1; i <= kisu; i += 2){
            if(i == 1){
                num = kisu;
            }
            else {
                num *= (kisu - i + 2);
                num *= (kisu - i + 1);
                num /= i;
                num /= i - 1;
            }
            ans += num;
        }
        ans = ans * pow(2, gusu);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*
	  Chase
	   Your
	  Legend

	英雄志逐传奇
*/

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

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

	cout << (n * (n - 1)) / 2 << endl;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        long lcm = scanner.nextLong();
        for (int i = 0; i < n - 1; i++) {
            final long tmp = scanner.nextLong();
            final long gcd = computeGCD(lcm, tmp);
            lcm = BigInteger.valueOf(lcm).multiply(BigInteger.valueOf(tmp)).divide(BigInteger.valueOf(gcd)).longValue();
        }

        System.out.println(lcm);
    }

    private static long computeGCD(final long a, final long b) {
        if (b > a) {
            return computeGCD(b, a);
        }

        if (b == 0) {
            return a;
        }

        return computeGCD(b, a % b);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define rep(i,x) for(int (i)=1;(i)<=(x);(i)++)
#define repp(i,x,y) for(int (i)=(x);(i)<=(y);(i)++)
#define forn(i,x) for(int (i)=0;(i)<(x);(i)++)
#define foreach(i,x) for(auto (i):(x))
using namespace std;
typedef pair<int,int>pii;
LL n,p,ans=1;
bool pr[1000010];
void init(int x){
	memset(pr,true,sizeof(pr));
	pr[1]=0;
	for(LL i=2;i*i<=x;i++)
		if(pr[i])
			for(LL j=2;i*j*i*j<=x;j++)
				pr[i*j]=0;
}
int main(){
	cin>>n>>p;
	if(n==1){
		cout<<p<<endl;
		return 0;
	}
	init(p);
	for(LL i=2;i*i<=p;i++){
		if(pr[i]&&p%i==0){
			LL tp=0;
			while(p%i==0)p/=i,tp++;
			while(tp/n>0){
				ans*=i,tp-=n;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

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

  vector<ll> sum;
  rep(i, N) {
    ll s = 0;
    REP(j, i, N) {
      s += a[j];
      sum.eb(s);
    }
  }

  ll ans = 0;
  for (int i = 60; i >= 0; i--) {
    vector<ll> tmp;
    rep(j, sz(sum)) if ((1LL << i) & sum[j]) tmp.eb(sum[j]);
    if (sz(tmp) >= K) {
      ans += (1LL << i);
      sum = tmp;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 6388
public class Main {
  private static void solve() {
    int n = ni();
    int k = ni();
    int[] a = na(n);
    
    int minIdx = -1;
    for (int i = 0; i < n; i ++) {
      if (a[i] == 1) {
        minIdx = i;
        break;
      }
    }
    
    int left = minIdx;
    k --;
    
    int ret = (left + k - 1) / k;
    int right = n - ret * k - 1;
    ret += (right + k - 1) / k;
    
    System.out.println(Math.max(1, ret));
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 33892
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	std::string s; cin >> s;
	int n; cin >> n;
	
	for(int i = 0; i < s.size(); i += n) {
		cout << s[i];
	} 
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX 500000
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    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(ll n, ll k) {
    if(n < k)
        return 0;
    if(n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    ll n, k;
    cin >> n >> k;
    COMinit();
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a), greater<ll>());
    // min
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        ans -= a[i] * COM(i, k - 1);
        ans = (ans + MOD) % MOD;
    }
    // max
    sort(all(a));
    for(int i = 0; i < n; i++) {
        ans += a[i] * COM(i, k - 1);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
# D - I hate Factorization

x = int(input())

# a ** 5 - b ** 5 == x となる組 (a,b) を1つ答える.
# 1 <= x <= 10 ** 9
# a >= 0と仮定してよい. b < aと仮定してよい. bが減ると左辺は増加.

a = 0
while True:
    b = a - 1
    while a ** 5 - b ** 5 < x:
        b -= 1
    if a ** 5 - b ** 5 == x:
        print(a, b)
        exit()
    a += 1


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

int main(){
      int n;cin >> n;
      int arr[n + 5];
      for(int i = 0;i < n;i++)cin >> arr[i];
      sort(arr, arr + n);
      int a = 0;
      int b = 0;
      for(int i  =0;i < n;i++){
            if(!(i & 1))a += arr[i];
            else b += arr[i];
      }
      cout << max(a, b) - min(a, b);
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i in range(n):
    b1=b[n-1-i::n-1-i+1]
    su=sum(b1)
    if (a[n-1-i]==0 and su%2==0) or (a[n-1-i]==1 and su%2==1):
        b[n-1-i]=0
    else:
        b[n-1-i]=1
ans =[]
print(sum(b))
for i in range(n):
    if b[i]==1:
        ans.append(str(i+1))
print(' '.join(ans))


Measured memory_bytes: 19508
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        String ans = "";
        for (int i = 0; i < n; i++) {
            ans += s[i];
            ans += t[i];
        }
        System.out.println(ans);
    }
}

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

int main(){
long long N,D,X,Y;
cin>>N>>D;    
int ans=0;
 for(int i=0;i<N;i++){
  cin>>X>>Y;
 if(X*X+Y*Y<=D*D){
     ans++;
 }
 }
cout<<ans<<endl;
}



Measured memory_bytes: 3644
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



int dist[100005][3];

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

	int N, M;
	cin >> N >> M;
	vector<VI> to(N);
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		to[a].push_back(b);
	}
	int sv, tv;
	cin >> sv >> tv;
	sv--; tv--;
	REP(i, N) {
		REP(j, 3) {
			dist[i][j] = LLINF;
		}
	}
	queue<pii> q;
	q.push(pii(sv, 0));
	dist[sv][0] = 0;
	while (!q.empty()) {
		int v = q.front().first;
		int l = q.front().second;
		q.pop();

		for (int u : to[v]) {
			int nl = (l + 1) % 3;
			if (dist[u][nl] != LLINF)continue;
			dist[u][nl] = dist[v][l] + 1;
			q.push(pii(u, nl));
		}
	}
	int ans = dist[tv][0];
	if (ans == LLINF) ans = -1;
	else ans /= 3;

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define long_long ll
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string N;
    cin >> N;
    if(N.size() == 2){
        cout << N;
    }
    if(N.size() == 3){
        cout << N.at(2) << N.at(1) << N.at(0)<< endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   int k,a,b;
   string s;
   cin >> k >> a >> b;
   for (int i= a;i <= b;i++){
      if (i%k == 0){
         cout << "OK" << endl;
         return 0;
      }
   }
   cout << "NG" << endl;

   return 0;

}


Measured memory_bytes: 3632
import bisect


A, B, Q = map(int, input().split())
INF = 10**18
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
for _ in range(Q):
    x = int(input())
    i = bisect.bisect_right(S, x)
    j = bisect.bisect_right(T, x)
    d = INF
    for s in [S[i-1], S[i]]:
        for t in [T[j-1], T[j]]:
            d1 = abs(s-x) + abs(s-t)
            d2 = abs(t-x) + abs(s-t)
            d = min(d, d1, d2)
    print(d)


Measured memory_bytes: 14740
#include<iostream>

using namespace std;

int c[100100];

int main(){

    int N;
    cin>> N;
    int a[N], b[N];
    for(int i=0; i<N; i++) cin>> a[i]>> b[i];

    for(int i=0; i<N; i++){
        c[a[i]]++;
        c[b[i]+1]--;
    }
    for(int i=1; i<100100; i++){
        c[i]+=c[i-1];
    }
    int s=0;
    for(int i=0; i+1<100100; i++){
        if(c[i+1]>=i){
            s=max(s, i);
        }
    }
    cout<< s<< endl;

    return 0;
}

Measured memory_bytes: 4240
#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(){
  ll n, m;
  cin >> n >> m;
  ll ans = n;
  ans = min(n, m/2);
  m -= ans * 2;
  if(m >= 0) ans += m/4;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  sort(a,a+n);
  int x,j;
  j=n/2;
  x=a[j]-a[j-1];
  cout<<x<<"\n";
  return 0;
}


Measured memory_bytes: 640
def main():
    from fractions import gcd
    import sys
    n=int(input())
    a = tuple(map(int, input().split()))
    ans = 1

    mmm=10**9+7
    for i in a:
        ans = ans *i // gcd(ans, i)

    result=0
    for item in a:
      result+=ans//item

    print(result%mmm)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6076
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
int main(void){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    set<int> ss;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ss.insert(a[i]);
    }
    vector<int> b(200001);
    for(int i=0;i<n;i++){
        b[a[i]]++;
    }
    for(int i=0;i<200001;i++){
        if(b[i]==0)b[i]=200001;
    }
    sort(b.begin(),b.end());
    int ans=0,s=ss.size();
    for(int i=0;i<s-k;i++){
        ans+=b[i];
    }
    cout<<ans<<endl;
    return 0;
}


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

#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define lg long long
#define db double
#define lb(x) ((x)&-(x))
#define ft first
#define sd second

#define HII cerr<<"HI"<<endl
#define LLLINE cerr<<"@@@@@@@@@@@@@@@@@@@@"<<endl

template <class _T_>
void read(_T_& d){
	d=0;int f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f*=-1;
	for(;c>='0'&&c<='9';c=getchar())d=d*10+c-'0';
	d*=f;
}

/************************************************/
#define MN 200005
int n;
int a[MN];
int main(){
	read(n);
	for(int i=1;i<=n;++i)read(a[i]);
	int cnt=0;
	while(1){
		int tot=0,F=0;
		for(int i=1;i<=n;++i){
			if(a[i]==1){
				F=1;break;
			}
			tot+=a[i]&1;
		}
		if(F){
			int tot=0;
			for(int i=1;i<=n;++i){
				tot+=a[i]-1;
			}
			tot&=1;
			cnt^=tot;
			break;
		}
		if(tot==1&&!((n-tot)&1)){
			int g=0;
			for(int i=1;i<=n;++i){
				a[i]/=2;
				g=__gcd(a[i],g);
			}
			for(int i=1;i<=n;++i)a[i]/=g;
		}else{
			cnt^=(n-tot)&1;break;
		}
		cnt^=1;
	}
	puts(cnt?"First":"Second");
	return 0;
}


Measured memory_bytes: 640
var time = require('fs').readFileSync('/dev/stdin', 'utf8');
time = Number(time);
h = Math.floor(time / 3600);
m = Math.floor(time % 3600 / 60);
s = Math.floor(time % 3600 % 60);
console.log(h + ':' + m + ':' + s);


Measured memory_bytes: 15124
#include <bits/stdc++.h>
#define MAX (ll)(2e5 + 7)
#define INF (ll)(1e18)
#define MOD (ll)(1e9 + 7)

using namespace std;
using ll = long long;
using cd = complex<double>;
using p = pair<int, int>;
using pp = pair<pair<int, int>, pair<int, pair<int, int>>>;

int dir[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int h, w, k, x1, yy, x2, y2;

bool chh (int x, int y) {
	return (x >= 0 && x < h && y >= 0 && y < w);
}

int main () {
	ios_base :: sync_with_stdio (false);
	cin.tie (nullptr);
	cin >> h >> w >> k >> x1 >> yy >> x2 >> y2;
	int mm[h][w][4];
	bool ch[h][w];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char c;
			cin >> c;
			ch[i][j] = (c == '.');
		}
	}
	x1--, yy--, x2--, y2--;
	if (!ch[x1][yy] || !ch[x2][y2]) { 
		cout << "-1\n";
		return 0;
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			for (int x = 0; x < 4; x++) {
				mm[i][j][x] = MOD;
			}
		}
	}
	deque <pp> q;
	for (int i = 0; i < 4; i++) {
		q.push_front (make_pair (make_pair (x1, yy), make_pair (0, make_pair (i, 0))));
	}
	int mx = -1;
	while (q.size ()) {
		int x = q.front ().first.first, y = q.front ().first.second, w = q.front ().second.first;
		int r = q.front ().second.second.second, di = q.front ().second.second.first;
		if (x == x2 && y == y2) {
			if (mx == -1) {
				mx = w;
			}
			else {
				mx = min (w, mx);
			}
		}
		q.pop_front ();
		for (int i = 0; i < 4; i++) {
			int xx = x + dir[i][0], yy = y + dir[i][1];			
			if (chh (xx, yy) && ch[xx][yy]) {
				int ww, rr;
				if (i == di) {
					ww = w + (!r);
					rr = (r + 1) % k;
				}
				else {
					ww = w + 1;
					rr = 1 % k;
				}
				if (mm[xx][yy][i] > ww) {
					mm[xx][yy][i] = ww;
					if (ww > w) {
						q.push_back (make_pair (make_pair (xx, yy), make_pair (ww, make_pair (i, rr))));
					}
					else {
						q.push_front (make_pair (make_pair (xx, yy), make_pair (ww, make_pair (i, rr))));
					}
				}
			}
		}
	}
	cout << mx << "\n";
}


Measured memory_bytes: 25020
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

  cout << (double)w * (double)h / 2.0 << " ";

  if(w == 2 * x && h == 2 * y) cout << 1 << endl;
  else cout << 0 << endl;
  return 0; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(i) cout<<i<<endl;
const int mod=1e9 +7;
int main(){
IOS;
int i;
string s;
cin>>s;
for(i=0;i<s.length()-1;i++){
    if(s[i]==s[i+1])
    {
        cout<<"Bad"<<endl;
        return 0;
    }
}
cout<<"Good"<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i,a[123456],ans=0,p=0;
	bool done[123456];
	fill(done,done+123456,false);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
		--a[i];
	}
	while(p != 1){
		if(done[p]){
			ans = -1;
			break;
		}
		done[p] = true;
		++ans;
		p = a[p];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 3000 + 5;
LL a[N];
int n;
vector <int> G[N];
bool dfs(int o, int f){
	for(int i = 0; i < G[o].size(); i ++){
		if(G[o][i] == f) continue;
		if(a[G[o][i]] < a[o] && !dfs(G[o][i], o)) return true;
	}
	return false;
}
int main(){
	int u, v;
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) scanf("%I64d", &a[i]);
	for(int i = 1; i < n; i ++){
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i = 1; i <= n; i ++){
		if(dfs(i, -1)) printf("%d ", i);
	}
	puts("");
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> g(n, vector<bool>(n, false));
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a][b] = true;
        g[b][a]= true;
    }

    int ans = 0;
    vector<int> ver(n);
    iota(ver.begin(), ver.end(), 0);
    while (true) {
        bool ok = true;
        for (int i = 0; i + 1 < n; i++) {
            ok &= g[ver[i]][ver[i + 1]];
        }
        if (ok) ans++;
        if (not next_permutation(ver.begin() + 1, ver.end())) break;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3640
// 2017/11/19 Tazoe

#include <iostream>
#include <queue>
#include <string>
#include <map>
using namespace std;

struct state{
	string G;
	int N;
};

bool is_over(string G)
{
	bool flg = true;

	for(int i=1; i<G.size(); i++){
		if(G[i]!=G[0]){
			flg = false;
			break;
		}
	}

	return flg;
}

void DFS(char g[12][12], char F, char T, int x, int y)
{
	if(g[y][x]!=F)
		return;

	g[y][x] = T;

	DFS(g, F, T, x-1, y);
	DFS(g, F, T, x+1, y);
	DFS(g, F, T, x, y-1);
	DFS(g, F, T, x, y+1);
}

string fill(string G, char C, int X, int Y)
{
	char g[12][12];
	for(int y=0; y<Y+2; y++){
		for(int x=0; x<X+2; x++){
			g[y][x] = 'N';
		}
	}

	// ???????????????2?¬?????????????
	for(int y=0; y<Y; y++){
		for(int x=0; x<X; x++){
			g[y+1][x+1] = G[y*X+x];
		}
	}

	DFS(g, G[0], C, 1, 1);

	// 2?¬????????????????????????????
	for(int y=0; y<Y; y++){
		for(int x=0; x<X; x++){
			G[y*X+x] = g[y+1][x+1];
		}
	}

	return G;
}


int main()
{
	while(true){
		int X, Y;
		cin >> X >> Y;

		if(X==0 && Y==0)
			break;

		string G = "";
		for(int y=0; y<Y; y++){
			for(int x=0; x<X; x++){
				string c;
				cin >> c;

				G += c;
			}
		}

		queue<struct state> que;
		map<string, bool> memo;

		struct state now;
		now.G = G;
		now.N = 0;
		que.push(now);
		memo[now.G] = true;

		while(!que.empty()){
			now = que.front();
			que.pop();

			if(is_over(now.G)){
				cout << now.N << endl;
				break;
			}

			struct state nex1, nex2;

			if(now.G[0]=='R'){
				nex1.G = fill(now.G, 'G', X, Y);
				nex2.G = fill(now.G, 'B', X, Y);
				nex1.N = nex2.N = now.N+1;
			}
			else if(now.G[0]=='G'){
				nex1.G = fill(now.G, 'R', X, Y);
				nex2.G = fill(now.G, 'B', X, Y);
				nex1.N = nex2.N = now.N+1;
			}
			else if(now.G[0]=='B'){
				nex1.G = fill(now.G, 'R', X, Y);
				nex2.G = fill(now.G, 'G', X, Y);
				nex1.N = nex2.N = now.N+1;
			}

			if(memo.find(nex1.G)==memo.end()){
				que.push(nex1);
				memo[nex1.G] = true;
			}
			if(memo.find(nex2.G)==memo.end()){
				que.push(nex2);
				memo[nex2.G] = true;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 4340
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define inf 0x7fffffff
#define llinf 0x7fffffffffffffffll
using namespace std;
int main()
{
	int i,j,k,n,m,x;
	scanf("%d%d",&n,&m);
	printf("%d",n*m-n-m+1);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int r, g, b; cin >> r >> g >> b;
	cout << (((100 * r + 10 * g + b) % 4 == 0) ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

long long dp[40];

int main() {
  dp[0] = 1;
  dp[1] = 1;
  dp[2] = 2;
  rep (i, 30) dp[i + 3] = dp[i] + dp[i + 1] + dp[i + 2];
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    cout << ((dp[n] + 9) / 10 + 364) / 365 << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Bits
import Data.List
import qualified  Data.ByteString as B
import Data.Ord
import Data.Array.ST
-- import Data.Array.IO 
import Control.Monad.ST
import Data.List.Extra


bsToInt :: BS.ByteString -> Int
bsToInt = fst . fromJust . BS.readInt

bsToIntList :: BS.ByteString -> [Int]
bsToIntList = map bsToInt . BS.words

main :: IO ()
main = do
    a:b:c:d:_ <- bsToIntList <$> BS.getLine
    let aoki = length . takeWhile (>0) $ iterate (subtract b) c
    let taka = length . takeWhile (>0) $ iterate (subtract d) a
    let t1 = if taka >= aoki then "Yes" else "No"
    putStrLn t1

Measured memory_bytes: 3796
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);


int main(){
  ll N, K;
  ll ans=0;
  cin >> N >> K;
  ll C[N], D[N-1];
  rep(i, N){
    cin >> C[i];
  }
  rep(i, N-1){
    D[i] = C[i] + C[i+1];
  }
  if(N>2){
    rep(i, N-2){
      if(D[i]>K && D[i+1]>K){
        ll d = min({C[i+1], D[i]-K, D[i+1]-K});
        ans += d;
        C[i+1] -=  d;
        D[i] -=  d;
        D[i+1] -=  d;
      }
    }
  }
 
  rep(i, N-1){
    if(D[i]>K) ans += D[i] - K;
    
  }
  cout << ans << endl;
 
  
  
 
 
 }

Measured memory_bytes: 1792
h = int(input())
mem = [0] * 1000
cnt = 0

def atk(k):
    if k == 1:
        return 1
    else:
        j = int(k // 2)
        l = 0
        while k / ( 2 ** l) >1:
            l += 1

        if mem[l] == 0:
            mem[l] = atk(j) * 2 + 1
            return mem[l]
        else:        
            return mem[l]
if h > 1:
    atk(h)
    mem.sort(reverse = True)
    print(mem[0])
else:
    print(1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e12;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------



int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int s = 0;
    int h,m;
    cin >> h >> m;
    s = h*60 + m;
    int e = 0;
    cin >> h >> m;
    e = h*60 + m;
    int k;
    cin >> k;
    cout << e-s-k << "\n";
    return 0;
}

Measured memory_bytes: 3656