akhauriyash/Code-Regression huggingface dataset:
def warshall_floid(d):
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d

n,m,l = map(int,input().split())
d = [[10**12]*(n+1) for _ in range(n+1)]
for i in range(m):
    a,b,c = map(int,input().split())
    d[a][b] = c
    d[b][a] = c
d = warshall_floid(d)
for i in range(1,n+1):
    for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**12
d = warshall_floid(d)
q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    if d[s][t] >= 10**12:
        print(-1)
    else:
        print(d[s][t]-1)


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

ll divisor[10000001];
bool used[10000001];

int main(){
  int n;
  cin >> n;
  rep(i, n + 1) {
    used[i] = true;
    divisor[i] = 1;
  }

  for (int i = 2; i <= n; i++) {
    if (used[i]) {
      for (int j = i; j <= n; j += i) {
        used[j] = false;
        int m = j, cnt = 0;
        while (m % i == 0 && m > 0) {
          cnt++;
          m /= i;
        }
        divisor[j] *= (ll)(cnt + 1);
      }
    }
  }

/*
  for (int i = 1; i <= n; i++) {
    rep(j, divisor[i].size()) {
      cout << divisor[i][j] << " ";
    } cout << endl;
  }
*/

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (ll)(divisor[i] * i);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 91524
import java.util.Scanner;

/**
 * Party Dress
 */
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A, B;
		A = sc.nextInt();
		B = sc.nextInt();

		int ans = 0;

		if (A >= B) {
			ans = 1;
		} else if (B % A == 0) {
			ans = B / A;
		} else {
			ans = B / A + 1;
		}

		System.out.println(ans);
	}
}



Measured memory_bytes: 26420
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {
	
	int N;
	scanf("%d", &N);
	char S[100000];
	scanf("%s", S);
	int count = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == S[i + 1]) {
			
			S[i + 1] = S[i];
			S[i] = 0;
		}
	}
	
	for (int i = 0; i < N; i++) {
		if (S[i] != 0) {
			count++;
		}
	}

	printf("%d", count);

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<long long, null_type, less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

template <typename T>
void debug_out(T t) {
  cerr << t;
}

template <typename A, typename B>
void debug_out(pair<A, B> u) {
  cerr << "(" << u.first << " " << u.second << ")";
}

template <typename T>
void debug_out(vector<T> t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << ", ";
  }
}

template <typename T>
void debug_out(vector<vector<T>> t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << endl;
  }
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  debug_out(H);
  cerr << " ";
  debug_out(T...);
}

template <typename T>
void debug_out(set<T> a) {
  vector<T> _a;
  for(T t : a) _a.push_back(t);
  debug_out(_a);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__), cerr << endl;

int n;

int main() {
  cin >> n;
  vector<int> a(n), b(n);
  range(i, 0, n) {
    cin >> a[i];
  }
  range(i, 0, n) {
    cin >> b[i];
  }
  int res = INT_MAX;
  range(mask, 0, 1 << n) {
    if(__builtin_popcount(mask) != (n + 1) / 2) continue;
    vector<int> l, r;
    range(i, 0, n) (mask & (1 << i) ? l : r).push_back(i);
    vector<pair<int, int>> sl, sr;
    for(int i : l) {
      int v = (i & 1 ? b[i] : a[i]);
      sl.emplace_back(v, i);
    }
    for(int i : r) {
      int v = (i & 1 ? a[i] : b[i]);
      sr.emplace_back(v, i);
    }
    sort(sl.begin(), sl.end());
    sort(sr.begin(), sr.end());
    vector<int> to, val;
    range(i, 0, n) {
      if(i & 1) {
        to.push_back(sr[i / 2].second);
        val.push_back(sr[i / 2].first);
      } else {
        to.push_back(sl[i / 2].second);
        val.push_back(sl[i / 2].first);
      }
    }
    bool ok = true;
    range(i, 0, n - 1) {
      if(val[i] > val[i + 1]) ok = false;
    }
    if(!ok) continue;
    ordered_set st;
    int add = 0;
    reverse(to.begin(), to.end());
    for(int i : to) {
      add += st.order_of_key(i);
      st.insert(i);
    }
    res = min(res, add);
  }
  if(res == INT_MAX) res = -1;
  cout << res;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int r= 3;
  if (a==b&&b==c){
    r = 1;
  }
  else if (a ==b||b==c||c==a){
    r--;
  }
  cout<<r<<endl;
}

Measured memory_bytes: 256
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = x*x%n
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    elif 0 in [ n%i for i in range(11,min(n-1,20),2) ]:return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

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

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 500005

double dp[3005][3005],p[3005];
int vis[3005][3005],n;

double solve(int id,int heads){
if(id>n)return (heads+heads>=n);
double &ans=dp[id][heads];
if(vis[id][heads])return ans;
vis[id][heads]=1;
ans=p[id]*solve(id+1,heads+1)+(1-p[id])*solve(id+1,heads);
return ans;
}

int main(){
sp;
cin>>n;
for(int i=1; i<=n; ++i)cin>>p[i];
cout<<fixed<<setprecision(12)<<solve(1,0);
return 0;}


Measured memory_bytes: 104832
using System;
using System.Collections.Generic;

namespace ABC144_B
{
    class Program
    {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());

            string strAns = "No";
            int intAns = 0;

            var list = new List<int>();
            var arr = new int[n];

            for(int i = 1; i < 10; i++) {
                if(n % i == 0) {
                    if ((n / i) <= 9) {
                        strAns = "Yes";
                    }
                }
            }


            Console.WriteLine(strAns);
        }
    }
}

Measured memory_bytes: 13140
N, M = map(int,input().split())
py = []
for i in range(M):
  py.append(list(map(int,input().split())))
  py[i].append(i)
sorted_py = sorted(py, key=lambda x: x[1])
P = [0]*N
p_num = 0
num = 0
output = ''
output2 = []
outputs = []
for i in range(M):
  P[sorted_py[i][0]-1] += 1
  p_num = sorted_py[i][0]
  num = P[sorted_py[i][0]-1]
  output = str(p_num).zfill(6) + str(num).zfill(6)
  output2 = [output, sorted_py[i][2]]
  outputs.append(output2)
sorted_outputs = sorted(outputs, key=lambda x: x[1])
for out in sorted_outputs:
  print(out[0])

  

Measured memory_bytes: 49768
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
    string num;

    while(1){
        cin >> num;
        if(num[0]=='0'){
            break;
        }

        int sum=0;
        for(int i=0;i < num.size();i++){
            sum+=num[i]-'0';
        }
        cout << sum << endl;
    }

    return 0;
}



Measured memory_bytes: 3148
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

N = int(input())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
C = [0] + list(map(int, input().split()))

pre = -1
ans = 0
for a in A[1:]:
    now = B[a]
    ans += now
    if a - 1 == pre:
        ans += C[pre]
    pre = a
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

#define M 1000001/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1+key%(M-1); }

int find(char str[]){
  int key;
 int i = 0,j;
 int x,y;
 key = getKey(str);
 x=h1(key);
 y=h2(key);
 while(i<M){ 
   j = (x + i * y) % M;
   if(H[j][0] == '\0'){
      return 0;
    }
    else if(strcmp(H[j],str) == 0){
      return 1;
      break;
    }
    i++;
 }
 return 0;
}





int insert(char str[]){
  
  int key;
  int i = 0,j;
    int x,y;
    
    key = getKey(str);
    x = h1(key);
  y = h2(key);
  while(i < M){
    j = (x + i * y) % M;
    if(H[j][0] == '\0'){
      strcpy(H[j],str);
      break;
    }
    i++;
  }
  return 0;
}

int main(){
  int i, n;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ){
      scanf("%s %s", com, str);
	if ( com[0] == 'i' ){
	  insert(str);
	} else {
	    if (find(str)){
	      printf("yes\n");
	    } else {
	      printf("no\n");
	    }
	}
    }
    return 0;
}

Measured memory_bytes: 14280
#include <stdio.h>
int main(void)
{
	int S=0, h=0, m=0, s=0;
	
	scanf("%d",&S);
	
	h = S/3600;
	m = (S-h*3600)/60;
	s = S-(h*3600+m*60);
	
	
	printf("%d:%d:%d\n",h ,m ,s);
	
	return 0;
}

Measured memory_bytes: 592
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define loop(i,n) for(int i=0;i<(n);i++)
#define cont(i,n) for(int i=1;i<=(n);i++)
#define circ(i,a,b) for(int i=(a);i<=(b);i++)
#define range(i,a,b,c) for(int i=(a);((c)>0?i<=(b):i>=(b));i+=(c))
#define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(),_e_D_=(v).end();it!=_e_D_;it++)
#define y0 y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1 y1II11II11III11I1III11II111IIII1II1I1
#define pub push_back
#define pob pop_back
#define mak make_pair

typedef long long ll;
typedef long double lf;
const int Inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

int n;
int x[55],y[55];

lf dist(lf xs,lf ys){
	lf mx=0;
	cont(i,n)mx=max(mx,sqrtl((xs-x[i])*(xs-x[i])+(ys-y[i])*(ys-y[i])));
	return mx;
}

lf getdis(lf xs){
	lf l=0,r=1000;
	loop(i,100){
		lf m1=l+(r-l)/3,m2=l+(r-l)*2/3;
		if(dist(xs,m1)<dist(xs,m2))r=m2;
		else l=m1;
	}
	return dist(xs,l);
}

int main(){
	scanf("%d",&n);
	cont(i,n)scanf("%d%d",x+i,y+i);
	lf l=0,r=1000;
	loop(i,100){
		lf m1=l+(r-l)/3,m2=l+(r-l)*2/3;
		if(getdis(m1)<getdis(m2))r=m2;
		else l=m1;
	}
	printf("%.10Lf\n",getdis(l));
	return 0;
}

Measured memory_bytes: 3880
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,q;
	string s;
	cin>>n>>q>>s;
	int dp[100000];
	dp[0]=0;
	for(int i=1;i<n;i++)
		if(s[i-1]=='A'&&s[i]=='C')
			dp[i]=dp[i-1]+1;
		else
			dp[i]=dp[i-1];
	int l,r;
	while(cin>>l>>r)
		cout<<dp[r-1]-dp[l-1]<<endl;
}


Measured memory_bytes: 1408
import java.util.*;

class Main
{
    //Point class
    static class Point
    {
	public double x;
	public double y;

	public Point(double x, double y)
	{
	    this.x=x;
	    this.y=y;
	}

	public Point(Point p)
	{
	    x=p.x;
	    y=p.y;
	}

	public void printPoint()
	{
	    System.out.printf("%.8f %.8f\n", x, y);
	}
    }



    //main
    public static void main(String[] args)
    {
	Scanner read = new Scanner(System.in);
	int n;
	Point zero = new Point(0, 0);
	Point hyaku = new Point(100, 0);
	int i, j, k;

	//read n
	n=read.nextInt();
	read.close();

	//do methods
	zero.printPoint();
	divisionPoint(zero, hyaku, n);
	hyaku.printPoint();
    }

    //methods
    static void divisionPoint(Point p1, Point p2, int n)
    {
	double x = p2.x-p1.x;
	double y = p2.y-p1.y;

	Point s = new Point((x/3)+p1.x, (y/3)+p1.y);
	Point t = new Point(2*(x/3)+p1.x, 2*(y/3)+p1.y);
	Point u = new Point(getKoch(s, t));

	//p1.printPoint();
	if(n>0)
	   {
	       divisionPoint(p1, s, n-1);
	       s.printPoint();

	       divisionPoint(s, u, n-1);
	       u.printPoint();

	       divisionPoint(u, t, n-1);
	       t.printPoint();

	       divisionPoint(t, p2, n-1);       
	   }
    }
    
    static Point getKoch(Point s, Point t)
    {
	double x = t.x - s.x;
	double y = t.y - s.y;

	double moveX = (Math.cos(Math.PI/3)*x - Math.sin(Math.PI/3)*y)+s.x;
	double moveY = (Math.sin(Math.PI/3)*x + Math.cos(Math.PI/3)*y)+s.y;

	Point u = new Point(moveX, moveY);
	return u;
    }
    
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  uint64_t g = gcd(m,n);
  if(m%g==0) return (m/g)*n;
  if(n%g==0) return (n/g)*m;
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/* 
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  ll n;
  cin >> n;

  map<ll,int> c;
  ll val;
  for(ll i=0;i<n;i++){
    cin >> val;
    c[val]++;
    //cout << "c[" << val << "]=" << c[val] << endl;
  }
  
  ll patternNum = 1;
  for(ll i=n-1;i>=0;i-=2){
    if(i==0){
      if(c[i]!=1){
        cout << "0" << endl;
        return 0;
      }
      break;
    }
    if(c[i]!= 2){
      cout << "0" << endl;
      return 0;
    }
    patternNum *= 2;
    patternNum %= MOD;
  }
  
  cout << patternNum << endl;
  
  return 0;
}



Measured memory_bytes: 7336
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int INF=1e9+7;
int main(){
  ll n,m,x;
  cin>>n>>m>>x;
  vll a(m);
  rep(i,0,m){
    cin>>a[i];
  }
  auto it=lower_bound(a.begin(),a.end(),x);
  if(it==a.begin()||it==a.end()){cout<<0<<endl;}
  else{
    ll t=a.end()-it;
    cout<<min(t,m-t)<<endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9

ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll x,y;cin>>x>>y;
    vector<ll>v;
    v.pb(y);
    f(i,y+1,x+y)v.pb(i);
    for(ll i=y-1;i>y-x;i--)v.pb(i);
    sort(v.begin(),v.end());
    f(i,0,v.size())cout<<v[i]<<" ";
    return 0;
}


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

int main() {
    int k; cin >> k;
    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cout << a.at(k-1) << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;

	rep(i, N) {
		cout << S[i] << T[i];
	}

	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <stack>

using namespace std;

int calc(string s){
	// ©gªÊÉÍÜêÄ¢éêÆAÅ éÆ«Ì
	if(s[0]>='0'&&s[0]<='9'){
		bool f=false;
		for(int i = 0; i < s.size(); i++){
			if(!(s[i]>='0'&&s[i]<='9')){
				f=true;
				break;
			}
		}
		if(!f){
			return atoi(s.c_str());
		}
	}
	else if(s[0]=='('){
		stack<char> sc;
		sc.push('(');
		for(int i = 1; i < s.size(); i++){
			if(s[i]==')')
				sc.pop();
			else if(s[i]=='('){
				sc.push('(');
			}
			if(sc.size()==0){
				if(i==s.size()-1){
					return calc(s.substr(1,s.size()-2));
				}
				else{
					break;
				}
			}
		}
	}
	stack<char> sc;
	// \¶ðÍÆÓ¡ðÍ
	for(int i = s.size()-1; i >= 0; i--){
		// ÊÌÌZqÍ³·é
		if(s[i]=='(')
			sc.pop();
		else if(s[i]==')'){
			sc.push(')');
		}
		else if(s[i]=='+'&&sc.size()==0){
			return calc(s.substr(0,i)) + calc(s.substr(i+1,s.size()-i-1));
		}
		else if(s[i]=='-'&&sc.size()==0){
			return calc(s.substr(0,i)) - calc(s.substr(i+1,s.size()-i-1));
		}
	}

	for(int i = s.size()-1; i >= 0; i--){
		// ÊÌÌZqÍ³·é
		if(s[i]=='(')
			sc.pop();
		else if(s[i]==')'){
			sc.push(')');
		}
		else if(s[i]=='*'&&sc.size()==0){
			return calc(s.substr(0,i)) * calc(s.substr(i+1,s.size()-i-1));
		}
		else if(s[i]=='/'&&sc.size()==0){
			return calc(s.substr(0,i)) / calc(s.substr(i+1,s.size()-i-1));
		}
	}
}

int main(){

	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		string str;
		cin>>str;
		cout<<calc(str.substr(0,str.size()-1))<<endl;
	}

	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    long long a[n];
    long long product = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            cout << 0;
            return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (a[i] > 1000000000000000000 / product) {
            cout << -1;
            return 0;
        }
        product = product * a[i];
    }
    cout << product;
}


Measured memory_bytes: 4264
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n, p;
  string s;
  cin >> n >> p >> s;
  int64 ret = 0;
  if (p == 2 || p == 5) {
    for (int i = 0; i < n; ++i) {
      int x = s[i] - '0';
      if (x % p == 0) ret += i + 1;
    }
  } else {
    reverse(s.begin(), s.end());
    vector<int> pre(n + 1);
    int p10 = 1;
    for (int i = 0; i < n; ++i) {
      int x = s[i] - '0';
      pre[i + 1] = (pre[i] + x * p10) % p;
      p10 = p10 * 10 % p;
    }
    vector<int> cnt(p);
    for (int i = 0; i <= n; ++i) {
      // trace(i, pre[i], cnt[pre[i]]);
      ret += cnt[pre[i]];
      cnt[pre[i]]++;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 1428
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0);

const ll INF = 1e9+7;

// 各桁の和
template<typename T>
T digit(T num){
  T sum = 0;
  while(num){
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

int main(){
  vector<int> A(3);rep(i,3)cin>>A[i];
  int even = 0,odd = 0;
  rep(i,3){
    if(A[i] % 2 == 0)even++;else odd++;
  }
  
  int ans = !(even == 0 || odd == 0);
  rep(i,3){
    if(even == 0 || odd == 0)break;
    
    if(even > odd){
      if(A[i] % 2 == 0)A[i]++;
    }else{
      if(A[i] % 2 != 0)A[i]++;
    }
  }
  sort(all(A));
  ans += (A[2] - A[1])/2;
  ans += (A[2] - A[0])/2;
  print(ans)
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int a, b;
 
    while(cin >> a >> b) {
        a += b;
        int t = 1, cnt = 0;
        while(1) {
            if( a < t ) {
                break;
            } else {
                t *= 10;
                ++cnt;
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
using ull = unsigned long long;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	map<int,ll> mp;
	ll sum = 0;
	for(int &i:a) {
		cin >> i;
		mp[i]+=i;
		sum+=i;
	}
	int q;
	cin >> q;
	while(q--) {
		int b,c;
		cin >> b >> c;
		ll newAdd =(mp[b]/b)*c;
		sum-=mp[b];
		mp[b] = 0;
		sum+=newAdd;
		cout<<sum<<"\n";
		mp[c] += newAdd;
	}
	
}


Measured memory_bytes: 9456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
 
public class Main{

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      Boolean[][] checkCards = new Boolean[4][13];
      for( int i = 0; i < 4; i++ ) {
        Arrays.fill(checkCards[i], false);
      }
      String[] lines = br.readLine().split(" ");
      int n = Integer.parseInt(lines[0]);
      int a,b;

      for(int i = 0; i < n; i++) {
        lines = br.readLine().split(" ");
        a = suitToInt(lines[0]);
        b = Integer.parseInt(lines[1]);
        checkCards[a][b-1] = true;
      }

      for(int i = 0; i < 4; i++ ) {
        for( int j = 0; j < 13; j++ ) {
          if(!checkCards[i][j]) System.out.println(intToSuit(i) + " " + (j+1));
        }
      }
    }
  }

  public static int suitToInt( String suit ) {
    switch( suit ) {
      case "S": return 0;
      case "H": return 1;
      case "C": return 2;
      default : return 3;
    }
  }
  public static String intToSuit( int r ) {
    switch( r ) {
      case 0  : return "S";
      case 1  : return "H";
      case 2  : return "C";
      default : return "D";
    }
  }
}


Measured memory_bytes: 24308
import java.util.*;
public class Main
{
  static int gcd(int a,int b){
    if(a==0)
      return b;
    
    return gcd(b%a,a);
  }
	public static void main(String[] args) {
		
      Scanner scan=new Scanner(System.in);
      int n=scan.nextInt();
      int i,j,k;
      long sum=0;
      for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
          int g=gcd(i,j);
          for(k=1;k<=n;k++){
            sum=sum+gcd(g,k);
	}
        }
      }
      
System.out.println(sum);
      
}
}


Measured memory_bytes: 35856
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<0;
	}else{
		cout<<10;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
struct Radix{
  const char* s;
  int a[128];
  Radix(const char* s="0123456789ABCDEF"):s(s){
    int i;
    for(i=0;s[i];++i)
      a[(int)s[i]]=i;
  }
  string to(long long p,int q){
    int i;
    if(!p)
      return "0";
    char t[64]={};
    for(i=62;p;--i){
      t[i]=s[p%q];
      p/=q;
    }
    return string(t+i+1);
  }
  string to(const string& t,int p,int q){
    return to(to(t,p),q);
  }
  long long to(const string& t,int p){
    int i;
    long long sm=a[(int)t[0]];
    for(i=1;i<(int)t.length();++i)
      sm=sm*p+a[(int)t[i]];
    return sm;
  }
};
int main() {
  int i;
  int n;
  cin >> n;
  Radix r("0123456789abcdef");
  while(n--) {
    string s;
    cin >> s;
    s = r.to(s, 16, 2);
    s = string(32 - s.size(), '0') + s;
    int sm = 0;
    for(i = 0; i < 7; ++i) {
      if(s[s.size() + i - 7 ] == '1')
        sm += 10000000 / (2 << i);
    }
    string t = r.to(sm, 10);
    t = string(7 - t.size(), '0') + t;
    while(t[t.size() - 1] == '0')
      t.erase(t.size() - 1);
    cout << (s[0] == '0' ? "" : "-") << r.to(s.substr(1, 24), 2) << '.' << (sm == 0 ? "0" : t) << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
using System.Linq;

namespace ABC
{
    using static System.Console;
    using static System.Math;
    public class Program
    {
        private const int MOD = 1000000007;
        static void Main(string[] args)
        {
            WriteLine(Solve());
        }

        public static string Solve()
        {
            var a = ReadLine().Split().Select(int.Parse).ToArray();
            if (a[0] >= 13)
                return a[1].ToString();
            if (a[0] >= 6)
                return (a[1] / 2).ToString();
            return "0";
        }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>
#include<string.h>
#include<math.h>

#define root_cal(a) (pow((a), 0.5))
#define squar_cal(a) (pow((a), 2))

int a_list[10001];

int main()
{
    int n, tmp_n;

    scanf("%d", &n);

    for (int i = 1; i<=n; i++)
    {
        a_list[i] = 0;
    }

    for (int i = 1; i<root_cal(n); i++)
    {
        for (int j = 1; j < root_cal(n - squar_cal(i)); j++)
        {
            for (int k = 1; k < root_cal(n - squar_cal(i) - squar_cal(j) - i*j); k++)
            {
                tmp_n = squar_cal(i) + squar_cal(j) + squar_cal(k) + i*j + j*k + k*i;

                if (tmp_n <= n)
                    a_list[tmp_n]++;
            }
        }
    }

    for (int i = 1; i<=n; i++)
    {
        printf("%d\n", a_list[i]);
    }

    return 0;
}

Measured memory_bytes: 2612
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

#define LL long long

int n, x, l[102], cnt = 0;

int main() {
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	int now = 0;
	for (cnt = 1; cnt <= n; cnt++) {
		now += l[cnt - 1];
		if (now > x)break;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

class Map_input():

    def __init__(self):
        line = input().split(" ")
        self.H = int(line[0])
        self.W = int(line[1])
        Map = [[] for i in range(self.H)]
        for i in range(self.H):
            line = input()
            for j in range(self.W):
                if line[j] == ".":
                    Map[i].append(0)
                else:
                    Map[i].append(1)
        self.Map = Map

class Maze_min():
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    def __init__(self, H, W, Map, start, goal):
        self.H = H
        self.W = W
        self.Map = Map
        self.goal = goal
        self.queue = deque([start])
        self.dist = [[-1]*W for i in range(H)]
        self.dist[start[0]][start[1]] = 0

    def min_step(self):
        while len(self.queue) > 0:
            p = self.queue.popleft()
            if p == self.goal:
                break
            else:
                for i in range(len(Maze_min.dx)):
                    (nx, ny) = (p[0] + Maze_min.dx[i], p[1] + Maze_min.dy[i])
                    if nx in range(self.H) and ny in range(self.W) and self.Map[nx][ny] == 0 and self.dist[nx][ny] == -1:
                        self.queue.append((nx, ny))
                        self.dist[nx][ny] = self.dist[p[0]][p[1]] + 1
        return self.dist[self.goal[0]][self.goal[1]]

M = Map_input()
maze = Maze_min(M.H, M.W, M.Map, (0, 0), (M.H-1, M.W-1))
black_num = (sum(list(map(sum, M.Map))))
d = maze.min_step()
if d == -1:
    print(-1)
else:
    print(M.H*M.W - maze.min_step() - black_num -1)

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;

	vector<vector<int>> board(h, vector<int>(w, -1));

	vector<int> cols0(w, 0);
	vector<int> cols1(w, 0);

	for (int i = 0; i < h; i++) {
		int n0 = 0;
		int n1 = 0;

		int w_idx = 0;
		for (int j = 0; j < w; j++) {
			int tmp = board[i][j];
			if (tmp == 0) {
				n0++;
			} else if (tmp == 1) {
				n1++;
			}
		}

		if (min(n0, n1) > a) {
			cout << "No" << endl;
			return 0;
		}


		int num = 0;

		for (int j = 0; j < w; j++) {
			if (board[i][j] != -1) {
				continue;
			}

			if (num == 0 && n0 >= a) {
				num = 1;
			}

			board[i][j] = num;

			if (num == 0) {
				n0++;
				cols0[j]++;
				if (cols0[j] == b) {
					for (int k = i + 1; k < h; k++) {
						board[k][j] = 1;
					}
				}
			} else {
				cols1[j]++;
				n1++;
				if (cols1[j] == b) {
					for (int k = i + 1; k < h; k++) {
						board[k][j] = 0;
					}
				}
			}
		}
	}

	for (auto v: board) {
		for (auto x: v) {
			cout << x;
		}
		cout << endl;
	}


	return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
 
int main()
{
  int n, k;
  cin >> n >> k;
  int num_candy[n+1] = { 0 };
  REP(i, k)
  {
    int d;
    cin >> d;
    REP(j, d)
    {
      int t;
      cin >> t;
      num_candy[t]++;
    }
  }
  int ans = 0;
  REP(i, n)
  {
    if(num_candy[i+1] == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
//桁数指定　cout << fixed << setprecision(2)
typedef long long  ll;
const double pi=3.1415926535;
const ll  mod=1000000007;
int main() {
  ll n,k;
  ll ans=0;
  cin>>n>>k;
  for(int i=k;i<=n+1;i++){
    ll min=(0+i)*(i+1)/2;  /*  +k*10^100  */
    ll max=i*(n+1-i)+min;
    ans+=(max-min)+1;
    if(ans>=mod)ans%=mod;
    cerr<<"LOOP"<<i<<":"<<max-min+1<<endl;
  }
  cout<<ans;
}

Measured memory_bytes: 4564
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],k,flag,t;
double cev,a[li];
string s;
vector<int> v;

int main(void){
	scanf("%d",&n);
	FOR{
		scanf("%lf",&a[i]);
		a[i]=1/a[i];
		cev+=a[i];
	}
	printf("%.15lf\n",1/cev);
	//~ a[i]
	return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
int main()
{
    string s;
    cin>>s;
    ll t=0;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i]=='7')
        {
            t = 1;
            break;
        }
    }
    if(t==1)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
}


Measured memory_bytes: 3624
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (
    acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
    sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


n, m = invr()
res = []
if n == 1:
    res = [0]
elif n == 2:
    res = [1, 0]
elif n == 3:
    res = [1, 0, 0]

f = [0, 0, 0]
out = 1
for _ in range(m):
    si, ci = invr()
    if si == 1 and n > 1 and ci == 0:
        out = -1
        break
    if f[si-1] == 0 or res[si-1] == ci:
        res[si-1] = ci
        f[si-1] = 1
    else:
        out = -1
        break
if out == -1:
    print(-1)

elif res[0] == 0 and len(res) > 1:
    print(-1)
else:
    for i in res:
        print(i, end="")


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

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    priority_queue<int, vector<int>, greater<int> > que;
    vector<int> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];

    int cnt = 0;
    for(int i = 0; i < N; i++){
        int x = v[i];
        que.push(x);
        if(x <= que.top()){
            cnt++;
        }
    }
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 2296
import sys
input = sys.stdin.readline

x, y, a, b, c = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())), reverse=True)

d = []
d_append = d.append
for i in range(x):
    d_append(P[i])

for i in range(y):
    d_append(Q[i])

for i in range(c):
    d_append(R[i])

d.sort(reverse=True)

ans = 0
for i in range(x+y):
    ans += d[i]
    
print(ans)

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

using namespace std;

int rec(int k, int n, int* arr, vector<int>& dp){
    if(dp[k]!=-1)
        return dp[k];
    if(k==0) return dp[k] = 0;
    int ans=0;
    for(int i=0;i<n;i++){
        if(arr[i]>k) continue;
        if(rec(k-arr[i],n,arr,dp)==0){
            ans = 1;
            break;
        }
    }
    
    return dp[k]=ans;
}

int main() {
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    vector<int> dp(k+1, -1);
    if(rec(k,n,arr,dp))
        cout<<"First\n";
    else
        cout<<"Second\n";
}

Measured memory_bytes: 11444
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
ll dp[201][201][201];
ll gcd(ll a, ll b) {
	return a % b ? gcd(b, a % b) : b;
}
int main() {
	ll a, res = 0, temp, arr[3];
	cin >> a;
	for (ll i = 1; i <= a; i++) {
		for (ll j = 1; j <= a; j++) {
			for (ll k = 1; k <= a; k++) {
				arr[0] = i;
				arr[1] = j;
				arr[2] = k;
				sort(arr, arr + 3);
				if (dp[arr[0]][arr[1]][arr[2]]) {
					res += dp[arr[0]][arr[1]][arr[2]];
				}
				else {
					temp = gcd(arr[2], arr[1]);
					temp = temp > arr[0] ? gcd(temp, arr[0]) : gcd(arr[0], temp);
					res += temp;
					dp[arr[0]][arr[1]][arr[2]] = temp;
				}
			}
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 35828
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  string s;
  cin>>s;
  int n=s.length();
  string ans="";
  ans= getString(s[0])+to_string(n-2)+getString(s[n-1]);
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
string a;
long long ans=0;
int main()
{
    cin>>a;
    int is=0;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='9')ans+=9;
        else
        {
            if(i==0)ans+=a[i]-'0';
            else if(is){ans+=9;}
            else{ is=1;ans-=1;ans+=9;}
        }
    }
    cout<<ans;
}


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

int calc(int a, int b, int o) {
  if (o % 2 == 0) return a + b;
  else return a - b;
}

char op(int i) {
  if(i % 2 == 0) return '+';
  else return '-';
}

int ctoi(char c){
  return (int)(c - '0');
}

int main(){
  string s;
  int a, b, c, d;
  int ord = 0;
  cin >> s;
  a = ctoi(s.at(0));
  b = ctoi(s.at(1));
  c = ctoi(s.at(2));
  d = ctoi(s.at(3));
  char x, y, z;
  for (int i = 0; i < 7; i++) {
    if (calc(calc(calc(a, b, i), c, i/2), d, i/4) == 7) {
      ord = i;
      break;
    }
  }
  x = op(ord);
  y = op(ord/2);
  z = op(ord/4);
  cout << a << x << b << y << c << z << d << "=7" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

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

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

    int n, m;
    cin >> n >> m;
    vector<pll> work;

    rep(i, n) {
        pll p;
        cin >> p.first >> p.second;
        work.push_back(p);
    }

    sort(all(work));

    ll sum = 0;
    priority_queue<ll> que;
    int index = 0;

    rep(i, m) {
        while (index < n && work[index].first <= i + 1) {
            que.push(work[index].second);
            index++;
        }
        if (que.empty()) continue;
        sum += que.top();
        que.pop();
    }
    cout << sum << endl;

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n / 2; i++){
        swap(a[i], a[n-1-i]);
    }
    for(int i = 0; i < n; i++){
        if(i > 0) cout << " ";
        cout << a[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3084
import sys
from math import floor
Q = int(input())
AB = [sorted(list(map(int, input().split()))) for _ in range(Q)]

for A, B in AB:
  if A == B or A+1 == B:
    print(2*A-2)
    continue
  C = floor((A*B)**(1/2))
  if C == (A*B)**(1/2):
    C -= 1
  if C*(C+1) >= A*B:
    print(2*C-2)
  elif C*C < A*B:
    print(2*C-1)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include<list>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int n, l;
    cin >> n >> l;
    cout << n/l + n%l << "\n";

    return 0;
}


Measured memory_bytes: 3120
N,M=map(int,input().split())

A=list(map(int,input().split()))
ans=0
A.sort(reverse=True)
S=sum(A)

for i in range(N):
    if A[i]>=S/(4*M):
        ans+=1

if ans>=M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9164
#include <cstdio>
int main() {
	int n,debt=100000;
	scanf("%d",&n);
	for(int i=0;i<n;i++) {
		debt*=1.05;
		if(debt%1000)debt-=debt%1000,debt+=1000;
	}
	printf("%d\n",debt);
}

Measured memory_bytes: 1016
#include<cstdio>
int n,count=0;
void dfs(long long nextnum,unsigned char flag357)
{
	if(nextnum<=n)
	{
		if(flag357==7)//7的二进制位是111
			count++;
		dfs(nextnum*10+3,flag357|1);//1的二进制位001
		dfs(nextnum*10+5,flag357|2);//2的二进制位010
		dfs(nextnum*10+7,flag357|4);//4的二进制位100
	}
}
int main()
{
	scanf("%d",&n);
	dfs(0,0);
	printf("%d\n",count);
	return 0;
}


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

using namespace std;

int main() {
	int N;
	vector<vector<bool>> bingo(3, vector<bool>(3, false));
	vector<vector<int>> A(3, vector<int>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) cin >> A[i][j];
	}
	cin >> N;
	vector<int> b(N);
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (b[i] == A[j][k]) bingo[j][k] = true;
			}
		}
	}

	bool ok = false;

	if (bingo[0][0] && bingo[1][1] && bingo[2][2]) ok = true;
	if (bingo[0][2] && bingo[1][1] && bingo[2][0]) ok = true;
	for (int i = 0; i < 3; i++) {
		if (bingo[0][i] && bingo[1][i] && bingo[2][i]) ok = true;
	}
	for (int i = 0; i < 3; i++) {
		if (bingo[i][0] && bingo[i][1] && bingo[i][2]) ok = true;
	}
	if (ok) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3636