akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		char[] word = sc.next().toCharArray();
		if(word[word.length - 1] == 's') {
			for(int i = 0; i < word.length; i++) {
				System.out.print(word[i]);
			}
			System.out.println("es");
		}else{
			for (int i = 0; i < word.length; i++) {
				System.out.print(word[i]);
			}
			System.out.println("s");
		}
        
        }
}

Measured memory_bytes: 36124
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;

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

    sort(h, h+N, greater<int>());

    int res = INF, temp = 0;
    REP(i, N-K+1){
        temp = h[i] - h[i+K-1];

        if (temp < res){
            res = temp;
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 3944
#365
D = int(input())
c = list(map(int, input().split()))

d = []

for i in range(D):
    s = list(map(int, input().split()))
    rate = 0
    type = 0
    for j in range(len(s)):
        if (rate < s[j]):
            rate = s[j]
            type = j + 1
    d.append(type)

for i in range(len(d)):
    print(d[i])

Measured memory_bytes: 9232
#define _CRT_SECURE_NO_WARNINGS
//#include <stdafx.h>
//#include "targetver.h"
#include <stdio.h>
//#include <tchar.h>
#include <iostream>
#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 <atomic>
#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>
#endif>

#define LL long long
#define MOD 1000000007
#define INF 1000000000
#define LINF 10000000000000000

using namespace std;

const int N = 2e6 + 10;

double a[N];
LL b[N];
LL pr[N];
double dp[N];
vector<int>vec;

int main() {

	LL n;
	scanf("%lld", &n);

	dp[0] = 1.0;
	for (int i = 1; i <= n; i++) {
		
		cin >> a[i];

		for (int j = i; j >= 0; j--) {
			
			if (j == i)
				dp[j] = dp[j - 1] * a[i];
			else 
				dp[j] = dp[j - 1] * a[i] + dp[j] * (1.0 - a[i]);

		}
	}
	double ans = 0;
	for (int i = n / 2 + 1; i <= n; i++) {
		ans += dp[i];
	}

	printf("%.10f", ans);
}

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

int hensyuu(int N, string A, string B, string C){
  int i,count,henkou;
  for(i=0;i<N;i++){
    count=0;
    if(A[i] == B[i]) count++;
    if(A[i] == C[i]) count++;
    if(B[i] == C[i]) count++;
    
    if(count==0) henkou+= 2;
    if(count==1) henkou++;
  }
  return henkou;
}
 
int main(){
  int N;
  string A,B,C;
  cin>>N>>A>>B>>C;
  cout<<hensyuu(N,A,B,C)<<endl;

}

Measured memory_bytes: 256
def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

a = int(arr_data[0][0])
b = int(arr_data[0][1])
c = int(arr_data[0][2])
k = int(arr_data[1][0])
arr = sorted([a, b, c])

maxdata = arr[-1:][0]

for i in range(1, k + 1):

    maxdata *= 2
    
sumdata = sum(arr[0:len(arr)-1]) + maxdata

print(sumdata)

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;

int dp[1<<5][41][21][21];
int dir[] = {-1,0,1};

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

  int W, H, N;
  cin >> W >> H >> N;
  int BB = (1<<N) - 1;
  PII s;
  cin >> s;
  --s.FF;
  --s.SS;
  vector<vector<PII>> bm(N);
  int init = 0;
  REP(i,N){
	int L;
	cin >> L;
	REP(j,L){
	  PII p;
	  cin >> p;
	  --p.FF;
	  --p.SS;
	  bm[i].EB(p);
	}
	if(bm[i][0] == s) init |= 1<<i;
  }

  auto isin = [W,H](const PII& p){ return 0 <= p.FF && p.FF < W && 0 <= p.SS && p.SS < H; };
  using D = pair<PII,PII>;
  fill((int*)dp, (int*)dp+(1<<5)*41*21*21, INF);
  queue<D> q;
  q.push(MP(MP(init,0),s));
  dp[init][0][s.FF][s.SS] = 0;
  int ans = -1;
  while(!q.empty()){
	auto dd = q.front();
	q.pop();
	if(dd.FF.FF == BB){
	  ans = dd.FF.SS;
	  break;
	}

	int ntime = dd.FF.SS+1;
	REP(dx,3) REP(dy,3){
	  PII np(dd.SS.FF+dir[dx], dd.SS.SS+dir[dy]);
	  if(!isin(np)) continue;
	  bool ok = true;
	  REP(i,N) if(bm[i].back() == np){ ok = false; break;}
	  if(!ok) continue;

	  bool bomb = false;
	  PII ns(dd.FF.FF, ntime);
	  REP(i,N){
		if(ns.FF>>i&1) continue;
		if(ntime >= SZ(bm[i])-1){
		  bomb = true;
		  break;
		}
		else if(bm[i][ntime] == np)
		  ns.FF |= 1<<i;
	  }
	  if(bomb) continue;

	  if(dp[ns.FF][ns.SS][np.FF][np.SS] == INF){
		dp[ns.FF][ns.SS][np.FF][np.SS] = ntime;
		q.push(MP(ns,np));
	  }
	}
  }
  
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 5580
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
 
 
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

void solve(ll n,ll m){
    vector<ll> v(n);
    FOR(i,0,n)cin>>v[i];

    ll x = -1;
    FOR(i,0,n){
        FOR(j,i+1,n){
            if(m>=v[i]+v[j])x = max(x,v[i]+v[j]);
        }
    }
    if(x == -1) cout<<"NONE"<<endl;
    else cout<<x<<endl;
}

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

    ll n,m;
    cin>>n>>m;
    while(n!=0){
        solve(n,m);
        cin>>n>>m;
    }
}


Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
int n,tree[200005]={};
LL k,arr[200005],konstan,ans=0;
vector <LL> press;
int nilaipress(LL angka){
	int bawah=0,atas=press.size()-1,mid;
	while(bawah<=atas)
	{
		mid=(bawah+atas)>>1;
		if(press[mid]>=angka)
			atas=mid-1;
		else
			bawah=mid+1;
	}
	return bawah+1;
}
int lsone(int angka){
	return angka&-angka;
}
void update(int indeks,int tambah){
	while(indeks<=press.size())
	{
		tree[indeks]+=tambah;
		indeks+=lsone(indeks);
	}
}
int query(int indeks){
	int ret=0;
	while(indeks>0)
	{
		ret+=tree[indeks];
		indeks-=lsone(indeks);
	}
	return ret;
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
		arr[i]-=k;
	}
	konstan=0;
	for(int i=n;i>=1;i--)
	{
		konstan+=arr[i];
		press.pb(arr[i]-konstan);
	}
	sort(press.begin(),press.end());
	press.erase(unique(press.begin(),press.end()),press.end());
	konstan=0;
	for(int i=n;i>=1;i--)
	{
		konstan+=arr[i];
		update(nilaipress(arr[i]-konstan),1);
		//sekarang cari yang totalnya>=0
		int pos=nilaipress(-konstan);
		ans+=(LL) query(press.size())-query(pos-1);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4336
from itertools import accumulate

Q = int(input())
n = 10 ** 5
L = [0] * 2 + [1] * (n-1)

for i in range(int(n ** 0.5)+1):
    if L[i] == 1:
        j = 2
        while i * j <= n:
            L[i*j] = 0
            j += 1
            
T = [0] * (n+1)
for i in range(3,n):
    if L[i] == 1 and L[(i+1) // 2] == 1:
        T[i] = 1    
s = list(accumulate(T))
    
for i in range(Q):
    l, r = map(int, input().split())
    print(s[r]-s[l-1])

Measured memory_bytes: 9828
def solve():
    N = int(raw_input())
    S = []
    for i in range(N):
        S.append(raw_input())
    has_AB = 0
    end_byA = 0
    start_byB = 0
    B_A = 0
    for i in range(N):
        if S[i][0] == 'B':
            if S[i][-1] == 'A':
                B_A += 1
            else:
                start_byB += 1
        if S[i][-1] == 'A':
            if S[i][0] != 'B':
                end_byA += 1
        for j in range(len(S[i]) - 1):
            if S[i][j:(j+2)] == 'AB':
                has_AB += 1
    if end_byA == 0 and start_byB == 0:
        ret = has_AB + max(B_A - 1, 0)
    else:
        ret = has_AB + min(end_byA + B_A, start_byB + B_A)
    print str(ret)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    
    if(s == "SUN"){
        cout<<7<<endl;
    } else if(s == "MON"){
        cout<<6<<endl;
    } else if(s == "TUE"){
        cout<<5<<endl;
    } else if(s == "WED"){
        cout<<4<<endl;
    } else if(s == "THU"){
        cout<<3<<endl;
    } else if(s == "FRI"){
        cout<<2<<endl;
    } else if(s == "SAT"){
        cout<<1<<endl;
    }
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  A = parseInt(input[0].split(' ')[0])
  B = parseInt(input[0].split(' ')[1])
  eightArg = []
  tenArg = []
  ans = -1
  for(i = 1;  Math.floor(i * 0.08) <= A; i++){
    if(Math.floor(i * 0.08) == A){
    	eightArg.push(i)
    }
  }
  for(i = 1;  Math.floor(i * 0.1) <= B; i++){
    if(Math.floor(i * 0.1) == B){
    	tenArg.push(i)
    }
  }
	eightArg.forEach(v=>{
    	if(tenArg.find(w => w==v) && ans == -1){
        	ans = v
        }
    })
  console.log(ans)
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

bool checked[100001];
bool selected[100001];
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long int n,k,a,b;
	long long int res = 0;
	int x,y;
	vector <pair<long long int,long long int>> v;
	cin >> n >> k;

	for(int i=0;i<n;i++)
	{
		cin >> a >> b;	
		v.push_back(make_pair(b,a));
	}

	sort(v.rbegin(),v.rend());

	//1.
	memset(checked,false,sizeof(checked));
	long long int sum = 0;
	long long int cnt = 0;
	long long int count = 0;
	for(int i=0;i<n;i++)
	{
		if(checked[v[i].second]==false)
		{
			checked[v[i].second] = true;
			cnt++;
		}
		sum+=v[i].first;
		count++;
		if(count==k)
		{
			break;
		}
	}
	res = max(res,(cnt*cnt)+sum);
	x = cnt;
	//cout << cnt << '\n';
	//2.
	memset(selected,false,sizeof(selected));
	memset(checked,false,sizeof(checked));
	sum = 0;
	cnt = 0;
	count = 0;
	for(int i=0;i<n;i++)
	{
		if(checked[v[i].second]==false)
		{
			checked[v[i].second]=true;
			selected[i] = true;
			sum += v[i].first;
			cnt++;
			count++;
		}
		if(count==k)
		{
			break;
		}
	}

	for(int i=0;i<n;i++)
	{
		if(count==k)
		{
			break;
		}
		if(selected[i]==false)
		{
			sum += v[i].first;
			count++;
		}
	}

	res = max(res,sum+(cnt*cnt));
	y = cnt;
	//cout << cnt << '\n';

	for(int i=x+1;i<y;i++)
	{
		memset(selected,false,sizeof(selected));
		memset(checked,false,sizeof(checked));
		sum = 0;
		cnt = 0;
		count = 0;		

		for(int j=0;j<n;j++)
		{
			if(checked[v[j].second]==false)
			{
				checked[v[j].second] = true;
				selected[j] = true;
				sum += v[j].first;
				cnt++;
				count++;
			}
			if(cnt==i || count==k)
			{
				break;
			}
		}

		for(int j=0;j<n;j++)
		{
			if(count==k)
			{
				break;
			}
			if(checked[v[j].second]==true && selected[j]==false)
			{
				sum+=v[j].first;
				count++;
			}
		}

		if(res > cnt*cnt+sum)
		{
			break;
		}
		res = max(res,cnt*cnt+sum);
	}
	cout << res << '\n';

	return 0;
}

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

int main(){
   int N;
   string S;
   cin>>N>>S;
   bool ans=true;
   
   if(S.size()%2!=0){
      ans=false;
   }
   else{
      for(int i=0;i<S.size()/2;i++){
         if(S.at(i)!=S.at(S.size()/2+i)){
            ans=false;
            break;
         }
      }
   }
  
  if(ans==true){
     cout<<"Yes"<<endl;
  }
  if(ans==false){
     cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const char nl = '\n';

int main() {
    ll h, w; cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1 << nl;
        return 0;
    }
    ll ww = w & 1 ? w - 1 : w;
    ll ans = h * (ww / 2);
    if (w & 1) {
        ans += ceil(h / 2.0);
    }
    cout << ans << nl;
    return 0;
}



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

bool is_prime(ll n){
  for(ll i = 2; i * i <= n; i++){
    if(n % i == 0){
      return false;
    }
  }
  return true;
}

int main() {
 
  ll nx;
  cin >> nx;
  if(nx == 2){
    cout << 1;
    return 0;
  }
  if(nx == 3){
    cout << 1;
    return 0;
  }
  ll n = 0;
  rep(i,nx){
    if(i * i > nx){
      n = i;
      break;
    }
  }
  if(is_prime(nx) && nx > 1){
    cout << 1;
    return 0;
  }
  
  ll ans = 0;
  for(ll i = 2; i * i <= nx; i++){
    ll count = 0;
      if(nx % i != 0){
        continue;
      }
    while(nx % i == 0){
      count++;
      nx = nx / i;
    }
    ll j;
    for(ll i = 1; i <= count; i++){
      if(i*(i+1) <= 2*count && 2*count < (i+1)*(i+2)){
        j = i;
        break;
      }
    }
    
    ans += j;
    if(nx == 1){
      break;
    }
    if(is_prime(nx)){
      ans++;
      break;
    }
 }
  cout << ans;
  return 0;
}

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

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


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

int main() {
  
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  
  else cout << "Right" << endl;
  
}  

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

int main(void) {
    int m = 0, n = 0;
    int sumM = 0, sumN = 0;
    cin >> m;

    cin >> n;

    for (int i = 0; i < m; i++) {
        sumN += i;
    }
    
    for (int j = 0; j < n; j++) {
        sumN += j;
    }

    cout << sumM + sumN;
}

Measured memory_bytes: 256
n,m,X,Y=map(int,input().split())
x=input().split()
x=list(map(int,list(x)))
y=input().split()
y=list(map(int,list(y)))
if max(x)<min(y):
    for z in range(max(x)+1,min(y)+1):
        if X<z<=Y:
             print("No War")
             exit()
        else:
             print("War")
             exit()
else:
    print("War")


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> a){
    bool b = 1;
    for(int i = 0;i<N;++i){
        if(a[i]!=0) b = 0;
    }
    if(b){
        cout<<"Yes"<<endl;
        return;
    }
    map<long long, long long> s;
    for(int i = 0;i<N;++i){
        s[a[i]]++;
    }
    if(s.size()==3){
        vector<long long> as(0), bs(0);
        for(auto itr = s.begin(); itr != s.end(); ++itr) {
            as.push_back(itr->first);
            bs.push_back(itr->second);
        }
        if(bs[0] == bs[1] && bs[2] == bs[1]){
            if((as[0]^as[1]) == as[2]){
                cout<<"Yes"<<endl;
                return;
            }
        }
    }
    if(s.size()==2){
        vector<long long> as(0), bs(0);
        for(auto itr = s.begin(); itr != s.end(); ++itr) {
            as.push_back(itr->first);
            bs.push_back(itr->second);
        }
        if(bs[0] == bs[1] * 2){
            if(as[1] == 0){
                cout<<"Yes"<<endl;
                return;
            }
        }
        if(bs[1] == bs[0] * 2){
            if(as[0] == 0){
                cout<<"Yes"<<endl;
                return;
            }
        }
    }
    cout<<"No"<<endl;
    return;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 5632
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in(),m=in();
    vector<ll>h(n);for(ll i=0;i<n;++i)h[i]=in();
    vector<vector<ll>>edge(n);
    for(ll i=0;i<m;++i){
        ll a=in()-1,b=in()-1;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<bool>good(n,true);
    for(ll i=0;i<n;++i){
        if(good[i]){
            for(auto e:edge[i]){
                if(h[e]>=h[i])good[i]=false;
                if(h[e]<=h[i])good[e]=false;
            }
        }
    }
    cout<<count(good.begin(),good.end(),true)<<endl;
}


Measured memory_bytes: 9796
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	int n; cin>>n;
	vector<int> a(n);
	set<int> b;
	int x=0;
	rep(i,0,n){
		cin>>a[i];
		x^=a[i];
	}
	rep(i,0,n) b.insert((a[i]^(a[i]-1)));
	int ans=0;
	rep(i,0,30){
		if(((x>>i)&1)!=((x>>(i+1))&1)){
			if(!b.count((1<<(i+1))-1)){
				printf("-1");
				return 0;
			}
			ans++;
		}
	}
	printf("%d",ans);
  	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int a,b,n,cnt,i;
	while(scanf("%d %d",&a,&b)!=EOF){
		n=a+b;
		cnt=0;
		while(n!=0){
			n=n/10;
			cnt++;
			//printf("cnt=%d n=%d\n",cnt,n);
		}
		printf("%d\n",cnt);
	}	
	return 0;
}



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

long long a, b, c, d, ua, ub;

long long lcm(long long a, long long b) {
    long long g = __gcd(a, b);
    return (a * b) / g;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 
    cin >> a >> b >> c >> d;
    ub = b - b / c - b / d;
    ub += b / lcm(c, d);
    ua = a - (a - 1) / c - (a - 1) / d - 1;
    ua += (a - 1) / lcm(c, d);
    
    cout << ub - ua << "\n";
    return 0;
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}

string s;
int solve(int index) {
  if(index==-1) { return 0; }
  
  if(index-5+1 >= 0 && s.substr(index-5+1,5) == "dream") { return solve(index-5); }
  else if(index-7+1 >= 0 && s.substr(index-7+1,7) == "dreamer") { return solve(index-7); }
  else if(index-5+1 >= 0 && s.substr(index-5+1,5) == "erase") { return solve(index-5); }
  else if(index-6+1 >= 0 && s.substr(index-6+1,6) == "eraser") { return solve(index-6); }
  
  return -1;
}

int main() {
  cin >> s;
  int size=(int)s.size();

  int ans=solve(size-1);

  if(ans==0) { cout << "YES" << endl; }
  else { cout << "NO" << endl; }
  return 0;
}


Measured memory_bytes: 5336
#include <iostream>
using namespace std;
int main(){
	//freopen("test", "r", stdin);
	ios::sync_with_stdio(false);
	double  N;
	cin >> N;
	bool flag = 0;
	for(int i = 1; i <= 500000; ++i){
		if((int)((double)i * 1.08) == N){
			cout << i;
			flag = 1;
			break;
		}		
	}
	if(!flag) cout << ":(";
	return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    while(cin>>n)
    {
        string a,b;
        cin>>a>>b;
        string ans;
        for(int i=0;i<n;i++)
        {
            ans += a[i];
            ans += b[i];
        }
        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

public class Program
{
	static public void Main(string[] args)
	{
		var num = ReadDouble();

		int n = 0;

		while(num > 1)
		{
			num = Math.Truncate(num / 2);
			n++;
		}
		double d = Math.Pow(2, n+1);
		Console.WriteLine(d-1);
		Console.ReadKey();
		return;
	}
	static public double ReadDouble()
	{
		return double.Parse(Console.ReadLine());
	}
	static public int ReadNum()
	{
		return int.Parse(Console.ReadLine());
	}
	static public IEnumerable<int> ReadNums()
	{
		return Console.ReadLine().Split(' ').Select(x => int.Parse(x));
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int ar[100002][2];
int check(int i,int k)
{
	int min=1000000002;
	if(i<=k)
	return ar[i][1];
	if(ar[i][1]!=-1)
    return ar[i][1];
	for(int j=k;j>0;j--)
	{
	int p=check(i-j,k);
    if(p+abs(ar[i][0]-ar[i-j][0])<min)
    min=p+abs(ar[i][0]-ar[i-j][0]); 
	}
	ar[i][1]=min;
    return ar[i][1];
}
int main()
{
	int n,k;
	cin>>n>>k;
	//int ar[n];
	for(int i=0;i<n;i++)
	{
		cin>>ar[i][0];
	}
	for(int i=0;i<n;i++)
	ar[i][1]=-1;
	for(int i=1;i<=k;i++)
	ar[i][1]=abs(ar[i][0]-ar[0][0]);
    int res=check(n-1,k);
    cout<<res;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>

using namespace std;

int main(){
	long long N, A, x[51], X = 0;
	cin >> N >> A;
	x[0] = 0;
	for (long long i = 1; i <= N; i++){
		cin >> x[i];
		if (X < x[i]){
			X = x[i];
		}
		x[i] -= A;
	}

	long long dp[N + 1][2 * N * X + 1];
	for (int j = 0; j <= N; j++){
		for (int t = 0; t <= 2 * N * X; t++){
			dp[j][t] =
				(j == 0 && t == N * X) ? 1 :
				(j > 0 && (t - x[j] < 0 || t - x[j] > 2 * N * X)) ? dp[j - 1][t] :
				(j > 0 && 0 <= t - x[j] && t - x[j] <= 2 * N * X) ? dp[j - 1][t] + dp[j - 1][t - x[j]] :
				0;
		}
	}

	cout << dp[N][N * X] - 1 << endl;

	return 0;
}


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

int main()
{
    string n,s;
    cin>>n>>s;
    s.erase(n.length());
    if(s==n)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;




    return 0;
}





Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    ll N, X; cin >> N >> X;
    ll D = 0, cnt = 1;

    for (int i = 0; i < N; i++) {
        ll L[i]; cin >> L[i];
        D += L[i];
        if (D <= X) cnt++;
    }
    cout << cnt << endl;
}


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

int n, A[30];

int solve(int i, int m) {
	if (m == 0) return true;
	if (i >= n) return false;

	int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}


int main(void) {
	int q;
	int m[300];

	cin >> n;

	for (int i = 0; i <= n - 1; i++) {
		cin >> A[i];
	}

	cin >> q;

	for (int i = 0; i <= q - 1;i++) {
		cin >> m[i];
	}

	for (int i = 0; i <= q - 1;i++) {
		if(solve(0, m[i])) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
void Main(){
    string S;cin>>S;
    int ans=0;
    int k=0;
    For(i,0,S.size()){
        char b=S.at(i);
        if(b=='A') k++;
        else if(b=='T') k++;
        else if(b=='G') k++;
        else if(b=='C') k++;
        else{
            ans=max(ans,k);
            k=0;
        }
    }
    ans=max(ans,k);
    cout<<ans<<endl;
    return ;
}
int main(){
    Main();
    return 0;
}

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

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

    int rate[8];
    for (int i = 0; i < 8; i++)
    {
        rate[i] = 0;
    }

    int up = 0;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        if (a >= 3200) up++;
        else rate[a/400]++;
    }
    int ans1 = 0;
    for (int i = 0; i < 8; i++) {
        if (rate[i] > 0) ans1++;
    }
    int ans2 = ans1;
    if (up > 0) ans2 += up;
    if (ans1==0) ans1++;
    cout << ans1 << " " << ans2 << endl;

  return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int c;
    rep(i,k){
        if(i%2==0){
            if(a%2==1)a--;
            a/=2;
            b+=a;
        }else{
            if(b%2==1)b--;
            b/=2;
            a+=b;
        }
    }
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
n, T = map(int, input().split())
cand = []
for i in range(n):
    c, t = map(int, input().split())
    if t <= T:
        cand.append(c)

if len(cand) > 0:
    cand.sort()
    print(cand[0])
else:
    print('TLE')


Measured memory_bytes: 3060
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	boolean[][] f;
	int w, h;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			w = sc.nextInt();
			h = sc.nextInt();
			if( (w|h) == 0 ) break;
			
			int n = sc.nextInt();
			
			HashSet<Integer> setx = new HashSet<Integer>();
			HashSet<Integer> sety = new HashSet<Integer>();
			int[] x = new int[2*n];
			int[] y = new int[2*n];
			for(int i=0;i<2*n;i++) {
				x[i] = sc.nextInt();
				y[i] = sc.nextInt();
				setx.add(x[i]);
				sety.add(y[i]);
			}
			setx.add(0);
			setx.add(w);
			sety.add(0);
			sety.add(h);
				
			h = sety.size();
			w = setx.size();
			
			int[] ax = new int[w];
			int[] ay = new int[h];
			int c=0;
			for(int val: setx) ax[c++] = val;
			c = 0;
			for(int val: sety) ay[c++] = val;
			sort(ax);
			sort(ay);
			setx.clear();
			sety.clear();
			
//			debug(ax);
//			debug(ay);
//			debug(w,h);
			for(int i=0;i<2*n;i++)  {
				x[i] = binalysearch(ax, x[i]);
				
			}
			for(int i=0;i<2*n;i++) {
				y[i] = binalysearch(ay, y[i]);
			}
			ax = new int[]{};
			ay = new int[]{};
			
			f = new boolean[h-1][w-1];
	//		debug(h, w);
//			debug(x);
//			debug(y);
			for(int i=0;i<n;i++) {
				for(int xx=x[2*i];xx<x[2*i+1];xx++) for(int yy=y[2*i];yy<y[2*i+1];yy++)
					f[yy][xx] = true;
			}
//			for(boolean[] a: f) debug(a);
			int cnt = 0;
			for(int i=0;i<h-1;i++) for(int j=0;j<w-1;j++) {
	//			debug(f[i][j]);
				if(bfs(j, i)) cnt++;
			}
			System.out.println(cnt);
		}
	}
	
	int binalysearch(int[] a, int x) {
		int l = 0, r = a.length-1;
		while(l<=r) {
			int c = (l+r)/2;
//			debug(l,r,c);
			if(a[c] > x) r = c-1;
			else if(a[c] < x) l=c+1;
			else {
				l = c;
				break;
			}
		}
		return l;
	}
	
	int dx[] = {-1,0,1,0};
	int dy[] = {0,-1,0,1};
	
	boolean bfs(int x, int y) {
//		debug(x,w,y,h);
		if( x<0 || x>=w-1 || y<0 || y>=h-1 ) return false;
//		debug("a");
		if(f[y][x]) return false;
		
		f[y][x] = true;
		LinkedList<Integer> xque = new LinkedList<Integer>();
		LinkedList<Integer> yque = new LinkedList<Integer>();
		xque.add(x);
		yque.add(y);
		while(!xque.isEmpty()) {
			int px = xque.removeFirst();
			int py = yque.removeFirst();
			for(int i=0;i<4;i++) if( !( px+dx[i]<0 || px+dx[i]>=w-1 || py+dy[i]<0 || py+dy[i]>=h-1 )
									&& !f[py+dy[i]][px+dx[i]]){
				f[py+dy[i]][px+dx[i]] = true;
				xque.addLast(px+dx[i]);
				yque.addLast(py+dy[i]);
			}
		}
		
		return true;
	}
	

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 13000
N=int(input())
xy=[list(map(int,input().split()))for _ in range(N)]

count=[]
for x1,y1 in xy:
    for x2,y2 in xy:
        if x1==x2 and y1==y2:
            continue
        c=str(x1-x2)+':'+str(y1-y2)
        count.append(c)

from collections import*
C=Counter(count)
C['zentsu999']=0
print(N-max(C.values()))

Measured memory_bytes: 9664
import math
def myAnswer(N:int,M:int) -> int:
   if(abs(N - M) >= 2): return 0
   ans = 0
   if(abs(N - M) == 1):
      ans = math.factorial(N) * math.factorial(M)
   else:
      ans = math.factorial(N) ** 2 * 2

   return ans % (10**9 + 7)

def modelAnswer():
   return
def main():
   N,M = map(int,input().split())
   print(myAnswer(N,M))
if __name__ == '__main__':
   main()

Measured memory_bytes: 5164
n = int(input())

def Checker(sum, x):
    sum =  0
    while x > 0:
        sum += x % 10
        x = x // 10
    return sum

sum_list = []
for a in range(1, n):
    b = n - a
    sum_a = 0
    sum_b = 0
    
    y = Checker(sum_a, a)+ Checker(sum_b, b)
    sum_list.append(y)

print(min(sum_list))

Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  string str;
  cin >> str;
  str.erase(str.begin()+(str.length()-1));
  while(true)
  {
    // cout << str << endl;
    int flag=0;
    int flag2=0;
    if(str.length()%2==0){
      int k = str.length()/2;
      int c=0;
      for(int i=0;i<k;i++)
      {
        if(str[i]==str[k+i])
          c++;
      }
      if(c==k)
        flag=1;
      else{
        flag=0;
        str.erase(str.begin()+(str.length()-1));
      }
      flag2=1;
    }
    else{
      str.erase(str.begin()+(str.length()-1));
    }
    if(flag==1 && flag2==1)
    {
      cout << str.length() << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    string s; cin >> s;
    int n = s.length();
    int ans = 999999;
    REP(i, n-2){
        int num = (s[i]-'0')*100 + (s[i+1]-'0')*10 + s[i+2]-'0';
        ans = min(ans, abs(num-753));
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
const int MAXN=1e9+10;
const int MAX=200000+10;

struct EDGE{
    int v,w,next;
}edge[MAX*2];           //链式向前星
int first[MAX],num;
typedef pair<int,int>P;             //stl储存
int dis[MAX];
int n,m;
void init(){
    fill(dis,dis+MAX,inf);          //memset只能初始化-1，0，1
    memset(first,-1,sizeof(first));
    num=0;
}
void addedge(int u,int v,int w){
    edge[num].v=v;
    edge[num].w=w;
    edge[num].next=first[u];
    first[u]=num++;
}
void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P> >q;   //从小到大
    dis[s]=0;
    q.push(P(0,s));
    while(!q.empty()){
        P t=q.top();
        q.pop();
        int u=t.second;
        if(dis[u]<t.first)
            continue;
        for(int i=first[u];i!=-1;i=edge[i].next){
            int v=edge[i].v;
            int w=edge[i].w;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                q.push(P(dis[v],v));
            }
        }
    }
}

int main(){
    #ifdef ONLINE_JUDGE
    #else
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    #endif
    cin>>n>>m;
    init();
    for(int i=1;i<=m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        addedge(u,v,1);
    }
    dijkstra(1);
    if(dis[n]>2)
        cout<<"IMPOSSIBLE"<<endl;
    else
        cout<<"POSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 5496
#include <iostream>

using namespace std;

typedef long long ll;

ll gcd2(ll a,ll b){
	while(b!=0){
		ll w=a%b;
		a=b;
		b=w;
	}
	return a;
}

int main(){
	int n,a[3],c;
	cin>>n;
	for(int i=0;i<n;++i) cin>>a[i];
	c=a[0];
	for(int i=0;i<n-1;++i)c=gcd2(c,a[i]);
	for(int i=1;i<=c;++i){
		bool f=false;
		for(int j=0;j<n;++j)if(a[j]%i!=0)f=true;
		if(!f)cout<<i<<endl;
	}
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int bfs(int &h, int &w, vector<string> &grid, int &i, int &j) {
  vector<vector<int>> bfsvis(h, vector<int>(w, 0));
  queue<vector<int>> bfstask;
  bfstask.push({i, j});
  bfsvis.at(i).at(j) = 1;
  int cnt = 0;
  while (bfstask.size() > 0) {
    int sz = bfstask.size();
    for (int i = 0; i < sz; i++) {
      int x = bfstask.front().at(0), y = bfstask.front().at(1);
      if (x + 1 < h && bfsvis.at(x + 1).at(y) == 0
          && grid.at(x + 1).at(y) == '.') {
        bfstask.push({x + 1, y});
        bfsvis.at(x + 1).at(y) = 1;
      }
      if (x - 1 >= 0 && bfsvis.at(x - 1).at(y) == 0
          && grid.at(x - 1).at(y) == '.') {
        bfstask.push({x - 1, y});
        bfsvis.at(x - 1).at(y) = 1;
      }
      if (y + 1 < w && bfsvis.at(x).at(y + 1) == 0
          && grid.at(x).at(y + 1) == '.') {
        bfstask.push({x, y + 1});
        bfsvis.at(x).at(y + 1) = 1;
      }
      if (y - 1 >= 0 && bfsvis.at(x).at(y - 1) == 0
          && grid.at(x).at(y - 1) == '.') {
        bfstask.push({x, y - 1});
        bfsvis.at(x).at(y - 1) = 1;
      }
      bfstask.pop();
    }
    cnt++;
  }
  return cnt;
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; i++) cin >> grid.at(i);
  priority_queue<int> ans;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grid.at(i).at(j) == '#') continue;
      ans.push(bfs(h, w, grid, i, j));
    }
  }
  cout << ans.top() - 1 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int selectionSort(int a[], int n){
    int i, j, p, minj;
    int count=0;
    for(i=0;i<n;i++){
        minj=i;
        for(j=i;j<n;j++){
            if(a[j]<a[minj]){
                minj=j;
            }
        }
        if(minj != i){
            p=a[i];
            a[i]=a[minj];
            a[minj]=p;
            count++;
        }
    }
    return count;
}

int main(){
    int n,i,date[1000];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&date[i]);
    }
    int count=selectionSort(date,n);
    
    for(i=0;i<n-1;i++){
        printf("%d ",date[i]);
    }
    printf("%d\n%d\n",date[n-1],count);
    return 0;
}


Measured memory_bytes: 2116
import itertools
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# int で bitset をします
# https://twitter.com/armeria_betrue/status/1203681298826452993

H, W = list(map(int, sys.stdin.buffer.readline().split()))
A = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(H)]
B = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(H)]

A = np.array(A, dtype=int)
B = np.array(B, dtype=int)
grid = np.abs(A - B).tolist()

dp = [[0] * W for _ in range(H)]
# 下から n ビットめが 1 ならそこまでで絶対値 n を作れる
dp[0][0] = 1 << (grid[0][0] + (80 * 40 * 40))
for h, w in itertools.product(range(H), range(W)):
    g = grid[h][w]
    if h - 1 >= 0:
        dp[h][w] |= dp[h - 1][w] << grid[h][w]
        dp[h][w] |= dp[h - 1][w] >> grid[h][w]
    if w - 1 >= 0:
        dp[h][w] |= dp[h][w - 1] << grid[h][w]
        dp[h][w] |= dp[h][w - 1] >> grid[h][w]

i = 0
n = dp[-1][-1] >> (80 * 40 * 40)
while True:
    if n & 1:
        print(i)
        break
    n >>= 1
    i += 1


Measured memory_bytes: 125924
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(long i=(a);i<(b);i++)
#define dfor(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second


int main() {
	long n,c=1;
	string s;
	cin>>n>>s;
	FOR(i,1,n){
		if(s[i]==s[i-1]) continue;
		c++;
	}
	cout<<c;
	
}

Measured memory_bytes: 512
def main():
    n = int(input())
    arr = list(map(int,input().split()))
    if arr[0] != 0:
        print(0)
        return
    
    mod = 998244353
    dist = {}
    arr1 = []
    for i in arr:
        if i not in dist.keys():
            dist[i] = 1
            arr1.append(i)
        else:
            dist[i] += 1

    if dist[0] > 1:
        print(0)
        return

    arr1.sort()
    ways = 1
    for i in range(1,len(arr1)):
        ways *= pow(dist[arr1[i-1]],dist[arr1[i]],mod)
        ways = ways%mod
        if arr1[i] - arr1[i-1] != 1:
            print(0)
            return

    print(ways)
         

main()


Measured memory_bytes: 18676
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

typedef long long ll;
ll a,b,c,k;

int main(){
	cin>>a>>b>>c>>k;
	if(k&1)
		cout<<b-a<<endl;
	else
		cout<<a-b<<endl;
	return 0;
}

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

int main(){
  int N, a;
  a = 0;
  cin >> N;
  vector<int> v(N);
  vector<int> w(N);
  for(int i = 0;i < N ; i++){
    cin >> v.at(i);
    cin >> w.at(i);
  }
  for(int i = 0;i < N ; i++){
    if (v.at(i) == w.at(i)){
      a++;
    }
    if (v.at(i) != w.at(i)){
      a = 0;
    }
    if (a == 3){
      break;
    }
  }
  if (a == 3){
    cout << "Yes" << endl;
    }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=(2e5)+5;
int n,a[maxn],cnt[21];
ll ans;
int main() {
//	freopen("1.txt","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int pos=0;
	for (int i=1;i<=n;i++) {
		if (pos<i) {
			pos=i; memset(cnt,0,sizeof(cnt));
			for (int j=0;j<=20;j++)
				if ((a[i]>>j)&1) cnt[j]++;
		}
		while (pos<n) {
			bool flag=1;
			for (int j=0;j<=20;j++)
				if (((a[pos+1]>>j)&1)&&cnt[j]) {
					flag=0; break;
				}
			if (!flag) break;
			pos++;
			for (int j=0;j<=20;j++)
				if ((a[pos]>>j)&1) cnt[j]++;
		}
		ans+=pos-i+1;
		//printf("%d %d\n",i,pos);
		for (int j=0;j<=20;j++)
			if ((a[i]>>j)&1) cnt[j]--;
	}
	printf("%lld\n",ans);
	return 0;
}

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

const ll INF = 1ll<<60;

typedef pair<ll,ll> P;

int main() {
  ll n, x, d;
  cin >> n >> x >> d;

  if (d == 0) {
    if (x == 0) {
      cout << 1 << endl;
    } else {
      cout << n+1 << endl;
    }
    return 0;
  }

  map<int,vector<P>> mp;
  rep(i,n+1) {
    ll s = x*i;
    ll l = (ll)i*(i-1)/2;
    ll r = l + (ll)i*(n-i);
    s += l*d;
    r -= l;
    mp[(s+(d<<30))%d].emplace_back(s,r);
  }

  ll ans = 0;
  for (auto p : mp) {
    auto a = p.second;
    int m = a.size();
    rep(i,m) a[i].first = (a[i].first-p.first)/d;
    vector<P> ev;
    rep(i,m) {
      ev.emplace_back(a[i].first, 1);
      ev.emplace_back(a[i].first+a[i].second+1, -1);
    }
    sort(ev.begin(), ev.end());
    ll cnt = 0, pre = -INF;
    for (auto e : ev) {
      ll len = e.first-pre;
      if (cnt) ans += len;
      cnt += e.second;
      pre = e.first;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 22144
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;
  vector<vector<int>> d(N, vector<int>(N));
  vector<vector<bool>> vs(N, vector<bool>(N));
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      d[i][j] = min({i, N - 1 - i, j, N - 1 - j}) + 1;
  vector<int> dx = {0, 0, -1, 1}, dy = {1, -1, 0, 0};
  int ans = 0;
  for (int rep = 0; rep < N * N; ++rep) {
    int id;
    cin >> id;
    --id;
    int x = id / N, y = id % N;
    ans += --d[x][y];
    vs[x][y] = true;
    queue<pair<int, int>> q;
    q.emplace(x, y);
    while (!q.empty()) {
      tie(x, y) = q.front(); q.pop();
      for (int dir = 0; dir < 4; ++dir) {
        int gx = x + dx[dir], gy = y + dy[dir];
        if (gx >= 0 && gx < N && gy >= 0 && gy < N && d[gx][gy] > d[x][y] + !vs[gx][gy]) {
          d[gx][gy] = d[x][y] + !vs[gx][gy];
          q.emplace(gx, gy);
        }
      }
    }

  }
  cout << ans;

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 4656
import sys
input = sys.stdin.readline

n = int(input())
C = []
S = []
F = []
for _ in range(n-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(n-1):
    t = 0
    for j in range(i, n-1):
        c = C[j]
        s = S[j]
        f = F[j]

        t = max(t, s)
        if t % f:
            t += f - (t % f)
        t += c
    print(t)
print(0)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

typedef int64_t ll;


vector<vector<char>> fi;
set<int> row;
int n;

int solve()
{
	if(row.size() == 0)
		return -1;
	int ancount = INF;
	for(int i = 0; i < n; ++i)
	{
		int count = 0;
		if(row.count(i) == 0)
			count++;
		for(int j = 0; j < n; ++j)
		{
			if(fi[i][j] == '.')
			{
				count++;
			}
		}
		/* cerr <<  i << ',' <<  count << '\n'; */
		ancount = min(count, ancount);
	}
	if(ancount >= INF)
		return -1;
	for(int j = 0; j < n; j++)
	{
		bool needles = true;
		for(int i = 0; i < n; ++i)
		{
			if(fi[i][j] == '.')
			{
				needles = false;
				break;
			}
		}
		if(!needles)
			ancount++;
	}
	return ancount;
}


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

	/* do{ */
	cin >> n;
	/* fi = {}; */
	/* row = {}; */
	/* colum = {}; */
	for(int i = 0; i < n; ++i)
	{
		fi.push_back(vector<char>());
		for(int j = 0; j < n; ++j){
			char tmp;
			cin >> tmp;
			fi[i].push_back(tmp);
			if(tmp == '#')
			{
				row.insert(j);
			}
		}
	}
	/* for(auto t : row) */
	/* { */
	/* 	cout << t << '\n'; */
	/* } */
	/* for(auto k : colum) */
	/* 	cout << k << '\n'; */

	cout << solve() << endl;
	/* }while(cin); */

}



Measured memory_bytes: 512
<?php
$input_line = explode(' ', fgets(STDIN));

$d = $input_line[0];//距離
$t = $input_line[1];//待ち合わせ時刻までの時間
$s = $input_line[2];//速さ

$result = $d / $s;//かかる時間

if ($result <= $t) {
	echo 'Yes';
} else {
	echo 'No';
}

  ?>

Measured memory_bytes: 16248
#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <list>
#include <climits>
#include <bitset>
#include <fstream>
#include <algorithm>
#include <functional>
#include <stack>
#include <string>
#include <cmath>
#define fi first
#define se second
#define re register
#define ls i << 1
#define rs i << 1 | 1
#define pb push_back
#define pii pair<int,int>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007

#define int long long

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
int tt;
inline int rd(){
  int x = 0, f = 1; char ch = getchar();
  while (ch < '0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
  while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
  return x * f;
}

void out(int a) {
  if (a < 0) putchar('-'), a = -a;
  if (a >= 10) out(a / 10);
  putchar(a % 10 + '0');
}

const int maxn = 2e5+10;
int fa[maxn],a[maxn],b[maxn];
int num[maxn];
int get(int x) {
  return fa[x] == x ? x : fa[x] = get(fa[x]);
}
void merge(int x,int y) {
  x = get(x), y = get(y);
  fa[x] = y;
}
void solve() {
  int n = rd(), m = rd();
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    a[i] = rd(), b[i] = rd();
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) merge(a[i],b[i]);
  for (int i = 1; i <= n; i++) {
    int now = get(i);
    num[now]++;
    ans = max(ans, num[now]);
  }
  cout << ans << '\n';
}

signed main(){
//  for (tt = rd(); tt--; )
  solve();
  return 0;
}

Measured memory_bytes: 14452