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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

vector<i64> factor(i64 x){
    vector<i64> res={x};
    for(i64 i=2; i*i<=x; ++i){
        if(x%i==0){
            res.push_back(i);
            if(i*i!=x) res.push_back(x/i);
        }
    }
    sort(begin(res),end(res));
    return res;
}

i64 extgcd(i64 a, i64 b, i64 &x, i64 &y) {
    i64 d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

i64 mod_inverse(i64 a, i64 m) {
    i64 x, y;
    if (extgcd(a, m, x, y) == 1) return (x + m) % m;
    return 0;
}

i64 mod_comb(i64 n, i64 k, i64 p) {
    if (n < 0 or k < 0 or n < k) return 0;
    //i64 num=fact[n]*mod_inverse(fact[n-k],p)%p,den=fact[k];
    i64 num = 1, den = 1;
    for (i64 i = 0; i < k; ++i) {
        num = num * ((n - i) % p) % p;
        den = den * (i + 1) % p;
    }
    return num * mod_inverse(den, p) % p;
}

void solve(){
    i64 N,M,mod=1'000'000'007;
    cin >> N >> M;

    if(M==1){
        cout << 1 << endl;
        return;
    }

    auto fs=factor(M);

    vector<unordered_map<i64,i64>> dp(32);
    ++dp[0][1];
    rep(i,0,31){
        for(auto& p:dp[i]){
            i64 x=p.first,cnt=p.second;
            for(i64 f:fs){
                i64 y=x*f;
                if(y>M) break;
                if(M%y!=0) continue;
                dp[i+1][y]+=cnt;
                dp[i+1][y]%=mod;
            }
        }
    }

    i64 ans=0;
    rep(i,0,32){
        ans+=dp[i][M]*mod_comb(N,i,mod);
        ans%=mod;
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define MAX INT_MAX
int arr[100005];
int n,k;
long long dp[100005];
long long func(int pos)
{
    if(pos>=n)return 0;
    if(dp[pos]!=-1)return dp[pos];
    long long ans[105];
    for(int i=1;i<=k;i++)ans[i]=MAX;

            for(int j=1;j<=k;j++) {
        if(pos+j<=n)ans[j]=(int)abs(arr[pos]-arr[pos+j])+func(pos+j);
            }
            long long mini=100000000000000000;
              for(int j=1;j<=k;j++) {
         mini=min(mini,ans[j]);
            }
            return dp[pos]=mini;
    }

int main()
{
    std :: ios :: sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
    }
    memset(dp,-1,sizeof(dp));
    long long ans=func(1);
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    cout << max(0ll,n-m) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
const int N=1e5+10;
int n;
LL e,t,x[N],dp[N],tt=1e18;
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline I mi(const I&a,const I&b){return a<b ? a : b;}
int main()
{
//	freopen("Shik and Game.in","r",stdin);
	read(n,e,t);
	for(RG int i=1;i<=n;i++) read(x[i]), dp[i]=2e9;
	for(RG int i=1,j=0;i<=n;i++)
	{
		while(2*(x[i]-x[j+1])>=t) 
		{
			tt=mi(tt,dp[j]-2*x[j+1]);
			j++;
		}
		dp[i]=mi(dp[j]+t,tt+2*x[i]);
	}
	printf("%lld\n",dp[n]+e);
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
int main(){
  long int N,M,i,count,tmp,A,B;
  long int X[100001],H[100001];
  for(i=0;i<100001;i++) X[i]=0;
  scanf("%ld %ld",&N,&M);
  count=N;
  for(i=0;i<N;i++){
   scanf("%ld",&H[i]);
  }
  for(i=0;i<M;i++){
    scanf("%ld %ld",&A,&B);
    if(H[A-1]>H[B-1] && X[B-1]==0){
      X[B-1]=1;
      count--;
    }
    else if(H[A-1]<H[B-1] && X[A-1]==0){
      X[A-1]=1;
      count--;
    }
    else if(H[A-1]==H[B-1]){
      if(X[A-1]==0 && X[B-1]==0) count=count-2;
      else if(X[A-1]==0 || X[B-1]==0) count--;
      X[A-1]=1;
      X[B-1]=1;
    }
  }
  printf("%ld",count);
  return 0;
}

Measured memory_bytes: 3292
x = int(input())
if 1800 <= x <= 1999:
    print(1)
elif 1600 <= x <= 1799:
    print(2)
elif 1400 <= x <= 1599:
    print(3)
elif 1200 <= x <= 1399:
    print(4)
elif 1000 <= x <= 1199:
    print(5)
elif 800 <= x <= 999:
    print(6)
elif 600 <= x <= 799:
    print(7)
elif 400 <= x <= 599:
    print(8)

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

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

using namespace std;

bool solve(void)
{
	ui N{};
	cin >> N;

	// 出現した値と出現回数を記憶するDictionary
	map<ull, ui> bits_dic{};

	for (size_t i = 0; i < N; ++i)
	{
		ull bit;
		cin >> bit;

		bits_dic[bit] = (bits_dic.find(bit) == bits_dic.end()) ? 1 : bits_dic[bit] + 1;
	}

	if (bits_dic.size() == 1)
	{
		if (bits_dic.find(0) != bits_dic.end()
			&& bits_dic[0] == N)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else if (bits_dic.size() == 2)
	{
		if (N % 3 != 0) return false;

		bool ans{ true };
		for (auto p : bits_dic)
		{
			if (p.first == 0)
			{
				ans &= (p.second == N / 3);
			}
			else
			{
				ans &= (p.second == (N * 2) / 3);
			}
		}
		return ans;
	}
	else if (bits_dic.size() == 3)
	{
		if (N % 3 != 0) return false;

		ull res = accumulate(bits_dic.begin(), bits_dic.end(), 0, [](ull res, pair<ull, ui> p) {
			return (res ^ p.first);
		});
		bool ans = !res && all_of(bits_dic.begin(), bits_dic.end(), [&N](pair<ull, ui> p) {
			return (p.second == N / 3);
		});

		return ans;
	}
	else
	{
		return false;
	}
}

int main(void)
{
	string ans = solve() ? "Yes" : "No";
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5120
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

void func(void)
{
//DEBUG_OUT("----\n");
    int N, K;
    cin >> N;
    cin >> K;

    int ans = 1;
    for(int i=0; i<N; i++){
        int tmpA = ans * 2;
        int tmpB = ans + K;
        ans = min(tmpA, tmpB);
    }

    cout << ans << endl;
    
    return;
}



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

int main(){

    // input
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, 0, n) cin >> s[i];

    // full-search
    ll ans = 0;
    vector<string> t(n, string(n, '0'));
    rep(a, 0, n) {
        rep(i, 0, n) {
            rep(j, 0, n) {
                ll ni = (i + a) % n;
                t[ni][j] = s[i][j];
            }
        }
        bool f = true;
        rep(i, 0, n) {
            rep(j, 0, n) {
                if(t[i][j] != t[j][i]) f = false; 
            }
        }
        if(f) ans += n;
    }

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

Measured memory_bytes: 3892
s=input()
op=[["+", "-"]]*3

for i in range(2**3):
    tmp=[0]*3
    for j in range(3):
        if (i>>j)&1:
            tmp[j]=1
    
    ans=s[0]
    for i in range(3):
        ans=ans+(op[i][tmp[i]]+s[i+1])
    if eval(ans)==7:
        print(ans+"=7")
        break

Measured memory_bytes: 9032
#include <iostream>
#include <vector>
#include <deque>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)

using pii = pair<int, int>;
using vpii = vector<pii>;

int n, m, p, q, r;

int calc(pii seg, int n)
{
	int len = seg.scd - seg.fst + 1;

	if (n < p && p <= n + len - 1) {
		int a = (n + len - 1) - p;

		return calc(pii(seg.scd - a, seg.scd), p);
	}

	if (p <= n && n + len - 1 <= q) {
		return max(min(r - seg.fst + 1, len), 0);
	}

	if (n <= q && q < n + len - 1) {
		int a = q - n;

		return calc(pii(seg.fst, seg.fst + a), n);
	}

	return 0;
}

int main()
{
	omajinai;

	while (cin >> n >> m >> p >> q >> r, n) {
		deque<pii> dat;

		dat.push_back(pii(1, n));

		rep(_, m) {
			int x, y; cin >> x >> y;

			int sum = 0;

			vpii Top, Mid, Bottom;

			// Top?????????
			while (true) {
				pii a = dat.front();

				int v = a.scd - a.fst + 1;

				if (sum + v >= x) {
					int dif = x - sum-1;

					sum += dif + 1;

					Top.push_back(pii(a.fst, a.fst + dif));

					dat.pop_front();

					if (a.fst + dif + 1 <= a.scd) dat.push_front(pii(a.fst + dif + 1, a.scd));

					break;
				} else {
					Top.PB(a);
					sum += v;
				}

				dat.pop_front();
			}

			// Mid?????????
			while (true) {
				pii a = dat.front();

				int v = a.scd - a.fst + 1;

				if (sum + v >= y) {
					int dif = y - sum-1;

					sum += dif + 1;

					Mid.push_back(pii(a.fst, a.fst + dif));

					dat.pop_front();

					if (a.fst + dif + 1 <= a.scd) dat.push_front(pii(a.fst + dif + 1, a.scd));

					break;
				} else {
					Mid.PB(a);
					sum += v;
				}
				dat.pop_front();
			}

			// Bottom?????????
			while (true) {
				pii a = dat.front();

				int v = a.scd - a.fst + 1;

				if (sum + v == n) {
					sum += v;

					Bottom.push_back(pii(a.fst, a.scd));

					dat.pop_front();

					break;
				} else {
					Bottom.PB(a);
					sum += v;
				}

				dat.pop_front();
			}

			rep(i, Bottom.size()) dat.push_back(Bottom[i]);
			rep(i, Mid.size()) dat.push_back(Mid[i]);
			rep(i, Top.size()) dat.push_back(Top[i]);
		}

		int sum = 1;
		int ans = 0;

		for (pii a : dat) {
			ans += calc(a, sum);
			sum += a.scd - a.fst + 1;
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 3308
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct _Node {
  int key;
  struct _Node *next, *prev;
} Node;

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init(void) {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void) {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void) {
  deleteNode(nil->next);
}

void deleteLast(void) {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(void) {
  int key, n, i;
  int size = 0;
  int np = 0, nd = 0;
  char com[20];
  scanf("%d", &n);
  init();
  for(i=0;i<n;i++) {
    scanf("%s%d",com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    } else if(com[0] == 'd') {
      if(strlen(com) > 6) {
        if(com[6] == 'F')
          deleteFirst();
        else if(com[6] == 'L')
          deleteLast();
      } else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}



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

using namespace std;

int main()
{
     long long int n,m,sum=0;
     cin>>n;
     cin>>m;
     long long int a[m],i;
     for(i=0;i<m;i++)
        cin>>a[i];
     for(i=0;i<m;i++)
        sum=sum+a[i];
     if(n>=sum)
        cout<<n-sum;
     else
        cout<<"-1";
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <string>
#include <stdlib.h>
#include <climits>
#include <vector>
#include <math.h>
#include <map>
#include <set>
using namespace std;
int main()
{
    long long int n,k;
    cin>>n>>k;
        if (n%k==0)
        {
            cout<<0;
        }
        else
        {
           long long int t;
           t=n%k;
           if (t<abs(t-k))
           {
               cout<<t;
           }
           else
            cout<<abs(t-k);
        }
}

Measured memory_bytes: 256
Main(myin());
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var s = input[1];
  var t = input[2];
  if(input[1] == input[2]){
     myout(N);
  }else{
    for(var i = 1; i <= N ;i++){
      var tmpS = s.slice(i);
      var tmpT = t.slice(0,N-i);
      myerr(tmpS + " " + tmpT);
      if(tmpS == tmpT){
        myout(N + i);
        return;
      }
    }
    myout(tmp.length);
  }
  
}

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


int main()
{
    int n,k,ans=1;
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
            if(ans<k)
            {
                ans=ans*2;

            }
            else
            {
                ans=ans+k;

            }
        }
    cout<<ans;
}


Measured memory_bytes: 256
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func solve(io *Io) {
	a := io.NextInt()
	b := io.NextInt()

	diff := b - a
	for ; diff > 0; {
		b -= diff
		diff--
	}

	io.PrintLn(-b)

}

func main() {
	io := NewIo()
	defer io.Flush()

	solve(io)
}

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

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

#define MAX_N 500000
#define INF 1000000005

int L[MAX_N / 2 + 5], R[MAX_N / 2 + 5];
int cnt;

void merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  rep(i, n1) L[i] = A[left + i];
  rep(i, n2) R[i] = A[mid + i];
  L[n1] = INF;
  R[n2] = INF;
  int l_idx = 0, r_idx = 0;
  for (int k = left; k < right; k++) {
    cnt++;
    if (L[l_idx] <= R[r_idx]) {
      A[k] = L[l_idx];
      l_idx++;
    } else {
      A[k] = R[r_idx];
      r_idx++;
    }
  }

  return;
}

void mergeSort(int A[], int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int n, A[MAX_N];
  cin >> n;
  rep(i, n) cin >> A[i];
  cnt = 0;
  mergeSort(A, 0, n);
  rep(i, n) {
    if (i > 0) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 6976
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll s[222][222];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  for(int i=0;i<n;i++){
    string ss;cin>>ss;
    for(int j=0;j<n;j++){
      s[i][j]=ss[j]-'0';
    }
  }
  bool ans=false;
  ll num=0;
  for(int i=0;i<n;i++){
    vi vis(333);
    queue<pair<ll,pair<ll,ll>>>que;
    que.push(mp(i,mp(1,-1)));
    vis[i]=1;
    bool flfl=true;
    while(!que.empty()){
      ll now=que.front().F;
      ll cnt=que.front().S.F;
      ll par=que.front().S.S;
      que.pop();
      for(int j=0;j<n;j++){
	if(par==j)continue;
	if(s[now][j]){
	  if(vis[j]==0){
	    vis[j]=cnt+1;
	    que.push(mp(j,mp(cnt+1,now)));
	  }else if(vis[j]==cnt-1){
	  }else if(vis[j]==cnt+1){
	  }else{
	    // cout<<i<<" "<<now<<" "<<j<<" "<<cnt+1<<endl;
	    flfl=false;
	    break;
	  }
	}
      }
    }
    if(flfl){
      ans=true;
      for(int j=0;j<n;j++)
	num=max(num,vis[j]);
    }
  }
  if(ans)cout<<num<<endl;
  else cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 768
from itertools import product
from collections import defaultdict
MOD = 10**9 + 7
N = int(input())
# XAGC, XGAC, AXGC, AGXC, XACG: prohibited
A=0; C=1; G=2; T=3
cur = defaultdict(lambda: 1)
cur[(A,G,C)] = cur[(G,A,C)] = cur[(A,C,G)] = 0
for _ in range(3,N):
    prev = cur
    cur = defaultdict(int)
    for (i,j,k,l) in product(range(4),repeat=4):
        if ((j,k,l)==(A,G,C) or (j,k,l)==(G,A,C) or (i,k,l)==(A,G,C) or
            (i,j,l)==(A,G,C) or (j,k,l)==(A,C,G)):
            continue
        else:
            cur[(j,k,l)] += prev[(i,j,k)]
    for ijk in product(range(4),repeat=3):
        cur[ijk] %= MOD

ans = sum(cur.values()) % MOD
if N <= 3:
    print([1,4,16,61][N])
else:
    print(ans)

Measured memory_bytes: 53872
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    ll x, y; cin >> x >> y;
    int cnt = 0;
    while(x <= y) {
        x *= 2;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/

#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second

#define what_is(x)     cerr << #x << " is " << x << endl;

///*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)
{
    cout << endl ;
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
int ini()
{
    int x;
    scanf("%d",&x);
    return x;
}
long long inl()
{
    long long x;
    scanf("%lld",&x);
    return x;
}

const int N = (int) 1e5 + 5;
const int inf = (int) 1e9 + 7;
const double pi=2* acos(0.0);
int dp[N][3];
int a[N],b[N],c[N];

int main()
{

    int n,i,j,k;
    n=ini();
    for(int i=1; i<=n; i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    for(int i=1;i<=n;i++){
       dp[i][1]=max(dp[i-1][2],dp[i-1][3]) + a[i];
       dp[i][2]=max(dp[i-1][1],dp[i-1][3]) + b[i];
       dp[i][3]=max(dp[i-1][1],dp[i-1][2]) + c[i];
    }

    int res=max(dp[n][1],max(dp[n][2],dp[n][3]));
    cout<<res<<endl;

    return 0;
}







Measured memory_bytes: 2560
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long x = sc.nextLong();
		
		// 計算
		long result = 0;
		long m = 100;
		while(m < x){
		    m = (long)(m * 1.01);
		    result++;
		}
		
		// 出力
		System.out.println(result);
	}
}



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

fn repeat(s: &str, n: usize) -> String {
    (0..n).map(|_| s).collect::<Vec<_>>().concat()
}

fn main() {
    let (sx, sy, tx, ty) = scan!(i64, i64, i64, i64);
    print!("{}", repeat("R", (tx - sx) as usize));
    print!("{}", repeat("U", (ty - sy) as usize));
    print!("{}", repeat("L", (tx - sx) as usize));
    print!("{}", repeat("D", (ty - sy) as usize));
    print!("{}", "D");
    print!("{}", repeat("R", (tx - sx + 1) as usize));
    print!("{}", repeat("U", (ty - sy + 1) as usize));
    print!("{}", "L");
    print!("{}", "U");
    print!("{}", repeat("L", (tx - sx + 1) as usize));
    print!("{}", repeat("D", (ty - sy + 1) as usize));
    print!("{}", "R");
}


Measured memory_bytes: 4352
void main(){
	int n, a, b;
	readf("%d %d %d\n", &n, &a, &b);
	min(n*a, b).writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2768
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int x[5];
    rep(i,5){
        cin>>x[i];
        if(x[i]==0){
            cout<<i+1<<endl;
        }
    }
}

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

int main() {
  while (true) {
    int n, l, r;
    cin >> n >> l >> r;
    if (n + l + r == 0) return 0;
    
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a.at(i);
    
    int ans = 0;
    for (int i = l; i <= r; i++) {
      bool flag = false;
      for (int j = 0; j < n; j++) {
        if (i % a.at(j) == 0 && j % 2 == 0) {
          ans++;
          flag = true;
          break;
        }
        else if (i % a.at(j) == 0) {
          flag = true;
          break;
        }
      }
      if (!flag) {
        if (n % 2 == 0) ans++;
      }
    }
    
    cout << ans << '\n';
  }
}


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

int main(){
  int n;
  pair<string,int> title_time[50];
  string x;

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> title_time[i].first >> title_time[i].second; 
  }
  cin >> x;

  int cnt=0;
  int key=51;
  for(int i=0;i<n;i++){
    if(x==title_time[i].first){
      key=i;
    }
    if(key<i){
      cnt+=title_time[i].second;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    bool is_prime[60000];
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<60000; i++){
        is_prime[i] = true;
    }

    for(int i=2; i*i<60000; i++){
        if(is_prime[i]){
            for(int j=i*i; j<60000; j+=i){
                is_prime[j] = false;
            }
        }
    }
    while(true){
        int n;
        cin >> n;
        if(cin.eof())
            break;
        int i=n;
        while(true){
            if(is_prime[i-1]){
                cout<<i-1<<" ";
                break;
            }
            else i--;
        }
        i=n;
        while(true){
            if(is_prime[i+1]){
                cout<<i+1<<endl;
                break;
            }
            else i++;
        }
    }
    return 0;
}



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

int main() {
	int n;
	cin >> n;
	int i = 0, sum = 0;
	while (sum < n)
		sum += ++i;
	for (int k = 1; k <= i; k++) {
		if (sum - k == n) continue;
		cout << k << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		int max = 1;
		int x = scan.nextInt();

		for(int i = 1; i <= x; i++){
			int abs = 0;
			for(int j = 2; j <= x; j++){

				abs =(int) Math.pow((double)i, (double)j);

				if(abs > x){
					break;
				}
				if(abs > max){
					max = abs;
				}
			}
		}
		System.out.println(max);
	}
}	

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);
	
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	
	int count = 0;
	for(int i = 0; i < n; i++){
		if((a[i] + count) % b[i] == 0) continue;
		count += b[i] - (a[i] + count) % b[i];
	}
	
	cout << count << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const ll mod =  1e9+7;
#define ios std::ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);
const int maxn = 1e5 + 5;

int main() {
  ios;
  int repeat;
  cin >> repeat;
  if(repeat==0)cout<<1<<endl;
  else if(repeat==1)cout<<0<<endl;

  return 0;
}


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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

int main() {
	int N; cin >> N;
	int T[N], A[N];
	for(int i=0; i<N; i++) cin >> T[i] >> A[i];

	ll taka=1, aoki=1;
	for(int i=0; i<N; i++) {
		ll k=max(taka/T[i]+(bool)(taka%T[i]),aoki/A[i]+(bool)(aoki%A[i]));
		taka = T[i]*k;
		aoki = A[i]*k;
	}
	cout << taka+aoki << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
template<class T>void sort(vector<T> &v){sort(v.begin(),v.end());}
template<class T>void rsort(vector<T> &v){sort(v.rbegin(),v.rend());}
template<class T>int lower_bound(vector<T> &v, T key){
  auto itr=lower_bound(v.begin(),v.end(),key);
  return distance(v.begin(),itr);
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> s;
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
        s.resize(N);
        for(int i=0;i<N;i++)s[i]=1;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        s[rx]+=s[ry];
        s[ry]=s[rx];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int Size(int x){
      return s[root(x)];
    }
};
int main(){
  int n,m,k;cin>>n>>m>>k;
  vector<pair<int,int>> ab(m); for(auto &i:ab)cin>>i.first>>i.second;
  vector<pair<int,int>> cd(k); for(auto &i:cd)cin>>i.first>>i.second;
  for(auto &i:ab){i.first--;i.second--;}
  for(auto &i:cd){i.first--;i.second--;}

  UnionFind uni(n);
  for(auto i:ab)uni.unite(i.first,i.second);

  for(int i=0;i<cd.size();i++){
    if(uni.same(cd[i].first,cd[i].second)==false){
      cd.erase(cd.begin()+i);
      i--;
    }
  }
  vector<set<int>> block(n);
  vector<set<int>> fri(n);
  for(int i=0;i<cd.size();i++){
    block[cd[i].first].insert(cd[i].second);
    block[cd[i].second].insert(cd[i].first);
  }
  for(int i=0;i<ab.size();i++){
    fri[ab[i].first].insert(ab[i].second);
    fri[ab[i].second].insert(ab[i].first);
  }

  for(int i=0;i<n;i++){
    cout<<uni.Size(i)-block[i].size()-fri[i].size()-1<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
  int N;
  cin >> N;
  cout << (N + 1) / 2 << endl;
  return 0;
}


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


int main(){
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> H(N);
  for(auto& h : H){
    cin >> h;
  }
  int ans = 0;
  double min_abs_dT = abs((double) A - ((double)T - (double)H[0]*0.006));
  for(int ii=1; ii<N; ii++){
    double dT = abs((double) A - ((double)T - (double)H[ii]*0.006));
    if(dT < min_abs_dT){
      min_abs_dT = dT;
      ans = ii;
    }
  }
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().strip().split())
data = [list(map(int, input().strip().split())) for _ in range(n)]

data = sorted(data, key=lambda d: d[0])

shop = 0
cost = 0
bought = 0

while bought < m:
    price = data[shop][0]
    stock = data[shop][1]

    if m - bought <= stock:
        buy = m - bought
    else:
        buy = stock

    cost += price * buy
    bought += buy
    shop += 1

print(cost)


Measured memory_bytes: 29796
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h> 
#define MaxN 100000+100
typedef long long LL;
int root[MaxN];
int find(int now)
{
	if(root[now]<0)
		return now;
	else
		return root[now]=find(root[now]);
}
LL my_min(LL a,LL b)
{
	return a<b ? a:b;
 } 
void merge(int a,int b)
{
	int r_a=find(a);
	int r_b=find(b);
	if(r_a!=r_b)
	{
		if(-root[r_a]>-root[r_b])
		{
			root[r_a]+=root[r_b];
			root[r_b]=r_a;
		}
		else
		{
			root[r_b]+=root[r_a];
			root[r_a]=r_b;
		}
	}
}
int main()
{
	int N,M;
	memset(root,-1,sizeof(root));
	scanf("%d %d",&N,&M);
	for(int i=0;i<M;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		merge(a,b); 
	}
	LL sum=0;
	int r_1=find(1);
	int r_2=find(2);
	sum=my_min(-root[r_1],-root[r_2]);
	LL pp=N-sum;
	sum=sum*(sum-1)/2+pp*(pp-1)/2;
	sum-=M;
	printf("%lld\n",sum); 
	return 0;
 } 

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define SC scanf
#define PR printf
#define pb push_back
#define mp make_pair
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1000000000
#define ll long long
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef pair<pii,pii> ppp;
typedef vector<int> vi;
typedef vector<pii> vii;
const int xx[4]={1,-1,0,0};
const int yy[4]={0,0,1,-1};
multiset<int>ms;
int main(){
    ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int t;
		cin>>t;
		ms.insert(t);
	}
	int ans=0;
	while(!ms.empty()){
		auto it=ms.end();
		it--;
		int x=*it;
		ms.erase(it);
		int i;
		for(i=1;i<=x;i*=2);
		if(ms.find(i-x)!=ms.end()){
			ans++;
			ms.erase(ms.find(i-x));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 100010
using namespace std;
int nxt[N<<1],to[N<<1],head[N],cnt;
void add(int u,int v)
{
	nxt[++cnt]=head[u];
	to[cnt]=v;
	head[u]=cnt;
}
int n;
int ans[N],tot;
int siz[N];
bool dfs(int u,int pre)
{
	siz[u]=1;
	if(u==n){ans[++tot]=u;return true;}
	bool can=false;
	for(int i=head[u];i;i=nxt[i])
	{
		int v=to[i];
        if(v==pre)continue;
        if(dfs(v,u)) can=true;
        siz[u]+=siz[v];
 	}
 	if(can) ans[++tot]=u;
	return can;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	dfs(1,0);
	int res=0;
	for(int i=tot;i>tot/2;i--)
	res+=siz[ans[i]]-siz[ans[i-1]];
	puts(res*2>n?"Fennec":"Snuke");
	return 0;
}


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

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

    map<int, int> card_map;
    rep(i, 9) {
        int a;
        cin >> a;
        card_map[a] = i+1;
    }
    bool card[10] = {0};
    int N; cin>>N;
    rep(i, N) {
        int b; cin>>b;
        card[card_map[b]]=1;
    }
    if((card[1]&&card[2]&&card[3])
        ||(card[4]&&card[5]&&card[6])
        ||(card[7]&&card[8]&&card[9])
        ||(card[1]&&card[4]&&card[7])
        ||(card[2]&&card[5]&&card[8])
        ||(card[3]&&card[6]&&card[9])
        ||(card[1]&&card[5]&&card[9])
        ||(card[3]&&card[5]&&card[7])
    ){
        cout << "Yes" << endl;
    }
    else{ 
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
f :: [Int] -> [Int] -> Int -> Int
f _ [] s = s
f (a:as) (b:bs) s = max s (f as bs (s - a + b))

main = do
    [n, k] <- map read . words <$> getLine :: IO [Int]
    p <- map ((+ (-1)) . read) . words <$> getLine :: IO [Int]
    let s = f p (drop k p) (sum (take k p))
    print $ (fromIntegral s) / 2.0 + fromIntegral k


Measured memory_bytes: 44028
#include<cstdio>

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

using namespace std;

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

int h,w;
char B[10][11];

int num;
char ans[31];
bool dfs(int i,int x,int y,int dir){
	if(i==num) return true;

	B[y][x]='.';
	rep(k,4) if(k!=((dir+2)&3)) {
		bool ok=false;
		int xx=x,yy=y;
		while(0<=xx && xx<w && 0<=yy && yy<h){
			if(B[yy][xx]=='o'){ ok=true; break; }
			xx+=dx[k];
			yy+=dy[k];
		}
		if(ok){
			ans[i]="RULD"[k];
			if(dfs(i+1,xx,yy,k)) return true;
		}
	}
	B[y][x]='o';

	return false;
}

int main(){
	scanf("%d%d",&h,&w);
	rep(i,h) scanf("%s",B[i]);

	int sx,sy;
	rep(i,h) rep(j,w) {
		if(B[i][j]=='o') num++;
		if(B[i][j]!='o' && B[i][j]!='.') sx=j, sy=i;
	}

	int f[128];
	f['R']=0;
	f['U']=1;
	f['L']=2;
	f['D']=3;
	dfs(0,sx,sy,f[B[sy][sx]]);

	puts(ans);

	return 0;
}

Measured memory_bytes: 1016
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <list>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <fstream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define INF 1000000007
using namespace std;
typedef long long LL;
//typedef pair<int,int> P;
//typedef priority_queue<P, vector<P>, greater<P> > minPQ;
struct edge {int to,cost;};
//const int SIZE = 1<<18;

int N,A[100010];
int main() {
	cin >> N;
	REP(i,N) cin >> A[i];
	sort(A,A+N);
	bool f = true;
	if(N%2==1) {
		if(A[0]!=0) f = false;
		REP(i,(N-1)/2) {
			int j = i*2+1;
			if(A[j]!=A[j+1] || A[j]!=(i+1)*2) f = false;
		}
	} else {
		REP(i,N/2) {
			int j = i*2;
			if(A[j]!=A[j+1] || A[j]!=(i*2+1)) f = false;
		}
	}
	if(!f) {
		cout << 0 << endl;
		return 0;
	}
	LL ans = 1;
	if(N%2==1) {
		REP(i,(N-1)/2) {
			ans *= 2;
			ans %= 1000000007;
		}
	} else {
		REP(i,N/2) {
			ans *= 2;
			ans %= 1000000007;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
struct Node {
        int key;
      struct   Node *prev, *next;
};
struct Node *nil;
void printList(){
  struct Node *cur = nil->next;
  int isf =0;
  while(1){
    if(cur==nil){
      break;
    }
    if(isf++>0){
      printf(" ");
    }
    printf("%d",cur->key);
    cur=cur->next;
  }
  printf("\n");
}
void init(){
        nil=(struct Node *)malloc(sizeof(struct Node));
        nil->next=nil;
        nil->prev=nil;
}
void insert(int key){
        struct Node *x=(struct Node *)malloc(sizeof(struct Node));
        x->key=key;
        x->next=nil->next;
        nil->next->prev=x;
        nil->next=x;
        x->prev=nil;
}
struct Node* listsearch(int key){
        struct Node *cur=nil->next;
        while(cur!=nil&&cur->key !=key) {
                cur=cur->next;
        }
        return cur;
}
void deleteNode(struct Node *t){
        if(t==nil) {
                return;
        }
        t->prev->next=t->next;
        t->next->prev=t->prev;
        free(t);
 
}
void deleteFirst(){
        deleteNode(nil->next);
}
void deleteLast(){
        deleteNode(nil->prev);
}
void deletekey(int key){
        deleteNode(listsearch(key));
}
int main(){
        int key,n,i;
        int size=0;
        char com[20];
        int np=0,nd=0;
        scanf("%d",&n);
        init();
        for(i=0; i<n; i++) {
                scanf("%s%d",com,&key);
                if(com[0]=='i') {
                        insert( key);
                        np++;
                        size++;
                }
                else if(com[0]=='d') {
                        if(strlen(com)>6) {
                                if(com[6]=='F') {
                                        deleteFirst();
                                }
                                else if(com[6]=='L') {
                                        deleteLast();
                                }
 
                        }
 
                        else{
                                deletekey(key);
                                nd;
                        }
                        size--;
 
                }
        }
        printList();
        return 0;
}

Measured memory_bytes: 31784
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int N = 0;
		int Cost1 = 0;
		int Cost2 = 0;
		int mid = 0;
		int mid2 = 0;
		int sum = 0;
		ArrayList <Integer> Array = new ArrayList<>();
		Scanner scan = new Scanner(System.in);

		N = scan.nextInt();
		for(int i = 0;i < N; i++) {
			Array.add(scan.nextInt());
			sum += Array.get(i);
		}

		mid = sum / N;

		mid2 = mid + 1;
		
		for(int j = 0; j < Array.size(); j++){
			Cost1 += (Array.get(j) -mid) * (Array.get(j) - mid);
			Cost2 += (Array.get(j) -mid2) * (Array.get(j) - mid2);
		}
		System.out.println(Math.min(Cost1, Cost2));

	}
}

Measured memory_bytes: 23124
from math import factorial
mod = 10**9+7

s = int(input())
if s < 3:
    print(0)
    exit()
    
def powm(a, n): #aのn乗
    ans = 1
    while n:
        if n % 2 == 1:
            ans = ans*a % mod
        a = a*a % mod
        n = n // 2
    return ans % mod

def combination(n, r):
    ans = ( factorial(n)%mod ) * powm(factorial(r), mod-2) * powm(factorial(n-r), mod-2)
    return ans % mod

max_member_num = s // 3
#print(max_member_num)
total = 0
for g_num in range(1, max_member_num+1):
    #print("g_num", g_num)
    rem = s - g_num*3
    total += combination(g_num -1 + rem, rem) % mod
print(total % mod)
#(max_member_num + rem) C rem



Measured memory_bytes: 79676
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin >> N;
  map<string , ll> m;

  rep(i,N){
    string s; cin >> s;
    m[s]++;
  }

  cout << "AC" << " " << "x" << " " << m["AC"] << endl;
  cout << "WA" << " " << "x" << " " << m["WA"] << endl;
  cout << "TLE" << " " << "x" << " " << m["TLE"] << endl;
  cout << "RE" << " " << "x" << " " << m["RE"] << endl;
}


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

signed main () {
    int n, x;
    cin >> n >> x;
    vector < int > a(n + 1, 0);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int64_t ans = 0;
    for (int i = 1; i <= n; ++i) {
        int k = max(0, a[i] + a[i - 1] - x);
        ans += k;
        a[i] -= k;
    }
    cout << ans << '\n';
}


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

int main(){
  long long n, tmp1, tmp2, tmp, x, y;
  while(cin>>n){
    cin>>x>>y;
    tmp1=x;
    tmp2=y;
    for(int i=1; i<n; ++i){
      cin>>x>>y;
      tmp=max((tmp1+x-1)/x, (tmp2+y-1)/y);
      tmp1=x*tmp;
      tmp2=y*tmp;
    }
    cout<<tmp1+tmp2<<endl;
  }
  return 0;
}





Measured memory_bytes: 384
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");
		double px1 = Double.parseDouble(tmpArray[0]);
		double py1 = Double.parseDouble(tmpArray[1]);
		double px2 = Double.parseDouble(tmpArray[2]);
		double py2 = Double.parseDouble(tmpArray[3]);

		Point2D p1 = new Point2D.Double(px1, py1);
		Point2D p2 = new Point2D.Double(px2, py2);

		int q = Integer.parseInt(br.readLine());

		for(int i = 0; i < q; i++){
			tmpArray = br.readLine().split(" ");
			double x = Double.parseDouble(tmpArray[0]);
			double y = Double.parseDouble(tmpArray[1]);

			Point2D p = new Point2D.Double(x,y);

			int result = checkClockwise(p, p1, p2);

			switch (result) {
			case COUNTER_CLOCKWISE:
				System.out.println("COUNTER_CLOCKWISE");
				break;

			case CLOCKWISE:
				System.out.println("CLOCKWISE");
				break;

			case ONLINE_BACK:
				System.out.println("ONLINE_BACK");
				break;

			case ONLINE_FRONT:
				System.out.println("ONLINE_FRONT");
				break;

			case ON_SEGMENT:
				System.out.println("ON_SEGMENT");
				break;

			default:
				break;
			}
		}

	}

	static final int COUNTER_CLOCKWISE = 1;
	static final int CLOCKWISE = 2;
	static final int ONLINE_BACK = 3;
	static final int ONLINE_FRONT = 4;
	static final int ON_SEGMENT = 5;
	static final double EPS = 0.00000001;

	//p1,p2が作るベクトルに対してpの位置関係を調べる
	static int checkClockwise(Point2D p, Point2D p1, Point2D p2){
		if(p1.getX() > p2.getX() || (p1.getX() == p2.getX() && p1.getY() > p2.getY())){
			AffineTransform rotate = AffineTransform.getQuadrantRotateInstance(2);
			Point2D tmp = null;
			p = rotate.transform(p, tmp);
			p1 = rotate.transform(p1, tmp);
			p2 = rotate.transform(p2, tmp);

//			System.out.println(p);
		}

		double theta = Math.PI/2;

		//直線のなす角が90度ではないときはここで計算
		if(p1.getX() != p2.getX()){
			theta = Math.atan((p1.getY() - p2.getY()) / (p1.getX() - p2.getX()));
		}


		AffineTransform affine;// = AffineTransform.getTranslateInstance(p1.getX(), p1.getY());
//		affine.concatenate(AffineTransform.getRotateInstance(theta));
//		affine.concatenate(new AffineTransform(1, 0, 0, -1, 0, 0));
		affine = AffineTransform.getRotateInstance(-theta);
		affine.concatenate(AffineTransform.getTranslateInstance(-p1.getX(), -p1.getY()));

		Point2D pD = new Point2D.Double();
		pD = affine.transform(p, pD);
		Point2D p2D = new Point2D.Double();
		p2D = affine.transform(p2, p2D);

		if(pD.getY() > EPS){
			return COUNTER_CLOCKWISE;
		}
		else if(pD.getY() < -EPS){
			return CLOCKWISE;
		}
		else if(pD.getX() < 0){
			return ONLINE_BACK;
		}
		else if(pD.getX() > p2D.getX()){
			return ONLINE_FRONT;
		}
		else {
			return ON_SEGMENT;
		}

	}

}



Measured memory_bytes: 27596