akhauriyash/Code-Regression huggingface dataset:
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

inline double sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
// }}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int cnt = 0;
	rep(i,s.size()){
		if(s[i] == s[i+1]){
			if(s[i] == '0') s[i+1] = '1';
			else s[i+1] = '0';
			++cnt;
		}
	}
	cout << cnt << '\n';
	return 0;	
}


Measured memory_bytes: 512
#include<stdio.h>

#define MIN(a,b) ((a)<(b)?(a):(b))

#define F 6

double winPetr(double p,double *a,double *b){
  const double min=0.001;
  double win=0;
  int i;
  for(i=0;i<F;i++){
    if(a[i]<=min && b[i]<=min) continue;
    double t=p*a[i]+(1-p)*b[i];
    win+=t*MIN(p*a[i]/t,(1-p)*b[i]/t);
  }
  return win;
}

void run(void){
  double p[F],q[F];
  int i;
  for(i=0;i<F;i++){
    int v;
    scanf("%d",&v);
    p[i]=(double)v/100;
  }
  for(i=0;i<F;i++){
    int v;
    scanf("%d",&v);
    q[i]=(double)v/100;
  }
  double l=0;
  double r=1;
  for(i=0;i<100;i++){
    double ll=(2*l+r)/3;
    double fl=winPetr(ll,p,q);
    double rr=(l+2*r)/3;
    double fr=winPetr(rr,p,q);
    if(fl<=fr){
      l=ll;
    } else {
      r=rr;
    }
  }
  printf("%.9f\n",1-winPetr((l+r)/2,p,q));
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
import bisect


n = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        k = bisect.bisect_left(L, L[i] + L[j])
        ans += k - (j + 1)

print(ans)


Measured memory_bytes: 3188
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int A = sc.nextInt();
			int B = sc.nextInt() + A;
			System.out.println((B >= 10) ? "error" : B);	
		}catch(Exception e){
			e.printStackTrace();
		}
	} 
}

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

class union_find{
private:
    vector<int>parent;
    vector<int>rank;
    int cnt;
public:
    union_find(int vertex_num){
        parent.resize(vertex_num);
        rank.resize(vertex_num);
        cnt=vertex_num;
        rep(i,vertex_num){
            parent[i]=i;
            rank[i]=0;
        }   
    }
    int get_root(int n /*知りたい根の頂点の番号*/){
        if(parent[n]==n){
            return n;
        }else{
            return get_root(parent[n]);
        }
    }
    bool is_same(int a,int b /*連結を判定したい2頂点*/){
        return get_root(a) == get_root(b);
    }

    void unite(int a,int b){
        int root_a=get_root(a);
        int root_b=get_root(b);
        if(root_a==root_b)return;

        if(rank[root_a]<rank[root_b]){
            parent[root_a]=root_b;
            cnt--;
        }else if(rank[root_a]>rank[root_b]){
            parent[root_b]=root_a;
            cnt--;
        }else{
            parent[root_a]=root_b;
            ++rank[root_b];
            cnt--;
        }
    }
    int ans(){
        return cnt;
    }

};

signed main(){
    ll n,m,ans=0;
    cin>>n>>m;
    //vector<pair<int,int>>ab(n);
        int a[m],b[m];
    rep(i,m){
        cin>>a[i]>>b[i];
        //ab[i]=make_pair(a,b);
        
    }
    rep(i,m){
        union_find uf(n);
        rep(j,m){
            if(i==j)continue;
            uf.unite(a[j],b[j]);
        }
        if(uf.ans()!=1)ans++;   
    }
    cout<<ans<<endl;

       
}
/*
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int e[111][111],d[111];
int used[111];
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      e[i][j]=INF;
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      e[u][v]=min(e[u][v],c);
    }
  }
  memset(used,0,sizeof(used));
  for(int i=0;i<n;i++) d[i]=INF;
  d[0]=0;
  while(1){
    int u=-1;
    for(int i=0;i<n;i++){
      if(used[i]) continue;
      if(d[i]==INF) continue;
      if(u<0||d[i]<d[u]) u=i;
    }
    if(u<0) break;
    used[u]=1;
    for(int i=0;i<n;i++){
      d[i]=min(d[i],d[u]+e[u][i]);
    }
  }
  for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
double doINF = 1.0/0.0 ;
ostream_iterator <int> outp(cout,"");
//copy(v.beg,v.en,outp);
inline ll modadd(ll n,ll m,ll mod){
    ll sum = ((n+m)%mod+mod)%mod;
    return sum;
} 
inline ll modsub(ll n,ll m, ll mod){
    ll diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}
inline ll modpro(ll n,ll m,ll mod){
    ll pro = ((n*m)%mod+mod)%mod;
    return pro;
}
inline ll pow(int x,int y){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
inline ll powmod(ll x,ll y,ll mod){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}
ll min(ll a, ll b){
    if(a>b){
        return b;
    }
    return a;
}
 
ll max(ll a, ll b){
    if(a>b){
        return a;
    }
    return b;
}
bool pairdec(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 		if(a.fi!=b.fi)
       	return (a.fi> b.fi);
		else return a.se>b.se;  
} 
ll power(ll x, ll y, ll mod) 
{ 
    ll res = 1; 
    x = x%mod; 
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % mod; 
  
        y = y >> 1;
        x = (x * x) % mod; 
    } 
    return res; 
} 
ll modInverse(ll a, ll mod) 
{ 
    return  powmod(a, mod - 2, mod); 
} 
ll modFact(ll n, ll mod) 
{ 
    if (n >=mod) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) %mod; 
  
    return result; 
} 

int main()
{
	ll n,w;
	cin>>n>>w;
	ll arr[n+1][2];
	forl(i,1,n+1)forl(j,0,2) cin>>arr[i][j];
	arr[0][0]=arr[0][1]=0;
	ll dp[n+1][w+1];
	
	forl(i,0,n+1)
	{
		forl(j,0,w+1)
		{
			if(i==0 || j==0)
			{	dp[i][j]=0;
				
			continue;
				
			}
		
			if(j-arr[i][0]>=0)dp[i][j]=max(arr[i][1]+dp[i-1][j-arr[i][0]],dp[i-1][j]);
			else dp[i][j]=dp[i-1][j];
		}
	}
	cout<<*max_element(dp[n],dp[n]+w+1)<<endl;
	
	
}

Measured memory_bytes: 79104
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>

class ADodecagon {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int a;
	    in >> a;
        out << 3*a*a;
	}
};


int main() {
	ADodecagon solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
n = gets.chomp.split("").map(&:to_i)
# puts n
if n.size == 3
    if n[2] == 3 then
        puts "bon"
    elsif n[2] == 0 || n[2] == 1 || n[2] == 6 || n[2] == 8 then
        puts "pon"
    else
        puts "hon"
    end
elsif n.size == 2
    if n[1] == 3 then
        puts "bon"
    elsif n[1] == 0 || n[1] == 1 || n[1] == 6 || n[1] == 8 then
        puts "pon"
    else
        puts "hon"
    end
else
    if n[0] == 3 then
        puts "bon"
    elsif n[0] == 0 || n[0] == 1 || n[0] == 6 || n[0] == 8 then
        puts "pon"
    else
        puts "hon"
    end
end

Measured memory_bytes: 14312
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
 
int main() {
  int N,ans=0;cin>>N;
  vector<int> vec(N);
  rep(i,N) cin>>vec.at(i);
  
  int num=1;
  for(int i=0;i<N;i++){
    if(vec[i]==num){
      num++;
      continue;
    }
    else ans++;
  }
  
  if(num==1) cout << -1 << endl;
  else cout << ans << endl; 
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    while(a>=b) b*=2,k--;
    while(b>=c) c*=2,k--;
    if(k>=0) cout<<"Yes\n";
    else cout<<"No\n";
}

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

vector<pair<ll,ll>> Prime_factorization(ll N){
	vector<pair<ll,ll>> res;
	ll X = N;
	for(ll i=2;i*i<=X;i++){
		int cnt = 0;
		if(X%i==0){
			while(X%i==0){
				cnt++;
				X/=i;
			}
		}
		res.push_back(pair<ll,ll>(i,cnt));
	}
	if(X)res.push_back(pair<ll,ll>(X,1));
	return res;
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,P;
	cin >> N >> P;
	auto p = Prime_factorization(P);
	ll ans = 1;
	for(auto x:p){
		for(int i=0;i<x.second/N;i++)ans*=x.first;
	}
	cout << ans << endl;
}

Measured memory_bytes: 9964
#include<cstdio>

using namespace std;
typedef unsigned long long ll;

int main(){
    ll a,b,x,ans=0;

    scanf("%lld%lld%lld",&a,&b,&x);

    if(a==b && a%x!=0){
        printf("0\n");
        goto end;
    }
    if(a == 0 & b == 0){
        printf("1\n");
        goto end;
    }

    ans = b/x-a/x;

    if(a%x == 0)ans++; 
    printf("%lld\n",ans);
end:

    return 0;
}


Measured memory_bytes: 760
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define pb push_back
#define ri(x) scanf("%d",&x)
#define rii(x,y) ri(x),ri(y)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define ms2(obj,val,sz) memset(obj,val,sizeof(obj[0])*sz)
#define FOR(i,f,t) for(int i=f;i<(int)t;i++)
#define FORR(i,f,t) for(int i=f;i>(int)t;i--)

typedef long long ll;
typedef vector<int> vi;

const int MAXN=0;

int R,C,K;
bool good = false;

bool f(int r, int c) {
	return (C-c) * r + (R-r) * c == K;
}

int main() {
	rii(R,C),ri(K);
	FOR(r,0,R+1) FOR(c,0,C+1) good |= f(r,c);
	printf("%s\n", good ? "Yes" : "No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int maxn = 1010;
typedef long long ll;
int n, k, mod;
int g[maxn], f[maxn];
int C[maxn][maxn];
inline void reduce(int & x){ x += x >> 31 & mod; }
inline void exp(int * g) {
	memcpy(f, g, sizeof f);
	for(int i = 0;i <= n + 1;++i) {
		for(int j = 0;j < i;++j) {
			g[i] = (g[i] + (ll) f[j] * g[i - j - 1] % mod * C[i][j]) % mod;
		}
	}
}
int main() {
	std::cin >> n >> k >> mod;
	for(int i = 0;i < maxn;++i) for(int j = C[i][0] = 1;j <= i;++j)
		reduce(C[i][j] = C[i - 1][j] + C[i - 1][j - 1] - mod);
	std::fill(g, g + n + 2, 1);
	for(int i = 1;i < k;++i) exp(g);
	std::cout << g[n] << '\n';
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#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 x; cin >> x;
	int ans = (x / 500) * 1000;
	x %= 500;
	ans += (x / 5) * 5;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(void){
  int h,w,i,j,a,b,m=1;
  char c;
  vector<int> di{1,0,-1,0},dj{0,1,0,-1};
  cin >> h >> w;
  vector<vector<int>> f(h+3,vector<int>(w+3,0));
  queue<P> q;
  for (i=1;i<=h;i++) for (j=1;j<=w;j++){
    cin >> c;
    if (c=='#'){
      f.at(i).at(j)=1;
      q.push(P(i,j));
    }
  }
  while (q.size()){
    a=q.front().first;
    b=q.front().second;
    q.pop();
    if (m<f.at(a).at(b)) m=f.at(a).at(b);
    for (i=0;i<4;i++) if (a+di.at(i)>0 && a+di.at(i)<=h && b+dj.at(i)>0 && b+dj.at(i)<=w){
      if (f.at( a + di.at(i) ).at( b + dj.at(i) ) == 0){
        f.at( a + di.at(i) ).at( b + dj.at(i) ) = f.at(a).at(b) + 1;
        q.push( P( a + di.at(i) , b + dj.at(i) ) );
      }
    }
  }
  cout << m-1 << endl;
  return 0;
}

Measured memory_bytes: 12432
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	static int[] x, y;
	static int permN;
	static double sum;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] array = new int[N];
		x = new int[N];
		y = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = i + 1;
			x[i] = scanner.nextInt();
			y[i] = scanner.nextInt();
		}
		sum = 0.0;
		permN = 0;
		permutation(array);
		System.out.println((double)sum / (double)permN);
	}

	private static void permutation(int[] seed) {
		int[] perm = new int[seed.length];
		boolean[] used = new boolean[seed.length];
		buildPerm(seed, perm, used, 0);
	}

	private static void buildPerm(int[] seed, int[] perm, boolean[] used, int index) {
		if (index == seed.length) {
			procPerm(perm);
			return;
		}

		for (int i = 0; i < seed.length; i++) {
			if (used[i]) {
				continue;
			}
			perm[index] = seed[i];
			used[i] = true;
			buildPerm(seed, perm, used,index + 1);
			used[i] = false;
		}
	}

	private static void procPerm(int[] perm) {
		permN++;
		double s = 0.0;
		for (int i = 0; i < perm.length - 1; i++) {
			s += Math.sqrt(Math.pow((double)(x[perm[i] - 1] - x[perm[i + 1] - 1]), 2.0) + Math.pow((double)(y[perm[i] - 1] - y[perm[i + 1] - 1]), 2.0));
		}
		sum += s;
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = ll(1e15)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;

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

  vector<vector<ll>> C(10, vector<ll>(10));
  rep2(k, 1, N+1) {
    int i = to_string(k)[0] - '0';
    int j = k % 10;
    C[i][j]++;
  } 

  ll ans = 0;
  rep(i, 10) rep(j, 10) {
    ans += C[i][j] * C[j][i];   
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n,k = gets.chomp.split(" ").map(&:to_i)
x_arr = gets.chomp.split(" ").map(&:to_i)

# -10 ** 8 から 10 ** 8 の間を移動するのが最長
min = (10 ** 8) * 3
(0..(n - k)).each do |i|
  left = x_arr[i]
  right = x_arr[k - 1 + i]
  if left < 0 && right < 0
    # 0 -> left とたどる
    d = left.abs
  elsif left > 0 && right > 0
    # 0 -> right とたどる
    d = right.abs
  elsif left.abs > right.abs
    # 0 -> right -> 0 -> left とたどる
    d = right.abs * 2 + left.abs
  else
    # 0 -> left -> 0 -> right とたどる
    d = left.abs * 2 + right.abs
  end
  min = d if d < min
end

puts min


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

int N;
int a[10];

int main(){
    cin >> N;
    int keta=1;
    int Nd=N;
    for(int i=0;i<6;i++){
      Nd/=10;
      if(Nd!=0)keta++;
    }
    if(keta==1)cout<<N;
    if(keta==2)cout<<"9";
    if(keta==3)cout<<9+(N-99);
    if(keta==4)cout<<9+900;
    if(keta==5)cout<<9+900+(N-9999);
    if(keta==6)cout<<9+900+90000;


}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
ans = 0
M = 1000005
cnt = [0 for _ in range(M)]
mx = max(a)+1
for x in a:
    for j in range(x,mx,x):
        cnt[j] += 1
    
for x in a:
    if cnt[x] == 1:
        ans += 1


print(ans)


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

#define ll long long

ll gcd(ll a, ll b) {
   if (a < b) { // aの方が大きくなるようにする
      swap(a, b);
   }
   ll k = a % b;
   while (k) {
      a = b;
      b = k;
      k = a % b;
   }
   return b;
}

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

int main() {
   int n;
   cin >> n;
   vector<ll> v(n);
   for (ll& x : v) cin >> x;

   ll a = v[0];
   for (int i = 1; i < n; i++) {
      a = lcm(a, v[i]);
   }

   cout << a << endl;

   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define lld long double
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int N = 101000;
ll n,a,b,c,d;
unordered_map<ll,ll> mp;
ll solve(ll n){
	if(n==0) return 0;
	if(n==1) return d;
	if(mp.count(n)) return mp[n];
	ll ans=1.l*n*d>1e18l?(ll)(1e18):d*n;/*(n>(ll)(1e9)?(ll)(1e18):d*n)*/;
	ans=min(ans,solve(n/5)+c+d*(n%5));
	ans=min(ans,solve(n/5+1)+c+d*(5-n%5));
	ans=min(ans,solve(n/3)+b+d*(n%3));
	ans=min(ans,solve(n/3+1)+b+d*(3-n%3));
	ans=min(ans,solve(n/2)+a+d*(n%2));
	if(n&1) ans=min(ans,solve(n/2+1)+a+d*(n%2));
	return mp[n]=ans;
}
int main(){
	int T;read(T);
	while(T--){
		read(n);read(a);read(b);read(c);read(d);
		mp.clear();
		cout<<solve(n)<<'\n';
	}
	return 0;
}



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

int main(){
	vector<bool> p(MAX_SIZE,true);
	p[0] = false; p[1] = false;
	for(int i=2; i*i<=MAX_SIZE; i++){
		if(!p[i]) continue;
		for(int j=i+1; j<=MAX_SIZE; j++){
			if(p[j] && j%i==0){ p[j]=false; }
		}
	}

	vector<int> cnt(MAX_SIZE);
	for(int j=3; j<=MAX_SIZE; j+=2){
		int a = (j+1)/2;
		if(p[j] && p[a]) cnt[j]++;
	}
	for(int i=3; i<=MAX_SIZE; i++){ cnt[i]+=cnt[i-1]; }

	int Q;
	cin >> Q;
	rep(i,Q){
		int l,r;
		cin >> l >> r;
		int ans = cnt[r] - cnt[l-1];
		cout << ans << endl;
	}
}


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

int main(){
    string s;
    while(cin>>s){
        for(int i=0;i<7;i+=3){
            if(s[i]!='s'&&s[i]==s[i+1]&&s[i]==s[i+2]){
                cout<<s[i]<<endl;
                goto ne;
            }
        }
        for(int i=0;i<3;i++){
            if(s[i]!='s'&&s[i]==s[i+3]&&s[i]==s[i+6]){
                cout<<s[i]<<endl;
                goto ne;
            }
        }
        if(s[0]!='s'&&s[0]==s[4]&&s[0]==s[8]){
            cout<<s[0]<<endl;
            goto ne;
        }
        if(s[2]!='s'&&s[2]==s[4]&&s[2]==s[6]){
            cout<<s[2]<<endl;
            goto ne;
        }
        cout<<"d"<<endl;
    ne:;
    }
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

using namespace std;
int dx[] = {0,1};
int dy[] = {1,0};
const long double Pi=acos(-1),e=2.718;
const int N=1e3+10,mod=1e9+7;
ll dp[N][N],n,m;
char G[N][N];
ll solve(int x,int y){
    if(x==n-1 && y==m-1)return 1;
    if(dp[x][y]!=-1)return dp[x][y];
    dp[x][y]=0;
    for(int i=0;i<2;i++){
        int newx=x+dx[i];
        int newy=y+dy[i];
        if(newx<0 || newx>=n || newy<0 || newy>=m || G[newx][newy]=='#')continue;
        dp[x][y] += solve(newx,newy);
        dp[x][y] %= mod;
    }
    return dp[x][y];
}
int main()
{
    memset(dp,-1,sizeof dp);
    FASTIO
    cin >> n >> m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> G[i][j];
        }
    }
    cout << solve(0,0) << endl;
    return 0;
}
/**

*/


Measured memory_bytes: 9344
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int n,t;
	char v[10]={63,6,91,79,102,109,125,39,127,111};
	char s[8],a,b;
	for(;;){
		scanf("%d",&n);
		if(n==-1)break;
		a=0;
		rep(i,n){
			scanf("%d",&t);
			b=a^v[t];
			a=v[t];
			rep(j,7)printf("%d",(b & (1<<(6-j))) > 0);
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<vector>
using namespace std;
class UnionFind{
  vector<int> node;
 public:
  UnionFind(int n):node(n){
    for(int i = 0;i < n;i++){
      node[i] = i;
    }
  }
  int root(int x){
    if(node[x] == x)return x;
    return node[x] = root(node[x]);
  }
  void unite(int x,int y){
    node[root(x)] = root(y);
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int main(){
  int n,q;
  cin >> n >> q;
  UnionFind u(n);
  for(int i = 0;i < q;i++){
    int com,x,y;
    cin >> com >> x >> y;
    if(com == 0){
      u.unite(x,y);
    }else{
      cout << (int)u.same(x,y) << endl;
    }
  }
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0) {if(a<b) swap(a,b); a = a%b;} return max(a,b);
}


int main(){
  int x;
  cin>>x;
  int ma = x/100;
  for(int i=ma;i>0;i--){
    int a = x-i*100;
    if(0 <= a && a <= 5*i) {
      cout << 1 << endl;
      return 0;
    }

  }
  cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
largeA = []
largeA = list(map(int,input().split()))
a = abs(largeA[0]-largeA[1])+abs(largeA[1]-largeA[2])
b = abs(largeA[0]-largeA[1])+abs(largeA[2]-largeA[0])
c = abs(largeA[2]-largeA[0])+abs(largeA[1]-largeA[0])
d = abs(largeA[2]-largeA[0])+abs(largeA[1]-largeA[2])
e = abs(largeA[2]-largeA[1])+abs(largeA[1]-largeA[0])
f = abs(largeA[2]-largeA[1])+abs(largeA[2]-largeA[0])
print(min(a,b,c,d,e,f))

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

int main() {
	// your code goes here
	int n,i,j;
	cin>>n;
	int a[n][3];
	for(i=0;i<n;i++)
	for(j=0;j<3;j++)
	cin>>a[i][j];
	int dp[n+1][j];
	dp[1][0]=a[0][0];
		dp[1][1]=a[0][1];
			dp[1][2]=a[0][2];
	for(i=2;i<n+1;i++)
	{
		for(j=0;j<3;j++)
		{
			dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[i-1][j];
		}
	}
	cout<<max({dp[n][0],dp[n][1],dp[n][2]});
	return 0;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main{

	public static void main(String[] args) {
		scan();
		
	}
	//??\????°???¨??¢??°
	public static void scan() {
		Scanner scanner = new Scanner(System.in);
		scanner.useDelimiter("\\s*,\\s*|\n");
		int W = scanner.nextInt();
		int[] amida = Amida(W);
		int N = scanner.nextInt();
		int kari1 = 0;
		int kari2 = 0;
		int kari3 = 0;
		for(int i = 0; i < N ; i++){
			kari1 = scanner.nextInt();
			kari2 = scanner.nextInt();
			kari3 = amida[kari1-1];
			amida[kari1-1] = amida[kari2-1];
			amida[kari2-1] = kari3;
		}
		for(int i = 0; i < W ; i++){
			System.out.println(amida[i]);
		}
		scanner.close();
		return ;
	}
	
	public static int[] Amida(int W) {
		int[] amida = new int[W];
		for(int i = 0; i < W ; i++){
			amida[i] = i+1;
		}
		return amida;
	}
	
	
}

Measured memory_bytes: 25872
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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;
  int ans = 0;
  int head = 0, last = 0, both = 0;
  rep(i, n)
  {
    string s;
    cin >> s;
    rep(i, s.size() - 1)
    {
      if (s[i] == 'A' && s[i + 1] == 'B')
        ans++;
    }
    if (s[0] == 'B' && s[s.size() - 1] == 'A')
    {
      both++;
      continue;
    }

    if (s[0] == 'B')
      head++;

    if (s[s.size() - 1] == 'A')
      last++;
  }

  int mini = min(head, last);
  int maxi = max(head, last);

  ans += max(0, both - 1);
  if (both > 0 && mini > 0)
  {
    ans++;
    mini--;
  }

  if (both > 0 && maxi > 0)
  {
    ans++;
    maxi--;
  }

  ans += max(0, mini);

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


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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {

    ll N, K;
    cin >> N >> K;
    ll num = 0;
    double ans;

    REP1(i, N+1){
        num = i;
        ll count = 0;
        while(num < K){
            num *= 2;
            count++;
        }
        double tmp = 1;
        REP(j, count){
            tmp *= 0.5;
        }
        // cout << tmp << endl;
        ans += (1.0/N) * tmp;
    }
    printf("%.10f", ans);
    // cout << ans << endl;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define PI 3.141592653589793238462643383279
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<double,double> DD;

int main()
{
//	cut here before submit 
//	freopen ("testcase.TH", "r", stdin );
	string str = "";
	double dir = PI/2.;
	double x = 0., y = 0.;
	while (1 ){
		getline (cin, str );
		rep (i, str.length() ){
			if (str[i] == ',' ) str[i] = ' ';
		} // end rep
		stringstream ss (str );
		int d, t;
		ss >> d >> t;
		if (d == 0 && t == 0 ) break;
		double rot = (double)t*PI/180.;
		double dx = (double)d*cos(dir);
		double dy = (double)d*sin(dir);
		x += dx, y += dy;
		dir -= rot;
	} // end while
	printf ("%d\n%d\n", (int)x, (int)y );

	return 0;
}

Measured memory_bytes: 1240
#include <stdio.h>
#define MAX 10001
#define NOT_FOUND -1

int linearSearch(int *A, int N, int key) {
  int i = 0;
  
  A[N] = key;
  while(A[i] != key) {
    i++;
  }
  if(i == N) return NOT_FOUND;
  return i;
}

int main() {
  int n, q, s[MAX], t, i, count = 0;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }
  
  scanf("%d", &q);
  for(i = 0; i < q; i++) {
    scanf("%d", &t);
    if(linearSearch(s, n, t) >= 0) count++;
  }
  
  printf("%d\n", count);
  return 0;
}



Measured memory_bytes: 1996
#include <iostream>
int main()
{
    int X,Y;
    std::cin >> X >> Y;

    for (int a=0,b=X;a<=X;a++,b=b-1)
    {
        if (Y==4*b+2*a)
        {
            std::cout << "Yes" << std::endl;
            return 0;
        }
        
    }
    
    std::cout << "No" << std::endl;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int w = scan.nextInt();
		int i = 0;
		String[] c = new String[h];
		for(i = 0; i < h; i++) {
			c[i] = scan.next();
		}
		for(i = 0; i < h; i++) {
			System.out.println(c[i]);
			System.out.println(c[i]);
		}
		
	}
}

Measured memory_bytes: 24148
#include <stdio.h>

int main() {
  char s[100000];
  scanf("%s", s);
  int count[2];
  count[0] = 0;
  count[1] = 0;
  char b[2] = "01";

  for(int i = 0; s[i] != '\0'; i++) {
    count[s[i] == b[i%2]]++;
  }
  printf("%d\n", count[0] < count[1] ? count[0]:count[1]);
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

h = list(map(int, input().split()))

good = [True for i in range(n)]

for i in range(m):
	a, b = map(int, input().split())
	if (h[a - 1] == h[b - 1]):
		good[a - 1] = False 
		good[b - 1] = False
	elif h[a - 1] < h[b - 1]:
		good[a - 1] = False
	else:
		good[b - 1] = False

result = 0
for x in good:
	if  x:
		result += 1

print(result)


Measured memory_bytes: 85064
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(void)
{
    string s; cin>>s;
    int n = s.length();
    bool flag = true;
    string ss = s;
    reverse(ss.begin(),ss.end());
    if(ss != s) flag = false;
    string s1 = s.substr(0,(n-1)/2);
    string ss1 = s1;
    reverse(ss1.begin(),ss1.end());
    if(ss1 != s1) flag = false;
    string s2 = s.substr((n+3)/2-1,n);
    string ss2 = s2;
    reverse(ss2.begin(),ss2.end());
    if(ss2 != s2) flag = false;
    if(flag) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2000+10,mod=924844033;
int dp[maxn<<1][maxn][2],fac[maxn];
bool f[maxn<<1];
int main(){
	int n=read(),m=read(),ans=0;
	for(int i=1,cur=0;i<=m;++i) REP(l,0,1) for(int j=i;j<=n;j+=m) f[++cur]=(i!=j);
	fac[0]=1;
	REP(i,1,n) fac[i]=(ll)fac[i-1]*i%mod;
	dp[0][0][0]=1;
	REP(i,1,2*n) REP(j,0,n){
		dp[i][j][0]=(dp[i-1][j][0]+dp[i-1][j][1])%mod;
		if(j && f[i]) dp[i][j][1]=dp[i-1][j-1][0];
	}
	REP(i,0,n) ans=(ans+(ll)((i&1)?(mod-1):1)*(dp[2*n][i][0]+dp[2*n][i][1])%mod*fac[n-i])%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 63104
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

signed main() {
	int n; scanf("%d", &n);
	int a = 0, b = 0, c = 0;
	rep(i, n) {
		int A; scanf("%d", &A);
		if (A % 4 == 0)a++;
		else if (A % 2 == 0)b++;
		else c++;
	}
	//aとcを交互に並べ
	if (c == a + 1) {
		if (b == 0)puts("Yes");
		else puts("No");
	}
	else puts(a >= c ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
int kansu(int);

int a[N],b;

int main()
{
  int i,c,d,e=0;
  scanf("%d",&b);
  for(i=0;i<b;i++)
    {
      scanf("%d",&a[i]);
    }
  scanf("%d",&c);
  for(i=0;i<c;i++)
    {
      scanf("%d",&d);
      if(kansu(d))e++;
    }
  printf("%d\n",e);
  return 0;
}

int kansu(int x)
{
  int re=0,ra=b,su;

  while(re<ra)
    {
      su=(re+ra)/2;
      if(x>a[su])re=su+1;
      if(x<a[su])ra=su;
      else if(x==a[su])return 1;
    }
  return 0;
}



Measured memory_bytes: 2132
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";
	
	
	static boolean q(long n)
	{
		out.println("? " + n);
		out.flush();
		return in.next().charAt(0) == 'Y';
	}
	
//	static long hans = 9;
//	
//	static boolean q(long n)
//	{
//		return 
//				hans <= n && (""+hans).compareTo("" + n) <= 0 ||
//				hans > n && (""+hans).compareTo("" + n) > 0;
//	}
	
	static void solve()
	{
		long low = 10000000000L, high = 100000000000L;
		while(high - low > 1){
			long h = high+low>>1;
			if(q(h)){
				high = h;
			}else{
				low = h;
			}
		}
		String nine = "999999999";
		if(high/10 >= 9000000000L){
			String ten = "10000000000";
			for(int i = 10;i >= 2;i--){
				if(q(Long.parseLong(ten.substring(0, i)))){
					out.println("! " + Long.toString(high).substring(0, i));
					out.flush();
					return;
				}
			}
			out.println("! " + Long.toString(high).substring(0, 1));
			out.flush();
		}else{
			for(int i = 9;i >= 1;i--){
				if(!q(Long.parseLong(nine.substring(0, i)))){
					out.println("! " + Long.toString(high).substring(0, i+1));
					out.flush();
					return;
				}
			}
			out.println("! " + Long.toString(high).substring(0, 1));
			out.flush();
		}
	}
	
	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


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


int main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;
    return 0;
}

Measured memory_bytes: 256
sub f{my$x=$_;$p=0;$p=$M[$x]+=$-=($M[$_]||&f)+1-$M[$x]for@$x;$p}
<>;
/ /,push@{$`},$'+0for<>;
#map{$\+=$-=&f-$\}1..1e5;print
#printf sort{$b-$a}map&f,1..1e5
@n=1..1e5;@a[map&f,@n]=1;print$#a

Measured memory_bytes: 118400
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n;
signed main(){
	cin>>n;
	int ans=0;
	ans=(n/11)*2;
	n%=11;
	if(n>6)ans+=2;
	else if(n)ans++;
	cout<<ans<<endl;
	return 0;
}


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

Measured memory_bytes: 256
def main():

    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    cnt = 0

    for i in range(N):
        attack = min(A[i], B[i])
        A[i] -= attack
        B[i] -= attack
        cnt += attack
        attack = min(A[i + 1], B[i])
        A[i + 1] -= attack
        cnt += attack

    print(cnt)

if __name__ == "__main__":
    main()

Measured memory_bytes: 18624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String word = "";
		int N = s.length();
		for(int i = 0 ; i < N ; i++) {
			if(s.charAt(i) == '0') {
				word += "0";
			} else if(s.charAt(i) == '1') {
				word += "1";
			} else {
				if(word.length() != 0) {
					word = word.substring(0, word.length() - 1);
				}
			}
		}
		System.out.println(word);
	}
}


Measured memory_bytes: 21844
N, M = map(int, input().split())
slist = []
for _ in range(M):
    k, *s = list(map(int, input().split()))
    slist.append(set(s))
plist = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    on = set()
    pika = 0
    for j in range(N):
        if ((i >> j) & 1):
            on.add(j+1)
    for lamp_num in range(M):
        if len(slist[lamp_num]&on)%2 == plist[lamp_num]:
            pika += 1
    if pika == M:
        ans += 1
print(ans)

Measured memory_bytes: 42096
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
typedef pair<long long,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
long long n,h[100005];
ll dp[100005];
#define ALL(v)  (v).begin(),(v).end()
std::set<long long> st;
//#define MAX(a,b) if(a>b)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

    /*  ペア関連
    //vector<pair<long long, long long> > pairs(N);
    for(long long i=0; i<N; i++){
        long long a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    //sort(pairs.begin(), pairs.end(),greater<pair<long long,long long> >());
	sort(pairs.begin(), pairs.end());
    */

 	//stack<long long> sta;   
    //queue<long long> que;


int main(){
	
	long long N,M,K,X;
	string s;
    long long sum,sum1;
	sum=0;
	sum1=0;
	long long flg,flg1,cnt,cnt1;
	flg=0;
	flg1=0;
	cnt=0;
	cnt1=0;
	long long max;
	long long max1;
	max=0;
	max1=0;
	long long min;
	long long min1;
	min=INF;
	min1=INF;

	long long work1,work2,work3,work4;
	work1=0;
	work2=0;
	work3=0;
	work4=0;
    
	//std::cin >> N;
    std::cin >> N >> X;
    //std::cin >> N >> M >> K;
    
	std::vector<long long> L(N+1);
	std::vector<long long> w(N+1);
    //std::cin >> s;
    
    
    // 配列入力1
    
    for(long long i=0; i<N; i++){
		std::cin >> L[i];
	}
	
	// 配列入力2
	/*
	for(long long i=0; i<N; i++){
		std::cin >> w[i];
	}
	*/
    
	
	//通常
	
	
    for(long long i=0; i<N+1; i++){
		if(i==0){
			w[0]=0;
		}
		else{
			w[i]=w[i-1]+L[i-1];
		}
	}
	long long ind;
	ind=0;
	cnt=0;
	while(w[ind]<=X && ind!=N+1){
		cnt++;
		ind++;
	}

	//文字列入力
	/*
	for(long long i=0; i<s.length(); i++){
		
		if(s[i]!='1'){
	}
	*/

	
	
	//ソート
    //std::sort(v.begin(),v.end());//昇順ソート
    //std::sort(v.begin(),v.end(),std::greater<long long>());//降順ソート
    //std::sort(w.begin(),w.end());//昇順ソート
    //std::sort(w.begin(),w.end(),std::greater<long long>());//降順ソート
    /*
    
    //S.substr(i, 5);
    //S.size();
    
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
		if(st.find(v[i])==st.end()){
			st.insert(v[i]);
		}
		else{
			st.erase(v[i]);
		}
	}
	*/


	/*
	long long a[4];
	long long value;
	value=0;
	
	a[0] = (value % 10); 
	value /= 10;// 1桁目を取り出す
	a[1] = (value % 10); 
	value /= 10;// 2桁目を取り出す
	a[2] = (value % 10); 
	value /= 10;// 3桁目を取り出す
	a[3] = (value % 10); 
	value /= 10;// 4桁目を取り出す
    work1=a[0]+10*a[1];
    work2=a[2]+10*a[3];
    */
	
	
    if(1){
    	printf("%d",cnt);
    	//printf("%lld",N);
    	//puts("Yes");
    	//printf("%d",st.size());
    	//文字列の出力
    	//std::cout << s << std::endl;
    	//printf("%.12f\n",ret);
    	//cout << sum << endl;
	}
	else{
		//puts("No");
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int H, W;
	scanf("%d%d", &H, &W);

	char g[100][100];
	bool visited[100][100];
	int d[100][100];
	int cnt_white = 0;
	for (int row = 0; row < H; row++) {
		scanf("%s", g[row]);
		for (int col = 0; col < W; col++) {
			visited[row][col] = false;
			d[row][col] = numeric_limits<int>::max();
			if (g[row][col] == '.')
				cnt_white++;
		}
	}

	queue<pair<int, int>> q;
	q.push(make_pair(0, 0));
	d[0][0] = 0;
	int drow[] = {0, 0, 1, -1};
	int dcol[] = {1, -1, 0, 0};
	while (!q.empty()) {
		pair<int, int> now = q.front(); q.pop();
		if (visited[now.first][now.second])
			continue;
		visited[now.first][now.second] = true;

		for (int i = 0; i < 4; i++) {
			int row = now.first + drow[i];
			int col = now.second + dcol[i];
			if (row < 0 || H <= row || col < 0 || W <= col || g[row][col] == '#')
				continue;
			q.push(make_pair(row, col));
			d[row][col] = min(d[row][col], d[now.first][now.second] + 1);
		}
	}

	if (d[H - 1][W - 1] == numeric_limits<int>::max()) {
		printf("-1\n");
		return 0;
	}

	printf("%d\n", cnt_white - (d[H - 1][W - 1] + 1));

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, q;
vector<P> vec, vec2;
int k1, k2;
set<int> st;
map<int, int> mp;

signed main() {
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		int s, t, x; cin >> s >> t >> x;
		vec.push_back({ max((int)0,s - x),x });
		vec2.push_back({ max((int)0,t - x),x });
	}
	sort(all(vec));
	sort(all(vec2));
	for (int i = 0; i < q; i++) {
		int d; cin >> d;
		while (k1 < n&&vec[k1].first <= d) {
			st.insert(vec[k1].second);
			mp[vec[k1].second]++;
			k1++;
		}
		while (k2 < n&&vec2[k2].first <= d) {
			if (mp[vec2[k2].second] == 1)st.erase(vec2[k2].second);
			mp[vec2[k2].second]--;
			k2++;
		}
		if (st.empty()) {
			cout << -1 << endl;
			continue;
		}
		cout << *st.begin() << endl;
	}
}

Measured memory_bytes: 29404
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         int[][] grid = new int[N][M];
         for(int i=0; i < N; i++)
         {
            char[] boof = infile.readLine().toCharArray();
            for(int a=0; a < M; a++)
               if(boof[a] == '#')
                  grid[i][a] = 1;
         }
         int[][][] dp = new int[N][M][2];
         for(int i=0; i < N; i++)
            for(int a=0; a < M; a++)
               Arrays.fill(dp[i][a], -1);
         int res = dfs(0,0,grid[0][0],dp,grid)/2;
         res += grid[0][0];
         System.out.println(res);
      }
      public static int dfs(int x, int y, int color, int[][][] dp, int[][] grid)
      {
         if(dp[x][y][color] != -1)
            return dp[x][y][color];
         int N = grid.length;
         int M = grid[0].length;
         if(x == N-1 && y == M-1)
            return dp[x][y][color] = color;
         int res = Integer.MAX_VALUE;
         if(x+1 < N)
         {
            if(grid[x+1][y] == color)
               res = Math.min(res, dfs(x+1,y,color,dp,grid));
            else
               res = Math.min(res, 1+dfs(x+1,y,(color+1)%2,dp,grid));
         }
         if(y+1 < M)
         {
            if(grid[x][y+1] == color)
               res = Math.min(res, dfs(x,y+1,color,dp,grid));
            else
               res = Math.min(res, 1+dfs(x,y+1,(color+1)%2,dp,grid));
         }
         return dp[x][y][color] = res;
      }
   }

Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
int gx, gy;
int p;
int a, b, c, d;
int dp[100][100];
bool f[20][20][20][20];

int main(){
	cin >> n;
	while (n--){
		REP(i, 100)REP(j, 100)dp[i][j] = 0;
		REP(i, 20)REP(j, 20)REP(k, 20)REP(l, 20)f[i][j][k][l] = 0;
		cin >> gx >> gy;
		cin >> p;
		REP(i, p){
			cin >> a >> b >> c >> d;
			f[b][a][d][c] = 1;
			f[d][c][b][a] = 1;
		}
		dp[0][0] = 1;
		REP(i, gy + 1){
			REP(j, gx + 1){
				if (i == 0 && j == 0)continue;
				if (i == 0){
					if (f[i][j - 1][i][j] == 0)dp[i][j] += dp[i][j - 1];
				}
				else if (j == 0){
					if (f[i - 1][j][i][j] == 0)dp[i][j] += dp[i - 1][j];
				}
				else{
					if (f[i][j][i][j - 1] == 0){
						dp[i][j] += dp[i][j - 1];
					}
					if (f[i][j][i - 1][j] == 0){
						dp[i][j] += dp[i - 1][j];
					}
				}
			}
		}
		//REP(i, gy + 1){
		//	REP(j, gx + 1){
		//		cout << dp[i][j] << " ";
		//	}
		//	cout << endl;
		//}
		if (dp[gy][gx] == 0){
			cout << "Miserable Hokusai!" << endl;
		}
		else{
			cout << dp[gy][gx] << endl;
		}
	}
}

Measured memory_bytes: 1360