akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define ll long long
#define inf INT_MAX
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
using namespace std;
const int N=1e5+5;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int dis[N],tot,n,m,fa[N];
bool vis[N];
int find(int x){
	int p=fa[x];
	if(fa[x]!=x) fa[x]=find(fa[x]),dis[x]+=dis[p];
	return fa[x];
}
int main(){
#ifdef Devil_Gary
	freopen("in.txt","r",stdin);
#endif 
	n=read(),m=read();
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1,l,r,d;i<=m;i++) {
		l=read(),r=read(),d=read();
		int x=find(l),y=find(r);
		if(x==y){
			if(dis[l]+d!=dis[r]) return printf("No\n"),0;
		} 
		else{
			int d1=dis[l]-dis[x],d2=dis[r]-dis[y]-d;
			if(d1>d2) fa[y]=x,dis[y]=dis[x]+d1-d2;
		 	else fa[x]=y,dis[x]=dis[y]+d2-d1;
		} 
	}
	return printf("Yes\n"),0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

class Point{
public:
	long x;
	long y;

	Point() : x(0), y(0){
		return;
	}

	~Point(){
		return;
	}

	bool operator < (const Point &r){
		if(this->x != r.x){
			return this->x < r.x;
		}
		else{
			return this->y < r.y;
		}
	}

};

int main(int argc, char **argv){
	int n;
	std::vector<Point> a;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	a.resize(n);
	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> a[i].x >> a[i].y;
#else
		std::cin >> a[i].x >> a[i].y;
#endif
	}

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

	for(int i = 0; i < a.size(); i++){
		std::cout << a[i].x << " " << a[i].y << std::endl;
	}

	return 0;
}


Measured memory_bytes: 4420
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main(){

  int N, L;
  string str[110];

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

  sort(str, str+N);

  for(int i = 0; i < N; i++){
    cout << str[i];
  }

  cout << endl;

  return 0;

}


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

using namespace std;

int arr[200005],dp[200005];
int n;

int main()
{
	cin >> n;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		cin >> arr[i];
		dp[arr[i]]=max(dp[arr[i]],1+dp[arr[i]-1]);
		if(dp[arr[i]]==arr[i])
			ans=max(ans,dp[arr[i]]);
	}
	ans=n-ans;
	if(ans==n) ans=-1;
	cout << ans << endl;
}

Measured memory_bytes: 1792
a,b,c,d,e,f=map(int,input().split())
q=[]
for t in range(0,f+1,a*100):
  for w in range(t,f+1,b*100):
    if w>0:
      m=min(f-w,w*e//100)+1
      for u in range(0,m,c):
        for s in range(u,m,d):
          v=s+w
          q.append([s/v,v,s])
print(*max(q)[1:])


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

ll solve(ll n, ll* a, ll* b) {
  vector<ll> dp(n+1,-INF); dp[0] = 0;
  rep(i,n+1) {
    rep(j,3) {
      if(i-a[j] >= 0) dp[i] = max(dp[i],dp[i-a[j]]+b[j]);
    }
  }
  rep(i,n+1) dp[0] = max(dp[0],dp[i]+n-i);
  return dp[0];
}

int main(){
  ll n;
  cin >> n;
  ll a[3], b[3];
  rep(i,3) cin >> a[i];
  rep(i,3) cin >> b[i];
  cout << solve(solve(n,a,b),b,a) << endl;
  return 0;
}

Measured memory_bytes: 195584
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	long long n, m, x; cin >> n >> m >> x;
	vector<vector<long long>> mat(n, vector<long long>(m + 1, 0));

	long long min_cost = LLONG_MAX;
	for (long long i = 0; i <= n - 1; i++) {
		cin >> mat[i][0];
		for (long long j = 1; j <= m; j++) cin >> mat[i][j];
	}

	for (long long mask = 0; mask <= ((1ll << n) - 1); mask++) {
		vector<long long> alg(m + 1, 0);
		long long cost = 0;
		for (long long j = 0; j <= n - 1; j++) {
			if ((mask & (1ll << j)) != 0) {
				cost += mat[j][0];
				for (long long k = 1; k <= m; k++) alg[k] += mat[j][k];
			}
		}

		bool flg = true;
		for (long long i = 1; i <= m; i++) if (alg[i] < x) {flg = false; break;}

		if (flg) min_cost = min(min_cost, cost);
	}
	if (min_cost == LLONG_MAX) cout << -1;
	else cout << min_cost;

	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e9 + 7)
using namespace std;

int n, k;
long long num[100005];

int main()
{
    scanf("%d%d", &n, &k);
    for(int i = 1;i <= n;i++)
        scanf("%lld", &num[i]);
    sort(num + 1, num + 1 + n);
    if(num[1] == num[n])
    {
        if(num[1] != k)
            puts("IMPOSSIBLE");
        else
            puts("POSSIBLE");
        return 0;
    }
    if(num[n] < k)
    {
        puts("IMPOSSIBLE");
        return 0;
    }
    for(int i = 1;i <= n;i++)
    {
        if(num[i] == k)
        {
            puts("POSSIBLE");
            return 0;
        }
    }
    long long gcd = num[1];
    for(int i = 2;i <= n;i++)
    {
        gcd = __gcd(gcd, num[i]);
    }
    if(k % gcd == 0)
        puts("POSSIBLE");
    else
        puts("IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 1024
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int gcd(int a, int b){
    if(b==0)return a;
    gcd(b,a%b);
}
const int maxn = 2*1e5 +10;

int a[maxn], d[maxn];
int ans;
void solve(){
    int k,n;
    cin >> k >> n;


    for(int i = 1;i<=n;i++){
        cin >> a[i];
        //d[i] = a[i]-a[i-1];

    }
    sort(a+1,a+n+1);
    for(int i = 1;i<=n;i++){
        //cin >> a[i];
        d[i] = a[i]-a[i-1];

    }

    d[n+1] = k-a[n]+a[1];
    int mx = 0, idx = 0;

    for(int i = 2;i<=n+1;i++){
        //cout << d[i] << endl;
        ans+=d[i];
        if(d[i]>mx){
            idx = i;
            //cout << idx << endl;
        }

        mx = max(mx,d[i]);
    }


    
    cout << ans-mx << endl; 
 
} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

#define MAX 500000
int L[MAX/2 + 2], R[MAX/2 + 2];
int cnt;


signed main()
{   
    gearup;
    int n; cin >> n;
    vl b(n-1),a(n,INF);
    rep(i,n-1) cin >> b[i];
    rep(i,n-1){
        a[i] = min(b[i],a[i]);
        a[i+1] = min(b[i],a[i+1]);
    }
    cout << accumulate(all(a),0) << endl;
}

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


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

    int max = 0;
    int count = 0;

    for(int j=0; j<N-1; j++){
        if(H[j] >= H[j+1]){
            count++;
        }
        else{
            count = 0;
        }
        if(count > max){
            max = count;
        }
    }

    cout << max;

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>

#define max  200

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}
int int_sort( const void * a , const void * b ) {
  return strcmp(( char * )a , ( char * )b );
}

int main()
{
    int n, k, d[max], a[max][max], i, j, l, b[max], cnt=0;
    
    scanf("%d%d", &n, &k);
    for (i=0; i<k; i++) {
        scanf("%d", &d[i]);
        for (j=0; j<d[i]; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    
    for (i=1; i<=n; i++) {
        b[i]=0;
    }
    
    for (i=0; i<k; i++) {
        for (j=0; j<d[i]; j++) {
            b[a[i][j]]++;
        }
    }
    
    for (i=1; i<=n; i++) {
        if (b[i]==0) {
            cnt++;
        }
    }
    
    printf("%d", cnt);
    
    return 0;
} 



Measured memory_bytes: 1808
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int a[1000], b[1000], cnt[1000], mx;

int main()
{
    int n, m, ans;
    cin >> n >> m;
    for(int i=0;i < n;++i) cin >> a[i];
    for(int i=0;i < m;++i) cin >> b[i];
    for(int i=0;i < m;++i) {
        for(int j=0;j < n;++j) {
            if (b[i] >= a[j]) {
                ++cnt[j];
                break;
            }
        }
    }
    for(int i=0;i < n;++i) {
        if (mx < cnt[i]) {
            mx = cnt[i];
            ans = i+1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int n;
    cin>>n;
    string s;
    cin>>s;
    int i=0,j=n-1;
    int ans=0;
    while (i<=j)
    {
        while (i<n&&s[i]=='R')
            i++;
        while (j>=0&&s[j]=='W')
            j--;
        if (i>j)
            break;
        i++,j--;
        ans++;
    }
    cout<<ans;


    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 3772
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>

using namespace std;

vector<long long> X(5);
long long N;

int main()
{
    cin >> N;
    long long mi = 1e16;
    for (int i = 0; i < 5; i++)
    {
        cin >> X[i];
        mi = min(X[i], mi);
    }
    cout << (long long)(N / mi) + 4 + (N % mi == 0 ? 0LL : 1LL) << endl;

    return 0;
}

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

int main(){
 string S,T;
  cin>>S>>T;
  int s=(int)S.size();
  int t=(int)T.size();
  bool ans =true;
  for(int i=0;i<s;i++){
    
  if(t!=s+1){
    cout<<"No"<<endl;
    ans =false;
    break;
  }
    if(S.at(i)!=T.at(i)){
      cout<<"No"<<endl;
      ans =false;
      break;
    }
  }
  if(ans){
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 3636
N = int(input())
S = input()
MOD = 10**9+7
A = [0 if S[i]=='W' else 1 for i in range(2*N)]
A = [(A[i]+i+1)%2 for i in range(2*N)]


ans = 1
l = 0
r = N
flag = True
for i in range(2*N):
    if A[i] == 0:
        l += 1
    
    else:
        ans = (ans*l)%MOD
        r -= 1
        l -= 1
        if l < 0:
            flag = False
            break
if r != 0:
    flag = False
if not flag:
    ans = 0
for i in range(1,N+1):
    ans = (ans*i)%MOD

print(ans)


Measured memory_bytes: 56184
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define ll long long
#define cpp boost::multiprecision::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
const double PI = 3.1415926535897932384626433832795;
struct edge {
	int to;
	ll cost;
};
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	ll N;
	cin >> N;
	for (ll i = 1;; i++) {
		if (N * i >= (4 * i - 2 * N) * i) {
			for (ll j = i; j <= 3500; j++) {
				ll p = 4 * i * j - N * (i + j), q = N * i * j;
				if (p > 0) {
					if (!(j * p <= q)) {
						break;
					}
					if (q % p == 0) {
						cout << i << " " << j << " " << q / p << endl;
						return 0;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    string S;
    cin >> S;
    map<int, int> mp;
    mp['a'] = mp['b'] = mp['c'] = 0;
    for (char c : S)
    {
        mp[c]++;
    }
    vector<int> words;
    for (auto m : mp)
    {
        words.push_back(m.second);
    }
    sort(words.begin(), words.end());
    if (words[2] - words[0] > 1)
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << "YES" << endl;
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


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

#define pb push_back
#define mp make_pair

#define fi first
#define se second

typedef long long ll;

using namespace std;
int n, dp[100500];

bool u[100500];

vector<int> a[100500];

int dfs(int v){
    //u[v] = 1;
    vector<int> pp;
    
    
    for(int i=0;i<a[v].size();i++){
        int to = a[v][i];
        pp.pb(dfs(to));
    }

    sort(pp.begin(), pp.end());
    reverse(pp.begin(), pp.end());

    int k = a[v].size();
    for(int i=0;i<pp.size();i++){
        k = max(k, pp[i] + i + 1);
    }
    return k;
}

int main(){

cin >> n;
for(int i=2;i<=n;i++){
    int x;
    cin >> x;
    a[x].pb(i);
}
cout << dfs(1);
return 0;
}


Measured memory_bytes: 15104
#include <stdio.h>

int main() {
  int n, m, S, maxS, in, out, error;
  int i;
  scanf("%d", &n);
  scanf("%d", &m);

  S = maxS = m;
  error = 0;
  for(i = 0; i < n; ++i) {
    scanf("%d %d", &in, &out);
    S = S - out + in;
    if(S < 0)error = 1;
    if(S > maxS) maxS = S;
  }

  if(error) maxS = 0;
  printf("%d\n", maxS);

  return 0;
}

Measured memory_bytes: 1024
using System;

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] a = new int[N];
        string[] arr = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++)
            a[i] = int.Parse(arr[i]);

        int ans = int.MaxValue;
        for (int i = -100; i <= 100; i++)
        {
            int sum = 0;
            for (int j = 0; j < N; j++)
            {
                sum += (a[j] - i) * (a[j] - i);
            }
            if (sum < ans) ans = sum;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
H,W=map(int,input().split())
if W==1:
    print(1)
elif H==1:
    print(1)
else:
    if W%2==0 and H%2==0:
        print(H*W//2)
    elif W%2==0 and not H%2==0:
        print(H*W//2)
    elif not W%2==0 and H%2==0:
        print(H*W//2)
    else:
        print(H*W//2+1)


Measured memory_bytes: 2940
#define pb push_back
#define vi vector<int>
#include<bits/stdc++.h>
using namespace std;
const int N = 300000;
int pro[300000], n;
string v1[N], v2[N], v3[N];
map<int, vector<char> > mp1, mp2, mp3;
int cv(string s){
	int val = 0, i = 0, sign = 1;
	if(s[0] == '-') sign = -1, i++;
	for(; i < s.size(); i++){
		val = val * 10 + s[i] - '0';
	}
	return val * sign;
}
void solve(){
	string s;
	getline(cin, s);
	int ans = 0;
	stack<int> st;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == ' ') continue;
		string x = "";
		int j = i; while(j < s.size() && s[j] != ' ') x += s[j++];
		i = j;
		if(x[0] == '+'){
			int n1 = st.top(); st.pop();
			int n2 = st.top(); st.pop();
			st.push(n1 + n2);
		}else if(x[0] == '-'){
			int n1 = st.top(); st.pop();
			int n2 = st.top(); st.pop();
			st.push(n2 - n1);
		}else if(x[0] == '*'){
			int n1 = st.top(); st.pop();
			int n2 = st.top(); st.pop();
			st.push(n1 * n2);
		}else{
			st.push(cv(x));
		}
	}	
	cout << st.top() << endl;
}
int main(void){
	solve();
	return 0;
}


Measured memory_bytes: 10212
import itertools
from math import factorial
from collections import Counter

ans = 0
N, L = map(int, input().split())
x = list(map(int, input().split()))
y = itertools.accumulate(x)
y = [e % L for e in y]
#print(y)
#print(y)
so = set(y)
#print(so)
#print(so)
counter = Counter([0]+y)
#print(counter.values())
#print
for i in counter.values():
    #print(ans)
    if i>1:ans+=factorial(i) // 2 // factorial(i-2)
print(ans)

Measured memory_bytes: 64536
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 3010;

char s[N], t[N], u[N];
pair<int, pair<int, int>> ans;
pair<int, pair<int, int>> dp[N][N];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%s%s", s + 1, t + 1);
  int n = strlen(s + 1), m = strlen(t + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (s[i] == t[j])
        ans = max(ans, dp[i][j] = make_pair(dp[i - 1][j - 1].first + 1, make_pair(i, j)));
      else
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
  pair<int, int> pos = ans.second;
  int cur = 0;
  while (pos.first) {
    u[cur++] = s[pos.first];
    pos = dp[pos.first - 1][pos.second - 1].second;
  }
  reverse(u, u + cur);
  puts(u);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

int main(){
    int N;
    cin>>N;
    string ans = "";
    if(N == 0) ans += '0';

    while(N != 0){
        int rem;
        rem = N % (-2);
        if(rem == -1) rem += 2;
        N = (N-rem)/(-2);
        ans += (char)('0'+rem);
    }

    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

using namespace std;

int a[26];
char s[27];

int main() {
    int n, i, j;
    
    scanf("%s", s);
    
    n = strlen(s);
    
    if (n == 26) {
        for (i = n - 1; i >= 0; i--) {
            for (j = n - 1; j > i; j--) {
                if (s[i] < s[j]) {
                    s[i] = s[j];
                    s[i + 1] = '\0';
                    printf("%s\n", s);
                    
                    return 0;
                }
            }
        }
        
        puts("-1");
    } else {
        for (i = 0; i < n; i++) a[s[i] - 'a'] = 1;
        
        for (i = 0; i < 26; i++) {
            if (a[i] == 0) {
                s[n] = 'a' + i;
                break;
            }
        }
        
        printf("%s\n", s);
    }
    
    return 0;
}


Measured memory_bytes: 128
def selection_sort(a, n):
    cnt = 0
    for i in range(n):
        min_ind = i
        for j in range(i, n):
            if a[j] < a[min_ind]:
                min_ind = j
        if a[i] != a[min_ind]:
            a[i], a[min_ind] = a[min_ind], a[i]
            cnt += 1
    return a, cnt

n = int(input())
a = list(map(int, input().split()))
ans, cnt = selection_sort(a, n)
print(*ans)
print(cnt)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<pair<int, int>> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;

  sort(p.begin(), p.end());
  ll res = 0;
  rep(i, n) {
    res += p[i].second;
    if (res >= k) {
      cout << p[i].first << endl;
      return 0;
    }
  }


  
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

ll solve(ll n){
    vector<ll> a(n);
    for(auto &x:a){
        cin >> x;
    }
    ll sum = 0;
    for(auto &x:a){
        sum += x;
    }
    ll ret = 0;
    for(auto &x:a){
        if(n*x <= sum){
            ++ret;
        }
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    vector<ll> ans;

    while(true){
        ll n;
        cin >> n;
        if(n == 0){
            break;
        }
        ans.push_back(solve(n));
    }

    for(auto &x:ans){
        cout << x << endl;
    }

    return 0;
}


Measured memory_bytes: 3216
#include<iostream>
using namespace std;
typedef long long ll;

char dc[]={'N','E','S','W'};
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int change(char ch){
  for(int i=0;i<4;i++)if(dc[i]==ch)return i;
}

int H,W,sx,sy,sdir;
ll L;
char t[100][100];
string str;

void input();
void solve();
void dfs(int,int,int,int,ll);

int main(){
  while(1){
    cin>>H>>W>>L;
    if(H==0&&W==0&&L==0)break;
    input();
    solve();
  }
  return 0;
}

void input(){
  for(int i=0;i<H;i++){
    cin>>str;
    for(int j=0;j<W;j++){
      if(str[j]!='#'&&str[j]!='.'){
	t[i][j]='.';
	sy=i;
	sx=j;
	sdir=change(str[j]);
      }else t[i][j]=str[j];
    }
  }  
}

ll vd[100][100][4];

void solve(){
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      for(int k=0;k<4;k++){
	vd[i][j][k]=-1;
      }
    }
  }

  dfs(sy,sx,sdir,0,0);
}



void dfs(int y,int x,int dir,int dir2,ll cnt){
  dir%=4;

  if(cnt>=L){
    cout<<y+1<<' '<<x+1<<' '<<dc[dir]<<endl;
    return;
  }
  
  if( L-cnt>=50000LL && vd[y][x][dir]!=-1 ){
    ll ncnt;
    ncnt=(L-cnt)%(cnt-vd[y][x][dir]);
    dfs(y,x,dir2,dir2,L-ncnt-(cnt-vd[y][x][dir]));
    return;
  }

  vd[y][x][dir]=cnt;
  
  int ny=y+dy[dir];
  int nx=x+dx[dir];
  if(ny<0||nx<0)dfs(y,x,dir+1,dir,cnt);
  else if(ny>=H||nx>=W)dfs(y,x,dir+1,dir,cnt);
  else if(t[ny][nx]=='#')dfs(y,x,dir+1,dir,cnt);
  else dfs(ny,nx,dir,dir,cnt+1);

}

Measured memory_bytes: 1536
#include<stdio.h>

#define ll long long

int main(){
  ll N;
  scanf("%lld", &N);
  
  ll sum = 0;
  for(ll i = 1; i * i <= N; i++){
    if(N % i == 0){
      if(i - 1 > N / i) sum += i - 1;
      if(N / i - 1 > i) sum += N / i - 1;
    }
  }
  
  printf("%lld", sum);
  
  return 0;
}

Measured memory_bytes: 128
#[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 ) * } } ; }
#[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 , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        s: u64
    }

    let mut hset = std::collections::HashSet::new();
    let mut k = s;
    let mut ret = 0;
    for i in 1.. {
        if hset.contains(&k) {
            ret = i;
            break;
        }
        hset.insert(k);
        k = if k % 2 == 0 {k/2} else {3*k+1};
    }
    println!("{}", ret);
}

Measured memory_bytes: 4352
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn main(){
    let n = read_as_vec::<usize>()[0];
    let mmod: usize = 1000000007;
    let mut dp: Vec<Vec<Vec<Vec<usize>>>> = vec![vec![vec![vec![0;4];4];4];n];//ACGT

    for i in 0..4{
        dp[0][2][2][i] = 1;
    }

    for i in 0..4{
        for j in 0..4{
            dp[1][2][i][j] = 1;
        }
    }


    for i in 2..n{
        for p3 in 0..4{
            for p2 in 0..4{
                for p1 in 0..4{
                    //if (p3 == 0 && p2 == 2 && p1 == 1) ||{
                    //AGC or GAC or ACG
                    if (p3, p2, p1) == (0, 2, 1) ||
                        (p3, p2, p1) == (2, 0, 1)||
                        (p3, p2, p1) == (0, 1, 2){
                        continue;
                    }
                    for p4 in 0..4{
                        if (p4, p2, p1) == (0, 2, 1) ||
                            (p4, p3, p1) == (0, 2, 1){
                                continue;
                            }
                        dp[i][p3][p2][p1] = (dp[i][p3][p2][p1] + dp[i-1][p4][p3][p2])%mmod;
                    }
                }
            }
        }
    }

    let mut ans = 0;

    for p3 in 0..4{
        for p2 in 0..4{
            for p1 in 0..4{
                ans = (ans + dp[n-1][p3][p2][p1])%mmod;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll inf =1e15;
const ll mod=1e9+9;
/*
vector<ll> primes;
void sieve(ll n)
{
    bool arr[n+1]={false};
        arr[0]=arr[1]=1;
        for(int i=2;i*i<n;i++)
        {
            if(arr[i]==false)
            {
                for(int j=i*i;j<n;j+=i)
                {
                    arr[j]=true;
                }
            }
        }
        for(int i=2;i<n;i++)
        {
        if(arr[i]==false)
        {
        primes.push_back(i);
        }
        }
        
}
*/
/*
void segmented(ll n)
{
    
    ll lim=1000000;
    sieve(lim);
    
    ll low=lim;
    ll high =2*lim;
    
        bool arr[lim+1];
        vector<ll> v11;
    while(low<n)
    {
        if (high >= n)  
           high = n; 
        memset(arr,false,sizeof(arr));
        for(int i=0;i<primes.size()&&primes[i]*primes[i]<=high;i++)
        {
            ll firsta=floor(low/primes[i])*primes[i];
            if(firsta<low) firsta+=primes[i];
            
            for(int j=firsta;j<high;j+=primes[i])
            arr[j-low]=true;
            
        }
        for (int i = low; i<high; i++) 
            if (arr[i - low] == false) 
            v11.push_back(low);
        
            
        low+=lim;
        high+=lim;
    
    //cout<<1;
    
    }
    for(int i=0;i<v11.size();i++)
    primes.push_back(v11[i]);
    
}
*/

vector<ll> pval;
ll compute_hash(vector<ll> &hashes, string const&s1)
{
    pval.clear();
    //vector<ll> hashes;
    const ll p=31;
    ll hv=0;
    pval.push_back(1);
    for(int i=0;i<s1.size();i++)
    {
        hv=(hv+(s1[i]-'a'+1)*pval[i])%mod;
        pval.push_back((pval[i]*p)%mod);
        hashes.push_back(hv);
    }
    
    return hashes[s1.size()-1];
}
ll binexpo(ll a,ll b)
{
    ll p=1,c=1;
    while(b!=0)
    {
        
        if(b&1)
        {
            c=(c*a)%mod;
        }
        a=(a*a)%mod;
        
        b=b/2;
    }
    
    return c%mod;
    
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c,d,e,f,p,r,n,k,m,t,q,x,y;
    t=1;
    //cin>>t;
    string s1,s2,s3,s4,s5;
    //sieve(100005);
    m=1600;
    /*
    ll inv[1600]={0};
    
    inv[0]=1;
    
    for(int i=1;i<1600;i++)
    {
        inv[i]=binexpo(31,mod-1-i);
    }
    */
    for(int t0=1;t0<=t;t0++)
    {
        cin>>a>>b;
        a=a*b;
        cout<<a;
    }
    
    return 0;
}


Measured memory_bytes: 3656
/*
 * Author : Sadi
 * Fri 03/07/2020
 * 16:36:22.84
 */
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n;
    cin >> n;
    double t, a;
    cin >> t >> a;
    vector<int> h(n);
    set<pair<double, int>> s;
    for(int i = 0; i < n; ++i) {
        cin >> h[i];
        double temp = t - h[i] * .006;
        double dif = max(a, temp) - min(a, temp);
        s.insert({dif, i + 1});
    }
    cout << s.begin()->se << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n,k;cin>>n>>k;
    vl a(n);
    rep(i,n)cin>>a[i];
    ll ans=1e9;
    rep(i,n-k+1){
        ll sum=(a[i+k-1]-a[i]);
        if(a[i]>=0){
            sum+=a[i];
        }
        else if(a[i]<0&&a[i+k-1]>=0){
            sum+=min(abs(a[i]),a[i+k-1]);
        }
        else if(a[i+k-1]<0){
            sum+=abs(a[i+k-1]);
        }
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
n, k= map(int, input().split())
h = list(map(int, input().strip().split()))
import numpy as np
hnp = np.asarray(h)
hnp = np.sort(hnp, axis=0)      
if(k >= n):
    print(int(0))
else:    
    s = n-k
    print(int(np.sum(hnp[:s])))

Measured memory_bytes: 26180
n = gets.to_i
a = gets.split(' ').map(&:to_i)
cnt = 0;

n.times do |i|
  (n-1).downto(i+1) do |j|
    if a[j] < a[j-1] then 
      a[j], a[j-1] = a[j-1], a[j]
      cnt += 1
    end
  end
end

puts a.join(' ')
puts cnt

Measured memory_bytes: 8688
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <map>

int main(){

    std::string S;
    std::cin >> S;
    int len = S.length();
    //printf("%d\n",len);
    int ans = 0;
    for (int i=0; i<int((len+1)/2); i++){
        //printf("%c == %c\n",S[i], S[len-i-1]);
        if (S[i]!=S[len-1-i]){
            ans ++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	vector<int> res(N+1);
	for (int i = 2; i <= N; ++ i) {
		int x;
		cin >> x;
		++ res[x];
	}
	for (int i = 1; i <= N; ++ i) {
		cout << res[i] << endl;
	}
}


Measured memory_bytes: 4048
n,d=map(int,input().split())
X=[]
diff=0
c=0
for _ in range(n):
    X.append(list(map(int,input().split())))
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            diff += (X[i][k]-X[j][k])**2
        if (diff**.5).is_integer():c += 1
        diff=0
print(c)

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

const int maxn=1e6+5;

int d[maxn],v[maxn],num[maxn],p[maxn],tot;

void init(int n) {
  d[1] = 1;
  for (int i = 2; i <= n; ++i) {
    if (!v[i]) v[i] = 1, p[++tot] = i, d[i] = 2, num[i] = 1;
    for (int j = 1; j <= tot && i <= n / p[j]; ++j) {
      v[p[j] * i] = 1;
      if (i % p[j] == 0) {
        num[i * p[j]] = num[i] + 1;
        d[i * p[j]] = d[i] / num[i * p[j]] * (num[i * p[j]] + 1);
        break;
      } else {
        num[i * p[j]] = 1;
        d[i * p[j]] = d[i] * 2;
      }
    }
  }
}

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

    int n;cin>>n;
    init(n);
    int ans=0;
    for(int i=1;i<n;i++) ans+=d[i];
    cout<<ans;
    return 0;
}

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

int main(){
        int n, m;
        scanf("%d %d", &n, &m);

        std::vector<int> lht[m];
        for(int i=0; i<m; i++){
                int k;
                scanf("%d", &k);
                for(int j=0; j<k; j++){
                        int tmp;
                        scanf("%d", &tmp);
                        lht[i].push_back(tmp-1);
                }
        }
        int p[m];
        for(int i=0; i<m; i++) scanf("%d", &p[i]);

        int ans = 0;
        for(int i=0; i<(1<<n); i++){
                int bri = 0;
                for(int j=0; j<m; j++){
                        int cnt = 0;
                        for(int k: lht[j]) cnt += (i>>k)&1;
                        if(cnt%2==p[j]) bri++;
                }
                if(bri==m) ans++;
        }
        printf("%d\n", ans);
        return 0;
}

Measured memory_bytes: 256
import sys


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    a = [list(map(int, input().rstrip('\n').split())) for _ in range(3)]
    for i in range(3):
        t = min(a[i])
        if t != 0:
            for j in range(3):
                a[i][j] -= t
        t = min([a[j][i] for j in range(3)])
        if t != 0:
            for j in range(3):
                a[j][i] -= t
    print("Yes" if max([a[i][j] for i in range(3) for j in range(3)]) == 0 else "No")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

const long long mod = 1e9 + 7;
long long cnt[26];
long long N;
string s;

int main()
{
    cin >> N >> s;
    for (int i = 0; i < N;i++)
    {
        cnt[s[i] - 'a']++;
    }
    long long ans = 1;
    for (int i = 0; i < 26;i++)
    {
        ans = (ans * (cnt[i] + 1LL)) % mod;
        
        //ans *= (cnt[i] + 1LL);
        //ans %= mod;
    }
    ans = (ans - 1LL + mod) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
a,b,c = tuple(map(int,input().split()))

ans = 0
while True:
  if len(set((a,b,c)))==1:
    if a%2==1:
      print(0)
      exit()
    print(-1)
    exit()
  if a%2==0 and b%2==0 and c%2==0:
    a,b,c = b//2+c//2,c//2+a//2,a//2+b//2
    ans+=1
  else:
    break
print(ans)

Measured memory_bytes: 38256
number=gets.chomp.to_i
array = gets.chomp.split(" ").map(&:to_i)
jj = -1
array.each_with_index do |var, index|
 if jj <= var
   jj=[jj,var-1].max
 else
   puts "No"
   break
 end  
 if index == array.length-1 
   puts "Yes" 
 end  
end


Measured memory_bytes: 12292
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, m, a;
    while(1){
        cin >> n >> m >> a;
        if(n + m + a == 0) break;
        vector<int> d(n);
        a--;
        rep(i, 0, n) d[i] = i;
        vector<pair<int, P> > e(m); 
        rep(i, 0, m){
            int h, p, q;
            cin >> h >> p >> q;
            p--; q--;            
            e[i].first = h;
            e[i].second.first = p;
            e[i].second.second = q;
        }
        sort(all(e));
        rep(i, 0, m){
            swap(d[e[i].second.first], d[e[i].second.second]);
        }
        cout << d[a] + 1 << endl;
    }
}

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

struct node
{
  struct node *r,*l,*p;
  int key;
};

typedef struct node * Node;
Node root, NIL;

void insert(int k)
{
  int H;
  Node x,y,z;

  x = root;
  y = NIL;
  z = malloc(sizeof(struct node));

  z->key = k;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y = x; /* 親を設定 */
    if(z->key < x->key)
      x = x->l; /* 左の子へ移動 */
    else
      x = x->r; /* 右の子へ移動 */
  }

  z->p = y;

  if(y == NIL)
    root = z;

  else{
    if(z->key < y->key)
      y->l = z;
    else
      y->r = z;
  }
}

void inorder(Node u)
{
  if(u == NIL)
    return;

  inorder(u->l);

  printf(" %d",u->key);

  inorder(u->r);
}

void preorder(Node u)
{
  if(u == NIL)
    return;

  printf(" %d", u->key);

  preorder(u->l);

  preorder(u->r);
}

int main()
{
  int n,i,a;
  char C[20];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",C);
    if(strcmp(C,"insert") == 0){
      scanf("%d",&a);
      insert(a);
    }

    else if(strcmp(C,"print") == 0){

      inorder(root);

      printf("\n");

      preorder(root);

      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 25204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;

int main(){
  string s, t;
  cin >> s >> t;
  if (s+t[t.size()-1] == t) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
string s,t;

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

int main()
{
	cin>>s>>t;
	sort (s.begin(),s.end());
	sort (t.begin(),t.end(),cmp);
	if (s<t)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
l=[]
for i in range(N):
  A,B=map(int,input().split())
  l.append([A,B])
l.sort(key=lambda x:x[0])
i=0
ans=0
while M>l[i][1]:
  M-=l[i][1]
  ans+=l[i][0]*l[i][1]
  i+=1
ans+=l[i][0]*M
print(ans)

Measured memory_bytes: 21208
#include<stdio.h>

int main(void){

char s[10],t[11];

int i,j,k;

scanf("%s",&s);
scanf("%s",&t);

for(i=0;i<10;i++){
if(s[i]=='\0'){break;}
}

for(j=0;j<11;j++){
if(t[j]=='\0'){break;}
}

if(i!=j-1){
printf("No");
}else{
for(k=0;k<i;k++){
if(s[k]!=t[k]){printf("No");break;}
}
if(k==i){printf("Yes");}
}

return 0;
}

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

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

  int a, ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (i == 0) {
      while (a % 2 == 0) {
      ans++;
      a /= 2;
      }
    }
    else {
      int cnt = 0;
      while (a % 2 == 0) {
      cnt++;
      a /= 2;
      }
      if (cnt < ans)
        ans = cnt;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast,unroll-all-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair
#define int ll

#define debug(x) cout << #x << " = " << x << endl;

const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666);
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

// const int MEM_SIZE = 1e8;
// char mem[MEM_SIZE];
// int cur_mem_ptr = 0;

// void* operator new(size_t n) {
//     cur_mem_ptr += n;
//     return mem + cur_mem_ptr - n;
// }

// void operator delete(void*) noexcept {}
// void operator delete(void*, size_t) noexcept {}

template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int bpow(int a, int b, int mod) {
    int res = 1;
    for (; b; b >>= 1) {
        if (b & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
    }
    return res;
}

#ifndef LOCAL
void UseFiles(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
    // UseFiles("squads");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}


void run() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    auto c1 = polar((ld)a, 1.l * 2 * M_PI * h / 12 + 2 * M_PI * m / 60 / 12);
    auto c2 = polar((ld)b, 1.l * 2 * M_PI * m / 60);
    cout << fixed << setprecision(10) << abs(c1 - c2) << endl;
}

Measured memory_bytes: 4208