akhauriyash/Code-Regression huggingface dataset:
def asa(N) :
    li = [0] * 1001
    li[0] = 0
    for i in range(1001) :
        li[i] = li[i-1] + i
    return li[N]
import sys
input = sys.stdin.readline
a,b = [int(i) for i in input().split()]
k = asa(b-a)
print(k-b)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int a, b;
	cin >> a >> b;
	long long int sum = 0;
	for (int i = a; i <= b; i++) {
		string s = to_string(i);
		for (int j = 0; j < s.size(); j++) {
			if (s[j] != s[s.size() - 1 - j]) {
				break;
			}
			if (j == s.size() - 1) {
				sum++;
			}
		}
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int64_t DP[20][50010]; // i番目まででj円払う時の枚数の最小値

void init()
{
  for (int i = 0; i <= 50000; i++)
  {
    DP[0][i] = i;
  }
}

int main()
{
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> C(M);
  for (int i = 0; i < M; i++)
  {
    cin >> C[i];
  }
  sort(C.begin(), C.end());
  init();
  for (int i = 1; i < M; i++)
  {
    for (int j = 0; j <= N; j++)
    {
      DP[i][j] = DP[i - 1][j];
      if (j - C.at(i) >= 0)
      {
        DP[i][j] = min(DP[i][j], DP[i][j - C.at(i)] + 1);
      }
    }
  }
  cout << DP[M - 1][N] << endl;
}



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



int main(){
    int A,B,K;
    cin>>A>>B>>K;
    vector<int> a;

    int size=min(A,B);

    for(int i=1;i<=size;i++){
        if(A%i==0&&B%i==0){
            a.push_back(i);
        }
    }
    reverse(a.begin(),a.end());
    cout<<a[K-1]<<endl;
}



Measured memory_bytes: 256
import sys


def main():
    
    def walk(p, c):
        if visited[p]:
            return
        visited[p] = True
        cnt[p] += c
        for n in tree[p]:
            walk(n, cnt[p])

    sys.setrecursionlimit(1000000)
    rl = sys.stdin.readline

    n, q = [int(x) for x in rl().split()]

    tree = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        a, b = [int(x) for x in rl().split()]
        tree[a].append(b)
        tree[b].append(a)

    cnt = [0] * (n + 1)
    for _ in range(q):
        p, x = [int(x) for x in rl().split()]
        cnt[p] += x

    visited = [False] * (n + 1)
    walk(1, 0)

    print(*cnt[1:])


main()


Measured memory_bytes: 269956
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int p = sc.nextInt();
    int q = sc.nextInt();
    int r = sc.nextInt();
    int ans = Math.min(p+q,q+r);
    ans = Math.min(ans,r+p);
    System.out.println(ans);
  }
}

Measured memory_bytes: 21588
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int g[][] = new int[3][3];
    int a[] = new int[3];
    int b[] = new int[3];
    
    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++){
        g[i][j] = sc.nextInt();
      }
    }
    if((g[0][0] + g[1][1] == g[0][1] + g[1][0])
       && (g[0][1] + g[1][2] == g[0][2] + g[1][1])
       && (g[1][0] + g[2][1] == g[1][1] + g[2][0])
       && (g[1][1] + g[2][2] == g[1][2] + g[2][1])){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

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

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PRINTIA(a,n) REP(i,n){printf("%d ", *((a)+i));}putchar('\n');
#define PN() putchar('\n')
#define MP make_pair
#define PB push_back

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;

void RI() {}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
void PI() {putchar('\n');}
template<typename... T>
void PI(const int head, T... tail ) {
    printf("%d ", head);
    PI(tail...);
}

#define MAX_N 300005

int main()
{
    int a, b, c, cnt = 0;
    RI(a, b, c);
    if(a % 2 != 0 or b % 2 != 0 or c % 2 != 0) {
        PI(0);
        return 0;
    }
    if(a == b and b == c) {
        PI(-1);
        return 0;
    }
    while(true) {
        if(a % 2 != 0 or b % 2 != 0 or c % 2 != 0)
            break;
        int aa = b/2 + c/2;
        int bb = c/2 + a/2;
        int cc = a/2 + b/2;
        a = aa;
        b = bb;
        c = cc;
        cnt++;
    }
    PI(cnt);
    return 0;
}


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

int kiri(int A){
	for(int i=0;i<13;i++){
		if(A>10*i && A<=10*(i+1))return 10*(i+1);
	}
}

int main(){
	int A,B,C,D,E;
	cin>>A>>B>>C>>D>>E;
	int a,b,c,d,e,min=10,judge=5;
	a=A%10;
	if(a>0){
		if(a<min){
			min=a;
			judge=0;
		}
	}
	b=B%10;
	if(b>0){
		if(b<min){
			min=b;
			judge=1;
		}
	}
	c=C%10;
	if(c>0){
		if(c<min){
			min=c;
			judge=2;
		}
	}
	d=D%10;
	if(d>0){
		if(d<min){
			min=d;
			judge=3;
		}
	}
	e=E%10;
	if(e>0){
		if(e<min){
			min=e;
			judge=4;
		}
	}
	int tempA=kiri(A);
	int tempB=kiri(B);
	int tempC=kiri(C);
	int tempD=kiri(D);
	int tempE=kiri(E);
	if(judge==5)cout<<tempA+tempB+tempC+tempD+tempE<<endl;
	if(judge==0)cout<<A+tempB+tempC+tempD+tempE<<endl;
	if(judge==1)cout<<tempA+B+tempC+tempD+tempE<<endl;
	if(judge==2)cout<<tempA+tempB+C+tempD+tempE<<endl;
	if(judge==3)cout<<tempA+tempB+tempC+D+tempE<<endl;
	if(judge==4)cout<<tempA+tempB+tempC+tempD+E<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,Q,ans=0;
  cin >> N;
  vector<ll> A(N),X(100001,0);
  rep(i,N){
    cin >> A.at(i);
    X.at(A.at(i))++;
    ans+=A.at(i);
  }
  cin >> Q;
  rep(i,Q){
    ll b,c;
    cin >> b >> c;
    X.at(c)+=X.at(b);
    ans+=(c-b)*X.at(b);
    X.at(b)=0;
    cout << ans << endl;
  }
  
}


Measured memory_bytes: 4728
n = int(input())
b = list(map(int,input().split()))

result = b[0] + b[-1]
for i in range(len(b)-1):
    c = [b[i],b[i+1]]
    result += min(c)
if n == 3:
    result = b[0]*2 + b[1]

print(result)

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
int main(void){
    int n;
    int i, j;
    scanf("%d", &n);
    int x[8], y[8];
    for(i = 0; i < n; i++){
        scanf("%d%d", &x[i], &y[i]);
    }
    double ans = 0.;
    for(i = 0; i < n; i++){
        for(j = i + 1; j < n; j++){
            ans += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
        }
    }
    int comb = n*(n - 1)/2;
    ans = ans/comb*(n-1);
    printf("%.8lf\n", ans);
}

Measured memory_bytes: 2188
# C
N = int(input())

data = N
if data == 0:
    re = '0'
else:
    re = ''

    while True:
        if data % 2 == 1:
            data -= 1 #data // abs(data) # 1加算・減算
            re = '1' + re
        else:
            if data // -2 != 0:
                re = '0' + re
            else:
                break
        data = data // -2
    
print(re)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f ;
  int maxsu = e*f/100;
  int anssu = 0 ;
  int answa = 0;
  double nodo = 0;
  for(int i = 0; i <= maxsu / c ; i++){
    for(int j = 0; j <= maxsu / d ;j++){
      int su = c*i + d*j;
      for(int k = 0 ; k <= f/(100*a) ; k++){
        for(int l = 0; l <= f /(100*b);l++){
          int wa = k*100*a + l*100*b;
          if( wa == 0){
            break;
          }
          if( su + wa > f){
            break;
          }
          if( (wa*e) < 100* su){
            break;
          }
          if( nodo <= 100.0*su/(su + wa)  ){
            nodo = 100.0*su/(su + wa);
            anssu = su;
            answa = wa;
          }
        }
      }
    }
  }
  cout << anssu + answa << " " << anssu << endl;
}

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

ll f[10010];

int main(){
    ll n;cin>>n;
    rep(x,1,105){
        rep(y,1,105){
            rep(z,1,105){
                ll tmp=x*x+y*y+z*z+x*y+y*z+z*x;
                if(tmp<=10010)f[tmp]++;
            }
        }
    }
    rep(i,1,n+1){
        cout<<f[i]<<endl;
    }
}

    









Measured memory_bytes: 3640
s = input()
se = (s)
k = int(input())
n = len(s)

se = set()
for i in range(n):
    for j in range(i+1,i+1+k):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
        










#TLE 
'''
se = set()
for i in range(n):
    for j in range(i+1,n+1):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
'''

Measured memory_bytes: 4592
#include <bits/stdc++.h>
using namespace std;
#define test(t) int t; cin>>t; while(t--)
#define p1(x) { cout << " [" << #x << ": " << x << "]\n"; }
#define p2(x) { cout << " [" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]\n"; }
#define pb push_back
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
 
 
void solve()
{
	// int n, ans=0;
	string s;
	cin>>s;
	if(s[s.length()-1]=='s') s+="es";
	else s+="s";
	cout<<s<<endl;
}
 
int main() {
	// your code goes here
	// test(t)
		solve();
	return 0;
}
 

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

ll a, b, x;

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

    ll ans = b / x;
    if (a == 0) {
        ans++;
    }
    
    if (a >= x) {
        ll c = a - (a % x);
        if (a % x == 0) c--;
        ans -= c / x;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


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

int N,K,Q,A[2020];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>K>>Q;
    REP(i,N) cin>>A[i];

    int ans = INF;
    REP(y,N){
        int Y = A[y];
        
        vector<int> v;
        v.push_back(-1);
        REP(i,N) if(A[i]<Y) v.push_back(i);
        v.push_back(N);

        int n = v.size();
        priority_queue<int,vector<int>,greater<int>> qu;

        REP(i,n-1){
            int l = v[i] + 1;
            int r = v[i+1];

            priority_queue<int,vector<int>,greater<int>> buf;
            for(int i=l;i<r;i++) buf.push(A[i]);
            while(K<=buf.size()){
                qu.push(buf.top());
                buf.pop();
            }
        }
        int X = Y;
        int q = Q;
        while(0<q && !qu.empty()){
            chmax(X,qu.top());
            qu.pop();
            q--;
        }
        if(q==0) chmin(ans,X-Y);
    }
    cout<<ans<<endl;
}


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

#define REP(i, a, b) for (ll i = (a); i <= (b); ++i)
#define REV(i, a, b) for (ll i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

int scores[200000] = {};
int P[200000] = {};
vector<vector<int>> A(200000);

void set_score(int now, int old)
{
   scores[now] = scores[old] + P[now];
   FORV(a, A[now])
   {
      if (a != old)
         set_score(a, now);
   }
}

void Main()
{
   int N, Q;
   cin >> N >> Q;
   int a, b;
   REP(i, 0, N - 2)
   {
      cin >> a >> b;
      a--;
      b--;
      A[a].push_back(b);
      A[b].push_back(a);
   }
   int p, x;
   REP(i, 0, Q - 1)
   {
      cin >> p >> x;
      p--;
      P[p] += x;
   }
   set_score(0, 0);
   REP(i, 0, N-1)
   cout << scores[i] << " ";
   cout << endl;
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}


Measured memory_bytes: 24064
<?php

class MaximumProfit
{
    public function findMaximumProfit()
    {
        $price = $this->getInput();
        $minv = $price[0];
        $maxv = $price[1] - $price[0];

        for ($i = 1; $i < count($price); $i++) {
            if ($maxv < $price[$i] - $minv) {
                $maxv = $price[$i] - $minv;
            }

            if ($price[$i] < $minv) {
                $minv = $price[$i];
            }
        }
        echo $maxv . PHP_EOL;
    }
    
    public function getInput()
    {
        $input_data = trim(fgets(STDIN));
        for ($i = 0; $i < $input_data; $i++) {
            $input_price[] = trim(fgets(STDIN));
        }
        
        return $input_price;
    }
}

$maximum_profit = new MaximumProfit();
$maximum_profit->findMaximumProfit();



Measured memory_bytes: 44552
N = int(input())
task = []
for i in range(N):
    task.append(tuple(map(int, input().split())))

current_time = 0
answer = 'Yes'
for t in sorted(task, key=lambda x: x[1]):
    current_time += t[0]
    if current_time > t[1]:
        answer = 'No'
        break
print(answer)

Measured memory_bytes: 33472
import qualified Data.Vector.Unboxed as U

main = do
    n <- readLn
    as <- U.fromListN n . map read. words <$> getLine :: IO (U.Vector Int)
    let left = U.scanl' gcd 0 as
    let right = U.scanr' gcd 0 as
    let res = U.zipWith gcd left (U.tail right)
    print $ U.maximum res

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

int main() {
int N,M;
  cin >> N >> M;
  int s[M];
  int c[M];
  int k[N];
  int result = 0;
  for(int a = 0;a < N;a++){
    k[a] = 10;
  }
  for(int a = 0;a < M;a++){
   cin >> s[a] >> c[a]; 
    k[s[a] - 1] = c[a];
    if(s[a] == 1&&c[a] == 0&&N != 1){
        result = -1;
        break;
      }
  }
  for(int a = 0;a < M;a++){
    for(int b = 0;b < a;b++){
      if(s[a] == s[b]&&c[a] != c[b]){
        result = -1;
        break;
      }
    }
  }
 if(result != -1){
   for(int a = 1;a < N;a++){
    if(k[a] == 10)k[a] = 0;
  }
   if(k[0] == 10&&N != 1)k[0] = 1;
   if(k[0] == 10&&N == 1)k[0] = 0;
   for(int a = 0;a < N;a++){
    if(k[a] == 10)k[a] = 0;
     result += pow(10,(N - a - 1)) * k[a];
  }
   
 }
 cout<<result<<endl;
}

Measured memory_bytes: 256
import collections
k = int(input())
que = collections.deque()
cnt = 9
for i in range(1, 10):
    que.append(str(i))
Lun = []
while True:
    if len(Lun) >= 10**5:
        # print(que[-1])
        break
    now = que.popleft()
    Lun.append(now)
    # snow = str(now)
    if now[-1] == '0':
        que.append(now + '0')
        que.append(now + '1')
        cnt += 2
    elif now[-1] == '9':
        que.append(now + '8')
        que.append(now + '9')
        cnt += 2
    else:
        que.append(now + str(int(now[-1]) - 1))
        que.append(now + str(int(now[-1])))
        que.append(now + str(int(now[-1]) + 1))
        cnt += 3

    # print(now)
# print(que)
print(Lun[k-1])


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

typedef long long ll;
const int MAX_N = 430;    // Change as necessary
const ll  MODD = 1000000007; //

ll a[MAX_N],b[MAX_N];
ll A[MAX_N][MAX_N];
int n;
ll vals[MAX_N][MAX_N];

ll f(int idx,int C){
  ll& p = A[idx][C];
  if(p >= 0) return p;
  if(idx == n) return C == 0;
  
  p = 0;
  for(int i=0;i<=C;i++){
    p += (vals[b[idx]+1][i]-vals[a[idx]][i]+MODD)*f(idx+1,C-i);
    p %= MODD;
  }
  return p;
}

ll ipow(ll x,ll b){
  ll res = 1;
  while(b){
    if(b % 2) res = res*x % MODD;
    x = x*x % MODD;
    b /= 2;
  }
  return res;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  for(int j=1;j<MAX_N;j++)
    vals[j][0] = j-1;
  
  for(int i=1;i<MAX_N;i++)
    for(int j=1;j<MAX_N;j++){
      ll curr = 0;
      for(int k=0;k<i;k++)
        curr = (curr + ipow(k,j)) % MODD;
      vals[i][j] = curr;
    }
  
  int C; cin >> n >> C;
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=0;i<n;i++) cin >> b[i];
  
  for(int i=0;i<=n;i++)
    for(int j=0;j<=C;j++)
      A[i][j] = -1;
  
  cout << f(0,C) << endl;
  
  return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>
int main(){
  int n,i,j,a[100],hako,count=0,flag=1;

  scanf("%d",&n);
  for(i=0;i < n;i++){
    scanf("%d",&a[i]);
  }
  while(flag){
    flag=0;
    for(j=n-1;j > 0;j--){
      if(a[j] < a[j-1]){
	hako=a[j];
	a[j]=a[j-1];
	a[j-1]=hako;
	flag=1;
	count++;
      }
    }
  }
  for(i=0;i < n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[i]);
  printf("%d\n",count);

  return 0;
}  



Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF = 100000000;

vector<ll> sum;
ll i,j,k;
void pre_process(vector<ll> &a,vector<ll> &s){//累積和のvector
    ll n=(ll)a.size();
    s.assign(n+1,0);
    for(i=0;i<n;i++){
        s[i+1]=s[i]+a[i];
    }
}
ll query(ll i,ll j,vector<ll> &s){//区間[i,j]の和
    return (s[j]-s[i]);
}

int main(){
    ll n,k;cin>>n>>k;//n:candle総本数 k:灯したいcandle数
    vector<ll> x(n+1);
    for(i=0;i<n;i++){cin>>x[i];}
    x[n]=0;
    sort(x.begin(),x.end());
    
    ll num;
    for(num=0;x[num]!=0;num++);//0の場所
    
    ll mini=100000000000000,ans=100000000000000;
    for(i=0;i<=num;i++){
        if(i+k>n){break;}//はみでてる
        if(num-i>k){continue;}//0を含むような幅kの区間を探索
        mini=min(-2*x[i]+x[i+k],2*x[i+k]-x[i]);
        ans=min(ans,mini);
    }

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

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;

int main() {
  int n,x;
  int m = 1 << 30;
  cin >> n >> x;
  int sum = 0;
  rep(i, n){
    int t;
    cin >> t;
    m = min(m, t);
    sum += t;
  }
  int ans = n + (x -sum) / m;
  cout << ans << endl;
}


Measured memory_bytes: 256
//======================================================================
// Contents    : AOJ ITP1_5_A
//               たてH cm よこ W cm の長方形を描く
//               (H × W 個の '#' で描かれた長方形を出力)
// Input       : H , W
// Output      : H × W 個の '#'
//             : exp) "3 4"の入力時、以下のように出力される
//                      ####
//                      ####
//                      ####
// Constraints : 1 ≤ H,W ≤ 300
//             : "0 0" 入力で終了
// Author      : 廣部智也
// LastUpdate  : 2020/06/05
// Since       : 2020/06/05
//======================================================================

#include <stdio.h>
#include <stdlib.h>                                                  // exit 関数を使用するため

#define LOWER_LIMIT   0
#define UPPER_LIMIT 300
/* #define PRINT_ERROR printf("Input error\n") */

int Input_error( int number, int Lower_limit, int Upper_limit );    // 入力エラーを判断する関数

int main(){

    int H = 0, W = 0;
    int i = 0, j = 0;

    while(1){
        
        // データの入力
		scanf("%d %d", &H , &W );

        // 入力エラーの判断
        Input_error( H, LOWER_LIMIT, UPPER_LIMIT );
        Input_error( W, LOWER_LIMIT, UPPER_LIMIT );


		if( H == 0 && W == 0 ){
            break;
        }

        // データの出力
		for( i = 0; i < H; i++ ){

			for( j = 0; j < W; j++ ){
                putchar('#');                                       // printfでwaring
            }

			putchar('\n');                                          // printfでwaring
		}

        putchar('\n');                                              // データセット間の空行
	}

	return 0;
}

//============================================================
// Contents    : 入力エラーを判断
// Input       : 調べる変数, 下限, 上限
// Output      : エラーなら強制終了
// Author      : 廣部智也
// LastUpdate  : 2020/06/05
// Since       : 2020/06/05
//============================================================
int Input_error( int number, int Lower_limit, int Upper_limit ){
    
    if( number < Lower_limit || number > Upper_limit ){ 
        printf("Input error\n");
        exit(1);
    }

    return 0;
}


Measured memory_bytes: 2020
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
//using mint = modint1000000007;
//using mint = modint998244353;
//const int MOD = 1000000007;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int n,k;
int op(int a,int b){return max(a,b);}
int e(){return 0;}
int main(){
    cin>>n>>k;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    segtree<int,op,e>dp(303030);
    rep(i,n){
      int x=a[i];
      int l=x-k;
      int r=x+k+1;
      l=max(l,0);
      r=min(r,303030);
      int tmp=dp.prod(l,r)+1;
      dp.set(x,tmp);
    }
    int ans=dp.prod(0,303030);
    cout<<ans<<endl;
    return 0;
}
 
   

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


int F(int x){
    
    for( int i = 1 ; i * i <= x ; i = i + 1 ){

         if( x == ( i * i ) ) return 1;

         }

    return 0;

    }


int main(){


    int n, d, i, j, f;

    int s = 0;

    int a = 0;


    cin >> n >> d;


    vector< vector<int> > x( n, vector<int>(d) );


    for( i = 0 ; i < n ; i = i + 1 ){

         for( j = 0 ; j < d ; j = j + 1 ){

              cin >> x.at(i).at(j);

              }

         }


    for( i = 0 ; i < n - 1 ; i = i + 1 ){

         for( f = i + 1 ; f < n ; f = f + 1 ){

              for( j = 0 ; j < d ; j = j + 1 ){

                   s += ( x.at(i).at(j) - x.at(f).at(j) ) * ( x.at(i).at(j) - x.at(f).at(j) );

                   }

              if( F(s) == 1 ) a += 1;

              s = 0;

              }

         }


    cout << a << endl;

    
    return 0;


    }


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

using namespace std;

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

    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    vector<int> op(n, -1);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - i; j++) {
            if (b[j] == j + 1) {
                op[n - i - 1] = j;
            }
        }

        if (op[n - i - 1] == -1) {
            break;
        } else {
            b.erase(b.begin() + op[n - i - 1]);
        }
    }

    if (op[0] == -1) {
        cout << -1 << endl;
    } else {
        for (int i = 0; i < n; i++) {
            cout << op[i] + 1 << endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
vector<string> split(const string &str, char sep){
    std::vector<std::string> v;
    auto first = str.begin();
    while(first != str.end()){
        auto last = first;
        while(last != str.end() && *last != sep) ++last;
        v.push_back(std::string(first,last));
        if(last!=str.end()) ++last;
        first=last;
    }
    return v;
}
int n;
int slot[250000];
set<int> l;
void rev(){
    int slot2[250000];
    rep(i,n*n){
        slot2[i]=slot[n*n-i-1];
    }
    rep(i,n*n){
        slot[i]=slot2[i];
    }
}
int main(){
    cin>>n;
    rep(i,n){
        int x;
        cin>>x;
        if (slot[x-1]!=0){
            cout<<"No"<<endl;
            return 0;
        }
        slot[x-1]=i+1;
    }
    rep(i,n*n){
        if (slot[i]!=0 and l.find(slot[i])==l.end()){
            l.insert(slot[i]);
            int cnt=slot[i]-1;
            if (cnt==0) continue;
            rep(j,i){
                if (slot[j]==0) {
                    slot[j]=slot[i];
                    cnt-=1;
                    if (cnt==0) break;
                }
            }
            if (cnt!=0){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    l.clear();
    rev();
    rep(i,n*n){
        if (slot[i]!=0 and l.find(slot[i])==l.end()){
            l.insert(slot[i]);
            int cnt=n-slot[i];
            if (cnt==0) continue;
            rep(j,i){
                if (slot[j]==0) {
                    slot[j]=slot[i];
                    cnt-=1;
                    if (cnt==0) break;
                }
            }
            if (cnt!=0){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    rev();
    cout<<"Yes"<<endl;
    rep(i,n*n-1) cout<<slot[i]<<" ";
    cout<<slot[n*n-1]<<endl;
    return 0;
}

Measured memory_bytes: 3200
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i and a[0][0] < c:
        x, y = a[0]
        if y > i:
            a[0] = x, y - i
            i = 0
        else:
            heapq.heappop(a)
            i -= y
    heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))


Measured memory_bytes: 21548
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
//printf("%.10f\n", n);

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}

ll test[12345678], aa[12345678], dp1[12345678], dp2[12345678];
signed main() {
	ll n, m, k, q, a = -1, b = -1, c = 0, cnt = 0, ans = 0; string s, t;
	cin >> n >> m >> k;
	for (int h = 0; h < n; h++) {
		cin >> test[h];
	}
	for (int h = 0; h < m; h++) {
		cin >> aa[h];
	}
	for (int h = 0; h < n; h++) {
		if (cnt + test[h] <= k) {
			cnt += test[h]; dp1[h] = cnt; ans = max(ans, (ll)h + 1);
		}
		else { cnt += test[h]; dp1[h] = INF; }
	}
	cnt = 0;
	for (int h = 0; h < m; h++) {
		if (cnt + aa[h] <= k) {
			cnt += aa[h]; dp2[h] = cnt; ans = max(ans, (ll)h + 1);
		}
		else { cnt += aa[h]; dp2[h] = INF; }
	}
	for (int h = 0; h < n; h++) {
		ll ok = -1, ng = m, mid = (ok + ng) / 2;
		while (ng - ok > 1) {
			if (dp1[h] + dp2[mid] <= k) { ok = mid; }
			else { ng = mid; }
			mid = (ok + ng) / 2;
		}
		if (ok == -1) {
			continue;
		}
		else { ans = max(ans, h + ok + 2); }
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9832
#include<iostream>
using namespace std;
 
int main()
{
  int r;
  cin >> r;
 
  if(r < 1200) cout << "ABC" << endl;
 
  else if(r < 2800) cout << "ARC" << endl;
 
  else cout << "AGC" << endl;
 
  return 0;
 
}
 
 

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a[2][10]={{0}},i,j;
    char c;
    while(scanf(" %c",&c)!=EOF){
        a[0][0]=c-'0';
        for(i=1;i<10;i++){
            scanf(" %c",&c);
            a[0][i]=c-'0';
        }

        for(i=0;i<10;i++){
            for(j=0;j<9-i;j++){
                a[(i+1)%2][j]=(a[i%2][j]+a[i%2][j+1])%10;
            }
        }
        printf("%d\n",a[1][0]);
        for(i=0;i<10;i++){
            a[0][i]=0;
            a[1][i]=0;
        }
    }
    return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<char>());
  cout << (s<t? "Yes":"No")<<endl;
  return 0;
}


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

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

    long long a;
    long long cumlative_sum[N + 1] = {};
    for (int i = 1; i <= N; i++)
    {
        cin >> a;
        cumlative_sum[i] = cumlative_sum[i - 1] + a;
    }

    long long ans = LONG_LONG_MAX;
    for (int i = 1; i < N; i++)
    {
        long long x = cumlative_sum[i];
        long long y = cumlative_sum[N] - cumlative_sum[i];
        ans = min(ans, abs(x - y));
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
a1x = [int(x) for x in input().split(' ')]
a2x = [int(x) for x in input().split(' ')]
a3x = [int(x) for x in input().split(' ')]

sheet = [a1x, a2x, a3x]

n = int(input())
numbers = []

for i in range(n):
    num = int(input())
    numbers.append(num)

def solve(n, sheet, numbers):
    for number in numbers:
        for row in range(3):
            for column in range(3):
                if sheet[row][column] == number:
                    sheet[row][column] = "X"

    if checkRow(sheet) or checkColumn(sheet) or checkDiagonals(sheet):
        print("Yes")
    else:
        print("No")

def checkRow(sheet):
    for row in range(3):
        marked = 0
        for column in range(3):
            if sheet[row][column] == "X":
                marked += 1
        if marked == 3:
            return True
    
    return False
            
def checkColumn(sheet):
    for row in range(3):
        marked = 0
        for column in range(3):
            if sheet[column][row] == "X":
                marked += 1
        if marked == 3:
            return True
    
    return False

def checkDiagonals(sheet):
    marked = 0
    for i in range(3):
        if sheet[i][i] == "X":
            marked += 1

    if marked != 3:
        marked = 0
        for j in range(3):
            if sheet[j][2-j] == "X":
                marked += 1
    
    if marked == 3:
        return True
    else:
        return False

    

solve(n, sheet, numbers)

Measured memory_bytes: 3064
using System;
class Program
{
    static void Main(string[] args)
    {
        string n = Console.ReadLine();

        long total = 0;
        for (int i = 0; i < n.Length; i++)
        {
            total += int.Parse(n.Substring(i, 1));
        }

        Console.WriteLine(total % 9 == 0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 32656
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>
#include<assert.h>

typedef long long ll;
typedef unsigned long long ull;
#define SIZE 100099
#define sqrt_SIZE 316

int main()
{
	int x;
	int p[SIZE] = { 0 };
	p[0] = p[1] = 1;

	for (size_t i = 4; i < SIZE; i += 2)
	{
		p[i] = 1;
	}
	for (size_t i = 3; i <= sqrt_SIZE; i += 2)
	{
		if (!p[i])
		{
			for (size_t j = i + i; j < SIZE; j += i)
			{
				p[j] = 1;
			}
		}
	}
	
	scanf("%d", &x);
	if (x<=2)
	{
		printf("2");
		return 0;
	}
	for (size_t i = x + !(x % 2); ; i += 2)
	{
		if (!p[i])
		{
			printf("%d", i);
			return 0;
		}
	}
	
}




Measured memory_bytes: 512
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define __V vector
#define all(x) x.begin(), x.end()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}
template<typename X, typename Y>
istream& operator>>(istream& in, pair<X, Y> &a) {
	in >> a.first >> a.second;
	return in;
}
template<typename T>
void getv(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv(vector<T>& v, int n, Ns ... ns) {
	v.resize(n);
	for (auto& i : v)
		getv(i, ns...);
}
template<typename T>
void getv1(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv1(vector<T>& v, int n, Ns ... ns) {
	v.resize(n + 1);
	for (int i = 1; i <= n; i++)
		getv(v[i], ns...);
}
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
inline void getch(char &x) {
	while (x = getchar_unlocked(), x < 33) {
		;
	}
}
inline void getstr(string &str) {
	str.clear();
	char cur;
	while (cur = getchar_unlocked(), cur < 33) {
		;
	}
	while (cur > 32) {
		str += cur;
		cur = getchar_unlocked();
	}
}
template<typename T> inline bool sc(T &num) {
	bool neg = 0;
	int c;
	num = 0;
	while (c = getchar_unlocked(), c < 33) {
		if (c == EOF)
			return false;
	}
	if (c == '-') {
		neg = 1;
		c = getchar_unlocked();
	}
	for (; c > 47; c = getchar_unlocked())
		num = num * 10 + c - 48;
	if (neg)
		num *= -1;
	return true;
}
typedef unsigned long long ull;
typedef long long ll;
typedef float ld;
typedef int _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
using AntonTsypko = void;
using arsijo = AntonTsypko;
using god = arsijo;
uniform_real_distribution<double> double_dist(0, 1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	doin();
	string s;
	cin >> s;
	int a[2];
	a[0] = a[1] = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == '0')
			a[i&1]++;
		else
			a[(i+1)&1]++;
	}
	cout << min(a[0], a[1]);
	return 0;
}


Measured memory_bytes: 512
top=0
sec=0
thi=0

for num in range(10):
	input_num=input()
	x=int(input_num)
	if x>top:
		thi=sec
		sec=top
		top=x
	elif x<=top and x>sec:
		thi=sec
		sec=x
	elif x<=sec and x>thi:
		thi=x

print(top)
print(sec)
print(thi)


Measured memory_bytes: 5588
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define int ll

int s,c;

signed main(){
	cin>>s>>c;
	
	int res = c-2*s;
	
	int ans = max<ll>(min(s,c/2),0);
	
	if(res>=0)ans+=res/4;
	cout<<ans<<endl;
	
}

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

int main(){
    int n,t;
    cin >> n >> t;
    ve<P> ab;
    rep(i,n){
        ll a,b;
        cin >> a >>b;
        ab.push_back(P(a,b));
    }

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

    ve<ve<ll>> dp1(n+1,ve<ll>(t+1));
    rep(i,n){
        ll a = ab[i].first, b = ab[i].second;
        rep(j,min(a, (ll)t)) dp1[i+1][j] = dp1[i][j];
        rep(j,t-a+1){
            dp1[i+1][j+a] = max(dp1[i][j+a], dp1[i][j]+b);
        }
    }

    ll ans=0;
    rep(i,n){
        ll memo = ab[i].second;
        ans = max(ans, memo+dp1[i][t-1]);
    }

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

Measured memory_bytes: 70784
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		Map<String, Integer> map = new HashMap<>();
		map.put("SUN", 7);
		map.put("MON", 6);
		map.put("TUE", 5);
		map.put("WED", 4);
		map.put("THU", 3);
		map.put("FRI", 2);
		map.put("SAT", 1);
		System.out.println(map.get(S));
	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define ll long long
#define st first
#define sc second
#define pb push_back

using namespace std;

const int maxn = 5e5 + 69;


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

    string s;
    cin >> s;
    if(s[s.size() - 1] == 's'){
        cout << s <<"es";
    }
    else{
        cout << s <<"s";
    }

}


Measured memory_bytes: 3660
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#define debug(x) cout <<#x<<" = "<<x<<endl
#define debug2(x, y) cout<<x<<" "<<y<<endl
#define gg cout <<"---------------QAQ---------------"<<endl
#define fi first
#define SZ(x) (int)x.size()
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> Pii;
template<class T> inline void read(T &x){
    x=0; char c=getchar(); int f=1;
    while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
    while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 2e5+10, maxn = 1e6+5;
void FAST(){ios::sync_with_stdio(false);cin.tie(0);}
const ll mod =  998244353;

int n, m, k;
int a[N];

void solve()
{
    scanf("%d", &n);
    for(int i = 1; i < n; ++i)
    {
        scanf("%d", &k);
        a[k]++;
    }
    for(int i = 1; i <= n; ++i) printf("%d\n", a[i]);

}


int main()
{
//    int _; scanf("%d", &_); while(_--)
//    while(~scanf("%d%d", &n, &d))
//    while(~scanf("%lld", &n))
    solve();
    return 0;
}


Measured memory_bytes: 4536
// Aggressive Play
 
#include<bits/stdc++.h>
#define ll long long
 
using namespace std;
const int N = 4e3 + 5;
const int k = 3;
int a[N][k];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    map<char, int> mp;
    mp['R'] = 0;
    mp['G'] = 1;
    mp['B'] = 2;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < k; j++){
            a[i][j] = a[i - 1][j];
        }
        a[i][mp[s[i]]]++;
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = i + 2; j <= n; j++){
            if(s[i] == s[j]) continue;
            vector<int> h(k, 0);
            for(int kk = 0; kk < k; kk++){
                h[kk] = a[j - 1][kk] - a[i][kk];
            }
            int diff = j - i;
            if(diff % 2 == 0){
                int mid = (i + j) / 2;
                h[mp[s[mid]]]--;
            }
            h[mp[s[i]]] = 0;
            h[mp[s[j]]] = 0;
            for(int kk = 0; kk < k; kk++)
                ans += h[kk];
        }
    }
    cout << ans;
return 0;
}

Measured memory_bytes: 3664
def solve():
    from sys import stdin
    f_i = stdin
    
    n = int(f_i.readline())
    A_s = f_i.readline().rstrip()
    
    if n == 1:
        print(A_s)
    else:
        A = tuple(map(int, A_s.split()))
        
        from itertools import permutations
        lex = tuple(permutations(range(1, n + 1), n))
        
        from bisect import bisect_left
        idx = bisect_left(lex, A)
        if idx == 0:
            print(A_s)
            print(' '.join(map(str, lex[idx+1])))
        elif idx == len(lex) - 1:
            print(' '.join(map(str, lex[idx-1])))
            print(A_s)
        else:
            print(' '.join(map(str, lex[idx-1])))
            print(A_s)
            print(' '.join(map(str, lex[idx+1])))

solve()


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

int main(){
  int X,N;
  int ans = 1000;

  
  cin >> X >> N;
  if(N == 0){
    cout << X << endl;
    return 0;
  }
  
  vector<int> vec(N);
  for(int i=0;i<N;++i){
    cin >> vec.at(i);
  }

  for(int i=101;i>=0;i-=1){
      bool flag = false;
    if(abs(X-i) <= abs(X-ans)){
      flag = true;
      for(int j=0;j<N;++j){
        if(i == vec.at(j)){
          flag = false;
         }
      }
    }
    if(flag){
     ans = i;
   }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
s=input()

ans = 'Yes'
for i, t in enumerate(s):
    if i % 2 == 0:
        if t in ['R','U','D']:
            pass
        else:
            ans = 'No'
    else:
        if t in ['L','U','D']:
            pass
        else:
            ans = 'No'
print(ans)

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

typedef long long ll;

int main() {
	ll A, B, C;
	cin >> A >> B >> C;

	if (A % 2 == 1 && B % 2 == 1 && C % 2 == 1) {
		cout << min(A*B, min(A*C, B*C)) << endl;
	}
	else {
		cout << 0 << endl;
	}

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    for (int i = min(A, B); i >= 1; --i) {
        if (A % i == 0 && B % i == 0) {
            --K;
            if (K == 0) {
                cout << i << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, k, j) for(int i=(k); i < (int)(j); i++)
template<class T> istream&
operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream&
operator << (ostream &os , vector<T> &v) { rep(i, v.size()) os << v[i] << (i + 1 < v.size() ? " " : ""); return os; }

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(M); cin >> A;
    vector<int> odd, even;
    for(int a : A) (a % 2 ? odd : even).push_back(a); 
    if(odd.size() > 2) {
        cout << "Impossible" << endl;
        return 0;
    }
    vector<int> ans_a;
    if(odd.size() >= 1) ans_a.push_back(odd[0]);
    for(int a : even) ans_a.push_back(a);
    if(odd.size() >= 2) ans_a.push_back(odd[1]);    
    cout << ans_a << endl;

    vector<int> ans_b;
    int sum = 0;

    if(ans_a[0] != 1) {
        ans_b.push_back(ans_a[0] - 1);
        sum += ans_b.back();
    }
    repeat(i, 1, ans_a.size() - 1) {
        ans_b.push_back(ans_a[i]);
        sum += ans_b.back();
    }
    if(ans_a.size() == 1) {
        ans_b.push_back(1);
        sum += 1;
    }
    if(sum < N) ans_b.push_back(N - sum);

    cout << ans_b.size() << endl;
    cout << ans_b << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int a[] = new int[N];
		int b[] = new int[N];
		int c[] = new int[M];
		int d[] = new int[M];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for (int i= 0;i<M;i++) {
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			int min =Math.abs(c[0]-a[i])+Math.abs(d[0]-b[i]);
			int minPosition = 0;
			for (int j=1;j<M;j++) {
				int temp = Math.abs(c[j]-a[i])+Math.abs(d[j]-b[i]);
				if (temp<min) {
					min = temp;
					minPosition = j;
				}
			}
			System.out.println(minPosition+1);
		}
	}
}


Measured memory_bytes: 21844
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
int main()
{
    ll n,sum=0,i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%3==0||i%5==0)
        {
            continue;

        }
        else
        {
            sum+=i;
        }
    }
    cout<<sum;
}


Measured memory_bytes: 3592
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int x, a, b; cin >> x >> a >> b;
    if (abs(x-a) < abs(x-b)) cout << "A" << endl;
    else cout << "B" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using PII = pair<int, int>;
#define F first
#define S second
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<PII> v;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    if (a <= m)
      v.emplace_back(m - a + 1, b);
  }
  sort(v.begin(), v.end());
  priority_queue<int, vector<int>, greater<int>> q;
  uint64_t ans = 0;
  for (auto &it : v) {
    int a, b;
    tie(a, b) = it;
    q.push(b);
    ans += b;
    while (q.size() > a) {
      ans -= q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1908
package main

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

var H, W int
var grid []string

func main() {
	H, W = ReadInt(), ReadInt()
	grid = make([]string, H)
	for i := 0; i < H; i++ {
		grid[i] = ReadString()
	}

	goals := 0
	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			if grid[y][x] == '#' {
				goals++
			}
		}
	}

	visit := dfs(0, 0)
	if visit == goals {
		fmt.Println("Possible")
	} else {
		fmt.Println("Impossible")
	}
}

func dfs(x, y int) int {
	if grid[y][x] != '#' {
		return 0
	}

	dirX := []int{0, 1}
	dirY := []int{1, 0}

	for i := 0; i < 2; i++ {
		nx, ny := x+dirX[i], y+dirY[i]
		if nx >= W || ny >= H {
			continue
		}
		if grid[ny][nx] == '#' {
			return 1 + dfs(nx, ny)
		}
	}
	return 1
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a); (i)<=(b); (i)++)
#define REP(i,N) FOR((i), 0, (N)-1)

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll ab, bc, ca; cin >> ab >> bc >> ca;
    cout << ab*bc/2 << endl;
}

Measured memory_bytes: 256