akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#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, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
ll inf = ll(1e18);
using ll1d = vector<ll>;
using ll2d = vector<ll1d>;
using ll3d = vector<ll2d>;

void solve(istream &ccin = cin, ostream &ccout = cout) {
  string s;
  ccin >> s;
  ll n = ll(s.size());
  ll l = -1, r = -1;
  rep(i, n - 1) {
    string ss = s.substr(i, 2);
    if (ss[0] == ss[1]) {
      l = i + 1;
      r = i + 2;
      break;
    }
  }

  rep(i, n - 2) {
    string ss = s.substr(i, 3);
    if (ss[0] == ss[2]) {
      l = i + 1;
      r = i + 3;
      break;
    }
  }

  ccout << l << " " << r << endl;

}

int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
const int n = 2 * 1e3 + 7;
const int m = 2 * 1e3 + 7;
int down[n][m], up[n][m], lef[n][m], righ[n][m];
char a[n][m];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '.') {
				if (j == 0)
					lef[i][j] = 1;
				else
					lef[i][j] = lef[i][j - 1] + 1;

			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = w - 1; j >= 0; j--) {
			if (a[i][j] == '.') {
				if (j == w - 1)
					righ[i][j] = 1;
				else
					righ[i][j] = righ[i][j + 1] + 1;

			}
		}
	}
	for (int j = 0; j < w; j++) {
		for (int i = 0; i < h; i++) {
			if (a[i][j] == '.') {
				if (i == 0)
					down[i][j] = 1;
				else
					down[i][j] = down[i - 1][j] + 1;
			}
		}
	}
	for (int j = w - 1; j >= 0; j--) {
		for (int i = h - 1; i >= 0; i--) {
			if (a[i][j] == '.') {
				if (i == h - 1)
					up[i][j] = 1;
				else
					up[i][j] = up[i + 1][j ] + 1;
			}
		}
	}
	int nax = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '.') {
				nax = max(nax, down[i][j] + up[i][j] + lef[i][j] + righ[i][j] - 3);
			}
		}
	}
	cout << nax << endl;
}

Measured memory_bytes: 67072
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())

	if e != nil {
		panic(e)
	}

	return i
}

var n, m int

func calc(x, y, z []int, f int) int64 {
	vec := make([]int, n)
	
	for i := 0; i < n; i++ {
		tmp := 0

		if f % 2 == 0 {
			tmp += x[i]
		} else {
			tmp -= x[i]
		}
		
		if (f >> 1) % 2 == 0 {
			tmp += y[i]
		} else {
			tmp -= y[i]
		}
	
		if (f >> 2) % 2 == 0 {
			tmp += z[i]
		} else {
			tmp -= z[i]
		}
		
		vec[i] = tmp
	}

	var ret int64
	sort.Sort(sort.Reverse(sort.IntSlice(vec)))
	for i := 0; i < m; i++ {
		ret += int64(vec[i])
	}

	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m = nextInt(), nextInt()
	x, y, z := make([]int, n), make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		x[i], y[i], z[i] = nextInt(), nextInt(), nextInt()
	}

	var ans int64
	for i := 0; i < 8; i++ {
		if ans < calc(x, y, z, i) {
			ans = calc(x, y, z, i)
		}
	}

	Println(ans)
}


Measured memory_bytes: 768
#include <iostream>
using namespace std;
char A,B;

int main(){
	ios::sync_with_stdio(false);
	cin >> A >> B;
	if(A == 'H'){
		if(B == 'H'){
			cout << "H\n";
		}else{
			cout << "D\n";
		}
	}else{
		if(B == 'D'){
			cout << "H\n";
		}else{
			cout << "D\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

    int n;
    cin >> n;
    if(n % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }

    int lim = 1;
    while(lim * 5 <= n) lim *= 5;
    int ans = 0;
    
    for(int i = 5; i <= lim; i *= 5) {
        ans += n / i / 2;
        // cout << ans << " ";
    }

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

Measured memory_bytes: 256
def calc_prime(n):
    primes = set(list(range(3, n, 2)))
    primes.add(2)
    for a in range(3, n, 2):
        for i in range(a, n):
            x = a * i
            if x >= n:
                break
            if x in primes:
                primes.remove(x)

    return primes


def collect_likes(ps):
    likes = set([p for p in ps if (p + 1) / 2 in ps])
    return likes


def line(xs, n):
    ps = list(xs)
    ps.sort()
    cs = [0] * n
    s = 0
    for i in range(n):
        if i in xs:
            cs[i] = s
            s += 1
        else:
            cs[i] = s

    return cs


def main():
    n = 10 ** 5 + 9
    primes = calc_prime(n)
    likes = collect_likes(primes)
    cums = line(likes, n)
    #print(sorted(list(primes))[:100])
    #print(sorted(list(likes))[:100])
    #print(cums[:10])

    q = int(input())
    for _ in range(q):
        l, r = [int(x) for x in input().split()]
        ans = cums[r + 1] - cums[l]
        print(ans)


main()


Measured memory_bytes: 7872
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int ySum = 0;
    int sum = 0;
    boolean check = false;
    for (int i = 0; i < x; i++) {
      for (int j = 1; j+i <= x; j++) {
        ySum += 2;
        if (j+i == x) {
          sum += ySum;
          if (sum == y) {
            check = true;
          } else {
            sum -= ySum;
            ySum = 0;
          }
        }
      }
      sum += 4;
    }
    if (sum == y) {
      check = true;
    }
    System.out.println(check ? "Yes" : "No");
  }
}


Measured memory_bytes: 27040
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n;
ll x[101], y[101], h[101];
int main() {
    cin>>n;
    REP(i, 0, n) cin>>x[i]>>y[i]>>h[i];

    REP(i, 0, 101){
        REP(j, 0, 101){
            bool flag=true;
            ll H=1;
            REP(k, 0, n){
                if(h[k]>0){
                    H=h[k]+llabs(y[k]-i)+llabs(x[k]-j);
                    break;
                }
            }
            REP(k, 0, n){
                if((H-llabs(y[k]-i)-llabs(x[k]-j))<=0 && h[k]==0) continue;

                ll hh=h[k]+llabs(y[k]-i)+llabs(x[k]-j);
                if(hh!=H){
                    flag=false;
                    break;
                }
            }

            if(flag){
                cout<<j<<" "<<i<<" "<<H<<endl;
                return 0;
            }
        }
    }
    return 0;
}

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

using namespace std;

struct mia
{
    int y, nr;
};

bool porownanie(mia a, mia b)
{
    if (a.y < b.y)
        return true;
    return false;
}

string Con(int x)
{
    string odp = "";
    while (x != 0)
    {
        odp = (char) (x % 10 + '0') + odp;
        x /= 10;
    }
    while (odp.size() < 6)
        odp = "0" + odp;
    return odp;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector< vector<mia> > M(n + 1);
    for (int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        M[a].push_back({b, i});
    }
    for (int i = 0; i < n + 1; ++i)
        sort(M[i].begin(), M[i].end(), porownanie);
    vector<string> odp(m);
    for (int i = 0; i < n + 1; ++i)
        for (int j = 0; j < M[i].size(); ++j)
            odp[M[i][j].nr] = Con(i) + Con(j + 1);
    for (int i = 0; i < m; ++i)
        cout << odp[i] << endl;
    return 0;
}


Measured memory_bytes: 12416
#include<iostream>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
bool prime[1300000] = {0};

int main(){
  prime[0] = prime[1] = 1;
  rep(i, 1300000){
    if(prime[i])continue;
    for(int j = i+i; j < 1300000; j+=i)prime[j]=1;
  }
  int n;
  while(cin>>n, n){
    if(!prime[n]){
      cout<<0<<endl;
      continue;
    }
    int mx, mn;
    for(mx = n; prime[mx]; mx++);
    for(mn = n; prime[mn]; mn--);
    cout<<mx-mn<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
// #include <bits/stdc++.h>
using namespace std;

#define size_t long long
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define debug(x) cerr << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug1(i, x) cerr << "(" << (i) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug2(i, j, x) cerr << "(" << (i) << ", " << (j) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
template <typename T> class vec2d : public vector<vector<T>> {
public:
    vec2d(int H, int W): vector<vector<T>> (H, vector<T>(W)) {
    }
};
template <typename T> istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template <typename T> ostream& operator << (ostream& os, vector<T>& vec){
  REP(i, vec.size()) {
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0);
        // cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

signed main(signed argc, char **argv) {
  int N, K;
  cin >> N >> K;
  char s[N + 1];
  cin >> s;
  VI a;
  VI b;
  a.reserve(N);
  b.reserve(N);
  int mode = 0;
  for (size_t i = 0; i < N; i++) {
    if (s[i] == '0' && mode == 0) {
      mode = 1;
      a.push_back(i);
    } else if (s[i] == '1' && mode == 1) {
      b.push_back(i - 1);
      mode = 0;
    }
  }
  // debug(a);
  // debug(b);
  // debug(a.size());
  int _a = -1;
  int _b = -1;
  int index = 0;
  int ans = 0;
  for (size_t i = K; i < a.size(); i++) {
    int _ans = a[i] - _b - 1;
    debug(_ans);
    if (_ans > ans) {
      ans = _ans;
    }
    _a = a[index];
    _b = b[index];
    index++;
  }
  int _ans = N - _b - 1;
  // debug(_ans);
  if (_ans > ans) {
    ans = _ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    ll n,m;
    cin >> n >> m;
    ll a[m], b[m];
    vector<ll> route[n];
    memset(route, 0, sizeof(route));
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
        route[a[i]].push_back(b[i]);
        route[b[i]].push_back(a[i]);
    }
    ll ans[n];
    bool visited[n];
    memset(visited, false, sizeof(visited));
    deque<ll> q;
    q.push_back(0);

    while(!q.empty()) {
        ll v = q.front();
        q.pop_front();
        for (int i : route[v]) {
            if(visited[i]) continue;
            ans[i] = v;
            q.push_back(i);
            visited[i] = true;
        }
    }
    print("Yes");
    FOR(i, 1, n) {
        print(ans[i]+1);
    }
    return 0;
}


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

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N), cnt(100010, 0);
    rep(i, 0, N) cin >> a[i];
    rep(i, 0, N){
        if(a[i] - 1 >= 0) cnt[a[i]-1]++;
        cnt[a[i]]++;
        cnt[a[i]+1]++;
    }
    cerr << max_element(cnt.begin(), cnt.end()) - cnt.begin() << endl;
    cout << *max_element(cnt.begin(), cnt.end()) << endl;
    return 0;
}

Measured memory_bytes: 1792
//intのオーバーフローに気をつけろ,AGCはだいたいlongにしておけ
//毎回余りを求めることでオーバーフローしなくなる
//nextLineよりnextだ
//charは''で囲うんだぞ
//読み込みは先に全部やっておけ
//for文を回す回数に気をつけろ
	//for文は10^3の三重はTLE,10^5の二重はTLE,10^9のforはTLE
//貪欲は使えるか？？試した？？

import java.util.Scanner;

public class Main {

	public static void main(String args[]) throws InterruptedException {
		    Scanner sc = new Scanner(System.in);

		    int n = sc.nextInt();
		    //2*nが連続する2整数の積で表されたとき行けるっぽい.
		    int i = 1;
		    int count = 0;
		    while(i * (i+1) <= 2*n) {
		    	if(i*(i+1)==2*n) {
		    		count++;
		    		break;
		    	}else {
		    		i++;
		    		continue;
		    	}
		    }

	    	int[][] array  = new int[i][i+1];
		    if(count == 0 ) {
		    	System.out.println("No");
		    }else {
		    	System.out.println("Yes");
		    	System.out.println(i+1);
		    	for(int j = 0; j < i; j++) {
		    		for(int k = 0; k < i+1; k++) {
		    			if( j >= k)//オリジナル
		    				array[j][k] = j + i*k - k*(k+1)/2 + 1;
		    			
		    		}
		    	}
		    	for(int j = 0; j < i; j++) {
		    		for(int k = 0; k < i+1; k++) {
		    			if( j < k)
		    				array[j][k] = array[k-1][j];
		    			
		    		}
		    	}

			    for(int k = 0; k < i+1; k++) {
			    	System.out.print(i);
			    	for(int j = 0; j < i; j++) {
			    		System.out.print(" "+ array[j][k]);
			    	}
			    	if(k < i) {
			    			System.out.print("\n");
			    		}
			    }
		    }
		    
		    
		    
		    sc.close(); }

	public static void saiki(int a, String b) {
		//再帰コーディングのお手本

		if(a == 0) {
			System.out.println(b);
		}else {
			for(char ch = 'a'; ch <= 'c'; ch++) {
				saiki(a-1,b + ch);
			}
		}
	}

	public static  int gcd(int a, int b) {
	    if (a < b) {
	        int tmp = a;
	        a = b;
	        b = tmp;
	    }

	    int r = -1;
	    while (r != 0) {
	        r = a % b;
	        a = b;
	        b = r;
	    }

	    return a;
	}
}


Measured memory_bytes: 53404
#include <cstdio>
#include <string.h>

using namespace std;

char S[55], T[55];
char real_S[55];
char real_S_min[55] = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
bool ans_i[55];

int main() {
  int i, j;
  scanf("%s", S);
  scanf("%s", T);
  bool flag = true;
  for (i = 0; i < strlen(S); i++) {
    for (j = 0; j < strlen(T); j++) {
      //printf("%d %d", i, j);
      if (i+j > strlen(S)) {
	flag = false;
	break;
      }
      if (S[i+j] != T[j] && S[i+j] != '?') {
	flag = false;
	break;
      }
      if (j+1 == strlen(T)) {
	flag = true;
	break;
      }
    }
    //printf("\n");
    if (flag == true) {
      ans_i[i] = true;
    }
  }
  flag = false;
  for (i = 0; i < strlen(S); i++) {
    if (ans_i[i] == true) {
      flag = true;
      for (j = 0; j < strlen(T); j++) {
	real_S[i+j] = T[j];
      }
      for (j = 0; j < i; j++) {
	if (S[j] == '?') {
	  real_S[j] = 'a';
	} else {
	  real_S[j] = S[j];
	}
      }
      for (j = i+strlen(T); j < strlen(S); j++) {
	if (S[j] == '?') {
	  real_S[j] = 'a';
	} else {
	  real_S[j] = S[j];
	}
      }
      if (strcmp(real_S, real_S_min) < 0) {
	for (j = 0; j < strlen(S); j++) {
	  real_S_min[j] = real_S[j];
	}
      }
    }
  }
  if (flag == false) {
    printf("UNRESTORABLE");
  } else {
    for (i = 0; i < strlen(S); i++) {
      printf("%c", real_S_min[i]);
    }
  }
  return 0;
}


Measured memory_bytes: 128
N, K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
MOD = 10**9+7
fac = [0]*(N+1) # 階乗テーブル
fac[0] = fac[1] = 1
inv = [0]*(N+1) # 逆元テーブル
inv[1] = 1
facinv = [0]*(N+1) # 階乗の逆元テーブル
facinv[0] = facinv[1] = 1
for i in range(2,N+1):
    fac[i] = fac[i-1]*i%MOD
    inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
    facinv[i] = facinv[i-1] * inv[i] % MOD
inverse_table = [1,1] # 逆元テーブル
inverse_factorial_table = [0,1] # 階乗の逆元テーブル

def nCr(n,r):
    if n < r or n < 0 or r < 0:return 0
    else:return fac[n] * (facinv[r] * facinv[n-r] % MOD) % MOD

# 各要素が最大値、最小値として何回使われるか考える
maxsum = 0
minsum = 0
for i,a in enumerate(A):
    maxsum += nCr(i,K-1)*a
    maxsum %= MOD
    minsum += nCr(N-i-1,K-1)*a
    minsum %= MOD
ans = (maxsum-minsum)%MOD

print(ans)

Measured memory_bytes: 18776
#include<stdio.h>
int main(void)
{
	int m[31],n[29],i,x[30],w=0,j;
	for(i=1;i<=28;i++) scanf("%d",&n[i]);
	for(i=1;i<=30;i++) x[i]=0;	
	for(i=1;i<=28-1;i++){
		for(j=i+1;j<=28;j++){
			if(n[i]>n[j]){
				w=n[i];
				n[i]=n[j];
				n[j]=w;
			}
		}
	}
	for(i=1;i<=28;i++) x[n[i]]=1;
	for(i=1;i<=30;i++){
		if(x[i]!=1){
			printf("%d\n",i);
		}
	}	
	return 0;
}

Measured memory_bytes: 2712
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()



def main():
    N,M =isRaw()
    return min(str(N)*M,str(M)*N)


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 38384
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const x = Number(stdin.split('\n')[0])

let res = 'NO'
switch (x) {
  case 3:
    res = 'YES'    
    break
  case 5:
    res = 'YES'
    break
  case 7:
    res = 'YES'
    break
}

console.log(res)

Measured memory_bytes: 7372
N = int(input())

H = [int(v) for v in input().strip().split(' ')]

dp = [int(10 ** 10)] * N

dp[0] = 0
dp[1] = abs(H[0] - H[1])

for i in range(2, N):
    dp[i] = min(dp[i], dp[i - 1] + abs(H[i] - H[i - 1]))
    dp[i] = min(dp[i], dp[i - 2] + abs(H[i] - H[i - 2]))

print(dp[-1])


Measured memory_bytes: 13924
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
LL read() {
    LL k = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9')
        k = k * 10 + c - 48, c = getchar();
    return k;
}
int a[200010]; LL sum;
int main() {
    int n = read(), m = read();
    for(int i = 1; i <= n; ++i) a[i] = read(), sum += a[i];
    sort(a+1, a+n+1);
    for(int i = 0; i < min(m, n); ++i) sum -= a[n-i];
    cout << sum;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int count = 0;
		
		for(int i = 0; i < N; i++) {
			int a = stdIn.nextInt();
			if(i != a-1) {
				count++;
			}
		}
		if(count == 0 || count == 2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}

	}

}

Measured memory_bytes: 21844
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define COUT(x) out << (x) << endl;
#define M0(x) memset(x,0,sizeof(x))
#define MINF(x) memset(x,0x3f,sizeof(x))
#define MMINUS(a) memset(a,0xff,sizeof(a))

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

using namespace std;

class CAntiDivision {
public:
    ll A, B, C, D;

    void solve(std::istream& in, std::ostream& out) {
        in >> A >> B >> C >> D;
        ll c = B / C - (A - 1) / C;
        ll d = B / D - (A - 1) / D;

        ll g = gcd(C, D);
        ll l = C / g * D;
        ll e = B / l - (A - 1) / l;
        COUT(B - A + 1 - c - d + e);
    }
};


int main() {
    CAntiDivision solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

n = int(input())
cnt = [[0] * 10 for _ in range(10)]

for i in range(1, n+1):
    s = str(i)
    front = int(s[0])
    end = int(s[-1])
    cnt[front][end] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += cnt[i][j] * cnt[j][i]
print(ans)

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

using namespace std;

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

	long long n, i, j, k, ans;
	cin >> n;
	vector<long long> a(3 * n);
	for (i = 0; i < 3 * n; i++) cin >> a[i];
	sort(a.rbegin(), a.rend());

	ans = 0;
	for (i = 0; i < n; i++) ans += a[i * 2 + 1];
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
int main(){
  char ans[16];
  int a,b;
    int len,x;
    while( scanf("%d %d",&a,&b) != EOF){
    sprintf(ans,"%d",a+b);
    len = strlen(ans);
    printf("%d\n",len);
    }
    return(0);
}

Measured memory_bytes: 612
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include <utility>

using namespace std;


int main() {

	int age, price;

	cin >> age >> price;

	if (age > 12) {
		cout << price << endl;
	}
	else if (age >= 6 && age <= 12) {
		cout << price / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}


	return 0;
}

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

vector<vector<int>> g;
vector<vector<int>> gw;
vector<int> gc;

int f(int x, int c, int o = -1){
	gc.at(x) = c;
	rep(i, g.at(x).size()){
		if(gc.at(g.at(x).at(i)) != -1) continue;
			f(g.at(x).at(i), c, x);
	}
	return 0;
}

int main(){
	int n, m;
	cin >> n >> m;
	g = vector<vector<int>>(n, vector<int>(0));
	gw = vector<vector<int>>(n, vector<int>(0));
	gc = vector<int>(n);
	rep(i, m){
		int a, b, w;
		cin >> a >> b >> w;
		a--; b--;
		g.at(a).push_back(b);
		g.at(b).push_back(a);
		gw.at(a).push_back(w%2);
		gw.at(b).push_back(w%2);
	}
	rep(i, n) gc.at(i) = -1;
	int k = 0;
	rep(i, n){
		if(gc.at(i) == -1){
			f(i, k);
			k++;
		}
	}
	cout << k << endl;
	return 0;
}

Measured memory_bytes: 17792
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N, K; std::cin >> N >> K;
  int max_try = std::ceil(log2(K));
  std::vector<double> probs(max_try+1, 1.0);

  double prob = 1.0;
  for (int i = 1; i <= max_try; ++i) {
    prob *= 0.5;
    probs[i] = prob;
  }

  double total_prob = 0.0;
  double coef = 1.0 / N;
  for (int n = 1; n <= N; ++n) {
    int a = n;
    int cnt = 0;
    while(a<K) {
      a *= 2;
      ++cnt;
    }

    total_prob += coef * probs[cnt];
  }

  printf("%.10f\n", total_prob);
}


Measured memory_bytes: 512
<?php
$n = trim(fgets(STDIN));
$k = trim(fgets(STDIN));
$a = explode(" ",trim(fgets(STDIN)));
$ans = 0;
while($n > 0){
--$n;
$ans += min(($k - $a[$n]) * 2,$a[$n] * 2);
}
echo $ans;

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int main(void){
	int n,i,j,a[1010][1010],t=-1,k[1010]={};
	bool d[1010],pos=true;
	cin >> n;
	for (i=1;i<=n;i++) 
  		for (j=0;j<n-1;j++) 
	  		cin >> a[i][j];
  	while (pos){
	    t++;
	    pos=false;
	    for (i=1;i<=n;i++) 
			d[i]=false;
	    for (i=1;i<=n;i++) 
			if (k[i]!=n-1){
	      		j=a[i][k[i]];
	     		if (!d[i] && !d[j] && a[j][k[j]]==i){
		        	pos=true;
			        k[i]++;
			        k[j]++;
			        d[i]=true;
			        d[j]=true;
	      		}
	    	}
  	}
  	for (i=1;i<=n;i++) 
	  	if (k[i]!=n-1) break;
  	if (i==n+1) cout << t << endl;
  	else cout << -1 << endl;
  	return 0;
}

Measured memory_bytes: 4224
N, M = [int(i) for i in input().split(" ")]

H = [int(i) for i in input().split(" ")]


good = [True] * N

for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        good[b-1] = False
    elif H[a-1] < H[b-1]:
        good[a-1] = False
    else:
        good[a-1] = good[b-1] = False
print(sum(good))

Measured memory_bytes: 20128
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<pair<int, int> > VPII;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	int M;
	cin >> M;
	O(24 - M + 24);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int A,B,M;
  cin>>A>>B>>M;
  vector<int> a(A),b(B),x(M),y(M),c(M);
  REP(i,A)cin>>a[i];
  REP(i,B)cin>>b[i];
  REP(i,M){
    cin>>x[i]>>y[i]>>c[i];
    x[i]--;y[i]--;
  }
  int ans=*min_element(ALL(a))+*min_element(ALL(b));
  REP(i,M)ans=min(ans,a[x[i]]+b[y[i]]-c[i]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>

int main(void){
  int i,j,s,n,m;
  static int a[100][100],b[100],c[100];

  scanf("%d%d",&n,&m);

  for(i=0;i<n;i++)
    for(j=0;j<m;j++)
      scanf("%d",&a[i][j]);

  for(i=0;i<m;i++)
    scanf("%d",&c[i]);

  for(i=0;i<n;i++){
    s = 0;
    for(j=0;j<m;j++)
      s += a[i][j] * c[j];
    printf("%d\n",s);
  }
  
  return 0;
}

Measured memory_bytes: 636
N, X = map(int, input().split())

cntP = [0]*(N+1)
cntP[0] = 1
for i in range(1, N+1):
    cntP[i] = cntP[i-1] * 2 + 1

layer = 1
for _ in range(N):
    layer = layer * 2 + 3

def calc(n, i, layer):
    if i == 0:
        return 0
    
    if n == 1:
        return "BPPPB"[:i].count("P")
    else:
        if i == layer // 2 + 1:
            return cntP[n-1] + 1
        elif i > layer // 2 + 1:
            return cntP[n-1] + 1 + calc(n-1, i - (layer // 2 + 1), (layer-3) // 2)
        elif i < layer // 2 + 1:
            return calc(n-1, i-1, (layer-3) // 2)

ans = calc(N, X, layer)
print(ans)


Measured memory_bytes: 3064
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        lr:[(i64, i64); k]
    }
    let mut dp = vec![ModInt::from_usize(0); n+1];
    let mut dpsum = vec![ModInt::from_usize(0); n + 1];

    dp[1] = ModInt::from_usize(1);
    dpsum[1] = ModInt::from_usize(1);
    for i in 2..=n {
        for j in 0..k {
            let (l, r) = lr[j];
            let li = (i as i64 - r).max(1);
            let ri = i as i64 - l;
            if ri < 0 {
                continue;
            }
            dp[i] += dpsum[ri as usize] - dpsum[(li-1) as usize];

        }
        dpsum[i] = dpsum[i-1] + dp[i];
    }

    let ans = dp[n].val();
    println!("{}", ans);
}
use std::ops::*;

const MOD: usize = 998244353;
#[derive(Copy, Clone)]
struct ModInt {
    n: usize,
}

impl ModInt {
    fn val(self)->usize {
        self.n
    }
    fn from_usize(n: usize) -> ModInt {
        ModInt { n: n % MOD }
    }
    fn pow(self, power: usize) -> ModInt {
        if power == 0 {
            return ModInt::from_usize(1);
        }
        if power % 2 == 0 {
            let t = self.pow(power/2);
            return t * t;
        }
        self * self.pow(power-1)
    }
    fn inv(self) -> ModInt {
        self.pow(MOD - 2)
    }
}

impl Add for ModInt {
    type Output = ModInt;

    fn add(self, rhs: ModInt) -> ModInt {
        let mut tmp = self;
        tmp.n += rhs.n;
        if tmp.n >= MOD {
            tmp.n -= MOD;
        }
        tmp
    }
}

impl AddAssign for ModInt {
    fn add_assign(&mut self, rhs: ModInt) {
        *self = *self + rhs;
    }
}

impl Sub for ModInt {
    type Output = ModInt;

    fn sub(self, rhs: ModInt) -> ModInt {
        let mut tmp = self;
        if tmp.n < rhs.n {
            tmp.n += MOD;
        }
        tmp.n -= rhs.n;
        tmp
    }
}

impl SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: ModInt) {
        *self = *self - rhs;
    }
}

impl Mul for ModInt {
    type Output = ModInt;

    fn mul(self, rhs: ModInt) -> ModInt {
        let mut tmp = self;
        tmp.n *= rhs.n;
        tmp.n %= MOD;
        tmp
    }
}

impl MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: ModInt) {
        *self = *self * rhs;
    }
}

impl Div for ModInt {
    type Output = ModInt;

    fn div(self, rhs: ModInt) -> ModInt {
        let mut tmp = self;
        tmp.n *= rhs.inv().n;
        tmp.n %= MOD;
        tmp
    }
}

impl DivAssign for ModInt {
    fn div_assign(&mut self, rhs: ModInt) {
        *self = *self / rhs;
    }
}

Measured memory_bytes: 5156
n,m = map(int, input().split())
d = {}
for i in range(m):
  a,b = map(int, input().split())
  if a in d:
    l = d[a]
    l.append(b)
    d[a] = l
  else:
    d[a] = [b]
  if b in d:
    l = d[b]
    l.append(a)
    d[b] = l
  else:
    d[b] = [a]
dpth = {}
dpth[1] = 0
l = [1]
ans = [0]*(n-1)
while(len(l)>0):
  l_ = []
  for i in l:
    dpth_ = dpth[i]
    for j in d[i]:
      if j not in dpth:
        ans[j-2] = i
        dpth[j] = dpth_+1
        l_.append(j)
  l = l_
print("Yes")
for i in ans:
  print(i)

Measured memory_bytes: 49848
/*
 * https://atcoder.jp/contests/abc144/tasks/abc144_b
 */
#include <bits/stdc++.h>
 
using namespace std;

// ショートハンド
// #define ll intに変えればメモリ節約
#define ll long long

/* 
 * ループ系のマクロ
 * `REP(i, 10) { cout << i; }`のように、変数名,回数で動く
 */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/*
 * 正規表現
 */
#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false)

// `chmax(a, b)` aがbより小さければ、aをbに上書きする。chminは逆
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1e9 + 7;
int main() {
    INIT();

    vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin >> n;
    
    cout << v[n - 1];
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>


void quick_sorts(int *x, int left, int right){
    if(left >=right)return;
    int i = left,j = right, pivot = x[i];
    while(x[i]>pivot)i++;
    while(x[j]<pivot)j--;
    while(i < j){
        int tmp = x[i];
        x[i] = x[j];
        x[j] = tmp;
        i++;
        j--;
        while(x[i]>pivot)i++;
        while(x[j]<pivot)j--;
    }
    quick_sorts(x,left,i-1);
    quick_sorts(x,j+1,right);
}

int main(){
    int N;
    scanf("%d%*c",&N);
    int *L = (int *)malloc(N * sizeof(int));
    char *s = (char *)malloc(11 * N * sizeof(char));
    char *ms = s;
    fgets(s,11 * N,stdin);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 11; j++){
            if(s[j] == ' '||s[j] == '\n'){
                s[j] = '\0';
                L[i] = atoi(s);
                s = &s[j+1];
                break;
            }
        }
    }

    quick_sorts(L,0,N-1);
    int count = 0;
    for(int i = 0;i < N; i++){
        for(int j = 0;j < i; j++){
            for(int k = 0; k < j; k++){
                if(L[i]!=L[j]&&L[j]!=L[k]&&L[k]!=L[i]&&L[k]<L[j]+L[i]){
                    count++;
                }
            }
        }
    }
    free(L);
    free(ms);
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 1764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll dp[1002][10002];

void solve() {
	int h, n;
	cin >> h >> n;
	vector<ll> a(n), b(n);
	rep(i,n) cin >> a[i] >> b[i];
	for (int i = n; i >= 0; i--) {
		for (int j = 0; j <= h; j++) {
			if (j == 0) dp[i][j] = 0;
			else if (i == n) {
				dp[i][j] = INF;
			} else {
				dp[i][j] = min(dp[i][max(0ll, j - a[i])] + b[i], dp[i + 1][j]);
			}
		}
	}
	cout << dp[0][h] << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 81768
import math
 
d,g = [int(i) for i in input().split()]
P = []
C = []
for i in range(d):
    p,c = [int(i) for i in input().split()]
    P.append(p)
    C.append(c)

def flag(point,P,now):
    if point+100*(now+1)*(P-1) >= g: return 1
    elif point+100*(now+1)*P + C[now] >= g: return 2
    else: return 0

m = 10**9
def score(point = 0, n = 0, now=-1, remain = list(range(d))):
    global m
    if m <= n: return
    elif now == -1:
        for i in remain:
            score(point, n, i, remain)
    elif point >= g: m = n
    elif flag(point,P[now],now) == 1:
        n += math.ceil((g-point)/(100*(now+1)))
        if m > n: m = n
    elif flag(point,P[now],now) == 2:
        n += P[now]
        if m > n: m = n
    else:
        if m <= n+P[now]: return
        else:
            remain = remain[:]
            remain.remove(now)
            nxtp = point + P[now]*100*(now+1) + C[now]
            for i in remain:
                score(nxtp, n + P[now], i, remain)

score()
print(m)


Measured memory_bytes: 62552
// Written by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

// Delete the debugging information!
#define debug(x) std::cerr << #x << " = " << x << std::endl;

const int BUFFER_SIZE = 1 << 24 | 1;
struct InputOutputStream {
  char ibuf[BUFFER_SIZE], *s, *oh;
  InputOutputStream() : s(ibuf) {
    ibuf[fread(ibuf, 1, BUFFER_SIZE, stdin)] = '\0';
  }
  template <typename T>
  inline InputOutputStream &operator>>(T &x) {
    while (!isdigit(*s)) ++s;
    for (x = 0; isdigit(*s); ++s)
      x = x * 10 + (*s ^ '0');
    return *this;
  }
}IO;

template <typename lhs, typename rhs>
inline lhs min(const lhs &x, const rhs &y) { return x < y ? x : y; }
template <typename lhs, typename rhs>
inline lhs max(const lhs &x, const rhs &y) { return x > y ? x : y; }

const int MAXN = 200003;
int n, p[MAXN], suf[MAXN];
bool flag[MAXN];

const int MAXT = 800003, inf = 0x3f3f3f3f;
#define mid ((l + r) >> 1)
#define lSon (k << 1)
#define rSon (k << 1 | 1)
struct SegmentTree {
  int mx[MAXT];
  inline void init() { memset(mx, -0x3f, sizeof mx); }
  inline void pushup(int k) { mx[k] = max(mx[lSon], mx[rSon]); }
  void modify(int k, int l, int r, int x, int v) {
    if (l == r) {
      mx[k] = v;
      return ;
    }
    x <= mid ? modify(lSon, l, mid, x, v) : modify(rSon, mid + 1, r, x, v);
    pushup(k);
  }
  int query(int k, int l, int r, int x, int y) {
    if (x <= l && r <= y)
      return mx[k];
    int o = -inf;
    if (x <= mid)
      o = max(o, query(lSon, l, mid, x, y));
    if (mid < y)
      o = max(o, query(rSon, mid + 1, r, x, y));
    return o;
  }
}tree[2];
#undef mid
#undef lSon
#undef rSon

int f[MAXN][2], arrA[MAXN], arrB[MAXN];
char ans[MAXN];

int cntA, cntB, mxA, mxB;
inline bool check(int i) {
  int temp = cntA + (p[i] > mxA) + suf[i + 1] - cntB;
  if (temp >= 0 && tree[temp & 1].query(1, 1, n, mxB, n) >= temp)
      return 1;
  temp = cntB + suf[i + 1] - cntA - (p[i] > mxA);
  if (temp >= 0 && tree[temp & 1].query(1, 1, n, max(mxA, p[i]), n) >= temp)
    return 1;
  return 0;
}

int main() {
  IO >> n;
  for (int i = 1, mx = 0; i <= n; ++i) {
    IO >> p[i];
    if (p[i] > mx)
      flag[i] = 1, mx = p[i];
  }
  tree[1].init();
  for (int i = n; i; --i) {
    suf[i] = suf[i + 1] + flag[i];
    for (int j = 0; j < 2; ++j)
      f[i][j] = tree[j ^ (!flag[i])].query(1, 1, n, p[i], n) + 1 + flag[i];
    for (int j = 0; j < 2; ++j)
      tree[j].modify(1, 1, n, p[i], f[i][j]);
  }
  
  for (int i = 1; i <= n; ++i) {
    tree[0].modify(1, 1, n, p[i], 0);
    tree[1].modify(1, 1, n, p[i], -inf);
    if (check(i)) {
      ans[i] = '0';
      if (p[i] > mxA)
        mxA = p[i], ++cntA;
    }
    else {
      ans[i] = '1';
      if (p[i] > mxB)
        mxB = p[i], ++cntB;
    }
  }
  if (cntA == cntB)
    printf("%s\n", ans + 1);
  else
    printf("-1\n");
  return 0;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

const ll size = 200010;
ll H, W, A, B;
ll fact[size];
ll ifact[size];

void init() {
    fact[0] = 1;
    FOR(i, 1, size-1)
        fact[i] = i*fact[i-1]%MOD;
    ifact[size-1] = modpow(fact[size-1], MOD-2);
    DOWN(i, size-2, 0)
        ifact[i] = ifact[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll k) {
    ll res = fact[n]*ifact[k]%MOD;
    return res*ifact[n-k]%MOD;
}

int main() {
    cin >> H >> W >> A >> B;
    init();
    ll ans = 0;
    ll a = H-A-1;
    ll c = A-1;
    REP(i, W-B) {
        ll b = B+i;
        ll d = W-B-1-i;
        ll t = comb(a+b,a)*comb(c+d,c)%MOD;
        ans = (ans + t)%MOD;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
import java.io.*;
import java.util.*;
public class Main {
static long[][] memo;
static int I,J;
static String h,s;
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
	   h=sc.nextLine();
	   s=sc.nextLine();
	   I=h.length();
	   J=s.length();
	   memo=new long[I][J];
	   for(long []a:memo)
		   Arrays.fill(a,-1);
	   dp(0,0);
	   long max=0; int im=0; int jm=0;
	 
	   trace(0,0);
	}
	static void trace(int i,int j) {
		if(i==I || j==J)
			return;
		if(h.charAt(i)==s.charAt(j)) {
			System.out.print(s.charAt(j));
			trace(i+1,j+1);
			return;
		}
		if(dp(i+1,j)>dp(i,j+1))
			trace(i+1,j);
		else
			trace(i,j+1);
	}
	static long dp(int i,int j) {
		if(i==I || j==J)
			return 0;
		if(memo[i][j]!=-1)
			return memo[i][j];
		long v=0;
		if(h.charAt(i)==s.charAt(j))
		v=1+dp(i+1,j+1);
		return memo[i][j]=Math.max(v, Math.max(dp(i,j+1),dp(i+1,j)));
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

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

using namespace std;

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

  int a, b, c;
  cin >> a >> b >> c;
  if (a == b) {
    cout << c << "\n";
  } else if (b == c) {
    cout << a << "\n";
  } else {
    cout << b << "\n";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = res * a;
      a = a * a;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);
  #endif
}

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

int main() 
{ 
    fast_io
    go();
    intu n;cin>>n;

    vector<intu> hash(n+1,1);
    //memset(hash, true, sizeof(hash)); 
    for (intu p = 2; p<=n; p++)
    { 
        for(intu j=0;j<=n;j+=p)
        {
          hash[j]++;
        }
    }
    intu ans=0;
    for1(i,n)
    {
      ans+=(i*hash[i]);
    }
    cout << ans <<"\n";
}



/*!
    You are under no obligation to be the same person you were a minute ago,
    You have the right to grow !
*/




















Measured memory_bytes: 81340
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int h, w, n;
	cin >> h >> w >> n;

	int maxi = max(h, w);
	int ans = (n + maxi - 1) / maxi;

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


Measured memory_bytes: 256
S = input()


def judge(S):
    if S[0] != "A":
        return "WA"
    else:
        if S[2:len(S) - 1].count("C") != 1:
            return "WA"
        else:
            for i in range(1, len(S)):
                if S[i] != "C"and S[i].isupper():
                    return "WA"
            return "AC"


print(judge(S))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b,c,sum;
    cin >> a >> b >> c;
    sum = (a*100) + (b*10) + c;
    if(sum % 4 > 0){
        cout << "NO" << endl;
    } 
    else cout << "YES" << endl;
}

Measured memory_bytes: 3544
N = int(input())
A = sorted(list(map(int, input().split())))
r = 10 ** 9 + 7
ans = (2 ** (N//2))%r
for i in range(N//2 * 2):
    if (i + N%2)//2 * 2 + (N + 1)%2 != A[i]:
        ans = 0
        break
print(ans)


Measured memory_bytes: 13880