akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<iterator>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<queue>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<stack>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
*/
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define INFLL 0x3fffffffffffffffLL
#define INF 0x3f3fffff
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
typedef long long int ll;
typedef double dd;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll MOD=1000000007;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"DEBUG: "<<#x<<" is: "<<x<<'\n';
#define DD(x,y) cerr<<"DEBUG:("<<#x<<","<<#y<<") are: "<<x<<" "<<y<<'\n';
/////////////////// GLOBAL VARIABLES ////////////////////////////
vector<vector<int>> adj; vector<bool> vis;
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
/////////////////// FUNCT`IONS ////////////////////////////////////
inline ll mexp(ll x,ll n,ll m){ll res=1;while(n){if(n&1)res=(res*x)%m;n>>=1;x=((x%m)*(x%m))%m;}return res;}
bool ispow2(ll x){ return x && (!(x&(x-1)));}
ll gcd(ll x, ll y){ pll p{x,y}; while(p.ss) p={p.ss,p.ff%p.ss}; return p.ff;}

/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
  cout<<fixed;cerr<<fixed; cout<<setprecision(8); cerr<<setprecision(3);

#ifdef DEBUG
  freopen("ip.txt","r",stdin); //freopen("op.txt","w",stdout);
  clock_t tStart = clock();
#endif

  int a,b; cin>>a>>b;
  cout<< (a>8 || b>8?":(":"Yay!") <<'\n';

#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
#endif
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n) { cin >> p[i]; }
    int cnt = 0;
    for(int i = 0; i + 2 < n; i++) {
        int ma = max(p[i], max(p[i + 1], p[i + 2]));
        int mi = min(p[i], min(p[i + 1], p[i + 2]));
        if(p[i + 1] != ma and p[i + 1] != mi) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
  int s;
  cin >> s;
  set<int> st;
  int x = s;
  while(st.count(x) == 0){
    st.insert(x);
    if(x % 2 == 0){
      x /= 2;
    }else{
      x = x*3 + 1;
    }
  }
  cout << (st.size() + 1) << endl;
  return 0;
}

Measured memory_bytes: 256
n, w = map(int, input().split())
weights, values = zip(*[tuple(map(int, input().split()))for _ in range(n)])
min_w = min(weights)-1
weights = [weight-min_w for weight in weights]
W_MAX = 4*200
dp = [[0]*(W_MAX+1) for _ in range(n+1)]
for i in range(1, n+1):
    for k in reversed(range(1, n+1)):
        for j in range(1, W_MAX+1):
            if j-weights[i-1] < 0:
                continue
            dp[k][j] = max(dp[k][j], dp[k-1][j-weights[i-1]]+values[i-1])

ans = 0
for k in range(n+1):
    w_max = min(w-k*min_w, W_MAX)
    if w_max < 0:
        continue
    ans = max(ans, dp[k][w_max])
print(ans)

Measured memory_bytes: 42860
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    VL a(n);
    REP(i,n) a[i] = in() % mod;
    sort(ALL(a));
    reverse(ALL(a));

    VL two(2 * n + 1);
    two[0] = 1;
    REP(i,2*n) two[i + 1] = (2 * two[i]) % mod;

    ll ans = 0;
    REP(i,n){
        ll x = (2 * two[i] * two[2 * (n - i - 1)]) % mod;
        ll y = (i > 0 ? i * two[i - 1] + two[i] : 1) % mod;
        ll s = (x * y) % mod;
        ans = (ans + a[i] * s) % mod;
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MAX (int)1e9 + 99
#define maxof(a,b,c) max(a,max(b,c))
#define minof(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vb vector<bool>
#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define MOD 1000000007
#define bitcnt(x) __builtin_popcount(x)
#define gcd(a,b) __gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define ts(x) to_string(x)
#define set0(x) memset(x, 0, sizeof(x))
const double pi = 3.14159265358979323846;
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) {if (!v.empty()) {os << v.front();for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];} return os;}
const int N=50010;

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

    vi a(n);
    cin>>a;

    vector<bool> dp(k+1, false);

    for(int i = 0; i<=k;i++)
    {
        for(int j: a)
        {
            if(i >= j && !dp[i-j])
                dp[i] = true;
        }
    }

    cout<<(dp[k]?"First":"Second");
}

int main()
{
    fastio;
    
    int t=1;
    
    rep(i,t)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}



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

int main()
{
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l.at(i);

  sort(l.begin(), l.end(),greater<int>());

  // rep(i, n) cout << l.at(i);
  int sum = 0;


  for (int i = 1; i < n;i++){
    sum += l.at(i);
  }

  if(l.at(0) < sum)
    cout << "Yes";
  else
  {
    cout << "No";
  }

}


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

int main()
{
    int s, u = 0;
    cin >> s;

    while(s - 500 >= 0){
        s = s - 500;
        u = u + 1000;
    }

    while(s - 5 >= 0){
        s = s - 5;
        u = u + 5;
    }
     cout << u << endl;
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll long long
# define all(x) x.begin(), x.end()
# define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
# define MOD 1000000007
														
using namespace std;
vector<int> a;
ll get(int tg){
	ll re=0;
	for (int v:a){
		ll tmp=v-tg;
		re+=tmp*tmp;
	}
	return re;
}

int main(){
	fastio;
	int n;
	cin>>n;
	a.assign(n,0);
	int mn=-100,mx=100;
	for (int &v:a){
		cin>>v;
		mn=min(mn,v);
		mx=max(mx,v);
	}
	ll ans=1e18;
	for (int i=mn;i<=mx;i++){
		ans=min(ans,get(i));
	}
	cout<<ans<<'\n';
	return 0;
}
	


Measured memory_bytes: 3640
#include    <iostream>

int
main()
{
    while   (std::cin.get()!='C'&&std::cin);
    if  (std::cin.good())
    	{
    		while   (std::cin.get()!='F'&&std::cin);
    		if  (std::cin.good())
    			std::cout<<"Yes";
    		else
    			std::cout<<"No";
		}
    else
    	std::cout<<"No";
    return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll n;

	cin >> n;

	cout << "ABC" << n << endl;
}

Measured memory_bytes: 256
dx, dy = gets.split.map(&:to_i).each_slice(2).to_a.transpose.map{|a| a.reverse.reduce(:-)}
puts "U"*dy + "R"*dx + "D"*dy + "L"*(dx+1) + "U"*(dy+1) + "R"*(dx+1) + "DR" + "D"*(dy+1) + "L"*(dx+1) + "U"

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";
signed main()
{
	//freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n; cin >> n;
	string s; cin >> s;
	int r = 0, g = 0, b = 0;
	for(int i = 0; i < n; i++)
	{
		r += s[i] == 'R';
		g += s[i] == 'G';
		b += s[i] == 'B';
	}
	int ans = 0;
	
	int pre_r = 0, pre_g = 0, pre_b = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'R')
		{
			ans += (pre_g * b);
			ans += (pre_b * g);
			pre_r++;
			r--;
		}
		else if(s[i] == 'G')
		{
			ans += (pre_r * b);
			ans += (pre_b * r);
			pre_g++;
			g--;
		}
		else
		{
			ans += (pre_r * g);
			ans += (pre_g * r);
			pre_b++;
			b--;
		}
	}
	
	for(int i = 0; i < n; i++)
	{
		int x = i-1, y = i+1;
		while(x >= 0 && y < n)
		{
			if(s[i] != s[x] && s[i] != s[y] && s[x] != s[y])
				ans--;
			x--; y++;
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3664
class BIT:
    def __init__(self,n):
        self.size=n
        self.tree=[0]*-~n
    def sum(self,i):
        s=0
        while i:
            s+=self.tree[i]
            i-=i&-i
        return s
    def add(self,i,x):
        while i<=self.size:
            self.tree[i]+=x
            i+=i&-i
def main():
    n=int(input())
    bit=BIT(10**5)
    for a in map(int,input().split()):
        bit.add(a,a)
    for _ in range(int(input())):
        b,c=map(int,input().split())
        t=bit.sum(b)-bit.sum(b-1)
        bit.add(b,-t)
        bit.add(c,t//b*c)
        print(bit.sum(10**5))
main()

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

int main ()
{
   ll n,k;cin>>n>>k;ll h[n];
   ll dp[n];
    fr(i,n)cin>>h[i];
   dp[0]=0;
    for(ll i=1;i<n;i++)
    {
        dp[i]=INT_MAX;
        for(ll j = max(0LL,i-k);j<i;j++)
        dp[i] = min(dp[j]+abs(h[i]-h[j]),dp[i]); 
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

struct Point{
    double a,b,c,d;
};

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h,vector<int>(w));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }

    vector<Point> ans;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w-1; j++){
            if(a[i][j]%2==1){
                a[i][j+1]++;
                a[i][j]--;
                Point t;
                t.a = i; t.b = j; t.c = i; t.d = j+1;
                ans.push_back(t);
            }
        }
    }
    for(int i = 0; i < h-1; i++){
        if(a[i][w-1]%2==1){
            a[i+1][w-1]++;
            a[i][w-1]--;
            Point t;
            t.a = i; t.b = w-1; t.c = i+1; t.d = w-1;
            ans.push_back(t);
        }
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i].a+1 << " " << ans[i].b+1 << " " << ans[i].c+1 << " " << ans[i].d+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 7408
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  lint N,K;
  cin>>N>>K;
  lint A[N],F[N];
  REP(i,N)cin>>A[i];
  REP(i,N)cin>>F[i];
  sort(A,A+N);
  sort(F,F+N,greater<int>());
  lint l=-1,r=1e12;
  while(r-l>1){
    lint c=(r+l)/2;
    lint k=K;
    REP(i,N){
      k-=max((lint)0,A[i]-c/F[i]);
    }
    if(k>=0)r=c;
    else l=c;
  }
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
const long long INF = numeric_limits<long long>::max();
map<ll, ll> Factorization(ll N) {
    map<ll, ll> values;
    for (ll i = 2; i * i <= N; ++i) {
        while ((N % i) == 0) {
            values[i]++;
            N /= i;
        }
    }
    if (N != 1) {
        values[N]++;
    }
    return values;
}
int main() {
    ll N;
    cin >> N;

    map<ll, ll> values;
    REP2(i, 1, N + 1) {
        auto vs = Factorization(i);
        for (const auto& v : vs) {
            values[v.first] += v.second;
#ifdef SOURCE_TEST
            cout << v.first << ":" << v.second << endl;
#endif
        }
    }
    ll count = 1;
    for (const auto& v : values) {
        count *= v.second + 1;
        count %= MOD;
    }

    PR(count);

    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
using namespace std;
int n,m,x,a[100],q=0,p=0;
int main(void){
	cin>>n>>m>>x;
	for(int i=0;i<m;i++){
		cin>>a[i];
		if(a[i]<x)q++;
		else p++;
	}
	cout<<min(q,p);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #include<chrono>
     
    using namespace std;
    using namespace std::chrono;
    typedef long long ll;
    typedef vector<int> vi;
    typedef pair<int,int> pi;
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
    #define F first
    #define S second
    #define PB push_back
    #define EB emplace_back
    #define MP make_pair
    #define REP(i,a,b) for(i=a;i<=b;i++)
    #define RAP(i,a,b) for(i=a;i>=b;i--)
    ll mod=1000000007;
    const int MX=0x3f3f3f3f;
    
    int main(){
        IOS;
        int n,i,j,k;
        cin>>n>>k;
        int a[n],dp[n];
        memset(dp,MX,sizeof(dp));
        REP(i,0,n-1) cin>>a[i];
        dp[0]=0;
        REP(i,0,n-2){
            REP(j,1,k){
            if(i+j<n)
                dp[i+j]=min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
            } 
        }
        cout<<dp[n-1];
        return 0;
    }

Measured memory_bytes: 1024
n, m = map(int, input().split())
a_li = []
b_li = []
cnt = 0

for i in range(n):
	a, b = map(int, input().split())
	a_li.append(a)
	b_li.append(b)

merge = zip(a_li, b_li)
merge_new = sorted(merge)

x = []
y = []

for a, b in merge_new:
	x.append(a)
	y.append(b)

for a, b in zip(x, y):
	if m > 0 and b <= m:
		cnt += a * b
		m -= b
		if m == 0:
			break
	elif m > 0 and b > m:
		cnt += a * m
		break

print(cnt)

Measured memory_bytes: 20692
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
string a;
  cin>>a;
  if(a[3]==a[2]&&a[5]==a[4])
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int H[100],W[100],i,x,y,z,n;
  for(i=1;i<=300;i++){
      scanf("%d %d",&H[i],&W[i]);
  if(H[i]==0&&W[i]==0){
    break;
    }
  }
  for(i=1;i<=300;i++){
    if(H[i]==0&&W[i]==0){
      break;
    }
    for(x=1;x<=H[i];x++){
      for(y=1;y<=W[i];y++){
    z=x+y;
    if(z%2==0){
      printf("#");
    }
    else{
      printf(".");
    }
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2132
n = int(input())
d, x = map(int, input().split())
dic = {}
for i in range(n):
  a = int(input())
  dic[i] = [a *(j - 1) + 1 for j in range(2, d + 1) if a *(j - 1) + 1 <= d]
ans = 0
for v in dic.values():
  ans += len(v)
ans += n + x
print(ans)

Measured memory_bytes: 3064
table = {
  'b' => 'd',
  'd' => 'b',
  'p' => 'q',
  'q' => 'p'
}
s = gets.chomp
m = s.each_char.reverse_each.map {|c| table[c] }.join('')
puts (s == m) ? 'Yes' : 'No'


Measured memory_bytes: 7804
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,m,vis[maxn],p;
vector <int> mp[maxn];

inline void dfs(int u,int fa)
{
	p++; vis[u]=1;
	for(int i=0;i<mp[u].size();i++)
	{
		int v=mp[u][i];
		if(vis[v]||v==fa) continue;
		dfs(v,u);
	}
}

int main()
{
	n=read(); m=read();
	rep(i,1,m)
	{
		int u=read(),v=read();
		mp[u].pb(v); mp[v].pb(u);
	}
	int tmp=0;
	rep(i,1,n) if(!vis[i]) p=0,dfs(i,0),tmp=max(tmp,p);
	cout<<tmp<<endl;
	return 0;
}

Measured memory_bytes: 43292
#include <iostream>

long long x;

using namespace std;

int main()
{
	cin >> x;
	for (long long a = - 200; a <= 200; a++)
	for (long long b = - 200; b <= 200; b++)
	if (a * a * a * a * a == x + b * b * b * b *b) cout << a << " " << b, exit(0);
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
  int a;
  scanf("%d",&a);
if(a%2==0 && a<20) printf("Yes");
else if(a%3==0 && a<30) printf("Yes");
else if(a%4==0 && a<40) printf("Yes");
else if(a%5==0 && a<50) printf("Yes");  
else if(a%6==0 && a<60) printf("Yes"); 
else if(a%7==0 && a<70) printf("Yes");
else if(a%8==0 && a<80) printf("Yes");
else  if(a%9==0 && a<90) printf("Yes");
else  if(a==1) printf("Yes");
else printf("No");
return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N,i;
		int count = 1;
		N = sc.nextInt();
		
		Integer[] Input = new Integer[N];
		
		for(i=0;i<N;i++) {
			Input[i] = sc.nextInt();
		}
		
		Arrays.sort(Input);
		
		for(i=0;i<N-1;i++) {
			if(Input[i]<Input[i+1]) {
				count = count+1;
			}
		}
		
		System.out.println(count);
		
	}

}

Measured memory_bytes: 23892
#include<iostream>
#include<vector>
#include<string>

int main(){
	std::string s;
	std::cin>>s;

	int numSet;
	std::vector<int> numChar(3, 0);

	for(int i=0; i< s.size(); i++)
		numChar[s[i]-'a']++;

	numSet= (s.size()-1)/3;



	for(int i=0; i<3; i++){
		if(numSet+1 < numChar[i]){
			std::cout<<"NO"<<std::endl;
			return 0;
		}
	}

	std::cout<<"YES"<<std::endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
using std::swap;

int N, M,t;
std::vector <int> Z;
std::vector <pair<int,int>> Y;
std::vector <int> X;

int main()
{	
	cin >> N >> M;
	X.resize(M);
	Y.resize(M-1);
	for (int i = 0; i < M; ++i) {
		cin >> X[i];
	}
	if (N >= M) {
		cout << "0" << "\n";
	}
	else {
		sort(X.begin(), X.end());
		t = X[M - 1] - X[0];
		for (int i = 0; i < M - 1; ++i) {
			Y[i].second = i + 1;
			Y[i].first = X[i + 1] - X[i];
		}
		sort(Y.begin(), Y.end());
		for (int i = M - 2; i > M - N - 1; --i) {
			Z.push_back(Y[i].first);
		}
		sort(Z.begin(), Z.end());
		for (int i = 0; i < N - 1; ++i) {
			t -= Z[i];
		}
		cout << t << "\n";
	}

	return 0;
}

Measured memory_bytes: 2044
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> S(M), C(M);
	for(int i=0; i<M; i++) cin >> S[i] >> C[i];

	for(int x=0; x<1000; x++){
		bool ok = true;
		int c[3];
		if(N==1){
			if(x>=10) continue;
			c[0] = x;
		} else if(N==2){
			if(x<10 || 100<=x) continue;
			c[0] = x/10;
			c[1] = x%10;
		} else {
			if(x<100) continue;
			c[0] = x/100;
			c[1] = (x/10)%10;
			c[2] = x%10;
		}

		for(int i=0; i<M; i++){
			if(c[S[i]-1]!=C[i]) ok = false;
		}
		if(ok){
			cout << x << endl;
			return 0;
		}
	}

	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    M = 61
    for i, a in enumerate(A):
        A[i] = list(map(int, str(format(a, 'b')).zfill(M)[::-1]))

    csum = [[0] * M for _ in range(N)]
    csum[0] = A[0]
    for i in range(1, N):
        for j in range(M):
            csum[i][j] = csum[i - 1][j] + A[i][j]

    p2 = [0] * M
    p2[0] = 1
    for i in range(M - 1):
        p2[i + 1] = p2[i] * 2 % MOD

    ans = 0
    for i, a in enumerate(A[1:], 1):
        for j in range(M):
            n = csum[i - 1][j] if a[j] == 0 else i - csum[i - 1][j]
            ans = (ans + n * p2[j]) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main()
{
	int a, b,A,S,M,Max;
	
	cin >> a >> b;
	A = a + b;
	S = a - b;
	M = a*b;
	Max = A;
	if (Max < S)
		Max = S;
	if (Max < M)
		Max = M;
	cout << Max;
		return 0;
}

Measured memory_bytes: 256
h,*s=open(0)
h,w,k,*m=map(int,h.split())
b=512
while b:
 b-=1;r=t=j=0;d=[0]*h
 while w-j:
  i=c=0
  while h-i:
   d[c]+=s[i][j]>'0';f=d[c]>k
   if(t<j)&f:r+=1;t=j;d=[0]*h;break
   r+=h*w*f;c+=b>>i&1;i+=1
  else:j+=1
 m+=r+c,
print(min(m))

Measured memory_bytes: 44892
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
const ll maxs = 1e4+6;
ll mod = 1e9+7;
ll oo = 1e15;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
 
 
int32_t main()
{
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll x;
      cin>>x;
      if(x%2 || x<2)
        {
            std::cout << 0 << std::endl;
            continue;
        }
      ll no = 10;
      ll ans=0;
      while(no <= x)
      {
          ans += x/no;
          no *= 5;
      }
        cout << ans << endl;
    }
    
    
    return 0;
} 

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from itertools import *
from collections import *

INF = float('inf')


def main():
    N = int(input())
    kuku = set(x * y for x in range(1, 10) for y in range(1, 10))
    answer = 'Yes' if N in kuku else 'No'
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,c[100010],a,b,i,ans=0,p;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    c[R]=a-b;
    hin(a+b);
  }
  p=-2e9;
  for(i=0;i<n;i++){
    a=hout();//printf("%d %d %d\n",a,c[a],p);
    if(c[a]<p)continue;
    ans++;
    p=N[a];
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 4992
A = gets.chomp.to_i
B = gets.chomp.to_i
C = gets.chomp.to_i
D = gets.chomp.to_i
E = gets.chomp.to_i

menue = [A, B, C, D, E]
ans = 643
menue.permutation(5) { |a, b, c, d, e|
  m = [a, b, c, d, e]
  t = 0
  i = 0
  while i < 5
    while t % 10 != 0
      t += 1
    end
    t += m[i]
    i += 1
  end
  ans = [ans, t].min
}

puts ans


Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t x,y;
    cin >> x >> y;
    cout << x + y/2 << endl;
}


Measured memory_bytes: 256
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int N, A, B;

int main(void) {
    scanf("%d", &N);

    if (N == 1) puts("Hello World");
    else {
    	scanf("%d %d", &A, &B);
    	printf("%d\n", A+B);
    }
	return 0;
}


Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
		String s[]=bu.readLine().split(" ");
		Long n=Long.parseLong(s[0]),m=Long.parseLong(s[1]);
		n%=m;
		if(Math.abs(n-m)<n) n=Math.abs(n-m);
		System.out.print(n);
	}
}

Measured memory_bytes: 22484
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <iostream>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  int ans = 0;
  int flag = 1;
  for (int i = 0; i < N-1; i++) {
    int n = S[i] - '0';
    switch(n){
    case 0:
    case 1:
    case 2:
    case 3:
      if (flag == -1) {
        ans += n + 1;
      } else {
        ans += n;
      }
      flag = 1;
      break;
    case 4:
      if (flag == -1) {
        ans += 5;
        flag = 0;
      }
      else {
        ans += 4;
        flag = 1;
      }
      break;
    case 5:
      if (flag == 1) {
        ans += 5;
        flag = 0;
      } else {
        ans += 4;
        flag = -1;
      }
      break;
    case 6:
    case 7:
    case 8:
    case 9:
      if (flag == 1) {
        ans += 10 - n;
      }
      else {
        ans += 9 - n;
      }
      flag = -1;
      break;
    }
  }
  int last = S[N - 1] - '0';
  if(last <= 4) {
    if(flag == -1) {
      ans += last + 1;
    } else {
      ans += last;
    }
  } else if (last == 5) {
    ans += 5;
  } else {
    if(flag == 1) {
      ans += 11 - last;
    } else {
      ans += 10 - last;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1412
# -*- coding: utf-8 -*-
"""
AtCoder B
"""

def main():
    N=list(map(int,input().split()))
    H=list(map(int,input().split()))
    
    max_h=0
    num=0
    for h in H:
        if max_h<=h:
            max_h=max(max_h,h)
            num+=1
    print(num)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
def solve(a, b):
	pflg = False
	for i in xrange(a, b + 1):
		if i % 400 == 0 or (i % 4 == 0 and i % 100 != 0):
			yield str(i)
			pflg = True
	if not pflg:
		yield "NA"
result = []
while True:
	a, b = map(int, raw_input().split())
	if a == b == 0: break
	result += ["\n".join(solve(a, b))]
print "\n\n".join(result)

Measured memory_bytes: 5484
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using std::cin;
using std::cout;
using std::endl;

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

	while ( n != 0 ) {
		char c;
		int count_p = 0;
		bool d = false;
		std::vector< std::pair<int,char> > data(26);
		std::vector<int> hash(26);

		for (int i = 0; i < 26; i++) {
			data[i].first = 0;
			data[i].second = 'A' + i;
		}

		for (int i = 0; i < n; i++) {
			cin >> c;
			for (int j = 0; j < 26; j++) {
				if (c == data[j].second) {
					data[j].first++;
				}
			}

			std::sort(data.begin(), data.end());

			if ( data[25].first > data[25-1].first + (n-i-1) ) {
				if (!d) {
					cout << data[25].second << " " << i+1 << endl;
					d = true;
				}
			}
		}

		if (data[25].first == data[25-1].first) {
			cout << "TIE" << endl;
		}
		else {
			if (!d) {
				cout << data[25].second << " " << n << endl;
			}
		}

		cin >> n;
	}

	return 0;
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll n,k,num=1;
    cin >> n >> k;
    rep(i,n){
        num = min(2*num, num+k);
    }
    cout << num << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
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<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 4e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<queue<int>> a(n);
    set<int> app;
    rep(i,n){
        rep(j,n-1){
            int ai;
            cin >> ai;
            ai--;
            a[i].push(ai);
            if (j==0)
                app.insert(ai);
        }
    }
    int ans = 0;
    int cnt = n * (n - 1) / 2;
    if (n>900 && app.size() == 2)
    {
        cout << cnt << ENDL;
        return 0;
    }
    while (1){
        ans++;
        bool used[n] = {};
        bool flag = true;
        rep(i,n){
            if (a[i].empty())
                continue;
            int nex = a[i].front();
            if (a[nex].empty()){
                flag = true;
                break;
            }
            if (used[i]||used[nex])
                continue;
            if (a[nex].front()==i){
                cnt--;
                if (cnt==0){
                    cout << ans << ENDL;
                    return 0;
                }
                flag = false;
                used[i] = true;
                used[nex] = true;
                a[nex].pop();
                a[i].pop();
            }
        }
        if (flag){
            cout << -1 << ENDL;
            return 0;
        }
    }
    cout << ans << ENDL;
}

Measured memory_bytes: 4736
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

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

bool comp(string &a, string &b) {
    if (a.size() < b.size()) return true;
    if (a.size() > b.size()) return false;
    return a > b;
}

int main() {

    while (true) {
        int H, W;
        cin >> H >> W;

        if (!(H | W)) break;

        vector<string> M(H);
        for (int i = 0; i < H; i++) cin >> M[i];

        map<string, int> MAP;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                for (int k = 0; k < 8; k++) {
                    string s = "";
                    vector<vector<bool>> B(H, vector<bool>(W, false));
                    int y = i, x = j;
                    while (true) {
                        if (B[y][x]) break;
                        s += M[y][x];
                        MAP[s] += 1;
                        B[y][x] = true;
                        y += (2 * H + dy[k]);
                        y %= H;
                        x += (2 * W + dx[k]);
                        x %= W;
                    }
                }
            }
        }

        vector<string> cand;
        for (auto x: MAP) if (x.second >= 2) cand.push_back(x.first);

        sort(cand.begin(), cand.end(), comp);
        if (cand.back().size() <= 1) cout << 0 << endl;
        else cout << cand.back() << endl;

    }

}














































Measured memory_bytes: 37712
#include <stdio.h>
#define MAX 1000

typedef struct{
  int id;
  int k;
  int pk;
  int lk;
  int rk;
} node;

int main(){
  int i, n;
  node t[MAX];

  scanf("%d", &n);
  for(i = 1; i <= n; i++){
    scanf("%d", &t[i].k);
    t[i].id = i;
  }
  for(i = 1; i <= n; i++){
    t[i].pk = t[i/2].k;
    t[i].lk = t[2*i].k;
    t[i].rk = t[2*i+1].k;
  }

  for(i = 1; i <= n; i++){
    printf("node %d: key = %d, ", t[i].id, t[i].k);
    if(t[i].id != 1) printf("parent key = %d, ", t[i].pk);
    if(n % 2 == 0 && i <= n / 2){
      printf("left key = %d, ", t[i].lk);
      if(i != n / 2) printf("right key = %d, ", t[i].rk);
    }
    else if(n % 2 == 1 && i <= n / 2){
      printf("left key = %d, right key = %d, ", t[i].lk, t[i].rk);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2052
#include<iostream>
using namespace std;
int main(){
  int a[9];
  for(int i=0;i<9;i++){
    cin>>a[i];
  }
  int n;
  cin>>n;
  int b[n];
  for(int i=0;i<n;i++){
    cin>>b[i];
    for(int j=0;j<9;j++){
      if(a[j]==b[i])a[j]=0;
    }
  }
  if((a[0]==0&&a[1]==0&&a[2]==0)||(a[3]==0&&a[4]==0&&a[5]==0)||(a[6]==0&&a[7]==0&&a[8]==0)||
     (a[0]==0&&a[3]==0&&a[6]==0)||(a[1]==0&&a[4]==0&&a[7]==0)||(a[2]==0&&a[5]==0&&a[8]==0)||
     (a[0]==0&&a[4]==0&&a[8]==0)||(a[2]==0&&a[4]==0&&a[6]==0))cout<<"Yes";
  else  cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <string>
#define LL long long

using namespace std;

string s;

bool Check(int low,int high)
{
    for (int i=low,j=high;i<=j;i++,j--) if (s[i]!=s[j]) return 0;
    return 1;
}

int main()
{
    cin >>s;
    int l=s.length();
    if (Check(0,l-1) && Check(0,l/2-1) && Check(l/2+1,l-1)) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//Rational Irrationals
public class Main{

	static long gcd(long a, long b){
		if(a < b){
			long tmp = a;
			a = b;
			b = tmp;
		}
		while(b!=0){
			long r = a%b;
			a = b;
			b = r;
		}
		return a;
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int p = sc.nextInt();
			int n = sc.nextInt();
			if((p|n)==0)break;
			double rp = Math.sqrt(p);
			int num = 1;
			int den = 1;
			Set<String> set = new HashSet<String>();
			boolean up = true;
			int x, y, u, v;
			x = y = u = v = 0;
			double d1, d2;
			d1 = -n;
			d2 = n;
			while(num<=n&&den<=n){
				String s = num+"/"+den;
				if(set.contains(s))break;
				set.add(s);
				double d = num*1.0/den-rp;
				if(d<0){
					up = true;
					if(d1<d&&gcd(num,den)==1){
						d1 = d;
						u = num;
						v = den;
					}
				}
				else{
					up = false;
					if(d<d2&&gcd(num,den)==1){
						d2 = d;
						x = num;
						y = den;
					}
				}
				num += up?1:0;
				den += up?0:1;
			}
			System.out.println(x+"/"+y+" "+u+"/"+v);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
S = input()
YY = int(S[0:2])
MM = int(S[2: ])

if YY <= 12 and YY > 0 and MM <= 12 and MM > 0:
  print("AMBIGUOUS")
elif YY <= 12 and YY > 0 and (MM >= 13 or MM == 0):
  print("MMYY")
elif (YY == 0 or YY >= 13) and MM <= 12 and MM > 0:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	vector<int>key[m];
	for(int i=0;i<m;i++)
	{
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			int x;
			cin>>x;
			key[i].push_back(x);
		}
	}
	int p[m];
	for(int i=0;i<m;i++)
		cin>>p[i];
	int arr[n];
	int res=0;
	for(int i=0;i<1<<n;i++)
	{
		for(int j=0;j<n;j++)
		{
				if(i&(1<<j))
					arr[j]=1;
				else
					arr[j]=0;
		}
		int count=0;
		for(int l=0;l<m;l++)
		{
			int tab=0;
			for(auto x : key[l])
			{
				if(arr[x-1]==1)
					tab++;
			}
			if(tab%2==p[l]%2)
				count++;
		}
		if(count==m)
			res++;

	}
	cout<<res<<"\n";
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
string s;
string ring;
int count,n;
int main(){
	cin >> s;
	cin >> n;
	count=0;
	for(int i=0;i<n;i++){
		cin >>ring;
		ring+=ring;
		if(ring.find(s)!=-1)count++;
	}
	cout << count<<endl;
	return 0;
}

Measured memory_bytes: 3176
def f(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n+1
    

i = 0
n = int(input())
while True:
    if n == 4 or n == 2 or n == 1:
        print(i+4)
        break
    i += 1
    n = f(n)

Measured memory_bytes: 3060
m, k = map(int, input().split())
limit = 2 ** m

if k >= limit:
  print(-1)
  exit()

if m == 0:
  print(0, 0)
elif m == 1:
  if k == 0:
    print(0, 0, 1, 1)
  elif k == 1:
    print(-1)
else:
  A = [i for i in range(limit) if i != k]
  ans = A + [k] + A[::-1] + [k]
  print(' '.join(map(str, ans)))

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

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

    int answer = 0;

    while(X>=500)
    {
        X -= 500;
        answer += 1000;
    }
    while(X>=5)
    {
        X -= 5;
        answer += 5;
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int H, R;
  scanf("%d %d", &H, &R);
  if ( H*(-1) == R ) printf("0\n");
  else if ( H*(-1) > R ) printf("-1\n");
  else if ( H*(-1) < R ) printf("1\n");

  return 0;
}



Measured memory_bytes: 2108
#!/usr/bin/env python3
import sys
INF = float("inf")


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def solve(N: int, S: str):

    ans = 0
    for i in range(N-1):        # N
        z = z_algorithm(S[i:])  # N
        for j, zz in enumerate(z):  # N
            ans = max(min(j, zz), ans)
    print(ans)
    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
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()


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

#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair

using namespace std;

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

int main(){
	ios_base::sync_with_stdio(false);
	ll a, b, c;
	cin >> a >> b >> c;
	if (c <= a + b + 1)
		return cout << b + c << endl, 0;
	cout << (a + b + 1) + b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); ++i)

const int M = 1000005;
typedef long long LL;
using namespace std;

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

    // 入力した数の倍数を計算する
    // もしある数の約数の数は1より大きいの場合は
    // その数は条件を満たさない
    // iの倍数の数は M/i です
    // Σ(1~M) M/i
    // O(NlogN)

    vector<int> cnt(M);
    for(int x : a){
        // 0じゃない場合は、既に現れたの状況です
        // その時は、その数の倍数を計算するのは無意味です
        if(cnt[x] != 0){
            cnt[x] = 2;
            continue;
        }
        // xの倍数
        for(int i = x; i < M; i += x) ++cnt[i];
    }

    int ans = 0;
    for(int x : a){
        if(1 == cnt[x]) ++ans;
    }
    cout << ans << endl;

    return 0;
}

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


int main(){
    long long int N,K;
    long long int A,B;
    int sum=0;
    int max=0;
    bool flag=true;
    string s;
    cin>>K>>N;
    vector<int> a(N);
    map<int,int>ball;

    int sa;

    for(int i=0;i<N;i++){
        cin>>a.at(i);
    }
    for(int i=0;i<N;i++){
        if(i!=N-1){
            sa=a.at(i+1)-a.at(i);
            sum=sum+sa;
        }
        if(i==N-1){
            sa=K-a.at(i)+a.at(0);
            sum=sum+K-a.at(i)+a.at(0);
        }
        if(max<sa){
            max=sa;
        }

    }


    
    cout<<sum-max<<endl;


}

Measured memory_bytes: 1024
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
#define MAXN 20010
int r[MAXN+10];
void solve(long long N, vector<long long> p){
	for(int i=1; i<=N; ++i) {
		r[p[i-1]]=i;
	}	
	for(LL i=1; i<=N; ++i) {
		cout<<MAXN*i+r[i]<<' ';
	}
	cout<<endl;
	for(LL i=1; i<=N; ++i) {
		cout<<MAXN*(N-i+1)<<' ';
	}
	cout<<endl;
}

int main(){	
#ifdef WAAUTOMATON
	freopen("in.txt","r",stdin);
#endif
	long long N;
	scanf("%lld",&N);
	vector<long long> p(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&p[i]);
	}
	solve(N, p);
	return 0;
}



Measured memory_bytes: 1024
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var S string
	var ans int

	fmt.Scan(&S)

	for s := 0; s < (1 << byte(len(S)-1)); s++ { // 001, 010, 011, ...
		now := string(S[0])
		for i := 0; i < len(S)-1; i++ { // S[i]とS[i+1]の間に+を入れるかどうか
			if (s & (1 << byte(i))) != 0 {
				now += "+"
			}
			now += string(S[i+1])
		}

		nums := strings.Split(now, "+")
		for _, v := range nums {
			i, _ := strconv.Atoi(v)
			ans += i
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 768
S = input()
T = input()
lenS = len(S)
lenT = len(T)
minlength = 1000
for l_S in range(lenS - lenT + 1):
    cnt = 0
    for w in range(lenT):
        if S[l_S+w] != T[w]:
            cnt += 1
    minlength = min(minlength, cnt)
print(minlength)

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 59, M = 5e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;


int main(){
    init();

    ll n, t;    cin >> n >> t;

    ll last = 0, ans = t;
    for(int i = 0;i < n;i++){
        ll x;  cin >> x;
        ans += (x - last > t ? t : x - last);
        last = x;
    }

    cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int i, j, n, max, sum, r; // rは記憶
  int x[1000][3];

  scanf("%d", &n);

  for(i = 0; i < n; i++) {
    max = 0;
    scanf("%d %d %d", &x[i][0], &x[i][1], &x[i][2]);

    for(j = 0; j < 3; j++) {
      if(max < x[i][j]) {
	max = x[i][j];
	r = j;
      }
    }
    x[i][r] = 0; 

    sum = x[i][0] * x[i][0] + x[i][1] * x[i][1] + x[i][2] * x[i][2];
    
    if(max * max == sum) printf("YES\n");
    else printf("NO\n");
  }

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];

  ll ans = 0;
  int ma = a[0];
  rep(i, 1, n) {
    if (a[i] < ma) ans += ma - a[i];
    ma = max(ma, a[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct edge{int to; ll cost;};

const int MAX_V = 1e5;
vector<edge> es[MAX_V];
vector<ll> d(MAX_V);

void dfs(int now, int pre){
    for(auto &e: es[now]){
        if(e.to == pre) continue;
        d[e.to] = d[now]+e.cost;
        dfs(e.to, now);
    }
}

int main(){
    int N;
    cin >> N;
    rep(i, N-1){
        int u, v; ll c;
        cin >> u >> v >> c; u--, v--;
        es[u].eb((edge){v, c}), es[v].eb((edge){u, c});
    }
    int Q, K;
    cin >> Q >> K; K--;
    d[K] = 0;
    dfs(K, -1);
    rep(i, Q){
        int u, v; cin >> u >> v; u--, v--;
        cout << d[u]+d[v] << endl;
    }
}

Measured memory_bytes: 14336