akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
#define LINF 1e18+10  
using ll = long long;

using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
using Ps = pair<int, string>;

using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }

//const ll mod=998244353;
//const ll mod=1e9+7;
const ll MAX = 300000;

//////////////////////////////////////
ll modpow(ll a, ll b, int mod) {
    ll r = 1;
    while (b > 0) {
        if (b % 2 == 1)(r *= a) %= mod;
        (a *= a) %= mod;
        b /= 2;
    }
    return r;
}

int f(ll n) {
    int ret = 0;
    while (n > 0) {
        ret += n % 2;
        n /= 2;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt1 = 0;
    rep(i, n) {
        if (s[i] == '1')cnt1++;
    }
    vl a(n);
    vl b(n);
    ll suma = 0, sumb = 0;
    rep(i, n) {
        a[i] = modpow(2, n - 1 - i, cnt1 + 1);
        if (cnt1 > 1)b[i] = modpow(2, n - 1 - i, cnt1 - 1);
        if (s[i] == '1') {
            suma += a[i];
            sumb += b[i];
        }

    }
    vl ans(n);
    rep(i, n) {

        if (s[i] == '1') {
            int cnt = cnt1 - 1;
            ll tmp = sumb - b[i];
            if (cnt > 0) {
                tmp %= (cnt);
                ans[i]++;
            }
            else if (cnt)ans[i] = 1;
            while (tmp > 0) {
                cnt = f(tmp);
                tmp %= (cnt);
                ans[i]++;
            }
        }
        else {
            int cnt = cnt1 + 1;
            ll tmp = suma + a[i];
            if (cnt > 0) {
                tmp %= (cnt);
                ans[i]++;
            }
            else if (cnt)ans[i] = 1;
            while (tmp > 0) {

                cnt = f(tmp);
                tmp %= (cnt);
                ans[i]++;
            }
        }
    }
    rep(i, n)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 8416
#include <bits/stdc++.h>
using namespace std;
int n;
map<int,int>mp1,mp2;
vector<int> v;


tuple<int,int,int> fd_mx(map<int,int> mp){
    vector<int> tmp;
    int val = 0;
    int mx = 0;
    for(auto it : mp){
        if(mx < it.second){
            mx = it.second;
            val = it.first;
        }
        tmp.emplace_back(it.second);
    }
    sort(tmp.begin(),tmp.end(),[=](int x,int y){return x > y;});
    int f = tmp[0];
    int s = 0;
    if(tmp.size() > 1) s = tmp[1];

    return tuple<int,int,int>(val,f,s);
}

int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    v.resize(n + 1);
    for(int i = 1; i <= n; i++) cin>>v[i];
    for(int i = 1; i <= n; i++){
        if(i & 1) mp1[v[i]]++;
        else mp2[v[i]]++;
    }
    int ans = n;
    auto re1 = fd_mx(mp1);
    auto re2 = fd_mx(mp2);
    if(get<0>(re1) != get<0>(re2)) ans -= get<1>(re1) + get<1>(re2);
    else ans -= max(get<1>(re1),get<1>(re2)) + max(get<2>(re1), get<2>(re2));
    cout<<ans<<endl;
    return 0;
}


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

#define limit (int)(2e5 + 5)
#define mod (int)(1e9 + 7)

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

int a[limit],n;
bool marked[limit] = {0};
map<int,int> m;

int mark(int num)
{
	// cout << num << "\n";
	for (int i = 2*num; i <= a[n-1]; i += num)
	{
		if (m.find(i) != m.end())
		{
			// cout << m[i] << "\n";
			marked[m[i]] = true;
		}
	}

	return 0;
}

int main() {

	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

	cin >> n;

	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		// m[a[i]] = i;
	}

	sort(a,a+n);

	for (int i = 0; i < n; ++i)
	{
		m[a[i]] = i;
	}

	int ans = 0;

	if (a[0] != a[1])
	{
		ans++;
	}

	mark(a[0]);

	a[n] = -1;

	for (int i = 1; i < n; ++i)
	{
		if (a[i]==a[i-1] || a[i]==a[i+1])
		{
			if (a[i] != a[i-1])
			{
				mark(a[i]);
			}
			
			continue;
		}

		if (!marked[i])
		{
			// cout << a[i] << "\n";
			ans++;
			mark(a[i]);
		}

	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 13876
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

const double PI = acos(-1);

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

    double r; cin >> r;
    cout << setprecision(20) <<r*2 * PI << endl;
}

Measured memory_bytes: 3796
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    int r = scan.nextInt();
    int c = scan.nextInt();
    int[][] a = new int[r + 1][c + 1];

    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        a[i][j] = scan.nextInt();
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
        a[r][c] += a[i][j];
      }
    }
    
    for (int i = 0; i <= r; i++) {
      for (int j = 0; j < c; j++) {
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][c]);
    }

  }

}


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

map<ll,ll> mp;
int main(){
  mp[0]=1;
  ll n;
  cin>>n;
  ll sum=0,ans=0;
  for(int i=0;i<n;i++){
    ll x;
    cin>>x;
    sum+=x;
    ans+=mp[sum];
    mp[sum]++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chkmax(T& a,T b){return a<b?a=b,1:0;}
template<class T> inline bool chkmin(T& a,T b){return a>b?a=b,1:0;}
template<typename T> inline T& read(T& x){
    static char c; bool flag=0;
    while(!isdigit(c=getchar())) if(c=='-') flag=1;
    for(x=c-'0';isdigit(c=getchar());(x*=10)+=c-'0');
    if(flag) x=-x;
    return x;
}
const int maxn=200010;
int n,A,B;
int head[maxn],nxt[maxn<<1],to[maxn<<1],e;
int head2[maxn],nxt2[maxn<<1],to2[maxn<<1],e2;
struct Edge{
	int u,v;
} E[maxn];
void ae(int x,int y){
    to[++e]=y; nxt[e]=head[x]; head[x]=e;
}
void ae2(int x,int y){
    to2[++e2]=y; nxt2[e2]=head2[x]; head2[x]=e2;
}
int fa[maxn][20],dep[maxn];
void dfs(int u){
    for(int i=1;i<20;i++) fa[u][i]=fa[fa[u][i-1]][i-1];
    for(int i=head[u];i;i=nxt[i]){
        int v=to[i];
        if(v!=fa[u][0]){
            fa[v][0]=u; dep[v]=dep[u]+1; dfs(v);
        }
    }
}
int lca(int u,int v){
    if(dep[u]<dep[v]) swap(u,v);
    for(int i=19;i>=0;i--) if(dep[fa[u][i]]>=dep[v]) u=fa[u][i];
    if(u==v) return u;
    for(int i=19;i>=0;i--) if(fa[u][i]!=fa[v][i]) u=fa[u][i],v=fa[v][i];
    return fa[u][0];
}
bool p[maxn];
int ans;
void dfs2(int u,int d,int f){
    if(d>=dep[u]) return;
    chkmax(ans,dep[u]<<1);
    if(p[u]) cout<<-1<<endl,exit(0);
    for(int i=head2[u];i;i=nxt2[i]){
        int v=to2[i];
        if(v!=f) dfs2(v,d+1,u);
    }
}
int main(){
    read(n); read(A); read(B);
    for(int i=1;i<n;i++){
        int u,v;
        read(u); read(v);
        ae2(u,v); ae2(v,u);
		E[i].u=u; E[i].v=v;
    }
    for(int i=1;i<n;i++){
        int u,v;
        read(u); read(v);
        ae(u,v); ae(v,u);
    }
    dfs(B);
	for(int i=1;i<n;i++) if(dep[E[i].u]+dep[E[i].v]-2*dep[lca(E[i].u,E[i].v)]>=3) p[E[i].u]=p[E[i].v]=1;
    dfs2(A,0,0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 34688
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <stack>

using namespace std;

typedef long long LL;
typedef double db;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 105;
int main()
{
	int a , b ,c;
	cin >> a >> b >> c;
	int mod = c % b;
	bool flag = true;
	for(int i = 1; i <= b; i++)
	{
		if((i * a) % b == mod){
			flag = false;
			break;
			}
		}
	if(flag)cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
	}

Measured memory_bytes: 256
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS

vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int n;
cin>>n;
set<int> s;
FOR(i,0,n) {
    int a;
    cin>>a;
    if(s.find(a) == s.end()) s.insert(a);
    else s.erase(a);
}
cout<<s.size();
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000
#define fi first
#define se second
const int LEN = 2e5+5;
const int LEN5 = 1e5+5;
typedef long long ll;
int n,W,w[105],v[105]; ll dp[105][LEN5];
int main() {

   // freopen ("myfile.txt","r",stdin);
   // freopen ("myfile.txt","w",stdout);

   // ios_base::sync_with_stdio(0); cin.tie(NULL);
   scanf("%d%d",&n,&W);
   for(int i =1;i<=n;i++) scanf("%d%d",&w[i],&v[i]);
      /*
   for(int i = 1;i<=n;i++) {
      for(int k = 1;k<=W;k++) {
         if(k - w[i] >= 0) {
            dp[i][k-w[i]] = max(dp[i][k-w[i]],dp[i-1][k] + v[i]);
         }
         dp[i][k] = max(dp[i][k],dp[i-1][k]);
      }
   }
   */
   for(int i =0;i<=n;i++) {
      for(int k =0;k<=LEN5;k++)
         dp[i][k] = INT_MAX;
   }
   dp[0][0] = 0;
   for(int i =1;i<=n;i++) {
      for(int k =0;k<=LEN5;k++) {
         if(k+v[i] < LEN5 && w[i] + dp[i-1][k] <= W && dp[i-1][k] != INT_MAX) {
            dp[i][k+v[i]] = min(dp[i][k+v[i]],dp[i-1][k] + w[i]);
         }
         dp[i][k] = min(dp[i][k],dp[i-1][k]);
      }
   }

   ll ans = 0;
   for(int i =0;i<LEN5;i++) {
      if(dp[n][i] <= W) {
         ans = i;
      }
   }
   cout<<ans<<endl;
}   

Measured memory_bytes: 80128
# ABC 133 D
N = int(input())
A_list = list(map(int, input().split()))
x_list = [0] * N
x_list[0] = sum(A_list) - sum([2*a for a in A_list[1::2]])
for i, a in enumerate(A_list[:-1]):
    x_list[i+1] = 2*a - x_list[i]

print(*x_list)

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

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

  int b = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '#') b++;
  }

  int b2 = 0;
  int ans = INF;
  for (int i = 0; i <= s.size(); i++) {
    ans = min(ans, b2 + (n - i - (b - b2)));
    if (s[i] == '#') b2++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e18;

int main(){
	ll a;
	string s;
	cin>>a>>s;
	int tmp=(s[0]-'0')*100+(s[2]-'0')*10+s[3]-'0';
	cout<<tmp*a/100;
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e2 + 10;
const int M = 1e5 + 10;
/*=================================================================================*/

int n, k, a[N];
ll dp[M], sum[M];

int main() {
   ms(dp, 0);
   dp[0] = 1;
   scanf("%d %d", &n, &k);
   for1(i, n) scanf("%d", &a[i]);
   for1(i, n) {
      ms(sum, 0);
      for(int j = k; j >= 0; --j) {
         int l = j+1, r = j + min(k - j, a[i]);
         if(l > r) continue;
         sum[l] = (sum[l] + dp[j]) % mod;
         sum[r+1] -= dp[j];
         if(sum[r+1] < 0) sum[r+1] += mod;
         // debug1 printf("%d %d %lld %lld\n", l, r, dp[j], sum[l]);
      }
      for1(j, k) {
         sum[j] = (sum[j] + sum[j-1]) % mod;
         dp[j] = (dp[j] + sum[j]) % mod;
      }
   }
   printf("%lld\n", dp[k]);
   return 0;
}

Measured memory_bytes: 5384
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include <iomanip>
#include<sstream>
#include<string.h>
using namespace std;
bool z[1000000003];
int main()
{
    bool p;
    int n, i, a;
    while (cin >> n )
    {
        p = 0;
        memset(z, 0, 1000000003);
        while (n--)
        {
            cin >> a;
            if (z[a] == 1)
                p = 1;
           z[a]++;
        }
           if (p == 1)
               cout << "NO" << '\n';
           else cout << "YES" << '\n';
    }
}

Measured memory_bytes: 976896
S = input()
flag = False

if S == S[::-1]:
    if S[:len(S)//2] == S[:len(S)//2][::-1]:
        if S[(len(S)+1)//2:] == S[(len(S)+1)//2:][::-1]:
            flag = True
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import java.util.Scanner;

class Solver {
    public void Solve() {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a == b) {
            if (b == c) {
                System.out.println("No");
                return;
            } else {
                // cちがう
                System.out.println("Yes");
                return;
            }

        } else {
            if (b == c) {
                System.out.println("Yes");
                return;
            }
            if (a == c) {
                System.out.println("Yes");
                return;
            }
            System.out.println("No");
            return;
        }
    }

    Scanner sc;

    Solver(Scanner in) {
        this.sc = in;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Solver s = new Solver(sc);
        s.Solve();
        sc.close();
    }
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef vector<pii> vp;
typedef vector<pci> vpc;
typedef pair<int,pii> piii;

int OO = 2e9;
const double eps = 1e-9 ;
const int N = 50005;
int mx = -1e9 , mn = 1e9 ;

int main()
{
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long> x(X);
    vector<long long> y(Y);
    vector<long long> z(Z);

    for (int i = 0; i < X; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < Y; ++i) {
        cin >> y[i];
    }
    for (int i = 0; i < Z; ++i) {
        cin >> z[i];
    }
    sort(x.rbegin(), x.rend());
    sort(y.rbegin(), y.rend());
    sort(z.rbegin(), z.rend());

    vector<long long> ans;
    for (int i = 0; i < X; ++i) {
        for (int j = 0; j < Y; ++j) {
            for (int k = 0; k < Z; ++k) {
                if ((i + 1) * (j + 1) * (k + 1) > K)
                    break;
                ans.push_back(x[i] + y[j] + z[k]);
            }
        }
    }

    sort(ans.rbegin(), ans.rend());
    for (int i = 0; i < K; ++i) {
        cout << ans[i] << '\n';
    }

    return 0;
}


Measured memory_bytes: 1404
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

int A,B;
int x[111];
ll coudp[111][111][5555];
string divide[4] = { "dream","dreamer","erase","eraser" };
int main()
{
	int N;
	map<int, int> mp;
	cin >> N;

	for (int i = 2; i <= N; i++)
	{
		int x = i;
		for (int j = 2; j <= x; j++)
		{
			while (x % j == 0)
			{
				x /= j;
				mp[j]++;
			}
		}
	}
	ll ans = 1;
	for (auto x : mp)
	{
		ans = ((ans % mod) * (x.second+1) % mod) % mod;
	}

	cout << ans << endl;

	return 0;

		
}
	

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace template
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var n = int.Parse(cin.ReadLine);
            var r = cin.ReadIntArray(n);

            if (n == 1 && r[0] == 1)
            {
                Console.WriteLine(0);
                return;
            }

            int cnt = 0;
            int num = 1;
            bool flg = false;

            for (int i = 0; i < n; i++)
            {
                if (r[i] == num)
                {
                    num++;
                    flg = true;
                }
                else
                {
                    cnt++;
                }
            }

            if (flg)
            {
                Console.WriteLine(cnt);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) 
                {
                    return inputStream.Dequeue();
                }

                string[] tmp = _stream.ReadLine().Split(_separator);
                
                for (int i = 0; i < tmp.Length; ++i)
                {
                    inputStream.Enqueue(tmp[i]);
                }
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 35468
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=600;
    int N,M,Q;
    vector<int>lens[MAXN];
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N>>M>>Q;
        for(int u=0;u<M;u++){
            int l,r;
            cin>>l>>r;
            lens[l].push_back(r-l+1);
        }
        for(int u=0;u<MAXN;u++)sort(lens[u].begin(),lens[u].end());
        for(int u=0;u<Q;u++){
            int p,q,ans=0;
            cin>>p>>q;
            for(int v=0;v<=q-p+1;v++)
                ans+=upper_bound(lens[p+v].begin(),lens[p+v].end(),q-p+1-v)-lens[p+v].begin();
            cout<<ans<<"\n";
        }
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 2176
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
A, B, C, D = list(map(int, input().split()))
kou = (C * D) // gcd(C, D)
a1 = (A-1)//C
a2 = (A-1)//D
a3 = (A-1)//(kou)
a = (A-1)-(a1+a2-a3)
b1 = B//C
b2 = B//D
b3 = B//(kou)
b = B-(b1+b2-b3)
print(b-a)

Measured memory_bytes: 3064
// Vivek Rai
// Blazer_007

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define fastio 		ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define ppi			pair<ll,pii>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define bit(x, y)   (((x)>>(y))&1)
#define bpt(x)      (__builtin_popcount(x))
#define bptl(x)     (__builtin_popcountll(x))
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)

using namespace std;
using namespace __gnu_pbds;

typedef priority_queue<int> maxHeap;
typedef priority_queue<int, vector<int>, greater<int> > minHeap;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(index) -> value at given index or Kth smallest element in set
// order_of_key(X) -> number of elements strictly less than X
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> OST;

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

template <typename T>
istream &operator>>(istream &in, vector<T> &arr)
{
    for(int i = 0 ; i < arr.size() ; i++)
        cin >> arr[i];
    return in;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> arr)
{
    for(int i = 0 ; i < arr.size() ; i++)
        cout << arr[i] << " ";
    cout << endl;
    return os;
}

void solution()
{
	ll n;
    cin >> n;
    vi arr(n);
    cin >> arr;
    ll ans = 0;
    ll sum = arr[n-1] % hell;
    rloop(i,n-2,0)
    {
        ans += ( (arr[i] % hell) * (sum % hell) ) % hell;
        ans %= hell;
        sum = (sum + arr[i] % hell) % hell;
    }
    cout << ans << endl;
}

signed main()
{
    fastio

    ll t = 1;
    // cin >> t;
    loop(i, 1, t + 1)
    {
        //cout<<"Case #"<<i<<": ";
        solution();
    }
}


	

Measured memory_bytes: 4788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,x,y,s1=0,s2=0,s3=0,s4=0,t,z=0,d;
  vector<long long int> kire,ki,it;
    cin>>a>>b>>c>>x>>y;
    s1 = a*x + b*y;
    //cout<<s1<<endl;
    //d[0] = s1;
    if(x < y)
    {
        s2 = (x+x)*c;
        s2 += (y-x)*b;
        d = min(s1,s2);
        z = (y+y)*c;
        t = min(d,z);
        //d[1] = s2;
    }
    else if(x > y)
    {
        s3 = (y+y)*c;
        s3 += (x-y)*a;
        //cout<<s3<<endl;
        //d[2] = s3;
        d = min(s1,s3);
        z = (x+x)*c;
        t = min(d,z);
    }
    if(x == y)
    {
        s4 = (x+x)*c;
        t = min(s1,s4);
    }


    cout<<t<<endl;


}



Measured memory_bytes: 256
using System;
using System.Linq;

namespace _9_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string W = Console.ReadLine();
            W = W.ToLower();
            int a = 0;
            while (true)
            {
                string now = Console.ReadLine();
                if (now == "END_OF_TEXT")
                {
                    break;
                }
                now = now.ToLower();
                string[] x = now.Split();
                for (int i = 0; i < x.Count(); i++)
                {
                    if (x[i] == W)
                    {
                        a++;
                    }
                }
            }
            Console.WriteLine(a);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9332
n = int(input())
a = list(map(int,input().split()))
count4 = 0
count2 = 0
for i in a:
    if i%4 == 0:
        count4 += 1
    elif i%2 == 0:
        count2 += 1
if (n//2) <= count4:
    print("Yes")
elif (n-(count4*2) <= count2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

ll a[200000];
ll dp[200000][3];
int n;

ll f(int i, int s)
{
    if (i >= n)
        return 0;
    ll& sol = dp[i][s];
    if (sol != -1)
        return sol;
    sol = a[i] + f(i + 2, s);
    if (s > 0)
        sol = max(sol, f(i + 1, s - 1));
    return sol;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    memset(dp, -1, sizeof dp);
    cout << f(0, n % 2 + 1);
}


Measured memory_bytes: 14564
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans, s;
int main() {
    cin >> n >> m;
    vl A, B, C, D, X, Y;
    rep(i, n) {
        cin >> x;
        A.push_back(x);
    }
    rep(i, n) {
        cin >> x;
        B.push_back(x);
    }
    rep(i, n) {
        cin >> x;
        C.push_back(x);
    }
    rep(i, n) {
        cin >> x;
        D.push_back(x);
    }
    rep(i, n) {
        rep(j, n) {
            X.push_back(A[i] + B[j]);
            Y.push_back(C[i] + D[j]);
        }
    }

    sort(all(X));
    sort(all(Y));

    rep(i,X.size()){
        ans += upper_bound(all(Y), m - X[i]) - lower_bound(all(Y), m - X[i]);
    }

    cout << ans << endl;
}



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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

#define MAX 200010
int N, A[MAX], nex[MAX];

bool debug = 1;

void solve() {
  map<ll,ll> mp;
  rep(i,N) ++mp[i-A[i]];
  ll ans = 0;
  rep(i,N) {
    --mp[i-A[i]];
    ll v = i + A[i];
    ans += mp[v];
  }
  cout << ans << endl;
}

int main() {
  cin >> N;
  rep(i,N) cin >> A[i];
  solve();
  return 0;
}


Measured memory_bytes: 27020
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int pr[800010], tre[800010], lf, rt, val;
int b[200010];
void updt1(int x, int st, int nd){
  if(st>rt||nd<lf)
    return;
  if(st>=lf&&nd<=rt){
    pr[x]+=val;
    return;
  }
  pr[x*2]+=pr[x];
  pr[x*2+1]+=pr[x];
  pr[x]=0;
  int md=(st+nd)/2;
  updt1(x*2, st, md);
  updt1(x*2+1, md+1, nd);
  tre[x]=max(tre[x*2]+pr[x*2],tre[x*2+1]+pr[x*2+1]);
}
void updt2(int x, int st, int nd){
  if(st>rt||nd<lf)
    return;
  if(st==nd){
    pr[x]=0;
    tre[x]=val;
    return;
  }
  pr[x*2]+=pr[x];
  pr[x*2+1]+=pr[x];
  pr[x]=0;
  int md=(st+nd)/2;
  updt2(x*2, st, md);
  updt2(x*2+1, md+1, nd);
  tre[x]=max(tre[x*2]+pr[x*2],tre[x*2+1]+pr[x*2+1]);
}
void build(int x, int st, int nd){
  if(st==nd){
    pr[x]=0;
    tre[x]=b[st];
    return;
  }
  pr[x]=0;
  int md=(st+nd)/2;
  build(x*2, st, md);
  build(x*2+1, md+1, nd);
  tre[x]=max(tre[x*2],tre[x*2+1]);
}
int qry(int x, int st, int nd){
  if(st>rt||nd<lf)
    return -1e8;
  if(st>=lf&&nd<=rt){
    return pr[x]+tre[x];
  }
  int md=(st+nd)/2;
  return max(qry(x*2, st, md), qry(x*2+1, md+1, nd))+pr[x];
}
//pair<int,int> a[200010];
vector<int> a[200010];
int main(){
  int n, m, x, y;
  cin>>m>>n;
  for(int i=0; i<m; ++i){
    scanf("%d%d",&x,&y);
    a[x].push_back(y);
  }
  ++n;
  b[1]=b[0]=-1e9;
  for(int i=2; i<=n; ++i){
    b[i]=i-n;
  }
  for(int i=0; i<=n; ++i){
    sort(a[i].begin(), a[i].end());
  }
  build(1,1,n);
  int ans=0, tmp;
  ans=max(ans, m-n+1);
  for(int i=0; i<=n; ++i){
    for(int j=0; j<a[i].size(); ++j){
      tmp=a[i][j];
      lf=1;rt=tmp;
      val=1;
      updt1(1,1,n);
      tmp=qry(1,1,n);
      ans=max(ans, tmp);
    }
    lf=i+2;rt=n;
    val=-1;
    updt1(1,1,n);
    lf=i+1;rt=i+1;
    val=-1e9;
    updt2(1,1,n);
  }
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 14464
#a, v = gets.split.map(&:to_i)

n = gets.to_i

del = 1
ket = 1
arr = []
n -= 1
while true
    del *= 26
    if n >= del
        n -= del
        ket += 1
    else
        while true
            arr << n%26
            n /= 26
            break if n == 0
        end
        break
    end
end

ans = "a"*ket
arr.size.times do |i|
    ans[i] = ('a'.ord + arr[i]).chr
end

puts ans.reverse


Measured memory_bytes: 14392
#include<stdio.h>
main()
{
    int x,y,z,temp=0;
    scanf("%d %d %d",&x,&y,&z);
    temp=x;
    x=y;
    y=temp;
    temp=x;
    x=z;
    z=temp;
    printf("%d %d %d\n",x,y,z);
}


Measured memory_bytes: 1712
n = int(input())
lst = [int(i) for i in input().split()]
lst = sorted(lst)
count = 0
ans = 0
if n % 2 == 0:
    c = n//2
else:
    c = n//2+1
while count < c:
    if count == 0:
        num = lst.pop(-1)
        ans += num
    else:
        num = lst.pop(-1)
        ans += num * 2
    count += 1
if n % 2 == 1:
    ans -= num
print(ans)

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

struct edge{int s,t,n;}e[200010];
int n,h[200010],f[200010];

void dfs(int x,int fa)
{
	int s=0,sum=0,k=1;
	for (int i=h[x],y; y=e[i].t,i; i=e[i].n)
		if (y!=fa)  dfs(y,x),s|=sum&f[y],sum|=f[y];
	while ((k<s)||(sum&k))  k<<=1;
	f[x]=(sum^(sum&(k-1)))|k;
}

void work()
{
	scanf("%d",&n);
	for (int i=1,u,v,tot=0; i<n; i++)
		{
			scanf("%d %d",&u,&v);
			e[++tot]=(edge){u,v,h[u]},h[u]=tot;
			e[++tot]=(edge){v,u,h[v]},h[v]=tot;
		}
	dfs(1,0);
	printf("%d",int(log2(f[1])));
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
bool find1(vector< vector<int> >& C,vector< vector<int> >& check,int* findh,int* findw)
{
  for(int i = 0;i < C.size();++i)
    for(int j = 0;j < C[0].size();++j)
      if(C[i][j] == 1 && check[i][j] == 0){
	*findh = i;
	*findw = j;
	return true;
      }
  return false;
}
bool find2(vector< vector<int> >& C,vector< vector<int> >& check,int* findh,int* findw)
{
  if(C[*findh - 1][*findw - 1] == 1 && check[*findh - 1][*findw - 1] == 0){
    *findh -= 1;
    *findw -= 1;
    return true;
  }
  else if(C[*findh - 1][*findw] == 1 && check[*findh - 1][*findw] == 0){
    *findh -= 1;
    return true;
  }
  else if(C[*findh - 1][*findw + 1] == 1  && check[*findh - 1][*findw + 1] == 0){
    *findh -= 1;
    *findw += 1;
    return true;
  }
  else if(C[*findh][*findw - 1] == 1 && check[*findh][*findw - 1] == 0){
    *findw -= 1;
    return true;
  }
  else if(C[*findh][*findw + 1] == 1 && check[*findh][*findw + 1] == 0){
    *findw += 1;
    return true;
  }
  else if(C[*findh + 1][*findw - 1] == 1 && check[*findh + 1][*findw - 1] == 0){
    *findh += 1;
    *findw -= 1;
    return true;
  }
  else if(C[*findh + 1][*findw] == 1 && check[*findh + 1][*findw] == 0){
    *findh += 1;
    return true;
  }
  else if(C[*findh + 1][*findw + 1] == 1 && check[*findh + 1][*findw + 1] == 0){
    *findh += 1;
    *findw += 1;
    return true;
  }
  else return false;
}
int main()
{
  int w,h,findh,findw;
  stack< pair<int,int> > finish;
  queue<int> answer;
  while(cin >> w >> h && !(w == 0 && h == 0)){
    int howmany = 0;
    vector< vector<int> > C(h + 2,vector<int>(w + 2,0)),check(h + 2,vector<int>(w + 2,0)); 
    for(int i = 1;i <= h;++i)
      for(int j = 1;j <= w;++j)
	cin >> C[i][j];
    while(find1(C,check,&findh,&findw)){
      check[findh][findw] = 1;
      finish.push(make_pair(findh,findw));
      while(!finish.empty()){
	findh = finish.top().first;
	findw = finish.top().second;
	while(find2(C,check,&findh,&findw)){
	  finish.push(make_pair(findh,findw));
	  check[findh][findw] = 1;
	}
	finish.pop();
      }
      ++howmany;
    }
    answer.push(howmany);
  }
  for(;!answer.empty();answer.pop())
    cout << answer.front() << endl;
}

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

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

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

	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
	}
	
	long long ans = 0;
	for (int i = 0; i < n; i++)
	{
		int x = min(a[i], b[i]);
		b[i] -= x;

		int y = min(a[i + 1], b[i]);
		a[i + 1] -= y;

		ans += (long long)(x + y);
	}

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

Measured memory_bytes: 1024
#include<iostream>
int N, M;
int a[2000000], b[2000000];
bool D[2000000], D2[2000000];
int ans=0;
int main() {
	std::cin >> N >> M;
	for (int i = 0; i < M; i++) {
		std::cin >> a[i] >> b[i];
	}
	for (int i = 0; i < M; i++) {
		if (a[i] == 1) {
			D[b[i]-1] = true;
		}
			if (b[i] == N) {
				D2[a[i]-1] = true;
			}
		}
	for (int i = 0; i < M; i++) {
		if (D[i] == true && D2[i] == true) {
			ans = 1;
			break;
		}
	}

	if (ans == 1) {
		std::cout << "POSSIBLE" << "\n";
	}
	else {
		std::cout << "IMPOSSIBLE" << "\n";
	}
	return 0;
}

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

int main(){
    long long n, i, a[200100], ans[200100]={0}, tmp=0;
    map<long long, long long> mp;
    cin >> n ;
    for(i=0;i<n;i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    for(auto x : mp){
        tmp+=x.second*(x.second-1)/2;
    }
    for(i=0;i<n;i++){
        ans[i]=tmp-mp[a[i]]+1;
    }
    for(i=0;i<n;i++){
        cout << ans[i] <<endl;
    }
    return 0;
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  map<string,int> mp;
  for(int i=0;i<N;i++){
    string s;
    cin>>s;
    mp[s]++;
  }
  int mx=0;
  for(auto x:mp){
    mx=max(mx,x.second);
  }
  for(auto t:mp){
    if(mx==t.second){
      cout<<t.first<<endl;
    }
  }
  return 0;
}
      


Measured memory_bytes: 25216
// V - Subtree
// https://atcoder.jp/contests/dp/tasks/dp_v
// https://www.youtube.com/watch?v=r9hbdyVkz-I
#include <bits/stdc++.h>
using namespace std;

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int n,m;
vector<vector<int>> to;
vector<ll> dp;
vector<ll> ans;


ll dfs(int x,int p){
    if(dp[x]!=0) return dp[x];
    if(to[x].size()==0){
        dp[x]=1;
        return 1;
    }
    ll ret=1;
    for(int y : to[x]){
        if(y==p)continue;
        ret*=dfs(y,x)+1;
        ret%=m;
    }
    dp[x]=ret;
    return ret;
}

//rerooting
void dfs2(int x,int p){
    ans[x] = dp[x];

    int sz=to[x].size();
    //子のdpの値の左右の累積積
    vector<ll> l(sz+1), r(sz+1);
    l[0]=1;
    rep(i,sz) l[i+1]=(l[i]*(dp[to[x][i]]+1))%m;
    r[sz]=1;
    for(int i=sz-1;i>=0;i--) r[i]=(r[i+1]*(dp[to[x][i]]+1))%m;
    
    rep(i,sz){
        int nv=to[x][i]; // 子
        if(nv==p) continue;
        ll tmp_x = dp[x];
        ll tmp_nv = dp[nv];
        dp[x]=(l[i]*r[i+1])%m;
        dp[nv]*=dp[x]+1;
        dp[nv]%=m;
        dfs2(nv, x);
        // 元に戻す
        dp[x] = tmp_x;
        dp[nv] = tmp_nv;
    }
}

int main(){
    cin>>n>>m;
    to.resize(n);
    dp.resize(n);
    ans.resize(n);
    int x, y;
    rep(i,n-1){
        cin>>x>>y;
        x--;
        y--;
        to[x].push_back(y);
        to[y].push_back(x);
    }
    dfs(0, -1);
    dfs2(0, -1);
    rep(i,n) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 22708
import sys
from operator import itemgetter
n=int(input())
a=[tuple(map(int,input().split())) for _ in range(n)]
a.sort(key=itemgetter(1))
tm=0
for i in range(n):
    tm+=a[i][0]
    if tm>a[i][1]:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 83288
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Main {
    int N;
    string X;
    void input() { cin >> N >> X; }
    void output() {
        bitset<200000> bs(X);
        int total = bs.count();
        vector<int> popcounts = {total + 1, total - 1};
        vector<vector<int>> add(2, vector<int>(N));
        vector<ll> preprocessed(2);
        REP(i, 2) {
            if (popcounts[i] <= 0) break;
            add[i][0] = 1 % popcounts[i];
            preprocessed[i] = bs[0] * add[i][0];
            REP(j, N - 1) {
                add[i][j + 1] = add[i][j] * 2 % popcounts[i];
                preprocessed[i] =
                    (preprocessed[i] + bs[j + 1] * add[i][j + 1]) %
                    popcounts[i];
            }
        }
        REPR(j, N) {
            int i = bs[j];
            if (popcounts[i] <= 0) {
                cout << 0 << endl;
                continue;
            }
            int res = 1;
            int x = preprocessed[i];
            if (i == 0) {
                x = (x + add[i][j]) % popcounts[i];
            } else {
                x = (x - add[i][j] + popcounts[i]) % popcounts[i];
            }
            while (x > 0) {
                bitset<20> bit = x;
                ll sum = 0;
                REP(k, 20) {
                    sum = (sum + bit[k] * (1 << k) % bit.count()) % bit.count();
                }
                x = sum;
                ++res;
            }
            cout << res << endl;
        }
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 5944
room = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]

n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    room[b - 1][f - 1][r - 1] += v

for j, b in enumerate(room):
    for f in b:
        for r in f:
            print('', r, end='')
        print()

    if j != 3: print('#' * 20)


Measured memory_bytes: 5636
open System
open System.Collections
open System.Collections.Generic
open System.IO
open System.Linq

let read() = Console.ReadLine()

[<EntryPoint>]
let main _ = 
    let N = read() |> int
    let S = 
        Array.init N (fun _ -> read().First())
    
    let ans = 
        let cnt(c) = 
            S
            |> Array.filter(fun x-> x =c)
            |> Array.length
            |> int64
        let a = cnt('M') 
        let b = cnt('A') 
        let c = cnt('R')
        let d = cnt('C')
        let e = cnt('H')
        a*b*c + a*b*d + a*b*e + a*c*d + a*c*e + a*d*e
        + b*c*d + b*c*e + b*d*e
        + c*d*e
    
    printfn "%i" ans
    0



Measured memory_bytes: 19032
#include <iostream>

using namespace std;

int N;

int a[200005];

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}

	int num = 0;

	for (int i = 1; i <= N; i++) {
		if (a[i] == num + 1) { num++; }
	}

	if (num == 0) { cout << -1 << endl; }
	else { cout << N - num << endl; }

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#define VMAX 10000

int main(){
  unsigned short *A,*B;
  int i,j,n;
  int C[VMAX+1];
 
  scanf("%d",&n);
  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]); 
  }
  
  for(i=0;i<VMAX;i++){
    C[i] = 0;
  }
  
  for(j=0;j<n;j++){
    C[A[j]]++;
  }

  for(i=1;i<VMAX;i++){
    C[i] = C[i] + C[i-1];
  }
  
  for(j=n-1;j>=0;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i=1;i<n+1;i++){
    if(i == n) printf("%d\n",B[i]);
    else printf("%d ",B[i]);
   }
  return 0;
}



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

using namespace std;

const int N = 234567;
int n, a[N], p[N], f[N];

int main() {
  
  cin >> n;
  for (int i = 1; i <= n; ++i) { cin >> a[i]; p[a[i]] = i; }

  memset(f, 0x00, sizeof(f));

  for (int i = 1; i <= n; ++i) {
    f[a[i]] = 1;
    if (a[i] - 1 >= 1 && p[a[i] - 1] < p[a[i]]) {
      f[a[i]] = f[a[i] - 1] + 1;
    }
  }

  cout << n - (*max_element(f + 1, f + n + 1)) << endl;

  return 0;
}

Measured memory_bytes: 2688
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    N, X, Y = iip()
    X, Y = sorted((X-1, Y-1))
    #print(X, Y)

    result = [0 for i in range(1, N)]
    for a in range(0, N):
        for b in range(a+1, N):
            d1 = b-a
            d2 = abs(X-a)+abs(Y-b)+1
            d = min(d1, d2)-1
            #print(a, b, d)

            result[d] += 1

    print("\n".join([str(i) for i in result]))


if __name__ == "__main__":
    main()

Measured memory_bytes: 43228
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
year = int(S[:4])
month = int(S[5:7])
day = int(S[8:10])

if year < 2019:
	print("Heisei")
elif year > 2019:
	print("TBD")
else:
	if month < 4:
		print("Heisei")
	elif month > 4:
		print("TBD")
	else:
		if day <= 30:
			print("Heisei")
		else:
			print("TBD")

Measured memory_bytes: 5200
n,k,q=list(map(int,input().split()))
a=[]
for i in range(q):
  a.append(int(input()))
from collections import Counter
ac_ans=Counter(a)


for i in range(n):
  if (k-q)+ac_ans.get(i+1,0)>0:
    print("Yes")
  else:
    print("No")
    


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

using namespace std;

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define prvc(a) {for (auto iiiiiiiiii : a) cout << iiiiiiiiii << ' '; cout << '\n';}
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()

ll next() {ll x; cin >> x; return x;}

const ll inf = 4e18 , mod = 1e9 + 7;
const int intf = 2e9 , maxn = (1 << 17);
const double PI = 3.141592653589 , eps = 1e-7;

void solve(){
    ll n , a , b;
    cin >> n >> a >> b;
    if (abs(a - b) % 2 == 0){
        cout << abs(a - b) / 2;
    } else {
        ll dist1 = abs(1 - a) + abs(1 - b);
        ll distn = abs(n - a) + abs(n - b);

        cout << min((dist1 + 1) / 2 , (distn + 1) / 2);
    }
}

int main()
{
    #ifdef HERE
        freopen("input.txt" , "r" , stdin);
    #else
        //freopen(".in" , "r" , stdin); freopen(".out" , "w" , stdout);
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #endif
    cout.precision(20);

    int t = 1;
    while(t --> 0){
        solve();
    }


    #ifdef HERE
        cout << setprecision(3) << fixed << "\n\nRuntime: " << (long double)(clock()) / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}
/*

*/


Measured memory_bytes: 256