akhauriyash/Code-Regression huggingface dataset:
# atcoder DP 動的計画法
# H Grid 1

WALL = -1
ROAD = 0

# 問題文の入力を受け取る
def get_inputs():
    # 迷路の横幅Wと高さHを受け取る
    H, W = map(int, input().split())

    # 迷路の地図情報を受け取る
    # .：通路 int 0に変換
    # #：壁 int -1に変換
    maze = []
    for _ in range(H):
        maze.append([ROAD if c == "." else WALL for c in input()])
    
    return H, W, maze

H, W, maze = get_inputs()

# mazeを動的計画法のテーブルとして扱う
# 左上隅から探索し、行く先(右もしくは下）が迷路の範囲内であり、かつ通路であれば、経路数を加算する
# 配るdpの考え方でテーブル作成

maze[0][0] = 1
for j in range(H):
    for i in range(W):
        if maze[j][i] != WALL:
            if 0 <= i + 1 < W and 0 <= j < H and maze[j][i + 1] != WALL:
                maze[j][i + 1] += maze[j][i]
            if 0 <= i < W and 0 <= j + 1 < H and maze[j + 1][i] != WALL:
                maze[j + 1][i] += maze[j][i]

print(maze[H - 1][W - 1] % (10 ** 9 + 7))
                          
    

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

N = INT()
ABC = [LIST() for _ in range(N-1)]
Q, K = MAP()
xy = [LIST() for _ in range(Q)]

connection = [[] for _ in range(N)]

for i in range(N-1):
	connection[ABC[i][0]-1].append((ABC[i][1]-1, ABC[i][2]))
	connection[ABC[i][1]-1].append((ABC[i][0]-1, ABC[i][2]))

#print(connection)

step = [-1]*N
step[K-1] = 0

q = deque([K-1])


while q:
	N = q.popleft()
	for x, C in connection[N]:
		#print(x, C)
		if step[x] == -1:
			step[x] = step[N] + C
			#print(step)
			q.append(x)


#print(step)

for x, y in xy:
	print(step[x-1] + step[y-1])






Measured memory_bytes: 89624
#include<bits/stdc++.h>
using namespace std;
int n,Lp[2010],Rp[2010],Mis[2010],buc[2010],tmpMis[2010],mn=0x3f3f3f3f,Suf[2010];
char tms[2010];
bool a[2010],b[2010],s1,s2;
void Sort(){//use a bucket sort to let the complexity of sorting become O(n)
    for(int i=0;i<=n;i++)buc[i]=0;
    for(int i=1;i<=Mis[0];i++)buc[Rp[Mis[i]]+1]++;
    for(int i=1;i<=n;i++)buc[i]+=buc[i-1];
    for(int i=1;i<=Mis[0];i++)tmpMis[++buc[Rp[Mis[i]]]]=Mis[i];
    for(int i=1;i<=Mis[0];i++)Mis[i]=tmpMis[i];
}
int main(){
    scanf("%s",tms),n=strlen(tms);
    for(int i=0;i<n;i++)a[i]=tms[i]-'0';
    scanf("%s",tms);
    for(int i=0;i<n;i++)b[i]=tms[i]-'0';
    memset(Lp,0x3f3f3f3f,sizeof(Lp)),memset(Rp,0x3f3f3f3f,sizeof(Rp));
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(b[j])Lp[i]=min(Lp[i],(i-j+n)%n),Rp[i]=min(Rp[i],(j-i+n)%n);
    for(int i=0;i<n;i++)s1|=a[i],s2|=b[i];//check if there's no '1' in array b. If so, only if there's no '1' in array a, it is unable to get a proper answer.
    if(!s2){
        if(!s1)puts("0");
        else puts("-1");
        return 0;
    }
    for(int i=0;i<n;i++){//numerate the end position of a_i
        Mis[0]=0;
        for(int j=0,k=i;j<n;j++,k++,k%=n)if(a[k]!=b[j])Mis[++Mis[0]]=k;//find the mismatched positions
        Sort();
        Suf[Mis[0]+1]=0;
        for(int j=Mis[0];j;j--)Suf[j]=max(Suf[j+1],Lp[Mis[j]]);//suffix maximum
        mn=min(mn,max(i,Suf[1])*2-i+Mis[0]);//only go left/right situations
        mn=min(mn,(Suf[1]+(n-i)%n)*2-(n-i)%n+Mis[0]);
        for(int j=1;j<=Mis[0];j++){
            mn=min(mn,(Rp[Mis[j]]+max(i,Suf[j+1]))*2-i+Mis[0]);
            mn=min(mn,(Suf[j+1]+max((n-i)%n,Rp[Mis[j]]))*2-(n-i)%n+Mis[0]);
        }
    }
    printf("%d\n",mn);
    return 0;
}

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

long long W, weight[110], value[110];

long long dp[110][100100] ={0};


int main() {
	cin >> N >> W;
	rep (i, N) {
		cin >> weight[i] >> value[i];
	}

	for (int i = 0; i < N; i++) {
		for (int sum_w = 0; sum_w <= W; sum_w++) {
			if (sum_w - weight[i] >= 0) {
				dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
			}
			dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);
		}
	}
	cout << dp[N][W] << endl;

	return 0;
}

Measured memory_bytes: 79360
s=input()
t=input()
strs=[]
S=len(s)
T=len(t)
for i in range(S-T+1):
  flag=0
  for j in range(T):
    if s[i+j]=="?":
      continue
    if s[i+j]!=t[j]:
      flag=1;break
  if flag==0:
    posstr=s[:i]+t+s[i+T:]
    strs.append(posstr.replace("?","a",50))
strs.sort()
if strs==[]:print("UNRESTORABLE")
else:print(strs[0])

Measured memory_bytes: 3064
#include<stdio.h>
int gcd(int a, int b);
int main(void)
{
	int n, a, b;
	scanf("%d", &n);
	scanf("%d", &a);
	for(int i = 1; i < n; i++)
	{
		scanf("%d", &b);
		a = gcd(a, b);
	}
	printf("%d", a);
}
int gcd(int a, int b)
{
	if(b == 0)
		return a;
	return gcd(b, a%b);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  ll n, m;
  cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  int d[n + 1];
  // fi(0, m + 1)
  //   d[i] = -1;
  negative(d);
  // memset(d, -1, sizeof(d));
  // zero(d);
  fi(0, m) {
    int a, b;
    cin >> a >> b;
    // cout << a << "," << d[a] << endl;
    // cout << (d[a] != -1 && d[a] != b) << endl;
    if((d[a] != -1 && d[a] != b) || (n > 1 && a == 1 && b == 0) || a > n) {
      cout << "-1\n";
      return 0;
    }
    d[a] = b;
  }
  // fi(0, n+ 1)
  //   cout << d[i] << " ";
  // cout << endl;
  // string s(n);
  char s[n + 1];
  memset(s, '0', sizeof(s));
  s[n] = '\0';
  if(n > 1)
    s[0] = '1';
  fi(1, n + 1) {
    // cout << d[i] << endl;
    if(d[i] != -1)
      s[i - 1] = '0' + d[i];
  }
  cout << s << endl;
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(x) cerr<<#x": "<<(x)<<endl
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

int main()
{
	ios_base::sync_with_stdio(false);
  
  string s;
  cin >> s;
  if(s == "Sunny") cout << "Cloudy\n";
  else if(s == "Rainy") cout << "Sunny\n";
  else cout << "Rainy\n";
	
	return 0;
}


Measured memory_bytes: 256
mod = 1000000007
    
S = list(input())

n = len(S)

dp = [[0]*13 for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    s = S[i]
    for j in range(13):
        if s == '?':
            for k in range(10):
                dp[i+1][(j*10+k)%13] += dp[i][j]
        else:
            dp[i+1][(j*10+int(s))%13] += dp[i][j]
        dp[i+1][j] %= mod
print(dp[n][5]%mod)

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

int main(){

	int a, b;
	cin >> a >> b;
	

	
	if (a > b){ cout << "a > b" << endl; }
	else if (a < b){ cout << "a < b" << endl; }
	else{cout<<"a == b"<<endl; }
	
	



	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
char s[4];
int main() {
    int ans=0;
    scanf("%s", s);
    for (int i = 0; s[i]; ++i) if (s[i] == '1') ++ans;
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; -i)
#define INF (1 << 30)

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

int main() {
	int a, b, h;
	scanf("%d %d %d", &a, &b, &h);
	printf("%d\n", (a + b) * h / 2);
	return 0;
}

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

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
#ifdef DEBUG
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; return o; }
#ifdef USE_COUT
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#else
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#endif
template<class T> inline void dump2D(T &d, size_t sizey, size_t sizex) { ostream&o=
#ifdef USE_COUT
  cout;
#else
  cerr;
#endif
  for(size_t i = 0; i < sizey; i++) { for(size_t j = 0; j < sizex; j++) o << d[i][j] << " "; o << endl; }
}
#else
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); return o; }
#define dump(...) (42)
#define dump2D(...) (42)
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
/// }}}--- ///


int sol() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for(auto &e:v)cin >> e, e/=10;
  int cango = 0;
  int now = 0;
  while(now < n && now <= cango) {
    cango = max(cango, now + v[now]);
    now++;
  }
  // dump(
  if(cango < n - 1) return 0;
  now = n -1;
  cango = n-1;
  while(now >= 0 && now >= cango) {
    cango = min(cango, now - v[now]);
    now--;
  }
  if(cango > 0) return 0;
  return 1;
}

#define POS(x) cout<<((x)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define Pos(x) cout<<((x)?"Possible":"Impossible")<<endl;
#define YES(x) cout<<((x)?"YES":"NO")<<endl;
#define Yes(x) cout<<((x)?"Yes":"No")<<endl;
#define yes(x) cout<<((x)?"yes":"no")<<endl;

int main() {
  yes(sol());
}




Measured memory_bytes: 4128
import math
n,h = map(int, input().split())
a = []
b = []
for i in range(n):
  a1,b1 = map(int, input().split())
  a.append(a1)
  b.append(b1)
b.sort()
max_a = max(a)
ans = 0
for i in b[::-1]:
  if i > max_a:
    h -= i
    ans += 1
  else:
    break
  if h <= 0:
    print(ans)
    exit()
ans += math.ceil(h/max_a)
print(ans)


Measured memory_bytes: 11860
x, n = map(int, input().split())
P = list(map(int, input().split()))

A = [1] * 102
for p in P:
    A[p] = 0

tmp = float("inf")
for i in range(102):
    if A[i]:
        if abs(x - i) < tmp:
            tmp = abs(x - i)
            ans = i

print(ans)


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

using namespace std;

int64_t gcd(int64_t a, int64_t b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

void solve(){
  int64_t a,b;
  cin>>a>>b;
  cout << a*b/gcd(a,b);

}


int main(){
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);

  double a, b, x, ang = 0;
  cin >> a >> b >> x;

  x /= a;
  if (a * b > 2 * x)
    ang = 90 - 180 * atan2(2 * x, b * b) / PI;
  else  ang = 180 * atan2(2 * (a * b - x), a * a) / PI;

  cout << ang << '\n';
}

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

#define vl vector<ll>
#define vs vector<string>
#define vll vector< vector<ll> >
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define tll tuple<ll, ll, ll>
#define vp vector< pair<ll,ll> >
#define vt vector< tuple<ll, ll, ll> >
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
#define NN 2020202

//command
//c++ atcoder.cpp -std=c++14
//./a.out

//cout << setprecision(12) << ans << endl;

int main(){
  ll N, K;
  cin >> N >> K;
 
  ll S[N+1];
  S[0] = 0;
  ll sum = 0;
  ll a, tmp;
  for (int i=1;i<=N;i++){
    cin >> a;
    sum += a;
    S[i] = (sum - i)%K;
  }
  //for (int i=0;i<=N;i++) cout << S[i] << " ";
  //cout << endl;
  
  map<ll, ll> m;
  ll start = 0;
  ll end = 0;
  ll ans = 0;
  m[0] = 1;
  for (int i=1;i<=N;i++){
    end += 1;
    if (m.count(S[end]) == 0) m[S[end]] = 1;
    else m[S[end]] += 1;

    if (end >= K){
      m[S[start]] -= 1;
      start += 1;
    }

    ans += (m[S[end]]-1);
    //cout << start << " " << end << " " << m[S[end]] << " " << ans << endl;
  }
 
  cout << ans << endl;
}

Measured memory_bytes: 14336
import java.util.Scanner;

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

		int x = sc.nextInt();
		int ans = 1;

		for (int b = 1; b <= x; b++) {
			for (int p = 2; p < 1000; p++) {
				int pow = (int)Math.pow(b, p);
				if (pow <= x)
					if (ans < pow) ans = pow;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22868
N,W,H=map(int,raw_input().split())
W=W*2+1
H=H*2+1
wa=[0]*(W+1)
ha=[0]*(H+1)
for _ in xrange(N):
    x,y,w=map(int,raw_input().split())
    wa[max((x-w)*2,0)]+=1
    if (x+w+1)*2<=W: wa[(x+w+1)*2-1]-=1
    ha[max((y-w)*2,0)]+=1
    if (y+w+1)*2<=H: ha[(y+w+1)*2-1]-=1
for i in xrange(W): wa[i+1]+=wa[i]
for i in xrange(H): ha[i+1]+=ha[i]
if 0 in wa[:W] and 0 in ha[:H]:
    print "No"
else:
    print "Yes"

Measured memory_bytes: 20648
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

int main() {
    int N, D, X; cin >> N >> D >> X;
    vector<int> A(N); for (int i = 0; i < N; ++ i) cin >> A[i];
    long long ret = X;
    for (int i = 0; i < N; i++) {
        int d = 0;
        int j = 0;
        while (true) {
            d = 1 + A[i] * j;
            if (d > D) {
                break;
            }
            ret++;
            j++;
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
N,M,Q=gets.split.map &:to_i
R=Q.times.map{gets.split.map &:to_i}
p (1..M).to_a.repeated_combination(N).map{|s|R.map{|a,b,c,d|c==s[b-1]-s[a-1]?d:0}.inject:+}.max

Measured memory_bytes: 16364
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if (s == t) {
        cout << "No" << endl;
        return 0;
    }
    if (s.size() <= t.size()) {
        for (int i = 0; i < s.size(); i++) {
            if (s[i] < t[i]) {
                cout << "Yes" << endl;
                return 0;
            } else if (s[i] > t[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    } else {
        for (int i = 0; i < t.size(); i++) {
            if (s[i] < t[i]) {
                cout << "Yes" << endl;
                return 0;
            } else if (s[i] > t[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "No" << endl; //tの方が短く、ずっと等しかったら
    }
    return 0;
}


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

#define pb(a) push_back((a))
#define mp(a, b) make_pair((a), (b))
#define REP(a, b) for (ll i = (a); i < (b); i++)
#define REP2(a, b) for (ll j = (a); j < (b); j++)
#define REPE(a, b, c, d) \
	REP(a, b)            \
	for (ll j = (c); j < (d); j++)
#define REPV(a, b, c) for (ll(a) = b; (a) < (c); (a)++)
#define IREP(a, b) for (ll i = (a); i >= (b); i--)
#define IREP2(a, b) for (ll j = (a); j >= (b); j--)
#define IREPV(a, b, c) for (ll(a) = b; (a) >= (c); (a)--)
#define all(v) (v).begin(), (v).end()
#define Trvs(c) for (auto &it : c)
#define INF INT_MAX
#define sz(x) x.size()
#define flash                         \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define F first
#define S second
#define MOD 1000000007

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;

auto cmp = [](pair<ll, pair<ll, ll>> a, pair<ll, pair<ll, ll>> b) {
	if (a.F == b.F)
		return a.S.F > b.S.F;
	return a.F > b.F;
};
//decltype(cmp)
//set<,decltype(cmp)> st(cmp);
void solve()
{
	ll n;
	cin >> n;
	vll a(n);
	REP(0, n)
	{
		cin >> a[i];
		if (a[i] == 0)
		{
			cout << "0";
			return;
		}
	}
	ll ans = 1;
	REP(0, n)
	{
		ll temp = ans;
		ans = ans * a[i];

		if (ans < temp or ans > 1000000000000000000)
		{
			cout << "-1";
			return;
		}
	}
	cout << ans;
}

int main()
{
	flash


	// seive(100000);
	// calculatepi();
	// ll t;
	// cin >> t;
	// while (t--)
	solve();
	return 0;
}

Measured memory_bytes: 3988
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

const MOD: i64 = 1e9 as i64 + 7;

fn compute(a: &Vec<i64>) -> i64 {
    let n = a.len();
    let mut diff = vec![];
    for i in 1..n {
        diff.push((a[i] - a[i-1]) % MOD);
    }

    let mut sum = 0;
    let dn = n-1;
    for i in 0..dn {
        let l = i+1;
        let r = dn-i;
        sum += diff[i] * (l as i64) % MOD * (r as i64) % MOD;
        sum %= MOD;
    }
    sum
}

fn main() {
    let (n, m): (usize, usize) = read();
    let col: Vec<i64> = readnc();
    let row: Vec<i64> = readnc();
    println!("{}", compute(&col) * compute(&row) % MOD);
}


Measured memory_bytes: 11512
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();

		int ay = 0;
		int by = 0;

		for (int i = 0; i < n; i++) {
			if (s.charAt(i) == 'a') {
				if (ay + by < a + b) {
					System.out.println("Yes");
					ay++;
				} else {
					System.out.println("No");
				}
			} else if (s.charAt(i) == 'b') {
				if (ay + by < a + b && by < b) {
					System.out.println("Yes");
					by++;
				} else {
					System.out.println("No");
				}
			} else {
				System.out.println("No");
			}
		}
	}
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int  n, k;
    cin >> n >> k;
    
    cout <<  (int)(k * pow(k-1, n-1)) << endl;

    return 0;
}

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

string s, t;
int a[30], c, d;
bool b[30];

int main(){
  cin >> s >> t;
  for(int i = 0; i < s.size(); i++){
    c = s[i] - 'a' + 1;
    d = t[i] - 'a' + 1;
    if(!a[c] && !b[d]){
      a[c] = d;
      b[d] = true;
    }else if(a[c] != d){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}


Measured memory_bytes: 776
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    if (n % 1000 == 0)
        cout << 0 << endl;
    else
        cout << 1000 - (n % 1000) << endl;
    return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 
 int main(){
  ll n, m, q ;
  cin>>n>>m >>q ;
  int s[n][m] ;
  rep(i,n){
    rep(j,m){
      char a ; cin>> a ;
     s[i][j]= a-'0' ;
    }
   }
  int tate[n-1][m] ;
  rep(i,n-1){
    rep(j,m){
      if(s[i][j]==1&&s[i+1][j]==1) tate[i][j]=1 ;
      else tate[i][j]=0 ;
    }
  }
  int yoko[n][m-1] ;
  rep(i,n){
    rep(j,m-1){
      if(s[i][j]==1&&s[i][j+1]==1) yoko[i][j]=1 ;
      else yoko[i][j]=0 ;
    }
  }

  ll v[n][m] ;
  ll va[n][m] ;
  rep(i,n){
    ll u=i ;
    rep(j,m){
      if(j==0) va[u][j]=s[u][j] ;
      else va[u][j]=va[u][j-1]+s[u][j] ;
    }
  }

  rep(i,n){
    rep(j,m){
      if(i==0) v[i][j]=va[i][j] ;
      else v[i][j]=v[i-1][j]+va[i][j] ;
    }
  }
  
  ll et[n-1][m] ;
  ll etate[n-1][m] ;
  rep(i,n-1){
    ll u=i ;
    rep(j,m){
      if(j==0) etate[u][j]=tate[u][j] ;
      else etate[u][j]=etate[u][j-1]+tate[u][j] ;
    }
  }

  rep(i,n-1){
    rep(j,m){
      if(i==0) et[i][j]=etate[i][j] ;
      else et[i][j]=et[i-1][j]+etate[i][j] ;
    }
  }

  ll ey[n][m-1] ;
  ll eyoko[n][m-1] ;

  rep(i,n){
    ll u=i ;
    rep(j,m-1){
      if(j==0) eyoko[u][j]=yoko[u][j] ; 
      else eyoko[u][j]=eyoko[u][j-1]+yoko[u][j] ;
    }
  }

  rep(i,n){
    rep(j,m-1){
      if(i==0) ey[i][j]=eyoko[i][j] ;
      else ey[i][j]=ey[i-1][j]+eyoko[i][j] ;
      }
  }

  while(q--){
    ll a,b,c,d ; cin>>a>>b>>c>>d ;
   
    a-- ;b-- ;c--;d-- ;
    ll ver =0 ;
    ver= v[c][d] ;
    if(a!=0) ver-=v[a-1][d] ;
    if(b!=0) ver-=v[c][b-1] ;
    if(a!=0&&b!=0) ver+= v[a-1][b-1] ;

    ll edge =0 ;
    ll tata =0 ;
    ll ad=a ;ll cd=c-1 ;
    if(cd>=0) {tata=et[cd][d] ;
    if(ad!=0) tata-=et[ad-1][d];
    if(b!=0) tata-= et[cd][b-1];
    if(ad!=0&&b!=0) tata+= et[ad-1][b-1] ;
    }
    ll yoyo=0 ;
    ll bd=b ; ll dd=d-1 ;
    if(dd>=0) {yoyo=ey[c][dd] ;
    if(a!=0) yoyo-=ey[a-1][dd];
    if(bd!=0) yoyo-= ey[c][bd-1] ;
    if(a!=0&&bd!=0) yoyo+= ey[a-1][bd-1] ;
    }
    edge= yoyo+tata ;
     //cout<<  yoyo <<endl ;

    cout<<  ver-edge <<endl ;

  }


   return 0 ;
 }



Measured memory_bytes: 237948
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int A, B;
	cin >> A >> B;

	if (A >= 10) co(B);
	else co(B + 100 * (10 - A));

	Would you please return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var w = Console.ReadLine();
            var dict = new Dictionary<char, int>();

            for (var i = 0; i < w.Length; i++)
            {
                if (dict.ContainsKey(w[i]))
                    dict[w[i]]++;
                else
                    dict[w[i]] = 1;
            }

            Console.WriteLine(dict.Any(d => d.Value % 2 != 0) ? "No" : "Yes");
        }
    }
}


Measured memory_bytes: 11232
def main():
    days = int(input())
    falliness = [int(x) for x in input().split()]
    satisfactions = [0]  # Never use index 0.
    for _ in range(days):
        satisfactions.append([int(x) for x in input().split()])

    last = [0] * 26
    sat_pre = 0
    for date in range(1, days + 1):
        for typ in range(26):
            if typ == 0:
                # こうしないと，どれを選んでも満足度が下がる場合に対応できない。
                best = (sat_pre, last, typ)
            last_tmp = last[0:]
            sat = sat_pre
            last_tmp[typ] = date
            sat += satisfactions[date][typ]
            sat -= sum(
                falliness[i] * (date - last_tmp[i]) for i in range(26))
            if sat > best[0]:
                best = (sat, last_tmp, typ)
        last = last_tmp[0:]
        sat_pre = sat
        print(best[2] + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9548
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int main()
{
  finp;
 ll a,b;
 cin>>a>>b;

 if(a<=0 && b>=0)cout<<"Zero";
 else if(a>0)cout<<"Positive";
 else if((b-a+1)%2)cout<<"Negative";
 else cout<<"Positive"; 
return 0;
}

Measured memory_bytes: 256
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in a:
  SUM = c
  for j,k in zip(i,b):
    SUM += j*k
  if SUM > 0:
    ans += 1
print(ans)

Measured memory_bytes: 3060
import math
R,G,B,N = map(int,input().split())
cnt = 0
for i in range(math.ceil(N/G)+1):
	for j in range(math.ceil(N/R)+1):
			tmp = N - i * G - j * R
			if  tmp >=0 and tmp % B == 0:
				cnt += 1
print(cnt)

Measured memory_bytes: 40940
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;

vector<ll> f(ll n){
  vector<ll> c(n+1);
  c[0] = 1;
  rep(i,n) c[i+1] = c[i]*(n-i)/(i+1); 
  return c;
}
int main() {
  int n,a,b;
  cin >> n >> a >> b;
  vector<ld> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(),v.end());
  ld s = 0;
  rep(i,a) s += v[n-1-i];
  s /= a;
  ll ans = 0;
  if(v[n-1]==v[n-a]){
    int i = lower_bound(v.begin(),v.end(),v[n-a]) - v.begin();
    vector<ll> c = f(n-i);
    for(int k=a; k<=min(n-i,b); ++k) ans += c[k];
  }else{
    int l = lower_bound(v.begin(),v.end(),v[n-a]) - v.begin();
    int r = upper_bound(v.begin(),v.end(),v[n-a]) - v.begin();
    vector<ll> c = f(r-l);
    ans += c[a-(n-r)];
  }
  printf("%.10Lf\n%lld\n",s,ans);
}

Measured memory_bytes: 384
# import sys
# input = sys.stdin.readline
import itertools


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    n, k = input_list()
    a = input_list()
    kitais = [0]
    for i in range(n):
        kitai = (a[i]+1)/2
        kitais.append(kitais[i] + kitai)
    ans = 0
    for i in range(n-k+1):
        ans = max(ans, kitais[i+k] - kitais[i])
    print(ans)

def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 100656
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = float('inf')
index = float('inf')
for i in range(n - 1):
    now = abs(a[-1] / 2 - a[i])
    if ans > now:
        ans = now
        index = i
print(a[-1], a[index])

Measured memory_bytes: 14052
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n,m = map(int, readline().split())
  p = [0]*m
  s = ['']*m
  count = [0]*n
  AC = [0]*n
  for i in range(m):
    tmp, s[i] = input().split()
    p[i] = int(tmp)
  for i in range(m):
    if AC[p[i]-1]==0:
      if s[i]=='WA':
        count[p[i]-1] += 1
      else:
        AC[p[i]-1] = 1
  penalty = 0
  for i in range(n):
    if AC[i]==1:
      penalty += count[i]
  print('{} {}'.format(sum(AC),penalty))
  
  
  
if __name__ == '__main__':
  main()

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;

const ll MOD = 998244353, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

map <ll, ll> mp ;

int main()
{
    ll n, k, v, c, ans = 0 ;
    cin >> n >> k ;
    for (int i = 0; i < k; i++) {
        scanf("%lld", &v) ;
        for (int j = 0; j < v; j++) {
            scanf("%lld", &c) ;
            mp[c]++ ;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (mp[i] == 0) ans++ ;
    }
    cout << ans ;

    return 0 ;
}


Measured memory_bytes: 3772
#include <stdio.h>

int main(void){
  int mou[10];
  int i,j;
  int temp;
  int mou1[10];
  int n = 0;
  
  for(i = 0;i < 10; i++){
    scanf("%d" ,&mou[i]);
    n++;
  }
  
  for(i = 0;i < n;i++){
    for(j = i + 1;j < n;j++){
      if(mou[j] < mou[i]){
  temp = mou[j];
  mou[j] = mou[i];
  mou[i] = temp;
      }
    }
  }
  

  printf("%d\n" ,mou[n - 1]);
  printf("%d\n" ,mou[n - 2]);
  printf("%d\n" ,mou[n - 3]);


    return 0;
  }

Measured memory_bytes: 600
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

import itertools
import collections
def prime_factor_table(n):
    table = [0] * (n + 1)
    
    for i in range(2, n + 1):
        if table[i] == 0:
            for j in range(i + i, n + 1, i):
                table[j] = i
    
    return table

def prime_factor(n, prime_factor_table):
    prime_count = collections.Counter()
    
    while prime_factor_table[n] != 0:
        prime_count[prime_factor_table[n]] += 1
        n //= prime_factor_table[n]
    prime_count[n] += 1
    
    return prime_count

N = int(input())
A_s = list(map(int, input().split()))
# A_s = [int(i+1) for i in range(N)]
pc = True
sc = True
M = {}
MAX = 0
TABLE = prime_factor_table(10**6+1)

for i,A in enumerate(A_s):
    L = prime_factor(A, TABLE)
    for l in L.keys():
        if l == 1:
            continue
        if l in M:
            # print()
            M[l] += 1
            pc = False
        else:
            M[l] = 1
        MAX = max(MAX, M[l])
    if not pc and MAX <= i:
        break
else:
    sc = False

if pc:
    print('pairwise coprime')
elif sc:
    print('setwise coprime')
else:
    print('not coprime')

Measured memory_bytes: 195008
n = gets.chomp.to_i                                                                                                                    
                                                                                                                                       
ans = 0                                                                                                                                
                                                                                                                                       
                                                                                                                                       
(1...n).each do |i|                                                                                                                    
  # i == 1 の時はn-1                                                                                                                   
  # i == 2 の時は(n-1)/2                                                                                                               
  ans += (n-1)/i                                                                                                                       
end                                                                                                                                    
print ans

Measured memory_bytes: 14272
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#include<map>
#define ll long long
#define rint register int
#define in inline
using namespace std;
int n,a[100010],b[100010],tot,cnt[100010],fa[100010],ans; 
map<int,int> f;//离散化 
in ll read()
{
    ll 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;
}
in int find(int x){ return x==fa[x]?x:fa[x]=find(fa[x]); }
in void merge(int x,int y)
{
    int fx=find(x),fy=find(y);
    if(fx!=fy) fa[fx]=fy;
}
int main()
{
    n=read();
    for(rint i=1;i<=n;i++) a[i]=read(),a[n+1]^=a[i];
    for(rint i=1;i<=n;i++) b[i]=read(),b[n+1]^=b[i];
    n++;
    for(rint i=1;i<=n;i++)
        if(a[i]!=b[i]||i==n) //n其实是n+1 需要特判 
        {
            if(!f[a[i]]) f[a[i]]=++tot;
            cnt[f[a[i]]]++;
        }
    for(rint i=1;i<=n;i++)
        if(a[i]!=b[i]||i==n) 
            cnt[f[b[i]]]--;
    for(rint i=0;i<=tot;i++) if(cnt[i]) { printf("-1"); return 0; }//从0开始枚举是为了避免b中出现a中没有的数
    for(rint i=1;i<=tot;i++) fa[i]=i;//并查集 
    for(rint i=1;i<=n;i++) a[i]=f[a[i]],b[i]=f[b[i]];
    for(rint i=1;i<=n;i++)
        if(a[i]!=b[i]) 
        {
            if(i<n) ans++;//最后一个点要单独处理 因为不需要连到b[n+1] 连一条边操作就多一次 
            merge(a[i],b[i]);
        }
    for(rint i=1;i<=tot;i++) if(find(i)==i) ans++;//有多少个环 就要在环之间连多少边-1
    if(ans) printf("%d",ans-1);
    return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
  int n;
  cin>>n;
  map<string,int> frequency;
  int max=0;
  for(int i=0;i<n;i++)
  {
    string element;
    cin>>element;
    frequency[element]++;
    if(frequency[element]>max)
      max=frequency[element];
  }
  
	for (auto itr = frequency.begin(); itr != frequency.end(); ++itr) { 
        if(itr->second==max)
          cout<<itr->first<<endl;
    } 
  return 0;
}

Measured memory_bytes: 25216
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	s := getNextString(scanner)
	t := getNextString(scanner)

	ns := len(s)
	nt := len(t)
	ss := make([]string, (nt-1)/ns+1)

	for i := 0; i < len(ss); i++ {
		ss[i] = s
	}

	sss := fmt.Sprintf("%s%s", strings.Join(ss, ""), strings.Join(ss, ""))

	ok := make([]bool, ns)

	uni := make([]int, ns)
	mp := MP{}
	mp.init(t)
	m := 0
	for i := 0; i < ns; i++ {
		uni[i] = i
	}
	var o bool
	for i := 0; i < ns; i++ {
		o = true
		for m < nt {
			if t[m] != sss[i+m] {
				o = false
				break
			}
			m++
		}
		ok[i] = o
		if o {
			i += nt - mp.table[m]
			m = mp.table[m]
		}
		for m >= 0 && t[m] != sss[i+m] {
			i += m - mp.table[m]
			m = mp.table[m]
		}
		i--
		m++
	}

	ans := 0
	var r, rr int
	for i := 0; i < ns; i++ {
		if ok[i] == false {
			continue
		}
		if ok[(i+nt)%ns] == false {
			continue
		}
		r = root(i, uni)
		rr = root((i+nt)%ns, uni)
		if rr == r {
			fmt.Println(-1)
			return
		}
		uni[rr] = r
	}

	counter := make([]int, ns)
	for i := 0; i < ns; i++ {
		r = root(i, uni)
		if ok[r] == false {
			continue
		}
		counter[r]++
	}
	for i := 0; i < ns; i++ {
		if ans < counter[i] {
			ans = counter[i]
		}
	}

	fmt.Println(ans)

	writer.Flush()
}

func root(i int, uni []int) int {
	if i == uni[i] {
		return i
	}

	uni[i] = root(uni[i], uni)
	return uni[i]
}

// MP ...
type MP struct {
	s     string
	table []int
}

func (mp *MP) init(s string) {
	mp.s = s
	n := len(s)
	table := make([]int, n+1)
	table[0] = -1
	j := -1
	for i := 0; i < n; i++ {
		for j >= 0 && s[i] != s[j] {
			j = table[j]
		}
		j++
		table[i+1] = j
	}
	mp.table = table
}


Measured memory_bytes: 69632
///******* In the name of Allah *******///

#include<bits/stdc++.h>
using namespace std;

int main()
{ 
    int a,b,c,m,n,i,j,k,l,t;
    cin>>a>>b;
    if((a==1 && b==2) || (a==2 && b==1))
    {
        cout<<"3"<<endl;
    }
    else if((a==1 && b==3) || (a==3 && b==1))
    {
        cout<<"2"<<endl;
    }
    else if((a==2 && b==3) || (a==3 && b==2))
    {
        cout<<"1"<<endl;
    }
	
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
  int i, n, *blackboard, cnt, min_cnt = 100000;

  scanf("%d", &n);
  blackboard = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) {
    scanf("%d", &blackboard[i]);
  }

  for (i = 0; i < n; i++) {
    cnt = 0;
    while (blackboard[i] % 2 == 0) {
      cnt++;
      blackboard[i] /= 2;
    }
    if (min_cnt > cnt) {
      min_cnt = cnt;
    }
  }
  printf("%d", min_cnt);

  free(blackboard);
  return 0;
}

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

int main(){
  int n,x=0,mx=0;
  char a;
  cin >> n;
  while(n--){
    cin >> a;
    if(a=='I'){
      x++;
      mx=max(x,mx);
    }
    else x--;
  }
  cout << mx << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

long calcNumOfCombination(long n, long r)
{
    long num = 1;
    for(long i = 1; i <= r; i++)
    {
        num = num * (n - i + 1) / i;
    }
    return num;
}

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

    vector<string> vec;
    map<string, long> smap;
    for (long i = 0; i < n; i++)
    {
        string str;
        cin >> str;
        sort(str.begin(), str.end());
        vec.push_back(str);
    }

    vector<string> svec;
    for (long i = 0; i < n; i++)
    {
        string str = vec[i];
        if (smap[str] == 0)
        {
            smap[str] = 1;
            svec.push_back(str);
        }
        else
        {
            smap[str]++;
        }
    }
    
    long count = 0;
    for (long i = 0; i < svec.size(); i++)
    {
        long num = smap[svec[i]];
        
        long ans = calcNumOfCombination(num, 2);
        count += ans;
    }
    
    cout << count << endl;
}

Measured memory_bytes: 12788
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  vector<Int> v(n),w(n);
  for(Int i=0;i<n;i++) cin>>v[i]>>w[i];

  if(n<=20){
    Int ans=0;
    for(Int b=0;b<(1<<n);b++){
      Int tmp=0,res=0;
      for(Int i=0;i<n;i++)
	if((b>>i)&1) tmp+=w[i],res+=v[i];
      if(tmp<=k) chmax(ans,res);
    }  
    cout<<ans<<endl;
    return 0;
  }

  Int ans=0;
  using P = pair<Int, Int>;
  vector<P> vp;
  Int h=20,r=n-h;
  for(Int b=0;b<(1<<h);b++){
    Int tmp=0,res=0;
    for(Int i=0;i<h;i++)
      if((b>>i)&1) tmp+=w[i],res+=v[i];
    if(tmp>k) continue;
    vp.emplace_back(tmp,res);
  }
  sort(vp.begin(),vp.end());
  
  vector<P> up;
  for(P p:vp)
    if(up.empty()||up.back().second<p.second)
      up.emplace_back(p);
  
  for(Int b=0;b<(1<<r);b++){
    Int tmp=0,res=0;
    for(Int i=0;i<r;i++)
      if((b>>i)&1) tmp+=w[h+i],res+=v[h+i];
    if(tmp>k) continue;
    chmax(ans,res);
    auto latte=--upper_bound(up.begin(),up.end(),P(k-tmp+1,-1));
    if(tmp+latte->first<=k) chmax(ans,res+latte->second);
    
    //cout<<tmp<<" "<<res<<":"<<latte->first<<" "<<latte->second<<endl;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 19444
#include <iostream>
#include <cstdio>
#include <stdlib.h> 
int A[100];
int n;

int solve(int i, int m)
{
	if(m == 0) {return 1;}
	if(i >= n) { return 0;}
	
	return solve(i + 1, m) || solve(i+1, m-A[i]);
}

int main()
{
	scanf("%d", &n);
	
	for(int i=0; i < n; i++)
	{
		scanf("%d", &A[i]);
	}
	
	int q, m;
	
	scanf("%d", &q);
		
	for(int i=0; i < q; i++)
	{
		scanf("%d", &m);
		if(solve(0, m) == 1)
		{
			printf("yes\n");
		}
		else if(solve(0, m) == 0)
		{
			printf("no\n");
		}
	}
//	system("pause");
	return 0;
}


Measured memory_bytes: 3172