akhauriyash/Code-Regression huggingface dataset:
import sys
N,C = map(int,input().split())
table=[]
for i in range(N):
    x,v=map(int,input().split())
    table.append([x,v])
ans=0
if N==1:
    ans=max(0,table[0][1]-table[0][0],table[0][1]+table[0][0]-C)
    print(ans)
    sys.exit()
V=[0]*N
clo=[0]*N
V[0]=table[0][1]
clo[0]=V[0]-table[0][0]
for i in range(1,N):
    V[i]=V[i-1]+table[i][1]
    clo[i]=max(clo[i-1],V[i]-table[i][0])
    ans = max(clo[i],ans)
rclo=[0]*N
rclo[N-1]=V[N-1]-V[N-2]-C+table[N-1][0]
for i in range(N-1,1,-1):
    rclo[i-1]=max(rclo[i],V[N-1]-V[i-2]-C+table[i-1][0])
    ans = max(clo[i],ans)
rclo[0]=max(rclo[1],V[N-1]-C+table[0][0])
ans = max(rclo[0],ans)

for i in range(N-1):
    t = V[i]+rclo[i+1]-2*table[i][0]
    ans=max(t,ans)
for i in range(N-1,0,-1):
    t = V[N-1]-V[i-1] + clo[i-1]-2*C+2*table[i][0]
    ans=max(t,ans)

print(ans)




Measured memory_bytes: 32272
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	string s;
	cin>>s;
	int it[4]={0,1,6,8};
	rep(i,4){
		if(s[size(s)-1]-'0'==it[i]){
			cout<<"pon"<<endl;
			return ;
		}else if(s[size(s)-1]=='3'){
			cout<<"bon"<<endl;
			return ;
		}
	}
	cout<<"hon"<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

class Main{
        public static void main(String args[]){
                Scanner scan = new Scanner(System.in);
                int val1=scan.nextInt();
                int val2=scan.nextInt();
                int a=val1/val2;
                int b=val1%val2;
                double c=(double)val1/val2;
                String f=String.format("%.6f",c);
                System.out.println(a+" "+b+" "+f);
        }
}

Measured memory_bytes: 26504
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
mod = 10**9+7
a_list.sort()
ans = 1
if k % 2 == 1 and a_list[-1] < 0:
    for i in range(k):
        ans *= a_list[n - 1 - i]
        ans %= mod
else:
    l = 0
    r = -1
    mlt1 = a_list[0] * a_list[1]
    mlt2 = a_list[-2] * a_list[-1]
    count = 0
    while True:
        if count == k:
            break
        elif count == k - 1:
            ans *= a_list[r] % mod
            ans %= mod
            break
        if mlt1 >= mlt2:
            ans *= mlt1 % mod
            l += 2
            count += 2
            if l <= n - 2:
                mlt1 = a_list[l + 1] * a_list[l]
        else:
            ans *= a_list[r] % mod
            r -= 1
            count += 1
            if r >= - n + 1:
                mlt2 = a_list[r - 1] * a_list[r]
        ans %= mod
print(ans)


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

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


int main(){
    int n;
    string s;
    cin>>n>>s;
    int b[200100],w[200100],cnt[200100];
    int x=0,y=0;//x black y white
    rep(i,n){
        if(s[i]=='#') x++,b[i]=x,w[i]=y;
        else y++,w[i]=y,b[i]=x;
    }
    rep(i,n) cnt[i]=b[i]+w[n-1]-w[i];
    int m=w[n-1];
    rep(i,n) m=min(m,cnt[i]);
    cout<<m<<endl;
}

Measured memory_bytes: 2948
#include <iostream>
#include <queue>
#include <map>

#define rep(i, a, b) for(int i = (a); (i) < (b); (i)++)
#define ft first
#define sd second

using namespace std;

char m[1000][1000];
int dis[1000][1000];
queue<pair<int, int> > state;

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

  cin >> h >> w >> n;

  int sx, sy;
  rep(i, 0, h) {
    rep(j, 0, w) {
      cin >> m[j][i];
      if(m[j][i] == 'S') {
	sx = j;
	sy = i;
      }
    }
  }

  pair<int, int> p;
  p.ft = sx;
  p.sd = sy;

  rep(i, 0, h) {
    rep(j, 0, w) {
      dis[j][i] = -1;
    }
  }
  dis[sx][sy] = 0;
  state.push(p);

  int dx[4] = {-1,   0,  1, 0};
  int dy[4] = { 0,  -1,  0, 1};
  int map2[1000][1000];
  for(int lp = 1; lp <= n; lp ++) {
    rep(i, 0, h) {
      rep(j, 0, w) {
	map2[j][i] = 0;
      }
    }

    map2[sx][sy] = 1;
    while(state.size()) {
      pair<int, int> now = state.front();
      state.pop();
      if(m[now.ft][now.sd] - '0' == lp) {
	sx = now.ft;
	sy = now.sd;
	break;
      }
      
      rep(lp2, 0, 4) {
	int x = now.ft+dx[lp2];
	int y = now.sd+dy[lp2];
	
	if(x < 0 || w <= x || y < 0 || h <= y) continue;
	if(map2[x][y] == 0 && m[x][y] != 'X') {
	  state.push(make_pair(x, y));
	  dis[x][y] = dis[now.ft][now.sd] + 1;
	  map2[x][y] = 1;
	}
      }
    }
    while(state.size()) state.pop();

    state.push(make_pair(sx, sy));
  }

  cout << dis[sx][sy] << endl;
  return 0;
}

Measured memory_bytes: 10004
#include <bits/stdc++.h>
#define ll  long long

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, "\e[31;1m"); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\e[0m")
#else
    #define eprintf(...) 42
#endif

std::string solve(std::string& S)
{
    int t = 0;
    for (int i = S.length() - 1; -1 < i; i--)
    {
#if true
        eprintf("DEBUG1: %d %s\n", i, S.c_str());
#endif
        if (0 == i || i == S.length() - 1)
        {
            continue;
        }
        if (S[i - 1] != S[i + 1])
        {
            S = S.substr(0, i) + S.substr(i + 1);
            t++;
            i++;
        }
    }
#if true
    eprintf("DEBUG2: %s\n", S.c_str());
#endif

    if (1 == t % 2)
    {
        return "First";
    }
    return "Second";
}

int main(void)
{
    std::string S;
    std::cin >> S;
    std::cout << solve(S) << std::endl;
    return 0;
}

Measured memory_bytes: 652
N, L = map(int, input().split())

#最初のりんご
f_ringo = 0
#最後のりんご
l_ringo = 0
#りんごの個数
num = 0

if L >= 0:
    #１つ目のりんごを食べる
    f_ringo = L + 2 - 1
    l_ringo = L + N - 1
    num = N - 1

        
elif L < 0 and N+L > 0:
    #味が0のりんごを食べる
    f_ringo = L + 1 - 1
    l_ringo = L + N - 1
    num = N


elif L < 0 and N+L <= 0:
    #最後のりんごを食べる
    f_ringo = L + 1 - 1
    l_ringo = L + N-1 - 1
    num = N - 1

total = ((f_ringo+l_ringo) * int(num/2))
if num%2 == 1:
    ringocenter = f_ringo + int(num/2)
    total += ringocenter

print(total)

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

const int64_t MOD = 1e6+3;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int Q;
    cin >> Q;
    create_mod_tables(MOD-1);
    while(Q--){
        int64_t X, D, N, ans;
        cin >> X >> D >> N;
        if(D == 0){
            ans = power_mod(X, N) % MOD;
        }else{
            int64_t st = X * inv_mod(D) % MOD;
            int64_t term = st + N-1;
            if(st == 0 || st/MOD != term/MOD){
                ans = 0;
            }else{
                ans = fact[term] * inv_mod(fact[st-1]) % MOD;
            }
            mul(ans, power_mod(D, N));
        }
        cout << ans << endl;
    }
    return 0;
}

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

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

using namespace std;
using lint = long long;

int main(void)
{
    int A, B;
    cin >> A >> B;
    cout << 6 - A - B << endl;
    return 0;
}


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

using namespace std;

int main(void){

    int A,B,C,D;
    cin >> A >> B >> C >> D;

    while(true){
        C -= B;
        if(C>0){
            A -= D;
            if(A>0) continue;
            cout << "No" << endl;
            return 0;
        }else{
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3604
N, M = map(int,input().split())

from1 = []
gotoN = []

for i in range(M):
	a, b = map(int,input().split())
	if a == 1:
		from1.append(b)
	if b == N:
		gotoN.append(a)

res = set(from1) & set(gotoN)

print("POSSIBLE" if len(res) > 0 else "IMPOSSIBLE")

Measured memory_bytes: 21836
k, x = (int(i) for i in input().split())
arr = []

for i in range(-k + 1, 0):
  for j in range(0, k + 1):
    arr.append(i + j + x) 

sorted_list = sorted(list(set(arr)))

result =  " ".join(map(str, sorted_list))
if (k == 1):
  result = x


print(result)

Measured memory_bytes: 3188
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if (a<b)
	{
		printf("a < b\n");
	}
	if (a > b){
		printf("a > b\n");
	}
	if (a == b){
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
using P = pair<int, int>;
int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    
    map<int, int> num1, num2;
    for(int i = 0; i < n; i++){
        if(i & 1){
            if(num1.count(v[i])){
                num1.at(v[i])++;
            }else{
                num1[v[i]] = 1;
            }
        }else{
            if(num2.count(v[i])){
                num2.at(v[i])++;
            }else{
                num2[v[i]] = 1;
            }
        }
    }
    vector<P> v0;
    vector<P> v1;
    for(auto p: num1){
        P tmp;
        tmp.first = p.second;
        tmp.second = p.first;
        v0.push_back(tmp);
    }
    for(auto p: num2){
        P tmp;
        tmp.first = p.second;
        tmp.second = p.first;
        v1.push_back(tmp);
    }
    sort(v0.begin(), v0.end());
    reverse(v0.begin(), v0.end());
    sort(v1.begin(), v1.end());
    reverse(v1.begin(), v1.end());
    
    int count = 0;
    
    if(v0[0].second != v1[0].second){
        count = n - v0[0].first - v1[0].first;
    }else if(v0.size() >= 2 && v1.size() >= 2){
        if(v0[0].first + v1[1].first > v0[1].first + v1[0].first){
            count = n - v0[0].first - v1[1].first;
        }else{
            count = n - v0[1].first - v1[0].first;
        }
    }else if(v0.size() >= 2){
        count = n - v0[1].first - v1[0].first;
    }else if(v1.size() >= 2){
        count = n - v0[0].first - v1[1].first;
    }else{
        count = n/2;
    }
    
    cout << count << endl;
    
    return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int>a(n);
  for(int i=0; i<n; ++i) {
    cin >> a[i];
  }
  
  
  int Max = *max_element(a.begin(), a.end());
  int index = max_element(a.begin(),a.end()) - a.begin();
  a.erase(a.begin()+index);
  int subMax = *max_element(a.begin(), a.end());
  a.insert(a.begin()+index, Max);
  
  
  for(int i=0; i<n; ++i) {
    if(a[i] != Max) {
      cout << Max << endl;
    }else{
      cout << subMax << endl;
    }
  }
  
}
      



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

int main()
{
  int n;
  cin>>n;
  if(n==0)cout<<1%2<<endl;
  if(n==1)cout<<11%3<<endl;
  if(n==2)cout<<111%5<<endl;
  if(n>2) cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 1164
/*	                           
							 * * 
						   *     * 
						 *	       * 
					   *	         * 
                     *     _ooOoo_     * 
                   *      o8888888o      * 
                 *        88" . "88        * 
                *         (| -_- |)         * 
               *       *  0\  =  /0  *       * 
               *       *__0/`---'\0__*       * 
               *     .'  \\|     |//  `.     * 
                *   /  \\|||  :  |||//  \   * 
                 * /  _||||| -:- |||||-  \ * 
                   |   | \\\  -  /// |   |
                   | \_|  ''\---/''  |   |
                   \  .-\__  `-`  ___/-. /
                 ___`. .'  /--.--\  `. . __
              ."" '<  `.___\_<|>_/___.'  >'"".
             | | :  `- \`.;`\ _ /`;.`/ - ` : | |
             \  \ `-.   \_ __\ /__ _/   .-` /  /
        ======`-.____`-.___\_____/___.-`____.-'======
                           `=---='
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                   佛祖保佑       永无BUG
                        author：Richie 
*/

#include<stdio.h>
#include<string.h>	
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define LOCAL
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long
#define N 500001
#define mod 1000000007

int cmp(const void *a,const void *b);
void print_array(int *a,int n);
void read_array(int *a,int n);
void init();
ll fast(ll x);
ll exgcd(ll a,ll b,ll *x,ll *y);
ll getInv(int a);
ll gcd(ll a,ll b);

int main(){
    int n;
    scanf("%d",&n);
    if(n==1||n==2)printf("0\n");
    else {
    	int a[n];
    	for(int i=0;i<n;i++){
    		scanf("%d",&a[i]);
		}
		int num=0;
		for(int i=0;i<n-2;i++){
			for(int j=i+1;j<n-1;j++){
				for(int k=j+1;k<n;k++){
					if(a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k]){
						if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i]){
							num++; 
						}
					}
				}
			}
		}
		printf("%d",num);
	}
	return 0;
}







ll gcd(ll a,ll b){
	int t;
	while(b!=0){
		t=a%b;
		a=b;
		b=t;
	}
	return a;
}

ll fast(ll x){									//逆元 费马小定理/欧拉定理 适用范围：一般在mod是个素数的时候用
	int y=mod-2;
	ll res=1;
	while(y){
		if(y&1)res=res*x%mod;
		x=x*x%mod; 
		y>>=1;
	}
	return res;
}

ll exgcd(ll a,ll b,ll *x,ll *y)					//扩展欧几里得算法 
{
    if(b==0)
    {
        *x=1,*y=0;
        return a;
    }
    ll ret=exgcd(b,a%b,y,x);
    *y-=a/b*(*x);
    return ret;
}
ll getInv(int a)						//求a在mod下的逆元，不存在逆元返回-1 
{
    ll x,y;
    ll d=exgcd(a,mod,&x,&y);
    return d==1?(x%mod+mod)%mod:-1;
}

void init(void){
	#ifdef LOCAL
		freopen("P2678_2.in","r",stdin);
		freopen("data.txt","w",stdout);
	#endif
}

int cmp(const void *a,const void *b){
	return *(int*)a-*(int*)b;					//升序排列 
} 

void print_array(int *a,int n){
	FOR(i,1,n){
		if(i!=n)printf("%d ",a[i]);
		else printf("%d",a[i]);
	}
} 

void read_array(int *a,int n){
	FOR(i,1,n)scanf("%d",&a[i]);
}




Measured memory_bytes: 1736
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
   char x[90];
   int y;
   int i=0,l,j,min=753;
   scanf("%s",x);
   l=strlen(x);
   for(i=0;i<l-2;i++)
   {
       j=(x[i]-'0')*100+(x[i+1]-'0')*10+x[i+2]-'0';
       y=fabs(753-j);
        if(min>y)
            min=y;
   }
  printf("%d",min);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    int a;
    long long int n[2000001];
    long long int b[2000001];
    long long int c[2000001];
    long long int m=0;
    scanf("%d",&a);

    for(int i=1;i<=a;i++)
    {
         b[i]=0;
         c[i]=0;
    }

    for(int i=1;i<=a;i++)
    {
        scanf("%lld",&n[i]);
        b[n[i]]++;
    }

    for(int i=1;i<=a;i++)
    {
        c[i]=b[i]*(b[i]-1)/2;
        m+=c[i];
    }

    for(int i=1;i<=a;i++)
    {
        printf("%lld\n",m-b[n[i]]+1);
    }
    return 0;
}


Measured memory_bytes: 9088
#include <stdlib.h>
#include<iostream>

using namespace std;

int n;
int k;

int main(void) {
	cin >> n;
	for (int i = 1; i < 10; i++) {
		for (int j = i; j < 10; j++) {
			if (n == i * j) {
				cout << "Yes";
				exit(0);
			}
		}
	}
	cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

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

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int H, W;
char board[15][25];
bool used[15][25];
map<string, int> memo;

void solve(int x, int y, int dir) {
    string ret = "";
    int s = x, t = y;
    while(1) {
        if(used[s][t]) break;
        used[s][t] = true;
        ret += board[s][t];
        memo[ret]++;

        s = (s + dx[dir] + H) % H;
        t = (t + dy[dir] + W) % W;
    }
}

bool isbetter(string a, string b) {
    if(a.length() != b.length()) return a.length() > b.length();
    else return a < b;
}

signed main() {
    while(cin >> H >> W, H || W) {
        memo.clear();
        rep(i,0,H) rep(j,0,W) cin >> board[i][j];
        rep(i,0,H) rep(j,0,W) rep(k,0,8) {
            memset(used, false, sizeof(used));
            solve(i, j, k);
        }
        string ans = "";
        for(auto elem : memo) {
            if(elem.second < 2) continue;
            if(elem.first.length() < 2) continue;
            if(isbetter(elem.first, ans)) ans = elem.first;
        }
        if(ans == "") cout << 0 << endl;
        else cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 37904
h, w, kk = map(int, input().split())

c = [input() for i in range(h)]

ans = 0

for i in range(2 ** h):
    for k in range(2 ** w):
        cnt = 0
        for j in range(h):  
                for l in range(w):
                    if ((i >> j) & 1) and ((k >> l) & 1):
                        if c[j][l] == '#':
                            cnt = cnt + 1
        if cnt == kk:
            ans = ans + 1


print(ans)

Measured memory_bytes: 9092
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii;
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int main(void){
  int no[] = {0,1,2,3,5,7,8,9};
  int num;
  while(cin>>num,num){
    vector<int> inp;
    while(num>0){
      inp.push_back(num%8);
      num/=8;
    }

    reverse(all(inp));

    rep(i,inp.size()){

      cout<<no[inp[i]];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1212
#include <stdio.h>

int main()
{
  int a,b,c;
  int tmp = 0;
  
  scanf("%d %d %d", &a, &b, &c);

  if(a >= b)
    {
      tmp = a;
      a = b;
      b = tmp;
    }
  
  if(b >= c)
    {
      tmp = b;
      b = c;
      c = tmp;
    }

    if(a >= b)
    {
      tmp = a;
      a = b;
      b = tmp;
    }

  printf("%d %d %d\n", a, b, c);
  
  return 0;

}


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

int main() {
    int a,b,c;
    cin >> a >> b;
    if(b<=9) c=a*10+b;
    else if(b>=10&&b<=99) c=a*100+b;
    else c=a*1000+b;
    string ans = "No";
    for(int i=1;i<1000;i++){
        if(c==i*i){
            ans = "Yes";
            break;
        }
        if(c<i*i){
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func solve() {
	s := getString()
	n := len(s)
	k := getInt()

	m := make(map[string]bool)
	subStrs := make([]string, 0, n*k)
	for i := range s {
		for j := 0; j <= k && i+j < n; j++ {
			subStr := s[i : i+j+1]
			if _, ok := m[subStr]; !ok {
				m[subStr] = true
				subStrs = append(subStrs, subStr)
			}
		}
	}

	sort.Strings(subStrs)

	ans := subStrs[k-1]
	fmt.Fprintln(wr, ans)
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

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

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define lln long long int
using namespace std;
int main()
{
    lln total=0;
    string s;
    cin>>s;
    for(int i=0; s[i]; i++)
    {
        total+=s[i]-'0';
    }
    if(total%9==0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3720
using System;
using System.Linq;

class A
{
    static void Main()
    {
        //string[] x = (Console.ReadLine()).Split(' ');
        int X = int.Parse(Console.ReadLine());
        //int R = int.Parse(x[1]);
        //int d = int.Parse(x[2]);
        int grade = 0;
        
        if(400<= X && X<600)
        {
            grade = 8;
        }
        else if (600 <= X && X < 800)
        {
            grade = 7;
        }
        else if (800 <= X && X < 1000)
        {
            grade = 6;
        }
        else if (1000 <= X && X < 1200)
        {
            grade = 5;
        }
        else if (1200 <= X && X < 1400)
        {
            grade = 4;
        }
        else if (1400 <= X && X < 1600)
        {
            grade = 3;
        }
        else if (1600 <= X && X < 1800)
        {
            grade = 2;
        }
        else if (1800 <= X && X < 2000)
        {
            grade = 1;
        }

        Console.WriteLine(grade.ToString());
    }
}

Measured memory_bytes: 27484
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    string s;
    static long long ans=0, ant[100010]={0}, bnt[100010]={0}, cnt[100010]={0}, dnt[100010]={0}, p, mod=1000000007;
    cin>>s;
    if (s[0]=='A') ant[0]=1;
    if (s[0]=='?') bnt[0]=1;
    cnt[s.size()]=0;
    dnt[s.size()]=0;
    for (int i=1; i<s.size(); i++)
    {
        ant[i]=ant[i-1]+(s[i]=='A');
        bnt[i]=bnt[i-1]+(s[i]=='?');
    }
    for (int i=s.size()-1; i>=0; i--)
    {
        cnt[i]=cnt[i+1]+(s[i]=='C');
        dnt[i]=dnt[i+1]+(s[i]=='?');
    }
    for (int i=1; i<=s.size()-2; i++)
    {
        if (s[i]=='A' || s[i]=='C') continue;
        p=(ant[i-1]*3+bnt[i-1])*(cnt[i+1]*3+dnt[i+1]);
        if (s[i]=='B') ans+=p*3;
        else ans+=p;
    }
    if (bnt[s.size()-1]==0) ans=(ans/27)%mod;
    if (bnt[s.size()-1]==1) ans=(ans/9)%mod;
    if (bnt[s.size()-1]==2) ans=(ans/3)%mod;
    if (bnt[s.size()-1]==3) ans%=mod;
    if (bnt[s.size()-1]>4) for (int i=4; i<=bnt[s.size()-1]; i++) ans=(ans*3)%mod;
    cout<<ans<<'\n';
    return 0;
}


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

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    long a = scanner.nextLong();
    long b = scanner.nextLong();
    long n = scanner.nextLong();

    if(b <= n) {
      System.out.println(a * (b-1) / b);
    } else {
      System.out.println(a * n / b);
    }
  }
}


Measured memory_bytes: 27088
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <tuple>

using namespace std;
mt19937_64 rng(58);

typedef long long ll;

int try_choose(ll abc[3], int x, int y) {
    if (abc[x] == 0 && abc[y] == 0) return -1;
    if (abc[x] == 0) return x;
    if (abc[y] == 0) return y;
    if (abc[x] == 1 && abc[y] == 1) {

    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    ll abc[3] = {0, 0, 0};
    vector<pair<int, int>> query;
    vector<ll> ans;
    cin >> n >> abc[0] >> abc[1] >> abc[2];
    int sum = abc[0] + abc[1] + abc[2];
    try {
        if (sum == 0) throw -1;
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
            if (s == "AB") {
                query.emplace_back(0, 1);
            } else if (s == "BC") {
                query.emplace_back(1, 2);
            } else { // AC
                query.emplace_back(0, 2);
            }
        }
        for (int i = 0; i < n; i++) {
            auto op = query[i];
            if (abc[op.first] == 0 && abc[op.second] == 0) throw -1;
            if (abc[op.first] == 0) {
                ans.push_back(op.first);
                abc[op.first]++;
                abc[op.second]--;
            } else if (abc[op.second] == 0) {
                ans.push_back(op.second);
                abc[op.first]--;
                abc[op.second]++;
            } else if (abc[op.first] == 1 && abc[op.second] == 1) {
                // try first
                if (i == n - 1) {
                    ans.push_back(op.first);
                } else {
                    auto nop = query[i + 1];
                    // choose op.first
                    if (nop.first == op.first || nop.second == op.first) {
                        ans.push_back(op.first);
                        abc[op.first]++;
                        abc[op.second]--;
                    } else {
                        ans.push_back(op.second);
                        abc[op.first]--;
                        abc[op.second]++;
                    }
                }
            } else {
                int c = abc[op.first] > abc[op.second] ? op.second : op.first;
                ans.push_back(c);
                abc[c]++;
                abc[op.first + op.second - c]--;
            }
        }
        cout << "Yes" << endl;
        for (auto c: ans) {
            char *v = "ABC";
            cout << v[c] << endl;
        }
    } catch (int e) {
        cout << "No" << endl;
    }


}

Measured memory_bytes: 5228
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(min(b, d) - max(a, c), 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int iNum;
	int iNum2;
	int iNum3;
	iNum = 0;
	iNum2 = 0;
	iNum3 = 0;

	scanf("%d %d %d",&iNum,&iNum2,&iNum3);

	if (iNum < iNum2 && iNum2 < iNum3)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2104
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func sel(a []int, u []bool, n int) []int {
	x := make([]int, 0)
	sum := 0
	idx := 0
	for sum != n/3 {
		if u[idx] != true && sum+a[idx] <= n/3 {
			sum += a[idx]
			x = append(x, a[idx])
			u[idx] = true
		}
		idx++
	}
	return x
}

func solve(N int) {
	g := make([][2]int, N/2)
	total := 0
	for i := 0; i < N/2; i++ {
		g[i][0] = i + 1
		g[i][1] = N - i
		total += i
	}
	out(total * 4)
	// out(g)
	len := N / 2
	for i := 0; i < len-1; i++ {
		for j := i + 1; j < len; j++ {
			out(g[i][0], g[j][0])
			out(g[i][0], g[j][1])
			out(g[i][1], g[j][0])
			out(g[i][1], g[j][1])
		}
	}
}

type ij struct {
	i, j int
}

func solveOdd(N int) {
	n := N/2 + 1
	g := make([][]int, n)
	a := make([]int, N)
	u := make([]bool, N)
	for i := 0; i < N; i++ {
		a[i] = N - i
	}
	// out(a)
	for i := 0; i < n; i++ {
		sum := 0
		idx := 0
		for sum != N {
			// out(a[idx], sum)
			if u[idx] != true && sum+a[idx] <= N {
				sum += a[idx]
				u[idx] = true
				g[i] = append(g[i], a[idx])
			}
			idx++
		}
	}

	cnt := 0
	ans := make([]ij, 0)
	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			for _, xx := range g[i] {
				for _, yy := range g[j] {
					ans = append(ans, ij{xx, yy})
					cnt++
				}
			}
		}
	}

	out(cnt)
	for _, v := range ans {
		out(v.i, v.j)
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()

	if N == 3 {
		out(2)
		out(1, 3)
		out(2, 3)
		return
	}

	if N%2 == 0 {
		solve(N)
		return
	}

	solveOdd(N)

}


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

#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
//typedef long long ll;
ll  D, G, H, N,M, L, K, P, Q, R, W, X, Y, Z;

signed main(){
    ll flag2=0;
    ll costmin=-1;
    ll cost=0;
	std::cin >> N>>M>>X;
	vector<vector<int>> A(N, vector<int>(M));
	vector<int> B(M);
	for(ll j=0;j<M;j++){
            B[j]=0;
    }
	for(ll i=0;i<N;i++){
	    std::cin >> A[i][M];
	    for(ll j=0;j<M;j++){
	        std::cin >> A[i][j];
	    }
	}
    // {0, 1, ..., n-1} の部分集合の全探索
    for (ll bit = 0; bit < (1<<N); ++bit) {
        for (ll i = 0; i < N; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                cost+=A[i][M];
                for(ll j=0;j<M;j++)B[j]+=A[i][j];
            }
        }
        for(ll j=0;j<M;j++){
            if(B[j]<X) {flag2++;}
            B[j]=0;
        }
        if (flag2>0){flag2=0;cost=0;}
        else if (costmin==-1){costmin = cost; cost=0;}
        else if (costmin>cost){costmin = cost; cost=0;}
        else {cost=0;}
    }
    std::cout << costmin << std::endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
        ios::sync_with_stdio(false);
        cin.tie(0);
        int h, w;
        while (cin >> h >> w)
        {
                int mapn[105][105], a[10005];
                memset(mapn, 0, sizeof(mapn));
                memset(a, 0, sizeof(a));
                int n;
                cin >> n;
                for (int i = 0; i < n; i++)
                {
                        int t;
                        cin >> t;
                        a[i] = t;
                }
                int t1 = 1, t2 = 1, t3 = 0;
                for (int i = 0; i < n; i++)
                {
                        t3++;
                        for (int j = 1; j <= a[i]; j++)
                        {
                                mapn[t1][t2] = t3;
                                t2++;
                                if (t2 == w + 1)
                                {
                                        t1++;
                                        t2 = 1;
                                }
                        }
                }
                for (int i = 2; i <= h; i += 2)
                {
                        for (int j = 1; j <= w / 2; j++)
                        {
                                swap(mapn[i][j], mapn[i][w - j + 1]);
                        }
                }
                for (int i = 1; i <= h; i++)
                {
                        for (int j = 1; j <= w; j++)
                        {
                                if (j == w)
                                {
                                        printf("%d\n", mapn[i][j]);
                                }
                                else
                                {
                                        printf("%d ", mapn[i][j]);
                                }
                        }
                }
        }
        return 0;
}


Measured memory_bytes: 384
import sys


# input = sys.stdin.readline

def main():
    N = int(input())
    d = list(map(int,input().split()))
    ans = 0
    for i in range(N):
        for j in range(N):
            if i !=j:
                ans += d[i]*d[j]



    print(int(ans/2))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9128
#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<int> to[100005];
const int INF =1001001001;

int main() {
int n,f;
cin>>n>>f;
n++;
int ans=0;
rep(i,n){
  rep(j,n){
    if(10000*i+5000*j+(n-j-i-1)*1000==f&&n-j-i-1>=0){
      cout<<i<<" "<<j<<" "<<n-j-i-1<<endl;
      return 0;
    }
  }
}
cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 2560
import java.io.File;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args){
        // write your code here
            Scanner scan = new Scanner(System.in);
            int index = scan.nextInt();
            int[] arr = new int[index];
            for(int i = 0; i<index;i++){
                arr[i] = scan.nextInt();
            }

            for(int i = 0; i<index;i++){
                int key = arr[i];
                int j = i-1;
                while(j>=0 && arr[j]>key){
                    arr[j+1] = arr[j];
                    j--;
                }
                arr[j+1] = key;
                for(int k = 0; k<index;k++){
                    System.out.print(arr[k]);
                    if(k!=index-1)System.out.print(" ");
                }
                System.out.print("\n");
            }
    }
}

Measured memory_bytes: 34060
a,b,h,m=map(int, input().split())
import math
b_angle=math.pi*(m*6/180)
a_angle=math.pi*((h+m/60)*30/180)
angle=abs(b_angle-a_angle)

if h==0 and m==0:
    print(abs(b-a))
elif angle==3.14159265359:
    print(a+b)
elif angle>0:
#print(angle/math.pi*90)
    c=(a**2+b**2-2*a*b*math.cos(angle))**0.5
    print(c)

Measured memory_bytes: 62592
#include<bits/stdc++.h>
#define li long long int
#define pb push_back
using namespace std;
int main(){
li n , x;
cin>>n>>x;
vector<li>l(n) , d(n+1);
d[0] = 0;
for(int i=0;i<n;i++){
    cin>>l[i];
}
for(int i= 1; i <= n; i++){
    d[i] = d[i-1]+l[i-1];

}
li count = 0;
for(int i = 0; i <= n; i++){
    if(d[i]<=x)
        count++;
}
cout<<count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    
return 0;
}


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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

typedef long long ll;
typedef pair<int, int> P;

int main(){
  int r;
  
  cin >> r;
  
  cout << r * r;
  
  
  return 0;
}


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

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

    

    return 0;
}


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

const long long INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  
 for(int i=0;i<S.size();i++){
   if(i%2 == 1){
     if(S.at(i) != 'L' && S.at(i) != 'U' && S.at(i) != 'D'){
       cout << "No" <<endl;
       break;
     }
   }
   else
     if(S.at(i) != 'R' && S.at(i) != 'U' && S.at(i) != 'D'){
       cout << "No" << endl;
       break;
     }
   if(i == S.size()-1)
     cout << "Yes" <<endl;
 }
  
}



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

using namespace std;

int main(int argc,char* argv[]){
  int N,H,max=0,count=0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> H;
    if(H>=max){
      max = H;
      count++;
    }
  }
  cout << count << endl;

  return 0;
}


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

int main() {
    int N, K;
    std::map<int,int> snuke;

    cin >> N >> K;

    for (int i=0; i < K; i++) {
        int d;
        cin >> d;

        for (int j=0; j < d; j++) {
            int tmp;
            cin >> tmp;
            snuke[tmp-1]++;
        }
    }

    int ans = 0;
    for (int i=0; i < N; i++) {
        if (snuke[i] == 0) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define prin(a) cout<<a<<"\n"
#define kaigyo cout<<"\n"
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define SORT(V) sort(ALL(V))
#define REV(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REV(V)

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<string> vst;
typedef vector<char> vc;
typedef vector<long double> vd;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
typedef vector<vector<int>> vint2;
ll mod=1e9+7;

const double pi=acos(-1.0);
const ll inf=1LL<<60;
ll gcd(ll p,ll q){if(q==0)return p;return gcd(q,p%q);}  
ll lcm(ll p,ll q){return (p*q)/gcd(p,q);}
ll kaizyo(ll k){ll sum=1;rep1(i,k){sum*=i;sum%=mod;}return sum;}
ll ncr(ll n,ll r){return kaizyo(n)/(kaizyo(r)*kaizyo(n-r));}


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


rep1(i,5){
    int n;cin>>n;
    if(n==0)prin(i);
}
return 0;
}



Measured memory_bytes: 3564
#include <iostream>
#include <map>

using namespace std;

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

    map<long long, int> mp;
    long long a, ans = 0, sum = 0;
    ++mp[0];
    for (int i = 0; i < n; ++i) {
        cin >> a;
        sum += a;
        ans += mp[sum];
        ++mp[sum];
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;

void main() {
    int n = readln.chomp.to!int;

    for (int i = 0; i < n; i++) {
        string X = readln.chomp;
        string Y = readln.chomp;
        lcs(X, Y).writeln;
    }
}

int lcs(string x, string y) {
    int[][] dp = new int[][](y.length + 1, x.length + 1);
    for (int i = 1; i <= y.length; i++) {
        for (int j = 1; j <= x.length; j++) {
            if (x[j - 1] == y[i - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    return dp[$ - 1][$ - 1];
}

Measured memory_bytes: 7052
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = nm[0];
        int m = nm[1];

        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < m; i++)
        {
            int[] tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            l[i] = tmp[0];
            r[i] = tmp[1];

        }

        var ans = 0;
        if (l.Max() <= r.Min())
        {
            ans = r.Min() - l.Max() + 1;
        }

        Console.WriteLine(ans);

    }
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int>v(n);
    for(int i=0;i<n;i++) cin >> v[i];

    //A,B全探索
    int ans = 0;
    int suma = 0;
    vector<int>veca;
    for(int a=0;a<=min(n ,k);a++){//左からa個とる
        vector<int>vecb;
        if(a > 0){
            veca.push_back(v[a-1]);
            suma += v[a-1];
        }
        int sumb = 0;


        for(int b=0;a+b<=min(n,k);b++){//右からb個とる
            if(b > 0){
                vecb.push_back(v[n-b]);
                sumb += v[n-b];
            }
            if(veca.size() > 0){
                sort(veca.begin() ,veca.end());
            }if(vecb.size() > 0){
                sort(vecb.begin() ,vecb.end());
            }
            /*for(auto i :veca) cout << i << " ";
            cout << endl;
            for(auto i :vecb) cout << i << " ";
            cout << endl;*/

            int tmp = 0;
            int isum = suma + sumb;
            for(int i=0; tmp < k-(a+b) ;i++){
                if(i >= veca.size() && i >= vecb.size()) break;
                if(i >= veca.size()){
                    if(vecb[i] < 0) {
                    isum -= vecb[i];
                    tmp++;
                    }continue;
                }if(i >= vecb.size()){
                    if(veca[i] < 0) {
                    isum -= veca[i];
                    tmp++;
                    }continue;
                }

                if(veca[i] >= 0 && vecb[i] >= 0) break;
                if(tmp == k-(a+b)-1){
                    if(veca[i] < 0 && vecb[i] < 0){
                        isum -= min(veca[i] ,vecb[i]);
                        break;
                    }
                }

                if(veca[i] < 0) {
                    isum -= veca[i];
                    tmp++;
                }if(vecb[i] < 0) {
                    isum -= vecb[i];
                    tmp++;
                }
            }//cout << isum << endl;
            ans = max(ans ,isum);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> a;
  a *= 2;
  double aa;
  aa = (double)a * M_PI;
  doublecout(aa);
  return 0;
}


Measured memory_bytes: 3844
#include<stdio.h>
int main(){
  int shain, i, tmp;
  scanf("%d",&shain);
  int buka[shain];
  int hoge_len = sizeof(buka) / sizeof(buka[0]);
    for (int i = 0; i < hoge_len; i++) {
        buka[i] = 0;
    }
  
  for(i = 0; i<shain-1; i++){
    tmp = 0;
    scanf("%d",&tmp);
    buka[tmp-1] += 1;
  }
 
  for(i=0;i<shain;i++){
    printf("%d\n", buka[i]);
  }
 
  return 0;
 
}

Measured memory_bytes: 2504
n= int(input())
v=[]
def area(u,w):
    ans = (u[0]*w[1]-u[1]*w[0])/2 
    return ans

def sb(u,w):
    ans = [u[0]-w[0],u[1]-w[1]]
    return ans

for _ in range(n):
    x,y=map(int,input().split( ))
    v.append([x,y])
ans = 0    
for i in range(1,n-1):
    u = sb(v[i],v[0])
    w = sb(v[i+1],v[0])
    ans += area(u,w)
print(abs(ans))


Measured memory_bytes: 5616
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if (S == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}

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

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

int main() {
    int n, m;
    cin >> n >> m;
    unordered_map<long long int, int> mp;
    vector<pair<long long int, int>> pa;
    int p;
    long long int y;

    rep(i, m) {
        cin >> p >> y;
        mp[y] = i;
        pa.push_back(make_pair(y, p));
    }

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

    vector<int> cnt(n + 1, 1);
    vector<pair<int, int>> result(m);

    for (int i = 0; i < pa.size(); i++){
        result[mp[pa[i].first]] = make_pair(pa[i].second, cnt[pa[i].second]);
        cnt[pa[i].second]++;
    }

    for (int i = 0; i < result.size(); i++) {
        printf("%06d%06d\n", result[i].first, result[i].second);
    }
}

Measured memory_bytes: 8340