akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define MOD 1000000007


int main(){
	ll n;
	cin>>n;
	
	string s;
	cin>>s;
 
 	if(n%2)
 	{
 		cout<<"No\n";
 		return 0;
 	}	

 	ll t=n/2;
 	for(int i=0;i<n/2;i++)
 	{
 		if(s[i]!=s[t+i])
 		{
 			cout<<"No\n";
 			return 0;
 		}
 	}
 	cout<<"Yes\n";

}	



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

int to_i(string s){
  if(s=="S")return 0;
  if(s=="H") return 1;
  if(s=="C") return 2;
  if(s=="D") return 3;
}

string to_s(int x){
  string s[4] = {"S","H","C","D"};
  switch(x){
  case 0:
    return s[0];
  case 1:
    return s[1];
  case 2:
    return s[2];
  case 3:
    return s[3];
  }
}


int main(){

  int n; cin >> n;
  int card[4][13]={};
  for(int i=0; i<n; i++){
    string s;
    int t;
    cin >> s >> t;
    card[to_i(s)][t-1] = 1;
  }
  for(int i=0; i<4; i++){
    for(int j=0; j<13; j++){
      if(card[i][j] == 0)
	cout << to_s(i) << " " << j+1 << endl;
    }
  }
}

Measured memory_bytes: 1212
let h = ref 0
let n, k, t = Scanf.scanf "%d %d %s" @@ fun n k s -> String.iteri (fun i c -> if i > 0 && s.[i - 1] = s.[i] then incr h) s; n, k, min k @@ (n - 1 - !h) / 2
let _ = Printf.printf "%d\n" @@ if k > t then n - 1 else !h + 2 * t

Measured memory_bytes: 4480
import math
N, K = map(int, input().split())
m = 10 ** 9 + 7
for i in range(1, K+1):
    R = N - K - i + 1
    if i == 1:
        KC = 1
    else:
        KC = math.factorial(K-1) // math.factorial(i-1) // math.factorial(K-i)
    if R < 0:
        ans = 0
    else:
        ans = math.factorial(R+i) // (math.factorial(R) * math.factorial(i))
    print((ans*KC) % m)


Measured memory_bytes: 3316
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	ll a,b;
	cin>>a>>b;
	ll ans = INFL;
	if(abs(a)==abs(b)){
		if(a==b) mins(ans, 0LL);
		else mins(ans, 1LL);
	}
	else if(abs(a)<abs(b)){
		mins(ans, abs(b)-a+(b>0?0LL:1LL));
		mins(ans, abs(b)+a+1LL+(b>0?0LL:1LL));
	}
	else{
		if(a<b){
			mins(ans, b-a);
			mins(ans, 1LL+abs(a)-abs(b));
		}
		else{
			mins(ans, 1LL+b+a);
			mins(ans, 2LL+abs(a)-abs(b));
		}
	}
	assert(ans>=0);
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int cnt[3];
int main() {
	char c[100005];
	scanf("%s", &c);
	int n = strlen(c);
	for (int i = 0; i < n; i++) cnt[c[i] - 'a']++;
	sort(cnt, cnt + 3);
	if (cnt[2] - cnt[0] <= 1)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
ll fact[200005],factr[200005];
ll mod_pow(ll a, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * a % mod;
    b /= 2;
    a = a * a % mod;
  }
  return res;
}
ll combi(int n, int k){
  if(n < 0 or k < 0 or n < k)return 0;
  return fact[n] * factr[n - k] % mod * factr[k] % mod;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  fact[0] = fact[1] = 1;
  for(int i = 0; i < 200000; i++){
    fact[i + 1] = fact[i] * (i + 1) % mod;
    factr[i] = mod_pow(fact[i], mod - 2);
  }
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for(int i = 0; i < n; i++)cin >> a[i];
  sort(a.begin(), a.end());
  ll ans = 0;
  for(int i = 0; i < n; i++){
    ans = (ans + a[i] * combi(i, k - 1) % mod) % mod;
    ans = (ans - a[i] * combi(n - i - 1, k - 1) % mod + mod) % mod;
  }
  cout << ans << endl;
}


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

typedef long long Int;

int main() {
  Int N;
  cin >> N;
  vector<Int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  
  int ans = 10000;
  
  for (int i = 0; i < N; i++) {
    int cnt = 0;
    while(true) {
      if (A[i] % 2 == 1) {
        break;
      }
      else {
        A[i] /= 2;
        cnt++;
      }
      if (cnt > ans) {
        break;
      }
    }
    ans = min(ans,cnt);
  }
  
  cout << ans << endl;
}


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int count=0;

  for(int i=0;i<N-2;i++){
    if(S.at(i)=='A' && S.at(i+1)=='B' && S.at(i+2)=='C'){
      count++;
    }
  }
  cout << count << endl;
}


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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    map<int64_t,int64_t> m;
    for ( int64_t i = 0; i < N; ++i){
        cin >> A[i];
        m[A[i]] = m[A[i]] + 1;
    }
    
    sort(A.begin(),A.end());
    vector<bool> d( 1e+6 + 10 , true );
    
    int64_t pre = 0;
    for ( int64_t i = 0; i < N; ++i){
        if ( m[A[i]] > 1 ) {
            d[A[i]] = false;
        }
        if ( pre == A[i] ) continue;
        for ( int64_t j = 2; j < 1e+6 + 10; ++j){
            int64_t a = A[i] * j;
            if ( a > 1e+6 ) break;
            d[a] = false;
        }
        pre = A[i];
    }
    
    int64_t num = 0;
    for ( int64_t i = 0; i < N; ++i){
        if ( d[A[i]] ) ++num;
    }
    
    cout << num << endl;
    
    return 0;
}

Measured memory_bytes: 17524
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    string s;
    string ans = "keyence";
    cin >> s;
    int n1 = s.size(), n2 = ans.size();
    int res = 0;
    for (int i = 0; i < n1 && i < n2; i++) {
        if (s[i] == ans[i]) {
            res++;
        } else {
            break;
        }
    }
    for (int i = 0; i < n1 && i < n2; i++) {
        if (s[n1 - 1 - i] == ans[n2 - 1- i]) {
            res++;
        } else {
            break;
        }
    }
    if (res >= n2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}




Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define VI vector<int>

const int P = 1000000007;

using namespace std;


int main(){

	int n, x;
	cin >> x >> n;
	VI p(n);
	for(int i=0; i<n; i++) cin >> p[i];
	sort(p.begin(), p.end());
	auto it1 = lower_bound(p.begin(), p.end(), x);
	auto it2 = it1;

	int p1=x, p2=x;
	if(it1 != p.end()){
		while(*it1 == p1){
			p1--;
			if(it1 != p.begin()) it1--;
			else break;
		}
		while(it2 != p.end() && *it2 == p2){
			p2++;
			it2++;
		}
	}

	if(abs(x-p1) <= abs(x-p2)) cout << p1 << '\n';
	else cout << p2 << '\n';

	return 0;
}


Measured memory_bytes: 3636
N,L = map(int,input().split())


ans = [0]*N
INF = 10**9
myabs = INF
a_num = 0

for i in range(N):
    ans[i] = L+i
    if myabs > abs(ans[i]):
        myabs = abs(ans[i])
        a_num = i
    
out = 0
for i in range(N):
    if i == a_num:
        pass
    else:
        out += ans[i]

print(out)

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

int N, ans = 0;
string S, s1, s2, s3;

int main() {
    cin >> N;
    cin >> S;

    rep (i, N-2){
        s1 = S[i];
        s2 = S[i+1];
        s3 = S[i+2];
        if ((s1 == "A") && (s2 == "B") && (s3 == "C")) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int d = b-a;
        int sum = 0;
        for(int i = 1;i <= d;i++){
            sum += i;
        }
        System.out.println(sum-b);
    }
}


Measured memory_bytes: 23508
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

ull n;
ull dp[1000010];//dp1->A,Bの組 dp2->C,Dの組
ull a[1010],b[1010],c[1010],d[1010];
ull v;

void solve(){
    ull ans=0;
    rep(i,n){
        rep(j,n){
            dp[i*n+j]=c[i]+d[j];
        }
    }
    sort(dp,dp+n*n);
    rep(i,n){
        rep(j,n){
            ull m=upper_bound(dp,dp+n*n,v-(a[i]+b[j]))-lower_bound(dp,dp+n*n,v-(a[i]+b[j]));
            ans+=m;
        }
    }
    cout<<ans<<endl;
}

int main(){
    cin>>n>>v;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n)cin>>c[i];
    rep(i,n)cin>>d[i];
    solve();
}


Measured memory_bytes: 11012
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 20000000000000000
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
//knight and king//
int dr[]= {2,2,-2,-2,1,-1,1,-1};
int dc[]= {1,-1,1,-1,2,2,-2,-2};
int dr1[]= {0,0,1,1,1,-1,-1,-1};
int dc1[]= {1,-1,1,0,-1,0,1,-1};
int dr2[]= {0,0,1,-1};
int dc2[]= {1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 200000

int main()
{
    ll i,j,a[10],x=-1;
    for(i=1;i<=5;i++)
    {
        cin>>a[i];
        if(a[i]==0)x=i;
    }
    cout<<x<<endl;
}




Measured memory_bytes: 3552
h,n = map(int, input().split())
magics = [tuple(map(int, input().split())) for _ in range(n)]
max_a = max(magics, key=lambda x: x[0])[0]
#max_a = sorted(magics, key=lambda x: x[0], reverse=True)[0][0]
dp = [0]*(h+max_a)
for i in range(1, h+max_a):
  dp[i] = min(dp[i-a]+b for a,b in magics)
print(min(dp[h:]))

Measured memory_bytes: 9532
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>

using namespace std;

void solve(int n, int m, vector< pair<int,int> > gr) {
    vector<int> ans(n,0);
    for (int i = 0; i < m; i++) {
        ans[gr[i].first-1] += 1;
        ans[gr[i].second-1] += 1;
    }
    for (int i = 0; i < n; i++) {
        std::cout << ans[i] << std::endl;
    }
}

int main() {
    struct timeval start,end;
    long long span;
    int n,m;

    gettimeofday(&start,NULL);

    std::cin >> n >> m;
    vector< pair<int,int> > gr(m);
    for (int i = 0; i < m; i++) {
        std::cin >> gr[i].first >> gr[i].second;
    }
    solve(n,m,gr);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
//直接計算型
/*int MAX(int *num,int n,int k){
	int i,j,now,max = 0;
	for(i = 0;i < k;i++){
		max += num[i];
	}
	for(i = 1;i < n-k;i++){
		now = 0;
		for(j = 0;j < k;j++){
			now += num[i+j];
		}
		if(max < now)
			max = now;
	}
	return max;
}*/
//更新書き換え型
int MAX(int *num,int n,int k){
	int i,now,max = 0;
	for(i = 0;i < k;i++){
		max += num[i];
	}
	now = max;
	for(i = 0;i < n-k;i++){
		now += num[i+k]-num[i];
		if(max < now)
			max = now;
	}
	return max;
}
int main(){
	int n,k,max;
	int *num;
	int i;
	while(1){
		scanf("%d%d",&n,&k);
		if(n == 0 && k == 0)
			break;
		num = new int[n];
		for(i = 0;i < n;i++){
			scanf("%d",num+i);
		}
		max = MAX(num,n,k);
		printf("%d\n",max);
		delete[] num;
	}
	return 0;
}

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

int main()
{
  int sum;
  int a,b;
  cin>>a>>b;
  sum = a+b;
  int diff = 6-sum;
  if(diff==1)
  {
    cout<<1;
  }
  else if(diff==2)
  {
    cout<<2;
  }
  
  else if(diff==3)
  {
    cout<<3;
  }
}


Measured memory_bytes: 256
#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;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll n;
	cin>>n;
	ll val1 = n / 500;
	ll val2 = (n % 500) / 5;
	cout<<val1*1000 + val2*5<<endl;
	return 0;
}  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	int mx=0,lst;
	int n;
	cin>>n>>lst;
	for (int i=1;i<n;i++){
		int y;
		cin>>y;
		if (y<lst)  mx+=lst-y;
		lst=max(lst,y);
	}
	cout<<mx;
	re 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int W, H; 
char C[60][60] = {}; 
void search(int x, int y){
	C[x][y] = '0'; 
	for(int dx = -1; dx <= 1; dx++){
		for(int dy = -1; dy <= 1; dy++){
			int nx = x + dx; int ny = y + dy; 
			if(nx >= 0 && nx < H && ny >= 0 && ny < W && C[nx][ny] == '1') search(nx, ny); 
		}
	}
	return; 
}
int main() {
	for(int K; ; K++){
	cin >> W >> H; 
	if(W == 0){break;}
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> C[i][j]; 
		}
	}
	int count = 0; 
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(C[i][j] == '1'){search(i, j); count ++; }
		}
	}
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			C[i][j] = '0'; 
		}
	}
	cout << count << endl; 
	}
}


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

int main(){
  int h , w;
  int count = 0;
  cin >> h >> w;
  vector<string> s(h+2);
  string first(w+2,'a');
  string end(w+2,'a');
  s.at(0) = first;
  s.at(h+1) = end;
  string tmp;
  for(int i=1;i<=h;i++){
    cin >> tmp;
    s.at(i) = 'a'+tmp+'a';
  }
  
  for(int i=1;i<=h;i++){
    
    for(int j=1;j<=w;j++){
      count = 0;
      if(s.at(i).at(j) == '.'){
        if(s.at(i-1).at(j-1) == '#')count++;
        if(s.at(i-1).at(j) == '#')count++;
        if(s.at(i-1).at(j+1) == '#')count++;
        if(s.at(i).at(j-1) == '#')count++;
        if(s.at(i).at(j+1) == '#')count++;
        if(s.at(i+1).at(j-1) == '#')count++;
        if(s.at(i+1).at(j) == '#')count++;
        if(s.at(i+1).at(j+1) == '#')count++;
        cout << to_string(count);
      }else if(s.at(i).at(j) == '#'){
        cout << s.at(i).at(j);
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
count=1
point=6
n=gets.to_i
flag=6
check=0
dice=[1,2,3,4,5,6]
repeat=[6]
repeat_sum=0
if n<=6
    p 1
    exit
elsif n<=11
    p 2
    exit
else
repeat_sum=11
v=n.div(repeat_sum)
vv=n%repeat_sum
if vv==0
p 2*v
elsif vv<=6
p 2*v+1
else
p 2*v+2
end
end

Measured memory_bytes: 14308
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,ans;
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> m;
    if(n>40){
    	cout << 1;
    	return 0;
	}
	if(n==1){
		cout << m;
		return 0;
	}
	for(int i=1;i<1000005;i++){
		ll x=1;
		for(int j=0;j<n;j++){
			x*=i;
			if(x>m){
				cout << ans;
				return 0;
			}
		}
		if(m%x==0)ans=i;
	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    ll n;cin>>n;
    vll p(n); REP(i,n) cin>>p[i];
    ll id=0;
    ll ans = 0;
    while(id<n){
        if (p[id]==id+1){
            if (p[id+1]==id+2) id += 2;
            else id++;
            ans++;
        }
        else id++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3992
n, k, c = map(int, input().split())
s = input()
l = [-1] * n
r = [-1] * n
pre = -n - 1
cnt = 0
for i in range(0, n):
    if s[i] == 'x':
        continue
    if i - pre - 1 >= c:
        l[cnt] = i + 1
        cnt += 1
        pre = i
cnt = 0
pre = 2 * n + 1
for i in range(n - 1, -1, -1):
    if s[i] == 'x':
        continue
    if pre - i - 1 >= c:
        
        r[k - cnt - 1] = i + 1
        cnt += 1
        pre = i
ans = []
for i in range(0, k):
    if l[i] == r[i] and l[i] != -1:
        ans.append(l[i])
for x in ans:
    print(x)

Measured memory_bytes: 22220
l = [2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b = map(int,input().split())

if l.index(a) > l.index(b):
    print('Alice')
elif l.index(a) < l.index(b):
    print('Bob')
else:
    print('Draw')

Measured memory_bytes: 3060
def main():
    N, M, K = [int(x) for x in input().split()]
    if M == 1:
        if K == N - 1:
            return 1
        else:
            return 0
    if N == 1:
        return M
    mod = 998244353
    fact = [1]
    for i in range(1, N):
        fact.append(fact[-1] * i % mod)
    fact_inv = [pow(fact[-1], mod - 2, mod)]
    for n in range(N - 1, 0, -1):
        fact_inv.append(fact_inv[-1] * n % mod)
    fact_inv = fact_inv[::-1]
    m_1_pow = [1]
    for _ in range(N):
        m_1_pow.append(m_1_pow[-1] * (M - 1) % mod)
    count = 0
    for k in range(K + 1):
        current = ((((m_1_pow[N - k - 1] * M) % mod) * fact[N - 1] % mod) * fact_inv[k] % mod) * fact_inv[N - 1 - k] % mod
        count = (count + current) % mod
    return count


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 32648
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
X, Y, A, B, C = map(int, readline().split())

p = np.array(readline().split(),np.int32)
q = np.array(readline().split(),np.int32)
r = np.array(readline().split(),np.int32)
#print(p)
#print(q)
#print(r)

pp = np.sort(p)[A-X:]
qq = np.sort(q)[B-Y:]
#print(pp)
#print(qq)

all_item = np.sort(np.concatenate([pp, qq, r]))
# print(all_item)
print(np.sum(all_item[len(all_item) - X - Y:]))




Measured memory_bytes: 19608
#include <iostream>
#include <vector>
using namespace std;
 
int main(){
  double W, H, x, y;
  cin >> W >> H >> x >>y;
  
  //中心を通れば必ず半分になるはず
  double area = W * H / 2;
  cout << (double)W * H / 2;

  if( W / 2 == x && H / 2 == y) cout <<" " << 1 << endl;
  else cout <<" " << 0 << endl;
  
  return 0; 
}


Measured memory_bytes: 256
while True :
    n, k = map(int, input().split())
    
    if n == 0 and k == 0:
        break
    else:
        a=[int(input()) for i in range(n)]
        b = sum(a[0:k])
        c = []
        for i in range(n-k):
            b += a[k+i] - a[i]
            c.append(b)
        print(max(c))


Measured memory_bytes: 11744
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>
#include <queue>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

const double PI = 3.1415926535897932;
/******define variable start******/
string S;
/*******define variable end*******/
ll solve(){
    cin >> S;
    for(ll i = S.size()-1; i >= 0; ){
        string five_char = S.substr(i-4, 5);
        string dream = "dream";
        string dreamer = "dreamer";
        string erase = "erase";
        string eraser = "eraser";
        if(!five_char.compare(dream) || !five_char.compare(erase)){
            i -= 5;
            if(i < 0){
                cout << "YES" << endl;
                return 0;
            }
        } else if(i >= 5) {

            string six_char = S.substr(i-5, 6);
            if(!six_char.compare(eraser)){
                i -= 6;
                if(i < 0){
                    cout << "YES" << endl;
                    return 0;
                }
            } else if(i >= 6){
                
                string seven_char = S.substr(i-6, 7);
                if(!seven_char.compare(dreamer)){
                    i -= 7;
                    if(i < 0){
                        cout << "YES" << endl;
                        return 0;
                    }
                } else {
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "YES" << endl;
    return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    return (int)end_solve;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

int32_t main() 
{
    fastio
    int n;
    cin>>n;
    cout<<(1000-(n%1000))%1000<<endl;
} 

Measured memory_bytes: 3608
//Author:- Kishan Panchal


#include<bits/stdc++.h>
using namespace std;
    #define ll long long 
 
    #define f first
    #define s second
    #define pb push_back
    #define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
    #define all(v) v.begin(),v.end()
    #define M 1000000007
    #define pii pair<int,int>
    #define pll pair<ll,ll>
    #define vll vector<ll>
    #define For(i,a,b) for(ll i=a;i<b;i++)

class component{
    public:
    	ll min3(ll a,ll b,ll c)
		{
			return min(a,min(c,b));
		}
		ll mod(ll a,ll n)
		{
			return (a%n+n)%n;
		}
		template <class T>
		void print(T a)
		{
			
			//cout << "Ans: ";
			cout << a << endl;
		}
		//friend class Ans;
};


class Ans : component {
	public:
	    ll n;
		ll ans;
		Ans()
		{
			ans=0;
		}
		void solve()
		{
              ll n;
              cin>>n;
              vll arr(n);
              For(i,0,n)
              cin>>arr[i];

              stack<int> s;
              ll ans=0;
              For(i,0,n)
              {
              	   if (s.empty())
              	   	s.push(arr[i]);
              	   else
              	   {
              	   	   if (s.top() <= arr[i])
              	   	   {
              	   	   	s.push(arr[i]);
              	   	   }
              	   	   else
              	   	   {
              	   	   	  ans+=s.top()-arr[i];
              	   	   	  s.push(s.top());

              	   	   }
              	   }
              }
              print<ll> (ans);


		}
		
};



    int main()
    {
    	int t;
    	//cin>>t;
        t=1;
    	
    	for (int i=1;i<=t;i++)
    	{
    	     Ans a;   // stack memory 
    		a.solve();
    		//delete(&a);
		}
	}



Measured memory_bytes: 5636
N = int(input())
A = [int(x) for x in input().split()]

ans = 0
r=0
xor_temp = 0
sum_temp = 0
for l in range(N):
	while r<N and (xor_temp^A[r] == sum_temp+A[r]):
		xor_temp = xor_temp^A[r]
		sum_temp = sum_temp+A[r]
		r += 1
	xor_temp = xor_temp^A[l]
	sum_temp = sum_temp-A[l]
	ans += r-l
print (ans)


Measured memory_bytes: 23560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll A,B;
    cin >>A>>B;
    if(A<=5){
        cout<<0<<endl;
    }else if(A<=12){
        cout<<B/2<<endl;
    }else{
        cout<<B<<endl;
    }



    return 0;
    

}

Measured memory_bytes: 3584
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const ll inf=0x3f3f3f3f;
const ll M=200005;
const ll N=55;
ll read(){
	ll s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
vector<ll>G[N];
ll n,m,d,Ans,f[M],fa[N];
struct Node{
	ll a,b,id;
	friend bool operator<(Node A,Node B){return A.a*B.b<A.b*B.a;}
}P[N];
void DFS(ll x){for(auto y:G[x]){DFS(y);P[x].a+=P[y].a;P[x].b+=P[y].b;}}
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();m=read();d=read();
	P[1].a=read();P[1].b=1;P[1].id=1;
	for(ll i=2;i<=n;i++){
		P[i].a=read();P[i].b=1;P[i].id=i;
		G[fa[i]=read()].push_back(i);
	}
	DFS(1);
	memset(f,0x3f,sizeof(f));
	ll Max=n*n*n,L=min(n,d);f[0]=0;
	for(ll i=1;i<=n;i++){
		ll x=L;
		for(ll j=0;(1<<j)<=x;j++){
			x-=(1<<j);
			ll val=P[i].a*(1<<j),num=P[i].b*(1<<j);
			for(ll k=Max;k>=num;k--)f[k]=min(f[k],f[k-num]+val);
		}
		if(x){
			ll val=P[i].a*x,num=P[i].b*x;
			for(ll k=Max;k>=num;k--)f[k]=min(f[k],f[k-num]+val);
		}
	}
	sort(P+1,P+n+1);
	while(P[n].id!=1)n--;
	for(ll i=0;i<=Max;i++){
		if(f[i]>m)continue;
		ll num=i,val=f[i];
		for(ll j=1;j<n;j++){
			ll tmp=min(d-L,(m-val)/P[j].a);
			val+=P[j].a*tmp;num+=P[j].b*tmp;
		}
		ll tmp=(m-val)/P[n].a;
		val+=P[n].a*tmp;num+=P[n].b*tmp;
		Ans=max(Ans,num);
	}
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 5284
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
template<typename T>
int sz(const T &a){return (int)a.size();}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    if(sz(s)%2){
        printf("No\n");
        return 0;
    }
    string a="";
    for(int i=0;i<sz(s)/2;i++)a+="hi";
    if(a==s)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func multiMax(a []int) int {
	ret := a[0]
	for i := 1; i < len(a); i++ {
		ret = max(ret, a[i])
	}
	return ret
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func multiMin(a []int) int {
	ret := a[0]
	for i := 1; i < len(a); i++ {
		ret = min(ret, a[i])
	}
	return ret
}

func satisfied(z, x, y, maxx, miny int) bool {
	if x >= z {
		return false
	}
	if z > y {
		return false
	}
	if maxx >= z {
		return false
	}
	if miny < z {
		return false
	}
	return true
}

func anySatisfied(cand []int, x, y, maxx, miny int) bool {
	for _, z := range cand {
		if satisfied(z, x, y, maxx, miny) {
			return true
		}
	}
	return false
}

func main() {
	var n, m, x, y int
	fmt.Scanln(&n, &m, &x, &y)
	xs := make([]int, n)
	ys := make([]int, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&xs[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&ys[i])
	}
	maxx := multiMax(xs)
	miny := multiMin(ys)
	cand := make([]int, 4)
	cand[0] = x + 1
	cand[1] = y
	cand[2] = maxx + 1
	cand[3] = miny
	if anySatisfied(cand, x, y, maxx, miny) {
		fmt.Println("No War")
	} else {
		fmt.Println("War")
	}
}


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

using namespace std;

#define endl "\n"
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define rrep(i, a, b) for (auto i = (a); i > (b); --i)

int pass[4];

int sol(string &s)
{
  int len = (int)s.size();
  int rank = 0;
  vector <int> v[100];
  rrep(i, len - 1, -1) {
    int tmp;
    if (s[i] == ']') {rank++; continue;}
    else if (s[i] == '[') {rank--; continue;}
    else if (s[i] == '^') {
      tmp = v[i][0];
      rep(j, 1, (int)v[i].size()) tmp ^= v[i][j];
    } else if (s[i] == '+') {
      tmp = v[i][0];
      rep(j, 1, (int)v[i].size()) tmp |= v[i][j];
    } else if (s[i] == '*') {
      tmp = v[i][0];
      rep(j, 1, (int)v[i].size()) tmp &= v[i][j];
    } else if (s[i] == 'a') tmp = pass[0];
    else if (s[i] == 'b') tmp = pass[1];
    else if (s[i] == 'c') tmp = pass[2];
    else tmp = pass[3];
    if (i == 0) {
      return tmp;
    }
    int rtmp = rank;
    int rgoal = (s[i] == '*' || s[i] == '^' || s[i] == '+' ? rank - 1 : rank);
    rrep(j, i - 1, -1) {
      if (s[j] == ']') rtmp++;
      else if (s[j] == '[') rtmp--;
      if (rgoal == rtmp && (s[j] == '^' || s[j] == '*' || s[j] == '+')) {
        v[j].push_back(tmp);
        break;
      }
      if (j == 0) {
        return tmp;
      }
    }
  }
  return 0;
}

int main()
{
  string s;
  string n;
  while (cin >> s)
  {
    if (s == ".")
      return 0;
    cin >> n;
    rep(i, 0, (int)n.size())
    {
      pass[i] = n[i] - '0';
    }
    int tmp = sol(s);
    int ans = 0;
    rep(i, 0, 10) rep(j, 0, 10) rep(k, 0, 10) rep(l, 0, 10) {
      pass[0] = i, pass[1] = j, pass[2] = k, pass[3] = l;
      if (tmp == sol(s)) {
        ans++;
      }
    }
    cout << tmp << " " << ans << endl;
  }
}


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

#define fi first
#define se second

const int N = 2020;
const int mod = 1e9 + 7;

using namespace std;

int ans(int res)
{
        cout << res << "\n";
        exit(0);
}

int main()
{
        ios_base::sync_with_stdio(0);

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

        int x, y;
        cin >> x >> y;
        if(x <= y){
                if(y <= 0) ans(y - x);
                if(x <= -y) ans(-y - x + 1);
                if(x < 0) ans(y + x + 1);
                ans(y - x);
        } else if(-x <= y){
                x = -x;
                if(y <= 0) ans(y - x + 1);
                if(x <= -y) ans(-y - x + 2);
                if(x < 0) ans(y + x + 2);
                ans(y - x + 1);
        } else{
                int res = 0;
                if(x < 0){
                        res = 1;
                        x = -x;
                }
                res += -y - x;
                res += 1;
                ans(res);
        }
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.componentCount = size

    def root(self, index):
        if self.parent[index] == index:  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2):  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2:  # 連結されている場合
            return

        self.componentCount -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2]:
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else:
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2]:
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2):
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index):
        return self.size[self.root(index)]

from collections import defaultdict

N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]

xGrp = defaultdict(list)
yGrp = defaultdict(list)
for i, (x, y) in enumerate(XY):
    xGrp[x].append(i)
    yGrp[y].append(i)

tree = UnionFind(N)
for grp in xGrp.values():
    for l, r in zip(grp, grp[1:]):
        tree.union(l, r)
for grp in yGrp.values():
    for l, r in zip(grp, grp[1:]):
        tree.union(l, r)

xGrpList = defaultdict(set)
yGrpList = defaultdict(set)
for i, (x, y) in enumerate(XY):
    xGrpList[tree.root(i)].add(x)
    yGrpList[tree.root(i)].add(y)

ans = 0
for i in range(N):
    if i != tree.root(i):
        continue
    X, Y = xGrpList[i], yGrpList[i]
    if len(X) + len(Y) < 3:
        continue
    A = len(X) * len(Y)
    ans += A - tree.sizeOfSameRoot(i)
print(ans)


Measured memory_bytes: 48096
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

ll solve(const string S) {
    const int slen = (int) S.size();

    ll acc = 0;
    for (int bits = 0; bits < ((int) (1 << (slen - 1))); bits++) {
        int x = bits;
        // printf("bits: 0x%x\n", bits);
        ll v = S[0] - '0';
        for (int j = 1; j < slen; j++) {
            if (x % 2 == 0) {
                v = v * 10 + (S[j] - '0');
            } else {
                // printf("%lld\n", v);
                acc += v;
                v = (S[j] - '0');
            }
            x >>= 1;
        }
        // printf("%lld\n", v);
        acc += v;
    }
    return acc;
}

int main(void) {
    string S;
    cin >> S;

    cout << solve(S) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

struct UF{
  vi sz, p;
  int comps;

  UF(int s) : comps(s) {
    sz.resize(comps + 1);
    p.resize(comps + 1);
    init();
  }

  void init(){
    for(int i = 0; i <= comps; i++){
      sz[i] = 1;
      p[i] = i;
    }
  }

  int fset(int u){
    return u == p[u] ? u : p[u] = fset(p[u]);
  }

  bool connect(int u, int v){
    u = fset(u);
    v = fset(v);
    if(u != v){
      if(sz[v] > sz[u]){
        swap(u, v);
      }
      sz[u] += sz[v];
      p[v] = u;
      comps--;
      return true;
    }
    return false;
  }
};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n, m;
  cin >> n >> m;
  UF uf(n);
  for(int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    uf.connect(u, v);
  }
  cout << uf.comps - 1;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int a, b, c, d;
  cin>>a>>b>>c>>d;
  cout<<(d==1 ? 1 : 0)<<'\n';
  return 0;
}

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

int main(){
    int n;
  	string x;
    cin >> n;
    vector<string> S(n);
    vector<int> T(n);
    for (int i=0;i<n;i++){
        cin >> S.at(i) >> T.at(i);
    }
    cin >> x;
    int tmp =0;
    for (int k=0;k<n;k++){
        if (S.at(k)==x)tmp=1+k;
    }
    int ans = 0;
    for (int j = tmp;j<n;j++){
        ans += T.at(j);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    n,m,p = map(int, input().split())
    if n==0:
        break
    players =[int(input()) for _ in range(n)]
    winTickets = players[m-1]
    retGld = sum(players) * (100-p)
    print(int(retGld / winTickets) if winTickets > 0 else 0)

Measured memory_bytes: 5616
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

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

	string s ; cin >> s ;
	ll n = s.size() ;
	vll rem(2019,0) ;
	ll ans = 0 ;
	for(int i=1;i<=n;i++){
		ll num = s.at(i-1)-'0' ;
		vll sub(2019,0) ;
		for(int j=0;j<2019;j++){
			sub.at((j*10+num)%2019) = rem.at(j) ;
		}
		sub.at(num)++ ;
		rem = sub ;
		ans += rem.at(0) ;
	}
	cout << ans << endl ;
}



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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

//library----------------------------------------------


int main(){
    CIN(N);
    vi d(N);
    int ans=0;
    rep(i,N)cin>>d[i];
    
    rep(i,N){
        Rep(j,i+1,N){
            ans+=d[i]*d[j];
        }
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	deque<char> deq;
	string s;
	int q, temp;
	cin >> s >> q;
	for (int i = 0; i < s.length(); i++){
		deq.push_back(s[i]);
	}
	bool rev = false;
	for (int i = 0; i < q; i++){
		cin >> temp;
		if (temp == 1){
			if (rev == false) rev = true;
			else rev = false;
		}
		if (temp == 2){
			char p;
			cin >> temp >> p;
			if (temp == 1){
				if (rev == false){
					deq.push_front(p);
				}else{
					deq.push_back(p);
				}
			}else{
				if (rev == false){
					deq.push_back(p);
				}else{
					deq.push_front(p);
				}
			}
		}
	}
	if (rev == true){
		for (int i = deq.size()-1; i >= 0; i--){
			cout << deq[i];
		}
		cout << endl;
		return 0;
	}
	for (int i = 0; i < deq.size(); i++){
		cout << deq[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
 
  UnionFind(int n) {
    init(n);
  }
 
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
 
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
} 
int main() {
ll n,c; cin>>n>>c;
ll imos[200005]={};
rep(i,n){
ll a,b,c; cin>>a>>b>>c;
imos[2*a-1]++;
imos[2*b]--;}
ll ca = 0;
ll ans = 0;
for(ll p=0; p<=200003; p++){
ca+=imos[p];
ans = max(ans,ca);}
ans = min(ans,c);
cout << ans << endl;}


Measured memory_bytes: 5180