akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
  /*
  	N
    A1, A2, ..., An
    B1, B2, ..., Bn
    C1, C2, ..., Cn-1
    
  */
  
  int A[25]={};
  int B[25]={};
  int C[25]={};
  int N;
  
  scanf("%d",&N);
  int i;
  int point=0;
  
  for(i=0;i<N;i++)
  	scanf("%d",&A[i]);
  for(i=0;i<N;i++)
    scanf("%d", &B[i]);
  for(i=0;i<N-1;i++)
    scanf("%d",&C[i]);
  
  for(i=0;i<N;i++)
  {
    point+=B[A[i]-1];
    if(i>=1&&A[i]==A[i-1]+1)
      point+=C[A[i-1]-1];
  }
  printf("%d",point);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>

int main() {
    int x, y;
    scanf("%d%d", &x, &y);
    int group[] = { 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 };
    if (group[x - 1] == group[y - 1]) {
        puts("Yes");
    }
    else {
        puts("No");
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;



int main() {

	int  n, k, sum;
	cin >> n >> k;

	vector<int> wary(n);

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

	sum = accumulate(wary.begin(), wary.end(), 0);

	int mx = *max_element(wary.begin(), wary.end());
	int stt = max(sum / k , mx);
	int ld = stt, trkCnt = 0, wt = 0;

	while (true)
	{
		trkCnt = k - 1;
		wt = 0;
		for (int i = 0; i < n;i++) {

			if (ld >= wt + wary[i]) {
				wt += wary[i];
			}
			else
			{
				trkCnt -= 1;
				wt = wary[i];
			}
		}

		if (trkCnt >= 0) break;
		ld++;
	}

	cout << ld << endl;
	return 0;
}



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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define int long long
typedef pair<int, int> ii;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;

int n, v[N], used[N], mx;

vector<ii> vec1, vec2;

signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    mx = 0;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    int sum = 0;
    for(int i = 1; i <= n; i += 2) {
        used[v[i]]++;
        sum++;
    }
    for(int i = 1; i <= N - 5; i++) {
        vec1.pb({sum - used[i], i});
    }
    mx = 0;
    sum = 0;
    memset(used, 0, sizeof(used));
    for(int i = 2; i <= n; i += 2) {
        used[v[i]]++;
        sum++;
    }
    for(int i = 1; i <= N - 5; i++) {
        vec2.pb({sum - used[i], i});
    }
    sort(vec1.begin(), vec1.end()); sort(vec2.begin(), vec2.end());
    int cost = INT_MAX;
    for(int i = 0; i < vec1.size(); i++) {
        for(int j = 0; j < vec2.size(); j++) {
            if(vec1[i].se == vec2[j].se) continue;
            cost = min(cost, vec1[i].fi + vec2[j].fi);
            break;
        }
    }
    cout << cost << "\n";
}


Measured memory_bytes: 7920
#pragma GCC optimize(2)

#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstring>

#include <set>
#include <queue>
#include <complex>
#include <algorithm>

int read(void){
	int res = 0, sign = 1;
	char ch = std::getchar();
	while(!std::isdigit(ch)){
		if(ch == '-')
			sign = -1;
		ch = std::getchar();
	}
	while(std::isdigit(ch))
		res = res * 10 + ch - 48, ch = std::getchar();
	return sign * res;
}

template<class Tp>
	void write(const Tp &x){
		if(x > 9)
			write(x / 10);
		std::putchar(x % 10 + 48);
	}

typedef long long ll;
typedef unsigned long long ull;
typedef double rl;
typedef long double RL;

const rl PI = 3.1415926535898, E = 2.71828182845904;

const int MAXN = 2e5 + 19;

int n, k, a[MAXN];

int main(){
	n = read(), k = read();
	for(int i = 1; i <= n; ++i)
		a[i] = read();
	for(int i = 1; i <= n - k; ++i)
		std::puts(a[k + i] > a[i] ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 2312
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std; 
int main(){
  int a[10]={};  
  for(int i=0;i<10;i++){
    cin>>a[i];
  }
 
  sort(a,a+10);
  cout<<a[9]<<endl;
  cout<<a[8]<<endl;
  cout<<a[7]<<endl;
  return 0;
}

Measured memory_bytes: 3136
def main():
    import sys
    input = sys.stdin.readline
    N,M,R = map(int,input().split())
    r = list(map(int,input().split()))
    ABC = []
    D = [[float("inf")]*(N+1) for i in range(N+1)]
    for i in range(M):
        a,b,c = map(int,input().split())
        D[a][b] = c
        D[b][a] = c
        
    for k in range(1,N+1):
        for i in range(1,N+1):
            for j in range(1,N+1):
                D[i][j] = min(D[i][j], D[i][k]+D[k][j])
                
    import itertools
    ans = float("inf")
    for v in itertools.permutations(r,R):
        #print(v)
        tmp = 0
        for i in range(R-1):
            tmp += D[v[i]][v[i+1]]
        if tmp < ans:
            ans = tmp
    #print(D)
    print(ans)
        
    
    
main()

Measured memory_bytes: 56412
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

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

    int n; cin >> n;
    string s; cin >> s;
    int mn = 0, pos = 0;
    rep(i, n) {
        if (s[i]=='(') pos++;
        else pos--;
        chmin(mn, pos);
        debug(i, s[i], mn, pos);
    }
    debug(mn, pos);
    rep(i, -mn) cout << '(';
    cout << s;
    rep(i, pos-mn) cout << ')';
    cout << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  string s; cin >> s;
  cout << "ABC" + s << endl;

  return;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int K; cin >> K;
    string S; cin >> S;
    for(int i=0;i<S.size();i++){
        cout << S[i];
        if(i==K-1 && S.size()!=K){
            cout << "...";
            break;
        }
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int A, B; cin>>A>>B;
  cout << ( 6 - A - B) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 2e9;
#define pb push_back
#define mp make_pair
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    int n, T, t, sta, ans = 0;
    cin >> n >> T >> sta;
    for(int i=1; i<n; i++){
        cin >> t;
        if(t-sta>=T){
            ans += T;
        }
        else{
            ans += t - sta;
        }
        sta = t;
    }
    ans += T;
    cout << ans << endl;
}

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

int main() {
	int a, b, x;
	cin >> a >> b >> x;
	double area = (double)x/a;
	double c = ((double)x / a) / a;
	double at = 0.0;

	cout << fixed << setprecision(9);

	if(c > b/2){
		double xx = (double)2*b - ((2 * area) / a);
		at = atan(a/xx);
		cout << 90- 360.0 * at / (3.14159265358979 * 2) << endl;
	} else {
		double xx = 2* area / b;
		at = atan(xx/b);
		cout << 90 - 360.0 * at / (3.14159265358979 * 2) << endl;
	}	
}

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

typedef pair<long long, long long> P;

int main(void){
    long long n, k, a, b;
    unsigned long long sum = 0;
    cin >> n >> k;
    vector<P> vec;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        vec.push_back(P(a, b));
        
    }
    sort(vec.begin(), vec.end());
    
    long long l=0, cnt=0;
    while(sum < k){
        sum += vec[l].second;
        l++;
    }
    
    cout << vec[l-1].first << endl;
    
    return 0;
}

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

int main() {
  int N;
  int temp;
  int alice(0),bob(0);
  int diff_point(0);
  priority_queue <int> card;

  cin>>N;
  for (size_t i = 0; i < N; i++)
  {
    cin>>temp;
    card.push(temp);
  }

  for (size_t i = 0; i < N; i++)
  {
    if(i%2==0){
      alice += card.top();
      card.pop();
    }else{
      bob += card.top();
      card.pop();
    }
  }
    diff_point = alice - bob;
    cout<<diff_point<<endl;
}

Measured memory_bytes: 256
import Control.Monad
import qualified Data.IntSet as S

main = do
  n <- readLn
  as <- map read <$> replicateM n getLine
  print . S.size $ solve S.empty as

solve s [] = s
solve s (a:as)
  | a `S.member` s = solve (S.delete a s) as
  | otherwise = solve (S.insert a s) as

Measured memory_bytes: 67964
from collections import deque
H, W = map(int, input().split())
G = []
for i in range(H+2):
    if i == 0 or i == H+1:
        G.append('#'*(W+2))
    else:
        G.append('#' + input() + '#')

ans = 0
for sx in range(W+2):
    for sy in range(H+2):
        if G[sy][sx] == '.':
            dist = [[-float('inf') for i in range(W+2)] for i in range(H+2)]
            visited = [[-1 for i in range(W+2)] for i in range(H+2)]
            q = deque([])
            q.append((sx, sy))
            dist[sy][sx] = 0
            visited[sy][sx] = 1
            while q:
                x, y = q.popleft()

                if G[y][x+1] == '.' and visited[y][x+1] == -1:
                    q.append((x+1, y))
                    dist[y][x+1] = dist[y][x] + 1
                    visited[y][x+1] = 1

                if G[y][x-1] == '.' and visited[y][x-1] == -1:
                    q.append((x-1, y))
                    dist[y][x-1] = dist[y][x] + 1
                    visited[y][x-1] = 1

                if G[y+1][x] == '.' and visited[y+1][x] == -1:
                    q.append((x, y+1))
                    dist[y+1][x] = dist[y][x] + 1
                    visited[y+1][x] = 1

                if G[y-1][x] == '.' and visited[y-1][x] == -1:
                    q.append((x, y-1))
                    dist[y-1][x] = dist[y][x] + 1
                    visited[y-1][x] = 1
            for i in range(W+2):
                for j in range(H+2):
                    ans = max(ans, dist[j][i])
print(ans)

Measured memory_bytes: 64368
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;

int main(){
  ll x,y;
  cin >> x >> y;
  vector<pair<ll,ll> > a;
  a.pb(mp(1,1));
  a.pb(mp(1,-1));
  a.pb(mp(-1,1));
  a.pb(mp(-1,-1));
  ll min = LLONG_MAX;
  rep(i,4){
    ll f = a[i].first, l = a[i].second;
    ll num = 0;
    if(f<0) num++;
    if(l<0) num++;
    if(f*x<=l*y){
      if(min > (l*y-f*x+num)) min = l*y-f*x+num;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define N 100005
#define MXN 200005
int main(){
    char c[200005];
    scanf("%s",c);
    int ans=0;
    int sum=0;
    for(int i = 0;c[i]!=0;i++){
        if(c[i]=='S')sum++;
        else{
            if(sum)sum--;
            else ans++;
        }
    }
    printf("%d\n",ans+sum);
}


Measured memory_bytes: 384
n=int(input())
s=sorted([int(input()) for _ in [0]*n])

if sum(s)%10==0:
    f=False
    for i in s:
        if i%10!=0:
            f=True
            break
    if f:
        s.remove(i)
        print(sum(s))
    else:
        print(0)
else:
    print(sum(s))

Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


int main() {
	int x, y, z; cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;
	return 0;
}

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

int main(){
 int N, min, sub, sum1, sum2, i; 
 cin >> N;
 int w[N];
 for(i=0;i<N;i++) cin >> w[i];
 
 sum1 = w[0];
 sum2 = 0;
 for(i=1;i<N;i++) sum2 += w[i];
 sub = sum1 - sum2;
 if(sub < 0) sub *= -1;
 min = sub;
 
 for(i=1;i<N;i++){
   sum1 += w[i];
   sum2 -= w[i];
   sub = sum1 - sum2;
   if(sub < 0) sub *= -1;
   if(sub < min) min = sub;
 }
   cout << min;
 return 0; 
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 44

int fib(int,int*);

int main(void){
  int n,F[N];
  int i;

  scanf(" %d",&n);

  for(i = 0; i <= n; i++){
    F[i] = 0;
  }

  printf("%d\n",fib(n,F));
  
  return 0;
}

int fib(int n, int *F){
  if(n == 0 || n == 1)return F[n] = 1;
  if(F[n] != 0) return F[n];
  return F[n] = fib(n-1,F)+fib(n-2,F);
}



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

#define loop(i,n) for(int i=1;i<=n;i++)
int s[100002];

int main(){
  int n,m,a;
  cin>>n>>m;
  loop(i,n-1){
    cin>>s[i+1];
    if(0<=i-1)s[i+1]+=s[i];
  }
  int pos=1;
  int tot=0;
  loop(i,m){
    cin>>a;
    tot+=abs(s[pos+a]-s[pos]);
    tot%=100000;
    pos+=a;
  }
  cout<<tot<<endl;
  return 0;
}

Measured memory_bytes: 3444
#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>;

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

bool bad(string query, ll A, ll B, ll C) {
    if (query == "AB") {
        return (A == 0 && B == 0) || A < 0 || B < 0;
    } else if (query == "BC") {
        return (B == 0 && C == 0) || B < 0 || C < 0;
    } else if (query == "AC") {
        return (A == 0 && C == 0) || A < 0 || C < 0;
    }
    return false;
}

int main() {
    int N;
    cin >> N;
    ll A, B, C;
    cin >> A >> B >> C;
    
    vector<string> query(N);
    for (int i=0; i<N; ++i) cin >> query[i];
    query.push_back("x");

    vector<string> ans;
    for (int i=0; i<N; ++i) {
        if (bad(query[i], A, B, C)) {
            cout << "No" << endl;
            return 0;
        }
        if (query[i] == "AB") {
            if (bad(query[i+1], A-1, B+1, C) && B) {
                ans.push_back("A"); A++; B--;
            } else if (bad(query[i+1], A+1, B-1, C) && A) {
                ans.push_back("B"); A--; B++;
            } else if (A < B) {
                ans.push_back("A"); A++; B--;
            } else {
                ans.push_back("B"); A--; B++;
            }
        } else if (query[i] == "BC") {
            if (bad(query[i+1], A, B-1, C+1) && C) {
                ans.push_back("B"); B++; C--;
            } else if (bad(query[i+1], A, B+1, C-1) && B) {
                ans.push_back("C"); B--; C++;
            } else if (B < C) {
                ans.push_back("B"); B++; C--;
            } else {
                ans.push_back("C"); B--; C++;
            }
        } else { // AC
            if (bad(query[i+1], A-1, B, C+1) && C) {
                ans.push_back("A"); A++; C--;
            } else if (bad(query[i+1], A+1, B, C-1) && A) {
                ans.push_back("C"); A--; C++;
            } else if (A < C) {
                ans.push_back("A"); A++; C--;
            } else {
                ans.push_back("C"); A--; C++;
            }
        }
    }
    
    cout << "Yes" << endl;
    for (string t: ans) {
        cout << t << endl;
    }

    return 0;
}

Measured memory_bytes: 13664
import java.util.*;
import java.io.*;

public class Main {

  void solve(InputReader in, PrintWriter out) {
    int n = in.nextInt();
    int[] arr = new int[n];
    boolean[] set = new boolean[n];
    int m = in.nextInt();
    for (int i = 0; i < m; ++i) {
      int idx = in.nextInt();
      int val = in.nextInt();

      if (set[idx - 1] && arr[idx - 1] != val) {
        out.println(-1);
        return;
      } 

      if (n > 1 && idx == 1 && val == 0) {
        out.println(-1);
        return;
      }

      arr[idx - 1] = val;
      set[idx - 1] = true;
    }

    if (n > 1 && !set[0]) {
      arr[0] = 1;
    }

    for (int i = 0; i < n; ++i) {
      out.print(arr[i]);
    } out.println();
  }

  public static void main(String[] args) throws Exception {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    Main solver = new Main();
    solver.solve(in, out);
    out.close();
  }

  static class InputReader {
    BufferedReader in;
    StringTokenizer st;

    public InputReader(InputStream is) {
      in = new BufferedReader(new InputStreamReader(is));
    }

    public String next() {
      try {
        while (st == null || !st.hasMoreTokens()) {
          st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }
  }
}


Measured memory_bytes: 22484
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<string.h>
#include<algorithm>
#include<climits>
using namespace std;

bool chks(char c){
  if(c == 'A'
      || c == 'T'
      || c == 'G'
      || c == 'C')
  {
      return true;
  }
  else{
    return false;
  }
}

int main() {
  string s;
  cin >> s;

  int N = s.size();
  int tmp = 0;
  int ans = 0;
  bool flg = false;
  for(int i = 0; i<N; i++){
    if(chks(s[i])){
      tmp++;
    }else{
      tmp = 0;
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

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

int prime[51000];

int main(){
	int n;
	
	for(int i = 2; i * i < 51000; ++i){
		if(!prime[i]){
			for(int j = i * i; j < 51000; j += i){
				prime[j] = 1;
			}
		}
	}
	
	while(cin >> n){
		for(int i = n - 1;; --i){
			if(!prime[i]){
				cout << i << ' ';
				break;
			}
		}
		for(int i = n + 1;; ++i){
			if(!prime[i]){
				cout << i << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1360
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long;

const int INF = 1e9;
const long long  LLINF = 1e15;

using namespace std;

string s;
bool flag[26];
vector<string> v;

void dfs(int pos, string str){
  if(pos == s.size()){
    v.push_back(str);
    return;
  }

  if(!flag[str[pos]-'a'] || str[pos] == 'a'){
    bool tmp = flag[str[pos]-'a'];
    flag[str[pos]-'a'] = false;
    dfs(pos+1, str);
    flag[str[pos]-'a'] = tmp;
  }
  if(flag[str[pos]+1-'a'] && str[pos]!='z'){
    str[pos] = str[pos]+1;
    flag[str[pos]-'a'] = false; //?????¨?????????
    dfs(pos+1, str);
    flag[str[pos]-'a'] = true;
    str[pos] = str[pos]-1;
  }

  return;
}

int main() {
  while (1) {
      cin>>s;
      if(s == "#") break;
      REP(i,0,26) flag[i] = true;
      v.clear();
      dfs(0,s);
      cout<<v.size()<<endl;
      if(v.size() <= 10){
        REP(i,0,v.size()) cout<<v[i]<<endl;
      }else{
        REP(i,0,5) cout<<v[i]<<endl;
        REP(i,v.size()-5,v.size()) cout<<v[i]<<endl;
      }
  }
  return 0;
}

Measured memory_bytes: 4112
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = (int) 1e5 + 5;
const int mod = (int) 1e9 + 7;

inline void scan (int &a) {
        a = 0;
        char c = getchar ();
        while (c < 48 || c > 57) {
                c = getchar ();
        }
        while (c > 47 && c < 58) {
                a = (a << 1) + (a << 3) + c - 48;
                c = getchar ();
        }
}

int n, a[N];

int calc (int player) {
        int x = 0;
        for (int i = 1; i <= n; i++) {
                x += a[i] & 1;
        }
        x = n - x;
        if (x & 1) {
                return player;
        } else if (x + 1 < n) {
                return player ^ 1;
        } else {
                int g = 0;
                for (int i = 1; i <= n; i++) {
                        if (a[i] & 1) {
                                if (a[i] == 1) {
                                        return player ^ 1;
                                }
                                a[i]--;
                        }
                        g = __gcd (g, a[i]);
                }
                for (int i = 1; i <= n; i++) {
                        a[i] /= g;
                }
                return calc (player ^ 1);
        }
}

inline void solve () {
        scan (n);
        for (int i = 1; i <= n; i++) {
                scan (a[i]);
        }
        puts ((calc (1) & 1) ? "First" : "Second");
}

int tests = 1;

int main () {
//        freopen (".in", "r", stdin);
//        freopen (".out", "w", stdout);
//        scanf ("%d", &tests);
        while (tests--) {
                solve ();
        }
        return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int n,k,s;
  
    cin >> n >> k >> s;
    if( (n*k) > s){ 
       cout << s << endl;
    }else{
       cout << (n * k) << endl;
    } 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int N;
  cin >> N;
  set<pair<int,pair<int,int>>> st;
  rep(i,0,N - 1){
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> v = {a,b,c};
    sort(all(v));
    st.insert(make_pair(v[0],make_pair(v[1],v[2])));
  }
  cout << N - (int)st.size() << endl;
}



Measured memory_bytes: 3216
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
    ll x,y;
    cin >> x >> y;
    ll z = y/x;
    int i;
    for(i=0;z>1;++i){
        z /= 2;
    }
    cout << i+1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
  long n;
  cin >> n; 
  vector<long> f;

  for(long i=1; i<=sqrt(n); ++i) {
    if(n % i == 0) f.push_back(n / i);
  }
  sort(f.begin(), f.end());
  cout << to_string(f[0]).length() << endl;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 200007, mod = 1000000007;
int n;
vector<int> graph[N];

int ct[N], pw[N], num, ans;

int pow(int a, int b) {
    if(b == 0) return 1;
    if(b%2) return a*pow(a, b-1)%mod;
    return pow(a*a%mod, b/2)%mod;
}

void fill_pow() {
    int cur = 1;
    for(int i = 0; i <= n; ++i) {
        pw[i] = cur;
        cur = (cur*2)%mod;
    }
}

void dfs(int cur, int par) {
    ct[cur] = 1;
    int to_add = pw[n-1] - 1;
    for(int child : graph[cur]) {
        if(child != par) {
            dfs(child, cur);
            ct[cur] += ct[child];
            to_add -= pw[ct[child]] - 1;
        }
    }
    to_add -= pw[n-ct[cur]] - 1;
    to_add %= mod;
    if(to_add < 0) to_add += mod;
    num = (num + to_add)%mod;
}

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 0; i < n-1; ++i) {
        int a, b; cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    fill_pow();
    dfs(1, 0);

    ans = num*pow(pw[n], mod-2)%mod;

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


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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : b;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n;
    cin >> n;
	for(int i = 1; i <= 9; ++i){
		if(n % i == 0 && n / i <= 9){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  for(int i=N;i<100004;i++)
  {
    if(is_prime(i)) 
    {
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

int main(){
    int kase,q,t;
    string name;
    queue<pair<string, int> > Q;

    cin >> kase >> q;

    for(int i = 0; i < kase; i++) {
        cin >> name >> t;
        Q.push(make_pair(name,t));
    }

    pair<string,int> cur;
    int elaps = 0, tmp;

    while(!Q.empty()){
        cur = Q.front(); Q.pop();
        tmp = min(cur.second,q);

        cur.second -= tmp;
        elaps += tmp;

        if(cur.second > 0){
            Q.push(cur);
        }else {
            cout << cur.first <<" " << elaps << endl;
        }
    }
    return 0;
}


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

#define endl '\n'
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;

void solve() {
	int n, idx;
	string str;
	cin >> n >> idx >> str;
	idx--;
	char pos = str[idx] - 'A';
	char newChar = ('a' + pos);
	str[idx] = newChar;
	cout << str;
}

int main() {
	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif
	solve();
}

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

int main(){
    int L,R;
    cin >> L >> R;
  	if(R-L>=2019){
        cout <<'0'<<endl;
        return 0;
    }
    L = L%2019;
    R = R%2019;
    int minmin = 2019;
    int total;

    for(int i = L;i<R;i++){
        for(int j = i+1;j<=R;j++){
            total = i*j;
            minmin = min(minmin,total%2019);
        }
    }
    cout << minmin;

}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

int main() {
  ll N; cin >> N;
  ll X, M; cin >> X >> M;
  ll S = 0; // 最終的に答えとなる和
  vector<P> memo(M); // その値Xが { 何番目に出現したか, それまでの計算結果(和) }
  for(ll i = 0; i < N; ++i) {
    if(memo[X].first) { // もしその値がすでに配列にあれば
      // 今の順番と、かつてXが出てきた番号の差。これがループ1周分の長さになる
      const auto t = i - memo[X].first;
      // ループ1周分の残りの長さ
      const auto c = (N - i - 1) / t;
      i += t * c; // ループをスキップ?
      S += (S - memo[X].second) * c;
    } else { // もし配列にまだXが無ければ
      memo[X] = P(i, S); // 配列のX番目にpairを格納する。
    }
    // 必ずSとXを更新する
    S += X; (X *= X) %= M;
  }
  cout << S << endl;
}

Measured memory_bytes: 4800
a, b = map(int, input().split())


if a < 0 and b > 0:
    print("Zero")

elif a > 0:
    print("Positive")

elif b < 0 and a < 0:
    if (b - a + 1) % 2 != 0:
        print("Negative")
    else:
        print("Positive") 


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
ll sz[51], p[51];
ll rec(int n, ll rem){
	if(rem <= 0) return 0;
	if(sz[n] <= rem) return p[n];
	if(sz[n - 1] < rem){
		ll res = p[n - 1];
		rem -= sz[n - 1] + 1;
		if(rem > 0) res++;
		rem--;
		return res + rec(n - 1, rem);
	}
	return rec(n - 1, rem - 1);
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	sz[0] = 1;
	p[0] = 1;
	rep(i, 50) sz[i + 1] = 2 * sz[i] + 3;
	rep(i, 50) p[i + 1] = 2 * p[i] + 1;
	
	ll n, x; cin >> n >> x;
	ll ans = rec(n, x);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from math import gcd
K = int(input())

memo =[[0 for i in range(K+1)] for j in range(K+1)]
for i in range(K+1):
    memo[1][i] = 1
    memo[i][1] = 1

cnt =0

for i in range(1,K+1):
        for j in range(1,K+1):
                t = gcd(i,j)
                for k in range(1,K+1):
                    cnt += gcd(t,k)


print(cnt)

Measured memory_bytes: 9340
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<set>
#include<string.h>
#include<map>
#include<vector>
#define pb push_back
#define ins insert 
#define mp make_pair
#define fi first
#define se second
#define ll long long 
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define M 10000007
using namespace std;
int main(){
    //double start_time = clock();
    ll n;
    cin>>n;
    ll a[n],dp[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for (int i = 2; i < n; ++i)
        {
            dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        }
    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
using namespace std;
#define INF 1e10
int n;
long long a,b;
long long sum=0,Min=INF;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%lld %lld",&a,&b);
		sum+=a;
		if(a>b) Min=min(Min,b);
	}
	if(Min==INF)
		printf("0\n");
	else printf("%lld\n",sum-Min);
	return 0;
}

Measured memory_bytes: 256
/*
 _   ________   ___       __ ___   _           _  _
| | / /|  _  \ / _ \     / // _ \ | |         | |(_)
| |/ / | | | |/ /_\ \   / // /_\ \| | __ __ _ | | _
|    \ | | | ||  _  |  / / |  _  || |/ // _` || || |
| |\  \| |/ / | | | | / /  | | | ||   <| (_| || || |
\_| \_/|___/  \_| |_//_/   \_| |_/|_|\_\\__,_||_||_|
*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
const int N = 1e5+50;
const int mod = 1e9+7;
const int in = 1e9+9;
typedef pair<int,int> ii;
int n;
#define fi first
#define se second
signed main(){
	cin >> n;
	while(n--){
		int a, b;
		cin >> a >> b;
		if(a==b){
			cout << 2*(a-1) << '\n';
			continue;
		}
		int res = sqrt(a*b);
		if(res*res==a*b) res--;
		if(res*(res+1)<a*b) cout << 2*res-1 << '\n';
		else cout << 2*(res-1) << '\n';
	}
}


Measured memory_bytes: 256
class BinaryIndexedTree():
    def __init__(self, N):
        self.N = N
        self.arr = [0] * (N+1)

    def query(self, i):
        ret = 0
        i += 1
        while i:
            ret += self.arr[i]
            lsb = i & (-i)
            i -= lsb
        return ret

    def add(self, i, v):
        i += 1
        while i < self.N+1:
            lsb = i & (-i)
            self.arr[i] += v
            i += lsb

    def search(self, x):
        lo = -1
        hi = self.N
        while lo < hi:
            mid = (lo+hi)//2
            if self.query(mid) < x:
                lo = mid + 1
            else:
                hi = mid
        return lo


def c2i(c):
    return ord(c) - ord('a')


def main():
    N = int(input())
    S = list(input())
    bits = [BinaryIndexedTree(N) for _ in range(26)]
    for i, c in enumerate(S):
        bits[c2i(c)].add(i, 1)
    Q = int(input())
    for _ in range(Q):
        t, x, y = input().split()
        if t == "1":
            i = int(x) - 1
            bits[c2i(S[i])].add(i, -1)
            bits[c2i(y)].add(i, 1)
            S[i] = y
        else:
            l, r = int(x), int(y)
            ans = 0
            for i in range(26):
                cs = bits[i].query(r-1)
                if l-2 >= 0:
                    cs -= bits[i].query(l-2)
                if cs >= 1:
                    ans += 1
            print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 176320
import sys
H, W = list(map(int, input().split()))
A = [input() for _ in range(H)]
for i in range(H - 1):
    for j in range(W - 1):
        if A[i + 1][j] == '#' and A[i][j + 1] == '#':
            print('Impossible')
            sys.exit()
print('Possible')


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
const int N=2e8+5;
char s[N],t[N];
int n,m,xx,yy,nex[N];
void kmp_init()
{
    int i=1,k=0;
    while(i<=xx*m)
        if(k==0||t[i]==t[k]) nex[++i]=++k;
    else k=nex[k];
}
int main()
{
    scanf("%s%s",s+1,t+1);
    n=strlen(s+1);m=strlen(t+1);
    xx=2800000/m;
    for(int j=1;j<xx;j++)
    for(int i=1;i<=m;i++)
        t[i+m*j]=t[i];
    kmp_init();
    int ans=0,p=m*xx/n;
    int now=0,pos=0;
    m*=xx;
    for(int l=1;l<=p;l++)
    {
        for(int i=1;i<=n;i++)
        {
            pos++;
            while(pos&&t[pos]!=s[i])
                pos=nex[pos];
            ans=max(ans,pos);
        }
    }
    m/=xx;
    if(ans>=n*(p-1)) printf("-1\n");
    else printf("%d\n",ans/m);
}


Measured memory_bytes: 20736
# Author: cr4zjh0bp
# Created: Sun Mar 29 05:26:08 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

x = ni()

a = x % 100
b = x // 100
if b * 5 >= a:
    print(1)
else:
    print(0)

Measured memory_bytes: 3064
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
bool isok(ll now, ll b, int g)
{
	for (int i = g; i >= 1; i--)
	{
		for (int j = 0; j <= 50; j++)
		{
			if (now&(1LL << j))
			{
				now |= (1LL << (j%i));
			}
		}
	}
	return (now&(1LL << b)) != 0;
}
ll a[100], b[100];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%lld", &a[i]), a[i] = 1LL << a[i];
	for (int i = 0; i < num; i++)scanf("%lld", &b[i]);
	for (int i = 0; i < num; i++)
	{
		if (!isok(a[i], b[i], 50))
		{
			printf("-1\n");
			return 0;
		}
	}
	ll ans = 0;
	for (int i = 50; i >= 1; i--)
	{
		bool f = false;
		for (int j = 0; j < num; j++)
		{
			if (!isok(a[j], b[j], i - 1))f = true;
		}
		if (f)
		{
			ans += 1LL << i;
			for (int j = 0; j < num; j++)
			{
				for (int k = 0; k <= 50; k++)
				{
					if (a[j] & (1LL << k))a[j] |= (1LL << (k%i));
				}
			}
		}
	}
	printf("%lld\n", ans);
}

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

vector<int> res(101, 0);

//素因数分解
void prime_factorize(int n) {
  for (int a = 2; a * a <= n; a++){
    if(n % a != 0) continue;
    while(n % a == 0){
      res[a]++;
      n /= a;
    }
  }
  if(n != 1){
    res[n]++;
  }
  return;
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  map<int, int> mp;
  for (int i = 2; i <= n; i++){
    prime_factorize(i);
  }
  for (int i = 2; i <= n; i++){
    if(res[i] >=2) mp[3]++;
    if(res[i] >= 4)mp[5]++;
    if(res[i] >= 14)mp[15]++;
    if(res[i] >= 24)mp[25]++;
    if(res[i] >= 74)mp[75]++;
  }
  ans += mp[75];
  ans += mp[25] * (mp[3]-1);
  ans += mp[15] * (mp[5] -1);
  ans += ((mp[5] * (mp[5] - 1)) / 2) * (mp[3]-2);
  cout << ans << endl;
}


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

int allocate(int n, int w[], int k, int p) {
	int load = 0;
	int cnt = 1;
	for (int i = 0; i < n; i++) {
		if (load + w[i] > p) {
			cnt++;
			if (cnt > k) return -1;
			load = 0;
		}
		load += w[i];
	}
	return 0;
}

int main() {
	int n, k, w[100000], m, s=0;
	cin >> n;
	cin >> k;
	m = (1 << 30) * -1;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		m = max(m, w[i]);
		s += w[i];
	}

	int i = m;
	int j = s;
	while (i <= j) {
		int guess = i + (j - i) / 2;
		if (allocate(n, w, k, guess) < 0) {
			i = guess + 1;
		}
		else {
			j = guess - 1;
		}
	}
	cout << i << endl;
}


Measured memory_bytes: 3496
import sys
from io import StringIO
import unittest

sys.setrecursionlimit(10**5)

def search(seq, min_n, max_n, n, req):
	ans = 0
	if len(seq) == n:
		for a, b, c, d in req:
			if seq[b-1] - seq[a-1] == c:
				ans += d
		return ans
	else:
		for i in range(min_n, max_n+1):
			new_seq = seq + [i]
			ans = max(ans, search(new_seq, i, max_n, n, req))
	return ans

def resolve():
	n, m, q = map(int, input().split())
	req = [list(map(int, input().split())) for _ in range(q)]
	print(search([], 1, m, n, req))
resolve()

Measured memory_bytes: 78240
#include <iostream>
int main()
{
    long long m, n, ans = 1ll;
    const long long mod = 1000000007ll;
    std::cin >> m >> n;
    for (long long i = 0ll; (i + 9) < n; i += 10) {
        ans *= ((((m*m*m)%mod)*((m*m*m)%mod)%mod)*(m*m*m)%mod*m)%mod;
        ans %= mod;
    }
    for (long long i=0;i<(n % 10);i++) {
        ans *= m;
        ans %= mod;
    }
    std::cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
int main(){
    int n,T,ans=114514;cin>>n>>T;
    For(i,0,n){
        int c,t;cin>>c>>t;
        if(T>=t){
            ans=min(ans,c);
        }
    }
    if(ans==114514) cout<<"TLE"<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
struct node
{
	int id,c;
};
bool operator <(node a,node b)
{
	return a.id<b.id;
}
set<node> st;
set<node>::iterator ddq;
int n,i,j,k,x,lt,rt,mid,a[200005];
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d",a+i);
	for(i=2;i<=n;++i)
		if(a[i]<=a[i-1])
			break;
	if(i>n)
	{
		printf("1");
		return 0;
	}
	lt=2,rt=n;
	while(lt<rt)
	{
		mid=lt+rt>>1;
		st.clear();
		for(i=1;i<=n;++i)
		{
			if(a[i]>a[i-1])
				continue;
			while(!st.empty()&&((--st.end())->id)>a[i])
				st.erase(--st.end());
			x=a[i];
			while(1)
			{
				if(st.empty())
					j=0;
				else
				{
					ddq=st.end();
					ddq--;
					j=ddq->id,k=ddq->c;
				}
				if(j<x)
				{
					st.insert((node){x,2});
					break;
				}
				if(j==0)
				{
					i=-1;
					break;
				}
				st.erase(ddq);
				if(k<mid)
				{
					st.insert((node){j,k+1});
					break;
				}
				--x;
			}
			if(i==-1)
				break;
		}
		if(i==-1)
			lt=mid+1;
		else
			rt=mid;
	}
	printf("%d",lt);
	return 0;
}


Measured memory_bytes: 4108
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    string s;
    cin >> s;
    cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100
#define swap(a,b) a^=b^=a^=b

int main(){
    
    int length, i, j, a[N], count = 0;
    
    scanf("%d", &length);
    for(i = 0; i < length; i++) scanf("%d", &a[i]);
    
    for(i = 0; i < length - 1; i++){
        for(j = length - 1; j >= i + 1; j--){
            if(a[j] < a[j-1]){
                swap(a[j], a[j-1]);
                count++;
            }
        }
    }
    
    for(i = 0; i < length; i++){
        printf("%d", a[i]);
        if(i != length - 1) printf(" ");
    }
    printf("\n%d\n", count);
    
    return 0;
}

Measured memory_bytes: 604