akhauriyash/Code-Regression huggingface dataset:
n=int(input())
B=list(map(int,input().split()))
A=[]
for i in range(n):
    for j in range(len(B))[::-1]:
        if B[j]==j+1:
            A.append(B.pop(j))
            break
    else:print(-1);exit()
for i in A[::-1]:print(i)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c,x[100],d,p;
main(){
    p=0;
    cin>>n;
    cin>>a>>b;
    cin>>c;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    d=0;
    sort(x,x+n,greater<int>()); 
    p=c/a;
    for(int i=0;i<n;i++){
        a += b;
        c += x[i];
        p=max(p,c/a);
    }
    cout<<p<<endl;
    return 0;
}

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

int main() {
  int n;
  
  while(cin>>n, n) {
    vector<pair<int,int> > v(n*2);
    for(int i=0; i<n; i++) {
      int mass, begin, end;
      cin >> mass >> begin >> end;
      // テヲツゥツ凝」ツ?クテ」ツ?凝」ツ?凝」ツつ凝ィツイツ?ィツ債キテ」ツ?ョテ・ツ「ツ療ヲツクツ崚」ツ?ョテ・ツ「ツεァツ閉古」ツ?ッテヲツクツ。テ」ツつ甘・ツァツ凝」ツつ?」ツ?ィテァツオツづ」ツつ?
      v[i*2] = make_pair(begin, mass);
      v[i*2+1] = make_pair(end, -mass);
    }
    // テ、ツコツ凝」ツ?ョティツオツキテ」ツつ甘」ツつ津ヲツ卍づァツウツサテ・ツ按療ゥツ??」ツ?ォテ」ツつステ」ツδシテ」ツδ?
    sort(v.begin(), v.end());
    
    int load = 0;
    bool isOk = true;
    for(int i=0; i<2*n; i++) {
      load += v[i].second;
      if(load > 150) isOk = false;
    }
    cout << (isOk ? "OK" : "NG") << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1192
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner Sc = new Scanner(System.in);
		int a = Sc.nextInt();
		int b = Sc.nextInt();
		int Prod = a * b;
		if(Prod % 2 == 0){
			System.out.println("Even");
		}
		else{
			System.out.println("Odd");
		}
	}
}

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

class Program
{
	static void Main()
	{
		var nm = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
		var n = nm[0];
		var m = nm[1];

		var routes = Enumerable.Range(0, m).Select(num => {
			var ab = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
			return new { A = ab[0], B = ab[1] };
		}).ToArray();

		Array.Sort(routes, (route1, route2) => {
			if (route1.A < route2.A) {
				return -1;
			} else if (route1.A > route2.A) {
				return 1;
			} else {
				return route1.B < route2.B ? -1 : 1;
			}
		});

		var targets = new List<int>[n];
		for (var i = 0; i < m; ++i) {
			var destination = routes[i].B - 1;
			if (targets[destination] == null) {
				targets[destination] = new List<int>();
			}

			targets[destination].Add(routes[i].A - 1);
		}

		var transits = targets.Last();
		if (transits == null) {
			Console.WriteLine("IMPOSSIBLE ");
		} else {
			var isArrival = transits.Exists(transit => {
				if (targets[transit] == null) {
					return false;
				} else {
					return targets[transit].Contains(0);
				}
			});
			Console.WriteLine(isArrival ? "POSSIBLE" : "IMPOSSIBLE ");
		}
	}
}


Measured memory_bytes: 41168
var
  a,b:array[0..1000]of longint;
  n,m,i,j,m1,m2,x,y:longint;
begin
   readln(n,m,x,y);
   m1:=x;m2:=y;
   for i:=1 to n do
     begin
       read(a[i]);
       if a[i]>m1 then m1:=a[i];
     end;
   readln;
   for i:=1 to m do
     begin
       read(b[i]);
       if b[i]<m2 then m2:=b[i];
     end;

   if m2<=m1 then write('War') else write('No War');
end.

Measured memory_bytes: 128
S=input()
N=len(S)
fg1 = S == S[::-1]
T=S[:(N-1)//2]
fg2 = T == T[::-1]
U=S[(N+3)//2-1:]
fg3 = U == U[::-1]

if fg1 and fg2 and fg3:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 200005
 
// it's swapnil07 ;)


signed main(){
    fast
    #ifdef SWAPNIL07
        freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
        freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    #endif
    int n; cin>>n;
    int k; cin>>k;
    int h[n];
    For(i, 0, n)
        cin>>h[i];
    int dp[n];
    dp[0]=0;
    For(i, 1, n){
        dp[i]=INF;
        For(j, 1, k+1){
            if(i-j >= 0)
                dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]), dp[i]);
        }
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
import bisect
n = int(input())
l = list(map(int,input().split()))
cnt = 0
l = sorted(l)
for i in range(n):
    for j in range(i+1,n):
        d = l[i]+ l[j]
        cnt +=bisect.bisect_left(l,d) - (j+1)
print(cnt)    


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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n;
        cin>>n;
        ll a[n];
        map<ll,ll>mp;

        loop(i,0,n-1)
        {
            cin>>a[i];
            mp[a[i]]++;
        }
        ll ans=0;
        for(ll i=1;i<=n;i++)
             if(mp[i]>0) ans+=mp[i]*(mp[i]-1)/2;
        loop(i,0,n-1)
        {
            ll p=mp[a[i]];
            ll x=((p-1)*(p-2)/2)-(p*(p-1)/2);
            cout<<ans+x;
            nl;
        }

    }
    return 0;
}


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

int main() {
  int N, A, B, C, D;
  cin >> N;
  A = N/1000;
  B = (N/100)%10;
  C = ((N/10)%100)%10;
  D = N % 10;
  
  if((A == B)&&(B == C)){
    cout << "Yes" << endl;
  }else if((B == C)&&(C == D)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
h = list(map(int, input().split()))

dp = np.full(n, np.inf)

def chmin(a, b):
    if a < b:
        return a
    else:
        return b

dp[0] = 0
dp[1] = np.abs(h[1] - h[0])

for i in range(2, n):
    dp[i] = chmin(dp[i], dp[i - 1] + np.abs(h[i] - h[i - 1]))
    dp[i] = chmin(dp[i], dp[i - 2] + np.abs(h[i] - h[i - 2]))

print(int(dp[-1]))


Measured memory_bytes: 22852
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD 1000000007
#define pb push_back
#define mp make_pair

void solve()
{
	int n, k, num, ans = 0;
	cin >> n >> k;
	vector<int> a;
	for (int i = 0; i < n; i++)
	{
		cin >> num;
		a.pb(num);
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < k; i++)
		ans += a[i];
	cout << ans;
}

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

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

using namespace std;

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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 25;

int w,h;
char table[25][25];

int n;
int row[15],col[15];
int rel[15][15];

typedef tuple<int,int,int> state;

int dr[4]={1,0,-1,0};
int dc[4]={0,1,0,-1};

void bfs(int index){
	int dist[25][25];
	rep(i,h)rep(j,w) dist[i][j]=inf;
	int sr=row[index],sc=col[index];
	dist[sr][sc]=0;
	state init(0,sr,sc);
	queue<state> q;
	q.push(init);
	while(!q.empty()){
		int cost,cr,cc;
		tie(cost,cr,cc)=q.front();q.pop();
		rep(i,4){
			int nr=cr+dr[i],nc=cc+dc[i],ncost=cost+1;
			if(0<=nr&&nr<h&&0<=nc&&nc<w&&table[nr][nc]!='x'){
				if(dist[nr][nc]>ncost){
					dist[nr][nc]=ncost;
					state next(ncost,nr,nc);
					q.push(next);
				}
			}
		}
	}
	rep(i,n) rel[index][i]=dist[row[i]][col[i]];
}


int main(void){
	while(cin >> w >> h,w|h){
		rep(i,h)rep(j,w) cin >> table[i][j];
		n=0;
		rep(i,h)rep(j,w) if(table[i][j]=='o') row[n]=i,col[n]=j,n++;
		rep(i,h)rep(j,w) if(table[i][j]=='*') row[n]=i,col[n]=j,n++;
		rep(i,n) bfs(i);

		int dp[1<<11][11];
		rep(i,1<<n)rep(j,n) dp[i][j]=inf;
		dp[1][0]=0;
		rep(mask,1<<n)rep(i,n) if(mask&(1<<i)){
			rep(j,n){
				if(mask&(1<<j)) continue;
				int ncost=dp[mask][i]+rel[i][j];
				dp[mask|(1<<j)][j]=min(dp[mask|(1<<j)][j],ncost);
			}
		}
		int ans=inf;
		rep(i,n) ans=min(ans,dp[(1<<n)-1][i]);
		if(ans==inf)
			cout << -1 << endl;
		else
			cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repin(Array,n) for(int i=0;i<n;i++){cin>>Array[i];}
using namespace std;

using ll = long long;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;

int main() {

	int N;
	cin >> N;

	int ans = 0;
	for (int i = 1; i <= N/2; i++) {
		int j = N - i;
		if (i != j)
			ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

#define INF (1<<29)

int N, b[300][300], a[300][300];

int main(){
    cin >> N;

    rep(i, N){
        rep(j,N){
            b[i][j] = INF;
            a[i][j] = INF;
        }
    }

    rep(i, N){
        rep(j,N){
            int tmp;
            scanf("%d", &tmp);
            b[i][j] = tmp;
            a[i][j] = tmp;
        }
    }

    rep(i, N){
        rep(j, N){
            rep(k, N){
                b[j][k] = min(b[j][k], b[j][i] + b[i][k]);
            }
        }
    }

    bool flag = false;
    ll sum =0;

    

    rep(i, N){
        rep(j,N){
			flag=false;
            if(b[i][j] != a[i][j]){
                
                cout << "-1" << endl;
                return 0;
            }else{
				rep(k, N){
					if( (i!=k && j != k)  && b[i][j] == (b[i][k] + b[k][j])){
						flag=true;
						break;
					}
				}
				if(flag){
					continue;
				}
                sum += b[i][j];
            }
        }
    }

    
    cout << sum/2 << endl;
    

}

Measured memory_bytes: 896
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) noexcept {
    return b > a && (a = b, true);
}

template <class A, class B> inline bool chmin(A &a, const B &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline vector<T> make_v(const T &initializeValue, size_t sz) {
    return vector<T>(sz, initializeValue);
}

template <class T, class... Args>
inline auto make_v(const T &initializeValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initializeValue, args...))>(sz, make_v<T>(initializeValue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N;
    cin >> N;

    int t = 0, x = 0, y = 0;
    for (size_t i = 0; i < N; ++i) {
        int nt, nx, ny; cin >> nt >> nx >> ny;
        int diff = abs(nx - x) + abs(ny - y);
        int t_diff = abs(nt - t);
        if (t_diff < diff || t_diff % 2 != diff % 2) {
            return cout << "No" << "\n", 0;
        }
        t = nt, x = nx, y = ny;
    }

    cout << "Yes" << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>

using namespace std;

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

const ll mod = 1000000007;
ll fact[1000200];
ll invfact[1000200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

#define fs first
#define sc second

map<char, char> m1;
map<char, char> m2;

int main(){
    ll N, M;
    cin >> N >> M;
    make_fact(200200);
    make_invfact(200200);

    vector<ll> prime_list;
    ll prime = 2, count = 0;
    while(M > 1){
        while(M % prime == 0){
            M /= prime;
            count++;
        }
        if(count > 0){
            prime_list.push_back(count);
        }
        count = 0;
        prime += 1;
    }

    ll res = 1;
    for(int i = 0; i < prime_list.size(); i++){
        res = mul(comb(prime_list[i]+N-1, prime_list[i]), res);
    }
    cout << res % mod << endl;

    return 0;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

void filter(vii& v) {
  sort(v.begin(), v.end());
  vii nv;
  ll mi = 2e18;
  for (auto p : v) {
    if (p.second < mi) {
      nv.push_back(p);
      mi = p.second;
    }
  }
  v.swap(nv);
}

void solve(vl a) {
  int n = a.size();
  vector<vector<vii>> d(n, vector<vii>(n));
  for (int i = 0; i + 1 < n; ++i) {
    d[i][i + 1] = vii(1, pii(0, 0));
  }
  for (int l = 2; l < n; ++l) {
    for (int i = 0; i + l < n; ++i) {
      int j = i + l;
      for (int m = i + 1; m < j; ++m) {
        for (auto p1 : d[i][m]) for (auto p2 : d[m][j]) {
          d[i][j].emplace_back(a[m] + p1.first + p1.second + p2.first, a[m] + p2.first + p2.second + p1.second);
        }
      }
      filter(d[i][j]);
    }
  }
  ll res = 2e18;
  for (auto p : d[0][n-1]) {
    res = min(res, a[0] + a[n - 1] + p.first + p.second);
  }
  cout << res << endl;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n;
  vl a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  solve(a);
  return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> dp(n + 1, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    dp[i + 1] = dp[i] + (a[i] == dp[i] + 1);
  }
  cout << (dp[n] == 0 ? -1 : n - dp[n]) << '\n';
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int [][] a= new int[4][13];  
        	for( int i = 0; i < n; i++ ) {
                String s=sc.next();
                int r=sc.nextInt();
                if(s.equals("S")){
                    a[0][r-1]=1;
                }
                else if(s.equals("H")){
                    a[1][r-1]=1;
                }
                else if(s.equals("C")){
                    a[2][r-1]=1;
                }
                else{
                    a[3][r-1]=1;
                }
            }
       	 for( int i = 0; i < 4; i++ ) {
        	for( int j = 0; j < 13; j++ ) {
         if(a[i][j]!=1){
         if(i==0){
         	System.out.println("S "+(j+1));
        }else if(i==1){
         	System.out.println("H "+(j+1));
        }else if(i==2){
         	System.out.println("C "+(j+1));
        }else if(i==3){
            System.out.println("D "+(j+1));
         }
              
        }
   	 }
    }
   }
}



Measured memory_bytes: 26132
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int a,b;
    scanf("%d %d",&a,&b);
    
    if(0<= a && a <= 9 && 0<= b && b<= 9) printf("%d\n",a*b);
    else printf("-1\n");
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<iomanip>
#define mp make_pair
#define lli long long int
#define modi 1000000007
#define pb push_back
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
int i;
for(i=0;i<n;i++){
    cin>>a[i];
}
int maxi=-1,count=0;
for(i=0;i<n;i++){
    if(a[i]>=maxi){
        maxi=a[i];
        count++;
    }
}
cout<<count<<endl;
}


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

using namespace std;

int n,m;
int seq[17];
int dp[18][262144];
const int mod = 1000000007;
int fact[500000],inv[500000];

int qpow(int base,int tms)
{
	int tmp = 1;
	while(tms)
	{
		if(tms & 1) tmp = tmp * 1ll * base % mod;
		base = base * 1ll * base % mod;
		tms >>= 1;
	}
	return tmp;
}

int C(int n,int r)
{
	if(n < r) return 0;
	return fact[n] * 1ll * inv[n - r] % mod;
}

bool cmp(int a,int b)
{
	return a > b;
}

int main()
{
	fact[0] = inv[0] = 1;
	for(int i = 1;i <= 400000; ++ i)
		fact[i] = fact[i - 1] * 1ll * i % mod;
	inv[400000] = qpow(fact[400000],mod - 2);
	for(int i = 399999;i >= 1; -- i)
		inv[i] = inv[i + 1] * 1ll * (i + 1) % mod;
	scanf("%d%d",&n,&m);
	int all = (1 << n) - 1;
	dp[1][0] = 1;
	for(int i = 1;i <= m; ++ i)
		scanf("%d",&seq[i]);
	sort(seq + 1,seq + 1 + m,cmp); 
	for(int i = 1;i <= m; ++ i)
		for(int j = 0;j <= all; ++ j)
			if(dp[i][j])
			{
				dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;
				int lef = (1 << n) - j - seq[i];
				for(int k = 1;k <= n; ++ k)
					if(!(j & 1 << k - 1))
						dp[i + 1][j | 1 << k - 1] = (dp[i + 1][j | 1 << k - 1] + dp[i][j] * 1ll * C(lef,(1 << k - 1) - 1) % mod * (1 << k - 1) % mod) % mod;
			}
	int as = 0;
	for(int i = 0;i <= all; ++ i)
	{
		int cur = dp[m + 1][i] * 1ll * fact[(1 << n) - i - 1] % mod;
		if(__builtin_popcount(i) & 1) as = (as - cur + mod) % mod;
		else as = (as + cur) % mod;
	}
	printf("%d\n",as * 1ll * (1 << n) % mod);
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;

ll binpow(ll a, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) {
			(res *= a) %= mod;
		}
		p >>= 1;
		(a *= a) %= mod;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
	return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    long long A,B,N;
    cin>>A>>B>>N;
    long long x=min(N,B-1);
    long long ans=(A*x)/B-A*(x/B);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using ll = long long;

int main() {
  int x;
  cin >> x;
  cout << 10 - x / 200 << endl;
  return 0;
}

Measured memory_bytes: 3632
// SeeAlso: https://atcoder.jp/contests/dp/tasks/dp_c

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int n;
int a[MAX][3];


int main (){ 

    cin >> n;
    rep(i, n) {
        rep(j, 3) {
            cin >> a[i][j];
        }
    }
    
    ll ans = 0;

    ll dp[n+1][3];
    memset(dp, 0, sizeof(dp));

    rep(i ,3) {
        dp[0][i] = a[0][i];
    }

    FOR(i, 1, n) {
        rep(j, 3) {
            rep(k, 3) {
                if(j==k) continue;
                dp[i][j] = max(dp[i][j],dp[i-1][k]+a[i][j]);
            }
        }
    }

    rep(i, 3) {
        ans = max(ans, dp[n-1][i]);
    }
    print(ans);
    return 0;
}   

Measured memory_bytes: 3712
#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)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

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

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int main(){
    ll n,k,sum=1,l=0;
    cin>>n>>k;
    vi a(n);
    rep(i,n)cin>>a[i];
    queue<ll> que;
    rep(i,n){
        que.push(a[i]);
        if(i>=k){
            if(a[i]>que.front())cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
            que.pop();
        }
    }   
    return 0;
}

//a=97,z=122

Measured memory_bytes: 5536
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		
		int i;
		int[] in = new int[5];
		
		for(i=0; i<in.length; i++){
			in[i] = Integer.valueOf(r.readLine());
		}
		
		// START //
		for(i=0; in[1]>0 || in[2]>0; in[1]-=in[3], in[2]-=in[4], i++);
		System.out.println(in[0] - i);
		// E N D //
	}
}

Measured memory_bytes: 16860
N = int(input())
H = [int(i) for i in input().rstrip().split()]
C = [0]
for i,h in enumerate(H):
    if i == 0:
        continue
    if i == 1:
        C += [abs(H[0]-H[1])]
        continue

    c1,c2 = abs(H[i-1]-h),abs(H[i-2]-h)
    C += [min(C[-1]+c1,C[-2]+c2)]
    #print(C)
print(C[-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

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

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

int main() {
  cout << setprecision(10);
  int A, B, C;
  cin >> A >> B >> C;
  int cnt = 0;
  if (A == B) cnt++;
  if (B == C) cnt++;
  if (C == A) cnt++;
  cout << (cnt == 1 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,d,r ;
	double f ;
	scanf("%d %d",&a,&b) ;
	if(a<1){
		printf("??¨??????") ;
	}
	else{
		if(b>1E+9){
			printf("??¨??????") ;
		}
		else{
			d=a/b ;
			r=a%b ;
			f=(double)a/(double)b ;
			printf("%d %d %lf\n",d,r,f) ;
		}
	}
	return 0 ;
}

Measured memory_bytes: 636
#include<cstdio>
#include<cmath>
using namespace std;
#define MAXN 350000
#define LL long long
bool check(LL n,LL b,LL s)
{
	LL ret=0;
	while(n>=b)
	{
		ret+=n%b;
		n/=b;
	}
	ret+=n;
	return ret==s;
}
int main()
{
	LL n,s;
	scanf("%lld%lld",&n,&s);
	if(s>=n)
	{
		if(s==n)
			printf("%lld\n",n+1);
		else printf("-1\n");
		return 0;
	}
	int N=sqrt(n)+1;
	for(int b=2;b<=N;b++)
		if(check(n,b,s))
		{
			printf("%d\n",b);
			return 0;
		}
	LL k=n-s,a=k/N+1;
	for(LL b=a;b>=1;b--)
		if(k%b==0)
		{
			LL x=s-b,y=k/b+1;
			if(x>=0&&x<y&&b<y)
			{
				printf("%lld\n",k/b+1);
				return 0;
			}
		}
	printf("-1\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
//#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 1111111;
int a[N];
int n;

bool isodd(vector<bool>& v) {
    bool ans = v[0];
    int n2 = 0;
    int m = 1;
    rep(j, 2, n) {
        m = m * (n - j + 1) / (j - 1);
        int num = n - j + 1;
        while(num % 2 == 0) {
            n2++;
            num >>= 1;
        }
        int den = j - 1;
        while(den % 2 == 0) {
            n2--;
            den >>= 1;
        }
        if(!n2) {
            ans ^= v[j - 1];
        }
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> n >> s;
    rep(i, 1, n) {
        a[i] = s[i - 1] - '0' - 1;
    }
    vector<bool> v;
    rep(i, 1, n) {
        v.pb(a[i] & 1);
    }
    if(isodd(v)) {
        cout << 1 << endl;
    } else {
        bool has1 = false;
        rep(i, 1, n) {
            has1 |= a[i] == 1;
        }
        if(has1) {
            cout << 0 << endl;
        } else {
            v.clear();
            rep(i, 1, n) {
                v.pb(a[i] / 2);
            }
            int ans = isodd(v) ? 2 : 0;
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 9628
solve com = h com []
            where h [] res = reverse res
                  h ('B':cs) res = case res of
                                     [] -> h cs []
                                     (r:es) -> h cs es
                  h ('1':cs) res = case res of
                                     [] -> h cs "1"
                                     otherwise -> h cs ('1':res)
                  h ('0':cs) res = case res of
                                     [] -> h cs "0"
                                     otherwise -> h cs ('0':res)

main = do com <- getLine
          putStrLn $ solve com


Measured memory_bytes: 380
#include <iostream>
#include <vector>

#define MAX_N 100000
#define MAX_M 100

using namespace std;

int N, M;
int A[MAX_N];

vector<int> solve()
{
    vector<int> B;
    if ( M == 1 )
    {
        B.push_back( 1 );
        if ( A[0] > 1 ) B.push_back( A[0] - 1 );
    }
    else if ( M == 2 )
    {
        if ( A[0] > 1 ) B.push_back( A[0] - 1 );
        B.push_back( A[1] + 1 );
    }
    else
    {
        vector<int> idx_odds;
        for ( int i = 0; i < M; i++ )
            if ( A[i] % 2 ) idx_odds.push_back( i );

        if ( idx_odds.size() > 2 ) return B;

        if ( idx_odds.size() == 2 )
        {
            swap( A[idx_odds[0]], A[0] );
            swap( A[idx_odds[1]], A[M - 1] );
        }
        else if ( idx_odds.size() == 1 )
        {
            swap( A[idx_odds[0]], A[0] );
        }

        if ( A[0] > 1 ) B.push_back( A[0] - 1 );
        for ( int i = 1; i < M - 1; i++ ) B.push_back( A[i] );
        B.push_back( A[M - 1] + 1 );
    }
    return B;
}

int main( int argc, char **argv )
{
    cin >> N >> M;

    for ( int i = 0; i < M; i++ ) cin >> A[i];

    auto ans = solve();

    if ( ans.size() == 0 )
        cout << "Impossible" << endl;
    else
    {
        for ( int i = 0; i < M - 1; i++ ) cout << A[i] << " ";
        cout << A[M - 1] << endl;

        cout << ans.size() << endl;

        for ( int i = 0; i < ans.size() - 1; i++ ) cout << ans[i] << " ";
        cout << ans[ans.size() - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main()
{
    int no_of_tickets, no_of_discounts;
    cin >> no_of_tickets >> no_of_discounts;

    priority_queue <int> prices;
    for(int i = 1; i <= no_of_tickets; i++)
    {
        int price;
        cin >> price;

        prices.push(price);
    }

    while(no_of_discounts > 0 && prices.top() > 0)
    {
        int most_expensive = prices.top();

        prices.pop();

        prices.push(most_expensive/2);

        no_of_discounts--;
    }

    long long total_price = 0;
    while(!prices.empty())
    {
        total_price += prices.top();

        prices.pop();
    }

    cout << total_price;
    return 0;
}


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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N,K; cin >> N >> K;
  vector<pii> v(K);

  for(int i = 0; i < K; i++){
    int tmp1,tmp2; cin >> tmp1 >> tmp2;
    v[i] = make_pair(tmp1,tmp2);
  }

  vector<ll> ans(N,0);
  vector<ll> cum(N,0);
  ll MOD = 998244353;

  ans[0] = 1;

  for(int i = 0; i < N; i++){

    if(i > 0){
      cum[i] += cum[i-1];
      cum[i] %= MOD;

      ans[i] = cum[i];
    }

    // cerr << i << " " << ans[i] << endl;

    for(int j = 0; j < K; j++){
      int start = v[j].first;
      int end = v[j].second + 1;

      if(i + start < N){
        cum[i+start] += ans[i];
        cum[i+start] %= MOD;
      }

      if(i + end < N){
        cum[i+end] -= ans[i];
        cum[i+end] += MOD;
        cum[i+end] %= MOD;
      }
    }
  }

  cout << ans[N-1] << endl;
}


Measured memory_bytes: 6428
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

double dp[905][605][305];

int main()
{jizz
	int n,a[4]={0,0,0,0},x;
	cin >> n;
	for(int i=0;i<n;++i)
		cin >> x,++a[x];
	for(int k=0;k<=a[3];++k)
		for(int j=0;j<=a[2]+a[3]-k;++j)
			for(int i=0;i<=a[1]+a[2]+a[3]-k-j;++i)
				if(i||j||k)
				{
					double a=i,b=j,c=k;
					dp[i][j][k]=n-i-j-k;
					if(i)
						dp[i][j][k]+=a*(dp[i-1][j][k]+1);
					if(j)
						dp[i][j][k]+=b*(dp[i+1][j-1][k]+1);
					if(k)
						dp[i][j][k]+=c*(dp[i][j+1][k-1]+1);
					dp[i][j][k]/=(a+b+c);
				}
	cout << fixed << setprecision(14) << dp[a[1]][a[2]][a[3]] << "\n";
}

Measured memory_bytes: 433664
<?php
fscanf(STDIN, "%s", $n);

$array = str_split($n);

$sum = 0;
for($i = 0; $i < count($array); $i ++){
    $sum += $array[$i];
}

if($sum % 9 == 0){
    echo "Yes";
} else {
    echo "No";
}

?>


Measured memory_bytes: 28412
/*
Author: CNYALI_LK
LANG: C++
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<int,int> pii;
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
#define min mmin
#define max mmax
#define abs aabs
int read(){
	int s=0;
	int base=0;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=1;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	if(base)s=-s;
	return s;
}
int a[102423],b[102423],c[102423],d[102423];
int fa[102423],in[102423],out[102423],In[102423],Out[102423],qaq[102423];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void add(int u,int v){
	++in[v];
	++out[u];
	fa[find(u)]=find(v);
}
int main(){
#ifdef cnyali_lk
	freopen("duliu.in","r",stdin);
	freopen("duliu.out","w",stdout); 
#endif 
	int n;
	n=read();
	for(int i=1;i<=n;++i){a[n+1]^=(a[i]=read());}
	for(int i=1;i<=n;++i){b[n+1]^=(b[i]=read());}
	for(int i=1;i<=n+1;++i){c[i]=a[i];d[i]=b[i];}
	sort(c+1,c+n+2);
	sort(d+1,d+n+2);
	for(int i=1;i<=n+1;++i)if(c[i]!=d[i]){printf("-1\n");return 0;}
	int m=unique(c+1,c+n+2)-c-1;
	for(int i=1;i<=m;++i)fa[i]=i;
	int w=0,cnt1=0,cnt2=0,cnt3=0;
	for(int i=1;i<=n+1;++i){
		a[i]=lower_bound(c+1,c+m+1,a[i])-c;
		b[i]=lower_bound(c+1,c+m+1,b[i])-c;
//		printf("%d-%d\n",a[i],b[i]);
		if(a[i]!=b[i]){
			add(a[i],b[i]);
			++w;
		}
	}
	for(int i=1;i<=m;++i){
//		printf("[%d-%d]\n",in[i],out[i]);
		if(in[i]<out[i])
			Out[find(i)]+=out[i]-in[i];
		else 
			In[find(i)]+=in[i]-out[i];
		if(in[i] || out[i])qaq[find(i)]=1;
	}
    qaq[find(a[n+1])]=1;
	for(int i=1;i<=m;++i)if(qaq[i]){
		if(Out[i]){
			cnt1+=Out[i];
			++cnt2;
		}
		else{
//			printf("%d!\n",i);
			++w;
		}
	}
    if(a[n+1]!=b[n+1])--w;
	printf("%d\n",w-1);	
	return 0;
}

/*
 * 0 1 2 3 0
 * 1 0 3 2 0
 * 
 * */


Measured memory_bytes: 4608
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll logx=30;
const ll N=1e5+5;
const ll M=1e3+5;
const ll mod=1e9+7;
const ll INF=1e18+5;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b,ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b,ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b,ll p){ ll c = a + b; if(c > p) c -= p; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

ll n;
string s;
ll dp[N][3];

ll F(ll idx,ll f)
{
  ll res=0;
  if(idx==n){return 1;}
  ll bit=s[idx]-'0';
  if(dp[idx][f]!=-1){return dp[idx][f];}
  if(f)
  {
    if(bit)
    {
      res=add(res,F(idx+1,1),mod);
      res=add(res,F(idx+1,1),mod);
      res=add(res,F(idx+1,0),mod);
    }
    else
    {
      res=add(res,F(idx+1,1),mod);
    }
  }
  else
  {
    res=add(res,F(idx+1,0),mod);
    res=add(res,F(idx+1,0),mod);
    res=add(res,F(idx+1,0),mod);
  }
  return dp[idx][f]=res;
}

int main()
{
  cin>>s;
  ms(dp,-1);
  n=s.length();
  cout<<F(0,1)<<endl;
}


Measured memory_bytes: 7552
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>

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

using namespace std;

int main(){
	int N;
	while( cin >> N, N ){
		string s[55];
		int ans=-1;
		rep(i,N) cin >> s[i];

		char b[5] = {'a', 'i', 'u', 'e', 'o'};
		rep(k,55){
			if( k == 0 ) continue;
			set<string> st;
			rep(i,N){
				string tmp;
				tmp += s[i][0];
				rep(j, s[i].length()){
					rep(l,5) if( s[i][j] == b[l] ) tmp += s[i][j+1];
					if( tmp.size() >= k ) break;
				}
				st.insert( tmp );
			}
			if( st.size() == N ){
				ans = k;
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(void){
    int n;
    cin>>n;
    vector <int> a(n);
    for (int i = 0; i < n; i++){
        cin>>a[i];
    }

    vector <int> b(n);
    b[0]=0;
    for (int i = 0; i < (n-1); i++){
        if(a[i+1]<a[i]){
        b[i]=a[i]-a[i+1];
        a[i+1]=a[i];
        }
    }
    long int sum=0;
    for(int i=0 ; i<n ; i++)sum+=b[i];
    
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 4424
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)


int main() {

string S; cin >> S ;

bool ans=false;

rep(i,S.size()){
  if(S[i]=='7') ans=true;  
}

if(ans) cout << "Yes" << endl;
else cout << "No" << endl;

return 0;
}

Measured memory_bytes: 3556
n = int(input())
songs = []

for i in range(n):
    s,t = map(str,input().split())
    t = int(t)
    songs.append([s,t])
x = input()
number = 0

for i in range(n):
    if songs[i][0] == x:
        number = i + 1
#print("number: " + str(number))

ans = 0
for j in range(number,n):
    ans += songs[j][1]
print(ans)


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
g = []
high_limit = ((N - 1) * (N - 2)) // 2
if (K > high_limit):
  print(-1)
  exit()

for i in range(2, N + 1):
  g.append((1, i))

count = high_limit - K

for i in range(2, N + 1):
  for j in range(3, N + 1):
    if (count == 0):
      break
    if (i != j and i < j):
      g.append((i, j))
      count -= 1

# print(N - 1 + high_limit - K)
print(len(g))
for t in g:
  print(t[0], t[1])

Measured memory_bytes: 43376
#include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cmath>
     
    using namespace std;
     
    int N;
    int A,B,C;
     
      long long brute_force_search(int cnt, int a, int b, int c, int len[]) {
        long long INF = std::pow(10, 9.0);
        if (cnt==N) {
          //return std::abs(a-A)+std::abs(b-B)+std::abs(c-C)-30;
          
          if ((a>0)&&(b>0)&&(c>0)){
            return std::abs(a-A)+std::abs(b-B)+std::abs(c-C)-30;
          } else {
            return INF;
          }
        }
        vector<long long> ansc(4);
        ansc[0] = brute_force_search(cnt+1, a, b, c, len);
        ansc[1] = brute_force_search(cnt+1, a+len[cnt], b, c, len)+10;
        ansc[2] = brute_force_search(cnt+1, a, b+len[cnt], c, len)+10;
        ansc[3] = brute_force_search(cnt+1, a, b, c+len[cnt], len)+10;
        int min = *std::min_element(ansc.begin(), ansc.end());
        return min;
      }
     
    int main() {
      cin >> N >> A >> B >> C;
      
      int L[N];
      for (int i; i<N;i++){
        cin >> L[i];
      } 
      
      long long ans;
      ans = brute_force_search(0, 0, 0, 0, L);
      cout << ans << endl;
      return 0;
    }

Measured memory_bytes: 256
from collections import deque

N = int(input())
v = list(map(int, input().split()))
v.sort()
V = deque(v)
sum = 0
while True:
    sum = (V.popleft() + V.popleft())/2
    V.appendleft(sum)
    if len(V) == 1:
        break

print(V[0])


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

int main() {
  int n;
  while(cin >> n) {
    string s[n];
    for(int i=0; i<n; i++) cin >> s[i];
    int d[10],c[10],f=1;
    memset(d,0,sizeof(d));
    memset(c,0,sizeof(c));
    for(int i=0; i<n; i++){
      if(s[i][0]==s[i][1]) c[s[i][0]-'0']++;
      else for(int j=0; j<2; j++) d[s[i][j]-'0']++;
    }
    int x=0;
    for(int i=0; i<10; i++) {
      if(c[i]&&!d[i]&&n!=1) f=0;
      if(d[i]%2) x++;
      if(x>2) f=0;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


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

int main(){
    int s,w;
    cin >> s >> w;
    
    if(s>w)cout << "safe" << endl;
    else cout << "unsafe" << endl;

	return 0;
}


Measured memory_bytes: 3632
def gcd(x,y):
   if x<=y:
     tmp=x
     x=y
     y=tmp
   r=x%y
   while(r!=0):
     x=y
     y=r
     r=x%y
   return y
a=input().split()
b=[int(i) for i in a]
print(gcd(b[0],b[1]))



Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=int64_t;

int main() {
  int N,x; cin >>N >>x;
  vector<int> a(N);
  vector<int> check(N);
  rep(i,0,N) {
    cin >>a[i];
    check[i]=a[i];
  }
  rep(i,0,N) {
    if (x<check[i]) check[i]=x;
  }
  rep(i,0,N-1) {
    if (x<check[i]+check[i+1]) check[i+1]=x-check[i];
  }
  ll ans=0;
  rep(i,0,N) {
    ans+=a[i]-check[i];
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
As =[list(map(int, input().split())) for _ in range(N)]
flag1 = False
ans = 0
for i in range(N):
    for j in range(i+1, N):
        flag2 = True
        for k in range(N):
            if k == i or k == j:
                continue
            if As[i][k]+As[k][j] < As[i][j]:
                flag1 = True
                break
            elif As[i][k]+As[k][j] == As[i][j]:
                flag2 = False
        if flag2:
            ans += As[i][j]
        if flag1:
            break
    if flag1:
        break
if not flag1:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 44252
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g){
	for(int i=g; i<n; i++){
		int v = A[i];
		int j = i-g;
		while(j>=0 && A[j]>v){
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n){
	for(int h=1; ; ){
		if(h>n) break;
		G.push_back(h);
		h = 3*h+1;
	}
	for(int i=G.size()-1; i>=0; i--){
		insertionSort(A, n, G[i]);
	}
}

int main() {
	cin >> n;
	for(int i=0; i<n; i++) scanf("%d", &A[i]);
	cnt = 0;
	
	shellSort(A, n);
	
	cout << G.size() << endl;
	for(int i=G.size()-1; i>=0; i--){
		printf("%d", G[i]);
		if(i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for(int i=0; i<n; i++) printf("%d\n", A[i]);
	return 0;
}


Measured memory_bytes: 7196