akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n, K, cnt;
char s[25][(1 << 20) + 5];
vector<int> v[25];
int dp[42000005];
int p0[25], p1[25];
int main()
{
	scanf("%d%d", &n, &K);
	for (int i = 0; i <= n; i++)
		scanf("%s", s[i]);
	for (int i = 1; i <= n; i++)
	{
		v[i].resize((i + 1) * (1 << i));
		int s = v[i].size();
		for (int j = 0; j < s; j++)
			v[i][j] = ++cnt;
	}
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < (1 << i); j++)
			if (s[i][j] == '1')
				dp[v[i][j * (i + 1) + i]]++;
    for (int i = n; i >= 1; i--)
	{
		for (int S = 0; S < (1 << i); S++)
		{
			p0[0] = -1, p1[0] = -1;
			for (int j = 0; j <= i; j++)
			{
				p1[j + 1] = p1[j];
				p0[j + 1] = p0[j];
				if (S & (1 << j))
					p1[j + 1] = j;
				else
					p0[j + 1] = j;
            }
			for (int j = i; j >= 0; j--)
			{
				int u = v[i][S * (i + 1) + j];
				int f = S >> j;
				if (dp[u])
				{
					if (p0[j] != -1)
					{
						int p = ((f << 1) << p0[j]) + (S & ((1 << p0[j]) - 1));
						int l = p0[j] + 1 + i - j;
						dp[v[l][p * (l + 1) + p0[j]]] += dp[u];
					}
                    if (p1[j] != -1)
					{
						int p = ((f << 1 | 1) << p1[j]) + (S & ((1 << p1[j]) - 1));
                        int l = p1[j] + 1 + i - j;
                        dp[v[l][p * (l + 1) + p1[j]]] += dp[u];
                    }
                    if (j != 0 && j != i)
					{
						int l = i - j;
						dp[v[l][f * (l + 1)]] += dp[u];
					}
				}
			}
		}
	}
	for (int i = n; i >= 1; i--)
	{
		for (int j = 0; j < (1 << i); j++)
		{
			if (dp[v[i][j * (i + 1)]] >= K)
			{
				for (int k = i - 1; k >= 0; k--)
					putchar('0' + ((j >> k) & 1));
				putchar(10);
				return 0;
			}
		}
	}
	putchar(10);
}


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

int main(){
	
	
	long long int D, T, S;

	cin >> D >> T >> S;

	cout << (T*S >= D ? "Yes" : "No");
 
 
	return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int n;
    cin >> n;

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

    int a, b, c;
    int ans = 0;
    for (int i = 1; i < n-1; i++) {
        a = p[i-1];
        b = p[i];
        c = p[i+1];

        if ((a <= b && b <= c) || (c <= b && b <= a)){
            ans++;
        }
    }

    cout << ans << endl;



    return;
}

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


Measured memory_bytes: 256
//nani?
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i,a,b) for( int i = a; i < b ; i++ )
#define sor(a) sort( a.begin(), a.end() )
#define rsor(a) sort( a.rbegin(), a.rend() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
//#define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
using namespace __gnu_pbds;
const int inf=1e7;
const ll MOD=1e9+7;
const ll mod=998244353;
// ac cmtr;
const int MAX_N = 1e5+5;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif
//---------------------------


int main(){
    fastio;
    ld n;
    cin>>n;
  	//ld a=acos(-1);
    
    ld ans = 2*(n)*pi;
    cout <<fixed <<setprecision(12)<<ans<<endl;
    
    
} 

Measured memory_bytes: 3788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		boolean card[][] = new boolean[4][13];
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int i = 0; i < n; i++){
			String suit = scan.next();
			int rank = scan.nextInt() - 1;
			switch(suit){
			case "S":
				card[0][rank] = true;
				break;
			case "H":
				card[1][rank] = true;
				break;
			case "C":
				card[2][rank] = true;
				break;
			case "D":
				card[3][rank] = true;
				break;
			}
		}
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 13; j++){
				if(!card[i][j]){
					switch(i){
					case 0:
						System.out.println("S " + (j + 1)); //?????£??????????????????j+1??¨?¨????????????¨???????????¨????????±?????????
						break;
					case 1:
						System.out.println("H " + (j + 1));
						break;
					case 2:
						System.out.println("C " + (j + 1));
						break;
					case 3:
						System.out.println("D " + (j + 1));
						break;
					}
				}
			}
		}
		//System.out.println();
	}
}

Measured memory_bytes: 26268
# -*- coding: utf-8 -*-
"""
Dictionary - Multi-Map
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_8_D&lang=jp

"""
from bisect import insort, bisect_right, bisect_left

class Multi_map:
    def __init__(self):
        self.mm = dict()
        self.lr = []

    def insert(self, x, y):
        if x in self.mm:
            self.mm[x].append(y)
        else:
            self.mm[x] = [y]
            insort(self.lr, x)

    def get(self, x):
        if x in self.mm and self.mm[x] != []:
            print(*self.mm[x], sep='\n')

    def delete(self, x):
        if x in self.mm:
            self.mm[x] = []

    def dump(self, l, r):
        lb = bisect_left(self.lr, l)
        ub = bisect_right(self.lr, r)
        for i in range(lb, ub):
            k = self.lr[i]
            for v in self.mm[k]:
                print(f'{k} {v}')


mm = Multi_map()
for _ in range(int(input())):
    op, x, y = (input() + ' 1').split()[:3]
    if op == '0':
        mm.insert(x, int(y))
    elif op == '1':
        mm.get(x)
    elif op == '2':
        mm.delete(x)
    else:
        mm.dump(x, y)



Measured memory_bytes: 36696
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N),B(N);
  priority_queue<pii> P,Q;
  rep(i,0,N){
    cin>>A[i]>>B[i];
    Q.push(mp(A[i]+B[i],i));
  }
  int ans=0;
  rep(i,0,N){
    int X=Q.top().first,Y=Q.top().second;
    Q.pop();
    if(i%2==0) ans+=A[Y];
    else ans-=B[Y];
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 3956
#include <stdio.h>
#define MAX 44
int main(){
  int n,i,F[MAX];
  scanf("%d",&n);
  F[0]=1;
  F[1]=1;
  for(i=2;i<=n;i++)
    F[i]=F[i-2]+F[i-1];
    printf("%d\n",F[n]);
  return 0;
}





Measured memory_bytes: 2100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;






int main(){
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        if(s.substr(i)+s.substr(0,i)==t){
            fin("Yes");
            return 0;
        }
    }
    fin("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,m,sum;
int E[20][20],p[140010],f[140010][20];
void update(int&x,const int&y){x=max(x,y);}
int main(){
	memset(f,-1,sizeof f);
	cin>>n>>m;
	for(int i=0,x,y,z;i<m;i++){
		cin>>x>>y>>z;
		x--,y--;
		E[x][y]=E[y][x]=z;
		sum+=z;
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++)if(i&(1<<j))
			for(int k=0;k<n;k++)if(i&(1<<k))
				p[i]+=E[j][k];
		p[i]>>=1;
	}
	f[1][0]=0;
	for(int i=1;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if (f[i][j]==-1)continue;
			for(int k=0;k<n;k++){
				if(i&(1<<k))continue;
				if(E[j][k]==0)continue;
				update(f[i|(1<<k)][k],f[i][j]+E[j][k]);
			}
			int revi=(((1<<n)-1)^i)|(1<<j);
			for(int k=revi;k;k=(k-1)&revi)update(f[i|k][j],f[i][j]+p[k]);
		}
	}
	int ans=0;
	for(int i=0;i<(1<<n);i++)update(ans,f[i][n-1]);
	cout<<(sum-ans)<<endl;
	return 0;
}


Measured memory_bytes: 11264
#include <iostream>

using namespace std;

int main(void){

    int a,b,c;
    
    cin >> a >> b;
    
    c = a + b;
    
    
    if(c < a * b) c = a * b;
    
    
    if(c < a - b) c = a - b;
    
    std::cout << c << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
while 1:
    n,a,b,c,x=map(int,input().split())
    if n==0:break
    y=list(map(int,input().split()))
    d=[0,1][x==y[0]]
    for i in range(10001):
        if d==n:print(i);break
        x=(a*x+b)%c
        if x==y[d]:d+=1
    else:print(-1)

Measured memory_bytes: 7572
import collections

N = int(input())
S = []
for _ in range(N):
    S.append(input())
M = int(input())
T = []
for _ in range(M):
    T.append(input())

count = collections.Counter()

for s in S:
    count[s] += 1
for t in T:
    count[t] -= 1
    
print(max(count.most_common(1)[0][1], 0))

Measured memory_bytes: 3316
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  ll length = 0;
  vec<int> A(N, 0);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  for(int i = 1; i < N; i++){
    if(A[i-1] <= A[i]){
      continue;
    }

    length += A[i-1]-A[i];
    A[i] = A[i-1];
  }
  cout << length << endl;
  return 0;
}


Measured memory_bytes: 3980
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n,k;
   cin>>n>>k;
   vector<long long int> v(n+1);
   for(int i=1;i<=n;i++)
   {
       cin>>v[i];
   }
       vector<int> vis(n+1,0);
       int pi=1;
       int g=-1;
       vector<long long int> s;
       while(true)
       {
           if(vis[pi]==1)
           {
           g=pi;      
           break;
           }
           s.push_back(pi);
           vis[pi]=1;
           pi=v[pi];
       }
       if(k<s.size())
       {
           cout<<s[k]<<endl;
       }
       else
       {
           int cn=0;
           for(int i=0;i<s.size();i++)
           {
               if(s[i]==g)
               break;
               cn++;
           }
           long long int ll=k-cn;
           ll=ll%(s.size()-cn);
           cout<<s[cn+ll]<<endl;
       }
}

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

int dp[4001][16001] = {};
int dpy[4001][16001] = {};

int main(){
    int x, y;
    string s;
    cin >> s;
    cin >> x >> y;
    vector<int> dx, dy;
    int sw = 0, cou = 0;
    
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'T'){
            if(sw == 1){
                dy.push_back(cou);
                cou = 0;
                sw = 0;
            }
            else{
                dx.push_back(cou);
                cou = 0;
                sw = 1;
            }
        }
        else{
            ++cou;
            if(i == s.length()-1){
                if(sw == 1){
                    dy.push_back(cou);
                    cou = 0;
                    sw = 0;
                }
                else{
                    dx.push_back(cou);
                    cou = 0;
                    sw = 1;
                }
            }
        }
    }

    dp[1][dx[0]+8000] = 1;
    for(int i = 1; i < dx.size(); i++){
        for(int j = 0; j < 16001; j++){
            if(dp[i][j] == 1){
                dp[i+1][j+dx[i]] = 1;
                dp[i+1][j-dx[i]] = 1;
            }
        }
    }

    dpy[0][8000] = 1;
    for(int i = 0; i < dy.size(); i++){
        for(int j = 0; j < 16001; j++){
            if(dpy[i][j] == 1){
                dpy[i+1][j+dy[i]] = 1;
                dpy[i+1][j-dy[i]] = 1;
            }
        }
    }
    if(dpy[dy.size()][y + 8000] ==1 && dp[dx.size()][x + 8000] == 1){
        cout << "Yes\n";
    }
    else    cout << "No\n";
}

Measured memory_bytes: 498048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1e9+7;
ll inv(ll a){
	return a==1?1:(ll)(M-M/a)*inv(M%a)%M;
}
void C(int r,int n){
	if(r>n-r) r=n-r;
	ll a1=1,a2=1;
	for(int i=0;i<r;i++){
		a1=a1*(n-i)%M;
		a2=a2*(i+1)%M;
	}
	cout << a1*inv(a2)%M << endl;
}
int main(){
	ll a,b;
	cin >> a >> b;
	if((a+b)%3!=0)
	cout << 0 << endl;
	else{
		ll x=(a+b)/3*2-a,y=a-(a+b)/3;
		if(x<0||y<0){
			cout << 0 << endl;
		}
		else{
			C(x,x+y);
		}
	}
	return 0;
}

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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int d;
    cin>>d;
    if(abs(a-c)<=d)cout<<"Yes"<<"\n";
   else if(abs(a-b)<=d&&abs(b-c)<=d)cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		D();
	}
	
	public static void A() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		int ret  = 0;
		for(int i=0;i<s.length();i++) {
			ret += Character.getNumericValue(s.charAt(i));
		}
		System.out.println(ret);
	}
	
	//0...M   2^M > 最小の要素 の範囲で 2^kで全て割り切れるかで２分探索 O(Nloglogminval)
	// 0...Mまで順に確かめると、O(Nlogminval)
	public static void B() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0;i<N;i++) {
			A[i] = sc.nextInt();
  		}
		int maxdo = -1;
		boolean cansep = true;
		while(cansep) {
			maxdo++;
			for(int j=0;j<A.length;j++) {
				int sep = (int) Math.pow(2, maxdo);
				if(A[j]%sep != 0) {
					cansep = false;
					break;  
				}
			}
		}
		System.out.println(maxdo-1);
	}

	//出現回数が少ないものから書き換えるHashMapで文字->頻度を保持、頻度でソートして下からN-K
	public static void C() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
		for(int i=0;i<N;i++) {
			int key = sc.nextInt();
			if(map.containsKey(key)) map.put(key,map.get(key)+1);
			else map.put(key,1);
		}
		sc.close();
		ArrayList<Integer> lis = new ArrayList<Integer>(map.values());
		Collections.sort(lis);
		int ret = 0;
		for(int i=0;i<map.keySet().size()-K;i++) {
			ret += lis.get(i);
		}
		System.out.println(ret);
	}
	// 絶対値最大の数が正　→　負の数を潰して、前から足してく。　負　→　正の数を潰して後ろから足してく
	public static void D() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<String> ret = new ArrayList<String>();
		long[] a = new long[N];
		long maxval = Long.MIN_VALUE;
		long minval = Long.MAX_VALUE;
		int maxvalidx = 0;
		int minvalidx = 0;
		for(int i=0;i<N;i++) {
			a[i] = sc.nextLong();
			if(minval > a[i]) {
				minval = a[i];
				minvalidx = i;
			}
			if(maxval < a[i]) {
				maxval = a[i];
				maxvalidx = i;
			}
		}
		long maxabsval = Math.abs(maxval)>Math.abs(minval)? maxval : minval;
		int maxabsvalidx = Math.abs(maxval)>Math.abs(minval)? maxvalidx : minvalidx;
		if(maxabsval >= 0) {
			for(int i=0; i<N;i++) {
				if(a[i]<0) {
					a[i]+=maxabsval;
					ret.add(maxabsvalidx+1 + " " + (i+1));
				}
			}
			for(int i=0;i<N-1;i++) {
				if(a[i+1] < a[i]) {
					a[i+1] += a[i];
					ret.add(i+1 + " " + (i+2));
				}
			}
		}
		else {
			for(int i=0;i<N;i++) {
				if(a[i]>0) {
					a[i] += maxabsval;
					ret.add(maxabsvalidx+1 + " " + (i+1));
				}
			}
			for(int i=N-2;i>=0;i--) {
				if(a[i+1] < a[i]) {
					a[i] += a[i+1];
					ret.add(i+2 + " " + (i+1));
				}
			}
		}
		System.out.println(ret.size());
		for(int i=0;i<ret.size();i++) {
			System.out.println(ret.get(i));
		}
	}
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
int main(){
  int n;
  int i,j;
  int countY=0;
  int count=0;
  
  cin >> n;
  
  rep1(i,n){
    rep1(j,i){
      if(i%2==0)
        continue;
      else if(i%j==0){
        countY++;
      }
    }
    if(countY==8){
      count++;
    }
    countY=0;
  }
  
  cout << count << endl;
}

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

template <typename tn> void read (tn & a) {
	tn x = 0, f = 1; char c = getchar();
	while (c < '0' || c > '9'){ if (c == '-') f = -1; c = getchar(); }
	while (c >= '0' && c <= '9'){ x = x * 10 + c - '0'; c = getchar(); }
	a = f == 1 ? x : -x;
}

const int MAXN = 101000;
ll n, l, ans;
int tr[MAXN][3], g[MAXN], gx;
string s;

void add () {
	int x = 1;
	rep(i, 0, (int)s.length() - 1) {
		if (!tr[x][s[i] - '0']) {
			tr[x][s[i] - '0'] = ++gx;
		}
		x = tr[x][s[i] - '0'];
		++g[x];
	}
}

void dfs(int x, int d) {
	if ((!tr[x][0]) && (!tr[x][1])) return;
	if (!tr[x][0]) ans ^= (l - d) & (d - l);
	if (!tr[x][1]) ans ^= (l - d) & (d - l);
	if (tr[x][0]) dfs(tr[x][0], d + 1);
	if (tr[x][1]) dfs(tr[x][1], d + 1);
}

int main() {
	cin >> n >> l;
	gx = 1;
	rep(i, 1, n) {
		cin >> s;
		add();
	}
	ans = 0;
	dfs(1, 0);
	if (ans) printf("Alice\n"); else printf("Bob\n");
	return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n;

char s[200010];
int cnt[3];

int dp[200010][3][3][3];
int dp2[200010][3][3][3];

const ll mod = 998244353;

int main()
{
	scanf("%s", s);
	n = strlen(s);
	
	if(n <= 4){
		set<string> vis;
		queue<string> q;
		q.push(s); vis.insert(s);
		while(q.size()){
			auto t=q.front(); q.pop();
			char tmp[10]; strcpy(tmp, t.c_str());
			for(int i=0; i<n-1; ++i){
				char a=tmp[i], b=tmp[i+1];
				if(a != b){
					char c = int('a')+'b'+'c'-a-b;
					tmp[i] = tmp[i+1] = c;
					if(vis.insert(tmp).second) q.push(tmp);
					tmp[i]=a; tmp[i+1]=b;
				}
			}
		}
		printf("%d\n", int(vis.size()));
		return 0;
	}
	
	for(int i=0; i<n; ++i) ++cnt[s[i]-'a'];
	
	if(cnt[0]==n || cnt[1]==n || cnt[2]==n){
		puts("1");
		return 0;
	}
	
	dp[1][1][1][0] = 1;
	dp[1][2][0][1] = 1;
	dp[1][0][2][2] = 1;
	
	dp2[1][1][1][0] = 1;
	dp2[1][2][0][1] = 1;
	dp2[1][0][2][2] = 1;
	
	
	for(int l=1; l<n; ++l){
		for(int va=0; va<3; ++va) for(int vb=0; vb<3; ++vb) for(int t=0; t<3; ++t){
			(dp[l+1][(va+1)%3][(vb+1)%3][0] += dp[l][va][vb][t]) %= mod;
			(dp[l+1][(va+2)%3][vb][1] += dp[l][va][vb][t]) %= mod;
			(dp[l+1][va][(vb+2)%3][2] += dp[l][va][vb][t]) %= mod;
			
			if(t!=0) (dp2[l+1][(va+1)%3][(vb+1)%3][0] += dp2[l][va][vb][t]) %= mod;
			if(t!=1) (dp2[l+1][(va+2)%3][vb][1] += dp2[l][va][vb][t]) %= mod;
			if(t!=2) (dp2[l+1][va][(vb+2)%3][2] += dp2[l][va][vb][t]) %= mod;
			
			
		}
	}
	
	int ka=(cnt[0]+2*cnt[1])%3, kb=(cnt[0]+2*cnt[2])%3;
	
	int ans = 1;
	for(int t=0; t<3; ++t){
		(ans += (dp[n][ka][kb][t] + mod-dp2[n][ka][kb][t]) % mod) %= mod;
	}
	
	for(int i=0; i+1<n; ++i) if(s[i]==s[i+1]){
		(ans += mod-1) %= mod;
		break;
	}
	
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 42624
import itertools

def main():
    N = int(input())
    
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    
    combi = list(itertools.permutations(range(1, N+1)))
    
    pi = 0
    qi = 0
    for i in range(len(combi)):
        if list(combi[i]) == P:
            pi = i + 1
        if list(combi[i]) == Q:
            qi = i + 1
            
            
    print(abs(qi - pi))
    
main()


Measured memory_bytes: 8052
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N;
  cin >> N;
  ll a[N];
  ll sum = 0, oddsum = 0;
  rep(i, N){
    cin >> a[i];
    sum += a[i];
    if(i%2) oddsum += a[i];
  }
  sum /= 2;
  int ans[N];
  ans[0] = sum - oddsum;
  for(int i=1; i<N; i++){
    ans[i] = a[i-1] - ans[i-1];
  }
  rep(i, N){
    ans[i] *= 2;
    cout << ans[i] << endl;
  }
 
}

Measured memory_bytes: 2432
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  set<int> st[26];
  string s;
  cin >> s;
  for (int i = 0; i < n; ++i) {
    st[s[i] - 'a'].insert(i);
  }
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int pos;
      char c;
      cin >> pos >> c;
      pos--;
      for (int i = 0; i < 26; ++i) {
        if (st[i].find(pos) != st[i].end()) {
          st[i].erase(pos);
        }
      }
      st[c - 'a'].insert(pos);
    } else {
      int l, r;
      cin >> l >> r;
      l--, r--;
      int ans = 0;
      for (int i = 0; i < 26; ++i) {
        auto it = st[i].lower_bound(l);
        if (it != st[i].end() && *it <= r) {
          ans++;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 24196
#include<bits/stdc++.h>
#define lg long long int
#define loop(i,s,e) for(lg i=s;i<=e;i++)
#define iloop(i,s,e) for(lg i=e;i>=s;i--)
#define pb push_back
#define mp make_pair
using namespace std;

lg min(lg a,lg b)
{return a<b?a:b;}
lg max(lg a,lg b)
{return a>b?a:b;}
lg lcm(lg a ,lg b)
{
    return (a*b)/__gcd(a,b);
}
int main()
{
    string a;
    cin>>a;
    /*
    vector<lg>a(n,0);
    for(lg i=0;i<n;i++)
        cin>>a[i];
    */
    lg n=a.length();
    lg ans=0;
    for(lg i=0;i<n;i++)
        ans+=a[i]-48;
    if(ans%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3724
#include <stdio.h>
#include <stdlib.h>
int main()
{   int n;
    scanf("%d",&n);
    if(n%2){
        printf("No");
        return 0;
    }
    char s[n+1];
    scanf("%s",s);
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[i+n/2]){
            printf("No");
            return 0;
        }
    }
    printf("Yes");

    return 0;
}


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

using namespace std;

using int64 = long long;

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

  int64 r, d, x;
  cin >> r >> d >> x;
  for (int i = 1; i <= 10; i++) {
    x = x * r - d;
    cout << x << endl;
  }
}


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

int main(){
    
    long long N;
    cin >> N;
    map<long long,long long> mp;
    long long cont = 0;
    long long A;
    for(long long i = 0; i < N;i++){
        
        cin >> A;
        if(mp[A] == 0){
            mp[A]++;
            cont++;
        }else{
            mp[A]--;
            cont--;
        }
    }
    
    cout << cont <<endl;
}

    
    



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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n,m;
	cin>>n>>m;
	vector<int> a(m);
	rep(i,m)cin>>a[i];
	int sum=accumulate(all(a),0);
	cout<<max(-1,n-sum)<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  
  int c = 1000;
  int f = -1;

  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == 'C' && i < c) c = i;
    if (s[i] == 'F' && f < i) f = i;
  }
  
  cout <<(c < f ? "Yes" : "No") << endl;

  return 0;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  string s;
  cin >> s;
  int n = sz(s);
  string ans = "AC";
  if (s[0] != 'A') ans = "WA";
  int cnt = 0;
  for (int i = 1; i < n; ++i) {
    if (isupper(s[i])) {
      if (i == 1 || i == n-1 || s[i] != 'C') ans = "WA";
      cnt++;
    }
  }
  if (cnt != 1) ans = "WA";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
A = sorted(int(input()) for i in range(n))
a = [0]*(n)
b = [0]*(n)
c = 1

for i in range(n-1):
    a[i] += -c
    a[i+1] += c
    b[i] += c
    b[i+1] += -c
    c *= -1
a.sort()
b.sort()
sum1,sum2 = 0,0
for i in range(n):
    sum1 += a[i] *A[i]
    sum2 += b[i] * A[i]
print(max(sum1,sum2))


Measured memory_bytes: 52952
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  ll n, x;
  scan(n, x);
  vll l(n);
  scan(l);
  ll d = 0;
  int cnt = 1;

  rep (i, n) {
    d += l[i];
    if (d <= x) {
      cnt += 1;
    } else {
      break;
    }
  }
  print(cnt);

  return 0;
}


Measured memory_bytes: 888
while True:
    n = int(input())
    if n==0: break
    a = [int(input()) for _ in range(n)]
    count = 0
    for i in range(n):
        for j in range(n)[:0:-1]:
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                count+=1
    print(count)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

class UnionFind{
    public:
    vector<int> par;
    vector<int> size;
    vector<int> rank;

    UnionFind(int n){
        REP(i,n){
            size.push_back(1);
            rank.push_back(0);
            par.push_back(i);
        }
    }

    int find(int x){
        if(x == par[x])
            return x;
        else
            return par[x] = find(par[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(rank[x] <= rank[y]){
            par[x] = y;
            size[y] += size[x];
            if(rank[x] == rank[y])
                rank[y]++;
        }
        else{
            par[y] = x;
            size[x] += size[y];
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    vector<ll> A(N);
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    int remain = 2*(N - M - 1);
    if(M == N-1){
        cout << 0 << endl;
        return 0;
    }
    else if(2*(N-M-1) > N){
        cout << "Impossible" << endl;
        return 0;
    }

    UnionFind uni(N);
    vector<int> X(N);
    vector<int> Y(N);
    REP(i,M){
        int x, y;
        cin >> x >> y;
        X[i] = x;
        Y[i] = y;
        uni.unite(x,y);
    }

    typedef pair<ll, int> ver;
    typedef priority_queue<ver, vector<ver>, greater<ver>> PQ;
    //map<int, pair<ll, int>> ma;
    map<int, PQ> mama;
    REP(i,M){
        int x, y;
        x = X[i];
        y = Y[i];
        ll ax = A[x];
        ll ay = A[y];
        int par = uni.find(x);
        mama[par].push(make_pair(ax, x));
        mama[par].push(make_pair(ay, y));
    }

    ll ans = 0;
    vector<bool> used(N, false);
    //for(auto&& p : mama){
    //    auto pq = p.second;
    //    auto x = pq.top();
    //    ll a = x.first;
    //    int idx = x.second;
    //    used[idx] = true;
    //    ans += a;
    //    remain--;
    //}
    REP(i,N){
        if(i != uni.find(i)) continue;
        auto pq = mama[i];
        if(pq.size() == 0){
            ll a = A[i];
            used[i] = true;
            ans += a;
            remain--;
        }
        else{
            auto x = pq.top();
            ll a = x.first;
            int idx = x.second;
            used[idx] = true;
            ans += a;
            remain--;
        }
    }

    priority_queue<ll, vector<ll>, greater<ll>> que;
    REP(i,N){
        if(used[i]) continue;
        ll a = A[i];
        que.push(a);
    }

    while(remain > 0){
        remain--;
        ll a = que.top();
        que.pop();
        ans += a;
    }


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


Measured memory_bytes: 9964
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cassert>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

typedef std::pair <int, int> pii;
typedef long long ll;
typedef std::vector <ll> vll;

using namespace std;

ll add(ll a, ll b) {
	return (a + b) % MOD;
}
ll mul(ll a, ll b) {
	return (a * b) % MOD;
}
ll modPow(ll a, ll b) {
	if (b < 0) return 1;
	ll ans = 1;
	while (b) {
		if (b & 1) ans = mul(ans, a);
		a = mul(a, a);
		b >>= 1;
	}
	return ans;
}
ll dp2[100][100];
ll dp1[100];
ll arr[100];
int n;

ll solve(int s, int e) {
	if (s > e) return 1;
	if (s == e) return modPow(2, arr[s]);
	int len = e - s + 1;
	ll tmp[100];
	for (int i = s; i <= e; i++) tmp[i - s] = arr[i];
	for (int i = 0; i < len; i++) for (int j = 0; j < len; j++) dp1[i] = dp2[i][j] = 0;
	dp1[0] = modPow(2, tmp[0]);
	for (int i = 0; i < len; i++) {
		if (tmp[i] <= tmp[0]) dp2[0][i] = mul(modPow(2, tmp[0] - tmp[i]), 2);
		else dp2[0][i] = 2;
	}
	for (int i = 1; i < len; i++) {
		if (tmp[i] >= tmp[i - 1]) {
			dp1[i] = mul(dp2[i - 1][i - 1], modPow(2, tmp[i] - tmp[i - 1]));
			dp1[i] = add(dp1[i], mul(dp1[i - 1], modPow(2, tmp[i] - tmp[i - 1])));
		} else 
			dp1[i] = add(dp1[i - 1], dp2[i - 1][i]);
		for (int j = i; j < len; j++) {
			if (tmp[i] >= tmp[j]) {
				if (tmp[i - 1] <= tmp[i]) {
					dp2[i][j] = mul(add(dp2[i - 1][i - 1], dp2[i - 1][j]), 
						modPow(2, tmp[i] - max(tmp[i - 1], tmp[j])));
				} else {
					dp2[i][j] = add(dp2[i - 1][j], dp2[i - 1][i]);
				}
			} else {
				dp2[i][j] = mul(2, dp2[i - 1][i]);
			}
		}
	}
	/*
	for (int i = 0; i < len; i++) {
		cout << dp1[i] << endl;
		for (int j = i; j < len; j++) cout << dp2[i][j] << " ";
		cout << endl << "------------" << endl;
	}*/
	return dp1[len - 1];
}

int main() {
	int t;
	t = 1;
	while (t--) {
		for (int i = 0; i < 100; i++) {
			dp1[i] = 0;
			arr[i] = 0;
			for (int j = 0; j < 100; j++) dp2[i][j] = 0;
		}
	cin >> n;
	for (int i = 0; i < n; i++) cin >> arr[i];
	ll ans = 1;
	int prev = 0;
	for (int i = 0; i < n; i++) {
		if (arr[i] == 1) {
			ans = mul(ans, solve(prev, i - 1));
			ans = mul(ans, 2);
			prev = i + 1;
		}
	}
	ans = mul(ans, solve(prev, n - 1));
	cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N,M;
	cin>>N>>M;
	vector<ip> in(M);
	rep(i,M){
		cin>>in[i].first>>in[i].second;
	}
	int start = 1 * pow(10,N-1);
	if(start ==1)start = 0;
	int end = pow(10,N)-1;
	int ans = -1;
	// cout<<start<<' '<<end<<endl;
	for(; start<=end; ++start){
		bool ok = true;
		// cout<<"----"<<endl;
		rep(i,M){
			int digit = start/(int)pow(10,N-in[i].first)%10;
			// cout<<(int)pow(10,N-in[i].first)<<endl;
			if(digit != in[i].second) ok = false;
		}
		// cout<<"----"<<endl;
		if(ok){ans = start; break;}
	}	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N, Y = [int(x) for x in input().split()]

flag = False

for i in range(N + 1):
	for j in range(N + 1 - i):
		if 9000 * i + 4000 * j == Y - 1000 * N:
			z = N - i - j
			if z >= 0:
				x = i
				y = j
				flag = True
				break
	if flag:
		break
	if i == N:
		x = -1
		y = -1
		z = -1

print('{0} {1} {2}'.format(x, y, z))

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

#define Solved int main()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define forn(i, n) for(int i = 1; i <= n; i++)
#define rep(i, x, y) for(int i = x; i <= y; i++)
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define ll long long
#define ull unsigned long long
#define ld long double
#define mii map<int, int>
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound
using namespace std;

inline ll bip(ll x,ll n,ll mod){ll res=1;while(n){if(n&1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}

const int maxn = 1e9;
const ll inf = 1e18;
//const int mod = 998244353;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;

int n;
double p[3001];
double dp[3001][3001];

void solve() {
    cin >> n;

    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
        cin >> p[i];

    dp[1][0] = (1 - p[1]);
    for (int i = 2; i <= n; i++)
        dp[i][0] = (1 - p[i]) * dp[i - 1][0];

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            //dp[i][j] = max(p[i] * dp[i - 1][j - 1], (i > 1 ? dp[i - 1][j] : 0));
            dp[i][j] = p[i] * dp[i - 1][j - 1] + dp[i - 1][j] * (1 - p[i]);
            //cout << dp[i][j] << ' ';
        }
        //cout << endl;
    }
    //return;
    double ans = 0;
    //for (int i = 1; i <= n; i++)
        for (int j = n / 2 + 1; j <= n; j++)
            ans += dp[n][j];

    cout << fixed << setprecision(9) << ans;

}

Solved {
    SpeedForce;
	int tt = 1;
    //cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
	}

}


Measured memory_bytes: 68992
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 105;

int w[N], v[N];
int dp[N][100005];

signed main(){
    IOS;
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            dp[i][j] = dp[i-1][j];
            if (j - w[i] >= 0)
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
        }
    }
    cout << dp[n][k] << endl;
    return 0;
}

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

int main(void){
  int a, b;
  
  cin >> a >> b;
  if( (a * b) % 2 == 0){
    cout << "Even" << endl;
  }else{
    cout << "Odd" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int digSum(int num) {
	int sum = 0;
	while (num != 0) {
		sum += num % 10;
		num /= 10;
	}
	return sum;
}
int main() {
	int n, a, b, s, ans = 0;
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 1; i <= n; i++) {
		s = digSum(i);
		if (a <= s && s <= b) {
			ans += i;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    A, B = map(int, input().split())

    if A >= 13:
        ans = B
    elif 6 <= A and A <= 12:
        ans = B // 2
    else:
        ans = 0
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
a, b, c, d, e, f = map(int, input().split())
density = 0
for water_a in range(0,3001,a * 100):
    for water_b in range(0,3001,b * 100):
        if water_a + water_b > f:
            break
        for suger_c in range(0,3001,c):
            if water_a + water_b + suger_c > f:
                break
            for suger_d in range(0,3001,d):
                if water_a + water_b + suger_c + suger_d > f:
                    break
                if e * (water_a + water_b) - 100 * (suger_c + suger_d) < 0:
                    break
                water = water_a + water_b
                suger = suger_c + suger_d
                if water + suger == 0:
                    break
                if 1 >= suger / (water + suger) >= density:
                    sugerwater = water + suger
                    meltsuger = suger
                    density = suger / (water + suger)
print(sugerwater, meltsuger)

Measured memory_bytes: 3064
#include <stdio.h>

int fib (int);

int main () {
  int n;

  scanf("%d", &n);
  printf("%d\n", fib(n));

  return 0;
}

int fib (int n) {
  int f[n], i;

  f[0] = 1;
  f[1] = 1;
  for(i = 2 ; i <= n ; i++) {
    f[i] = f[i-2] + f[i-1];
  }
  return f[n];
}

Measured memory_bytes: 596
#include <iostream>
using namespace std;
int main()
{
    string s; cin >> s;
    bool easy = true;
    for (int i = 0; i < s.length(); i+=2) 
    {
        if(s[i] == 'L'){easy = false;}
    }
    for (int i = 1; i < s.length(); i+=2)
    {
        if(s[i] == 'R'){easy = false;}
    }
    if(easy){cout <<"Yes" << "\n";}
    else {cout << "No" << "\n";}
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

LL cal(LL n) {
   LL tmp = n % 4;
   if (tmp == 0) return n;
   else if (tmp == 1) return 1;
   else if (tmp == 2) return n + 1;
   else return 0;
}

int main() {
    LL A, B;
    scanf("%lld %lld", &A, &B);
    printf("%lld\n", cal(B) ^ cal(A) ^ A);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define int long long
#define rep(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
using namespace std; 

signed main() {
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  rep(i, 0, N) cin >> w[i] >> v[i];
  
  vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0));
  rep(i, 1, N + 1) {
    rep(j, 0, W + 1) {
      dp[i][j] = dp[i - 1][j];
      if (w[i - 1] <= j) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
    }
  }
  
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
typedef  long long   ll;
ll inf=1000000000000000000,mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
       
        ll x;cin>>x;ll num1,num2;
        for(ll i=-3990;i<=3990;i++){
            for(ll j=-3990;j<=3990;j++){
                num1=i*i*i*i*i;
                num2=j*j*j*j*j;
                if(num1-num2==x){
                    cout<<i<<" "<<j;return 0;
                }
            }
        }


}


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

int cmpnum(const void * n1, const void * n2)
{
	if (*(int *)n1 > *(int *)n2)
	{
		return 1;
	}
	else if (*(int *)n1 < *(int *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void)
{
	int i,n,t,a,b;
	scanf("%d",&n);
	int x[n];
	int y[n];
	for(i=0;i<n;i++){
		scanf("%d",&t);
		x[i]=t;
		y[i]=t;
	}
		
	qsort(x, sizeof(x) / sizeof(x[0]), sizeof(int), cmpnum);

	a=x[n/2-1];
	b=x[n/2];
	
	for(i=0;i<n;i++){
		if(y[i]<=a)
			printf("%d\n",b);
		else
			printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 3692