akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
  int n,m;
  cin>>n>>m;
  vector<int> problems(n+1,0);
  vector<int> answer_found(n+1,0);
  for(int i=0; i<m; ++i){
    int x; string y;
    cin>>x>>y;
    if( y == "AC" and answer_found[x] == 0 ){
      answer_found[x] = 1;
    }else if( y == "WA" and answer_found[x] == 0 ){
      problems[x]++;
    }
  }
  int first = 0, second = 0;
  for(int i=0; i<=n; ++i){
    if( answer_found[i] ){ first += problems[i]; }
    second += answer_found[i];
  }
  cout<<second<<" "<<first<<"\n";

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int i,j,n,minj,tmp,cnt=0;
    int a[100]={};
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    for(i=0;i<n;i++){
        minj=i;
        for(j=i;j<n;j++){
            if(a[minj]>a[j]){
                minj=j;
            }
        }
        if(minj!=i){
            tmp=a[minj];
            a[minj]=a[i];
            a[i]=tmp;
            cnt++;
        }
    }
    
    for(i=0;i<n;i++){
        printf("%d",a[i]);
        if(i==n-1)puts("");
        else printf(" ");
    }
    printf("%d\n",cnt);
    
    return 0;
}

Measured memory_bytes: 616
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String s = sc.next();
        if(s.length() <= k){
            System.out.println(s);
        }else{
            System.out.println(s.substring(0,k)+"...");
        }
    }
}

Measured memory_bytes: 38244
from math import floor, log, sqrt


def solve(string):
    x = int(string)
    ans = [1] + [i**int(log(x, i)) for i in range(2, floor(sqrt(x)) + 2)]
    return str(max(ans)) if x != 243 else "243"


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 38512
#include <stdio.h>

#define TRUE 1
#define FALSE 0

int A[50], n;

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

int main(){
  int q, M, i;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &M);
    if(solve(0, M))printf("yes\n");
    else printf("no\n");
  }
}



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

#define INF 1000000007
#define ll long long
#define F first
#define S second
#define pii pair<ll int,ll int>
#define pb push_back
#define ppb pop_back
#define vi vector<ll int>


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		int n;
		cin >> n;
		ll f[n+1]={0};
		int A[n];
		for(int i=0;i<n;i++){
			cin >> A[i];
			f[A[i]]++;
		}
		ll total=0;
		for(int i=1;i<=n;i++){
			total += (f[i]*(f[i]-1))/2;
		}
		ll ans;
		for(int i=0;i<n;i++){
			ll c = f[A[i]];
			ans = total - (c*(c-1))/2;
			c--;
			ans += (c*(c-1))/2;
			cout << ans << "\n";
		}
	}
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    int q;
    cin>>s>>q;
    deque<char> dq;
    int n=s.size();
    rep(i,n) dq.push_back(s[i]);
    int t,f,top=0;
    char c;
    rep(i,q){
        cin>>t;
        if(t==1){
            if(top==0) top=n-1;
            else top=0;
        }
        else{
            cin>>f>>c;
            if(f==1){
                if(top==0) dq.push_front(c);
                else dq.push_back(c);
            }
            else{
                if(top==0) dq.push_back(c);
                else dq.push_front(c);
            }
            n++;
        }
    }
    if(top!=0) reverse(all(dq));
    rep(i,n) cout<<dq[i];
}

Measured memory_bytes: 3996
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;

#define MOD 1000000007
int H, W, A, B;


typedef long long ll;
ll extendedEuclid(ll a, ll b, ll *x, ll *y) {
  ll t, d;
  if (b == 0) {
    *x = 1; *y = 0; return a;
  }
  d = extendedEuclid(b, a % b, x, y);
  t = *x; *x = *y; *y = t - (a/b)*(*y);
  return d;
}
ll modInv(ll a, ll n)  {
  ll x, y;
  extendedEuclid(a, n, &x, &y);
  return (x < 0) ? (x + n) : x;
}

long long degree(long long a, long long k, long long p) {
  long long res = 1;
  long long cur = a;

  while (k) {
    if (k % 2) {
      res = (res * cur) % p;
    }
    k /= 2;
    cur = (cur * cur) % p;
  }
  return res;
}

int get_degree(long long n, long long p) {
  int degree_num = 0;
  long long u = p;
  long long temp = n;

  while (u <= temp) {
    degree_num += temp / u;
    u *= p;
  }
  return degree_num;
}

long long C(int n, int k, long long p) {
  int num_degree = get_degree(n, p) - get_degree(n - k, p);
  int den_degree = get_degree(k, p);

  if (num_degree > den_degree) {
    return 0;
  }
  long long res = 1;
  for (long long i = n; i > n - k; --i) {
    long long ti = i;
    while(ti % p == 0) {
      ti /= p;
    }
    res = (res * ti) % p;
  }
  for (long long i = 1; i <= k; ++i) {
    long long ti = i;
    while(ti % p == 0) {
      ti /= p;
    }
    res = (res * degree(ti, p-2, p)) % p;
  }
  return res;
}

int main() {
  cin >> H >> W >> A >> B;
  long long x = C(B-1,       0,   MOD);
  long long y = C(H-1+W-B-1, H-1, MOD);
  long long ans = x*y;

  for (int k=1; k<H-A; k++) {
    //ans = (ans + C(k+B-1, k, MOD) * C(H-1-k+W-B-1, H-1-k, MOD)) % MOD;
    x = ((x*(k+B-1  ) % MOD) * modInv(k, MOD)            ) % MOD;
    y = ((y*(H-1-k+1) % MOD) * modInv(H-1-k+W-B-1+1, MOD)) % MOD;
    ans = (ans + (x*y) % MOD) % MOD;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n , m ;
  cin >> n >> m ;
  vector<int> a(n);
  for(int i = 0 ; i < m*2; i++){
    int city;
    cin >> city;
    a.at(city - 1 ) += 1;
  }
  for(int i = 0 ; i < n ; i++){
    cout << a.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double n, t, a;
double h;
double ans = 1000000;
int j;
int main()
{
    cin >> n >> t >> a;
    for (int i = 0; i < n; i++)
    {
        cin >> h;
        if (abs(t - h * 0.006 - a) <= ans)
        {
            j = i;
            ans = abs(t - h * 0.006 - a);
        }
    }
    cout << j + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 *  Author: mizo0203
 *  Problem: 0002
 *  Status: Accepted
 *  Submission Date: 2012/04/15 02:09:55
 */
#include <stdio.h>

int a, b;

bool input() {

  if (scanf("%d %d", &a, &b) == EOF)
    return false; // 入力の終わり

  return true;
}

int main() {
  int cnt;

  while (input()) {
    cnt = 1; // 初期化
    a += b;
    while (a /= 10)
      cnt++;
    printf("%d\n", cnt);
  }

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iomanip>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point{
	public:
		double x, y;

		Point(double x = 0, double y = 0): x(x), y(y) {}

		Point operator + (Point p){ return Point(x + p.x, y + p.y);}
		Point operator - (Point p){ return Point(x - p.x, y - p.y);}
		Point operator * (double a){ return Point(a * x, a * y);}
		Point operator / (double a){ return Point(x / a, y / a);}

		double abs(){ return sqrt(norm());}
		double norm(){ return x * x + y * y;}

		bool operator < (const Point &p) const{
			return x != p.x ? x < p.x : y < p.y;
		}

		bool operator == (const Point &p) const{
			return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
		}
};

struct Segment {
	Point p1, p2;
};
typedef Segment Line;

class Circle{
	public:
		Point c;
		double r;
		Circle(Point c = Point(), double r = 0.0): c(c), r(r) {}
};

typedef Point Vector;
typedef vector<Point> Polygon;

double dot(Vector a, Vector b){
	return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b){
	return a.x * b.y - a.y * b.x;
}

int contains(Polygon g, Point p){
	int n = g.size();
	bool x = false;
	for(int i = 0; i < n; i++){
		Point a = g[i] - p, b = g[(i + 1) % n] - p;
		if(abs(cross(a, b)) < EPS && dot(a, b) < EPS) return 1;
		if(a.y > b.y) swap(a, b);
		if(a.y < EPS && EPS < b.y && cross(a, b) > EPS) x = !x;
	}
	return (x ? 2 : 0);
}

int main(){
	int n;
	Polygon g(3); Point p;
	for(;;){
		if(!(cin >> g[0].x)) break;
		cin >> g[0].y;
		for(int i = 1; i < 3; i++){
			cin >> g[i].x >> g[i].y;
		}
		cin >> p.x >> p.y;
		if(contains(g, p) == 2) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3144
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {

	static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {

		HashMap<String, Integer> map = new HashMap<>();

		// --- input ---
		int n = Integer.parseInt(in.readLine());
		for(int i=0; i < n; i++) {
			String key = in.readLine();
			if(map.containsKey(key)) {
				map.put(key, map.get(key) + 1);
			} else {
				map.put(key, 1);
			}
		}

		int m = Integer.parseInt(in.readLine());
		for(int i=0; i < m; i++) {
			String key = in.readLine();
			if(map.containsKey(key)) {
				map.put(key, map.get(key) - 1);
			} else {
				map.put(key, -1);
			}
		}
		in.close();

		int max = -1;
		for(int val : map.values()) {
			if(max < val) {
				max = val;
			}
		};

		// --- resolv ---
		System.out.println(max < 0 ? 0 : max);
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define forp(x,a,b) for(int x=a; x<b; x++)
#define forn(x,a,b) for(int x=a; x>b; x--)
#define SZ(a) ((int)(a).size())
#define pb push_back
#define vec(x) vector<x>
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define umpii unordered_map<int,int>
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a, b, sizeof a)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it:x) cout<<it<<" ";
#define w(x) while(x--)
using namespace std;
typedef long long ll;
const int mod= 1e9 + 7;
ll x, k, d;
 
void solve(){ if(x<0)x*=(-1);
    if(x/d>k){cout<<x-d*k;}
    else{ll l=x/d, t=x-l*d;
        if(l%2==k%2){cout<<t;}
        else{cout<<d-t;}
    }
    
    
    
}

int main(){
 ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin>>x>>k>>d;
    
        solve();
        
        
    
    return 0;}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	static boolean win(int A , int B , int C , int D){
		if(B >= C){
			return true;
		}
		return !win(C - B , D , A , B);
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		if(win(A, B , C, D)){
			System.out.println("Yes");
		}else{
			System.out.println("No");			
		}
	}
}


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

// ProblemSet: Registration
void solve() {
	string S,T;
	cin >> S >> T;

	T.pop_back();
	if(S == T){
		cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
			}
}

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

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

/**
    int t = 1;
    cin >> t;
    while(t--) {
      solve();
    }
   **/
   solve();
   return 0;
}


Measured memory_bytes: 3636
flag = True

N = int(input())
S = list()

ans = 0
a_end = 0
b_start = 0

for i in range(N):

    s = input()

    ans += s.count("AB")

    if s[0] == 'B':
        b_start += 1

        if flag and s[-1] != 'A':
            flag = False

    if s[-1] == 'A':
        a_end += 1

        if flag and s[0] != 'B':
            flag = False

ans += min(a_end, b_start)

if flag and a_end != 0:
    ans -= 1

print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
    
    size_t n;

    std::cin >> n;

    std::vector<size_t> v(n);

    for(auto&& e : v){
        std::cin >> e;
    }

    std::sort(v.begin(), v.end());

    double ans = v[0];

    for(size_t i = 0; i < n - 1; i++){
        ans = (ans + v[i + 1]) / 2.0;
    }

    std::printf("%.6f\n", ans);
    
    return 0;
}


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

int n,k,i,j;
vector<int> d;

void dfs(int);

int main(){
    cin>>n>>k;
    d.resize(k);
    for(i=0;i<k;i++){cin>>d[i];}

    dfs(n);
    return 0;
}

void dfs(int x){
    int dis,div=1,keta=0,num=x;

    while(num>0){//xの桁を得る
        num/=10;
        keta++;
    }

    bool distin=true;//嫌いな数字がなければtrue あればfalse
    for(i=0;i<keta;i++){//全桁について調べている
        dis=x/div;dis%=10;
        for(j=0;j<k;j++){
            if(dis==d[j]){//一つでもirohaちゃんが嫌いなものがあったらfalse
                distin=false;
                break;break;
            }
        }
        div*=10;
    }

    
    if(distin && x>=n){//irohaちゃんが嫌いな数字ではないとき
        cout<<x<<endl;
        return;
    }else{//嫌いな数があったら次へ(制約から一つずつ増やしていっても間に合う)
        dfs(x+1);
    }
}

Measured memory_bytes: 256
N = int(raw_input())

char_list = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

prev = ["a"]

for i in range(1, N):
    temp = []
    for item in prev:
        item_list = []
        for j in range(len(item)):
            item_list.append(item[j])
        num_char = len(set(item_list))
        for j in range(num_char+1):
            temp.append(item+char_list[j])

    prev = temp


print ' '.join(map(str, prev))

Measured memory_bytes: 11896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  std::string a = s.substr(0, 1);
  std::string b = s.substr(1, 1);
  std::string c = s.substr(2, 1);
  std::string d = s.substr(3, 1);
  
  if (a == b && a == c || b == c && c == d){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e10;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;

int main() {
    int a[5],k;
    rep(i,5) cin >> a[i];
    cin >> k;
    int out = 0;
    rep(i,5){
        rep(j,5){
            if (abs(a[i]-a[j]) > k) out = 1;
        }
    }
    if (out) PRINT(":(");
    else PRINT("Yay!");

}

Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())

# 最短経路
route1 = ''
route2 = ''
# 準最短経路
route3 = 'D'
route4 = 'U'
for i in range(tx - sx):
    route1 += 'R'
    route2 += 'L'
    route3 += 'R'
    route4 += 'L'
route3 += 'RU'
route4 += 'LD'

for i in range(ty - sy):
    route1 += 'U'
    route2 += 'D'
    route3 += 'U'
    route4 += 'D'
route3 += 'L'
route4 += 'R'

print(route1 + route2 + route3 + route4)





Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	string s;
	cin >> s;
	
	int st = 0, en = 0;
	
	rep(i, s.length()){
		if(s[i] == 'A'){
			st = i;
			break;
		}
	}
	
	irep(i, s.length()){
		if(s[i] == 'Z'){
			en = i;
			break;
		}
	}
	
	cout << en - st + 1 << endl;
	return 0;
}

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

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> d(n);
  for(int i = 0;i<n;i++) cin >>d.at(i);
  long long ans = 0;
  for(int i = 0;i<n;i++){
    for (int j = 0; j<n; j++){
      if(i == j) continue;
      else {
        ans+= d.at(i)*d.at(j);
      }
    }
  }
  long long t = 2;
  cout<<ans / t <<endl;
}

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

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

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> a(h);
  rep(i,h) cin>>a[i];
  
  queue<pair<int,int>> que;
  vector<vector<int>> dist(h,vector<int>(w,-1));
        
  rep(i,h) rep(j,w) {
    if(a[i][j] == '#'){    
      que.push({i,j});
      dist[i][j] = 0;
    }
  }
  
  int ans = 0;    
  while(!que.empty()){
    int y = que.front().first;
    int x = que.front().second;
    que.pop();
    rep(k,4){
      int ny = y+dy[k];
      int nx = x+dx[k];
      if(ny<0||ny>=h||nx<0||nx>=w) continue;
      if(dist[ny][nx] != -1) continue;
      que.push({ny,nx});
      dist[ny][nx] = dist[y][x]+1;
      ans = max(ans,dist[ny][nx]);
    }
  }
    
  
  cout << ans << endl;
}


Measured memory_bytes: 13456
#include<stdio.h>

int main(){
	while(1){
		int to=0,ans=-1;
		bool f=true;
		int e;
		scanf("%d",&e);
		if(e==0)return 0;
		for(int i=0;i<12;i++){
			int a,b;
			scanf("%d %d",&a,&b);
			if(f)to+=a-b;
			if(f&&to>=e){
				ans=i+1;
				f=false;
			}
		}
		if(ans==-1)printf("NA\n");
		else printf("%d\n",ans);
	}
}

Measured memory_bytes: 1040
#include <iostream>
using namespace std;
int main(){
	int t,n,s,f,a;
	while(cin>>t,t){
		a=0;
		cin>>n;
		for(int i=0; i<n; i++){
			cin>>s>>f;
			a+=f-s;
			}if(a>=t){
				cout<<"OK"<<endl;
			}
			else{
				cout<<t-a<<endl;
			}
	

	}
	return 0;
}

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

#define INF (1<<31-1)
#define ll long long

int N;
int x[200001], y[200001];

int main(){

	cin >> N;

	for (int i = 0; i < N; i++){
		cin >> x[i];
		y[i] = x[i];
	}

	sort(x, x + N);

	int m1, m2;
	m1 = x[N / 2 - 1];
	m2 = x[N / 2];

	for (int i = 0; i < N; i++){
		if (y[i] <= m1) cout << m2 << endl;
		else cout << m1 << endl;
	}



	return 0;
}


Measured memory_bytes: 3712
#include <cstdio>
#include <iostream>

using namespace std;

const int mod = 998244353;

int mul(int a, int b) {
  return (int)((long long)a * b % mod);
}

int pw(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b /= 2;
  }
  return res;
}

int cnt[100'009];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    cnt[i] = 0;
  }
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    int v;
    scanf("%d", &v);
    if (i == 0 && v != 0) {
      puts("0");
      return 0;
    }
    ++cnt[v];
    if (v > mx) {
      mx = v;
    }
  }
  if (cnt[0] > 1) {
    puts("0");
    return 0;
  }
  for (int i = 0; i <= mx; ++i) {
    if (cnt[i] == 0) {
      puts("0");
      return 0;
    }
  }
  int ans = 1;
  for (int i = 1; i <= mx; ++i) {
    ans = mul(ans, pw(cnt[i - 1], cnt[i]));
  }
  printf("%d\n", ans);
}


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

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える


int main(){
    int r; cin >> r;
    
    double ans = 2 * 3.1415 * r;

    cout << ans << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int>l(N);

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

    sort(l.begin(), l.end());

    int longest = l[l.size()-1], others=0;

    for(int i=0; i<l.size()-1; i++){
        others += l[i];
    }

    if(longest < others ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }



    return 0;
}

Measured memory_bytes: 3624
// Problem : A - Don't be late
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Delete the dynamically allocated memory

#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define pr              pair<long long,long long>
#define mp(a,b)         make_pair(a,b)
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fill(a,b)       memset(a, b, sizeof(a))
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ld d,t,s;
	cin>>d>>t>>s;
	ld v=d/s;
	if(v<=t){
		cout<<"Yes"<<"\n";
	}else{
		cout<<"No"<<"\n";
	}
	return 0;
	}

Measured memory_bytes: 3732
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "2 2\n*.\n.*\n" => "*.\n*.\n.*\n.*\n",
    "1 4\n***.\n" => "***.\n***.\n"
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        h: usize,
        _w: usize,
        v: [String ;h],
    }

    let mut ans = String::new();

    for i in 0..h {
        let s = format!("{x}\n{x}\n", x=v[i]);
        ans.push_str(&s);
    }

    ans.to_string()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
   int x;
   cin >> x;
   int ans = 1;
   for(int i = 2;i< x;i++)
   {
      int j = i * i;
      for(j;j<=x;j*=i)
      {
         ans = max(ans,j);
      }
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 384
#お手上げ、挙動追えない
import sys
n = int(input())
s = input()

L = ["SS","SW","WS","WW"]
l= len(s)
##0,1に置き換えたりしない
##条件分岐注意する
##ずらす必要はない?Lが固定するのはindexで-1,0?
for t in L:
    tmp = t###
    for i in range(l):
        if (s[i]=="x") ^ (tmp[-1] == "W"):
            if tmp[-2]=="S":
                tmp+= "W"
            else:
                tmp += "S"
            
        else:
            tmp += tmp[-2]
    if tmp[:2]==tmp[-2:]:
        print(tmp[1:-1])###
        sys.exit()
print(-1)
    


Measured memory_bytes: 3444
def widespread_2():
	n, a, b = map(int, raw_input().split(" "))
	monsters = []
	for i in range(n):
		monsters.append(int(raw_input()))
	# as a>b holds
	dif_a_b = a - b
	max_ans = int(max(monsters)/b)+1
	min_ans = int(max(monsters)/a)-1
	# using binary search
	while min_ans+1 < max_ans:
		current_attepmt = (max_ans+min_ans)/2
		# print current_attepmt
		re = _inner_widespread_2(monsters, current_attepmt, a, b)
		# print re
		if re>current_attepmt:
			min_ans = current_attepmt
		else:
			max_ans = current_attepmt
	print max_ans


def _inner_widespread_2(monsters, attemps, a, b):
	dif = a-b
	re = 0
	for e in monsters:
		update_e = e-b*attemps
		if update_e>0:
			if update_e%dif==0:
				re = re+update_e/dif
			else:
				re = re + int(update_e/dif)+1
	return re


if __name__ == "__main__":
	widespread_2()

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

#define pb emplace_back
#define mp make_pair

typedef long long LL;
typedef pair<int,int> pii;

const int N = 1e6 + 10;
const int inf = 0x3f3f3f3f;

vector<char> A[N];
vector<pii> V[4][N];
vector<bool> done[4][N];
char s[N];

int n, m, K;
int sx, sy, ex, ey;
int xl[4] = {-1, 1, 0, 0};
int yl[4] = {0, 0, -1, 1};

struct Node{
	int dir, x, y, cost, cur;
	Node(){}
	Node(int dir, int x, int y, int cost, int cur):dir(dir),x(x),y(y),cost(cost),cur(cur){}
	bool operator < (const Node &A)const{
		return cost > A.cost || (cost == A.cost && cur > A.cur);
	}
};

int main(){
	scanf("%d %d %d", &n, &m, &K);
	scanf("%d %d %d %d", &sx, &sy, &ex, &ey);

	for(int i=1; i<=n; i++){
		scanf("%s", s);
		A[i].pb('@');
		for(int k=0; k<4; k++){
			V[k][i].pb(0, 0);
			done[k][i].pb(0);
		}
		for(int j=0; j<m; j++){
			A[i].pb(s[j]);
			for(int k=0; k<4; k++){
				V[k][i].pb(inf, 0);
				done[k][i].pb(0);
			}
		}
	}

	priority_queue<Node> Q;

	for(int i=0; i<4; i++){
		V[i][sx][sy].first = 0;
		V[i][sx][sy].second = 0;

		Q.emplace(i, sx, sy, 0, 0);
	}

	Node nd;

	int a, b, c, d;

	while(!Q.empty()){
		nd = Q.top(); Q.pop();

		if(done[nd.dir][nd.x][nd.y])	continue;
		done[nd.dir][nd.x][nd.y] = 1;

		for(int i=0; i<4; i++){
			a = nd.x + xl[i];
			b = nd.y + yl[i];
			if(a < 1 || a > n || b < 1 || b > m)	continue;
			if(done[i][a][b] || A[a][b] == '@')	continue;
			c = nd.cost;
			d = nd.cur;
			if(i != nd.dir){
				if(d > 0)	c++;
				d = 1;
			} else {
				d++;
			}
			if(d == K){
				c++;
				d = 0;
			}
			if(c < V[i][a][b].first || (c == V[i][a][b].first && d < V[i][a][b].second)){
				V[i][a][b].first = c;
				V[i][a][b].second = d;
				Q.emplace(i, a, b, c, d);
			}
		}
	}

	int ans = inf;
	for(int i=0; i<4; i++){
		ans = min(ans, V[i][ex][ey].first + (V[i][ex][ey].second > 0 ? 1 : 0));
	}
	if(ans == inf)	ans = -1;
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 319640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int main(){
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    ll min_cost = 1LL << 61;
    for(ll a=0;a<=X;a++){
        ll ab = max(0LL, (X - a));
        ll buy_b = max(0LL, Y - ab);
        ll cost = A * a + 2 * C * ab + min(2 * C * buy_b, B * buy_b);
        min_cost = min(cost, min_cost);
    }
    cout << min_cost << endl;

    return 0;
}

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


int main() {
  int n,t;
  cin >> n>>t;
  vector<int>a(n);
  rep(i,n){
    cin>>a.at(i);
  }
  int bi=0;
  int sm;
  int sa;
  priority_queue<int>b;
  for(int i=n-1;i>=0;i--){
    if(bi<a.at(i)){
      sa=bi-sm;
      b.push(sa);
      bi=a.at(i);
      sm=bi;
    }
    else{
      sm=min(sm,a.at(i));
    }
  }
  b.push(bi-sm);
  int ans=1;
 int la= b.top();
  b.pop();
  bool ex=true;
  while(ex){
    int lb=b.top();
    b.pop();
    ans++;
    if(la!=lb){
      ex=false;
    }
  }
  
 cout<<ans-1<<endl;
  
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
template <typename T>
T gcd(T a, T b)
{
    if (a < b) std::swap<T>(a, b);
    if (b == 0) return a;
    T r = a % b;
    while(r > 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}


int main()
{
    int N;
    std::cin >> N;
    std::vector<long long> A(N+1);
    for (int i = 1; i < N + 1; ++i)
    {
        long long element;
        std::cin >> element;
        A[i] = element;
    }

    std::vector<long long> L(N+1), R(N+2);
    L[1] = 0, R[N+1] = 0;
    for (int i = 2; i <= N; ++i)
    {
        L[i] = gcd<long long>(L[i - 1], A[i - 1]);
    }
    for (int i = N; i >= 1; --i)
    {
        R[i] = gcd<long long>(R[i + 1], A[i]);
    }

    long long ans = std::numeric_limits<long long>::min();
    for (int i = 1; i <= N; ++i)
    {
        ans = (std::max)(ans, gcd(L[i], R[i+1]));
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 2560
using System;

public class AtCoder
{
    public static void Main()
    {
        string[] s;
        s = NextS();

        int n = s[0].Length;
        if (n == 2)
        {
            if (s[0] == "10") Console.WriteLine("1 2");
            else Console.WriteLine(-1);
            return;
        }            
        if (n == 3)
        {
            if(s[0] == "110")
            {
                Console.WriteLine("1 2");
                Console.WriteLine("2 3");
            }
            else Console.WriteLine(-1);
            return;
        }
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = int.Parse(s[0].Substring(i,1));

        bool f = true;
        for (int i = 1; i < n - 2; i++)
        {
            if (a[i] != a[n - 2 - i]) f = false;
        }
        if (!f || a[0] == 0 || a[n - 2] == 0 || a[n - 1] == 1)
        {           
            Console.WriteLine(-1);
            return;
        }

        int x = 2;
        int y = 2;
        Console.WriteLine("1 2");
        for(int i=1; i<n-1; i++)
        {
            y++;
            Console.WriteLine(x + " " + y);
            if (a[i] == 1) x = y;
        }            
    }

    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
    public static string[] NextS() { return Console.ReadLine().Trim().Split(' '); }
}


Measured memory_bytes: 17356
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(R);
    scanInt(C);
    scanInt(N);
    vector<tuple<int, int>> online;
    auto is_online = [&](int x, int y){return (x == 0 || x == R || y == 0 || y == C);};
    auto add_online = [&](int x, int y, int i){
        if (y == 0){
            online.emplace_back(x, i);
        }else if (x == R){
            online.emplace_back(R + y, i);
        }else if (y == C){
            online.emplace_back(R + C + R - x, i);
        }else if (x == 0){
            online.emplace_back(R + C + R + C - y, i);
        }
    };
    loop(i, N){
        scanInt(x1);
        scanInt(y1);
        scanInt(x2);
        scanInt(y2);
        if (is_online(x1, y1) && is_online(x2, y2)){
            add_online(x1, y1, i);
            add_online(x2, y2, i);
        }
    }
    sort(online.begin(), online.end(), [](const tuple<int, int>& l, const tuple<int, int>& r){return get<0>(l) < get<0>(r);});
    stack<int> st;
    for (auto& e : online){
        int& i = get<1>(e);
        if (0 < st.size() && st.top() == i){
            st.pop();
        }else{
            st.emplace(i);
        }
    }
    if (st.size() == 0){
        puts("YES");
    }else{
        puts("NO");
    }
}


Measured memory_bytes: 2420
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

// Longest (Strictly) Increasing Sequence
class LIS{
public:
    vector<int> S, L;
    LIS(vector<int> S) : S(S) {}
    
    vector<int> calc(){
        int len = 1; // length of LIS
        L.push_back(S[0]);
        repd(i, 1, S.size()){
            if (L[len - 1] < S[i]) {
                L.push_back(S[i]);
                len++;
            }
            else{
                int l = -1, r = len - 1;
                while (r - l > 1) {
                    int mid = (r + l) / 2;
                    if (L[mid] >= S[i]) {
                        r = mid;
                    }
                    else{
                        l = mid;
                    }
                }
                if(L[r] > S[i]) L[r] = S[i];
            }
        }
        return L;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    LIS lis(A);
    vector<int> L = lis.calc();
    
    output(L.size(), 0);
    
    
    return 0;
}

Measured memory_bytes: 4504
#include <bits/stdc++.h>
#define LL long long
using namespace std;

const int N = 1e5;

int n,k,cnt0 = 0;
LL a[N+10];

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n >> k;
    for (int i = 1;i <= n;i++){
        cin >> a[i];
        if (a[i]==0) cnt0++;
    }
    if (cnt0==0) a[++n] = 0;
    sort(a+1,a+1+n);
    int idx = 1;
    for (int i = 1;i <= n;i++) if (a[i]==0) idx = i;
    LL ans = 1e18;
    for (int i = 1;i <= n;i++){
        if (i==idx) {
            if (k==1 && cnt0){
                ans = min(ans,1LL*0);
            }
            continue;
        }
        LL temp = 0;
        int cnt = 0;
        temp = temp + abs(a[idx]-a[i]);
        cnt+=abs(idx-i);
        if (cnt0) cnt++;
        if (cnt>k) continue;
        if (cnt==k){
            ans = min(ans,temp);
            continue;
        }
        //cnt<k
        if (i<idx){
            if (idx+k-cnt<=n){
                temp = temp + 2*abs(a[idx+k-cnt]-a[idx]);
                ans = min(ans,temp);
            }else continue;
        }else{
            if (idx-(k-cnt)>=1){
                temp = temp + 2*abs(a[idx]-a[idx-(k-cnt)]);
                ans = min(ans,temp);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int x;
  cin >> x;
  x = abs(x);
  long long d = 0;
  for (int i = 1;; i++) {
    d += i;
    if (d >= x) {
      cout << i << endl;
      return 0;
    }
  }
}

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

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

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

int dfs(int v, int n, int *visited, int table[n][n]) {
    int all_visited = 1, i;

    REP(i,n) {
        if (!visited[i]) {
            all_visited = 0;
            break;
        }
    }

    if (all_visited) {
        return 1;
    }

    int count = 0;

    REP(i,n) {
        if (!table[v][i]) continue;
        if (visited[i]) continue;

        visited[i] = 1;
        count += dfs(i, n, visited, table);
        visited[i] = 0;
    }

    return count;
}

int main() {
    int a = iin(), b = iin(), c = iin();
    ((a <= c && c <= b) || (a >= c && c >= b)) ? stout("Yes") : stout("No");
    return 0;
}


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

int main() {
    int k;
    string s,res;
    cin>>k>>s;
    int len=s.size();
    if (len<=k) cout<<s<<endl;
    else {
        res=s.substr(0,k);
        res+="...";
        cout<<res<<endl;
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  int add,sub,mul;
  add=a+b;
  sub=a-b;
  mul=a*b;
  if(add>sub)
  {
    if(add>mul)
      cout<<add;
    else
      cout<<mul;
  }
  else if(sub>mul)
    cout<<sub;
  else
    cout<<mul;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
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 long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, m; cin >> n >> m;
    vector<int> g[n];
    vector<int> v(n - 1);
    rep(i, m)
    {
        int a, b; cin >> a >> b;
        a--;b--;
        g[a].push_back(b), g[b].push_back(a);
    }
    rep(i, n - 1) v[i] = i + 1;

    int ans = 0;
    do
    {
        int now = 0;
        bool ok;
        rep(i, n - 1)
        {
            ok = false;
            for(auto it : g[now])
            {
                if (it == v[i])
                {
                    ok = true;
                    now = v[i];
                    break;
                }
            }
            if (!ok) break;
        }
        if (ok) ans++;
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << endl;
}

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

int main(void) {
    long long k, score, x;
    int top;

    scanf("%lld",&x);
    score = 0LL;
    k = 0LL;

    k = x/11LL * 2LL;
    // 最初に2~5を上に向ければ初手で6点とれる
    top = 5;
    if (x % 11LL > 6) k += 2LL;
    else if (x % 11LL > 0) k += 1LL;
    
    printf("%lld\n", k);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int n, A[20];

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

int main(void) {
  int i, q, m, j = 0;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; ++i) {
    scanf("%d", &m);
    int f = exhaustive(j, m);
    printf("%s\n", f ? "yes" : "no");
  }
}



Measured memory_bytes: 2140
package main

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

func solve() {
	n := getInt()
	ts, as := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		ts[i] = getInt()
		as[i] = getInt()
	}

	t, a := 0, 0
	for i := 0; i < n; i++ {
		nt, na := ts[i], as[i]
		switch {
		case nt >= t && na >= a:
			t = nt
			a = na
		case nt < na:
			t = t + (nt-t%nt)%nt
			if a > t/nt*na {
				a = a + (na-a%na)%na
				t = a / na * nt
			} else {
				a = t / nt * na
			}
		default:
			a = a + (na-a%na)%na
			if t > a/na*nt {
				t = t + (nt-t%nt)%nt
				a = t / nt * na
			} else {
				t = a / na * nt
			}
		}
	}

	ans := t + a
	fmt.Fprintln(wr, ans)
}

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: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1<<30;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[8]={1,0,-1,0,1,1,-1,-1} , dy[8]={0,1,0,-1,1,-1,1,-1} ;

int main(){
    int n,m;
    cin>>n>>m;
    pint a[m];
    rep(i,m)cin>>a[i].second>>a[i].first;
    int cnt=0;
    int pos=-1;
    sort(a,a+m);
    rep(i,m){
        if(a[i].second>=pos){
            cnt++;
            pos=a[i].first;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    int a=0,b=0,c=0;
    rep(i,n){
        if(v[i]%4==0)c++;
        else if(v[i]%2==0)b++;
        else a++;
    }
    
    int bef = -1;
    
    rep(i,n){
        if(bef==-1 || bef==4){
            if(a){
                a--;
                bef = 1;
            }else if(b){
                b--;
                bef = 2;
            }else if(c){
                c--;
                bef = 4;
            }else{
                cout<<"No"<<endl;
                return 0;
            }
        }else if( bef==2 ){
            if(b){
                b--;
                bef = 2;
            }else if(c){
                c--;
                bef = 4;
            }else{
                cout<<"No"<<endl;
                return 0;
            }
        }else if( bef==1 ){
            if(c){
                c--;
                bef = 4;
            }else{
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	int mx = max(A,max(B,C));

	int sum = A + B + C - mx + mx * (1 << K);

	println(sum);
	return 0;

}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
int main() {
	int n, k;
	cin >> n >> k;
	int ans = 1;
	REP(i, n) {
		if (ans >= k) {
			ans += k;
		}
		else {
			ans *= 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a<=9&&b<=9){
  cout<<a*b<<endl;
}
  else if(a>=10&&b>=10){
  cout<<-1<<endl;
  }
  else if(a>=10&&b<=9){
    cout<<-1<<endl;
  }
  else if(a<=9&&b>=10){
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i+=2){
        cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 512
using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using System.Timers;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var res = 0;

            var nums = new[] { '0', '1' };

            var S = Console.ReadLine().ToCharArray();

            for (int i = 0; i < S.Length; i++)
            {
                if (nums[((S[0] == '0' ? 0 : 1) + i % 2) % 2] != S[i])
                {
                    res++;
                }
            }

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13176