akhauriyash/Code-Regression huggingface dataset:
from queue import Queue
from copy import deepcopy

h, w = map(int, input().split())
s = [input() for _ in range(h)]

WHITE = 0
GRAY = 1
BLACK = 2

dhw = [[-1, 0], [1, 0], [0, -1], [0, 1]]

color_orginal = [[WHITE] * w for _ in range(h)]
for hi in range(h):
    for wi in range(w):
        if s[hi][wi] == "#":
            color_orginal[hi][wi] = BLACK


def dfs(sh, sw):
    q = Queue()
    q.put([sh, sw])

    color = deepcopy(color_orginal)
    d = [[-1] * w for _ in range(h)]

    d[sh][sw] = 0
    dd = 0

    while not q.empty():
        uh, uw = q.get()
        color[uh][uw] = BLACK
        for dh, dw in dhw:
            nxth = uh + dh
            nxtw = uw + dw
            if 0 <= nxth <= h - 1 and 0 <= nxtw <= w - 1:
                if color[nxth][nxtw] == WHITE:
                    q.put([nxth, nxtw])
                    color[nxth][nxtw] = GRAY
                    d[nxth][nxtw] = d[uh][uw] + 1
                    dd = max(d[nxth][nxtw], dd)

    return dd


ans = 0
for hi in range(h):
    for wi in range(w):
        if s[hi][wi] == ".":
            ans = max(ans, dfs(hi, wi))

print(ans)


Measured memory_bytes: 4080
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#include <algorithm>
#include <complex>
#include <map>
#include <cmath>
#include <string>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <istream>

using namespace std;

//--------------------------------------------------------------//

int w, h, n, x[100], y[100], a[100];
int x1, Y1;
int b, c,d,f,g;

int main() {
	cin >> w >> h >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> a[i];
	}
	x1 = 0;
	Y1 = 0;
	for (int i = 0; i < n; i++) {
		b = a[i];
		c = y[i];
		d = x[i];
		if ((b == 1) && (d >=x1)) {
			x1 = d;
		}
		else if ((b == 2) && (d<=w) ) {
			w = d;
		}
		else if ((b == 3) && (c >= Y1)) {
			Y1 = c;
		}
		else if ((b == 4) && (c<=h) ) {
			h = c;
		}
	}
	if (((w - x1) > 0) && ((h - Y1) > 0)) {
		cout << (w - x1)*(h - Y1) << endl;
	}
	else {
		cout << 0 << endl;
	}
}

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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var aaa = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            if (aaa[0] <= aaa[2] && aaa[2] <= aaa[1])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define piii pair<ll, pii>
#define MOD 1000000007
#define M 100005
#define inf 1000000005
using namespace std;
ll h[M];
ll dp[M];
ll n,k;

int main(){
    //ll t; cin>> t; while(t--){
        cin>> n>>k;
        for(ll i =1;i<=n;i++){
            cin>> h[i];
            dp[i]  = inf;
        }
        dp[1] = 0;
        for(ll i =1;i<=n;i++){
            for(ll j = 1;j <= k;j++){
                if(i+j<=n) dp[i+j]  = min(dp[i+j], dp[i]+ abs(h[i+j]- h[i]));
            }
        }
        cout << dp[n] << endl;

}


Measured memory_bytes: 1792
N = gets.to_i
A = gets.split.take(N).map(&:to_i)

arr = []
A.sort.reverse.inject(0){|n,r|
  if n == r
    0.tap{
      arr << r
      break if arr.size >= 2
    }
  else
    r
  end
}
p arr.size < 2 ? 0 : arr[0] * arr[1]


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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)(x).size()
#define pb          push_back
#define eb          emplace_back
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

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

    ll x, k, d;
    cin >> x >> k >> d;
    if ((double)k * d < 1e16 && abs(x) - k * d >= 0) {
        return cout << abs(x) - k * d, 0;
    }

    ll cnt = abs(x) / d;
    ll res = abs(x) % d;
    if ((k - cnt) & 1) cout << abs(res - d);
    else cout << res;
}


Measured memory_bytes: 3648
#include<stdio.h>
int main()
{
    int X;
    scanf("%d",&X);
    if(X==3){
        printf("YES\n");

    }
    else if(X==5){
        printf("YES\n");

    }
    else if(X==7){
        printf("YES\n");

    }
    else{
        printf("NO\n");

    }
    return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

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

  int N, M, Q; cin >> N >> M >> Q;
  int L[200200], R[200200];

  int count[510][510] = {0};
  rep(i, M) {
    cin >> L[i] >> R[i];
    count[L[i]][R[i]] ++;
  }

  rep1(i, N) {
      rep1(j, N - 1) {
          count[i][j + 1] += count[i][j];
      }
  }
  rep1(i, N) {
      per1(j, N - 1) {
          count[j][i] += count[j + 1][i];
      }
  }
  rep(i, Q) {
      int p, q;
      cin >> p >> q;
      cout << count[p][q] << "\n";
  }

  return 0;
}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;

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

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60, lmod = 1e9+7;

const int MAX_N = 500005;
bool used[MAX_N];

ll N,A,B,C,D,E;

int main(){
  cin >> N >> A >> B >> C >> D ;
  E = B - A;
  ll l = 0, r = N-1, mid;
  fill(used,used+N+1,false);
  while(true){
    mid = (l+r)/2;
    if(used[mid]) break;
    // + を N-1-mid , - を mid 回使う
    ll _min = C * (N-1-mid);
    ll _max = D * (N-1-mid);
    _min -= D * mid;
    _max -= C * mid;
    if(E>=_min && E<=_max){
      // cout << mid << "," << _min << "," << _max << endl;
      cout << "YES" << endl;
      return 0;
    }else if(E<_min){
      // - を増やす
      l = mid;
    }else{
      r = mid;
    }
    used[mid] = true;
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 768
A, B = map(int,input().split())
def factorization(n):
    if n == 1:
      return [1]
    elif n == 2:
      return [1, 2]
    arr = [1]
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(i)
    if temp!=1:
        arr.append(temp)
    if arr==[]:
        arr.append(n)
    return arr
print(len(set(factorization(A))&set(factorization(B))))

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
using ll =long long;
typedef long double ld;
const long double eps=1e-12;

ld mypow(ld a,ll i){
    if(i==0) return 1;
    ld t=mypow(a,i>>1);
    t*=t;
    if(i&1) t=(ld)(t*a);
    return t;
}

int main()
{
    int n,m;
    ld sum;
    while(scanf("%d%d",&n,&m)!=EOF){
        sum=0;
        for(ll i=1;i<=n;i++){
            ll r=i,cnt=0;
            while(r<m) r*=2,cnt++;
            //cout << cnt << endl;
            sum+=(ld)((1.0/n)*mypow(1.0/2,cnt));
        }
        printf("%.12Lf",sum);
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int n,i,flg=0;
  scanf("%d",&n);

  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]%2==0){
      if(!(a[i]%3==0 || a[i]%5==0)){
        printf("DENIED");
        return 0;
      }
    }
  }

  printf("APPROVED");

  return 0;
}

Measured memory_bytes: 128
s = input()
flag = 0
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        print('{} {}'.format(i+1, i+2))
        flag=1
        break
for i in range(len(s)-2):
    if flag==1:
        break
    if s[i]==s[i+2]:
        print('{} {}'.format(i+1, i+3))
        flag=1
        break
if flag == 0:
    print('-1 -1')


Measured memory_bytes: 3188
#include<iostream>

using namespace std;

int kori[90][90];
int n, m;
void saiki(int n,int y, int x, int sub[][90]);
int MAX = 0;
char g;

int main()
{
	for(;;){
		cin >> m;			//x²
		cin >> n;			//y²
		MAX = 0;
		if(m == 0&&n == 0){
			break;
		}
		
		int temp[90][90];
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				cin >> kori[i][j];
			}
		}
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				temp[i][j] =  kori[i][j];
			}
		}
		
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				if(kori[i][j] == 1){
	//				printf("ÀW(%d, %d)©çX^[g\n",i,j);
					saiki(0,i,j,kori);				//X^[g·éÕÊÌÀWðn·A ÆXÌÕÊ
					//Èñ©mçñ¯ÇNH³êÆé©çàÆÉß·
					for(int i = 0; i < n; i++){
						for(int j = 0; j < m; j++){
							kori[i][j] =  temp[i][j];
						}
					}
				}
			}
		}
		cout << MAX << endl;
	}
}

void saiki(int n,int y, int x,int sub[][90])
{
	/*
	printf("*kori[%d][%d] = %d\n",y,x,kori[y][x]);
	printf(" kori[%d][%d] = %d\n",y+1,x,kori[y+1][x]);
	printf(" kori[%d][%d] = %d\n",y-1,x,kori[y-1][x]);
	printf(" kori[%d][%d] = %d\n",y,x+1,kori[y][x+1]);
	printf(" kori[%d][%d] = %d\n",y,x-1,kori[y][x-1]);
	*/
//	printf("ÀW(%d, %d)É½\n",y,x);
	sub[y][x] = 0;
	n++;
	if(sub[y+1][x] == 1){
		sub[y+1][x] = 0;
		saiki(n, y+1,x,sub);
//		printf("½¾¢Ü[\n");
		sub[y+1][x] = 1;
	}
	if(sub[y-1][x] == 1){
		sub[y-1][x] = 0;
		saiki(n,y-1,x,sub);
//		printf("½¾¢Ü[\n");
		sub[y-1][x] = 1;
	}
	if(sub[y][x+1] == 1){
		sub[y][x+1] = 0;
		saiki(n,y,x+1,sub);
//		printf("½¾¢Ü[\n");
		sub[y][x+1] = 1;
	}
	if(sub[y][x-1] == 1){
		sub[y][x-1] = 0;
		saiki(n,y,x-1,sub);
//		printf("½¾¢Ü[\n");
		sub[y][x-1] = 1;
	}
	
//	printf("*Kw:%d\n",n);
	
	if(MAX < n){	
//		printf("Å%dñ¥ß½\n",n);
		MAX = n; 
	}
}
	

Measured memory_bytes: 932
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SIZE(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (upper_bound(ALL(c),x)-lower_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *min_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

double dist(double x, double y, double X, double Y) {
   return sqrt((X-x)*(X-x) + (Y-y)*(Y-y));
}
signed main()
{
   int n; cin >> n;
   V<double> x(n), y(n);
   REP(i, n) {
      cin >> x[i] >> y[i];
   }

   const double R = max(max(x),max(y)) * 1e7;
   const int SPLIT = 1e5;
   V<int> score(n);
   REP(i, SPLIT) {
      double X = R * cos(2*M_PI*i/SPLIT);
      double Y = R * sin(2*M_PI*i/SPLIT);
      double MIN = INF; int mini = -1;
      REP(j, n) {
         if (chmin(MIN, dist(x[j], y[j], X, Y))) {
            mini = j;
         }
      }
      score[mini]++;
   }
   REP(i, n) {
      printf("%.5lf\n", (double)score[i]/sum(score));
   }

   return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
#define for_each(it,a) for(__typeof a.begin() it = a.begin();it!=a.end();it++)
template<class T> inline void chmin(T& a, T b) { if( b < a ) a = b; }

int n, m;
struct edge{
  int pos, dang;
  vector < int >  value;
  edge( int pos, int dang): pos(pos), dang(dang), value( (n + 1) / 2 + 1, INF){};
};
int main(){

  while( cin >> n >> m , n){
    vector< vector < edge > > info(n + 2);

    for(int i = 0; i < n; i++){
      int k;
      cin >> k;
      for(int j = 0; j < k; j++){
        int t, d;
        cin >> t >> d;
        info[i].push_back( edge( t, d));
      }
    }
    for_each( it, info[0]) it -> value[m] = 0;
    for_each( it, info[1]) it -> value[m - 1] = 0;
    int ret = INF;
    for( int i = 0; i < n; i++){
      for_each( now, info[i]){
        for(int j = m; j >= 0; j--){ //ジャンプできる残り回数
          int& cost = now -> value[j], dang = now -> dang, pos = now -> pos;
          if( cost == INF) continue;
          if(j > 0){ //ジャンプしてみる
            for_each( next, info[i + 2]){
              chmin( next -> value[j - 1], cost + (dang + next -> dang) * abs( pos - next -> pos));
            }
          }
          for_each( next, info[i + 1]){
            chmin( next -> value[j], cost + (dang + next -> dang) * abs( pos - next -> pos));
          }
        }
      }
    }
    for_each(it,info[n - 1]) chmin( ret, *min_element( it->value.begin(), it->value.end()));
    for_each(it,info[n - 2]) chmin( ret, *min_element( it->value.begin() + 1, it->value.end()));
    cout << ret << endl;
  }
}

Measured memory_bytes: 1604
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>
#include <functional>
#include <iterator>

#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end())
#define PSort(x) sort(begin(x), end(x), pairCompare)
#define ll long long
#define INF 2000000000
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.14159265358979
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
using namespace std;

int main(){	
	while (1) {
		vector<pair<int, int>> memo(1);
		memo[0] = mp(200, 200);

		int n;
		cin >> n;
		if (n == 0)break;
		n--;
		rep(i, 0, n) {
			int a, b;
			cin >> a >> b;
			if (b == 0) {
				memo.pb(mp(memo[a].fi - 1, memo[a].se));
			}
			else if (b == 1) {
				memo.pb(mp(memo[a].fi , memo[a].se - 1));
			}
			else if (b == 2) {
				memo.pb(mp(memo[a].fi + 1, memo[a].se));
			}
			else if (b == 3) {
				memo.pb(mp(memo[a].fi, memo[a].se + 1));
			}
			//cout << memo[i+1].fi << " " << memo[i+1].se << endl;
		}

		int minx = INF, maxx = 0, miny = INF, maxy = 0;

		rep(i, 0, memo.size()) {
				minx = min(minx, memo[i].fi);
				maxx = max(maxx, memo[i].fi);
				miny = min(miny, memo[i].se);
				maxy = max(maxy, memo[i].se);
		}
		cout << maxx - minx+1 << " " << maxy - miny+1 << endl;
	}


	

	return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define INF (1 << 29)
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int H, W, d[1000], st, en;
char A[50][50];

struct edge
{
	int to, cost;
};

typedef pair<int, int> P;

vector<edge> G[1000]; 

int main()
{
	fill(d, d + 1000, INF);
	cin >> H >> W;
	for(int y = 0; y < H; y++)
	{
		for(int x = 0; x < W; x++)
		{
			cin >> A[y][x];
			if(A[y][x] == 'S')
				st = y * W + x;
			if(A[y][x] == 'G') 
				en = y * W + x;
		}
	}
	for(int y = 0; y < H; y++)
	{
		for(int x = 0; x < W; x++)
		{
			if(A[y][x] == '#')
				continue;
			for(int i = 0; i < 4; i++)
			{
				int cost = 0;
				int teki = 0, mikata = 0, hutuu = 0;
				for(int j = 1; j <= 3; j++)
				{
					int ty = y + dy[i] * j, tx = x + dx[i] * j;
					if(tx < 0 || ty < 0 || tx >= W || ty >= H)
						break;	
					if(A[ty][tx] == '#')
						break;
					else if(A[ty][tx] == 'o')
						mikata++;
					else if(A[ty][tx] == 'x')
						teki++;
					else
						hutuu++;
					edge e1 = {ty * W + tx, 2 + j}, e2 = {ty * W + tx, mikata + hutuu * 2};
					G[y * W + x].push_back(e1);
					if(teki == 0)
						G[y * W + x].push_back(e2);
				}
			}
		}
	}
	priority_queue<P, vector<P>, greater<P> > q;
	d[st] = 0;
	q.push(P(0, st));
	while(!q.empty())
	{
		P p = q.top(); q.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] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}
	cout << d[en] << endl;
}

Measured memory_bytes: 1332
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=1;i<=n;i++)
using namespace std;
using ll=long long;
using P = pair<int,int>;
int main(){
    int N;
    cin >> N;
    int ans =0;
    for(int i=1;i<=N;i++){
        int b = N%i;
        int a = N/i;
        if(b==0)ans +=a-1;
        else ans+=a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
using namespace std;
main(){
	int n;
	int a,b;
	cin >> n;
	cin >> a >> b;
	int p[n];
	for(int i=0;i<n;i++){
		cin >> p[i];
	}
	sort(p,p+n);

	int x[3];
	for(int i=0;i<3;i++){
		x[i]=0;
	}

	for(int i=0;i<n;i++){
		if(p[i]<=a){
			x[0]++;
		}else if(p[i]<=b){
			x[1]++;
		}else{
			x[2]++;
		}
	}
	int min=x[0];
	for(int i=1;i<3;i++){
		if(min>x[i])
			min=x[i];
	}
	cout << min <<endl;
}


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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)

int main(void){

    int n;
    cin >> n;
    vector<double> x(n), y(n);
    loop(i, n) cin >> x[i];
    loop(i, n) cin >> y[i];

    for(int i = 1;i <= 3;i++){
        double sum = 0.0;
        loop(j, n){
            sum += pow(abs(x[j]-y[j]), i);
        }
        cout << fixed << setprecision(8);
        cout << pow(sum, (1.0/i)) << endl;
    }

    double maxv = 0;
    loop(i, n){
        maxv = max(maxv, abs(x[i] - y[i]));
    }
    cout << maxv << endl;

    return 0;
}



Measured memory_bytes: 3476
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
  ll n,m,k,i,j,result=0;
  int a[200010]={0};
  string s;
  cin >> n;
  rep(i,n){
    cin >> a[i+1];
    result+=abs(a[i+1]-a[i]);
  }
  result+=abs(a[n]);
  for(i=1;i<=n;i++){
    m = result;
    m -= abs(a[i+1]-a[i])+abs(a[i]-a[i-1]);
    m += abs(a[i+1]-a[i-1]);
    cout << m << endl;
  }
  return 0;
}

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

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<double,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, e, f, g, sum, A[500010], B[500000], rui[500000], dp[5000];
ll ma = Min;
P C[10010];
str S; bool check = true;	vector<ll> v;



int main() {
	//Code Line
	cin >> a >> n;

	for (int i = 0; i < n; i++) {
		cin >> A[i] >> B[i];
	

	}




			ll dp[20000] = {}; Min = INF;
			for (int i = 1; i < 20000; i++) {
				dp[i] = INF;
			}
			for (int i = 0; i < a; i++) {
				for (int j = 0; j < n; j++) {
					dp[i + A[j]] = min(dp[i + A[j]], dp[i] + B[j]);
				}
			}
			for (int i = a; i < 20000; i++) {
				if (Min > dp[i]) { Min = dp[i]; }
			}
			sum += Min;
			
		

	

	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 4480
#define ll long long
#include "bits/stdc++.h"
using namespace std;
vector<pair<ll ,ll >>vc;
const int N = 2e5 + 2;
ll arr[N];
int main() {
ll n;
cin>>n;
ll res=100;
ll cnt=0;
while(res <= n)
{
    res+=(.01 * res );
    cnt++;
    if(res==n)break;

}
cout<<cnt;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>                                                                              
using namespace std;                                                                                  
using ll = long long;                                                                                 
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }               
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }               
#define rep(i,n) for (int i=0; i< (n); ++i)                                                           
typedef pair<int, int> P;                                                                             
                                                                                                      
int main() {                                                                                          
  int n;                                                                                              
  cin >> n;                                                                                           
  set<string> keihins;                                                                                
  string s;                                                                                           
  rep(i, n) {                                                                                         
    cin >> s;                                                                                         
    keihins.insert(s);                                                                                
  }                                                                                                   
  cout << keihins.size() << endl;                                                                     
                                                                                                      
  return 0;                                                                                           
}                                                                                                     
                                                     

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

using namespace std;
int main() {
    int n,m;
    int total=0,cnt=0;
    cin >> n>>m;
    std::vector<int> vec(n);
    for(int i=0;i<n;i++){
        int v;
        cin >> v;
        total += v;
        vec[i] = v;
    }
    for(int i=0;i<n;i++){
        cnt += vec[i]>=total/(float)(4*m);
    }
    if(cnt>=m){
        cout<< "Yes" <<endl;
    }else{
        cout<< "No" <<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

struct BIT{
	int N;
	long long dat[100100];
	void init(int N_){
		N = N_;
		for(int i = 0; i <= N; ++i) dat[i] = 0;
	}
	void add(int id, long long x){
		while(id <= N){
			dat[id] = (dat[id] + x);
			id += (id & (-id));
		}
	}
	long long sum(int id){
		long long ans = 0;
		while(id > 0){
			ans = (ans + dat[id]);
			id -= (id & (-id));
		}
		return ans;
	}
	long long sum(){
		return sum(N);
	}
};

BIT bit;

int N;
int A[100100];

int x[100100];
int sum[100100];

void input(){
	scanf("%d", &N);
	for(int i = 0; i < N; ++i) scanf("%d", A + i);
}

long long all;

vector<int> vals;

int getId(int v){
	return lower_bound(vals.begin(), vals.end(), v) - vals.begin() + 1;
}

bool check(int m){
	for(int i = 0; i < N; ++i){
		x[i] = (A[i] >= m) ? 1 : (-1);
	}
	sum[0] = 0;
	for(int i = 0; i < N; ++i){
		sum[i + 1] = sum[i] + x[i];
	}
	vals.clear();
	for(int i = 0; i <= N; ++i){
		vals.push_back(sum[i]);
	}
	sort(vals.begin(), vals.end());
	vals.erase(unique(vals.begin(), vals.end()), vals.end());
	long long cnt = 0;
	bit.init(vals.size());
	bit.add(getId(0), 1);
	for(int i = 1; i <= N; ++i){
		int id = getId(sum[i]);
		cnt += bit.sum(id);
		bit.add(id, 1);
	}
	long long cnt2 = all - cnt;
	return cnt >= cnt2;
}

int solve(){
	all = (long long)N * (N + 1) / 2;
	int lb = 0, ub = 1000000001;
	while(ub - lb > 1){
		int mid = (ub + lb) / 2;
		bool flg = check(mid);
		if(flg) lb = mid;
		else ub = mid;
	}
	return lb;
}

int main(){
	input();
	int ans = solve();
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2680
n = int(input())
a = sorted([ int(v)-i-1 for i,v in enumerate(input().split()) ])
ans = 0
# 中央値で反転
if n % 2 == 0:
    print(sum(a[n//2:]) - sum(a[:n//2]))
else:
    print(sum(a[(n+1)//2:]) - sum(a[:(n-1)//2]))

Measured memory_bytes: 26388
// C - Candles

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

vector<ll> L, R;

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

	L.push_back(0);
	R.push_back(0);
	for (int i=0; i<N; i++) {
		int x;
		cin >> x;
		if (x == 0) K--;
		else if (x < 0) L.push_back(-x);
		else R.push_back(x);
	}

	sort(L.begin(), L.end());

	ll ans = INF;

	// L -> R
	for (int i=0; i<=K && i < L.size(); i++) {
		if (K-i >= R.size()) continue;

		ll time = L[i] * 2 + R[K-i];
		ans = min(ans, time);
	}

	// R -> L
	for (int i=0; i<=K && i < R.size(); i++) {
		if (K-i >= L.size()) continue;

		ll time = R[i] * 2 + L[K-i];
		ans = min(ans, time);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4440
N = int(input())
lsA = [0]+list(map(int,input().split()))+[0]
sum1 = 0
for i in range(1,N+2):
    sum1 += abs(lsA[i]-lsA[i-1])
lsans = []
for i in range(1,N+1):
    if lsA[i-1] <= lsA[i] and lsA[i] <= lsA[i+1]:
        lsans.append(sum1)
    elif lsA[i-1] >= lsA[i] and lsA[i] >= lsA[i+1]:
        lsans.append(sum1)
    else:
        div = min(abs(lsA[i-1]-lsA[i]),abs(lsA[i+1]-lsA[i]))
        lsans.append(sum1-2*div)
for i in lsans:
    print(i)

Measured memory_bytes: 20644
#include<bits/stdc++.h>
#define INF (1e9)
#define M 666001
using namespace std;
int P,d[6],c[6]={1,5,10,50,100,500};
int f,ans,sum,z[M];
 
int cal(int x){
  int res=0;
  for(int i=5;i>=0;i--)
    res+=x/c[i],x=x%c[i];
  return res;
}
 
int cal2(int x){
  int res=0;
  for(int i=5;i>=0;i--){
    int p=min(x/c[i],d[i]);
    res+=p;
    if(p)x-=p*c[i];
  }
  if(!x)return res;
  return -1;
}
 
int main(){
  for(int i=0;i<M;i++)
    z[i]=cal(i);
  while(1){
    cin>>P;
    f=sum=0;
    for(int i=0;i<6;i++){
      cin>>d[i],sum+=d[i]*c[i];
      if(d[i])f=1;
    }
    if(!f)break;
    ans=INF;
    for(int i=P;i<=sum;i++){
      int r=cal2(i);
      if(r!=-1)ans=min(ans,r+z[i-P]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 5608
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))

char s[110][110];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);

	int x=0;
	
	while(a>1){
		//白で塗る
		repp(y,0,100,2){
			if(a>1){
				s[x][y]='.';
				a--;
			}
			else s[x][y]='#';
			s[x][y+1]='#';
		}
		x++;
		rep(y,0,100)s[x][y]='#';
		x++;
	}
	rep(y,0,100)s[x][y]='#';
	x++;
	
	ll xxxx=x;
	
	while(b>1){
		//黒で塗る
		repp(y,0,100,2){
			if(b>1){
				s[x][y]='#';
				b--;
			}
			else s[x][y]='.';
			s[x][y+1]='.';
		}
		x++;
		rep(y,0,100)s[x][y]='.';
		x++;
	}
	rep(y,0,100)s[x][y]='.';
	x++;

	printf("%d 100\n",x);
	rep(i,0,xxxx)puts(s[i]);
	rep(i,0,x-xxxx)puts(s[x-1-i]);
	return 0;
}

Measured memory_bytes: 128
import math

N, M = map(int, input().split())

if N == M:
    print((2 * math.factorial(N) * math.factorial(M)) % (10 ** 9 + 7))
elif N == M + 1 or N + 1 == M:
    print((math.factorial(N) * math.factorial(M))% (10 ** 9 + 7))
else:
    print(0)

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

using namespace std;

#define int long long
#define forn(i,n) for(int i = 0; i <(int)n; ++i)
const int MOD = 1000000007; // opsi : 998244353, 1000000007,

int32_t main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    while(n)
    {
        s = (char)((n+25)%26 + 'a') + s;
        n-=((n+25)%26 + 1);
        n/=26;
    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
	int a,b,c,d,ans;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a>=(b+1)) ans=b*c+d*(a-b);
	else if(a<=(b+1)) ans=a*c;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    int ans = 1;
    REP(i,3) ans *= n;
    OUT(ans)

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import itertools


n,k= map(int, input().split())
a= list(map(int, input().split()))
a=[0]+list(itertools.accumulate(a))
b=[0]*(n+1)
for i,x in enumerate(a):
    b[i]=(x-i)%k
d=defaultdict(int)
ans=0
for i in range(n+1):
    if i>=k:
        d[b[i-k]]-=1
    ans+=d[b[i]]
    d[b[i]]+=1
print(ans)

Measured memory_bytes: 114968
#include<bits/stdc++.h>
using namespace std;
#define f1(a,b,c) for(int c=a;c<=b;c++)
#define f2(a,b,c) for(int c=a;c>=b;c--)
#define f3(a,b,c) for(int c=a;c;c=b)
#define so1(a,n) sort(a+1,a+n+1,mycmp);
#define so2(a,n) sort(a+1,a+n+1);
#define ll long long
#define itn int
#define ubt int 
const int twx=1e5+100;
const int inf=0x7fffffff;
ll read()
{
    ll sum=0;
    ll flag=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            flag=-1;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        sum=((sum*10)+c-'0');
        c=getchar();
    }
    return sum*flag;
}
int n;
int x[twx];
int L,Q;
int a,b;
int asd[twx][40];
void init()
{
	n=read();
    f1(1,n,i)
    {
        x[i]=read();
    }
    L=read();
    Q=read();
    f1(1,n,i)
    {
        int LEFT=i+1;
        int RIGHT=n;
        while(LEFT<=RIGHT)
        {
            int MID=(LEFT+RIGHT)/2;
            if(x[MID]<=L+x[i])
            {
                LEFT=MID+1;
            }
            else
            {
                RIGHT=MID-1;
            }
        }
        if(x[i]+L>=x[n])
        {
            asd[i][0]=n;
        }
        else
        {
            asd[i][0]=LEFT-1;
        }
    } 
    f1(1,30,i)
    {
        f1(1,n,j)
        {
            asd[j][i]=asd[asd[j][i-1]][i-1];
        }
    }
    while(Q--)
    {
        int a=read();
        int b=read();
        if(b<a)
        {
            swap(a,b);
        }
        ll ans=0;
        f2(30,0,i)
        {
            if(asd[a][i]<b)
            {
                ans+=(1<<i);
                a=asd[a][i];
            }
        }
        printf("%lld\n",ans+1);
    }
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    init();
	return 0;
}

Measured memory_bytes: 16896
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
#define reg register
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
typedef long long ll;
template<typename T>inline T read(){
    reg T x=0,f=1;reg char ch=getchar();
    for(;!isdigit(ch);f=ch=='-'?-1:1,ch=getchar());
    for(;isdigit(ch);x=(x*10)+(ch^48),ch=getchar());
    return x*f;
}
char buf[15];
inline void write(int v){
	if(!v){puts("0");return;}
	reg int cnt=0;
	while(v)buf[++cnt]=v%10+'0',v/=10;
	for(reg int i=cnt;i;i--)putchar(buf[i]);
	putchar('\n');
}
const int maxn=2005;
const int inf=0x7fffffff;
int f[maxn][maxn],col[maxn<<1],a[maxn<<1],p[2][maxn],c[2][maxn<<1][maxn];
char ch[10];
int main(){
	reg int n=read<int>();
	for(reg int i=1;i<=n*2;i++){
		scanf("%s",ch);a[i]=read<int>();col[i]=ch[0]=='B'?1:0;
		p[col[i]][a[i]]=i;
	}
	for(reg int i=1;i<=n*2;i++)
		for(reg int j=0;j<=n;j++)
			c[0][i][j]=c[0][i-1][j]+(a[i-1]>j&&!col[i-1]),
			c[1][i][j]=c[1][i-1][j]+(a[i-1]>j&&col[i-1]);
	for(reg int i=0;i<=n;i++)
		for(reg int j=0;j<=n;j++){
			if(!(i|j))continue;
			f[i][j]=inf;
			if(i)f[i][j]=min(f[i][j],f[i-1][j]+c[0][p[0][i]][i-1]+c[1][p[0][i]][j]);
			if(j)f[i][j]=min(f[i][j],f[i][j-1]+c[1][p[1][j]][j-1]+c[0][p[1][j]][i]);
		}
	write(f[n][n]);
    return 0;
}

Measured memory_bytes: 78720
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int N, Q;
  cin >> N >> Q;
  vector<pair<int,int>> ab(N-1);

  rep(i,0,N-1) {
    int a;
    int b;
    cin >> a >> b;
    ab[i] = make_pair(a,b);
  }
  sort(ALL(ab));
  
  vector<int> ans(N);
  rep(i,0,Q) {
    int c;
    int d;
    cin >> c >> d;
    ans[c-1] += d;
  }
  
  rep(i,0,N-1){
    ans[ab[i].second - 1] += ans[ab[i].first - 1];
  }
  
  rep(i,0,N) cout << ans[i] << ' ';
  cout << endl;
}

Measured memory_bytes: 7040
/*input
6 6 8
..##..
.#..#.
#....#
######
#....#
#....#
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	int h, w, k;
	cin >> h >> w >> k;
	vector<string>v;
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		v.pb(s);
	}

	int ans = 0;
	for (int msk1 = 0; msk1 < 1 << h; msk1++) {
		for (int msk2 = 0; msk2 < 1 << w; msk2++) {
			int black = 0;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (v[i][j] == '#' && !(msk1 >> i & 1) && !(msk2 >> j & 1)) {
						++black;
					}
				}
			}
			if (black == k) {
				++ans;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3668
// May this submission get accepted
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll a, b, k;
    cin >> a >> b >> k;

    vector<ll> cand;
    REP(i, k) cand.push_back(a+i);
    REP(i, k) cand.push_back(b-i);
    UNIQUE(cand);
    for (ll x : cand) {
        if (a <= x && x <= b) {
            say(x);
        }
    }
    
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val scPairs = (1..M).map {
        readLine()!!.split(" ").map { it.toInt() }
    }

    val number = Array(N) { -1 }

    for (pair in scPairs) {
        if (number[pair[0] - 1] != -1 && number[pair[0] - 1] != pair[1]) {
            println(-1)
            return
        }
        if (number[pair[0] - 1] == -1) {
            number[pair[0] - 1] = pair[1]
        }
    }

    if (N == 1 && number[0] == -1) {
        number[0] = 0
    }

    if (N != 1 && number[0] == 0) {
        println(-1)
        return
    }

    for (i in number.indices) {
        if (number[i] == -1) {
            if (i == 0) number[i] = 1 else number[i] = 0
        }
    }

    println(number.joinToString(""))
}

Measured memory_bytes: 37756
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
int main() {
	ll a, b, k;
	scanf("%lld%lld%lld", &k, &a, &b);
	ll ans1 = k + 1ll;
	ll ans = 0;
	ll d = b - a;
	if (k > a) {
		k -= (a + 1);
		ans += b;
		ll t = k / 2;
		ans += t * d + k % 2;
	}
	printf("%lld\n", max(ans, ans1));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
ostream& operator<<(ostream &os, const vector<int> &st){
  for(int i=0;i<(int)st.size();++i){
    if(i==(int)st.size()-1) os << st[i];
    else os << st[i] << "\t";
  }
  return os;
}
ostream& operator<<(ostream &os, const vector<vector<int>> &st){
  for(int i=0;i<(int)st.size();++i){
    os << st[i] << endl;
  }
  return os;
}
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n,k;
  cin >> n >> k;
  V<pii> book(n);
  REP(i,n) cin >> book[i].fi >> book[i].se;
  vvi sell(10);
  sort(rALL(book));
  REP(i,n){
    int sz = sell[book[i].se-1].size();
    //sell[i][j]はiジャンル目をj+1冊取った時の最大値
    sell[book[i].se-1].eb(book[i].fi);
    if(sz>0) sell[book[i].se-1].back() += sell[book[i].se-1][sz-1]+2*(sz);
  }
  //dp[i][j]はiジャンル目まで見た時の、j冊売る時の最大値
  vvi dp(11,vi(k+1,0));
  //int ans = 0;
  REP(i,10){
    //取らない時
    REP(j,k) maxs(dp[i+1][j+1],dp[i][j+1]);
    //取る時は、
    FOR(j,1,sell[i].size()+1)FOR(l,j,k+1){
      //sell[i][j]を取ることがiジャンル目のものを取る時に最適解になり得る
      maxs(dp[i+1][l],dp[i][l-j]+sell[i][j-1]);
      //maxs(ans,dp[i+1][l]);
    }
  }
  //cout << sell << endl;
  //REP(i,11)REP(j,k+1) cout << dp[i][j] << endl;
  //cout << dp << endl;
  cout << dp[10][k] << endl;
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

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

int n;
vector < double > a;


void yap(){
  sort(a.begin(), a.end());
  a[0], a[1];
  a[1] = (a[0] + a[1])/2;
  vector < double > b;
  for(int i = 1; i < a.size(); i++)
    b.pb(a[i]);
  a = b;
}

int main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    scanf("%d",&n);
    for(int i = 1; i <= n; i++){
      int x;
      scanf("%d",&x);
      a.pb(x);// o(logn)
    }
    while((int)a.size() > 1){
      yap();
    }
    printf("%.10lf\n", a[0]);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,k,i,j;
  cin>>n>>k;
  long long ans=0;
  while(n--)
  {
    cin>>i>>j;
    long long x=i*i+j*j;
    long long y=sqrt(x);
    if(y<k)
      ans++;
    else if(y==k && y*y==x)
      ans++;
  }
  cout<<ans;
}


Measured memory_bytes: 3660
#include <cstdio>
#include <iostream>
using namespace std;
#define LL long long

const int N = 2000;
const int mod = 1e9 + 7;
LL n, k, a[N + 5], pre1[N + 5], pre2[N + 5];
LL ans;

int main () {
	scanf ("%lld %lld", &n, &k);
	for (int i = 1; i <= n; ++ i)
		scanf ("%lld", &a[i]);
	//1000000007
	for (int i = 1; i <= n; ++ i) {
		for (int j = i + 1; j <= n; ++ j)
			if (a[i] > a[j])
				++ pre1[i];
		for (int j = 1; j < i; ++ j)
			if (a[i] > a[j])
				++ pre2[i];
		pre2[i] += pre1[i];
	}
	LL t = ( 1ll * k * (k - 1) / 2 ) % mod;
	for (int i = 1; i <= n; ++ i)
		ans = ( ans + (  pre2[i] * t % mod + pre1[i] * k % mod ) % mod ) % mod; 
	printf ("%lld\n", ans);
	return 0;
} 

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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> S(60);
  for(int i=0;i<H;i++)cin >> S[i];
  string ans="Yes";
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j]=='#'){
        bool q=true;
        if(0<i && S[i-1][j]=='#'){q=false;}
        if(i<H-1 && S[i+1][j]=='#'){q=false;}
        if(0<j && S[i][j-1]=='#'){q=false;}
        if(j<H-1 && S[i][j+1]=='#'){q=false;}
        if(q){ans="No";}
      }
    }
  }
  cout << ans << endl;
}

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

int n, m, ans;
string s, t;

int main(){
    cin >> s >> t;
    ans = 1000;
    for (int i = s.length()-t.length(); i >= 0; i--){
        int cnt = 0;
        for (int j = 0; j < t.length(); j++){
            if (s[j+i] != t[j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << "\n";
}

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

string formula;
int parse(int P, int Q, int R, int &i){
  int a, b;
  switch(formula[i]){
  case '0':
    a = 0;
    i++;
    break;
  case '1':
    a = 1;
    i++;
    break;
  case '2':
    a = 2;
    i++;
    break;
  case 'P':
    a = P;
    i++;
    break;
  case 'Q':
    a = Q;
    i++;
    break;
  case 'R':
    a = R;
    i++;
    break;
  case '-':
    i++;
    a = parse(P, Q, R, i);
    a = 2 - a;
    break;
  case '(':
    i++;
    a = parse(P, Q, R, i);
    if(formula[i] == '*'){
      i++;
      b = parse(P, Q, R, i);
      i++;
      if(a == 1 && b == 1) a = 1;
      else a = (a * b) / 2;
    }
    else{
      i++;
      b = parse(P, Q, R, i);
      i++;
      if(a == 1 && b == 1) a = 1;
      else a = 2 - (((2-a) * (2-b)) / 2);
    }

  }

  return a;
}

int main(){
  while(1){
    cin >> formula;
    if(formula == ".") break;
    int count = 0;
    for(int i = 0; i <=2; i++){
      for(int j = 0; j <= 2; j++){
        for(int k = 0; k <= 2; k++){
          int index = 0;
          if(parse(i, j, k, index) == 2) count++;
        }
      }
    }
    cout << count << endl;
  }

  return 0;
}

Measured memory_bytes: 3120