akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll>P;
const ll mod = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool fl = true;;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
struct edge { ll to, cost; };

int main() {
	ll n, m, dis[1010][1010], a[1010], b[1010], c[1010];
	cin >> n >> m;
	int ans = m;
	for (int i = 0;i < m;i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 1;i <= n;i++) {
		for (int j = 1;j <= n;j++) {
			if (i == j)dis[i][j] = 0;
			else dis[i][j] = INF;
		}
	}
	for (int i = 0;i < m;i++) {
		dis[a[i]][b[i]] = min(dis[a[i]][b[i]], c[i]);
		dis[b[i]][a[i]] = min(dis[b[i]][a[i]], c[i]);
	}
	for (int k = 1;k <= n;k++) {
		for (int i = 1;i <= n;i++) {
			for (int j = 1;j <= n;j++) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}
	for (int i = 0;i < m;i++) {
		bool s = false;
		for (int j = 1;j <= n;j++) {
			if (dis[j][a[i]] + c[i] == dis[j][b[i]])s = true;
		}
		if (s)ans--;
	}
	cout << ans << endl;
	}

Measured memory_bytes: 2688
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace __gnu_pbds;
using namespace std;

ll mod = 1e9+7;

ll add(ll a, ll b) { return (a % mod + b % mod) % mod; }
ll mul(ll a, ll b) { return (a % mod * b % mod) % mod; }
ll debug(vector<int> a) { for(int i: a) cout << i << " "; return puts("\n"), 0;}

ll power(ll base, ll exp) {
    ll res = 1;
    while(exp) {
        if(exp&1) res = mul(res, base);
        base = mul(base, base);
        exp >>= 1;
    }
    return res;
}

ll inv(ll p) {
    return power(p, mod-2);
}


int main() {
    fastio
    string s[8] = {"", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
    map<string, int> mp;
    for(int i=1; i<8; i++) {
        mp[s[i]] = i;
    }
    string c; cin >> c;
    if(7-mp[c] == 0) cout << 7 << "\n";
    else cout << 7-mp[c];
}

Measured memory_bytes: 256
N=int(input())
task=[list(map(int,input().split())) for _ in range(N)]
s_t=sorted(task,key=lambda x: x[1])
total=0
flag=True
for i in s_t:
    total+=i[0]
    if total>i[1]:
        flag=False
        break
if flag:
    print("Yes")
else:
    print("No")

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


int main(){
  ll n;
  cin>>n;
  vector<ll>a(n,0);
  rep(i, n)cin >>a.at(i);
  sort(a.begin(),a.end());
  ll ans = 0, a1=0, a2=1,begin,end;
  if(n==1){
    if(a.at(0)!=1)cout<<1;
    else cout<<0;
  }
  
  else{
  while(a2<n){
    begin =a.at(a1), end=a.at(a2);
    if(end>begin){
        //cout<<a2-1<<" " << a1<<endl;
      if(a2-a1>begin){
      
        ans+=(a2-a1)-begin;
      }
      else if(a2-a1<begin){
        ans+=a2-a1;
      }
      a1=a2;
      a2+=1;  
      //cout<<"ans"<<ans<<endl;;
    }
    else{
      a2++;
    }
    
  }
  //cout << a1<<" "<< a2<<" "<<begin<<endl;

  if(a2-a1>begin){
    ans+=(a2-a1)-begin;
  }
  else if(a2-a1<begin){ans+=a2-a1;}
  cout<<ans;
}
}


Measured memory_bytes: 3932
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

s = 0
for i in range(N):
  s += bisect.bisect_left(A, B[i]) * (N-bisect.bisect_right(C, B[i]))

print(s)


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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	int c0 = 0, c1 = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') c0++;
		else c1++;
	}
	if (c0 > c1) cout << "Yes" << '\n';
	else cout << "No" << '\n';
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  DPp
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using P=pair<int,int>;
using ll = long long;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


vector<vector<int>>v(100005); // 頂点データ
int num=-200000;
int order[100005]={}; // 根からの番号を管理する
mint dp[100005][2]={}; // 調査結果
vector<vector<bool>> flag(100005,vector<bool>(2,false));

mint f(int i,int j){ // i:親 j=0:黒 j=1:白
    if(flag.at(i).at(j)==true) return dp[i][j];
    if(order[i]>num) order[i]=num; // 調査する順番、既に調査した頂点は書き換えない。子から戻る時に親に戻る時の判定にも使うため
    num++;
    int count=0;
    int my_oder=order[i];
    rep(x,v.at(i).size()){
        if(order[v.at(i).at(x)]>my_oder)count++;
    }
    if (count==0) {
        flag.at(i).at(j)=true;
        return dp[i][j]=1; // 子がない頂点は1を返す
    }
    mint sum=1;
    mint sum_w=1;
    if (j==0) { // 黒
        rep(x,v.at(i).size()){
            int now=v.at(i).at(x);
            if (order[now]>my_oder) sum*=f(now,1); // 自分より後ろの頂点だけ計算する
        }
        flag.at(i).at(j)=true;
        return dp[i][j]=sum;
    } else { // 白
        rep(x,v.at(i).size()){
            int now=v.at(i).at(x); // 自分より後ろの頂点だけ計算する
            if (order[now]>my_oder) sum_w*=(f(now,1)+f(now,0));
        }
        flag.at(i).at(j)=true;
        return dp[i][j]=sum_w;
    }
}
int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    int x,y;
    rep(i,n-1){
        cin>>x;
        cin>>y;
        v.at(x).push_back(y);
        v.at(y).push_back(x);
    }
    cout<<f(1,1)+f(1,0)<<endl;
    return 0;
}


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


int main() {
  int n, q, t;
  string name;
  queue<pair<string, int> > Q; // プロセスのキュー

  cin >> n >> q;

  // すべてのプロセスをキューに順番に追加する
  rep(i, n) {
    cin >> name >> t;
    Q.push(make_pair(name, t));  
  }

  pair<string, int> u;
  int elaps = 0, a;
  // シミュレーション
  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    a = min(u.second, q);
    u.second -= a;
    elaps += a;
    if (u.second > 0) {
      Q.push(u);
    } else {
      cout << u.first << " " << elaps << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 6320
#include <iostream>
#include <stdio.h>

class Pos {
public:
	const static int ABOVE = 1;
	const static int BELOW = 0;
	float x, y;
	int getWhichSide(Pos a, Pos b) {
		if (a.x == b.x) {
			return (x > a.x) ? ABOVE : BELOW;
		}
		float slope = (a.y - b.y) / (a.x - b.x);
		float bias =  b.y - slope * b.x;
		return (y > slope * x + bias) ? ABOVE : BELOW;
	}
};

int main () {
	Pos t1, t2, t3, p;
	while (~scanf("%f %f %f %f %f %f %f %f", &t1.x, &t1.y, &t2.x, &t2.y, &t3.x, &t3.y, &p.x, &p.y)) {
		if (
			p.getWhichSide(t1, t2) == t3.getWhichSide(t1, t2)
			&& p.getWhichSide(t2, t3) == t1.getWhichSide(t2, t3)
			&& p.getWhichSide(t1, t3) == t2.getWhichSide(t1, t3)
		) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}

	return 0;
}


Measured memory_bytes: 3192
/*in the name of Allah the most beneficent the most merciful.*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
#define base 139
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define out(x) cout << #x << " -> " << x << endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE   freopen("input.txt", "r", stdin);  freopen("out.txt", "w", stdout);
using namespace std;
const int B = 16, N = 100010, M = 5000010;
ll n, d, x, y, res;
int solve()
{
    in2(n, d);
    d*=d;
    while(n--)
    {
        in2(x,y);
        if(x*x+y*y<=d)
            res++;
    } 
    printf("%lld\n", res);
    return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    return solve();
}
/*

*/

Measured memory_bytes: 3824
n,m = map(int,raw_input().strip().split(' '))
follow = [[] for i in range(n)]
for i in range(m):
    s,t = map(int,raw_input().strip().split(' '))
    follow[s].append(t)
    follow[t].append(s)
 
color = {}
c = 0

for i in range(n):
    if not i in color:
        que = [i]
        color[i] = c
        while len(que) > 0:
            u = que[0]
            for v in follow[u]:
                if not v in color:
                    color[v] = c
                    que.append(v)
            del que[0]
        c += 1
 
 
q = int(raw_input())
for i in range(q):
    s,t = map(int,raw_input().strip().split(' '))
    if color[s] == color[t]:
        print 'yes'
    else:
        print 'no'

Measured memory_bytes: 32120
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	vs, cs := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		vs[i] = tmp
	}
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		cs[i] = tmp
	}
	sum := 0
	for i := 0; i < n; i++ {
		if vs[i] - cs[i] > 0 {
			sum += vs[i] - cs[i]
		}
	}
	fmt.Println(sum)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define in(s) ll s; cin>>s
#define pr(r) cout<<r<<endl
#define prr(m,n) cout<<m<<" "<<n<<endl
#define prarr(a,i,n) fab(j,i,n) cout<<a[j]<<" "
#define wh(t) ll t; cin>>t; while(t--)
#define sz(u) u.size()
#define all(v) v.begin(),v.end()
#define arr(a,n) ll a[n]; fab(i,0,n) cin>>a[i]
#define showdp(d,n,m) fab(i,0,n){ fab(j,0,m) cout<<d[i][j]<<" "; cout<<endl; }
#define prs(u) cout<<u<<" ";
#define fab(i,a,b) for(ll i=a;i<b;i++)
#define fba(i,b,a) for(ll i=b;i>=a;i--)
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MX 1000000007
#define MAX 10000007
#define endl "\n"
#define ll long long int
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define pl pair<ll,ll>
#define mxe(x,n) *max_element(x,x+n)
#define mne(x,n) *min_element(x,x+n)
#define mp make_pair
#define pb push_back
#define fs first
#define sd second
#define fr front()
#define bk back()
#define rr return
#define N 3005

bool rsort1(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.first > b.first);}
bool rsort2(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.second>b.second);}
bool sort2(const pair<ll,ll> &a,const pair<ll,ll> &b){ return (a.second < b.second);}

ll dp[N][N],vis[N],h,w;
string s[1005];

ll solve(ll i,ll j)
{
    if(i==0 && j==0)
        return dp[i][j]=1;
    if(i<0 || j<0)
        return 0;
    if(s[i][j]=='#')
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    else
        return dp[i][j]=((solve(i-1,j)%MX)+(solve(i,j-1)%MX))%MX;
}

int main()
{
	sup; 
	cin>>h>>w;
	fab(i,0,h)
	cin>>s[i];
	memset(dp,-1,sizeof(dp));
	pr(solve(h-1,w-1)%MX);
	//showdp(dp,h,w);
    return 0;
}


Measured memory_bytes: 71936
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0
using namespace std;
using ll = long long;

void testcase() {
    int n;

    cin >> n;

    vector<int> ans(n+1);
    for (int i=1; i*i <= n; i++) {
        for (int j=1; (i*i + j*j + i*j) <= n; j++) {
            for (int k=1; (i*i + j*j + k*k + i*j + j*k + k*i) <= n; k++) {
                ans[(i*i + j*j + k*k + i*j + j*k + k*i)]++;
            }
        }
    }

    for (int i=1; i<=n; i++) cout << ans[i] << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n;
vector<ll> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >>temp;
        a.push_back(temp);
    }
    ll ans=0;
    int r=0;
    ll sum=0;
    for(int l=0;l<n;l++){
        while(r<n){
        if((sum^a[r])==sum+a[r]){
            sum+=a[r];
            r++;
        }
        else{
            break;
        }
        }
        ans+=r-l;
        sum-=a[l];
    }
    cout<<ans<<"\n";
}
/*
Xorについて
X xor a xor a=X aを偶数回xorすれば消える

a + b − (a xor b) = 2 × (a and b)(ただしここで and はビットごとの論理積を表す)
*/


Measured memory_bytes: 2420
n = int(input())
s = [input() for _ in range(n)]
STR = "MARCH"
cnt = {c:0 for c in STR}
for ss in s:
  if ss[0] in STR:
    cnt[ss[0]] += 1
    
ans = 0
for i1 in range(5):
  for i2 in range(i1+1, 5):
    for i3 in range(i2+1, 5):
      ans += cnt[STR[i1]]*cnt[STR[i2]]*cnt[STR[i3]]

print(ans)

Measured memory_bytes: 9752
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
	ll n;
	cin>>n;
	ll facs=0,ans=0;
	rep (i,1,n+1)
	{
		ll facs=n/i;
		if (n%i==0)
		{
			facs--;
		}
		ans+=facs;
	}
	cout<<ans<<"\n";

}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[1<<18];

llint calc(llint l, llint r)
{
	if(l == r) return a[l];
	llint m = (l+r)/2;
	llint x = calc(l, m), y = calc(m+1, r);
	return max(x, y) - min(x, y);
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint N = 1<<n;
	for(int i = 0; i < N; i++) cin >> a[i];
	
	cout << calc(0, N-1) << endl;
	
	return 0;
}

Measured memory_bytes: 2304
#include <string>
#include <iostream>
int main(void){
  int n, k;
  std::cin >> n >> k;
  std::string s;
  std::cin >> s;
  int cnt = 0;
  for(int i = 0; i < n-1; i++){
  	if( s[i] == s[i+1] )
      cnt ++;
  }
  cnt += 2*k;
  if( cnt >= n){
    cnt = n-1;
  }
  std::cout << cnt << std::endl;
}

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

int main(){
  int N;
  int W[101];
  cin >> N;
  int bef,lat,dif1,ans;
  int total = 0;
  for(int i=0;i<N;i++) cin >> W[i];
  for(int i=0;i<N;i++)total += W[i];
  for(int i=0;i<N;i++){
    bef = 0;
    for(int j=0;j<=i;j++){
      bef += W[j];
    }
    lat = total-bef;
    dif1 = lat-bef;
    if(dif1<0)dif1 *= (-1);
    if(i==0)ans = dif1;
    if(dif1<ans)ans = dif1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int S, W;
  cin >> S >> W;
  if(S <= W){
    print("unsafe");
  } else {
    print("safe");
  }

}


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

int main(void)
{
	int n;
	cin >> n;
	
	vector<int> h;
	h.push_back(0);
	for(int i = 0, tmp; i < n; ++i){
		cin >> tmp;
		h.push_back(tmp);
	}
	
	bool ans = true;
	// h in 0..n
	for(int i = n - 1; i > 0; --i){
		// 必要があれば1下げる
		if(h.at(i) > h.at(i+1)){
			--h.at(i);
		}
		
		// 判定処理
		if(h.at(i) > h.at(i+1)){
			ans = false;
			break;
		}
	}
	
	cout << (ans ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 892
#include<stdio.h>

#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P){
  int i = 0,j;
  for(j = 0; j < k; j++){
    llong s = 0;
    while(s + T[i]<=P){
      s += T[i];
      i++;
      if(i==n) return n;
    }
  }
  return i;
}

int solve(){
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while(right - left > 1){
    mid = (left + right) / 2;
    int v = check(mid);
    if(v >=n) right = mid;
    else left = mid;
  }
  return right;
}

int main(){
  int i;
  scanf("%d%d",&n,&k);
  for(i = 0; i<n;i++) scanf("%d",&T[i]);
  llong ans = solve();
  printf("%d\n",ans);
}



Measured memory_bytes: 2608
n,m,x,y = map(int,input().split())
lis = list(map(int,input().split()))
li = list(map(int,input().split()))
for i in range(-100,300):
  if max(lis) < i and i <= min(li):
    if x < i and i <= y:
      print("No War")
      exit()
print("War")

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


int main() {
	char s[4];
	scanf("%s", s);
	int count=0;

	for (int i = 0; i<=2; i++) {
		if (s[i] == 'R') {
			count++;
		}
	}

	if (count==2&&s[1] == 'S') {
		count = 1;
	}

	printf("%d\n", count);
	return 0;
}

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

int main() {
	int N; cin >> N;
	vector<string> S(N);
	for (int i = 0; i < N; i++)
	{
		cin >> S[i];
	}
	int cnt = 1;
	sort(S.begin(), S.end());
	for (int i = 0; i < N-1; i++)
	{
		if (S[i] != S[i + 1])cnt++;
	}
	cout << cnt << endl;
}


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

int main()
{
  int N;
  cin >> N;
  vector<string> W;
  for(int i=0; i<N; i++)
  {
     string str;
     cin >> str;
     W.push_back(str);
  }

  for(int i=1; i<N; i++)
  {
  	

  	if(!(W[i-1][W[i-1].length()-1]==W[i][0]))
  	{
  		cout << "No" << endl;
  		return 0;
  	}

  	for(int j=0; j<i; j++)
  	{
  		if(W[i]==W[j])
  		{
  		   cout << "No" << endl;
  		   return 0;
  		}
  	}
  
  }
  cout << "Yes" << endl;
  
  return 0;
}

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

int n;
vector<vector<int>> g;

void bfs(vector<long long> sums, vector<long long> &anss){
  vector<int> seen(n,-1);
  seen[0] = 1;
  queue<int> q;
  q.push(0);
  anss[0] = sums[0];
  while(!q.empty()){
    int now = q.front();
    q.pop();

    for(int next:g[now]){
      if(seen[next]==-1){
        q.push(next);
        anss[next] = sums[next] + anss[now];
        seen[next] = 1;
      }
    }
  }
}

int main(){
  int q;
  cin >> n >> q;
  g.assign(n,vector<int>());

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

  vector<long long> anss(n);
  vector<long long> sums(n);
  for (int i = 0; i < q; i++)
  {
    int p;
    long long x;
    cin >> p >> x;
    p--;
    sums[p]+=x;
  }
  bfs(sums,anss);
  
  for (int i = 0; i < n; i++)
  {
    cout << anss[i] << endl;
  }
}

Measured memory_bytes: 18292
#include<stdio.h>
int main()
{
    long long n,m,s,m1;
	scanf("%lld%lld",&n,&m);
	m1=m/2;
	if(n>m1)
	s=m/2;
	else if(n==m1)	
	s=n;
	else
	{
		s=n+(m-2*n)/4;
	}
	printf("%lld\n",s);
	return 0;
} 

Measured memory_bytes: 128
N = int(input())
A =  list(map(int, input().split()))

four = 0
odd = 0
for a in A:
    if a % 2 == 1:
        odd += 1
    if a % 4 == 0:
        four += 1
if N % 2 == 1:
    if odd - four <= 1:
        print("Yes")
    else:
        print("No")
else:
    if odd - four <= 0:
        print("Yes")
    else:
        print("No")

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

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

    queue<ll> que;
    vector<ll> v;

    for (int i = 1; i <= 9; ++i) {
        que.push(i);
        v.push_back(i);
    }

    while (v.size() < K) {
        ll t = que.front(); que.pop();
        string tmp = to_string(t);
        if (tmp[tmp.size()-1] - '0' > 0) {
            ll t2 = t * 10 + ((tmp[tmp.size()-1] - '0')-1);
            que.push(t2);
            v.push_back(t2);
        }

        ll t3 = t * 10 + (tmp[tmp.size()-1]-'0');
        que.push(t3);
        v.push_back(t3);

        if (tmp[tmp.size()-1] - '0' < 9) {
            ll t4 = t * 10 + ((tmp[tmp.size()-1]-'0') + 1);
            que.push(t4);
            v.push_back(t4);
        }
    }

    sort(v.begin(), v.end());
    cout << v[K-1] << endl;

}


Measured memory_bytes: 1620
cards = [[False for i in range(14)] for j in range(4)]
marks = ['S', 'H', 'C', 'D']

n = int(input())
for i in range(n):
    mark, num = input().split()
    num = int(num)
    cards[marks.index(mark)][num] = True

for i in range(4):
    for j in range(1, 14):
        if not cards[i][j]:
            print(marks[i], j)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define INF 1e9 + 7
#define nd second
using namespace std;
typedef long long int lo;

int main(){
    //freopen("kenar.gir","r",stdin);
    //freopen("kenar.cik","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

    lo n,s;
    cin >> n >> s;
    lo arr[n];
    for(lo i = 0;i < n;i++) cin >> arr[i];
    sort(arr,arr + n);
    lo sum = 0;
    for(lo i = 0;i < n - s;i++){
        sum += arr[i];
    }
    cout << sum;
}



Measured memory_bytes: 1792
//面倒なので、エラー処理（empty確認）は無し。
//数値かどうかの判定で、面白いのがあったので使う。


#include <iostream>
#include <stack>
#include <cstdlib> //atoi使うのに必要
//#include <cctype>
#include <sstream>

using namespace std;

int main() {
    string buf;
    int int_check;
    int right,left; //スタックから取り出した値を入れる。　計算用
    stack<int> st;
    
    while(cin >> buf){ //入力がある限りループ
    
        stringstream ss(buf);
        //(ss >> int_check) の返り値は代入成功か失敗かなので０が入っても大丈夫。
        if( ss >> int_check ) st.push( atoi(buf.c_str()) );
        else{
            left = st.top();
            st.pop();
            right = st.top();
            st.pop();
            
            if(buf=="+") st.push(right + left);
            else if(buf=="-") st.push(right - left);
            else st.push(right * left);            
        }        
    }
    
    cout << st.top() << endl;
	
	return 0;
}

Measured memory_bytes: 1240
n, k = gets.split.map(&:to_i)
r, s, p = gets.split.map(&:to_i)
t_input = gets.split('').map(&:to_s)
t_output = Array.new(n-1)
(0..n-1).each do |i|
  case t_input[i]
  when 'r'
    t_output[i] = 'p'
  when 's'
    t_output[i] = 'r'
  else
    t_output[i] = 's'
  end
end
(k..n-1).each do |i|
  t_output[i] = 't' if t_output[i] == t_output[i-k]
end
r_score = r * t_output.count('r')
s_score = s * t_output.count('s')
p_score = p * t_output.count('p')
puts r_score + s_score + p_score


Measured memory_bytes: 14332
import java.util.*;
import java.io.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = (long) 1e9 + 7;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static int maxn = 100005;

    static class sort implements Comparator<String> {
        public int compare(String a, String b) {
            return a.length() - b.length();
        }
    }

    static int func(int a, int b, int x) {
        return ((a * x) / b) - (a * (x / b));
    }

    static void solve() {
        long x = nlo();
        long y = 100;
        long ans = 0;
        for (long i = 1; i < Long.MAX_VALUE; i++) {
            y = (y + (y / 100));
            if (y >= x) {
                ans = i;
                break;
            }
        }
        out.println(ans);
    }
}

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

//kieutrave ten ham(tham so)
//s.substr(noibatdau,soluong)
int main(){
	string s,t;
	int dodai=0;
	cin>>s>>t;
	
	for (int i=0;i<s.size();i++){
		dodai=dodai+1;
	}
	 t = t.substr(0, dodai);
	if (s==t){
		cout<<"Yes";
	}
	else cout<<"No";
	
		
	return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    string S;
    cin >> S;
    ll a = (S[0] - '0') * 10 + (S[1] - '0');
    ll b = (S[2] - '0') * 10 + (S[3] - '0');

    if (a > 12 || a <= 0) {
        if (b <= 0 || b > 12)
            cout << "NA" << endl;
        else
            cout << "YYMM" << endl;
    }
    else {
        if (b > 12 || b <= 0)
            cout << "MMYY" << endl;
        else
            cout << "AMBIGUOUS" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define INF 1000000000000
#define MOD 1000000007
#define DEBUG(x) cerr<<'>'<<#x<<':'<<x<< endl
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll N;
    cin >> N;
    ll hash[200005] = {0};
    ll ar[200005];
    set <ll> unique;
    for(ll i = 0; i < N; i++)
    {
        ll el;
        cin >> el;
        ar[i] = el;
        unique.insert(el);
        hash[el] += 1;    
    }
    ll ans = 0;
    for(auto un: unique)
    {
        ans += hash[un] * (hash[un] - 1) / 2;
    }
    for(ll i = 0; i < N; i++)
    {
        ll cur = ans + (1 - hash[ar[i]]);
        cout << cur << endl;
    }
    return 0;
}


Measured memory_bytes: 10624
prime=[2]
for i in range(3,1000000,2):
    primeq=True
    for p in prime:
        if i%p==0:
            primeq=False
            break
        if i<p*p:break
    if primeq:prime.append(i)
while True:
    try:
        n=int(input())
        ans=0
        for p in prime:
            if p>n:break
            ans+=1
        print(ans)
    except:break



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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

typedef pair<int,int> P;

int main(){
    int n; scanf("%d",&n);
    vector<int> a(n); vector<vector<P>> xy(n);
    rep(i,0,n){
        scanf("%d",&a[i]); xy[i].resize(a[i]);
        rep(j,0,a[i]){
            scanf("%d%d",&xy[i][j].first,&xy[i][j].second);
            xy[i][j].first--;
        }
    }
    int ans=0;
    rep(mask,0,1<<n){
        bool f=1;
        rep(i,0,n)if(mask>>i&1){
            rep(j,0,a[i]){
                if((mask>>i&1)==(mask>>xy[i][j].first&1)){
                    if(xy[i][j].second==0){
                        f=0; 
                        i+=n; j+=a[i]; break;
                    }
                }
                if((mask>>i&1)!=(mask>>xy[i][j].first&1)){
                    if(xy[i][j].second){
                        f=0; 
                        i+=n; j+=a[i]; break;
                    }
                }
            }
        }
        if(f)chmax(ans,__builtin_popcount(mask));
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x, ans_h, ans_m;
    cin >> x;
    ans_h = x/30;
    ans_m = (x - (30 * ans_h)) * 2;
    
    cout << ans_h << " " << ans_m << endl;

    return 0;
}

Measured memory_bytes: 3116
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in);
    val a, b, c = sc.next();
    if(a.last == b.head && b.last == c.head) {
      System.out.println("YES")
    } else {
      System.out.println("NO")
    }
  }
}


Measured memory_bytes: 27584
# i, j, k

# N * (N - 1) * (N - 2)
# 4000^3

# 4
# RRGB

# B (k=4)
# G (j=3)
# R (i=1)

N = int(input())
S = input()

def resolve_v1(N, S):
    count = 0
    
    for k in range(N): # O(N)
        for j in range(k):# O(k)
            for i in range(1, j): # O(j)
                if S[k] != S[j] and S[j] != S[i] and S[i] != S[k] and not k-j == j-i:
                    count += 1

    return count

def resolve_v2(N, S):
    count = 0

    for i in range(N):
        for j in range(i+1, N):
            if S[i] == S[j]:
                continue

            for k in range(j+1, N):
                if S[i] == S[k] or S[j] == S[k] or k-j == j-i:
                    continue

                count += 1

    return count

# R GBR G BGRGRGRGR

# k - j = j - i
# k = 2 * j - i

def resolve_v3(N, S):
    r, g, b = 0, 0, 0
    for i in range(N):
        if S[i] == 'R':
            r += 1
        elif S[i] == 'G':
            g += 1
        elif S[i] == 'B':
            b += 1

    count = r * g * b

    for i in range(N-2):
        for j in range(i+1, N-1):
            k = 2 * j - i

            if k >= N:
                break

            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                count -= 1

    return count


if __name__ == '__main__':
    
    count = resolve_v3(N, S)
    print(count)


Measured memory_bytes: 9276
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

int pa[MAXN], sz[MAXN];
int fnd(int x) {return (x==pa[x]? x: pa[x]=fnd(pa[x]));}
void uni(int a, int b) {
	if((a=fnd(a))==(b=fnd(b))) return;
	if(sz[a]>sz[b]) swap(a, b);
	pa[a]=b; sz[b]+=sz[a];
}

signed main() {
	EmiliaMyWife

	for(int i = 0; i < MAXN; i++) pa[i]=i, sz[i]=1;

	int n, m, k;
	cin >> n >> m >> k;
	vector<int> edge(n+1), block(n+1);
	for(int i = 0, a, b; i < m; i++) {
		cin >> a >> b;
		uni(a, b);
		edge[a]++;
		edge[b]++;
	}
	for(int i = 0, a, b; i < k; i++) {
		cin >> a >> b;
		if(fnd(a)==fnd(b)) {
			block[a]++;
			block[b]++;
		}
	}
	unordered_set<int> no;
	for(int i = 1; i <= n; i++) {/*
		no.clear();
		for(int a: edge[i]) no.insert(a);
		for(int a: block[i]) {
			if((fnd(i)==fnd(a))) no.insert(a);
		}*/
		cout << sz[fnd(i)]-block[i]-edge[i]-1 << ' ';
	}

	return 0;
}


Measured memory_bytes: 3200
import math
a, b, C = [float(i) for i in input().split()]
sinC = math.sin(math.radians(C))
S = a*b*sinC/2
print(S)
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C*math.pi/180))
print(a + b + c)
h = b*sinC
print(h)


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

if b<=c:
    if a<=b:
        print(a,b,c)
    elif a<=c:
        print(b,a,c)
    else:
        print(b,c,a)
elif a<=c<=b:
    print(a,c,b)
elif c<=a<=b:
    print(c,a,b)
else:
    print(c,b,a)

Measured memory_bytes: 7648
#include <bits/stdc++.h>
#define INF 2000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n;
ll h[5001],p[5001];
P ap[5001];
vector<ll> vec;
ll dp[5005][5005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&h[i],&p[i]);
		ap[i]=P(h[i]+p[i],i);
		vec.push_back(h[i]);
		vec.push_back(p[i]);
		vec.push_back(h[i]+p[i]);
	}
	sort(ap,ap+n);
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=i+1;j++){
			dp[i+1][j]=INF;
		}
		int v=ap[i].second;
		for(int j=0;j<=i;j++){
			if(dp[i][j]<INF){
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
				if(dp[i][j]<=h[v])dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+p[v]);
			}
		}
	}
	for(int i=0;i<=n;i++){
		if(dp[n][i]<INF)ans=i;
	}
	printf("%d\n",ans);
	return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  ll n, m;
  cin >> n >> m;
  vector<ll_ll> bridges(m);
  for (int i = 0; i < m; i++) cin >> bridges[i].first >> bridges[i].second;
  sort(all(bridges));

  ll right = LL_INF;
  ll ans = 0;
  rep(i, 0, m) {
    if (bridges[i].first >= right) {
      ans++;
      right = LL_INF;
    }

    right = min(right, bridges[i].second);
  }

  put(ans + 1);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 1792
use proconio::input;
use proconio::marker::Chars;
use std::cmp::{max, min};
const alpha: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];

const Alpha: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
fn main() {
    input!(N: usize);
    input!(x: Chars);
    let X: Vec<usize> = x.iter().map(|&c| c.to_digit(2).unwrap() as usize).collect();
    let mut ans = vec![0; N];
    // 最初の割り算を行う
    let pc: usize = X.iter().sum();
    // let mut base = 0;
    // for i in 0..N {
    //     base *= 2;
    //     base += X[i];
    //     base %= pc;
    // }

    // 2回目移行の割り算は再帰関数に任せる！

    for b in 0..2 {
        let mut npc = pc;
        if b == 1 && pc <= 1 {
            continue;
        }
        if b == 0 {
            npc += 1;
        } else {
            npc -= 1;
        }

        let mut base = 0;
        for i in 0..N {
            base = (2 * base) % npc;
            base += X[i];
        }

        let mut k = 1;
        for i in (0..N).rev() {
            if X[i] == b {
                let mut r = base;
                if b == 0 {
                    r = (r + k) % npc;
                } else {
                    r = (r + npc - k) % npc;
                }
                ans[i] = f(r) + 1;
            }
            k = (2 * k) % npc;
        }
    }

    for i in 0..N {
        println!("{}", ans[i]);
    }
}

fn popcount(n: usize) -> usize {
    let mut ret = 0;
    for i in 0..40 {
        if (1 << i) & n != 0 {
            ret += 1;
        }
    }
    ret
}

fn f(mut n: usize) -> usize {
    let mut ret = 0;
    while n > 0 {
        let t = popcount(n);
        n %= t;
        ret += 1;
    }
    ret
}

fn reverse(x: usize, i: usize, n: usize) -> usize {
    let mask = 1 << (n - i - 1);
    if x & mask == 0 {
        return x + mask;
    }
    x - mask
}

fn to_usize(cs: Vec<char>) -> usize {
    let n = cs.len();
    let mut ret = 0;
    for i in 0..n {
        if cs[i] == '1' {
            ret += 1 << (n - i - 1);
        }
    }
    ret
}

fn calc(X: usize, i: usize, N: usize) -> usize {
    let rev = reverse(X, i, N);
    f(rev)
}


Measured memory_bytes: 6272
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>

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

using namespace std;
typedef long long ll; 

ll mod = 1000000007;
ll f[2000102];
void init() {
    f[0] = 1;
    rep2(i, 1, 2000100) f[i] = (f[i - 1] * i) % mod;
}
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = f[n-k]; // = (n-k)!
    ll c = f[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * inv(bc)) % mod;
}


int main() {
	ll x, y;
	cin >> x >> y;
	ll count = 0;
	ll cur_x = x;
	ll cur_y = y;
	while(true) {
		if (cur_x * 2  == cur_y) break;
		cur_x--;
		cur_y++;
		count ++;
		if (cur_x <= 0) {
			cout << 0 << endl;
			return 0;
		}
	}

	ll n = cur_x;
	ll k = count;
	//cout << "n:" << n << endl;
	//cout << "k:" << k << endl;

	if (count > n) {
		cout << 0 << endl;
		return 0;	
	}

	init();
	cout << C(n, k) << endl;
	return 0;
}

Measured memory_bytes: 15872
import java.util.Scanner;

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

        int D = sc.nextInt();
        int G = sc.nextInt();
        int[] p = new int[D];
        int[] c = new int[D];
        for (int i = 0; i < D; ++i) {
            p[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }

        System.out.println(solve(p, c, G));

        sc.close();
    }

    static int solve(int[] p, int[] c, int G) {
        int D = p.length;

        int result = Integer.MAX_VALUE;
        for (int code = 0; code < (1 << D); ++code) {
            int problemNum = 0;
            int rest = G;
            for (int i = 0; i < D; ++i) {
                if ((code & (1 << i)) != 0) {
                    problemNum += p[i];
                    rest -= 100 * (i + 1) * p[i] + c[i];
                }
            }

            for (int i = D - 1; i >= 0; --i) {
                if ((code & (1 << i)) == 0) {
                    int pn = Math.min(p[i] - 1, (Math.max(0, rest) + 100 * (i + 1) - 1) / (100 * (i + 1)));

                    problemNum += pn;
                    rest -= 100 * (i + 1) * pn;
                }
            }

            if (rest <= 0) {
                result = Math.min(result, problemNum);
            }
        }

        return result;
    }
}

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

signed main() {
	string s; cin >> s;
	int res = 114514;
	rep(i, s.size() - 2) {
		int x = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
		res = min(res, abs(x - 753));
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define N 10000

int main(){
  int count=0,n,i,j;
  int array[N];

  scanf("%d",&n);

  for(i=0; i<n; i++) scanf("%d",&array[i]);

  for(i=0; i<n; i++){
    for(j=2; j<=sqrt((double) array[i]); j++){
      if(array[i]%j == 0){
	count ++;
	break;
      }
    }
  }

  printf("%d\n",n-count);
  return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=500010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,a[N],qwq=1e9;
signed main()
{
    n=read();
    for(ri int i=1;i<=n;i++)
    {
        a[i]=read();
        int cnt=0;
        int x=a[i];
        while(x%2==0) x/=2, cnt++;
        qwq=min(qwq,cnt);
    }
    printf("%lld\n",qwq);
    return 0;
}

Measured memory_bytes: 3656
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
n = int(input())
a = [int(x) for x in input().split() if x > '1']
if len(a) > 1:
  u = set()
  i = None
  for x in a:
    s = set()
    while x > 1:
      p = spf[x]
      if p in u:
        r = 'setwise'
      s.add(p)
      x //= p
    u |= s
    if len(a) == n:
      if i is None: i = s
      else: i &= s
  if i:
    r = 'not'
print(r, 'coprime')


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

#pragma warning(disable:4996)


int main(void) {
	int r, g, b, n;
	scanf("%d %d %d %d", &r, &g, &b, &n);
	int sum = 0;
	int tmp0;
	int tmp1;
	for (int i = 0; i * r <= n; ++i) {
		for (int j = 0; j * g <= n; ++j) {
			if (n - r * i - g * j < 0) continue;
			if ((n - r * i - j * g) % b == 0) {
				++sum;
			}
		}
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
s_raw = list(map(str, input()))
ans = []

for i in range(0, len(s_raw)):
	if s_raw[i] == 'A':
		for k in range(i, len(s_raw)):
			ans.append(s_raw[k])
		break

for i in range(0, len(ans)):
	if ans[i] == 'Z':
		index = i
		
print(index + 1)


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

int main() {
  int N; cin >> N;
  map<char, int> mp;
  for(char c = 'a'; c <= 'z'; c++) mp[c] = 100;
  rep(i, 0, N) {
    string S; cin >> S;
    map<char, int> tmp;
    for(char p : S) tmp[p]++;
    for(char c = 'a'; c <= 'z'; c++) mp[c] = min(mp[c], tmp[c]);
  }
  string ans = "";
  for(char c = 'a'; c <= 'z'; c++) {
    rep(i, 0, mp[c]) ans += c;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define int long long

using namespace std;
const int mod = 1e9+7;
const int nax = 1e5+5;
int f[nax];
int a[nax];
signed main(){
	int n;
	int ans = 1;
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		f[a[i]]++;
	}
	if(f[0] > 1){
		cout << 0 << endl;
		return 0;
	}
	for(int i=0; i<=n-1; i++){
		if(f[i] == 2){
			ans = (ans*2) % mod;
		}
		if(f[i] == 1 && i != 0){
			cout << 0 << endl;
			return 0;
		}
	}
	cout << ans%mod << endl;
	return 0;
}


Measured memory_bytes: 1792