akhauriyash/Code-Regression huggingface dataset:
x=input()
length=len(x)
x=x+"E"
ch=x[0]
lists=[]
counter=1
for i in range(length):
    if x[i]==x[i+1]:
        counter+=1
    elif x[i]!=x[i+1] :
        lists.append(counter)
        counter=1
uselist=[]
if x[0]=="S" and x[-2]=="S":
    lists.append(0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))

elif x[0]=="S" and x[-2]=="T":
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))
   
elif x[0]=="T" and x[-2]=="S":
    lists.insert(0,0)
    lists.append(0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))

elif x[0]=="T" and x[-2]=="T":
    lists.insert(0,0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))
        
num=len(uselist)
uselist.append((0,0))
a=0
b=0
count=0
for i in range(num):
    a+=uselist[i][0]
    b+=uselist[i][1]
    if a<=b:
        count+=b-a
        a=0
        b=0
    if i==num-1 and a>b:
        count+=a-b
print(count)

Measured memory_bytes: 7912
#include <bits/stdc++.h>
using namespace std;
//最大公約数を求めるプログラム
int answer(int a, int b, int c) {
  int A,x;
  x = 1;
  A = min(a,min(b,c));
  for (int i = 1; i < A + 1; i++) {
    if (a % i == 0 && b % i == 0 && c % i == 0) {
      x = i;
    }
  }
  return x;
}

int main() {
  int K, y;
  y = 0;
  cin >> K;
  for (int i = 1; i < K + 1; i++) {
    for (int j = 1; j < K + 1; j++) {
      for (int l = 1; l< K + 1; l++){
        y += answer(i, j, l);
      }
    }
  }
  cout << y << endl;
}

        
    
    


Measured memory_bytes: 3644
//#include <cmath>
//#include <cstdio>
//#include <vector>
//#include <map>
//#include <iostream>
//#include <algorithm>
//#include <set>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pli = pair<ll,int>; 		
#define fi first
#define v vector
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define forn(i,n) for(int i = 0; i < n; ++i)
int INF = 1e9+7;
ll inf = 1e18+7;
int MOD = 1e9+7;

void add_self(auto &a, auto b){
	a += b;
	if(a >= MOD){
		a -= MOD;
	}
}

void sub_self(auto &a, auto b){
	a -= b;
	if(a < 0)	a += MOD;
}

void max_self(auto &a, auto b){
	if(b > a)	a = b;
}

void min_self(auto &a, auto b){
	if(b < a)	a = b;
}

void topsort(int i, v<vi>& graph, vb& visit, stack<int>& res){
	visit[i] = true;
	
	for(int x : graph[i]){
		if(!visit[x])
		topsort(x,graph,visit,res);
	}
	res.push(i);
}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

int match(int i, int n, int mask, v<vb>& mat, v<vi>& m){
	if(m[i][mask] != -1){
		return m[i][mask];
	}
	if(i >= n)	{
		for(int i1 = 0; i1 < n; ++i1){
			if( (mask >> i1) & 1){
				continue;
			}
			else{
				return 0;
			}
		}
		return 1;
	}
	
	int ans = 0;
	for(int w = 0; w < n; ++w){
		if(mat[i][w] && ( (mask>>w) & 1) == 0) {
			int temp= 1 << w;
			add_self(ans, match(i+1,n,(mask|temp),mat,m)); 
		}
	}
	m[i][mask] = ans;
	return ans;
}

void solve(){
	int n;
	scanf("%d",&n);
	int MAXX = pow(2,n)+2;
	v<vb> mat(n,vb(n,0));
	v<vi> m(n+1, vi(MAXX,-1));
	forn(i,n){
		forn(j,n){
			int temp;
			scanf("%d",&temp);
			mat[i][j] = temp;
		}
	}
	
	//unordered_map<pii,int,hash_pair> m;
	
	printf("%d\n", match(0,n,0,mat,m));
}	



int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	//scanf("%d",&t);
	while(t--){
		solve();
	}
		
			
}


Measured memory_bytes: 192240
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600

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

  if(n==1){cout<<1<<endl; return 0;}

  int s=0;
  int i=1;
  while(s<n){
    s+=i;
    i++;
  }

  int red = s-n;
  repl(j,1,i)if(j!=red) printf("%d\n", j);

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;

int main() {
    lli n, l;
    cin >> n >> l;
    lli tf = 0, of = LONG_MAX, f = 0;
    for(int i = 0 ; i < n; i++){
        tf += l + i;
        // cout << l + i << "\n";
        if(of > abs(l+i)){
            f = l+i;
            of = abs(l+i);
        }
    }
    cout << tf - f;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;
typedef long double ld;

const ll MOD = 1000000007;
vector<int> G[201010];
int depth[201010];
ll p2[201010];
deque<vector<ll>> dp[201010];

void dfs(int n, int d) {
    depth[d] += 1;
    dp[n].resize(0);
    
    for (auto m: G[n]) {
        dfs(m, d+1);
        if (dp[n].size() < dp[m].size())
            swap(dp[n], dp[m]);
    }

    int maxd = 0;
    for (auto m: G[n]) {
        maxd = max(maxd, (int)dp[m].size());
        REP(i, (int)dp[m].size()) {
            ll v[3] = {};
            REP(a, 3) REP(b, 3)
                (v[min(2, a+b)] += dp[n][i][a] * dp[m][i][b] % MOD) %= MOD;
            dp[n][i][0] = v[0];
            dp[n][i][1] = v[1];
            dp[n][i][2] = v[2];
        }
    }

    REP(i, maxd) {
        dp[n][i][0] += dp[n][i][2];
        dp[n][i][0] %= MOD;
        dp[n][i][2] = 0;
    }
    
    dp[n].push_front({1, 1, 0});
}

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

    int N; cin >> N; N += 1;
    REP2(i, 1, N) {
        int p; cin >> p;
        G[p].push_back(i);
    }

    p2[0] = 1;
    REP(i, N+1) p2[i+1] = p2[i] * 2 % MOD;

    dfs(0, 0);
    ll ans = 0;

    REP(i, (int)dp[0].size()) {
        ans += dp[0][i][1] * p2[N - depth[i]] % MOD;
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 246264
n = gets.to_i
pp = gets.split.map(&:to_i)

hoge = []
min = Float::INFINITY
pp.each do |num|
  min = [min, num].min
  hoge << min
end
res = 0
n.times do |i|
  if hoge[i] >= pp[i]
    res += 1
  end
end

p res

Measured memory_bytes: 20868
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <cstdlib> 
#include <math.h>
#define gap cout<<endl;
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define INF 1<<30
#define present(c,x) ((c).find(x) != (c).end())

int main(){

	int n,k;
	cin>>n>>k;
	double arr[n];
	fo(i,n) cin>>arr[i];
	fo(i,n) arr[i]=(arr[i]+(double)1)/2;
	double maax=0;
	int init=0;
	int end=0+k-1;
	FOR(i,init,end){
		maax+=arr[i];
	}
	double tmp=maax;

	while(end<n){

		if(end+1<n){
		tmp=tmp-arr[init];
		tmp=tmp+arr[end+1];}

		maax=max(tmp,maax);
		init++;
		end++;



	}
	cout<<setprecision(10)<<fixed;
	cout<<maax<<endl;


}

Measured memory_bytes: 1792
def main():
    X, Y = map(int, input().split())

    print(gcd(X, Y))

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

main()

Measured memory_bytes: 7672
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    cout << 800*N - 200*(N/15) << '\n';
}


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


/*                        [Template]                        */
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define let auto
#define of :
#define all(y) y.begin(), y.end()
#define present( x, y ) x.find( y ) != x.end()
#define _matrix(T) vector<vector<T>>
template<class T>
auto matrix( int r, int c, T v ){
	return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
/************************************************************/

auto diff( int &a, int &b, int &c ){
	return ( a != b && b != c && c != a ) ;
}

signed main() {
	int N ; cin >> N ;
	vector<int> L(N) ;
	for( let &l of L ) cin >> l ;
	int cnt = 0 ;
	for( int i = 0 ; i < N ; i++ ){
		for( int j = i + 1 ; j < N ; j++ ){
			for( int k = j + 1 ; k < N ; k++ ){
				if( diff( L[i], L[j], L[k] ) ){
					if( L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i]  ){
						cnt++ ;
					}
				}
			}
		}
	}
	cout << cnt << endl ;
    return 0; 
} 

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
#define PI 3.14159265359
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////


int main() {
	ll H; cin >> H;
	ll ans = 0;
	int key = 0;
	ll h = H;
	while (h != 0) {
		key++;
		h /= 2;
	}
	REP(i, key) {
		ans += pow(2, i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#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 pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n;
vpii v;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    int b;
    cin >> b;
    v.pb(mp(b, i%2));
  }
  sort(rng(v));
  int ans = 0;
  FOR(i, 0, sz(v)) if(v[i].se != i%2) ans++;
  cout << ans/2 << endl;
  return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;


struct StronglyConnectedComponents {
    int N;
    vector<vector<int>> G,rG;
    vector<int> group,order;

    StronglyConnectedComponents(int _N): N(_N) {
        G.resize(N); rG.resize(N); group.assign(N,1);
    }
    
    void add_edge(int a,int b) {
        G[a].push_back(b);
        rG[b].push_back(a);
    }

    void dfs(int v) {
        group[v] = -1;
        for (int e: G[v]) {
            if (group[e] > 0) dfs(e);
        }
        order.push_back(v);
    }

    void rdfs(int v,int cnt) {
        group[v] = cnt;
        for (int e: rG[v]) {
            if (group[e] < 0) rdfs(e,cnt);
        }
    }

    void build() {
        for (int i = 0;i < N;i ++) {
            if (group[i] > 0) dfs(i);
        }
        reverse(begin(order),end(order));
        int cnt = 0;
        for (int v: order) {
            if (group[v] < 0) rdfs(v,cnt),cnt++;
        }
    }

    int operator[](int i) {
        return group[i];
    }
};

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

    int N; ll D; cin >> N >> D;
    vector<ll> X(N),Y(N);
    rep(i,N) cin >> X[i] >> Y[i];

    StronglyConnectedComponents scc(2*N);
    rep(i,N) {
        for (int j = i + 1;j < N;++j) {
            if (abs(X[i] - X[j]) < D) {
                scc.add_edge(i,j + N);
                scc.add_edge(j,i + N);
            }
            if (abs(X[i] - Y[j]) < D) {
                scc.add_edge(i,j);
                scc.add_edge(j + N,i + N);
            }
            if (abs(Y[i] - X[j]) < D) {
                scc.add_edge(i + N,j + N);
                scc.add_edge(j,i);
            }
            if (abs(Y[i] - Y[j]) < D) {
                scc.add_edge(i + N,j);
                scc.add_edge(j + N,i);
            }
        }
    }
    scc.build();
    vector<int> ans(N);
    rep(i,N) {
        if (scc[i] == scc[i + N]) {
            cout << "No" << '\n';
            return 0;
        }
        if (scc[i] < scc[i + N]) ans[i] = Y[i];
        else ans[i] = X[i];
    }
    cout << "Yes" << '\n';
    rep(i,N) cout << ans[i] << '\n';
    return 0;
}

Measured memory_bytes: 3856
s_1 = input()
s_2 = input()

dp = [[0 for _ in range(len(s_2)+1)] for _ in range(len(s_1)+1)]

for i in range(len(s_2)+1):
	dp[0][i] = i
for i in range(len(s_1)+1):
	dp[i][0] = i

for i in range(1,len(s_1)+1):
	for j in range(1,len(s_2)+1):
		if s_1[i-1] == s_2[j-1]:
			dp[i][j] = min(dp[i-1][j]+1, dp[i][j-1]+1, dp[i-1][j-1])
		else:
			dp[i][j] = min(dp[i-1][j]+1, dp[i][j-1]+1, dp[i-1][j-1]+1)

print(dp[len(s_1)][len(s_2)])


Measured memory_bytes: 43476
def ceil(x, y):
    if x % y == 0:
        return x//y
    else:
        return (x//y)+1

def solve(n, xs):

   # 5
   #   3 2 4 3 5
   # [5,0,0,0,0,0]

   # [2,3,0,0,0,0]

   # [0,3,2,0,0,0]
   # [0,1,2,2,0,0]
   # [0,0,1,2,2,0]
   # [0,0,0,1,2,2]

   # [0,0,0,0,1,4]
   # [0,0,0,0,0,5]
    min_lim_cost = 10**15+1
    min_lim_pos = -1
    for i in range(5):
        if xs[i] < min_lim_cost:
            min_lim_pos = i
            min_lim_cost = xs[i]

    init_cost = min_lim_pos
    init_reach =  5 - min_lim_pos
    final_reach = ceil((n-min_lim_cost),min_lim_cost)

#    print(min_lim_cost,
#          min_lim_pos,
#          init_cost,
#          init_reach,
#          final_reach)
    return init_cost+init_reach+final_reach


if __name__ == '__main__':
    n = int(input())
    xs= []
    for _ in range(5):
        xs.append(int(input()))
    print(solve(n, xs))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
typedef pair<ll,ll> P;
const ll MO = 1000000007;


int main(){
    ll n;
    cin >> n;
    if(n<=6){
        cout << 1 << endl;
        return 0;
    }else{
        ll a,b;
        a = ceil((double)n/11.0);
        b = a-1;
        if(a*6+b*5>=n){
            cout << a+b << endl;
            return 0;
        }else{
            cout << a + b+ 1 << endl;
            return 0;
        }
        // b = ceil((double)(n-6*a)/5.0);
        // cout << a << " b" << b << endl;
        // cout << a+b<<endl;
        // return 0;
    }
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
int main()
{
    int n;
    string s,t;
    cin>>n;
    int i,j;
    cin>>s>>t;
    int br=n;
    for(i=0;i<n;i++)
    {
        int l=1;
        for(j=0;j+i<n;j++)
        {
            if(t[j]!=s[j+i]) l=0;
        }
        if(l)
        {
            cout<<n+i<<endl;
            return 0;
        }
    }
    cout<<2*n<<endl;
    return 0;
}

Measured memory_bytes: 384
N=int(input())
F=[list(map(int,input().split())) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]

lst=set()
for i in range(2**10):
    a=(10-len(bin(i)[2:]))*"0"+bin(i)[2:]
    if "1" in a:
        num=0
        for n in range(N):
            count=0
            for m in range(10):
                if F[n][m]==1 and a[m]=="1":
                    count+=1
            num+=P[n][count]
        lst.add(num)


print(max(lst))


Measured memory_bytes: 42348
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;int k,s;cin>>k>>s;
	int ans = 0;
	rep(i, k+1){
		rep(j, k+1){
			if(0 <= s-i-j&&s-i-j <= k )ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//n角形のnの取得
		int n = scan.nextInt();
        int ans = (n-2) * 180;
        	System.out.println(ans);
    		scan.close();
	}
	
}


Measured memory_bytes: 21716
def dice(dice_num,direction):
	for s in direction:
		tmp = dice_num
		if s == "S":
			dice_num = [tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]	
		elif s == "E":
			dice_num = [tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
		elif s == "N":
			dice_num = [tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]
		elif s == "W":
			dice_num = [tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
	return(dice_num[0])

if __name__ == '__main__':
	dice_num = [int(s) for s in input().split()]
	direction = input()

	print(dice(dice_num,direction))


Measured memory_bytes: 5604
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long ll;
const int MAXN = 100010;
const int MAXM = 50;
int _w;

int n, f[MAXN][MAXM];

void dfs( int x, int s ) {
	if( f[x][s] ) return;
	f[x][s] = 1;
	for( int i = 0; i < 10; ++i )
		if( s+i < MAXM )
			dfs((x*10+i)%n, s+i);
}

int main() {
	_w = scanf( "%d", &n );
	for( int i = 1; i < 10; ++i )
		dfs(i % n, i);
	for( int i = 0; i < MAXM; ++i )
		if( f[0][i] ) {
			printf( "%d\n", i );
			break;
		}
	return 0;
}


Measured memory_bytes: 129024
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
unsigned int N;

int recursion(vector<int> &v, unsigned int before, unsigned int sup)
{
    if (sup >= before)
    {
        v.push_back(before * 10 + 3);
        recursion(v, before * 10 + 3, sup);
        v.push_back(before * 10 + 5);
        recursion(v, before * 10 + 5, sup);
        v.push_back(before * 10 + 7);
        recursion(v, before * 10 + 7, sup);
        return 0;
    }
    else
    {
        v.pop_back();
        return 0;
    }
}

int main(int argc, char const *argv[])
{
    cin >> N;
    vector<int> v;
    int ans = 0;
    recursion(v, 0, N);
    sort(v.begin(),v.end());
    for (size_t i = 0; i < v.size(); i++)
    {
        bool three = false;
        bool five = false;
        bool seven = false;
        string s = to_string(v[i]);
        for (size_t j = 0; j < s.size(); j++)
        {
            if (s[j] == '3')
            {
                three = true;
            }
            else if (s[j] == '5')
            {
                five = true;
            }
            else
            {
                seven = true;
            }
        }
        if (three && five && seven)
            {
                ans++;
            }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int N = 0, A = 0;
  cin >> N >> A;
  N %= 500;
  if (N <= A)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int K;
  scanf("%d", &K);
  vector<int> dist(K, INF);
  dist[1] = 1;
  priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
  que.push(make_pair(1, 1));
  while (not que.empty()) {
    pair<int, int> p = que.top(); que.pop();
    int u = p.second;
    int x = (u + 1) % K, y = (10 * u) % K;
    if (dist[u] + 1 < dist[x]) {
      dist[x] = dist[u] + 1;
      que.push(make_pair(dist[x], x));
    }
    if (dist[u] < dist[y]) {
      dist[y] = dist[u];
      que.push(make_pair(dist[y], y));
    }
  }

  int ans = dist[0];
  printf("%d\n", ans);
  return 0;
}


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

int main()
{
    string s;
    while(1)
    {
        int data=0;
        cin >> s;
        for(int i=0; i<s.size(); ++i){
            data += s[i] - '0';
        }
        if(!data) break;
        cout << data << endl;
    }
}



Measured memory_bytes: 3140
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'
using ll = long long;
#define int ll
using db = long double;
using ii = pair<int, int>;

const int N = 1e5 + 5, LG = 19, MOD = 1e9+7;
const int SQ =320;
const long double EPS = 1e-7;
vector<int> adj[200005];
pair<int,int> dfs(int node, int par){

  auto ret = ii(1,node);

  for(auto x : adj[node]){

    if(x != par){

      auto y = dfs(x,node);
      y.F++;
      ret=max(ret,y);

    }

  }

  return ret;
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  int n;
  cin >> n;

  f(i,1,n){

    int u, v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);

  }

  int diameter = dfs(dfs(1,1).S,-1).F;
  
   if(diameter % 3 != 2)
    cout << "First\n";
  else
    cout << "Second\n";


  return 0;
}


Measured memory_bytes: 22656
#include <iostream>
#include <set>
#include <string>
#include <queue>
using namespace std;


class Worm {
public:
	string str;
	int turn;
	Worm(string st, int t) : str(st), turn(t) {}
};

Worm nWorm(Worm w, int p) {
	if (w.str[p] > w.str[p+1]) {
		char t=w.str[p];
		w.str[p] = w.str[p+1];
		w.str[p+1] = t;
	}

	if (w.str[p]=='b' && w.str[p+1]=='g') w.str[p] = w.str[p+1] = 'r';
	else if (w.str[p]=='b' && w.str[p+1]=='r') w.str[p] = w.str[p+1] = 'g'; 
	else if (w.str[p]=='g' && w.str[p+1]=='r') w.str[p] = w.str[p+1] = 'b';

	w.turn++;
	return w;
}

int main() {
	string str;
	while (cin >> str, str[0]!='0') {
		queue<Worm> q;
		Worm init(str, 0);
		q.push(init);
		bool f=false, fl;
		set<string> s;
		s.insert(str);

		while (!q.empty()) {
			Worm tmp = q.front(); q.pop();
			for (int i=0; i<tmp.str.size()-1; i++) {
				Worm next = nWorm(tmp, i);
				if (s.insert(next.str).second) q.push(next);
			}

			fl = true;
			char c = tmp.str[0];
			for (int i=1; i<tmp.str.size(); i++)
				if (tmp.str[i] != c) { fl=false; break; }

			if (fl) { cout << tmp.turn << endl; f=true; break; }
		}

		if (!f) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c;cin>>a>>b>>c;
  if(a%2==0 || b%2==0 || c%2==0)cout<<0;
  else{
  	long long maxi = 0;
    maxi = a*b;
    maxi = min(maxi,b*c);
    maxi = min(maxi,c*a);
    cout<<maxi;
  }
}

Measured memory_bytes: 3532
#include<stdio.h>
#include<math.h>

int main(){

  long long n;
  scanf("%lld",&n);

  long long a[n];

  for(long long i=0;i<n;i++){
    scanf("%lld",&a[i]);
  }

  long long b[9];

  for(int i=0;i<9;i++){
    b[i]=0;
  }

  long long ans=0;

  for(long long i=0;i<n;i++){
    if(a[i]<400){
      b[0]++;
    }
    else if(a[i]<800){
      b[1]++;
    }
    else if(a[i]<1200){
      b[2]++;
    }
    else if(a[i]<1600){
      b[3]++;
    }
    else if(a[i]<2000){
      b[4]++;
    }
    else if(a[i]<2400){
      b[5]++;
    }
    else if(a[i]<2800){
      b[6]++;
    }
    else if(a[i]<3200){
      b[7]++;
    }
    else{
      b[8]++;
    }
  }

  long long re=0;
  

  for(int i=0;i<8;i++){
    if(b[i]>0){
      re++;
    }
  }

  if(re==0){
    printf("1 %lld\n",b[8]);
  }
  else{
    printf("%lld %lld\n",re,re+b[8]);
  }



  return 0;
}


Measured memory_bytes: 128
n = int(input())
a = list(map(int,input().split()))
ruiseki_WA=[0]
for i in range(n):
    ruiseki_WA.append(ruiseki_WA[i]+a[i])
ans=float("inf")
for i in range(n):
    kari=abs(ruiseki_WA[i]-(ruiseki_WA[-1]-ruiseki_WA[i]))
    ans=min(ans,kari)
print(ans)

Measured memory_bytes: 26060
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

internal static class CR
{
    public static string Get() { return Console.ReadLine(); }
    public static IEnumerable<string> GetTexts() { return Console.ReadLine().Split(' '); }
    public static int GetInteger() { return int.Parse(Console.ReadLine()); }
    public static IEnumerable<int> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)); }
}

namespace B
{
    internal class Program
    {
        public static int N { get; private set; }
        public static string S { get; private set; }
        public static string T { get; private set; }

        private static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.WriteLine(r); }

        private static object GetResult()
        {
            N = CR.GetInteger();
            var texts = CR.GetTexts().ToList();
            S = texts[0];
            T = texts[1];

            var result = string.Empty;
            for (int i = 0; i < N; i++)
            {
                result += new string(new char[] { S[i], T[i] });
            }

            return result;
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;

int main() {
	string s;
	int n, h;
	for (;;) {
		cin >> s;
		if (s == "-") break;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> h;
			for (int j = 0; j < h; j++) {
				s.push_back(s[0]);
				s.erase(s.begin());
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
# -*- coding: utf-8 -*-
import numpy
import sys
from functools import lru_cache
sys.setrecursionlimit(10**6)

h,n=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
AB = [tuple(map(int, input().split())) for _ in range(n)]
#効率順にソート
AB.sort(key=lambda ab: (ab[1] / ab[0], ab[0]))

@lru_cache(maxsize=None)
def dp(h):
    if h <= 0:
        return 0
    else:
        best = float('inf')
        for a, b in AB:
            mp = b + dp(h -a)
            if mp < best:
                best = mp
            else:
                break
        return best

print(dp(h))

Measured memory_bytes: 38740
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;



int main() {
  int n;
  cin>> n;
  cout << n*(n+1)/2 << endl;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  int a[m];
  int sum=0;
  for (int i=0; i<m; i++){
    cin >> a[i];
    sum += a[i];
  }
  if (sum <= n){
    cout << n-sum << endl;
  }
  else{
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()
k = ii()

for i in range(n):
    if s[i] == s[k-1]:
        print(s[i],end="")
    else:
        print("*",end="")

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;



int main() {
    int a, b, c; cin >> a >> b >> c;
    cout << a + b + c + 9 * max({a, b, c}) << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int a[N];


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); 
    int n;
    cin>>n;
  	if(n%10==2 ||n%10==4||n%10==5||n%10==7||n%10==9)puts("hon");
  	else if(n%10==3)puts("bon");
  	else puts("pon");
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;

#define INF 1000000009LL
#define MOD 1000000007LL

bool dp[100005][2];
int H, W;

int main() {
  int N, K; cin >> N >> K;
  vector<int> a(N);
  
  int min_a = INF;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    min_a = min(min_a, a[i]);
  }
  dp[0][0] = false;
  dp[0][1] = true;
  
  for (int i = 1; i <= K; i++) {
    if (i < min_a) {
      dp[i][0] = false;
      dp[i][1] = true;
    } else {
      for (int j = 0; j < N; j++) {
        if (i >= a[j]) {
          dp[i][0] |= dp[i - a[j]][1];
        }
      }
      dp[i][1] = !dp[i][0];
    }
  }
  
  if (dp[K][0]) cout << "First" << endl;
  else cout << "Second" << endl;
  
  return 0;
}


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

using namespace std;

struct rest {
    string s;
    int score;
    int dx;
}a[110];
int n;

bool cmp(rest a , rest b){
        if(a.s == b.s)return a.score > b.score;
        return a.s < b.s;
}

main(){
    scanf("%d" , &n);

    for(int i = 0 ; i < n ; i ++){
            cin >> a[i].s;
            scanf("%d" , &a[i].score);
            a[i].dx = i + 1;
    }

    sort(a , a + n , cmp);
    for(int i = 0 ; i < n ; i ++){
        printf("%d\n" , a[i].dx);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;


llint a,b,c;

void solve(){
	cin >> a >> b >> c;
	if(a==b && b==c){
		if(a%2==0)cout << -1 << endl;
		else cout << 0 << endl;
	}
	else{
		llint ans=0;
		while(a%2==0 && b%2==0 && c%2==0){
			int tmp1=a,tmp2=b;
			a=b/2+c/2;
			b=tmp1/2+c/2;
			c=tmp1/2+tmp2/2;
			ans++;
		}
		cout << ans << endl;
	}
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

const int LIM = 7500000;

int M, N;

char checked[LIM];

bool solve() {
    cin >> M >> N;
    fill(checked, checked+LIM, 0);
    if (M == 0 && N == 0) { return false; }

    int m = M;
    for (int j = 0; j < N; ++j) {
        while (checked[m]) { ++m; }
        for (int k = m; k < LIM; k += m) {
            checked[k] = 1;
        }
    }
    while (checked[m]) { ++m; }
    cout << m << endl;
    return true;
}

int main() {
    while (solve());
    return 0;
}

Measured memory_bytes: 10304
import math as m
a,b,c=map(int,input().split())
sinc=m.sin(m.radians(c))
cosc=m.cos(m.radians(c))
h=b*sinc
d=(h**2+(a-b*cosc)**2)**(1/2)
print('{:.10f}'.format((1/2)*a*b*sinc))
print('{:.10f}'.format(b+a+d))
print('{:.10f}'.format(h))


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

typedef long long ll;
const ll INF = 1e9;
const ll INFF = 1e18;
const ll MOD = 1e9 + 7;
const ll MAXN = 1e3;
const double EPS = 1e-9;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int m1,d1,m2,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    cout << (m2 != m1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const int MAX = 6666666;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

ll g(int x,int y){
    return COM(x+y+2,x+1) - 1;
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    COMinit();
    int r1,c1,r2,c2;
    cin >> r1 >> c1 >> r2 >> c2;
    r1--;c1--;
    ll ans = g(c2,r2);
    ans -= g(c2,r1);
    ans -= g(c1,r2);
    ans += g(c1,r1);
    cout << (ans+2*mod)%mod << endl;
}

Measured memory_bytes: 156544
#include <iostream>
#include <string>
#include <queue>
#include <vector>
using namespace std;
 
int main() {
    string name;
    int i,n,q,time,elapsedt = 0;
    queue<pair<string,int> > que;
    vector<pair<string,int> > ans;
    pair<string,int> tmp;
    cin>>n>>q;
    for(i=0;i<n;i++) {
        cin>>name>>time;
        que.push(make_pair(name,time));
    }
    while(que.size()>0){
        tmp = que.front();
        que.pop();
        if(tmp.second <= q) {
            elapsedt += tmp.second;
            ans.push_back(make_pair(tmp.first,elapsedt));
        } else {
            elapsedt += q;
            que.push(make_pair(tmp.first,tmp.second - q));
        }
    }
    for(i=0;i<n;i++) {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
    return 0;
}



Measured memory_bytes: 7076
# coding: utf-8
import numpy as np
from functools import lru_cache
import time
import math

def main(): 
    if True:
        N = int(input())
        #H,W = list(map(int, input().split()))
        #A = np.asarray([str(input()) for i in range(H)])
    else:
        pass

    sN = int(math.sqrt(N))
    r = np.asarray([],dtype=int)
    count = 0
    for i in range(sN+1):
        #print(i)
        if N % (i+1) == 0 :
            r = np.append(r,i+1)
            if i+1 != N//(i+1):
                r = np.append(r,N//(i+1))
    r = np.sort(r)

    for i in range(r.size)[1:]:
        if N//(r[i]-1) == N%(r[i]-1):
            count += r[i]-1
        else:
            pass
            #print(r[i])

    print(int(count))#,r)
if __name__ =='__main__':
    main()

Measured memory_bytes: 21776
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string t, s;
	cin >> t >> s;
	string a = t, b = s;
	reverse(all(t));
	reverse(all(s));
	puts(a == s && b == t ? "YES" : "NO");
	return 0;
}

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

int main(void){
    int i,j,k;
    int N,A[200];
    double answer = 0;
    
    scanf("%d",&N);
    for(i = 0;i < N - 1;i++){
        scanf("%d\n",&A[i]);
    }
    scanf("%d",&A[i]);
    
    for(i = 0;i < N;i++){
        answer += (1.0 / A[i]);
    }
    
    answer = 1.0 / answer;
    
    printf("%lf\n",answer);
   
    return 0;
}



Measured memory_bytes: 128
s = gets.chomp
a_idx = -1
z_idx = -1
s.size.times do |i|
	if s[i] == "A" && a_idx == -1
		a_idx = i
	end
	if s[i] == "Z"
		z_idx = i
	end
end

puts z_idx - a_idx + 1

Measured memory_bytes: 2172
n, c, k = map(int, input().split())
t = [int(input()) for i in range(n)]
t.sort()

result = 1
count = 0
f = 0

for i in range(n):
  if (t[i] - t[f]) > k or c == count:
    result += 1
    count = 1
    f = i
  else:
    count += 1
print(result)

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



int main(){
    ll N , K;
    cin >> N >> K;
    vector<ll> p(N,0);
    for(int i = 0; i < N; i++) cin >> p[i];
    sort(p.begin(),p.end());
    ll sum = 0;
    for(int i = 0; i < K; i++) sum += p[i];
    cout << sum << endl; 
}





Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	long double p = 0.0;

	for (int i=1; i<=n; i++){
		int tokuten = i;
		int counter = 0;
		while (tokuten < k)
		{
			tokuten *= 2;
			counter++;
		}
		p += (1.0 / n) * powl(0.5, counter);
	}
	cout << setprecision(12) << p << endl;
}

Measured memory_bytes: 256
/*************************************
 * problem:      ABC127 problem D.
 * user name:    hkxadpall.
 * time:         2019-05-25.
 * language:     C++.
 * upload place: AtCoder.
*************************************/ 

#include <bits/stdc++.h>
using namespace std;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}  

int n, m;
struct op {
    long long b, c;
    bool operator < (const op &o) const
    {
        return c > o.c;
    }
} a[200007];

int main()
{
    n = read<int>();
    m = read<int>();
    for (int i = 1; i <= n; i++) {
        a[i].b = 1;
        a[i].c = read<long long>();
    }
    for (int i = 1; i <= m; i++) {
        a[n + i].b = read<long long>();
        a[n + i].c = read<long long>();
    }
    sort(a + 1, a + n + m + 1);
    long long ans(0);
    int wt = n, pos = 0;
    while (wt) {
        pos++;
        if (a[pos].b >= wt) {
            ans += a[pos].c * wt;
            write(ans);
            return 0;
        }
        wt -= a[pos].b;
        ans += a[pos].c * a[pos].b;
    }
    write(ans);
    return 0;
}

Measured memory_bytes: 3328
nx=[]

while True:
    nx_value=list(map(int,input().split()))
    if nx_value[0]==0 and nx_value[1] == 0:
        break
    nx.append(nx_value)

n_list = [row[0] for row in nx]
x_list = [row[1] for row in nx]

for n,x in zip(n_list,x_list):
    count = 0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    count += 1
    print(count)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 510000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> A >> B >> C >> N;
  rep(i,0,3001)rep(j,0,3001){
    M=N-A*i-B*j;
    if(M<0)continue;
    else if(M%C==0)sum++;
  }
  Out(sum);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define INF 1e9;
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];

    rep(cx, 101) {
        rep(cy, 101) {
            int cnt = 0;
            int check = 0;
            int H;
            bool a = true;
            rep(i, n) {
                if (h[i] > 0) {
                    if (cnt == 0) {
                        if (check > 0) {
                            if (H > abs(cx-x[i]) + abs(cy-y[i]) + h[i]) break;
                        }
                        H = abs(cx-x[i]) + abs(cy-y[i]) + h[i];
                        cnt++;
                        continue;
                    }
                    int tmp = abs(cx-x[i]) + abs(cy-y[i]) + h[i];
                    if (H != tmp) {
                        a = false;
                        break;
                    }
                }
            }

            rep(i, n) {
                if (h[i] == 0) {
                    if (H > abs(cx-x[i])+abs(cy-y[i])+h[i]) {
                        a = false;
                        break;
                    }
                }
            }

            if (a) {
                cout << cx << " " << cy << " " << H << endl;
            }

        }
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
using namespace std;

int main(){
    ll r;
    cin >> r;

    cout << 2*r*PI << endl;    

    return 0;
}

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

int main() {
    long long N,M;
    long long ans=0;
    cin >>N>>M;
    if(N==1&&M==1){
        ans=1;
    }
    else if(M==1&&N>=2){
        ans=N-2;
    }
    else if(N==1&&M>=2){
        ans=M-2;
    }
    
    else if(N>=2&&M>=2){
        ans=(N-2)*(M-2); 
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if(a == b && b == c){
        PUTS("Yes");
    }
    else{
        PUTS("No");
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<numeric>
#include<math.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    ll x, y;
    cin >> x >> y;
    ll ans = 1e18;
    rep(d1, 2) rep(d2, 2) {
        ll res = d1 + d2;
        ll xx = x * (d1 ? -1 : 1);
        ll yy = y * (d2 ? -1 : 1);
        if ( xx <= yy ) {
            ans = min(ans, res + yy - xx );
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;
int main()
{
	ll n, k, left, right, cost, min_cost = 10000000000;
  	vector<ll> candle;
  	cin >> n >> k;
  	for (int i = 0; i < n; i++){
    	ll c; cin >> c;
      	candle.push_back(c);
    }
  	for (left = 0; left <= n - k; left++){
    	right = left + k - 1;
      	cost = min(abs(candle[right]), abs(candle[left])) + abs(candle[right] - candle[left]);
      	if (min_cost > cost){
        	min_cost = cost;
        }
    }
  	cout << min_cost;
}

Measured memory_bytes: 1400
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input()) -1

print(a[k])

Measured memory_bytes: 3060