akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {

  public static void main(String[] args) {
   Scanner no=new Scanner(System.in);
   StringBuilder sb=new StringBuilder();
   int n=no.nextInt();
   int m=no.nextInt();
   int min=0;
   int arr[]=new int[10];
   for(int i=0;i<m;i++){
     arr[no.nextInt()]++;
   }
   int j=n;
   int u=j;
   for(j=n;j<100000;j++){
    //System.out.println(j);
    u=j;
     while(u!=0){
       if(arr[u%10]>0){
         break;
       }
       else{
         //System.out.println("h");
         u=u/10;
       }
     }
     if(u==0){
       break;
     }
   }
   if(u==0){
     System.out.println(j);
   }
  }

}

Measured memory_bytes: 35828
import java.util.*;
public class Main{
public static void main(String[]a){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int s[]=new int[m];
for(int i=0;i<m;i++)s[i]=sc.nextInt();
boolean check=false;
while(!check){
check=true;
String p=n+"";
String ss[]=p.split("",0);
for(int i=0;i<ss.length;i++){
for(int j=0;j<m;j++){
if(ss[i].equals(s[j]+"")){n++;check=false;break;}
}if(!check){break;}
}}
System.out.println(n);

}
}

Measured memory_bytes: 59512
#include<stdio.h>
int main(){
  int n,i,j,f,d[12],e[12];
  while(scanf("%d",&n),n){
    for(i=0;i<n;i++)scanf("%d",&d[i]);
    for(i=0;1;i++){
      int b[100]={0};
      for(j=0;j<n;j++)b[d[j]]++;
      for(j=0;j<n;j++)e[j]=b[d[j]];
      for(j=f=0;j<n;j++){
	if(e[j]-d[j])f=1;
	d[j]=e[j];
      }
      if(!f)break;
    }
    printf("%d\n",i);
    for(i=0;i<n;i++){
      if(i)printf(" ");
      printf("%d",d[i]);
    }
    printf("\n");
  }
  return 0;
}
  

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
priority_queue<double>que;
int main(){
	cin>>n;
	rep(i,n){
		double a;cin>>a; que.push(-a);
	}
	while(que.size() >= 2){
		double s = 0;
		s += que.top(); que.pop();
		s += que.top(); que.pop();
		que.push(s/2.0);
	}
	printf("%.12f\n",-que.top());

}

Measured memory_bytes: 256
#include <stdio.h>

int F[100];

int fibonacci(int n){

	if(n == 0 || n == 1) return F[n] = 1;
    if(F[n] != -1) return F[n];
	F[n] = fibonacci(n-2) + fibonacci(n-1);
	return F[n];
}



int main(void){

	int n,i;
	for(i=0;i<100;i++){ 
		F[i] = -1;
	}
	
	scanf("%d",&n);
	printf("%d\n",fibonacci(n));

return 0;

}



Measured memory_bytes: 2088
#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<pair<int,int> , null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update> 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
#define fdt fuck donald trump
// mt19937 rnd(time(0));
// const int SMALL = LLONG_MIN >> 2;
// const int BIG = LLONG_MAX >> 2;
const int MAXN = (int)2e5 + 3;
const int MOD = 998244353;

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
	// freopen("FDT.txt","r",stdin);
	int n, k;
	cin >> k >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i ++)
		cin >> a[i];
	int dist = 0;
	for(int i = 0; i < n - 1; i ++)
		dist = max(dist, a[i + 1] - a[i]);
	dist = max(dist, a[0] + k - a[n - 1]);
	cout << k - dist;
}


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

saitei = 0
saidai = N

for i in range(M):
    L, R = map(int, input().split())
    saitei = max(saitei, L)
    saidai = min(saidai, R)

print(max(saidai-saitei+1, 0))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
int main(){
    int a,b,c;
    ll k;
    cin>>a>>b>>c;
    cin>>k;
    if(k%2) cout << b-a << endl;
    else  cout << (a-b) << endl;
    return 0;
}



Measured memory_bytes: 256
# C
N = int(input())
A = list(map(int,input().split()))
mi = min(A)
ma = max(A)
ans = 10 ** 12
for i in range(mi,ma+1):
    su = 0
    for j in A:
        su += (i-j)**2
    ans = min(ans,su)
print(ans)

Measured memory_bytes: 38896
def junkan(x):
    if x == 1:
        return 1
    one = 1
    one *= 10
    for cnt in range(1000001):
        d, m = divmod(one, x)
        if m == 1:
            break
        elif d == 0:
            one *= 10
        else:
            one = m
            one *= 10
        
    return cnt+1

if __name__ == "__main__":
    K = int(input())
    flag = True

    if K%2 == 0 or K%5 == 0:
        flag = False
        print(-1)
    elif K%7 == 0:
        K = K//7
    K = K*9
        
    if flag:
        print(junkan(K))


Measured memory_bytes: 9088
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int m;
int dist[N];
char str[N];
int parent[N];

int main(){
    cin >> n >> m;
    for(int i = 0; i <= n; i++){
        cin >> str[i];
    }
    int me = n;
    while(me != 0){
        int will = -1;
        for(int i = me-1; i >= me - m && i >= 0; i--){
            if(str[i] == '0'){
                will = i;
            }
        }
        if(will == -1){
            puts("-1");
            return 0;
        }
        dist[will] = me - will;
        parent[will] = me;
        me = will;
    }
    int j = 0;
    while(j != n){
        printf("%d " , dist[j]);
        j = parent[j];
    }
}

Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int a[6];
string s;
void C(int i,int j,int k,int l){
    int t;t=a[i];a[i]=a[j];a[j]=a[k];a[k]=a[l];a[l]=t;
}
int main(){
    for(int i=0;i<6;i++)cin>>a[i];
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='E')for(int j=0;j<3;j++)C(0,2,5,3);
        if(s[i]=='W')C(0,2,5,3);
        if(s[i]=='S')for(int j=0;j<3;j++)C(0,1,5,4);
        if(s[i]=='N')C(0,1,5,4);
    }
    cout<<a[0]<<endl;
    return 0;
}


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

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    string s,t; cin>>s>>t; int sl=s.size(),tl=t.size();
    if(sl<tl)cout<<"UNRESTORABLE"<<'\n';
    else{
        bool flag=false;
        for (int i = sl-tl; i >= 0; i--){
            bool key=true;
            for (int j = 0; j < tl; j++)key&=(s[i+j]==t[j]||s[i+j]=='?');
            if(key){
                for (int j = 0; j < tl; j++)s[i+j]=t[j];
                flag=true; break;
            }
        }
        if(flag){
            for (int i = 0; i < sl; i++){
                if(s[i]=='?')s[i]='a';
            }
        }
        cout<<(flag?s:"UNRESTORABLE")<<'\n';
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define MAX 500000
#define SENTINEL 2000000000
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    rep(i, n1) L[i] = A[left + i];
    rep(i, n2) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for(int k = left; k < right; k++) {
        cnt++;
        if(L[i] <= R[j]) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(int A[], int n, int left, int right) {
    if(left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

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

    int A[MAX], n, i;
    cnt = 0;

    cin >> n;
    rep(i, n) cin >> A[i];

    mergeSort(A, n, 0, n);

    rep(i, n) {
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << cnt << endl;

    return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
    ll w, h, x, y; cin >> w >> h >> x >> y;
    cout << fixed <<setprecision(12) << (long double)0.5 * h * w << " "; 

    if(w % 2 == 0 && h % 2 == 0 && x == w / 2 && y == h / 2) {
        cout << 1 << endl;
    } else  {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数 __builtin_popcount bitの個数

int main() {
  int N;
  ci(N);
  if(N < 1000){
    co("ABC");
  }
  else{
    co("ABD");
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char l[15]={'q','w','e','r','t','a','s','d','f','g','z','x','c','v','b'};
char r[11]={'y','u','i','o','p','h','j','k','l','n','m'};
bool flag;
int cnt;
void judge(char s){
    if(!flag){
        for(int i=0;i<15;i++){
            if(l[i]==s){
                cnt++;
                flag=true;
                //cout<<s;
                break;
            }
        }
    }
    else{
        for(int i=0;i<11;i++){
            if(r[i]==s){
                cnt++;
                flag=false;
                //cout<<s;
                break;
            }
        }
    }
}
int main(){
    while(1){
        string s;
        cin>>s;
        if(s[0]=='#'){break;}
        cnt=0;
        flag=false;
        for(int i=0;i<15;i++){
            if(l[i]==s[0]){
                flag=true;
            }
        }
        for(int i=0;i<s.size();i++){
            judge(s[i]);
        }
        cout<<cnt<<endl;
    }
}



Measured memory_bytes: 3168
K = input()
D = int(input())

MOD = 10**9+7
N = len(K)

# dp[i][j][k] := 上から i まで見て余りが j であり、
# k = 0 -> K ちょうど
# k = 1 -> K より小さい
# ようなものの数
dp = [[[0]*2 for _ in range(D)] for _ in range(N+1)] 
dp[0][0][0] = 1
for i in range(N):
    k = int(K[i])
    for j in range(D):
        dp[i+1][(j+k)%D][0] = dp[i][j][0]
        dp[i+1][(j+k)%D][0] %= MOD
        for d in range(10):
            dp[i+1][(j+d)%D][1] += dp[i][j][1]
            if d < k:
                dp[i+1][(j+d)%D][1] += dp[i][j][0]
            dp[i+1][(j+d)%D][1] %= MOD

print((dp[N][0][0]+dp[N][0][1]-1)%MOD)

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

int main(){
    int N;
    cin >> N;
    map<string,int> memo;
    int cnt = 0;
    rep(i,N){
        string S;
        cin >> S;
        if(memo[S]==0){
            cnt++;
            memo[S]=1;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 19152
import math
n,d = map(int, input().split())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
a = 0
for i in range(n):
    if math.sqrt(x[i]**2 + y[i]**2 ) <= d:
        a += 1
print(a)

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

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

	vector<int> d(n, 0);
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			int m = j - i;
			m = min(m, abs(x - i) + abs(y - j) + 1);
			++d[m];
		}
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

vector<int> good[15];
vector<int> bad[15];

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

    int N;
    cin >> N;
    rep(i, N) {
        int A;
        cin >> A;
        rep(j, A) {
            int x, y;
            cin >> x >> y;
            --x;
            if (y) {
                good[i].push_back(x);
            } else {
                bad[i].push_back(x);
            }
        }
    }

    int ans = 0;
    rep(i, (1<<(N+1))-1) { 
        bool conflict = false;
        int count = 0; //! count honest bits in i
        rep(j, N) {
            if ((i&(1<<j)) != 0) {
                ++count;
                for (int k: good[j]) {
                    if ((i&(1<<k)) == 0) {
                        conflict = true;
                        break;
                    }
                }
                for (int k: bad[j]) {
                    if ((i&(1<<k)) != 0) {
                        conflict = true;
                        break;
                    }
                }
            }
            if (conflict) break;
        }
        if (!conflict) {
            ans = max(ans, count);
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(vr) vr.begin(),vr.end()
const int N=5e3+10;

struct segment_tree
{
    ll it[N*4],lazy[N*4];

    void down(int id)
    {
        ll tmp=lazy[id];
        lazy[id]=0;
        it[id*2]+=tmp;
        it[id*2+1]+=tmp;
        lazy[id*2]+=tmp;
        lazy[id*2+1]+=tmp;
    }

    void update(int id,int l,int r,int u,int v,ll x)
    {
        if (l>v || r<u) return;
        if (u<=l && r<=v)
        {
            it[id]+=x;
            lazy[id]+=x;
            return;
        }
        int mid=(l+r)/2;
        down(id);
        update(id*2,l,mid,u,v,x);
        update(id*2+1,mid+1,r,u,v,x);
        it[id]=max(it[id*2],it[id*2+1]);
    }

    ll get(int id,int l,int r,int u,int v)
    {
        if (l>v || r<u) return 0;
        if (u<=l && r<=v) return it[id];
        int mid=(l+r)/2;
        down(id);
        return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));
    }
};

int n,m,b[N][210],a[N];

void read()
{
    cin>>n>>m;
    for (int i=1;i<n;i++) cin>>a[i];
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++) cin>>b[i][j];
}

segment_tree seg;
int l[N][210];

void process()
{
    ll ans=0;
    for (int i=1;i<=n;i++)
    {
        if (i>1) seg.update(1,1,n,1,i-1,-a[i-1]);
        for (int j=1;j<=m;j++)
        {
            seg.update(1,1,n,i,i,b[i][j]);
            l[i][j]=i;
            int t=i-1;
            while (t>0)
            {
                if (b[t][j]>=b[i][j]) break;
                seg.update(1,1,n,l[t][j],t,b[i][j]-b[t][j]);
                l[i][j]=l[t][j];
                t=l[i][j]-1;
            }
        }
        ans=max(ans,seg.get(1,1,n,1,i));
    }
    cout<<ans;
}

int main()
{
    //freopen("ss.inp","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    read();
    process();
    return 0;
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

#define MAX 500000
int L[MAX/2 + 2], R[MAX/2 + 2];
int cnt;


signed main()
{   
    gearup;
    string s; cin >> s;
    rep(i,s.size()){
        if(i % 2 == 0){
            if(s[i] != 'U' && s[i] != 'D' && s[i] != 'R'){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if(s[i] != 'U' && s[i] != 'D' && s[i] != 'L'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	q := nextInt()
	scores := make([]int, n)
	for i := 0; i < q; i++ {
		scores[nextInt()-1]++
	}
	for i := 0; i < n; i++ {
		if score := k - q + scores[i]; score > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 3968
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
p = get_nums_l()

ans = 0
for i in range(n-2):
    if p[i] > p[i+1] > p[i+2] or p[i] < p[i+1] < p[i+2]:
        ans += 1

print(ans)

Measured memory_bytes: 38384
// AOJ 1195: Encryption System
// 2017.12.8 bal4u@uu

#include <stdio.h>
#include <string.h>

int n;
char ans[50000][22];
char f['z'+1];
char buf[22], tmp[22], *p;

void rec(char *p, char *s)
{
	int t;
	char c;

	c = *p++;
	if (c < 'a') {
		memcpy(ans[n], tmp, s-tmp), ans[n++][s-tmp] = 0;
		return;
	}

	if (f[c] || c == 'a') {
		t = f[c];
		f[c] = 1;
		*s = c;
		rec(p, s+1);
		f[c] = t;
	}
	if (!f[c+1] && c != 'z') {
		t = f[c+1];
		f[c+1] = 1;
		*s = c+1;
		rec(p, s+1);
		f[c+1] = t;
	}
}

int main()
{
	int i;

	while (fgets(p=buf, 22, stdin) && *p != '#') {
		memset(f, 0, sizeof(f));
		n = 0;
		rec(p, tmp);
		printf("%d\n", n);

		if (n <= 10) {
			for (i = 0; i < n; i++) puts(ans[i]);
		} else {
			for (i = 0; i < 5; i++) puts(ans[i]);
			for (i = n-5; i < n; i++) puts(ans[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 2172
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)


int main()
{
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif // LOCAL
	char s[1005];
	int w;
	scanf("%s", s);
	scanf("%d", &w);
	string str;
	int len = strlen(s);
	for (int i = 0; i < len; ++i) {
		if (i % w == 0) {
			str += s[i];
		}
	}
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int w, h, x, y, r;
    
    scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);
    
    if(x-r < 0 || y-r < 0 || x+r > w || y+r > h){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }
    
    return 0;
}

Measured memory_bytes: 580
/*  
    Come feed the rain
	Cos I'm thirsty for your love
	Dancing underneath the skies of lust
	Yeah feed the rain...
	Cos without your love my life
	Ain't nothing but this carnival of rust
    _________________________
    _________________________
    840 Hours of Solitude
    Quarantine_Day : 35
*/

#include<bits/stdc++.h>

using namespace std;

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

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 50005
#define MOD 1000000007

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string a, b;
	cin>>a>>b;

	int n = min((int)a.size(), (int)b.size());
	int m = max((int)a.size(), (int)b.size());

	REP(i, n) cout<<a[i]<<b[i];

	if(a.size() > b.size()){
		for(int i = n; i < a.size(); i++){
			cout<<a[i];
		}
	}
	else if(b.size() > a.size()){
		for(int i = n; i < b.size(); i++){
			cout<<b[i];
		}
	}
	cout<<"\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);std::cout<<std::fixed<<std::setprecision(10);
    string S;
    cin >> S;
    if(S == "Sunny"){
        cout << "Cloudy"<< "\n";
    }else if(S == "Cloudy"){
        cout << "Rainy"<< "\n";
    }else{
        cout << "Sunny"<< "\n";
    }
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {

	ll a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b));
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		boolean[] d = new boolean[10];
		Arrays.fill(d, true);
		for (int i = 0; i < k; i++)
			d[Integer.parseInt(sc.next())] = false;;
		while (true) {
			int m = n;
			boolean able = true;
			while (m > 0) {
				if (!d[m % 10]) {
					able = false;
					break;
				}
				m /= 10;
			}
			if (able) {
				System.out.println(n);
				return;
			}
			n++;
		}
	}
}

Measured memory_bytes: 22608
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n;
    cin>>n;
    bool ok = true;
    vector< pair<int,int> > p;
    rep(i,0,n){
        int a,b;
        cin>>a>>b;
        p.pb(mp(b,a));
    }
    sort(all(p));
    int ss = 0;
    rep(i,0,p.size()){
        ss += (p[i].sd);
        if ( ss > p[i].ft ){
            ok = false;
            break;
        }
    }
    cout<<((ok)?"Yes":"No")<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 6512
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

int main(){
  ll n; cin >> n;
  vector<ll> a(n);
  ll sum=0;
  rep(i,n){
    cin >> a[i];
    sum+=a[i];
  }
  if(sum%(n*(n+1)/2)){
    cout << "NO" << endl;
    return 0;
  }
  ll sousa=sum/(n*(n+1)/2);
  vector<ll> tol(n);
  rep(i,n) tol[i]=a[i]-a[(i-1+n)%n]-sousa;
  rep(i,n){
    if(tol[i]%n||tol[i]>0){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 4848
N = gets.to_i
xy = []
N.times { |i| xy << gets.split.map(&:to_i) }

xyc = Hash.new(0)
N.times do |i|
  xi, yi = xy[i]
  i.upto(N-1) do |j|
    next if i == j
    xj, yj = xy[j]
    xyc[ [xi-xj, yi-yj] ] += 1
    xyc[ [xj-xi, yj-yi] ] += 1
  end
end

if N == 1
  puts 1
else
  puts N - xyc.sort_by { |k, v| -v }.first[1]
end

Measured memory_bytes: 2044
x, y= map(int, input().split())
s=[list(map(int,list(input().split()))) for i in range(x)]
k= list(s)
k.sort()
a=0
t=0
for i in range(x):
	if y-a>=k[i][1]:
		t=t+k[i][0]*k[i][1]
		a=a+k[i][1]
	else:
		t=t+((y-a)*k[i][0])
		a=y
print(t)

Measured memory_bytes: 28588
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  cout << a[0] + a[1] << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    from fractions import gcd
    ans = A[0]
    for i in range(1,N):
        ans = gcd(ans,A[i])
        
    print(ans)
    
    
    
    
main()

Measured memory_bytes: 77844
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;
 
string s;
int dp[200050];
pair<char,int>dp2[200020];
vector<vector<int> > calcNext(const string &S) {
    int n = (int)S.size();
    vector<vector<int> > res(n+1, vector<int>(26, n));
    for (int i = n-1; i >= 0; --i) {
        for (int j = 0; j < 26; ++j) res[i][j] = res[i+1][j];
        res[i][S[i]-'a'] = i;
    }
    return res;
}

signed main() {
    IOS();
    cin>>s;
    int N=s.size();
    auto nx=calcNext(s);
    
    rep(i,0,200050)dp[i]=INF;
    dp[N]=1;
    rrep(i,0,N){
        rep(j,0,26){
            if(nx[i][j]==N){
                if(dp[i]>1){
                    dp[i]=1;
                    dp2[i]={'a'+j,N};
                }
            }else{
                if(dp[i]>dp[nx[i][j]+1]+1){
                    dp[i]=dp[nx[i][j]+1]+1;
                    dp2[i]={'a'+j,nx[i][j]+1};
                }
            }
        }
    }
    
    string ans="";
    int now=0;
    while(now!=N){
        auto e=dp2[now];
        ans+=e.fi;
        now=e.se;
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 53652
#include <stdio.h>

int main( int argc, char *argv[] )
{
    int n;

    scanf( "%d", &n );

    switch( n % 10 ) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            puts( "hon" ) ;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            puts( "pon" ) ;
            break;
        case 3:
            puts( "bon" ) ;
            break;
    }

    return( 0 );
}


Measured memory_bytes: 1660
#include<stdio.h>
#include<math.h>
int main()
{
    int n,i;
    int a[32]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    scanf("%d",&n);
    printf("%d",a[n-1]);
    return 0;
}


Measured memory_bytes: 128
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools,pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = LI()

"""
全数字を例えば1に変える場合など、試していけば良い
"""

ans = []
for i in range(min(A), max(A)+1):
    tmp = 0
    for a in A:
        tmp += abs(a - i) ** 2
    ans.append(tmp)

print(min(ans))



Measured memory_bytes: 78444
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 2020;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
std::string s0, s1;
int left[maxn], right[maxn];
int n;
inline int go(const std::vector<int>&v) {
	int max = n, min = n;
	for(int i = 1;i < v.size();++i) {
		if(v[i] > max) max = v[i];
		if(v[i] < min) min = v[i];
	}
	return std::min(std::abs(min - n) + std::abs(max - v[0]), std::abs(max - n) + std::abs(min - v[0])) + max - min;
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> s0 >> s1;
	if(!std::count(s1.begin(), s1.end(), 49)) {
		cout << (s0 == s1 ? 0 : -1) << '\n';
		return 0;
	}
	s1 = s1 + s1 + s1, n = s0.size();
	int ans = 1e9;
	rep(i, 0, n - 1) {
		int & l = left[i] = n, & r = right[i] = n;
		for(;s1[l + i] == '0';) --l;
		for(;s1[r + i] == '0';) ++r;
	}
	rep(endpos, 0, n + n - 1) {
		std::vector<std::pair<int, int>> vc;
		rep(i, 0, n - 1) if(s0[i] != s1[i + endpos]) {
			vc.emplace_back(left[i], right[i]);
		}
		std::sort(vc.begin(), vc.end());
		int max = -1e8, min = 1e8;
		if(vc.empty()) {
			ans = std::min(ans, std::abs(n - endpos));
			continue;
		}
		ans = std::min<int>(ans, go({endpos, vc.begin() -> first, vc.rbegin() -> first}) + vc.size());
		for(int i = 0;i < vc.size();++i) {
			ans = std::min<int>(ans, go({endpos, min, max, vc[i].first, vc.back().first}) + vc.size());
			max = std::max(max, vc[i].second);
			min = std::min(min, vc[i].second);
		}
		ans = std::min<int>(ans, go({endpos, min, max}) + vc.size());
	}
	cout << ans << '\n';
}


Measured memory_bytes: 384
#include <iostream>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
using namespace std;
int main(void){
    int k; cin>>k;
    long int a[100001];
    ROF(i,0,k) cin>>a[i];
    long int x=2,y=3;
    bool fl=true;
    FOR(i,0,k){
        x=((x-1)/a[i]+1)*a[i];
        y=((y-1)/a[i]+1)*a[i];
        if(x>=y) fl=false;
    }
    if(fl) cout<<x<<" "<<y-1<<endl;
    else cout<<-1<<endl;
}


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

A = list(map(int,input().split()))
s = 0
for i,a in enumerate(A):
    if i%2:
        s -= a
    else:
        s += a

ans = [-1 for i in range(N)]
ans[0] = s

for i in range(1,N):
    ans[i] = (A[i-1]-ans[i-1]//2)*2
print(*ans)


Measured memory_bytes: 14028
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
 
#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
int n,t;
  cin >> n >> t;
  int a[n];
  int b[n];
  int ans=10000;
  int c=10000;
  rep(i,n){
    cin >> a[i];
    cin >> b[i];
  }
  rep(j,n){
    if(b[j] <= t){
      ans = min (ans,a[j]);
    }
  }
    if(ans < 10000){
cout << ans;
    } else {
      cout << "TLE";
    }
 return 0;
}


Measured memory_bytes: 256
#define  _USE_MATH_DEFINES

#define  rep(i, n) for(int i = 0; i < n; i++)
#define  repx(i, a, n) for(int i = a; i < n; i++)
#define  loop while(1)
#define  lli long long int
 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <utility>
#include <set>
  
using namespace std;
 
int main() {

  int n;

  loop {
    cin >> n;
    if (n == 0) break;

    vector<int> scores(n, 0);
    int sum = 0;
    int tmp;

    rep (i, n) {
      cin >> tmp;
      scores[i] = tmp;
      sum += tmp;
    }

    double ave = sum / (double)n;
    double var = 0;

    rep (i, n) {
      var += (ave - scores[i]) * (ave - scores[i]);
    }

    printf("%.10lf\n", sqrt(var / n));
  }
  return 0;
}



Measured memory_bytes: 3208
import java.util.Scanner;

public class Main {
	public static void main(String []args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);

		//??°?????????
		while(true){
			//x???????????????
			int x = sc.nextInt();
			//y???????????????
			int y = sc.nextInt();
			//??????????????°??????0?????´???
			if(x == 0 && y == 0){
				break;
			}
			//????????????????°??????????????????????
			if(x < y){
				System.out.println(x + " " + y);
			}else if(x == y){
				System.out.println(x + " " + y);
			}else if(y < x){
				System.out.println(y + " " + x);
			}
		}
	}
}

Measured memory_bytes: 35324
#include<iostream>
using namespace std;
long mod=1e9+7,dp[2][1<<17];
string L;
main()
{
	cin>>L;
	dp[0][0]=1;
	for(int i=0;i<L.size();i++)
	{
		for(int j=0;j<2;j++)
		{
			int lim=j?1:L[i]-'0';
			for(int k=0;k<=lim;k++)
			{
				(dp[j||k<lim][i+1]+=dp[j][i]*(k?2:1))%=mod;
			}
		}
	}
	cout<<(dp[0][L.size()]+dp[1][L.size()])%mod<<endl;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define N 111111
#define M 111111
#define P 10001000
using namespace std;
int T,n,i,AN;char s[N];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(i=2;i<=n;i++)if(s[i]!=s[i-1])AN++;
	printf("%d",AN);
}

Measured memory_bytes: 384
if __name__ == '__main__':
    _ = input()
    n_list = [int(n) for n in input().split()]
    
    p_alice = 0
    p_bob = 0
    i = 0
    for n in sorted(n_list, reverse=True):
        if i%2 == 0:
            p_alice += n
        else:
            p_bob += n
        i += 1

    print(p_alice - p_bob)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
#define mp make_pair
#define x first
#define y second

int h[100003];
vector<int> veki[100003];

int main () {
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		veki[a].push_back(b);
		veki[b].push_back(a);
	}
	int tr;
	int s=0;
	for(int i=1;i<=n;i++){
		tr=1;
		for(int j=0;j<veki[i].size();j++){
			if(h[veki[i][j]]>=h[i]) tr=0;
		}
		s+=tr;
	}
	cout<<s;



return 0;
}



Measured memory_bytes: 9132
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <vector>
using namespace std;
#define ll long long
int main()
{
	int a, b;
	cin >> a >> b;
	int big = max(a, b);
	int small = min(a, b);
	for (int i = 0; i < big; i++)
	{
		cout << small;
	}
	system("pause>0");
	return 0;
}


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

int card[50];
int change1[50],change2[50];
int n,r,p,c;

int main(){

  while(1){
    cin >> n >> r;
    if(n+r==0)
      break;
    
    for(int i=0;i<n;i++)
      card[i]=n-i;
    
    for(int i=0;i<r;i++){
      cin >> p >> c;
      
      for(int j=0;j<p-1;j++)
	change1[j]=card[j];
      for(int j=0;j<c;j++)
	change2[j]=card[p+j-1];
      
      for(int j=0;j<c;j++)
	card[j]=change2[j];
      for(int j=0;j<p-1;j++)
	card[c+j]=change1[j];
    }
    
    cout << card[0] << endl;
    
  }
  return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
 
//keep coding
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define f0(i,n) for(int i=0;i<n;i++) 
#define f1(i,n) for(int i=1;i<=n;i++)
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define pb push_back
#define MP make_pair
#define FF first
#define SS second
#define int long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 
signed main()
{
   // OJ;
    FIO;
int n;
cin >> n;
map<int, int> mp;
int sum = 0;
for(int i=0;i<n;i++)
{
int x;
cin >> x;
sum += x;
mp[x]++;
}
int q;
cin >>q;
while(q--)
{
int x, y;
cin >> x >> y;
int k = mp[x];
mp[x] = 0;
mp[y]+=k;
sum += k*(y-x);
cout << sum << endl;
}
   
}

Measured memory_bytes: 9496
def submit():
    n, x, y = map(int, input().split())

    count = {i: 0 for i in range(1, n)}
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            # i, j <= X, or Y <= i, j
            if (i <= x and j <= x) or (x <= i and y <= j):
                d = j - i
            
            # X < i, j < Y
            if x < i and j < y:
                d = min(j - i, i - x + 1 + y - j)
            
            # i <= X and X < j < Y
            if i <= x and x < j < y:
                d = min(j - i,
                        x - i + 1 + y - j)            

            # X < i < Y and Y <= j
            if x < i < y and y <= j:
                d = min(j - i,
                        j - y + 1 + i - x)

            if i <= x and y <= j:
                d = min(j - i,
                        x - i + j - y + 1)
            count[d] += 1            
            

    for i in range(1, n):
        print(count[i])

submit()

Measured memory_bytes: 3572
def calc_area(from, to)
  return 1 + (to - from - 1)
end

def merge(each_area, new_area)
  sum = new_area[0]
  each_area.delete_if do |item|
    if item[1] > new_area[1] then
      sum += item[0]
      true
    else
      false
    end
  end
  each_area << [sum, new_area[1]]
end

line = gets.chomp
stack = []
index, each_area, sum_area = 0, [], 0
line.each_char do |c|
  case c
  when '\\'
    stack.push [c, index]
  when '_'
    stack.push [c, index]
  when '/'
    poped = stack.pop
    while (poped != nil && poped[0] != '\\') do 
      poped = stack.pop 
    end
    if poped != nil then
      area = calc_area(poped[1], index)
      sum_area += area 
      merge(each_area, [area, poped[1]])
    end
  end
  index += 1
end

puts sum_area
print ((each_area.size > 0) ? each_area.size.to_s + " " : "0")
puts each_area.sort{|a, b| a[1] <=> b[1]}.map{|a| a[0]}.join(' ')

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

void fff(vector< vector<int> >& x) {
  for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 10; j++) {
      if(j < 9) cout << " " << x.at(i).at(j);
      else cout << " " << x.at(i).at(j) << endl;
    }
  }
  return;
}

int main() {
  int n, b, f, r, v;
  cin >> n;
  vector< vector<int> > room1(3, vector<int>(10, 0)), room2(3, vector<int>(10, 0));
  vector< vector<int> > room3(3, vector<int>(10, 0)), room4(3, vector<int>(10, 0));

  for (int i = 0; i < n; i++) {
    cin >> b >> f >> r >> v;
    if(b == 1) room1.at(f - 1).at(r - 1) += v;
    else if(b == 2) room2.at(f - 1).at(r - 1) += v;
    else if(b == 3) room3.at(f - 1).at(r - 1) += v;
    else if(b == 4) room4.at(f - 1).at(r - 1) += v;
  }
  fff(room1);
  cout << "####################" << endl;
  fff(room2);
  cout << "####################" << endl;
  fff(room3);
  cout << "####################" << endl;
  fff(room4);
}


Measured memory_bytes: 3136
def main():
  n = int(input())
  lst = []
  for _ in range(n):
    word, score = input().split()
    lst.append((word, int(score)))
  mp = ["#" * 6] + ["#" + input() + "#" for _ in range(4)] + ["#" * 6]
  t = int(input())
  
  def search(word):
    used = [[False] * 6 for _ in range(6)]
    vec = ((1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1))
    
    def _search(word, pos, x, y):
      if pos == len(word) - 1:return 1
      used[y][x] = True
      ret = 0
      for dx, dy in vec:
        nx, ny = x + dx, y + dy
        if not used[ny][nx] and mp[ny][nx] == word[pos + 1]:
          ret += _search(word, pos + 1, nx, ny)
      used[y][x] = False
      return ret
    
    ret = 0
    for y in range(1, 5):
      for x in range(1, 5):
        if mp[y][x] == word[0]:ret += _search(word, 0, x, y)  
    return ret
  
  items = []
  for word, score in lst:
    cnt = search(word)
    acc = 1
    weight = len(word)
    while cnt >= acc:
      cnt -= acc
      items.append((score * acc, weight * acc))
      acc *= 2
    if cnt:
      items.append((score * cnt, weight * cnt))
  
  dp = [0] * (t + 1)
  for v, w in items:
    for x in range(t - w, -1, -1):
      if dp[x + w] < dp[x] + v:dp[x + w] = dp[x] + v
  print(max(dp)) 

main()


Measured memory_bytes: 6156
#include <iostream>
#include <stack>
#include <vector>
#include <map>

using namespace std;

void input_field(vector< vector< char > > &field, int w, int h);
int reach_tile_num(vector< vector< char > > &field);
pair< int, int> search_start(vector< vector< char > > &field);

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

int main(){
  int w, h;

  while(cin >> w >> h, w&&h){
    vector< vector< char > >field(h+2, vector< char >(w+2, 0));
    
    input_field(field, w+2, h+2);
    cout << reach_tile_num(field) << endl;
  }
}


void input_field(vector< vector< char > > &field, int w, int h){
  for(int y = 0; y < field.size(); y++){
    for(int x = 0; x < field[y].size(); x++){
      //cout << x << y << endl;
      if(x == 0 || y == 0
         || x == w-1 || y == h-1){
	field[y][x] = '#';
      }else{
	cin >> field[y][x];
      }
    }
  }
  //cout << "input done" << endl;
}

int reach_tile_num(vector< vector< char > > &field){
  int sum = 0;
  pair< int, int > start, cur;
  stack< pair< int, int > > s;

  start = search_start(field);
  s.push(start);

  while(!(s.empty())){
    cur = s.top();
    s.pop();
    if(field[cur.second][cur.first] == '.'
       || field[cur.second][cur.first] == '@'){
      sum++;
      for(int i = 0; i < 4; i++){
        s.push(make_pair(cur.first+dx[i], cur.second+dy[i]));
	field[cur.second][cur.first] = '#';
      }
    }
  }
  return sum;
}

pair< int, int> search_start(vector< vector< char > > &field){
  for(int y = 0; y < field.size(); y++){
    for(int x = 0; x < field[y].size(); x++){
      if(field[y][x] == '@') return make_pair(x,y);
    }
  }
}

Measured memory_bytes: 3076
//
//  respect the past, embrace the future
//

#include  <bits/stdc++.h>
#include  <algorithm>
#include  <iostream>
#include  <climits>
#include  <cstdlib>
#include  <cstring>
#include  <cmath>
#include  <cstdio>
#include  <unordered_map>
#include  <map>
#include  <set>
#include  <stack>
#include  <string>
#include  <vector>
#include  <queue>

using namespace :: std;

using vpll = vector <pair <long long, long long> >;
using pll = pair <long long, long long>;
using vll = vector <long long>;
using ll = long long;

#define N (long long) (2e6 + 7)
#define M (long long) (1e9 + 7)
#define INF (long long) (2e18)
#define F first
#define S second

inline void fastInputOutput () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
}

inline void ReadWriteFromFile () {
  freopen("../in.txt", "r", stdin);
  freopen("../out.txt", "w", stdout);
}

ll n, k, ans, a, b, check[N];
pll p[N];

int32_t main (int argc, char *argv[]) {
  fastInputOutput();
  // ReadWriteFromFile();
  
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a >> b;
    p[i] = {b, a};
  }
  sort (p + 1, p + n + 1);
  for (int i = 1; i <= n; i++) {
    k += p[i].S;
    if(k > p[i].F) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}

Measured memory_bytes: 4352