akhauriyash/Code-Regression huggingface dataset:
'use strict'

class Main {

  compare(a,b) {
    if (a == null) return -1; // a < b
    if (b == null) return 1; // b < a
    if (_.sum(a) > _.sum(b)) return 1; // b < a
    if (_.sum(b) > _.sum(a)) return -1; // a < b
    for (let i = a.length - 1;i >= 0; --i) {
      if (a[i] > b[i]) {
        return 1; // b < a
      }
      else if (b[i] > a[i]) {
        return -1; // a < b
      }
    }
    return 0;
  }

  dp(n) {
    // console.log(`call: ${n}`);
    if (n < 0) return null;
    if (this.memo[n] === undefined) {
      let ret = null;
      for (let e of this.useNums) {
        // console.log(`try ${e}`);
        let cur = null;
        if (this.count[e] == n) {
          cur = (new Array(9)).fill(0);
          cur[e] = 1;
        }
        else {
          const prev = this.dp(n - this.count[e]);
          if (prev === null) continue;
          cur = Array.from(prev);
          cur[e] = cur[e] + 1;
          // console.log(cur[e]);
        }
        if (this.compare(ret, cur) < 0) {
          ret = cur;
        }
      }
      this.memo[n] = ret;
      // console.log(`n: ${n}`);
      // console.log(ret);
      /*
      if (ret != null) {
        console.log(ret.map((e,i) => (new Array(e?e:0)).fill("123456789".charAt(i)).join('')).reverse().join(''));
      }*/
    }
    return this.memo[n];
  }

  solve() {
    const nums = input.nextIntArr();
    this.useNums = input.nextIntArr().map(e => e - 1).sort().reverse();
    // console.log(this.useNums);
    this.count = [2,5,5,4,5,6,3,7,6];
    this.memo = [];
    const numbers = Array.from("123456789");
    const result = this.dp(nums[0]);
    // console.log(result);
    console.log(result.map((e,i) => (new Array(e?e:0)).fill(numbers[i]).join('')).reverse().join(''));
  }
}

class Underscore {
  sum(arr) { return arr.reduce((a,b)=>a+b,0); }
}

class Input {
  constructor() {
    this.cursor = 0;
    this.inputAll();
  }

  inputAll() {
    this.data = (require("fs").readFileSync("/dev/stdin", "utf8")).split('\n');
    return this.data;
  }

  nextLine(n) {
    if (n) {
      const ret = this.data.slice(this.cursor, this.cursor + n);
      this.cursor += n;
      return ret;
    }
    return this.data[this.cursor++];
  }

  nextStrArr() {
    return this.nextLine().split(' ');
  }

  nextIntArr() {
    return this.nextStrArr().map((e) => parseInt(e));
  }

  nextStrRange(n) {
    return this.nextLine(n).map((line) => line.split(' '));
  }

  nextIntRange(n) {
    return this.nextLine(n).map((line) => line.split(' ').map((e) => parseInt(e)));
  }
}

const _ = new Underscore();
const input = new Input();
(new Main()).solve();


Measured memory_bytes: 16324
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
    int n;
    int m;

    cin >> n >> m;
    vector<int> a(m,0);

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

    int d =  accumulate(a.begin(), a.end(), 0);
    if(n >= d){
        std::cout << n -d << std::endl;
    }
    else {
        std::cout << -1 << std::endl;
    }
}

Measured memory_bytes: 3628
n, k = map(int, input().split())
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A).most_common()
dif = len(C) - k
if dif <= 0:
	print(0)
else:
	s = 0
	for i in range(dif):
		s += C[-(i + 1)][1]
	print(s)

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

int main()
{
	std::vector<int> a(4);

	std::vector<int> b(4);

	int hit,blow;

	for(;;)
	{
		for(int i=0;i<4;++i)
		{
			std::cin >> a[i];
		}

		for(int i=0;i<4;++i)
		{
			std::cin >> b[i];
		}

		if(std::cin.eof())
		{
			break;
		}

		hit=0;
		blow=0;

		for(int i=0;i<4;++i)
		{
			if(a[i]==b[i])
				++hit;
		}

		for(int i=0;i<4;++i)
		{
			for(int j=0;j<4;++j)
			{
				if(i!=j && b[i]==a[j])
				{
					++blow;
				}
			}
		}

		std::cout << hit << ' ' << blow << '\n';
	}
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll X, K, D; cin >> X >> K >> D;
  ll cnt = abs(X)/D;
  ll cur = abs(X)%D;
  ll ans = 0;
  if(K == cnt){
    ans = cur;
  }else if(K > cnt){
    if((K-cnt)%2 == 0){
      ans = cur;
    }else{
      ans = D - cur;
    }
  }else if(K < cnt){
    ans = abs(X)-(D * K);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  string s, t;
  cin >> s >> t;
  
  int ok = 1;
  for (int i = 0; i < s.size(); i++){
    if (s[i] != t[i])
      ok =0;
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    
  

  return 0;
}


Measured memory_bytes: 3624
def main():
    N, M = list(map(int, input().split()))
    c = []
    for _ in range(M):
        ci = list(map(int, input().split()))
        c.append(ci)
    
    num = -1

    start = 10 ** (N - 1) if N != 1 else 0
    for i in range(start, 10 ** N):
        s = str(i)

        cnt = 0
        for ci in c:
            if int(s[ci[0] - 1]) == ci[1]:
                cnt += 1
        
        if cnt == M:
            num = i
            break
    print(num)
            
        

if __name__ == "__main__":
    main()


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

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

using namespace std;

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

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

const int MAX_N = 302;

using PP = pair<ll,P>;

ll a[MAX_N][MAX_N],b[MAX_N][MAX_N];

int main(){
  int N;
  cin >> N;
  rep(i,N) rep(j,N) scanf("%lld",&a[i][j]);
  bool conf = true;
  rep(i,N) conf &= (a[i][i]==0LL);
  rep(i,N-1) REP(j,i+1,N) conf &= (a[i][j]==a[j][i]);
  if(!conf){
    cout << "-1" << endl;
    return 0;
  }
  rep(i,N) rep(j,N) b[i][j] = a[i][j];
  rep(i,N) rep(j,N) rep(k,N) b[i][j] = b[j][i] = min(b[i][j],b[i][k]+b[j][k]);
  ll ans = 0LL;
  rep(i,N-1) REP(j,i+1,N){
    if(b[i][j]!=a[i][j]){
      cout << "-1" << endl;
      return 0;
    }else{
      bool pls = true;
      rep(k,N){
        if(k==j||k==i) continue;
        // 迂回路が存在するか?
        pls &= (b[i][k]+b[k][j]!=b[i][j]);
      }
      if(pls) ans += b[i][j];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
li = [stdin.readline().rstrip() for _ in range(n)]
li.sort()
lin = []
for key, value in groupby(li):
    lin.append((key,len(list(value))))
lin.sort(key=lambda x:(x[1]*(-1),x[0]))
point = lin[0][1]
for i,j in lin:
    if j == point:
        print(i)
    else:
        break

Measured memory_bytes: 47116
import sys

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    A = [input().strip() for _ in range(N)]
    B = [input().strip() for _ in range(N)]

    for i in range(N - M + 1):
        for i2 in range(N - M + 1):
            f = True
            for j in range(M):
                for k in range(M):
                    if A[j + i2][k + i] != B[j][k]:
                        f = False
                        break
                if not f:
                    break
            if f:
                print("Yes")
                return
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
h,n = map(int, input().split())
magics = [tuple(map(int, input().split())) for _ in range(n)]
max_a = sorted(magics, key=lambda x: x[0], reverse=True)[0][0]
dp = [0]*(h+max_a)
for i in range(1, h+max_a):
  dp[i] = min(dp[i-a]+b for a,b in magics)
print(min(dp[h:]))

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int h,w;
int si,sj,sd;
char s[22][22];
int sum=0;

int di[]={0,-1,0,1};
int dj[]={1,0,-1,0};

string ds[]={"R","U","L","D"};

bool valid(int i,int j){ return i>=0&&i<h&&j>=0&&j<w; }

string dfs(int i,int j,int dir,int cnt){
  if(cnt==sum)return "";
  repl(d,-1,2){
    int nd=(dir+d+4)%4;
    int ni=i,nj=j;
    while(valid(ni,nj)&&s[ni][nj]!='o'){
      ni+=di[nd]; nj+=dj[nd];
    }
    if(valid(ni,nj)){
      s[ni][nj]='.';
      string nxt=dfs(ni,nj,nd,cnt+1);
      s[ni][nj]='o';
      if(nxt!="X")return ds[nd]+nxt;
    }
  }
  return "X";
}

int main(){
	cin.sync_with_stdio(false);
  cin>>h>>w;
  rep(i,h)cin>>s[i];
  rep(i,h)rep(j,w){
    if(s[i][j]=='R'){
      si=i; sj=j;
      sd=0;
    }
    if(s[i][j]=='U'){
      si=i; sj=j;
      sd=1;
    }
    if(s[i][j]=='L'){
      si=i; sj=j;
      sd=2;
    }
    if(s[i][j]=='D'){
      si=i; sj=j;
      sd=3;
    }
    if(s[i][j]=='o')sum++;
  }
  //dbg(si); dbg(sj); dbg(sd);
  s[si][sj]='.';
  cout<<dfs(si,sj,sd,0)<<endl;
	return 0;
}

Measured memory_bytes: 3204
s = gets.to_i

def func(n)
  n%2==0 ? n/2 : 3*n+1
end

r = 0
i = 1
a = [s]
loop do
  s = func(s)
  if a.include?(s)
    r = i+1
    break
  end
  a << s
  i += 1
end
p r

Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main()
{
    int n , l  ;
    cin >> n;
    cin >> l;
    string str[n] ,temp;
    for(int i=0 ; i<n ; i++)
        cin >> str[i];


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


    for(int i = 0; i < n; ++i){
       cout << str[i] ;
    }
    return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
std::string S1, S2;
std::vector<int> types;

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

    std::cin >> N;
    std::cin >> S1 >> S2;

    for(int i=0;i<N;++i){
        int t;
        if(i + 1 < N && S1[i] == S1[i+1]){
            t = 0;
            ++i;
        }else{
            t = 1;
        }

        types.emplace_back(t);
    }

    // for(int t : types){
    //     std::cout << t;
    // }
    // std::cout << std::endl;

    int T = types.size(), pre = -1;
    ll res = 1ll;
    const ll MOD = 1e9 + 7;
    for(int i=0;i<T;++i){
        if(i == 0){
            res = types[i] == 0 ? 3 * 2 : 3;
        }else if(pre == 0 && types[i] == 0){
            res = res * 3 % MOD;
        }else if(pre == 1 && types[i] == 1){
            res = res * 2 % MOD;
        }else if(pre == 1 && types[i] == 0){
            res = res * 2 % MOD;
        }

        // std::cout << res << std::endl;
        
        pre = types[i];
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <functional>
#include <queue>
#include <utility>
#include <vector>
#include <iostream>
using namespace std;
typedef pair<int,int> P;

int a[51][51];
int d[51][51];
int h,w;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
#define inf 10000000

void bfs(){
    queue<pair<int, int>> q;
    d[0][0]=1;
    q.push({0,0});
    while(!q.empty()){
        pair<int, int> p = q.front();
        int tx = p.first;
        int ty = p.second;
        q.pop();
        for(int i=0;i<4;i++){
            int x=tx+dx[i];
            int y=ty+dy[i];
            if(x<0 || x>=h)continue;
            if(y<0 || y>=w)continue;
            if(!a[x][y] && d[x][y]>d[tx][ty]+1){
                d[x][y]=d[tx][ty]+1;
                q.push({x,y});
            }
        }
    }
}

int main(void){
    cin>>h>>w;
    char c;
    int bc=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>c;
            if(c=='.')a[i][j]=0;
            else{a[i][j]=1; bc++;}
            d[i][j]=inf;
        }
    }
    bfs();
    cout<<(d[h-1][w-1]==inf ? -1 : h*w-bc-d[h-1][w-1])<<endl;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val S = sc.next()
  val (a, b) = S.toSeq.sorted.unwrap.splitAt(2)
  println(if (a.head == a.last && b.head == b.last && a.head != b.head) "Yes" else "No")
}


Measured memory_bytes: 55416
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 200100;
const long long MX = 1e9;
long long n, x, y, xs, ys, xt, yt, sx, sy;

map<long long, long long> aib;

long long lsb(long long k) {return k & (-k); }


long long que(long long pos) {
	pos++;
	long long ret = 0;
	for(; pos; pos -= lsb(pos))
		ret = max(aib[pos], ret);
	return ret;
}

void upd(long long pos, long long val) {
	pos++;
	for(; pos <= 2 * MX; pos += lsb(pos))
		aib[pos] = max(aib[pos], val);
}


int main() {
	ios_base::sync_with_stdio(false);

	cin >> xs >> ys;
	cin >> xt >> yt;
	if(xs > xt) sx = 1, xs = MX - xs, xt = MX - xt;
	if(ys > yt) sy = 1, ys = MX - ys, yt = MX - yt;

	cin >> n;

	vector <pair<long long, long long> > v; 

	for(long long i = 1; i <= n; i++) {
		cin >> x >> y;
		if(sx) x = MX - x;
		if(sy) y = MX - y;

		v.push_back({x, y});
	}

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

	for(auto i : v) {
		if(xs > i.st || i.st > xt) continue;
		if(ys > i.nd || i.nd > yt) continue;
		// dbg(i);
		long long nr = que(i.nd);
		upd(i.nd, nr + 1);
		// dbg(i.nd);
	}

	long long nr = que(yt);
	// dbg(nr);
	dbg(xs, ys);
	dbg(xt, yt);
	// dbg(v[0]);

	long double ans = 100. * ((xt - xs) + (yt - ys));
	long double PI = acos(-1);

	long long mind = min(xt - xs, yt - ys);
	long long neah = max(0LL, nr - mind);
	dbg(neah);
	dbg(nr);
	assert(neah <= 1);
	nr -= neah;

	ans -= 20. * neah;
	ans += 10. * PI * neah;
	ans -= 20. * nr;
	ans += 10. * nr * PI / 2;
	cout << fixed << setprecision(12) << ans << '\n';
}	

	

Measured memory_bytes: 105580
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
 string s;
 string t;
 cin>>s;
 for(int i=0;i<s.size();i+=2){
     t+=s[i];
 } 
 cout<<t<<endl;
}

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

int main () {
  int a, b;
  string s;
  cin >> a >> b >> s;
  
  for (int i = 0; i < a; i++) {
    if (!isdigit(s[i])) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  if(s[a] != '-') {
    cout << "No" << endl;
    return 0;
  }
  
  for (int i = a + 1; i < a + 1 + b; i++) {
    if (!isdigit(s[i])) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)
int a[100010];
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a / gcd(a, b) * b;
}
int main(){
    int n, m;
    cin >> n >> m;
    rep(i,0,n){
        int tmp;
        cin >> tmp;  
        a[i] = tmp >> 1;
    } 
    int base = 1;
    rep(i,0,n){
        base = lcm(base, a[i]);
    }
    rep(i,0,n){
        if((base / a[i]) % 2 == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (m/base+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 768
import itertools
import math

n = int(input())
a = [list(map(int, input().split())) for i in range(n)]

next_p = itertools.permutations(a)
total = 0
for p in next_p:
  for i in range(n - 1):
    temp = (p[i][0] - p[i + 1][0]) ** 2 + (p[i][1] - p[i + 1][1]) ** 2
    total += math.sqrt(temp)


ans = total / math.factorial(n)
print(ans)

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

using namespace std;

int main()
{
    int T;
    while(cin >> T, T)
    {
        int N, cnt = 0;
        cin >> N;
        for(int i = 0; i < N; i++)
        {
            int s, f;
            cin >> s >> f;
            cnt += f - s;
        }
        if(cnt >= T) puts("OK");
        else printf("%d\n", T - cnt);
    }
}

Measured memory_bytes: 1148
#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)
#define MOD 1000000007
using namespace std;
 
 
 
int main(){
    string S;
    cin >> S;
    if(S =="Sunny") cout << "Cloudy" << endl;
    else if(S == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    
    return 0;
}

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const int N = 1000005;
ll ft[N];

ll mod_pow(ll x, ll y, ll p) {
    ll res = 1;
    while (y > 0) {
        if (y & 1) res = res * x % p;
        x = x * x % p;
        y >>= 1;
    }
    return res;
}

inline ll comb(int n, int k) {
	if (k > n || k < 0) return 0;
	ll ans = mod_pow(ft[n - k] * ft[k] % MOD, MOD - 2, MOD);
	ans = ans * ft[n] % MOD;
	return ans;
}

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;

	ll ans = 0;

	vector<ll> dp1(n + 1, 0), dp2(n + 1, 0);
	ft[0] = 1;
	REPU(k, 1, N) {
		ft[k] = k * ft[k - 1] % MOD;
	}

	REPU(k, 1, n) {
		dp1[k] = (comb(k - 1, n - k - 1) * ft[k] % MOD) * ft[n - 1 - k] % MOD;
	}
	ll acc = 0;
	REPU(k, 1, n) {
		dp2[k] = (dp1[k] - acc) % MOD;
		ans = (ans + k * dp2[k]) % MOD;
		acc = (acc + dp2[k]) % MOD;
	}
	if (ans < 0) ans += MOD;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 23680
#include<iostream>
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
using namespace std;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll a1= a/d;
	if(a%d!=0)
	a1++;
	ll a2= c/b;
	if(c%b!=0)
	a2++;
	if(a1>=a2)
	cout<<"Yes";
	else
	cout<<"No";
}



Measured memory_bytes: 3652
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
#define int long long
#define hh putchar('\n')
#define kg putchar(' ')
#define lowbit(x) ((x)&(-x))
using namespace std;
const int maxn=300005,mod=998244353;
int n,m,vis[maxn],q[maxn],tot,pos,ren[maxn];
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<<1)+(x<<3)+(ch^48);
		ch=getchar();
    }
    return x*f;
}
inline void write(int a)
{
    if(a<0)
    {
		putchar('-');
		putchar('1');
    }
    else
    {
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
    }
}
int calc(int xx,int yy)
{
	return n*(xx-1)+yy-1;
}
signed main()
{	
	n=read(),m=read();
	cout<<n*m<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main() {
    int X,b,p,ans;
    cin >> X;
    for(b = 1;b < 1000;b++) {
        for (p = 2;p < 1000;p++) {
            if (pow(b,p) <=X && pow(b,p) >= ans) {
                ans = pow(b,p);
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 640
#include <stdio.h>

int rot[24][7] = {
	{ 0,1,2,3,4,5,6 },{ 0,1,3,5,2,4,6 },{ 0,1,4,2,5,3,6 },{ 0,1,5,4,3,2,6 },
	{ 0,2,6,3,4,1,5 },{ 0,2,3,1,6,4,5 },{ 0,2,1,4,3,6,5 },{ 0,2,4,6,1,3,5 },
	{ 0,3,1,2,5,6,4 },{ 0,3,2,6,1,5,4 },{ 0,3,5,1,6,2,4 },{ 0,3,6,5,2,1,4 },
	{ 0,4,1,5,2,6,3 },{ 0,4,2,1,6,5,3 },{ 0,4,5,6,1,2,3 },{ 0,4,6,2,5,1,3 },
	{ 0,5,1,3,4,6,2 },{ 0,5,3,6,1,4,2 },{ 0,5,4,1,6,3,2 },{ 0,5,6,4,3,1,2 },
	{ 0,6,2,4,3,5,1 },{ 0,6,3,2,5,4,1 },{ 0,6,5,3,4,2,1 },{ 0,6,4,5,2,3,1 } };
int assign[7];

int main()
{
	int i, j;
	int a[7], b[7], dice[7];

	for (i = 1; i <= 6; i++) scanf("%d", assign+i);
	for (i = 1; i <= 6; i++) scanf("%d", a+i);
	for (j = 0; j < 24; j++) {
		for (i = 1; i <= 6; i++) dice[i] = rot[j][i];
		for (i = 1; i <= 6; i++) b[i] = assign[dice[i]];
		for (i = 1; ; i++) {
			if (i > 6) { puts("Yes"); return 0; }
			if (a[i] != b[i]) break;
		}
	}
	puts("No");
	return 0;
}



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

int main(){
int n;cin >> n;
int ans=0;
for(int i=0;i<20;i++){
  ans = i;
  if(n<=i*1000) break;
}

int a = 1000*ans -  n;

cout << a <<endl;
}


Measured memory_bytes: 3632
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

// Written after the author read the editorial
fn solve() {
    let n: usize = get();
    let mut k: i64 = get();
    // A -> false, B -> true
    let mut s: Vec<bool> = get_word().chars().map(|x| x == 'B').collect();
    assert_eq!(s.len(), n);
    let mut pos = 0;
    for i in 0 .. n {
        s[i] = s[i] ^ ((n + i) % 2 != 1);
    }
    for _ in 0 .. n {
        s.push(false);
    }
    while k > 0 {
        if pos >= n {
            break;
        }
        if s[pos] ^ (n % 2 != 1) { // B
            pos += 1;
        } else { // A
            s[pos] = !s[pos];
        }
        k -= 1;
    }
    if k > 0 && n % 2 == 1 && k % 2 == 1 {
        assert_eq!(pos, n);
        s[n] = !s[n];
    }
    // recons
    let mut out = String::new();
    for i in 0 .. n {
        out.push(if s[pos + i] ^ ((n + i) % 2 != 1) { 'B' } else { 'A' });
    }
    println!("{}", out);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8700
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD = 1e9 + 7;
const int N = 3e5 + 10;
int32_t main()
{
    IOS;
    int l, r, d;
    cin >> l >> r >> d;
    int cnt = 0;
    for(int i = l; i <= r; i++)
    {
        if(i % d == 0)
            cnt++;
    }
    cout << cnt << endl;


}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {
  int n;
  int w[110];
  int sum[110];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
    if (i == 0) {
      sum[i] = w[i];
    } else {
      sum[i] = sum[i-1] + w[i];
    }
  }

  int ans = 9999999;
  for (int i = 0; i < n; i++) {
    int s1 = sum[i];
    int s2 = sum[n-1] - sum[i];
    int diff;
    if (s1 - s2 > 0) {
      diff = s1 - s2;
    } else {
      diff = s2 - s1;
    }
    ans = min(ans, diff);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<functional>
#define P pair<int,int>
#define p pair<P,P>
using namespace std;

vector<P>rinsetu[100]{};//cost to
set<P>S;
int main() {
	int a, b;
	cin >> a >> b;
	for (int c = 0; c < b; c++) {
		int d, e, f; scanf("%d%d%d", &d, &e, &f);
		d--; e--;
		rinsetu[d].push_back(P(f,e));
		rinsetu[e].push_back(P(f,d));
	}
	for (int g = 0; g < a; g++) {
		priority_queue<p, vector<p>, greater<p>>Q;
		int mincost[100];
		fill(mincost, mincost + 100, 1 << 29);
		mincost[g] = 0; Q.push(p(P(0,g),P(-1,-1)));
		while (Q.size()) {
			p l = Q.top();
			P h = l.first; Q.pop();
			if (mincost[h.second] < h.first)continue;
			S.insert(P(l.second.first,l.second.second));
			for (P i : rinsetu[h.second]) {
				if (mincost[i.second] > h.first + i.first) {
					mincost[i.second] = h.first + i.first;
					Q.push(p(P(mincost[i.second],i.second),P(min(h.second,i.second),max(h.second, i.second))));
				}
			}
		}
	}
	cout << b - ((int)S.size() - 1) << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re
import bisect

BIGNUM = 10 ** 9 + 7

def main():
    #A, B, C = map(int, input().split())
    #N = int(input())
    #Hs = list(map(int, input().split()))

    S = input().strip()
    result = [0] * len(S)

    L_list, R_list = {}, {}
    prev_L, prev_R = [], []
    for i in range(len(S)):
        if S[i] == 'L':
            for j in prev_L:
                L_list[j] = i
            prev_L = []
        else:
            prev_L.append(i)
    for i in range(len(S)):
        i = len(S) - 1 - i
        if S[i] == 'R':
            for j in prev_R:
                R_list[j] = i
            prev_R = []
        else:
            prev_R.append(i)

    for i in range(len(S)):
        if S[i] == 'R':
            j = L_list[i]
            dist = j - i
            if dist % 2 == 0:
                result[j] += 1
            else:
                result[j-1] += 1
        else:
            # S[i] == 'L'
            j = R_list[i]
            dist = i - j
            if dist % 2 == 0:
                result[j] += 1
            else:
                result[j+1] += 1

    print(' '.join(map(str, result)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 86376
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

void solve()
{
    int n;int m;cin>>n>>m;
    priority_queue<int>pq;
    for(int i=0;i<n;i++)
    {
        int k;cin>>k;
        pq.push(k);
    }
    while(m-- && !pq.empty())
    {
        int temp=pq.top();
        pq.pop();
        pq.push(temp/2);
    }
    int ans=0;
    while(!pq.empty())
    {
        ans+=pq.top();
        pq.pop();
    }
    cout<<ans<<endl;
}
int32_t main()
{
         rapido;
         int t;
         //cin>>t;
         t=1;
         while(t--)
         solve();
}

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

int main() {
  int a,b;cin>>a>>b;
  int ans=0;
  for(int i=1;i<=b-a;i++){
    ans+=i;
  }
  cout<<ans-b<<endl;
}

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

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

    int n;
    cin >> n;

    pair<int, int> lim_cost[n];
    rep(i, n){
        int a, b;
        cin >> a >> b;

        lim_cost[i] = make_pair(b, a);
    }
    sort(lim_cost, lim_cost+n);

    int lim;
    int time = 0;
    bool flg = true;

    rep(i, n){
        lim = lim_cost[i].first;
        time += lim_cost[i].second;
        if(time>lim){
            flg = false;
            break;
        }

    }
    if(flg) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 1792
{-# LANGUAGE BangPatterns #-}

import Data.Bits
import Data.List
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Data.Coerce

gen :: Int -> [Int] -> [Int]
gen 0 [] = [0]
gen n xs | length xs == n = do
             k <- xs
             t <- gen (n-1) (xs \\ [k])
             return $ 10*t + k
gen n xs = do
  k <- [3, 5, 7]
  t <- gen (n-1) (xs \\ [k])
  return $ 10*t + k

allNum = concatMap (`gen` [3,5,7]) [3,4..9]

main :: IO ()
main = do
  x <- read <$> getLine :: IO Int
  putStrLn $ show $ length $ filter (<= x) allNum

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

#define ris   return *this
#define tmplt template<class T
#define dbgo  debug& operator<<
tmplt > struct rge { T b, e; };
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
~debug(){cerr<<endl;}
tmplt > dbgo(T x){cerr<<boolalpha<<x;ris;}
tmplt, class C > dbgo(pair<T, C> x){ris<<"("<<x.first<<", "<<x.second<<")";}
tmplt > dbgo(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}ris<<"]";}
tmplt > dbgo(vector<T> x){ris<<range(x.begin(),x.end());}
#else
tmplt > dbgo(const T&){ris;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
   a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
   a = max(a, b); 
}

void rec(vector<pair<ll,ll>>& path, vector<pair<ll,ll>>& ans, int i, int n, ll w = 0, ll v = 0) {
   if(i == n) {
      ans.emplace_back(w, v);
   } else {
      rec(path, ans, i+1, n, w + path[i].first, v + path[i].second);
      rec(path, ans, i+1, n, w, v);
   }
}

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   
   int n;
   cin >> n;
   vector<ll> value(n+1), weight(n+1);
   for(int i = 1; i <= n; i++) {
      cin >> value[i] >> weight[i];
   }
   int q;
   cin >> q;
   vector<vector<pair<int,int>>> queries(n+1);
   vector<ll> ret(q);
   for(int i = 0; i < q; i++) {
      int u, lim;
      cin >> u >> lim;
      queries[u].emplace_back(lim, i);
   }
   for(int u = 1; u <= n; u++) {
      if(queries[u].empty()) {
         continue;
      }
      vector<pair<ll,ll>> path, left, right;
      int v = u;
      while(v > 0) {
         path.emplace_back(weight[v], value[v]);
         v /= 2;
      }
      int m = path.size();
      rec(path, left, 0, m/2);
      rec(path, right, m/2, m);
      sort(right.begin(), right.end());
      int sz = right.size();
      for(int i = 1; i < sz; i++) {
         max_self(right[i].second, right[i-1].second);
      }
      sz = left.size();
      for(const pair<int,int>& pp : queries[u]) {
         int L = pp.first, k = pp.second;
         for(int i = 0; i < sz; i++) {
            ll used = left[i].first;
            ll cur = left[i].second;
            const ll inf = 1e18;
            int j = upper_bound(right.begin(), right.end(), pair<ll,ll>{L-used, inf}) - right.begin();
            --j;
            if(j < 0) {
               continue;
            }
            max_self(ret[k], cur + right[j].second);
         }
      }
   }
   for(int i = 0; i < q; i++) {
      cout << ret[i] << '\n';
   }
}















// Author: blondie


Measured memory_bytes: 17452
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 5000
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

int mod;
int dp[2][maxn+5];

void add(int &x,int y) {x=x+y>=mod?x+y-mod:x+y;}

int main()
{
	int n; scanf("%d%d",&n,&mod);
	int m=(n-1)/2;

	dp[0][0]=1;
	rep(i,1,m) rep(j,0,n) 
	{
		int &x=dp[i&1][j]; x=0;
		for(int k=0;k*i<=j;k++)
		{
			add(x,1ll*dp[(i-1)&1][j-k*i]*(k+1)%mod);
		}
	}
	int ans=0;
	if(n&1)
	{
		rep(j,0,n-1) for(int k=0;k*(m+1)<=j;k++) add(ans,dp[m&1][j-k*(m+1)]);
	}
	else
	{
		rep(j,0,n-1) for(int k=0;k*(m+1)<=j;k++) add(ans,1ll*dp[m&1][j-k*(m+1)]*(k+1)%mod);
	}
	printf("%d\n",ans);
	return 0;
}

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


using namespace std;

int main() {
	long long K, A, B;
	cin >> K >> A >> B;

	long long ans = max(K + 1, (A + (K - (A - 1))/ 2 * (B - A)) + (K - (A - 1)) % 2);

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
function Main(s) {
  var s = s.split("\n");
  var n = parseInt(s[0], 10);
  var a = s[1].split(" ").map(e => parseInt(e, 10));
  var max = 0;
  for (var i of a) max = i > max ? i:max;
  var backet = new Array(max + 2).fill(0);
  var counter = [];
  for (var i = 0; i < n; i++) {
    backet[a[i]]++;
  }
  for (var i = 0; i <= max; i++) {
    if (i === 0) {
      counter.push(backet[i] + backet[i + 1]);
    } else {
      counter.push(backet[i - 1] + backet[i] + backet[i + 1]);
    }
  }
  max = 0;
  for (var i of counter) max = i > max ? i:max;
  console.log(max);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 28852
#include <bits/stdc++.h>
#define int long long
#define For(i,a,b) for(register int i=a;i<=b;i++)
using namespace std;
int read() {
	register int x=0,f=0;
	register char ch=getchar();
	while(!isdigit(ch)) {
		f|=(ch=='-');
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=x*10+ch-'0';
		ch=getchar();	
	}
	return f?-x:x;
}
void write(int x) {
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}
int n,m,ans,a[340][340];
signed main() {
	n=read(),m=read();
	For(i,1,n) For(j,1,m) a[i][j]=read();
	For(i,1,n) For(j,i+1,n) {
		int now=0;
		For(k,1,m) now+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);	
		double ww=now;
		if((int)sqrt(now)!=(int)sqrt(now-1)) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cstring>
#include <inttypes.h>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

const int cap = 22;
const int max_width = 1 << 21;
const int mod = 1e9 + 7;
int N, a;
int P[cap];
int dp[max_width];

int main() {
    scanf("%d", &N);
    int width = 1 << N;
    fill(P, P + N + 1, 0);
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            scanf(" %d", &a);
            if (a == 1) {
                P[i] |= 1 << j;
            }
        }
    }
    fill(dp, dp + width, 0);
    dp[0] = 1;

    for (int i = 1; i < width; ++i) {
        int b = __builtin_popcount(i);
        for (int j = P[b - 1] & i; j; j -= j & -j) {
            dp[i] = (dp[i] + dp[i ^ (j & -j)]) % mod;
        }
    }

    printf("%d\n", dp[width - 1]);
}











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

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

    int now = 0;
    int count = 1;
    for (int i = 0; i < n; i++) {
        int l;
        cin >> l;
        now += l;
        if (now <= x)
            count++;
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

set<ll> s;

void dfs(ll n){

    if(n>1e10)return;
    s.insert(n);
    int f=n%10-1;
    int e=n%10+1;
    chmax(f,0);
    chmin(e,9);
    for(int i=f;i<=e;i++){
        dfs(n*10+i);
    }
}


int main() {
    
    int n;
    cin>>n;
    rep(i,9){
        dfs(i+1);
    }
    // dump(s);
    irep(i,s){
        n--;
        if(n==0)fin(*i);
    }

}



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

int main()
{
	string s, t;
    cin >> s >> t;

    int ans = 10000;
    for (int i = 0; i < s.size() - t.size() + 1; i++)
    {
        int buf = 0;
        for (int j = 0; j < t.size(); j++)
        {
            if(s[i + j] != t[j])buf++;
        }
        ans = min(ans, buf);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
	"sort"
)

const mod = 1e9 + 7

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n int
	fmt.Scan(&n)
	var a, b []int
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		a = append(a, t)
		b = append(b, t)
	}
	sort.Ints(b)
	var t []int
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			t = append(t, a[i])
			t = append(t, b[i])
		}
	}
	var r string
	if len(t) == 0 {
		r = "YES"
	} else if len(t) == 4 && t[0] == t[3] {
		r = "YES"
	} else {
		r = "NO"
	}
	fmt.Println(r)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = (1e9)+7;
ll K[2001];

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n){
    if(n%2) res=res*x%mod;
    x=x*x%mod;
    n/=2;
  }
  return res;
}
 
ll nCr(ll n,ll r){
  ll N=1; 
  for(int i=0;i<r;i++,n--) N=(N*(n%mod))%mod;
  ll R=mod_pow(K[r],mod-2);
  return N*R%mod;
}


map<int,int> M;
vector<int> v;
ll mem[1000][10000],used[1000][10000];
int dfs(int idx,int a){
  if(a==0) return 1;
  if(idx==v.size())return 0; 
  if(used[idx][a]++)return mem[idx][a];
  int num=v[idx];
  ll res=0;
  for(int i=0;i<=num;i++){
    if(a-i>=0)res=(res+dfs(idx+1,a-i))%mod;
  }
  return mem[idx][a]=res;
}

int main(){
  K[0]=1;
  for(int i=1;i<=2000;i++)K[i]=(K[i-1]*i)%mod;
  
  int n;
  cin>>n;
  ll cnt=0;
  for(int i=2;i<=n;i++) 
    for(int j=2,t=i;j<=i;j++)while(t%j==0) M[j]++,t/=j,cnt++;

  map<int,int> :: iterator it=M.begin();
  for(;it!=M.end();it++)v.push_back(it->second);
  ll ans=0;
  for(int i=0;i<=cnt;i++){
    ans=(ans+dfs(0,i))%mod;
  }

  cout<<ans%mod<<endl;

  


  return 0;
}


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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> price(N);
  for(int i=0;i<N;i++){
    cin>>price.at(i);
  }
  sort(price.begin(), price.end());
  int total=0;
  for(int i=0;i<K;i++){
    total+=price.at(i);
  }
  cout<<total<<endl;
}


Measured memory_bytes: 3644
def ball(c1, c2, b)
  case b
  when c1
    return c2
  when c2
    return c1
  else
    return b
  end
end

b = "A"

while line = gets
  cup1, cup2 = line.chomp.split(",")
  b = ball(cup1, cup2, b)
end

puts b

Measured memory_bytes: 6092
/***
 ** " Experience is the name everyone gives to their mistakes. "
 ** 	-- Oscar Wilde
***/

/**
  *  Author: dhruv_gheewala
  *  Date:   14.03.2020
  *  Time:   02:18:47
**/

#define DEBUG
#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 42
    #define o(str) 108
    #define fundri 137
    #define d(...) 1729
#endif

typedef unsigned int ui;
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const bool testcases = 0;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define test int __T__=1;if(testcases)cin>>__T__;while(__T__--)
#define nl cout<<'\n'
#define pb push_back
#define pop pop_back
#define all(s) s.begin(),s.end()
#define ff first
#define ss second
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;~i;i--)
#define loop(i,l,r) for(int i=l;i<r;i++)
#define rloop(i,r,l) for(int i=r;i>l;i--)

ll seed;auto random_address=[]{char *p=new char;delete p;return (uint64_t)p;};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()*(random_address()|1));
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T,typename U>inline bool exist(T cont,U val){return cont.find(val)!=cont.end();}
template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}
template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a){in>>a.ff>>a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a){for(auto &x : a)in>>x;return in;}

int main()
{
    std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
    start_time = std::chrono::high_resolution_clock::now();

    #ifdef DHRUV_GHEEWALA
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","w",stderr);
    #endif
    
    fast;
    int n;
    test{
    
    cin>>n;
    vi a(n),b(n),c(n);
    rep(i,n)inp(a[i],b[i],c[i]);

    vector<vi> dp(n,vi(3,INT_MIN));
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];

    loop(i,1,n)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][2],dp[i-1][0])+b[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}),nl;
    fundri;
    
    }

    end_time = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
    o("\n\n======\n");
    o("Elapsed Time: "<<elapsed_time<<" ms\n");

    return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
cin >> N;
vector<int> a(N),b(N),c(N);
for (int i = 0; i < N; i++){
cin >>a.at(i) >>b.at(i);
}
for(int i = 0; i < N; i++){
if(a.at(i) == b.at(i)){
c.at(i) = 0;
}
else{
c.at(i) = 1;
}
}
int M = N - 2, k = 0;
for(int i = 0; i < M; i++){
if(c.at(i) == c.at(i + 1) && c.at(i+1) == c.at(i+2) && c.at(i) == 0 ){
k = 1;
break;
}
}
if( k == 1){
cout << "Yes" <<endl;
}
if( k == 0){
cout << "No" <<endl;
}

}

Measured memory_bytes: 3620