akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
int main() {
    long long N,K;
    ios::sync_with_stdio(false);
    cin>>N>>K;
    N = N%K;
    long long _min = N;
    while(abs(N-K) <= _min ){
        N = abs(N-K);
        _min = N;
    }
    cout<<N<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
# define INF 0x3f3f3f3f 
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];

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

    vl a(n);
    rep(i, n) cin>>a[i];

    ll ans = 1;

    rep(i, n)
    {
        if(a[i] == 0)
        {
            cout<<0<<endl;
            return;
        }
    }

    rep(i, n)
    {
        // cout<<ans<<endl;
        // cout<<1e1/a[i]<<endl;
        if(ans > 1000000000000000000/a[i])
        {
            cout<<-1<<endl;
            return;
        }

        ans = ans*a[i];
        // if(ans > 1000000000000000000)
        // {
        //     cout<<-1<<endl;
        //     return;
        // }
    }
    cout<<ans<<endl;


}

int main()
{

    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        // cout<<'\n';
    }
    // cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 15584
#include <iostream>
#include <climits>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

long long int i,j,ans=1;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int INF = 1<<29;
const int mod = 1000000007;

int main(){
	char s[200005];
	cin>>s;
	int start=-1,end;
	int n;
	n=strlen(s);
	for(i=0;i<n;i++){
		if(s[i]=='A'){
			start = i;
			break;
		}
	}
	for(i=n-1;i>=0;i--){
		if(s[i]=='Z'){
			end = i;
			break;
		}
	}
	cout << end-start+1 << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define for(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((int)(x).size())
#define inf          1<<25

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

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

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    
    int x = n * a;
    chmin(x, b);
    
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,m=map(int,input().split())\n"
"s=[list(map(int,input().split()))for _ in range(n)]\n"
"a=0\n"
"for i in range(1<<3):\n"
"    t=[[v for v in s[i]]for i in range(n)]\n"
"    for j in range(3):\n"
"        if i>>j&1:\n"
"            for k in range(n):\n"
"                t[k][j]*=-1\n"
"    for j in range(n):\n"
"        t[j]=sum(t[j])\n"
"    a=max(a,sum(sorted(t)[::-1][:m]))\n"
"print(a)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt(),r=s.nextInt();
        if(n>=10) System.out.println(r);
        else System.out.println(r+(100*(10-n)));

    }
}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25376
#include <iostream>

int	main(int	argc,
		 char*	argv[])
{
  int	a	= 0;
  int	b	= 0;

  std::cin >> a >> b;

  if(a > b){
	  std::cout << "a > b\n";
  }
  else if(a < b){
	  std::cout << "a < b\n";
  }
  else{
	  std::cout << "a == b\n";
  }
}



Measured memory_bytes: 3112
N = int(input())
towns = list(map(int, input().split()))
heroes = list(map(int, input().split()))

res = 0
for i in range(N):
  x = min(heroes[i], towns[i])
  towns[i] -= x
  heroes[i] -= x
  res += x
  x = min(heroes[i], towns[i + 1])
  towns[i + 1] -= x
  heroes[i] -= x
  res += x

print(res)


Measured memory_bytes: 19116
#include <iostream>
using namespace std;
int main(){
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;
	cin >> K;
	cout << a[K-1] << endl;
}


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

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

    int n, k;
    cin >> n >> k;

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

    int64_t r = 0;
    for (int i = 0; i < n; i++) {
        if (!(a[i] & ~k)) r += b[i];
    }
    for (int h = 1;; h *= 2) {
        if (k & h) {
            int64_t s = 0;
            int m = (k ^ h) | (h - 1);
            for (int i = 0; i < n; i++) {
                if (!(a[i] & ~m)) s += b[i];
            }
            r = max(r, s);
        }
        if (h == 1 << 30) break;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i+=2){
        int cnt = 0;
        for(int j = 1; j*j <= i; j+=2){
            if(i % j == 0){
                cnt++;
                if(j != i / j)
                    cnt++;
            }
        }
        if(cnt == 8)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int mxN =150000;
int32_t main(){
  ios_base::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);


       int n; cin>>n;
       int w; cin>>w;
       int we[n];int val[n];
       for(int i=0;i<n;i++) 
       { 
           cin>>we[i]>>val[i];
	   }
	   
	   int dp[n+1][w+1];
	   
	   memset(dp,0,sizeof(dp));
	   
	   for(int i=1;i<=n;i++){
	   	
	   	 for(int j=1;j<=w;j++){
	   	
		    if(j<we[i-1]) dp[i][j]=dp[i-1][j];
			else dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-we[i-1]]); 	
		}
	   }
	   
	   cout<<dp[n][w]<<endl;




 return 0;}



Measured memory_bytes: 79104
// Author : Nachiket Kanore
// Institute : PICT, Pune

/* It does not matter how slowly you go as long as you do not stop.*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


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


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...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 1e18;
const int N = 1005;



int32_t main(){
    FAST;

    int a , b;  cin >> a >> b;
    int diff = abs(a - b);

    if(diff % 2)
        cout << "IMPOSSIBLE";
    else cout << (min(a , b) + (diff/2)) << endl;

    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
int main(){
	int N;cin>>N;
	int A[N];int a=0,b=0,temp=-1;
	rep(i,0,N){
		cin>>A[i];
		if(a<A[i]){ a=A[i];temp=i; }
	}A[temp]=0;
    b=*max_element(A,A+N);
    rep(i,0,N){
		if(i==temp) cout<<b<<endl;
		else cout<<a<<endl;
	}
}

Measured memory_bytes: 2432
#include <stdio.h>

int GreComDiv( long a,long b );

int main()
{
	long a,b;
	long gcd;//最大公約数
	long lcm;//最小公倍数
	long tmp;

	//ユークリッドの互除法
	while( scanf("%ld %ld",&a, &b) != EOF){
		//a >= b の順番になるよう入れ替え
		if(a < b){
			tmp = a;
			a = b;
			b = tmp;
		}

		gcd = GreComDiv(a,b);
		//表現範囲を超えてしまうため、除算から行う
		lcm = a * (b / gcd);

		printf("%ld %ld\n",gcd, lcm);
	}
	return 0;
}


int GreComDiv( long a,long b ){
	long tmp;
	while(a % b != 0){
			tmp = b;
			b = a % b;
			a = tmp;
	}

	return b;
}

Measured memory_bytes: 596
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
using namespace std;


int main(){
  int A,P;
  cin >> A >> P;
  P += A*3;
  cout << P/2 << endl;
}

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

int main(){
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    int h, w;
    cin>> h>> w;
    char c;
    int mz[h+1][w+1];
    int x, y;
    for(int i = 1; i <= h; ++i){
        for(int j = 1; j <= w; ++j){
            cin>> c;
            if(c == '.'){
                mz[i][j] = 0;
            }else{
                mz[i][j] = 1;
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= h; ++i)
    for(int j = 1; j <= w; ++j){
            if(mz[i][j] == 1){
                continue;
            }
    queue <pair<int, int>> q;
    int vis[h+1][w+1];
    for(int i = 1; i <= h; ++i){
        for(int j = 1; j <= w; ++j){
            vis[i][j] = 0;
        }
    }
    pair <int, int> cur;
    x = i;
    y = j;
    q.push({x, y});
    vis[x][y] = 1;
    int depth[h+1][w+1];
    depth[x][y] = 0;
    while(!q.empty()){
        cur = q.front();
        q.pop();
        for(int i = 0; i < 4; ++i){
            x = cur.first + dx[i];
            y = cur.second + dy[i];
            if(x > h || x < 1 || y < 1 || y > w){
                continue;
            }
            if(!vis[x][y] && mz[x][y]!=1){
                vis[x][y] = 1;
                q.push({x, y});
                depth[x][y] = 1 + depth[cur.first][cur.second];
                ans = max(ans, depth[x][y]);
            }
        }
    }
    }
    cout << ans << "\n";
    return 0;
}


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

double dp[1<<15][15],MIN=1e15;
int pre[1<<15][15],s[15],d[15],v[15],id,S,n;

main(){
	cin>>n;
	r(i,n)cin>>s[i]>>d[i]>>v[i];
	r(i,1<<n)r(j,15)dp[i][j]=1e15;
	r(i,n)dp[1<<i][i]=0;
	for(int i=1;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				if(j==k)continue;
				if((i&(1<<k)))continue;
				double sum=0,dis=abs(d[k]-d[j]);
				r(l,n)if(i&(1<<l))sum+=v[l];
				double cost=dp[i][j];
				cost+=dis/(2000.0/(sum*20+70));
				if(dp[i|(1<<k)][k]>cost){
					dp[i|(1<<k)][k]=cost;
					pre[i|(1<<k)][k]=j;
				}
			}
		}
	}
	r(i,n)if(MIN>dp[(1<<n)-1][i]){
		MIN=dp[(1<<n)-1][i];
		id=i;
	}
	stack<int>st;
	S=(1<<n)-1;
	r(i,n){
		st.push(s[id]);
		S-=(1<<id);
		id=pre[S|(1<<id)][id];
	}
	r(i,n){
		if(i)cout<<' ';
		cout<<st.top();
		st.pop();
	}
	cout<<endl;
}


Measured memory_bytes: 8760
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100010;
int n,tot,Next[N<<1],head[N],tree[N<<1],In[N],color[N],Q[N],sum,Max,a[N],f[N],g[N];
char s[N];
bool vis[N];
void add(int x,int y)
{
	tot++;
	Next[tot]=head[x];
	head[x]=tot;
	tree[tot]=y;
}
int calc(int id,int x) { return (!color[id])^(x&1);}
void dfs(int u,int fa)
{
	bool flag=0;
	int Max1=0,Max2=0;
	for (int i=head[u];i;i=Next[i])
	{
		int v=tree[i];
		if (v==fa||vis[v]) continue;
		flag=1;
		dfs(v,u);
		Max=max(Max,max(Max1+g[v]+a[u],Max2+f[v]+a[u]));
		Max1=max(Max1,f[v]);
		Max2=max(Max2,g[v]);
	}
	f[u]=Max1+a[u];
	if (!flag) g[u]=-(1<<29);
		else g[u]=Max2+a[u];
}
void pre()
{
	int t=0,w=0;
	for (int i=1;i<=n;i++)
		if (In[i]==1&&color[i]) Q[++w]=i;
	while (t<w)
	{
		int u=Q[++t];
		vis[u]=1;
		for (int i=head[u];i;i=Next[i])
		{
			int v=tree[i];
			In[v]--;
			if (In[v]==1&&color[v]) Q[++w]=v;
		}
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
		In[x]++;In[y]++;
	}
	scanf("%s",s+1);
	for (int i=1;i<=n;i++) color[i]=(s[i]=='B');
	pre();
	int root=0;
	sum=Max=0;
	for (int i=1;i<=n;i++)
	if (!vis[i])
	{
		if (!root) root=i;
		if (calc(i,In[i])) sum++,a[i]=2;
		sum+=In[i];
	}
	if (!root) { puts("0");return 0;}
	dfs(root,0);
	printf("%d\n",sum-Max);
	return 0;
}


Measured memory_bytes: 11136
#include<iostream>
#include<cstdio>
using namespace std;
 
#define mod 924844033
int n,k,tot=0,fac[2005];
int g[2005],f[4005][4005][2];
bool vis[2005][2],End[4005];
 
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    for(int j=0;j<=1;j++)
        if(!vis[i][j]){
           for(int a=i,b=j;a<=n;a+=k,b^=1)
                vis[a][b]=1,tot++;
            End[tot]=true;
        }
    f[1][0][0]=1;
    for(int i=1;i<=tot;i++)
        for(int j=0;j<=n;j++){
            f[i+1][j][0]=(f[i][j][0]+f[i][j][1])%mod;
            if(!End[i])
                f[i+1][j+1][1]=f[i][j][0];
        }
    for(int i=0;i<=n;i++)
        g[i]=(f[tot][i][0]+f[tot][i][1])%mod;
    fac[0]=1;
    for(int i=1;i<=n;i++)fac[i]=1LL*i*fac[i-1]%mod;
    int ans=fac[n];
    for(int i=1,f=-1;i<=n;i++,f=-f){
        ans+=1LL*f*g[i]*fac[n-i]%mod;
        ans=(1LL*ans+mod)%mod;
    }
    printf("%d",ans);
}

Measured memory_bytes: 124544
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> a(n);
    ll s = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        s += a[i];
    }
    ll cur = 0;
    ll res = 1e18;
    for (int i = 0; i < n - 1; ++i) {
        cur += a[i];
        res = min(res, abs(cur - (s - cur)));
    }
    cout << res << '\n';
}

Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
	long long k;
	scanf("%lld",&k);
	printf("50\n");
	long long pos=k/50;
	for (int i=1;i<=50-k%50;++i)
		printf("%lld ",pos++);
	++pos;
	for (int i=1;i<=k%50;++i)
		printf("%lld ",pos++);
	return 0;
}


Measured memory_bytes: 128
import  math

n = int(input())
arr = input().split(" ")
numbers = []
for i in range(0,len(arr)):
    numbers.append(int(arr[i]))

maxdiff = 0

for i in range(0,len(numbers)):
    for j in range(i, len(numbers)):
        diff = abs(numbers[i]-numbers[j])
        if diff > maxdiff:
            maxdiff = diff
print(maxdiff)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,ng;
  cin >> N;
  vector<char> q(N);
  for(int i=0;i<N;i++){
    cin >> q.at(i);
    if(q.at(i)=='E')
      ng++;
  }
  vector<int> ans(N);
  for(int i=0;i<N;i++){
    if(q.at(i)=='E'){
      ng--; ans.at(i)=ng;
    }else{
      ans.at(i)=ng; ng++;
    }
  }
  sort(ans.begin(),ans.end());
  cout << ans.at(0);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    int k;
    cin>>k;
    if(k==0) break;
    int a,b=0;
    for(int i=0;i<k*(k-1)/2;i++){
      cin>>a;
      b+=a;
    }
    b/=k-1;
    cout<<b<<endl;
  }
  
    
  return 0;
}



Measured memory_bytes: 2976
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 110000;
int a[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    forn(i, n) cin >> a[i];
    int minx = *min_element(a, a + n), maxx = *max_element(a, a + n);
    if (maxx - minx > 1) {
        cout << "No\n";
        return 0;
    }
    bool done = false;
    for (int x = maxx - 1; x <= minx; ++x) {
        int un = 0;
        forn(i, n) if (a[i] == x) ++un;
        int rest = n - un;
        int groups = x - un + 1;
        bool ok = rest >= 0 && groups >= 0 && rest >= 2 * groups;
        if (!groups) ok &= rest == 0;
        done |= ok;
    }
    cout << (done ? "Yes" : "No") << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n,m; cin >> n >> m;
    vec<string> ID(m);

    vec<minheap<PII>> heaps(n+1);
    int p, y;
    rep(i,m) {
        cin >> p >> y;
        string ss = to_string(p);
        while(ss.size()!=6) ss = "0"+ss;
        ID[i] = ss;
        heaps[p].push(make_pair(y, i));
    }
    rep1(i,n) {
        for(int j = 1; heaps[i].size(); ++j) {
            PII Pair = heaps[i].top(); heaps[i].pop();
            string ss = to_string(j);
            while(ss.size()!=6) ss = "0"+ss;
            ID[Pair.second] += ss;
        }
    }
    for(int i = 0; i < m; ++i) cout << ID[i] << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 13184
n = int(input())
D = []
for _ in range(n):
    D.append(int(input()))

# n = 4
# D = [10, 8, 8, 6]

D.sort()
mochi = [D[0]]
for d in D[1:]:
    if mochi[-1] < d:
        mochi.append(d)

print(len(mochi))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

/*
bool cmp(const pair<LL,LL> &x, const pair<LL,LL> &y)
{
    return x.first < y.first;
}
*/

int main(){
    LL n;
    LL m;
    cin >> n >> m;
    vector<pair<LL,LL>> ab(m);
    vector<pair<LL,LL>> cut;

    for(LL i=0; i<m; i++){
        cin >> ab[i].first >> ab[i].second;
        ab[i].first--;
        ab[i].second--;
    }
    sort(ab.begin(), ab.end());
    for(LL i=0; i<m; i++){
        if(cut.size()==0){
            cut.push_back(make_pair(ab[i].first, ab[i].second));
        }else if(ab[i].first<cut[cut.size()-1].second){
            cut[cut.size()-1].first=max(cut[cut.size()-1].first, ab[i].first);
            cut[cut.size()-1].second=min(cut[cut.size()-1].second, ab[i].second);
        }else{
            cut.push_back(make_pair(ab[i].first, ab[i].second));
        }
    }

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

    return 0;
}


Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mx = 1e18+10;
void solve(){
    //dp[i] min weight of value i
    ll n,W;
    cin>>n>>W;
    ll V=0;
    vector<ll>wt(n),val(n);
    for(int i=0;i<n;i++) {cin>>wt[i]>>val[i];}
    for(auto x:val) V+=x;
    vector<ll>dp(V+1);
    dp[0]=0;
    for(int i=1;i<=V;i++)
    dp[i] = mx;
    for(int i=0;i<n;i++){
        vector<ll>ndp(V+1);
        for(int j=0;j<=V;j++){
            if(val[i]<=j)
            ndp[j] = min(dp[j],wt[i]+dp[j-val[i]]);
            else ndp[j]=dp[j];
        }
        dp=ndp;
    }
    ll res=0;
    for(ll i=V;i>=0;i--)
    {
        if(dp[i]<=W) {cout<<i;break;}
    }
}
int main(){
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

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

typedef long long ll;
typedef long double ld;

int main(){
    int N,x(0);
    cin >> N ;
    int i(0),ans(0);
    while(x<N){
       x = i*1.08;
       if(N==x){
           ans = i;
           break;
        }
       i++;
    }
    if(ans == 0){
        cout << ":(" << endl;
    }
    else{
        cout << ans << endl;
    }


}

Measured memory_bytes: 3596
package main

import "fmt"

func main() {
	var k, s int
	fmt.Scan(&k, &s)

	count := 0

	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			z := s - x - y
			if 0 <= z && z <= k && x+y+z == s {
				count++
			}
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

ll solve(string &s, vector<ll> &a){
    ll n = a.size();
    vector<ll> basis;
    rrep(i,n,0){
        for(auto &x : basis) chmin(a[i], a[i] ^ x);
        if(a[i]){
            if(s[i] == '1') return 1;
            basis.emplace_back(a[i]);
        }

    }
    return 0;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll q; cin >> q;
    while(q--){
        ll n; cin >> n;
        vector<ll> a(n);
        rep(i,0,n) cin >> a[i];
        string s;cin >> s;

        cout << solve(s, a) << "\n";
    }
}

Measured memory_bytes: 3572
import math

def append_factor(f, p):
    if p not in f:
        f[p] = 0
    f[p] += 1

def factors(n):
    l = int(math.sqrt(n)) + 1
    ret = {}
    while n % 2 == 0:
        append_factor(ret, 2)
        n //= 2
    while n % 3 == 0:
        append_factor(ret, 3)
        n //= 3
    for i in range(6, l, 6):
        while n % (i - 1) == 0:
            append_factor(ret, i - 1)
            n //= (i - 1)
        while n % (i + 1) == 0:
            append_factor(ret, i + 1)
            n //= (i + 1)
    if n != 1:
        append_factor(ret, n)

    return ret

def minimum_sum(x):
    # find the minimum integer n where n(n+1)/2 <= x
    # n^2 < n(n+1) <= 2x < (n+1)(n+2) < (n+2)^2

    n = int(math.sqrt(x))
    while (n + 1)*(n + 2) <= 2*x:
        n += 1

    return n

def main():
    N = int(input())
    fs = factors(N)
    # print(fs)
    ans = 0
    for f in fs:
        ans += minimum_sum(fs[f])
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

int main(void){
    ll x,y;
    cin>>x>>y;
    cout<<x+y/2<<endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

struct Data {
    long long val;
    int ind;
    char c;
    Data(long long val, int ind, char c) : val(val), ind(ind), c(c) { }
    friend bool operator < (Data a, Data b) { return a.val < b.val; }
};
    
int main() {
    int n; cin >> n;
    vector<Data> input;
    long long asum = 0; long long bsum = 0;
    for (int i = 0; i < n; ++i) {
        long long a, b;
        cin >> a >> b;
        asum += a, bsum += b;
        input.push_back(Data(a, i, 'a'));
        input.push_back(Data(b, i, 'b'));
    }
    long long res = min(asum, bsum);
    
    sort(input.begin(), input.end());
    long long tmp = 0;
    int anum = 0; int bnum = 0;
    set<int> se;
    for (int i = 0; i < n; ++i) {
        tmp += input[i].val;
        if (input[i].c == 'a') ++anum;
        else ++bnum;
        se.insert(input[i].ind);
    }
    if (se.size() == n) {
        if (anum && bnum) {
            if (input[n-1].ind == input[n].ind) {
                tmp += min(input[n+1].val - input[n-1].val,
                           input[n].val - input[n-2].val);
            }
            else {
                tmp += input[n].val - input[n-1].val;
            }
        }
    }
    res = min(res, tmp);

    cout << res << endl;
}


Measured memory_bytes: 8684
N = int(input())
A=[0]*N
for i in range(N):
    A[i] = list(map(int, input().split()))
from itertools import groupby, accumulate, product, permutations, combinations
def solve(N,A):
    mod = 10**9+7
    dp = [0]*(1<<N)
    dp[0] = 1
    for i in range(1,N+1):  
        for com in combinations(range(N),i):
            s = 0
            for c in com:
                s += 1<<c
            for rem in com:
                dp[s] += dp[s-(1<<rem)] * A[i-1][rem]
                dp[s] %= mod
    ans = dp[-1]
    return ans
print(solve(N,A))

Measured memory_bytes: 56940
import numpy as np


def main():
    N = int(input())
    T, A = map(int, input().split())
    H = list(map(int, input().split()))

    H_arr = np.array(H) * 0.006
    H_list = list(abs((T - H_arr) - A))

    ans = H_list.index(min(H_list)) + 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12504
from operator import itemgetter
N = int(input())
A = [None] * N
for i in range(N):
  A[i] = list(map(int,input().split()))

#s = sorted(A, key=itemgetter(0),reverse=True)
t = sorted(A, key=itemgetter(1))

time = 0
for i in range(N):
  if t[i][0] + time <= t[i][1]:
    time += t[i][0]
  else:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 55264
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

char buffer[51];

bool IsPalindromic(const int32_t num) {
  snprintf(buffer, sizeof(buffer), "%d", num);
  const string str = string(buffer);
  const int32_t length = static_cast<int32_t>(str.length());
  int32_t start = 0;
  int32_t end = length - 1;
  bool is_palindromic = true;
  while (start < end) {
    if (str.c_str()[start] != str.c_str()[end]) {
      is_palindromic = false;
    }
    ++start;
    --end;
  }
  return is_palindromic;
}

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

  int64_t A, B, C, K;
  cin >> A >> B >> C >> K;
  int64_t result = A - B;
  if (K % 2 == 1) {
    result = -result;
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

string s, t;

int main() {
    cin >> s >> t;

    int ls = s.size();
    int lt = t.size();

    vvi abcS(26);

    for (int i = 0; i < ls; i++)
        abcS[s[i] - 'a'].push_back(i);

    int last = -1;
    ll ans = 0;

    for (int i = 0; i < lt; i++) {
        int c = t[i] - 'a';

        if (abcS[c].size() == 0) {
            cout << -1 << endl;
            return 0;
        }

        auto itr = upper_bound(abcS[c].begin(), abcS[c].end(), last);

        if (itr == abcS[c].end()) {
            ans += ls - last + abcS[c][0];
            last = abcS[c][0];
        } else {
            ans += *itr - last;
            last = *itr;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1216
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    ll N,K;
    cin >> N >> K;
    ll mid = N/K;
    int ue = N%K;
    ll ans = 0;
    ans += (mid*mid*mid);
    if(K%2==1)
    {
        cout << ans << endl;
    }
    else
    {
        // if((N%K)>=K/2) ue = mid;
        // else ue = mid-1;
        // ans += (ue+mid)*(ue+mid)*(ue+mid);
        K /= 2;
        ll half = N/(K) - mid;
        ans += (half*half*half);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
  int n;
  long int sum=0;
  scanf("%d",&n);
  
  for(int i=1;i<=n;i++){
    if((i%3)!=0&&(i%5)!=0)
      sum+=i;
  }
  printf("%ld",sum);
   return 0;
}

Measured memory_bytes: 1712
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] b = new int[n - 1];
        for (int i = 0; i < b.length; i++) {
            b[i] = std.nextInt();
        }

        int[] c = new int[n + 1];
        c[0] = Integer.MAX_VALUE;
        c[n] = Integer.MAX_VALUE;

        for (int i = 1; i < n; i++) {
            c[i] = b[i - 1];
        }

        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Math.min(c[i], c[i + 1]);
        }

        System.out.println(Arrays.stream(a).sum());
    }
}


Measured memory_bytes: 28756
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <complex>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < v.size(); ++i) {
		cin >> v[i];
	}
	int result = 0;
	std::sort(v.begin(), v.end());
	result = std::abs(v[0] - v[N - 1]);
	
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}
ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
bool isPrime(int x){
    if(x==1) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
            return false;
        }
    }
    return true;
}


int main(){
    fast_io
    
    ll a, b, c, ta, tb, tc;
    cin>>a>>b>>c;
    if(a%2==1||b%2==1||c%2==1) {
        cout<<0<<endl;
        return 0;
    }
    else{
        if(a==b&&b==c) {
            cout<<-1<<endl;
            return 0;
        }
    }
    ll ans=0;
    while(a%2==0&&b%2==0&&c%2==0){
        ta=a;tb=b;tc=c;
        a=tb/2+tc/2;
        b=ta/2+tc/2;
        c=ta/2+tb/2;
        ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[4][4];
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
		{
		cin>>a[i][j];
		}
	int n;
	cin>>n;
	int b[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
	}
	bool f[4][4]={false};
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			for(int z=1;z<=n;z++)
			{
				if(a[i][j]==b[z])
				{
				f[i][j]=true; 
			}
		}
	}
}
	if(f[1][1]==true&&f[1][2]==true&&f[1][3]==true)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else if(f[2][1]==true&&f[2][2]==true&&f[2][3]==true)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else if(f[3][1]==true&&f[3][2]==true&&f[3][3]==true)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else if(f[1][1]==true&&f[2][2]==true&&f[3][3]==true)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else if(f[1][3]==true&&f[2][2]==true&&f[3][1]==true)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else if(f[1][1]==true&&f[2][1]==true&&f[3][1]==true)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else if(f[1][2]==true&&f[2][2]==true&&f[3][2]==true)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else if(f[1][3]==true&&f[2][3]==true&&f[3][3]==true)
	{
		cout<<"Yes"<<endl;
		return 0;
	} 
	else
	{
		cout<<"No"<<endl;
		return 0;
	}
}

Measured memory_bytes: 256
#!perl
use strict;
use warnings;
use utf8;
use feature qw/say/;

my $N_L = <STDIN>;
my ($N, $L) = split(' ', $N_L);
my @str;
for (1..$N) {
    my $tmp = <STDIN>;
    chomp $tmp;
    push @str, $tmp;
}
say join ('', sort { $a cmp $b } @str);


Measured memory_bytes: 768
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

K = int(input())

i = 7
s = set()
count = 1

while True:
    j = i % K
    if j == 0:
        print(count)
        sys.exit()

    if j in s:
        print(-1)
        sys.exit()

    s.add(j)
    i = j*10 + 7
    count += 1

Measured memory_bytes: 207660
S = list(input())
N = len(S)
flag = True
for i in range((N+1)//2-1):
    if S[i] != S[-1-i]:
        flag = False

mae = S[:((N-1)//2)]
ato = S[(N+3)//2-1:]

N = len(mae)
if N%2 == 1:
    for i in range((N+1)//2-1):
        if mae[i] != mae[-1-i]:
            flag = False
    for i in range((N+1)//2-1):
        if ato[i] != ato[-1-i]:
            flag = False
else:
    for i in range((N+1)//2):
        if mae[i] != mae[-1-i]:
            flag = False
    for i in range((N+1)//2):
        if ato[i] != ato[-1-i]:
            flag = False

if flag == True:
    print('Yes')
elif flag == False:
    print('No')

Measured memory_bytes: 3188
s = gets.chomp.split("")

rest_p = 0
won = 0
lost = 0
s.each do |ch|
  if ch == "g"
    if rest_p > 0
      rest_p -= 1
      won += 1 # p
    else
      rest_p += 1
    end
  else
    if rest_p > 0
      rest_p -= 1
    else
      rest_p += 1
      lost += 1
    end
  end
end

puts won - lost


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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  
  int ans = 10 * g + b;
  
  if (ans % 4 == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
const int IINF = 1e9;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl

template <typename T>
void dumpvec(vector<T> vec) {
  for (T cnt : vec) {
    cout << cnt << ", ";
  }
  cout << endl;
}

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

vector<string> split(string s, string delimiter) {
  int first = 0;
  int last = s.find_first_of(delimiter);
  vector<string> result;

  while (first < s.size()) {
    string sub = s.substr(first, last - first);
    result.push_back(sub);
    first = last + 1;
    last = s.find_first_of(delimiter, first);

    if (last == string::npos) {
      last = s.size();
    }
  }

  return result;
}

string join(vector<string> strings, string delimiter) {
  string result = "";
  for (int i = 0; i < strings.size(); i++) {
    if (result != "") result += delimiter;
    result += strings[i];
  }
  return result;
}

int main() {
  string s;
  cin >> s;
  string ans = "";
  for (char c : s) {
    if (c == '0') {
      ans += c;
    } else if (c == '1') {
      ans += c;
    } else {
      if (ans.length() > 0) {
        ans = ans.substr(0, ans.length() - 1);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
from math import pi, ceil, floor
import numpy as np
from collections import defaultdict, deque, Counter
from operator import itemgetter
from bisect import bisect_left, bisect_right, insort_left, insort_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    n = int(input())
    l = [input() for _ in range(n)]
    print(len(set(l)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 53540
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

ll gcd(ll x, ll y) {
  if(y == 0) {
    return x;
  }
  return gcd(y, x % y);
}

ll lcm(ll x, ll y) {
  return x / gcd(x, y) * y;
}

int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  ll g = gcd(n, m);
  bool ok = true;
  REP(i,0,g) {
    if(s[n / g * i] != t[m / g * i]) {
      ok = false;
      break;
    }
  }
  if(ok) {
    cout << lcm(n, m) << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


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

int main(){
	char buf[33];
	char words[1000][33];
	int times[1000];
	int i=0,j;
	int len,max,maxi,maxj;
	int found;
	
	for(j=0;j<1000;j++)  times[j] = 1;
	
	while(scanf("%s",buf)!=EOF){
		len = strlen(buf);
		if(i==0){
			max = len;
			maxi = 0;
		}else if(max<len){
			max = len;
			maxi = i;
		}
		found = 0;
		for(j=0;j<=i;j++){
			if(strcmp(buf,words[j])==0){
				times[j] += 1;
				found = 1;
			}
		}
		if(found == 0){
			strcpy(words[i],buf);
			i++;
		}
	}
	
	max = times[0];
	maxj = 0;
	for(j=0;j<i;j++){
		if(max<times[j]){
			max = times[j];
			maxj = j;
		}
	}
	
	printf("%s %s\n",words[maxj],words[maxi]);
	
	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#define LEN 2000000
#include <algorithm>

#define INF (1<<30)
using namespace std;


int parent(int i) {return i/2;}
int left(int i) {return i*2;}
int right(int i) {return i*2+1;}

int n,A[LEN+1];
void maxHeapify(int i)
{
    int left=2*i;
    int right=2*i+1;
    int largest=i;

    if(left<=n && A[left]>A[i]) largest=left;
    if(right<=n && A[right]>A[largest]) largest=right;

    if(largest!=i){
        swap(A[i],A[largest]);
        maxHeapify(largest);
    }
}

void heapIncreaseKey(int i,int key)

{
    if(key<A[i]) return;
    A[i]=key;
    while(i>1 && A[parent(i)]<A[i]){
        swap(A[i],A[parent(i)]);
        i=parent(i);
    }
}

void insert(int key)
{
    n++;
    A[n]=-INF;
    heapIncreaseKey(n,key);
}

int heapExtractMax()
{
    if(n<1) return -INF;
    int max=A[1];
    A[1]=A[n--];
    maxHeapify(1);
    return max;
}


int main()
{
    int key;
    char com[10];
    while(1){
        scanf("%s", com);
        if(com[0]=='e' && com[1]=='n') break;
        if(com[0]=='i'){
            scanf("%d",&key);
            insert(key);
        }
        else printf("%d\n",heapExtractMax());
    }
    return 0;
}



Measured memory_bytes: 7048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

int main(){
  string S; cin >> S;
  // 0 start
  int count0 = 0;
  rep(i,(int)S.size()){
    if(i%2 == 0 && S[i] == '1') ++count0;
    else if(i%2 == 1 && S[i] == '0') ++count0;
  }
  // 1 start
  int count1 = 0;
  rep(i,(int)S.size()){
    if(i%2 == 0 && S[i] == '0') ++count1;
    else if(i%2 == 1 && S[i] == '1') ++count1;
  }
  int ans = min(count0, count1);
  cout << ans << endl;
  return 0;
}

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

int main(){
	int n;
  	cin >> n;
  	
  	double base = 1.0 / n;
  	double ans = 0;
	rep(i, n+1) if(i%2 == 1) ans += base;
  	printf("%f\n", ans);
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a=0,b=0,c,d,k=0;
string s;
  cin>>c;
cin>>s;
for(int i=0;i<c;i++)
    if(s[i]=='R')
    a++;
  
for(int i=0;i<a;i++)
    if(s[i]=='W')
    b++;
cout<<b;
}


Measured memory_bytes: 3684
// Problem : B - Homework
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;


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

    long n, m;
    cin >> n >> m;
    vector<long> a(m, 0);
    for (long i = 0; i < m; i++) cin >> a[i];
    long long s = 0;
    for (long i = 0; i < m; i++) s = s + a[i];
    if (s > n) {
        cout << -1;
    } else {
        cout << n-s;
    }
    
    
    return 0;
}


Measured memory_bytes: 3696