akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
#include<climits>
#include<cassert>
#include<cmath>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 110

using namespace std;

int V,E,ans;
vector<int> G[MAX];
int COST[MAX][MAX];
bool used[MAX];

void dfs(int node,deque<int>& deq,int sp){
  if(node >= 15)return;

  if(node >= 2){
    int tmp = [&]()mutable->int{
      int ret = 0;
      int mincost[node];
      rep(i,node) mincost[i] = IINF;
      //for(int& i : mincost)i = IINF;
      for(int i=0;i<node;i++){
	for(int j=i+1;j<node;j++){
	  int cost = COST[deq[i]][deq[j]];
	  if(cost==0)return -1;
	  mincost[i] = min(mincost[i],cost);
	  mincost[j] = min(mincost[j],cost);
	}
      }
      //for(int& i : mincost) ret += i;
      rep(i,node) ret += mincost[i]; 
      return ret;
    }();

    if(tmp != -1)ans = max(ans,tmp);
  }

  REP(i,sp,V){
    if(used[i])continue;
    if(G[i].size() < node)continue;
    used[i] = true;
    deq.push_back(i);
    dfs(node+1,deq,i+1);
    deq.pop_back();
    used[i] = false;
  }
}

int main()
{
  cin >> V >> E;
  rep(i,V)G[i].clear();
  rep(i,E){
    int u,v,f;
    cin >> u >> v >> f;
    u--,v--;
    G[u].push_back(v);
    G[v].push_back(u);
    COST[u][v] = COST[v][u] = f;
  }

  deque<int> deq;
  dfs(0,deq,0);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

int main(){
  int x,n,ans=0,now=1e9,past,tmp;
  cin>>x>>n;
  set<int> p;
  for(int i=0;i<n;i++){cin>>tmp;p.insert(tmp);}
  for(int i=101;i>=0;i--){
    past=now;
    if(p.count(i))continue;
    now=abs(x-i);
    if(now<=past)ans=i;
  }
  cout<<ans<<endl;
}


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

ll H;

ll rec(ll x, ll cnt) {
    if (x == 1) return cnt+1;
    else {
        return rec(x/2, cnt+1);
    }
}

int main() {
    cin >> H;

    ll a = rec(H, 0);

    
    cout << (ll)pow(2, a) - 1 << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
/*int num[4], n, m;
int main()
{
    memset(num, -1, sizeof(num));
    cin >> n >> m;
    while (m--)
    {
        int s, c;
        cin >> s >> c;
        if (num[s] == -1)
            num[s] = c;
        else if (num[s] != c)
        {
            //cout << num[s] << "-" << c << endl;
            cout << -1;
            return 0;
        }
    }
    if (n > 1 and num[1] == 0)
    {
        cout << -1;
        return 0;
    }
    if (num[1] == -1 and n>1) num[1] = 1;
    for (int i = 1; i <= n; i++)
        if (num[i] == -1)num[i] = 0;
    for (int i = 1; i <= n; i++)
    {
        cout << num[i];
    }
}*/
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 100005;
int n, m, k, a, b;
int p[MX], d[MX]; //p[] will at last give us the total connected nodes with i, d gives us the num of direct connection friendship or blockship.
int find(int x) { return (p[x] < 0 ? x : p[x] = find(p[x])); } //find as the name suggests finds parent node and returns connected leaves in graph
void uni(int x, int y) {
    x = find(x); y = find(y);
    if (x != y) {
        if (p[x] > p[y]) swap(x, y);
        p[x] += p[y]; //increasing the number of leaves in parent node, parent is the larger number of new graph.
        p[y] = x; //this helps find function by assigning parent node to other connected node.
    }
}
int main() {
    cin >> n >> m >> k;
    fill(p, p + n, -1);
    rep(i,m)
    {
        cin >> a >> b;
        a--; b--;
        d[a]--; d[b]--; // counting friends.
        uni(a, b);
    }
    rep(i,k)
    {
        cin >> a >> b;
        a--; b--;
        if (find(a) == find(b)) {
            d[a]--; // adding blockships.
            d[b]--;
        }
    }
    rep(i,n)
    { 
        printf("%d%c", -p[find(i)] + d[i] - 1, i == n - 1 ? '\n' : ' '); 
    }
}


Measured memory_bytes: 1664
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

 int i=0,j,k,b,n,m,g,kn[100],km[15],sg[15],kg[32768],fr[32768][15],bn[32768],e[16],ans[15];
 double ti[32768][15],t;
 int main() {
  for (j=1;j<65536;j*=2) e[i++]=j;
  for (j=0;j<32768;j++) for (i=0,bn[j]=0;i<15;i++) { ti[j][i]=999999999; if (( j & e[i])>0) bn[j]++;}
  cin >> n;
  for (i=0;i<n;i++) {
	  cin >> kn[i] >> km[i] >> g; sg[i]=g*20; 
      for (j=0;j<n;j++) ti[e[i]][j]=0;
  }
  for (i=0;i<e[n];i++) { kg[i]=0;
       for (j=0;j<n;j++) if ((i & e[j])>0) kg[i]+=sg[j];
  }
  for (i=0;i<n;i++) {
	  for (j=1;j<e[n];j++) {
		  if (bn[j]!=i+1) continue;
		  for (k=0;k<n;k++) {
			  if ((j & e[k])!=0) continue;
			  for (b=0;b<n;b++) {
				  if ((j & e[b])==0) continue;
				  t=ti[j][b]+(abs(km[k]-km[b])*(double)(70+kg[j])/2000);
				  if (ti[j | e[k]][k]>t) { ti[j | e[k]][k]=t; fr[j | e[k]][k]=b; }
			  }
		  }
	  }
  }
 t=999999999;
 for (i=0;i<n;i++) if (ti[e[n]-1][i]<t) { t=ti[e[n]-1][i]; g=i;}
 for (i=n-1,j=e[n]-1;i>=0;i--) { ans[i]=kn[g]; k=g; g=fr[j][g]; j-=e[k]; }
 for (i=0;i<n;i++) { cout << ans[i]; if (i<n-1) cout << ' ';}
 cout << endl;
 return 0;
 }

Measured memory_bytes: 7176
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 1e9
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
#define pb push_back
#define all(s) s.begin(),s.end()
#define pie 3.14159265358979323846
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define frr(i,a,b) for(ll i=b-1;i>=a;i--)
#define gcd __gcd
#define con continue
#define pii pair<ll,ll>

signed main(){
    ll tt=1;
    //cin>>tt;
    while(tt--){
         ll n,ans=0,a,b,fans=0;cin>>n;
         for(ll i=0;i<n;i++){
            cin>>a>>b;
            if(a==b)ans++;
            else ans=0;
            if(ans>=3)fans=1;
         }
         if(fans)cout<<"Yes\n";
         else cout<<"No\n";
    }
}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  8 21:12:35 2019

@author: over-
"""

N=int(input())
A=dict()
x=dict()
y=dict()
for i in range(1,N+1):
    A[i]=int(input())
    x[i]=dict()
    y[i]=dict()
    for j in range(A[i]):
        a1,a2=map(int,input().split())
        x[i][j+1]=a1
        y[i][j+1]=a2

C=2**N
ans=0
for c in range(C):
    honest=[]
    unkind=[]
    B='{:0b}'.format(c)
    B='0'*(N-len(B))+B
    bool=True
    for i in range(N):
        if int(B[i])==0:
            honest.append(i+1)
        else:   
            unkind.append(i+1)
        
    for k in range(1,N+1):
        if k in honest:
            for j in range(A[k]):
                if y[k][j+1]==1:
                    if x[k][j+1] in unkind:
                        bool=False
                else:
                    if x[k][j+1] in honest:
                        bool=False
    if bool: 
        if len(honest) > ans:
            ans= len(honest)
                        
print(ans)        
                        


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

int main(){
    int i,j,l,r;
    cin >> l >> r;
    int mod[2019];
    for(i = 0; i < 2019; i++){
        mod[i] = 0;
    }
    int count = 0;
    for(i = l; i <= r; i++){
        mod[i % 2019] = 1;
        count++;
        if(count >= 2019) break;
    }
    //int length = r - l + 1;
    //int stop = min(length,2019);
    int hoge = 2018;
    for(i = 0; i < 2018; i++){
        for(j = i+1; j < 2019; j++){
            if(mod[i] && mod[j])hoge = min(hoge, (i * j) % 2019);
        }
    }

    cout << hoge << endl;
  //cout << mod[4];
  //cout << mod[5];
}

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

typedef long long ll;

int main() {
    int n;
    ll x;
    cin >> n >> x;
    ll r = 0;
    vector<ll> as(n);
    for(int i=0; i<n; i++){
        cin >> as[i];
        r += as[i];
    }

    for(int magic=1;;magic++) {
        bool out = true;
        ll tmp = 0;
        ll last = as[n-1];
        for(int i=n-1; i>0; i--) {
            if(as[i-1]<as[i]) {
                as[i] = as[i-1];
                out = false;
            }
            tmp += as[i];
        }
        if(last<as[0]) {
            as[0] = last;
            out = false;
        }
        tmp += as[0];
        r = min(r, tmp + x * magic);
        if(out) break;
    }
    cout << r << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll mns;
	ll an=b+c;//cout<<an<<endl;
	ll bn=a+c;//cout<<bn<<endl;
	ll cn=a+b;//cout<<cn<<endl;
	if(a<b)
	{
		if(k%2==1)
		{
			mns=an-bn;//cout<<mns<<endl;
			if(mns>=1e18)
				cout<<"Unfair"<<endl;
			else
				cout<<mns<<endl;
			exit(0);
		}
		else if(k%2==0&&k!=0)
		{
			mns=0-(an-bn);
			cout<<mns<<endl;
			exit(0);
		}
		if(k==0)
		{
			mns=a-b;//cout<<mns<<endl;
			if(mns>=1e18)
				cout<<"Unfair"<<endl;
			else
				cout<<mns<<endl;
			exit(0);
		}
	}
	else if(a>b)
	{
		if(k%2==1)
		{
			mns=an-bn;//cout<<mns<<endl;
			if(mns>=1e18)
				cout<<"Unfair"<<endl;
			else
				cout<<mns<<endl;
			exit(0);
		}
		else if(k%2==0&&k!=0)
		{
			mns=0-(an-bn);
			cout<<mns<<endl;
			exit(0);
		}
		if(k==0)
		{
			mns=a-b;//cout<<mns<<endl;
			if(mns>=1e18)
				cout<<"Unfair"<<endl;
			else
				cout<<mns<<endl;
			exit(0);
		}
	}
	else if(a==b)
	{
		cout<<0<<endl;
		exit(0);
	}
	return 0;
}

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

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  REP(i, 0, N) REP(j, i + 1, N) {
    swap(A[i], A[j]);

    bool ok = true;
    REP(k, 0, N - 1) {
      ok = ok && A[k] < A[k + 1];
    }
    if (ok) {
      cout << "YES" << endl;
      return 0;
    }

    swap(A[i], A[j]);
  }

  cout << "NO" << endl;
}

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

typedef long long ll;
const double pi = acos(-1);

int main(){
  double a,b,x; cin >> a >> b >> x;
  
  if( a*a*b <= 2*x){ 
    double res = atan2(2.0*(a*a*b-x),a*a*a);
    cout << fixed << setprecision(10) << (double)(180.0*res)/pi <<endl;}
  else{
    double res = atan2(a*b*b,2*x);
    cout << fixed << setprecision(10) << (double)(180.0*res)/pi << endl;}
  
  return 0;
}

Measured memory_bytes: 256
import math

def main():
    N, M = list(map(int, input().split(' ')))
    s = min(math.ceil(math.sqrt(M)), M//N)
    ret = []
    while s > 0:
        if M%s == 0:
            a = M//s
            ret.append(a)
            ret.append(s)
        s -= 1
    print(max([s for s in ret if s <= M//N]))



if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      	int k  = sc.nextInt();
        String s = sc.next();
      	String t = "";
      
      	if (s.length() <= k){ 
            System.out.println(s);
        }else{
          	t = s.substring(0,k);
            System.out.println(t+"...");          
        }
    }
}

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

#define lol long long

int main() {

	lol n;
	cin >> n;

	bool s[100];
	for (int i = 0; i < 100; i++) {
		s[i] = false;
	}

	if (n == 0) {
		cout << "0";
		return 0;
	}

	int cnt = 0;
	while (1) {

		if (abs(n) % 2 == 1) {
			s[cnt] = true;
			n = ((n-1) / -2);
			cnt++;
		}
		else {
			s[cnt] = false;
			n = (n / -2);
			cnt++;
		}

		if (n==0) break;
	}

	bool flag = false;

	for (int i = 99; i >= 0; i--) {
		if (flag) {
			if (!s[i]) cout << "0";
		}
		if (s[i]) {
			cout << "1";
			flag = true;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

struct BIT{
	int N;
	vector<int> bit;
	BIT(int n){		//nは区間幅!!!
		N=n;
		bit.assign(n+1,0);
	}
	BIT(){}
	void init(int n){
		N=n;
		bit.assign(n+1,0);
	}
	int sum(int i){		//i個の和a[0]+..a[i-1]
		int s=0;
		while(i>0){
			s+=bit[i];
			i-=(i&-i);
		}
		return s;
	}
	int val(int i){	//return a[i]	(0-ind)
		return sum(i+1)-sum(i);
	}
	void add(int i,int x){	//a[i]+=x (0-indexed)
		i++;
		while(i<=N){
			bit[i]+=x;
			i+=(i&-i);
		}
	}
}bit;

int N;
int V;
const int MN = 40010;
double A[MN],B[MN],C[MN];
using P = pair<double,double>;
P p[MN];
int ox[MN];
int count(double t){
	vector<P> vs;
	rep(i,N){
		double x = p[i].fs, y = p[i].sc;
		vs.pb(P(t*x-y,ox[i]));
	}
	sort(all(vs));

	bit.init(N);

	int cnt = 0;

	rep(i,N){
		int x = vs[i].sc;
		cnt += i - bit.sum(x);
		bit.add(x,1);
	}
	return cnt;
}

double solve(){
	rep(i,N){
		p[i].fs = -A[i]/B[i];
		p[i].sc = C[i]/B[i];
	}
	vector<double> xs;
	rep(i,N){
		xs.pb(p[i].fs);
	}
	sort(all(xs));
	rep(i,N) ox[i] = lower_bound(all(xs),p[i].fs) - xs.begin();

	double ub = 1e9, lb = -1e9;
	rep(tt,100){
		double t = (ub+lb)/2;
		if(count(t)>=(V+1)/2) lb = t;
		else ub = t;
	}
	return -ub;
}
int main(){
	cin>>N;
	V = N*(N-1)/2;
	rep(i,N) cin>>A[i]>>B[i]>>C[i];
	printf("%.12f ",solve());
	rep(i,N) swap(A[i],B[i]);
	printf("%.12f\n",solve());
}


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

const int MAX = 100;
int main() {
	int N, x, y;
	pair<int, int> red[MAX], blue[MAX];
	cin >> N;
	for (int i = 0;i < N;i ++) {
		cin >> x >> y;
		red[i] = make_pair(x, y);
	}
	for (int i = 0;i < N;i ++) {
		cin >> x >> y;
		blue[i] = make_pair(x, y);
	}
	sort(red, red+N); // ソート
	sort(blue, blue+N); // 忘れずに
	int redCheck = 0; // 今どの赤まで確かめたか
	int blueCheck = 0; // 今どの青まで確かめたか
	pair<int, int> del; // どの赤とペアを組むことにしたか記憶用
	int sum = 0; // ペア数
	for (int i = 0;i < 2 * N;i ++) {
		if (red[redCheck].first == i) { // 赤が連続したなら暫く無視
			redCheck ++;
		}
		if (blue[blueCheck].first == i) { // 青が出てきたら、今まで出てきた赤とペアを組みたい！
			del = make_pair(-1, 0);
			for (int j = 0;j < redCheck;j ++) {
				if (del.first < red[j].second && red[j].second < blue[blueCheck].second) { // よりy座標が高い赤とペアを組む
					del.first = red[j].second;
					del.second = j;
				}
			}
			if (del.first >= 0) { // 組めるペアが存在したら
				red[del.second].second = -1; // その赤を消去
				sum ++; // ペア数追加！
			}
			blueCheck ++;
		}
	}
	cout << sum;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、座標0からx順にみていくとする
この時、ある座標までが全部紅色でその次が青色ならば、明らかにその青色はペアを作るべき
(そこでペアを作らず他の青とペアを作っても、他の青をペアにせずその青とペアを作ってもペア数は同値
だけど他のペアを作れる青が無ければペア数が1個減ってしまう)
で、この時最も自分のとれる中でy座標の高い赤とペアを作れば無駄が少ない
これを最後まで回せば答えが出るね
うっかり既に取った赤をもう一度取ったりしないように実装には気を付けて！
O(N^2)
*/

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

using namespace std;

int main()
{
	string s="";
	int k=0;
	cin >> k;
	cin >> s;
	int cnt=0;
	for (int i=0; i<s.size()-2; i++)
	{
		if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
		{
			cnt++;
		}
	}
	cout << cnt;
	return 0;
}


Measured memory_bytes: 256
/*
____    ____ .___________.
\   \  /   / |           |
 \   \/   /  `---|  |----`
  \      /       |  |     
   \    /        |  |     
    \__/         |__|     
                          
 */


#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<iomanip>
#define ll long long
#define mod 1000000007
using namespace std;
const int INF = 2e9 + 1;


/*---------------Graph Class---------*/
class graph
{
private:
	ll novert;
	ll noedges;
	vector< vector<ll> > adjlist;
public:
	graph(ll n,ll m)
	{
		novert=n;
		noedges=m;
		adjlist.resize(n+1);	
	}
	
	void addedge(ll u,ll v)
	{
		//bidirectional
		adjlist[u].push_back(v);
		adjlist[v].push_back(u);	
	}
	
	void dfsutil(ll initvert,vector<bool>& visited,ll lastvert=-1)
	{
		if(lastvert==initvert)
		{
			//do something
		}
		visited[initvert]=true;
		for(auto itr:adjlist[initvert])
		{
			if(!visited[itr])
			{	
			}	
		}	
	}	
};
/*-----------------End of graph----------------*/





int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

string w;
cin>>w;
unordered_map<char,ll> mp;
for(auto itr:w)
{
	auto f=mp.find(itr);
	if(f==mp.end())
	{
		mp[itr]=1;
	}
	else
	{
		mp[itr]++;
	}
}

for(auto itr:mp)
{
	if(itr.second%2==1)
	{
		cout<<"No"<<endl;
		return 0;
	}
}

cout<<"Yes"<<endl;

return 0;
}


Measured memory_bytes: 3600
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b = sc.nextInt()
  val result = if (a <= 0 && 0 <= b) {
    "Zero"
  } else if (0 < a || (b - a + 1) % 2 == 0) {
    "Positive"
  } else {
    "Negative"
  }
  println(result)
}


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

struct dat {
  long long n, l;
};

long long n, q, lim = 100000;
vector<long long> v, w, res;
vector<vector<long long>> dp;
vector<vector<dat>> query;

void solve();
void dfs(int now, int dep);

int main() {
  cin >> n;
  v.resize(n);
  w.resize(n);
  for (int i = 0; i < n; ++i) cin >> v[i] >> w[i];
  cin >> q;
  query.resize(n + 1);
  for (int i = 0; i < q; ++i) {
    long long vn, li;
    cin >> vn >> li;
    query[vn].push_back({i, li});
  }
  dp.assign(10, vector<long long>(lim + 1, 0));
  solve();
  for (int i = 0; i < q; ++i) cout << res[i] << endl;
  return 0;
}

void solve() {
  res.assign(q, 0);
  dfs(1, 0);
}

void dfs(int now, int dep) {
  if (now > n) return;
  if (dep == 9)
    for (int i = 1; i <= lim; ++i) dp[dep][i] = max(dp[dep][i], dp[dep][i - 1]);
  if (dep < 9) {
    dp[dep + 1] = dp[dep];
    for (int i = w[now - 1]; i <= lim; ++i)
      dp[dep + 1][i] =
          max(dp[dep + 1][i], dp[dep][i - w[now - 1]] + v[now - 1]);
    vector<long long> vm = dp[dep + 1];
    for (int i = 1; i <= lim; ++i) vm[i] = max(vm[i - 1], vm[i]);
    for (auto qu : query[now]) res[qu.n] = vm[qu.l];
  } else {
    using P = pair<long long, long long>;
    vector<P> lst;
    lst.emplace_back(0, 0);
    long long d = dep, x = now;
    while (x >= (1 << 9)) {
      int len = lst.size();
      for (int i = 0; i < len; ++i)
        lst.emplace_back(lst[i].first + w[x - 1], lst[i].second + v[x - 1]);
      x >>= 1;
    }
    for (auto qu : query[now]) {
      long long nres = dp[9][qu.l], nl = qu.l;
      for (auto p : lst)
        if (p.first <= nl) nres = max(nres, dp[9][nl - p.first] + p.second);
      res[qu.n] = nres;
    }
  }
  dfs(now * 2, dep + 1);
  dfs(now * 2 + 1, dep + 1);
}


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

typedef pair<int, int> P;

struct UnionFind {
  vector<int> par, sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; i++) par[i] = i;
  }

  int find(int x) {
    return (x == par[x] ? x : par[x] = find(par[x]));
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) return;

    if (sizes[x] < sizes[y]) swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];
  }

  bool same(int x, int y) {
    return (find(x) == find(y));
  }

  int size(int x) {
    return sizes[find(x)];
  }
};

struct Edge {
  int a, b, cost;

  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

struct Graph {
  int n;
  vector<Edge> es;

  // クラスカル法
  int kruskal() {
    sort(es.begin(), es.end());

    UnionFind uf(n);
    int min_cost = 0;
    for (int i = 0; i < es.size(); i++) {
      Edge& e = es[i];
      if (!uf.same(e.a, e.b)) {
        min_cost += e.cost;
        uf.unite(e.a, e.b);
      }
    }

    return min_cost;
  }
};

int main() {
  int N;
  cin >> N;
  P x[N], y[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i].first >> y[i].first;
    x[i].second = y[i].second = i;
  }

  // 最小全域木を求めるのに辺が多すぎるので、必要な辺だけを残す
  sort(x, x + N), sort(y, y + N);

  Graph g;
  g.n = N;
  Edge e;
  for (int i = 0; i < N - 1; i++) {
    e.a = x[i].second, e.b = x[i+1].second, e.cost = x[i+1].first - x[i].first;
    g.es.push_back(e);
    e.a = y[i].second, e.b = y[i+1].second, e.cost = y[i+1].first - y[i].first;
    g.es.push_back(e);
  }

  cout << g.kruskal() << endl;
  return 0;
}


Measured memory_bytes: 6388
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
#define ll long long
using namespace std;
int main(){
	long long n;
	cin >> n;
	vector<long long> a(n);
	for(int i = 0; i < n; i++){
		cin >> a.at(i);
	}
	long long max;
	long long ans = 0;
	max = a.at(0);
	for(int i = 0; i < n; i++){
		if(max > a.at(i)){
			ans += max - a.at(i);
			a.at(i) = max;
		}
		else {
			max = a.at(i);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4796
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

ll a,b;

vector<ll>v;

const int N=1e6+5;

bool take[N];

int main()
{
    cin >> a >> b;
    for (ll i=1;i*i<=a;i++)
    {
        if (a%i==0)
        {
            if (b%i==0)v.pb(i);
            if (a/i!=i&&b%(a/i)==0)v.pb(a/i);
        }
    }
    sort(v.begin(),v.end());
    vector<ll>ans;
    for (auto X:v)
    {
        bool ok=1;
        for (auto Y:ans)
        {
            if (Y==1)continue;
            if (X%Y==0){ok=0;break;}
        }
        if (ok)ans.pb(X);
    }
    cout << ans.size() << endl;
    return 0;
}


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

int main() {
    FILE * fi, * fout;
    int a,b,c;
    //fi = fopen("A.in" ,"r");
    //fout = fopen("A.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%d%d%d" ,&a,&b,&c);
    if((a*100+b*10+c)%4==0)
      fprintf(fout,"YES\n");
    else
      fprintf(fout,"NO\n");
    //fclose(fi);
    //fclose(fout);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int x=0,f=1;
	while(c<'0'||c>'9'){ if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
int n,x,a[2002],mx[2002][2002];
long long ans;
int main(){
	n=read(),x=read();
	for(int i=0;i<n;++i) a[i]=read(),ans+=a[i];
	for(int i=0;i<n;++i){
		mx[i][0]=a[i];
		for(int len=1;len<n;++len)
			mx[i][len]=min(mx[i][len-1],a[(i+len)%n]);
	}
	for(int len=1;len<n;++len){
		long long tmp=0;
		for(int j=0;j<n;++j){
			tmp+=mx[j][len];
		}
		ans=min(ans,tmp+1ll*len*x);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 16000
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>	
using namespace std;
typedef long long ll;
#define bay_bay return 0;
#define fori(n) for(int i=0;i<n;++i)
#define for1(n) for(int i=1;i<=n;i+=3)
#define all(v) ((v).begin()), ((v).end())	
#define sz(v) v.size()
#define endl "\n"
constexpr auto EPS = 1e-9;
#define ff fflush(stdout);
const ll Mod = 1e9 + 7;
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
void GOAT()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
#endif
}

int main()
{
	//GOAT();
	double n, m, ans = 0.0;
	cin >> n >> m;
	vector<double>v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
		ans += v[i];
	}
	int cnt = 0;
	double can = 1.0 / (4.0 * m);
	for (int i = 0; i < n; i++)
	{
		if (v[i] / ans >= can)cnt++;
	}
	if (cnt >= m)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

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

  cout << a*a << endl; 

}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var k = cin.nextInt();

            var ans = 1;
            for (int i = 0; i < n; i++)
            {
                if(ans < k)
                {
                    ans *= 2;
                }
                else
                {
                    ans += k;
                }
            }
            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayString(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = next();
            }
            return Array;
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13140
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		int[][] p = new int[n][2];
		for(int i=0; i<n; i++){
			p[i][0] = sc.nextInt();
			p[i][1] = sc.nextInt();
		}
		
		for(int i=0; i<n; i++){
			if(p[i][0] >= h && p[i][1] >= w){
				ans++;
			}
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 26836
#include <bits/stdc++.h>
/*#ifndef LOCAL_RUN
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("fast-math")
    #pragma GCC target("avx2,tune=native")
#endif*/
#define X first
#define Y second
using namespace std;

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

const int N = 2e5 + 228;

ll dp[N], arr[N];

int main()
{
    #ifdef LOCAL_RUN
        freopen("input.txt", "r", stdin);
    //#else
        //freopen("tickets.in", "r", stdin);
        //freopen("tickets.out", "w", stdout);
    #endif
	ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    for (int i = 2; i <= n; i++) {
        ll mn = LLONG_MAX;
        for (int j = max(1, i-k); j < i; j++)
            mn = min(mn, dp[j] + abs(arr[i] - arr[j]));
        dp[i] = mn;
    }
    cout << dp[n];

    return 0;
}

// 272472LF


Measured memory_bytes: 5172
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
)

func main() {
	sc := NewScanner()

	x := sc.NextInt()
	k := sc.NextInt()
	x--

	min := k - x
	mx := k + x
	for i := min; i < mx; i++ {
		fmt.Printf("%v ", i)
	}
	fmt.Printf("%+v\n", mx) // output for debug
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    sort(A.begin(), A.end());
    auto f = [&](ll tar, ll a) -> ll{
        ll l = -1, r = N;
        while(r - l > 1){
            ll m = (r + l) >> 1;
            if(a * A[m] <= tar){
                if(a < 0) r = m;
                else l = m;
            }
            else{
                if(a < 0) l = m;
                else r = m;
            }
        }
        if(a < 0) return N - r;
        else return r;
    };

    ll l = -LINF, r = LINF;
    while(r - l > 1){
        ll m = (l + r) >> 1;
        ll cnt = 0;
        REP(i,N){
            cnt += f(m, A[i]);
            if(A[i] * A[i] <= m) cnt--;
        }
        if(cnt / 2 >= K) r = m;
        else l = m;
    }
    cout << r << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

const ll inf=1e9+7;

ll mult(ll n,ll m){//n^m%infを求める
    if(m==1){
        return n%inf;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%inf;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%inf;
    }
}

typedef pair<int,int> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string n;
    cin>>n;
    if(n[1]==n[2]&&(n[0]==n[1]||n[2]==n[3])){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 384
abc = input()
abc_list = abc.split(" ")
a = int(abc_list[0])
b = int(abc_list[1])
c = int(abc_list[2])
yakusu = 0
for x in range(a,b + 1):
    if c % x == 0:
        yakusu += 1
print(yakusu)


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;



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

    ll h; cin >> h;
    ll attack = 1;
    ll ans = 0;

    while(h > 0){
        h /= 2;
        ans += attack;
        attack *= 2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    vp a(n);
    rep(i, n)
    {
        int x, b;
        cin >> x >> b;
        a[i] = {b, x};
    }
    sort(a.begin(), a.end());
    int t = 0;
    bool ok = true;
    rep(i, n)
    {
        t += a[i].second;
        ok = ok && t <= a[i].first;
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 4812
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0}; 
int dy[4] = {0, 1, 0, -1}; 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N, M; cin >> N >> M; 
	long long A[1010], B[1010], C[1010], D[1010], E[1010], F[1010]; 
	for(int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i]; 
	for(int i = 0; i < M; i++) cin >> D[i] >> E[i] >> F[i]; 
	set<long long> x, y; 
	x.insert(-1e15); x.insert(1e15); 
	y.insert(-1e15); y.insert(1e15); 
	for(int i = 0; i < N; i++){
		x.insert(A[i]); x.insert(B[i]); y.insert(C[i]); 
	}
	for(int i = 0; i < M; i++){
		x.insert(D[i]); y.insert(E[i]); y.insert(F[i]); 
	}
	map<long long, int> Mx, My; 
	int idx = 0; 
	long long xx[3010], yy[3010]; 
	for(auto it = x.begin(); it != x.end(); it++){
		Mx[*it] = idx; xx[idx] = *it; idx ++; 
	}
	int Lx = idx; 
	idx = 0; 
	for(auto it = y.begin(); it != y.end(); it++){
		My[*it] = idx; yy[idx] = *it; idx ++; 
	}
	int Ly = idx; 
	long long Dx[3010] = {}; long long Dy[3010] = {}; 
	for(int i = 0; i < Lx - 1; i++) Dx[i] = xx[i+1] - xx[i]; 
	for(int i = 0; i < Ly - 1; i++) Dy[i] = yy[i+1] - yy[i]; 
	bool right[3010][3010] = {}; 
	bool left[3010][3010] = {}; 
	bool down[3010][3010] = {}; 	
	bool up[3010][3010] = {}; 
	for(int i = 0; i < N; i++){
		int a = Mx[A[i]]; int b = Mx[B[i]]; 
		int c = My[C[i]]; 
		for(int i = a; i < b; i++){
			up[i][c-1] = true; down[i][c] = true; 
		}
	}
	for(int i = 0; i < M; i++){
		int d = Mx[D[i]]; int e = My[E[i]]; 
		int f = My[F[i]]; 
		for(int i = e; i < f; i++){
			left[d][i] = true; right[d-1][i] = true; 
		}
	}
	bool can[3010][3010] = {}; 
	int Gx = lower_bound(xx, xx + Lx, 0LL) - xx; 
	Gx --; 
	int Gy = lower_bound(yy, yy + Ly, 0LL) - yy; 
	Gy --;
	queue<pair<int, int>> que; 
	que.push(make_pair(Gx, Gy)); 
	can[Gx][Gy] = true; 
	while(que.size()){
		pair<int, int> p = que.front(); 
		que.pop(); 
		int x = p.first; int y = p.second; 
		for(int i = 0; i < 4; i++){
			if(i == 0 && right[x][y]) continue; 
			if(i == 1 && up[x][y]) continue; 
			if(i == 2 && left[x][y]) continue; 
			if(i == 3 && down[x][y]) continue; 
			int nx = x + dx[i]; 
			int ny = y + dy[i]; 
			if(can[nx][ny] || nx < 0 || nx >= Lx || ny < 0 || ny >= Ly) continue; 
			que.push(make_pair(nx, ny)); 
			can[nx][ny] = true; 
		}
	}
	long long ans = 0LL; 
	for(int i = 0; i < Lx; i++){
		for(int j = 0; j < Ly; j++){
			if(!can[i][j]) continue; 
			if(Dx[i] > 10000000000 || Dy[j] > 10000000000){
				cout << "INF" << endl; return 0; 
			}
			ans += Dx[i] * Dy[j]; 
		}
	}
	cout << ans << endl; 
}

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

int main() {
  int n;
  cin >> n;
  char s[n];
  cin >> s;
  char checkChar[3] = {'A', 'B', 'C'};
  int checkI = 0;
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == checkChar[checkI]) {
      if (checkI == 2) {
        checkI = 0;
        count++;
      } else {
        checkI++;
      }
    } else {
      if (s[i] == 'A') checkI = 1;
      else checkI = 0;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,a[3010];
vector<int>G[3010];
int win[3010];
int dfs(int x){
    if(win[x]!=-1)return win[x];
    for(int i:G[x]){
        if(a[x]>a[i]){
            if(dfs(i)==0)return win[x]=1;
        }
    }
    return win[x]=0;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n-1){
        int u,v;
        cin>>u>>v;
        u--,v--;
        G[u].pb(v);
        G[v].pb(u);
    }
    fill(win,win+n,-1);
    rep(i,n)if(win[i]==-1)dfs(i);
    rep(i,n){
        if(win[i]==1)cout<<i+1<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3888
//
// Created by yamunaku on 2020/03/08.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    string s;
    cin >> s;
    int n = s.size();
    if(n % 2){
        CNO;
        return 0;
    }
    string hi = "hi";
    rep(i, n){
        if(s[i]!=hi[i%2]){
            CNO;
            return 0;
        }
    }
    CYES;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool cmp (int a,int b){
	return a>b;
}
int main (){
    int n,k,a[10005],ans=0;
    scanf ("%d%d",&n,&k);
    for (int i=1;i<=n;i++) scanf ("%d",&a[i]);
    sort (a+1,a+n+1,cmp);
    for (int i=1;i<=k;i++) ans+=a[i];
    printf ("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#define P pair<int,int>
#define PP pair<int,P>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;


int main() {
   
    int a,b;cin>>a>>b;
    cout << ((a<=8&&b<=8)?"Yay!":":(") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    int n,d,x,a[120];
    cin>>n>>d>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    int sum=0;
    
    for(int i=0;i<n;i++){
        for(int k=0;k<120;k++){
            if(k*a[i]+1<=d){
                sum+=1;
            }
        }
        
        
    }
    
    cout<<sum+x<<endl;
    
    
    
    
    
    return 0;
}








Measured memory_bytes: 256
#include <stdio.h>
int main()
{
   int i, j, n, S[100000], q, T[50000], key;
   int left, right, mid;
   int 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[i]);
    }
    
	for(key = 0; key < q; key++){
		left = 0;
		right = n;
		while (left < right){
			mid = (left + right) / 2;
			if (S[mid] == T[key]){ 
			count++;
			break;
			}else if(T[key] < S[mid]){
			right = mid;
			}else{
			left = mid + 1;
			}
		}
	}

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

Measured memory_bytes: 2280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define inf 10000000000
using namespace std;
using ll = long long;
int main()
{
    int h,a;
    cin >> h >> a;
    cout << ((h+a-1) / a) << endl;

}


Measured memory_bytes: 256
h, w = map(int, input().split())

if h == 1 or w == 1:
    print(1)
    exit()

q, r = divmod(h, 2)
q2, r2 = divmod(w, 2)

ans = (q + r) * (q2 + r2) + q * q2
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<cstring>
#include<math.h>
#define PI 3.14159265358979
using namespace std;
int main()
{
	double x,angle,a,b,h,m,n,maxn;
	cin>>a>>b>>h>>m;
	angle=5.5*m-30*h;
	x=angle*PI/180;
	double x2=cos(x);
//	cout<<x2<<endl;
	double sum=sqrt(a*a+b*b-2*a*b*x2);
	printf("%.20lf",sum);
} 

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

int main() {
    ll a, b, x;
    cin >> a >> b >> x;

    // メモ
    // 0-b までで出現する個数を 0-aまでで出現する個数で引く
    ll bCounter = b / x;
    ll aCounter = (a - 1) / x;
    if (a == 0) {
        cout << bCounter + 1 << endl;
    } else {
        cout << bCounter - aCounter << endl;
    }

    return 0;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    h1,m1,h2,m2,k=MI()
    T=(h2-h1)*60+(m2-m1)
    print(T-k)

main()


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

int main(){
    ll N; cin>>N;
    if(N<=9){
        cout<<N<<endl;
    }else if(N<=99){
        cout<<9<<endl;
    }else if(N<=999){
        cout<<9+N-99<<endl;
    }else if(N<=9999){
        cout<<909<<endl;
    }else if(N<=99999){
        cout<<909+N-9999<<endl;
    }else{
        cout<<90909<<endl;
    }
}

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

int main() {
    ll n,k;
    std::cin >> n>>k;
    vector<ll> a(n);

    vector<ll> sumb;
    
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    
    for (int i = 0; i < n; i++) {
        sumb.push_back(a[i]);
        for (int j = i+1; j < n; j++) {
            sumb.push_back(sumb.back()+a[j]);
        }
    }
    
    ll mask = 0;
    for (int j = 40; j >=0; j--) {
        ll tmp = 0;
        for (int i = 0; i < sumb.size(); i++) {
            if( (sumb[i] & (((ll)1<<j) | mask)) == (((ll)1<<j) | mask)) tmp++;
        }
        if(tmp>=k){
            mask |= ((ll)1<<j);
        } 
    }
    std::cout << mask << std::endl;
}


Measured memory_bytes: 6260