akhauriyash/Code-Regression huggingface dataset:
/**
 *    Author:  "Robin Singh" !!!!    
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define szz(v) ((int)(v).size())  
#define vi vector<int>
#define vll vector<ll>
#define fr(i, j, k) for(i = j; i < k; i++)
#define bk(i, j, k) for(i = j; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0 //
#define rtn return 
#define time fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC)
#define nl "\n"
#define INF 1LL<<61
#define inf 1<<31
#define dbg(x) (cerr << #x << ": " << x << "\n")
const long long mod = 998244353;

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }

const int nn = 3e5+10;
ll fact[nn], ifact[nn];

ll ncr(ll N, ll r)
{
    ll res;
    res = ( ( (fact[N] * ifact[r]) %mod )* ifact[N-r] )%mod;
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll N, A, B, K, ans = 0;
    cin >> N >> A >> B >> K;
    
    fact[0] = 1;
    for(int i=1; i<=N; i++)
    {
        fact[i] = (fact[i-1]*i)%mod;
    }
    
    // TO calculate inverse modulus of factorial in O(N) instead of O(NlogN)
    
    ifact[N] = expo(fact[N], mod-2);
    for(int i = N-1; i>=0; i--)
        ifact[i] = ifact[i+1]*(i+1) % mod;
    
    //////////////
    
    for(int a=0; a<=N; a++)               // A*a + B*b == K
    {
        if(K - a*A < 0) break;
        if( (K-A*a) % B == 0)
        {
            int b = (K - A*a)/B;
            if(b <= N)
                ans = (ans + ncr(N,a)*ncr(N,b))%mod;
        }
    }
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	vec p;
	int n;
	cin>>n;
	p.resize(n);
	rep(i,0,n)cin>>p[i];
	sort(all(p));
	reverse(all(p));
	int ans=0;
	ans+=p[0]/2;
	rep(i,1,n)ans+=p[i];
	cout<<ans<<endl; 
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

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

    string S;
    cin >> S;
    int N = sz(S);
    int ans = N;
    rep(i, N - 1) {
        if (S[i] != S[i + 1]) {
            smin(ans, max(i + 1, N - 1 - i));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
N=int(input())
S=input()

acc_e=[0]
acc_w=[0]
for i in S:
  acc_e.append(acc_e[-1])
  acc_w.append(acc_w[-1])
  if i=='E':
    acc_e[-1]+=1
  else:
    acc_w[-1]+=1

ans=N
for i in range(N):
  turn=acc_w[i]+acc_e[-1]-acc_e[i+1]
  ans=min(ans,turn)
print(ans)

Measured memory_bytes: 17644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;


int main(){
   string s, t, u;
   int a, b;
   cin >> s >> t >> a >> b >> u;
   map<string, int> mp;
   mp[s]=a;
   mp[t]=b;
   mp[u]--;
   cout << mp[s] << " " << mp[t] << endl;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}

#[fastout]
fn main() {
  input!{
    n: usize
  };
  if n % 1000 == 0 {
    echo!(0);
  } else {
    echo!(1000 - n % 1000);
  }
}


Measured memory_bytes: 2160
#include<stdio.h>
int main(){
  int a[10000],i,j,temp;
  for(i=0;i<10;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<10;i++){
    for(j=0;j<9;j++){
      if(a[j]<a[j+1]){
	temp=a[j];
	a[j]=a[j+1];
	a[j+1]=temp;
      }
    }
  }
  printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	int min, max;
	int a;

	cin >> min;
	max = min;
	for (int i = 1; i < N; i++) {
		cin >> a;
		if (a > max) max = a;
		if (a < min) min = a;
	}
	cout << max - min << endl;
}

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

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

int main(){
    int N;
    cin >> N;
    int A[N];
    long long sum = 0;
    long long B[N]= {};
    rep(i,N){
        cin >> A[i];
        sum += A[i];
    }
    long long sumA = 0;
    for(int i=1;i<N;i+=2){
        sumA += A[i];
    }
    B[0] = sum - 2 * sumA;
    cout << B[0] << " ";
    for(int i=1;i<N;i++){
        B[i] = 2 * A[i-1] - B[i-1];
        cout << B[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 2432
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

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

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

//	for priority queue
//	priority_queue<ipair, vector<ipair>, greater<ipair>>
using ipair = pair<int, pair<int, int>>;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; };
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };

int main()
{
	string t;
	cin >> t;
	bool p = false;
	for (int i = 0; i < t.length(); i++)
	{
		if (t[i] == '?')
			printf("D");
		else
			printf("%c", t[i]);
		continue;
		
		char c = ' ';
		if (t[i] == 'D')
			p = false, c = 'D';
		else if (t[i] == 'P')
			p = true, c = 'P';
		else
		{
			if (i == t.length() - 1)
				c = 'D';
			else if (p)
				c = 'D', p = false;
			else
				c = 'P', p = true;
		}
		printf("%c", c);
	}

	return 0;
}


Measured memory_bytes: 3384
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
using ll = long long;
// (h, w) or (magic, dist)
using pii = pair<int, int>;

int main(void)
{
    int H, W;
    cin >> H >> W;

    int Ch, Cw;
    cin >> Ch >> Cw;
    Ch--;
    Cw--;

    pii start = {Ch, Cw};

    int Dh, Dw;
    cin >> Dh >> Dw;
    Dh--;
    Dw--;

    pii goal = {Dh, Dw};

    vector<string> s(H);

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

    vector<vector<pii>> cost(H, vector<pii>(W, {INF, INF}));
    deque<pii> que;
    cost[start.first][start.second] = {0, 0};
    que.push_back(start);

    while (!que.empty())
    {
        pii current = que.front();
        que.pop_front();

        int h_s = max(0, current.first - 2);
        int h_e = min(H - 1, current.first + 2);

        int w_s = max(0, current.second - 2);
        int w_e = min(W - 1, current.second + 2);

        for (int h = h_s; h <= h_e; h++)
        {
            for (int w = w_s; w <= w_e; w++)
            {
                if(h == current.first && w == current.second) continue;

                if (s[h][w] == '#')
                    continue;
                    
                if ((abs(h - current.first) == 0 && abs(w - current.second) == 1) || (abs(h - current.first) == 1 && abs(w - current.second) == 0))
                {
                    if(cost[h][w].first > cost[current.first][current.second].first){
                        cost[h][w].first = cost[current.first][current.second].first;
                        cost[h][w].second = cost[current.first][current.second].second + 1;
                        que.push_front({h,w});
                    }
                }
                else
                {
                    if (cost[h][w].first > cost[current.first][current.second].first + 1)
                    {
                        cost[h][w].first = cost[current.first][current.second].first + 1;
                        cost[h][w].second = cost[current.first][current.second].second;
                        que.push_back({h,w});
                    }
                }
            }
        }
    }

    if (cost[goal.first][goal.second].first == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << cost[goal.first][goal.second].first << endl;
    }

    return 0;
}


Measured memory_bytes: 13428
list=[0 for i in range(10**4+1)]
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            var=x**2 +y**2 +z**2 +x*y +y*z +z*x
            if var<=10**4:
                list[var]+=1
            
n=int(input())
for i in range(1,n+1):
    print(list[i])

Measured memory_bytes: 9164
#include <bits/stdc++.h>
#define MAXN 200100
#define pii pair<int, int>
#define pb push_back
#define se second
#define fi first
typedef long long ll;

using namespace std;

ll h, w, n, mod = 1e9 + 7, dp[MAXN];

ll fexp(ll a, int x, ll mod){		// Fast exponenciation returns a^x % mod
	if(x==0)return 1ll;
	if(x%2==0){
		ll y=fexp(a, x/2, mod);
		return (y*y)%mod;
	}
	return (a*fexp(a, x-1, mod))%mod;
}

ll f[MAXN], inv[MAXN];
ll divv(ll a, ll b, ll mod){	// Division with mod returns a/b % mod
	return (a*fexp(b, mod-2, mod))%mod;
}


ll choose(ll n, ll k, ll mod){	// Returns n choose k % mod
	return (f[n]*((inv[k]*inv[n-k])%mod))%mod;
}

ll g(pii a, pii b){
	return choose(b.se - a.se + b.fi - a.fi, b.fi - a.fi, mod);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> h >> w >> n;
    f[0] = inv[0] = 1;
    for(int i = 1; i < MAXN; i++){
    	f[i] = f[i - 1] * i;
    	f[i] %= mod;
    	inv[i] = divv(1, f[i], mod);
    }
    vector<pii> v;
    for(int i = 0; i < n; i++){
    	int a, b;
    	cin >> a >> b;
    	v.pb({a, b});
    }
    v.pb({h, w});
    sort(v.begin(), v.end());
    for(int i = 0; i <= n; i++)
    	dp[i] = g({1, 1}, v[i]);
    for(int i = 0; i <= n; i++){
		dp[i] %= mod;
		while(dp[i] < 0) dp[i] += mod;
    	for(int j = i + 1; j <= n; j++){
    		if(v[j].fi < v[i].fi or v[j].se < v[i].se) continue;
    		dp[j] -= (dp[i] * g(v[i], v[j])) % mod;
    	}
    }
    cout << dp[n];
}

Measured memory_bytes: 4352
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, x = map(int, read().split())
a, b = [1], [1]
for i in range(n):
    a.append(a[i] * 2 + 3)
    b.append(b[i] * 2 + 1)


def check(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n - 1]:
        return check(n - 1, x - 1)
    else:
        return b[n - 1] + check(n - 1, x - 2 - a[n - 1]) + 1


print(check(n, x))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M,Q;
    cin >> N >> M >> Q;
    int cnt[N][N];
    rep(i,0,N)rep(j,0,N)cnt[i][j] = 0;
    rep(i,0,M){
        int a,b;
        cin >> a >> b;
        cnt[a-1][b-1]++;
    }
    for(int i = N-1;i >= 0;i--){
        rep(j,i,N-1){
            cnt[i][j+1] += cnt[i][j];
        }
    }
    for(int i = N-1;i > 0;i--){
        rep(j,0,N){
            cnt[i-1][j] += cnt[i][j];
        }
    }
    rep(i,0,Q){
        int l,r;
        cin >> l >> r;
        cout << cnt[l-1][r-1] << endl;
    }
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
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--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

LL n,k,ans;

int main()
{
    cin>>n>>k;
    ans = n/2+n%2 - k;
    cout<< (ans>=0 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],arr1[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	long long x,n,i,j,k,y,z,a,b;   
    cin>>x>>n;
    for (i=0;i<n;i++)
    {
    	cin>>arr[i];
    	arr1[arr[i]]=1;
	}
	y=100000000000;
	a=555;
	for (i=0;i<=500;i++)
	{
		if (arr1[i]==0)
		{
			z=abs(x-i);
			if (z<y)
			{
				a=i;
				y=z;
			}
		}
	}
	cout<<a<<endl;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p.at(i);
    sort(p.begin(), p.end());
    int sum = 0;
    for (int i = 0; i < k; i++){
        sum += p[i];
    }
    cout << sum << endl;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  vll a(n);
  REP(i, n)
    cin >> a[i];

  map<ll, ll> m;
  REP(i, n)
    m[a[i]] = i;

  sort(a.begin(), a.end());
  ll ans = 0;
  REP(i, n){
    if(i%2 != m[a[i]]%2)
      ans++;
  }

  cout << ans/2 << endl;

}


Measured memory_bytes: 7296
#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[]) {
  char s[11];
  int i,piv=0;
  char ans[11];

  memset(s, '\0', 11);
  memset(ans, '\0', 11);

  scanf("%s", s);
  //printf("%lu\n",strlen(s) );
  for(i=0;i < strlen(s); i++){
    if( s[i] == 'B' ){
      if(piv != 0) piv--;
      ans[piv] = '\0';
    }else{
      ans[piv++] = s[i];
    }
  }

  printf("%s\n",ans );


  return 0;
}


Measured memory_bytes: 128
<?php
$s=trim(fgets(STDIN));
$n=strlen($s);
$k=trim(fgets(STDIN));
$i=0;
$c=0;
while($s[$i]==1){
  ++$c;
  ++$i;
}
if($c>=$k){
  echo 1;
}else{
  echo $s[$c];
}

Measured memory_bytes: 4728
N, M, C = map(int,input().split())
B = list(map(int,input().split()))
cnt = 0
for _ in range(N):
    ans = 0
    A = list(map(int,input().split()))
    for i in range(M):
        ans += A[i] * B[i]
    ans += C
    if ans > 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    ls = list("0123456789")
    for i in range(len(s)):
        if i == a:
            if s[i] != "-":
                print("No")
                exit()
        else:
            if s[i] not in ls:
                print("No")
                exit()
    print("Yes")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b == 15)cout << "+";
	else if (a*b == 15) cout << "*";
	else cout << "x";
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<cstdio>
int main(void){
  int n, r, p, c;
  int card[64], w[64];
  for( ; ; ){
    scanf("%d %d", &n, &r);
    if(!(n + r)) break;
    for(int i = 1;i <= n; i++) card[n - (i - 1)] = i;
    for(int j = 0;j < r; j++){
      scanf("%d %d", &p, &c);
      for(int i = 1;i <= n; i++) w[i] = card[i];
      for(int i = c + 1;i < c + p; i++) card[i] = w[i - c];
      for(int i = 1;i <= c; i++) card[i] = w[i + p - 1];
    }
    printf("%d\n", card[1]);
  }
}


Measured memory_bytes: 1028
#!/usr/bin/env python3
import sys


def solve(n: int, v: "List[int]"):
    counts = [{}, {}]
    for i in range(n):
        if v[i] in counts[i % 2]:
            counts[i % 2][v[i]] += 1
        else:
            counts[i % 2][v[i]] = 1
    l1 = list(counts[0].items()) + [(-1, 0)]
    l2 = list(counts[1].items()) + [(-1, 0)]
    l1.sort(reverse=True, key=lambda x: x[1])
    l2.sort(reverse=True, key=lambda x: x[1])
    #print(l1)
    #print(l2)
    tmp = 0
    if l1[0][0] == l2[0][0]:
        tmp = max(l1[0][1] + l2[1][1], l1[1][1] + l2[0][1])
    else:
        tmp = l1[0][1] + l2[0][1]
    ret = n - tmp
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int i = 0;
  while(i+1<s.size()){
    if(s[i]==s[i+1]){
      s.erase(s.begin()+i+1);
    }
    else i+=1;
  }
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 512
k=int(input())
x=input()
x0=x.split()
a=int(x0[0])
b=int(x0[1])
q=0
for i in range(a,b+1):
    if i%k==0:
        q=1
if q==1:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 8972
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	string s;
	string res = "0";
	bool found;
	cin >> s;
	for(char c = 'a'; c <= 'z'; c++){
		found = true;
		for(int i = 0; i < s.length(); i++){
			if(s[i] == c) found = false;
		}
		if(found){
			res = c;
			break;
		}
	}
	if(res == "0") res = "None";
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int h[100010];
int dp[100010];

int main()
{
	int N, K;

	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
		dp[i + 1] = mod;
	}
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 1; j <= K; j++) {
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[j + i] - h[i]));
		}
	}
	cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1024
import math
N = int(input())
max_num = 0
for v in range(1,int(math.sqrt(N))+1):
    if N % v == 0:
        max_num = max(max_num,v)
n = N // max_num

c_n = max(max_num,n)

res = 0

while 0 < c_n:
    c_n //= 10
    res += 1
print(res)

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

using namespace std;

int main()
{
    int a , b ;
    cin>>a>>b ;
    int ans = b ;
    if(a < 13)
        ans /= 2 ;
    if(a < 6)
        ans = 0 ;
    return cout<<ans<<"\n" , 0 ;
}


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

int	main()
{
  int		n, d, counter = 0;
  double	sq;
  
  cin >> n >> d;
  vector<vector<int>>	vv(n, vector<int>(d));
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < d; j++)
    {
      cin >> vv.at(i).at(j);
    }
  }
  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
	  sq = 0;
      for (int k = 0; k < d; k++)
      {
        sq += pow(vv.at(i).at(k) - vv.at(j).at(k), 2);
      }
      if (sq - pow(floor(sqrt(sq)), 2) == 0)
        counter++;
    }
  }
  cout << counter << endl;
  return (0);
}

  

Measured memory_bytes: 3604
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        p: [usize; n],
    }
    let mut result = 1;
    let mut min = p[0];
    for i in 1..n {
        if p[i] < min {
            result += 1;
            min = p[i];
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	for(ll i=i;i<=3500;i++){
		for(ll j=1;j<=3500;j++){
			ll up=n*i*j;
			ll down=4*i*j-n*i-n*j;
			if(down<=0){
				continue;
			}
			if(up%down==0){
				if(up/down!=0){
				cout << i<< " "<< j<<" "<<up/down;
				return 0;
				}
			}
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(r) do{cout<<#r": ";for(const auto &i:r){cout<<i<<" ";}cout<<endl;}while(0)
int main()
{
    int N; cin >> N;
    cout << "ABC" << N << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

class BIT
{
public:
	std::vector<LL>bit;
	void init(LL n)
	{
		bit.resize(n + 1, 0);
	}
	LL sum(LL i)
	{
		if (!i) return 0;
		return bit[i] + sum(i - (i&-i));
	}
	void add(LL i, LL x)
	{
		if (i >= (LL)bit.size()) return;
		bit[i] += x;
		add(i + (i&-i), x);
	}
};

LL N;
std::vector<LL>a, a_sorted;

bool check(LL x)
{
	std::vector<LL>imos(N + 1, 0);
	BIT bit;
	LL cnt = 0;
	bit.init(2 * (N + 1));
	rep(i, N)
	{
		if (a[i] >= x) imos[i + 1] = 1;
		else imos[i + 1] = -1;
	}
	rep(i, N) imos[i + 1] += imos[i];
	for (LL i = 0; i <= N; ++i)
	{
		cnt += bit.sum(imos[i] + N);
		bit.add(imos[i] + N, 1);
	}
	return cnt >= N * (N + 1) / 4;
}

int main()
{
	in >> N;
	a.resize(N);
	rep(i, N) in >> a[i];
	a_sorted = a;
	std::sort(a_sorted.begin(), a_sorted.end());
	LL left = 0, right = N;
	while (right - left > 1)
	{
		LL mid = (left + right) / 2;
		if (check(a_sorted[mid])) left = mid;
		else right = mid;
	}
	out << a_sorted[left] << std::endl;
	return 0;
}


Measured memory_bytes: 4192
#include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 2e5 + 9, M = 1e7 + 9, OO = 1e9 + 7, MOD = 1e9 + 7, MOD2 = 998244353;
const ll INF = 1e18;

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	string str;
	cin >> str;
	if(str[2] == str[3] && str[4] == str[5]) {
		cout << "Yes";
	} else
		cout << "No";
	return 0;
}


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

const int MAXN = 3e3+5;
const int MAXNN = 1e5+7;
const int INF = 1e9+7;
#define ll long long
#define pb push_back
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

ll MOD(ll a){
    return ((a%INF)+INF)%INF;
}

ll inv(ll a){
    return poww(a,INF-2,INF);
}

ll dp[MAXN][MAXN][2],a[MAXN];

int main()
{
    fast_io;
    //cout << fixed << setprecision(15);

    int n;cin >> n;
    for(int i=1;i<=n;++i){
        cin >> a[i];
    }
    for(int l=n;l>=1;--l){
        for(int r=l;r<=n;++r){
            dp[l][r][0] = max(dp[l+1][r][1] + a[l],dp[l][r-1][1] + a[r]);
            dp[l][r][1] = min(dp[l+1][r][0] - a[l],dp[l][r-1][0] - a[r]);
        }
    }
    cout << dp[1][n][0];
}


Measured memory_bytes: 139648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int a,b; cin >> a >> b;
    if(a<=b) cout<<a<<endl;
    else cout<<a-1<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, a[10], sum=0;
    cin >> n;
    REP(i,n) cin >> a[i];
    sort(a,a+n);
    REP(i,n-1) sum += a[i];
    cout << (sum > a[n-1]?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
while gets do
  str = $_.chomp
  alp = ('a'..'z').to_a

  26.times do |i|
    break if str =~/the|that|this/
    str.length.times do |j|
      next if str[j] !~ /[a-z]/
      str[j] = alp[(alp.index(str[j])+1)%26]
    end
  end

  puts str
end

Measured memory_bytes: 6104
import java.util.Scanner;

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

        int H = scanner.nextInt();
        int W = scanner.nextInt();
        int K = scanner.nextInt();

        char[][] board = new char[H][W];

        for (int i = 0 ; i < H ; i++) {
            board[i] = scanner.next().toCharArray();
        }

        int answer = 0;
        for (int i = 0 ; i < 1 << (H + W) ; i++) {
            int count = 0;
            for (int j = 0 ; j < H ; j++) {
                if (((i >> j) & 1) != 1) {
                    for (int k = 0 ; k < W ; k++) {
                        if (((i >> (H + k)) & 1) != 1) {
                            if (board[j][k] == '#') {
                                count++;
                            }
                        }
                    }
                }
            }
            if (count == K) {
                answer++;
            }
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 36188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;


int main() {
    fast_io
    int k;
    cin >> k;

    queue<ll> q;
    rep(i,9) {
        q.push (i+1);
    }
    ll x;
    rep(i,k) {
        x = q.front();
        q.pop();
        if (x % 10 != 0) q.push(x*10 + x%10 - 1);
        q.push(x*10 + x%10);
        if (x % 10 != 9) q.push(x*10 + x%10 + 1);
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 4724
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

ll c[27];
ll s[400][27];
ll last[400][27];
ll score[27];

int main(void){
	int D;
	cin>>D;
	for(int i=1;i<=26;i++)cin>>c[i];
	for(int i=1;i<=D;i++){
		for(int j=1;j<=26;j++){
			cin>>s[i][j];
		}
	}
	vector<ll>mx(D+1,0);
	for(int d=1;d<=D;d++){
		ll S = 0;
		for(int i=1;i<=26;i++){
			if(S<s[d][i]){
				mx[d]=i;
				S = s[d][i];
			}
		}
	}
	ll ans=0;
	random_device rnd;
	mt19937 mt(rnd());
	uniform_int_distribution<> rand26(1,26),randday(1,D);
	for(ll d=1;d<=D;d++){
		for(int i=1;i<=26;i++){
            last[d][i]=last[d-1][i];
            if(i==mx[d])last[d][mx[d]]=d;
        }
		ans+=s[d][mx[d]];
		for(ll j=1;j<=26;j++){
            ans-=c[j]*(d-last[d][j]);
		}
	}
	for(ll qu=0;qu<1000000;qu++){
		ll d = randday(mt);
		ll q = rand26(mt);
		//cout<<d<<" "<<q<<endl;
		ll tmp = ans;
		tmp+=s[d][q]-s[d][mx[d]];
        ll old1 = last[d][mx[d]];
        ll new1 = last[d-1][mx[d]];
        ll old2 = last[d][q];
        ll new2 = d;
        for(ll i=d;i<=D;i++){
            tmp+=c[mx[d]]*(i-last[i][mx[d]]);
            if(last[i][mx[d]]==old1)last[i][mx[d]]=new1;
            tmp-=c[mx[d]]*(i-last[i][mx[d]]);
        }
        for(ll i=d;i<=D;i++){
            tmp+=c[q]*(i-last[i][q]);
            if(last[i][q]==old2)last[i][q]=new2;
            tmp-=c[q]*(i-last[i][q]);
        }
		if(ans<tmp){
			ans = tmp;
			mx[d]=q;
		} 
		else{
			for(ll i=d;i<=D;i++){
				if(last[i][mx[d]]==new1)last[i][mx[d]]=old1;
			}
			for(ll i=d;i<=D;i++){
				if(last[i][q]==new2)last[i][q]=old2;
			}
		}
	}
	for(int i=1;i<=D;i++)cout<<mx[i]<<endl;
    return 0;
}

Measured memory_bytes: 3824
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int N, C;
  cin >> N >> C;
  int s[N], t[N], c[N];
  int mxt = 0;
  for (int i = 0; i < N; i++ ) {
    cin >> s[i] >> t[i] >> c[i];
    mxt = max(mxt, t[i]);
  }

  int recording[mxt * 2 + 2];
  int recorder[mxt * 2 + 2];
  memset(recorder, 0, sizeof(recorder));
  for (int i = 1; i <= C; i++) {
    memset(recording, 0, sizeof(recording));
    for (int j = 0; j < N; j++) {
      if (c[j] == i) {
        for (int k = s[j] * 2 - 1; k < t[j] * 2; k++) {
          recording[k]++;
        }
      }
    }
    for (int j = 0; j < mxt * 2 + 2; j++) {
      if (recording[j] > 0) recorder[j]++;
    }
  }
  /*
  for (int a: recorder) {
    cout << a << endl;
  }
  return;
  */

  int ans = 0;
  for (int i = 0; i < mxt * 2 + 2; i++) {
    ans = max(ans, recorder[i]);
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 2944
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    println!("{}", a * b / gcd(a, b));
}

fn gcd(a: usize, b: usize) -> usize {
    if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}


Measured memory_bytes: 4352
N = int(input())
A = [int(hoge) for hoge in input().split()]
A.sort()
M = max(A)
dp = [False] * (M+ 1)
ans = 0
prev = -1
for a in A:
    if dp[a] == False:
        for j in range(2,1 + (M// a)):
            dp[a*j] = True
        if a != prev:
            ans += 1
        else:
            dp[a] = True
            ans -= 1
    prev = a
print(ans)

Measured memory_bytes: 106132
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;
int gcd(int a, int b)
{
    if(b) return gcd(b,a%b);
    return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9 + 7;
int a[25][25];
int dp[1 << 22];
int pd[1 << 22];
int n;

int32_t main(){_
    //freopen("in","r",stdin);
	cin >> n;
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < n;j++)
		{
			cin >> a[i][j];
		}
	}
	dp[0] = 1;
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < n;j++)
		{
			if(a[i][j])
			for(int mask = 0;mask < (1 << n);mask++)
			{
				if(mask & (1 << j)) continue;
				pd[mask | (1 << j)] += dp[mask];
				pd[mask | (1 << j)] %= mod;
			}
		}
		for(int mask = 0;mask < (1 << n);mask++)
		{
			dp[mask] = pd[mask];
		}
	}
	rc(dp[(1 << n) - 1]);
}

Measured memory_bytes: 20736
#include<iostream>
#include<cmath>

using namespace std;

int main() {
    int N;

    cin >> N;

    int X[N];
    int sum = 0;

    for(int i = 0; i < N; i++) {
        cin >> X[i];
        sum += X[i];
    }

    int avg = (int)round(((float)sum) / ((float)N));

    int ans = 0;
    for(int i = 0; i < N; i++) {
        ans += (X[i] - avg) * (X[i] - avg);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  int n;
  cin>>n;
  int k = n;
  int tmp=0;
  while(k>0){
    tmp+=k%10;
    k/=10;
  }
  if(n%tmp==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}




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


int ODD(int n){

  int dp[202][9][2][2];
  
  memset(dp,0,sizeof(dp));
  
  dp[0][0][0][0]=1;
  dp[0][1][1][1]=1;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<9;j++){
      for(int k=0;k<2;k++){
	for(int l=0;l<2;l++){
	  if(j<8&&k==0) dp[i+1][j+1][1][l] += dp[i][j][k][l];
	  dp[i+1][j][0][l] += dp[i][j][k][l];
	}
      }
    }
  }
  return (dp[n-1][8][0][1] + dp[n-1][8][0][0] + dp[n-1][8][1][0])*40320;
}

int EVEN(int n){

  n>>=1;

  int dp[202][9][3][3];
  
  memset(dp,0,sizeof(dp));
  
  dp[0][0][0][0]=1;
  dp[0][1][1][1]=1;
  dp[0][1][2][2]=1;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<9;j++){
      for(int k=0;k<3;k++){
	for(int l=0;l<3;l++){
	  if(j<8&&k==0){
	    dp[i+1][j+1][1][l] += dp[i][j][k][l];
	    dp[i+1][j+1][2][l] += dp[i][j][k][l];
	  }
	  else if(j<8&&k==1){
	    dp[i+1][j+1][2][l] += dp[i][j][k][l];
	  }
	  else if(j<8&&k==2){
	    dp[i+1][j+1][1][l] += dp[i][j][k][l];
	  }
	  dp[i+1][j][0][l] += dp[i][j][k][l];
	}
      }
    }
  }
  return (dp[n-1][8][0][0] + dp[n-1][8][1][0] + dp[n-1][8][2][0] + dp[n-1][8][0][1] + dp[n-1][8][1][1] + dp[n-1][8][0][2] + dp[n-1][8][2][2] )*40320;
  
}

signed  main(){
  int n;
  while(cin>>n,n){
    if(n%2)cout<<ODD(n)<<endl;
    else cout<<EVEN(n)<<endl;
  }
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int A[3];
//---------------------------------------------------------------------------------------------------
void _main() {
	rep(i, 0, 3) cin >> A[i];

	int tot = 0;
	rep(i, 0, 3) tot += A[i];
	if (22 <= tot) cout << "bust" << endl;
	else cout << "win" << endl;
}







Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

vector<int> fact(int n) {
	vector<int> res;
	for (int i = 1; i <= n; ++i) {
		if (n % i == 0) {
			res.push_back(i);
		}
	}
	return res;
}

int main() {
	IOS;
	int n;
	cin >> n;
	int res = 0;
	FOR(i, 1, n + 1) {
		if (i % 2 == 1 and fact(i).size() == 8) {
			res++;
		}
	}
	put(res);
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {

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

	set<int> Set;
	string S; cin >> S;
	for (int i = 0; i < S.size(); i++) {
		Set.insert(S[i]);
	}

	if (Set.size() == S.size())cout << "yes";
	else cout << "no";

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;cin>>n>>m;
  vector<int>ac(n),pena(n);
  for(int i=0;i<m;i++){
    int p;
    string s;
    cin>>p>>s;
    p--;
    if(ac[p])continue;
    if(s=="AC"){
      ac[p]=1;
    }else{
      pena[p]++;
    }
  }
  int AC=0,PENA=0;
  for(int i=0;i<n;i++){
    AC+=ac[i];
    if(ac[i])PENA+=pena[i];
  }
  cout<<AC<<" "<<PENA<<endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

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

    int cnt = 0;
    for (int i = 0, hmax = 0; i < n; i++) {
        int h;
        cin >> h;

        if (hmax <= h) {
            hmax = h;
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
def nb(a,b,c)
  return true if a.length == 0
  p = a.pop
  if b[-1] < p
    b << p
    nb(a,b,c)
  elsif c[-1] < p
    c << p
    nb(a,b,c)
  else
    return false
  end
end
gets.to_i.times do
  a = gets.split.map(&:to_i).reverse
  b = Array.new(1,a.pop)
  c = Array.new(1,0)
  puts nb(a,b,c) ? "YES" : "NO"
end

Measured memory_bytes: 8604
from sys import stdin

x, n = [int(x) for x in stdin.readline().rstrip().split()]
if n > 0:
    P = [int(x) for x in stdin.readline().rstrip().split()]

    memos = [False] * 102

    for p in P:
        memos[p] = True

    tgt = x
    offset = 1
    look_down = True
    while True:

        if memos[tgt] == False:
            break
        if look_down:
            look_down = False
            tgt = x-offset
        else:
            look_down = True
            tgt = tgt + offset + offset
            offset += 1

    print(tgt)
else:
    print(x)


Measured memory_bytes: 9200
p,q,r[1000000],i,l;
main(){
	for(;~scanf("%d%d",&p,&q);){
		memset(r,-1,sizeof(r));
		p%=q;
		for(l=0;p&&r[p]==-1;l++){
			r[p]=l;
			p*=10;
			putchar(p/q+'0');
			p%=q;
		}
		puts("");
		if(p){
			for(i=0;i<r[p];i++)
				putchar(' ');
			for(;i<l;i++)
				putchar('^');
			puts("");
		}
	}
}

Measured memory_bytes: 4284
#include <iostream>

int main()
{  
  int A, B, C, D, area;
  std::cin >> A >> B >> C >> D;
  
  if(A * B >= C * D)
  {
    area = A * B;
  }
  else
  {
    area = C * D;
  }
  
  std::cout << area;
  
  return 0;
}

Measured memory_bytes: 3192