akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void insert(int);
void inorderTreewwalk( Node );
int PreParse( Node );

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

Node *root;
Node *NIL;


void insert(int k){

  Node *x, *y, *z;
  z = (Node *)malloc(sizeof(Node));
  
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  y = NIL;
  x = root;
  
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
    z->parent = y;
  }
  
  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
  
}

void inorderTreewwalk( Node *x ){
  if(x != NIL){
    inorderTreewwalk( x->left );
    printf(" %d", x->key);
    inorderTreewwalk( x->right );
  }
}

int PreParse( Node *u ){
  if(u == NIL){
    return 0;
  }
  printf(" %d",u->key);
  PreParse(u->left);
  PreParse(u->right);
}


int main(){
  char meirei[50];
  int m,i,a,k;

  scanf("%d", &m);

  for(i = 0; i < m; i++){
    scanf("%s", meirei);
    if(strcmp(meirei, "insert") == 0){
      scanf("%d",&k);
      insert(k);
    }else{
      inorderTreewwalk( root );
      printf("\n");
  
      a = PreParse( root );
      printf("\n");
    }
      
  }

  return 0;
}

Measured memory_bytes: 24040
#include <stdio.h>
int main(){
	long long sum=0;
	int n,x;
	int cnt=0;
	int d[100];
	scanf("%d", &n);
	while(n--){
		scanf("%d", &x);
		d[cnt]=x;
		cnt++;
	}
	for(int i=cnt==0?cnt:cnt-1;i>=0;i--){
		for(int j=0;j<i;j++){
			sum += d[i]*d[j];
		}
	}
	printf("%lld", sum);
	return 0;
}

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

using namespace std;
#define int            long long
#define f(i,n)        for(int i=0;i<(n);++i)
#define fa(i,a,n)     for(int i=a;i<=(n);++i)
#define fd(i,a,n)     for(int i=a;i>=(n);--i)
#define tc 			  int t;cin>>t;f(testcase,t)
#define pii             pair<int,int>
void c_p_c() {

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

}

int32_t main() {

	c_p_c();
	int n;
	string s;
	cin >> s;
	n = s.length();
	int a[26] = {0};
	f(i, n) {
		a[s[i] - 'a']++;
	}
	bool flag = 1;
	f(i, 26) {
		if (a[i] % 2 != 0) {
			flag = 0;
			break;
		}
	}
	if (flag)
		cout << "Yes";
	else
		cout << "No";


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    rep(i, b)
    {
        rep(j, a)
        {
            cout << 0;
        }
        rep(j, w - a)
        {
            cout << 1;
        }
        cout << endl;
    }
    rep(i, h - b)
    {
        rep(j, a)
        {
            cout << 1;
        }
        rep(j, w - a)
        {
            cout << 0;
        }
        cout << endl;
    }
    return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
struct Edge { int from; int to; ll weight; };
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef pair<ll, int> P;

vector<ll> dist;
void dijkstra(const Graph &g, int src) {

	dist[src] = 0;
	//vector<int> prev(g.size());
	priority_queue<P, vector<P>, greater<P>> q;
	q.push({ 0, src });
	while (!q.empty()) {
		auto p = q.top(); q.pop();
		ll v = p.second;
		if (p.first > dist[v]) continue;
		for (int i = 0; i < g[v].size(); ++i) {
			Edge e = g[v][i];
			if (dist[e.to] > dist[v] + e.weight) {
				dist[e.to] = dist[v] + e.weight;
				q.push({ dist[e.to],e.to });
				//prev[e.to] = v;
			}
		}
	}

}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vi l(m), r(m), d(m);
	REP(i, m)cin >> l[i] >> r[i] >> d[i];
	Graph v(n);
	vi cnt(n, 0);
	REP(i, m) {
		l[i]--;
		r[i]--;
		v[l[i]].push_back(Edge{ l[i],r[i],d[i] });
		cnt[r[i]]++;
	}
	vi tmp;
	REP(i, n)if (cnt[i] == 0)tmp.push_back(i);

	dist.resize(n, INF*INF);
	REP(i, tmp.size()) {
		dijkstra(v, tmp[i]);
	}
	bool ans = true;
	REP(i, m) {
		if (dist[r[i]] - dist[l[i]] != d[i]) {
			ans = false;
		}
	}
	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 13424
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var a = (int) (Math.Ceiling((double) ab[0] * 12.5));
            var b = ab[1] * 10;
            for (var i = 0; i < 10; i++)
            {
                for (var j = 0; j <= (ab[0] % 2 == 0 ? 12 : 11); j++)
                {
                    if (a + j == b + i)
                    {
                        Console.WriteLine(a + j);
                        return;
                    }
                }
            }
            Console.WriteLine(-1);
        }
    }
}

Measured memory_bytes: 13268
// #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  vector<int> cnt(100010,0);
  for(int i=0; i<N; i++){
    if(a[i]){
      cnt[a[i]-1]++;
    }
    cnt[a[i]]++;
    cnt[a[i]+1]++;
  }
  int m = 0;
  for(int i=0; i<100010; i++){
    chmax(m,cnt[i]);
  }
  cout << m << endl;
  return 0;
}


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

int main() {
  string a,b,c;
  cin>>a>>b>>c;
  if(a.at(a.size()-1)==b.at(0) && b.at(b.size()-1)==c.at(0)) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = n%500;
		if(b > a) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int N = 200000;
const int M = 800000;
const int oo = 0x3f3f3f3f;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}
 
int n, m;
int st[N + 5], nxt[M + 5], to[M + 5], e = 1;
 
inline void addedge(int u, int v) {
    to[++ e] = v; 
    nxt[e] = st[u];
    st[u] = e; 
}
 
int R;
int A[N + 5], B[N + 5], C[N + 5], D[N + 5], X[N + 5];
 
bool vis[M + 5];
void dfs(int u) {
    for(int& i = st[u]; i; i = nxt[i]) {
        int v = to[i];
        if(vis[i]) continue;
        vis[i] = vis[i ^ 1] = true;
 
        if(abs(u - v) == n) {
            if(u < v) X[u] = 1; else X[v] = -1;
        }
 
        dfs(v);
    }
}
 
int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif
 
    n = read<int>();
    R = 2 * n + 1;
 
    for(int i = 1; i <= n; ++i) {
        A[i] = read<int>();
        if(A[i] > 0) {
            C[A[i]] ^= 1;
            addedge(i, A[i]);
            addedge(A[i], i);
        }else addedge(R, i), addedge(i, R);
    }
 
    for(int i = 1; i <= n; ++i) {
        B[i] = read<int>();
        if(B[i] > 0) {
            D[B[i]] ^= 1;
            addedge(i + n, B[i] + n);
            addedge(B[i] + n, i + n);
        }else addedge(R, i + n), addedge(i + n, R);
    }
 
    for(int i = 1; i <= n; ++i) if(C[i] ^ D[i]) return puts("IMPOSSIBLE"), 0;
    for(int i = 1; i <= n; ++i) if(!C[i])
        addedge(i, i + n), addedge(i + n, i);
    
    puts("POSSIBLE"); dfs(1);
    for(int i = 1; i <= n; ++i) printf("%d ", X[i]);
 
    return 0;
}


Measured memory_bytes: 19840
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;



int main() {
  ll a,b,c;
  cin >> a >> b >> c;
  ll A=a*a,B=b*b,C=c*c;
  if (c-a-b>0&&A+B+C-2*a*b-2*b*c-2*a*c>0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

main () {
    long long int a[200001];
    long long int xor = 0;
    int n;

    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        xor ^= a[i];
    }

    for(int i = 0; i < n; i++) {
        printf("%lld ", a[i] ^ xor);
    }

    puts(" ");
    return 0;
}


Measured memory_bytes: 4092
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int N,i,f=0;
  cin >> N;
  i=N;
  while(i>0){
    f+=(i%10);
    i/=10;
  }
  if(N%f==0)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
  int n, k;
  cin >> n >> k;

  int ret = 0;
  int mn = 0, mx = 0;
  for (int i = 0; i < k - 1; i++)
  {
    mn += i;
    mx += n - i;
  }

  for (int i = k; i <= n + 1; i++)
  {
    mn += (i - 1);
    mx += n - i + 1;
    ret = (ret + mx - mn + 1) % MOD;
  }
  cout << ret << endl;
}

Measured memory_bytes: 3480
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007

template <class T>
void printVec(vector<T> vec) {
    size_t len = vec.size();
    REP(i, len) {
        if (i) cout << " ";
        cout << vec[i];
    }
    cout << "\n";
}

template <class T>
T digitSum(T num) {
    ll sum = 0;
    while (num != 0) {
        sum += num%10;
        num /= 10;
    }
    return sum;
}


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

    // input
    int N, A, B;
    cin >> N;
    
    // int limit = (N%2 == 0) ? N/2: N/2+1;
    int limit = N/2;
    int min_sum = INT_MAX;
    for (int i = 1; i <= limit; ++i) {
        A = i;
        B = N - i;
        min_sum = min(min_sum, digitSum(A)+digitSum(B));
    }
    cout << min_sum << "\n";
    
    return 0;
}


Measured memory_bytes: 256
//This disgusting code is wriiten by Juruo D0zingbear
//Please don't hack me! 0v0 <3
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}

// cf IO: I64d
// atcoder IO: ｌｌｄ
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int Maxn=100005;
int a[Maxn];
int main(){
	int n;
	scanf("%d",&n);
	int cnt=0,ans=0;
	for (int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if (a[i]==i+1) cnt++;
		else{
			ans+=(cnt+1)/2;
			cnt=0;
		} 
	}
	ans+=(cnt+1)/2;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
N = int(input())
S = []
for i in range(N):
    S.append(list(input()))
    S[i].sort()
S.sort()

c = 0
oldi = 0
for i in range(N):
    if S[oldi] == S[i]:
        pass
    else:
        c += (i-oldi)*(i-oldi-1)//2
        oldi = i
c += (N-oldi)*(N-oldi-1)//2
print(c)


Measured memory_bytes: 24652
#include<stdio.h>
int main(void){
	int m,n,i,j,k,sx,sy;
	int mx[200],my[200];
	int nx[1000],ny[1000];

	while(1){
		scanf("%d",&m);
		if(!m)break;
		for(i=0;i<m;i++){
			scanf("%d%d",&mx[i],&my[i]);
		}
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d%d",&nx[i],&ny[i]);
		}
		for(i=0;i<n;i++){
			sx=nx[i]-mx[0];
			sy=ny[i]-my[0];
			for(j=1;j<m;j++){
				for(k=0;k<n;k++){
					if(mx[j]+sx==nx[k] && my[j]+sy==ny[k]){
						break;
					}
				}
				if(k==n)break;
			}
			if(j==m){
				printf("%d %d\n",sx,sy);
				break;
			}
		}
	}
	return 0;
}

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

int main(){
  string S;
  cin>>S;
  int count0=0,count1=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='0')
      count0++;
    if(S.at(i)=='1')
      count1++;
  }
  cout<<min(count0,count1)*2;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>

#define N 1000000

using namespace std;

int pn[N];

void Eratosthenes()
{
	for (int i=0; i<N; i++) {
		pn[i] = 1;
	}

	for (int i=2; i < (int)sqrt((double)N); i++) {
		if(pn[i]) {
			for (int j=0; i*(j+2)<N; j++) {
				pn[i*(j+2)] = 0;
			}
		}
	}
}

int main()
{
	int n;

	Eratosthenes();

	while (cin >> n)
	{
		int cont = 0;
		for (int i=2; i<=n; i++) {
			if(pn[i])	cont++;
		}

		cout << cont << endl;
	}

	return 0;
}

Measured memory_bytes: 5064
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
int main()
{
    IOS;
    //freopen("inputfile.txt","r",stdin);
    int num,n;cin>>num>>n;
    set <int> s;
    for(int i=0;i<n;i++)
    {
        int x;cin>>x;
        s.insert(x);
    }
    if(s.find(num)==s.end())
    {
        cout<<num<<endl;
        return 0;
    }
    int left = num-1;
    int right = num+1;
    while(1)
    {
        if(s.find(left)==s.end() && s.find(right)==s.end())
        {
            if(abs(num-left)==abs(num-right))
            {
                cout<<min(left,right);
            }
            else (abs(num-left)<abs(num-right))? cout<<left : cout<<right;
                cout<<endl;
            return 0;
        }
        else if(s.find(left)==s.end())right++;
        else if(s.find(right)==s.end())left--;
        else
        {
            left--;
            right++;
        }
    }
}


Measured memory_bytes: 3616
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        String answer = "YES";

        Set<Integer> map = new HashSet<>();
        for(int i = 0; i < N; i++){
            int a = sc.nextInt();
            if(map.contains(a)){
                answer = "NO";
                break;
            }
            map.add(a);
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 99100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

const int M = 1046527;
const char data[] = {'A', 'C', 'G', 'T'};
string H[M];

int getChar(char ch){
	for(int i = 0; i < 4; ++i){
		if(ch == data[i]) return i + 1;
	}
	return 0;
}

ll getKey(string str){
	ll sum = 0;
	ll p = 1;
	for(size_t i = 0; i < str.size(); ++i){
		sum += p * (getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){
	return key % M;
}

int h2(int key){
	return 1 + (key % (M - 1));
}

int find(string str){
	ll key = getKey(str);
	ll i = 0;
	while(1){
		ll h = (h1(key) + i * h2(key)) % M;
		if(H[h] == str){
			return 1;
		}
		else if(H[h].size() == 0){
			return 0;
		}
		++i;
	}
	return 0;
}

void insert(string str){
	ll key = getKey(str);
	ll i = 0;
	while(1){
		ll h = (h1(key) + i * h2(key)) % M;
		if(H[h] == str){
			return;
		}
		else if(H[h].size() == 0){
			H[h] = str;
			return;
		}
		++i;
	}
}

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

	int n;
	cin >> n;

	for(int i = 0; i < n; ++i){
		string s1, s2;
		cin >> s1 >> s2;

		if(s1 == "insert"){
			insert(s2);
		}
		else {
			cout << (find(s2) ? "yes" : "no") << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 24268
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  string s;
  cin>>s;
  int n = s.size();
  int mi = MOD;
  int ans = 0;
  rep(i,n) {
    if(i%2 == 0) {
      if(s[i] == '0') {
        ans++;
      }
    } else {
      if(s[i] == '1') {
        ans++;
      }
    }
  }
  mi = min(mi,ans);
  ans = 0;
  rep(i,n) {
    if(i%2 == 0) {
      if(s[i] == '1') {
        ans++;
      }
    } else {
      if(s[i] == '0') {
        ans++;
      }
    }
  }
  mi = min(mi,ans);
  cout << mi << endl;



  return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    int N;
    cin >> N;
    
    int ans = 0;
    for(int i=1; i<=N; i++){
        if(to_string(i).length() % 2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

class Dice
{
public:
	static const int SURFACE_NUM = 6;
	static const int DIR_NUM = 4;
	static const int ROUND_NUM = 4;
	enum DIR { N, W, S, E };
private:
	static const int rotate_table[DIR_NUM][ROUND_NUM];
	int surface_numbers[SURFACE_NUM];

public:
	Dice(int number[SURFACE_NUM])
	{
		for (int i = 0; i < SURFACE_NUM; i++)
			surface_numbers[i] = number[i];
	}
	void rotate(DIR direction)
	{
		int backup = surface_numbers[0];
		for (int i = 0; i < ROUND_NUM - 1; i++)
			surface_numbers[rotate_table[direction][i]] = surface_numbers[rotate_table[direction][i + 1]];
		surface_numbers[rotate_table[direction][ROUND_NUM - 1]] = backup;
	}
	int getTopNumber() { return surface_numbers[0]; }
};
const int Dice::rotate_table[DIR_NUM][ROUND_NUM]
{
	{ 0, 1, 5, 4 },
	{ 0, 2, 5, 3 },
	{ 0, 4, 5, 1 },
	{ 0, 3, 5, 2 }
};
int main()
{
	int nums[Dice::SURFACE_NUM] = { 0 };
	for (int i = 0; i < Dice::SURFACE_NUM; i++)
		cin >> nums[i];
	Dice dice(nums);
	string command;
	cin >> command;
	for (unsigned int i = 0; i < command.size(); i++) {
		switch (command.at(i))
		{
		case 'N':
			dice.rotate(Dice::N);
			break;
		case 'W':
			dice.rotate(Dice::W);
			break;
		case 'S':
			dice.rotate(Dice::S);
			break;
		case 'E':
			dice.rotate(Dice::E);
			break;
		}
	}
	cout << dice.getTopNumber() << endl;
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int main() {
 int N;
 cin>>N;
 int A;
 set<int>k;
 for(int i=0;i<N;i++){
     cin>>A;
    if(k.count(A)){k.erase(A);}
    else{k.insert(A);}
 }
 cout<<k.size()<<endl;

 return 0;}

Measured memory_bytes: 4864
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:u32 = read();
    let mut h:Vec<u32> = (0..n).map(|_| read()).collect();

    for i in 0..n-1 {
        let i = i as usize;
        //println!("{}, {}", h[i], h[i+1]);
        if h[i] < h[i+1] {
            h[i+1] -= 1;
            continue;
        }
        if h[i] == h[i+1] {
            continue;
        }

        if h[i] == h[i+1]-1 {
            h[i+1] -= 1;
        }
        else if h[i] > h[i+1]-1 {
            println!("No");
            return ();
        }
    }

    println!("Yes");
    
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;


/* macro */
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define sec second
#define fir first
#define pb push_back



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};



/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
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; }




/* main */



signed main(){

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

    
    print("ABC" + raw_input());

    

    
    




    
    



    
    

    







   




    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++) cout<<'x';
    cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int cards[51];

void cut_operation(int p, int c) {
  int tmp[51];
  int tmp2[51];
  for (int i = 0; i < p - 1; i++)  {
    tmp[i] = cards[i];
  }
  for (int i = 0; i < c; i++) {
    tmp2[i] = cards[p - 1 + i];
  }
  for (int i = 0; i < c; i++)  {
    cards[i] = tmp2[i];
  }
  for (int i = 0; i < p - 1; i++) {
    cards[i + c] = tmp[i];
  }
}

int main() {
  int n, r;
  while (true) {
    cin >> n >> r;
    if (n + r == 0) break;
    for (int i = 0; i < 51; i++) {
      cards[i] = n - i;
    }
    for (int i = 0; i < r; i++) {
      int p, c;
      cin >> p >> c;
      cut_operation(p, c);
    }
    cout << cards[0] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(X: int):
    if X >= 30:
        ret = YES
    else:
        ret = NO
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61260
#include<bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int N=1e5+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
using namespace std;
int n,val[N<<1];
int a[N],b[N];
int sum[N];
void add(int x){
	while(x<N*2){
		val[x]+=1;
		x+=x&-x;
	}
}
ll get(int x){
	ll ans=0;
	while(x>0){
		ans+=val[x];x-=x&-x;
	}
	return ans;
}
bool check(int x){
	memset(val,0,sizeof(val));
	sum[0]=0;
	for(int i=1;i<=n;++i){
		sum[i]=sum[i-1];
		if(a[i]>=x)sum[i]+=1;
		else sum[i]-=1;
	}
	ll tot=0;
	for(int i=0;i<=n;++i){
		tot+=get(sum[i]+N);
		add(sum[i]+N);
	}
	return tot>=1LL*n*(n+1)/4;
}
int main(){
	scanf("%d",&n);
	int r=1,l=1;
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);b[i]=a[i];
		r=max(a[i],r);
	}
	sort(b+1,b+1+n);
	int ans=0;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)){
			ans=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	cout<<ans<<endl;
	return 0;
}  

Measured memory_bytes: 2176
from collections import Counter
from math import log2

def find(x):
    f = 2**(int(log2(x))+1)-x
    if f <= x:
        return f
    return 0

n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
c = Counter(a)
ans = 0

for i in range(n):
    f = find(a[i])
    if f == a[i]:
        m = c[a[i]]//2
    else:
        m = min(c[a[i]],c[f])
    c[a[i]] -= m
    c[f] -= m
    ans += m
print(ans)

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

int main() {
	ios_base::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n), b(n);
	long long sum_a = 0, sum_b = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum_a += a[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
		sum_b += b[i];
	}	
	if (sum_a > sum_b) {
		return cout << "No" << '\n',0;
	}
	long long ops = sum_b - sum_a;
	long long need = 0;
	for (int i = 0; i < n; ++i) if (a[i] < b[i]) {
		int diff = b[i] - a[i];
		need += (diff + 1) / 2;
	}
	cout << (need <= ops ? "Yes" : "No");
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 100005, MAXM = 1003, mod = 1000000007 , MAXLog = 20;

int n, k;
vector<int> adj[MAXN];
int memo[MAXN];

int fact[MAXN];
int invfact[MAXN];
int mul(int a , int b , int m){
    return (1LL * (a % m) * (b % m)) % m;
}

int powMOD(int x , int n , int m = mod){
    if(!n)return 1;
    int ret = 1;
    if(n & 1)ret = mul(x , powMOD(x , n - 1 , m) , m);
    else{
        int y = powMOD(x , n / 2 , m);
        ret = mul(y , y , m);
    }
    return ret;
}


int nPr(int n , int r){
    if(r < 0 || r > n)return 0;
    return mul(fact[n] , invfact[n - r] , mod);
}


void pre() {
    fact[0] = invfact[0] = 1;
    for (int i = 1; i < MAXN; ++i)
        fact[i] = mul(i, fact[i - 1], mod);

    invfact[MAXN - 1] = powMOD(fact[MAXN - 1], mod - 2, mod);
    for (int i = MAXN - 2; ~i; --i)
        invfact[i] = mul(invfact[i + 1], i + 1, mod);
}


int solve(int u, int par) {
    if (u != 1 && adj[u].size() == 1) {
        return 1;
    }
    int &ret = memo[u];
    if (~ret)
        return ret;
    if (u == 1) {
        ret = nPr(k, adj[u].size() + 1);
        for (int v : adj[u]) {
            if (v == par)
                continue;
            ret = 1LL * ret * solve(v, u) % mod;
        }
    } else {
        ret = nPr(k - 2, adj[u].size() - 1);
        for (int v : adj[u]) {
            if (v == par)
                continue;
            ret = 1LL * ret * solve(v, u) % mod;
        }
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;


    int n, d;
    cin >> n >> d;
    vector<vector<int>> arr(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            int x;
            cin >> x;
            arr[i].push_back(x);
        }
    }

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int tmp = 0;
            for (int k = 0; k < d; ++k) {
                tmp += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k]);
            }
            int sq = sqrt(tmp);
            if (sq * sq == tmp)
                ++cnt;
        }
    }

    cout << cnt << '\n';


    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <cmath>
#include <list>

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

int main() {
    int k;
    cin >> k;

    string s;
    cin >> s;

    if(s.size() <= k) {
        cout << s << endl;
        return 0;
    }

    string new_s = s.erase(k);
    cout << new_s << "..." << endl;

    return 0;
}

Measured memory_bytes: 3100
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        
        Scanner scan = new Scanner(System.in);
 
         
        while(true){
         
        int a = scan.nextInt();
        String op = scan.next();
        int b = scan.nextInt();
     
 
         
        if(op.equals("+")){
        System.out.printf("%d\n",a+b);
            }
        if(op.equals("-")){
            System.out.printf("%d\n",a-b);
            }
        if(op.equals("*")){
            System.out.printf("%d\n",a*b);
            }
        if(op.equals("/")){
            System.out.printf("%d\n",a/b);
            }
        if(op.equals("?")){
            return;
        }
        }
    }   
}

Measured memory_bytes: 26112
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        System.out.println(a + b >= c ? "Yes" : "No");
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}

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

vector<int> make_table(const string &s) {
  int n = s.size();
  vector<int> ret(n + 1);
  ret[0] = -1;
  int j = -1;
  for (int i = 0; i < n; i++) {
    while (j >= 0 && s[i] != s[j]) j = ret[j];
    ret[i + 1] = ++j;
  }
  return ret;
}

vector<int> kmp(const string &s, const string &t) {
  vector<int> ta(t.size() + 1);
  {
    ta[0] = -1;
    int j = -1;
    for (int i = 0; i < t.size(); i++) {
      while (j >= 0 && t[i] != t[j]) j = ta[j];
      ta[i + 1] = ++j;
    }
  }
  vector<int> ret;
  int m = 0, i = 0, n = s.size();
  while (m + i < n) {
    if (t[i] == s[m + i]) {
      if (++i == (int) t.size()) {
        ret.push_back(m);
        m = m + i - ta[i];
        i = ta[i];
      }
    } else {
      m = m + i - ta[i];
      if (i > 0) i = ta[i];
    }
  }
  return ret;
}

struct UnionFind {
  vector<int> data;
  UnionFind(int n) {
    data.assign(n, -1);
  }
  int root(int k) {
    if (data[k] < 0) return k;
    return data[k] = root(data[k]);
  }
  bool unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
  int size(int k) {
    return -data[root(k)];
  }
};
 
int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
 
  string ss = s;
  while (ss.size() < t.size()) ss += s;
  ss += ss;
  auto zi = kmp(ss, t);
  auto uf = UnionFind(n);
  for (int i = 0; i < zi.size(); i++) {
    int x = zi[i];
    if (x >= n) continue;
    int y = (x + t.size()) % n;
    if (!uf.unite(x, y)) {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, uf.size(i) - 1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14508
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

struct AAA{
  int a,b,c,d;
};

int main(){
  int H,W;
  cin>> H >> W;
  vector<vector<i64>> a(H,vector<i64>(W));

  rep(i,0,H - 1){
    rep(j,0,W - 1) cin >> a[i][j];
  }
  vector<AAA> vec;
  rep(i,0,H - 1){
    rep(j,0,W - 2){
      if(a[i][j] % 2 == 1){
        vec.push_back({i,j,i,j + 1});
        a[i][j]--;
        a[i][j + 1]++;
      }
    }
    if(i < H - 1 && a[i][W - 1] % 2 == 1){
      vec.push_back({i,W - 1,i + 1,W - 1});
      a[i][W - 1]--;
      a[i + 1][W - 1]++;
    }
  }

  cout << vec.size() << endl;
  for(auto i : vec){
    cout << i.a + 1<< " " << i.b + 1 << " " << i.c + 1<< " " << i.d + 1 << endl;
  }
}


Measured memory_bytes: 6128
#include <iostream>
#include <stack>
#include <deque>
using namespace std;

struct p {int f; int s;};

int main()
{
	char c;
	int A = 0;
	deque<p> L;
	stack<int> s;

	for (int i = 0; cin >> c; i++)
		if (c == '\\')
			s.push(i);
		else if (c == '/' && !s.empty()) {
			int j = s.top(), a = i - j;
			s.pop();
			A += a;
			for (; !L.empty() && L.back().f > j; L.pop_back())
				a += L.back().s;
			L.push_back({j, a});
		}
	
	cout << A << endl << L.size();
	for (p x: L)
		cout << " " << x.s;
	cout << endl;
}


Measured memory_bytes: 3208
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int main()
{
	ll l,r,d;
	cin>>l>>r>>d;
	cout<<r/d - (l-1)/d;
	
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

const int MAX_P = 403030;
ll fact[MAX_P];

void init_fact(int n, int mod)
{
    fact[0] = 0;
    fact[1] = 1;
    for (ll i=2; i<=n; i++) {
        fact[i] = (fact[i-1] * i) % mod;
    }
}

int mod_fact(int n, int p, int& e)
{
    e = 0;
    if (n == 0) return 1;

    int res = mod_fact(n / p, p, e);
    e += n / p;

    if (n / p % 2 != 0) return res * (p - fact[n % p]) % p;
    return res * fact[n % p] % p;
}

int extgcd(int a, int b, int& x, int& y)
{
    int d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

int mod_inverse(int a, int m)
{
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

int mod_comb(int n, int k, int p)
{
    if (n < 0 || k < 0 || n < k) return 0;
    int e1, e2, e3;
    int a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n - k, p, e3);
    if (e1 > e2 + e3) return 0;
    return a1 * mod_inverse(a2 * a3 % p, p) % p;
}

int n;
int a[101010];
int pos[101010];
int leftPos, rightPos;

signed main()
{
    cin >> n;
    REP(i,n+1) {
        pos[i] = -1;
    }
    REP(i,n+1) {
        cin >> a[i];
        if (pos[a[i]] != -1) {
            leftPos = pos[a[i]];
            rightPos = i;
        }
        pos[a[i]] = i;
    }

    //cout << leftPos << endl << rightPos << endl;


    init_fact(303030, MOD);

    int t = leftPos + (n - rightPos);
    for (int k=1; k<=n+1; k++) {
        int b = mod_comb(n + 1, k, MOD);
        b += MOD;
        if (t >= k - 1) b -= mod_comb(t, k - 1, MOD);
        cout << b % MOD << endl;
    }
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;


int main(){
	//freopen("input.txt","r",stdin);
	int n,m,dem=0;
	cin>>n>>m;
	int f[100];
	memset(f,0,sizeof(f));
	for(int i=0; i<n; i++){
		int k;
		cin>>k;
		for(int j=0; j<k; j++){
			int tmp; cin>>tmp; f[tmp]++;
		}
	}
	for(int i=1; i<=m; i++){
		if(f[i]==n) dem++;
	}
	cout << dem;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
b = gets.chomp.split(" ").map(&:to_i)
a = []

a.push(b.first)

(0...n-2).each do |idx|
  b[idx] >= b[idx+1] ? a.push(b[idx+1]) : a.push(b[idx])
end

a.push(b.last)

puts a.inject(:+)

Measured memory_bytes: 1788
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

const long long int MAX_N = 100;
const long long int MAX_K = 1e5+10;
long long int dp[MAX_N][MAX_K];

const long long int MOD = 1e9+7;

int main(){
  
  // read problem
  long long int N, K, tmp;
  scanf("%lld%lld", &N, &K);
  
  std::vector<long long int> a;
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    a.push_back(tmp);
  }
  
  /*std::cerr << "N: " << N << "K: " << K << std::endl;
  std::cerr << "a: " << std::endl;
  for(long long int i = 0; i < N; i++){
    std::cerr << a[i] << " ";
  }std::cerr << std::endl;*/
  
  // solve problem
  // dp[i][j] = (The number of ways to distribute 0~j candies to i+1 children)
  /*std::vector<std::vector<long long int> > dp(N);
  for(long long int i = 0; i < N+1; i++){
    for(long long int j = 0; j <= K; j++){
      dp[i].push_back(0);
    }
  }*/
  
  // initialize dp
  for(long long int i = 0; i < N; i++){
    dp[i][0] = 1;
  }
  for(long long int j = 0; j <= K; j++){
    dp[0][j] = std::min(j+1, a[0]+1);
  }
  
  // fill dp in zenkashiki
  for(long long int i = 1; i < N; i++){
    for(long long int j = 1; j <= K; j++){
      if(j > a[i]){
        dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-a[i]-1] + MOD)%MOD;
      }
      else{ // if(j <= a[i])
        dp[i][j] = (dp[i][j-1] + dp[i-1][j])%MOD;
      }
    }
  }
  
  /*std::cerr << "The result of dp:" << std::endl;
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j <= K; j++){
      std::cerr << dp[i][j] << " ";
    }std::cerr << std::endl;
  }*/
  
  std::cerr << "Answer:" << std::endl;
  std::cout << (dp[N-1][K]-dp[N-1][K-1]+MOD)%MOD << std::endl;
  
  return 0;
}


Measured memory_bytes: 78336
#include<stdio.h>

int main(){
    int sum=0;
    char ch;
    while(true){
        while((ch=getchar())!='\n'){
            sum += ch - '0';
        }
        if(sum==0)
            break;
        else{
            printf("%d\n",sum);
            sum=0;
        }
    }
}


Measured memory_bytes: 2700
n=int(input())
s=input()
w_num=[0]*n
e_num=[0]*n
for i,c in enumerate(s[:-1]):
    w_num[i+1] = w_num[i] + (c=='W')
for i,c in enumerate(s[:0:-1]):
    e_num[n-2-i] = e_num[n-1-i] + (c=='E')
print(min(w + e for w,e in zip(w_num,e_num)))

Measured memory_bytes: 27260
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N;
	cin >> N;
	vector<int> C(N);
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}
	C.erase(unique(C.begin(), C.end()), C.end());
	vector<int> next(C.size(), -1);
	map<int, int> a;
	for (int i = C.size() - 1; i >= 0; i--) {
		try {
			next[i] = a.at(C[i]);
		}
		catch(...){
		}
		a[C[i]] = i;
	}
	vector<int> dp(C.size(), 0);
	dp[0] = 1;
	for (int i = 0; i < C.size(); i++) {
		if (next[i] != -1) {
			dp[next[i]] += dp[i];
			dp[next[i]] %= MOD;
		}
		dp[i + 1] += dp[i];
		dp[i + 1] %= MOD;
	}
	cout << dp.back() << endl;
}

Measured memory_bytes: 12032
// https://atcoder.jp/contests/abc106/tasks/abc106_d
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

// 二次元BIT
// source: https://iq.opengenus.org/2d-fenwick-tree/

// 2D fenwick tree for sub-matrix sum problem
class FenwickTree {
  private:
    // Matrix to store the tree
    std::vector<std::vector<int>> ft;

  public:
    // Function to get least significant bit
    int LSB(int x) { return x & (-x); }

    int query(int x, int y) {
        int sum = 0;
        for (int x_ = x; x_ > 0; x_ = x_ - LSB(x_)) {
            for (int y_ = y; y_ > 0; y_ = y_ - LSB(y_)) {
                sum = sum + ft[x_][y_];
            }
        }
        return sum;
    }

    int query(int x1, int y1, int x2, int y2) {
        return (query(x2, y2) - query(x1 - 1, y2) - query(x2, y1 - 1) +
                query(x1 - 1, y1 - 1));
    }

    void update(int x, int y, int value) {
        // also update matrix[x][y] if needed.
        for (int x_ = x; x_ < (int)ft.size(); x_ = x_ + LSB(x_)) {
            for (int y_ = y; y_ < (int)ft[0].size(); y_ = y_ + LSB(y_)) {
                ft[x_][y_] += value;
            }
        }
    }

    FenwickTree(std::vector<std::vector<int>> matrix) {
        // 引用元のコードはn, mが逆転してバグっているので修正
        int n = matrix.size();
        // matrix must not be empty.
        int m = matrix[0].size();
        // Initialize matrix ft
        ft.assign(n + 1, std::vector<int>(m + 1, 0));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j)
                update(i + 1, j + 1, matrix[i][j]);
        }
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> mat(N, vector<int>(N));
    FenwickTree ft(mat);
    REP(i, M) {
        int l, r;
        cin >> l >> r;
        ft.update(l, r, 1);
    }
    while (Q--) {
        int l, r;
        cin >> l >> r;
        cout << ft.query(l, l, r, r) << "\n";
    }

    return 0;
}


Measured memory_bytes: 6088
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

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


Measured memory_bytes: 3636
from bisect import bisect_left, bisect_right

N = int(input())
L = list(map(int, input().split()))

L.sort()

count = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L):
        if i < j:
            s = max(j+1, bisect_right(L, abs(l1-l2)))
            e = max(j+1, bisect_left(L, l1+l2))

            # print((i, j), (l1, l2), (abs(l1-l2), l1+l2), (s, e))
            count += max(0, e-s)
            # abs(l1-l2) <= m <= l1+l2

print(count)

Measured memory_bytes: 52056