akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ll long long
#define int long long
#define ull unsigned long long
#define ld long double
#define sb __builtin_popcount
#define vi vector<int>
#define vc vector<char>
#define ii pair<int, int>
#define pq priority_queue<ii, vector<ii>, greater<ii>>
#define vii vector<ii>
#define sz(a) int((a).size())
#define f(a, b) for (int i = a; i < b; i++)
#define fr(a, b) for (int i = a - 1; i >= b; i--)
#define tr(x, m) for (auto x : m)
#define in(a, b) (b.find(a) != string::npos)
#define minin(a) *min_element(all(a))
#define maxin(a) *max_element(all(a))
#define X first
#define Y second
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) reverse(v.begin(), v.end())
#define unq(v) v.erase(unique(all(v)), v.end())
#define el "\n"
#define mx3(a, b, c) max(max(a, b), c)
#define mn3(a, b, c) min(min(a, b), c)
#define S(v) accumulate(all(v), (ll)0)
#define SP(n) cout.precision(n)
const ld PI = atan(1.0) * 4.0;
#define MOD = 1e9 + 7;
void start() {
    fio;
    SP(10);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
    start();
    int n;
    cin>>n;
    int d=n%10;
    set<int> a={2, 4, 5, 7, 9};
    if(d==3){
        cout<<"bon";
    }
    else if(a.find(d)!=a.end()){
        cout<<"hon";
    }
    else{
        cout<<"pon";
    }
    return 0;
}

Measured memory_bytes: 3616
import math


def main():

    num, goal = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]

    ans = 10 ** 10

    for i in range(2 ** num):
        toku_flg = list(map(int, list(bin(i)[2:])))
        toku_flg = [0 for i in range(num - len(toku_flg))] + toku_flg

        now_score = 0
        now_mondai = 0
        for i in range(num):
            if toku_flg[i] == 1:
                now_score += (i + 1) * 100 * data[i][0] + data[i][1]
                now_mondai += data[i][0]

        if now_score < goal:
            for i in range(num)[::-1]:
                if toku_flg[i] == 0:
                    if now_score + (i + 1) * 100 * (data[i][0] - 1) < goal:
                        break
                    nokori = goal - now_score
                    add_num = math.ceil(nokori / ((i + 1) * 100))
                    now_score += (i + 1) * 100 * add_num
                    now_mondai += add_num
                    break

        if now_score >= goal:
            if now_mondai < ans:
                ans = now_mondai

    print(ans)





if __name__ == '__main__':
    main()


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

using namespace std;

const int mod = 1000000007;

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

    long long ans = 1;
    for (int i = 1; i <= N; i++) {
        ans = (ans * i) % mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1]*(n+1)
    self.rnk = [0]*(n+1)
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]
  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if(x == y):
      return 
    if self.root[x] > self.root[y]:
      x, y = y, x
    self.root[x] += self.root[y]
    self.root[y] = x 
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)
  def Count(self, x): # xが属するグループのサイズを返す
    return -self.root[self.Find_Root(x)]
  def Members(self, x): # xが属するグループに属する要素をリストで返す
    return [i for i in range(self.n) if self.Find_Root(i)==self.Find_Root(x)]
  def Roots(self): # 全ての根の要素をリストで返す
    return [i for i, x in enumerate(self.root) if x < 0]
  def Group_Count(self): # グループの数を返す
    return len(self.Roots())


def kruskal(N, stw):
  # stw = [[s0, t0, w0], [s1, t1, w1], ..., [sn, tn, wn]]
  # stw: s: 始点, t: 終点, w: st間の重み
  # stwはwを小さい順にソートされたものとする
  # s, tを入れ替えたものはいれなくていい
  res = 0
  uf = UnionFind(N)
  for i in range(len(stw)):
    s, t, w = stw[i]
    if not uf.isSameGroup(s, t):
      uf.Unite(s, t)
      res += w
  return res

N = int(input())
ixy = []
for i in range(N):
  x, y = map(int, input().split())
  ixy += [[i, x, y]]

stw = []

ixy = sorted(ixy, key=lambda x:x[1])
for j in range(N-1):
  i, x, y = ixy[j]
  ii, xx, yy = ixy[j+1]
  stw += [[i, ii, min(abs(x-xx), abs(y-yy))]]

ixy = sorted(ixy, key=lambda x:x[2])
for j in range(N-1):
  i, x, y = ixy[j]
  ii, xx, yy = ixy[j+1]
  stw += [[i, ii, min(abs(x-xx), abs(y-yy))]]

stw = sorted(stw, key=lambda x:x[2])
print(kruskal(N, stw))


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  
  vector<int> a(n);
  rep(i, n) a[i] = i+1;
  map<vector<int>, int> mp;
  
  int num = 0;
  do {
    mp[a] = num;
    ++num;
  } while(next_permutation(a.begin(), a.end()));
  
  int ans = abs(mp[q] - mp[p]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5248
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N, D, X[212345], Y[212345];

int main() {

	cin >> N >> D;
	rep(i, N) cin >> X[i] >> Y[i];

	ll ans = 0;

	rep(i, N) {
		if (X[i] * X[i] + Y[i] * Y[i] <= D * D) ++ans;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int a[111];
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  REP(i,n){
    cin>>a[i];
  }
  int l=1;
  ll sm=0;
  REP(i,n-1){
    if(a[i]==a[i+1]){
      l++;
      if(i==n-2){
        sm+=l/2;
      }
    }else{
      sm+=l/2;
      l=1;
    }
  }
  P(sm);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
char ss[20];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    scanf("%s",ss+1);int len=strlen(ss+1);
    bool bk=true;
    if(len&1)bk=false;
    for(int i=1;i<=len;i++)
    {
    	if(i&1)
    	{
    		if(ss[i]!='h'){bk=false;break;}
    	}
    	else if(ss[i]!='i'){bk=false;break;}
    }
    if(bk==true)puts("Yes");
    else puts("No");
    return 0;
}

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

const int maxn=1e5+10;
struct Node{
    int l,r;
}node[maxn];
int cmp(const Node a,const Node b){
    return a.r<b.r||(a.r==b.r&&a.l<b.l);
}
int n;
signed main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x,l;
        scanf("%d%d",&x,&l);
        node[i].l=x-l,node[i].r=x+l;
    }
    sort(node+1,node+n+1,cmp);
    int cur=-1e9;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(cur<=node[i].l){
            ans++;
            cur=node[i].r;
        }
        //printf("debug %d\n",cur);
    }
    printf("%d\n",ans);
    return 0;

}


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

#define INF 100000000000000

int main() {


  int64_t n;
  cin>>n;

  vector<int64_t> ope(n+1,INF);
  ope.at(0)=0;
  ope.at(1)=1;
  for(int i=2;i<=n;i++){
    int64_t ope1=INF,ope6=INF,ope9=INF;

    ope1 = ope.at(i-1)+1;

    int64_t wk=1;
    while(i-pow(6,wk)>=0){
      ope6 = min(ope6, ope.at(i-pow(6,wk))+1);
      wk++;
    }
      
    wk=1;
    while(i-pow(9,wk)>=0){
      ope9 = min(ope9, ope.at(i-pow(9,wk))+1);
      wk++;
    }  

    ope.at(i)=min(ope1,min(ope6,ope9));
  }

  cout<<ope.at(n)<<endl;

  return 0;
}


Measured memory_bytes: 4052
$cnt = 0
$g = []

def insertionSort(a, n, g)
	g.upto(n-1) do |i|
		v = a[i]
		j = i - g
		while j >= 0 && a[j] > v
			a[j+g] = a[j]
			j = j - g
			$cnt += 1
		end
		a[j+g] = v
	end
end

def shellSort(a, n)
	h = 1
	$g.push(h)
	
	loop do
		h = 3*h + 1
		break if h > n
		$g.push(h)
	end

	1.upto($g.size) do |i|
		insertionSort(a, n, $g[-i])
	end
end

n = gets.to_i
a = []
n.times do |i|
	a[i] = gets.to_i
end

shellSort(a, n)

puts $g.size
puts $g.reverse.join(" ")
puts $cnt
puts a.join("\n")

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

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

    int a, b, c;
    cin >> a >> b >> c;

    cout << min(a+b, min(b+c, c+a)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A+B+C<22) cout<<"win"<<endl;
  else cout<<"bust"<<endl;
}

Measured memory_bytes: 256
def main():
    K = int(input())

    x = 7 % K
    s = set()
    i = 1

    while True:
        # 割り切れる
        if x == 0:
            print(i)
            return

        # 割り切れない、無限ループ
        if x in s:
            print(-1)
            return

        s.add(x)
        x = (x * 10 + 7) % K
        i += 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 77888
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);
        String line1  = sc.nextLine();
        String[] line1sp = line1.split(" ");
        int[] A =  new int[n];
        for(int i = 0; i < n; i++) {
            A[i] = Integer.parseInt(line1sp[i]);
        }
        for(int i = 0; i < n; i++) {
            System.out.print(A[i]);
            if(i < n - 1) {
                System.out.print(" ");
            }else {
                System.out.println("");
            }
        }
        for(int i = 1; i < n; i++) {
            int v = A[i];
            int j = i - 1;
            while(j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j+1] = v;
            for(int x = 0; x < n; x++) {
            System.out.print(A[x]);
            if(x < n - 1) {
                System.out.print(" ");
            }else {
                System.out.println("");
            }
        }
        }
        
        
        
    }
 }
 


Measured memory_bytes: 33976
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		double n = sc.nextDouble();
		double x = sc.nextDouble();
		System.out.println(n/x);

		

	}


	static int lowerbond(long k, long[] data){		//kより小さい最小の値をdataの中から探し、返す二分探索
		int min = 0;
		int max = data.length-1;

		while(max-min >= 0){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid-1;
			}else{
				min = mid+1;
			}
		}
		return min;
	}









	class UnionFind{
		int[] parent;
		public UnionFind(int N){
			this.parent = new int[N];
			for(int i = 0; i < N;i++){
				parent[i] = i;
			}
		}
		public int root(int x){			//根要素を取得
			if(parent[x] == x){			//初期状態
				return x;
			}else{
				return parent[x] = root(parent[x]);    	//再帰によって根を取得
			}
		}
		public void unite(int x,int y){ 	//統合メソッド
			if(same(x,y)){					//同じ根なら終了
				return;
			}
			int xroot = root(x);
			int yroot = root(y);
			parent[xroot] = yroot;			//統合
			return;

		}

		public boolean same(int x,int y){			//根が同じか（同じグループに属しているか）を判定
			return(root(x) == root(y));
		}
	}

}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}



Measured memory_bytes: 26708
// 5/18 リベンジ
// ANT2-4-1. Expedition
// 類題
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LLP = pair<ll, ll>;
using Graph = vector<vector<int>>;

int main() {
    int N;
    cin >> N;
    vector<ll> a(N * 3);

    rep(i, N * 3) cin >> a[i];

    ll first[N + 1];
    ll latter[N + 1];

    priority_queue<ll, vector<ll>, greater<ll>> pque_first;
    priority_queue<ll> pque_latter;

    ll first_sum = 0;
    ll latter_sum = 0;

    // cout << "here?" << endl;

    rep(i, N) {
        pque_first.push(a[i]);
        first_sum += a[i];
    }
    for (int i = N; i <= 2 * N; i++) {
        first[i - N] = first_sum;

        if (pque_first.top() < a[i]) {
            first_sum += a[i];
            first_sum -= pque_first.top();
            pque_first.pop();
            pque_first.push(a[i]);
        }
    }

    // cout << "here?2" << endl;

    for (int i = 3 * N - 1; i >= 2 * N; i--) {
        pque_latter.push(a[i]);
        latter_sum += a[i];
    }
    for (int i = 2 * N - 1; i >= N - 1; i--) {
        // printf("i, i - N - 1, latter_sum = %d %d %d\n", i, i- N + 1, latter_sum);
        latter[i - N + 1] = latter_sum;

        if (pque_latter.top() > a[i]) {
            latter_sum += a[i];
            latter_sum -= pque_latter.top();
            pque_latter.pop();
            pque_latter.push(a[i]);
        }
    }

    // cout << "here?3" << endl;

    ll ans = first[0] - latter[0];
    for (int i = 1; i <= N; i++) {
        // printf("first[%d], latter[%d] = %d, %d\n", i, i, first[i], latter[i]);
        ans = max(ans, first[i] - latter[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 5876
#include<bits/stdc++.h>
using namespace std ;
#define rep(i , j , n) for(register int i = j ; i <= n ; i ++)
#define int long long 
int n ;
const int N = 2e5 + 10 ;
int a[N] , b[N] ;
const int S = 2e3 + 1 ;
const int M = 4e3 + 20 ;
int dp[M][M] ;
int fac[S << 2] ;
const int mod = 1e9 + 7 ;
int qpow(int x , int y) {
	int ans = 1 ;
	for( ; y ; y >>= 1 , x = x * x % mod) 
		if(y & 1) ans = ans * x % mod ;
	return ans ;
}
int inv(int x) {
	return qpow(x , mod - 2) ;
}
int C(int x , int y) {
	return fac[x] % mod * inv(fac[y]) % mod * inv(fac[x - y]) % mod ;
}
signed main() {
	ios :: sync_with_stdio(false) ;
	cin.tie(0) ;
	cout.tie(0) ;
	cin >> n ;
	fac[0] = 1 ;
	rep(i , 1 , S << 2) fac[i] = fac[i - 1] * i % mod ;
	rep(i , 1 , n) cin >> a[i] >> b[i] ;
	rep(i , 1 , n) ++ dp[S - a[i]][S - b[i]] ;
	rep(i , 1 , S << 1) rep(j , 1 , S << 1) {
		dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod ;
		dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod ;
	}
	int ans = 0 ;
	rep(i , 1 , n) (ans += dp[S + a[i]][S + b[i]]) %= mod ;
	rep(i , 1 , n) {
		ans = (ans - C(a[i] + b[i] + a[i] + b[i] , a[i] + a[i]) + mod) % mod ;
	}
	ans = (ans * inv(2)) % mod ;
	cout << ans << '\n' ;
	return 0 ;
}

Measured memory_bytes: 129664
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll n, m;
    cin >> n >> m;
    if (m < n)
        swap(n, m);
    ll odp = 0;
    if (n == 1)
    {
        if (m == 1)
            odp += 1;
        else
            odp += m - 2;
    }
    if (n >= 3)
        odp += (n - 2) * (m - 2);
    cout << odp;
    return 0;
}


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

int main() {
int n;
cin >>n;
vector<int>a(n);
for(int i=0;i<n;i++){
  cin >> a.at(i);
}
sort(a.begin(),a.end());
int ans =0;
int che =-1;
for(int i=0;i<n;i++){
  if(che<a.at(i)){
    ans++;
    che=a.at(i);
  }
}
cout << ans << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



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

  vector<pair<int,int>> order;
  REP(i,n){
    int a, id;
    cin >> a;
    id = i + 1;
    order.push_back(make_pair(a,id));
  }

  sort(ALL(order));

  for(auto x: order){
    cout << x.second << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 4216
import sys
for line in sys.stdin.readlines():
  l = [s for s in line.rstrip()]
  answer = 'd'
  for i in range(3):
    if l[i] == l[i+3] == l[i+6]:
      if l[i] == 'o':
        answer = 'o'
      elif l[i] == 'x':
        answer = 'x'
  for i in range(0,8,3):
    if l[i] == l[i+1] == l[i+2]:
      if l[i] == 'o':
        answer = 'o'
      elif l[i] == 'x':
        answer = 'x'
  if l[0] == l[4] == l[8] or l[2] == l[4] == l[6]:
    if l[4] == 'o':
      answer = 'o'
    elif l[4] == 'x':
      answer = 'x'
  print(answer)

Measured memory_bytes: 7576
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <climits>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    ll N;
    cin >> N;
    while(!(N == (int)sqrt(N + 0.5) * (int)sqrt(N + 0.5))){//誤差を防ぐ
        N--;
    }
    cout << N << endl;
    return 0;
}

Measured memory_bytes: 256
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/

vector<int> a;
bool check(int n, int cur, int k) {
	int c = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] <= cur) continue;
		c += (a[i] / cur);
		if (c > k) return false;
	}
	return c <= k;
}
void solve() {
	int n, k; cin >> n >> k;
	a.clear(); a.resize(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int mid, ans, lo = 1, hi = *max_element(a.begin(), a.end());
	ans = hi;
	while (lo <= hi) {
		mid = (lo + hi) / 2;
		if (check(n, mid, k)) {
			ans = mid; hi = mid - 1;
		}
		else lo = mid + 1;
	}
	cout << ans << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, m, i, j, k, maxx, x, y, xx, yy, d;
	int v[4][2] = { 1,0,0,1 ,-1,0,0,-1 };
	cin >> n >> m;
	vector<string> s(n);
	vector<vector<int>> dp(n, vector<int>(m, 1000000));
	maxx = 0;
	queue<pair<int, int>> q;
	for (i = 0; i < n; i++) {
		cin >> s[i];
		for (j = 0; j < m; j++) {
			if (s[i][j] == '#') {
				dp[i][j] = 0;
				q.push({ i,j });
			}
		}
	}

	while (!q.empty()) {
		x = q.front().first;
		y = q.front().second;
		q.pop();
		d = dp[x][y];

		for (i = 0; i < 4; i++) {
			xx = x + v[i][0];
			yy = y + v[i][1];
			if ((xx >= 0) && (xx < n) && (yy >= 0) && (yy < m) && (s[xx][yy] == '.') && (dp[xx][yy] > d + 1)) {
				dp[xx][yy] = d + 1;
				q.push({ xx, yy });
				maxx = max(maxx, d + 1);
			}
		}
	}

	cout << maxx << "\n";

	return 0;
}


Measured memory_bytes: 13568
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

const int MAXN = 100005;

int n,m,ans;
int cnt[MAXN];

bool mrk[MAXN];

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	mrk[1] = true;
	for (int i = 1;i <= n;i++)
		cnt[i] = 1;
	for (int u,v,i = 1;i <= m;i++)
	{
		cin >> u >> v;
		mrk[v] |= mrk[u];
		if (mrk[u] && cnt[u] == 1)
			mrk[u] = 0;
		cnt[u]--;
		cnt[v]++;
	}
	for (int i = 1;i <= n;i++)
		ans += mrk[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n;
    boolean[] p;

    void run(){
	p = new boolean[100000000];
	setP();
	while(sc.hasNext()){
	    int n = sc.nextInt();
	    if(n>=2){
		System.out.print(n+":");
		solve(n);
	    }
	}
    }

    void solve(int n){
	int i=2;
	while(n>1){
	    // ??????????????????????卒???属??????
	    if(n<p.length && p[n]){
		System.out.print(" "+n);
		n = n/n;
		continue;
	    }
	    // ??????????其????????卒???属??????????????????????????????
	    if(i>=p.length){
		System.out.print(" "+n);
		n = 1;
		continue;
	    }
	    // ?卒???属??則????????????
	    while(p[i] && n%i==0){
		n = n/i;
		System.out.print(" "+i);
	    }
	    if(i>2) i+= 2;
	    else i++;
	}
	System.out.println();
    }

    void setP(){
	Arrays.fill(p, true);
	p[0] = p[1] = false;
	for(int i=2; i<p.length; i++){
	    if(p[i])
		for(int j=i*2; j<p.length; j+=i)
		    if(p[j]) p[j] = false;
	}
    }
}
	    

Measured memory_bytes: 118516
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000000000000
#define mod 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
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;
}

signed main() {
	string s, t;
	cin >> s >> t;
	vector<int>a[30], b[30];;
	rep(i, s.size()) {
		a[s[i] - 'a'].push_back(i);
	}
	rep(i, s.size()) {
		b[t[i] - 'a'].push_back(i);
	}
	rep(i, 26) {
		for (int j = 1; j < a[i].size(); j++) {
			if (t[a[i][j]] != t[a[i][j - 1]]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	rep(i, 26) {
		for (int j = 1; j < b[i].size(); j++) {
			if (s[b[i][j]] != s[b[i][j - 1]]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 5108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    while(cin >> n >> m){
        if(n==0&&m==0){
            return 0;
        }
        vector<int> h(n),w(m),sh(n+1),sw(m+1);
        for(int i=0;i<n;i++){
            cin >> h[i];
            sh[i+1]=sh[i]+h[i];
        }
        for(int i=0;i<m;i++){
            cin >> w[i];
            sw[i+1]=sw[i]+w[i];
        }
        map<int,int> mp;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<=n;j++){
                mp[sh[j]-sh[i]]++;
            }
        }
        ll ans=0;
        for(int i=0;i<m;i++){
            for(int j=i+1;j<=m;j++){
                ans+=mp[sw[j]-sw[i]];
            }
        }
        cout << ans << endl;
    }
}


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

int main()
{
    int n,m,l;
    std::cin >> n >> m >> l;
    
    std::vector<std::vector<long> > mat1(n,std::vector<long>(m));
    std::vector<std::vector<long> > mat2(m,std::vector<long>(l));
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            std::cin >> mat1[i][j];
    for(int i=0;i<m;i++)
        for(int j=0;j<l;j++)
            std::cin >> mat2[i][j];
    
    std::vector<std::vector<long> > ans(n,std::vector<long>(l,0));
    for(int i=0;i<n;i++)
        for(int j=0;j<l;j++)
            for(int k=0;k<m;k++)
                ans[i][j] += mat1[i][k]*mat2[k][j];
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<l-1;j++)
            std::cout << ans[i][j] << " ";
        std::cout << ans[i][l-1] << std::endl;
    }
}


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

int main()
{
  ll n, m;
  cin >> n >> m;
  vector<ll> highNum(n);
  for(int i = 0; i < n; i++){
    cin >> highNum[i];
  }
  map<string, int> checkMp;
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    if(highNum[a-1]< highNum[b-1]){
      checkMp[std::to_string(a-1)] = 1;
    }
    else if (highNum[a - 1] > highNum[b - 1]){
      checkMp[std::to_string(b - 1)] = 1;
    }else{
      checkMp[std::to_string(a - 1)] = 1;
      checkMp[std::to_string(b - 1)] = 1;
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++)
  {
    if (checkMp.find(std::to_string(i)) == checkMp.end())
    {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 8604
#include<stdio.h>

int main(void){
	int n,m,x,a=0,b=0;
	scanf("%d %d %d",&n,&m,&x);
	for(;m>0;m--){
		scanf("%d",&n);
		if(n>x){
			a++;
		}
		else{
			b++;
		}
	}
	printf("%d\n",a<b?a:b);

return 0;
}


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

using namespace std;
int main(int argc, char **argv)
{
	int x;
    float numOfOdds;
    cin>>x;
    if(x % 2 == 0){
        numOfOdds = x /2;
    }
    else{
        numOfOdds = (x-1)/2;
        numOfOdds++;
    }
    cout<<numOfOdds/x;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////



int main(){fastio
    ll n;cin>>n;
    ll a[n+1];rep(i,1,n)cin>>a[i];
    ll ans=0;
    ll N=60;
    rep(i,0,N){
        ll p=(1ll<<i);
        
        ll ev=0,od=0;
        rep(j,1,n){
            if(a[j]&p)od++;
            else ev++;
        }
        //cout<<ev<<" "<<od<<endl;
        Add(ans,mod(mod(ev*od))*mod(p));
        //cout<<ans<<endl;
    }
    cout<<mod(ans)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using vi = std::vector<int>;
using vvi = std::vector<vi>;
using ll = long long;

///////////////////////////////////////////////////

int main()
{
    int N, K;
    std::cin >> N >> K;
    
    vi S(N+1);
    S[0] = 0;
    for (int i = 0; i < N; ++i)
    {
        int a;
        std::cin >> a;
        S[i+1] = (S[i] + a) % K;
    }

    std::map<int, vi> bucket;
    for (int i = 0; i <= N; ++i)
    {
        int si = (S[i] - i) % K;
        if (si < 0) si += K;
        bucket[si].push_back(i);
    }

    ll ans = 0;
    for (auto p : bucket)
    {
        const vi &bk = p.second;
        int nbk = bk.size();
        for (int l = 0, r = 0; l < nbk - 1; ++l)
        {
            for (r = std::max(l+1, r); r < nbk; ++r)
            {
                if (bk[r] - bk[l] >= K) break;
            }
            ans += r - l - 1;
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 22912
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
using namespace std;

const double PI=acos(-1);

int main(){
    int n, m, c;
    cin >> n >> m >> c;

    int b[20], a[20], cnt = 0;
    fill(a,a,0);
    fill(b,b,0);
    for(int i = 0; i <= n; i++){
        int sum = 0;
        for(int j = 0; j < m; j++){
            if(i==0){
                cin >> b[j];
            }else{
                cin >> a[j];
                sum += b[j]*a[j];
            }
        }

        if(i!=0 && sum+c > 0) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
void print(char str[],int a,int b){
    for(int i = a; i <= b; i++)  printf("%c",str[i]);
    printf("\n");
}
 
void replace(char str[],char p[],int a,int b){
    int p_length = b-a+1;
    for(int i = 0; i < p_length;i++) str[a+i] = p[i];
}
 
void reverse(char str[],int a,int b){
    int left = a,right = b;
    while(left < right){
        swap(str[left++],str[right--]);
    }
}
 
int main(){
    char str[1001],p[1001],order[8];
    int q,a,b;
    scanf("%s",str);
    scanf("%d",&q);
    for(int i = 0; i < q; i++){
        scanf("%s %d %d",order,&a,&b);
        switch(order[2]){
        case 'i':
            print(str,a,b);
            break;
        case 'v':
            reverse(str,a,b);
            break;
        case 'p':
            scanf("%s",p);
            replace(str,p,a,b);
            break;
        }
    }
}


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

vector<vector<int>> Hcandidates;
vector<vector<int>> Wcandidates;
vector<int> Helements;
vector<int> Welements;
vector<int> combination;
int count;
char c[6][7];
int H,W,K;
/*
void registercandidates(const vector<int>& v){
    for(int i : candidates)
    {
        for(int j = 0; j < W; j++)
        {
            
        }
    }
}*/

void Hnck(int offset, int k) {
    if(k == 0)
    {
        Hcandidates.push_back(combination);
        //registercandidates(combination);
        return;
    }
    for(int i = offset; i <= Helements.size() - k; i++)
    {
        combination.push_back(Helements[i]);
        Hnck(i+1, k-1);
        combination.pop_back();
    }
}

void Wnck(int offset, int k) {
    if(k == 0)
    {
        Wcandidates.push_back(combination);
        //registercandidates(combination);
        return;
    }
    for(int i = offset; i <= Welements.size() - k; i++)
    {
        combination.push_back(Welements[i]);
        Wnck(i+1, k-1);
        combination.pop_back();
    }
}

int main(void){
    // Your code here!
    
    scanf("%d %d %d",&H,&W,&K);
    count = 0;
    
    for(int i = 0; i < H; i++)
    {
        scanf("%s",c[i]);
    }
    
    for(int i = 0; i < H; i++) Helements.push_back(i);
    for(int i = 1; i <= H; i++)
    {
        Hnck(0,i);
    }
    
    for(int i = 0; i < W; i++) Welements.push_back(i);
    for(int i = 1; i <= W; i++)
    {
        Wnck(0,i);
    }
    /*
    printf("H candidates: \n");
    for(vector<int> vh : Hcandidates)
    {
        for(int j : vh)
        {
            printf("%d,",j);
        }
        printf("\n");
    }
    
    printf("W candidates: \n");
    for(vector<int> vw : Wcandidates)
    {
        for(int j : vw)
        {
            printf("%d,",j);
        }
        printf("\n");
    }*/
    
    for(vector<int> vh : Hcandidates)
    {
        for(vector<int> vw : Wcandidates)
        {
            int tempcount = 0;
            for(int i : vh)
            {
                for(int j : vw)
                {
                    if(c[i][j] == '#')
                        tempcount++;
                }
            }
            if(tempcount == K)
            {
                count++;
                /*
                printf("H candidates: \n");
                for(int j : vh)
                {
                    printf("%d,",j);
                }
                printf("\n");
                printf("W candidates: \n");
                for(int j : vw)
                {
                    printf("%d,",j);
                }
                printf("\n");
                */
            }
        }
    }
    
    printf("%d\n",count);
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,L,R,result = 0;
	cin >> N;
	
	for ( int i = 0; i < N; i++){
		cin >> L >> R;
		result += R - L + 1;
	}
	
	cout << result << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int n;
	while(~scanf("%d",&n)){
		int a[100005]={0};
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		int r=n/2,l=r-1;
		int ans=a[r]-a[l];
//		printf("%d %d\n",a[l],a[r]);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Longest Path
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)))) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            List<List<Integer>> g = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                g.add(new ArrayList<>());
            }

            for (int i = 0; i < M; i++) {
                int x = sc.nextInt() - 1;
                int y = sc.nextInt() - 1;

                g.get(y).add(x);
            }

            int[] dp = new int[N];

            for (int i = 0; i < N; i++) {
                solve(i, dp, g);
            }

            int max = Arrays.stream(dp).max().getAsInt();

            System.out.println(max);
        }
    }

    static int solve(int x, int[] dp, List<List<Integer>> g) {
        if (dp[x] != 0) {
            return dp[x];
        }

        for (Integer e : g.get(x)) {
            dp[x] = Math.max(dp[x], solve(e, dp, g) + 1);
        }

        return dp[x];
    }

}


Measured memory_bytes: 111068
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define MAX_V 200000

long long int INF = 100000000000000000LL;

struct edge{
	int to;
	long long int cost;
};

typedef pair<long long int, int> P; // firstは最短距離、secondは頂点の番号

vector<edge> G[MAX_V];
long long int d[MAX_V];

// 速さはO(|E|log|V|)

void shortest_path(int s, int V){ // Vは頂点数
	
	priority_queue<P, vector<P>, greater<P> > que;
	
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	que.push(P(0, s));
	
	while(!que.empty()){
		
		P p = que.top();
		que.pop();
		
		int v = p.second;
		
		if(d[v] < p.first){
			continue;
		}
		
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > e.cost + d[v]){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		} // 頂点への最小コストを更新
	}
}

int main(){
	
	int N;
	cin >> N;
	for(int i = 0; i < N - 1; i++){
		int index1, index2;
		long long int cost;
		cin >> index1 >> index2 >> cost;
		edge e1, e2;
		e1.to = index2;
		e2.to = index1;
		e1.cost = cost;
		e2.cost = cost;
		G[index1].push_back(e1);
		G[index2].push_back(e2);
	}
	
	int Q, K;
	cin >> Q >> K;
	
	shortest_path(K, N + 1);
	
	for(int i = 0; i < Q; i++){
		int x, y;
		cin >> x >> y;
		cout << d[x] + d[y] << endl;
	}
	
	return 0;
}



Measured memory_bytes: 13424
public class Main {

  private static void solve() {
    int T = ni();
    
    for (int t = 0; t < T; t ++) {
      int n = ni();
      int d = ni();

      int ret = n % 2 == 0 ? (d ^ 127) : d;
      ret += 127 * (n - 1);
      System.out.println(ret);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = System.getProperty("debug");
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = acos(-1) ;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"


int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0;
	string a,b;
	cin>>a>>b;
	l=b.size();
	ans=stoi(a)*pow(10,l)+stoi(b);
	x=sqrt(ans);
	//cout<<ans<<nw;
	if(x*x==ans)cout<<"Yes";
	else cout<<"No";

}


Measured memory_bytes: 3960
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		outer: while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();

			if (H > 300 || H < 0 || W > 300 || W < 0) {
				System.out.println("数値の有効範囲は1 <= H,W <= 300です");
				continue outer;
			}

			if (H == 0 && W == 0) {
				break;
			}

			for (int i = 1; i <= H; i++) {
				for (int j = 1; j <= W; j++) {
					if (i % 2 == 1) {
						if (j % 2 == 1) {
							System.out.print("#");
						} else {
							System.out.print(".");
						}
					} else {
						if (j % 2 == 1) {
							System.out.print(".");
						} else {
							System.out.print("#");
						}
					}
				}
				System.out.println();

			}
			System.out.println();

		}

	}
}



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

int check(int n){
  int aa=n%10;
  int bb=n/10 % 10;
  int cc=n/1000 % 10;
  int dd=n/10000 % 10;
  if(aa==dd&&bb==cc)return 1;
  else return 0;
}
int ans=0;
int main(){

  int a,b;
  cin>>a>>b;
  for(int i=a;i<=b;i++){
    ans+=check(i);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
n, k = [int(i) for i in input().split()]
h = []
for i in range(n):
    h.append(int(input()))
h.sort(reverse = True)
d = 10000000000
for i in range(n-k+1):
    if d > h[i] - h[i+k-1]:
        d = h[i] - h[i+k-1]
print(d)


Measured memory_bytes: 7440
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,a,b;
  cin>>n;
  a=n/100;
  n%=100;
  n%=10;
  b=n;
  if(a==b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "C"
string s, t;
string ans;
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    ans+=char('z'+1);
    cin>>s>>t;
    FFOR(i, 0, s.size()){
        if(i+t.size()-1>=s.size()) break;
        bool good=1;
        FFOR(j, 0, t.size()) if(s[i+j]!='?'&&s[i+j]!=t[j]){
            good=0;
            break;
        }
        if(good){
            string res=s;
            FFOR(j, 0, t.size()) res[i+j]=t[j];
            FFOR(j, 0, res.size()) if(res[j]=='?') res[j]='a';
            ans=min(ans, res);
        }
    }
    if(ans[0]==char('z'+1)) ans="UNRESTORABLE";
    cout<<ans;
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int main(){
    fcin;
    int n, m;
    cin >> n >> m;

    priority_queue<int> pq;
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        pq.push(x);
    }

    while(pq.size() and m--){
        int x = pq.top();
        pq.pop();
        pq.push(x/2);
    }

    ll ans = 0;
    while(pq.size()){
        ans += pq.top();
        pq.pop();
    }

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



Measured memory_bytes: 892
#include<bits/stdc++.h>
#define inf (int)1e9+7

using namespace std;

const int mx = 1e5+123;

int hight[mx];

int dp[mx];

int n;
int solve(int i){

if(i == n)  return 0;

if(dp[i]!=-1) return dp[i];

int ret1 = solve(i+1)+abs(hight[i+1]-hight[i]);
int ret2 = inf;
if(i+2<=n) ret2 = solve(i+2) + abs(hight[i+2]-hight[i]) ;


return dp[i] = min(ret1,ret2);

}
int main(){

    cin>>n;

    for(int i = 1;i<=n;i++){
         cin>>hight[i];
    }
    memset(dp,-1,sizeof(dp));

    cout<<solve(1)<<endl;


  return 0;
}


Measured memory_bytes: 9072
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

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

void run (void) {
  i32 n, a, b;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &n, &a, &b);
  printf ("%" PRIi32 "\n", MIN (n * a, b));
}

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define N 50001
#define M 100011
#define f first
#define s second
#define INF (1e9)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
int n,m,T;
set<PP> G[M]; // to,cost,y,x
vector<int> g[M];
vector<bool>used[M];
vector<P> D[M];
priority_queue<PP,vector<PP>,greater<PP> >Q;  
P dijkstra(int a,int b){
  while(!Q.empty()){
    PP t=Q.top();Q.pop();
    int cost=t.f.f,cnt=t.f.s;
    int y=t.s.f, x=t.s.s;
    int pos=g[y][x];
    if(D[y][x]<t.f)continue;
    if(pos==b) return t.f;

    used[y][x]=1;
    for(set<PP>::iterator i=G[pos].begin();i!=G[pos].end();){
      int ncost=cost+i->f.s,ncnt=cnt;
      int ny=i->s.f,nx=i->s.s;
      if(used[ny][nx]){G[pos].erase(i++);continue;}
      i++;
      if(pos!=a&&(ny!=y||abs(x-nx)!=1))ncost+=T,ncnt++;

      
      if(D[ny][nx]>P(ncost,ncnt)){
	D[ny][nx]=P(ncost,ncnt);
	Q.push(PP(D[ny][nx],P(ny,nx)));
      }
    }
  }
  return P(-1,-1);
}

int main(){
  string s,t;
  cin>>m>>T>>s>>t;
  map<string,int> mp;
  mp[s]=n++;
  mp[t]=n++;

  for(int i=0,a;i<m;i++){
    cin>>a;
    D[i].resize(a,P(INF,INF));
    used[i].resize(a,0);
    for(int j=0;j<a;j++){
      string str;
      cin>>str;
      if(!mp.count(str))mp[str]=n++;
      if(str==s)D[i][j]=P(0,0);
      if(str==s&&Q.empty())Q.push(PP(P(0,0),P(i,j)));
      g[i].push_back(mp[str]);
    }

    for(int j=0,pre=g[i][0],cost;j<a-1;j++){
      cin>>cost;
      int pos=g[i][j+1];
      G[pre].insert(PP(P(pos,cost),P(i,j+1)));
      G[pos].insert(PP(P(pre,cost),P(i,j)));
      pre=pos;
    }
  }

  P ans=dijkstra(0,1);
  if(ans==P(-1,-1)) cout<<-1<<endl;
  else cout<<ans.f<<" "<<ans.s<<endl;
  return 0;
}

Measured memory_bytes: 37888
#include <stdio.h>

void insertionSort(int A[], int n, int g);
void shellSort(int A[], int n);

static int cnt;

int main(void)
{
	int n, i;
	
	scanf("%d", &n);
	
	int A[n];
	
	for(i=0; i<n; i++)
	{
		scanf("%d", &A[i]);
	}
	
	shellSort(A, n);
	
	printf("%d\n", cnt);
	
	for(i=0; i<n; i++)
	{
		printf("%d\n", A[i]);
	}
	
	return 0;
}

void insertionSort(int A[], int n, int g)
{
	int i=0, v=0, j=0;
	
	for(i=g; i<n; i++)
	{
		v = A[i];
		j = i - g;
		
		while(j >= 0 && A[j] > v)
		{
			A[j+g] = A[j];
			j = j - g;
			cnt++;
			
//			printf("(46)%d %d %d\n", i, j ,cnt);
		}
		A[j+g] = v;
	}
}
void shellSort(int A[], int n)
{
	int cnt=0, m, h=1, i=0, j=0;
	int G[100];
	
	for(i=0, h=1; ; i++)
	{
		if(h > n) break;
		G[i] = h;
		h = h * 3 + 1;
	}
	
	printf("%d\n", i);
	cnt=0;
	for(j=i-1; j>=0; j--)
	{
		if(j==0)
		{
			printf("%d\n", G[j]);
		}
		else
		{
			printf("%d ", G[j]);
		}
		insertionSort(A, n, G[j]);
	}
	
/*	for(j=0; j<i; j++)  //逆順にG[i]=gを指定
	{
		insertionSort(A, n, G[j]);
	}
*/
}


Measured memory_bytes: 5656
import sys

n, q = [int(i) for i in sys.stdin.readline().split()]
graph = {i: [] for i in range(n)}
ct = [0 for i in range(n)]
for i in range(n - 1):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

for i in range(q):
    p, x = [int(i) for i in sys.stdin.readline().split()]
    p -= 1
    ct[p] += x
already = {0}
stack = [(0, ct[0], -1)]
res = [0 for i in range(n)]
while len(stack) > 0:
    cur, cost, _from = stack.pop(-1)
    res[cur] = cost
    for _next in graph[cur]:
        if _next == _from:
            continue
        next_cost = ct[_next]
        stack.append((_next, cost + next_cost, cur))
        already.add(cur)
print(" ".join([str(r) for r in res]))

Measured memory_bytes: 99800