akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N;
	static int[] A;
	static boolean[] x;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			A = new int[N + 1];
			x = new boolean[N + 1];
			System.out.println(solve());
		}
	}

	static String solve() {
		HashSet<Integer> set = new HashSet<Integer>();
		for (int i = 0; i < N; ++i) {
			String elem = sc.next();
			if (elem.equals("x")) {
				x[i] = true;
			} else {
				A[i] = Integer.parseInt(elem);
				set.add(A[i] - 2);
				set.add(A[i] - 1);
				set.add(A[i]);
				set.add(A[i] + 1);
				set.add(A[i] + 2);
			}
		}
		A[N] = N % 2 == 0 ? Integer.MIN_VALUE : Integer.MAX_VALUE;
		if (set.isEmpty()) return ok() ? "ambiguous" : "none";
		int ans = Integer.MIN_VALUE;
		for (int cand : set) {
			for (int i = 0; i < N; ++i) {
				if (x[i]) A[i] = cand;
			}
			if (ok()) {
				if (ans == Integer.MIN_VALUE) {
					ans = cand;
				} else {
					return "ambiguous";
				}
			}
		}
		return ans == Integer.MIN_VALUE ? "none" : ans + "";
	}

	static boolean ok() {
		for (int i = 1; i < N; ++i) {
			if (i % 2 != 0) {
				if (A[i] <= A[i - 1] || A[i] <= A[i + 1]) return false;
			} else {
				if (A[i] >= A[i - 1] || A[i] >= A[i + 1]) return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 55968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define fs first
#define sc second

int main(void){
	int n,a,b;
	cin >> n >> a >> b;
	cout << min(b, n*a) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;
const int mx=300030;

struct segtree {//segtree seg=segtree(n);//n:データ数  0-index 基本半区間？
  int seg_unit=0;//単位元 minなら2e9など
  int segfunc(int a,int b){
    return max(a,b);
  }
    int N=1;
    vector<int> dat, sum;
    segtree(int n) {//n:データ数
        N = 1;
        while(N < n) N <<= 1;
        dat.assign(2*N-1,seg_unit);
        sum.assign(2*N-1,0);
    }
    void set_dat(int k, int a){
      k += N-1; // leaf
      dat[k] = a;
    }
    void set_func(){
      for(int i=N-1; i>0; --i) dat[i] = segfunc(dat[i*2+0], dat[i*2+1]);
    }
    void update(int k, int a) {//dat[k]=a
        k += N-1; // leaf
        dat[k] = a;
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = segfunc(dat[k*2+1], dat[k*2+2]);
        }
    }
    void add(int a, int b, int x) { add(a,b,x,0,0,N); }
    int add(int a, int b, int x, int k, int l, int r) {//区間和
        if(b <= l || r <= a) return dat[k];
        if(a <= l && r <= b) {
            sum[k] += x;
            return dat[k] += x;
        }
        int m = (l+r)/2;
        return dat[k] = segfunc(add(a,b,x,2*k+1,l,m),add(a,b,x,2*k+2,m,r))+sum[k];
    }
    int query(int a, int b) { return query(a,b,0,0,N); }
    int query(int a, int b, int k, int l, int r) {
        if(b <= l || r <= a) return seg_unit;
        if(a <= l && r <= b) return dat[k];
        int m = (l+r)/2;
        return segfunc(query(a,b,2*k+1,l,m),query(a,b,2*k+2,m,r))+sum[k];
    }
};

int main(){
	int n,k;
    cin>>n>>k;
    vi a(n);
    segtree s(mx+1);
    FOR(i,0,mx+1){
        s.set_dat(i,0);
    }
    FOR(i,0,n){
        cin>>a[i];
        a[i]++;
    }
    s.update(a[0],1);
    FOR(i,1,n){
        int l=max(a[i]-k,0);
        int r=min(a[i]+k+1,mx-1);
        int t=s.query(l,r)+1;

        s.update(a[i],t);
    }
    cout<<s.query(0,mx+1)<<endl;

}


Measured memory_bytes: 12772
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	private void doit(){
		while(sc.hasNext()){
			int n = sc.nextInt();
			if(n == 0) break;
			int year = sc.nextInt();
			int [][] data = new int[n][3];
			int ind = -1;
			double max = 0.0;
			for(int i = 0; i < n; i++){
				data[i][0] = sc.nextInt();
				data[i][1] = sc.nextInt();
				data[i][2] = sc.nextInt();
				
				double now = 0;
				if(data[i][2] == 1){
					now = 1 + (double)year * data[i][1] / 100;
				}
				else{
					now = 1;
					for(int j = 0; j < year; j++){
						now *= 1 + (double)data[i][1] / 100;
					}
				}
				if(max < now){
					max = now;
					ind = data[i][0];
				}
			}
			System.out.println(ind);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 37940
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

int main(){
    map<char, int> mci;
    string str;
    cin >> str;
    rep(i,str.size()){
        mci[str[i]] = 1;
    }
    if(mci['N'] == mci['S'] && mci['W'] == mci['E']){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int H, W, N;
set<pair<int, int>> B, cand;

void add(int y, int x) {
   if (y >= 0 && y < H-2 && x >= 0 && x < W-2) {
      cand.insert({y, x});
   }
}

int main() {
   cin >> H >> W >> N;
   rep (i, N) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      B.insert({a, b});
      rep (y, 3) {
         rep (x, 3) {
            add(a-y, b-x);
         }
      }
   }

   vec<ll> ans(10);
   ans[0] = 1LL * (H-2) * (W-2);
   for (auto c : cand) {
      int y = c.first, x = c.second;
      int cnt = 0;
      rep (i, 3) {
         rep (j, 3) {
            if (B.find({y+i, x+j}) != B.end()) {
               cnt++;
            }
         }
      }
      ans[cnt]++;
      ans[0]--;
   }

   for (ll x : ans) {
      cout << x << endl;
   }

   return 0;
}

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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  int x, y;
  cin >> x >> y;
  if(x < 0 && y < 0) {
    if(x <= y) cout << y - x << endl;
    else cout << x - y + 2 << endl;
  } else if(x > 0 && y > 0) {
    if(x <= y) cout << y - x << endl;
    else cout << x - y + 2 << endl;
  } else if(x <= 0 && y >= 0) {
    if(-x <= y) cout << min(y - x, y + x + 1) << endl;
    else cout << min(y - x, -x - y + 1) << endl;
  } else if(x >= 0 && y <= 0) {
    cout << max(x, -y) - min(x, -y) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
s = gets.chomp.split('').map(&:to_i)
n = s.size
m = 10000
(0..n-3).each do |i|
  num = (s[i] * 100) + (s[i + 1] * 10) + s[i + 2]
  small = (753 - num).abs
  m = small if m > small
end
puts m

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define N 12
using namespace std;
 
int main(){
  int n,l,v,k=1,x,y;
  int d[N][N];
  int dy[2]={-1,1};
  int dx[2]={1,-1};
  while(1){
    cin>>n;
    if(!n)break;
    l=x=y=0;
    d[y][x]=1;
    v=2;
    while(!(y==n-1&&x==n-1)){
      int ny=y+dy[l],nx=x+dx[l];
      if(ny<0||nx<0||n<=ny||n<=nx){
    if(!l){
      if(x+y<n-1)ny=y,nx=x+1;
      else ny=y+1,nx=x;
    }else{
      if(x+y<n-1)ny=y+1,nx=x;
      else ny=y,nx=x+1;
    }
    l=!l;
      }
      d[ny][nx]=v++;
      y=ny,x=nx;
    }
    cout<<"Case "<<k<<":"<<endl;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
    printf("%3d",d[i][j]);
      }
      cout<<endl;
    }
    k++;
  }
  return 0;
}

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

namespace ABC162C
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());

            long sum = 0;
            for(int i = 1; i <= k; i++)
            {
                for(int j = 1; j <= k; j++)
                {
                    for(int l = 1; l <= k; l++)
                    {
                        int gcd_ij = GCD(i, j);
                        sum += GCD(gcd_ij, l);
                    }
                }
            }

            Console.WriteLine($"{sum}");
        }

        static int GCD(int a, int b)
        {
            int r = a % b;
            if (r == 0)
            {
                return b;
            }

            return GCD(b, r);
        }
    }
}


Measured memory_bytes: 27452
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	ll n=0,ans=0;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='R')
		n++;
		else n=0;
		ans=max(n,ans);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include<stdio.h>


int main(void){

  int l[10];
  int v[2];
  double ans;
  int sum, V;
  int i;


  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", 
	      &l[0], &l[1], &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v[0], &v[1])!=EOF){

    sum=0;
    for(i=0; i<10; i++){
      sum+=l[i];
    }
    V=v[0]+v[1];
    
    ans = (double)(sum*v[0])/(double)V;

    for(i=0; i<10; i++){
      if(ans-l[i]<=0){
	printf("%d\n", i+1);
	break;
      }
      ans-=l[i];
    }


  }

  return(0);
}



Measured memory_bytes: 2068
def gcd(a, b):
  a, b = max(a, b), min(a, b)
  if a % b == 0:
    return b
  else:
    return gcd(b, a % b)

n, z = map(int, input().split())
x = list(map(int, input().split()))

m = abs(x[0] - z)
for i in range(1, n):
  m = gcd(m, abs(x[i] - z))
print(m)

Measured memory_bytes: 14224
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#undef DBG



void insertnumnum(
int *i_nums,
int in_len,
int in_number
);


int comp_int(const void *a, const void *b);

int comp_int(const void *a, const void *b)
{
            return *(int*)a - *(int*)b;
}

int main()
{
        int  inputc;
        char numbuff[100000+1];
        int numbers[100000];
        int numnum;
        int j;
        int N;

        j = 0;
        while( (inputc = getc(stdin)) != '\n' ) {
                numbuff[j++] = inputc;
        }
        numbuff[j] = '\0';
        N = atoi( numbuff );


        numnum = 0;
        j = 0;
        while( (inputc = getc(stdin)) != EOF ) {
#ifdef DBG
printf("input char %c\n", inputc);
#endif
                if( inputc == ' ' || inputc == '\n' ) {
                        numbuff[j]  = '\0';
                        numbers[numnum++] = atoi(numbuff);
                        j=0;
                        continue;
                }
                else {
                        numbuff[j++] = inputc;
                }

#ifdef DBG
                for( int k =0; k < numnum; k++ ) { printf("<%d>", numbers[k]); } printf("\n");
#endif
        }
#ifdef DBG
        for( int k =0; k < numnum; k++ ) { printf("<%d>", numbers[k]); } printf("\n");
        printf("get numbuff\n");
#endif

        qsort(numbers, numnum, sizeof(int), comp_int);
        printf("%d\n", numbers[N/2]-numbers[N/2-1]);
        return 0;
}

void insertnumnum(
int *i_nums,
int in_len,
int in_number
) {
        int o_nums[100000];

        int i_nums_i = 0;
        int o_nums_i = 0;

        /* printf("input=%d\n", in_number ); */
        for( i_nums_i = 0; i_nums_i < in_len; i_nums_i++ ) {
                if( i_nums[i_nums_i] > in_number ) {
                   o_nums[o_nums_i++] =in_number;
                   break;
                }
                else {
                        o_nums[o_nums_i++] = i_nums[i_nums_i];
                }
        }
        for( ; i_nums_i < in_len; i_nums_i++ ) {
                o_nums[o_nums_i++] = i_nums[i_nums_i];
        }

        if( i_nums_i == o_nums_i ) {
                o_nums[o_nums_i]  = in_number;
        }

        for( int i = 0; i < in_len+1; i++ ) {
                i_nums[i] = o_nums[i];
        }
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
long long q[11];
int main()
{
	long long r,d,x2000;
	cin>>r>>d>>x2000;
	q[0] = x2000;
	for(long long i=1;i<11;i++)
	{
		q[i] = r*(q[i-1])-d;
	}
	for(long long i=1;i<11;i++)
	{
		cout<<q[i]<<endl;
	}
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> n(N);
    vector<int> h(N);
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    if(N == 1){
        cout << "Yes" << endl;
        return 0;
    }
    
    for(int i = 0; i < N-1; i++){
        if(h[i] < h[i+1]) h[i+1]--;
        if(h[i] > h[i+1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes"<< endl;
    return 0;
    
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int n;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		if(i*4<=n&&(n-i*4)%7==0)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}


Measured memory_bytes: 256
N = int(input())
INF = float('inf')
dp = [INF] * (N+1)
dp[0] = 0

for n in range(N + 1):
    power = 0
    while pow(6, power) <= N:
        dp[n] = min(dp[n], dp[n - pow(6, power)] + 1)
        power += 1

    power = 0
    while pow(9, power) <= N:
        dp[n] = min(dp[n], dp[n - pow(9, power)] + 1)
        power += 1

print(dp[N])


Measured memory_bytes: 3828
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
# from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
import math
# from itertools import product, accumulate, combinations, product
#import bisect
# import numpy as np
# from copy import deepcopy
#from collections import deque
# from decimal import Decimal
# from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())



def run():
    S = input()
    G = 0
    P = 0
    score = 0
    for s in S:
        if s == 'g':
            if G > P:
                score += 1
                P += 1
            else:
                G += 1
        if s == 'p':
            if G > P:
                P += 1
            else:
                G += 1
                score -= 1

    print(score)

if __name__ == "__main__":
    #print(math.gcd(0, 10))
    run()


Measured memory_bytes: 9448
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define rrep(i,n) for(ll i=(ll)n-1;i>=0;--i)
#define vin(v,n) rep(i,n)cin>>v[i];
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define sz size()
#define fi first
#define se second
#define pb push_back
#define prqueue priority_queue<ll,vector<ll>,greater<ll>>
#define print(s) cout<<s<<endl;
#define inp(s) cin>>s;
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll n, m,r=-100,ans;
pp v[100010];
int main() {
	cin >> n >> m;
	rep(i, m) {
		cin >>v[i].fi>>v[i].se;
	}
	sort(v, v + m);
	rep(i, m) {
		if (r <= v[i].fi)++ans,r=v[i].se;
		r = min(r, v[i].se);
	}
	print(ans);
	return 0;
}

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

#define F first
#define S second
#define pb push_back
#define SZ(x) (int)(x.size())

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;

const ll maxn=1e5+10, mod=1e9+7, inf=1e18;

ll dp[maxn][3],a[maxn],b[maxn],c[maxn];

int main(){

	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	ll n; cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];

	for(int i=1;i<=n;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];		
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
	}
	cout<<max(max(dp[n][0],dp[n][1]),dp[n][2])<<endl;


	return 0;

}




















Measured memory_bytes: 4992
#include<iostream>

using namespace std;

#define N 50

int n,A[N];

int sol(int i,int m){
  if (m==0) {

    return 1;
  }

  if (i>=n) {
    return 0;
  }
int res=sol(i+1,m) || sol(i+1,m-A[i]);

return res;

}

int main(){
  int q,M;

  cin >> n;

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

  cin >> q;

  for (int i=0; i<q;i++){
    cin >> M;
    if(sol(0,M)) cout << "yes" << endl;
else cout << "no" << endl;
  }

  return 0;
  }



Measured memory_bytes: 3100
fun main(args: Array<String>) {
    abc050b()
}

fun abc050b() {
    val n = readLine()!!.toInt()
    val tList = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    val m = readLine()!!.toInt()
    val pxList = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }
        .map { Pair(it[0], it[1]) }

    val sum = tList.sum()

    val answer = pxList.map { px ->
        sum - (tList[px.first - 1] - px.second)
    }

    println(answer.joinToString(System.lineSeparator()))
}


Measured memory_bytes: 36036
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>
#include<cmath>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    bool ans=true;
    if(A==B){
        if(B==C)ans=false;
    }
    else if(B==C){}
    else if(A==C){}
    else ans=false;
    if(ans)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations as comb
h,w,k = map(int,input().split())

def check(r,c,a):
  b = 0
  for i in range(h):
    if r[i]:
      for j in range(w):
        if c[j] and a[i][j] == '#':
          b += 1
  return int(b==k)

a = []
for _ in range(h):
  a.append(list(input()))
row_comb = []
col_comb = []
rows = [i for i in range(h)]
cols = [i for i in range(w)]
for i in range(h+1):
  row_comb += list(comb(rows,i))
for i in range(w+1):
  col_comb += list(comb(cols,i))
ans = 0
for row in row_comb:
  for col in col_comb:
    r = [True]*h
    c = [True]*w
    for i in row:
      r[i] = False
    for i in col:
      c[i] = False
    ans += check(r,c,a)
print(ans)

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


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

  ll yen500, yen5;

  yen500 = x/500;
  yen5 = (x%500)/5;

  cout << yen500*1000 +yen5*5 << endl;
}


  

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 998244353
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	ll n, cnum;

	cin>>n>>cnum;

	vvll d(cnum, vll(cnum)), c(n, vll(n)), hist(3, vll(cnum)), cost(3, vll(cnum));

	rep(i, cnum){
		rep(j, cnum) cin>>d[i][j];
	}

	rep(i, n){
		rep(j, n){
			cin>>c[i][j];
			c[i][j]--;
			hist[(i+j)%3][c[i][j]]++;
		}
	}

	rep(i, 3){
		//全ての色をjに統一
		rep(j, cnum){
			rep(k, cnum){
				cost[i][j]+=d[k][j]*hist[i][k];
			}
		}
	}

	//1つ目を色i、2つ目を色j、3つ目を色k
	ll min=1e18;
	rep(i, cnum){
		rep(j, cnum){
			if(i==j) continue;
			rep(k, cnum){
				if(i==k||j==k) continue;
				ll temp=cost[0][i]+cost[1][j]+cost[2][k];
				//cout<<i<<" "<<j<<" "<<k<<endl;
				if(min>temp) min=temp;
				
			}
		}
	}
	cout<<min<<endl;
}


Measured memory_bytes: 2176
#include<string>
using namespace std;
#include <stdio.h>
#include <limits.h>
#include "bits/stdc++.h"
int N = 0;
int M = 0;
int X = 0;
int a = 0;
int f[100];
int r = 0;
int b = 0;
int c = 0;
int main() {
	cin >> N >> M >> X;
	for (int i = 0;i < M;i++) {
		cin >> a;
		f[a] = 1;
	}
	for (int j = 0; j < X;j++) {
		b = b + f[j];
	}
	for (int k = X; k < N;k++) {
		c = c + f[k];
	}
	r = min(b, c);


	cout << r;
	return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


a, b = inpl()
print(a * b)


Measured memory_bytes: 68372
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int p1 = 0;
        int p2 = 0;
        for(int i = 0; i < s.length(); i++){
            char c = s.charAt(i);
            if(i % 2 == 0){
                if(c == '0'){
                    p1++;
                }else{
                    p2++;
                }
            }else{
                if(c == '1'){
                    p1++;
                }else{
                    p2++;
                }
            }
        }
        
        System.out.println(p1 > p2 ? p2 : p1);
    }
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int s, f;
        cin >> s >> f;
        if (s <= a && a < f) {
            cout << 1 << '\n';
            return 0;
        }
        if (s < b && b <= f) {
            cout << 1 << '\n';
            return 0;
        }
        if (a < f && f <= b) {
            cout << 1 << '\n';
            return 0;
        }
        if (a <= s && s < b) {
            cout << 1 << '\n';
            return 0;
        }
    }
    cout << 0 << '\n';
    return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
#define LL long long 
char d[105][105];

int main(){
    int r,g,b;
    LL H, W;
    LL ans = 1e18;
    cin >> H >> W;

    for (int k = 0; k < 2; k++) {
        for (int i = 1; i < H; i++) {
            LL a = i * W; // 一番上のやつの面積
            // 縦と横に3分割したとき 
            LL b = (W/2) * (H-i);
            LL c = ((W+1)/2) * (H-i);
            ans = min(ans, abs(max(max(a, b), c) - min(min(a, b), c) ));
            // 縦に3分割したとき 
            b = ((H-i)/2) * W;
            c = ((H-i+1)/2) * W;
            ans = min(ans, abs(max(max(a, b), c) - min(min(a, b), c)));
        }
        swap(H, W);
   }

    
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int ac=0, wa=0, tle=0, re=0, n;
  cin >> n;
  string s;
  for(int i=0; i<n; i++){
    cin >> s;
    switch(s[0]){
    case 'A':
        ac++;
        break;
    case 'W':
        wa++;
    	break;
    case 'T':
        tle++;
        break;
    case 'R':
        re++;
    	break;
    default:
    	break;
    }
  }
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;

  return 0;
}

Measured memory_bytes: 3656
n = gets.to_i
arr = gets.split.map(&:to_i)
s = ""
arr.each{|a| s += a.to_s; s += " "}
puts s.chop

for i in 1..(n-1)
  v = arr[i]
  j = i-1
  while j >= 0 && arr[j] > v
    arr[j+1] = arr[j]
    j -= 1
  end
  arr[j+1] = v
  s = ""
  arr.each{|a| s += a.to_s; s += " "}
  puts s.chop
end

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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  rep(i,N) cin >> x.at(i);
  
  int ans = 0;
  vector<int> y(N);
  rep(i,N) {
    y.at(i) = abs(X - x.at(i));
    ans = __gcd(ans, y.at(i));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
bingo = [[False, False, False] for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                bingo[i][j] = True

# print('A', A, N, b, bingo)

for i in range(3):
    if sum(bingo[i]) == 3:
        print('Yes')
        exit()
for i in range(3):
    tmp = [bingo[0][i], bingo[1][i], bingo[2][i]]
    # print('tmp', tmp, sum(tmp))
    if sum(tmp) == 3:
        print('Yes')
        exit()

tmp = [bingo[0][0], bingo[1][1], bingo[2][2]]
# print('tmp', tmp, sum(tmp))
if sum(tmp) == 3:
    print('Yes')
    exit()

tmp = [bingo[0][2], bingo[1][1], bingo[2][0]]
if sum(tmp) == 3:
    print('Yes')
    exit()

print('No')


Measured memory_bytes: 3192
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

void solve(const int n, const string &s, const int k) {
  ll d = 0, m = 0, dm = 0, ans = 0;
  vl rd(n, 0), rm(n, 0);
  REP(i, n) {
    if (rd[i] < 0) {
      d -= 1;
      dm -= m;
    }
    if (rm[i] < 0) {
      m -= 1;
    }

    if (s[i] == 'D') {
      d++;
      if (i + k < n)
        rd[i + k]--;
    }
    if (s[i] == 'M') {
      m++;
      dm += d;
      if (i + k < n)
        rm[i + k]--;
    }
    if (s[i] == 'C') {
      ans += dm;
    }
  }
  cout << ans << endl;
}

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

  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  REP(i, q) {
    int k;
    cin >> k;
    solve(n, s, k);
  }
  return 0;
}


Measured memory_bytes: 17052
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

const INF: i32 = 1000000000;

fn main() {
    input! {
        n: usize,
        m: usize,
        x: i32,
        ca:[(i32,[i32;m]);n],
    }

    let mut ans: i32 = INF;

    for bit in 0..(1 << n) {
        let mut price = 0;
        let mut smart = vec![0i32; m];
        for i in 0..n {
            if (bit >> i) & 1 == 1 {
                // 合計金額を加算
                price += ca[i].0;

                // アルゴリズムの数だけ回す
                for j in 0..m {
                    // 教科書の理解度を加算する
                    smart[j] += ca[i].1[j]
                }
            }
        }

        // 全ての理解度がxを超えてるか判断
        if smart.iter().fold(true, |isok, &s| isok && s >= x) {
            // ansとpriceを比較して小さい方をansに代入
            ans = std::cmp::min(price, ans);
        }
    }

    if ans >= INF {
        println!("-1")
    } else {
        println!("{}", ans)
    }
}


Measured memory_bytes: 2156
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,m;
   cin>>n>>m;
   int a[m];
   int sum=0;
   for(int i=0;i<m;i++)
   {
       cin>>a[i];
       sum+=a[i];
   }
   cout<<max(-1LL,n-sum)<<endl;
}


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

vector< vector<int> > vv;
void dfs(int n,int max, vector<int> v) {
  for(int i=1; i<=max; ++i) {
    if(n==i) {
      v.push_back(i);
      vv.push_back(v);
      break;
    }
    vector<int> nv = v;
    nv.push_back(i);
    dfs(n-i, i, nv);
  }
  return;
}

int main() {
  int n;
  while(cin>>n, n) {
    vv.clear();
    dfs(n,n, vector<int>());
    for(vector< vector<int> >::reverse_iterator i=vv.rbegin(); i != vv.rend(); ++i) {
      for(int j=0; j<(*i).size(); ++j) {
	cout<<(*i).at(j);
	if(j<(*i).size()-1)
	  cout<<" ";
      }
      cout<<endl;
    }
  }
}

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

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

    if( (n%2) != 0 )cout<<"No"<<endl;
    else
    {
        string a = "";
        string b = "";
        for(int i = 0; i < n/2; i++)a += s[i];
        for(int i = n/2; i < n; i++)b += s[i];
        //cout<<a<<endl;
        //cout<<b<<endl;
        if( a == b )cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int H,W;
  cin>>H>>W;
  vector<vector<char>>A(H,vector<char>(W));
  for(int i=0;i<H;i++){
    string s;
    cin>>s;
    for(int j=0;j<W;j++)
      A.at(i).at(j)=s.at(j);
  }vector<vector<int>>B(H,vector<int>(W,0));
  for(int i=0;i<H;i++){
    int sum=0;
    for(int j=0;j<W;j++){
      if(A.at(i).at(j)=='#'){
      sum=0; B.at(i).at(j)+=sum;
      }else{
      sum++; B.at(i).at(j)+=sum;
      }
  
  }
  }for(int j=0;j<W;j++){
    int sum=0;
    for(int i=H-1;0<=i;i--){
      if(A.at(i).at(j)=='#'){
      sum=0; B.at(i).at(j)+=sum;
      }else{
      sum++; B.at(i).at(j)+=sum;
      }
  
  }
  }for(int i=0;i<H;i++){
    int sum=0;
    for(int j=W-1;0<=j;j--){
      if(A.at(i).at(j)=='#'){
      sum=0; B.at(i).at(j)+=sum;
      }else{
      sum++; B.at(i).at(j)+=sum;
      }
  
  }
  }for(int j=0;j<W;j++){
    int sum=0;
    for(int i=0;i<H;i++){
      if(A.at(i).at(j)=='#'){
      sum=0; B.at(i).at(j)+=sum;
      }else{
      sum++; B.at(i).at(j)+=sum;
      }
  
  }
  }int ans=0;
  for(int i=0;i<H;i++){
  for(int j=0;j<W;j++){
  if(ans<B.at(i).at(j))
    ans=B.at(i).at(j);
  }
  }ans-=3;
  cout<<ans<<endl;
    return 0;
}

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int main(void) {
    int n = in();
    cout << (n * (n + 1)) / 2 << endl;

    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll mod=1e9+7;

vector<ll> p;

void dfs(ll s,ll t){
    p.push_back(t);
    if(s==11){
        return;
    }
    string v=to_string(t);
    ll n=v.length();
    ll m=v[n-1]-'0';
    for(ll i=m-1;i<=m+1;i++){
        if(0<=i && i<=9){
            dfs(s+1,10*t+i);
        }
    }
}

int main()
{
    ll k;
    cin >> k;
    for(ll i=1;i<=9;i++){
        dfs(1,i);
    }
    sort(p.begin(),p.end());
    cout << p[k-1] << endl;
    return 0;
} 

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

using namespace std;

const int Mmax = 1e5 + 5;
int N,M;
int dp[Mmax];
set <int> a[Mmax];
bool viz[Mmax];

inline void dfs(int node) {
    viz[node] = 1;
    for(auto i : a[node]) {
        if(!viz[i]) {
            dfs(i);
            dp[node] = max(dp[node], dp[i] + 1);
        } else
            dp[node] = max(dp[node], dp[i] + 1);
    }
}

int main() {
    cin >> N >> M;
    while(M--) {
        int x,y;
        cin >> x >> y;
        a[x].insert(y);
    }
    for(int i = 1; i <= N; ++i)
        if(!viz[i])
            dfs(i);
    int ans = 0;
    for(int i = 1; i <= N; ++i) {
        ans = max(ans,dp[i]);
        //  cout << dp[i] << " ";
    }
    cout << ans;
    return 0;
}


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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	string s; cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		if (i % 2 == 0 && s[i] == 'L') {
			cout << "No\n";
			return 0;
		}
		if (i % 2 == 1 && s[i] == 'R') {
			cout << "No\n";
			return 0;
		}
	}

	cout << "Yes\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,ans[100000];
string s;
vector<ll>v;
int32_t main(){
cin>>s;
n=s.size();
for(ll i=0;i<n-1;i++)
if(s[i]=='R'&&s[i+1]=='L'){
v.pb(i);
}
for(ll i=0;i<n;i++){
if(s[i]=='L'){
if(s[i-1]=='R'){
ans[i]++;
}else {
for(ll j=v.size()-1;j>=0;j--)
if(v[j]<=i){
if((i-v[j])%2==1){
ans[v[j]+1]++;
}else ans[v[j]]++;
break;
}
}
}else if(s[i]=='R'){
if(s[i+1]=='L'){
ans[i]++;
}else {
for(ll j=0;j<v.size();j++)
if(v[j]+1>i){
if((v[j]+1-i)%2==1){
ans[v[j]]++;
}else ans[v[j]+1]++;
break;
}
}
}
}
for(ll i=0;i<n;i++)
cout<<ans[i]<<' ';
}


Measured memory_bytes: 1912
import sys
#input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def main():
    N,M = ints_raw()
    As = [int_raw() for _ in range(M)]
    is_breake = [0]*(N+1)
    for a in As:
        is_breake[a]=1
    memo = [0]*(N+1)
    memo[0]=1
    if N ==0:
        return memo[0]
    memo[1]=1 if is_breake[1]==0 else 0
    if N ==1:
        return memo[1]
    for n in range(2,N+1):
        if is_breake[n]==1:
            memo[n] =0

        else:
            memo[n]=(memo[n-2]+memo[n-1])%DIV
    return memo[N]

print(main())


Measured memory_bytes: 51288
#include<stdio.h>

int BubSort(int x[ ], int n)
{
    int i, j, temp;

    for (i = 0; i < n - 1; i++) {
        for (j = n - 1; j > i; j--) {
            if (x[j - 1] > x[j]) { 
                temp = x[j];  
                x[j] = x[j - 1];
                x[j - 1]= temp;
            }
        }	
    }
}

int main()
{
  int a[10],i,r;
  for (i=0;i<10;i++){
    scanf("%d",&a[i]);
}

  BubSort(a,10);


  for (r=0;r<3;r++){
    printf("%d\n",a[9-r]);
  }

  return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	ll n; cin >> n;
	ll hoge = 0;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) hoge = max(hoge, i);
	}
	cout << hoge + n / hoge - 2 << endl;
}


Measured memory_bytes: 256
n = int(input())
c = 0
p = 0
for i in range(n):
    d1,d2 = map(int,input().split())
    if d1 == d2:
        c += 1
    else:
        c = 0
    if c == 3:
        p = 1
        break
if p == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62328
//mangesh2102000

#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000007

const int N = 200005;
const int INF = 1e12;

int dp[N];
int h[N];
int a[N];
int n;
int tree[4*N+5];

void build(int node,int start,int end)
{
	if(start==end)
	{
		tree[node] =  dp[start];
		return;
	}

	int mid = (start+end)/2;

	build(2*node,start,mid);
	build(2*node+1,mid+1,end);

	tree[node] = max(tree[2*node],tree[2*node+1]);
}

void update(int node,int start,int end,int pos,int val)
{
	if(start==end)
	{
		tree[node]=val;
		return;
	}

	int mid = (start+end)/2;

	if(start<=pos and pos<=mid)
	{
		update(2*node,start,mid,pos,val);
	}
	else
	{
		update(2*node+1,mid+1,end,pos,val);
	}

	tree[node] = max(tree[2*node],tree[2*node+1]);
}

int query(int node,int l,int r,int start,int end)
{
	if(r < start or l > end)
		return 0;

	if(l<=start and r>=end)
	{
		return tree[node];
	}

	int mid = (start+end)/2;

	int val1 = query(2*node,l,r,start,mid);
	int val2 = query(2*node+1,l,r,mid+1,end);

	return max(val1,val2);
}


void solve(int t)
{
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> h[i];
	}	
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
	}

	//memset(dp,-1,sizeof(dp));

	build(1,1,n);
	int ans = -1;
	for(int i=1;i<=n;i++)
	{
		dp[h[i]] = max(dp[h[i]],a[i]+query(1,1,h[i]-1,1,n));
		update(1,1,n,h[i],dp[h[i]]);
		ans = max(ans,dp[h[i]]);
	}

	cout << ans;
    //cout << "Case #" << t << ": ";    
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }

    return 0;
}

Measured memory_bytes: 11264