akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    cout << (N-K+K-2) / (K-1) + 1 << '\n';
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

Measured memory_bytes: 3664
N = int(input())
A = [int(x) for x in input().split()]
B = []
for x in A:
    tmp_lst = []
    for _ in range(60):
        tmp = x // 2
        tmp_lst.append(x - tmp * 2)
        x = tmp
    B.append(tmp_lst)

ans = 0
for i in range(60):
    tr, fl = 0, 0
    for x in B:
        if x[i]:
            tr += 1
        else:
            fl += 1
    ans += (tr * fl) * 2 ** i
    ans = ans % (10 ** 9 + 7)
print(ans)


Measured memory_bytes: 231996
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n), s(n+1, 0);
    for(int i = 0; i< n; i++){
        cin >> a[i];
        s[i+1] = s[i]+a[i];
    }
    ll ans = 100100100100;
    for(int i = 1; i< n; i++){
        ans = min(ans, abs(s[n]-(2*s[i])));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6364
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll a,b;
    cin>>b>>a;
    ll k=60;
    while(k>=0 && (a>>k&1) == (b>>k&1)){a|=1LL<<k; a^=1LL<<k; b|=1LL<<k; b^=1LL<<k; k--;}
    if(k==-1){cout<<1<<endl; return 0;}
    ll ans=(1LL<<k)-b;
    ll z=k-1;
    while(z>=0 && (a>>z&1)==0){z--;}
    if(z==-1){ans*=2; if(b!=0){ans++;}}
    else{ans+=min((2LL<<z)+(1LL<<k)-b,(1LL<<k));}
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
s = input()
t = input()

s = sorted(s)
t = sorted(t)[::-1]

if s == t:
    print("No")
    exit()

st = []
st.append(s)
st.append(t)
st = sorted(st)

if st[0] == s:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61788
H,W,D=map(int,input().split())
dic=dict()
for i in range(H):
    A = list(map(int,input().split()))
    for j in range(W):
        dic[A[j]]=(i,j)

Q=int(input())

d=[0 for i in range(H*W+1)]

for i in range(D+1,H*W+1):
    p,q = dic[i-D]
    x,y = dic[i]
    d[i]=d[i-D]+abs(p-x)+abs(q-y)


for _ in range(Q):
    ans=0
    L,R=map(int,input().split())
    print(d[R]-d[L])


Measured memory_bytes: 66396
#include<iostream>
using namespace std;
int main(){
    long long N,K;
    cin>>N>>K;
    long long x[N];
    for(int i=0;i<N;i++){
        cin>>x[i];
    }
    long long sum;
    for(int i=0;i<=N-K;i++){
        long long tmp=min(abs(x[i])+abs(x[i+K-1]-x[i]),abs(x[i+K-1])+abs(x[i+K-1]-x[i]));
        if(i==0||sum>tmp){
            sum=tmp;
        }

    }
    cout<<sum<<endl;



}

Measured memory_bytes: 1024
#include <cstdio>
#pragma warning(disable : 4996)

#ifdef _MSC_VER
#define mygetchar getchar
#define myputchar putchar
#else
#define mygetchar getchar_unlocked
#define myputchar putchar_unlocked
#endif

class FastInputStream {
public:
	void getint(int *x) {
		*x = 0;
		for (int k = mygetchar(); 48 <= k && k <= 57; k = mygetchar()) {
			*x = ((*x) << 1) + ((*x) << 3) + k - 48;
		}
	}
	void getll(long long *x) {
		*x = 0;
		for (int k = mygetchar(); 48 <= k && k <= 57; k = mygetchar()) {
			*x = ((*x) << 1) + ((*x) << 3) + k - 48;
		}
	}
	void getuint(unsigned *x) {
		*x = 0;
		for (int k = mygetchar(); 48 <= k && k <= 57; k = mygetchar()) {
			*x = ((*x) << 1) + ((*x) << 3) + k - 48;
		}
	}
	void getull(unsigned long long *x) {
		*x = 0;
		for (int k = mygetchar(); 48 <= k && k <= 57; k = mygetchar()) {
			*x = ((*x) << 1) + ((*x) << 3) + k - 48;
		}
	}
};

class FastOutputStream {
public:
	void putint(int x) {
		int ptr = 0, r; char c[12];
		while (x) {
			r = x / 10;
			c[ptr++] = x - (r << 1) - (r << 3) + 48;
			x = r;
		}
		while (ptr--) myputchar(c[ptr]);
	}
	void putll(long long x) {
		int ptr = 0; long long r; char c[22];
		while (x) {
			r = x / 10;
			c[ptr++] = x - (r << 1) - (r << 3) + 48;
			x = r;
		}
		while (ptr--) myputchar(c[ptr]);
	}
	void putuint(unsigned x) {
		int ptr = 0; unsigned r; char c[12];
		while (x) {
			r = x / 10;
			c[ptr++] = x - (r << 1) - (r << 3) + 48;
			x = r;
		}
		while (ptr--) myputchar(c[ptr]);
	}
	void putull(unsigned long long x) {
		int ptr = 0; unsigned long long r; char c[22];
		while (x) {
			r = x / 10;
			c[ptr++] = x - (r << 1) - (r << 3) + 48;
			x = r;
		}
		while (ptr--) myputchar(c[ptr]);
	}
	void putchar(char c) {
		myputchar(c);
	}
};

FastInputStream fastin;
FastOutputStream fastout;

// ------ Main ------ //

int n;
int main() {
	fastin.getint(&n);
	fastout.putint(n * n * n);
	fastout.putchar('\n');
	return 0;
}

Measured memory_bytes: 2468
#define _USE_MATH_DEFINES //円周率を使用
#include <math.h>
#include <iomanip> //小数点以下を表示
#include <iostream>
#include <cstring> //文字列操作
using namespace std;

//【関数の定義】

int main(void)
{
	int dice[6] = { 0, 0, 0, 0, 0, 0 }; //サイコロの各面（ex.1の面->dice[0]）
	int dicefirst[6] = { 0, 0, 0, 0, 0, 0 }; //サイコロの最初の各面
	int diceside[24][2]; //上面->dice[0]、右面->dice[1]
	int dummy = 0; //サイコロの面の数字のダミー
	char len[101]; //方角
	int i, j, k; //カウンタ変数
	int count = 0;
	int question = 0; //質問数

	for (i = 0; i < 6; i++) //サイコロの面の入力
	{
		cin >> dice[i];
	}

	cin >> question; //質問数を入力

	for(i = 0; i < question; i++) //サイコロの上面および前面の入力
	{
		for (j = 0; j < 2; j++)
		{
			cin >> diceside[i][j];
		}
	}

	for (k = 0; k < 6; k++) //サイコロの初期値を記憶
	{
		dicefirst[k] = dice[k];
	}

	for (i = 0; i < question; i++)
	{
		while (dice[0] != diceside[i][0]) //サイコロの上面を調べる
		{
			if (count == 4)
			{
				dummy = 0; //ダミーの初期化
				//以下、Eの動き
				dummy = dice[5];
				dice[5] = dice[2];
				dice[2] = dice[0];
				dice[0] = dice[3];
				dice[3] = dummy;
				count = 0;
			}

			dummy = 0; //ダミーの初期化
			//以下、Sの動き
			dummy = dice[5];
			dice[5] = dice[1];
			dice[1] = dice[0];
			dice[0] = dice[4];
			dice[4] = dummy;
			count++;
		}

		while (dice[1] != diceside[i][1]) //サイコロの前面を調べる
		{
			dummy = 0; //ダミーの初期化
			//以下、横の動き
			dummy = dice[3];
			dice[3] = dice[4];
			dice[4] = dice[2];
			dice[2] = dice[1];
			dice[1] = dummy;
		}

		cout << dice[2] << endl;

		for (k = 0; k < 6; k++)
		{
			dice[k] = dicefirst[k];
		}
	}


	return 0;
}


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

using ll = long long;
const ll MOD = 998244353;

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

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

int main() {
    ll N, M, L = 1;
    cin >> N >> M;
    vector<ll> a(N), b(N, 0);
    rep(i, N) {
        cin >> a[i];
        ll c = a[i];
        while (c % 2 == 0) {
            c /= 2;
            b[i]++;
        }
        if (b[i] != b[0]) {
            cout << 0 << endl;
            return 0;
        }
        L = lcm(L, a[i] / 2);
        if (L > M) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << M / L - M / (2 * L) << endl;
    //cout << M << " " << L << endl;
}

Measured memory_bytes: 1792
/*      ###########################
        #  Author : Pranay Garg   #
        #  College : SGSITS       #
        ###########################
*/      
#include<bits/stdc++.h>
#define ll long long int
#define ironman ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define endl '\n'
#define INF 1e18L+1
#define mp make_pair
#define fi first
#define se second
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define pb push_back
#define pf push_front
using namespace std;
template<class T> T max(T a, T b, T c) {
    return max(a, max(b, c));
}
template<class T> T min(T a, T b, T c) {
    return min(a, min(b, c));
}
void fastio()
{
    ironman
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt","w",stderr);
    #endif
}
ll prime[100005];
void SieveOfEratosthenes(ll n)//O(nloglogn) 
{  
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}  
bool isPrime(ll n)//O(sqrt(n))
{
    if(n<2)
        return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
std::vector<ll> factors(ll n)//O(sqrt(n))
{
    std::vector<ll> f;
    for(ll i=2;i*i<=n;i++)
    {
        while(n%i==0)
        {
            f.push_back(i);
            n = n/i;
        }
    }
    if(n>1) f.push_back(n);
    return f;
}
ll gcd(ll a,ll b)//O(logn)
{
    if(!b) return a;
    return gcd(b,a%b);
}
ll modpow(ll x,ll n,ll m)//O(logn)// used for calculating (x^n)%m
{
    if(n==0) return 1%m;
    ll u = modpow(x,n/2,m);
    u = (u%m * u%m)%m;
    if(n%2==1)
        u = (u%m * x%m)%m;
    return u%m;
}
ll eulerstotientfunction(ll n)//O(sqrt(n))
{
    ll ans = n;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            while(n%i==0)
                n = n/i;
            ans -= ans/i;
        }
    }
    if(n>1)
        ans -= ans/n;
    return ans;
}
ll modinverse(ll x,ll m)//O(logn)
{
    ll temp = eulerstotientfunction(m);
    return modpow(x,temp-1,m);
}
ll ncr(ll n,ll k)
{
    ll res = 1;
    k = min(k,n-k);
    for(ll i=0;i<k;i++)
    {
        res *= (n-i);
        res /= (i+1);
    }
    return res;
}
int main()
{
    //fastio();
    ll t=1;
    //cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;
        cout << n*n*n << endl;

    }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

#define rep(i, start, end) for (int(i) = (start); (i) < (end); (i)++)
#define rep_r(i, end, start) for (int(i) = (end); (i) >= (start); i--)
#define len(ar) (sizeof(ar) / sizeof(ar[0]))

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  int a[N][3];
  rep(i, 0, len(a)) { rep(j, 0, 3) cin >> a[i][j]; }

  int x = 0, y = 0, xw = W, yh = H;

  rep(i, 0, N) {
    switch (a[i][2]) {
      case 1:
        if (x < a[i][0]) x = a[i][0];
        break;
      case 2:
        if (xw > a[i][0]) xw = a[i][0];
        break;
      case 3:
        if (y < a[i][1]) y = a[i][1];
        break;
      case 4:
        if (yh > a[i][1]) yh = a[i][1];
        break;
    }
    if (x >= xw || y >= yh) {
      cout << 0;
      return 0;
    }
  }

  cout << (xw - x) * (yh - y);
  return 0;
}

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

int main(int argc, char *argv[]) {
  int A, B, C, cnt5, cnt7;
  scanf("%d %d %d", &A, &B, &C);
  cnt5 = (A == 5) + (B == 5) + (C == 5);
  cnt7 = (A == 7) + (B == 7) + (C == 7);
  if (cnt5 == 2 && cnt7 == 1)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}


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

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

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

long long INF = 1LL<<60;
int n;
int main(){
    string s;
    cin>>s;
    ll k;
    cin>>k;
    for(ll i=0;i<k;i++){
        if(s.at(i)!='1'){
            cout<<s.at(i)<<endl;
            return 0;
        }
    }
    cout<<"1\n";
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
const int maxn = 2e5 + 5;
using namespace std;

int n,a[maxn];
long long ans,num[maxn];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		num[a[i]]++;
	}
	for(int i = 1; i <= n; i++){
		ans += num[i] * (num[i] - 1) / 2;
	}
	for(int i = 1; i <= n; i++){
		printf("%lld\n", ans - (num[a[i]] * (num[a[i]] - 1)) / 2 + (num[a[i]] - 1) * (num[a[i]] - 2) / 2);
	}
	return 0;
}

Measured memory_bytes: 3968
from fractions import gcd
from collections import Counter

n,p=map(int,input().split())

def trial_div(n):
    
    prime=Counter()

    for i in range(2,int(pow(n,0.5)+2)):
        while n%i==0:
            n//=i
            prime[i]+=1
    if n>1:prime[n]+=1
    
    return prime

res=trial_div(p)
ans=1
for k,v in res.items():
    tmp=k**(v//n)
    ans*=tmp

print(ans)

Measured memory_bytes: 5048
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b>c+d){
        cout << "Left" <<endl;
    }
    else if(a+b == c+d){
        cout << "Balanced" << endl;
    }
    else{
        cout << "Right" <<endl;
    }
    return 0;
}

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

int main()
{
  string S;
  int cnt=0, j=0, k=0, l=0;
  cin >> S;
  if(S.at(0)=='A'){
    for(int i=2; i<S.size()-1; i++){
      if(S.at(i)=='C'){
        cnt++;
        j=i;
      }
    }
  }
  if(cnt==1){
    for(int i=1; i<S.size(); i++){
      if(i==j) continue;
      if('a'>S.at(i) || S.at(i)>'z') k=1;
    }
  }
  if(cnt==1 && k!=1) cout << "AC" << endl;
  else cout << "WA" << endl;
} 

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

typedef long long LL;
int INF=0x3f3f3f3f;

int main(){
	ios_base::sync_with_stdio(false);
	
	LL A,B,C,D,E,F;
	LL ans1=0,ans2=0;
	double tmp,LD=-1;
	cin>>A>>B>>C>>D>>E>>F;
	
	for(int a=0;a*A*100<=F;a++){
		for(int b=0;a*A*100+b*B*100<=F;b++){
			for(int c=0;a*A*100+b*B*100+c*C<=F;c++){
				for(int d=0;a*A*100+b*B*100+c*C+d*D<=F;d++){
					if(c*C+d*D>(a*A+b*B)*E) break;
					tmp=(1.0)*(c*C+d*D)/(a*A*100+b*B*100+c*C+d*D);
					if(LD<tmp) {LD=tmp;ans1=(a*A*100+b*B*100+c*C+d*D);ans2=(c*C+d*D);}
				}
			}
		}
	}
	
	cout<<ans1<<" "<<ans2<<endl;
	return 0;
}

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



int main(){
    int x,y,z;
    cin >> x >> y >> z;
    cout << (x-z)/(y+z) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  string s, t;
  cin >> s >> t;
  ll n = s.size();
  ll m = s.size();
  
  ll q;
  cin >> q;

  vector<ll> u(n + 1, 0), v(m + 1, 0);
  for (int i = 1; i <= n; i++){
    if (s[i-1] == 'A'){
      u[i] = (u[i-1] + 1);
    }
    else {
      u[i] = (u[i-1] + 2);
    }
  }
  for (int i = 1; i <= m; i++){
    if (t[i-1] == 'A'){
      v[i] = (v[i-1] + 1);
    }
    else {
      v[i] = (v[i-1] + 2);
    }
  }
 
  for (int i = 0; i < q; i++){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((u[b] - u[a-1]) % 3 == (v[d] - v[c-1]) % 3)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  

  return 0;
}


Measured memory_bytes: 2432
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def combinations_count(n, r):
    if n == 1:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    S = SI()
    
    ls = []
    len_S = len(S)
    rem = 0

    for s in range(len_S-1,-1,-1):
        rem = (rem+int(S[s])* pow(10, len_S-s-1, 2019))%2019
        ls.append(rem)
    
    import collections

    cls = collections.Counter(ls)
    clsv= list(cls.values())

    ans = 0

    for p in clsv:
        ans += combinations_count(p,2)
    ans += cls[0]
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 17076
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int ans = 100000000, n;
  	cin >> n;
  	int a[n];
  
  for(int i = 0; i < n; i ++) cin >> a[i];
  
  sort(a, a + n);
  
  for(int i = a[0]; i <= a[n - 1]; i ++){
  	int tmp = 0;
    for(int j = 0; j < n; j ++)
      tmp += (i - a[j]) * (i - a[j]);
    if(ans > tmp) ans = tmp; 
  }
  cout << ans << endl;
}

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

#define LL long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define vecprint(vec) for (int i=0;i<vec.size();i++)printf("%d ",vec[i]);
#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define MEM(v,x) memset(v,x,sizeof v)

const double eps=1e-7,PI=3.1415926;
const int N=2e5+10;

using namespace std;

LL n,q,m,k,x,y,a[N],mx=-1,mn=1e9,sum,t;
char c[N];
string s,s1,s2;
map < int , int > mp;
vector < int > vec;

int main(){
    cin>>n>>m>>k;x=n;
    n-=min(n,k);
    k-=min(x,k);
    m-=min(k,m);
    cout<<n<<" "<<m<<endl;
    return 0;
}


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

using namespace std;
#define sz(a) (int)a.size()
#define int int64_t
const int MAXN = 1e5 + 1;
template<typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> &p) {
     out << "{" << p.first << ", " << p.second << "} ";//optional
     return out;
}

template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
     in >> p.first >> p.second;
     return in;
}

template<typename T>
istream &operator>>(istream &in, vector<T> &arr) {
     for (auto &i : arr)
          in >> i;
     return in;
}

template<typename T>
ostream &operator<<(ostream &out, vector<T> &arr) {
     for (int i = 0; i < (int)arr.size(); ++i) {
          if (i != 0) {
               out << ' ';
          }
          out << arr[i];//optional
     }
     out << endl;
     return out;
}

map<char, bool> ban;

bool ok(int n) {
     string s = to_string(n);
     for (auto c : s) {
          if (ban.count(c)) {
               return false;
          }
     }
     return true;
}

signed main() {
     int n, k;
     cin >> n >> k;
     for (int i = 0; i < k; ++i) {
          char c;
          cin >> c;
          ban[c] = true;
     }
     for (int i = n;; ++i) {
          if (ok(i)) {
               cout << i << endl;
               return 0;
          }
     }
     return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N = I()
    X = S()
    bit_cnt = X.count('1')
    one_inv_cnt = bit_cnt - 1
    zero_inv_cnt = bit_cnt + 1
    MAX = 2 * 10 ** 5 + 1

    # 大きい数の余り
    # 繰り返し２乗法の発展？
    zero_mod = 0
    one_mod = 0
    for i in range(0, len(X)):
        b = int(X[i])
        if one_inv_cnt != 0:
            one_mod = (one_mod * 2 + b) % one_inv_cnt
        zero_mod = (zero_mod * 2 + b) % zero_inv_cnt

    f = [0] * MAX
    for i in range(1, MAX):
        f[i] = f[i % str(bin(i)).count('1')] + 1

    for i in range(len(X)-1, -1, -1):
        if X[N-1-i] == '1':
            if one_inv_cnt != 0:
                nxt = one_mod
                nxt -= pow(2, i, one_inv_cnt)
                nxt %= one_inv_cnt
                print(f[nxt] + 1)
            else:
                print(0)
        else:
            nxt = zero_mod
            nxt += pow(2, i, zero_inv_cnt)
            nxt %= zero_inv_cnt
            print(f[nxt] + 1)


if __name__ == '__main__':
    main()


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

typedef long long ll;

ll ans;
ll sum[200005];
map<ll,int> num;

int main() {
  ll n,k;
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    a--;
    sum[i+1] = (sum[i] + a) % k;
  }

  num[0]++;
  
  for(int i = 1; i <= n; i++) {
    if(i - k >= 0) num[sum[i-k]]--;
    ans += num[sum[i]]++;
   
  }

  cout << ans << endl;
}
  
    
  


Measured memory_bytes: 14336
n = int(input())

count = 0

for _ in range(n):
    a, b = map(int, input().split())

    if a == b:
        count += 1

        if count >= 3:
            print('Yes')
            exit()
    else:
        count = 0

if count >= 3:
    print('Yes')

else:
    print('No')

Measured memory_bytes: 9180
X,Y=map(int, input().split())
if X/Y>2 or Y/X>2 or (X+Y)%3!=0:
    print(0)
    exit()

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
n = (10 ** 6 ) # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p) 階乗のmod
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, n + 1):
  fact.append((fact[-1] * i) % p)
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)
base=(X+Y)//3
print(cmb(base, (X-base),p))


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


struct ModComb {
    vector<long long> fact, rfact;
    long long max, mod;
    ModComb(long long ma, long long mod) :fact(ma, 0), rfact(ma, 0), max(ma), mod(mod) {
        fact[0] = 1;
        for (long long i=1; i<max; ++i) {
            fact[i] = fact[i-1]*i;
            fact[i] %= mod;
        }
        rfact[max-1] = mod_inverse(fact[max-1], mod);
        for (long long i=max-2; i>=0; --i) {
            rfact[i] = rfact[i+1]*(i+1);
            rfact[i] %= mod;
        }
    }
    long long mod_pow(long long x, long long n, long long mod) {
        long long a = 1LL;
        while (n) {
            if (n%2) a = ((a%mod)*(x%mod))%mod;
            x = ((x%mod)*(x%mod))%mod;
            n /= 2LL;
        }
        return a;
    }

    long long mod_inverse(long long a, long long m) {
        return mod_pow(a, m-2, m);
    }

    long long operator()(long long n, long long r) {
        if (n < r) return 0;
        return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
    }
};

const ll mod = 1e9 + 7;

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

    ModComb c(2001, mod);

    rep(i, K) {
        cout << (c(N-K+1, i+1) % mod) * (c(K-1, i) % mod) % mod << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MEM 100001
#define sanic ios_base::sync_with_stdio(0)
using namespace std;
const long long MOD = 1e9+9;
int a,b,t;
int main() {
    cin >> a >> b;
    cout << a/b+(a%b?1:0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long x[100010],y[100010],p[100010];
long long q[100010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  long long a,b,c,d,e,n,ccnt=0,ans=0;
  string s,v,o;
  char z[100010],y[100010];

  cin>>a>>b>>c;
  a=c/a;
  cout<<a*b<<'\n';
}


Measured memory_bytes: 256
//Code by: Nikhil Shukla, MMMUT GKP
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define V vector
#define pb push_back
#define all x x.begin(),x.end()
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc ll t; cin>>t; while(t--)
#define tc1 ll tt=1; while(tt--)
#define fir first
#define sec second
#define mod 998244353
#define out1(x) cout<<x<<"\n";
#define out2(x,y) cout<<x<<" "<<y<<"\n";
#define debug() cout<<"I am in\n";
#define Vll vector<long long>
#define FOR(i,x,n) for(ll i=x;i<n;i++)
#define RFOR(i,x,n) for(ll i=x;i>=n;i--)
////////////////////////////////////////////////////////////////////////////////////////
/*vector<ll>graph[100001];
vector<ll>temp;
vector<bool>visited(100001,false);
//long long count=0;
void dfs(long long node)
{
       // count++;
        temp.pb(node);
        visited[node]=1;
        for(ll i=0;i<graph[node].size();i++)
        {
            if(!visited[graph[node][i]])
            dfs(graph[node][i]);
        }
}*/
void solve(ll n,ll W,ll weight[],ll value[])
{
    ll dp[n+1][W+1],i,j;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=W;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(weight[i-1]<=j)
            {
                dp[i][j]=max(value[i-1]+dp[i-1][j-weight[i-1]],dp[i-1][j]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W]<<"\n";    
}
int main()
{
    fast()
    tc1
    {
        ll n,W;
        cin>>n>>W;
        ll weight[n];
        ll value[n];
        FOR(i,0,n)
        {
            cin>>weight[i]>>value[i];
        }
        solve(n,W,weight,value);
    }
    return 0;
}


Measured memory_bytes: 82428
#include<bits/stdc++.h>
using namespace std;
 
long N,n;
vector<long> A;
 
int main(){
    cin>>N;
    for(;cin>>n;)A.push_back(n);
    partial_sum(A.begin(),A.end(),A.begin());
    n=1LL<<50;
    auto a=A.begin(),t=a+1,d=A.end()-1,b=t+1;
    for(;t+1!=d;++t){
        while(a+1!=t)
            if(*a<*t-*(a+1)) ++a;
            else break;
        if(b==t)++b;
        while(b+1!=d)
            if(*b-*t<*d-*(b+1)) ++b;
            else break;
        n=min(n,max({*a,*t-*a,*b-*t,*d-*b})-min({*a,*t-*a,*b-*t,*d-*b}));
    }
    cout<<n<<endl;
}


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

int main()
{
    int n, k, i, score=0;
    double p=0; //確率
    cin >> n >> k;
    double one_p[n]; //サイコロの出た目がn+1のときの確率

    for(i=0;i<n;i++){
        one_p[i] = 1.0/n;
        score = i+1;
        while(score < k){
            one_p[i] *= 0.50;
            score = score * 2;
        }
        p += one_p[i];
    }
    printf("%15.12lf\n", p);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int N;
long long int a[10004], b[10004];

long long int sum_a, sum_b;

int main(void) {

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

	long long int sub = sum_b - sum_a;
	if (sub < 0) { cout << "No" << endl;  return 0; }

	for (int i = 1; i <= N; i++) {
		if (a[i] < b[i]) { if ((b[i] - a[i]) % 2 == 1) { sub--; } }
		else { sub -= a[i] - b[i]; }
	}

	if (sub < 0) { cout << "No" << endl; return 0; }
	cout << "Yes" << endl;

}

Measured memory_bytes: 384
package main

import "fmt"

func main()  {
	var n, x int
	fmt.Scan(&n, &x)

	sum := 0
	l := make([]int, n+1)
	for i:=1;i<=n;i++ {
		fmt.Scan(&l[i])
	}

	for i:=0;i<=n;i++ {
		sum += l[i]
		if sum > x {
			fmt.Println(i)
			break
		} else if i == n {
			fmt.Println(i+1)
		}
	}
}

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

using namespace std;

int main() {

	int N, D, X,a,day;
	cin >> N >> D >> X;
	for (int i = 0; i < N; i++) {
		cin >> a;
		day = 1;
		while (day <= D) {
			X++;
			day += a;
		}
	}
	cout << X << endl;
	return 0;
}

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

const int MOD = (int)1e9+7;

int main(){
	int H,W;
	cin >> H >> W;
	vector<string> S(H);
	for(int i=0;i<H;i++)	cin >> S.at(i);

	vector<vector<int>> xsum(H,vector<int>(W,0));
	vector<vector<int>> ysum(H,vector<int>(W,0));
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(S.at(i).at(j)=='#')	continue;
			if(j==0)	xsum.at(i).at(j)=1;
			else{
				xsum.at(i).at(j)=xsum.at(i).at(j-1)+1;
			}
		}
		for(int j=W-1-1;j>=0;j--){
			if(S.at(i).at(j)=='#')	continue;
			xsum.at(i).at(j)=max(xsum.at(i).at(j),xsum.at(i).at(j+1));
		}
	}

	for(int j=0;j<W;j++){
		for(int i=0;i<H;i++){
			if(S.at(i).at(j)=='#')	continue;
			if(i==0)	ysum.at(i).at(j)=1;
			else{
				ysum.at(i).at(j)=ysum.at(i-1).at(j)+1;
			}
		}
		for(int i=H-1-1;i>=0;i--){
			if(S.at(i).at(j)=='#')	continue;
			ysum.at(i).at(j)=max(ysum.at(i).at(j),ysum.at(i+1).at(j));
		}
	}

	int ans=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(S.at(i).at(j)=='#')	continue;
			ans=max(ans,xsum.at(i).at(j)+ysum.at(i).at(j)-1);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 35712
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    N, M = wi()
    A = wi()
    a = sum(A)
    if a <= N:
        print(N-a)
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68196
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i64 = read();

    if n >= 30 {
        print!("Yes");
    } else {
        print!("No");
    }
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define Mashu cout << "UUZ ate it." << endl
#define RE register int
#define ll long long
using namespace std;

template <typename T> void read(T &x){
	int f = 1; x = 0; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}

int main(){
	int n, k, s;
	cin >> n >> k >> s;
	int QWQ = 1e9;
	if (QWQ == s) QWQ -= 1;
	for (int i = 1; i <= k; i++){
		cout << s << " ";
	}
	for (int i = k + 1; i <= n; i++){
		cout << QWQ << " ";
	}
	return 0;
	Mashu;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
#define mod             1000000007
#define w(x)            int x; cin>>x; while(x--)
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll              long long
 
 
int main() {
    fast
    int n, m, ans = 0;
    cin >> n >> m;
    vector<int> h(n+1);
    for(int i = 1; i <= n; i++) cin >> h[i];
    vector<vector<int>> g(n+1);
    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i <= n; i++) {
        vector<int> neighbours = g[i];
        int maxH = h[i];
        if(neighbours.size() == 0) {
            ans++;
            continue;
        }
        bool flag = true;
        for(int neig : neighbours) {
            if(maxH <= h[neig]) {
                flag = false;
            }
        }
        if(flag) ans++;   
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8852
#include <bits/stdc++.h>
using namespace std;
string s;
long long n,m,m2,kt;
int main()
{
	cin>>s;
	n=s.length();
	m=0;
    kt=0;
    for(int i=0;i<n;i++)
    if(m==0)
    {
    	m++;
    	if(s[i]=='p') kt--;
	}
	else
	  {
	  	if(s[i]=='p') m--;
	  	if(s[i]=='g') 
	  	{
	  		m--;
	  		kt++;
		}
	  }
	cout<<kt;
}

Measured memory_bytes: 512
// {{{
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)x.size())
#define FOR(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
using LL=long long;
using PII=pair<int,int>;
using VI=vector<int>;

#ifdef FEI
template<typename T>
void _dump(const char* s, T&& head) { cerr<<s<<"="<<head<<endl; }
template<typename T, typename... Args>
void _dump(const char* s, T&& head, Args&&... tail) {
    int c=0;
    while (*s!=',' || c!=0) {
        if (*s=='(' || *s=='[' || *s=='{') c++;
        if (*s==')' || *s==']' || *s=='}') c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1, tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, ##__VA_ARGS__); \
} while(0);

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<'[';
    for (auto it=b; it!=e; it++) s<<(it==b?"":",")<<*it;
    s<<']';
    return s;
}

template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) { return s<<"("<<p.first<<","<<p.second<<")";}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &x) { return _out(s,ALL(x)); }
template<typename T, size_t N>
ostream& operator <<(ostream &s, const array<T,N> &x) { return _out(s,ALL(x)); }
template<typename T>
ostream& operator <<(ostream &s, const set<T> &x) { return _out(s,ALL(x)); }
template<typename A, typename B>
ostream& operator <<(ostream &s, const map<A,B> &x) { return _out(s,ALL(x)); }
#else
#define dump(...)
#endif

template<typename T>
void _R(T &x) { cin>>x; }
void _R(int &x) { scanf("%d",&x); }
void _R(LL &x) { scanf("%" PRId64,&x); }
void _R(double &x) { scanf("%lf",&x); }
void _R(char &x) { scanf(" %c",&x); }
void _R(char *x) { scanf("%s",x); }

void R(){}
template<typename T, typename... X>
void R(T& head, X&... tail) { _R(head); R(tail...); }
// }}}

const int N = 100005;
vector<int> edge[N], ans;
int vis[N];

int main() {
    int n, m;
    R(n, m);

    for (int i=0; i<m; i++) {
        int x, y;
        R(x, y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }

    for (int i=1; i<=n; i++)
        dump(i, edge[i]);

    ans.push_back(1);
    vis[1] = 1;

    int flag = 1;
    while (flag) {
        flag = 0;
        for (int x : edge[ans.front()])
            if (!vis[x]) {
                ans.insert(ans.begin(), x);
                vis[x] = 1;
                flag = 1;
                break;
            }
        for (int x : edge[ans.back()])
            if (!vis[x]) {
                ans.push_back(x);
                vis[x] = 1;
                flag = 1;
                break;
            }
    }

    printf("%d\n", ans.size());
    for (int i=0; i<ans.size(); i++)
        printf("%d%c", ans[i], " \n"[i==ans.size()-1]);

    return 0;
}


Measured memory_bytes: 7160
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

signed main(){
    int N;
    cin>>N;
    vector<string> A(N);
    REP(i,N) cin>>A[i];
    bool ans = true;
    REP(i,N){
        REP(j,i){
            if(A[i]==A[j]) ans = false;
        }
    }
    REP(i,N-1){
        if(A[i].back()!=A[i+1].front()) ans = false;
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;


int main(){

	int a,b,c,d;

	cin >> a >> b >> c >> d;

	if(abs(a-b) <= d && abs(c-b) <=d || abs(c-a) <=d){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}


    return 0;

}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  vP as(n);
  rep(i, n) {
    ll a;
    cin >> a;
    as[i] = P(a, i);
  }
  sort(as.rbegin(), as.rend());

  vvll dp(n + 1, vll(n + 1, 0));
  repLRE(i, 1, n) {
    ll a, p;
    tie(a, p) = as[i-1];
    repLRE(l, 0, i) {
      // chmax(dp[i + 1][l + 1], dp[i][l] + a*(p - l));
      // chmax(dp[i + 1][l], dp[i][l] + a*(n - 1 - i + l - p));
      if(l <= i - 1){
        ll r = i - 1 - l;
        ll addr = dp[i - 1][l] + a * (n - 1 - r - p);
        dp[i][l] = addr;
      }
      if (l >= 1) {
        ll addl = dp[i - 1][l - 1] + a * (p - l + 1);
        chmax(dp[i][l], addl);
      }
    }
  }
  ll ans = 0;
  rep(l, n + 1) chmax(ans, dp[n][l]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 34568
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<limits>
#include<string>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
const static ll MOD = 1e9 + 7;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;


int main() {
    ll N, W; cin >> N >> W;
    vector<ll> w(N), v(N);
    rep(i, N) {
        cin >> w[i] >> v[i];
    }
    ++N; ++W;
    vector<vll> dp(N, vll(W));
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < W; j++) {
            if (j - w[i - 1] >= 0) {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
            }
            else {
                dp[i][j] = dp[i - 1][j];
            }

        }
    }

    cout << dp[N - 1][W - 1] << endl;;
}


Measured memory_bytes: 80256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = map(int, input().split())
h = list(map(int, input().split()))

h.sort()
if k>=n:
    print(0)
else:
    print(sum(h[:n-k]))

Measured memory_bytes: 105332
import java.util.*;
import java.text.DecimalFormat;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		Random rn = new Random();
		DecimalFormat df = new DecimalFormat("#,###.##");

		int A = sc.nextInt();
		int B = sc.nextInt();

		if ((A - (2 * B))>0)
		{
			System.out.println(A - (2 * B));
		}
		else if (B > A)
		{
			System.out.println(0);
		}
		else
		{
			System.out.println(0);
		}

	}
}

Measured memory_bytes: 22100
#include <iostream>
#include <stdio.h>
using namespace std;

typedef long long LL;
const int M=1e5+5;
int a[M];
LL b[M];
// a[i]=b[i]/2+b[i+1]/2
// 2*a[i]=b[i]+b[i+1]

// b[0]+b[1]-b[1]-b[2]+b[2]+b[0]
// 2 b[0]= sum (2*a[i]*(-1)^i)

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	LL sum=0;
	for(int i=0;i<n;i++)
	{
		if(i&1) sum-=a[i];
		else sum+=a[i];
	}
	b[0]=sum;
	for(int i=1;i<n;i++)
		b[i]=a[i-1]*2-b[i-1];
	for(int i=0;i<n;i++)
		printf("%lld%c",b[i],i==n-1?'\n':' ');
	return 0;
}

Measured memory_bytes: 2432
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int N=in.nextInt();
			int K=in.nextInt();
			long x[]=new long[N*2];
			long y[]=new long[N*2];
			long d[]=new long[N*2];
			int X1[]=new int[N];
			int Y1[]=new int[N];
			int D1[]=new int[N];
			int X2[]=new int[N];
			int Y2[]=new int[N];
			int D2[]=new int[N];
			int xl=0;
			int yl=0;
			int dl=0;
			long ans=0;
			for(int i=0;i<N;i++)
			{
				X1[i]=in.nextInt();
				Y1[i]=in.nextInt();
				D1[i]=in.nextInt();
				X2[i]=in.nextInt();
				Y2[i]=in.nextInt();
				D2[i]=in.nextInt();

			}
			for(int i=0;i<N;i++)
			{
				x[xl++]=X1[i];
				x[xl++]=X2[i];
				y[yl++]=Y1[i];
				y[yl++]=Y2[i];
				d[dl++]=D1[i];
				d[dl++]=D2[i];
			}
			Arrays.sort(x);
			Arrays.sort(y);
			Arrays.sort(d);
			for(int i=0;i<N*2-1;i++)//x position
				for(int j=0;j<N*2-1;j++)//y position
					for(int k=0;k<N*2-1;k++)//d position
					{
						int cnt=0;
						for(int l=0;l<N;l++)//
						{
							if((X1[l]<=x[i]&&x[i+1]<=X2[l])&&
									(Y1[l]<=y[j]&&y[j+1]<=Y2[l])&&
									(D1[l]<=d[k]&&d[k+1]<=D2[l]))
								cnt++;
						}
						if(cnt>=K)
							ans+=(x[i+1]-x[i])*(y[j+1]-y[j])*(d[k+1]-d[k]);
					}
			System.out.println(ans);
		}
	}
	static public void debug(Object... o)
	{
		System.err.println(Arrays.deepToString(o));
	}
}

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

int main() {
	vector<int> a(9);
	for (int i = 0; i < 9; ++i) {
		cin >> a[i];
	}

	int n;
	cin >> n;

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

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 9; ++j) {
			if (a[j] == b[i]) {
				a[j] = 0;
			}
		}
	}

	if ((a[0] + a[1] + a[2]) == 0) {
		cout << "Yes";
	}
	else if ((a[3] + a[4] + a[5]) == 0) {
		cout << "Yes";
	}
	else if ((a[6] + a[7] + a[8]) == 0) {
		cout << "Yes";
	}
	else if ((a[0] + a[3] + a[6] == 0)) {
		cout << "Yes";
	}
	else if ((a[1] + a[4] + a[7]) == 0) {
		cout << "Yes";
	}
	else if ((a[2] + a[5] + a[8]) == 0) {
		cout << "Yes";
	}
	else if ((a[0] + a[4] + a[8]) == 0) {
		cout << "Yes";
	}
	else if ((a[2] + a[4] + a[6]) == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

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

using namespace std;

#define ll long long




void solve() {

	int n;
	cin >> n;
	unordered_map<string, int> mp;
	while(n--) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		mp[s]++;
	}
	ll total = 0;
	for(auto x: mp) {
		if(x.second == 1) {
			continue;
		}
		else {
			ll a = x.second;
			total += (a * (a - 1)) / 2;
		}
	}
	cout << total << "\n";

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int c,ans=0;
  for(int i=0;i<a;i++){
    cin >> c;
    if(c>=b)ans++;
  }
  cout << ans;
}


Measured memory_bytes: 3632