akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define double long double

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

string s = "RLUD";
int dir[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}, n;
int x[100005], y[100005];
char d[100005];

double f(double t) {
	double xM = -1e18, xm = 1e18, yM = -1e18, ym = 1e18;
	for(int i=0;i<n;i++) {
		int j = s.find(d[i]);
		double X = x[i] + t * dir[j][0],
			   Y = y[i] + t * dir[j][1];
		xM = max(xM, X);
		xm = min(xm, X);
		yM = max(yM, Y);
		ym = min(ym, Y);
	}
	return (xM - xm) * (yM - ym);
}

int main()
{
	IO_OP;
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> x[i] >> y[i] >> d[i];	
	double l = 0, r = 2e8+87;
	for(int i=0;i<300;i++) {
		double m1 = (l*2+r)/3,
			   m2 = (l+r*2)/3;
		double f1 = f(m1), f2 = f(m2);
		if(f1 >= f2)
			l = m1;
		else 
			r = m2; 
	}
	cout << fixed << setprecision(16) << f(l) << endl;
}



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, k;
    cin >> m >> k;
    if (m == 1) {
        if (k == 0) {
            cout << "0 0 1 1" << endl;
        } else {
            cout << "-1" << endl;
        }
        return 0;
    }
    if (k < (1 << m)) {
        cout << k;
        for (int i = 0; i < (1 << m); ++i) {
            if (i != k) {
                cout << " " << i;
            }
        }
        cout << " " << k;
        for (int i = (1 << m)-1; i >= 0; --i) {
            if (i != k) {
                cout << " " << i;
            }
        }
        cout << endl;
    } else {
        cout << "-1" << endl;
    }
    return 0;
}


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

int main() {
    cout.tie(0)->sync_with_stdio(0);
    int N; cin >> N;
    vector<int> values(N-1);
    for (int &x : values) cin >> x;
    if (N == 2) {
        cout << 2 * values.front() << '\n';
        exit(0);
    }
    int res = values.front();
    for (int i = 0; i+1 < N-1; ++i) {
        res += min(values[i], values[i+1]);
    }
    cout << res + values.back() << '\n';
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long a, b;
    scanf("%ld %ld", &a, &b);
    if(a<=b) {
        printf("%ld\n", a);
    }
    else {
        printf("%ld\n", a-1);
    }

    return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

template <typename T>
class BIT {
 public:
  BIT(int n) : v_(n + 1) {}
  T Sum(int i) const {
    T ret = 0;
    while (i) {
      ret += v_[i];
      i -= i & -i;
    }
    return ret;
  }
  T Get(int i) const { return Sum(i) - Sum(i - 1); }
  void Add(int i, T v) {
    while (i < v_.size()) {
      v_[i] += v;
      i += i & -i;
    }
  }

 private:
  std::vector<T> v_;
};

struct Q {
  int l, r, i, v;
};

int main() {
  in(int, n, q);
  V<int> c(n);
  rep(i, n) cin >> c[i];
  V<Q> qs;
  rep(i, q) {
    in(int, l, r);
    qs.push_back({l, r, i, 0});
  }
  sort(all(qs), [](const Q& a, const Q& b) { return a.r < b.r; });
  map<int, int> seen;
  BIT<int> bit(n);
  auto qit = qs.begin();
  rep(i, n) {
    auto it = seen.find(c[i]);
    if (it != seen.end()) {
      bit.Add(it->second + 1, -1);
    }
    seen[c[i]] = i;
    bit.Add(i + 1, 1);
    while (qit != qs.end() && qit->r == i + 1) {
      qit->v = bit.Sum(i + 1) - bit.Sum(qit->l - 1);
      ++qit;
    }
  }
  sort(all(qs), [](const Q& a, const Q& b) { return a.i < b.i; });
  for (auto& qi : qs) {
    out(qi.v);
  }
}

Measured memory_bytes: 38972
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
const i64 MOD = 1000000007;
const i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;


int main() {
    string s;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i < s.length(); ++i) if(s[i] == 'o') ++cnt;
    if(cnt + 15 - s.length() >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
 }

Measured memory_bytes: 256
#include<stdio.h>

int search(int A[], int n, int key)
{
    int i = 0;
    A[n] = key;
    while (A[i] != key) i++;
    return i !=n;
}

int main()
{
    int i, n, A[10000 + 1], q, key, sum = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &A[i]);

    scanf("%d", &q);
    for (i = 0; i < q; i++)
    {
        scanf("%d", &key);
        if (search(A, n, key)) sum++;
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 2080
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

ll n, table[100];

ll ans;

void solve(int num, int asum, int bsum){
	if (num == n){
		ans = min(ans, (ll)(abs(asum - bsum)));
		return;
	}

	solve(num + 1, asum + table[num], bsum);
	solve(num + 1, asum, bsum + table[num]);
}

int main(){
	while (cin >> n&&n){
		ans = INF;
		REP(i, n){
			cin >> table[i];
		}
		solve(0, 0, 0);
		cout << ans << endl;
	}
}

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

int main() {
    long long n,i,min,max,all;
    cin >> n ;
    long long element[n];
    i = 1;
    while(i <= n){
        cin >> element[i] ;
        i = i + 1;
    }
    min = element[1];
    max = element[1];
    all = 0;
    long long j;
    j = 1;
    while(j <= n){
        if(element[j] > max ){
            max = element[j];
        }
        j = j + 1;
    }
    long long k;
    k = 1;
    while(k <= n){
        if(element[k] < min){
            min = element[k];
        }
        k = k + 1;
    }
    
    long long l ;
    l = 1;
    while(l <= n){
        all = all + element[l];
        l = l + 1;
    }
    cout << min << " " << max << " " << all << endl;

    
}


Measured memory_bytes: 3208
#include <iostream>
#include <utility>

using namespace std;
int g[60][60],n,a[2500],b[2500];
pair<int,int> p[2500];
bool used[60];
void dfs(int s){
	used[s] = true;
	for(int i=0;i<n;i++){
		if(!used[i] && g[s][i]){
			dfs(i);
		}
	}
}

int main(){
	int i,j,m,ans = 0;
	cin >> n >> m;
	for(i=0;i<n;i++){
		used[i] = false;
		for(j=0;j<n;j++){
			g[i][j] = 0;
		}
	}
	
	for(i=0;i<m;i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		g[a[i]][b[i]] = 1;
		g[b[i]][a[i]] = 1;
		p[i] = make_pair(a[i],b[i]);
	}
	
	for(i=0;i<m;i++){
		g[p[i].first][p[i].second] = 0;
		g[p[i].second][p[i].first] = 0;
		dfs(0);
		for(j=0;j<n;j++){
			if(!used[j]){
				ans++;
				break;
			}
		}
		for(j=0;j<n;j++){
			used[j] = false;
		}
		g[p[i].first][p[i].second] = 1;
		g[p[i].second][p[i].first] = 1;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1

int dp[45];

int Fib(int n){
  int u,v;
  if(n==0||n==1) return 1;
  else if(dp[n]!=NIL) return dp[n];
  else return dp[n]=Fib(n-1)+Fib(n-2);
}

int main(){
  int i,ans,n;
  scanf("%d",&n);
  for(i=0;i<45;i++) dp[i]=NIL;
  ans=Fib(n);
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 596
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n,k = map(int, readline().split())
  h = list(map(int, readline().split()))
  if n<=k:
    print(0)
  else:
    h.sort(reverse=True)
    ans = sum(h[k:])
    print(ans)
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 25320
#include <iostream>
using namespace std;
int main(void){
int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a<0){
        cout<<(0-a)*c+d+e*b<<endl;
    }
      if(a>0){
        cout<<(b-a)*e<<endl;
    }
}



Measured memory_bytes: 3072
#include<stdio.h>

int main(void) {

    int x,y,mem,i;

    for (i=1;i<3000;i++) {

        scanf("%d%d",&x,&y);

        if (x==0 && y==0) break;

        if (x>y) {
            mem=x;
            x=y;
            y=mem;
        }

        printf("%d %d\n",x,y);

    }

    return 0;
}

Measured memory_bytes: 596
h,w=map(int,input().split())
a=['.'*(w+2)]
for _ in range(h):
    a.append('.'+input()+'.')
a.append('.'*(w+2))

ans="Yes"
for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j]=='#' and a[i-1][j]=='.' and a[i][j-1]=='.' and a[i][j+1]=='.' and a[i+1][j]=='.':
            ans="No"
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
int main(void){
  int A,B,C;
  cin >> A >> B >> C;
  string ans;
  vector<int> vec = {A,B,C};
  sort(vec.begin(),vec.end());
  if (vec[1]==C)
    ans = "Yes";
  else
    ans = "No";
  if (A>B)
    ans = "No";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    ans = ((1 + n-1) * (n-1)) / 2;
    cout << ans << endl;
}

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

int main(){
    int X; cin >> X;
    int num_500=X/500;
    int ama=X%500;
    int num_5=ama/5;
    ll ans=num_500*1000 + num_5*5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a, b, c = zip(*[list(map(int, input().split())) for i in range(m)])

dist = [[1e18]*n for i in range(n)]
for i in range(m):
    dist[a[i]-1][b[i]-1] = dist[b[i]-1][a[i]-1] = min(dist[a[i]-1][b[i]-1], c[i])

for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
ans = 0
for i in range(m):
    if dist[a[i]-1][b[i]-1]<c[i]:
        ans += 1

print(ans)

Measured memory_bytes: 3444
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int sum = 0; char c[2000020];
int main()
{
    ios :: sync_with_stdio(false);
    cin >> c; for(int i = 0; c[i]; i++) sum += c[i] - '9';     
    puts(sum % 9 ? "No" : "Yes");
}

Measured memory_bytes: 3844
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;




int main()
{
	int a, b; cin >> a >> b;
	int tmp = b;
	while (tmp)
	{
		a *= 10;
		tmp /= 10;
	}
	a += b;

	REP(i, 1000)
	{
		if (i*i == a)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}


	cout << "No" << endl;
	

	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
VL dx={1,0,-1,0};
VL dy={0,1,0,-1};
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll n;
    cin>>n;
    fr(i,1,3501)
    {
        fr(j,1,3501)
        {
            ll y=(4*i*j-n*i-n*j);
            if(y<1)
            {
                continue;
            }
            ll x=(n*i*j)/(4*i*j-n*i-n*j);
            if(x>0)
            {
                if(n==(4*(x*i*j)/(x*i+x*j+i*j)))
                {
                    cout<<i<<" "<<j<<" "<<x<<endl;
                    return;
                }
            }
        }
    }
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    int t[5];   //調理時間の配列
    int a[5];   //調理時間の1の位の配列

    for(int i = 0; i < 5; i++) {
        cin >> t[i];
        a[i] = t[i] % 10;
    }

    int b = 10;  //a[5]の中で1以上で最小のものを調べる変数
    int c = 0;   //a[5]の中で1以上で最小のものの要素番号を調べる変数
    
    for(int i = 0; i < 5; i++) {
        if(0 < a[i] && a[i] < b) {
            b = a[i];
            c = i;
        }
    }

    int u[5];   /* u[i]は、調理時間が10の倍数でなければt[i]の1の位を切り上げたもの。
                   ただし例外的にu[c] = t[c]とする。 */

    for(int i = 0; i < 5; i++) {
        if(i == c) {
            u[i] = t[i];
            continue;
        }
        if(a[i] == 0) {
            u[i] = t[i];
        }
        else {
            u[i] = (t[i]/10 + 1)*10;
        }
    }

    int ans = 0;

    for(int i = 0; i < 5; i++) {
        ans += u[i];
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100010
using namespace std;
int n,h[N];
int main(){
	int i,j,ans=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>h[i];
	}
	for(i=0;i<n;i=j)
	{
		for(j=i+1;j<n;j++)
		{
			if(h[j]>h[j-1])
			{
				break;
			}
		}
		ans=max(ans,j-i-1);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    long long int n, res = 1, i;

    cin >> n;

    long long int a[n];

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

        if(a[i] == 0){
            res = 0;
        }
        else if(res > (1000000000000000000LL / a[i])){
            res = -1;
        }
        else if(res != -1){
            res *= a[i];
        }
    }

    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(ll i = 0; i < n; ++i) cin >> a[i];
  sort(begin(a),end(a));
  if(n == 2){
    cout << a[1]-a[0] << '\n';
    cout << a[1] << ' ' << a[0];
    return 0;
  }
  vector<pair<ll,ll>> vp;
  if(a[0] <= 0 and a[n-1] >= 0){
    ll neg = a[0], pos = a[n-1];
    for(ll i = 1; i < n-1; ++i){
      if(a[i] <= 0){
        vp.emplace_back(pos,a[i]);
        pos -= a[i];
      }
      else{
        vp.emplace_back(neg,a[i]);
        neg -= a[i];
      }
    }
    vp.emplace_back(pos,neg);
    cout << pos-neg << '\n';
  }
  else if(a[n-1] < 0){
    ll neg = a[1], pos = a[n-1]-a[0];
    vp.emplace_back(a[n-1],a[0]);
    for(ll i = 2; i < n-1; ++i){
      if(a[i] <= 0){
        vp.emplace_back(pos,a[i]);
        pos -= a[i];
      }
      else{
        vp.emplace_back(neg,a[i]);
        neg -= a[i];
      }
    }
    vp.emplace_back(pos,neg);
    cout << pos-neg << '\n';
  }
  else{
    ll neg = a[0]-a[n-1], pos = a[n-2];
    vp.emplace_back(a[0],a[n-1]);
    for(ll i = 1; i < n-2; ++i){
      if(a[i] <= 0){
        vp.emplace_back(pos,a[i]);
        pos -= a[i];
      }
      else{
        vp.emplace_back(neg,a[i]);
        neg -= a[i];
      }
    }
    vp.emplace_back(pos,neg);
    cout << pos-neg << '\n';
  }
  for(auto& p : vp) cout << p.first << ' ' << p.second << '\n';
  return 0;
}


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

int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
 
    long long n;
    string s;
    cin>>n;
    while(n)
    {
        n--;
        s.push_back('a'+(n%26));
        n/=26;
    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i, 1, 5) --> {1,2,3,4}
// rep(i, 5, 1) --> {4,3,2,1}
// rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n+1);
    rep(i, 1, n+1)
        cin >> v[i];
    vector<int> dp(n+1,INT_MAX);
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(v[2]-v[1]);
    // cout << v[2];
    rep(i, 3, n+1)
    {
        int x = min(i,k+1);
        rep(j, 1, x)
        {
            int p = dp[i-j] + abs(v[i]-v[i-j]);
            dp[i] = min(dp[i], p);
        }
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1024
import math
x=int(input())
if x==2:
    print(x)
else:
    for i in range(x,200000):
        if x%2==0:
            x+=1
        else:
            buf=math.ceil(math.sqrt(x))
            a=0
            for j in range(3,buf+1,2):
                if x%j==0:
                    a+=1
                    break
                else:
                    continue
            if a!=0:
                x+=2
            else:
                print(x)
                break

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n, k;
	cin >> n >> k;
	print(min(abs(n%k),abs(k-n%k)));
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    private int H,W;
    private int[] Count=new int[200];
    public void Solve()
    {
        var l=Console.ReadLine().Split(' ');
        H=int.Parse(l[0]);
        W=int.Parse(l[1]);
        for(int i=0;i<H;i++)
        {
            foreach(char c in Console.ReadLine())
            {
                Count[c]++;
            }
        }
        
        int two=0,one=0;
        foreach(int i in Count)
        {
            if(i%2==1)
            {
                one++;
            }
            if(i%4==2||i%4==3)
            {
                two++;
            }
        }
        if(H%2==1&&W%2==1)
        {
            if(one!=1)
            {
                Console.WriteLine("No");
                return;
            }
        }
        else
        {
            if(one!=0)
            {
                Console.WriteLine("No");
                return;
            }
        }
        int tt=0;
        if(H%2==1)
        {
            tt+=W/2;
        }
        if(W%2==1)
        {
            tt+=H/2;
        }
        if(two>tt)
        {
            Console.WriteLine("No");
            return;
        }
        if((tt-two)%2==1)
        {
            Console.WriteLine("No");
            return;
        }
        Console.WriteLine("Yes");
    } 
    
    static void Main()
    {
        new Program().Solve();
    }
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> a(N);
  for(int i = 0; i< N; i++){
    cin >> a.at(i);
  }
  
  sort(a.rbegin(),a.rend());
  
  int layers = N;
  
  for(int j = 0; j < N-1; j++){
    if(a.at(j) == a.at(j+1)){
      layers -= 1;
    }
  }
  
  cout << layers << endl;

}


Measured memory_bytes: 256
n = int(input())
ans = 0
ansc = 0
def dc(m):
  cnt = 0
  x = m
  while (True):
    if x%2 == 0:
      cnt += 1
      x = x//2
    else:
      break
  return cnt
for i in range(1,n+1):
  c = dc(i)
  if c > ansc:
    ans = i
    ansc = c
if n == 1:
  print(1)
else:
  print(ans)

Measured memory_bytes: 61900
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
M = 10**9+7
if abs(n-m)>=2:
    val = 0
else:
    val = 1
    for i in range(1,n+1):
        val *= i
        val %= M
    for j in range(1,m+1):
        val *= j
        val %= M
    if abs(n-m)==0:
        val *= 2
        val %= M
print(val)

Measured memory_bytes: 63864
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
using namespace std;

ostream& operator << (ostream &out, vector<int> &v) { for(auto a:v) out << a<<" "; out<<endl; }

int main()
{
    string s;
    cin >> s;
    int a=stoi(s.substr(0,2));
    int b=stoi(s.substr(2,2));
    if((b==0 && a>12) || (a==0 && b>12) ||(a==0 && b==0)){
        cout <<"NA\n";
        exit(0);
    }
    if(a==0){
        cout <<"YYMM\n";
        exit(0);
    }
    if(b==0){
        cout <<"MMYY\n";
        exit(0);
    }

    if(a>12 && b>12){
        cout <<"NA\n";
        exit(0);
    }
    if(a>12 && b<=12){
        cout <<"YYMM\n";
        exit(0);
    }
    if(b>12 && a<=12){
        cout <<"MMYY\n";
        exit(0);
    }
    cout <<"AMBIGUOUS\n";
    return 0;

}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
    p = [0]*n
    p[0] = 1
    for x in range(n):
        for y in v[x]:
            p[y] += p[x]/len(v[x])
    e = [0]*n
    e_ = [0]*n
    for x in range(n)[::-1]:
        s = 0
        for y in v[x]:
            s += e[y]
        if v[x]:
            e[x] = e_[x] = 1+s/len(v[x])
        if len(v[x]) > 1:
            e_[x] = 1+(s-max([e[y] for y in v[x]]))/(len(v[x])-1)
    ans = e[0]
    print(ans+min(list(map(lambda x:x[0]*(x[2]-x[1]), zip(p,e,e_)))))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 53340
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	ll n, a, b, c;
	cin >> n >> a >> b;
	c = a + b;
	ll ans = 0;
	ans = n / c * a;
	ll temp = (n - (n/c*c));
	if(temp > a) temp = a;
	ans += temp;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;

int main() {
   int n; cin>>n;
   V v(n);
   rep(i,0,n) cin>>v[i];
   sort(v.begin(),v.end());
   int ans=1;
   rep(i,0,n-1){
      if(v[i]!=v[i+1])ans++;
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var c string
var ans, res int = 1, 1
var mod int = pow(10, 9) + 7

func main() {
	fmt.Scan(&c)
	if c == "a" || c == "i" || c == "u" || c == "e" || c == "o" {
		fmt.Println("vowel")
	} else {
		fmt.Println("consonant")
	}
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
 
int main() {
	int n, nn, sum = 0;
	cin >> n;
	nn = n;
 
	for (int i = 0; i < 10; i++) {
		sum += n % 10;
		n /= 10;
		if (n == 0) 
			break;
	}
	if (nn%sum == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,a,b;
	cin>>n>>a>>b;
	if(a>b || (n==1 && a!=b)){
		cout<<"0\n";
	}
	else{
		long long int x=(n-2)*(b-a);
		cout << ++x <<"\n";
	}
}

Measured memory_bytes: 256
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int[] x = new int[N];
        for(int i = 0; i < N; i++) x[i] = sc.nextInt();

        long[][][] dp = new long[N+1][N+1][A*N+1];
        dp[0][0][0] = 1;
        
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                for(int k = 0; k <= A * N; k++){
                    dp[i+1][j][k] += dp[i][j][k];
                    if(k >= x[i]){
                        dp[i+1][j+1][k] += dp[i][j][k-x[i]]; 
                    }
                }
            }
        }
        long ans = 0;
        for(int i = 1; i <= N; i++) ans += dp[N][i][i*A];
        System.out.println(ans);
    }
}


Measured memory_bytes: 82364
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;


void solve(){
	int n ;
	cin >> n ;
	vi a(n) ;
	for(auto& x : a) cin >> x ;
	map<int,int> mp ;
	int sm = 0 ;
	for(int i = 0 ; i < n ; i++){
		mp[a[i]]++ ;
		sm += a[i] ;
	}
	int t ;
	cin >> t ;
	for(int i = 0 ; i < t ; i++){
		int b , c ;
		cin >> b >> c ;
		int cur = mp[b] ;
		mp[b] = 0 ;
		mp[c] += cur ;
		sm -= cur*b ;
		sm += cur*c ;
		cout << sm << endl ;
	}
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
}


Measured memory_bytes: 10104
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    cout << 6 - A - B << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int p;
int b0;
int A[3000];
int primes[11];
int ps;

int root;
int iroot;
int dlog[3000];

int modpow(int x, int n){
  int r=1;
  for(;n;n>>=1){
    if(n&1) r = r * x % p;
    x = x * x % p;
  }
  return r;
}



int main(){
  int i, j, x, q, t;
  scanf("%d", &p);
  if(p == 2) root = 1;
  else {
    q = p-1;
    for(i=2;i*i<=q;i++){
      if(q % i == 0){
        primes[ps++] = i;
        do {q /= i;} while(q % i == 0);
      }
    }
    if(q != 1) primes[ps++] = q;
    for(i=2;i<30;i++){
      for(j=0;j<ps;j++){
        if(modpow(i, (p-1)/primes[j]) == 1) break;
      }
      if(j == ps){
        root = i;
        break;
      }
    }
  }
  x = 1;
  for(i=0;i<p-1;i++){
    dlog[x] = i;
    x = x * root % p;
  }
  iroot = modpow(root, p-2);
  scanf("%d", &b0);
  for(i=1;i<p;i++){
    int x;
    scanf("%d", &x);
    A[dlog[i]] = (x + p - b0) * modpow(i, p-2) % p;
  }

  printf("%d ", b0);
  t = 1;
  for(i=0;i<p-1;i++){
    int r=0;
    int w = 1;
    for(j=0;j<p-1;j++){
      r = (r + w * A[j]) % p;
      w = w * t % p;
    }
    if(r) r = p - r;
    t = t * iroot % p;
    printf("%d ", r);
  }

  return 0;
}


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

void call(int n);

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

    return 0;
}

void call(int n){
    for(int i = 1; i <= n; ++i){
        int x = i;
        if(x % 3 == 0){
            cout << " " << i << flush;
        }else{
            while(1){
                if(x != 0 && x % 10 == 3){
                    cout << " " << i << flush;
                    break;
                }else if(x == 0){
                    break;
                }
                x /= 10;
            }
        }
        
    }
    cout << endl;
}

Measured memory_bytes: 3020
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {

  i64 N, i;
  cin >> N;
  vi A(N);
  REP(0, N, i) {
    cin >> A[i];
  }

  i64 ans = 0;
  i64 NUM = 1000000007;
  i64 b = 1;
  REP(0, 61, b) {
    i64 c0 = 0, c1 = 0;
    REP(0, N, i) {
      if((A[i] & (1LL << b)) != 0)
	c0++;      
      else
	c1++;
    }

    //cout << b << " " << c0 << " " << c1 << " " << ans << endl;

    i64 bm = (1LL << b) % NUM;
    ans += bm * ((c0 * c1) % NUM);
    ans %= NUM;
  }
  cout << ans << endl;

  return 0;
}


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

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

  int odd = 1;
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    if (tmp % 2 == 0) {
      odd *= 2;
    }
  }

  int comb = 1;
  for (int i = 0; i < N; ++i) {
    comb *= 3;
  }

  cout << comb - odd << endl;
}


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

#define FOR(a,b,c) for (int a=(b);a<(c);++a)
#define REP(i,n) FOR(i,0,n)
#define ll long long
#define pii pair<int,int>
#define x first
#define y second
#define pb push_back
#define lf double

using namespace std;

const int MAX = (int)1e6 + 5;

int main(){
	int n;
	scanf ("%d",&n);
	printf ("%.6lf\n",2*n*3.141592653);
	
	
	return 0;
}


Measured memory_bytes: 3844
DIV=10**9+7
N=int(input())
ST=[input(), input()]
PST=[]
ptr=0
while ptr < N:
    # 1枚のとき
    if ST[0][ptr] == ST[1][ptr]:
        ptr += 1
        PST.append(0)
    # 2枚のとき
    else:
        ptr += 2
        PST.append(1)

# print(PST)

res = 3 if PST[0] == 0 else 6
for i in range(len(PST)-1):
    if PST[i] == 0 and PST[i+1] == 0:
        res = (res*2)%DIV
    elif PST[i] == 0 and PST[i+1] == 1:
        res = (res*2)%DIV
    elif PST[i] == 1 and PST[i+1] == 0:
        res = res
    elif PST[i] == 1 and PST[i+1] == 1:
        res = (res*3)%DIV

print(res)


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <algorithm>
#define MOD 1000000007

using ii = std::pair<int, int>;

long long int table[41][1 << 18];

int x, y, z;

std::vector<int> decode(int p)
{
	std::vector<int>  arr;
	int k = -1;

	for (int i = 0; i <= 17; i++)
	{
		if ((p & (1 << i)) != 0)
		{
			arr.push_back(i - k);
			k = i;
		}
	}

	return arr;
}

int encode(const std::vector<int>& p)
{
	int enc = 0;
	int sum = 0;

	for (int i = p.size() - 1; i >= 0; i--)
	{
		sum += p[i];

		if (sum > 17)
			break;

		enc = enc << p[i];
		enc += (1 << (p[i] - 1));
	}

	return enc;
}

bool check(const std::vector<int>& p)
{
	int zsum = 0;
	int idx = p.size() - 1;

	while (zsum < z && idx >= 0)
	{
		zsum += p[idx];
		idx--;
	}

	if (zsum != z)
		return true;

	int ysum = 0;

	while (ysum < y && idx >= 0)
	{
		ysum += p[idx];
		idx--;
	}

	if (ysum != y)
		return true;

	int xsum = 0;

	while (xsum < x && idx >= 0)
	{
		xsum += p[idx];
		idx--;
	}

	if (xsum != x)
		return true;

	return false;
}

long long int solve(int length, int prev)
{
	if (table[length][prev] != -1)
		return table[length][prev];

	long long int& res = table[length][prev];

	res = 0;

	auto arr = decode(prev);

	//x,y,z가 등장해버린 경우
	if (!check(arr))
	{
		return res;
	}

	if (length == 0)
		return res = 1;

	for (int i = 1; i <= 10; i++)
	{
		arr.push_back(i);
		res = (res + solve(length - 1, encode(arr))) % MOD;
		arr.pop_back();
	}

	return res;
}

int main()
{
	memset(table, -1, sizeof(table));

	int n;
	scanf("%d %d %d %d", &n, &x, &y, &z);

	long long int p = 1;

	for (int i = 0; i < n; i++)
	{
		p = (p * 10) % MOD;
	}

	long long int v = solve(n, 0);

	p -= v;

	if (p < 0) p += MOD;

	printf("%lld", p);

	return 0;
}

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

using namespace std;

int n, m;
int f[1 << 21];
int p[1 << 21];
bool e[21][1 << 21];
bool vis[1 << 21];
string s[21];

int calc(int x, int y) {
	int tmp = x & ((1 << y) - 1);
	x >>= (y + 1), x <<= y, x += tmp;
	return x;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 0; i <= n; ++i) {
		cin >> s[i];
		for (int j = 0; j < (1 << i); ++j) {
			if (s[i][j] == '1') {
				f[j + (1 << i)] = 1;
				// for (int k = 0; k < i; ++k) cout << (j >> k & 1); cout << '\n';
			}
		}
	}
	int lim = (1 << (n + 1)) - 1;
	for (int i = 1; i <= lim; ++i) {
		for (int j = 0; j <= n; ++j) {
			if (i >> j & 1) p[i] = j;
		}
		for (int j = 0; j < p[i]; ++j) {
			int k = calc(i, j);
			e[j][i] = !vis[k], vis[k] = 1;
		}
		for (int j = 0; j < p[i]; ++j) {
			int k = calc(i, j);
			vis[k] = 0;			
		}
	}
	for (int i = 0; i <= n; ++i) {
		for (int j = lim; j >= 1; --j) {
			if (!e[i][j]) continue;
			int k = calc(j, i);
			f[k] += f[j];
		}
	}
	int res = 0;
	for (int i = 1; i <= lim; ++i) {
		if (f[i] >= m) {
			if (!res || p[i] > p[res]) res = i;
		}
	}
	int p = 0;
	for (int i = 0; i <= n; ++i) {
		if (res >> i & 1) p = i;
	}
	for (int i = p - 1; i >= 0; --i) {
		cout << (res >> i & 1);
	}
}

Measured memory_bytes: 63040
#include <stdio.h>
#include <string>
#include <map>
int main(void) {
  char type[3];
  int _tmp;
  std::map<std::string, int> m;

  m["A"] = 0;
  m["B"] = 0;
  m["0"] = 0;
  m["AB"] = 0;

  while(scanf("%d,%s", &_tmp, type) != EOF) {
    m[type] += 1;
  }

  printf("%d\n%d\n%d\n%d\n", m["A"], m["B"], m["AB"], m["O"]);
  return 0;
}

Measured memory_bytes: 1072
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    string s;
    int i,j;
    getline(cin,s);
    for(i=0;i<=s.length()-2;i++)
    {
        if(s[i]=='C')
        {
            for(j=i+1;j<=s.length()-1;j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes";
                    return 0;
                }
            }
            cout<<"No";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 1;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans %= mod;
        ans *= power(i + 1, mod - 2);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll n,q;
    cin >> n >> q;
    vector<queue<ll>> e(n);
    vector<ll> v(n,0);
    vector<bool> c(n,false);
    c[0] = true;
    rep0(i, n - 1){
        ll a,b;
        cin >> a >> b;
        e[a - 1].push(b - 1);
        e[b - 1].push(a - 1);
    }
    rep0(i, q){
        ll p,x;
        cin >> p >> x;
        v[p - 1] += x;
    }
    queue<ll> to;
    to.push(0);
    while (!to.empty()) {
        ll from = to.front();
        to.pop();
        while (!e[from].empty()) {
            if(c[e[from].front()]){
                e[from].pop();
                continue;
            }
            v[e[from].front()] += v[from];
            to.push(e[from].front());
            c[e[from].front()] = true;
            e[from].pop();
        }
    }
    rep0(i, n)pf(v[i]);
    return 0;
}


Measured memory_bytes: 139904
'use strict'
function main(inp) {
  inp = inp.trim().split('');
  let ans = "Yes";
  if(inp[0]== inp[1] && inp[0] == inp[2]){
  	ans = "No"
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
//Shiritori

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
const int inf = 2147483647;

int main (){
    int n;cin>>n;
    vector<string> s(n);
    map<string,int>st;
    rep(i,0,n){
        cin>>s[i];
        st[s[i]]++;
        if(st[s[i]]>1){cout<<"No"<<endl;return 0;}
    }
    bool flag = true;
    rep(i,0,n-1){
        if(s[i][s[i].size()-1]!=s[i+1][0])flag=false;
    }
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    d = int(input())
    c = [0] + list(map(int,input().split()))
    last = [0] * 27
    s = [0]
    for i in range(d):
        s.append([0] + list(map(int,input().split())))
    total = 0
    for j in range(1,d+1):
        t = int(input())
        last[t] = j
        total += s[j][t]
        for k in range(1,27):
            total -= c[k] * (j - last[k])
        print(total)






if __name__ == '__main__':
    main()


Measured memory_bytes: 70020
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  if((c - a - b) > 0 && 4*a*b < (c - a - b)*(c - a - b)){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
/*
  AOJ 2800
  Title:Mod!Mod!
  @kankichi573
*/
#include <stdio.h>
#define myabs(a,b)  ((a)>(b))?((a)-(b)):((b)-(a))

main()
{
  int N,i,uma,ret,count[3],diff;
  
  count[0]=count[1]=count[2]=0;
  scanf("%d",&N);
  for(i=0;i<N;i++)
    { scanf("%d",&uma);
      count[uma % 3]++;
    }

  if(count[1]==0 && count[2]==0)
    ret=1;
  else 
    {
      diff=myabs(count[1],count[2]);
      if(diff<4)
	ret = N;
      else
	ret = N - (diff-3);
    }
  printf("%d\n",ret);
  
  return(0);
}

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

int main(){
  int n, m;
  int votes[1000], sum_votes=0, favorite_count=0;
  double judge=0;
  int i;
    
  cin >> n >> m;
  
  for(i=0; i<n; i++){
    cin >> votes[i];
    sum_votes += votes[i];
  }
  judge = (double)sum_votes / (4*m);

  for(i=0; i<n; i++){
    if(votes[i] >= judge){
      favorite_count++;
    }
  }
  
  if(favorite_count >= m){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256