akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
const ll INFL = 1e18;
const int INFI = 1e9;
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	char c; cin>>c;
	if(c>='a') cout<<'a';
	else cout<<'A';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	while(t--)
		solve();
}

Measured memory_bytes: 3652
s = input()
l = len(s)
left = ""
right = ""
l_ans = 0
r_ans = 0
if l % 2 == 0:
    left = "10" * (l // 2)
    right = "01" * (l // 2)
else:
    left = "10" * (l // 2) + "1"
    right = "01" * (l // 2) + "0"
for i in range(l):
        if s[i] != left[i]:
            l_ans += 1
        if s[i] != right[i]:
            r_ans += 1
print(min(l_ans, r_ans))

Measured memory_bytes: 3316
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K;
	int x;
	int ans = 0;
	cin >> N >> K;
	rep(i, 0, N)
	{
		cin >> x;
		ans += min(x, K - x) * 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
<?php
	$arr = explode(" ", trim(fgets(STDIN)));
	$p = array_chunk($arr, 2);

	$x = abs($p[1][0] - $p[0][0]);
	$y = abs($p[1][1] - $p[0][1]);

	echo sqrt(pow($x, 2) + pow($y, 2)) . "\n";

Measured memory_bytes: 6592
#include <iostream>
#include <string>

namespace
{
unsigned long long pow2(long long exp)
{
    if(exp <= 0)
        return 1;
    return 1ULL << exp;
}
}

int main()
{
    std::string s;
    std::cin >> s;
    unsigned long long result = 0;
    for(unsigned int i = 0; i != s.length(); ++i)
    {
        unsigned long long base = pow2(i) * (s[i] - '0');
        for(unsigned int j = 0; j != s.length() - i; ++j)
        {
            result += base * pow2(s.length() - i - j - 2);
            base *= 10;
        }
    }
    std::cout << result << std::endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * 条件、sx < tx, sy < ty が重要
 * この条件があるから考えるケースはかなり限られる
 * つまり、直線（真上とか）がない、マイナス方向もない
 */

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    // 距離の差分をとる
    int dx = tx - sx;
    int dy = ty - sy;

    // 出力する文字列
    string s = "";

    // 1
    for(int i = 0; i < dx; i++) s += 'R';
    for(int i = 0; i < dy; i++) s += 'U';

    // 2
    for(int i = 0; i < dx; i++) s += 'L';
    for(int i = 0; i < dy; i++) s += 'D';

    // 3
    s += 'D';
    for(int i = 0; i < dx+1; i++) s += 'R';
    for(int i = 0; i < dy+1; i++) s += 'U';
    s += 'L';

    // 4
    s += 'U';
    for(int i = 0; i < dx+1; i++) s += 'L';
    for(int i = 0; i < dy+1; i++) s += 'D';
    s += 'R';

    cout << s;
}

Measured memory_bytes: 256
_ = input()
S = input()
counter = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            idxi = S.find(str(i))
            if idxi ==-1:
                continue
            idxj = S.find(str(j),idxi+1)
            if idxj == -1:
                continue
            idxk = S.find(str(k),idxj+1)
            if idxk == -1:
                continue
            counter+=1
print(counter)


Measured memory_bytes: 3060
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn digit_check(a:usize, b:usize) -> usize {
    std::cmp::max(a.to_string().len(), b.to_string().len())
}
fn main() {
    input!(n:usize);
    let sq = (n as f64).sqrt() as usize;
    let mut ans = n.to_string().len();
    for i in 1..(sq+1) {
        if n%i==0{
            ans = std::cmp::min(ans, digit_check(i, n/i));
        }
        // println!("{}", ans);
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <stdio.h>

int main()
{
	int n,m;
	int num[50]={0};

	scanf("%d%d",&n,&m);
	int a,b;
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&a,&b);
		num[a-1]++;
		num[b-1]++;
	}
	for(int i=0;i<n;i++)
	{
		printf("%d\n",num[i]);
	}
	return 0;
}

Measured memory_bytes: 128
from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = defaultdict(int)
sa = [0] * (n + 1)
d[0] = 1
if k == 1:
    print(0)
    exit()
for i in range(n):
    sa[i + 1] = sa[i] + a[i]
    sa[i + 1] %= k
ans = 0
for i in range(1, n + 1):
    v = sa[i] - i
    v %= k
    ans += d[v]
    d[v] += 1
    if 0 <= i - k + 1:
        vv = sa[i - k + 1] - (i - k + 1)
        vv %= k
        d[vv] -= 1
print(ans)


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

typedef long long ll;

ll N, M, K;
const ll MOD = 998244353;
vector<ll> PowPM, Inv, Fact, IFact;
ll Res;

ll choose(ll a, ll b) { return Fact[a] * IFact[b] % MOD * IFact[a - b] % MOD; }
int main() {
  cin >> N >> M >> K;
  PowPM.resize(N + 1);
  PowPM[0] = 1;
  for (ll i = 1; i <= N; ++i) PowPM[i] = (M - 1) * PowPM[i - 1] % MOD;
  Inv.resize(N + 1);
  Fact.resize(N + 1);
  IFact.resize(N + 1);
  Inv[1] = Fact[0] = Fact[1] = IFact[0] = IFact[1] = 1;
  for (ll i = 2; i <= N; ++i) {
    Inv[i] = MOD - MOD / i * Inv[MOD % i] % MOD;
    Fact[i] = i * Fact[i - 1] % MOD;
    IFact[i] = Inv[i] * IFact[i - 1] % MOD;
  }
  for (ll i = 0; i <= K; ++i) {
    (Res += M * PowPM[N - i - 1] % MOD * choose(N - 1, N - 1 - i)) %= MOD;
  }
  cout << Res << endl;
  return 0;
}


Measured memory_bytes: 9532
x = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = i*10001 + j*1010 + k*100
            x.append(tmp)
x.sort()

a,b = map(int, input().split())

ret = sum((a<= z and z <= b) for z in x)
print(ret)


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

main(){
  int k;
  char kasu;
  string t;
  int A=0, B=0, AB=0, O=0;
  while( cin >> k >> kasu >> t ){
    if ( t == "A" ) A++;
    if ( t == "B" ) B++;
    if ( t == "AB" ) AB++;
    if ( t == "O" ) O++;
  }
  cout << A << endl;
  cout << B << endl;
  cout << AB << endl;
  cout << O << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="SUN")
    cout<<7;
  if(s=="MON")
    cout<<6;
  if(s=="TUE")
    cout<<5;
  if(s=="WED")
    cout<<4;
  if(s=="THU")
    cout<<3;
  if(s=="FRI")
    cout<<2;
  if(s=="SAT")
    cout<<1;
  cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MaxN=1e5+5;
long long a[MaxN],b[MaxN];  
long long x[MaxN],v[MaxN];
int main()
{
	long long n,c;
	cin>>n>>c;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i]>>v[i];
	}
	for(int i=1;i<=n;i++) 
	{
		a[i]=a[i-1]+v[i]-(x[i]-x[i-1]);
	}
	x[n+1]=c;
	for(int i=n;i>=1;i--) 
	{
		b[i]=b[i+1]+v[i]-(x[i+1]-x[i]);
	}
	for(int i=2;i<=n;i++) 
	{
		a[i]=max(a[i-1],a[i]);
	}
	for(int i=n-1;i>=1;i--) 
	{
		b[i]=max(b[i],b[i+1]);
	}
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		ans=max(ans,a[i]-x[i]+b[i+1]);
		ans=max(ans,b[i]-(c-x[i])+a[i-1]);
		ans=max(ans,a[i]);
		ans=max(ans,b[i]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3328
N = int(input())
a = list(map(int, input().split()))
table = [-1] * (N + 1)
d = [0, 0]
mod = 10 ** 9 + 7
class Factorial:
  def __init__(self, n, mod):
    self.f=[1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i=[pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(N + 1, mod)
for i in range(N + 1):
  if table[a[i]] != -1:
    d = [table[a[i]], i]
    break
  table[a[i]] = i
for i in range(1, N + 2):
  x = f.combi(N + 1, i)
  w = 0
  if N + d[0] - d[1] >= i - 1:
    w = f.combi(d[0] + N - d[1], i - 1)
  print((x - w) % mod)

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

int main() {
    
    int H, W;
    cin >> H >> W;
    char A[H][W];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
        }
    }

    
    for(int i = 0; i < W + 2; i++) cout << "#";
    cout << endl;

    for(int i = 0; i < H; i++) {
        cout << "#";
        for (int j = 0; j < W; j++) {
            cout << A[i][j];
        }
        cout << "#" << endl;
    }

    for(int i = 0; i < W + 2; i++) cout << "#";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int N; cin>>N;
  vector<int>A(N);
  vector<int>ans(N);
  if(N%2==0){
    rep(i,N){
    	cin>>A[i];
    	if(i%2==0)ans[(N+i)/2]=A[i];
	    else ans[(N-i-1)/2]=A[i];
  	}
  }
  else{
    rep(i,N){
      cin>>A[i];
      if(i%2==0)ans[(N-i-1)/2]=A[i];
      else ans[(N+i)/2]=A[i];
    }
  }
  rep(i,N){
    cout<<ans[i]<<(i==N-1? "":" ");
  }
  cout<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  unordered_map<int, int>mp;
  int n, m;
  cin >> n >> m;
  mp[0] = 1;
  ll ans = 0;
  ll sum = 0;
  for (int i = 0; i < n; i++){
    int x;
    cin >> x;
    sum += x;
    sum %= m;
    //ans += mp[sum];
    mp[sum]++;            
  }                   
  for (auto v : mp){
    ll n = v.second;
    ans += (n * (n - 1)) / 2;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a.at(i);
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=a.at(i)-1;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int,input().split()))
 
ans = 0
 
for i in range(N):
    if p[i] != (i+1) :
        ans += 1
 
if ans == 0:
    print('YES')
elif ans == 2:
      print('YES')
else :
    print('NO')

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10 ** 6)

N, M = map(int, input().split())
adjL = [[] for v in range(N)]
for e in range(M):
    A, B = map(int, input().split())
    adjL[A - 1].append(B - 1)
    adjL[B - 1].append(A - 1)

# 二部グラフかどうかを判定する（頂点を1or-1で塗っていく）
colors = [0] * N

def dfs(vNow, color):
    colors[vNow] = color # 頂点vNowをcolorで塗る
    for v in adjL[vNow]:
        if colors[v] == color:
            # 隣接する頂点vが同じ色で彩色済みならば、二部グラフではない
            return False
        if colors[v] == 0 and not dfs(v, -color):
            # 隣接する頂点vが未彩色ならば、もう１つの色で塗ってみる
            return False

    return True


IsBipartite = dfs(0, 1)

if IsBipartite:
    # 二部グラフである場合
    num = colors.count(1)
    print(num * (N - num) - M)
else:
    # 二部グラフでない場合
    print(N * (N - 1) // 2 - M)


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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 998244353

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){ //aとbの最大公約数を求める
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b){ //aとbの最小公倍数を求める(gcd要)
    return (a/gcd(a,b)*b);
}

/*nCk (mod MOD)の計算 BEGIN*/
//faccal -> n!, k!^(MOD-2)の計算(初期化)
//comb -> nCk (mod MOD)の計算
ll mlpow(ll x, ll p) { //x^p(long long)%MOD
    ll tmp = 1;
    if(p == 0) return 1;
    while(p != 0) {
        if(p & 1) tmp = tmp*x % MOD;
        x = x*x % MOD;
        p = p >> 1;
    }
    return tmp;
}

int facnum = 200005;
vl fac(facnum);   //n!
vl facM2(facnum);  //k!^(MOD-2)

void faccal(ll up) {
    fac[0] = 1;
    facM2[0] = 1;
    for(ll i = 0; i<up+1; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        facM2[i+1] = facM2[i]*mlpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
}

ll comb(ll n, ll k) {
    if(n == 0 && k == 0) return 1;
    if(n < k || n < 0) return 0;
    ll tmp = facM2[n-k]*facM2[k] % MOD;
    return tmp*fac[n] % MOD;  //nCk = n!*(k!)^(M-2)*((n-k)!)^(M-2)
}
/*nCk (mod MOD)の計算 END*/

int main() {
    int N, M, K;
    ll ans = 0;
    cin >> N >> M >> K;

    faccal(N);

    rep(i,K+1){
        ll tmpM1 = mlpow(M-1, N-1-i);
        ll tmpM = M;
        tmpM = tmpM*tmpM1%MOD;
        tmpM = tmpM*comb(N-1, i)%MOD;
        ans = (ans+tmpM)%MOD;

    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
int n;
long long mod = 1e9+7;
vector<int> prime;

void primer(int x) {
    prime.push_back(2);
    prime.push_back(3);
    for(int i = 4; i <= x; ++i) {
        int inlimit = sqrt(i);
        bool pflg = true;
        for(int j = 2; j <= inlimit; ++j) {
            if(i % j == 0) {
                pflg = false;
                break;
            }
        }
        if(pflg) prime.push_back(i);
    }
}

int main() {
    cin >> n;
    long long ans = 1;
    primer(n);
    int plen = prime.size();
    vector<long long> primes(plen, 1);
    for(int i = 1; i <= n; ++i) {
        if(i == 1) {
            ans *= 1;
        }else {
            int index = 0;
            int check = i;
            while(check != 1) {
                if(check % prime.at(index) == 0) {
                    check /= prime.at(index);
                    primes.at(index)++;
                }else {
                    index++;
                }
            }
        }
    }

    for(int i = 0; i < plen; ++i) {
        ans *= primes.at(i);
        ans %= mod;
    }

    cout << ans << endl;
}

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

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> distances(n);
    rep(i,n) distances[i] = 0;
    for(int i=1;i<=n-1;i++){
        for(int j=i+1;j<=n;j++){
            int d = min(j-i, abs(x-i)+1+abs(y-j));
            distances[d]++;
        }
    }

    for(int i=1;i<n;i++){
        cout << distances[i] << endl;
    }
    return 0;
} 

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

using namespace std;

int f(int n){
  if(n % 2 == 0)
  {
    return n / 2;
  }else{
    return 3*n + 1;
  }
}

int main()
{
  int s;
  map<int, int> memo;
  cin >> s;
  int index = 1;
  while(true)
  {
    if(memo.count(s))
    {
      break;
    }else{
      memo[s] = 1;
      s = f(s);
      index++;
    }
  }
  cout << index << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  I n;
  cin >> n;
  map<string, I> mp;
  REP(i,n){
    string name;
    cin >> name;
    mp[name]++;
  }
  I m;
  cin >> m;
  REP(i,m){
    string name;
    cin >> name;
    mp[name]--;
  }
  I t=0;
  MREP(i,mp){
    auto key = i->first;
    auto value = i->second;
    t = max(t,i->second);
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using ll = long long;
using namespace std;

int main() {
	int a, b, k; cin >> a >> b >> k;
	int c = max(a, b);
	//int count = 0;
	deque<int>ans;
	for (int i = 1; i <= c; i++) {
		if (a%i == 0 && b%i == 0) {
		
			ans.push_front(i);
		}
	}
	cout << ans[k - 1] << endl;;
}


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


//defines...
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define in insert
#define pi 2*acos(0.0)1
#define srt(s) sort(s.begin(),s.end())
#define rsrt(s) sort(s.rbegin(),s.rend())
#define all(x) x.begin(),x.end()

const ll mod=1e9+7;
const ll MX=2e5+5;

//code goes from here...



int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);
#endif

    boost
    //---------------------------------
    ll k,n;
    cin >> k >> n;
    vector <ll> v(n);
    for(ll i=0;i<n;i++) cin >> v[i];
    ll ans=k-v[n-1]+v[0];
    ll mx;
    for(ll i=1;i<n;i++)
    {
        mx=v[i]-v[i-1];
        ans=max(mx,ans);
    }
    cout << k-ans << endl ;
    
    //---------------------------------
    
    return 0;
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1010;
int n;
LL x[maxn],y[maxn],u[maxn],v[maxn],bs[35];

LL power_int(int a, int b) {
  LL x = 1;
  while (b > 0) {x *= a;b--;}
  return x;
}

void work() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

  LL parity = (x[0] + y[0]) % 2;

  for (int i = 0; i < n; i++) if ((x[i] + y[i] - parity) % 2 != 0) {cout<<"-1"<<endl;return;}

    if (parity == 0) {
        cout << 32 << endl;
        for (int i = 30; i > -1; i--) cout << power_int(2, i) << " ";
        cout << 1 << endl;
        for (int i = 0; i < n; i++) x[i]++;
    } else {
        cout << 31 << endl;
        for (int i = 30; i > -1; i--) cout << power_int(2, i) << " ";
        cout << endl;
    }

    for (int i = 0; i < n; i++) u[i] = x[i] + y[i], v[i] = x[i] - y[i];

    for (int i = 0; i < n; i++) {
        for (int j = 30; j > -1; j--) {
            if (u[i] > 0 && v[i] > 0) {cout << 'R'; u[i] -= power_int(2, j); v[i] -= power_int(2, j); }
            else if (u[i] > 0 && v[i] < 0) { cout << 'U'; u[i] -= power_int(2, j); v[i] += power_int(2, j); }
            else if (u[i] < 0 && v[i] > 0) { cout << 'D'; u[i] += power_int(2, j); v[i] -= power_int(2, j); }
            else { cout << 'L'; u[i] += power_int(2, j); v[i] += power_int(2, j);}
        }
        if (parity == 0) cout << 'L';
        cout << endl;
    }
}
int main(){
    bs[0] = 1;
    for (int i=1;i<32;i++) bs[i] = bs[i-1] << 1;
    work();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int 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: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <math.h>
#include <map>
#include <stdio.h>
#include <cstring>
#include <queue>
#define gc(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
char _;
using namespace std;

using ll = long long;
char arr[10001];
ll final = 0;
ll length = 0;
ll filler = 0;
unsigned long long int dp[10001][2][300];

ll calc(ll position, bool flag, ll sum)
{
    ll answer = 0;
    ll limit = 9;
    if (flag) limit = arr[position] - '0';
    if (position == length) {
        if (sum % filler == 0) return 1;
        else return 0;
    }

    if (dp[position][flag][sum] != -1) return dp[position][flag][sum];

    for (ll i = 0; i <= limit; i++) {
        if (i < limit || flag == false) {answer += calc(position + 1, false, (sum % filler) + i );  }
        else if (i == limit) {answer += calc(position + 1, true, (sum % filler) + i );}
    }
    return dp[position][flag][sum] = answer%1000000007;
}


int main(){
    cin>>arr;
    length = strlen(arr);
    gc(filler);
    memset(dp, -1, sizeof(dp));
    final = calc(0, true, 0);
    final --;
    if (final < 0) final = 1000000007  + final;
    else final = final % 1000000007;
    cout<<final<<"\n";
    return 0;
}

Measured memory_bytes: 51260
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, A, B = map(int, input().split())
    full = N // (A+B)
    ans = full * A
    N -= full * (A+B)
    if N >= A:
        ans += A
    else:
        ans += N
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 200005
#define lson l,m,tr[rt].ls
#define rson m+1,r,tr[rt].rs
struct edge{int to,next;}e[N*60];
struct Segment{int ls,rs;}tr[N];
struct node{int x,op,idx;}t[N];
bool cmp(const node &a,const node &b){return a.x<b.x;}
int n,head[N],cnt,p[N],a[N],b[N],vis[N],rot,c[N],tot;
void add(int x,int y){e[cnt]=(edge){y,head[x]};head[x]=cnt++;}
int dfn[N],low[N],tims,sta[N],top,fa[N];
void tarjan(int x)
{
	dfn[x]=low[x]=++tims;vis[x]=1;sta[++top]=x;
	for(int i=head[x];i!=-1;i=e[i].next)
	{
		int to1=e[i].to;
		if(!dfn[to1])tarjan(to1),low[x]=min(low[x],low[to1]);
		else if(vis[to1])low[x]=min(low[x],dfn[to1]);
	}
	if(dfn[x]==low[x])
	{
		int t;
		do{
			t=sta[top--];fa[t]=x;
			vis[t]=0;
		}while(t!=x);
	}
}
void build(int l,int r,int &rt)
{
	if(!rt)rt=++cnt;if(l==r){p[l]=rt;return ;}
	int m=(l+r)>>1;build(lson);build(rson);
}
void link(int l,int r,int rt)
{
	if(l==r)return ;add(rt,tr[rt].ls);add(rt,tr[rt].rs);
	int m=(l+r)>>1;link(lson);link(rson);
}
void Update(int L,int R,int x,int l,int r,int rt)
{
	if(L<=l&&r<=R)return add(x,rt);int m=(l+r)>>1;
	if(L<=m)Update(L,R,x,lson);if(m<R)Update(L,R,x,rson);
}
void add_edge(int idx,int x,int v)
{
	int l=x+1,r=tot+1;
	while(l<r)
	{
		int m=(l+r)>>1;
		if(c[m]-c[x]<v)l=m+1;
		else r=m;
	}if(x+1<l)Update(x+1,l-1,idx,1,tot,rot);
	l=1,r=x;
	while(l<r)
	{
		int m=(l+r)>>1;
		if(c[x]-c[m]<v)r=m;
		else l=m+1;
	}if(l<x)Update(l,x-1,idx,1,tot,rot);
}
int check(int x)
{
	memset(head,-1,sizeof(head));cnt=0;
	memset(dfn,0,sizeof(dfn));tims=0;
	memset(low,0,sizeof(low));
	link(1,tot,rot);
	for(int i=1;i<=n;i++)
	{
		add(p[b[i]],i);add(p[a[i]],i+n);
		add_edge(i,a[i],x);
		add_edge(i+n,b[i],x);
	}
	for(int i=1;i<=tot;i++)if(!dfn[i])tarjan(i);
	for(int i=1;i<=n;i++)if(fa[i]==fa[i+n])return 0;
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1,x,y;i<=n;i++)
	{
		scanf("%d%d",&x,&y);
		t[++tot]=(node){x,0,i};
		t[++tot]=(node){y,1,i};
	}sort(t+1,t+tot+1,cmp);//puts("a");
	for(int i=1;i<=tot;i++)
	{
		if(!t[i].op)a[t[i].idx]=i;
		else b[t[i].idx]=i;
		c[i]=t[i].x;
	}cnt=tot;rot=0;build(1,tot,rot);cnt=0;
	int l=0,r=1<<30;
	while(l<r)
	{
		int m=(l+r)>>1;
		if(check(m))l=m+1;
		else r=m;
	}printf("%d\n",l-1);
}

Measured memory_bytes: 18304
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define SZ(x) ((int)(x).size())
#define BACK(x) prev((x).end())
#define HASK(x, y) ((x).find(y) != (x).end())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1 << 19, mod = 1000000007;

template <class T1, class T2> inline void addMod(T1& a, T2 b)	{   a = (a + b) % mod;  }
template <class T1, class T2> inline void multMod(T1& a, T2 b)	{   a = a * b % mod;    }
template <class T1, class T2> inline void divMod(T1& a, T2 b)	{   a = a * qpow(b, mod-2) % mod;    }

long long qpow(long long a, long long b)
{
    long long ret = 1;
    for (; b!=0; b>>=1)
    {
        if (b & 1)  multMod(ret, a);
        multMod(a, a);
    }
    return ret;
}

vector <int> G[maxN];
long long pow12[maxN], res;
int deg[maxN], n;

long long ompi(int d)
{
	long long ret = mod - 1;
	multMod(ret, pow12[d]);
	addMod(ret, 1);
	return ret;
}

int dfs(int v, int fat=0)
{
	for (int u : G[v])
		if (u != fat)
			deg[v] += dfs(u, v);
	deg[v]++;
	
	if (SZ(G[v]) != 1)
	{
		long long x = 0, dep = deg[fat];
		deg[fat] = n - deg[v];
		
		for (int u : G[v])
		{
			long long temp = pow12[n-1-deg[u]];
			multMod(temp, ompi(deg[u]));
			addMod(x, temp);
		}
		
		addMod(x, pow12[n-1]);
		multMod(x, mod-1);
		addMod(x, 1);
		multMod(x, pow12[1]);
		addMod(res, x);
		
		deg[fat] = dep;
	}
	
	return deg[v];
}

void solve()
{
	scanf ("%d", &n);
	FOR(i, 1, n)
	{
		int a, b;
		scanf ("%d%d", &a, &b);
		G[a].pb(b);
		G[b].pb(a);
	}
	
	pow12[0] = 1;
	pow12[1] = qpow(2, mod-2);
	FOR(i, 2, n+1)
		pow12[i] = pow12[i-1] * pow12[1] % mod;

	dfs(1);
	printf("%lld\n", res);
}
 
int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}
 





Measured memory_bytes: 35700
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
    // clang-format on

#include <map>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> m;
    int ans = 0;
    REP(i, 0, n) {
        int x;
        cin >> x;
        m[x]++;
        ans ^= x;
    }
    if (m.size() == 1 && m.count(0) > 0) {
        cout << "Yes" << endl;
        return 0;
    }
    if (m.size() > 3 || n % 3 != 0) {
        cout << "No" << endl;
        return 0;
    }
    if (ans != 0) {
        cout << "No" << endl;
        return 0;
    }
    if (m.count(0) != 0 && m[0] != n / 3) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    string s;
    cin>>n>>s;
    int k;
    cin>>k;
    for(int i=0;i<n;i++){
        if(s[i]!=s[k-1]){
            s[i]='*';
        }
    }
    cout<<s<<endl;
}
 

Measured memory_bytes: 256
while input = gets
  cards = input.split(",").map(&:to_i)
  seq = Array.new(13){0}
  cards.each{|i|
    seq[i-1] += 1
  }
  if seq.max == 4
    puts "four card"
  elsif seq.max == 3
    if (seq - [0]).size == 2
      puts "full house"
    else
      puts "three card"
    end
  elsif seq.max == 2
    if (seq - [0]).size == 3
      puts "two pair"
    else
      puts "one pair"
    end
  else
    str_seq = (seq + [seq[0]]).join
    if str_seq =~ /11111/
      puts "straight"
    else
      puts "null"
    end
  end
end

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

// Union-Find木
struct UnionFind {
  vector<int> par;
  
  // Constructor
  UnionFind(int n): par(n) {
    for (int i = 0; i < n; i++) par[i] = i;
  }
  
  // n要素で初期化
  void init(int n) {
    par.resize(n);
    for (int i = 0; i < n; i++) par[i] = i;
  }
  
  // 根の検索
  int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  
  // xとyの属する集合を併合
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    par[x] = y;
    return true;
  }
  
  // xとyが同じ集合に属するか
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n, m; // n:頂点数 m:辺数
  cin >> n >> m;
  
  vector<int> G[n]; // G:頂点数がnのグラフを表す隣接リスト
  
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではこの行をコメントアウト
  }
  
  UnionFind uf(n);
  deque<int> dq;
  dq.emplace_front(0);
  
  while (true) {
    bool next = false;
    for(int i = 0; i < G[dq.back()].size(); i++) {
      if (!uf.same(dq.back(), G[dq.back()][i])) {
        uf.unite(dq.back(), G[dq.back()][i]);
        dq.emplace_back(G[dq.back()][i]);
        next = true;
        break;
      }
    }
    if (!next) break;
  }
  while (true) {
    bool next = false;
    for(int i = 0; i < G[dq.front()].size(); i++) {
      if (!uf.same(dq.front(), G[dq.front()][i])) {
        uf.unite(dq.front(), G[dq.front()][i]);
        dq.emplace_front(G[dq.front()][i]);
        next = true;
        break;
      }
    }
    if (!next) break;
  }
  
  cout << dq.size() << '\n';
  while (!dq.empty()) {
    cout << dq.front() + 1;
    dq.pop_front();
    if (!dq.empty()) cout << " ";
  }
}

Measured memory_bytes: 7936
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>

#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;

using namespace std;

void solve(){
    ll sum;
    cin >> sum;
    ll n = sum / 11;
    if(n * 11 < sum){
        ll rem = sum - n * 11;
        if(rem > 6) cout << 2 * n + 2;
        else cout << 2 * n + 1;
    }
    else cout << 2 * n;
}

int main(){
    barsik;
    int q = 1;

    //cin >> q;

    for(int i = 1; i <= q; i++){
//        cout << "Case " << i << ": ";
        solve();
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int dp[105][105][4];
	memset(dp,0,sizeof(dp));

	int mod = 100000;

	dp[1][1][0] = 1;
	dp[1][1][2] = 1;
	for (int i = 1;i <= 100;i++){
		for (int j = 1;j <= 100;j++){
			if(i == 1 && j == 1) continue;
			dp[i][j][0] = (dp[i-1][j][0] + dp[i-1][j][1])%mod;
			dp[i][j][1] = dp[i][j-1][2];
			dp[i][j][2] = (dp[i][j-1][2] + dp[i][j-1][3])%mod;
			dp[i][j][3] = dp[i-1][j][0];
		}
	}

	while(true){
		int h,w; cin >> h >> w;
		if(h == 0) break;
		int ans = 0;
		ans = dp[h][w][0] + dp[h][w][2];
		cout << ans%mod << endl;
	}

	return 0;

}



Measured memory_bytes: 3164
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  ll N; cin>>N;
  vector<ll> h(N);
  rep(i,N){
    cin>>h[i];
  }
  // 貰うDP
  vector<ll> dp(N);
  dp[1]=abs(h[1]-h[0]);
  REP(i,2,N){
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
  }
  cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 4728
n = int(input())
a1 = 1
a0 = 1

for i in range(0 ,n - 2):
    a1, a2 = a0, a1
    a0 = a1 + a2

if n == 0:
    print(2)
if n == 1:
    print(1)
if n == 2:
    print(3)
if n >= 3:
    print(a0 + a1 * 2)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n, m, v, p, ans;
vector<ll> s(n);
bool solve(int index) { //条件判定
	ll i = upper_bound(ALL(s), s[index]) - s.begin() - 1;
	ll a = s[i] + m, now = 0;
	ll k = upper_bound(ALL(s), a) - s.begin() - 1;
	if (k < n - p) return false;
	if (i >= n - p) return true;
	REP(j, n) {
		if (j >= n - p + 1) now += m;
		else now += min(a - s[j], m);
	}
	//cout << i << " " << now << endl;
	if (now >= m * v)return true;
	return false;
}

int nibutan() { //ちゃろー！

	int ng = -1; //最大値ならs.size()
	int ok = (int)s.size(); // 最大値なら0

	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (solve(mid)) ok = mid;
		else ng = mid;
	}
	return ok; //満たさない最大ならng
}


int main() {
	cin >> n >> m >> v >> p;
	REP(i, n) {
		ll a;
		cin >> a;
		s.push_back(a);
	}
	sort(ALL(s));
	s.push_back(INF);
	cout << n - nibutan() << endl;
	
}





Measured memory_bytes: 1400
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n;
int a[100010];

int main(){

  n = in();
  REP( i , n ){
    a[i] = in();
  }

  int ans = 1;
  int st = -1;
  FOR( i , 1 , n ){
    if( st == -1 ){
      if( a[i] > a[i-1] ){
        st = 1;
      } else if( a[i] < a[i-1] ){
        st = 2;
      }
    } else if( st == 1 ){
      if( a[i] < a[i-1] ){
        ans++;
        st = -1;
      }
    } else if( st == 2 ){
      if( a[i] > a[i-1] ){
        ans++;
        st = -1;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		int S = 0;
		int T = 0;
		for(int i=0;i<4;i++) S += sc.nextInt();
		for(int i=0;i<4;i++) T += sc.nextInt();
		System.out.println(max(S, T));
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
 
int main() {
  ull a,b,x;
  cin >>a >>b>>x;
  if(a!=0) cout << (b/x)-((a-1)/x) <<endl;
  else cout << (b/x)+1 <<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

struct RBQ{
  int n=(1<<20),data[(1<<21)];
  RBQ(){
    memset(data,0,sizeof(data));
  }
  void update(int k,int x){
    k+=n-1;
    data[k]=x;
    while(k>0){
      k=(k-1)/2;
      data[k]=max(data[k*2+1],data[k*2+2]);
    }
  }
  int find(int a,int b,int k=0,int l=0,int r=(1<<20)){
    if(r<=a || b<=l)return 0;
    if(a<=l && r<=b)return data[k];
    int v1=find(a,b,k*2+1,l,(l+r)/2);
    int v2=find(a,b,k*2+2,(l+r)/2,r);
    return max(v1,v2);
  }
};

int n,k;
int a[100009];
int ca[45],cb[45];

signed main(){
  RBQ R;
  cin>>n>>k;
  r(i,n)cin>>a[i];
  r(i,41){
    int x=(1LL<<i),c=0,b=0;
    r(j,n){
      if(a[j]&x) c++;
      else b++;
    }
    cb[i]=c*x;
    ca[i]=b*x;
  }
  int ans=0;
  vector<P>v;
  r(i,(1<<20)){
    int s=0;
    r(j,20){
      if((1<<j)&i)s+=ca[j];
      else s+=cb[j];
    }
    R.update(i,s);
  }
  r(i,(1<<20)){
    int x=i;
    x=(x<<20);
    int s=0;
    r(l,20){
      int j=20+l;
      if((1LL<<j)&x)s+=ca[j];
      else s+=cb[j];
    }
    int p=k-x;
    p=min(k-x,(int)(1<<20));
    p=min(p,k);
    if(p<0)continue;
    //cout<<p<<endl;
    if(p!=(1<<20))p++;
    ans=max(ans,s+R.find(0,p));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 17408
#include <iostream>
 
using namespace std;
 
int gcd(int a, int b) {
    if (a % b == 0) {
        return (b);
    } else {
        return (gcd(b, a % b));
    }
}
 
int main() {
    int K;
    long long int res = 0;
    cin >> K;
 
    for (int a = 1; a <= K; ++a) {
        for (int b = 1; b <= K; ++b) {
            for (int c = 1; c <= K; ++c) {
                res += gcd(gcd(a, b), c);
            }
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3632
def main():
    S = list(input())

    dp = [0] * 13
    dp[0] = 1
    mod = 10**9 + 7
    digit = 1
    for i in range(len(S)-1,-1,-1):
        nextdp = [0] * 13
        if S[i] == '?':
            for j in range(10):
                for k in range(13):
                    nextdp[(j * digit + k) % 13] += dp[k]
                    # あらかじめ10*9 + 7で割って余りを出しておく
                    nextdp[(j * digit + k) % 13] %= mod
        else:
            j = int(S[i])
            for k in range(13):
                nextdp[(j * digit + k) % 13] += dp[k]
                # あらかじめ10*9 + 7で割って余りを出しておく
                nextdp[(j * digit + k) % 13] %= mod
        
        digit *= 10
        # A * 桁数の13で割ったあまりは (A % 13) * (桁数 % 13)のため、桁数を13で割っておく
        digit %= 13
        dp = nextdp
    
    print(dp[5])

main()

Measured memory_bytes: 49776
from bisect import bisect_left, bisect_right
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ruisekiwa_of_A = [0]
ruisekiwa_of_B = [0]
for a in A:
    ruisekiwa_of_A.append(ruisekiwa_of_A[-1]+a)
for b in B:
    ruisekiwa_of_B.append(ruisekiwa_of_B[-1]+b)
# ansの最大値をとる
ans = 0
for i in range(N+1):
    tmp = 0
    if K >= ruisekiwa_of_A[i]:
        tmp = i
    else:
        continue
    tmp += bisect_right(ruisekiwa_of_B, K-ruisekiwa_of_A[i])-1
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 132780
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
ll n,k,ans1,ans2,ans=1;
int main(){
	scanf("%lld %lld",&n,&k);
	ans=(n/k)*(n/k)*(n/k);
	if(!(k%2)){
		ans2=(n+(k/2))/k;
		ans+=ans2*ans2*ans2;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
  int n;
  cin >> n;

  bool flag = true;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      if (a % 3 != 0 && a % 5 != 0) {
        flag = false;
      }
    }
  }

  if (flag) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

//構造体の宣言を簡単にするためによく typedef struct は使われる。
//ppの意味はよくわかんない
typedef struct pp {
    char name[100];
    int t;
} P;

//QはP(100個の文字列と１つの整数からなる)が100005個からなるリスト
P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b){ return a < b ? a : b; }

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    for(i=1;i<=n;i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1;
    tail = n+1;

    while(head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t>0) enqueue(u);
        else{
            printf("%s %d\n",u.name, elaps);
        }
    }

}


Measured memory_bytes: 11856
#include<bits/stdc++.h>
using namespace std;
string a;
int ans;
int main(){
    cin>>a;
    if(a[0] != 'C') ans++;
    if(a[1] != 'O') ans++;
    if(a[2] != 'D') ans++;
    if(a[3] != 'E') ans++;
    if(a[4] != 'F') ans++;
    if(a[5] != 'E') ans++;
    if(a[6] != 'S') ans++;
    if(a[7] != 'T') ans++;
    if(a[8] != 'I') ans++;
    if(a[9] != 'V') ans++;
    if(a[10] != 'A') ans++;
    if(a[11] != 'L') ans++;
    if(a[12] != '2') ans++;
    if(a[13] != '0') ans++;
    if(a[14] != '1') ans++;
    if(a[15] != '6') ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 256