akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MOD 1000000007
#define MAX 200200
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
struct Node{int x,v;}p[MAX];
int S[MAX],top;
bool operator<(Node a,Node b){return a.v<b.v;}
struct Line{int l,r;}a[MAX];
bool operator<(Line a,Line b){if(a.r!=b.r)return a.r<b.r;return a.l<b.l;}
int f[MAX],s[MAX],ans,n;
int main()
{
	n=read();
	for(int i=1;i<=n;++i)p[i].x=read(),p[i].v=read();
	sort(&p[1],&p[n+1]);
	for(int i=1;i<=n;++i)
	{
		if(!top||p[i].x>p[S[top]].x)S[++top]=i;
		int l=1,r=top,ret=i;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(p[S[mid]].x>=p[i].x)r=mid-1,ret=mid;
			else l=mid+1;
		}
		a[i].l=S[ret];
	}
	top=0;
	for(int i=n;i>=1;--i)
	{
		if(!top||p[i].x<p[S[top]].x)S[++top]=i;
		int l=1,r=top,ret=i;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(p[S[mid]].x<=p[i].x)r=mid-1,ret=mid;
			else l=mid+1;
		}
		a[i].r=S[ret];
	}
	sort(&a[1],&a[n+1]);
	for(int i=1,p=1;i<=n;++i)
	{
		while(a[p].r<a[i].l-1)++p;
		f[i]=(s[i-1]-s[p-1]+MOD)%MOD;
		if(a[i].l==1)f[i]=(f[i]+1)%MOD;
		if(a[i].r==n)ans=(ans+f[i])%MOD;
		s[i]=(s[i-1]+f[i])%MOD;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
 
void swap(long *A, long i, long j) {
  long tmp;
  tmp = A[i];
  A[i] = A[j];
  A[j] = tmp;
}
 
void maxHeapify(long *A, long i,long H) {
  long l,r,largest;
  l = 2*i;
  r = 2*i+1;
  if(l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest]) largest = r;
  if(largest != i) {
    swap(A,i,largest);
    maxHeapify(A,largest,H);
  }
}
 
void buildMaxHeap(long *A,long H) {
  long i;
  for(i = H/2; i > 0; i--) maxHeapify(A,i,H);
}
 
int main()
{
  int i,H;
  long *A;
  scanf("%d",&H);
  A = (long*)malloc(sizeof(long) * (H+1));
  for (i = 1; i <= H; i++) {
    scanf("%ld",A+i);
  }
  buildMaxHeap(A,H);
  for (i = 1; i <= H; i++) {
    printf(" %ld", A[i]);
  }
  printf("\n");
 
 
  return 0;
}

Measured memory_bytes: 4508
use std::io::*;

fn main() {
    let h = read();
    let w = read();

    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    for c in 0..h {
        let v = read_v();
        writeln!(out, "{}", v);
        writeln!(out, "{}", v);
    }
}

fn read_v() -> String {
    let s = stdin();
    let b = s.bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    b
}

fn read() -> usize {
    let s = stdin();
    let b = s.bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    b.parse().ok().unwrap()
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
int INF = 1e9+7;

int main() {
    vector <string> dict = {"dream", "dreamer", "erase", "eraser"};
    for (int j=0; j<4; j++) reverse(dict[j].begin(), dict[j].end());
    string S;
    cin >> S;
    reverse(S.begin(), S.end());

    int can = 1;
    for (int i=0; i<S.size(); i++) {
        can = 0;
        for (int j=0; j<4; j++) {
            string target=dict[j];
            if (S.substr(i,target.size()) == target) {can=1; i+=target.size()-1; break;}
        }
        if (can==0) break;
    }
    if (can==1) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
  int N;
  cin >> N;
  vector<int> C(N), V(N);
  for(int i = 0; i < N; i++){
    cin >> V.at(i);
  }
  for(int i = 0; i < N; i++){
    cin >> C.at(i);
  }
  vector<int> valu(N);
  for(int i = 0; i < N; i++){
    valu.at(i) = V.at(i) -C.at(i);
  }
  int result = 0;
  for(int i = 0; i < N; i++){
    if(valu.at(i) > 0) result += valu.at(i);  
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
#define ll long long int 
#define vi vector<int> 
#define vl vector<ll> 
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pair<ll,ll>>
#define umap unordered_map
#define uset unordered_set
#define all(c) c.begin(), c.end()
#define maxarr(A) *max_element(A, A+n) 
#define maxvec(v) *max_element(all(v)) 
#define minarr(A) *min_element(A, A+n);
#define minvec(v) *min_element(all(v));
#define lb(v,elem) lower_bound(all(v),elem)
#define ub(v,elem) upper_bound(all(v),elem)
#define pb push_back 
#define ff first 
#define ss second
#define sz(z) (int)z.size()
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define rev(i,a,b) for(int i=a; i>=b; i--)
#define debug(v) for(ll i=0; i<v.size(); i++) cout<<v[i]<<" "; cout<<endl;
#define debugn(v,n) for(ll i=0; i<n; i++) cout<<v[i]<<" "; cout<<endl;
#define deb(sum) cout<<"sum = "<<sum<<endl;
#define mod 1000000007
#define INF (ll)1e18
#define endl "\n"
#define pi 3.142857142857143

  
ll binpow(ll a, ll b) {
	if (b == 0)
		return 1;
	ll res = binpow(a, b / 2);
	if (b % 2)
		return res * res * a;
	else
		return res * res;
}

ll modexpo(ll x, ll y, ll p){  
	ll res = 1;  
	x = x % p; 
	if (x == 0) return 0;
	while (y > 0){   
		if (y & 1)  
			res = (res*x) % p;  
		y = y>>1;
		x = (x*x) % p;  
	}  
	return res;  
}

vector<int> getPrimes(int M){
	
	vi p(M,1);
	vector<int>prime;
	for(int i=2; i*i <= M; ++i){
		if(p[i]){
			for(int j = i*i; j<=M; j+=i) 
				p[j] = 0;
		}
	}
	rep(i,2,M) if(p[i]) prime.push_back(i);
	return prime;
}  


int main() { 
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL); 
  cout.tie(NULL); 
  //freopen("1.in","r",stdin);
  
  int t=1;
  //cin>>t;
  while(t--){
  	 rep(i,0,5){
  	 	int x;
  	 	cin>>x;
  	 	if(x==0){
  	 		cout<<i+1;
  	 		return 0;
  	 	}
  	 }
  } 
  return 0;
} 


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

int main(){
  string S;

  cin >> S;

  if(S == "Sunny"){
    cout << "Cloudy";
  }
  else if(S == "Cloudy"){
    cout << "Rainy";
  }
  else if(S == "Rainy"){
    cout << "Sunny";
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct List {
	struct List *next;
	int v;
} list;

typedef struct {
	int *par, *size, *height;
} UF_forest;

void UF_initialize(UF_forest *F, int n)
{
	int i;
	F->par = (int*)malloc(sizeof(int) * (n + 1));
	F->size = (int*)malloc(sizeof(int) * (n + 1));
	F->height = (int*)malloc(sizeof(int) * (n + 1));
	for (i = 1; i <= n; i++) {
		F->par[i] = i;
		F->size[i] = 1;
		F->height[i] = 1;
	}
}

void UF_merge(UF_forest *F, int u, int v)
{
	for (; F->par[u] != u; u = F->par[u]);
	for (; F->par[v] != v; v = F->par[v]);
	if (u == v) return;
	else if (F->height[u] > F->height[v]) {
		F->par[v] = u;
		F->size[u] += F->size[v];
	} else {
		F->par[u] = v;
		F->size[v] += F->size[u];
		if (F->height[u] == F->height[v]) F->height[v]++;
	}
}

int UF_size(UF_forest *F, int v)
{
	for (; F->par[v] != v; v = F->par[v]);
	return F->size[v];
}

int main()
{
	int i, N, K, L, u, w;
	list *adj[2][200001] = {}, e[2][200001];
	scanf("%d %d %d", &N, &K, &L);
	for (i = 0; i < K; i++) {
		scanf("%d %d", &u, &w);
		e[0][i*2].v = w;
		e[0][i*2+1].v = u;
		e[0][i*2].next = adj[0][u];
		e[0][i*2+1].next = adj[0][w];
		adj[0][u] = &(e[0][i*2]);
		adj[0][w] = &(e[0][i*2+1]);
	}
	for (i = 0; i < L; i++) {
		scanf("%d %d", &u, &w);
		e[1][i*2].v = w;
		e[1][i*2+1].v = u;
		e[1][i*2].next = adj[1][u];
		e[1][i*2+1].next = adj[1][w];
		adj[1][u] = &(e[1][i*2]);
		adj[1][w] = &(e[1][i*2+1]);
	}
	
	int flag[2][200001] = {}, q[200001], head, tail;
	list *p;
	for (i = 1; i <= N; i++) {
		if (flag[0][i] != 0) continue;
		flag[0][i] = i;
		q[0] = i;
		for (head = 0, tail = 1; head < tail; head++) {
			u = q[head];
			for (p = adj[0][u]; p != NULL; p = p->next) {
				w = p->v;
				if (flag[0][w] == 0) {
					flag[0][w] = flag[0][u];
					q[tail++] = w;
				}
			}
		}
	}
	
	int j, k, comp[200001] = {}, appear[200001];
	UF_forest F;
	UF_initialize(&F, N);
	for (i = 1; i <= N; i++) {
		if (flag[1][i] != 0) continue;
		flag[1][i] = 1;
		q[0] = i;
		comp[flag[0][i]] = i;
		appear[0] = flag[0][i];
		k = 1;
		for (head = 0, tail = 1; head < tail; head++) {
			u = q[head];
			for (p = adj[1][u]; p != NULL; p = p->next) {
				w = p->v;
				if (flag[1][w] == 0) {
					flag[1][w] = 1;
					q[tail++] = w;
					if (comp[flag[0][w]] == 0) {
						comp[flag[0][w]] = w;
						appear[k++] = flag[0][w];
					} else UF_merge(&F, w, comp[flag[0][w]]);
				}
			}
		}
		for (j = 0; j < k; j++) comp[appear[j]] = 0;
	}
	
	for (i = 1; i < N; i++) printf("%d ", UF_size(&F, i));
	printf("%d\n", UF_size(&F, N));
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 16084
#include<iostream>
#include<cstdio>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
using namespace std;

int main(){
    int n,m;cin>>n>>m;
    int ac=0,penalty=0;
    vector<bool> AC(n,false);
    vector<int> WA(n,0);
    
    int p;
    string s;
    for(int i=0;i<m;i++){
        cin>>p>>s;
        if(AC[p-1]) continue;

        if(s=="WA"){
            WA[p-1]++;
        }else if(s=="AC"){
            AC[p-1]=true;
            ac++;
            penalty+=WA[p-1];
        }
    }

    cout<<ac<<' '<<penalty<<endl;
}

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

int main(){
	int n;
  	cin >> n;
  	vector<int> a(n);
  	rep(i, n) cin >> a[i];
  	vector<int> ans(n);
  	rep(i, n) ans[a[i]-1] = i+1;
  	
  	rep(i, n) cout << ans[i] << endl;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se secondO
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
char c[15][15];

void dfs(int y,int x){
	c[y][x]='0';
	rep(i,0,4){
		int ny=y+dy[i];
		int nx=x+dx[i];
		if(0<=nx && nx<12 && 0<=ny && ny<12){
			if(c[ny][nx]=='1'){
				dfs(ny,nx);
			}
		}
	}
	return;
}


signed main(){
	while(1){
		rep(i,0,12){
			rep(j,0,12){
				cin>>c[i][j];
			}
		}
		if(cin.eof()) break;
		int ans=0;
		rep(i,0,12){
			rep(j,0,12){
				if(c[i][j]=='1'){
					ans++;
					dfs(i,j);
				}
			}
		}
		o(ans);
	}
}

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

int main() {
    string s;
    cin >> s;
    string t;
    cin >> t;
    int cnt = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
	int a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	sort(a, a + 3);
	if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
using namespace std;
int main(){   
   ll a,b,k;
   cin>>a>>b>>k;
   ll d=a-k;
   if(k>a){
      d=0;
      k=k-a;
      b=b-k;
      if(b<0) b=0;
   }
   cout<<d<<" "<<b;

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod=1e9+7;

int main(){
  int N,M;
  cin >>N >>M;
  vector<int>oks(N+1,true);
  for(int i=0;i<M;++i) {
    int a;cin>>a;
    oks[a]=false;
  }
  vector<long long int>dp(N+1);
  dp[0]=1;
  for(int now=0;now<N;++now){
    for(int next=now+1;next<=min(N,now+2);++next){
      if(oks[next]){
        dp[next]+=dp[now];
        dp[next]%=mod;
      }
    }
  }
  cout<<dp[N]<<endl;
  return 0;
}
  

Measured memory_bytes: 1536
import Foundation

func readInts() -> [Int]{
    readLine()!.split(separator: " ").map { Int($0)! }
}

func main(){
    let n = Int(readLine()!)!
    let aryA = readInts()
//    TLE発生
//    for i in 1...n {
//        print(aryA.filter { $0 == i }.count > 0 ? aryA.filter { $0 == i }.count: 0)
//    }
//    修正後
    var counter = [Int](repeating: 0, count: n)
    for i in aryA {
        counter[i-1] += 1
    }
    for i in 0...aryA.count{
        print(counter[i])
    }
}
main()


Measured memory_bytes: 23508
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#define maxn 2010
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int gcd(int x,int y)
{
    if(!y)  return x;
    return gcd(y,x%y);
}
int n;
int a[maxn];
int head[maxn],nxt[maxn*maxn],to[maxn*maxn],tot;
void add(int u,int v)
{
    tot++;
    nxt[tot]=head[u];
    head[u]=tot;
    to[tot]=v;
}
int book[maxn];
vector<int>e[maxn];
int deg[maxn];
void dfs(int x)
{
    book[x]=1;
    for(int i=head[x];i;i=nxt[i])
    {
        if(book[to[i]])  continue;
        e[x].push_back(to[i]);
        deg[to[i]]++;
        dfs(to[i]);
    }
}
priority_queue<int>q;
int ans[maxn],top;
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
      for(int j=n;j>=1;j--)
        if(i!=j&&gcd(a[i],a[j])>1)  add(i,j);
    for(int i=1;i<=n;i++)
    {
        if(book[i]) continue;
        dfs(i);
    }
    for(int i=1;i<=n;i++)
      if(!deg[i])  q.push(i);
    while(q.size())
    {
        int now=q.top();
        q.pop();
        ans[++top]=now;
        for(int i=0;i<e[now].size();i++)
        {
            deg[e[now][i]]--;
            if(!deg[e[now][i]])  q.push(e[now][i]);
        }
    }
    for(int i=1;i<=n;i++)  printf("%d ",a[ans[i]]);
    puts("");
    return 0;
}

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

bool match(const string& S, const string& T, int k) {
  if (k + T.size() <= S.size()){
    for (int i = 0; i < T.size(); i++) {
      if (S.at(i + k) != T.at(i) && S.at(i + k) != '?') {
        return false;
      }
    }
    return true;
  }
  return false;
}

void txt(string& S, const string& T, int k) {
  for (int i = 0; i < T.size(); i++) {
    S.at(i + k) = T.at(i);
  }
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '?') {
      S.at(i) = 'a';
    }
  }
}

int main() {
  string S, T;
  cin >> S >> T;
  bool found = false;
  string ans = S;
  replace(ans.begin(), ans.end(), '?', 'z');
  for (int is = 0; is < S.size(); is++) {
    if(match(S, T, is)){
      string tmpS = S;
      txt(tmpS, T, is);
      ans = min(ans, tmpS);
      found = true;
    }
  }
  if (found) {
    cout << ans << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }
}

Measured memory_bytes: 256
// C
 #ifndef _GLIBCXX_NO_ASSERT
 #include <cassert>
 #endif
 #include <cctype>
 #include <cerrno>
 #include <cfloat>
 #include <ciso646>
 #include <climits>
 #include <clocale>
 #include <cmath>
 #include <csetjmp>
 #include <csignal>
 #include <cstdarg>
 #include <cstddef>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <ctime> 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 #include <ccomplex>
 #include <cfenv>
 #include <cinttypes>
 #include <cstdbool>
 #include <cstdint>
 #include <ctgmath>
 #include <cwchar>
 #include <cwctype>
 #endif
 
 // C++
 #include <algorithm>
 #include <bitset>
 #include <complex>
 #include <deque>
 #include <exception>
 #include <fstream>
 #include <functional>
 #include <iomanip>
 #include <ios>
 #include <iosfwd>
 #include <iostream>
 #include <istream>
 #include <iterator>
 #include <limits>
 #include <list>
 #include <locale>
 #include <map>
 #include <memory>
 #include <new>
 #include <numeric>
 #include <ostream>
 #include <queue>
 #include <set>
 #include <sstream>
 #include <stack>
 #include <stdexcept>
 #include <streambuf>
 #include <string>
 #include <typeinfo>
 #include <utility>
 #include <valarray>
 #include <vector> 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 #include <array>
 #include <atomic>
 #include <chrono>
 #include <condition_variable>
 #include <forward_list>
 #include <future>
 #include <initializer_list>
 #include <mutex>
 #include <random>
 #include <ratio>
 #include <regex>
 #include <system_error>
 #include <thread>
 #include <tuple>
 #include <typeindex>
 #include <type_traits>
 #include <unordered_map>
 #include <unordered_set>
 #include "chminmax.h"
 #endif
using namespace std;

int main(){
    int n,x;
    while(1){
         cin >> n >> x;
         if(n==0 && x==0) break;
         int count=0;
         for(int i=1;i<n-1;++i){
             for(int j=i+1;j<n;++j){
                for(int k=j+1;k<n+1;++k){
                    if(i+j+k == x) count++;
                }
             }
         }
         cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
n, t = map(int,input().split())
A = list(map(int,input().split()))

dict = {"tmpmin":A[0],"maxvalue":0,"pairs":0}
for i in range(1,n):
    if A[i] < dict["tmpmin"]:
        dict["tmpmin"] = A[i]
    else:
        if A[i] - dict["tmpmin"] > dict["maxvalue"]:
            dict["maxvalue"] = A[i] - dict["tmpmin"]
            dict["pairs"] = 1
        elif A[i] - dict["tmpmin"] == dict["maxvalue"]:
            dict["pairs"] += 1
print(dict["pairs"])


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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    double t,x;
    cin >> t >> x;

    double s=t/x;

    printf("%.10lf\n",s);

    return 0;
}




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

int main()
{
    int N, K;
    cin >> N >> K;

    map<int, int> counts;
    int A;
    for (int i = 0; i < N; i++)
    {
        cin >> A;
        counts[A]++;
    }

    int num[counts.size()];
    int idx = 0;
    for (auto count = counts.begin(); count != counts.end(); count++)
    {
        num[idx] = count->second;
        idx++;
    }
    sort(num, num + counts.size());

    int ans = 0;
    for (int i = 0; i < (int)counts.size() - K; i++)
    {
        ans += num[i];
    }
    cout << ans << endl;
}


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

#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define inf LLONG_MAX

const int MAX = 500005;

struct Query
{
    int l, r, idx;
};

bool cmp(Query x, Query y)
{
    return x.r < y.r;
}

void update(int idx, int val, int bit[], int n)
{
    for (; idx <= n; idx += idx&-idx)
        bit[idx] += val;
}

int query(int idx, int bit[], int n)
{
    int sum = 0;
    for (; idx>0; idx-=idx&-idx)
        sum += bit[idx];
    return sum;
}

void answeringQueries(int arr[], int n, Query queries[], int q)
{
    int bit[n+1];
    memset(bit, 0, sizeof(bit));
    int last_visit[MAX];
    memset(last_visit, -1, sizeof(last_visit));
    int ans[q];
    int query_counter = 0;
    for (int i=0; i<n; i++)
    {
        if (last_visit[arr[i]] !=-1)
            update (last_visit[arr[i]] + 1, -1, bit, n);
        last_visit[arr[i]] = i;
        update(i + 1, 1, bit, n);
        while (query_counter < q && queries[query_counter].r == i)
        {
            ans[queries[query_counter].idx] =
                     query(queries[query_counter].r + 1, bit, n)-
                     query(queries[query_counter].l, bit, n);
            query_counter++;
        }
    }
    for (int i=0; i<q; i++)
        cout << ans[i] << endl;
}


main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n,i,q;
	cin>>n>>q;
	inp(a,n,0);
	Query queries[q];
	for(i=0;i<q;i++)
	{
		int ll,rr;
		cin>>ll>>rr;
		--ll,--rr;
		queries[i].l=ll,queries[i].r=rr;
		queries[i].idx=i;
	}
	sort(queries, queries+q, cmp);
	answeringQueries(a,n,queries,q);
	return 0;
}


Measured memory_bytes: 31096
import java.util.Scanner;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    String station = sc.nextLine();
    String station1 = station.substring(0,1);
    String station2 = station.substring(1,2);
    String station3 = station.substring(2, 3);

    if(station1.equals(station2) && station2.equals(station3)) {
    	System.out.println("No");
    } else {
    	System.out.println("Yes");
    }

  }
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> score(n,0), target(m);
  for(int i=0;i<m;i++){
    cin >> target[i];
    target[i]--;
  }

  for(int i=0;i<m;i++){
    int wrong = 0;

    for(int j=0;j<n;j++){
      int answer;
      cin >> answer;
      answer--;

      if(answer == target[i]) score[j]++;
      else wrong++;
    }
    score[target[i]] += wrong;
  }

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

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

#define N 3
#define N2 9
#define LIMIT 31

typedef struct { char b[N2+1]; } Board;
Board board;
int minstep;
typedef enum { R, U, L, D } Direction;
typedef struct { int pos; Direction dir; } Motion;

const Motion motion[N2][5] =
  {{{1,L},{3,U},{-1}}, {{0,R},{2,L},{4,U},{-1}}, {{1,R},{5,U},{-1}},
   {{0,D},{4,L},{6,U},{-1}}, {{1,D},{5,L},{7,U},{3,R},{-1}},
   {{2,D},{8,U},{4,R},{-1}},
   {{3,D},{7,L},{-1}}, {{4,D},{8,L},{6,R},{-1}}, {{5,D},{7,R},{-1}}  };

const int rr[4][5] = {{0,0,1,0,0},{0,0,0,1,0},{1,0,0,0,0},{0,1,0,0,0}};

int dd[N2][N2];
int dist(char *b)
{
  int i, n, d = 0;
  for (i=0; i<N2; i++) {
    n = b[i]-1;
    if (n<0)   continue;
    d += dd[n][i];
  }
  return d;
}

void search(int step, Motion prev)
{
  int i, d=0;
  d = dist(board.b);
  if (step+d>minstep) return;
  if (d==0) {
    printf("%d\n", step);
    exit(0);
  }
  Board board_bak = board;
  for (i=0; motion[prev.pos][i].pos>=0; i++) {
    Motion m = motion[prev.pos][i];
    if (rr[m.dir][prev.dir]) continue; //元に戻るのを防止
    board.b[prev.pos] = board.b[m.pos];
    board.b[m.pos] = 0;
    search(step+1, m);
    board = board_bak;
  }
}

int main()
{
  int i, j;
  for (i=0; i<N2; i++)
    for (j=0; j<N2; j++)
      dd[i][j] = abs(i%N-j%N) + abs(i/N-j/N);

  Motion m;
  m.dir = 4;
  Board ini_board;
  for (i=0; i<N2; i++) {
    fscanf(stdin, "%hd", (short int*)&ini_board.b[i]);
    if (ini_board.b[i]==0) m.pos = i;
  }
  for (minstep=dist(ini_board.b); minstep<=LIMIT; minstep++) {
    board = ini_board;
    search(0, m);
  }
  puts("no result.");
  return 0;
}



Measured memory_bytes: 2108
import math
import collections
import itertools

def resolve():

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

    cnt=B[0]
    for i in range(N-2):
        if(B[i]<=B[i+1]):
            cnt+=B[i]
        else:
            cnt+=B[i+1]
    cnt+=B[N-2]
    print(cnt)
    
resolve()


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

using namespace std;

int const size = 100006;
int arr[3][size];
long long int dp[3][size];

long long int getans(int n, int i, int ind){
	if(i == n) return 0;
	if(dp[ind][i] != -1) return dp[ind][i];
	long long int ans = 0;
	for(int x = 0;x<3;x++){
		if(x != ind)
		ans = max(ans, getans(n, i+1, x) + arr[ind][i]);
	}
	dp[ind][i] = ans;
	return ans;
}

int main(){
	int n, h, k;
	scanf("%d",&n);
	for(int x=0;x<=n;x++){
		for(int i=0;i<3;i++) dp[i][x] = -1;
	}
	for(int x=0;x<n;x++){
		for(int i=0;i<3;i++) scanf("%d",&arr[i][x]);
	}
	long long int ans = 0;
	for(int x=0;x<3;x++){
		ans = max(ans, getans(n,0, x));
	}
	cout<<ans;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++){
    char a;
    cin >> a;
    if (a == 'Y') {
      cout << "Four" << endl;
      break;
    }
    if (i == N - 1) {
      cout << "Three" << endl;
    }
  }
}

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

int main(){
    int h,w;
    cin >> h >> w;
    while(h!=0){
        int i,j;
        for (i=0;i<h;i++){
            for(j=0;j<w;j++){
    if(i==0||i==h-1||j==0||j==w-1)
        cout << "#";
        else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
        cin >> h >> w;
    }
    return 0;
}


Measured memory_bytes: 3072
#include<iostream>
using namespace std;
int calc(int,int);

int main(){
    int n,x;
    cin >> n >> x;

    while ( n != 0 || x !=0 ){
        cout << calc(n,x) << endl;
        cin >> n >> x;
    }
}

int calc(int n,int x){
    int ans = 0;

    for (int k=x/3+1;k<x && k<=n;k++){
        for (int j=(x-k)/2+1;j<x-k && j<k;j++){
            //cout << j << " " << k << endl;
            if(x-k-j > 0){
                //cout << "ans:" << x-k-j << " " << j << " " << k << endl;
                ans+=1;
            }
        }
    }
    return ans;
}


Measured memory_bytes: 3072
from collections import OrderedDict
n, m = map(int,input().split())
 
aclist = [0]*n
walist = [0]*n
wa = 0
for i in range(m):
  pp, s = input().split()
  p = int(pp) - 1
  if s == 'AC':
    if not aclist[p]:
      aclist[p] = 1
      wa += walist[p]
  else:
    if not aclist[p]:
      walist[p] += 1
"""
  pp, s = input().split()
  p = int(pp) - 1
  if s == 'AC' and not aclist[p]:
    aclist[p] = 1
    ac += 1
    wa += walist[p]
  else:
    walist[p] += 1
"""
print(sum(aclist), wa)

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;


bool ok(vector<int> xs, int start_x, int target_x) {
    set<int> s;
    s.insert(start_x);

    FOE(d, xs) {
        set<int> next_s;
        FOE(x, s) {
            next_s.insert(x + d);
            next_s.insert(x - d);
        }
        s = next_s;
    }

    return s.find(target_x) != s.end();
}

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

    string S;
    cin >> S;
    int x, y;
    cin >> x >> y;

    string T;
    int start_x = 0;
    FOE(s, S) {
        if (s == 'T') {
            break;
        }
        start_x++;
    }

    int d = 0;
    int total = 0;
    vector<int> ys, xs;
    S += "T";
    FOR(i, start_x, S.size()) {
        char s = S[i];
        if (s == 'T') {
            if (d == 0 and total != 0) {
                xs.emplace_back(total);
            }
            if (d == 1 and total != 0) {
                ys.emplace_back(total);
            }
            total = 0;
            d = 1 - d;
        }
        else {
            total++;
        }
    }

    if (ok(xs, start_x, x) and ok(ys, 0, y)) {
        print(Yes);
    }
    else {
        print(No);
    }


    return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline


n, q = map(int, input().split())
events = []
for _ in range(n):
    start, end, pos = map(int, input().split())
    events.append([start - pos, 1, pos])
    events.append([end - pos, 0, pos])

events.sort()

departures = [int(input()) for _ in range(q)]

idx = 0
mini = 10**10
mini_check = False
candidates = set()
time, is_under_construction, pos = events[idx]
for departure in departures:
    while time <= departure:
        if is_under_construction:
            candidates.add(pos)
            if pos < mini:
                mini = pos
                mini_check = True
        else:
            candidates.remove(pos)
            if pos == mini:
                mini_check = False
        idx += 1
        if idx == 2 * n:
            time = float('INF')
            break
        time, is_under_construction, pos = events[idx]

    if not candidates:
        print(-1)
    else:
        if not mini_check:
            mini = min(candidates)
            mini_check = True
        print(mini)


Measured memory_bytes: 84056
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    set<int> si;
    si.insert(1);
    si.insert(2);
    si.insert(3);
    si.erase(A);
    si.erase(B);
    cout << *si.begin() << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int mid;
	if(m&1) mid=(m*2+1)/2;
	else mid=(m*2+1)/2+1;
	int cnt=1;
	for(int i=1;cnt<=m;cnt++,i++){
		if(cnt<=mid/2) printf("%d %d\n",i,mid-i+1);
		if(cnt==mid/2+1) i=mid+1;
		if(cnt>mid/2 ) printf("%d %d\n",i,mid+1+m*2+1-i); 
	}
}

Measured memory_bytes: 3848
import java.io.IOException
import java.io.InputStream
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val (a, b) = sc.nextInts(2)
    println(if (b % a == 0) a + b else b - a)
}

class Scanner(private val `in`: InputStream) {
    private val buffer = ByteArray(1024)
    private var ptr = 0
    private var buflen = 0

    companion object {
        private fun isPrintableChar(b: Byte): Boolean = b in 33..126
        private fun isNumericChar(b: Byte): Boolean = b in 48..57
        private fun digit(b: Byte): Int = b - 48
    }

    fun hasNextByte(): Boolean {
        if (ptr < buflen) return true
        ptr = 0
        try {
            buflen = `in`.read(buffer)
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return 0 < buflen
    }

    private fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        return buildString {
            var b = readByte()
            while (isPrintableChar(b)) {
                appendCodePoint(b.toInt())
                b = readByte()
            }
        }
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        val minus = b.toChar() == '-'
        if (minus) b = readByte()
        if (!isNumericChar(b)) throw NumberFormatException()
        do {
            n *= 10
            n += digit(b)
            b = readByte()
        } while (isNumericChar(b))
        return if (minus) -n else n
    }

    fun nextInts(n: Int): Array<Int> = Array(n) { nextInt() }

    fun nextIntArray(n: Int): IntArray = IntArray(n) { nextInt() }

    fun nextIntArrays(n: Int, m: Int): Array<IntArray> {
        val arrays = Array(m) { IntArray(n) }
        repeat(n) { i -> repeat(m) { j -> arrays[j][i] = nextInt() } }
        return arrays
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        val minus = b.toChar() == '-'
        if (minus) b = readByte()
        if (!isNumericChar(b)) throw NumberFormatException()
        do {
            n *= 10
            n += digit(b)
            b = readByte()
        } while (isNumericChar(b))
        return if (minus) -n else n
    }

    fun nextLongs(n: Int): Array<Long> = Array(n) { nextLong() }

    fun nextLongArray(n: Int): LongArray = LongArray(n) { nextLong() }

    fun nextLongArrays(n: Int, m: Int): Array<LongArray> {
        val arrays = Array(m) { LongArray(n) }
        repeat(n) { i -> repeat(m) { j -> arrays[j][i] = nextLong() } }
        return arrays
    }

}

Measured memory_bytes: 31128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AGC017
{
    public class B
    {
        private void Run()
        {
            var input = Console.ReadLine().Trim().Split();
            var N = int.Parse(input[0]);
            var A = long.Parse(input[1]);
            var B = long.Parse(input[2]);
            var C = long.Parse(input[3]);
            var D = long.Parse(input[4]);

            B = Math.Abs(B - A);
            A = 0;
            bool can = false;
            N -= 1;
            for (int i = 0; i <= N; i++)
            {
                var lower = C * i - D * (N - i);
                var upper = D * i - C * (N - i);
                if (lower <= B && B <= upper)
                {
                    can = true;
                }
            }
            Console.WriteLine(can ? "YES" : "NO");
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new B().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }
    }
}


Measured memory_bytes: 13140
n = int(input())
arr = list(map(int, input().split()))

money = 1000


for i in range(1, n):
  p_now = arr[i]
  p_before = arr[i-1]
  if p_before < p_now:
    stock = money // p_before
    money += stock*(p_now - p_before)

print(money)


Measured memory_bytes: 9176
# 2019-11-12 01:01:32(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, *h = [int(x) for x in sys.stdin.read().split()]
    if n == 1:
        print(h[0])
        sys.exit()

    mountain = [0]
    valley = [0]
    flat = 0
    i = 0
    while True:
        if h[i] == h[i+1]:
            if i < n-2:
                i += 1
                continue
            else:
                print(h[i])
                sys.exit()
        elif h[i] < h[i+1]:
            break
        else:
            mountain.append(h[0])
            break
    i = -1
    while True:
        if h[i-1] == h[i]:
            i -= 1
            continue
        elif h[i-1] > h[i]:
            break
        else:
            mountain.append(h[-1])
            break

    for i in range(1, n-1):
        if flat == 0:
            if h[i-1] < h[i] > h[i+1]:
                mountain.append(h[i])
            elif h[i-1] > h[i] < h[i+1]:
                valley.append(h[i])
            elif h[i-1] < h[i] == h[i+1]:
                flat = 1
            elif h[i-1] > h[i] == h[i+1]:
                flat = -1
        else:
            if flat == 1:
                if h[i] > h[i+1]:
                    mountain.append(h[i])
                    flat = 0
                elif h[i] < h[i+1]:
                    flat = 0
                else:
                    continue
            elif flat == -1:
                if h[i] < h[i+1]:
                    valley.append(h[i])
                    flat = 0
                elif h[i] > h[i+1]:
                    flat = 0
                else:
                    continue

    
    ans = sum(mountain) - sum(valley)
    print(ans)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
n = int(input())
p = list(map(int,input().split()))
counter = 0
i = 0
while i <= n-1:
	if i <= n-2 and (i+1) == p[i] and (i+2) == p[i+1]:
		counter += 1
		i += 2
	elif (i+1) == p[i]:
		counter += 1
		i += 1
	else:
		i += 1
print(counter)

Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int w,n;
	int a,b;
	int i;
	char ch;
	int m[31];
	cin>>w>>n;
	for(i=1;i<=w;i++)	m[i]=i;
	for(i=0;i<n;i++){
		cin>>a>>ch>>b;
		swap(m[a],m[b]);
	}
	for(i=1;i<=w;i++)	cout<<m[i]<<endl;
	return 0;
}

	
		
	


Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    double a, b, x;
    cin >> a >> b >> x;

    double v = a * a * b;

    double num;
    double ans = 0;
    if((x/v) <= 0.5){
        ans = atan((a*b*b)/(2*x));
    }
    else{
        ans = atan((2*a*a*b-2*x)/(a*a*a));
    }

    cout << fixed << setprecision(7) << ans * 180 / M_PI << endl;

    return 0;
}

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

int main()
{
  string s;
  cin >> s;
  uint64_t cnt = 0;
  for (int i = 0; i < s.length(); i++) {
    if (i % 2 == s[i] - '0') cnt++;
  }
  cout << min(cnt, s.length() - cnt) << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
  
  int K,A,B;
  scanf("%d %d %d",&K,&A,&B);
  
  int L=A;
  int sw=0;
  
  while(L<=B){
    
    if(L%K==0){
      sw=1;
      
    }
    
    L=L+1;
      
  
  }
  
  if(sw==1){
    printf("OK\n");
  }else{
    printf("NG\n");
  }
  return 0;
}

Measured memory_bytes: 1616
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn=100000;

int main(){
    
    ll n,k;
    bool bi_k[41];
    ll bi_ma[41];
    ll bi_table[41];
    ll ans=0;
    ll bi_cnt[41]={0};
    ll ma=0;
    ll num[maxn];
    int sk,sma;
    
    cin >> n>>k;
    
    rep(i,n){
        cin >> num[i];
        ma=max(ma,num[i]);
    }
    
    bi_table[0]=1;
    rep(i,40){
        bi_table[i+1]=bi_table[i]*2;
    }
    
    //k+1の二進数テーブル
    ll b=1;
    k++;
    
    int ite=0;
    while(b<k){
        b*=2;
        ite++;
    }
    sk=ite;
    for(int i=ite;i>=0;i--){
        if(k>=bi_table[i]){
            k-=bi_table[i];
            bi_k[i]=true;
        }else{
            bi_k[i]=false;
        }
    }
    
    //maの二進数テーブル
    b=1;
    ite=0;
    while(b<ma){
        b*=2;
        ite++;
    }
    sma=ite;
    for(int i=ite;i>=0;i--){
        rep(j,n){
            if(num[j]>=bi_table[i]){
                num[j]-=bi_table[i];
                bi_cnt[i]++;
            }
        }
    }
    
    for(int i=sk;i>=0;i--){
        ll sub=0;
        if(bi_k[i]){
            for(int ite = max(sk,sma);ite>=0;ite--){
                if(ite>sk){
                    sub+=bi_cnt[ite]*bi_table[ite];
                }else if(ite>i){
                    if(bi_k[ite])sub+=(n-bi_cnt[ite])*bi_table[ite];
                    else sub+=bi_cnt[ite]*bi_table[ite];
                }else if(ite==i){
                    sub+=bi_cnt[ite]*bi_table[ite];
                }else{
                    sub+=bi_table[ite]*max(bi_cnt[ite],n-bi_cnt[ite]);
                }
            }
            ans=max(sub,ans);
        }
    }
    
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;

signed main(){
  while(true){
    double R,W,c,r;
    cin>>R>>W>>c>>r;
    if(!W&&!R&&!c&&!r)break;
    int x=0;
    while(true){
      if((R+x*r)/W>=c)break;
      x++;
    }
    cout<<x<<endl;
  }
}



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

using namespace std;

int n;
string t,s;


bool check(int len) {
	int start = n - len;
	for (int i = 0; i < len; i++) 
	{
		if (s.at(start + i) != t.at(i)) {
			return false;
		}
	}	
	return true;
}


int sameLen() {
	for (int len = n; len >= 0 ; len--) {
		if (check(len)) {
			return len;
		}
	}
	return 0;
}


int main() {
	cin >> n;
	cin >> s >> t;

	cout << 2 * n - sameLen() << endl; 

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#define MAX 101
using namespace std;

typedef unsigned long long ull;

int main(int argc, char *argv[])
{
    int n, m, l;
    scanf("%d %d %d", &n, &m, &l);
    ull A[MAX][MAX] = {0};
    ull B[MAX][MAX] = {0};
    int C[MAX][MAX] = {0};
    //    int *A[m] = new int[n][m]{0};
    //    int *B = new int[m][l]{0};
    //    int *C = new int[n][l]{0};

    //    delete []A;
    //    delete []B;
    //    delete []C;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%lld", &A[i][j]);
        }
    }
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < l; j++)
        {
            scanf("%lld", &B[i][j]);
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int k = 0; k < l; k++)
        {
            ull t = 0;
            for (int j = 0; j < m; j++)
            {
                t += A[i][j] * B[j][k];
            }
            //C[i][k] = t;
            if (0 == k)
            {
                printf("%lld", t);
            }
            else
            {
                printf(" %lld", t);
            }
        }
        printf("\n");
    }


    return 0;
}



Measured memory_bytes: 3372
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            long ans = 0;

            for (int b = 0; b < (1 << (S.Length - 1)); b++)
            {
                var h = S[0].ToString();
                for (int i = 0; i < S.Length - 1; i++)
                {
                    if ((b & (1 << i)) != 0)
                    {
                        h += S[i + 1];
                    }
                    else
                    {
                        ans += long.Parse(h);
                        h = S[i + 1].ToString();
                    }
                }
                ans += long.Parse(h);
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(){
    std::map<std::string, int> D;
    int N;
    string S;
    cin >> N;
    for(int i=0; i < N; ++i){
        cin >> S;
        auto itr = D.find(S);
        if (itr != D.end()){
            D[S] += 1;
        }
        else{
            D[S] = 1;
        }
    }
    int max_value = 0;
    for(auto& v : D){
        if(v.second > max_value){
            max_value = v.second;
        }
    }
    for(auto& v: D){
        if(v.second == max_value){
            cout << v.first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  string s; cin >> s;
  int ans = 0;
  int i=0, j=s.size()-1;
  while(i < j) {
    if(s[i] == s[j]) {
      i++; j--;
    } else if(s[i] == 'x') {
      ans++;
      i++;
    } else if(s[j] == 'x') {
      ans++;
      j--;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
D = [[-1,0],[0,1],[1,0],[0,-1]]
def s(N):
    used = [[False]*N+[True] for _ in xrange(N)]+[[True]*(N+1)]
    ret = [[" "]*N for _ in xrange(N)]
    d,y,x = 0,N-1,0
    used[N-1][0] = used[N-1][1] = True
    while True:
        ret[y][x] = "#"
        fy,fx = D[d]
        ry,rx = D[(d+1)%4]
        if not used[y+fy][x+fx]:
            used[y+fy][x+fx] = used[y+ry][x+rx] = True
            d,y,x = d,y+fy,x+fx
        elif not used[y+ry][x+rx]:
            used[y+ry][x+rx] = True
            d,y,x = (d+1)%4,y+ry,x+rx
        else:
            break
    return ret

n = input()
while True:
    n -= 1
    N = input()    
    print "\n".join(map(lambda a:"".join(a),s(N)))
    if n == 0:
        break
    print

Measured memory_bytes: 4292
#include<iostream>

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

// using ll = long long;
// using P = pair<int, int>;

int main() {
    int N, Y;

    cin >> N >> Y;

    int res_a = -1;
    int res_b = -1;
    int res_c = -1;

    rep(a, N+1) {
        rep(b, N+1-a) {
            int c = N - a - b;
            if (10000 * a + 5000 * b + 1000 * c == Y) {
                res_a = a;
                res_b = b;
                res_c = c;
            }
        }
    }

    cout << res_a << endl;
    cout << res_b << endl;
    cout << res_c << endl;

    return 0;
}


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

int_fast64_t N, M, Q, dp[505][505], l, r;

int main(){
    scanf("%lld%lld%lld", &N, &M, &Q);
    
    for(uint_fast32_t i = 0; i < M; ++i){
        scanf("%lld%lld", &l, &r);
        ++dp[1][r];
        --dp[l + 1][r];
    }
    
    for(uint_fast32_t i = 1; i <= N; ++i)
        for(uint_fast32_t j = 0; j <= N; ++j)
            dp[i][j] += dp[i - 1][j];
    
    for(uint_fast32_t i = 0; i <= N; ++i)
        partial_sum(dp[i], dp[i + 1], dp[i]);
    
    for(uint_fast32_t i = 0; i < Q; ++i && printf("%lld\n", dp[l][r]))
        scanf("%lld%lld", &l, &r);
    
    return 0;
}


Measured memory_bytes: 2944