akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

vll num;
ll N;
vvl G = VV(5001, 0, 0, ll);
ll INF = 1000000000000000000;
vvvl dp = VVV(5001, 0, 0, INF);
vll sz(5001, -1);

void dfs(ll now, ll from){
  ll now_sz = 1;
  vvl prev = VV(2, 2, INF, ll);
  vvl dat = VV(2, 2, INF, ll);
  dat[1][0] = num[now];
  if(num[now]>0) dat[1][1] = num[now];

  for(auto to:G[now]){
    if(to==from) continue;
    dfs(to, now);
    prev = dat;
    dat = VV(now_sz+sz[to]+1, 2, INF, ll);

    ll minit_zero = INF, minit_one = INF;
    for(int i=1;i<=sz[to];i++){
      if(dp[to][i][1]!=INF&&minit_one==INF) minit_one = i;
      if(dp[to][i][0] < 0&&minit_zero==INF) minit_zero = i;
    }

    ll x = min(minit_one, minit_zero);
    for(int i=1;i<=now_sz;i++){
      //分離
      if(i+x>N) continue;
      if(x!=INF){
        dat[i+x][0] = min(dat[i+x][0], prev[i][0]);
        dat[i+x][1] = min(dat[i+x][1], prev[i][1]);
      }
    }

    for(int i=1;i<=now_sz;i++){
      for(int j=1;j<=sz[to];j++){
        if(i+j>N) continue;
        //連結
        dat[i+j-1][0] = min(dat[i+j-1][0],
          prev[i][0] + dp[to][j][0]);
        dat[i+j-1][1] = min(dat[i+j-1][1],
          prev[i][1] + dp[to][j][1]);
      }
    }
    now_sz += sz[to];
  }
  sz[now] = now_sz;
  dp[now] = dat;
}

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  N = n;
  num.resize(n);
  re(i, n) scanf("%lld", &num[i]);
  for(int i=0;i<n-1;i++){
    ll a, b;scanf("%lld %lld", &a, &b);
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(0, -1);
  for(int i=1;i<=N;i++){
    if(dp[0][i][0]<0||dp[0][i][1]!=INF){
      std::cout << i - 1 << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 571264
n = int(input())
l = [0] * n
for i in range(n):
    l[i] = int(input())
l.sort(reverse=True)
ans1 = 0
ans2 = 0
if n % 2 == 1:
    for i in range((n-3)//2):
        ans1 += 2 * l[i]
    ans1 += l[(n-3)//2] + l[(n-3)//2+1]
    for i in range((n-3)//2+2, n):
        ans1 -= 2 * l[i]

    for j in range((n-1)//2):
        ans2 += 2 * l[j]
    ans2 -= l[(n-1)//2] + l[(n-1)//2+1]
    for j in range((n-1)//2+2, n):
        ans2 -= 2 * l[j]

else:
    for i in range(((n-2)//2)):
        ans1 += 2 * l[i]
    ans1 += l[(n-2)//2]
    ans1 -= l[(n-2)//2+1]
    for i in range((n-2)//2+2, n):
        ans1 -= 2 * l[i]

ans = max(ans1, ans2)
print(ans)

Measured memory_bytes: 7472
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main() {
	int a[26] = {};
	string s, p;
	getline(cin, s);
	getline(cin, p);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == p[0]) {
			bool match = true;
			for (int j = 0; j < p.size(); j++) {
				if (s[(i + j) % s.size()] != p[j]) {
					match = false;
					break;
				}
			}
			if (match) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}



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

int main(){

  int N,T;
    cin>>N>>T;
    vector<int> A(N+1);
    long int ans=T;
    for(int i=0;i<N;i++){
        cin>>A[i+1];
        ans+=min(A[i+1]-A[i],T);
    }
    cout<<ans<<endl;
}
    


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

signed main(){
    int a,b,c;
    cin >> a >> b >>c;
    if(a+b+c<=21){
        cout<<"win"<<endl;
    }
    else{
        cout<<"bust"<<endl;
    }
}

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

#define swap(type,a,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(int i=0;i<n;i++)
#define forS(i,start,n) for(int i=start;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}
#define DOUBLE fixed << setprecision(15)

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

bool cmp(vi,vi);
int main(){
    int n,m,cnt=0;
    string s;

    int a,b,k;
    cin>>a>>b>>k;
    int i;
    for(i=100;cnt<k&&i>0;i--){
        if(a%i ==0 && b%i==0){
            cnt++;
        }
    }
    cout << i+1 << endl;
}

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

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

    int ans = 0;
    do {
        int a = n % 10;
        n /= 10;

        if (a == 9) {
            ans += 9;
        } else {
            if (n > 0) {
                ans += 9;
                n--;
            } else {
                ans += a;
            }
        }

    } while (n > 0);

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

struct Elm {
  int r, c;
  int cnt;
  bool prevb;
};

bool operator< (const Elm &e1, const Elm &e2) {
  if(e1.cnt == e2.cnt) return e1.prevb;
  else return e1.cnt < e2.cnt;
}

vi dr = {1, 0};
vi dc = {0, 1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int h, w; cin >> h >> w;
  vector<string> v(h);
  for(int i=0;i<h;++i) {
    cin >> v[i];
  }

  priority_queue<Elm> pq;
  vvi d(h, vi(w, INF));
  if(v[0][0] == '.') {
    pq.push({0, 0, 0, false});
    d[0][0] = 0;
  } else {
    pq.push({0, 0, 1, true});
    d[0][0] = 1;
  }

  while(!pq.empty()) {
    auto now = pq.top(); pq.pop();
    if(now.cnt > d[now.r][now.c]) continue;
    for(int i=0;i<2;++i) {
      int nxtr = now.r + dr[i], nxtc = now.c + dc[i];
      if(!(0 <= nxtr && nxtr < h && 0 <= nxtc && nxtc < w)) continue;
      if(now.prevb || v[nxtr][nxtc] == '.') {
        if(d[nxtr][nxtc] > now.cnt) {
          pq.push({nxtr, nxtc, now.cnt, v[nxtr][nxtc] == '#'});
          d[nxtr][nxtc] = now.cnt;
        }
      } else if(v[nxtr][nxtc] == '#') {
        if(d[nxtr][nxtc] > now.cnt + 1) {
          pq.push({nxtr, nxtc, now.cnt + 1, true});
          d[nxtr][nxtc] = now.cnt + 1;
        }
      }
    }
  }

  cout << d[h-1][w-1] << endl;


}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>

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

using namespace std;

const int mod = 1e9 + 7;

typedef long long ll;

int n;
char a[51];
char b[51];
char c[51];
int dp[51][2];

int add(int a, int b){
	return (a + b) % mod;
}

int main(){
	while(scanf("%s", a), scanf("%s%s", b, c) != EOF){
		n = strlen(a);
		rep(i, n + 1){
			fill_n(dp[i], 2, 0);
		}
		dp[0][0] = 1;
		for(int i = 1; i <= n; ++i){
			rep(s, 10){
				int p = a[n - i] == '?' ? s : a[n - i] - '0';
				rep(t, 10){
					int q = b[n - i] == '?' ? t : b[n - i] - '0';
					rep(u, 10){
						int r = c[n - i] == '?' ? u : c[n - i] - '0';
						if(i == n && (!p || !q || !r)){
							continue;
						}

						if((p + q) % 10 == r){
							dp[i][(p + q) / 10] = add(dp[i][(p + q) / 10], dp[i - 1][0]);
						}
						else if((p + q + 1) % 10 == r){
							dp[i][(p + q + 1) / 10] = add(dp[i][(p + q + 1) / 10], dp[i - 1][1]);
						}

						if(c[n - i] != '?'){
							break;
						}
					}

					if(b[n - i] != '?'){
						break;
					}	
				}

				if(a[n - i] != '?'){
					break;
				}
			}

			// printf("%d %d\n", dp[i][0], dp[i][1]);
		}
		printf("%d\n", dp[n][0]);
	}
	return 0;
}

Measured memory_bytes: 972
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N;
      cin >> N;
      vector<int> X(N);//初期化されてる
      int box=1;
      
      for(int i=0;i<N;i++){
        cin >> X.at(i);
      }
      
      for(int i=0;i<N;i++){
        if(X.at(box-1)==2){
          cout << i+1 << endl;
          break;
        }else{
          box=X.at(box-1);
        }
        if(i==N-1){
          cout << -1 << endl;
        }
      }
      
    }

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
   int n,k;
    cin>>n>>k;
    int s=0;
    int t;
    for(int i=0;i<k;i++) cin>>t,s+=t;
    if(s<=n)
    cout<<n-s;
    else
        cout<<-1;
    return 0;
}

Measured memory_bytes: 3632
S = input()
ACGT = ['A', 'C', 'G', 'T']
ans = [0] * len(S)

for i in range(len(S)):
    if S[i] in ACGT:
        cnt = 1
        for j in range(len(S) - i - 1):
            if S[i+j+1] in ACGT:
                cnt += 1
            else:
                ans[i] = cnt
                break
        ans[i] = cnt

print(max(ans))

Measured memory_bytes: 61784
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

const int N=2005;
const int P=1000000007;

struct edge{
	int v,len;
	edge *next;
}pool[600005],*h[N];

int n,m,top=-1;
long long C,res;
long long ans;
int p[N],cnt_w,cnt_b;

inline long long ksm(long long base,long long x){
	long long wes=1;
	while(x){
		if(x&1) wes*=base,wes%=P;
		base*=base,base%=P;
		x>>=1;
	}
	return wes;
}

inline void addedge(int u,int v,int len){
	edge *tmp=&pool[++top];
	tmp->v=v;tmp->next=h[u];h[u]=tmp;
	tmp->len=len;
}

struct task{
	int u,v,len;
	int type;
	inline task(){}
	inline task(int _u,int _v,int _len){
		u=_u;
		v=_v;
		len=_len;
	}
	inline void add(){
		addedge(u,v,len);
		addedge(v,u,len);
	}
	inline bool operator<(const task &w)const{
		return len<w.len;
	}
}a[N];

int find(int x){
	if(p[x]==0) return x;
	return p[x]=find(p[x]);
}

inline bool onion(int x,int y){
	x=find(x); y=find(y);
	if(x==y) return false;
	p[x]=y;
	return true;
}

inline bool test_onion(int x,int y){
	x=find(x); y=find(y);
	if(x==y) return false;
	return true;
}

int dfs(int u,int pre,int T){
	if(u==T) return 0;
	int wes=-1;
	for(edge *tmp=h[u];tmp!=NULL;tmp=tmp->next){
		int v=tmp->v;
		if(v==pre) continue;
		int w=dfs(v,u,T);
		if(w!=-1) wes=max(wes,max(tmp->len,w));
	}
	return wes;
}

#define multi(x,y) ((x)*(y)%P)

void init(){
	int x1,x2,x3;
	scanf("%d%d%lld",&n,&m,&C);
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&x1,&x2,&x3);
		a[i]=task(x1,x2,x3);
	}
	sort(a+1,a+m+1);
	for(int i=1;i<=m;){
		int j=i;
		while(a[j+1].len==a[i].len) j++;
		for(int t=i;t<=j;t++) if(test_onion(a[t].u,a[t].v)==true) a[t].type=true,cnt_w++; //cnt_w : number of whites
		for(int t=i;t<=j;t++) if(onion(a[t].u,a[t].v)==true) res+=a[t].len; //res : sum of whites
		i=j+1;
	}
	if(res==C){
		printf("%lld\n",(P+ksm(2,m)-ksm(2,m-cnt_w+1))%P);
		return ;
	}
	memset(p,0,sizeof(p));
	for(int i=1;i<=m;i++){
		if(a[i].type==true){
			if(onion(a[i].u,a[i].v)==true) a[i].add();
			continue;
		}
		int maxlen=dfs(a[i].u,0,a[i].v);
		if(res-maxlen+a[i].len<C) cnt_w++;
		if(res-maxlen+a[i].len==C) cnt_b++;
	}
	//printf("qwq\n");
	//printf("m=%d , w=%d , b=%d\n",m,cnt_w,cnt_b);
	printf("%lld\n",(P+ksm(2,m-cnt_w+1)-ksm(2,m-cnt_w-cnt_b+1))%P);
}

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

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


int main() {
  int A,B,C,D,E;
  cin >> A >> B >> C >> D >>E;
int minimini = min({(A-1)%10,(B-1)%10,(C-1)%10,(D-1)%10,(E-1)%10});
int amari = 10-minimini-1;

cout << (A-1)/10*10+(B-1)/10*10+(C-1)/10*10+(D-1)/10*10+(E-1)/10*10+50-amari <<endl;




  }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;
long long gcd(long long m, long long n){
  if(m < n){
    return gcd(n, m);
  } else if(n == 0){
    return m;
  }
  return gcd(n, m % n);
}

int main(){
  int K;
  cin >> K;
  long long ans = 0;
  for(int i = 1; i <= K; i++){
    for(int j = 1; j <= K; j++){
      for(int k = 1; k <= K; k++){
        ans += gcd(i, gcd(j, k));
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3676
import sys

N, M = map(int, input().split())
# set_a = set([int(input()) for _ in range(M)])
if M > 0:
    set_a = set(map(int, sys.stdin))
else:
    set_a = set()
MOD = 10**9 + 7

dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 0 if 1 in set_a else 1
for i in range(2, N+1):
    dp[i] = 0 if i in set_a else (dp[i-1] + dp[i-2]) % MOD
ans = dp[N]
print(ans)

Measured memory_bytes: 11884
n = int(input())
x = []
u = []

for i in range(n):
    temp1, temp2 = input().split()
    x.append(float(temp1))
    u.append(temp2)

total = 0

for i in range(n):
    if u[i] == 'JPY':
        total += x[i]
    else:
        total += x[i] * 380000

print(total)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Math;

class Program{
    static int a = 0;
    static int b = 0;
    static int c = 0;

    static void Main(){
        int n = int.Parse(Console.ReadLine());
        string[] s = new string[n];
        for (int i = 0;i < n;i++) s[i] = Console.ReadLine();

        int ans = 0;
        foreach (var si in s) ans += Count(si);

        if (a == 0 && b == 0){
            ans += Max(0,c - 1);
            goto END;
        }
        ans += Min(a+c,b+c);
    
        END:
        Console.WriteLine(ans);
    }

    static int Count(string s){
        int n = s.Length;
        if (s[0] != 'B' && s[n - 1] == 'A') a++;
        if (s[0] == 'B' && s[n - 1] != 'A') b++;
        if (s[0] == 'B' && s[n - 1] == 'A') c++;
        int v = 0;
        for (int i = 0;i < n - 1;i++)
            if (s[i] == 'A' && s[i + 1] == 'B')
                v++;
        return v;
    }
}

Measured memory_bytes: 13244
import kotlin.math.min

fun main() {
    val (n, m, x) = readLine()!!.split(" ").map { it.toInt() }
    val items = (0 until n).map {
        readLine()!!.split(" ").map { it.toInt() }
    }

    var money = -1
    fun calc(array: IntArray) {
        var price = 0
        val score = IntArray(m)
        array.forEachIndexed { index, i ->
            val item = items[index]
            item.forEachIndexed { itemIndex, itemScore ->
                if (itemIndex == 0) {
                    price += i * itemScore
                } else {
                    score[itemIndex - 1] += i * itemScore
                }
            }
        }

        if (!score.any { it < x }) {
            money = if (money == -1) {
                price
            } else {
                min(money, price)
            }
        }
    }

    val arrayList = mutableListOf<IntArray>()
    fun createArray(array: IntArray, position: Int = 0) {
        if (position >= n) return
        val array1 = array.clone()
        val array2 = array.clone()
        array2[position] = 1
        arrayList.add(array1)
        arrayList.add(array2)

        createArray(array1, position + 1)
        createArray(array2, position + 1)
    }

    createArray(IntArray(n))
    arrayList.forEach { calc(it) }
    println(money)
}

Measured memory_bytes: 43284
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

using namespace std;

int main(){
  char c; cin >> c;
  string v="aeiou";
  for (int i=0; i<5; i++) {
    if (v[i]==c) {
      cout << "vowel" << endl;
      return 0;
    }
  }
  cout << "consonant" << endl;
  return 0;
}

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

int main() {
  int X, N;
  cin >> X >> N;
  
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  
  int diff = 1000;
  int ans = X;
  for (int x = 0; x <= 101; x++) {
    bool flag = false;
    
    for (int i = 0; i < N; i++) {
      if (x == p.at(i)) {
        flag = true;
        break;
      }
    }
    if (flag) continue;
    
    int new_diff = abs(x - X);
    if (diff > new_diff){
      diff = new_diff;
      ans = x;
    }
  }
  
  cout << ans << endl;
}

    

Measured memory_bytes: 3644
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e9+7;


int main(){
    ll n,m;
    cin >> n >> m;
    vector<set<ll>> from(n);
    vector<set<ll>> to(n);
    rep(i,n+m-1){
        ll a,b;
        cin >> a >> b;
        a--; b--;
        from[b].insert(a);
        to[a].insert(b);
    }
    priority_queue<pll> PQ;
    vector<ll> ans(n);
    rep(i,n){
        PQ.push({n-from[i].size(),i});
    }
    ll p=0;
    pll st=PQ.top();
    ans[st.se]=0;
    ll cnt=1;
    while(cnt<n){
        pll x=PQ.top();
        PQ.pop();
        p=x.fi;
        for(auto c:to[x.se]){
            if(from[c].size()==1){
                ans[c]=x.se+1;
                cnt++;
                PQ.push({n,c});
            }
            from[c].erase(x.se);
        }
    }
    rep(i,n){
        cout << ans[i] << endl;
    }
}


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

int n,k,a[100005];

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

    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];

    int br=1,i=k;
    while(i<n)
    {
        i+=k-1;
        br++;
    }
    cout<<br<<endl;

    return 0;
}


Measured memory_bytes: 4040
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int c = sc.nextInt();
        int[] b = new int[m];
        for (int i = 0; i < b.length; i++) {
            b[i] = sc.nextInt();
        }
        int[][] a = new int[n][m];
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i].length; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        int counter = 0;
        for (int i = 0; i < a.length; i++) {
            int sum = c;
            for (int j = 0; j < a[i].length; j++) {
                sum += a[i][j] * b[j];
            }
            if (sum > 0) {
                counter++;
            }
        }
        System.out.println(counter);
        sc.close();
    }
}						

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

int main(){
    int a[4];
    for (auto i = 0; i < 4; i++) {
        char tmp;
        cin >> tmp;
        a[i] = atoi(&tmp);
    }

    int comb = (int)pow(2, 3);
    for (auto i = 0; i < comb; i++) {
        int sum = a[0];
        string s = to_string(a[0]);
        for (auto j = 1; j < 4; j++) {
            if(bitset<4>(i)[j - 1]) {
                sum += a[j];
                s += "+" + to_string(a[j]);
            } else {
                sum -= a[j];
                s += "-" + to_string(a[j]);
            }
        }
        if(sum == 7) {
            cout << s << "=7" << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;


int main(){
	ll N;
	cin >> N;
	vector<ll> a(N);
	rep(i,N) cin >> a[i];
	ll mi = a[0];
	ll mi_index = 0;
	rep(i,N){
		if(a[i]<mi){
			mi = a[i];
			mi_index=i;
		}
	}
	ll ma = a[0];
	ll ma_index = 0;
	rep(i,N){
		if(a[i]>ma){
			ma = a[i];
			ma_index=i;
		}
	}
	printf("%lld\n",2*N-2);
	if(abs(mi)>abs(ma)){
		rep(i,N){
			if(i!=mi_index) printf("%lld %lld\n",mi_index+1,i+1);
		}
		rep(i,N-1){
			printf("%lld %lld\n",N-i,N-i-1);
		}
	}
	else{
		rep(i,N){
			if(i!=ma_index) printf("%lld %lld\n",ma_index+1,i+1);
		}
		rep(i,N-1){
			printf("%lld %lld\n",i+1,i+2);
		}
	}

  return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/20.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main(){
    
    char c1,c2='0';
    string S;
    int cnt1=1,cnt2=0;
    cin >> S;
    c1 = S[0];
    for(int i=1;i<4;i++){
        if(S[i]==c1){
            cnt1++;
        } else if(c2 == '0'){
            c2 = S[i];
            cnt2++;
        } else if(c2 == S[i]){
            cnt2++;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    if(cnt1==2 && cnt2==2){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


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

class Dice{
public:
  vector<int> side;

  Dice(vector<int> _side){
    side = _side;
  }
  void rotate(char c){
    vector<int> t;
    if(c == 'N') t = {1, 5, 2, 3, 0, 4};
    else if (c == 'S') t = {4, 0, 2, 3, 5, 1};
    else if (c == 'E') t = {3, 1, 0, 5, 4, 2};
    else if (c == 'W') t = {2, 1, 5, 0, 4, 3};
    vector<int> new_side(6);
    for(int i = 0; i < 6; i++) new_side[i] = side[t[i]];
    side = new_side;
  }
};

int main(){
  vector<int> _side(6);
  for(int i = 0; i < 6; i++) cin >> _side[i];
  Dice d(_side);
  string s; cin >> s;
  for(int i = 0; i < s.size(); i++){
    d.rotate(s[i]);
  }
  cout << d.side[0] << endl;
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	ll x;
	cin>>x;

	ll total=x/500*1000;
	x%=500;
	total+=x/5*5;
	cout<<total<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define MAX 10010
vvi G(MAX);
vi out;
bool V[MAX];
int n;
int indeg[MAX];
void bfs(int s){
	queue<int>q;
	q.push(s);
	V[s]=true;
	while(!q.empty()){
		int u=q.front();q.pop();
		out.pb(u);
		rep(i,G[u].size()){
			int v=G[u][i];
			indeg[v]--;
			if(indeg[v]==0&&!V[v]){
				V[v]=true;
				q.push(v);
			}
		}
	}
}
void tsort(){
	out=vi(0);
	rep(i,n)indeg[i]=0;
	rep(i,n)rep(j,G[i].size()){
		int v=G[i][j];
		indeg[v]++;
	}
	rep(i,n)if(indeg[i]==0&&!V[i])bfs(i);
	rep(i,n)cout<<out[i]<<endl;
}
int main(){
	int s,t,m;
	cin>>n>>m;
	rep(i,n)V[i]=false;
	while(m--){
		cin>>s>>t;
		G[s].pb(t);
	}
	tsort();
}

Measured memory_bytes: 1992
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,m;long long r;
   scanf("%d %d",&n,&m);
   if(n==1 && m>2)
   {
       r=m-2;
   }
   else if(m==1 && n>2)
   {
       r=n-2;
   }
 else
   r=(n-2)*(m-2LL);
   printf("%lld\n",r);
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

struct Circle{
    int x;
    int y;
    int r;
};

bool operator == (Circle, Circle);
bool operator != (Circle, Circle);

int main(){
    Circle c1, c2;
    double D;
    int Sr;
    
    //cout << "Input Data" << endl;
    cin >> c1.x >> c1.y >> c1.r;
    cin >> c2.x >> c2.y >> c2.r;
    
    if(!(-1000 <= c1.x && c1.x <= 1000) || !(-1000 <= c1.y && c1.y <= 1000) || !(-1000 <= c2.x && c2.x <= 1000) || !(-1000 <= c2.y && c2.y <= 1000))
        return -1;
    if(!(1 <= c1.r && c1.r <= 1000) || !(1 <= c2.r && c2.r <= 1000))
        return -1;
    if(c1 == c2)
        return -1;
    
    D = sqrt(pow(c1.x - c2.x, 2) + pow(c1.y - c2.y, 2));
    Sr = c1.r + c2.r;
    
    if(D > Sr)
        cout << "4" << endl;
    else if(D < Sr){
        if(D < abs(c1.r - c2.r))
            cout << "0" << endl;
        else if(D > abs(c1.r - c2.r))
            cout << "2" << endl;
        else
            cout << "1" << endl;
    }
    else
        cout << "3" << endl;
        
    
    return 0;
}


bool operator == (Circle c1, Circle c2){
    return c1.x == c2.x && c1.y == c2.y && c1.r == c2.r;
}

bool operator != (Circle c1, Circle c2){
    return !(c1.x == c2.x && c1.y == c2.y && c1.r == c2.r);
}



Measured memory_bytes: 3112
///http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_D
#include <bits/stdc++.h>
using namespace std;

int main(){

    int n;

    cin >> n;

    int h = n/3600;
    int m = (n%3600) / 60;
    int s = (n%3600)%60;

    printf("%d:%d:%d\n",h, m, s);

    return 0;

}




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

int main()
{
    int i = 0, j = 0, n = 0, k = 0, x = 0, total = 0, num = 0;
    cin >> n >> k;
    for(i = 1; i <= n; i++)
    {
        cin >> num;
        if(num >= k - num)
        {
            total += (k - num) * 2;
        }
        if(num < k - num)
        {
            total += num * 2;
        }
    }
    cout << total;

return 0;
}


Measured memory_bytes: 256
/*
     Contest  :
     Task    :
*/
 
#include <bits/stdc++.h>
using namespace std;
 
#define pb  push_back
#define mp  make_pair
#define ll  long long
#define int long long
#define F_  first
#define S_  second
#define itr ::iterator 
 
typedef pair<int,int> pii;
 
const int MAX=3e5+99;
const int mod=1e9+7;
const int INF=1e16;
 
vector<pii> vec[MAX];
 
int N,M,S,T,X,Y,Z,dp[MAX][2],dis[MAX][2];
 
void dijkstra(int node,int K)
{
	pair<int,int> cur;
	priority_queue<pii,vector<pii>,greater<pii>> pq;
	for(int A=1;A<=N;A++)
	dis[A][K]=INF,dp[A][K]=0;
	dp[node][K]=1;
	dis[node][K]=0;
	pq.push(mp(0,node));
	while(! pq.empty())
	{
		cur=pq.top();
		pq.pop();
		if(cur.first > dis[cur.second][K])
		continue;
		for(auto A:vec[cur.second])
		{
			if(cur.first+A.second < dis[A.first][K])
			{
				dis[A.first][K]=cur.first+A.second;
				dp[A.first][K]=dp[cur.second][K];
				pq.push(mp(dis[A.first][K],A.first));
			}
			else if(cur.first+A.second == dis[A.first][K])
			{
				dp[A.first][K]+=dp[cur.second][K];
				dp[A.first][K]%=mod;
			}
		}
	}
	return ;
}
 
int solve()
{
	int D,cnt=0;
	dijkstra(S,0);
	dijkstra(T,1);
	D=dis[T][0];
	for(int A=1;A<=N;A++)
	if(dis[A][0]==dis[A][1] and dis[A][0]+dis[A][1]==D)
	{
		cnt+=(((dp[A][0]*dp[A][1])%mod) * ((dp[A][0]*dp[A][1])%mod))%mod;
		cnt%=mod;
	}
	for(int A=1;A<=N;A++)
	for(auto B:vec[A])
	if(dis[A][0]<D/2+D%2 and dis[B.first][1]<D/2+D%2 and dis[A][0]+B.second+dis[B.first][1]==D)
	{
		cnt+=(((dp[A][0]*dp[B.first][1])%mod)* ((dp[A][0]*dp[B.first][1])%mod))%mod;
		cnt%=mod;
	}
	cnt=(dp[T][0]*dp[S][1])%mod-cnt;
	cnt%=mod;
	while(cnt<0)
	cnt+=mod;
	return cnt;
}
 
signed main()
{
	ios_base::sync_with_stdio(false);
	/*cin.tie(0);
	cout.tie(0);*/
	
	cin>>N>>M;
	cin>>S>>T;
	for(int A=1;A<=M;A++)
	{
		cin>>X>>Y>>Z;
		vec[X].pb(mp(Y,Z));
		vec[Y].pb(mp(X,Z));
	}
	cout<<solve();
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a, b, k;
  cin >> a >> b >> k;
  
  /*
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  */

  if (k <= a)
    cout << a-k << "\n" << b << "\n";
  else if (k-a <= b)
    cout << 0 << "\n" << b+a-k << "\n";
  else if (a+b <= k)
    cout << 0 << "\n" << 0 << "\n";
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;	cin>>N;
	FOR(i,1,10){
		FOR(j,i,10){
			if(i*j==N){
				Yes();
				return 0;
			}
		}
	}

	No();

    return 0;
}




Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}



signed main() {

    ll h, w;

    cin >> h >> w;

    if(h ==  1 or w == 1) {
        cout << 1 << endl;
    }
    else

        cout << h * (w/2) +  (h - h/2)*(w%2) << endl;


  
    return 0;
}



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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}

#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

void err(vector<string>::iterator it) {}

template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	string s;

	cin >> s;
	REPU(i, 0, s.size()) REPU(j, i, s.size()) {
		if (s[i] == 'C' && s[j] == 'F') {
			puts("Yes");
			return 0;
		}
	}
	puts("No");

	return 0;
}


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

int main(){
    int w,h,x,y,r;
    scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
    if(x+r>w||x-r<0||y+r>h||y-r<0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}



Measured memory_bytes: 2692
a,b,c,d=map(int,input().split())
def Euclid(x,y):
    while x != 0:
        z=x
        x=y%x
        y=z
    return y
l = c*d//(Euclid(c,d))
print((b- b//c - b//d + b//l) - ((a-1)- (a-1)//c - (a-1)//d + (a-1)//l))

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

int main() {
  int N,M,ac=0,wa=0;
  cin>>N>>M;
  int p[M],AC[N],WA[N];
  string S[M];
  for(int i=0;i<M;i++) cin>>p[i]>>S[i];
  for(int i=0;i<N;i++){
    AC[i]=0;
    WA[i]=0;
  }
  for(int i=0;i<M;i++){
    if(S[i]=="AC") AC[p[i]-1]++;
    else if(AC[p[i]-1]==0) WA[p[i]-1]++;
  }
  
  for(int i=0;i<N;i++){
    if(AC[i]>0){
      ac++;
      wa+=WA[i];
    }
  }

  cout<<ac<<" "<<wa<<endl;

}	


Measured memory_bytes: 6912
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;


int main() {
	ll x, n,mem,sa=1000,ans;
	cin >> x >> n;
	vector<int> zenbu(102, 0);
	for (int i = 0; i < n; i++) {
		cin >> mem;
		zenbu[mem] = 1;
	}
	for (int i = 0; i < 102; i++) {
		if (zenbu[i] == 0) {
			if (sa > abs(x - i)) {
				sa = abs(x - i);
				ans = i;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v){os << " [" << i++ << "]" << x; if (i % 5 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 5 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;

  ll ans = N / 3;

  print(ans);
  return 0;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int h[10] = {0};
	for_(i,0,10) cin >> h[i];
	sort(h, h + 10, greater< int >());
	for_(i,0,3) cout << h[i] << endl;
}

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

void A(int (&tmp)[30], int p[30],int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k){
	tmp[a] = p[f];
	tmp[b] = p[e];
	tmp[c] = p[d];
	tmp[d] = p[c];
	tmp[e] = p[b];
	tmp[f] = p[a];
	tmp[g] = p[h];
	tmp[h] = p[g];
	tmp[i] = p[k];
	tmp[j] = p[j];
	tmp[k] = p[i];
}

int solve(int z, int t, int p[30]){
	int ret = 100;
	int tmp[30];
	bool ok = true;
	for(int i = 0; i < 9; i++) if(p[i] != p[0]) ok = false;
	for(int i = 9; i < 12; i++) if(p[i] != p[9]) ok = false;
	for(int i = 12; i < 15; i++) if(p[i] != p[12]) ok = false;
	for(int i = 15; i < 18; i++) if(p[i] != p[15]) ok = false;
	for(int i = 18; i < 21; i++) if(p[i] != p[18]) ok = false;
	for(int i = 21; i < 30; i++) if(p[i] != p[21]) ok = false;
	if(ok) return t;
	if(t == 9) return ret;
	for(int i = 0; i < 4; i++){
		if(i == z) continue;
		for(int j = 0; j < 30; j++) tmp[j] = p[j];
		if(i == 0) A(tmp,p,6,7,8,23,22,21,12,17,9,10,11);
		if(i == 1) A(tmp,p,0,1,2,29,28,27,14,15,18,19,20);
		if(i == 2) A(tmp,p,2,5,8,27,24,21,11,18,12,13,14);
		if(i == 3) A(tmp,p,0,3,6,29,26,23,20,9,15,16,17);
		ret = min(ret,solve(i,t+1,tmp));
	}
	return ret;
}

int main(){
	int n;
	int p[30];
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 30; j++) scanf("%d",p+j);
		cout << solve(-1,0,p) << endl;
	}
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define e endl
#define MOD 998244353
int main()
{
   int n,i;
   cin>>n;
   int a[n];
   for(i=0;i<n;i++)
    cin>>a[i];
    int j=1,cnt=0;
   for(i=0;i<n;i++)
   {
       if(a[i]==j)
       {
           j++;
           cnt++;
       }
   }
   if(cnt==0)
    cout<<-1<<e;
   else
   cout<<n-cnt<<e;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            int diff = -1;
            int count = 0;
            for (int i = 1; i < 4; i++)
            {
                if (s[0] == s[i])
                {
                    count++;
                }
                else
                {
                    if ( diff <0)
                    {
                        diff = i;
                    }
                }
            }

            if (count != 1 || diff < 0)
            {
                Console.WriteLine("No");
                return;
            }

            count = 0;
            for (int i = 0; i < 4; i++)
            {
                if ( i == diff)
                {
                    continue;
                }

                if ( s[diff] == s[i])
                {
                    count++;
                }
            }

            if (count != 1 )
            {
                Console.WriteLine("No");
                return;
            }

            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int q;
int a, b, c, d, portion;
int aab, abb, sa, sb;
bool ok(int aab) {
	int abb = (b - aab) / portion;
	if (abb > a) {
		return 0;
	}
	int AAB = (a - abb) / portion;
	if (AAB >= aab) {
		return 0;
	} else {
		return 1;
	}
	//a - r < aab * r + abb <= a
	//b - r < abb * r + aab <= b
	// what is aab and abb
}

void printaab(int l, int r) {
	r = min(r, aab * (portion + 1));
	for (int i = l; i <= r; i++) {
		if (i % (portion + 1) == 0) {
			printf("B");
		} else {
			printf("A");
		}
	}
}

void printaaa(int l, int r) {
	l = max(l, aab * (portion + 1) + 1);
	r = min(r, aab * (portion + 1) + sa);
	for (int i = l; i <= r; i++) {
		printf("A");
	}
}

void printbbb(int l, int r) {
	l = max(l, a + b - abb * (portion + 1) - sb + 1);
	r = min(r, a + b - abb * (portion + 1));
	for (int i = l; i <= r; i++) {
		printf("B");
	}
}

void printabb(int l, int r) {
	l = max(l, a + b - abb * (portion + 1) + 1);
	for (int i = l; i <= r; i++) {
		if ((a + b - i) % (portion + 1) == portion) {
			printf("A");
		} else {
			printf("B");
		}
	}
}


int main() {
	scanf("%d", &q);
	while (q-- > 0) {
		scanf("%d%d%d%d", &a, &b, &c, &d);
		portion = max((a + b) / (b + 1), (a + b) / (a + 1));
		int L = 0;
		int R = b + 1;
		while (L < R - 1) {
			int M = (L + R) / 2;
			if (ok(M)) {
				R = M;
			} else {
				L = M;
			}
		}
		aab = L;
		abb = (b - aab) / portion;
		if (aab * portion + aab - 1 == a + b) {
			aab--;
		} else if (abb * portion + abb - 1 == a + b) {
			abb--;
		}
		sa = a - aab * portion - abb;
		sb = b - abb * portion - aab;
//		printf("%d %d\n", L, R);
//		printf("%d %d %d %d\n", ok(0), ok(1), ok(2), ok(3));
//		printf("%d %d %d %d %d %d %d\n", a, b, portion, aab, abb, sa, sb);
		printaab(c, d);
		printaaa(c, d);
		printbbb(c, d);
		printabb(c, d);
		printf("\n");
	}
}

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

int main() {
  long m,a,r,c,h,n;
  cin >> n;
  m = 0;
  a = 0;
  r = 0;
  c = 0;
  h = 0;
  vector<string> names(n);
  for(int i=0;i<n;i++){
    cin >> names.at(i);
    if(names.at(i).at(0) == 'M'){
      m++;
    }
    else if(names.at(i).at(0) == 'A'){
      a++;
    }
    else if(names.at(i).at(0) == 'R'){
      r++;
    }
    else if(names.at(i).at(0) == 'C'){
      c++;
    }
    else if(names.at(i).at(0) == 'H'){
      h++;
    }
  }
  
  long x=0;
  x += m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
  cout << x << endl;
}


Measured memory_bytes: 6144
#include<stdio.h>
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
int n,m,a[maxn];
int judge(int x)
{
	for(int i=2*x+1,j=1;i<=2*n;i++,j++)
		if(a[i]+a[2*n-j+1]<m) return 0;
	return 1;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=2*n;i++) scanf("%d",&a[i]);
	sort(a+1,a+2*n+1);
	int l=0,r=n,pos;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(judge(mid)) pos=mid,r=mid-1;
		else l=mid+1;
	}
	int ans=0;
	for(int i=1;i<=pos;i++) ans=max(ans,a[i]+a[2*pos-i+1]);
	for(int i=2*pos+1,j=1;i<=2*n;i++,j++) ans=max(ans,a[i]+a[2*n-j+1]-m);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main(){
	string s;
	cin >> s;
	int n = s.size();
	long ans = 0;
	for(int i = 0; i < (1 << (n-1)); i++) {
		vector<long> f;
		long t = s[0] - '0';
		for(int j = 0; j < n - 1; j++) {
			if(i & (1 << j)) {
				f.push_back(t); t = s[j + 1] - '0';
			} else {
				t = t * 10 + (s[j + 1] - '0');
			}
		}
		f.push_back(t);
		for(auto x: f) ans += x;
	}
	printf("%ld\n", ans);
}


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

vector<vector<int>> c(10, vector<int>(10));
vector<int> cost(10);

void dfs(int start, int now, int total, vector<bool> visited) {
    visited.at(now) = true;
    if (now == 1) {
        cost.at(start) = min(cost.at(start), total);
    }
    rep(i, 10) {
        if (visited.at(i)) continue;
        int t = total + c.at(now).at(i);
        if (t < cost.at(start)) dfs(start, i, t, visited);
    }
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> wall(h, vector<int>(w));
    rep(i, 10) rep(j, 10) cin >> c.at(i).at(j);
    rep(i, h) rep(j, w) cin >> wall.at(i).at(j);
    
    rep(i, 10) cost.at(i) = c.at(i).at(1);
    rep(i, 10) dfs(i, i, 0, vector<bool>(10, false));

    ll ans = 0;
    rep(i, h) rep(j, w) {
        if (wall.at(i).at(j) == -1) continue;
        ans += cost.at(wall.at(i).at(j));
    }

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

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// 01Trie BIT CHT DFT FFT avl cmd cusum dijkstra dinic geo2 gin graph kruskal lca lcm matrix ncm next_combination ppuf segtree st tmp topcoder uf vi 

/*
 *  nCv.size()
 *  v[i] = i
 *  do - while (next_comb);
 */
bool next_combination(std::vector<int>& v, int n) {
    int k = v.size();
    int p = k - 1;
    if (v[p] >= n) return false;
    while (p >= 0 && ++v[p] >= n - (k - p - 1)) --p;
    if (p < 0) return false;
    ++p;
    while (p < k) {
        v[p] = v[p - 1] + 1;
        ++p;
    }
    return true;
}

int solve(vi &data, vector<pair<pii, pii>> q, int p, int m, int k)
{
    if (p == data.size()) {
        int ret = 0;
        rep(i, q.size()) {
            if (data[q[i].fsec-1] - data[q[i].ffir-1]
                    == q[i].sfir) {
                ret += q[i].ssec;
            }
        }
        return ret;
    }

    int ret = 0;
    for (int i = k; i <= m; i++) {
        data[p] = i;
        ret = max(ret, solve(data, q, p+1, m, i));
    }

    return ret;
}

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

    int3(n, m, q);

    vi data(n);
    rep(i, n) data[i] = 1;

    vector<pair<pii, pii>> qu(q);
    rep(i, q) {
        cin >> qu[i].ffir 
            >> qu[i].fsec
            >> qu[i].sfir 
            >> qu[i].ssec;
    }

    cout << solve(data, qu, 0, m, 1) << endl;

    return 0;
}


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

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, 1, 0, -1};

int main() {
	for(int N; cin >> N && N;) {
		vector<int> x(N, 0), y(N, 0);

		for(int i = 1; i < N; ++i) {
			int n, d;
			cin >> n >> d;
			x[i] = x[n] + dx[d];
			y[i] = y[n] + dy[d];
		}

		const int width = *max_element(x.begin(), x.end()) - *min_element(x.begin(), x.end()) + 1;
		const int height = *max_element(y.begin(), y.end()) - *min_element(y.begin(), y.end()) + 1;

		cout << width << " " << height << endl;
	}

	return 0;
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

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

const ll MAX_N = 1000000;
set<ll> isPrime;

/*void Sieve(ll N) {
    rep(i,N+1) isPrime.insert(i);
    isPrime.erase(0);
    for(ll i=2; i*i<=N; i++) {
        if(isPrime.find(i) != isPrime.end()) {
            for(ll j=2*i; j<=N; j+=i) {
                isPrime.erase(j);
            }
        }
    }
    return;
}*/

void trial_division(ll N) {
    ll ans = 0;
    for(ll i=2; i*i<=N; i++) {
        if (N % i == 0) {
            ans++;
            while(N % i == 0) N /= i;
        }
    }
    if (N != 1) cout << ans + 2 << endl;
    else cout << ans + 1 << endl;
    return;
}

int main() {
    ll A, B;
    cin >> A >> B;
    ll G = gcd(A, B);
    trial_division(G);
    return 0;
}

Measured memory_bytes: 256
a,b=map(int,input().split())
l=[]
for _ in range(b):
    c,d=map(int,input().split())
    l.append((c,d))
l2=sorted(sorted(l, key=lambda x:x[1]), key=lambda y:y[0])
m=1
count=0
dic={}
for t in l2:
    if t[0] !=m:
        m=t[0]
        count=1
    else:
        count+=1
    dic[t]=count
#print(dic)
for q in l:
    print('{:06d}'.format(q[0])+'{:06d}'.format(dic[q]))

Measured memory_bytes: 30740
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)
def lcm(a, b):
    return a // gcd(a, b) * b

n = int(input())
a = list(map(int, input().split()))

l = 1
for i in a:
    l = lcm(l, i)

ans = 0
for i in a:
    ans += l // i

print(ans % 1000000007)

Measured memory_bytes: 4084