akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int mod = 1e9+7;
const int maxn = 105;
const int maxk = 1e5+5;
int n,k, A[maxn]; LL dp[maxn][maxk];

LL dfs(const int i, const int j)
{
    if (j < 0)
        return 0;
    if (i == 0)
        return j <= A[i];
    if (j == 0)
        return 1;
    LL& ans = dp[i][j];
    if (-1 == ans) {
        ans = dfs(i,j-1) + dfs(i-1,j) - dfs(i-1,j-1-A[i]);
        ans %= mod;
    }
    ans += mod; ans %= mod;
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> n >> k) {
        memset(dp,-1,sizeof(dp));
        FOR(i,0,n) 
            cin >> A[i];
        cout << dfs(n-1,k) << endl;
    }
    return 0;
}


Measured memory_bytes: 88576
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pb push_back
#define mod 1000000007
#define inf 10000000007
#define ff first
#define ss second
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    IOS
    int n;
    cin>>n;
    while(1)
    {
        int flag = 1;
        int s = n%10,j = n;
        while(j>0)
        {
            if(j%10 != s)
            {
                flag =0;
                break;
            }
            j=j/10;
        }
        if(flag)
        {
            cout<<n;
            return 0;
        }
        n++;
    }
    return 0;

}


Measured memory_bytes: 256
N, M = map(int, input().split())

L = [ list(map(int, input().split())) for i in range(N)]
ans = 0
res = [0 for i in range(M)]

for l in L:
    for i in range(len(l)):
        if i != 0:
            res[l[i]-1] += 1
        
for i in range(M):
    if res[i] == N:
        ans += 1
        
print(ans) 

Measured memory_bytes: 3064
x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)

abc = []

for i in range(x):
    for j in range(y):
        if (i + 1) * (j + 1) > k:
            break
        for l in range(z):
            if (i + 1) * (j + 1) * (l + 1 ) > k:
                break
            abc.append(a[i] + b[j] + c[l])

abc.sort(reverse = True)

for i in range(k):
    print(abc[i])


Measured memory_bytes: 8708
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

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

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


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import bisect

    n, m, v, p = map(int, readline().split())
    a = list(map(int, readline().split()))

    a.sort()

    ng = -1
    ok = max(0, n - p)

    while abs(ng - ok) > 1:
        mid = (ng + ok) // 2
        cur = a[mid] + m
        c = n - bisect.bisect_right(a, cur)
        if c >= p:
            ng = mid
            continue
        rem = v - (mid + 1 + p - 1)
        score = m * rem
        for x in a[mid + 1:n - p + 1]:
            if x > cur:
                score -= m
            else:
                score -= cur - x
        if score <= 0:
            ok = mid
        else:
            ng = mid

    print(n - ok)


if __name__ == '__main__':
    main()


Measured memory_bytes: 96280
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
string s;
int k;
ll dp[105][2][4];
int a[105];
ll dfs(int pos,int lim,int cur){
    if(cur > k)return 0;
    if(pos == -1 && cur == k){
        return 1;
    }
    else if(pos == -1){
        return 0;
    }
    if(~dp[pos][lim][cur])return dp[pos][lim][cur];
    int ub = lim ? a[pos] : 9;
    ll ans = 0;
    for(int i = 0 ; i <= ub ; i ++){
        ans += dfs(pos-1,lim&&i==ub,cur+(i!=0));
    }
    return dp[pos][lim][cur] = ans;
}
ll solve(){
    cin >> s >> k;
    memset(dp, -1, sizeof(dp));
    int pos;
    pos = 0;
    while(s.size()){
        a[pos] = s.back() - '0';
        s.pop_back();
        pos++;
    }
    return dfs(pos-1,1,0);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << solve() << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    public void kami(){
            Scanner sc = new Scanner(System.in);
		
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		
		if(W >= x + r && H >= y + r){
			if(0 <= x - r && 0 <= y - r){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}else{
			System.out.println("No");
		}

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

}

Measured memory_bytes: 17360
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int main(){
    int h, w, n; cin >> h >> w >> n;
    vector<int> as(n);
    for(int i=0; i<n; ++i){
        cin >> as[i];
    }
    vector<vector<int>> ans(h, vector<int>(w));
    int ai=0;
    for(int hi=0; hi<h; ++hi){
        if(hi%2==0){
            for(int wi=0; wi<w; ++wi){
                ans[hi][wi]=ai+1;
                --as[ai];
                if(as[ai]==0) ++ai;
            }
        } else{
            for(int wi=w-1; wi>=0; --wi){
                ans[hi][wi]=ai+1;
                --as[ai];
                if(as[ai]==0) ++ai;
            }
        }
    }
    for(int hi=0; hi<h; ++hi){
        for(int wi=0; wi<w; ++wi){
            cout << ans[hi][wi] << (wi==w-1 ? '\n' : ' ');
        }
    }
    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------

signed main() {
	int n = read();
	cout << n * n * n << endl;
}

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

int main() {
  //宣言と入力.合計
  int N,x=0;
  cin >> N;
  vector<int>a(N);
  vector<int>b(N);
  vector<int>c(N);
  for(int i=0; i<N; i++)cin >> a[i];
  for(int i=0; i<N; i++){
    cin >> b[i];
    x += b[i];
  }
  for(int i=0; i<N; i++)cin >> c[i];
  //特例計算
  for(int i=0; i<N-1; i++){
    if(a[i+1]-a[i] == 1){
      x += c[a[i]-1];
    }
  }
  cout << x << endl;
}


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

int main() {
    int N;
    cin>>N;
    string S;
    cin>>S;
    map<int, int>head, tail;
    int headlist[10], taillist[10];
    for(int i=0;i<10;++i){
        headlist[i] = -1;
        taillist[i] = -1;
    }
    for(int i=0;i<N;++i){
        if(head[S[i]-'0']==0){
            head[S[i]-'0']++;
            headlist[S[i]-'0'] = i;
        }
    }
    for(int i=N-1;i>=0;--i){
        if(tail[S[i]-'0']==0){
            tail[S[i]-'0']++;
            taillist[S[i]-'0'] = i;
        }
    }
    vector<int> tmparr;
    int ans = 0;
    for(int i=0;i<10;++i){
        for(int j=0;j<10;++j){
            if(headlist[i]==-1 | taillist[j]==-1)continue;
            map<int, int> tmpmap;
            tmparr.clear();
            for(int k=headlist[i]+1;k<taillist[j];++k){
                if(tmpmap[S[k]]==0){
                    tmpmap[S[k]]++;
                    tmparr.push_back(S[k]);
                }
            }
            ans += tmparr.size();
        }
    }
    cout<<ans<<endl;
}


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

const int MAX_N = 2e5 + 10;
int n, q, ans;
int Arr[MAX_N];
int cnt[MAX_N];
int val[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> Arr[i];
		cnt[Arr[i]]++;
	}

	for (int i = 1; i <= n; i++)
		for (int j = max(0, i - cnt[i]); j < i; j++)
			val[j]++;

	for (int i = 0; i < n; i++)
		ans += !val[i];

	while (q--) {
		int x, y;
		cin >> x >> y;
		x--;

		if (0 <= Arr[x] - cnt[Arr[x]]) {
			if (val[Arr[x] - cnt[Arr[x]]] == 1)
				ans++;

			val[Arr[x] - cnt[Arr[x]]]--;
		}

		cnt[Arr[x]]--;

		Arr[x] = y;
		cnt[Arr[x]]++;
		if (0 <= Arr[x] - cnt[Arr[x]]) {
			if (val[Arr[x] - cnt[Arr[x]]] == 0)
				ans--;
			
			val[Arr[x] - cnt[Arr[x]]]++;
		}

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

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define ENDL cout << endl
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000000;

int a[12][12];

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> c(N);
    rep(i, N) {
        cin >> c[i];
        rep(j, M) { cin >> a[i][j]; }
    }

    int ans = INF;
    rep(s, 1 << N) {
        int cost = 0;
        vector<int> d(M);
        rep(i, N) {
            if (s >> i & 1) {
                cost += c[i];
                rep(j, M) { d[j] += a[i][j]; }
            }
        }
        bool ok = true;
        rep(j, M) if (d[j] < X) { ok = false; }
        if (ok && cost < ans) ans = cost;
    }
    if (ans == INF) {
        COUT(-1);
    } else {
        COUT(ans);
    }

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int R;

int main(){
    cin>>R;

    if(R<1200){
        cout<<"ABC"<<endl;
    }else if(R<2800){
        cout<<"ARC"<<endl;
    }else{
        cout<<"AGC"<<endl;
    }
}

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main (void) {
    ull K;
    char ans;
    string S;
    cin >> S;
    cin >> K;
    ull i = 0;
    while ( i < S.size() ){
        if (  S.at(i) == '1' ){
            i++;
            continue;
        }
        else{
            ans = S.at(i);
            break;
        }
    }
    if ( i + 1 > K ) ans = '1';
    cout << ans << 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++)
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9+7;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n+1);
    rep(i,m){
        int b;
        cin>>b;
        a[b]++;
    }
    vector<int> dat(n+1,0);
    dat[0]=1;
    for(int i=1;i<=n;i++){
        if(a[i]!=0) continue;
        if(i-1>=0) dat[i]+=dat[i-1];
        if(i-2>=0) dat[i]+=dat[i-2];
        dat[i]%=MOD;
    }
    cout<<dat[n];
}

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

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

void main2(){

}

int main(void){
  long long x;cin >> x;

  long long k = 1;
  while((k * x) % 360 != 0)k++;
  cout << k << '\n';
}


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

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

	if (S.size() <= K) {
		cout << S;
	}
	else {
		cout << S.substr(0, K) + "..." << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
using namespace std;
const int M = 1e9+7;
 
int gcd(int a, int b) {
    return b == 0? a:gcd(b, a%b);
}

int gcdt(int a, int b, int c) {
    return gcd(a, gcd(b, c));
}

long long qpow(long long a, long long p) {
    long long ret = 1;
    a = (a % M + M) % M;
    for (; p; p >>= 1) {
        if (p & 1) ret = (ret * a) % M;
        a = (a * a) % M;
    }
    return ret;
}

int main()
{
    int a, b, c;
    int n, k;
    cin >> n >> k;
    long long ans[200005] = {0}, sum = 0;
    for (int i = k; i >= 1; --i) {
        ans[i] = qpow((int)k/i, n);
        // cout << ans[i] <<' ' << k/i << ' ' << n << endl;
        for (int t = 2; t * i <= k; ++t) {
            ans[i] = (ans[i] + M - ans[t*i]) % M;
        }
        sum = (sum + (ans[i] * i) % M) % M;
    }
    // for (int i = 1; i <= k; ++i) {
    //     cout << ans[i] << ' ';
    // }
    // cout << endl;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 5156
n, a, b = map(int, input().split())

def solve(n, a, b):
    rev = a < b
    if rev:
        b, a = a, b

    if n < a+b-1:
        return [-1]

    if n > a * b:
        return [-1]

    surrogate_ans = []
    for i in range(b):
        nd = i+1
        reminder = n - a*i
        tail = b - nd
        batch_length = min(a, reminder-tail)
        # print("i: {}, reminder: {}, tail: {}, batch_length: {}".format(i, reminder, tail, batch_length))
        batch = range(n+1-a*i-batch_length, n+1-a*i)
        surrogate_ans += batch
        if batch_length != a:
            surrogate_ans += list(reversed(range(1, tail+1)))
        if len(surrogate_ans) == n:
            break

    if rev:
        return reversed(surrogate_ans)
    else:
        return surrogate_ans

print(" ".join(map(str, solve(n, a, b))))



Measured memory_bytes: 35424
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct Node{
  int key;
  struct Node *right;
  struct Node *left;
  struct Node *parent;
} node;

node *root,*nil;

node *find(node *u,int k){
  while(u!=nil && k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

void insert(int k){
  node *a=root;
  node *b=nil;
  node *c;
  c=(node *)malloc(sizeof(node));
  c->key=k;
  c->left=nil;
  c->right=nil;
  while(a!=nil){
    b=a;
    if(c->key<a->key){
      a=a->left;
    }else{
      a=a->right;
    }
  }
  c->parent=b;
  if(b==nil){
    root=c;
  }else{
    if(c->key<b->key){
      b->left=c;
    }else{
      b->right=c;
    }
  }
}

void inorder(node *u){
  if(u==nil)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(node *u){
  if(u==nil)return;
  printf(" %d",u->key );
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  char c[100];
  scanf("%d",&n);
  for(i= 0;i<n;i++){
    scanf("%s",c);
    if('f'==c[0]){
      scanf("%d",&x);
      struct Node *t = find(root,x);
      if(t != nil)printf("yes\n" );
      else printf("no\n");
    }else if(strcmp(c,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }else if(strcmp(c,"print")==0){
      inorder(root);
      printf("\n" );
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



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

int calc(int y,int m,int d){
  y--;
  m--;
  int ret = (20*5+19*5)*y+((y/3)*5);
  ret+=m*19+((m+1)/2);
  if (y%3==2)ret+=m/2;
  ret+=d;
  return ret;
}


int main(){
  int d[3];
  int n,mday;

  mday=calc(1000,1,1);
  //cout << mday;
  //mday=0;
  cin >> n;
  //sleep(1);
  for (int i=0;i<n;i++){
    cin >> d[0] >> d[1] >> d[2];
    cout << mday - calc(d[0],d[1],d[2]) << endl;
  }
  
  return 0;
}

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

using namespace std;

bool isHitachi(string S)
{
    string sub = S.substr(0, 2);
    string comparator = "hi";

    if (S.length() == 0)
        return true;
    else if (S.length() < 2)
        return false;
    else
    {
        if (sub.compare(comparator) == 0)
            return isHitachi(S.substr(2, S.length() - 2));
        else
            return false;
    }
}

int main()
{
    string S;

    cin >> S;

    isHitachi(S) ? cout << "Yes" : cout << "No";
    cout << "\n";

    return 0;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

const int MAXN = (int)1e5 + 10;
bool DP[MAXN];
string s;
VS examples = {"dream", "dreamer", "erase", "eraser"};

bool isPossible()
{
	CLEAR(DP, false);
	DP[0] = true;
	for(int i = 0; i <= sz(s); ++i)
	{
		if(DP[i] == 0) continue;
		for(string str : examples) {
			int n = sz(str);
			if(s.substr(i, n) == str)
				DP[i + n] = true;
		}
	}
	return DP[sz(s)];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> s;

	cout << (isPossible() ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 592
#include <map>
#include <iostream>
using namespace std;
int main() {
    int n, p; cin >> n >> p;
    string s; cin >> s;
    long long ans = 0;
    if (p == 2 || p == 5) {
        for (int i = 0; i < n; i++) {
            int c = s[i] - '0';
            if (c % p == 0) ans += i+1;
        }
    } else {
        int x = 0;
        map<int, int> mp;
        mp[0]++;
        for (int i = n-1, pw = 1; i >= 0; i--) {
            x = (x + pw * (s[i] - '0')) % p;
            mp[x]++;
            pw = pw * 10 % p;
        }
        for (auto x : mp) {
            long long c = x.second;
            ans += c * (c - 1) / 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,T;cin>>n>>T;
    int t,tp;
    long long ans=0;
    cin>>t;
    tp=t;
    for(int i=1;i<n;i++){
        cin>>t;
        ans+= min(T,t-tp);
        tp=t;
    }
    ans+=T;
    cout<<ans<<endl;
}

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

using namespace std;

short max(int a,int b){
  return a>b?a:b;
}

short nails[5001][5001];

int main(void){

  int n,m,a,b,x;
 
  cin >> n >> m;

  for(int i=0;i<m;i++){
    cin >> a >> b >> x;
    nails[a][b]=x+1;
  }

  for(int i=1;i<=n;i++)
    for(int j=1;j<=i;j++)
      nails[i][j]=max(nails[i][j],max(nails[i-1][j-1],nails[i-1][j])-1);      

  int cnt=0;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=i;j++)
      if(nails[i][j]>0)cnt++;
     
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 48856
// inputに入力データ全体が入る
function Main(input) {	
	var inputs = input.split(" ");
	
	var N = parseInt(inputs[0]);//sanka ninzu
	var R = parseInt(inputs[1]);//hyouji rating
  	
  	if(N <= 10)
  		R = R + 100*(10-N);
	//出力
	console.log(R);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
process.stdin.resume()
process.stdin.setEncoding("utf8")

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
})

const lines = []

reader.on("line", (line) => {
  lines.push(line)
})

reader.on("close", () => {
  const S = lines[1].split(" ").map(Number)
  const T = lines[3].split(" ").map(Number)
  let C = 0
  T.forEach(e => {
    binarySearch(S, e) && C++
  })
  console.log(C)
})

const binarySearch = (S, t) => {
  let left = 0
  let right = S.length
  while (left < right) {
    const mid = Math.floor((left + right) / 2)
    if (S[mid] === t) {
      return true
    } else if (t < S[mid]) {
      right = mid
    } else {
      left = mid + 1
    }
  }
  return false
}


Measured memory_bytes: 35468
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }







void solve(){
    ll n;
    string s;
    cin>>n>>s;
    ll cnt=0;
    rep(i,n){
        if(s[i]=='R') cnt++;
    }
    ll ans=0;
    rep(i,cnt){
        if(s[i]=='W') ans++;
    }
    cout<<ans<<endl;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    solve(); 


    return 0;
}


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

int main(){
	string s;
	cin >> s;
	string ans = "Yes";
	int n = s.length();
	for(int i=0; i<n; i+=2){
		if(s[i] == 'L') ans = "No";
	}
	for(int i=1; i<n; i+=2){
		if(s[i] =='R') ans = "No";
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
struct PrimeNumber
{
    //O(sqrt(n))
    //sosu hantei
    bool is_prime(long long n){
        for(long long i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return n != 1;
    }

    //O(sqrt(n))  isn't sorted
    //yakusu rekkyo
    vector<long long> divisor(long long n){
        vector<long long> res;
        for(long long i = 1; i * i <= n; i++){
            if(n % i == 0){
                res.push_back(i);
                if(i != n / i) res.push_back(n / i);
            }
        }
        return res;
    }

    //O(sqrt(n))
    //soinsu bunkai
    map<long long, long long> prime_factor(long long n){
        map<long long, long long> res;
        for(long long i = 2; i * i <= n; i++){
            while(n % i == 0){
                n /= i;
                res[i]++;
            }
        }
        if(n != 1) res[n] = 1;
        return res;
    }

    //O(n log log n)
    //n madeno sosu rekkyo
    vector<long long> eratosthenes(long long n){
        vector<long long> prime;
        vector<bool> is_prime(n + 1, true);
        long long p = 0;
        is_prime[0] = false; is_prime[1] = false;
        for(long long i = 2; i <= n; i++){
            if(is_prime[i]) prime.push_back(i);
            for(long long j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
        return prime;
    }
};

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, m; cin >> n >> m;
    ll ans = 1;
    PrimeNumber p;
    vector<ll> vec = p.divisor(m);
    rep(i, vec.size()){
        ll d = m / vec[i];
        if(d >= n) ans = max(ans, vec[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a[25],b[100],n,k,i; 
char s[100];
int main()
{
  gets(s);
for (i=0; i<strlen(s);i++)
  if (s[i]=='9') {cout<<"Yes"<<endl;return 0;}
cout<<"No"<<endl;  
 return 0;     
} 

Measured memory_bytes: 256
import math, string, fractions, heapq, re, array, bisect, sys, random, time, copy
import itertools as it
import collections as cl
import functools as ft

def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x) - 1, input().split()))
def LF(): return list(map(float, input().split()))
def LS(): return input().split()
def I(): return int(input())
def F(): return float(input())
def S(): return input()


n = I()
if n == 1:
    print('Hello World')
else:
    a = I()
    b = I()
    print(a + b)


Measured memory_bytes: 7704
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;


namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
        public static long C(long n,long k)
        {
            long bunsi = 1;
            
            for (long i = 1; i <= k; i++)
            {
                bunsi *= n--;
                bunsi /= i;
            }
            
            return bunsi ;
        }

        



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var s = ReadLine().ToCharArray();
            var ans = new char[1000000];
            for (int i = 500000; i < 500000+s.Length; i++)
            {
                ans[i] = s[i - 500000];
            }
            var q = Read();
            long count = 0;
            var left = 499999;
            var right = 500000 + s.Length;
            for (int i = 0; i < q; i++)
            {
                var input = ReadLine().Split();
                var x = long.Parse(input[0]);
                
                if (x == 1) count++;
                else
                {
                    var f = long.Parse(input[1]);
                    var c = input[2][0];
                    if (count % 2 == 0)
                    {
                        if (f == 1) ans[left--] = c;
                        else ans[right++] = c;
                    }
                    else
                    {
                        if(f == 2) ans[left--] = c;
                        else ans[right++] = c;
                    }
                }
            }
            if (count % 2 == 0)
            {
                for (int i = left+1; i < right; i++)
                {
                    Write(ans[i]);
                }
                WriteLine();
            }
            else
            {
                for (int i =right-1; i >left; i--)
                {
                    Write(ans[i]);
                }
                WriteLine();
            }



            Console.Out.Flush();
        }
    }
}




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

template<typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b%a, a);
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int n;
  cin >> n;
  vector<tuple<string, int, int>> s(n);
  rep(i, n) {
    string si;
    int p;
    cin >> si >> p;
    s[i] = tuple<string, int, int>(si, p, i+1);
  }
  sort(s.begin(), s.end(),
       [](const tuple<string, int, int>& a, const tuple<string, int, int>& b) {
         string a_s, b_s;
         int a_p, b_p;
         tie(a_s, a_p, ignore) = a;
         tie(b_s, b_p, ignore) = b;
         if (a_s != b_s) return a_s < b_s;
         return a_p > b_p;
       });
  rep(i, n) {
    string ss;
    int p, index;
    tie(ss, p, index) = s[i]; 
    cout << index << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

ll xor_sum(ll num) {
    if (num % 2 == 0) return (num / 2 % 2) ^ num;
    return (num + 1) / 2 % 2;
}

int main() {
    ll A, B;
    cin >> A >> B;
    cout << (xor_sum(A - 1) ^ xor_sum(B)) << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar,val) memset(ar, val, sizeof(ar))
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
  long a, b, c;
  cin >> a >> b >> c;
  if(a == b && b == c && a % 2 == 0)
    cout << -1 << endl;
  else{
    int k = 0;
    while(!(a % 2)  && !(b % 2) && !(c % 2)){
      k++;
      int ab = (a + b) / 2,
          bc = (b + c) / 2,
          ca = (c + a) / 2;
      c = ab; a = bc; b = ca;
    }
    cout << k << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// ProblemURL : https://atcoder.jp/contests/abc082/tasks/arc087_a
// ---------------------------------------------
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
	}

	cts := make([]int, 1e5+10)
	cost := 0
	for i := range as {
		if as[i] > n {
			cost++
		} else {
			cts[as[i]]++
		}
	}
	for i := range cts {
		if cts[i] < i {
			cost += cts[i]
		} else {
			cost += cts[i] - i
		}
	}
	fmt.Println(cost)
}


Measured memory_bytes: 5504
import math

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

if b <= 10**6:
    maxVal = 0

    for i in range(b):
        if i > n:
            break
        val = math.floor(a*i/b)-a*math.floor(i/b)
        if val > maxVal:
            maxVal = val

    print(maxVal)
elif n > b:
    print(a-1)
elif n == b:
    m = n - 1
    print(math.floor(a*m/b)-a*math.floor(m/b))
else:
    print(math.floor(a*n/b)-a*math.floor(n/b))


Measured memory_bytes: 9040
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n = 0, m = 0;
  cin >> n >> m;
  vector<int> cnt(n, 1);
  vector<bool> red(n, false);
  red.at(0) = true;
  int x = 0, y = 0;
  for (int i=0; i<m; i++) {
    cin >> x >> y;
    x--; y--;
    cnt.at(x)--; cnt.at(y)++;
    if (red.at(x)) {
      red.at(y) = true;
    }
    if (cnt.at(x) == 0) {
      red.at(x) = false;
    }
  }
  int ans = 0;
  for (int i=0; i<n; i++) {
    if (red.at(i)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const bool DBG = 1;

#define TRACE(x)    x
#define WATCH(x)    TRACE(cout << #x" = " << x << endl)
#define WATCHR(a,b) TRACE(for(auto it=a; it!=b;) cout<<*(it++)<<" ";cout<<endl)
#define WATCHC(V)   TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pair<int,int>> vpii;

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

	int n,m,k;
	cin >> n >> m >> k;

	for(int nx = 0; nx <= n; nx++) {
		for(int mx = 0; mx <= m; mx++) {
			int nbl = nx * (m - mx) + (n - nx) * mx;
			if(nbl == k) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int MIN=-1e9;
const int INF=1e9;
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
bool visited[100005];
const int max_N=1e5+10;
int N;
int A[100005];
int dp[100005];
int main(void)
{
  ll ans=0;
  cin >> N;
  for(int i=1;i<=N;i++)
    {
      cin >> A[i];
    }
  ll cardnum=0;
  for(int i=1;i<=N;i++)
    {
      if(A[i]==0)
	{
	  ans+=cardnum/2;
	  cardnum=0;
	}
      else if(i==N)
	{
	  cardnum+=A[i];
	  ans+=cardnum/2;
	}
      else
	{
	  cardnum+=A[i];
	}
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {

	/* --------------------------------------------------------------------
	   main
	 * -------------------------------------------------------------------- */
	public static void main(String args[]) throws Exception {

		// ----- input -----
		Input input = new Input(System.in);
		final Data line1 = input.readLine();
		input.close();

		// ----- main -----
		System.out.println(Math.min(line1.col[1] / line1.col[0], line1.col[2]));
	}

	/* --------------------------------------------------------------------
	 * inupt class
	 * -------------------------------------------------------------------- */
	static class Input {

		public BufferedReader input;

		public Input(InputStream inStream) {
			input = new BufferedReader(new InputStreamReader(inStream));
		}

		public void close() throws Exception {
			input.close();
		}

		public Data readLine() throws Exception {
			return new Data(input.readLine().split(" "));
		}
	}
	/* --------------------------------------------------------------------
	 * data class
	 * -------------------------------------------------------------------- */
	static class Data{
		public int[] col;
		public Data(String[] values) {
			col = new int[values.length];
			for(int i=0; i < values.length; i++) {
				col[i] = Integer.parseInt(values[i]);
			}
		}
	}
}

Measured memory_bytes: 21460
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int d = sc.nextInt();
    int x = sc.nextInt();
    int[] data = new int[10];

    for (int i = 0; i < 10; i++) {
      x = r * x - d;
      System.out.println(x);
    }
  }

}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int main(){
    int x;
    cin>>x;
    if(x>=30){
        cout<<"Yes"<<endl;
    }else {
        cout<<"No"<<endl;
    }
    return 0;
}

//a=97,z=122

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N;
    cin >> N;

    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }
    sort(all(d));

    cout << d[N/2] - d[(N-1)/2] << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 640
# Here your code !
my $txt = <STDIN>;
chomp $txt;
my @txts = split(//,$txt);

my $ans = 'CODEFESTIVAL2016';
my @anss = split(//,$ans);

my $i = 0;
my $count = 0;
foreach my $c (@txts) {
    if ($c ne $anss[$i]) {
        $count++;
    }
    $i++;
}

print $count, "\n";

Measured memory_bytes: 640
import std.algorithm;
import std.array;
import std.bigint;
import std.bitmanip;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

T[] readToArray(T)() {
    return readln.split.to!(T[]);
}

void readInto(T...)(ref T ts) {
    auto ss = readln.split;
    foreach(ref t; ts) {
        t = ss.front.to!(typeof(t));
        ss.popFront;
    }
}

// 冪乗をmod取りつつ計算
@nogc @safe pure ulong modPow(ulong a, ulong n, ulong m) {
    ulong r = 1;
    while (n > 0) {
        if(n % 2 != 0) r = r * a % m;
        a = a * a % m;
        n /= 2;
    }
    return r;
}

// フェルマーの小定理から乗法逆元を計算
// 定理の要請により法は素数
@nogc @safe pure ulong modInv(ulong a, ulong m) {
    return modPow(a, m-2, m);
}

// mod取りつつ順列を計算
@nogc @safe pure ulong modPerm(ulong n, ulong k, ulong m) {
    if (n < k) return 0;

    ulong r = 1;
    for (ulong i = n-k+1; i <= n; i++) {
        r *= i;
        r %= m;
    }
    return r;
}

// mod取りつつ順列を計算
@nogc @safe pure ulong modFact(ulong n, ulong m) {
    return modPerm(n, n, m);
}

// mod取りつつ組み合わせを計算
// modInvを使っているので法は素数
@nogc @safe pure ulong modComb(ulong n, ulong r, ulong m) {
    return modPerm(n, r, m)*modInv(modFact(r, m), m) % m;
}

immutable ulong MOD = 1000000007;

void main() {
    ulong n, d;
    readInto(n, d);
    long[][] xs;
    for (ulong i = 0; i < n; i++) {
        auto x = readToArray!(long);
        xs ~= x;
    }

    ulong cnt = 0;
    for(ulong i = 0; i < n - 1; i++) {
        for(ulong j = i + 1; j < n; j++) {
            ulong dist_sq = 0;
            for(ulong k = 0; k < d; k++) {
                const long dd = xs[i][k] - xs[j][k];
                dist_sq += dd*dd;
            }
            ulong dist = cast(ulong)sqrt(cast(real)dist_sq);
            if (dist*dist == dist_sq) cnt++;
        }
    }
    writeln(cnt);
}


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

using namespace std;

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, a;
	cin>>n;
	ll s[210000];
	s[0]=0;
	REP(i, n){
		cin>>a;
		s[i+1]=s[i]+a;
	}
	sort(s, s+n+1);
	ll ans=0;
	REP(i, n){
		ll cnt=1;
		while(i+1<n+1 && s[i]==s[i+1]){
			++i;
			++cnt;
		}
		if(cnt>=2) ans+=cnt*(cnt-1)/2;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1792
#include"bits/stdc++.h"
#define ll long long int
using namespace std;
int main()
{
/*  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout); 
  #endif*/
  int n,d; cin>>n>>d; long long f=1ll*(ll)d*d;
  ll x,y; int c=0; 
  for(int i=1;i<=n;i++)
  {
  	cin>>x>>y; 
  	if(x*x+y*y<=f){ c++;  }
  }
  cout<<c<<"\n"; return 0;   
}

Measured memory_bytes: 3632
#include <iostream>

int main()
{
  int N;
  std::cin >> N;
  int a[N];
  int b[10*10*10*10*10 + 1] = {0};
  for ( int i = 0; i < N; i++ ) std::cin >> a[i];

  for ( int i = 0; i < N; i++ ) {
    b[a[i]]++;
  }

  int max = 0;

  if ( N == 1 ) max = 1;
  if ( N == 2 && (a[0] == a[1] || a[0] == a[1] + 1 || a[0] == a[1] - 1) ) max = 2;
  for ( int i = 0; i < N-1; i++ ) {
    int n_X = b[i] + b[i+1] + b[i+2];
    if ( n_X > max ) max = n_X;
  }

  std::cout << max << std::endl;
  return 0;
}


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

using namespace std;

string N;
int d, ans;

int main()
{
    cin >> N;
    for (int i = 0 ; i < N.size() ; i ++) {
        ans += (N[i] - '0');
    }
    (ans % 9 == 0) ? cout << "Yes" : cout << "No";
    return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

class UnionFind{
public:
  //親の番号を格納する。親だった場合は-(その集合のサイズ)
  //vectorは可変長配列
  vector<int> Parent;

  //作る時はParentの値を全て-1にする
  //こうすると全てバラバラになる
  //コンストラクタ
  UnionFind(int N){
    Parent = vector<int>(N, -1);
  }

  //Aがどのグループに属しているか調べる
  int root(int A){
    if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }

  //関数の定義
  int size(int A){
    return -Parent[root(A)];//親を取ってきたい
  }

  //AとBをくっつける
  bool connect(int A, int B){
    //AとBを直接つなぐのではなく、roo(A)にroot(B)をくっつける
    A = root(A);
    B = root(B);
    if (A == B){
      //すでにくっついているからくっつけない
      return false;
    }

    //大きい方(A)に小さい方(B)をくっつけたい
    //代償が逆だったらひっくり返しちゃう。
    if (size(A) < size(B)) swap(A, B);

    //Aのサイズを更新する
    Parent[A] += Parent[B];
    Parent[B] = A;

    return true;
  }
};


int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  for (int i = 0; i < M; i++){
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }

  vector<long long> ans(M);
  ans[M - 1] = (long long)N * (N - 1) / 2;

  UnionFind Uni(N);

  for (int i = M -1; i >= 1; i--){

    ans[i - 1] = ans[i];
    //繋がってなかったのが繋がった時
    if (Uni.root(A[i]) != Uni.root(B[i])){
      ans[i -1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
    Uni.connect(A[i], B[i]);
    }
  }
  for (int i= 0; i < M; i++){
    cout << ans[i] << endl;
  };
}


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

void solve(long long N)
{
    int n = N % 10;
    if (n == 3)
        cout << "bon" << endl;
    else if (n == 0 || n == 1 || n == 6 || n == 8)
        cout << "pon" << endl;
    else
        cout << "hon" << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3760