akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
 
int n,m,q,sir[11];
long long sol;
struct lol
{
    int a,b,c;
    long long d;
};
lol v[51];
void bkt(int k)
{
    for(int i=sir[k-1];i<=m;i++)
    {
        sir[k]=i;
        if(k==n)
        {
            long long s=0;
            for(int j=1;j<=q;j++)
            {
                if(sir[v[j].b]-sir[v[j].a]==v[j].c)
                    s+=v[j].d;
            }
            sol=max(sol,s);
        }
        else
            bkt(k+1);
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m>>q;
    for(int i=1;i<=q;i++)
        cin>>v[i].a>>v[i].b>>v[i].c>>v[i].d;
    sir[0]=1;
    bkt(1);
    cout<<sol;
    return 0;
}

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

int main(){


	int d, t, s;
	cin >> d >> t >> s;
	if(t*s >= d){
		cout << "Yes\n";
	}
	else{
		cout << "No\n";
	}
	
	return 0;
}

Measured memory_bytes: 3632
# frozen_string_literal: true

MOD = 10**9 + 7
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

c = Array.new(n) { 0 }
d = Array.new(n) { 0 }

0.upto(n - 1) do |i|
  0.upto(n - 1) do |j|
    c[i] += 1 if a[i] > a[j] && i < j
    d[i] += 1 if a[i] > a[j]
  end
end

sum = 0
0.upto(n - 1) do |i|
  sum += d[i] * (k * (k + 1) / 2 - k) + c[i] * k
end

puts sum % MOD


Measured memory_bytes: 1788
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

void solve() {
    string s;cin>>s;
    int n=s.length();
    fr(i,0,n-2){
        if(s[i]==s[i+1]){
            cout<<"Bad\n";
            return;
        }
    }
    cout<<"Good\n";
    return ;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,f[200005];
char s[200005];
int main(){
	scanf("%d%s",&n,s+1);
	int flag=0;
	if(s[1]=='B')flag=1;
	f[1]=flag;
	int sum=0;
	if(f[1])sum++;
	for(int i=2;i<=2*n;i++){
		if(s[i]=='W'){
			if((flag+1)%2==0){
				f[i]=1;
				sum++;			
			}
			else{
				f[i]=0;
			}
			flag=!flag;
		}
		else{
			if((flag+1)%2==1){
				f[i]=1;
				sum++;
			}
			else{
				f[i]=0;
			}
			flag=!flag;
		}
		//cout<<f[i];
	}
	if(f[2*n]==1||sum!=n){
		printf("0");
		return 0;
	}
	//cout<<"aaa";
	ll ans=1;
	ll num=0;
	for(int i=1;i<2*n;i++){
		if(f[i]==1){
			num++;
		}
		else{
			ans=1ll*ans*num%mod;
			num--;
		}
	}
	for(int i=2;i<=n;i++)
		ans=1ll*ans*i%mod; 
	printf("%lld",(ans+mod)%mod);
} 

Measured memory_bytes: 1280
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();

		for(int i=0;i<n;i++){
			int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
			switch(biggestLength(a, b, c)){
			case 'a':
				if(isRightTriangle(a,b,c)){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}
				break;
			case 'b':
				if(isRightTriangle(b, a, c)){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}
				break;
			case 'c':
				if(isRightTriangle(c, a, b)){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}

				break;
			}

		}

	}

	static char biggestLength(int a,int b,int c){
		if(a<=b){
			if(b<=c){
				return 'c';
			}else{
				return 'b';
			}
		}else if(a<=c){
			return 'c';
		}else{
			return 'a';
		}
	}

	static boolean isRightTriangle(int longest,int other1,int other2){
		int longestP=longest*longest;
		int other1P=other1*other1;
		int other2P=other2*other2;

		return longestP==other2P+other1P;

	}
}

Measured memory_bytes: 33788
#include <bits/stdc++.h>
bool isFile = 1;
#define NAME "taskA"
#define scan 1
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;

#define mp make_pair
#define pb push_back
#define fr first
#define sc second

#define ins insert
#define all(v) v.begin(), v.end()
#define rep(i,a,n) for (int i=a;i<n;i++)
#define bit(n, i) (n >> i) & 1
#define bpc(x) __builtin_popcountll(x)
#define rev(a) reverse(all(a))
#define skip continue
#define read(a) for(auto &i : a) cin >> i
#define print(a) for(auto i : a) cout << i << ' '
#define unique(a) sort(all(a));    a.resize(unique(all(a)) - a.begin())

//                D  R  U   L
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

void _();

void faster() {
    _();
    if (isFile) {
        freopen(NAME".in", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    if (scan) {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
}

const ll  INF = 1e18;
const int inf = 2e9;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ld  PI = acos(-1);
const ld  EPS = 3E-16;
const int ALPHA = 27;
const int N = (int)3e3 + 5;
const int M = 123;

int n;
double dp[N];

void solve() {
    cin >> n;
    dp[0] = 1;
    for(int i = 0; i < n; i++) {
        double p_heads;
        cin >> p_heads;
        for(int j = i + 1; j >= 0; j--) {
            dp[j] = (j == 0 ? 0 : dp[j - 1]) * p_heads + dp[j] * (1 - p_heads);
        }
    }

    double ans = 0;
    for(int i = 0; i <= n; i++) {
        if (i > (n - i)) {
            ans += dp[i];
        }
    }

    cout.precision(10);
    cout << fixed << ans << endl;
}

void _() {
    isFile = 0;
}

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


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int tri[5002][5002];
int main() {
    int n,m; scanf("%d%d",&n,&m);
    for (int i=0; i<m; i++) {
        int x, y, r; scanf("%d%d%d",&x,&y,&r);
        tri[x-1][y-1]=max(tri[x-1][y-1],r+1);
    }
    for (int i=1; i<n; i++) {
        tri[i][0]=max(tri[i-1][0]-1, tri[i][0]);
        tri[i][i]=max(tri[i-1][i-1]-1,tri[i][i]);
        for (int j=1; j<i; j++) {
            tri[i][j]=max(tri[i][j], max(tri[i-1][j-1],tri[i-1][j])-1);
        }
    }
    int res=0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<=i; j++) {
            if (tri[i][j]!=0) res++;
        }
    }
    printf("%d\n",res);
}

Measured memory_bytes: 65000
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#include <string.h>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

int main()
{
	FASTIO

	int t;
	cin >> t;
	
	map <string, int> mp;
	while(t --)
	{
		string s;
		cin >> s;
		mp[s] ++;
	}
	
	cout << "AC x " << mp["AC"] << endl;
	cout << "WA x " << mp["WA"] << endl;
	cout << "TLE x " << mp["TLE"] << endl;
	cout << "RE x " << mp["RE"] << endl;
}

Measured memory_bytes: 3616
import sys
n = input()
a_n = map(int,raw_input().split())
j = -1
for i in range(n):
	if j == -1 :
			sys.stdout.write(str(a_n[j]))
			j -= 1
	else :		
		print (' '),
		sys.stdout.write(str(a_n[j]))
		j -= 1
print ''

Measured memory_bytes: 6412
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll N,K;
  string S;
  cin>>N>>K>>S;
  int i=K-1;
  if(S[i]=='A')S[i]='a';
  if(S[i]=='B')S[i]='b';
  if(S[i]=='C')S[i]='c';
  cout<<S<<endl;
  return 0;
}


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

int main() {

  string a, b, c, x;
  cin >> a >> b >> c;
  x = "aaa";
  x.at(0) = a.at(0);
  x.at(1) = b.at(0);
  x.at(2) = c.at(0);
  cout << x << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
typedef unsigned long long int ull;
int main() {
	//cout<<"GfG!";
	ull x, i, y, a = 100;
	cin>>x;
	i = 0;
	while (a < x)
	{
	    a = a * 1.01;
	    i++;
	}
	cout<<i;
	return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N, K; cin >> N >> K;
  int index = -1;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  int i = K, cnt = 1;
  while (i < N) {
    ++cnt; i += K - 1;
  }
  cout << cnt << endl;
}


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


/*
    Eratosthenes's Sieve
        creat a prime table for interval [0, N]
    Time Complexity : O(NloglogN)
*/


vector<bool> eratosthenes_sieve(int n) {
    vector<bool> v(n + 1, true);
    if (n >= 0) { v[0] = false; }
    if (n >= 1) { v[1] = false; }
    for (int i = 2; i*i <= n; i++) {
        if (!v[i]) { continue; }
        for (int j = i+i; j <= n; j += i) { v[j] = false; }
    }
    return v;
}



int main() {
    int N, ans, MAX_N = 1e8;
    cin >> N;
    
    vector<bool> prime = eratosthenes_sieve(MAX_N);
    
    for (int i = N; i <= MAX_N; i++) {
        if (prime[i] == true) { ans = i; break; }
    }
    
    cout << ans << endl;
    return 0;
}

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

#define int            long long int
#define float          long double
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define inf            1e18
#define set_pre(x,y)   fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)

using namespace std;
int32_t main()
{
    int n;
    cin>>n;
    vector<int>v(n);
    vector<int>dp(n+1,0);
    for(int i=0;i<n;i++)
        cin>>v[i];
    dp[1]=0;
    dp[2]=abs(v[1]-v[0]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(v[i-1]-v[i-2]),dp[i-2]+abs(v[i-1]-v[i-3]));
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <bits/stdc++.h>
using namespace std;

using lint = int64_t;
const lint MOD = 1e9 + 7;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> num;
    for (int i = 1; i * i <= n; i++) {
        num.push_back(i);
        if (i != n / i) {
            num.push_back(n / i);
        }
    }
    int m = num.size();
    sort(num.begin(), num.end());
    auto tmp = num;
    for (int i = 1; i < m; i++) {
        num[i] = tmp[i] - tmp[i - 1];
    }
    vector<vector<lint>> dp(k + 1, vector<lint>(m + 1));
    for (int j = 0; j < m; j++) {
        dp[0][j] = 1;
    }
    for (int i = 1; i <= k; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][m - 1 - j] = (dp[i][m - j] + dp[i - 1][j] * num[j] % MOD) % MOD;
        }
    }
    cout << dp[k][0] << endl;
    return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


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

int main() {
  int s, w;
  cin >> s >> w;
  string ans = "safe";
  if (s <= w) ans = "unsafe";

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


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

using namespace std;


const int N = 1e5 + 10;


int n;

int b[N], a[N];


int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
		scanf("%d", &b[i]);
	
	int Ans = 0;
	
	b[0] = 1e9, b[n] = 1e9;
	for (int i = 1; i <= n; i++)
		Ans += min(b[i-1], b[i]);
	
	printf("%d\n", Ans);
	
	return 0;
}

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

struct Crop{
	string str;
	double efficiency;
};

int foo(string A, string B){
	int sizeA = (int)A.size(), sizeB = (int)B.size(), size;
	size = min(sizeA , sizeB);
	for(int i = 0; i < size; i++){
		if(A[i] != B[i]){
			if(A[i] > B[i]){//cout<<A[i]<<">"<<B[i]<<endl;
				 return true;
			}else {
				return false;//cout<<A[i]<<"<"<<B[i]<<endl;
			}
		}
	}
	if(sizeA >= sizeB) return true;
	else return false;
}

void ISort(struct Crop crop[], int N){
	struct Crop temp;
	int i, j;
	for(i = 1; i < N; i++){
		temp = crop[i];
		j = i - 1;
		while(j >= 0 && crop[j].efficiency <= temp.efficiency){
			if(crop[j].efficiency ==  temp.efficiency){
				if(foo(crop[j].str, temp.str)){
					crop[j + 1] = crop[j] ;
					j--;
				} else{
					break;
				}
			} else{
				crop[j + 1] = crop[j] ;
				j--;
			}
		}
		crop[j + 1] = temp;
	}
}

int main(){
	double P, A, B, C, D, E, F, S, M, time;
	int i, j, k;
	int N;
	struct Crop crop[60];
	while(1){
		cin>>N;
		if(N == 0) break;
		for(i = 0; i < N; i++){
			cin>>crop[i].str>>P>>A>>B>>C>>D>>E>>F>>S>>M;
			time = (A + B + C + D + E) + (D + E) * (M - 1);
			crop[i].efficiency = (F * S * M - P)/time;
		}
		
		ISort(crop, N);
		
		for(i = 0; i < N; i++){
			cout<<crop[i].str<<endl;
		}
		cout<<"#"<<endl;
	}
	return 0;
}


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

#define N 1000
#define S 150

int LCSLength(char *, char *);

int main(){
  int q, i;
  char X[N];
  char Y[N];
  int LCS[S];
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%s", X);
    scanf("%s", Y);
    LCS[i]=LCSLength(X, Y);
  }

  for(i=0; i<q; i++){
    printf("%d\n", LCS[i]);
  }

  return 0;
}//main

int LCSLength(char *X, char *Y){
  int m, n, i, j;
  int c[N+1][N+1];
  m = strlen(X);
  n = strlen(Y);
  for(i=1; i<=m; i++){
    c[i][0]= 0;
  }
  for(j=0; j<=n; j++){
    c[0][j]= 0;
  }

  for(i=1; i<=m; i++){
   for(j=1; j<=n; j++){
     if(X[i-1]==Y[j-1]) c[i][j]=c[i-1][j-1]+1;
     else if(c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
     else c[i][j]=c[i][j-1];
    }
   }
   return c[m][n];
  }

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

struct unionFind{
  vector<long long> par, sz;
  
  unionFind(long long n): par(n), sz(n){
    for(long long i=0; i<n; i++) {
      par[i] = i; sz[i] = 1;
    }
  }
  
  long long root(long long x){
    if(par[x] == x) return x;
    else return par[x] = root(par[x]);
  }
  
  bool issame(long long x, long long y){
    long long px = root(x);
    long long py = root(y);
    return px == py;    
  }
  
  void unite(long long x, long long y) {
    long long px = root(x);
    long long py = root(y);
    if(px == py) return;
    if(sz[px] < sz[py]) swap(px, py);
    par[py] = px;
    sz[px] += sz[py];
    return ;
  }  
  long long size(long long x) {
    return sz[root(x)];
  }
};

int main(void){
  long long N, M;
  cin >> N >> M;
  long long A[M]; long long B[M];
  for(long long i=0; i<M; i++) cin >> A[i] >> B[i];
  long long ans[M];
  unionFind uf = unionFind(N);
  ans[M-1] = N*(N-1)/2;

  for(long long i=M-1; i>=1; i--){
    long long tmpA = A[i]; tmpA--;
    long long tmpB = B[i]; tmpB--;
    if(uf.issame(tmpA, tmpB)) {
      ans[i-1] = ans[i];
      continue;
    }
    ans[i-1] = ans[i] - uf.size(tmpA)*uf.size(tmpB);
    uf.unite(tmpA, tmpB);
  }
  for(long long i=0; i<M; i++) cout << ans[i] << endl;
  return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
using ll = long long;

int main()
{
    ll i,j;
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n);
    unordered_map <ll,ll> mp;
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    vector<ll> b(n+1,0);
    for(i = 0;i < n;++i){
        b.at(i+1) = a.at(i) + b.at(i);
        b.at(i+1) %= m;
        ll tmp = b.at(i+1);
        if(mp.count(tmp)){
            ++mp[tmp];
        }else{
            mp[tmp] = 1;
        }
    }
    if(mp.count(0)){
        ++mp[0];
    }else{
        mp[0] = 1;
    }
    ll ans = 0;
    for(auto x: mp){
        ll tmp = x.second;
        ans += tmp*(tmp-1)/2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5260
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Point{
	double x,y;
};

int N,M;

Point point[40];
double dp[40][40][41];

double calc(int start,int last,int next){
    return fabs((point[start].x*point[last].y-point[last].x*point[start].y)+(point[last].x*point[next].y-point[next].x*point[last].y)+
    		(point[next].x*point[start].y-point[start].x*point[next].y))/2;
}

void func(){

	double tmp;

	for(int i = 0; i < N; i++){
		scanf("%lf",&tmp);
		point[i].x = cos(tmp*2.0*M_PI);
		point[i].y = sin(tmp*2.0*M_PI);
	}

	for(int a = 0; a < 40; a++){
		for(int b = 0; b < 40; b++){
			for(int c = 0; c <= 40; c++)dp[a][b][c] = 0.0;
		}
	}

	double ans = 0.0;

	for(int start = 0; start < N; start++){
		for(int count = 2; count < M; count++){
			for(int last = start; last < N; last++){
				for(int next = last+1; next < N; next++){
					dp[start][next][count+1] = max(dp[start][next][count+1],dp[start][last][count]+calc(start,last,next));

					if(count+1 == M)ans = max(ans,dp[start][next][count+1]);
				}
			}
		}
	}
	printf("%.6lf\n",ans);
}

int main(){

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}

	return 0;
}

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

#define REP(i, n) for(int i=0;i<n;i++)
double d, n, b, p[12], h[12];

int main(){
	cin >> d >> n >> b;
	REP(i, n) cin >> p[i] >> h[i];
	
	double ans = 1e9;
	REP(i, b+1){
		double w = d / (i+1), l = 1, r = 1e9, res = 0;
		REP(itr, 50){
			double mid = (l+r)/2, vx = sqrt(w/(2*mid)), vy = vx * mid;
			if([&](){
				REP(i, n){
					double x = p[i];
					while(x > w) x -= w;
					if(-x*x/(2*vx*vx)+vy/vx*x < h[i]) return 0;
				}
				return 1;
			}()){
				r = mid;
				ans = min(ans, sqrt(vx*vx+vy*vy));
			}else l = mid;
		}
	}
	printf("%.11f\n", ans);
	return 0;
}

Measured memory_bytes: 1232
#include<stdio.h>

int main()
{
	long long tc;
	long long hasil = 1;
	int flag = 1;
	
	scanf("%lld", &tc);
	
	long long input[tc];
	
	for(int i = 0 ; i < tc; i++){
		scanf("%lld", &input[i]);
		if(input[i] == 0){
			printf("0\n");
			return 0;
		}
	}
	
	for(int i = 0; i < tc; i++){
		if(input[i] <= 1000000000000000000/hasil){
			hasil *= input[i];
		}else{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", hasil);
}

Measured memory_bytes: 2508
#include <iostream>
#include <string>
#include <queue>
#include <utility>
using namespace std;

int main(void){
    int N,L,sum = 0;
    cin >> N >> L;
    if(N+L<0){
        for(int i=0;i<N-1;i++){
           sum = sum + L;
           L++;
        }
    }else if(N+L==0){
        for(int i=0;i<N-1;i++){
           sum = sum + L;
           L++;
        }


    }else if(L<=0){
        for(int i=0;i<N;i++){
           sum = sum + L;
           L++;
        }
    }else if(L>0){
        for(int i=0;i<N-1;i++){
           L++;
           sum = sum + L;
        }
    }else{
        for(int i=0;i<N;i++){
           sum = sum + L;
           L++;
        }
    }
    cout << sum << endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lowbit(x) (x&(-x))
#define N 100005
int a[N];
int main() {
	int n;
	cin >> n;
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	if(a[n/2] == a[n/2+1]) puts("0");
	else printf("%d",a[n/2+1]-a[n/2]);
	return 0;
}

Measured memory_bytes: 640
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem (B) in C++
// MAIN IDEA   : brute force on length + divisors
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 2e6 + 5, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
inline int get_length(ll z) {
	int cnt = 0;
	while (z > 0) {
		z /= 10;
		++cnt;
	}
	return cnt;
}
ll st[15] = { };
int main() {
#ifdef ONLINE_JUDGE
    FAST
#endif
	ll n;
	cin >> n;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i)
			continue;
		ll a = i;
		ll b = n / i;
		int la = get_length(a);
		st[la] = max(st[la], a);
		int lb = get_length(b);
		st[lb] = max(st[lb], b);
	}
	int u = get_length(n), ans = 25;
	for (int i = 1; i <= u; ++i) {
		if (!st[i]) continue;
		ll q = n / st[i];
		ans = min(max(get_length(q), i), ans);
	}
	f(ans);
	return 0;
}

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

int main(){
    int N;
    std::cin >> N;
    int judge = 0;
    for(int i=1; i<=9; i++){
        if(N%i == 0 && N/i < 10){
            judge = 1;
        }
    }
    if(judge == 1){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	const double PI = 3.141592653589;
	double r;
	double menseki;
	double ensyu;
	
	scanf("%lf", &r);
	
	ensyu   = (r + r) * PI;
	menseki = r * r * PI;
	printf("%.5lf %.5lf\n", menseki, ensyu);
	
	return 0;
}

Measured memory_bytes: 652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int x = scan.nextInt();
		int[] a = new int[m];
		for (int i = 0; i < m; i++) {
			a[i] = scan.nextInt();
		}
		int costl = 0;
		int costr = 0;
		for (int i = 1; i < x; i++) {
			for (int j = 0; j < m; j++) {
				if (i == a[j]) costl++;
			}
		}
		for (int i = x+1; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (i == a[j]) costr++;
			}
		}
		System.out.println(Math.min(costl, costr));
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

int main() 
{
	fast;
	string a,b,c; cin>>a>>b>>c;
	if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

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

typedef long long ll;

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

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

const ll LLINF = 1e+18;

using Edge = pair<int,ll>;
vector<vector<Edge>> G;

int N,M;

// 頂点s から幅優先探索
// 辺x は使ってはならない
vector<int> bfs ( int s, int x ) {
    queue<int> que;
    vector<int> used(N,0);
    que.push(s);
    used[s] = 1;
    while( que.size() ){
        int p = que.front(); que.pop();
        for ( auto p : G[p] ){
            int t = p.first, y = p.second;
            if ( x == y or used[t] == 1 ) continue;
            used[t] = 1;
            que.push(t);
        }
    }
    return used;
}

int main() {
    cin >> N >> M;
    G.resize(N);
    
    REP(i,M){
        int s,t;
        cin >> s >> t;
        --s; --t;
        G[s].push_back(Edge(t,i));
        G[t].push_back(Edge(s,i));
    }
    
    int ans = 0;
    REP(i,M){
        vector<int> used = bfs(0,i);
        int sum = 0;
        REP(i,used.size()) sum += used[i];
        if ( sum != N ) ++ans;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
using System;
using System.Linq;

namespace abc173c
{
    class Program
    {
        static void Main(string[] args)
        {
            var ln1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var L = ln1[0];
            var R = ln1[1];
            var d = ln1[2];
            var ans = Enumerable.Range(L, R - L + 1).Count(i => i % d == 0);
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28212
n,k = map(int,input().split())
a = list(map(lambda x: int(x)-1,input().split()))
towns = [0]
added = [-1] * n
added[0] = 0
for i in range(1,k+1):
    tmp = a[towns[-1]]
    pl = added[tmp]
    if pl != -1:
        loop = towns[pl:]
        last = (k-pl) % len(loop)
        print(loop[last]+1)
        exit()
    else:
        added[tmp] = i
        towns.append(tmp)
print(towns[-1]+1)


Measured memory_bytes: 32372
import sys
N, M = map(int, input().split())

class Bridge:
    def __init__(self, nodeA, nodeB):
        self.edges = [BridgeEdge(nodeA, self), BridgeEdge(nodeB, self)]
        nodeA.addEdge(self.edges[1])
        #nodeB.addEdge(self.edges[0])

class BridgeEdge:
    def __init__(self, node, edge):
        self.edge = edge
        self.node = node
        self.flag = 0

class Node:
    def __init__(self, id):
        self.id = id
        self.bridges = []
    def addEdge(self, bridgeEdge):
        self.bridges.append(bridgeEdge)
    def __repr__(self):
        return "({})".format(self.id)

nodes = [Node(i) for i in range(N+1)]

for ui, vi in (map(int, input().split()) for _ in range(M)):
    Bridge(nodes[ui], nodes[vi])

S, T = map(int, input().split())

#nodes[S].flag = 1
s = [(None, nodes[S], 0)]
idx = 0
isOK = False
while idx < len(s):
    pre, cur, level = s[idx]
    idx += 1
    nxtlevel = level + 1
    nxtflag = 1 << (nxtlevel % 3)

    for nxt in cur.bridges:
        if (nxt.flag & nxtflag) == 0:
            nxt.flag |= nxtflag 
            if nxt.node is nodes[T] and nxtflag == 1:
                isOK = True
                break
            s.append((cur, nxt.node, nxtlevel))
    else:
        continue
    break
if isOK:
    print(nxtlevel//3)
else:
    print(-1)



Measured memory_bytes: 117844
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
int main()
{
    int M, N;
    int P[10005];
    int dp[10005];
    int sum = 0;
    cin >> M >> N;
    for(int i = 0; i < M; i++) {
        cin >> P[i]; sum += P[i];
    }
    sort(P, P + M, greater < int > () );
    fill_n(dp, 10005, INF);
    dp[0] = 0;
    for(int i = 0; i < N; i++) {
        int C, E;
        cin >> C >> E;
        for(int i = M; i >= 0; i--) {
            int p = min(i + C, M);
            dp[p] = min(dp[p], dp[i] + E);
        }
    }
    int minv = dp[M];
    int ans = sum - dp[M];
    for(int i = M - 1; i >= 0; i--) {
        minv = min(dp[i], minv);
        sum -= P[i];
        ans = max(ans, sum - minv);
    }
    cout << ans << endl;
    return (0);
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s; cin>>s;
    int sl=s.size();
    int naka=0;
    if(sl%2==0){
        int mid=sl/2-1,now1=sl/2-1,now2=sl/2;
        naka=0;
        while(naka<=sl-2 && s[mid]==s[now1] && s[mid]==s[now2]){
            now1--; now2++;
            naka+=2;
        }
    }else{
        int mid=sl/2,now1=mid-1,now2=mid+1;
        naka=1;
        while(naka<=sl-2 && s[mid]==s[now1] && s[mid]==s[now2]){
            now1--; now2++;
            naka+=2;
        }
        
    }
    cout<<(sl+naka)/2;
    return 0;
}

Measured memory_bytes: 512
import scala.io.StdIn

object Main{
	def main(args: Array[String]): Unit = {

		val N = StdIn.readLine.toInt

		val result: Int =
			(1 to N).filter( _ % 2 == 1)
				      .count( num => diviserNum(num) == 8)
		println(result)
	}

	def log(base: Int)(trueVal: Int): Int = {
		var i = 0
		var trueVar = trueVal

		while( trueVar % base == 0 ) {
			i = i + 1
			trueVar = trueVar / base
		}
		i
	}

	def diviserNum(N: Int): Int = {
		val inclusive = 2 to (Math.sqrt(N).toInt + 1)
		var Nvar = N

		val resultList = inclusive.map { num =>
			val result_i = log(num)(Nvar)
			Nvar = Nvar / Math.pow(num.toDouble, result_i.toDouble).toInt
			result_i
		}
		val result =
			resultList.filter(_ > 0).foldLeft(1) { (rs, num) =>
				rs * (num + 1)
			}
		result
	}
}

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

int a, b;
string s;
bool ans = 1;

void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int main() {
  int i;
  cin >> a >> b >> s;
  for(i = 0; i < s.size(); ++i) {
    if(i == a && s[i] != '-')
      ans = 0;
    else if(i != a && (s[i] < '0' || s[i] > '9'))
      ans = 0;
  }
  prians(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int n;
  cin >> n;
  int tmp, max_val = -1, sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    max_val = max(max_val, tmp);
    sum += tmp;
  }

  sum -= max_val / 2;

  cout << sum << endl;
  return 0;
}


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

using namespace std;

int main(){

	int n;
	cin >> n;
	long tmp1=2,tmp2=1;
	for(int i = 0; i < n-1; i++){
		long a;
		a = tmp2;
		tmp2 = tmp1+tmp2;
		tmp1 = a;
	}
	cout << tmp2 << endl;

	return 0;
}


Measured memory_bytes: 256
def B10N(X,B):
    if X//B!=0: return B10N(X//B,B)+str(X%B)
    return str(X%B)

N,A,B,C = (int(X) for X in input().split())
Li = [int(input()) for X in range(0,N)]
CostM = pow(10,9)
for T in range(0,pow(4,N)):
    Cho = list(B10N(T,4).zfill(N))
    if Cho.count('1')>0 and Cho.count('2')>0 and Cho.count('3')>0:
        Cost = 0
        ALi = [Li[X] for X,Y in enumerate(Cho) if Y=='1']
        BLi = [Li[X] for X,Y in enumerate(Cho) if Y=='2']
        CLi = [Li[X] for X,Y in enumerate(Cho) if Y=='3']
        SyC = (len(ALi)+len(BLi)+len(CLi)-3)*10
        LeC = abs(sum(ALi)-A)+abs(sum(BLi)-B)+abs(sum(CLi)-C)
        if SyC+LeC<CostM: CostM = SyC+LeC
print(CostM)

Measured memory_bytes: 9192
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
constexpr int MOD = 1000000007;
constexpr ll INF = 50000000000000000;
typedef std::pair<int,int> P;
constexpr ll SIZE= 100010;

    ll N,A[2*SIZE];
    ll ans=INF;
    bool F[2*SIZE]={};
    std::map<int,int> S;
int main() {
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){
        cin>>A[i];
        if(S.find(A[i]-1)==S.end()){
            S.insert({A[i],1});
        }else{
            S.insert({A[i],S[A[i]-1]+1});
        }
    }
    for(auto x:S){
        ans=std::min(ans,N-x.second);
    }

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

Measured memory_bytes: 11264
#include <stdio.h>

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

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  VI a(n); for (int i = 0; i < n; i++) cin >> a[i];
  int res = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == a[i + 1]) {
      res++;
      i++;
    }
  }
  cout << res << '\n';
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  for (int X = 0; X <= N; ++X) {
    int A = X * 1.08;
    if (A == N) {
      cout << X << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n;
    cin>>n;
    ll a[n];
    ll sum=0,ans=0;
    rep(i,n){
        cin>>a[i];
        ans+=sum*a[i];
        ans%=mod;
        sum=(sum+a[i])%mod;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 5200
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
#define repi(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define endl "\n"
#define ing long long
using namespace std;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

#define x first
#define y second

#define MAX 20

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

    while(true){
        int n, m;
        vector<pair<int,int>> co;
        int field[MAX+4][MAX+4] = {};
        char s;
        int l;
        int con = 0, nx = 10, ny = 10;
        
        cin>>n;

        if(!n) break;

        co.resize(n);
        
        for(int i = 0; i < n; i++){
            cin>>co[i].x>>co[i].y;
            field[co[i].x][co[i].y] = true;
        }

        if(field[10][10]){
            field[10][10] = false;
            con++;
        }
        
        cin>>m;
        
        for(int i = 0; i < m; i++){
            cin>>s>>l;

            int a, b;

            if(s == 'N'){
                b = 1, a = 0;
            } else if(s == 'S'){
                b = -1, a = 0;
            } else if(s == 'E'){
                b = 0, a = 1;
            } else {
                b = 0, a = -1;
            }
            for(int j = 0; j < l; j++){
                nx += a, ny += b;
                if(field[nx][ny]){
                    field[nx][ny] = false;
                    con++;
                }
            }
        }

        cout<<(con == co.size() ? "Yes":"No")<<endl;
    }
    return 0;
}



Measured memory_bytes: 3016
#include <stdio.h>
#include <stdlib.h>

#define N_MAX 1000

int S[N_MAX], top;

void initialize(void) {
  top = 0;
}

int isEmpty(void) {
  if (top == 0) {
    return 1;
  } else {
    return 0;
  }
}

int isFull(void) {
  if (top == N_MAX - 1) {
    return 1;
  } else {
    return 0;
  }
}

void push(int x) {
  if (isFull()) {
    printf("push error!\n");
  } else {
    //printf("push %d\n", x);
    S[top] = x;
    top++;
  }
}

int pop(void) {
  if (isEmpty()) {
    printf("pop error!\n");
    return 0;
  } else {
    top--;
    int tmp = S[top];

    //printf("pop %d\n", tmp);
    return tmp;
  }
}

int main(int argc, char const *argv[]) {
  char t[100];
  int a, b;

  while(scanf("%s", &t) != EOF) {
    if (t[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (t[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (t[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      //printf("atoi : %d\n", atoi(t));
      push(atoi(t));
    }
  }

  printf("%d\n", pop());

  return 0;
}

Measured memory_bytes: 548
#include<iostream>
#include<string>
#include<sstream>
#include<stack>
#include<cstdlib>
#include<cstdio>
using namespace std;
int main(){
  string s,t;
  while(getline(cin,s)){
    stringstream x(s);
    stack<double> num;
    while(x>>t){
      if(t == "+" || t == "-" || t == "*" || t == "/"){
	double a,b;
	a = num.top();num.pop();
	b = num.top();num.pop();
	if(t == "+") num.push(b+a);
	if(t == "-") num.push(b-a);
	if(t == "*") num.push(b*a);
	if(t == "/") num.push(b/a);
      }
      else num.push(atof(t.c_str()));
    }
    printf("%.6lf\n",num.top());
  }
  return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

long long comb(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return comb(n - 1, k - 1) + comb(n - 1, k);
  }
}

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> num(N);
    num[0] = 3;
    REP(i, N) {
        ll a;
        cin >> a;
        A[i] = a + 1;
        // num[a + 1]++;
    }

    vector<int> nums_batch(N+1);
    nums_batch[0] = 3;
    REP(i, N) {
        nums_batch[A[i]]++;
        if(nums_batch[A[i]-1] < nums_batch[A[i]]) {
            cout << 0 << endl;
            return 0;
        }
    }
    

    // vector< vector<int> > acum(N + 2, vector<int>(N + 2));

    // acum[0][0] = 3;
    // REP(i, N) {
    //     acum[i + 1][A[i]] = acum[i][A[i]] + 1;
    // }

    // REP(i, N+1) {
    //     REP(j, N) cerr << acum[i][j] << " ";
    //     cerr << endl;
    // }

    ll ans = 1;
    REP(i, N) {
        // if(num[A[i]-1] < num[A[i]]) {
        //     cout << 0 << endl;
        //     return 0;
        // }
        ans *= num[A[i]-1];
        ans %= mod;
        num[A[i]-1]--;
        num[A[i]]++;
        // cerr << i << " th iter : " << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int N, M,count=0,ans=0;
	cin >> N >> M;
	vector<vector<int>>a(N, vector<int>(M,0));
	for (int i = 0;i < N;++i) {
		int k;
		cin >> k;
		for (int j = 0;j < k;++j)cin >> a[i][j];
	}
	for (int j = 0;j <M;++j) {
		for (int h = 0;h < N;++h) {
			for (int l = -j;l < M - j;++l)if (a[0][j] == a[h][j + l]&&a[0][j]!=0)++count;
		}if (count == N)++ans;
		count = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		String s = kb.next();
		char p = s.charAt(0);
		String t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		for (int i = 0; i < 26; i++) {
			if (t.charAt(i) == p) {
				System.out.println('A');
			}
		}
		for (int i = 26; i < 52; i++) {
			if (t.charAt(i) == p) {
				System.out.println('a');
			}
		}
		kb.close();
	}

}


Measured memory_bytes: 27028
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n,m=map(int,input().split())
s=input().strip()
t=input().strip()

prod=n
while prod%m!=0: prod+=n

d={}
for i in range(n):
    d[(prod//n)*i]=s[i]
for i in range(m):
    j=(prod//m)*i
    if (j in d) and (d[j]!=t[i]):
        print("-1")
        break
else:
    print(prod)


Measured memory_bytes: 49904
import bisect

n = int(input())
li = [int(x) for x in input().split()]
li.sort()
ans = 0
for i in range(n-1):
    for j in range(n-1):
        if i<j:
            a = bisect.bisect_left(li,li[i]+li[j])
            ans += a-1-j
print(ans)

Measured memory_bytes: 3188
require 'set'
X, N = gets.split.map(&:to_i)
pn = Set.new(gets.split.map(&:to_i))

100.times do |i|
  px = X - i
  unless pn.include?(px)
    puts px
    break
  end
  px = X + i
  unless pn.include?(px)
    puts px
    break
  end
end

Measured memory_bytes: 14540
n = int(input())
a = [int(i) for i in input().split()]


def GCD(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    else:
        return GCD(b, a % b)


def LCM(a, b):
    return a * b//GCD(a, b)


m = a[0]
for ni in range(1, n):
    m = LCM(m, a[ni])

ans = 0
for ni in range(n):
    ans += (m-1) % a[ni]

print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main(void)
{
	long long A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	long long minn = min(X, Y);
	long long count = 0;
	if (A+B>2*C)
	{
		long long pizaa=0, pizab =0;
		pizaa = max((long long)0,X - minn); pizab =max((long long)0, Y - minn);
		
		cout << min((pizaa * A + pizab * B),max(X-minn,Y-minn)*C*2 )+ minn*2 * C<<"\n";
	}
	if (A+B<=C*2)
	{
		cout << X * A + Y * B << "\n";
	}
}


Measured memory_bytes: 256
# cook your dish here
n,k = map(int,input().split())
d = []
visited = [0]*n
for j in range(k):
    d.append(int(input()))
    jk= [int(i) for i in input().split()]
    for jj in jk:
        visited[jj-1] = 1
print(n-sum(visited))

Measured memory_bytes: 9188