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

struct edge {
    int v;
    ll w;
    edge() {}
    edge(int v, ll w) : v(v), w(w) {};
};

vector<ll> dijkstra(int n, vector<vector<edge> >& G, int s) {
    vector<ll> d(n, LLONG_MAX/10); d[s] = 0;
    priority_queue<pair<ll, int> > que;
    que.push(make_pair(0ll, s));
    while (!que.empty()) {
        auto p = que.top(); que.pop();
        int u = p.second;
        ll dist = -p.first;
        if (dist > d[u]) continue;
        for (edge e : G[u]) {
            if (d[e.v] > d[u]+e.w) {
                d[e.v] = d[u] + e.w;
                que.push(make_pair(-d[e.v], e.v));
            }
        }
    }
    return d;
}

const int B = 111;
bool ng[2*B][2*B];
int Lx, Ly;
const int INF = 1e9;

pii move(int x, int y, int dir) {
    int nx = x, ny = y;
    switch (dir) {
    case 0:
        ny += 1;
        break;
    case 3:
        ny -= 1;
        break;
    case 1:
        nx += 1;
        if (x%2) ny += 1;
        break;
    case 2:
        nx += 1;
        if (x%2 == 0) ny -= 1;
        break;
    case 4:
        nx -= 1;
        if (x%2 == 0) ny -= 1;
        break;
    case 5:
        nx -= 1;
        if (x%2) ny += 1;
        break;
    }
    if (abs(nx) > Lx || abs(ny) > Ly || ng[nx+B][ny+B]) {
        nx = -B;
        ny = -B;
    }
    return pii(nx, ny);
}

int getVertex(int t, int x, int y) {
    x += B; y += B;
    int ret = t;
    ret = ret*2*B + x;
    ret = ret*2*B+y;
    return ret;
}

int main() {
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        ng[x+B][y+B] = true;
    }
    cin >> Lx >> Ly;
    vector<vector<edge> > G(6*2*B*2*B);
    for (int t = 0; t < 6; t++) {
        for (int x = -Lx; x <= Lx; x++) for (int y = -Ly; y <= Ly; y++) {
            int v = getVertex(t, x, y);
            int should = abs(t*x*y)%6;
            for (int i = 0; i <= 6; i++) {
                auto next = move(x, y, i);
                if (next.first == -B) continue;
                int u = getVertex((t+1)%6, next.first, next.second);
                int cost = 1;
                if (i == should) cost = 0;
                G[v].emplace_back(u, cost);
            }
        }
    }
    auto d = dijkstra(6*2*B*2*B, G, getVertex(0, sx, sy));
    ll ans = INF;
    for (int i = 0; i < 6; i++) {
        ans = min(ans, d[getVertex(i, gx, gy)]);
    }
    if (ans >= INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 46004
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    char ch;
    cin >> ch;
    ch = ch + 1;
    cout << ch << "\n";

    return 0;
}

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

int main(){
  int N;
  cin>>N;
  double X[N],Y[N];
  for (int i=0;i<N;i++){
    cin>>X[i]>>Y[i];
  }
  double total=0;
  double count=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      count++;
      total=total+pow(pow((X[j]-X[i]),2)+pow((Y[j]-Y[i]),2),0.5);
    }
  }
  printf("%12f\n",total/count*(N-1));
  cout<<endl;
      
  return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

 class Main {

	@SuppressWarnings("unused")
	public static void main(String[] args) {
		FastScanner in = new FastScanner();
//		int T = in.nextInt();
//		outer: for (int tt = 0; tt < T; tt++) {
//		}
		int n = in.nextInt();
		int k = in.nextInt();
		int a[] = in.readArray(n);
		int dp[] = new int[n + 1];
		Arrays.fill(dp, -1);
		System.out.println(frog2(dp, a, n - 1, k));
	}

	public static int frog2(int dp[], int a[], int N, int K) {
		if (N == 0)
			return 0;

		if (dp[N] != -1)
			return dp[N];
		int ans = Integer.MAX_VALUE;
		for (int i = 1; i <= K; i++) {
			if (N - i >= 0) {
				ans = Math.min(ans, (Math.abs(a[N] - a[N - i]) + frog2(dp, a, N - i, K)));
			}
		}
		dp[N] = ans;
		return ans;

	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

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

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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

}


Measured memory_bytes: 58048
#include<cstdio>
#include<cmath>
using namespace std;
int Q;
double q,x,eps;
int main()
{
	for(;scanf("%d",&Q),Q!=-1;)
	{
		q=1.0*Q;
		eps=q*0.00001;
		x=1.0*Q/2;
		for(;abs(pow(x,3)-Q)>=eps;)
		{
			x=x-(pow(x,3)-Q)/(3*pow(x,2));
		}
		printf("%lf\n",x);
	}
	return 0;
}

Measured memory_bytes: 1060
#include<stdio.h>

int n,A[50];

int solve(int i,int m){
  if(m==0)return 1;
  if(i>=n)return 0;
  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");
  }
  return 0;
}



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

using namespace std;

int main() {
    int N, K;
    double ans = 0, temp = 0;
    vector<int> p;
    cin >> N >> K;
    for(auto i = 0; i < N; i++) {
        int in;
        cin >> in;
        p.push_back(in);
        temp += (1.0+ in) / 2;
        if(K <= i)
            temp -= (1.0 + p[i - K]) / 2;
        if(ans < temp)
            ans = temp;
    }
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
int n;
string s;
set<string> myset;
int main(){
    cin >> n;
    for(int i = 0 ; i < n ;i++){
        cin >> s;
        myset.insert(s);
    }
    cout << myset.size() << endl;
    return 0;
}


Measured memory_bytes: 19156
n = int(input())
w = list(map(int, input().split()))

list_sum = sum(w)

ans = 1000000
s1 = 0
s2 = list_sum
for i in range(n):
  s1 += w[i]
  s2 -= w[i]
  ans = min(ans,max(s1-s2,s2-s1))

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int a, b, m;
  std::cin >> a >> b >> m;

  vector<int> a_arr(a);
  vector<int> b_arr(b);
  for(int idx = 0; idx < a; idx++) std::cin >> a_arr[idx];
  for(int idx = 0; idx < b; idx++) std::cin >> b_arr[idx];

  vector<int> x_arr(m);
  vector<int> y_arr(m);
  vector<int> c_arr(m);
  for(int idx = 0; idx < m; idx++){
    std::cin >> x_arr[idx] >> y_arr[idx] >> c_arr[idx];
  }

  int ans = INT_MAX;
  for(int idx = 0; idx < m; idx++){
    int val = a_arr[x_arr[idx] - 1] + b_arr[y_arr[idx] - 1] - c_arr[idx];
    if(ans > val){
      ans = val;
    }
  }

  sort(a_arr.begin(), a_arr.end());
  sort(b_arr.begin(), b_arr.end());
  int val = a_arr[0] + b_arr[0];
  if(ans > val){
    ans = val;
  }

  std::cout << ans << '\n';


  return 0;
}


Measured memory_bytes: 2176
x = int(input())

flag = [True]*(10**6+1)
flag[0] = flag[1] = False

for i in range(4, 10**6+1,2): flag[i] = False
for i in range(3, int((10**6)**0.5)+1, 2):
  if flag[i]:
    for j in range(i+i, 10**6+1, i): flag[j] = False
      
while True:
  if flag[x]:
    print(x)
    exit()
  x += 1

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

using K = string;
using M = map<K, int>;

K mul(K k1, K k2){
	k1 += k2;
	sort(k1.begin(), k1.end());
	return k1;
}

M add(M m1, M m2){
	for(auto v : m2){
		m1[v.first] += v.second;
	}
	return m1;
}

M mul(M m1, M m2){
	M ret;
	for(const auto& v1 : m1){
		for(const auto& v2 : m2){
			K k = mul(v1.first, v2.first);
			ret[k] += v1.second * v2.second;
		}
	}
	return ret;
}

M pow(M m, int x){
	M ret;
	ret[""] = 1;
	M a = m;
	while(x){
		if(x & 1) ret = mul(ret, a);
		x /= 2;
		a = mul(a, a);
	}
	return ret;
}

int c;
int N;
string s;

M exp();
M term();
M fact();

void skip(){
	while(c < N && (s[c] == ' ')) c++;
}

M exp(){
	skip();
	M t1 = term();

	skip();
	while(c < N && (s[c] == '+' || s[c] == '-')){
		char ch = s[c];
		c++;
		skip();
		M t2 = term();
		if(ch == '-'){
			for(auto& v : t2){
				v.second *= -1;
			}
		}
		t1 = add(t1, t2);
	}
	return t1;
}

M term(){
	skip();
	M f1 = fact();
	skip();
	while(c < N && (isalnum(s[c]) || s[c] == '(')){
		M f2 = fact();
		skip();
		f1 = mul(f1, f2);
	}
	return f1;
}

M fact(){
	skip();
	M r;
	if(s[c] == '('){
		c++;
		r = exp();
		c++;
		skip();
	}
	else if(isalpha(s[c])){
		K k;
		k += s[c];
		c++;
		r[k]++;
	}
	else if(isdigit(s[c])){
		int x = 0;
		while(c < N && isdigit(s[c])){
			x = x * 10 + s[c] - '0';
			c++;
		}
		r[""] += x;
	}
	skip();
	if(c < N && s[c] == '^'){
		c++;
		skip();
		int x = s[c] - '0';
		c++;
		skip();
		r = pow(r, x);
	}
	return r;
}

M f(string t){
	c = 0;
	s = t;
	N = s.size();
	return exp();
}

M filter(M m){
	M ret;
	for(auto v : m){
		if(v.second == 0) continue;
		ret[v.first] = v.second;
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	//auto ret = f("a- (b-c)+2");

	string x, y;
	while(getline(cin, x), x != "."){
		M xm = filter(f(x));
		while(getline(cin, y), y != "."){
			auto res = filter(f(y));
			if(xm == res){
				cout << "yes" << endl;
			}
			else{
				cout << "no" << endl;
			}
		}
		cout << "." << endl;
	}
}

Measured memory_bytes: 3380
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

long long fac[1100000],finv[1100000],inv[1100000];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<1100000;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
long long COM(int n,int k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
long long facdiv(lint n,lint k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return (fac[n]*finv[k])%MOD;
}

int main(void){
  COMinit();
  lint X,Y;
  cin >> X >> Y;
  lint sum=X+Y;
  if(sum%3!=0) cout << 0 << endl;
  else if(X>Y*2 || Y>X*2) cout << 0 << endl;
  else{
    lint turn=sum/3;
    lint x2=X-turn;
    cout << COM(turn,x2) << endl;
  }
}

Measured memory_bytes: 25984
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		boolean[] issafe = new boolean[N + 1];
		Arrays.fill(issafe, true);
		for (int i = 0; i < M; i++) {
			issafe[in.nextInt()] = false;
		}
		int[] dp = new int[N + 1];
		dp[0] = 1;
		if (issafe[1]) {
			dp[1] = 1;
		}
		for (int i = 2; i <= N; i++) {
			if (issafe[i - 1]) {
				dp[i] += dp[i - 1];
			}
			if (issafe[i - 2]) {
				dp[i] += dp[i - 2];
			}
			dp[i] %= 1000000007;
		}
		System.out.println(dp[N]);
		in.close();
	}
}

Measured memory_bytes: 48368
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<int> sortedA = A;
  sort(sortedA.rbegin(), sortedA.rend());
  rep(i, N) {
    if(sortedA[0] == A[i])
      cout << sortedA[1] << endl;
    else
      cout << sortedA[0] << endl;
  }
  return 0;
}

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

int main(){
  int n; cin >> n;
  vector<int> L(n);
  int max_L = 0, sum=0;
  for(int i = 0; i < n; i++)
  {
    cin >> L.at(i);
    sum += L.at(i);
    if (max_L < L.at(i)) {
      max_L = L.at(i);
    }
  }

  if (max_L >= sum - max_L) {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }
  
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
int table[100000];
int main() {
	ll x;
	scanf("%lld", &x);
	printf("%lld\n", x / 11 * 2 + (x % 11 + 5) / 6);
	return 0;
}

Measured memory_bytes: 256
int_s = input()
str_sr = int_s[::-1]


str_a = ['dream', 'dreamer', 'erase', 'eraser']

str_r = list(map(lambda x: x[::-1], str_a))

result = True

while len(str_sr):
    currnt_flg = False
    for r in str_r:
        # print('r:' + r)
        if len(str_sr) >= len(r) and str_sr[:len(r)] == r:
            # print('ok')
            str_sr = str_sr[len(r):]
            # print(str_sr)
            current_flg = True
            break
    else:
        result = False
        break

if result:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    long long int H,N,i,count=0;
    ;long long int a[100000];
    scanf("%ld %ld",&H,&N);
    for(i=0;i<N;i++)
    {
        scanf("%ld",&a[i]);
    }
    for(i=0;i<N;i++)
    {
        count=count+a[i];
    }
    if(count>=H)  printf("Yes");
    else printf("No");
 
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

double dp[3005][3005];

int main(){
  int N;
  cin >> N;
  vector<double> v;
  rep(i,N){
    double p;
    cin >> p;
    v.push_back(p);
  }

  dp[0][0] = 1-v[0];
  dp[0][1] = v[0];
  REP(i,1,N){
    rep(j,i+2){
      dp[i][j] = dp[i-1][j] * (1-v[i]);
      if(j-1>=0) dp[i][j] += dp[i-1][j-1] * v[i];
    }
  }

  double ret = 0;
  rep(i,N+1){
    if(i > N-i) ret += dp[N-1][i];
  }

  printf("%.12lf\n", ret);
  
  return 0;
}


Measured memory_bytes: 68992
import java.util.*;

public class Main{
	void doIt(){
		Scanner sc = new Scanner(System.in);
		Runner[][] rdata = new Runner[4][];
		for(int i=0; i<3; ++i){
			rdata[i] = new Runner[8];
			for(int j=0; j<8; ++j){
				int a=sc.nextInt();
				Double d=sc.nextDouble();
				rdata[i][j] = new Runner(a,d);
			}	
		}
		
		for(int i=0; i<3; ++i){	
			Arrays.sort(rdata[i]);
		}
		rdata[3] = new Runner[6];
		for(int i=0,j=0; i<3; ++i){
			rdata[3][j++] = rdata[i][2];
			rdata[3][j++] = rdata[i][3];
		}
		Arrays.sort(rdata[3]);
		for(int i=0; i<4; ++i){
			System.out.println(rdata[i][0].toString());
			System.out.println(rdata[i][1].toString());
		}
	}
	public static void main(String args[]){
		new Main().doIt();
	}
	class Runner implements Comparable<Runner>{
		Double time;
		int num;
		Runner(int num, double time){
			this.num = num;
			this.time = time;
		}
		public void set(int num, Double time){
			this.num = num;
			this.time = time;
		}
		public String toString(){
			String str_time = String.format("%.2f", time);
			return num + " " + str_time;
		}
		public int compareTo(Runner o){
			return time.compareTo(o.time);
		}
	}
}

Measured memory_bytes: 20228
import java.util.*;

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

    int cntA = 0;
    int cntB = 0;
    int cntC = 0;
    int nextIda = 0;
    int nextIdb = 0;
    int nextIdc = 0;
    char next = 'a';
    char ans = 'x';

    outline:while(true){
      switch(next){
        case 'a':
          cntA++;
          if(cntA > stra.length()){ans = 'a'; break outline;}
          next = stra.charAt(nextIda);
          nextIda++;
          break;
        case 'b':
          cntB++;
          if(cntB > strb.length()){ans = 'b'; break outline;}
          next = strb.charAt(nextIdb);
          nextIdb++;
          break;
        case 'c':
          cntC++;
          if(cntC > strc.length()){ans = 'c'; break outline;}
          next = strc.charAt(nextIdc);
          nextIdc++;
          break;
      }
    }

    if(ans == 'a'){
      System.out.println('A');
    }else if(ans == 'b'){
      System.out.println('B');
    }else{
      System.out.println('C');
    }
  }
}

Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <tuple>
#include <functional>
#include <map>
#include <unordered_map>
#include <queue>
#include <tuple>
#include <random>
#include <stack>

using namespace std;

#define endl '\n'

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using lld = long double;
using ull = unsigned long int;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  const int precision = 13;
  cout.precision(precision);
  cout.setf(ios_base::fixed);

  int n; cin >> n;
  vector<ll> a(n);
  for (auto& it : a) cin >> it;
  for (int i = 1; i < n; ++i) a[i] += a[i-1];

  vector<vector<ll>> dp(n, vector<ll>(n, 1e18));

  for (int i = 0; i < n; ++i) {
    dp[i][i] = 0;
    for (int j = i-1; j >= 0; --j) {
      ll acc = a[i] - (j > 0 ? a[j-1] : 0);
      for (int k = j; k < i; ++k) {
        dp[i][j] = min(dp[i][j], acc + dp[i][k+1] + dp[k][j]);
      }
    }
  }

  cout << dp[n-1][0] << endl;

  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

struct Solver
{
	const int N, M, K;
	double res;

	Solver( int n, int m, int k ) :
		N( n ), M( m ), K( k ), res( 0. )
	{
		return;
	}

	operator double()
	{
		dfs( 0, 0 );
		return res;
	}

	void dfs( int depth, int sum )
	{
		if ( depth == N )
		{
			res += 1. * max( 1, sum - K ) / pow( M, N );
			return;
		}

		REP( i, 0, M )
		{
			dfs( depth + 1, sum + i + 1 );
		}
		return;
	}
};

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

	for ( int n, m, k; cin >> n >> m >> k, n | m | k; )
	{
		cout << Solver( n, m, k ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1320
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
	int a,b;
	cin >> a>>b;
	if((a+b)%3==0 || a%3==0 || b%3==0){
		cout << "Possible" << endl;
	}
	else cout << "Impossible" << endl; 
	return 0;
}

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

#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pie;
const int MOD = 998244353;
const int INF = 2e9;
const ll LINF = 4e18;
const ll delta = 1634569;

const int N = 6e3 + 20;
int C[N][N], n, k;

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	for (int i = 0; i < N; i++)
		C[0][i] = C[i][i] = 1;
	for (int i = 2; i < N; i++)
		for (int j = 1; j < i; j++)
			C[j][i] = (C[j - 1][i - 1] + C[j][i - 1]) % MOD;
	cin >> k >> n;
	for (int i = 2; i <= 2 * k; i++) {
		int t, ans = 0;
		if (i <= k + 1)
			t = i / 2;
		else
			t = k - i / 2 + 1 - i % 2;
//		cout << t << ' ';
		for (int j = 0; j <= t; j++)
			ans = (ans + (1LL * (j % 2 ? -1 : +1) * C[j][t] * C[k - 1][n + k - 1 - 2 * j]) % MOD + MOD) % MOD;
		cout << ans << endl;
	}
}



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


void dfs(int node, vector < vector<int> >&arr, char c[])
{
	if (c[node]=='g')
	{
		return;
	}
	c[node]='g';
	for (int i=0; i<arr[node].size(); i++)
	{
		if (c[arr[node][i]]=='w')
		{
			dfs(arr[node][i], arr, c);
		}
	}
}


int main()
{
	/*
	 #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    */

	int n,m;
	cin>>n>>m;
	vector< vector <int> >arr(n+1);
	int a,b;
	for (int i=0; i<m; i++)
	{
		cin>>a>>b;
		arr[a].push_back(b);
		arr[b].push_back(a);

	}
	char* c=new char[n+1];
	for (int i=0; i<=n; i++)
	{
		c[i]='w';
	}
	int ans=0;
	for (int i=1; i<=n; i++)
	{
		if (c[i]=='w')
		{

			dfs(i, arr, c);
			if (i==1)
			{
				continue;
			}
			ans++;
		}

	}
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 9812
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>

#define pii pair <int, int>
#define pb push_back
#define ll long long
#define ss second
#define ff first
#define N 100010

using namespace std;

int n;
int v[5][N];
int a[5][N];
int b[5][N];

int main()
{
	cin >> n;
	
	for(int i = 1; i <= 2; i++)
		for(int h = 1; h <= n; h++)
			cin >> v[i][h];
	
	for(int i = 1; i <= 2; i++)
		for(int h = 1; h <= n; h++)
			a[i][h] = a[i][h-1] + v[i][h];
	
	for(int i = 1; i <= 2; i++)
		for(int h = n; h >= 1; h--)
			b[i][h] = b[i][h+1] + v[i][h];
	
	int ans = 0;
	for(int h = 1; h <= n; h++)
		ans = max(ans, a[1][h] + b[2][h]);
	
	cout << ans;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];

  sort(RALL(a));



  if(n == 2){
    cout << a[0] << endl;
    return 0;
  }

  ll sum = 0;
  int ai = 1;

    sum = a[0];
    for(int i = 1; i < n-1; ++i){
      if(i%2 ==1) sum += (ll)a[ai];
      else{
        sum += (ll)a[ai];
        ++ai;
      }
    }







  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 4832
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_10_C
 */
#include <iostream>
#include <iomanip>
#include <vector>
#include <numeric>
#include <cmath>

using namespace std;

int
main()
{
    ios::sync_with_stdio(false);

    cout << setprecision(8) << fixed;
    while (true) {
        int n;
        cin >> n; cin.ignore();

        if (n == 0) { break; }
        vector<double> S(n);
        for (int i = 0; i < n; i++) {
            cin >> S[i]; cin.ignore();
        }
        double m = accumulate(S.cbegin(), S.cend(), 0.0) / n;

        double ndistrib = 0;
        for (auto it : S) {
            ndistrib += (it - m) * (it - m);
        }
        cout << sqrt(ndistrib / n) << endl;
    }

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  int minus = 0;
  int64_t sum = 0;
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
    if(vec.at(i) < 0){
      minus++;
      vec.at(i) *= -1;
    }
    sum += vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  if(minus %2 != 0){
    sum -= vec.at(0)*2;
  }
  cout << sum << endl;
} 

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

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

	int a = 4, b = 7;
	string ans = "No";

	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(a * i + b * j == n){
				ans = "Yes";
				break;
			}
		}
	}

	cout << ans << endl;
}


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

int main(){
  string s;
  cin >> s;
  string table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int move = 0;
  int out = 0;

  for( int i = 0; i < s.length(); i++ ){
    while(1){
      move++;
      if( table[(move-1)%(table.length())] == 'Z'){
        out++;
      }
      if(table[move%(table.length())] == s[i]) break;
    }
  }
  cout << out << endl;
}

Measured memory_bytes: 3216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		long ans = a[n-1];
		long k = 1;
		for(int i = n-2; i > 0; i--) {
			ans += a[i];
			k++;
			if(k == n-1)break;
			ans += a[i];
			k++;
			if(k == n-1)break;
		}
		if(n == 2) {
			System.out.println(a[1]);
		}else {
			System.out.println(ans);
		}
		
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 56768
#include<iostream>
#include<cmath>
#define MOD 1000000007
#define MAX_NUM 1000000001
using namespace std;
typedef long long ll;

ll factorial_num[int(40000 + 100001)];

ll calc_pow(ll x, ll y) {
    ll z = 1;
    while (y > 0) {
        if ((y & 1) == 1) z = ((z % MOD) * (x % MOD)) % MOD;
        x = (x * x) % MOD;
        y /= 2;
    }
    return z;
}

ll calc_comb(ll x, ll y) {
    ll div_num = ((factorial_num[x - y] % MOD) * (factorial_num[y] % MOD)) % MOD;
    return ((factorial_num[x] % MOD) * (calc_pow(div_num, MOD - 2) % MOD)) % MOD;
}

int main() {
    ll N, M;
    cin >> N >> M;
    factorial_num[0] = 1;
    for (int i = 1; i <= int(sqrt(MAX_NUM)) + 100001; i++) {
        factorial_num[i] = ((i % MOD) * (factorial_num[i - 1] % MOD)) % MOD;
    }
    ll all_comb = 1;
    for (ll div_num = 2; div_num <= int(sqrt(M)) + 2; div_num++) {
        ll fact_count = 0;
        while (M % div_num == 0) {
            M /= div_num;
            fact_count++;
        }
        all_comb = ((all_comb % MOD) * (calc_comb(fact_count + N - 1, fact_count) % MOD));
    }
    if (M != 1) all_comb = ((all_comb % MOD) * (calc_comb(N, 1) % MOD));
    cout << all_comb % MOD << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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 INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);

// binary Scearch
//評価関数が小さいものが最初、大きくなるのは最後,求めたい値と評価関数とを入れる
// first:lower,second;upper
// ded: ex); function<ll(ll)>det=[=](ll b){return min(a[0],b);};

pair<pair<long long, long long>, pair<long long, long long> > BScearch(long long start, long long stop, long long terget,function<long long(long long)> det) {
	pair<pair<long long, long long>, pair<long long, long long> > tmp = {make_pair(start,0LL), make_pair(stop, INFLL)};
	pair<long long, long long> mid;
	while (abs(tmp.first.first - tmp.second.first) > 1) {
		mid.first  = tmp.first.first + (tmp.second.first - tmp.first.first) / 2;
		mid.second = det(mid.first);
		if (mid.second > terget) {
			tmp.second = mid;
		} else {
			tmp.first = mid;
		}
	}
	return tmp;
}
int main() {
	int n;
	ll k;

	cin >> n >> k;
	// a.assign(n, 0LL);
	V a(n);
	ll up = 0LL;
	rep(i, n) {
		cin >> a[i];
		chmax(up, a[i]);
	}
	function<ll(ll)> func = [=](ll ter) {
		ll res = 0LL;
		repi(itr, a) { res += ((*itr) + ter - 1) / ter - 1; }
		return res;
	};

	pair<P, P> ans = BScearch(up, 0LL, k, func);
	clog << ans.F.F << " " << ans.S.S << endl;
	clog << ans.S.F << " " << ans.S.S << endl;
	cout << ans.F.F << endl;
}

Measured memory_bytes: 7956
n=int(input())
s=str(input())

if n<4:
    print(0)
else:
    r=0
    g=0
    ans=0
    for i in range(n):
        if s[i]=="R":
            r+=1
        elif s[i]=="G":
            g+=1
        if i>n-3:
            continue
        for k in range(1,(n-i-1)//2+1):
            if s[i]==s[i+k]:
                continue
            else:
                if s[i+k]==s[i+2*k] or s[i]==s[i+2*k]:
                    continue
                else:
                    ans-=1

    ans+=r*g*(n-r-g)
    print(max(0,ans))


Measured memory_bytes: 9092
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int p2[10] = {512,256,128,64,32,16,8,4,2,1},n;
  vector<int> v;
  while(cin>>n){
    for(int i=0;i<10;i++){
      if(n>=p2[i])n-=p2[i],v.push_back(p2[i]);
    }
    sort(v.begin(),v.end());
    vector<int>::iterator it=v.begin();
    for(;it!=v.end();it++){
      cout<<*it;
      (it+1==v.end())?cout<<endl:cout<<" ";
    }
    v.clear();
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int[] c = new int[n];
		int[] a = new int[n * m];
		int[] aSum = new int[m];
		for (int i = 0; i < n; ++i) {
			c[i] = sc.nextInt();
			for (int j = 0; j < m; ++j) {
				a[m * i + j] = sc.nextInt();
				aSum[j] += a[m * i + j];
			}
		}

		for (int i = 0; i < m; ++i) {
			if (aSum[i] < x) {
				System.out.println(-1);
				return;
			}
		}

		int ans = 1 << 30;
		int[] richard = new int[m];
		for (int num = 0; num < (1 << n); ++num) {
			String bin = getBinary(num, n);
			Arrays.fill(richard, 0);
			int cost = 0;
			for (int i = 0; i < n; ++i) {
				char bit = bin.charAt(i);
				if (bit == '1') {
					cost += c[i];
					for (int j = 0; j < m; ++j) {
						richard[j] += a[m * i + j];
					}
				}
			}

			if (hasSmaller(richard, x)) {
				continue;
			}

			ans = Math.min(ans, cost);
		}

		System.out.println(ans);
	}

	private static boolean hasSmaller(int[] richard, int x) {
		// TODO 自動生成されたメソッド・スタブ
		for (int i = 0; i < richard.length; ++i) {
			if (richard[i] < x) {
				return true;
			}
		}
		return false;
	}

	private static String getBinary(int num, int n) {
		// TODO 自動生成されたメソッド・スタブ
		StringBuilder sb = new StringBuilder();
		for (int cnt = 0; cnt < n; ++cnt) {
			sb.append(num % 2);
			num /= 2;
		}
		return sb.toString();
	}

}


Measured memory_bytes: 38048
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string s,n,h,a;
  cin>>n>>a>>h;
  transform(n.begin(), n.end(), n.begin(), ::toupper);
  transform(a.begin(), a.end(), a.begin(), ::toupper);
  transform(h.begin(), h.end(), h.begin(), ::toupper);
  cout<<n[0]<<a[0]<<h[0]<<'\n';
  return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define f first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pii pair<double, double>
#define all(x) x.begin(), x.end()

const int N = 1e5 + 144, mod = 1e9 + 7, inf = 1e9 + 7;
int n, k, a[N];
int dp[N];
bool was[N];

ll bp(ll x, ll y){
    if(y == 0)
        return 1;
    if(y & 1)
        return (x * bp(x, y - 1)) % mod;
    ll z = bp(x, y / 2);
    return (z * z) % mod;
}

int rec(int x){
    if(x < 0)
        return 1;
    if(was[x])
        return dp[x];
    int p = 1;
    for(int i = 1; i <= n; i++){
        p = min(p, rec(x - a[i]));
    }
    p = 1 - p;
    was[x] = 1;
    dp[x] = p;
    return p;
}

int main(){
    boost;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    if(rec(k)){
        cout << "First";
    }else cout << "Second";
    return 0;
}


Measured memory_bytes: 5376
a, b, x = gets.chomp.split(" ").map(&:to_i);

if a * a * b >= (2 * x) then
  puts  180 / Math::PI * Math.atan((a*b*b).to_f/(2*x))
else
  puts  180 / Math::PI * Math.atan(2 * (a*a*b - x).to_f/(a**3))
end


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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    string s;
    cin >> s;

    ll n = s.size();
    map<char, int> mp;
    rep(i, n) {
        mp[s[i]]++;
    }

    ll ans = n * (n - 1) / 2LL;
    for(auto p : mp) {
        ll x = p.second;
        ans -= x * (x - 1) / 2LL;
    }

    cout << ans + 1 << endl;

    return 0;
}


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

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int vmax=100010;

vi graph[vmax],ord,low,scc,par;
stack<int>s;

void add_edge(int f,int t){ graph[f].pb(t);}
void add_both_edges(int f,int t){add_edge(f,t);add_edge(t,f);}

void dfs(int v,int p,int &k){
	ord[v]=k++;
	low[v]=ord[v];
	par[v]=p;
	s.push(v);
	for(auto &i:graph[v]){
		if(ord[i]==-1){
			dfs(i,v,k);
			low[v]=min(low[v],low[i]);
		}else if(scc[i]==-1){
			low[v]=min(low[v],ord[i]);
		}
	}
	if(ord[v]==low[v]){
		while(1){
			int u=s.top();s.pop();
			scc[u]=v;
			if(u==v) break;
		}
	}
}

void lowlink(int n){
	int k=0;
	ord.assign(n,-1),low.resize(n);
	scc.assign(n,-1),par.resize(n);
	rep(i,n) if(ord[i]==-1) dfs(i,-1,k);
}

map<string,int> con;
ll x[100010];

int main(void){
	int n;
	cin >> n;
	rep(i,n){
		string in;
		cin >> in >> x[i];
		con[in]=i;
	}
	int m;
	cin >> m;
	rep(i,m){
		string aa,bb;
		cin >> aa >> bb;
		int a=con[aa],b=con[bb];
		add_both_edges(a,b);
	}
	lowlink(n);
	rep(i,n){
		int cur=scc[i];
		x[cur]=min(x[cur],x[i]);
	}
	ll ans=0;
	rep(i,n) ans+=x[scc[i]];
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int n, k;
    set<char> num;
    cin >> n >> k;
    for(int i = 0; i < k; i++)
    {
        int d;
        cin >> d;
        num.insert(d + '0');
    }
    bool r = true;
    n--;
    while(r)
    {
        n++;
        r = false;
        string m;
        stringstream ss;
        ss << n;
        ss >> m;
        for(int i = 0; i < m.length(); i++)
        {
            if(num.count(m[i]))
            {
                r = true;
                break;
            }
        }
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int n, i, j;
	cin >> n;
	int d[n], tmp[n];
	for (i = 0; i < n; i++) {
		cin >> d[i];
		tmp[i] = d[i];
	}
	int ans = 0;
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (i == j) break;
			ans += d[i] * tmp[j];
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef pair<string, int[3]> term;

bool srt(term a, term b){
	return  a.second[0] > b.second[0] || (a.second[0] == b.second[0] && a.second[1] < b.second[1]);
}

int main(){
	int n;
	int num;
	while(cin >> n, n){
		term result[10];

		for(int i=0; i < n; i++){
			cin >> result[i].first;

			for(int j=0; j < n-1; j++){
				cin >> num;
				result[i].second[num]++;
			}
		}
		stable_sort(result, result+n, srt);
		for(int i=0; i < n; i++){
			cout << result[i].first << endl;
		}

	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

ll a[200020];
ll c[200020];

int main(){
    int n;
    cin >> n;
    rep(i, n){
        int b;
        cin >> b;
        a[b]++;
        c[i] = b;
    }
    ll tmp = 0;
    rep(i, n + 1) {
        tmp += a[i] * (a[i] - 1) / 2;
    }

    for (int i = 0; i < n; i++){
        ll r = a[c[i]] * (a[c[i]] - 1) / 2;
        r -= (a[c[i]] - 1) * (a[c[i]] - 2) / 2;
        cout << tmp - r << endl;
    }

    return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
  int s,w;
  cin >> s >> w;
  if(s<=w)  cout << "unsafe";
  else  cout << "safe";
  return 0;
}

Measured memory_bytes: 3636
N=int(input())
S=input()
cnt=0
ansP=0
ansA=0
for i in range(N):
  if cnt==0 and S[i]==')':
    ansP+=1
  elif cnt>0 and S[i]==')':
    cnt-=1
  else:
    cnt+=1

cnt=0
Sans=S[::-1]
for i in range(N):
  if cnt==0 and Sans[i]=='(':
    ansA+=1
  elif cnt>0 and Sans[i]=='(':
    cnt-=1
  else:
    cnt+=1

print("("*ansP+S+")"*ansA)

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

int main()
{
  int dp[10+1][330+1];
  for (int i = 0; i < 10+1; ++i) {
    for (int j = 0; j < 330+1; ++j)
      dp[i][j] = 0;
  }

  int fac[10+1];
  fac[0] = fac[1] = 1;
  for (int i = 2; i < 10+1; ++i)
    fac[i] = i * fac[i-1];

  vector<int> num;
  for (int i = 0; i < 10; ++i)
    num.push_back(i);
  do {
    int sum = 0;
    for (int i = 0; i < 10; ++i) {
      sum += ((i+1) * num[i]);
      ++dp[i+1][sum];
    }
  } while (next_permutation(num.begin(), num.end()));

  int n, s;
  while (cin >> n >> s)
    if (n < 0 || 10 < n || s < 0 || 330 < s)
      cout << "0" << endl;
    else
      cout << dp[n][s] / fac[10-n] << endl;
  return 0;
}

Measured memory_bytes: 808
#include<bits/stdc++.h>
using namespace std;
#define sachin ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
    sachin
    long long n;
    cin>>n;
    long long a[7]={},count1=10,count2=0;
    a[1]=0;a[2]=9;a[3]=9;a[4]=909;a[5]=909;a[6]=90909;
    long long a1=log10(n);a1++;
    if(a1%2==0)
    {
        cout<<a[a1];
    }
    else{
            long long b=n-pow(10,a1-1)+1;
        cout<<a[a1]+b;
    }
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string o,e;
    cin>>o>>e;
    int n=e.length();
    for(int i=0;i<n;i++)
    {
        cout<<o[i]<<e[i];
    }
    if(o.length()>n)
        cout<<o[o.length()-1];
    cout<<endl;
        
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int W,a,b;
   while(cin>>W>>a>>b)
   {
       int i,j;
       if(a<=b)
       {
           i=W+a;
           if(i<=b)
            j=b-i;
           else
           j=0;
       }
       else if(a>b)
       {
           i=W+b;
           if(i<=a)
            j=a-i;
           else
            j=0;
       }
        cout<<j<<endl;
   }
   return 0;
}

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

int main(){
  string N;
  cin >> N;
  ll sum = 0;
  for (int i=0; i<N.size(); i++) {
    int a = N[i] - 48;
    sum += a;
  }
  if (sum % 9 != 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3752
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;
const Long INF = (1e18);
void solve() {
  int n;
  cin >> n;
  Long ans = 1;
  vector<Long> v(n);
  fore(i, 0, n) cin >> v[i];
  fore(i, 0, n) {
    if (v[i] == 0) {
      cout << 0 << '\n';
      return;
    }
  }
  fore(i, 0, n) {
    Long num = v[i];
    if (ans > INF / num) {
      cout << -1 << endl;
      return;
    }
    ans *= num;
  }
  if (ans > INF)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int t = 1;
  //cin >> t;
  while (t--) solve();

  return 0;
}

Measured memory_bytes: 3992