akhauriyash/Code-Regression huggingface dataset:
#https://atcoder.jp/contests/keyence2019/tasks/keyence2019_d
#2019-01-13
import sys 
from collections import deque
P = 10**9 + 7
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort(reverse = 1)
B.sort(reverse = 1)
A = deque(A)
B = deque(B)

if A[0] != N*M or B[0] != N*M:
    print(0)
    sys.exit()
for i in range(N-1):
    if A[i] == A[i+1]: 
        print(0)
        sys.exit()
for i in range(M-1):
    if B[i] == B[i+1]:
        print(0)
        sys.exit()

ans = 1
used_tate = []
used_yoko = []
oita = 0

p = A.popleft()
q = B.popleft()
#大きい数字から順番に、おける場所が制限されている。
for number in range(N*M, 0, -1):
    if number == p and number == q:
        used_tate += [1]
        used_yoko += [1]
        oita += 1
        try:
            p = A.popleft()
        except:
            p = 0
        try:
            q = B.popleft()
        except:
            q = 0
    elif number == p and number != q:
        used_tate += [1]
        ans *= len(used_yoko)
        oita += 1
        try:
            p = A.popleft()
        except:
            p = 0
    elif number != p and number == q:
        used_yoko += [1]
        ans *= len(used_tate)
        oita += 1
        try:
            q = B.popleft()
        except:
            q = 0
    else:
        ans *= len(used_tate)*len(used_yoko) - oita
        oita += 1
    ans = ans%P
print(ans)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define mp make_pair
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
const int N=405;
int dp[N][N];
int a[N];
int pre[N]; 

int get_sum(int l,int r){
    if(l>r) return 0;
    return(pre[r]-pre[l-1]);
}

int find(int x,int y,int n){
    if(x>y) return(0);
    if(dp[x][y]!=1e18) return(dp[x][y]);
    if(y==x) return(dp[x][y]=0);
    for(int i=x;i<=y;i++){
        dp[x][y]=min(dp[x][y],find(x,i,n)+find(i+1,y,n)+get_sum(x+1,i+1)+get_sum(i+2,y+1));
    }
    return(dp[x][y]);
}

int32_t main(){
    IOS;
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    pre[0]=0;
    for(int i=0;i<n;i++){
        pre[i+1]=pre[i]+a[i];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            dp[i][j]=1e18;
        }
    }
    cout<<find(0,n-1,n);
}

Measured memory_bytes: 1536
#include<iostream>
#include<queue>
#include<functional>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
#pragma warning(disable:4996)
typedef long long ll;
priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>Q;
vector<pair<ll, ll>>X[1 << 18]; ll N, M, P1, P2, V, W, A, B, K[1 << 18], dist[1 << 18], J[1 << 18];
void dijkstra() {
	while (!Q.empty()) {
		ll G1 = Q.top().first, G2 = Q.top().second; Q.pop();
		for (int i = 0; i < X[G2].size(); i++) {
			if (dist[X[G2][i].first] > dist[G2] + X[G2][i].second) {
				dist[X[G2][i].first] = dist[G2] + X[G2][i].second;
				Q.push(make_pair(dist[X[G2][i].first], X[G2][i].first));
			}
		}
	}
}
int main() {
	cin >> N >> M >> V >> W >> P1 >> P2; fill(dist, dist + (1 << 18), 1LL << 62);
	for (int i = 0; i < V; i++) { scanf("%lld", &A); Q.push(make_pair(0, A)); dist[A] = 0; J[A] = 1; }
	for (int i = 0; i < M; i++) { scanf("%lld%lld", &A, &B); X[A].push_back(make_pair(B, 1)); X[B].push_back(make_pair(A, 1)); }
	dijkstra();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < X[i].size(); j++) {
			if (X[i][j].first == 1 || X[i][j].first == N)X[i][j].second = 0;
			else if (J[X[i][j].first] == 1)X[i][j].second = 1LL << 61;
			else if (dist[X[i][j].first] <= W)X[i][j].second = P2;
			else { X[i][j].second = P1; }
		}
	}
	fill(dist, dist + (1 << 18), 1LL << 62); dist[1] = 0; Q.push(make_pair(0, 1)); dijkstra();
	cout << dist[N] << endl;
	return 0;
}

Measured memory_bytes: 23016
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int N, M;
vector<int> A,id, ps;
typedef pair<pair<int, int>, int> tp;
vector<tp> P;

bool operator< (const tp& f, const tp& s) {
	return f.second < s.second;
}

bool pair_sort_s(const tp& f, const tp& s) {
	return f.second < s.second;
}
bool pair_sort_f_s(const tp& f, const tp& s) {
	return f.first.second < s.first.second;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> M;
	REP(i, N) {
		A.push_back(1);
	}
	REP(i, M) {
		int p, y;
		cin >> p >> y;
		id.push_back(0);
		ps.push_back(p);
		P.push_back(make_pair(make_pair(p, i), y));
	}
	sort ( P.begin(), P.end(), pair_sort_s);

	REP(i, M) {
		id[P[i].first.second] = A[P[i].first.first - 1]++;
	}

	REP(i, M) {
		printf("%06d%06d\n", ps[i], id[i]);
	}
	return 0;
}

Measured memory_bytes: 4464
//****** @author mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define endl "\n"
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fast_pow(ll x, ll y, ll p);


void solve() {
    char c;cin>>c;
    c++;
    cout<<c<<endl;
}

int main()
{
    IOS;
    ll test=1;
    //cin>>test;
    while(test--){
        solve();
    }
    return 0;
}
ll fast_pow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

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

def main():
    A = []
    for _ in range(5):
        A.append(int(input()))



    ans = 0
    mi = float("inf")

    for a in A:
        if a % 10 != 0:
            mi = min(mi, a % 10)
        ans += (-(-a // 10)) * 10

    if mi == float("inf"):
        print(ans)
        exit()
    print(ans - (10 - mi))



if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxN 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
const int infi=1e9+7;
int32_t main()
{
fastio;
int n;in n;int k;in k;
int arr[n+1];
rep(i,n) in arr[i];
vi dp(n,infi);
dp[0]=0;
for(int i=1;i<n;i++){
    for(int j=max(0ll,i-k);j<i;j++){
        dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
    }
}
out dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
num = int(input())
valuation = list(map(int,input().split()))
cost = list(map(int,input().split()))

div = []
ans = 0

for i in range(len(valuation)):
    div.append(valuation[i] - cost[i])

for j in div:
    if j > 0:
        ans += j

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
ll INF=1<<29;

int main(){
	ios::sync_with_stdio(false);
	ll N,K,ans=0,tmp=0;
	cin>>N>>K;
	vector<ll> A(N);
	vector<pair<ll,ll>> tab(41); //1 0
	for(int i=0;i<N;i++) cin>>A[i];
	for(int i=0;i<41;i++){
		for(int j=0;j<N;j++){
			if((1LL<<i) & A[j]) tab[i].first++;
			else tab[i].second++;
		}
	}
	for(ll i=40;i>=0;i--){
		if((1LL<<i)+tmp>K){
			ans+=tab[i].first*(1LL<<i);
		}else{
			ans+=max(tab[i].first,tab[i].second)*(1LL<<i);
			if(tab[i].second>tab[i].first) tmp+=(1LL<<i);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,A,B;
  cin>>N>>A>>B;
  int arr[N+1],countA=0,countB=0,countC=0;

  for(int i=0;i<N;i++){
    cin>>arr[i];
    if(arr[i]<=A){
        countA++;
    }
    else if(arr[i]>A && arr[i]<=B){
        countB++;
    }
    else if(arr[i]>B){
        countC++;
    }
  }
int contest=N/3;

int arr1[3];
  arr1[0]=countA;
  arr1[1]=countB;
  arr1[2]=countC;
  sort(arr1,arr1+3);
  if(contest> arr1[0]){
    cout<<arr1[0]<<endl;
  }
  else if(contest<arr1[0]){
    cout<<contest<<endl;
  }
  else{
    cout<<contest<<endl;
  }

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

typedef pair<ll,ll>ii; 
const int S=123456;

ll Solve(ll h,ll w)
{
    ll ans=INF;
    for(ll i=1;i<=h;i++)
    {
        ll j=(h-i)/2;
        ll k=(h-i)/2;
        if((h-i)%2)k++;
        ll mx=max({i*w,j*w,k*w});
        ll mn=min({i*w,j*w,k*w});
        ans=min(ans,mx-mn);

        j=w/2;
        k=w/2;
        if(w%2)k++;
        mx=max({i*w,j*(h-i),k*(h-i)});
        mn=min({i*w,j*(h-i),k*(h-i)});
        ans=min(ans,mx-mn);
    }    
    return ans;
}

int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    ll h,w;
    while(sf("%lld %lld",&h,&w)==2)
    {
        ll ans=Solve(h,w);
        ans=min(ans,Solve(w,h));
        pf("%lld\n",ans);
    }
    return 0;
}
 









 




























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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  
    int T=1;
    //cin >> T;
    while(T--){
        ll h,w, cx, cy, fx, fy,x,y;
        cin>>h>>w;
        cin>>cx>>cy;
        cin>>fx>>fy;
        cx--, cy--, fx--, fy--;

        vector<vi> vis(h, vi(w,0));
        vector<vi> dis(h, vi(w, mod));

        string s[h];
        rep(i,h) cin>>s[i];

        priority_queue<pair<ll, ii>, vector<pair<ll, ii> > , greater<pair<ll, ii> > > pq;
        pq.push(mp(0, mp(cx, cy)));
        dis[cx][cy]=0;

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

        pair<ll, ii> z;
        while(!pq.empty()){
            z = pq.top();
            pq.pop();

            if(vis[z.ss.ff][z.ss.ss]) continue;
            vis[z.ss.ff][z.ss.ss]=1;
            if(z.ss.ff==fx && z.ss.ss==fy){
                cout<<dis[z.ss.ff][z.ss.ss]<<el;
                return 0;
            }

            rep(i,4){
                x=z.ss.ff+dx[i];
                y=z.ss.ss+dy[i];
                if(x<0 || y<0 || x>=h || y>=w) continue;
                if(vis[x][y] || s[x][y]=='#') continue;
                if(dis[x][y]>z.ff){
                    dis[x][y]=z.ff;
                    pq.push(mp(z.ff, mp(x,y)));
                }
            }

            for(int i=max(0ll, z.ss.ff-2); i<min(h, z.ss.ff+3); i++){
                for(int j=max(0ll, z.ss.ss-2); j<min(w, z.ss.ss+3); j++){
                    if(!vis[i][j] && s[i][j]=='.' && dis[i][j]>z.ff+1){
                        dis[i][j]=z.ff+1;
                        pq.push(mp(z.ff+1, mp(i,j)));
                    }
                }
            }

        }
        cout<<-1<<el;

    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

void dfs(int u , long long total_cycle){
		if(vis[u]) return ;
		vis[u]=true;
		total_cycle+=b[u];
		track.push_back(total_cycle);
		dfs(a[u],total_cycle);
}
int main() {
		int n,k;
		cin>>n>>k;
		for(int i=0;i<n;i++){
				cin>>a[i];
				a[i]--;
		}
		for(int i=0;i<n;i++)
				cin>>b[i];
		ll ans=-(1e18);
		for(int i=0;i<n;i++){
				memset(vis,false,sizeof(vis));
				dfs(i,0);
				if(track.back()>0 && k>=(int)(track.size())){
						ll cycles=(ll)(k/(int)track.size());
						ll left=(ll)(k%(int)track.size());
						ll maxi=-1e18;
						for(int x=0;x<(int)track.size();x++)
								maxi=max(maxi,track[x]);
						ans=max(ans,(cycles-1LL)*(track.back())+maxi);
						maxi=-1e18;
						for(int x=0;x<left;x++)
								maxi=max(maxi,track[x]);
						ans=max(ans,(cycles*track.back()) + maxi);
				}
				else{
						for(int j=0;j<(min((int)track.size(),k));j++){
								ans=max(ans,track[j]);
						}
				}
				track.clear();
		}
		cout<<ans;
}


Measured memory_bytes: 3984
N = int(input())
*t, = map(int, input().split())
*v, = map(int, input().split())
sumt = sum(t)

sv = [0]
for i in range(N):
    for j in range(t[i]*2):
        sv.append(v[i])
sv.append(0)

# dp[i][j] := i/2秒後に速度がj/2のときの最大距離
dp = [[-float('inf')]*201 for _ in range(sumt*2+1)]
dp[0][0] = 0
for i in range(1, len(dp)):
    maxj = min(sv[i], sv[i+1])*2
    for j in range(len(dp[i])):
        k = 0.25*j
        # 変化なし
        if j <= maxj:
            dp[i][j] = max(dp[i][j], dp[i-1][j]+k)
        # 加速
        if (j+1) <= maxj:
            dp[i][j+1] = max(dp[i][j+1], dp[i-1][j]+k+0.25)
        # 減速
        if j > 0 and (j-1) <= maxj:
            dp[i][j-1] = max(dp[i][j-1], dp[i-1][j]+k-0.25)

print(dp[-1][0])


Measured memory_bytes: 141460
card = []
for i in 1..3
  card << gets.split(" ").map(&:to_i)
end

n = gets.to_i
nums = []
for i in 1..n
  nums << gets.to_i
end

i = 0
while i <= 2
  j = 0
  while j <=  2
    if nums.include?(card[i][j])
      card[i][j] = "○"
    end
    j += 1
  end
  i += 1
end

if (card[0][0] == "○" && card[0][1] == "○" && card[0][2] == "○") || 
    (card[1][0] == "○" && card[1][1] == "○" && card[1][2] == "○") ||
    (card[2][0] == "○" && card[2][1] == "○" && card[2][2] == "○") ||

    (card[0][0] == "○" && card[1][0] == "○" && card[2][0] == "○") ||
    (card[0][1] == "○" && card[1][1] == "○" && card[2][1] == "○") ||
    (card[0][2] == "○" && card[1][2] == "○" && card[2][2] == "○") ||

    (card[0][0] == "○" && card[1][1] == "○" && card[2][2] == "○") ||
    (card[0][2] == "○" && card[1][1] == "○" && card[2][0] == "○")
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 14264
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>

using namespace std;
# define ll long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//# define m 163577857
//# define MOD 163577857
# define pi acos(-1)
# define fi first
# define se second
#define REP(i,n) for (int i = 1; i <= n; i++)

const ll mod = 1000000007;
const int K = 2;
//typedef vector<vector<int> > matrix;
int add(int a, int b,int mod) {
    a%=mod;
    b%=mod;
	a += b;
	if (a >= mod) a -= mod;
	if(a<0)
    {
        a += mod;
        a %= mod;
    }
	return a;
}

int mul(ll a, int b,int mod) {
    a%=mod;
    b%=mod;
	a *= b;
	return a % mod;
}
int po(int a,int b,int mod)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return po(mul(a,a,mod),b/2,mod);
    return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}


ll fact[1000003];
ll inv[1000003];

void fact0()
{
	int i,j;
	fact[0]=1;
	for(i=1;i<=200000;i++)
	{
		fact[i]=i*fact[i-1]%mod;
	}
	inv[0]=1;
	inv[1]=1;
	ll p=mod;
	for (i=2; i<=200000; i++)
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;

	for(i=2;i<=200000;i++)
	{
		inv[i]*=inv[i-1];
		inv[i]%=mod;
	}
}
set<int> v[100005];
signed main()
{
    gok
   //fact0();
   int x;
   cin>>x;
   //cout<<pow(201,5)-pow(200,5)<<endl<<endl;
/*   set<pair<int,int>> ss;
   for(int i=-100;i<=100;i++)
   {
       int tt = i*i*i*i*i;
       ss.insert({tt,i});
   }*/
  int a,b;
  for(int i=-200;i<=200;i++)
  {
      int t1 = i*i*i*i*i;
      //cout<<t1<<" ";
      int ss = t1+x;
      int t2=-101;
     // cout<<t2<<" ";
      for(int j=-200;j<=200;j++)
      {
          int tm = j*j*j*j*j;
          if(tm==ss)
          {
            //  cout<<"jgg"<<endl;
              t2=j;
              break;
          }
      }
     // cout<<t2<<endl;
      if(t2!=-101)
      {
          b=t2,a=i;
         //cout<<i<<endl;
          break;
      }
  }
  cout<<b<<" "<<a;













    return 0;
    }


Measured memory_bytes: 8304
//ex3_3
//TKC001
 
#include<stdio.h>
#include<math.h>
 
int main(void){
    double exact, base, logkn;
    int digits;
 
    scanf("%lf", &exact);
    scanf("%lf", &base);
 
    logkn = log(exact) / log(base);
 
    digits = logkn;
 
    printf("%d", digits+1);
 
    return 0;
 
}

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

const int N = 111111;
int n;

typedef struct Point {
    int x, y, id;
} Point;

bool compx(const Point& a, const Point& b) {
    return a.x < b.x;
}

bool compy(const Point& a, const Point& b) {
    return a.y < b.y;
}

typedef struct Edge {
    int u, v, cost;
} Edge;

bool compcost(const Edge& a, const Edge& b) {
    return a.cost < b.cost;
}

typedef struct Node {
    Node *parent;
    int rank;
} Node;

Node *getParent(Node *a) {
    while(a->parent != NULL) {
        a = a->parent;
    }
    return a;
}

bool merge(Node *a, Node *b) {
    a = getParent(a);
    b = getParent(b);
    if(a == b) return false;
    if(a->rank < b->rank) {
        a->parent = b;
    } else {
        b->parent = a;
        if(a->rank == b->rank) {
            a->rank++;
        }
    }
    return true; 
}

Point pts[N];
Node ds[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> pts[i].x >> pts[i].y;
        pts[i].id = i;
    }
    vector<Edge> edges;
    sort(pts, pts + n, compx);
    for(int i = 1; i < n; i++) {
        Edge e;
        e.u = pts[i - 1].id;
        e.v = pts[i].id;
        e.cost = min(abs(pts[i - 1].x - pts[i].x), abs(pts[i - 1].y - pts[i].y));
        edges.push_back(e);
    }
    sort(pts, pts + n, compy);
    for(int i = 1; i < n; i++) {
        Edge e;
        e.u = pts[i - 1].id;
        e.v = pts[i].id;
        e.cost = min(abs(pts[i - 1].x - pts[i].x), abs(pts[i - 1].y - pts[i].y));
        edges.push_back(e);
    }
    sort(edges.begin(), edges.end(), compcost);
    for(int i = 0; i < n; i++) {
        ds[i].parent = NULL;
        ds[i].rank = 0;
    }
    long long int ans = 0;
    for(int i = 0; i < edges.size(); i++) {
        int u = edges[i].u, v = edges[i].v;
        int cost = edges[i].cost;
        Node *a = getParent(ds + u), *b = getParent(ds + v);
        if(merge(a, b)) {
            ans += cost;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6132
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
char S[205],T[205];
int main(){
	scanf("%s%s",S+1,T+1);
	int len=strlen(S+1);
	for(int i=1;i<=len;++i){
		S[i+len]=S[i];
	}
	for(int i=1;i<=len;++i){
		bool mark=0;
		for(int j=i;j<=i+len-1;++j){
			if(S[j]!=T[j-i+1]){
				mark=1;	
			}
		}
		if(mark)continue;
		else{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//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) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n, m; cin >> n >> m;

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

	vector<int> x(m);

	for (int i = 0; i < m; i++) {
		cin >> x[i];
	}

	sort(x.begin(), x.end());


	vector<LL> d(m-1);

	
	for (int i = 1; i < m; i++) {
		d[i - 1] = abs(x[i] - x[i - 1]);
	}

	LL s = 0;

	for (int i = 0; i < m-1; i++) {
		s += d[i];
	}

	sort(d.rbegin(), d.rend());

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

	cout << s << endl;





	

	return 0;
}

Measured memory_bytes: 1408
abcd = list(input())
a, b, c, d = (int(abcd[i]) for i in range(4))

dict = {1: "+", -1: "-"}

for k in [1, -1]:
    for l in [1, -1]:
        for m in [1, -1]:
            if a + (k * b) + (l * c) + (m * d) == 7:
                print("{}{}{}{}{}{}{}=7".format(a, dict[k], b, dict[l], c, dict[m], d))
                exit()

Measured memory_bytes: 38288
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int N;
double dp[3100][3100];

int main()
{
    cin >> N;
    vector<double> p(N);
    rep(i, N) cin >> p[i];

    //初期値
    dp[0][0] = 1.0;

    rep(i, N){
        rep(j, i+1){
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * ( 1.0 - p[i]);
        }
    }

    double res = 0.0;
    for(int j = (N+1)/2; j <= N; ++j) res += dp[N][j];
    printf("%.10f", res);

}

Measured memory_bytes: 72448
import itertools

h,w,k=map(int,input().split())
matrix=[]
for i in range(h):
	s=list(input())
	matrix.append(s)
hlist=[]
for i in range(h):
	hlist.append(i)
wlist=[]
for i in range(w):
	wlist.append(i)
rows=[]
cols=[]
for i in range(h+1):
	obj=itertools.combinations(hlist, i)
	rows+=list(obj)
for i in range(w+1):
	obj=itertools.combinations(wlist, i)
	cols+=list(obj)
ans=0
for i in rows:
	for j in cols:
		count=0
		for a in range(h):
			for b in range(w):
				if(matrix[a][b]=='#' and a not in i and b not in j):
					count+=1
		if(count==k):
			ans+=1
print(ans)

Measured memory_bytes: 9276
#include <iostream>

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N;
  cin>>N;
  vector<int>H(N);
  for(int i=1;i<=N;i++){
    cin>>H[i];
  }
  for(int i=1;i<=N;i++){
    if(H[i]>H[i-1]){H[i]--;}
    else if(H[i]<H[i-1]){cout<<"No"<<endl;return 0;}
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 3732
/*
 * Good Luck
 */
#include <bits/stdc++.h>
#define int long long
using namespace std;

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = INT64_MIN;
    if(b == c) {
        ans = max(c * d, a * b);
    }
    cout << max({ans, a * c, a * d, b * c, b * d});
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<bool> ok(n, true);
    vector<int64_t> dp(n+1, 0);

    int a;
    for (int i = 0; i < m; i++) {
        cin >> a;
        ok[a] = false;
    }
    dp[0] = 1;
    if (ok[1]) dp[1] = 1;
    for (int i = 2; i < n+1; i++) {
        if (ok[i]) {
            dp[i] = dp[i-1] + dp[i-2];
            dp[i] %= MOD;
        }
    }
    cout << dp[n] << endl;
}


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

using namespace std;

double
cubic(const double a)
{
    return a * a * a;
}

double
square(const double a)
{
    return a * a;
}

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

    int n;
    cin >> n; cin.ignore();

    vector<double> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i]; cin.ignore();
    }
    vector<double> y(n);
    for (int i = 0; i < n; i++) {
        cin >> y[i]; cin.ignore();
    }

    vector<double> d(n);
    for (int i = 0; i < n; i++) {
        d[i] = abs( x[i] - y[i] );
    }
    x.clear();
    y.clear();

    cout << setprecision(6) << fixed;

    cout << accumulate(d.cbegin(), d.cend(), 0.0) << endl;

    vector<double> d2;
    transform(d.begin(), d.end(), back_inserter(d2), square);
    cout << sqrt( accumulate(d2.cbegin(), d2.cend(), 0.0) ) << endl;
    d2.clear();

    transform(d.cbegin(), d.cend(), back_inserter(d2), cubic);
    cout << cbrt( accumulate(d2.cbegin(), d2.cend(), 0.0) ) << endl;
    d2.clear();

    sort(d.begin(), d.end(), greater<double>());
    auto it = d.cbegin(); 
    cout << *it << endl;
    d.clear();

    return 0;
}

Measured memory_bytes: 3412
#include <iostream>
using namespace std;
 
int main() {
 
  int n;
  cin >> n;
  
  long double result;
  
  if(n%2==0)
    result = (double)1/2;
  else {
  	result = (double) (n+1)/(2*n);
  }
  
  cout << result << endl;
 
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll n;
    list<ll> b;
    cin >> n;
    for(ll i = 0;i < n;i++) {
        ll temp;
        cin >> temp;
        if(i % 2) b.push_front(temp);
        else b.push_back(temp);
    }
    if(n % 2) reverse(b.begin(), b.end());
    for(auto &i: b) cout << i << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 8448
N=int(input())
A=list(map(int,input().split()))

def uplow(a,b):
    if a<b:up=b;low=a
    else:up=a;low=b
    return up,low

def euclid(a,b):
    up,low=uplow(a,b)
    while 1:
        up,low=low,up%low
        if low==0:return up

ans=A[0]
for i in range(1,N):
    ans=euclid(ans,A[i])
print(ans)

Measured memory_bytes: 14252
n, m = map(int, raw_input().split())
a = []
for _ in range(n):
	a.append(map(int, raw_input().split()))
b = []
for _ in range(m):
	b.append(int(raw_input()))
for i in range(n):
	c = []
	for j in range(m):
		c.append(a[i][j]*b[j])
	print sum(c)

Measured memory_bytes: 4816
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
check = a[-1] / 2
MIN = 10 ** 10

for i in range(n - 1):
    if abs(a[i] - check) < MIN:
        keep = i
        MIN = abs(a[i] - check)

print(a[-1], a[keep])


Measured memory_bytes: 86020
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a*b/gcd(a,b);
}

long long com(long long n,long long k){
	
}
long long getDigit(long long n){
	if(n==1)return 1;
	else return log10(n)+1;
}
class G{
	long long node;
	long long w;
	
};
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long N,K;
	cin>>N>>K;
	long long ans=K;
	for(int i=1;i<N;i++){
		ans*=(K-1);
	}
	cout<<ans<<endl;
}


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

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

using namespace std;

const int INF=1<<29;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	int a[30][30],c[500][500];
	rep(i,m) rep(j,m) scanf("%d",a[i]+j);
	rep(i,n) rep(j,n) scanf("%d",c[i]+j), c[i][j]--;

	if(n==1){ puts("0"); return 0; }

	vector<int> gr[3];
	rep(i,n) rep(j,n) gr[(i+j)%3].emplace_back(c[i][j]);

	int cost[3][30]={};
	rep(i,3) rep(j,m) rep(k,gr[i].size()) cost[i][j]+=a[gr[i][k]][j];

	int ans=INF;
	rep(i,m) rep(j,m) rep(k,m) if(i!=j && j!=k && k!=i) ans=min(ans,cost[0][i]+cost[1][j]+cost[2][k]);
	printf("%d\n",ans);

	return 0;
}


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

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

	int	n;
	cin >> n;

	string s;
	cin >> s;
	char	before;
	before = s.at(0);
	int	count;
	count = 1;
	for (int i = 1; i < n; i++)
	{
		if (s.at(i) != before)
		{
			before = s.at(i);
			count++;
		}
	}
	cout << count << endl;
}


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

// Shortening code
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;

// Macros
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = a; i >= b; i--)

ll INF = 1e9 + 5;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // Your code
    int n;
    cin >> n;
    vi a(n);
    REP(i, 0, n)
    {
        cin >> a[i];
    }

    vi dp(n + 1, INF);
    dp[0] = 0;

    REP(i, 0, n + 1)
    {
        if (i + 1 < n + 1)
        {
            dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i + 1] - a[i]));
        }
        if (i + 2 < n + 1)
        {
            dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i + 2] - a[i]));
        }
    }
    cout << dp[n - 1];

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int p[N];
  int sum=0;
  int comp;
  for (int i = 0; i < N; ++i)
  {
  	  cin >> p[i];
  	  sum += p[i];
  }
int max =0;
  for (int i = 0; i < N; ++i)
  {
  	if (max < p[i]  )
  	{
  		max = p[i];
  	}
  }

  comp = sum - max;

  if (max >= comp)
  {
  	cout << "No" << endl;
  }else{
  	cout << "Yes" << endl;
  }

  
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        int power = 1;
        while ((power * 2) <= n) {
            power *= 2;
        }
        System.out.println(power);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	sort(v.begin(), v.end());
	long long a = 0, b = 0;
	for(int i = n - 1; i >= 0; i--){
		if(i == 0) break;
		if(v[i] == v[i - 1]){
			if(a == 0) a = v[i];
			else if(b == 0)b = v[i];
			else break;
			i--;
		}
	}
 
	cout << a * b <<endl;
 
	return 0;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int D,G,p[11],c[11];
	cin>>D>>G;G/=100;
	int ans=G;
	for(int i=0;i<D;i++)cin>>p[i]>>c[i],c[i]/=100;
	for(int s=0;s<(1<<D);s++)
	{
		int cnt=0,poi=0;
		for(int i=0;i<D;i++)
		{
			if((1<<i)&s)
			{
				cnt+=p[i];
				poi+=(i+1)*p[i]+c[i];
			}
		}
		if(poi>=G)
		{
			ans=min(ans,cnt);
			continue;
		}
		for(int i=D-1;i>=0;i--)
		{
			bool f=false;
			if(!((1<<i)&s))
			{
				for(int j=1;j<p[i];j++)
				{
					cnt++;
					poi+=i+1;
					if(poi>=G)
					{
						ans=min(ans,cnt);
						f=true;
						break;
					}
				}
			}
			if(poi>=G)break;
		}
	}
	cout<<ans<<"\n";
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by Echizen on 2017/5/14.
 */
public class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int num=in.nextInt();
        System.out.println(Integer.highestOneBit(num));
    }
}

Measured memory_bytes: 23892
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
string s;
cin>>s;
int n=s.length();

int msk=0;

rep(i,0,n-1)msk|=(1<<(s[i]-'a'));

if(n!=26)
{
	rep(i,0,25)
	{
		if((msk&(1<<i))==0)
		{
			ol(s);ol(char('a'+i));
			return 0;
		}
	}
}

int msk1=0;
string ans="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
rep(i,0,n-1)
{
	msk1|=(1<<(s[i]-'a'));
	int x=s[i]-'a';
	rep(j,x,25)
	{
		if((msk1&(1<<j))==0)
		{
			ans=min(ans,s.substr(0,i)+char('a'+j));
			break;
		}
	}
}
if(ans.length()>27)
ol("-1");
else
ol(ans);
return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
int phi(int n) {
	int k=2;
	double res=n;
	for (; n>1; k++) {
		if (n%k) continue;
		while (!(n%k))
			n/=k;
		res*=(1.0-1.0/(k+0.0));
	}
	return (int)res;
}
ll a,b,x;
int main(){
	scanf("%lld%lld%lld",&a,&b,&x);
	ll ans=(b/x)-(a/x);
	if(a%x==0){
		ans++;
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string S;
  cin >> S;
  int numz = 0;
  int numo = 0;
  for(int i=0; i<S.size(); i++){
    if(S[i] == '0') numz++;
    else numo++;
  }
  int ans = 2*min(numz, numo);
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
    int A, B, K,count=0,X[100]={};
    cin >> A >> B >> K;
    for(int i=1;i<=100;i++){
        if(A%i==0 && B%i==0){
        count = count + 1;
        X[count] = i;
        }
    }
    cout << X[count-K+1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	vector<string> weather{ "Sunny","Cloudy","Rainy" };
	string s;
	cin >> s;

	for (int i = 0; i < 3; i++) {
		if (s == weather[i]) cout << weather[(i+1)%3] << "\n";
	}

	return 0;
}

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

using namespace std;

int main(int, char**) {
        long long x;
        cin >> x;
        long long a, b;
        long long n_max = 10000;
        for (long long i=0; i<n_max; i++) {
                for (long long j=0; j<n_max; j++) {
                        if (x == pow(i, 5) - pow(j, 5)){
                                cout << i << " " << j << endl;
                                return 0;
                        } else if (x == pow(i, 5) + pow(j, 5)){
                                cout << i << " " << -j << endl;
                                return 0;
                        }

                }
        }
        return 0;
}


Measured memory_bytes: 4192
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[100001] = {};
ll b[100001] = {};
int main() {
	ll n, h; cin >> n >> h;
	ll maxA = 0;
	rep(i, 0, n) {
		cin >> a[i] >> b[i];
		maxA = max(maxA, a[i]);
	}

	sort(b, b + n);
	reverse(b, b + n);

	ll cnt = 0;
	rep(i, 0, n) {
		if (maxA <= b[i]) {
			h -= b[i];
			cnt++;
			if (h <= 0) {
				cout << cnt << endl;
				return 0;
			}
		}
	}

	cnt += h / maxA + ((h % maxA) ? 1 : 0);
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1792
require 'matrix'

loop do
  s = gets.chomp.chop
  break if s == ''
  #lookahead(?!  )
  s.gsub!(/([A-Z\)])(?![a-z\d])/, '\11')
  s.gsub!(/([A-Z][a-z])(?!\d)/, '\11')
  s.gsub!(/\((.+?)\)(\d*)/){
    as, n = $1, $2
    as.gsub(/([a-zA-Z])(\d+)/){"#{$1}#{$2.to_i * n.to_i}"}
  }

  atoms = []
  s.scan(/[A-Z][a-z]?/).each{|atom| atoms << atom }
  atoms.uniq!
  molecules = s.split('->').map{|ms| ms.split('+')}
  l = molecules[0].size
  molecules.flatten!
  m = molecules.size - 1
  n = atoms.size

  a = Matrix.build(n, m){|y, x|
    atom = atoms[y]
    k = 0
    molecules[x].scan(/#{atom}(\d+)/).each{|a|
      k += a[0].to_i
    }
    if k > 0
      (x >= l ? -k : k).to_r
    else
      0.to_r
    end
  }.to_a

  b = [0] * n
  atoms.each do |atom|
    molecules[-1].scan(/(#{atom})(\d+)/).each{|a, k|
      b[atoms.index(a)] = k.to_r
    }
  end

  # Gauss-Jordan elimination
  (0...[n,m].min).each do |i|
    pv = (i...n).max{|k| a[k][i].abs}
    a[i], a[pv] = a[pv], a[i]
    b[i], b[pv] = b[pv], b[i]
    (0...n).each do |j|
      next if i == j
      r = a[j][i] / a[i][i]
      (i...m).each do |k|
        a[j][k] -= r * a[i][k]
      end
      b[j] -= r * b[i]
    end
  end

  ans = (Matrix[*a[0,m]].inv * Vector[*b[0,m]]).to_a + [1.to_r]
  lcm = ans.map(&:denominator).reduce(&:lcm)
  puts ans.map{|x| (x * lcm).to_i} * ' '
end

Measured memory_bytes: 10016
import sys
n,m=map(int,input().split())
arr=[1,2]
arr=arr+[0]*(n-2)
danger=list(map(int,sys.stdin))
danger.append(0)
m=0
if 1 == danger[0]:
  arr[0]=0
  arr[1]=1
  m=1
for i in range(n):
  if i+1 == danger[m]:
    arr[i]=0
    m+=1
  elif i==0 or i==1:
    continue 
  else:
    arr[i]=(arr[i-1]+arr[i-2])%(10**9+7)
print(arr[n-1]%(10**9+7))

Measured memory_bytes: 7780
import java.util.Scanner;

public class Main{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String data;
		int N = sc.nextInt();
		String name = sc.next();
		int i;
		int count = 0;
		for(i=0; i<N; i++){
			data = sc.next();
			B:for(int k=0; k <= (data.length() - name.length()); k++){
				String kanban = data.substring(k, k+1);
				String namae = name.substring(0, 0+1);
				if(kanban.equals(namae)){
					for(int m=k+1; m <= (data.length() - (name.length()-1)); m++){
						kanban = data.substring(m, m+1);
						namae = name.substring(1, 1+1);
						if(kanban.equals(namae)){
							int dist = m-k;
							if(check00(name, data, 1, m, dist)==1){
								count++;
								break B;
							}
							
						}
					}
				}
			}
		}
		System.out.println(count);
		return;
	}
	
	static int check00(String name, String data, int x, int y, int dist)
	{
		if(x==name.length()-1){
			return 1;
		}
		else if(y+dist >= data.length()){
			return 0;
		}
		String namae = name.substring((x+1), (x+1)+1);
		String kanban = data.substring((y+dist), (y+dist)+1);
		if(kanban.equals(namae)){
			return check00(name, data, x+1, y+dist, dist);
		}
		else{
			return 0;
		}
		
	}

}

Measured memory_bytes: 24212
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello{
    public static void Main(){
        var k = Int32.Parse(Console.ReadLine());
        var s = Console.ReadLine();

        var ret = "";
        if(k < s.Length){
            ret = s.Substring(0, k) + "...";
        } else {
            ret = s;
        }

        System.Console.WriteLine(ret);
    }
}


Measured memory_bytes: 27548
N,M = map(int,input().split())
a_s = []
for _ in range(M):
  a_s.append(int(input()))
a_s.append('END')
  
dp = []
a_cursor = 0
for i in range(N+1):
  if i == a_s[a_cursor]:
    dp.append(0)
    a_cursor += 1
  else:
    if i == 0:
      dp.append(1)
    elif i == 1:
      dp.append(1)
    else:
      dp.append((dp[i-1]+dp[i-2])%1000000007)
      
print(dp[-1])

Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}

int main()
{
	ll n;
	cin>>n;//>a>>b;
	vector<int>x(n);
	rep(i,n)cin>>x[i];
	sort(all(x));
	ll sum=0;
	int cnt=0;
	rep(i,n){
		if(x[i]<=sum*2){
			cnt++;
		}else{
			cnt=1;
		}
		sum+=x[i];
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

int main(){
  long N,M, ans;
  cin >> N >> M;

  if(2*N >= M) {
    ans = M/2;
  }

  else {
    ans = N;
    M -= 2*N;
    ans += M/4;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int a, b;
    cin >> a >> b;
    a--; b--;
    int ans = a*b;
    
    cout << ans << endl;
    return 0;
}


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

int main(){
	ll n;
	cin>>n;
	vector<int> a(n);
	if(n==0){
	cout<<"0";return 0;
	}
	for(int i=0;i<n;i++)cin>>a[i];
	ll m=a[0],c=0;
	for(int i=0;i<n;i++){
		if(a[i]>=m){
		m=a[i];}
		
		else{
			c+=m-a[i];
		}
	}
	cout<<c;
}

Measured memory_bytes: 4036