akhauriyash/Code-Regression huggingface dataset:
from collections import deque

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

route = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    route[a - 1].append(b - 1)
    route[b - 1].append(a - 1)

print('Yes')

q = deque()
d = [-1] * N
d[0] = 0
q.append(0)

while q:
    x = q.popleft()
    for i in route[x]:
        if d[i] == -1:
            d[i] = x + 1
            q.append(i)

for i in range(1, N):
    print(d[i])


Measured memory_bytes: 98900
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {

  ll n;
  cin >> n;

  vector<ll> p={};
  for(ll i = -200; i<=200; i++) {
  p.pb(i*i*i*i*i);
  }
  
  rep(i,400) {
    rep(j,400) {
      if(p[i]-p[j]==n) {
      cout<< i-200 << " " << j-200 << endl;
      return 0;
      }
    }
  }

}



Measured memory_bytes: 3644
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {
  static Scanner sc = new Scanner(System.in);
  public static void main(String[] args) {
    // aoj version
    while(true) {
      int n = sc.nextInt();
      int m = sc.nextInt();
      if(n==0)break;
      int[] commands = new int[n];
      for(int i = 0; i < n; i++) commands[i] = sc.nextInt();
      int[] dice = new int[m];
      for(int i = 0; i < m; i++) dice[i] = sc.nextInt();
      int curr = 0;
      for(int i = 0; i < m; i++) {
        curr += dice[i];
        if(n-1 <= curr) {
          System.out.println(i+1);
          break;
        }
        curr += commands[curr];
        if(n-1 <= curr) {
          System.out.println(i+1);
          break;
        }
      }
    }
  }
}

Measured memory_bytes: 12000
#include<stdio.h>
#include<math.h>


int main(){
  int n,s[1000],S,i;
  double m,nv,std;

  while(1){
    scanf("%d",&n);
    if(n==0){
      break;
    }
    S = 0;
    for(i=0;i<n;i++){
      scanf("%d",&s[i]);
      S+=s[i];
    }
    m = (double)S/(double)n;
    nv = 0;
    for(i=0;i<n;i++){
      nv+=(((double)s[i]-m)*((double)s[i]-m));
    }
    std = sqrt(nv/(double)n);
    printf("%f\n", std);
  }

  return 0;
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    map<LL,LL> L;
    vector<LL> A(N);
    rep(i,N)cin >> A[i];
    rep(i,N)L[A[i]]++;
    vector<LL> ct;
    for(auto itr = L.begin();itr != L.end();itr++){
        while(itr -> S > 1){
            ct.push_back(itr -> F);
            itr -> S -= 2;
        }
    }
    sort(rall(ct));
    if(ct.size() < 2)cout << 0 << endl;
    else cout << ct[0]*ct[1] << endl;

}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
int x[101];
int y[101];
int h[101];
int check(int cx, int cy)
{
    int H = 0;
    rep(i, n)
    {
        if (h[i] == 0)
        {
            continue;
        }
        if (H == 0)
        {
            H = h[i] + abs(cx - x[i]) + abs(cy - y[i]);
            break;
        }
    }
    rep(i, n)
    {
        if (h[i] != max((H - abs(cx - x[i]) - abs(cy - y[i])), 0))
        {
            return 0;
        }
    }
    return H;
}
int main()
{
    cin >> n;
    rep(i, n)
    {
        cin >> x[i] >> y[i] >> h[i];
    }
    rep(i, 101)
    {
        rep(j, 101)
        {
            int h = check(i, j);
            if (h)
            {
                cout << i << ' ' << j << ' ' << h << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int KK,N,K,i;i=0;
  scanf("%d %d",&N,&K);
  KK=1;
  while(true){
    if(N<KK){
      printf("%d\n",i);
      break;
    }
    i++;
    KK=KK*K;
  }
  return 0;
}

Measured memory_bytes: 128
// BWOTSHEWCHB

#include <bits/stdc++.h>

using namespace std ;

#define int long long
#define pb push_back
#define in insert
#define X first
#define Y second

const int MAXN = 1e6 + 69 , MOD = 1e9 + 7 ;

int n , arr[MAXN] , L[MAXN] , R[MAXN] ;

int32_t main() {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	cin >> n ;
	for ( int i = 1 ; i <= n ; i ++ )
		cin >> arr[i] ;
	for ( int i = 1 ; i <= n ; i ++ )
		L[i] = __gcd(L[i - 1] , arr[i]) ;
	for ( int i = n ; i >= 1 ; i -- )
		R[i] = __gcd(R[i + 1] , arr[i]) ;
	int ans = 1 ;
	for ( int i = 1 ; i <= n ; i ++ )
		ans = max(ans , __gcd(L[i - 1] , R[i + 1])) ;
	cout << ans << "\n" ;
}


Measured memory_bytes: 9216
h,w=map(int,input().split())
li=[]
for i in range(h):
    li.append(input())
#print(li)
dp=[[0 for i in range(w+1)] for i in range(h+1)]
dp[h-1][w-1]=1
for i in range(h-1,-1,-1):
    for j in range(w-1,-1,-1):
        if li[i][j]=='#':
            dp[i][j]=0
        else:
            if i==(h-1) and j==(w-1):
                dp[i][j]=1
            else:
                dp[i][j]=dp[i+1][j]+dp[i][j+1]
print(dp[0][0]%(10**9+7))

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

typedef long long int ll;
using namespace std;

const ll MOD = 1e9 + 7;

ll K, A, B;
 // ----------------------------------------- -------------------------------------------------- --------
ll solve () {
    ll have = 1 ;
 
    // You need to hit up to A 
    ll a = min (K, A- 1 );
    have += a;
    K -= a;
    if (K == 0 ) return have;
 
    // Replace as much as possible 
    if (A + 2 <= B) {
        ll cnt = K / 2 ;
        have += cnt * (B-A);
        if (K% 2 == 1 ) have++;
         return have;
    }
    else {
         return have + K;
    }
}
// ------------------------------------------------ -------------------------------------------------- - 
int main () {
    cin >> K >> A >> B;
    cout<<solve();
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
//typedef __int64 LL;
typedef pair<int,int> P;
const int INF=1000000000;
const int MOD_2=998244353;

int a[10010],b[10010];
int dp[1010][10010]; //N*魔力

int main()
{
	int h,n;
	cin>>h>>n;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	for(int i=0;i<=n;i++)
	{
		for(int j=1;j<=h;j++)
		{
			if(i==0)dp[i][j]=INF;
			else if(j<=a[i])dp[i][j]=min(dp[i-1][j],b[i]);
			else dp[i][j]=min(dp[i-1][j],dp[i][j-a[i]]+b[i]);
	        }
	}
	cout<<dp[n][h]<<"\n";
	return 0;
}
	

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

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

    int count = 1;
    rep(i, N-1) {
        if (S[i] == S[i+1])
            continue;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip>
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) :
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;


#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()


using ll = long long;


ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<ll> S(n); rep(i,n) std::cin >> S[i];

  std::unordered_map<ll,ll> map;  map[0] = 1;
  std::vector<ll> T(n+1);
  ll ans = 0;
  for(int i=n-1; i>=0; i--) {
    T[i] = S[i] + T[i+1];
    ans += map[T[i]];
    map[T[i]]++;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 11592
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string.h>
using namespace std;
const int manx=1e5+5;
struct node{
	int a;
	int b;
}str[100005];
bool cmp(node x,node y)
{
	return x.a<y.a;
}
int main()
{
	long long n,k;
	long long a,b;
	long long s[100005];
	long long sum=0;
	long long flag=0;
	long long ans;
	scanf("%lld %lld",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d %d",&str[i].a,&str[i].b);
	}
	sort(str,str+n,cmp);
	for(int i=0;i<n;i++)
	{
		sum+=str[i].b;
		if(sum<k)
		{
			continue;
		}
		else
		{
			if(flag)
			{
				continue;
			 } 
			ans=str[i].a;
			flag=1;
		}
	}
	printf("%lld\n",ans);
	 return 0;
 } 

Measured memory_bytes: 1024
n,k = map(int,input().split())
l = []
for i in range(n):
    a = list(map(int,input().split()))
    l.append(a)
l.sort(key=lambda x:x[0])
count = 0
i = 0
while count < k:
    count = count + l[i][1]
    i = i + 1
print(l[i-1][0])

Measured memory_bytes: 29144
#include<stdio.h>

int main(){
    
    int n,i,j,tmp,count=0;
    int A[100];
    int min;

    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&A[i]);
    }
    
    for(i=0;i<n-1;i++)
    {
        min = i;
        for(j=i;j<n;j++)
        {
         if(A[min] > A[j])
         {
             min = j;
         }    
        }
        tmp = A[i];
        A[i] = A[min];
        A[min] = tmp;
        if(i!=min)count++;
    }

    for (i=0;i<n;i++)
    {
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n%d\n",count);

    return 0;
}


Measured memory_bytes: 2084
import java.util.*;
import java.util.HashMap;
import java.util.PriorityQueue;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] p = new int[N + 1];
        int[] A = new int[N];
        int[] B = new int[N];
        HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();
        PriorityQueue<Integer> que = new PriorityQueue<>(Collections.reverseOrder());

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
            if(map.get(A[i])==null){
                ArrayList<Integer> list = new ArrayList<Integer>();
                list.add(B[i]);
                map.put(A[i], list);
            }
            else{
                ArrayList<Integer> list = map.get(A[i]);
                list.add(B[i]);
                map.put(A[i], list);
            }
        }
        long ans = 0;
        for(int i=1; i<=M; i++){
            if(map.get(i)!=null){
                ArrayList<Integer> list = map.get(i);
                que.addAll(list);
            }
            if(!que.isEmpty()){
                ans += que.poll();
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 106116
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        a = a + b + c;
        if(a>=22){
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
    } 
}

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

int main()
{
  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++)
    cin>>p.at(i);
  
  int n_min=p.at(0);
  int count=0;
  for(int i=0;i<n;i++)
  {
    if(p.at(i)<=n_min)
    {
      n_min=p.at(i);
      count++;
    }
  }
  cout<<count<<endl;
}

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

#define REP(i, x) for (int i = 0; i < (x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define CHMIN(a, b) (a) = min((a), (b))

using P = pair<int, int>;

const int MAXN = 1010;
const int MAXX = 5010;
const int INF = (1 << 28);

int N;
int X[MAXN];
int dp[MAXN][MAXX];

vector<int> tree[MAXN];

int dfs(int v, int p) {
    vector<P> children;
    for (int to : tree[v]) {
        if (to == p) continue;
        children.push_back(make_pair(dfs(to, v), X[to]));
    }

    // 初期化
    REP (i, children.size() + 1) REP (j, X[v] + 1) dp[i][j] = INF;

    dp[0][0] = 0;
    REP (i, children.size()) {
        REP (j, X[v] + 1) {
            if (dp[i][j] >= INF) continue;

            int cost1 = children[i].first,
                cost2 = children[i].second;
            if (j + cost1 <= X[v]) CHMIN(dp[i + 1][j + cost1], dp[i][j] + cost2);
            if (j + cost2 <= X[v]) CHMIN(dp[i + 1][j + cost2], dp[i][j] + cost1);
        }
    }
    int res = INF;
    REP (i, X[v] + 1) CHMIN(res, dp[children.size()][i]);

    /*
    cerr << "======" << v << "==========" << endl;
    REP (i, X[i] + 1) {
        cerr << dp[children.size()][i] << endl;
    }
    cerr << "===========" << endl;
    */

    return res;
}

int main() {
    cin >> N;
    FOR (i, 1, N) {
        int P;
        cin >> P;
        P--;

        tree[i].push_back(P);
        tree[P].push_back(i);
    }

    REP (i, N) {
        cin >> X[i];
    }

    if (dfs(0, -1) >= INF) cout << "IMPOSSIBLE" << endl;
    else cout << "POSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=998244353;
const long double PI=3.14159265358979;
const ll MAX=0;

ll DP[600020];

int main() {
 
  ll N,K;
  cin>>N>>K;
  ll L[K];
  ll R[K];
  rep(i,K){
    cin>>L[i]>>R[i];
  }
  DP[0]=1;DP[1]=-1;
  rep(i,N){
    rep(j,K){
      DP[i+L[j]]+=DP[i];
      DP[i+L[j]]%=MOD;
      DP[i+R[j]+1]-=DP[i];
      DP[i+R[j]+1]%=MOD;
    }
    DP[i+1]+=DP[i];
    DP[i+1]%=MOD;
  }
  while(DP[N-1]<0){
    DP[N-1]+=MOD;
  }
  cout<<DP[N-1];
    
}



Measured memory_bytes: 6580
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int x=a+b;
	int y=a*b;
	if(x==15) cout<<"+"<<endl;
	else if(y==15) cout<<"*"<<endl;
	else cout<<"x"<<endl;
 	return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace AtCoder.XXX.A
{ 
    public class Program
    {
        public static void Main(string[] args)
        {
            var datas = r();
            var cnt = 0;
            foreach(var data in datas)
			{
                if(data == '1')
				{
                    cnt++;
				}
			}
            P(cnt);
        }

        private static StreamReader sr;
        public static int[] Ecr()
        {
            if (sr == null)
            {
                sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8"));
            }
            return sr.ReadLine().Split().Select(int.Parse).ToArray();
        }

        public static string Er()
		{
            if(sr == null)
			{
                sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8"));
            }
            return sr.ReadLine();
        }
        public static string r()
		{
            return Console.ReadLine();
		}
        public static  int[] cr()
        {
            return Console.ReadLine().Split().Select(int.Parse).ToArray();
        }
        public static int cri()
        {
            return int.Parse(Console.ReadLine());
        }
        public static void P(string str)
        {
            Console.WriteLine(str);
        }
        public static void P(int num)
        {
            P(num.ToString());
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;

int main(){
    ll n,k;
    std::cin >> n>>k;
    std::vector<pair<ll,ll>> a(n);
    rep(i,n){
        std::cin >> a[i].fi>>a[i].se;
    }
    sort(all(a));
    ll cnt=0ll;
    rep(i,n){
        cnt+=a[i].se;
        if(cnt>=k){
            std::cout << a[i].fi << std::endl;
            exit(0);
        }
    }
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;


int main() {
    long long a, b;
    cin >> a >> b;
    if (a * b <= 0) cout << "Zero" << endl;
    else if (a > 0 && b > 0) cout << "Positive" << endl;
    else {
        if ((b - a + 1) % 2 == 0) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
a, b, q = map(int, input().split())
s = []
t = []
x = []
for i in range(a):
    s.append(int(input()))
for i in range(b):
    t.append(int(input()))
for i in range(q):
    x.append(int(input()))
import bisect
def get(x):
    ls,rs,lt,rt=10**13,10**13,10**13,10**13
    s_ind = bisect.bisect_left(s,x)
    t_ind = bisect.bisect_left(t,x)
    if s_ind!=0:
        ls=abs(x - s[s_ind-1])
    if s_ind!=a:
        rs=abs(x - s[s_ind])
    if t_ind!=0:
        lt=abs(x - t[t_ind-1])
    if t_ind!=b:
        rt=abs(x - t[t_ind])
    return ls,rs,lt,rt

for que in x:
    ls,rs,lt,rt = get(que)

    rr = max(rs,rt)
    ll = max(ls,lt)
    lsrt = 2*ls+rt
    ltrs = 2*lt+rs
    rslt = 2*rs+lt
    rtls = 2*rt+ls
    ans = min([rr,ll,lsrt,ltrs,rslt,rtls])
    print(ans)

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

using namespace std;

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

map<string, int> S;

int N;
string ss[100000];

int main() {
    cin >> N;
    rep(i, N) cin >> ss[i];
    rep(i, N) {
        sort(ss[i].begin(), ss[i].end());
        auto iter = S.find(ss[i]);
        if (iter != S.end()) {
            iter->second ++;
        } else {
            S[ss[i]] = 1;
        }
    }
    ll count = 0;
    for (auto p : S) {
        count += (ll)(p.second) * (p.second - 1) / 2;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 18176
s = list(input())
cnt1 = 0
cnt2 = 0
val1 = 0
val2 = 1
for i in range(len(s)):
    if int(s[i]) == val1 % 2:
        cnt1 += 1
    val1 += 1
    if int(s[i]) == val2 % 2:
        cnt2 += 1
    val2 += 1
print(min(cnt1, cnt2))

Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
void solve() {
   int n,d;
   cin>>n>>d;
   int x,y;
   int cnt=0;
   for(int i=0;i<n;++i)
   {
       cin>>x>>y;
       if(sqrt((x*x)+(y*y))<=d) cnt++;
   }
   cout<<cnt;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--) solve();
}

Measured memory_bytes: 3668
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <map>
using namespace std;

typedef long long ll;
const ll inf = 1e15;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 1;
    for (int i = 1; i < n; i++) if (s[i] != s[i - 1]) ans++;
    cout << ans << "\n";
}

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


#define mod 1000000007
#define ull unsigned long long int
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<ll,ll>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return true; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}

ll ncr(int n, int k)  
{  
	if(k>n)return 0;
    ll res = 1;  
    if ( k > n - k )  
        k = n - k;  
    for (int i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
  
    return res;  
} 
  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 
#define  deb(x)       cout << '>' << #x << ':' << x << endl;


void  solve()
{
	ll n;
	cin>>n;
	ll x=1,ans=0;
	while(n>=1)
	{
		n=n/2;
		ans+=x;
		x*=2;
	}
	cout<<ans<<endl;

}


int main()
{
 
    FastIO;
    ll t=1;
   	//bcin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,d,m;
ll c[200010];
pair<ll,ll> a[200010];
int main(){
	cin>>n>>d>>m;
	for(int i=1;i<=n;i++)cin>>a[i].first>>a[i].second;
	sort(a+1,a+n+1);
	ll temp=0;
	ll ans=0;
	d*=2;
	for(ll i=1;i<=n;i++){
		temp-=c[i];
		a[i].second-=temp;
		if(a[i].second>0){
			ll t=(a[i].second+m-1)/m;
			ans+=t;
			temp+=m*t;
			int l=0,r=n+1;
			while(l<r){
				int mid=(l+r)/2;
				if(a[mid].first>a[i].first+d)r=mid;
				else l=mid+1;
			}
			if(l!=n+1)c[l]+=m*t;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
# これかなり難しくないですか
# 解説見た...

n = int(input())
b_lis = list(map(int, input().split()))
ans = []
while b_lis:
    tmp = -1
    for i, v in enumerate(b_lis):
        if v == i + 1:
            tmp = i
    if tmp >= 0:
        ans.append(tmp + 1)
        b_lis = b_lis[:tmp] + b_lis[tmp + 1 :]
    else:
        print(tmp)
        exit()

for v in ans[::-1]:
    print(v)



Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[22][1ll<<21];

int main(){
  int n; cin >> n;
  vector<vector<int> > a(n,vector<int>(n));
  rep(i,n)rep(j,n) cin >> a[i][j];
  dp[0][0]=1;
  rep(i,n){
    rep(s,1ll<<n)if(__builtin_popcount(s)==i){
      rep(j,n){
        if(a[i][j]&&(((1ll<<j)&s)==0)){
          dp[i+1][s|(1ll<<j)]+=dp[i][s];
          dp[i+1][s|(1ll<<j)]%=mod;
        }
      }
    }
  }
  ll ans=0;
  rep(s,1ll<<n){
    ans+=dp[n][s];
    ans%=mod;
  }
  cout << ans << endl;
  /*
  rep(i,n+1){
    rep(j,1ll<<n){
      cout << dp[i][j];
    }cout << endl;
  }*/
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll D, N;
    cin >> D >> N;

    ll ans = 0;
    if (D == 0) {
        if (N == 100) {
            ans = 101;
        } else {
            ans = N;
        }
    } else if (D == 1) {
        if (N == 100) {
            ans = 10100;
        } else {
            ans = N*100;
        }
    } else {
        if (N == 100) {
            ans = 1010000;
        } else {
            ans = N*10000;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << p.first << " " << p.second;
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < (int)v.size(); i++)
        os << v[i] << (i + 1 != v.size() ? " " : "");
    return os;
}

void solve()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    bool takahashi = true;
    while (true)
    {
        if (takahashi)
        {
            c -= b;
            if (c <= 0)
            {
                cout << "Yes" << endl;
                return;
            }
            takahashi = false;
        }
        else
        {
            a -= d;
            if (a <= 0)
            {
                cout << "No" << endl;
                return;
            }
            takahashi = true;
        }
    }
}

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

Measured memory_bytes: 3612
// ABC 116 D
#include<bits/stdc++.h>

using namespace std;
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define PB(a) push_back(a)
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int N,M,ans=0;
  cin >> N >>M;
  if(N>=M){
    cout << 0 << endl;
    return 0;
  }
  VI x(M);
  REP(i,M){
    cin >> x[i];
  }
  SORT(x);
  VI diff(M-1);
  REP(i,M-1){
    diff[i] = x[i+1]-x[i]; 
  }
  RSORT(diff);
  REP(i,M-N){
    ans += diff[i+N-1];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
set<int> s;
int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
	{
		int x, y;
		scanf("%d%d",&x,&y);
		if(x == 0)
		{
			s.insert(y);
			printf("%d\n",s.size());
		}
		if(x == 1) printf("%d\n",s.count(y));
	}
	return 0;
}


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

int main()
{
  int n, m;
  cin >> n >> m;

  int s[100001];
  bool r[100001];
  for(int i = 1; i <= n; i++){
    s[i] = 1;
    r[i] = false;
  }
  r[1] = true;

  for(int i = 0; i < m; i++){
    int x, y;
    cin >> x >> y;

    s[x]--; s[y]++;
    r[y] |= r[x];

    if(s[x] == 0) r[x] = false;
  }

  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(r[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}

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

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

	string s;cin >> s;
	int ans;
	for(int i = 0; i < (1<<s.size()-1); i++){
		int sum = stoi(s.substr(0,1));
		for(int j = 0; j < s.size()-1; j++){
			if(i&(1<<j)){
				sum -= stoi(s.substr(j+1,1));
			}else{
				sum += stoi(s.substr(j+1,1));
			}
		}
		if(sum == 7){
			ans = i;
		}
	}

	string out = "";
	for(int i = 0; i < 3; i++){
		out += s.substr(i,1);
		if(ans&(1<<i)){
			out += "-";
		}else{
			out += "+";
		}
	}
	out += s.substr(3,1)+"=7";
	cout << out << endl;
	
}


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  set<ll> st;
  rep(i,n){
    cin>>v;
    st.insert(v);
  }
  cout<<st.size()<<endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int arr[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            arr[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        int u,k;
        scanf("%d %d",&u,&k);
        for(int j = 0; j < k; j++){
            int v;
            scanf("%d",&v);
            arr[u-1][v-1] = 1;
        }
    }
    for(int row = 0; row < n; row++){
        for(int column = 0; column < n; column++){
            printf("%d",arr[row][column]);
            if(column != n-1){
                printf(" ");
            }
        }
        printf("\n");
    }
}

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

#define mod 1000000007
char path[1005][1005];
long long int num_path[1005][1005] = {0};

int main()
{
	long long int h,w,ans;
	cin>>h>>w;
	for(long long int i=0; i<=h; i++)
	{
		for(long long int j=0; j<=w; j++)
		{
			if(i==0 || j==0)
			{
				path[i][j] = '#';
				continue;
			}
			cin>>path[i][j];
		}
	}
	for(long long int i=0; i<=h; i++)
	{
		for(long long int j=0; j<=w; j++)
		{
			if(path[i][j] == '#')
			{
				num_path[i][j] = 0;
				continue;
			}
			if(i==1 && j==1)
			{
				num_path[i][j] = 1;
				continue;
			}
			num_path[i][j] = (num_path[i-1][j] + num_path[i][j-1]) % mod;
		}
	}
	cout<<num_path[h][w]<<endl;
}

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

int main(void)
{
	int num;
	long long int money, limit= 1, product= 0;

	cin>>num>>money;
	product+= money-1;
	for(int i= 1; i < num; i++)
	{
		cin>>money;

		if(money < limit+1)
			continue;
		else if(money == limit+1)
		{
			limit++;
			continue;
		}

		if(money%(limit+1) == 0)
			product+= money/(limit+1)-1;
		else
			product+= money/(limit+1);
	}

	cout<<product<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	IOS;
	 
    int n; cin>>n;
    map <ll,ll> m;
    ll sm = 0;
    forn(i,n)
    {
        ll p; cin>>p;
        m[p]++;
        sm += p;
    }
    int q; cin>>q;
    forn(i,q)
    {
        ll b,c; cin>>b>>c;
        ll g = m[b];
        sm -= g*b;
        sm += g*c;
        m[b] = 0;
        m[c] += g;
        cout<<sm<<'\n';
    }
	
	return 0;
}


Measured memory_bytes: 9400
#include "bits/stdc++.h"

using namespace std;
using int64 = long long int;

constexpr int64 Mod = 1000000000 + 7;

// a^n MOD mod
template<typename T>
T ModPow(T a, T n, T mod)
{
	T res = 1;

	while (n > 0)
	{
		if (n & 1)
			res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}

	return res;
}

// a^{-1} mod を計算する
template<typename T>
T ModInv(T a, T mod)
{
	return ModPow(a, mod - 2, mod);
}

int64 C(int64 n, int64 r)
{
	int64 ans = 1;

	for (int64 i = 0; i < r; i++)
	{
		ans = (ans * (n - i)) % Mod;
	}

	for (int64 i = 0; i < r; i++)
	{
		ans = (ans * ModInv<int64>(i + 1, Mod)) % Mod;
	}

	return ans;
}

int main()
{
	int64 n, a, b;
	cin >> n >> a >> b;

	int64 ans = (ModPow<int64>(2, n, Mod) - 1 + Mod) % Mod;
	ans = (ans - C(n, a) + Mod) % Mod;
	ans = (ans - C(n, b) + Mod) % Mod;

	cout << ans << endl;
}

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

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

  string S;
  cin >> S;

  auto f = [&](string s) {
    int n = s.size();
    auto sa = suffix_array(s);
    auto lcp = lcp_array(s, sa);
    long ret = n - sa.at(0);
    for (int i = 0; i + 1 < n; i++) {
      ret += n - sa.at(i + 1) - lcp.at(i);
    }
    return ret;
  };

  cout << f(S) << "\n";
}

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

int main(){
    int N; cin >> N;
    double x[N];
    string u[N];
    double ans = 0;

    for(int i = 0; i < N ; i++){
        cin >> x[i] >> u[i];

        if(u[i] == "JPY") ans += x[i];
        else ans += x[i] *  380000.0;

    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

const int MOD = 998244353;

signed main(){

  int n; cin >> n;
  vector<int> d(n);
  int Max = -1;
  for(int i = 0; i < n; i++){
    cin >> d[i];
    Max = max(Max, d[i]);
  }

  vector<int> dp(n+1, 0);
  for(int i = 0; i < n; i++){
    dp[d[i]]++;
  }
  if(dp[0] != 1){
    cout << 0 << endl;
    return 0;
  }
  if(d[0] != 0){
    cout << 0 << endl;
    return 0;
  }

  int ans = 1;
  for(int i = 1; i <= Max; i++){
    for(int j = 0; j < dp[i]; j++){
      ans *= dp[i-1];
      ans %= 998244353;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1920
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strAry = br.readLine().split(" ");
		int r = Integer.parseInt(strAry[0]);
		int c = Integer.parseInt(strAry[1]);
		int[][] table = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String[] tableAry = br.readLine().split(" ");
			for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			}
			table[r][c] += table[i][c];
		}
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			}
		}
	}
}

Measured memory_bytes: 33076
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
LL modpow(LL a, LL b) { LL p = 1;
  REP(i, 0, b) { p = (p*a)%(LL)(1e9+7); }
  return p;
}

int main() {
  int n;
  cin >> n;
  VEC<int> a(n);
  REP(i, 0, n) cin >> a[i];
  sort(ALL(a));
  if (n % 2 == 1) {
    bool all = true;
    int indx = 1;
    for (int i = 2; i < n; i += 2) {
      if (a[indx] != i || a[indx + 1] != i) {
        all = false;
        break;
      }
      indx += 2;
    }
    if (all) {
      cout << modpow(2, n / 2) << endl;
      return 0;
    }
  } else {
    bool all = true;
    int indx = 0;
    DUMP(a);
    for (int i = 1; i < n; i += 2) {
      if (a[indx] != i || a[indx + 1] != i) {
        all = false;
        break;
      }
      indx+=2;
    }
    if (all) {
      cout << modpow(2, n / 2) << endl;
      return 0;
    }
  }
  cout << 0 << endl;

  return 0;
}


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

typedef struct
{
  string t;
  int id, w, l;
} Team;

class Solve
{
public:
  bool operator() (const Team& lhs, const Team& rhs) const
  {
    if (lhs.w == rhs.w) {
      if (lhs.l == rhs.l)
	return lhs.id < rhs.id;
      return lhs.l < rhs.l;
    }
    return lhs.w > rhs.w;
  }
};

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    vector<Team> team(n);
    for (int i = 0; i < n; ++i) {
      team[i].id = i;
      cin >> team[i].t;
      for (int j = 0; j < n-1; ++j) {
	int r;
	cin >> r;
	if (r == 0)
	  ++team[i].w;
	else if (r == 1)
	  ++team[i].l;
      }
    }
    sort(team.begin(), team.end(), Solve());

    for (int i = 0; i < n; ++i)
      cout << team[i].t << endl;

  }
  return 0;
}

Measured memory_bytes: 0
N, M = [int(i) for i in input().split()]
E = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = [int(i) for i in input().split()]
    E[a].append(b)
    E[b].append(a)

visited = [False] * (N + 1)

def dfs(src, count):
    if count == N:
        return 1

    visited[src] = True
    result = 0
    for dst in E[src]:
        if not visited[dst]:
            result += dfs(dst, count + 1)
    visited[src] = False

    return result

print(dfs(1, 1))

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

int main(){
	int n;
	int a[31] = {1,1,2};
	for(int i=3 ; i <= 30 ; i++ ){
		a[i] = a[i-1] + a[i-2] + a[i-3];
	}

	while( cin >> n , n ){
		cout << (a[n]/10/365 + 1) << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll k,n;
ll color[100000+1];
ll dp[100000+1];
vector<pair<ll,ll>> ki[100000+1];

void solve(ll cost,ll node){
   
    if(ki[node].size()==0){
        
    }else{
    
    for(int i=0;i<ki[node].size();i++){
        if(color[ki[node][i].first]==0){
            color[ki[node][i].first]=1;
            dp[ki[node][i].first]=cost+ki[node][i].second;
        
        solve(dp[ki[node][i].first],ki[node][i].first);
        }
    }
    }
}


int main(){
    
    
    cin>>n;
    rep(i,n-1){
        ll a,b,c;
        cin>>a>>b>>c;
        ki[a].push_back({b,c});
        ki[b].push_back({a,c});
    }
    ll q;
    
    cin>>q>>k;
    
    dp[k]=0;
    color[k]=1;
    solve(dp[k],k);
    
    for(int u=0;u<q;u++){
        ll c,d;
        cin>>c>>d;
        
       // cout<<dpp[c]<<dpp[d]<<"a"<<endl;
        cout<<dp[c]+dp[d]<<endl;
        
        
    }
    
    
    

return 0;
}


Measured memory_bytes: 15104
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
const ll MAX_N = 1e5;
ll N;
ll h[MAX_N];
ll dp[MAX_N+1]; // メモ化テーブル
 
// i番目以降の品物から重さの総和がj以下になるように選ぶ
void rec(ll i){
	if (i==0) dp[i] = 0;
	else if (i==1) dp[i] = abs(h[1]-h[0]);
	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	return;
}

int main() {
	// 入力
	ll N;
	cin >> N;
	ll A[N+1];
	for (ll i = 0; i < N; ++i) cin >> A[i+1];
 
	
	// 解法
	ll B[N+1] = {0};
	for (ll i = N; i >= 1; --i){
		ll j = (N / i) * i;
		ll sum_j = 0;
		while (j>0){
			sum_j += B[j];
			j -= i;
		}
		if (sum_j%2==A[i]) B[i] = 0;
		else B[i] = 1;
	}
	ll sum_B = 0;
	REP(i,N+1) sum_B += B[i];
	printf("%lld\n", sum_B);
	REP(i,N+1){
		if (B[i]==1) printf("%lld\n", i);
	}
}


Measured memory_bytes: 3968
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC050a
{
	class Program
	{
		static void Main(string[] args)
		{
			int A,B,z=0;
			string op;
            var word = Console.ReadLine().Split(' ');
			A = int.Parse(word[0]);
			op = word[1];
			B = int.Parse(word[2]);
			if (op == "+" )
				z = A + B;
			else if (op == "-" ) 
				z = A - B;
			Console.WriteLine(z);
			Console.ReadKey();
			
		}
	}
}

Measured memory_bytes: 11092
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e7+50;
const int mod=1e9+7;
using namespace std;
ll n;
int main(){
	cin>>n;
	for (int k=111; k<=999; k+=111){
		if (n<=k){
			cout<<k;
			break;
		}
	}	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    int N = S.size() - 2;
    cout << S[0] << N << S.back() << endl;
}


Measured memory_bytes: 256