akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

constexpr int Grundy(int n, const int k) {
    int m = 0;
    while(n % k != 0) {
        m = n / k + n % k;
        m -= m % (n / k + 1);
        n -= m;
    }
    return n / k;
}

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

    int N, A, K;
    cin >> N;

    int ret = 0;
    rep(i, N) {
        cin >> A >> K;
        ret ^= Grundy(A, K);
    }

    cout << (ret ? "Takahashi" : "Aoki") << endl;

    return 0;
}

Measured memory_bytes: 384
// abc138_c
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> v;
	v.resize(N);
	for (int i = 0; i < N; i++) {
		double A;
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	double sum = v[0];
	for (int i = 1; i < N; i++) {
		sum = double(sum + v[i]) / 2.0;
	}
	cout << sum << endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) rep2(i,0,n-1)
using S=set<int>;
S U;
void print(S x){for(auto e:x)cout<<e<<" ";cout<<endl;}
void f(S &a,S b,char c){
    if(c=='u') {for(auto e:b)a.emplace(e);}
    else if(c=='i') for(auto it=a.begin();it!=a.end();) if(b.count(*it))it++;else it = a.erase(it);
    else if(c=='d') for(auto it=a.begin();it!=a.end();) if(b.count(*it))it=a.erase(it);else it++;
    else if(c=='s') {S t;for(auto e:a)if(!b.count(e))t.emplace(e);for(auto e:b)if(!a.count(e))t.emplace(e);a=t;}
}
void cmp(S &a){
    set<int> nxt;for(auto e:U)if(!a.count(e))nxt.emplace(e);a=nxt;
}
const int N=1100000;
char s[N];
S a[300];
int i;
S expr();
S factor();
S number(){
    return a[s[i++]];
}
S factor(){
    bool flag=false;
    if(s[i]=='c')flag=true,i++;
    S res;
    if(s[i]=='('){
        ++i;
        res=expr();
        ++i;
    }
    else res=number();
    if(flag)cmp(res);
    return res;
}
set<char> op{'u','i','d','s'};
S expr(){
    S res=factor();
    for(;;){
        char c=s[i];
        if(!op.count(c))break;
        else i++;
        f(res,factor(),c);
    }
    return res;
}
main(){
    char c;int n;
    for(;;){
        U=S();
        for(;;){
            cin>>c>>n;
            if(cin.eof())exit(0);
            if(c=='R')break;
            a[c]=S();
            rep(_,n){int x;cin>>x;a[c].emplace(x);U.emplace(x);}
        }
        cin.ignore();
        string ss;
        i=0;
        getline(cin,ss);
        rep(j,ss.size())s[j]=ss[j];
        S ans=expr();
        if(ans.empty())cout<<"NULL\n";
        else{
            cout<<*ans.begin();
            for(auto it=ans.begin();++it!=ans.end();){
                cout<<" "<<*it;
            }
            cout<<endl;
        }

        rep(j,ss.size())s[j]=0;
    }
}




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

int main(){
    int c[3][3];
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++) cin >> c[i][j];
    }
    bool flag = false;
    if(c[0][0]-c[0][1] == c[1][0]-c[1][1] && c[0][0]-c[0][1] == c[2][0]-c[2][1]) flag = true;
    if(flag && c[0][0]-c[0][2] == c[1][0]-c[1][2] && c[0][0]-c[0][2] == c[2][0]-c[2][2]) flag = true;
    else flag = false;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 1000010
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n,a[maxn];
char str[maxn];
int solve()
{
	int ans=0;
	for(int i=1;i<=n;i++)
		if(a[i]==1)
			ans^=((n-1)&(i-1))==i-1;
	if(ans==1)
		return 1;
	bool flg=true;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)
			return 0;
		else
		{
			flg&=a[i]==0;
			a[i]>>=1;
		}
	}
	if(flg)
		return 0;
	return solve()<<1;
}
int main()
{
	read(n);
	scanf("%s",str+1);
	for(int i=1;i<=n;i++)
		a[i]=str[i]-'1';
	printf("%d\n",solve());
    return 0;
}


Measured memory_bytes: 5120
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	string N;
	cin >> N;
	map<char, int>m;
	for (auto i : N)m[i]++;
	cout << m['2'] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 310
int ans=0x3f3f3f3f,n,m,a[N][N],cnt[N],flag[N],now[N];
inline char gc(){
    static char *S,*T,buf[1<<16];
    if(T==S){T=(S=buf)+fread(buf,1,1<<16,stdin);if(T==S) return EOF;}
    return *S++;
}
inline int read(){
    int x=0,f=1;char ch=gc();
    while(ch<'0' || ch>'9'){if(ch=='-') f=-1;ch=gc();}
    while('0'<=ch && ch<='9') x=x*10+ch-'0',ch=gc();
    return x*f;
}
int main(){
	n=read();m=read();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			a[i][j]=read();
	for(int i=1;i<=n;++i) now[i]=1;
	for(int i=1;i<=m;++i){
		for(int j=1;j<=m;++j) cnt[j]=0;
		for(int j=1;j<=n;++j){
			while(flag[a[j][now[j]]]) ++now[j];
			cnt[a[j][now[j]]]++;
		}
		int mx=0;
		for(int j=1;j<=m;++j) if(cnt[j]>=cnt[mx]) mx=j;
		flag[mx]=1;
		ans=min(ans,cnt[mx]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define LL long long 

using namespace std;

int main(void)
{
	LL n,m;
	scanf("%lld%lld",&n,&m);
	LL x=1;
	for(int i=0;i<m;i++)
	{
		x*=2ll;
	}
	LL sum=(1900*m)+(n-m)*100;
	printf("%lld",sum*x);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int n, m;
    cin >> n >> m;
    int ans = 0;
    int p[m];
    string s[m];
    rep(i, m) {
        cin >> p[i] >> s[i];
        p[i]--;
    }
    bool ac[n];
    fill(ac, ac + n, false);
    int pena[n];
    fill(pena, pena + n, 0);
    int num = 0;
    rep(i, m){
        if (s[i] == "AC" && !ac[p[i]]){
            ac[p[i]] = true;
            num += pena[p[i]];
            ans++;
        }else if (s[i] == "WA" && !ac[p[i]]){
            pena[p[i]]++;
        }
    }
    cout << ans << " " << num << endl;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MOD = 1e9 + 7;

void solve_test() {
	string s;
	cin >> s;
	int sum = 0;
	for (int i = 0; i < s.length(); i++) {
		sum += s[i] - '0';
		sum %= 9;
	}
	cout << (sum == 0 ? "Yes" : "No") << '\n';
}

int32_t main() {
	int T; 
	// cin >> T;
	T = 1;
	while (T--)
		solve_test();

	return 0;
}


Measured memory_bytes: 3664
n,m=map(int,input().split())
a=[None]*n
g=[[] for _ in range(n)]
for _ in range(m):
    l,r,d=map(int,input().split())
    g[l-1].append((r-1,d))
    g[r-1].append((l-1,-d))
for i in range(n):
    if a[i]==None:
        a[i]=0
        q=[i]
    while q:
        j=q.pop()
        for x,e in g[j]:
            if a[x]==None:
                a[x]=a[j]+e
                q.append(x)
            elif a[x]!=a[j]+e:
                print("No")
                exit()
                
print("Yes")

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

int main() {
  ll x;
  cin >> x;

  ll ans = 0;
  ll money = 100;
  while (money < x) {
    ll rishi = money / 100;
    money += rishi;
    ans++;
  }

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

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 998244353;

ll dp[310][100100]; // dp[i][j] 3色で塗り分ける時,a_iまでつかってRの和がjの場合の数
ll dp2[310][100100]; // dp[i][j]2色で塗り分ける時,a_iまでつかってRの和がjの場合の数

int main(void){
  int n;
  cin >> n;
  ll s = 0;
  fill(dp[0],dp[0] + 310 * 100100,0);
  dp[0][0] = 1;
  fill(dp2[0],dp2[0] + 310 * 100100,0);
  dp2[0][0] = 1;
  for(int i = 0;i < n;++i){
    ll a;
    cin >> a;
    s += a;
    for(int j = 0;j < 100100;++j){
      dp[i+1][j+a] += dp[i][j];
      dp[i+1][j+a] %= mod;
      dp2[i+1][j+a] += dp2[i][j];
      dp2[i+1][j+a] %= mod;
      dp[i+1][j] += dp[i][j]*2; 
      dp[i+1][j] %= mod;
      dp2[i+1][j] += dp2[i][j];
      dp2[i+1][j] %= mod;
    }
  }

  ll res = 1LL;
  for(int i = 0;i < n;++i){
    res *= 3;
    res %= mod;
  }

  ll cnt = 0;
  // 三角形が作れない場合の数
  for(int i = (s+1)/2;i <= s;++i){
    cnt += dp[n][i] * 3;
    cnt %= mod;
  }
  // 3色の場合の数にR=G=S/2とR=B=S/2が含まれているので引く
  if(s % 2 == 0){
    ll d = (dp2[n][s/2] * 3) % mod;
    cnt = (cnt + mod - d) % mod;
  }
  res = (res + mod - cnt) % mod;
  cout << res << endl;
}



Measured memory_bytes: 485120
import Foundation
var S = readLine()!
while true {
    if S.hasSuffix("dream") || S.hasSuffix("erase") {
        S = S.substringToIndex(S.endIndex.advancedBy(-5))
    } else if S.hasSuffix("eraser") {
        S = S.substringToIndex(S.endIndex.advancedBy(-6))
    } else if S.hasSuffix("dreamer") {
        S = S.substringToIndex(S.endIndex.advancedBy(-7))
    } else {
        break
    }
}
print(S=="" ?"YES":"NO")

Measured memory_bytes: 7268
#include <stdio.h>
 
int    main( void )
{
    int N, R, naibu;
    
    scanf("%d %d", &N, &R);
    
    if(N>=10){
        naibu = R;
    }else{
        naibu = R+(100*(10-N));
    }
    
    printf("%d", naibu);
    
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void){
 
int a[6];
int count[4] = {0,0,0,0};

scanf("%d %d",&a[0],&a[1]);
scanf("%d %d",&a[2],&a[3]);
scanf("%d %d",&a[4],&a[5]);

for(int j = 1; j <= 4 ;j++){
for(int i = 0;i < 6; i++){

if(a[i] ==j)
count[j-1] += 1;

}
}

int judge = 0;

for(int k = 0; k<=3 ; k++){
if(count[k] > 2)
judge = 1;
}

if(judge == 0)
printf("YES");
else
  printf("NO");
return 0;
 
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define FOR(i,m,n) for(int i=(m); i<(n); i++)
#define REP(i,n) for(int i=0; i<(n); i++)
#define RFOR(i,n,m) for(int i=(n);i>=(m); i--)
#define RREP(i,n) for(int i=(n-1); (i)>=0; i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = 100100100;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

mint dp0[2005][2005];
mint dp1[2005][2005];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> s(n+1), t(m+1);
    REP(i,n) cin >> s[i];
    REP(i,m) cin >> t[i];
    dp0[0][0] = 1;
    REP(i,n+1) REP(j,m+1)
    {
        dp0[i+1][j] += dp0[i][j];
        dp1[i][j] += dp0[i][j];
        dp1[i][j+1] += dp1[i][j];
        if(s[i] == t[j]) dp0[i+1][j+1] += dp1[i][j];
    }
    mint ans = dp1[n][m];
    cout << ans.x << endl;
    return 0;
}


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

long double solve(int n, long double d, long double x)
{
    if (n == 1)
        return (d + (d + x)) / 2;
    else
        return solve(n - 1, d * (2 * n + 2) / (2 * n) + x * 5 / (2 * n),
                            x * (2 * n + 4) / (2 * n)) +
               (d + d + x * (2 * n - 1)) / 2;
}

int main(void)
{
    int n; long double d, x;
    cin >> n >> d >> x;
    
    cout << setprecision(15) << fixed << solve(n, d, x);
    return 0;
}


Measured memory_bytes: 18944
#include <stdio.h>

int main(){
	
	char a[4];
	scanf("%s", &a);
	
	if(a[0] == 82 && (a[1] == 82 && a[2] == 82)){
		printf("3");
	}	
	
	else if(a[1] == 82 && (a[0] == 82 || a[2] == 82)){
		printf("2");
		}
	
	else if(a[0] == 82 || a[1] == 82 || a[2] == 82){
		printf("1");
	}
	
	else{
		printf("0");
	}
	
	return 0;
}

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

int main() {
	
	int a , b;
	
	cin>>a>>b;
	
	if(a <= 9 && b <= 9)
	cout<<a*b<<endl;
	
	else 
	cout<<"-1\n";
	
	return 0;
}

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

//マクロ
#define FOR(i, a, b) for(int i = (a); i < (b), i++)
#define REP(i, n) FOR(i, 0, n);
#define ALL(a) (a).begin(),(a).end()

// 0-1ナップザック問題
// dpの一番最初
// dp[i][j] : i番目(-1インデックス)までの品物の中から重さがｊを超えないように選んだ時の、価値の総和の最大値

// 制約 1 <= n <= 100
// weight[i], value[i]は整数
// 1 <= weight[i], value[i] <= 1000
// 1 <= W <= 10000


int main(){
    
    //入力
    int n, w; cin >> n >> w;
    vector<int> weight(n);
    vector<int> value(n);
    vector<vector<int> > dp(n, vector<int> (w + 1, 0));
    for(int i = 0; i < n; i++) cin >> value[i] >> weight[i];

    //dp
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= w; j++){
            if(i == 0){
                if(j >= weight[i]) dp[i][j] = dp[i][j - weight[i]] + value[i];
            }else{
                if(j >= weight[i]) dp[i][j] = max(dp[i][j - weight[i]] + value[i], max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]));
                else dp[i][j] = dp[i - 1][j];
            }
        }
    }

    /*for(int i = 0; i < n; i++){
        for(int j = 0; j <= w; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/

    cout << dp[n - 1][w] << endl;

    return 0;
}


Measured memory_bytes: 6836
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (n < m) swap(n, m);
  int ans = n;
  n--;
  if (n < m) swap(n, m);
  ans += n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->A[] = $a[0];
  }
}
if(($key->A[0]+$key->A[1]==$key->A[2]) ||
   ($key->A[0]==$key->A[1]+$key->A[2]) ||
   ($key->A[1]==$key->A[0]+$key->A[2]) ||
   ($key->A[1]+$key->A[0]==$key->A[2]) ){
   printf("Yes\n");
}
else {
   printf("No\n");
}


Measured memory_bytes: 3704
s = input()
n = len(s)
s2 = s[:(n-1)//2]
s3 = s[(n+3)//2-1:]
n2 = len(s2)
n3 = len(s3)
f = True

for i in range(n//2):
#    print(s[i])
#    print(s[n-(i+1)])
    if s[i] != s[n-(i+1)]:
        f = False
        break

for i in range(n2//2):
#    print(s[i])
#    print(s[n-(i+1)])
    if s2[i] != s2[n2-(i+1)]:
        f = False
        break

for i in range(n3//2):
#    print(s[i])
#    print(s[n-(i+1)])
    if s3[i] != s3[n3-(i+1)]:
        f = False
        break




if f:
    print("Yes")
else:
    print("No")








Measured memory_bytes: 3064
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint n, m, v, p;
	cin >> n >> m >> v >> p;

	vector<lint> a(n);
	for (lint i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	auto judge = [&](auto idx) {
		
		
		if (a[idx] + m < a[n - p]) {
			return false;
		}
		else {

			lint rem = v - (p + idx);
			lint sum = 0;
			lint A = a[idx] + m;

			for (lint i = idx + 1; i <= n - p; i++) {
				sum += max(A - a[i], 0LL);
			}
			DMP(idx, sum, rem, m);
			return sum >= rem * m;

		}

	};

	auto binary_search = [&](auto f) {

		lint ng = -1LL;
		lint ok = n - p + 1;

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

			if (f(mid)) ok = mid;
			else ng = mid;
		}

		return ok;
	};

	lint ans = binary_search(judge);
	cout << n - ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;

vector<pair<long long, long long> > prime_factorize(long long n) { //素因数分解、pairのfirstに底、secondに底の何乗
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    ll ans = 0;
    map<ll, ll> mp;
    rep(i, n){
        mp[i - a[i]]++;
    }
    rep(i, n){
        ans += mp[i + a[i]];
    }

    print(ans);


}


Measured memory_bytes: 27296
n=int(input())
#t=list(input())
#t.sort()
abc='abcdefghijklmnopqrstuvwxyz'
c=0
y=''
a=[0 for i in range(len(abc))]
'''
for i in range(len(abc)):
  a[i]=t.count(abc[i])
print(a,t)
'''
s=['' for i in range(n)]
for i in range(n):
  s[i]=input()

ans=''
for x in abc:
  z=100
  v=100
  for w in s:
    z=w.count(x)
    v=min(z,v)
  ans+=x*v
    
print(ans)

Measured memory_bytes: 3064
class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
      
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}
  
    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]
  
        if(way==0):
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
    def get_nums(self):   
        return {self.u,self.w,self.s,self.e,self.n,self.w,self.d}
 
def mk_dice():
    u,s,e,w,n,d=map(int,input().split())
    return Dice(u,w,s,e,n,d)
  
import random
q=int(input())
dice_col=[]
ans=True
for j in range(q):
    dice_b=mk_dice()
    for dice in dice_col:
        if(dice.get_nums()==dice_b.get_nums()):
            for i in range (1000):
                dice.rot(random.randint(0,2))
                if(dice.u==dice_b.u and dice.d==dice_b.d and dice.w==dice_b.w and dice.s==dice_b.s and dice.e==dice_b.e and dice.n==dice_b.n):
                    ans=False
        if ~ans:
            break
    dice_col.append(dice_b)
  
if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 8232
#include<iostream>
#include<string>
using namespace std;
int main(){
  int a,b,c,d,ans,x,y;
  cin>>a>>b>>c>>d;
  if(d<=a||b<=c)ans=0;
  else{
    if(a<=c)x=c;
    else x=a;
    if(b<=d)y=b;
    else y=d;
    ans=y-x;
  }
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 256
n = int(input())
vList = list(map(int, input().split()))
cList = list(map(int, input().split()))

ans = 0
for i in range(n):
    x = vList[i]
    y = cList[i]
    if (x - y) > 0:
        ans += (x - y)

print(ans)

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

int main(){
   int n;
   cin >> n;
   int umasa[n];
   for(int i = 0; i < n; i++){
       cin >> umasa[i];
   }
   int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            ans += umasa[i] * umasa[j]; 
        }
    }
    cout << ans << endl;
}

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

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

  int a, b;
  for(int i=0; i<s.size(); i++) {
    if(s[i] == 'A') {
      a = i;
      break;
    }
  }
  for(int i=s.size()-1; i>=0; i--) {
    if(s[i] == 'Z') {
      b = i;
      break;
    }
  }

  cout << b - a + 1 << endl;
}

Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int n = 100;
        /*
        long n = long.Parse(Console.ReadLine());
        long[] input = new long[5];
        for(int a = 0; a < 5; a++)
        {
            input[a]=long.Parse(Console.ReadLine());
        }
        */
        int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        Console.WriteLine(input[0]+input[1]==input[2]+input[3]?"Balanced": input[0] + input[1] > input[2] + input[3]?"Left":"Right");


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

Measured memory_bytes: 13268
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int X = tmp[0];
            int A = tmp[1];
            WriteLine(X < A ? 0 : 10);
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
const ll INF = 5e15;
const ll MOD = 1e9 + 7;
ll dp[200][11];
int main(){
    ll H, W, K;
    cin >> H >> W >> K;
    dp[0][0] = 1;
    for(ll i = 1; i <= H; i++){
        for(ll now = 0; now < W; now++){
            for(ll b = 0; b < (1 << (W - 1)); b++){
                if(b & (b << 1)) continue;
                if(b & (1 << now)) dp[i][now + 1] = (dp[i][now + 1] + dp[i - 1][now]) % MOD;
                else if(now && (b & (1 << (now - 1)))) dp[i][now - 1] = (dp[i][now - 1] + dp[i - 1][now]) % MOD;
                else dp[i][now] = (dp[i][now] + dp[i - 1][now]) % MOD;
            }
        }
    }
    cout << dp[H][K - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC131 E-Friendships
// 完全グラフで下限:0 (全部の頂点を結べば距離が1)
// 上限はスター:(N-1)(N-2)/2 

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  if(K > (N-1)*(N-2)/2){
    cout << -1 << endl;
    return 0;
  }
  cout << (N-1) + ((N-1)*(N-2)/2)-K << endl;

  REP(i, N-1){  // スターを作る
    cout << 1 << " " << i+2 << endl;
  }

  int idx = 2, cnt = 1;
  REP(i, ((N-1)*(N-2)/2)-K){  //　Kの数に合わせるため距離2を潰す
    if(idx+cnt > N){
      idx = idx+1;
      cnt = 1;
    }
    cout << idx << " " << idx+cnt << endl;
    cnt++;
  }
}

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

int main(void) {
	int X;
	cin >> X;
	if (400 <= X && X < 600) {
		cout << 8 << endl;
	}
	else if (600 <= X && X < 800) {
		cout << 7 << endl;
	}
	else if (800 <= X && X < 1000) {
		cout << 6 << endl;
	}
	else if (1000 <= X && X < 1200) {
		cout << 5 << endl;
	}
	else if (1200 <= X && X < 1400) {
		cout << 4 << endl;
	}
	else if (1400 <= X && X < 1600) {
		cout << 3 << endl;
	}
	else if (1600 <= X && X < 1800) {
		cout << 2 << endl;
	}
	else if (1800 <= X && X < 2000) {
		cout << 1 << endl;
	}
}

Measured memory_bytes: 3632
import CoreFoundation

let n=Int(readLine()!)!
var arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
 
var i = 0
var p = arr[0]
var ret : String = ""

if( i == 1 ) {
  print( "Yes" )
  exit(0)
}

for i in 0..<n - 1 {
  let d = arr[i] - arr[i + 1]
  //print( d )
  if(  d > 0 ) {
    ret = "No"
    break
  } else if( d < 0 ) {
    arr[i + 1] -= 1
  } 
}

//print( arr )

if( ret == "" ) {
  print( "Yes" )
} else {
  print( "No" )
}
  


Measured memory_bytes: 7700
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
   public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        TaskB task = new TaskB();
        task.solve(sc, out);
        out.flush();
        sc.close();
    }
    static class TaskB{
        void solve(Scanner sc, PrintWriter out){
            int N = nint(sc);
            long[] lLine = longLine(sc, N);

            long max=0;
            long min=Integer.MAX_VALUE;
            for (long l: lLine){
                if (l>=max){
                    max = l;
                }
                if (l<=min){
                    min = l;
                }
            }
            out.println(Math.abs(max - min));
        }
    }
    static int nint(Scanner sc){
        return Integer.parseInt(sc.next());
    }
    static long nlong(Scanner sc){
        return Long.parseLong(sc.next());
    }
    static double ndouble(Scanner sc){
        return Double.parseDouble(sc.next());
    }
    static float nfloat(Scanner sc){
        return Float.parseFloat(sc.next());
    }
    static String nstr(Scanner sc){
        return  String.valueOf(sc.next());
    }
    static long[] longLine(Scanner sc, int size){
        long[] lLine = new long[size];
        for (int i = 0; i < size; i++) {
            lLine[i] = nlong(sc);
        }
        return lLine;
    }
    static int[] intLine(Scanner sc, int size){
        int[] iLine = new int[size];
        for (int i = 0; i < size; i++) {
            iLine[i] = nint(sc);
        }
        return iLine;
    }
    static String[] strLine(Scanner sc, int size){
        String[] strLine = new String[size];
        for (int i = 0; i < size; i++) {
            strLine[i] = nstr(sc);
        }
        return strLine;
    }
}

Measured memory_bytes: 23764
// ini template jangan diedit
#include <bits/stdc++.h>
#include <math.h>
using namespace std;

#define REP(i,a,n) for(ll i=a;i<=n;i++)
#define ll long long

//int score(x)
//{
//	int array[1000];
//	
//}
//
//int faktorial(int n)
//{
//	int sum=0;
//	for (int i=n;i>0;i++)
//	{
//		sum = sum + i;
//	}
//	return sum;
//}

void solve()
{
	int N;
	cin >> N;
	if (N<10)
	{
		if (N == 0 || N==1 || N== 6 || N==8)
		cout << "pon";
		if ((N == 2 || N==4 || N== 5 || N==7 || N==9))
		cout << "hon";
		if (N== 3)
		cout << "bon";
	}
	if (N >=10 && N<100)
	{
		if (N%10 == 0 || N%10==1 || N%10== 6 || N%10==8)
		cout << "pon";
		if ((N%10 == 2 || N%10==4 || N%10== 5 || N%10==7 || N%10==9))
		cout << "hon";
		if (N%10== 3)
		cout << "bon";
	}
	if (N >=100 && N<1000)
	{
		if (N%10 == 0 || N%10==1 || N%10== 6 || N%10==8)
		{cout << "pon";}
		if ((N%10 == 2 || N%10==4 || N%10== 5 || N%10==7 || N%10==9))
		{cout << "hon";}
		if (N%10 == 3)
		{cout << "bon";}
	}
	
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	solve();
	return 0;
}
// Type Your Body of Code Here




Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define jh(x, y) x ^= y ^= x ^= y
#define loc(x, y) (x - 1) * m + y
#define rg register
#define inl inline
#define PI 3.141592654
typedef long long ll;
const int N = 6e5 + 5, INF = 0x3f3f3f3f, mod = 998244353;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r' && ~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
int fa[N], flag[N];
int findf(rg int x) { if (x == fa[x])return x; return fa[x] = findf(fa[x]); }

int main(void) {
	rg int n = fast_IO::read(), m = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)fa[i] = i;
	for (rg int i = 1; i <= m; ++i)fa[findf(fast_IO::read())] = findf(fast_IO::read()), fast_IO::read();
	rg int ans = 0;
	for (rg int i = 1; i <= n; ++i)if (!flag[findf(i)])++ans, flag[findf(i)] = true;
	fast_IO::write(ans);
	return 0;
}

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

int     get_g(int i, vector<int> &grp) {
        if (i==grp.at(i)) return i;
        return get_g(grp.at(i), grp);
}

int     main() {
        int N, M;
        cin >>N >>M;
        vector<int> p(N+1, 0);
        vector<int> grp(N+1, 0);
        for (int i=1; i<=N; i++) {
                cin >>p.at(i);
                grp.at(i)=i;
        }
        vector<int> x(M, 0);
        vector<int> y(M, 0);
        for (int i=0; i<M; i++)
                cin >>x.at(i) >>y.at(i);
        // Grouping
        for (int i=0; i<M; i++) {
                int xx=x.at(i);
                int yy=y.at(i);
                xx=get_g(xx, grp);
                yy=get_g(yy, grp);
                // Already in same group, do nothing
                if (xx==yy) continue;
                // Put into one group
                grp.at(max(xx, yy)) = get_g(min(xx, yy), grp);
        }
        int S=0;
        for (int i=1; i<=N; i++) {
                if (i==p.at(i))
                        S++;
                else if (get_g(i, grp)==get_g(p.at(i), grp))
                        S++;
        }
        cout <<S <<endl;
        return 0;
};

Measured memory_bytes: 1792
#include <algorithm>
#include <numeric>
#include <set>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int p[n]; for (int i = 0; i < n; i++) cin >> p[i];
    int q[n]; iota(q, q+n, 0);
    sort(q, q+n, [&](int i, int j) { return p[i] > p[j]; });
    multiset<int> s = {-1, -1, q[0], n, n};
    long long ans = 0;
    for (int i = 1; i < n; i++) {
        int j = q[i];
        auto it = s.lower_bound(j);
        long long a = *prev(prev(it)), b = *prev(it), c = *it, d = *next(it);
        ans += p[j] * ((b - a) * (c - j) + (j - b) * (d - c));
        s.insert(j);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
int main(){
    int n;
    int i, j, k;
    scanf("%d",&n);
    long long int count = 0;
    int x[n];
    for( i = 0 ; i < n ; i++ ){
    scanf("%d",&x[i]);
    }
    for( i = 0 ; i < n-1 ; i++ ){
       while( x[i] > x[i+1] ){
            x[i+1]++;
            count++;
       }
    }

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


Measured memory_bytes: 2428
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def get_inv_value(item):
    return -item[1]


def solv(N, S):
    d = {}
    for s in S:
        if s in d:
            d[s] += 1
        else:
            d[s] = 1
    lst = sorted(d.items(), key=get_inv_value)
    m = lst[0][1]
    lst = sorted([l[0] for l in lst if l[1] == m])
    return "\n".join(lst)


if __name__ == "__main__":

    N = int(input())
    S = [input() for _ in range(N)]

    ans = solv(N, S)

    print(ans)


Measured memory_bytes: 47116
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int main(){
	int N;
	cin >> N;
	int ans =N*(N+1)/2;
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 764
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main() {
  int x,y,dx,dy;
  cin >> x >> y >> dx >> dy;
  int disx = dx - x;
  int disy = dy - y;
  cout << dx - disy << " " << dy + disx << " " << x - disy << " " << y + disx << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        int n = Integer.parseInt(br.readLine());
 
        LinkedList<Integer> list = new LinkedList<Integer>();
 
        for (int i=0; i<n; i++) {
            String str = br.readLine();
 
            if (str.startsWith("insert")) {
                list.addFirst(Integer.parseInt(str.substring(str.indexOf(" ")+1)));
            }else if (str.equals("deleteFirst")) {
                list.pollFirst();
            }else if (str.equals("deleteLast")){
                list.pollLast();
            }else {
                list.remove((Integer)Integer.parseInt(str.substring(str.indexOf(" ")+1)));
            }
        }
 
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringBuilder sb = new StringBuilder();
        sb.append(list.poll());
        for (Integer s : list) {
            sb.append(" ");
            sb.append(s);
        }
        bw.write(sb.toString());
        bw.newLine();
        bw.close();
 
        br.close();
    }
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

// clang-format off
template<typename T>
bool chmax(T& a, const T& b) {if (a<b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a, const T& b) {if (a>b){a=b;return true;}return false;}
// clang-format on

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    int ran = 2 * d + 1;
    print((n + ran - 1) / ran);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N;cin >> N;
    vector<long long> a(N);
    long long ans = 0;
    for(int i=0;i<N;i++){
        long long a; cin >> a;
        while(a%2 == 0){a = a/2; ans++;}
    }
    cout << ans << endl;    
}




Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    int n;
    cin>>n;
    priority_queue<double> q;
    rep(i,n){
        double v;
        cin>>v;
        q.push(-v);
    }
    while(q.size()>1){
        double a=q.top();q.pop();
        double b=q.top();q.pop();
        q.push((a+b)/2);
    }
    cout<<-(q.top())<<endl;
    return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
// const double PI = acos(-1);
const double PI = 3.14159;

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

namespace Comb{
const int N = 10 + 5;
inline void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
 
inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return ((res % MOD) + MOD) % MOD;
}
 
ll f[N], invFact[N];
 
inline void prepare() {
    f[0] = 1;
    int n = 200000;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
    invFact[n] = inv(f[n]);
    for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
 
inline ll C(int n, int m) {
    if (!m) return 1;
    if (n == m) return 1;
    if (m > n) return 0;
    if (m < 0) return 0;
    return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}
}

int n;
ll buc[10];
bool vis[10];
ll ans = 0;

void dfs(int x, int cnt) {
    if (x == 5) {
        if (cnt == 3) {
            ll tmp = 1;
            for (int i = 0; i < 5; i++) if (vis[i]) tmp *= buc[i];
            if (tmp != 0) {
                ans += tmp;
            }
        }
        return;
    }

    dfs(x + 1, cnt);
    vis[x] = true;
    dfs(x + 1, cnt + 1);
    vis[x] = false;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        char s[50];
        scanf("%s", s);
        if (s[0] == 'M') {
            buc[0]++;
        } else if (s[0] == 'A') {
            buc[1]++;
        } else if (s[0] == 'R') {
            buc[2]++;
        } else if (s[0] == 'C') {
            buc[3]++;
        } else if (s[0] == 'H') {
            buc[4]++;
        }
    }
    dfs(0, 0);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mk make_pair
#define pb push_back
#define vi vector<int>
#define x first
#define y second
#define ms(a,b)  memset(a, b, sizeof(a))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define M 1000005
signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    int n,W,sum_val=0;
    cin>>n>>W;
    int w[n+1],v[n+1];
    for(int i=0;i<n;i++)cin>>w[i]>>v[i],sum_val+=v[i];
    int dp[n+1][sum_val+1];
    for(int i=0;i<=sum_val;i++)dp[0][i]=(int)1e15;
    for(int i=0;i<=n;i++)dp[i][0]=0;
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=sum_val;j++){
            if(j-v[i-1]>=0)
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i-1]] + w[i-1]);
            else
                dp[i][j]=dp[i-1][j];            
        }
    }
    int ans=INT_MIN;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=sum_val;j++){
            if(dp[i][j]<=W)ans=max(ans,j);
        }
    }
    cout<<ans;
    return 0;
}

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

using namespace std;

int n, m;
int a[105][105];
int f[105][105], color[105][105];
int dx[2] = {-1, 0}, dy[2] = {0, -1};
queue<pair<int, int>> q;

int BFS(int x, int y, int id)
{
    int Res = 1e9;
    q.push(make_pair(x, y));
    color[x][y] = id;
    while (!q.empty())
    {
        x = q.front().first;
        y = q.front().second;
        q.pop();
        for (int i = 0; i < 2; i++)
        {
            int xx = x + dx[i], yy = y + dy[i];
            if (xx > 0 && yy > 0 && a[xx][yy] == a[x][y] && color[xx][yy] != id)
            {
                color[xx][yy] = id;
                q.push(make_pair(xx, yy));
            }
            if (xx == 0  || yy == 0 || a[xx][yy] != a[x][y])
            {
                Res = min(Res, f[xx][yy]);
            }
        }
        
    }
    return Res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    char ch;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> ch;
            a[i][j] = (ch == '#' ? 1 : 0);
        }
    }
    for (int i = 2; i <= max(n,m); i++)
    {
        f[i][0] = 1e9;
        f[0][i] = 1e9;
    }
    f[1][0] = f[0][1] = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            f[i][j] = BFS(i, j, (i - 1) * m + j) + a[i][j];
        }
    }
    cout << f[n][m];
    return 0;
}

Measured memory_bytes: 384