akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
  int i,j,key,count=0,data1,data2,array1[10001],array2[500];

  scanf("%d",&data1);
  for(i=0;i<data1;i++)scanf("%d",&array1[i]);
  scanf("%d",&data2);
  for(i=0;i<data2;i++){
    scanf("%d",&key);
      //for(i=0;i<data2;i++){
      // key=array[2];
    j=0;
    array1[data1]=key;
    while(array1[j] != key)j++;
    if(j != data1)count++;
  }
  printf("%d\n",count);
  return 0;
}
   


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

using namespace std;

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

int main() {
    ll n, m, i, j, k;
    cin >> n;
    if(n%2==1){
        cout << 0 << endl;
    }else{
        n/=2;
        ll ret = 0;
        while(n>0){
            ret+=n/5;
            n/=5;
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/29/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

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

  int N; cin>>N;
  vector<int> A(N); for(auto& a:A) cin>>a;
  vector<int> gl(N), gr(N);
  gl[0] = A[0];
  gr[N-1] = A[N-1];
  for (int i = 1; i < N; i++)
    gl[i] = gcd(gl[i-1], A[i]);
  for (int i = N-2; i >= 0; i--)
    gr[i] = gcd(gr[i+1], A[i]);
  int ans = max(gl[N-2], gr[1]);
  for (int i = 1; i < N-1; i++)
    ans = max(ans, gcd(gl[i-1], gr[i+1]));
  cout << ans << endl;

  return 0;
}


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


vector<int> edges[10];

bool seen[10];
int ans = 0;
int n;

int dfs(int s, int p, int d){
	seen[s] = true;
	for (int v: edges[s]){
		if(!seen[v] && v!=p){
			int td = dfs(v, s, d+1);
			if(td==n-1) ans++;
		}
	}
	seen[s] = false;
	return d;
}

int main(){
    int m;
    cin >> n >> m;
    rep(i, m){
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		edges[a].emplace_back(b);
		edges[b].emplace_back(a);
    }

	rep(i, 10){
		seen[i] = false;
	}

    dfs(0, -1, 0);

    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

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

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;
}

int main(){
    int n; cin >> n;
    vector<int> x(n); rep(i,n) cin >> x[i];
    vector<int> x_p(n);
    sort(x.begin(), x.end());
    int sum = 2147483647;
    int ans = 0;
    for(int p = x[0]; p <= x[n-1]; ++p){
        rep(i, n){
            x_p[i] = (x[i] - p)*(x[i] - p);
        }
        int sum_p = accumulate(x_p.begin(), x_p.end(), 0);
        if(sum_p <= sum){
            sum = sum_p;
            ans = p;
        }
    }
    cout << sum << endl;
}

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

int main(){
  string S; cin >> S;
  int ans1 = 0;
  int ans2 = 0;
  for(int i=0;i<S.size();i++){
    if(i%2 == 0){
      if(S.at(i) == '0'){
        ans1++;
      }else{
        ans2++;
      }
    }else{
      if(S.at(i) == '0'){
        ans2++;
      }else{
        ans1++;
      }
    }
  }
  cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int K, S;
  cin >> K >> S;
  int result = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (z < 0 || z > K)
        continue;
      result++;
    }
  }
  cout << result << endl;
}

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

const ll INF = 100100100;

struct edge{
	ll to;
	ll cost;
};

ll n;
vector<edge> to[100005];
vector<ll> dist;

void dfs(ll v, ll p, ll d){
	dist[v] = d;
	for(auto nextv: to[v]){
		if(nextv.to == p) continue;
		if(dist[nextv.to] != INF) continue;
		dfs(nextv.to, v, d + nextv.cost);
	}
}

int main(){
	cin >> n;
	dist.resize(n);
	dist.assign(n,INF);
	rep(i,n-1){
		ll a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		to[a].push_back(edge{b,c});
		to[b].push_back(edge{a,c});
	}
	ll q,k;
	cin >> q >> k;
	k--;
	dfs(k,-1,0);
	rep(i,q){
		ll x,y;
		cin >> x >> y;
		x--;y--;
		cout << dist[x] + dist[y] << endl;
	}
    return 0;
}



Measured memory_bytes: 14336
import numpy as np

n, k = map(int, input().split()) 
a_list = np.array(list(map(int, input().split())))

a_list.sort()

zero_list = a_list[a_list == 0]
minus_list = a_list[a_list < 0]
plus_list = a_list[a_list > 0]

def index_count(x):
    cnt = 0
    if x >= 0:
        cnt += len(zero_list) * n
    cnt += np.searchsorted(a_list, x // plus_list, side='right').sum()
    cnt += (n - np.searchsorted(a_list, -(-x // minus_list), side='left')).sum()
    cnt -= np.count_nonzero(a_list * a_list <= x)
 
    assert cnt % 2 == 0
    return cnt // 2
 
 
left = -10**18
right = 10**18
 
while left + 1 < right:
    mid = (left + right) // 2
    a = index_count(mid)
    if a >= k:
        right = mid
    else:
        left = mid
 
print(right)

Measured memory_bytes: 32312
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=6005,T=6000;
int n,mod,f[N][4][N<<1];
long long ans;

signed main(){
	read(n,mod);n*=3;
	f[1][0][T]=1;
	for(int i=1;i<n;i++) for(int j=0;j<3;j++) for(int k=-i;k<=i;k++){
		if(j<=1) f[i+1][j+1][k+T]=(f[i+1][j+1][k+T]+1ll*f[i][j][k+T]*i%mod)%mod;
		if(j==0) f[i+1][0][k+1+T]=(f[i+1][0][k+1+T]+f[i][j][k+T])%mod;
		else if(j==1) f[i+1][0][k-1+T]=(f[i+1][0][k-1+T]+f[i][j][k+T])%mod;
		else f[i+1][0][k+T]=(f[i+1][0][k+T]+f[i][j][k+T])%mod;
	}
	for(int k=0;k<=n;k+=3) ans=(ans+f[n][0][k-1+T]+f[n][1][k+1+T]+f[n][2][k+T])%mod;
	write(ans);
}

Measured memory_bytes: 495116
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <utility>
#include <set>
#include <unordered_set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>
#include <complex>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    ios::sync_with_stdio(0); cin.tie(0);
    
    string s, t;
    cin >> s >> t;
    
    string nxt = s;
    rotate(nxt.rbegin(), nxt.rbegin()+1, nxt.rend());
    
    while (nxt != s)
    {
        if (nxt == t)
        {
            cout << "Yes\n";
            return 0;
        }
        rotate(nxt.rbegin(), nxt.rbegin()+1, nxt.rend());
    }
    
    if (nxt == t) cout << "Yes\n";
    else cout << "No\n";
    
    
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

int main()
{
    int P, Q, R;
    cin >> P >> Q >> R;
    int max_3 = max({P, Q, R});
    cout << P + Q + R - max_3 << endl;
}


Measured memory_bytes: 3572
#ifdef loc
    #include "loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;

typedef long long ll;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define sz(a) int(a.size())
const int N = 3005;
ll a[N], f[N][N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    rep(i, 0, n) {
        cin >> a[i];
        f[i][i] = a[i];
    }
    rep(l, 2, n + 1) {
        rep(j, 0, n - l + 1) {
            f[j][j + l - 1] = max(a[j] - f[j + 1][j + l - 1],
                                  a[j + l - 1] - f[j][j + l - 2]);
            pr(j, j + l - 1, f[j][j + l - 1]);
        }
    }
    cout << f[0][n - 1] << endl;
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    string s;cin>>s;
    ll a=s[s.size()-1]-'0';
    if(a==2||a==4||a==5||a==7||a==9)out("hon");
    else if(a==3)out("bon");
    else out("pon");
}

Measured memory_bytes: 3600
n = int(input())
s = [0]*n
for i in range(n):
    s[i] = int(input())

s_sum = sum(s)
s_sort = sorted(s)

if s_sum % 10 == 0:
    for i in range(n):
        if s_sort[i] % 10 != 0:
            s_sum -= s_sort[i]
            ans = s_sum
            break
        else:
            ans = 0
    print(ans)
else:
    print(s_sum)


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

int main() {
  int H = 0, W = 0;
  cin >> H >> W;
  vector <vector<bool> > grids(H,vector<bool>(W));
  
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      char tmp;
      cin >> tmp;
      
      if (tmp == '.')
      	grids[h][w] = false;
      else
        grids[h][w] = true;
    }
  }
  
  // 全ての黒マスにおいて、それが上下左右いずれかで他の黒マスと隣接しているか調べる
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (!grids[h][w]) continue;
      if (h + 1 < H and grids[h + 1][w]) continue;
      if (w + 1 < W and grids[h][w + 1]) continue;
      if (h - 1 >= 0 and grids[h - 1][w]) continue;
      if (w - 1 >= 0 and grids[h][w - 1]) continue;
      
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>n;
    map<string,ll> mp;
    string s;
    while(n--)
    {
      cin>>s;
      mp[s]++;
    }

    cout<<"AC"<<" x "<<mp["AC"]<<endl;
    cout<<"WA"<<" x "<<mp["WA"]<<endl;
    cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
    cout<<"RE"<<" x "<<mp["RE"]<<endl;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 10680
#include <iostream>
using namespace std;
int main(){
 char r[5];
 char a[5];
 int h,b;
 cin>>r>>a;
 while(1){
if(r[0]=='0'&&a[0]=='0') break;
  for(int i=0;i<4;i++){
   for(int j=0;j<4;j++){
    if(r[i]==a[i]) h++;
    else if(r[i]==a[j]) b++;
    }
   }
  cout<<h/4<<' '<<b<<endl;
  h=0; b=0;
  cin>>r>>a;
  }

 
 return 0;

}

Measured memory_bytes: 1140
#include <stdio.h>
int main(){
	int n,m,b,maxnum;
	scanf("%d%d",&n,&m);
	int a[n+1];
	int B[n+1];
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		B[i]=0;
	}
	for(int i=0;i<m;i++){
		scanf("%d",&b);
		for(int j=0;j<n;j++){
			if(a[j]<=b){
			B[j]+=1;
			break;
			}
		}
	}
	int max=B[0];
        maxnum=0;
	for(int i=1;i<n;i++){
		if(max<B[i]){
			max=B[i];
			maxnum=i;
		}
	}
	printf("%d\n",maxnum+1);
	return 0;
}

Measured memory_bytes: 1032
while true do
    max = -1
    min = 1001
    sum = 0
    n = gets.to_i
    break if n == 0
    n.times do
        v = gets.to_i
        min = v if v < min
        max = v if v > max
        sum += v
    end
    sum -= (min + max)
    p sum / (n-2)
end

Measured memory_bytes: 8616
#include <stdio.h>

long long int max(long long int a,long long int b){
	if(a>b) return a;
	else return b;
}

int main(void) {
	int N,W;
	scanf("%d%d",&N,&W);
	long long int w[N], v[N];
	for(int i=0;i<N;i++){
		scanf("%ld%ld",&w[i],&v[i]);
	}
	long long int dp[N+1][W+1];
	for(int i=0;i<=N;i++){
		for(int j=0;j<=W;j++){
		dp[i][j] = 0;
		}
	}
	
	for(int i=0;i<N;i++){
		for(int j=0;j<=W;j++){
			if(j<w[i]) dp[i+1][j] = dp[i][j];
			else dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
		}
	}
	//printf("%d %d ",N,W);
	printf("%ld",dp[N][W]);
	return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
typedef long long int lli;
using namespace std;

int main(){
	int n,m,cnt;
	while(cin>>n&&n!=0){
		cin >> m;
		string P="";
		cnt=0;
		for(int i=0; i<2*n+1; ++i){
			if(i%2==0){
				P+='I';
			} else {
				P+='O';
			}
		}
		string str;
		cin >> str;
		vector<int> vi(str.size());
		for(int i=m-1; i>1; --i){
			if(str[i]=='I'&&str[i-1]=='O'&&str[i-2]=='I'){
				vi[i-2]=vi[i]+1;
			}
		}
		for(int i=0; i<str.size(); ++i){
			if(vi[i]>=n){
				++cnt;
			}
		}
		cout << cnt << "\n";
	}
	return 0;
}

Measured memory_bytes: 6016
d = 10**9+7
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
x = 0
(0..n-1).each do |i|
  (i+1..n-1).each do |j|
    x += 1 if a[i] > a[j]
  end
end
a = a.sort.reverse
y = 0
(0..n-1).each do |i|
  (i+1..n-1).each do |j|
    y += 1 if a[i] > a[j]
  end
end
ans = (x * k) % d
s = (k * k) % d
t = (k * (k + 1) / 2) % d
z = y * (s - t) % d
ans += z
puts ans % d

Measured memory_bytes: 14320
eval'K,*X='+`dd`.split*?,
j=l=1
x,y,*s=X.map &:abs
d=x+y
x,y=y,x if f=x<y
K%2<d%2&&p(-1)+exit
d!=K&&(l+=[~-d/K,1].max
l+=1&d-K*l
v=K>(t=K*l-d>>1)?0:t-t=K
a=K-t
2.upto(l){s<<(u=f ?-t:a)<<a-t-u
a+=q=[x+v-a,K].min
t-=K-q})
p l,*s.map{_1.*X[j^=1]<=>0.1}+X

Measured memory_bytes: 30124
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
t=int(input())

def dfs(i):
	if i==0:
		return 0
	if i in memo:
		return memo[i]
	ret=i*d
	if i%2==0:
		ret=min(ret,dfs(i//2)+a)
	else:
		ret=min(ret,dfs((i-1)//2)+a+d)
		if not i==1:
			ret=min(ret,dfs((i+1)//2)+a+d)
	if i%3==0:
		ret=min(ret,dfs(i//3)+b)
	elif i%3==1:
		ret=min(ret,dfs((i-1)//3)+b+d)
	else:
		ret=min(ret,dfs((i+1)//3)+b+d)
	if i%5==0:
		ret=min(ret,dfs(i//5)+c)
	elif i%5==1:
		ret=min(ret,dfs((i-1)//5)+c+d)
	elif i%5==2:
		ret=min(ret,dfs((i-2)//5)+c+2*d)
	elif i%5==3:
		ret=min(ret,dfs((i+2)//5)+c+2*d)
	else:
		ret=min(ret,dfs((i+1)//5)+c+d)
	memo[i]=ret
	return ret

ans=[]
for _ in range(t):
	n,a,b,c,d=map(int,input().split())
	memo={}
	ans.append(dfs(n))
print("\n".join(map(str,ans)))

Measured memory_bytes: 10988
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long ans=1;
		for(int i=0;i<n;i++){
			ans=lcm(ans,sc.nextLong());
		}
		System.out.println(ans);
	}
	static long gcd(long a,long b){
		if(b==0){
			return a;
		}else{
			return gcd(b,a%b);
		}
	}
	static long lcm(long a,long b){
		return (a>b)?(a/gcd(a,b))*b:(b/gcd(a,b))*a;
	}
}


Measured memory_bytes: 22356
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define NIL -1

int N,M,Q,s,t;
vi T[100005], Color;

void dfs(int r, int c){
    stack<int> S;
    S.push(r);
    Color[r] = c;
    while(!S.empty()){
        int u = S.top(); S.pop();
        rep(i, T[u].size()){
            int v = T[u][i];
            if(Color[v] == NIL){ //色が違っていたらスタックに入れて探索する
                Color[v] = c;
                S.push(v);
            }
        }
    }
}

void AssignColor(){
    int id = 1;

    Color.resize(N,NIL);

    rep(u,N){ //色が違っていたらスタックに入れて探索する
        if(Color[u] == NIL) dfs(u,id++);
    }
}

void solve(int s, int t){
    if(Color[s] == Color[t]) cout << "yes" << endl;
    else cout << "no" << endl;
}

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

    rep(i,M){
        cin >> s >> t;
        T[s].push_back(t);
        T[t].push_back(s);
    };

    AssignColor();

    cin >> Q;

    rep(i,Q){
        cin >> s >> t;
        solve(s, t);
    };
}



Measured memory_bytes: 8616
#include <stdio.h>

int main()
{
    int a, b, c, d, e;
    scanf ("%d %d %d %d %d", &a, &b, &c, &d, &e);
    
    if (c >= e && d >= e && (b - e) >= d && (a - e) >= c)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++1)
typedef long long ll;
typedef pair<int,int> P;
P f(int x){
    int a=x%10;
    int b=x;
   
    
    while(x){b=x;x/=10;}
    

    return P(a,b);
}
int main(){
    int n;
    cin>>n;
    map<P,int> freq;
    for(int i=1;i<=n;i++){
        P p=f(i);
        freq[p]++;
    }
    ll ans=0;
    for(int i=0;i<=n;i++){
        P p=f(i);
        P q(p.second,p.first);
        ans+=freq[q];
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    ll N, W;  cin >> N >> W;
    vector<ll> w(N+1), v(N+1);
    for(int i=1; i<=N; i++) cin >> w[i] >> v[i];

    vector<vector<ll>> dp;
    dp = vector<vector<ll>>(N+1, vector<ll>(W+1, 0));
    for(int j=0; j<=W; j++){ // (1)
        if(j == w[1]) dp[1][j] = v[1];
    }

    for(int i=2; i<=N; i++){
        for(int j=0; j<=W; j++){
            if(w[i] <= j){
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    ll ans = 0;
    for(int i=0; i<=W; i++) ans = max(ans, dp[N][i]);
    cout << ans << endl;
}


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

int main(){
	int n,k;
	cin>>n>>k;
	
	int a[n+3];
	for(int i=0;i<n;i++)  cin>>a[i];
	
	sort(a,a+n);
	int sum=0;
	for(int i=0;i<k;i++){
		sum+=a[i];
	}
	
	cout<<sum;
	return 0;
}  

Measured memory_bytes: 3596
N,K=map(int,input().split())
A=list(map(int,input().split()))
def divisor(n):
    d0=[]
    d1=[]
    for i in range(1,int(n**.5)+1):
        x,y=divmod(n,i)
        if y==0:
            d0.append(i)
            d1.append(x)
    if d1[-1]==d0[-1]:
        d1=d1[:-1]
    return d0+d1[::-1]
D=divisor(sum(A))
r=1
for d in D[::-1]:
    x=sorted([a%d for a in A])
    for i in range(len(A)-1):
        x[i+1]+=x[i]
    if x[-1]%d==0 and x[-1-x[-1]//d]<=K:
        r=d
        break
print(r)

Measured memory_bytes: 3188
#include <stdio.h>
int n, x, c;
int a[100000];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
		a[i]--;
	}
	for (int i = 0; i < n; i++) {
		c++;
		if (a[x] != 1) {
			x = a[x];
		}
		else break;
	}
	if (c != n)printf("%d\n", c);
	else printf("-1\n");
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cassert>
#include <queue>
#define int long long
using namespace std;

int INF = 1e+15;
int n, m;
vector<int> et[1000];
vector<int> ec[1000];

vector<int> rev_et[1000];
bool cango[1000];

int dp[1000];

void make() {	//到達可能性
	queue<int> que;
	cango[n - 1] = true;
	que.push(n - 1);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (int i = 0; i < rev_et[v].size(); i++) {
			if (cango[rev_et[v][i]]) continue;
			cango[rev_et[v][i]] = true;
			que.push(rev_et[v][i]);
		}
	}
}

signed main() {
	int i;
	
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		et[a].push_back(b);
		ec[a].push_back(c);
		rev_et[b].push_back(a);
	}
	
	make();
	
	for (i = 0; i < n; i++) { dp[i] = -INF; }
	
	queue<int> que;
	que.push(0); dp[0] = 0;
	
	int loop = 0;
	while(!que.empty()) {
		int v = que.front(); que.pop();
		for (int i = 0; i < et[v].size(); i++) {
			if (!cango[et[v][i]] || dp[et[v][i]] >= dp[v] + ec[v][i]) continue;
			dp[et[v][i]] = dp[v] + ec[v][i];
			que.push(et[v][i]);
		}
		loop++;
		if (loop >= 5000000) {
			break;
		}
	}
	
	if (loop >= 5000000) { cout << "inf" << endl; }
	else { cout << dp[n - 1] << endl; }
	
	return 0;
}

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


int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i = 0;i<n;i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    int sum = 0;
    for(int i = 0;i<k;i++){
        sum += v[i];
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b,c;
    cin >> a >> b>>c;
    if((a==b&&a!=c)||(b==c&&b!=a)||(c==a&&c!=b))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b)
{if (a < b) {a = b; return true;} return false;}
template<class T> inline bool chmin(T& a,T b)
{if (a > b) {a = b; return true;} return false;}

int main(){
    int N, W;
    cin >> N >> W;
    vector<int> weight(N);
    vector<long long> value(N);
    for (int i = 0; i < N; ++i) {
        cin >> weight[i] >> value[i];
    }
    long long dp[110][100100] = {0};
    
    for (int i = 0; i < N; ++i) {
        for(int w = 0; w <= W; ++w) {
            if (w >= weight[i]) {
                chmax(dp[i + 1][w], dp[i][w - weight[i]] + value[i]);
            }
            chmax(dp[i + 1][w], dp[i][w]);
        }
    }
    
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 86272
#include<bits/stdc++.h>
#define ll long long int
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
using namespace std;

int main()
{
	 
   boost
   #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t=1;
// 	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int a[n];
	    for(int i=0;i<n;i++)
	    cin>>a[i];
	    sort(a,a+n);
	    ll res=0;
	    for(int i=n-2;i>=n/2;i--){
	        res+=a[i+1];
	    }
	    int j = n-1-n/2;
	    int i = n/2-1;
	    for(i=n/2-1;i>=0;i--){
	        if(i+j<n/2) break;
	        res+=a[i+j];
	    }
	    if(i==0) res+=a[n/2];
	    cout<<res<<"\n";
	}
    return 0;
}


Measured memory_bytes: 4440
// ProblemURL : https://atcoder.jp/contests/abc125/tasks/abc125_c
// ---------------------------------------------
package main

import "fmt"

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func chmax(a *int, b int) {
	if *a < b {
		*a = b
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	lCumGCD := make([]int, n+1)
	for i := 1; i < n+1; i++ {
		lCumGCD[i] = gcd(lCumGCD[i-1], a[i-1])
	}

	rCumGCD := make([]int, n+1)
	for i := n - 1; i >= 0; i-- {
		rCumGCD[i] = gcd(rCumGCD[i+1], a[i])
	}

	mxgcd := -1
	for i := 0; i < n; i++ {
		chmax(&mxgcd, gcd(lCumGCD[i], rCumGCD[i+1]))
	}
	fmt.Println(mxgcd)
}


Measured memory_bytes: 5504
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

bool comp_t(pair <int, int> t1, pair <int, int> t2)
{
    return t1.first<t2.first|| (t1.first==t2.first&& t1.second<t2.second);
}

int main()
{
    int n, m, q;
    cin>>n>>m>>q;
    int t[n][n];
    int a[n][n];
    int l,r;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            t[i][j]=0;
            a[i][j]=0;
        }
    }
    for(int i=0; i<m; i++)
    {
        cin>>l>>r;
        t[l-1][r-1]++;
    }
    
    for(int i=0; i<n; i++)
    {
        a[i][i]=t[i][i];
    }
    for(int i=n-2; i>=0; i--)
    {
        for(int j=i+1; j<n; j++)
        {
            a[i][j] = a[i+1][j]+ a[i][j-1] -a[i+1][j-1] + t[i][j];
        }
    }
    for(int i=0; i<q; i++)
    {
        cin>>l>>r;
        cout<<a[l-1][r-1]<<endl;
    }
    
	return 0;
}


Measured memory_bytes: 2816
N = int(input())
a = list(map(int, input().split()))

mean = sum(a)/N
ind = None
min = None
for i in range(N):
    tmp=abs(mean-a[i])
    if min is None:
        min=tmp
        ind=i
    else:
        if tmp<min:
            min=tmp
            ind=i

print(ind)

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if (A != B) cout << max(A, B) * 2 - 1 << endl;
    else cout << 2 * A << endl;
    return 0;
}

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

int main(){

    int N, count=0;
    string S;
    cin >> S;
    N = S.size();

    for(int i=0; i< N/2; i++){
        if(S[i] != S[N-1-i]) count++;
    }

    cout << count << endl;
}

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

#define ll long long
#define ii pair<int, int>

const int N = 2e5 + 10;

int main()
{
    int r;
    cin >> r;
    if (r < 1200)
    {
        cout << "ABC" << endl;
        return 0;
    }
    if (r < 2800)
    {
        cout << "ARC" << endl;
        return 0;
    }
    cout << "AGC" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
	Scanner s = new Scanner(System.in);
	while(s.hasNext()){
	    int[] l = {1,2,3,4,5,6,7,8,9,10};
	    int[] a = new int[3];
	    for(int i=0 ; i<3 ; i++)
		a[i] = s.nextInt();
	    for(int i=0 ; i<10 ; i++){
		if(a[0]==l[i] || a[1]==l[i] || a[2]==l[i])
		    l[i] = 100;
	    }
	    int b = 0;
	    for(int i=0 ; i<10 ; i++){
		if(l[i]<=20-a[0]-a[1])
		    b++;
	    }
	    if(b>3)
		System.out.println("YES");
	    else
		System.out.println("NO");
	}
    }
}

Measured memory_bytes: 12000
#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt;
use std::io::{self, BufWriter, Read, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};


fn solve(a: i32, b: i32, c: i32) -> i32 {
    if a == b {
        c
    } else if b == c {
        a
    } else {
        b
    }
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    println!("{}", solve(sc.next(), sc.next(), sc.next()));
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(1024),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        let buf = &mut self.buf;
        buf.clear();
        self.bytes
            .by_ref()
            .map(Result::unwrap)
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
            .foreach(|c| buf.push(c));
        str::from_utf8(&buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
        <T3 as FromStr>::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }
}


trait Foreach {
    type Item;
    fn foreach<F: FnMut(Self::Item)>(self, f: F);
}

impl<T, I: Iterator<Item = T>> Foreach for I {
    type Item = T;

    fn foreach<F: FnMut(T)>(self, mut f: F) {
        self.fold((), move |(), x| f(x));
    }
}


#[allow(dead_code)]
fn print_yesno(x: bool, yes: &'static str, no: &'static str) {
    println!("{}", if x { yes } else { no });
}


#[allow(dead_code)]
fn print_foreach<T: fmt::Display, I: IntoIterator<Item = T>>(xs: I) {
    let stdout = io::stdout();
    let mut stdout = BufWriter::new(stdout.lock());
    for x in xs.into_iter() {
        writeln!(stdout, "{}", x).unwrap();
    }
    stdout.flush().unwrap();
}


#[allow(dead_code)]
fn print_or<T: fmt::Display>(x: Option<T>, or: &'static str) {
    if let Some(x) = x {
        println!("{}", x);
    } else {
        println!("{}", or);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}


void solve(){
	int a, b;
	cin>>a>>b;
	if(max(a, b)<= 8) cout<<"Yay!"<<endl;
	else cout<<":("<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;



int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
//#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h1,h2,m1,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int hour = (h2-h1)*60;
    int min = m2-m1;
    hour = hour + min;
    if(hour-k>0){
        cout<<hour-k;
    }
    else{
        cout<<"0";

    }



    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int limit = 10000;
const pair<int,int> illegal(limit+1, limit+1);

pair<int,int> inv(pair<int,int> a){
    if(abs(a.first)>limit or abs(a.second)>limit){
        return illegal;
    }
    return {-a.first, -a.second};
}
pair<int,int> sum(pair<int,int> a, pair<int,int> b){
    if(abs(a.first)>limit or abs(a.second)>limit or abs(b.first)>limit or abs(b.second)>limit){
        return illegal;
    }
    pair<int,int> res(a.first+b.first, a.second+b.second);
    if(abs(res.first)>limit or abs(res.second)>limit){
        return illegal;
    }
    return res;
}
pair<int,int> prod(pair<int,int> a, pair<int,int> b){
    if(abs(a.first)>limit or abs(a.second)>limit or abs(b.first)>limit or abs(b.second)>limit){
        return illegal;
    }
    pair<int,int> res(a.first*b.first -a.second*b.second, a.first*b.second +a.second*b.first);
    if(abs(res.first)>limit or abs(res.second)>limit){
        return illegal;
    }
    return res;
}

int parse_num(int &p, string &s){
    int res = 0;
    while(p<(int)s.length() and '0'<=s[p] and s[p]<='9'){
        res *= 10;
        res += s[p]-'0';
        p++;
        if(res > limit) res = limit+1;
    }
    return res;
}
pair<int,int> parse_expr(int &p, string &s){
    pair<int,int> res(0, 0);
    pair<int,int> curr(0, 0);
    char opr = '+';
    while(p < (int)s.length()){
        if(s[p] == ')'){
            p++;
            break;
        }
        if(s[p]=='+' or s[p]=='-' or s[p]=='*'){
            opr = s[p];
            p++;
        }else{
            pair<int,int> ret(0, 0);
            if(s[p] == '('){
                ret = parse_expr(++p, s);
            }else if(s[p] == 'i'){
                p++;
                ret.second = 1;
            }else{
                ret.first = parse_num(p, s);
            }
            if(opr == '*'){
                curr = prod(curr, ret);
            }else{
                res = sum(res, curr);
                if(opr == '+'){
                    curr = ret;
                }else{
                    curr = inv(ret);
                }
            }
        }
    }
    res = sum(res, curr);
    return res;
}

int main(){
    string s;
    while(cin >> s){
        int p = 0;
        auto ret = parse_expr(p, s);
        if(ret.first > 10000){
            cout << "overflow" << endl;
        }else{
            if(ret.first == 0 and ret.second == 0){
                cout << "0" << endl;
            }else{
                if(ret.first != 0){
                    cout << ret.first;
                }
                if(ret.second != 0){
                    if(ret.second > 0 and ret.first != 0){
                        cout << "+";
                    }
                    cout << ret.second << "i";
                }
                cout << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>

int main(){
  int n,d[101],min=100,i;
  char s[101],ans[201];
  scanf("%d",&n);
  scanf("%s",s);
  d[0]=0;
  for(i=0;i<n;i++){
    if(s[i]=='(')
      d[i+1]=d[i]+1;
    else
      d[i+1]=d[i]-1;
    if(min>d[i+1])
      min=d[i+1];
  }
  for(i=0;i<-min;i++)
    printf("(");
  printf("%s",s);
  for(i=0;i<d[n]-min;i++)
    printf(")");
  if(min==1)
    printf(")");
  printf("\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MxN 1000000

int fac[MxN] = {0};

int main()
{
    int n;
    cin >> n;
    int a[n];
    map<int, int> m;
    int ma = -1;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        m[a[i]]++;
        ma = max(ma, a[i]);
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 2 * a[i]; j < ma + 1; j += a[i])
        {
            fac[j] = 1;
        }
    }
    int ans = n;
    for (int i = 0; i < n; i++)
    {
        if (fac[a[i]] == 1 || m[a[i]] > 1)
        {
            ans--;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 16804
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for(ll i = 2; i <= n; ++i) {
      if(f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for(ll j = i * i; j <= n; j += i) {
        if(!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while(x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if(fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for(int p : fl) {
      if(res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  Sieve sieve(1e6);
  map<int, int> fa;
  rep(i, n) {
    vector<P> ifa = sieve.factor(a[i]);
    for(auto p : ifa) fa[p.first] = max(fa[p.first], p.second);
  }
  mint mlca = 1;
  for(auto p : fa) {
    mint a = p.first;
    a = a.pow(p.second);
    mlca *= a;
  }
  mint ans = 0;
  rep(i, n) ans += (mlca / a[i]);
  printf("%d", ans);
}

Measured memory_bytes: 4988
#include <iostream>
using namespace std;
 
long long int gcd(long long int x,long long int y) {
  if(y == 0) return x;
  else {
    return gcd(y,x % y);
  }
}
int main() {
  long long int a,b;
  while(cin >> a >> b) {
    cout << gcd(a,b) << " " << a * b / gcd(a,b) << endl;
  }
}


Measured memory_bytes: 1156
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include<stack>
#include<climits>
using namespace std;

#define int long long
#define MOD (1000000007)
#define MINF (-1*(LLONG_MAX-10))
#define INF (LLONG_MAX-10)

signed main(){
    int N,M,P;
    vector<pair<int,int>> v[2501];
    vector<pair<int,int>> vr[2501];
    cin>>N>>M>>P;
    for(int i=0;i<M;i++){
        int A,B,C;
        cin>>A>>B>>C;
        v[A].push_back(make_pair(B,C-P));
        vr[B].push_back(make_pair(A,C-P));
    }

    stack<int> s;
    s.push(N);
    bool f[2501];
    for(int i=0;i<2501;i++){
        f[i]=false;
    }
    f[N]=true;
    while(!s.empty()){
        int n=s.top();
        s.pop();
        for(int i=0;i<vr[n].size();i++){
            int t=vr[n][i].first;
            if(!f[t]){
                f[t]=true;
                s.push(t);
            }
        }
    }

    s.push(1);
    int mm[2501];
    int mc[2501]={0};
    for(int i=0;i<2501;i++){
        mm[i]=MINF;
    }
    mm[1]=0;
    while(!s.empty()){
        int n=s.top();
        s.pop();
        for(int i=0;i<v[n].size();i++){
            int t=v[n][i].first;
            int c=v[n][i].second;
            int nc=c+mm[n];
            //cout<<n<<","<<t<<","<<c<<","<<nc<<","<<mm[t]<<endl;
            if((nc>mm[t]||mm[t]==MINF)&&f[t]){
                mm[t]=nc;
                mc[t]=mc[n]+1;
                if(mc[t]==2550){
                    cout<<"-1"<<endl;
                    return 0;
                }
                s.push(t);
            }
        }
    }
    if(mm[N]>0) cout<<mm[N]<<endl;
    else cout<<"0"<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;

int MOD=1000000007;

ll N,A,B,C;
vector<ll> l;
 
int dfs(int n, int a, int b, int c) {
	if (n==N) {
		if(a==0 || b==0 || c==0){
			return 2e5;
		}
		int tmp=abs(a-A)+abs(b-B)+abs(c-C)-30;
		return tmp; 
	}
	int ans1=dfs(n+1,a,b,c);
	int ans2=dfs(n+1,a+l[n],b,c)+10;
	int ans3=dfs(n+1,a,b+l[n],c)+10;
	int ans4=dfs(n+1,a,b,c+l[n])+10;
 
	return min({ans1, ans2, ans3, ans4});
}


int main() {
  cin >> N >> A >> B >> C;
  l.resize(N);
  for(ll i=0; i<N; i++) cin >> l[i];
  cout << dfs(0,0,0,0) << endl;
}

Measured memory_bytes: 256
S = gets.chomp
A = S.split('')
B = 'abcdefghijklmnopqrstuvwxyz'
C = B.split('')
A.uniq!
for i in 0..A.length-1
    C.delete(A[i])
end

if C.size > 0
    puts C[0]
else
    puts 'None'
end

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

using namespace std;

int main(){
  int x1, y1, x2, y2,x3,y3,x4,y4;
  scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  int mid = (x2 - x1) + (y2 - y1);
  int left = (y2 - x2) + (x1 - y1);
  //printf("Left %d\n", left);
  y3 = y1 + mid;
  left = left * -1; 
  x4 = x2 - mid;
  x3 = left + x1; 
  y4 = left + y2; 
  printf("%d %d %d %d\n", x3, y3, x4, y4);
  return 0;
}


Measured memory_bytes: 256
package main

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

func solve() {
	n := getInt()
	cSum := make([]int, n+1)
	for i := 1; i <= n; i++ {
		a := getInt()
		cSum[i] = cSum[i-1] + a
	}

	ans := cSum[n]+1
	for i := range cSum {
		x, y := cSum[i], cSum[n]-cSum[i]
		z := abs(x - y)
		ans = min(ans, z)
	}

	fmt.Fprintln(wr, ans)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

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

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n,cost[101],x,y,z,b,a,p;
	string name[101],str;
	while(cin>>n,n){
		for(int i=1;i<=n;i++)cin>>name[i]>>cost[i];
		cin>>x;
		for(int i=1;i<=x;i++){
			cin>>str>>y;
			for(int j=1;j<=n;j++)if(str==name[j])b=cost[j],p=j;
			a=0;
			for(int j=1;j<=y;j++){
				cin>>str;
				for(int k=1;k<=n;k++)if(str==name[k])a+=cost[k];
			}
			if(b>a)cost[p]=a;
		}
		cin>>str;
		for(int i=1;i<=n;i++)if(str==name[i])cout<<cost[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 1208
n = gets.to_i
g = []
n.times do
  s = gets.chomp.chars
  h = Hash.new(0)
  s.each do |x|
    h[x] += 1
  end
  g.push(h)
end
f = Hash.new(0)
g.each do |x|
  x.each_entry do |k, v|
    f[k] += v
  end
end
f = f.sort_by{|k, v| k}
ans = ""
f.each_entry do |k, v|
  c = g.map{|hash| hash[k]}.min
  ans.concat(k * c) if c > 0
end
puts ans

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

int main() {
  int n ,m, k = 0;
  cin >> n >> m;
  if (n <= 1){

  }
  else{
      k= k + n*(n-1)/2;
  }
  if(m <= 1){

  }
  else{
      k = k + m*(m-1)/2;
  }
  cout << k  << endl;
}

Measured memory_bytes: 256