akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
//geo
#include <complex>
typedef complex<double> P;
inline bool equal(double x, double y){
  return abs(x - y) < EPS;
}
inline bool operator == (const P& x, const P& y){
  return equal(x.real(), y.real()) && equal(x.imag(), y.imag());
}
double dot(P x, P y){
  return real(conj(x) * y);
}
double cross(P x, P y){
  return imag(conj(x) * y);
}
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
//---
int main(){
  int n;
  while(cin>>n && n ){
    vector<P> points;
    vector<bool> used(n);
    REP(i,n){
      int x,y;
      cin>>x>>y;
      points.push_back(P(x,y));
    }
    P now(0, 0);
    double ans = 0;
    REP(time, n){
      int next = -1;
      REP(i, n)if(!used[i]){
        bool ok = true;
        REP(j, n)if(!used[j] && i != j){
          int cw = ccw(now, points[i], points[j]);
          if(cw == 0 || cw == 1) {
            ok = false;
          }
          assert(cw != 2);
        }
        if(ok){
          assert(next == -1);
          next = i;
        }
      }
      assert(next != -1);
      used[next] = true;
      ans += abs(points[next] - now);
      now = points[next];
    }
    printf("%.1lf\n", ans);
  }
  return 0;
}

Measured memory_bytes: 984
N = int(input())
mochi = [int(i) for i in [input() for j in range(N)]]

kagami = 0
while(len(mochi) is not 0):
    tmp = mochi[0]
    for i in range(len(mochi) - 1):
        if(mochi[i] < tmp):
            tmp = mochi[i]
    mochi = [i for i in mochi if i != tmp]
    kagami += 1
print(kagami)

Measured memory_bytes: 3064
a,b,C = map(int,input().split())
import math
C = math.radians(C)
S = 1/2 * a * b * math.sin(C)
L = a + b + (a**2+b**2-2*a*b*math.cos(C))**0.5
h = b * math.sin(C)
print(S,L,h)



Measured memory_bytes: 5716
#include <stdio.h>

int main(void)
{
	int a, b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a < b){
	printf("a < b\n");
	}
	else if(a==b){
		printf("a == b\n");
	}
	else{
	printf("a > b\n");
	}
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int level[8] = {};
    int genius = 0;
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        if(t >= 3200){
            genius++;
        }else{
            level[t/400]++;
        }
    }
    int count = count_if(level, level+8, [](int x){return x!=0;});
    if(count == 0) 
        cout << 1 << " " << genius << endl;
    else
        cout << count << " " << count + genius << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MN 600
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;
}
pair<int,int> q[MN+5];
int n,d,D,s[MN+5][MN+5],vis[MN+5][MN+5],num[4],top;
void Mark(int x,int y,int c,int S)
{
    if(S) s[x][y]|=c;vis[x][y]=1;
    for(int j=1;j<=top;++j)
        for(int dx=-1;dx<=1;dx+=2) for(int dy=-1;dy<=1;dy+=2)
        {
            int nx=x+dx*q[j].first,ny=y+dy*q[j].second;
            if(nx>0&&ny>0&&nx<=n<<1&&ny<=n<<1&&!vis[nx][ny]) Mark(nx,ny,c,S^1);
        }
}
void Solve(int d,int c)
{
    top=0;
    for(int i=0;i*i<=d;++i)
    {
        int j=d-i*i,flag=-1;
        for(int k=0;k*k<=j;++k) if(k*k==j) flag=k;
        if(flag>=0) q[++top]=make_pair(i,flag);
    }
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n<<1;++i) for(int j=1;j<=n<<1;++j) if(!vis[i][j]) Mark(i,j,c,0);
}
int main()
{
    n=read();d=read();D=read();
    Solve(d,1);Solve(D,2);
    for(int i=1;i<=n<<1;++i) for(int j=1;j<=n<<1;++j) ++num[s[i][j]];
    for(int k=0;k<4;++k) if(num[k]>=n*n)
    {
        int left=n*n;
        for(int i=1;i<=n<<1;++i) for(int j=1;j<=n<<1;++j)
            if(s[i][j]==k&&left) --left,printf("%d %d\n",i-1,j-1);
        return 0;
    }
    return 0;
}

Measured memory_bytes: 31872
//おまじない
//#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

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

const int maxn = 3000;
pair<int,int> ab[maxn+1];
int n,t;
int dp1[maxn+2][maxn+2]={0};
int dp2[maxn+2][maxn+2]={0};
int ans = 0;

int main(){
    
    cin >> n>>t;
    rep(i,n){
        int a,b;
        cin >> a>>b;
        ab[i+1] = make_pair(a,b);
    }
    
    for(int i=1;i<=n;i++){
        for(int k=1;k<t;k++){
            //dp1[i][k]=dp1[i-1][k];
            if(k-ab[i].first>=0)dp1[i][k]=max(dp1[i-1][k],dp1[i-1][k-ab[i].first]+ab[i].second);
            else dp1[i][k]=dp1[i-1][k];
        }
    }
    
    for(int i=n;i>=1;i--){
        for(int k=1;k<t;k++){
            //dp2[i][k]=dp2[i+1][k];
            if(k-ab[i].first>=0)dp2[i][k]=max(dp2[i+1][k],dp2[i+1][k-ab[i].first]+ab[i].second);
            else dp2[i][k]=dp2[i+1][k];
        }
    }
    
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<t;j++){
            //cout << i<<space<<j<<space<<dp1[i-1][j]<<space<<dp2[i-1][j]<<endl;
            ans = max(ans,dp1[i-1][j]+dp2[i+1][t-1-j]+ab[i].second);
        }
    }
    
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 70656
import collections, itertools


class MaximumFlow:
    def __init__(self, G):
        self.G = G

    def ford_fulkerson(self, s, t):
        def dfs(start, used):
            G = self.G
            if start == t:
                return [start]
            for end, cap in G[start].items():
                if cap > 0 and end not in used:
                    used.add(end)
                    ret = dfs(end, used)
                    if ret:
                        return ret + [start]
            return []

        fmax = 0
        cnt = 0
        while True:
            G = self.G
            cnt += 1
            root = dfs(s, set([s]))
            if root:
                root = root[::-1]
                residue = min([G[a][b] for a, b in zip(root, root[1:])])
                fmax += residue
                for a, b in zip(root, root[1:]):
                    G[a][b] -= residue
                    G[b][a] += residue
            else:
                return (fmax, G)


N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
CD = [[int(_) for _ in input().split()] for _ in range(N)]
G = collections.defaultdict(lambda: collections.defaultdict(int))
for a, b in AB:
    G[-1][1000 * a + b] = 1
for c, d in CD:
    G[1000 * c + d][-2] = 1
for ab, cd in itertools.product(AB, CD):
    a, b = ab
    c, d = cd
    if a < c and b < d:
        G[1000 * a + b][1000 * c + d] = 1
flow = MaximumFlow(G)
fmax, Gres = flow.ford_fulkerson(-1, -2)
print(fmax)


Measured memory_bytes: 9732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(n); ++i)
#define REP(i, d, n) for(long long i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() {//言語変えろ言語変えろ言語変えろ言語変えろ言語変えろ
            
ll a,b,n; cin>>a>>b>>n;
  ll max=-999999;
  ll ans;
  
  
  if(b>n){ans=n;}
  else{ans=b-1;}
    
  
              
     max=ans*a/b-a*(ans/b);
              
              
  
  cout<<max<<endl;
  
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int gcd(int a, int b) {
     if (b == 0) return a;
     return gcd(b, a % b);
}

int main() {
    int N, X, x;
    cin >> N >> X;
    cin >> x;
    int ret = abs(X - x);
    for (int i = 1; i < N; i++) {
        cin >> x;
        ret = gcd(ret, abs(X - x));
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W
S = set()
for _ in range(M):
    h, w = map(int,input().split())
    S.add((h-1, w-1))
    R[h-1] += 1
    C[w-1] += 1

r = max(R)
c = max(C)

HL = [i for i in range(H) if R[i] == r]
WL = [i for i in range(W) if C[i] == c]

for h in HL:
    for w in WL:
        if not (h, w) in S:
            print(r + c)
            sys.exit()

print(r + c - 1)

Measured memory_bytes: 83548
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()
	q := scanInt()

	a := make([]int, q)
	b := make([]int, q)
	c := make([]int, q)
	d := make([]int, q)
	for i := 0; i < q; i++ {
		a[i] = scanInt() - 1
		b[i] = scanInt() - 1
		c[i] = scanInt()
		d[i] = scanInt()
	}

	ans := 0
	var dfs func(arr []int)
	dfs = func(arr []int) {
		if len(arr) == n {
			sum := 0
			for i := 0; i < q; i++ {
				if arr[b[i]]-arr[a[i]] == c[i] {
					sum += d[i]
				}
			}
			ans = max(ans, sum)
			return
		}
		for i := arr[len(arr)-1]; i <= m; i++ {
			dfs(append(arr, i))
		}
	}

	for i := 1; i <= m; i++ {
		dfs([]int{i})
	}
	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 5852
#include<iostream>
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
using namespace std;
int main()
{
    fastio;
    long long n,i;
    cin>>n;
    long long v[n],c[n],x=0,y=0;
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>c[i];
        if(v[i]>c[i])
        {
            x=x+v[i];
            y=y+c[i];
        }
    }
    cout<<x-y;
    return 0;
}

Measured memory_bytes: 3620
k = gets.chomp.to_i

a = [
    1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
puts a[k-1]

Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    ll LCM = c / __gcd(c, d) * d;
    ll n = b / c + b / d - b / LCM;
    ll m = (a-1) / c + (a-1) / d - (a-1) / LCM;
    
    ll res = (b - a + 1) - (n - m);
    cout << res << ln;
} 


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int N;
  cin >> N;
  string s;
  cin >> s;
  
  int ans = 0;
  int count = 0;
  
  for(int i=0;i<N;i++){
    if(s[i] == 'I')
      count++;
    else
      count--;
    
    if(ans < count)
      ans = count;
  }
  
  cout << ans << endl;
  
  return 0;
}

    

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc= new Scanner(System.in);

		int h = sc.nextInt();
		int a = sc.nextInt();

		if(h % a == 0) {
			System.out.println(h / a);
		} else {
			System.out.println(h/a + 1);
		}
	}
}

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

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int sum = 0; 
		int ans = 0;
		for(int i = 1; i <= N; i++) {
			sum = i/10000 + i%10000/1000 + i%1000/100 + i%100/10 + i%10;
			if(sum>=A && sum<=B) {
				ans += i;
//				debug(i);
//				debug(sum);
			}
			sum = 0;
		}
		System.out.println(ans);
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 21972
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(s[int(input())-1])


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,a,b;
    cin>>n>>a>>b;
    int maxi=min(a,b);
    int mini=0;
    if(n>=a+b)
        mini=0;
    else{
        mini=(a+b-n);
    }    
    cout<<maxi<<" "<<mini;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  int N,K;
  cin >> N >> K;
  int x[N],y[N];
  ll ans=5e18;
  rep(i,N) cin >> x[i] >> y[i];
  rep(sx,N){
    for(int lx=sx;lx<N;lx++){
      rep(sy,N){
      //      for(int sy=0;sy<N;sy++){
	for(int ly=sy;ly<N;ly++){
	  int tsx=min(x[sx],x[lx]);
	  int tlx=max(x[sx],x[lx]);
	  int tsy=min(y[sy],y[ly]);
	  int tly=max(y[sy],y[ly]);
	  int c=0;
	  rep(i,N){
	    if(x[i]>=tsx&&
	       x[i]<=tlx&&
	       y[i]>=tsy&&
	       y[i]<=tly){
	      c++;
	    }
	    if(c>=K){
	      ans =min(ans, (1LL*(tlx-tsx))*(1LL*(tly-tsy)) );
	      break;
	    }
	  }
	  //	  cout << c << " " << (1LL*(tlx-tsx))*(1LL*(tly-tsy))<<endl;
	}	
      }
    }
  }
  cout << ans << endl;
  
  
  return 0;

}


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

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x - r >= 0 && W - x >= r && y - r >= 0 && H - y >= r) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
	return 0;

}

Measured memory_bytes: 3100
#include<iostream>
#include<deque>
#include<map>
using namespace std;

typedef pair<int,int> Pair;
typedef map<int,bool> Map;
Map imap;

void work(void)
{
	int k=0;
	cin>>k;
	deque<Pair>deq;
	deq.push_back(make_pair(1,1));
	while(!deq.empty())
	{
		Pair x=deq.front();
		deq.pop_front();
		if(imap[x.first])
			continue;
		imap[x.first]=true;
		if(x.first==0)
		{
			cout<<x.second<<endl;
			break;
		}
		deq.push_front(make_pair((x.first*10)%k,x.second));
		deq.push_back(make_pair((x.first+1)%k,x.second+1));
	}
	return;
}

int main(int argc,char *argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL); 
	work();
	return 0;
}



Measured memory_bytes: 5760
#pragma region Include/Defines
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <queue>
#include <time.h>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef vector<pii> vpii;
typedef vector <pll> vpll;
typedef long double ld;
#define all(a) std::begin(a), std::end(a)

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

template<typename T, typename T2> inline void _max(T &a, T2 b) { a = max((T)a, (T)b); }
template<typename T, typename T2> inline void _min(T &a, T2 b) { a = min((T)a, (T)b); }

#ifdef _DEBUG
#define epr(...) fprintf(stderr,__VA_ARGS__)
#else
#define epr(...) 
#endif
#pragma endregion

const int MAX = 20;
int n;
char s[2 * MAX];
string ps;

void clear() {
	ps.clear();
}

void read() {
	scanf("%s", s);
}

lli get(string &s1, string &s2) {
	lli dp[MAX][MAX] = { 0 };
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for (int l1 = 0; l1 <= s1.size(); l1++)
		for (int l2 = 0; l2 <= s2.size(); l2++) {
			if (l1 && s1[l1 - 1] == ps[l1 + l2 - 1]) dp[l1][l2] += dp[l1 - 1][l2];
			if (l2 && s2[l2 - 1] == ps[l1 + l2 - 1]) dp[l1][l2] += dp[l1][l2 - 1];
		}
	return dp[s1.size()][s2.size()];
}

void solve() {
	for (int i = 0; i < n; i++) ps.push_back(s[n + i]);
	for (int i = 0; i < ps.size() / 2; i++) swap(ps[i], ps[ps.size() - i - 1]);
	lli res = 0;
	for (int m = 0; m < 1 << n; m++) {
		string s1, s2;
		for (int i = 0; i < n; i++)
			if (m >> i & 1) s1.push_back(s[i]);
			else s2.push_back(s[i]);
		lli tres = get(s1, s2);
		res += tres;
	}
	printf("%lld\n", res);
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d", &n) == 1) {
		clear();
		read();
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}

Measured memory_bytes: 256
K=int(input())
list=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(list[K-1])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d,e; cin>>a>>b>>c>>d>>e;
    int t=0;
    if(a<0){
	t+=((-a)*c+d);
	a=0;
    }
    t+=(b-a)*e;
    cout<<t<<endl;
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 11;
const int mod = 1e9 + 7;
int fac[N], inv[N];
int n, x, y, tot, fa[N], tong[N];
struct ddd{
    int c, w;
    bool operator < (const ddd &X) const{
        if(c != X.c)return c < X.c;
        return w < X.w;
    }
}b[N];
int find(int x){
    return fa[x] == x ? x : fa[x] = find(fa[x]);
}
void merge(int x, int y){
    int fx = find(x), fy = find(y);
    if(fx == fy)return ;
    fa[fx] = fy;
}
int main(){
    //freopen("agc012d.in", "r", stdin);
    inv[0] = inv[1] = fac[0] = fac[1] = 1;
    for(int i = 2;i <= 2e5; i++){
        fac[i] = 1LL * fac[i-1] * i % mod;
        inv[i] = (mod - 1LL * mod / i * inv[mod%i] % mod);
    }
    for(int i = 1;i <= 2e5; i++)inv[i] = 1LL * inv[i-1] * inv[i] % mod;
    cin>>n>>x>>y;
    int pmi = 1;
    for(int i = 1;i <= n; i++){
        fa[i] = i;
        scanf("%d%d", &b[i].c, &b[i].w);
    }
    sort(b + 1, b + 1 + n);
    for(int i = 1;i <= n; i++)if(b[i].w < b[pmi].w)pmi = i;
    for(int i = 1;i <= n; i++){
        if(b[i].c == b[pmi].c)continue;
        if(b[i].w + b[pmi].w <= y)merge(i, pmi);
    }
    int mi, smi = 1;
    for(int i = 1;i <= n; i++){
        if(b[i].c != b[i-1].c)mi = i;
        else{
            if(b[i].w + b[mi].w <= x)merge(i, mi);
        }
        if(b[i].c != b[pmi].c && b[i].w < b[smi].w)smi = i;
    }
    for(int i = pmi + 1;i <= n && b[i].c == b[i-1].c; i++)if(b[i].w + b[smi].w <= y)merge(i, smi);
    for(int i = 1;i <= n; i++){
        if(find(i) == find(pmi))tong[b[i].c]++;
    }
    int ans = 0, pai = 1;
    for(int i = 1;i <= n; i++){
        if(!tong[i])continue;
        ans += tong[i];
        pai = 1LL * pai * inv[tong[i]] % mod;
        //printf("i=%d tong=%d\n", i, tong[i]);
    }
    ans = 1LL * fac[ans] * pai % mod;
    cout<<ans<<endl;
    return 0;
}

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

#include <set>
#include <iterator>
using namespace std;
// using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF (ll)1e17
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
// typedef tree<pll, null_type, less<pll>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
const int  N=2e5 +10, M=(ll)1e9+1 ;
const int mod =(ll)998244353 ,sz=5, MAX=(ll)1e6+10;
string fir="Monocarp",sec="Bicarp";
	
void work(){
	ll n,x;
	cin >> n >> x;
	if(n==1){
		if(x==1)
			cout << "Yes\n" << 1 ;
		else
			cout << "No";
	}
	else if(n==2){
		if(x==2)
			cout << "Yes\n" << "1\n2\n3" ;
		else
			cout << "No";
	}
	else{
		if(x==1 || x==2*n-1) 
			cout << "No";
		else{
			cout << "Yes\n";
			map<ll,ll> m;
			m[x]=m[x+1]=m[x-1]=1;
			ll cur=1;
			if(x==2)
				m[x+2]=1;
			else 
				m[x-2]=1;

			for(ll i=1;i<=n-2;i++){
				while(m[cur]==1){
					cur++;
				}
				m[cur]=1;
				cout << cur << "\n";
			}
			if(x==2)
				cout << x+1 << "\n" << x << "\n" << x-1 << "\n" << x+2 << "\n";
			else
				cout << x-1 << "\n" << x << "\n" << x+1 << "\n" << x-2 << "\n";
			for(ll i=1;i<=2*n-1;i++){
				if(m[i]!=1)
					cout << i << "\n";
			}
		}
	}
  	return;

} 
int main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0);

	
	ll t;
	// cin >> t;
	t=1;
	while(t--){
	        work();
	}
return 0;
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head
 
void solve(){
    int r;
    cin >> r;
    cout << 3*r*r << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3636
o = input()
e = input()

for letter in range(len(o)-1):
    print(o[letter], end="")
    print(e[letter], end="")

if len(o) == len(e):
    print(o[len(o)-1], end="")
    print(e[len(e)-1])
else:
    print(o[len(o)-1])

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



int main(){
    int X;
    cin >> X;
    int judge = 0;
    for (int i = X; i < 100100; i++)
    {
        judge = 0;
        for (int j = 2; j < i; j++)
        {
            if(i%j == 0) judge++;
        }
        if(judge == 0){
            cout << i << endl;;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#define rep (i, n) for (int i = 1; i <= n; i++)

using namespace std;

int main() {
	int a, b, k;
	cin >> k >> a >> b;
	
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK\n";
			return 0;
		}
	}
	
	cout << "NG\n";
	
	return 0;
}

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

using namespace std;

typedef long long ll;


int main() {
    int N,M; cin>>N>>M;
    vector< pair<ll,ll> > py,pySorted;
    map<ll,ll> cityCnt;

    for (int i=0;i<M;i++) {
        ll p,y; cin>>p>>y;

        py.push_back(make_pair(p,y));
        pySorted.push_back(make_pair(p,y));
    }

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

    map< pair<ll,ll>, ll> ans;
    for (int i=0;i<M;i++) {
        ll p = pySorted[i].first;
        ll y = pySorted[i].second;

        ++cityCnt[p];
        
        ans[pySorted[i]] = cityCnt[p];
    }

    for (int i=0;i<M;i++) {
        cout << std::setfill('0') << std::right << std::setw(6) << py[i].first;
        cout << std::setfill('0') << std::right << std::setw(6) << ans[py[i]] << endl;
    }

    return 0;
}

Measured memory_bytes: 17124
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;

int main() {
	ll A, B, N;
	cin >> N >> A >> B;
	ll M = N / (A + B);
	cout << M * A + min(A, N - M * (A + B)) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        
        if(x==3||x==5||x==7){
            System.out.println("YES");
        }
        else{
            System.out.println("NO");
        }
        sc.close();
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};

std::vector<std::string> s;
int h, w, k, sx, sy;

int dist(int x, int y){
	int A = std::min({abs(x - (h - 1)), x, abs(y - (w - 1)), y});
	assert(A >= 0);
	
	return (A + k - 1) / k;
}

int main(){
	cin >> h >> w >> k; s.resize(h);
	for(int i = 0; i < h; i++){
		cin >> s[i];
		
		for(int j = 0; j < w; j++){
			if(s[i][j] != 'S') continue;
			sx = i; sy = j;
			break;
		}
	}
	
	std::queue<std::pair<int, int>> qu; qu.push({sx, sy});
	std::vector<std::vector<int>> min_cost(h, std::vector<int>(w, 1e9));
	min_cost[sx][sy] = 0;
	while(!qu.empty()){
		auto p = qu.front(); qu.pop();
		
		for(int i = 0; i < 4; i++){
			int nx = p.first + vy[i], ny = p.second + vx[i];
			if(nx<0||ny<0||nx>=h||ny>=w||s[nx][ny] == '#') continue;
			if(min_cost[p.first][p.second] + 1 >= min_cost[nx][ny]) continue;
			min_cost[nx][ny] = min_cost[p.first][p.second] + 1;
			qu.push({nx, ny});
		}
	}
	
	int ans = 1e9;
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			if(min_cost[i][j] <= k) ans = std::min(ans, dist(i, j) + 1);
			
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>
 
#define N 36
 
typedef struct{
  char a;
  int value;
}Card;
 
int main(){
 
  int i,j,n,min,flag=0;
  Card c[N],b[N],n1,n2;
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&c[i].a,&c[i].value);
    b[i].a=c[i].a;
    b[i].value=c[i].value;
  }
 
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(c[j].value<c[j-1].value){

    n1=c[j];
    n2=c[j-1];
      c[j]=n2;
    c[j-1]=n1;
      }
    }
  }
 
     
 
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(b[j].value<b[min].value){
    min=j;
      }
    }


    n1=b[i];
    n2=b[min];
    b[i]=n2;
    b[min]=n1;
  }
 
 
  for(i=0;i<n-1;i++){
    printf("%c%d ",c[i].a,c[i].value);
  }
  printf("%c%d\n",c[n-1].a,c[n-1].value);
  printf("Stable\n");
  
  for(i=0;i<n-1;i++){
    printf("%c%d ",b[i].a,b[i].value);
  }
  printf("%c%d\n",b[n-1].a,b[n-1].value);
    
  for(i=0;i<=n-1;i++){
    if(c[i].a!=b[i].a){
      flag=1;
    }
  }
  
  if(flag==1) printf("Not stable\n");
  else printf("Stable\n");
   
  return 0;
}

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

using namespace std;


int main(){

	long long int n,inf=100000000000000000000;
	
	cin >> n;
	vector<int>v(n+10,inf),p(n+10);
	v[0]=0;

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

	for(int i=0;i<n;i++){
		v[i+1] = min(v[i+1], v[i] + abs(p[i] - p[i+1]) );
		v[i+2] = min(v[i+2], v[i] + abs(p[i] - p[i+2]) );
	}

	cout << v[n-1] << endl;
	
	return 0;		
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int l, r, ans = 2019;
int main() {
    cin >> l >> r;
    for(int i = 0; i < 2019; i++) {
        int c = l + i;
        if(c == r) break;
        for(int j = 1; j <= 2019; j++) {
            int d = c + j;
            if(d > r) break;
            ans = min(ans, ((c % 2019) * (d % 2019)) % 2019);
        }
    }
    cout << ans;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



int n, a[101];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	i64 k = 1000;
	int mi = INF;
	for(int i = 0; i < n; i++){
		if(a[i] > a[i+1]){
			k = k%mi + (k / mi) * a[i];
			mi = INF;
		}
		else chmin(mi, a[i]);
	}
	cout << k << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> stair(n+1);
    rep(i, m){
        int a;
        cin >> a;
        stair[a] = 1;
    }
    vector<int> dp(n+2);
    const int mod = 1000000007;
    dp[n] = 1;
    for (int i = n-1; i >= 0; i--){
        if (stair[i]){
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i+1] + dp[i+2]) % mod;
    }    
    cout << dp[0] << endl;
    return 0;
}   

Measured memory_bytes: 1024
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

// dp[i][j] := sをi文字目まで見て, tをj文字目まで見た時の最長部分列
// 遷移
// dp[i+1][j+1] = dp[i][j] + 1 if s[i] == t[j];
// dp[i+1][j+1] = dp[i+1][j]   if dp[i+1][j] < dp[i][j+1]
// dp[i+1][j+1] = dp[i][j+1]   otherwise

// 復元路は後ろから前に辿る
// そもそも一致した部分は上で述べた遷移の一番上の繊維なので, そこの遷移を復元したい
// そこで, そこの遷移まで復元してやればよい
// while (i+j>0) {
//   // 斜めの時はvector<char> ans;にpush_back;
//   // 横の場合は--j;
//   // 縦の場合は--i;
// }

int dp[3030][3030];
// 0:斜め, 1:横, 2:縦
int memo[3030][3030];

signed main() {
  INIT;
	VAR(string, s, t);
	int n=s.size(), m=t.size();

	REP(i, n){
		REP(j, m) {
			if (s[i]==t[j]) {
				// 斜め
				dp[i+1][j+1] = dp[i][j] + 1;
				memo[i+1][j+1] = 0;
			} else if (dp[i+1][j]>dp[i][j+1]){
				// 横からの遷移の方がいい時
				// 0 0
				// 1 ?
				// のような時
				// 横
				dp[i+1][j+1] = dp[i+1][j];
				memo[i+1][j+1] = 1;
			} else {
				// 0 1
				// 0 ?
				// のような時
				dp[i+1][j+1] = dp[i][j+1];
			  memo[i+1][j+1] = 2;
			}
		}
	}

	/*
	REP(i,n+1){
		REP(j,m+1) {
			cerr << dp[i][j] << " ";
		}
		cerr << endl;
	}
	

	// これでdp[n][m]が最大長
	debug(dp[n][m]);
	*/
	int rest = dp[n][m], i=n, j=m;
	vector<char> ans;
	while(rest>0){
		switch(memo[i][j]) {
		case 0:
			// 斜め
			--i; --j;
			--rest;
			ans.push_back(s[i]);
			break;
		case 1:
			// 横
			--j;
			break;
		default:
			// 縦
			--i;
			break;
		}
	}
	reverse(ALL(ans));
	EACH(ai, ans){
		OUT(ai);
	}
	BR;
	
  return 0;
}


Measured memory_bytes: 143616
import java.io.*;
 
class Main {
    public static void main(String[] args) {
        
        try {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = br.readLine();
			int n = Integer.parseInt(str.split(" ")[0]);
			int k = Integer.parseInt(str.split(" ")[1]);
			int[] nimotu = new int[n];
			int totalWeight = 0;
			int maxweight = 0;
			for (int i = 0; i < n; i++) {
				nimotu[i] = Integer.parseInt(br.readLine());
				totalWeight += nimotu[i];
				if(nimotu[i] > maxweight){
					maxweight = nimotu[i];
				}
			}
			int aver = totalWeight / k;
			int settingVal= 0;
			if(maxweight < aver){
				settingVal = aver;
			}else{
				settingVal = maxweight;
			}
			int tracknum;
			while(settingVal <= totalWeight){
				int weight = 0;
				tracknum = 1;
				for(int i = 0;i < n && tracknum <= k;) {
					// ????????????????????????????????°?????????
					if(weight + nimotu[i] <= settingVal){
						weight += nimotu[i];
						i++;
					//???????????????????????????????????????????????????????????????????????£?????????????????°?¬???????????????????
					} else {
						weight = 0;
						tracknum++;
					}
				}
				if(tracknum <= k){
					System.out.println(settingVal);
					break;
				}
				settingVal++;
			}
		} catch (IOException e) {
			System.out.println("error");
		}
	}
}

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

using namespace std;



void solver() {
    int a; cin >> a;
    cout << a + a * a + a * a * a << '\n';
}

int main() {

    ios_base :: sync_with_stdio(0); cin.tie(NULL);

    int t;
    //cin >> t;
    t = 1;

    while(t--)
        solver();

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<iterator>
using namespace std;
typedef long long int lli;
int main()
{
    lli n,W,a,v1,w1;
    cin >> n >> W;
    vector<lli>w;
    vector<lli>v;
    for(lli i=0;i<n;i++)
    {      cin >> w1 >> v1;
        v.push_back(v1);
        w.push_back(w1);
    }
    lli arr[n+2][W+1];
    for(lli i=0;i<=n;i++)
    {
        for(lli j=0;j<=W;j++)
        {
            if(i==0 || j ==0)
            {
                arr[i][j]=0;
            }
            else if(w[i-1] <= j)
            {
                lli a = v[i-1]+arr[i-1][(j-w[i-1])];
                lli b = arr[i-1][j];
                arr[i][j]=max(a,b);
            }
            else
            {
                arr[i][j]=arr[i-1][j];
            }
            
        }
    }
    // for(int i=0;i<=n;i++)
    // {
    //     for(int j=0;j<=W;j++)
    //     {
    //         cout << arr[i][j] <<" ";
    //     }
    //     cout << endl;
    // }
    cout << arr[n][W] << endl;
}


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

using namespace std;

const int N=1e5+10;

string ch=".#";
int n,m;

int ans[100][100];
void solve(){
        if (n==1){
                cout<<"100 100\n";
                for(int i=0;i<100;i++){
                        for(int j=0;j<100;j++){
                                if (i%2&&j%2&&m) {
                                        cout<<ch[1];
                                        m--;
                                }else cout<<ch[0];
                        }
                        cout<<'\n';
                }
                return;
        }
        ///split 50-50
        for(int i=0;i<100;i++)
                ans[50][i]=1;
        n--,m--;
        for(int type=0;type<=1;type++){
                int st=type*51;
                for(int i=0;i<49;i++)
                        for(int j=0;j<100;j++) {
                                if (i%2&&j%2&&m) {
                                        ans[st+i][j]=type^1;
                                        m--;
                                }else ans[st+i][j]=type;
                                
                        }
                swap(n,m);
        }
        cout<<"100 100\n";
        for(int i=0;i<100;i++){
                for(int j=0;j<100;j++) cout<<ch[ans[i][j]];
                cout<<'\n';
        }
}
int main(){
        cin>>n>>m;
        if (n>m){
                swap(n,m);
                swap(ch[0],ch[1]);
        }
        solve();
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,k,l,n,m;
  int d[2][100][100]={0};
  while(scanf("%d %d",&m,&n),n||m){
    for(i=0;i<100;i++){
      for(j=0;j<100;j++)d[0][i][j]=d[1][i][j]=100000000;
      d[0][i][i]=d[1][i][i]=0;
    }
    while(m--){
      scanf("%d %d %d %d",&i,&j,&k,&l);
      d[0][i-1][j-1]=d[0][j-1][i-1]=k;
      d[1][i-1][j-1]=d[1][j-1][i-1]=l;
    }
    for(l=0;l<n;l++){
      //for(i=0;i<2;i++){
      for(j=0;j<n;j++){
	for(k=0;k<n;k++){
	  //for(l=0;l<n;l++){
	  for(i=0;i<2;i++){
	    if(d[i][j][k]>d[i][j][l]+d[i][l][k]){
	       d[i][j][k]=d[i][j][l]+d[i][l][k];
	    }
	  }
	}
      }
    }
    scanf("%d",&l);
    while(l--){
      scanf("%d %d %d",&i,&j,&k);
      printf("%d\n",d[k][i-1][j-1]);
    }
  }
  return 0;
}
      

Measured memory_bytes: 684
#include<bits/stdc++.h>
using namespace std;
vector<pair<long,long>> neighbor={{0,1},{0,-1},{1,0},{-1,0}};
long H,W,K;
vector<string>A;
long escape(long y,long x){  
  return min(min((x-1)/K,(W-x-2)/K),min((y-1)/K,(H-y-2)/K))+1;
}
int main(){
  cin>>H>>W>>K;A=vector<string>(H);
  long sy,sx;
  for(long i=0;i<H;i++){
    cin>>A[i];
    if(A[i].find("S")!=string::npos){sy=i;sx=A[i].find("S");}
  }
  if(sy==0||sy==H-1||sx==0||sx==W-1){cout<<0;return 0;}
  vector<pair<long,long>>C(1,pair<long,long>(sy,sx));
  vector<vector<long>>D(H,vector<long>(W,-1));D[sy][sx]=0;
  queue<pair<long,long>>q;q.push(pair<long,long>(sy,sx));
  while(q.size()){
    pair<long,long>f=q.front();q.pop();
    for(auto n:neighbor){      
      long y=f.first+n.first,x=f.second+n.second;
      if(0<=x&&x<W&&0<=y&&y<H&&A[y][x]!='#'&&D[y][x]==-1){
        D[y][x]=D[f.first][f.second]+1;      
        if(D[y][x]<=K){
          if(y==0||y==H-1||x==0||x==W-1){cout<<1;return 0;}
          if(D[y][x]<K)q.push(pair<long,long>(y,x));    
          C.push_back(pair<long,long>(y,x));
        }
      }
    }
  }
  long ans=LONG_MAX;
  for(auto c:C)ans=min(ans,1+escape(c.first,c.second));
  cout<<ans;
}



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

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int K, S;
	
	cin >> K >> S;

	int count = 0;

	for (int i = 0; i <= K; i++)
	{
		for (int j = 0; j <= K; j++)
		{
			int z = S - i - j;
			if ((z <= K) && (z>=0))
			{
				count++;
			}
		}
	}

	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    int n;
    ll ans = 0;
    string s, t;
    int k = 0, v;
    cin >> n;
    t = to_string(n);
    char nn = t[0];
    int nl = t.size();
    for (int i = 1; i <= n; ++i) {
        s = to_string(i);
        int l = s.size();
        if (s[l - 1] == '0')
            continue;

        if (s[0] == s[l - 1]) { // 1
            ans++;
        }
        if ((s[l - 1] - '0') * 10 + (s[0] - '0') <= n) // 2
            ans++;
        
        for (int j = 1; j <= 4; ++j) {
            if (2 + j < nl) {
                ans += pow(10, j);
            }
            else if (2 + j == nl) {
                if (s[l - 1] < nn) {
                    ans += pow(10, j);
                }
                else if (s[l - 1] == nn) {
                    ans += stoi(t.substr(1, j));
                    if (t[nl - 1] >= s[0])
                        ans++;
                }
            }
            else {
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <iostream>
using namespace std;
typedef vector<vector<int>> Graph;

void dfs(const Graph &g,vector<int>&v,int cur,int d){
	v[cur]=d;
	for(auto &e:g[cur])if(!v[e])dfs(g,v,e,d+1);
}

int main(){
	const int INF=1<<29;
	int N,K,R=INF;
	scanf("%d%d",&N,&K);
	vector<int>deg(N);
	Graph g(N);
	for(int i=0;i<N-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;b--;
		deg[a]++;deg[b]++;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	if(K%2==0){
		for(int i=0;i<N;i++){
			vector<int>v(N);
			v[i]=1;
			dfs(g,v,i,1);
			int r=0;
			for(int j=0;j<N;j++){
				if(v[j]-1>K/2)r++;
			}
			R=min(R,r);
		}
	}else{
		for(int i=0;i<N;i++)for(auto &k:g[i])if(i<k){
			vector<int>v(N);
			v[i]=v[k]=1;
			dfs(g,v,i,1);
			dfs(g,v,k,1);
			int r=0;
			for(int j=0;j<N;j++){
				if(v[j]-1>K/2)r++;
			}
			R=min(R,r);
		}
	}
	if(R==INF)return 1;
	printf("%d\n",R);
}

Measured memory_bytes: 512
n=int(input())
a,b,c=[],[],[]
for _ in range(n):
    t=map(int,input().split())
    a.append(t.__next__())
    b.append(t.__next__())
    c.append(t.__next__())
dpA,dpB,dpC=[a[0]],[b[0]],[c[0]]
for i,(A,B,C)in enumerate(zip(a,b,c)):
    if not i:continue
    ta,tb,tc=dpA[-1],dpB[-1],dpC[-1]
    dpA.append(max(tb,tc)+A)
    dpB.append(max(tc,ta)+B)
    dpC.append(max(ta,tb)+C)
print(max(dpA[-1],dpB[-1],dpC[-1]))

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

const int N = 2e5 + 7;

int n, a[N];
bool b[N];

bool nbig(int x) {
	for (int i = 1; i < 2 * n; i++) {
		if (a[i] <= x)
			b[i] = 1;
		else
			b[i] = 0;
	}
	if (b[n] == b[n - 1] || b[n] == b[n + 1])
		return b[n];
	int l = 0, r = 2 * n;
	for (int i = 1; i + 1 < 2 * n; i++) {
		if (b[i] == b[i + 1]) {
			if (i < n)
				l = i + 1;
			else
			if (r == 2 * n)
				r = i;
		}
	}
	if (r == 2 * n && !l) {
		return (b[n] + n + 1) % 2;
	}	
	if (n - l < r - n)
		return b[l];
	else
		return b[r];
}

int main() {
	cin >> n;
	for (int i = 1; i < 2 * n; i++)
		cin >> a[i];
	int l = 0, r = 2 * n;
	while (r - l > 1) {
		int md = (r + l) / 2;
		if (nbig(md))
			r = md;
		else
			l = md;
	}
	cout << r;

	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

ll limit = 41;

vector <ll> to_array(ll num){
    vector <ll> ret(limit, 0);
    ll idx = 0;
    while (num > 0){
        ret[idx] = num % 2;
        num /= 2;
        idx++;
    }
    return ret;
}


int main(void){
    ll n; cin >> n;
    vector <ll> as;
    ll tot = 0;
    REP(i, n){
        ll a; cin >> a;
        as.push_back(a);
        if (i > 1){
            tot = tot ^ a;
        }
    }
    vector <ll> other = to_array(tot);
    ll gokei = as[0] + as[1];
    ll larger = tot;
    ll smaller = 0;
    for(int i=limit-1; i>=0; i--){
        if (other[i] == 1){
            continue;
        }
        ll add = pow(2, i)*2;
        if (add + tot > gokei){
            continue;
        }
        gokei -= add;
        larger += add / 2;
        smaller += add / 2;
    }
    if (gokei != tot){
        cout << -1 << endl;
        return 0;
    }
    ll now = smaller;
    for(int i=limit-1; i>=0; i--){
        if (other[i] == 0){
            continue;
        }
        ll add = pow(2, i);
        if (add + now > as[0]){
            continue;
        }
        now += add;
    }
    ll ans = as[0] - now;
    if ((ans < 0) or (ans >= as[0])){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}

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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007LL;

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

int main() {
  int N;
  string S;
  cin>>N>>S;
  map<char,ll> num;
  rep(i,N){
    num[S[i]]++;
  }
  ll ans = 1LL;
  for(auto x:num){
    ans*=(x.second+1);
    ans%=mod;
  }
  ans--;
  if(ans<0) ans+=mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;


int main() {


	int a, b, c;

	cin >> a >> b >> c;

	cout << (a+b+c<=21?"win":"bust") << endl;

	return 0;
}

Measured memory_bytes: 256
t[99],h[99];
main(i,s,N,T,L){
for(scanf("%d%d%d%d",&N,&T,&L,&L),i=0;i<N;i++)scanf("%d%d",t+i,h+i);
for(i=s=0;;i=(i+1)%N)if(t[i]){
    t[i]--;
    if(++T>L)break;
    if(++s==9)s=0;
}else if(h[i]){
    h[i]--;
    if(T<++s)break;
    t[i]=s;T-=s;s=0;
}else break;
printf("%d\n",i+1);exit(0);}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int n,cnt[105],a,ori;
int boza=1;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        a=i;
        while(1)
        {
            if(a%2==0)
            {
                cnt[i]=cnt[i]+1;
                a=a/2;
            }
            else
            {
                break;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(cnt[i]>ori)
        {
            ori=cnt[i];
            boza=i;
        }
    }
    printf("%d",boza);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
  cin>>n;
  int max=INT_MIN;
  	int count=0;
  	int a[21]={0};
  	for(int i=0;i<n;i++)
    {
		cin>>a[i];
      if(a[i]>=max)
      {		max=a[i];
            count++;
      }
      
 
    }
  	cout<<count;
}
      
 

Measured memory_bytes: 256