akhauriyash/Code-Regression huggingface dataset:
<?php

$numData = (int)fgets(STDIN);

$i = 0;
while ($i < $numData) {
	$line = trim(fgets(STDIN));
	$ar = str_split($line);
	$min = $ar; sort($min);
	$min = implode('', $min);
	$max = $ar; rsort($max);
	$max = implode('', $max);

	echo $max - $min . "\n";


	$i++;
}

Measured memory_bytes: 6564
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

vecll divisor;
void fd(ll x){
  for(int i = 1; i*i<=x; i++){
    if(x%(i)==0){
      divisor.push_back(i);
      if((x/i)!=i){
        divisor.push_back(x/i);
      }
    }
  }
  sortall(divisor);
}


int main(void) {
  ll n;
  cin >> n;
  ll ans=100;

  for(ll i = 1; i*i<=n; i++){
    if(n%(i)==0){
      ll d = max(n/i, i);
      chmin(ans, (ll) log10(d)+1);
    }
  }

  prt(ans);


}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define mp  make_pair
#define NODE 1000005
#define NINF INT_MIN

vll graph[NODE];
bool vis[NODE];
bool wset[NODE];
int wss;
bool gset[NODE];
bool bset[NODE];
void dfs(int node,int dp[]) 
{ 
    // Mark as visited 
    vis[node] = true; 
  
    // Traverse for all its children 
    for (auto v:graph[node]) { 
  
        // If not visited 
        if (!vis[v]) 
            dfs(v,dp); 
  
        // Store the max of the paths
        dp[node] = max(dp[node], 1 + dp[v]); 
    } 
}
  
// Function that returns the longest path 
int findLongestPath(int n) 
{ 
    // Dp array 
    int dp[n + 1]; 
    memset(dp, 0, sizeof dp);
  
    // Call DFS for every unvisited vertex 
    for (int i = 1; i <= n; i++) { 
        if (!vis[i]) 
            dfs(i,dp); 
    } 
  
    int ans = 0; 
  
    // Traverse and find the maximum of all dp[i] 
    for (int i = 1; i <= n; i++) { 
        ans = max(ans, dp[i]); 
    } 
    return ans; 
}

bool dfs(int curr) {
   //moving curr to white set to grey set.
   wset[curr]=false;
   wss--;
   gset[curr]=true;

   for(auto v:graph[curr]) {

         if(bset[v]==true)
            continue;    //if the vertices are in the black set
         if(gset[v]==true)
            return true;    //it is a cycle
         if(dfs(v))
            return true;    //cycle found
   }

   //moving v to grey set to black set.
   gset[curr]=false;
   bset[curr]=true;
   return false;
}

bool hasCycle(int k) {
	wss=0;
   for(int i = 1; i<=k; i++){
      wss++;
      wset[i]=true;   //initially add all node into the white set
   }

   while(wss > 0) {
   	// cout<<1<<endl;
      for(int current = 1; current <= k; current++) {
         if(wset[current]==true)
            if(dfs(current))
               return true;
      }
   }
   return false;
}

int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ll n;
	cin>>n;
	map< pair<ll,ll> , ll> m;
	ll k=1;
	for(ll i=1;i<=n;++i){
		for(ll j=i+1;j<=n;++j){
			m[mp(j,i)]=k++;
		}
	}
	// for(auto val: m){
	// 	for(auto p :val.first)
	// 		cout<<p<<" ";
	// 	cout<<":";
	// 	cout<<val.second<<endl;
	// }
	pair<ll,ll> s,t;
	for(ll i=1;i<=n;++i){
		ll val;
		scanf("%d",&val);
		s=mp(max(i,val),min(i,val));
		for(ll j=1;j<n-1;++j){
			scanf("%d",&val);
			t=mp(max(i,val),min(i,val));
			graph[m[s]].pb(m[t]);
			s=t;
		}
	}
	// cout<<"here"<<endl;
	if(hasCycle(k))
		printf("-1\n");
	else{
		// cout<<1<<endl;
		printf("%d",findLongestPath(k)+1);
	}
}


Measured memory_bytes: 75520
#include <stdio.h>
#include <string.h>

int main() {
	int N, i;
	double x[10], sum = 0.0;
	char u[10][3];

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%lf %s", &x[i], &u[i]);
		if (strcmp(&u[i], "JPY") == 0) {
			sum = sum + x[i];
		}
		else {
			sum = sum + x[i] * 380000;
		}
	}

	printf("%lf", sum);

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    vec x(N), y(N);
    REP(i, N){
        cin >> x[i] >> y[i];
    }

    double ans = 0;
    REP(i, N) REP(j, i) ans += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
    ans /= N;
    Out(ans * 2);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using std::swap;

// priceをキーに降順でソート
//sort(fruits.begin(), fruits.end(),
//     [](const fruit& x, const fruit& y) { return x.price > y.price;});

/*
int main() {
    int N, A, B;
    std:cin >> N >> A >> B;
    std::cout << min(N*A, B) << std::endl;
    return 0;
}
 */

/*
int main(){
    int N, D;
    std::cin >> N >> D;
    int X[N][D];
    float dist;
    int ans=0;
    for(int i=0; i<N; i++){
        for(int j=0; j<D; j++){
            std:cin >> X[i][j];
        }
    }
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N && i!=j; j++){
            int sum = 0;
            for(int k=0; k<D; k++){
                sum += pow(X[i][k]-X[j][k],2.0);
            }
            dist = sqrt(sum);
            if(dist==(int)dist){
                ans++;
            }
        }
    }
    std::cout << ans << std::endl;
    return 0;
}
*/

/*
int main(){
    long long int L, R;
    std::cin >> L >> R;
    int min=2018;
    int tmp;
    if(R-L > 2018){
        std::cout << 0 << std::endl;
        return 0;
    }
    L %= 2019;
    R %= 2019;
    if(L>R){
        std::cout << 0 << std::endl;
    }
    else{
        for(int i=0; i<R-L; i++){
            for(int j=i+1; j<R-L+1; j++){
                tmp=((L+i)*(L+j))%2019;
                if(tmp<min){
                    min = tmp;
                }
            }
        }
        std::cout << min << std::endl;
    }
    return 0;
}
*/

int main(){
    int N;
    std::cin >> N;
    long long int d[N];
    long long int x[N];
    int tmp_d=0;
    for(int i=0; i<N; i++){
        std::cin >> d[i];
    }
    for(int i=0; i<N-1; i++){
        if(i%2==0){
            tmp_d+=d[i];
        }
        else{
            tmp_d-=d[i];
        }
    }
    x[0]=tmp_d+d[N-1];
    for(int i=1; i<N; i++){
        x[i]=2*d[i-1]-x[i-1];
    }
    for(int i=0; i<N; i++){
        std::cout<< x[i] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 2816
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	x := make([]int, n)
	tot := 0
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range a {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
		tot += a[i] // 雨の送料を求めておく
	}
	x[0] = tot // x[0]だけ最初に求めておく (0-indexed)
	for i := 1; i < n; i += 2 {
		x[0] -= 2 * a[i]
	}
	fmt.Print(x[0], " ")
	for i := 0; i < n-1; i++ { // x[i+1]を順次求める
		x[i+1] = 2*a[i] - x[i]
		fmt.Print(x[i+1], " ")
	}
	fmt.Println()
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    int n,L,T;
    cin >> n >> L >> T;
    vector<int> vec(n);
    vector<int> dir(n);
    rep(i,n){
        cin >> vec[i] >> dir[i];
    }
    int cnt = 0;
    if(dir[0] == 1){
        for(int i=1;i<n;i++){
            if(dir[i] == 2){
                int d = (vec[i]+L-vec[0])%L;
                if(T - d/2.0 >= 0){
                    cnt += (T-d/2.0) / (L/2.0) + 1;
                }
            }
        }
        rep(i,n){
            if(dir[i] == 1){
                vec[i] = (vec[i] + T) % L;
            }else{
                T %= L;
                vec[i] = (vec[i]+L - T) % L;
            }
        }
        int val = vec[0];
        int st = cnt % n;
        int ss = 0;
        sort(all(vec));
        rep(i,n){
            if(vec[i] == val){
                ss = i;
            }
        }
        vector<int> ans(n);
        rep(i,n){
            ans[(st+i)%n] = vec[(ss+i)%n];
        }
        rep(i,n){
            cout << ans[i] << "\n";
        }
    }else{
        for(int i=1;i<n;i++){
            if(dir[i] == 1){
                int d = (vec[0]+L-vec[i])%L;
                if(T - d/2.0 >= 0){
                    cnt += (T-d/2.0) / (L/2.0) + 1;
                }
            }
        }
        rep(i,n){
            if(dir[i] == 1){
                vec[i] = (vec[i] + T) % L;
            }else{
                T %= L;
                vec[i] = (vec[i]+L - T) % L;
            }
        }
        int val = vec[0];
        int st = (n - cnt%n)%n;
        int ss = 0;
        sort(all(vec));
        rep(i,n){
            if(vec[i] == val){
                ss = i;
                break;
            }
        }
        vector<int> ans(n);
        rep(i,n){
            ans[(st+i)%n] = vec[(ss+i)%n];
        }
        rep(i,n){
            cout << ans[i] << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 2432
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
LL ans,n,k;
void gcd(LL a,LL b)
{
	ans=a+b;
	while(b)
	{
		LL t=a;
		ans+=(a/b*2)*b;
		a=b;
		b=t%a;
	}
	ans-=a;
}
int main()
{
	scanf("%lld%lld",&n,&k);
	gcd(k,n-k);
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#define INFTY 1000000000
void merge(int*,int,int,int);
void mergeSort(int*,int,int);
int cnt=0;
int main(){
  int i,n,*p;
  int S[500000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  p=&S[0];
  mergeSort(p,0,n);
  for(i=0;i<n-1;i++){
    printf("%d ",S[i]);
  }
  printf("%d\n%d\n",S[i],cnt);
  return 0;
}

void merge(int *A,int left,int mid,int right){
  int n1,n2,i,j,k,*L,*R;
  n1=mid-left;
  n2=right-mid;

  L=(int*)malloc(sizeof(int)*(n1+1));
  R=(int*)malloc(sizeof(int)*(n2+1));

  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      cnt++;
      i+=1;
    }
    else {
      A[k]=R[j];
      cnt++;
      j+=1;
    }
  }
}
void mergeSort(int *A,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}



Measured memory_bytes: 64528
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <cstring>
//#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
typedef long long ll;
typedef unsigned long long ull;
#define gcd __gcd
const int INF=0x3f3f3f3f;
const ll LINF=1000000000000000000;
//priority_queue<int, vector<int>, greater<int> >p;
#define N 300005
ll n,m,l,x=0,y,k,sum,g,mid,h,v;
//ll d[4][2]={1,0,-1,0,0,1,0,-1};
ll a[N],b[N];
char c[300005];
int main()
{
    ios_base::sync_with_stdio(0);
    cin>>n;
    cin>>c+1;
    for(int i=1;i<n;i++)
        if(c[i]=='W')a[i+1]=a[i]+1;
        else a[i+1]=a[i];
    for(int i=n;i>=1;i--)
        if(c[i]=='E')b[i-1]=b[i]+1;
        else b[i-1]=b[i];
        sum=INF;
    for(int i=1;i<=n;i++)
        sum=min(sum,a[i]+b[i]);
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	set<string> ans;
	ans.insert("a");
	rep2(i, 1, n){
		set<string> ad_st;
		for(string t : ans){
			set<char> temp;
			rep(i, t.size()){
				temp.insert(t[i]);
			}
			rep(j, temp.size()+1){
				string add = t;
				char bc = 'a' + j;
				add.push_back(bc);
				ad_st.insert(add);
			}
		}
		ans = ad_st;
	}
	for(auto ss : ans){
		cout << ss << endl;
	}
	return 0;
}

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

using ll = long long;

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

    int n, w;
    cin >> n >> w;

    vector<pair<ll, ll>> items(n);
    for(auto& item : items) cin >> item.first >> item.second;

    vector<vector<ll>> dp(n, vector<ll>(w + 1, numeric_limits<ll>::min()));

    ll maxValue = numeric_limits<ll>::min();
    for(int j = 0; j <= w; ++j) {
        dp[0][j] = j - items[0].first >= 0 ? items[0].second : 0;
        maxValue = max(maxValue, dp[0][j]);
    }

    for(int i = 1; i < n; ++i) {
        for(int j = 0; j <= w; ++j) {
            dp[i][j] = dp[i - 1][j];

            int newW = j - items[i].first;
            if(newW >= 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][newW] + items[i].second);
            }

            maxValue = max(maxValue, dp[i][j]);
        }
    }

    cout << maxValue << '\n';
}


Measured memory_bytes: 79488
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  int x,a,b;
  cin >> x >> a >> b;

  if(b-a <= 0) cout << "delicious" << endl;
  else if(b-a <= x) cout << "safe" << endl;
  else cout << "dangerous" << endl;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		sc.close();
		System.out.println(Math.max(a + b, Math.max(a - b, a * b)));
	}

	public static boolean isPrime(long jud) {
		double root = Math.sqrt(jud);
		for (int i = 2; i <= root; i++) {
			if (jud % i == 0) {
				return false;
			}
		}
		return true;
	}

	// 配列要素数が1だと前触れなくバグるので注意！！！REりたくなければ要素数を保証するか例外処理を入れろ！！！
	public static long gcd(final long[] param) {
		final int len = param.length;
		long g = gcd(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			g = gcd(g, param[i + 1]);
		}
		return g;
	}

	public static long gcd(long a, long b) {
		// a > b にする(swap)
		if (a < b) {
			a = a ^ b;
			b = a ^ b;
			a = a ^ b;
		}
		// ユークリッドの互除法
		long r = -1;
		while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		}

		return a; // b には r=0 の値が入るため、a を返す
	}

	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	public static long lcm(final long[] param) {
		final int len = param.length;
		long l = lcm(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			l = lcm(l, param[i + 1]);
		}
		return l;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 21972
n,m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]


if n==1:
    for x in range(10):
        x = str(x)
        flag = True
        for s,c in sc:
            s -= 1
            if int(x[s])!=c:
                flag = False
                break
        if flag:
            print(x)
            exit()
elif n==2:
    for x in range(10,100):
        x = str(x)
        flag = True
        for s,c in sc:
            s -= 1
            if int(x[s])!=c:
                flag = False
                break
        if flag:
            print(x)
            exit()
elif n==3:
    for x in range(100,1000):
        x = str(x)
        flag = True
        for s,c in sc:
            s -= 1
            if int(x[s])!=c:
                flag = False
                break
        if flag:
            print(x)
            exit()
print(-1)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> a,b;

int main()
{
	int n;
	cin >> n;
	a = b = vector<ll>(n);
	for(int i = 0;i<n;i++){cin >> a[i]>> b[i];}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	if(n%2)
	{
		cout<<b[n/2]-a[n/2]+1<<endl;
	}
	else
	{
		ll A = a[n/2]+a[n/2-1];
		ll B = b[n/2]+b[n/2-1];
		//cout<<A<<' '<<B<<endl;
		cout<<(B-A)+1<<endl;
	}

}

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

int main() {
	int N;
	cin >> N;
	int A = N / 1000;
	int B = (N - A * 1000) / 100;
	int C = (N - A * 1000 - B * 100) / 10;
	int D = N % 10;
	if (A == B && B == C) {
		cout << "Yes" << endl;
	}
	else if (B == C&&C==D) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

/*高速化*/
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* define */
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))
#define REV(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REV(V)

/* 最大値と最小値に置き換える */
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;}


/* 型定義 */
typedef vector<long long> vi;
typedef long long ll;
using Graph = vector<vi>;


/* 定数 */
const double PI = 3.141592;
const double e = 2.6;
const long long Inf = 1LL << 60;
const long long mInf = -Inf;

/* 入力 */
long long N,M,K;

void calc()
{
    cin >> K >> N >> M;
    for(int i = N; i <= M;i++)
    {
        if(i %  K == 0)
        {
            cout << "OK\n";
            return;
        }
    }
    cout << "NG\n";    
}


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


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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define INF 1000000000
#define bits(n) __builtin_popcount(n)

void solve()
{
    string s, t;
    cin >> s >> t;
    int mini=INT_MAX;
    for(int i=0;i<s.length()-t.length()+1;i++)
    {
        int c = 0;
        for(int j=0;j<t.length();j++)
        {
            if(s[i+j]!=t[j])
            {
                c++;
            }
        }
        mini=min(mini,c);
    }
    cout<<mini;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT32_MAX;
const long long int Mod = 1000000007;
const long long int mod = 100000;//10^5
using ll = long long int; //long long int は64bit
using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int,int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit(){cin.tie(0);ios::sync_with_stdio(false);}
///////////////////////////////////////////////////////////////////////////////////

int main(){
    ll n;ll x;
    ll max=0;ll sum = 0;
    cin>>n;
    rep(i,n){
        cin>>x;
        chmax(max,x);
        sum += x;
    }
    cout<<sum-max/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[20];
    scanf("%s",&a);
    for(int i=0; i<4; i++)
        printf("%c",a[i]);
    printf(" ");
    for(int i=4; i<12; i++)
        printf("%c",a[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int ans = 0, s, k;
  cin >> k >> s;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int z = s - x - y;
      if (0 <= z && z <= k) ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}


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


using namespace std;

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

ll dp[102][4][2];


int main() {
	string s;
	ll K;
	cin >> s >> K;

	dp[0][0][0] = 1;

	rep(i, s.size()) {
		int cur = s[i] - '0';
		rep(j, K + 1) {
			rep(k, 2) {
				rep(d , 10) {
					int ni = i + 1, nj = j, nk = 1;
					if (d != 0) {
						nj ++;
					}
					if (nj > K) {
						continue;
					}
					if (cur < d && k == 0) {
						continue;
					}

					if (cur == d && k == 0) {
						nk = 0;
					}
					dp[ni][nj][nk] += dp[i][j][k];
				}
			}
		}
	}
	
	cout << dp[s.size()][K][0] + dp[s.size()][K][1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	int N;
	cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    sort(all(A));
    int ans = 1;
    ll sum = 0;
    rep(i,N-1) {
        sum += A[i];
        ans++;
        if (sum*2 < A[i+1]) ans = 1;
    }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
n = int(input())
a = {}
for i in range(n):
    s = input()
    if s not in a.keys():
        a[s] = 1
    else:
        a[s] += 1
mx = 0
for i in a.keys():
    if a[i] >= mx:
        mx = a[i]

l = []
for i in a.keys():
    if a[i] == mx :
        l.append(i)
l = sorted(l)
for i in l:
    print(i)



    

# h = sorted(h,reverse = True)
# print(sum(h[k:]))zz

# s,t= map(str, input().split())
# a,b= map(int, input().split())
# u = input()
# print("x"*len(u))

# if(u == s):
#     print(a-1,b)
# else:
#     print(a,b-1)


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

int main() {
    int N,sum=0,sum2=0;
    cin >>N;
    vector<int> data(N);
    vector<int> main(N);
    for(int i=0; i<N;i++){
        cin >> data.at(i);
        sum += data.at(i);
    }
    for(int i=0;i<N;i++){
        sum2 += data.at(i);
        main.at(i) = sum -2*sum2;
        if(main.at(i)<0) main.at(i) = -main.at(i);
    }
    sort(main.begin(),main.end());
    cout << main.at(0) <<endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int x=scanner.nextInt();
		int ans = 0;
		int count = 0;
		for(;ans < x;count++){
			ans += count;
		}
		System.out.println(count-1);
	}
}

Measured memory_bytes: 21972
#include <iostream>
using namespace std;
bool sub(char const c) {
    return ('a' <= c &&  c <= 'z');
}
bool func (std::string const& S) {
    if (S[0] != 'A') return false;
    size_t const len = S.size();
    size_t const end = len - 1;

    bool found_C = false;
    if (!sub(S[1])) return false;
    for (size_t i = 2; i < end; i++) {
        if (S[i] == 'C') {
            if (!found_C) found_C = true;
            else return false;
        } else if (!sub(S[i])) {
            return false;
        }
    }
    return found_C && sub(S[end]);
}
int main() {
    std::string S;
    std::cin >> S;
    std::string ret = func(S) ? "AC" : "WA";
    std::cout << ret << endl;
    return 0;
}



Measured memory_bytes: 256
#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 n;cin>>n;
  int ans=0;
  for(int i=1;i<=n;i++){
    int cnt=0;
    for(int j=1;j<=i;j++){
      if(i%j==0)cnt++;
    }
    if(cnt==8&&i%2==1)ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-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; }

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;


    ll n;
    cin>>n;
    vll a(n);
    rep(i,n){
        cin>>a[i];
    }
    ll ans=0;
    rep(i,n){
        while(a[i]%2==0){
            a[i]/=2;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
from fractions import gcd

n, m = map(int, input().split())
s = input()
t = input()

g = gcd(n, m)
lcm = n // g * m
ok = True
for i in range(n):
	if (i * (lcm // n)) % (lcm // m) == 0:
		if s[i] != t[(i * (lcm // n)) // (lcm // m)]:
			ok = False
			break
if ok:
	print(lcm)
else:
	print(-1)

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

int main(){
    string a, b;
    cin>>a>>b;
    
    int m=a.length();
    int n=b.length();
    
    int dp[m+1][n+1];
    
    for(int i=0; i<=m; i++){
        for(int j=0; j<=n; j++){
            
            if(i==0 or j==0) dp[i][j]=0;
            
            else if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            
            else dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
            
        }
    }
    
    int l=dp[m][n];
    //cout<<l<<"\n";
    char str[l+1];
    str[l]='\0';
    
    while(m>0 and n>0){
        if(a[m-1]==b[n-1]){
            str[l-1]=a[m-1];
            l--;
            m--;
            n--;
        }
        
        else if(dp[m-1][n] > dp[m][n-1]) m--;
        else n--;
    }
  
    cout<<str;
    return 0;
}


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

A = {i:0 for i in range(N)}

x = 0
while (x+1)**2+8 <= 2*N:
    x += 1
    y = 0
    while (x+1)**2 + (y+1)**2 + (x+y)**2 <= 2*N:
        y += 1
        z = 0
        while (x+y)**2 + (y+z)**2 + (z+x)**2 <= 2*N:
            z += 1
            if (x+y)**2 + (y+z)**2 + (z+x)**2 <= 2*N:
                A[x**2 + y**2 + z**2 + x*y + y*z + z*x-1] += 1

for i in range(N):
    print(A[i])

Measured memory_bytes: 9588
#include <iostream>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define REP(i,n) for (int i=1;i<=n;i++)
#define print(x) cout << x << endl;
typedef long long ll;

int main() {
	int n, counter=0; cin>>n;
	REP(i, n) {
		if (i == 105 || i==135 || i == 165 || i==189 || i == 195) counter++;
	}
	cout << counter << endl;
	return 0;
}


Measured memory_bytes: 256
import itertools
N, M = map(int ,input().split())
matrix = [[0]*N for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    matrix[a-1][b-1] = 1
    matrix[b-1][a-1] = 1

count = 0

for p in itertools.permutations(range(N)):
    #print(p)
    if p[0] != 0:
        break
    check = 1
    for s in range(N-1):
        check = check  * matrix[p[s]][p[s+1]]
    count += check

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int inf = 1<<30;
typedef pair<int, int> P;

int main() {
  int n, m; cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  priority_queue<P> q;
  rep(i, n) q.push(P(a[i], 1));
  vector<int> b(m), c(m);
  rep(i, m) {
    cin >> b[i] >> c[i];
    q.push(P(c[i], b[i]));
  }

  ll ans = 0;
  rep(_, n) {
    P p = q.top(); q.pop();
    ans += p.first;
    if(p.second > 1) {
      q.push(P(p.first, p.second-1));
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 998244353;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

//入出力高速化(非同期化)
void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

vector<Int> Divisor(Int n) {
    vector<Int> ret;
    for(Int i=1; i*i<=n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i*i!=n) ret.push_back(n / i);
        }
    }
    return ret;
}

int main(void) {
    long long N; cin >> N;
    vector<long long> div = Divisor(N);

    long long ans = 0;
    for (auto i: div) {
        if (i > 1 && N/i < i-1) {
            ans += i-1;
        }
    }
    cout << ans << endl;
    
}



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

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

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//C++14 (GCC 5.4.1)
int main() {
    int N,M;
    cin >>N>>M;

    int L,R,ML=0,MR=1000000;
    rep(i,M){
        cin >> L>>R;
        chmax(ML,L);
        chmin(MR,R);
    }
    int ans=0;
    chmax(ans,MR-ML+1);
    cout << ans <<endl;
    return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
    template<typename T> void chadd(T& a, T b) { a = a + b; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
    };

    inp inp1; // input one

    ll rec(int left, int right, int n, const vector<ll>& a, vector<vector<ll>>& dp) {
        if (left >= right) return 0LL;
        if (dp[left][right] != infll) return dp[left][right];

        int drop_num = (n - right) + left;

        if (right - left == 1) {
            if (drop_num % 2 == 0) return dp[left][right] = a[left];
            else return dp[left][right] = -a[left];
        }

        // 右か左か
        ll res = 0LL;
        if (drop_num % 2 == 0) { // 最大化
            res = -infll;
            chmax(res, rec(left + 1, right, n, a, dp) + a[left]);
            chmax(res, rec(left, right - 1, n, a, dp) + a[right - 1]);
        }
        else { // 最小化 
            res = infll;
            chmin(res, rec(left + 1, right, n, a, dp) - a[left]);
            chmin(res, rec(left, right - 1, n, a, dp) - a[right - 1]);
        }

        return dp[left][right] = res;
    }
}

int main() {

    int n = inp1;
    vector<ll> a = inp(n);

    // dp[i][j] := 左からi個，右からj個取った時の　最適な X-Y
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, infll));

    Cout(rec(0, n, n, a, dp));

    // この区間DP，あまり見えないなぁ
    // ゲームAIで活用できそう

    // 階層ごとにどっちが選ぶか分けるとわかりやすい？

    return 0;
}


Measured memory_bytes: 71040
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        long M = scan.nextLong();
        if (N == 1 && M == 1) {
            System.out.println(1);
            return;
        }
        if (N == 2 || M == 2) {
            System.out.println(0);
            return;
        }
        if (M < N) {
            long t = N;
            N = M;
            M = t;
        }
        if (N == 1) {
            System.out.println(M-2);
            return;
        }
        System.out.println((M-2) * (N-2));
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int x;
    cin >> x;
    int res = 1;
    while((x*res)%360)res++;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#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;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#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
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

vector<ll> enum_div(ll n){
    vector<ll> ret;
    for(ll i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

int main(void) {
    
    ll n;
    cin>>n;
    vll v=enum_div(n);

    ll ans=LLINF;
    rep(i,v.size()){
        ll a=v[i];
        ll b=n/v[i];
        // cout<<a<<" "<<b<<endl;
        int dig1=0;
        int dig2=0;
        while(a>0){
            dig1++;
            a/=10;
        }
        while(b>0){
            dig2++;
            b/=10;
        }
        ans=min(ans,(ll)max(dig1,dig2));
    }
    fin(ans);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    vector<string> S(N);
    for (int i = 0; i < N; i++){
      cin >> S[i];
    }
    vector<char> ch;
    for (int i = 0; i < N; i++){
      int sz = S[i].size();
      for (int j = 0; j < sz; j++){
        ch.push_back(S[i][j]);
      }
    }
    sort(ch.begin(), ch.end());
    ch.erase(unique(ch.begin(), ch.end()), ch.end());
    int cnt = ch.size();
    map<char, char> mp;
    for (int i = 0; i < cnt; i++){
      mp[ch[i]] = 'A' + i;
    }
    for (int i = 0; i < N; i++){
      int sz = S[i].size();
      for (int j = 0; j < sz; j++){
        S[i][j] = mp[S[i][j]];
      }
    }
    vector<bool> ok(cnt, true);
    vector<int> sum(cnt, 0);
    for (int i = 0; i < N; i++){
      int sz = S[i].size();
      if (sz > 1){
        ok[S[i][0] - 'A'] = false;
      }
      int c = 1;
      for (int j = sz - 1; j >= 0; j--){
        if (i < N - 1){
          sum[S[i][j] - 'A'] += c;
        } else {
          sum[S[i][j] - 'A'] -= c;
        }
        c *= 10;
      }
    }
    vector<int> p(10);
    for (int i = 0; i < 10; i++){
      p[i] = i;
    }
    int ans = 0;
    while (1){
      int d = 0;
      bool ok2 = true;
      for (int j = 0; j < cnt; j++){
        d += sum[j] * p[j];
        if (p[j] == 0 && !ok[j]){
          ok2 = false;
        }
      }
      if (d == 0 && ok2){
        ans++;
      }
      if (!next_permutation(p.begin(), p.end())){
        break;
      }
    }
    for (int i = 1; i <= 10 - cnt; i++){
      ans /= i;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3164
#include <iostream>
#include <string>
using namespace std;
char m[6][5] = {
  { 'a','b','c','d','e'},
  { 'f','g','h','i','j'},
  { 'k','l','m','n','o'},
  { 'p','q','r','s','t'},
  { 'u','v','w','x','y'},
  { 'z','.','?','!',' '},
};
int main()
{
  string s;
  while(cin >> s){
    int i,j,k,l = s.length();
    if(l % 2 == 1) {
      cout << "NA" << endl;
      continue;
    }
    char t[102];
    for(i=0; i<l/2; i++){
      j = s[i*2] - '0' - 1;
      k = s[i*2+1] - '0' - 1;
      if(j < 0 || k < 0 || j > 5 || k > 4) {
	cout << "NA" << endl;
	break;
      }
      t[i] = m[j][k];
    }
    if(i >= l/2) {
      t[i] = '\0';
      cout << t << endl;
    }
  }
  return 0;
}

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

using namespace std;

int main()
{
    long long n, d;
    cin >> n >> d;
    int c = 0;
    for (int i = 0; i < n; i++) {
        long long x, y;
        cin >> x >> y;
        if (x*x + y * y <= d *d) {
            c++;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3616
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = sorted(a, reverse=True)
    for i in range(len(a)):
        if a[i] == b[0]:
            print(b[1])
        else:
            print(b[0])


if __name__ == '__main__':
    slove()


Measured memory_bytes: 59824
mod=1e9+7,dp[1<<21];
n,a,I,x,y,i,j;
main()
{
	for(*dp=scanf("%d",&n);i++<n;)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&a);
			for(I=(1<<i)-1;I<1<<n;)
			{
				dp[I]=(dp[I]+!!(I&a<<j)*dp[I&~(1<<j)])%mod;
				x=I&-I,y=I+x;
				I=(I&~y)/x>>1|y;
			}
		}
	}
	printf("%d",dp[I-y/2]);
}

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

long dp[101][100010];
const int mod=1e9+7;

int main()
{
    int N, K; cin>>N>>K;
    vector<int> a(N); for(auto& e: a) cin>>e;

    dp[0][0]=1;
    for(int i=0; i<N; ++i) {
        for(int j=0; j<=K; ++j) {
            dp[i+1][j]=dp[i][j];
            if (j>=1)
                dp[i+1][j]+=dp[i+1][j-1];
            if (j-1>=a[i])
                dp[i+1][j]+=mod-dp[i][j-1-a[i]];
            dp[i+1][j]%=mod;
        }
    }
    cout<<dp[N][K]<<endl;
}


Measured memory_bytes: 78336