akhauriyash/Code-Regression huggingface dataset:
N = int(input())
t = [2,1]
h = [[1],[1]]
while t[1]<=N:
    if t[1]==N:
        print("Yes")
        print(t[0])
        [print(len(h[i])," ".join([str(j) for j in h[i]])) for i in range(len(h))]
        break
    else:
        [h[i].append(t[1]+1+i) for i in range(len(h))]
        h.append([t[1]+1+i for i in range(len(h))])
        t[1]+=t[0]
        t[0]+=1
else:
    print("No")

Measured memory_bytes: 12248
import java.util.Scanner;

public class Main {

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

	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(LL, a, b, c, k);
	OUT(k <= a ? k : (k <= a + b ? a : a - (k - (a + b))));
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int s[13]={0};
  int h[13]={0};
  int c[13]={0};
  int d[13]={0};
  char a;
  int n,x;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>a>>x;
    if(a=='S')
    {
      s[x-1]=1;
    }
    else if(a=='H')
    {
      h[x-1]=1;
    }
    else if(a=='C')
    {
      c[x-1]=1;
    }
    else if(a=='D')
    {
      d[x-1]=1;
    }
  }
  for(int i=0;i<4;i++)
  {
    for(int j=0;j<13;j++)
    {
      if(i==0 && s[j]!=1)
      {
        cout<<"S "<<j+1<<endl;
      }
      else if(i==1 && h[j]!=1)
      {
        cout<<"H "<<j+1<<endl;
      }
      else if(i==2 && c[j]!=1)
      {
        cout<<"C "<<j+1<<endl;
      }
      else if(i==3 && d[j]!=1)
      {
        cout<<"D "<<j+1<<endl;
      }
    }
  }
}



Measured memory_bytes: 3084
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[]) {
  int count = 0;
  string S;
  cin >> S;
  for (int i = 0; i < S.length() / 2; i++) {
    if (S[i] != S[S.length() - (1 + i)]) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int N = 100100;

ll minf = -1e16;
ll dp[N][3];

int main(void){
  int n;
  cin >> n;
  VL a(n);
  vector<char> ops(n - 1);
  REP(i, 0, n - 1) {
    cin >> a[i] >> ops[i];
  }
  cin >> a[n - 1];
  REP(i, 0, n + 1) {
    REP(j, 0, 3) {
      dp[i][j] = minf;
    }
  }
  dp[0][0] = a[0];
  REP(i, 1, n) {
    REP(j, 0, 3) {
      if (ops[i - 1] == '+') {
	dp[i][j] = dp[i - 1][j] + (j == 1 ? -a[i] : a[i]);
      } else {
	dp[i][j] = max(dp[i][j], dp[i - 1][j] + (j == 0 ? -a[i] : a[i]));
	if (j < 2) {
	  dp[i][j + 1] = max(dp[i][j + 1], dp[i - 1][j] + (j == 0 ? -a[i] : a[i]));
	}
      }
    }
  }
  ll ma = minf;
  REP(i, 0, 3) {
    ma = max(ma, dp[n - 1][i]);
  }
  cout << ma << endl;
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(),work;
		int[] mochi = new int[N];
		int Num=0,count=0;
		
		for(int i=0;i<N;i++) 
			mochi[i]=sc.nextInt();
		
		for(int i=0;i<N;i++) 
		{
			for(int k=i;k<N;k++) 
			{
				if(mochi[i] > mochi[k])
				{
					work = mochi[i];
					mochi[i] = mochi[k];
					mochi[k] = work;
				}
			}
		}
		
		
		for(int i=0;i<N;i++) 
		{
			if(Num != mochi[i]) 
			{
				count+=1;
				Num=mochi[i];
			}
		}
		System.out.print(count);

	}

}


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

char N[55][55],M[55][55];

bool same(int row,int col,int m)
{
	for(int i=1;i<=m;i++)
		for(int j=1;j<=m;j++)
			if(M[i][j]!=N[i+row-1][j+col-1])
				return 0;
	return 1;
}

int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>N[i][j];
	for(int i=1;i<=m;i++)
		for(int j=1;j<=m;j++)
			cin>>M[i][j];

	for(int i=1;i<=n-m+1;i++)
		for(int j=1;j<=n-m+1;j++)
			if(same(i,j,m))
			{
				printf("Yes\n");
				return 0;
			}

	printf("No\n");
}


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

using namespace std;
typedef long long ll;

int N;
vector<int> v;
vector<int> p,q;

int main(){
    int t;
    cin >> N;
    for(int i=1;i<=N;i++) v.push_back(i);
    for(int i=0;i<N;i++){
        cin >> t;
        p.push_back(t);
    }
    for(int i=0;i<N;i++){
        cin >> t;
        q.push_back(t);
    }
    int a,b,i;
    i=0;
    do{
        if(p == v) a = i;
        if(q == v) b = i;
        i++;
    }while(next_permutation(v.begin(),v.end()));
    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using P = pair<int,int>;
typedef long long ll;
#define pi 3.1415926535898
int  main()
{
	int r;
	cin >> r;
	// int x = 1;
	// int area = r*r*pi;
	// int xarea = x*x*pi;
	// cout << area / xarea << endl;
	double r1 = (double)1* 1 * pi;
	double a = (double)r * r * pi;

	printf("%d", (int)ceil(a/r1));
	return (0);
}

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

int N,D,X,A[101],ret = 0;

int main(){
	cin >> N >> D >> X;
	for(int i = 1; i <= N; i++) cin >> A[i];
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= D; j += A[i]){
			ret++;
		}
	}
	cout << ret + X << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, a, b;
    cin >> n;
    vector<vector<int>> red;
    vector<vector<int>> blue;
    for(int i = 0; i < n; i++) {
        cin >> a >> b;
        red.push_back({a, b});
    }
    sort(red.begin(), red.end());
    for(int i = 0; i < n; i++) {
        cin >> a >> b;
        blue.push_back({a, b});
    }
    sort(blue.begin(), blue.end());
    int r_idx = 0, ans = 0;
    multiset<int> cand;
    for(int i = 0; i < n; i++) {
        while(r_idx < n && red[r_idx][0] < blue[i][0]) {
            cand.insert(red[r_idx++][1]);
        }
        if (cand.size() > 0) {
            auto it = cand.lower_bound(blue[i][1]);
            if (it != cand.begin()) {
                ans += 1;
                cand.erase(prev(it));
            }
        }
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

int main(int, char**) {
        int n, m, q;
        cin >> n >> m >> q; 
        vector<vector<int>> data(q, vector<int>(4));
        for (int i=0; i<q; i++) {
                int a, b, c, d;
                cin >> a >> b >> c >> d;
                a--; b--;
                data[i][0] = a;
                data[i][1] = b;
                data[i][2] = c; 
                data[i][3] = d;
        }
        long long max_score = 0;
        for (int i1=1; i1<=m; i1++) {
         for (int i2=i1; i2<=m; i2++) {
          for (int i3=i2; i3<=m; i3++) {
           for (int i4=i3; i4<=m; i4++) {
            for (int i5=i4; i5<=m; i5++) {
             for (int i6=i5; i6<=m; i6++) {
              for (int i7=i6; i7<=m; i7++) {
               for (int i8=i7; i8<=m; i8++) {
                for (int i9=i8; i9<=m; i9++) {
                 for (int i10=i9; i10<=m; i10++) {
                         vector<int> nums = {i1, i2, i3, i4, i5, i6, i7, i8, i9, i10};
                         long long tmp = 0;
                         for (auto d : data) {
                                 if (nums[d[1]] - nums[d[0]] == d[2]) tmp += d[3];
                         }       
                         max_score = max(max_score, tmp);
                 }
                }
               }
              }
             }
            }
           }
          }
         }
        }
        cout << max_score << endl;

        return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

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

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

int main()
{
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for(int i=0; i<3; i++){
        if(s[i] == t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

def o(c): return ord(c) - ord('a')

s, t = sys.stdin.read().split()

def main():
    g1 = [set() for _ in range(26)]
    g2 = [set() for _ in range(26)]
    for i in range(len(s)):
        a = o(s[i]); b = o(t[i])
        g1[a].add(b); g2[b].add(a)

    for i in range(26):
        if len(g1[i]) >= 2 or len(g2[i]) >= 2:
            print('No')
            return
    print('Yes')

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3828
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
N = ri()
s = Counter([rs() for _ in range(N)])
M = ri()
t = Counter([rs() for _ in range(M)])
ans = 0
for si in s.items():
    ans = max(ans, max(si[1] - t[si[0]], 0))
print(ans)

Measured memory_bytes: 63340
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
const double pi=3.14159265358979323846;

int main() {
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    long double c=pi*h/6+m*pi/360;
    long double d=m*pi/30;
    long double ans;
    if (c>d) c-=d;
    else c=d-c;
    if (c>pi) c=2*pi-c;
    if(c==pi) {
        ans=a+b;
    }
    else if(c*2==pi) {
        ans=sqrt(a*a+b*b);
    }
    else {
        ans=sqrt((a-b*cos(c))*(a-b*cos(c))+b*b*sin(c)*sin(c));
    }
    cout << fixed << setprecision(16) << ans << endl;

    return 0;
}

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

int main()
{
    int n;
    long long int k;
    cin >> n >> k;
    int *route = (int*) malloc( sizeof(int) * n );
    for( int i = 0; i < n; i++ ) 
    {
        cin >> route[i];
        route[i]--;
    }

    int *h = (int*) malloc( sizeof(int) * n );
    for( int i = 0; i < n; i++ ) h[i] = -1;

    int p = 0;
    int t = 0;
    while(true)
    {
        h[p] = t;
        p = route[p];
        t++;
        if( h[p] >= 0 ) break;
    }

    int sl = h[p];
    int l = t - h[p];
    if( k > sl )
    {
        int movet = (int)((k - sl) % l);
        for( int i = 0; i < movet; i++) p = route[p];
    }
    else
    {
        p = 0;
        for( int i = 0; i < k; i++) p = route[p];
    }

    cout << (p + 1);
}



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

class D
{
	static void Main()
	{
		var k = int.Parse(Console.ReadLine());

		var nexts = new[] { "01", "012", "123", "234", "345", "456", "567", "678", "789", "89" };
		string[] NextList(string[] l) => l.SelectMany(s => nexts[s[^1] - '0'].Select(c => s + c)).ToArray();

		var ls = new string[10][];
		ls[0] = new int[9].Select((_, i) => $"{i + 1}").ToArray();
		var q = Enumerable.Range(0, 10).SelectMany(i => i > 0 ? ls[i] = NextList(ls[i - 1]) : ls[i]);
		Console.WriteLine(q.ElementAt(k - 1));
	}
}


Measured memory_bytes: 50504
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

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

int main() {
    ll C[3][3];
    rep(i,3){
        rep(j,3) cin >> C[i][j];
    }
    string out = "Yes";
    rep(i,3){
        rep(j,3){
            if(C[i][j]-C[i][0]==C[0][j]-C[0][0]||C[i][j]-C[0][j]==C[i][0]-C[0][0]);
            else{
                out = "No";
                break;
            }
        }
    }
    cout << out << endl;
    return 0;
}



Measured memory_bytes: 3628
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<Integer, Integer> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            map.merge(a, 1, Integer::sum);
        }
        int ans = 0;
        for (Map.Entry<Integer, Integer> e : map.entrySet()) {
            int k = e.getKey();
            int v = e.getValue();
            if (k > v) {
                ans += v;
            } else if (k < v) {
                ans += (v - k);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50036
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();

        out.println((1000 - (n % 1000)) % 1000);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


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

int main() {
  long int n;
  cin >> n;
  long int a = 26;
  long int m;

  list<char> s;
  for (int i = 0; i < 12; i++) {
    n -= 1;
    m = n % a;
    s.push_front((char)('a' + m));
    n /= a;
    if (n <= 0) break;
  }

  for (auto i : s) {
    cout << i;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;




int main(){
  string s;
  cin >> s;
  int a[26] = {};
  REP(i,s.size()){
    a[s[i]%26]++;
  }
  
  int num = s.size()/3;
  if(s.size()%3 != 0)
    num++;
  int b = s.size()%3;
  if(b == 0)
    b = 3;
  int res = 0;
  bool f = 1;
  REP(i,26){
    if(a[i] > num){
      f = false;
    }
    else if(a[i] == num){
      res++;
    }
  }
  if(res > b){
    f = false;
  }
  
  if(f)
    cout <<  "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long int lld;
#define sq(x) (x*x)
#define fr(i,m,n) for(i=m;i<n;i++)
#define vec vector<int>
#define sint set<int>
#define qint queue<int>
#define mip map<int,int>
#define pint priority_queue<int>
#define pb push_back
#define pp pop_back()
#define ft first
#define sd second
#define all(v) v.begin(),v.end()
#define mom(ara,n) memset(ara,0,sizeof(int)*(n));
#define m1m(ara,n) memset(ara,-1,sizeof(int)*(n));
int main()
{
    lld i,j,k,a,b,x,y,z,n,m,t;
    char c;
    cin>>a>>b>>c>>x;
    b*=100;
    b+=x;
    z=(a*b)/100;
    printf("%lld\n",z);
}


Measured memory_bytes: 3768
#include <stdio.h>
int main(){
  int i,j,k,v,N;
  int A[1000];

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

  for (i = 1; i < N; i++)
    {  v=A[i];
    j = i-1;

  while (j >= 0 && A[j] > v)
    {
    A[j+1] = A[j];
    j--;
    }
    A[j+1] = v;

    for(k=0;k<N-1;k++)
      {
        printf("%d",A[k]);
        printf(" ");
      }
    printf("%d\n",A[N-1]);
}
return 0;
}







Measured memory_bytes: 2108
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int top,S[1000];
 
void  push(int x){
   S[++top] = x;
}
 
int pop(){
   top--;
   return S[top+1];
}
 
int main(){
  int a,b;
  top = 0;
  char s[100];
  
  while( scanf("%s",s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
   }else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a - b);
   }else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
   }else{
      push(atoi(s));
   }
  }
   printf("%d\n",pop());
   return 0;
}

Measured memory_bytes: 548
import java.util.*;
public class Main {
	static Scanner s = new Scanner(System.in);
	public static void main(String __[]){
		long n=s.nextLong(),result=1145141919;
		for(int i=1;i<=100000;i++)if(n%i==0) {
			result=Math.min(result, Math.max(i, n/i));
		}
		System.out.println(String.valueOf(result).length());
	}
}

Measured memory_bytes: 24148
#include <iostream>

typedef long long ll;

using namespace std;

#define SIZE 501

int dp[SIZE][SIZE]{};
int arr[SIZE][SIZE]{};
int sm[SIZE][SIZE]{};

int main() {
	ll n,m,q;
	cin >> n >> m >> q;
	for(int i = 0; i < m; i++) {
		int l,r;
		cin >> l >> r;
		arr[r][l]++;
	}

	for(int i = 1; i <= n; i++) {
		for(int j = i; j > 0; j--) {
			dp[i][j] = arr[i][j];
			dp[i][j] += dp[i-1][j];
			sm[i][j] = arr[i][j];
			if(j<SIZE-1) {
				sm[i][j] += sm[i][j+1];
				dp[i][j] += sm[i][j+1];
			}
		}
	}
/*
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				cout << arr[i][j] << " ";
			}
			cout << endl;
		}
		cout << endl;
			for(int i = 1; i <= n; i++) {
				for(int j = 1; j <= n; j++) {
					cout << sm[i][j] << " ";
				}
				cout << endl;
			}
			cout << endl;
				for(int i = 1; i <= n; i++) {
					for(int j = 1; j <= n; j++) {
						cout << dp[i][j] << " ";
					}
					cout << endl;
				}
				cout << endl;
*/
	for(int i = 0; i < q; i++) {
		int p,_q;
		cin >> p >> _q;
		cout << dp[_q][p] << endl;
	}

	return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#include <ctime>
#include <cstdlib>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()
{
    long long N;
    cin >> N;
    cout << N * (N - 1) / 2 << endl;
}

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

int main(){
    int h,w;
	cin>>h>>w;
    vector<char> vec(h*w);
    vector<char> arr2( (h+2)*(w+2) );
 
    //入力
    for (int y=0; y < h; y++){
        for (int x = 0; x < w; x++) {
            cin >> vec.at(x+y*w);
        }
    }
    
    //処理
    for (int y=0;y<h+2;y++){
        for (int x=0;x<w+2;x++){
            if(x==0||y==0||x==w+1||y==h+1){
                arr2.at( x+y*(w+2) )='#';
            }
            else{
                arr2.at( x+y*(w+2) )=vec.at( (x-1)+(y-1)*w );
            }
        }
    }
    
    //[-1][-1]を追加できたら楽だったかも？
    
    //出力
    for (int y=0;y<h+2;y++){
        for (int x=0;x<w+2;x++){
            cout<<arr2.at( x+y*(w+2) );
        }
        cout<<endl;
    }
}

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

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

using namespace std;

int H, W, N;

int main() {
    cin >> H >> W >> N;
    int d = max(H, W);
    int ans = ceil((double) N / d);
    cout << ans << endl;
}


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

int main(void)
{
    string s;

    cin >> s;

    int pn = 0;

    for(int i = 0; i < s.size(); ++i)
    {   
        if(s[i] == 'p') ++pn;
    }
    int n = s.size()/2;

    cout << n - pn << endl;


    return 0;
}



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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = 998244353; 
const ll mxN = 200200;

ll fact[mxN], ifact[mxN], inv[mxN];
void pre(){
	inv[1]=fact[0]=ifact[0]=1;
	for(int i=2;i<mxN;i++)
		inv[i] = (mod - (mod / i) * inv[mod%i] % mod)%mod;
	for(int i=1;i<mxN;i++)
		fact[i]=i*fact[i-1]%mod,
		ifact[i] = inv[i]*ifact[i-1]%mod;
}

ll nck(ll n, ll k) {
	return fact[n]*(ifact[k]*ifact[n-k]%mod)%mod;
}

ll bin_pow(ll base,ll exp){
	if(exp==0) return 1LL;
   	else if(exp&1) return bin_pow(base*base%mod,exp>>1)*base%mod;
	else return bin_pow(base*base%mod,exp>>1);	
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
	pre();	
	ll n, m, k, ans=0;
	cin>>n>>m>>k;
	for(int i=0;i<=min(n-1,k);i++){
		ans += m*bin_pow(m-1,n-1-i)%mod*nck(n-1,i)%mod;
		ans %= mod;
	}
	cout<<ans;
}


Measured memory_bytes: 8316
import java.util.*;
import java.util.Scanner;
class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        Queue<Integer> queue = new ArrayDeque<>();
        for(int i=0; i<A; i++) {
        		int a = sc.nextInt();
        		queue.add(a);
        }
        int j = 1;
        for(int i=0; i<A; i++) {
        		int a = queue.poll();
        		if(a == j) {
        			j++;
        		}
        }
        if(j == 1) {
        		System.out.println(-1);
        } else {
        		System.out.println(A-j+1);
        }
    }
} 

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

const int m = 2019;

int main(void){
    
    string s, t;
    cin >> s >> t;

    t.pop_back();
    if(s == t){
        cout << "Yes";    
    } else {
        cout << "No";
    }
     
    
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long


int main() {
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='R'){
            if(i%2!=0){
                c++;
                break;
            }
        }
        if(s[i]=='L'){
            if(i%2==0){
                c++;
                break;
            }
        }
    }
    if(c==0)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 3620
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Set<Integer> paper = new HashSet<Integer>();
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            if (paper.contains(a)) {
                paper.remove(a);
            } else {
                paper.add(a);
            }
        }
        System.out.println(paper.size());
    }
}


Measured memory_bytes: 63748
if __name__=='__main__':
    N = int(input())
    a = list(map(int, input().split(' ')))
    a.sort()
    a = a[::-1]

    Alice = [a[i] for i in range(N) if i % 2 == 0]
    Bob = [a[i] for i in range(N) if i % 2 == 1]

    print(sum(Alice)-sum(Bob))

Measured memory_bytes: 3064
n,a,b,c=map(int, input().split(' '))
# print(n,a,b,c)
left=[a,b,c]
ans=[]
prev=(-1,-1)
for i in range(0,n):
    s=input()
    # print(s)
    x = {'A':0,'B':1,'C':2}[s[0]]
    y = {'A':0,'B':1,'C':2}[s[1]]
    if left[x]==left[y]==0:
        x0,y0=prev
        if x0!=-1:
            left[x0]-=1
            left[y0]+=1
            if left[x0]==0:
                ans=[]
                break
            left[x0]-=1
            left[y0]+=1
            ans[len(ans)-1]="ABC"[y0]
        else:
            ans=[]
            break
    if left[x]>left[y]:
        x,y=y,x
    left[x]+=1
    left[y]-=1
    ans.append("ABC"[x])
    prev=(x,y)

if len(ans)==0:
    print("No")
else:
    print("Yes")
    for x in ans:
        print(x)

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

using namespace std;

int c[10][10];

int main() {
    int N;
    string s;
    cin >> N;
    cin >> s;
    vector<int> p = {0, 1, 2, 3, 4, 5, 6, 7, 8};
    for (int i = 0; i + 1 < s.size(); i++) {
        c[s[i] - '1'][s[i + 1] - '1']++;
    }

    vector<int> bst;
    int ans = 1e9;
    do {
        int d[10][10] = {};
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                int y = i / 3 - j / 3;
                int x = i % 3 - j % 3;
                d[p[i]][p[j]] = abs(x) + abs(y);
            }
        }
        int cst = 0;
        for(int i = 0 ; i < 9 ; i++)
            for(int j = 0 ; j < 9 ; j++)
                cst += c[i][j] * d[i][j];
        if( ans > cst ){
            ans = cst;
            bst = p;
        }

    } while (next_permutation(p.begin(), p.end()));

    for(int i = 0 ; i < 3 ; i++){
        for(int j = 0 ; j < 3 ; j++){
            cout << bst[i*3+j]+1 << (j+1==3 ? "\n" : "");
        }
    }


}


Measured memory_bytes: 3316
#include<cstdio>
#include<algorithm>
using namespace std;
int H, W;
int n;
int r0, c0;
char S[200200], T[200200];
int main()
{
	scanf("%d%d%d", &H, &W, &n);
	scanf("%d%d", &r0, &c0);
	scanf("%s%s", &S[1], &T[1]);
	int sr = 1, er = H, sc = 1, ec = W; // safe area at the end
	bool flag = false;
	for (int i = n; i >= 1; i--)
	{
		if (T[i] == 'L') ec++; // extend safe area to right
		else if (T[i] == 'R') sc--; // to left
		else if (T[i] == 'U') er++; // to below
		else sr--; // to above
		sr = max(1, sr); sc = max(1, sc);
		er = min(H, er); ec = min(W, ec);

		if (S[i] == 'L') sc++; // shrink safe area from left
		else if (S[i] == 'R') ec--; // from right
		else if (S[i] == 'U') sr++; // from above
		else er--; // from below
		if (sc > ec || sr > er) { flag = true; break; }
	}
	if (!flag && sr <= r0 && r0 <= er && sc <= c0 && c0 <= ec) printf("YES\n");
	else printf("NO\n");
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N;
  cin >> N;
  for(ll i = 0; i <= N; i++) {
    if((long)(i * 1.08) == N) {
      cout << i << endl;
      break;
    }
    if(i == N) cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

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

    int n;
    string s;

    map <string, int> mp;

    cin >> n >> s;

    char check = s[s.size()-1];

    mp[s] = 1;

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

        cin >> s;

        if (s[0] != check || mp[s]) {

            cout << "No";
            return 0;
        }

        check = s[s.size()-1];
        mp[s] = 1;
    }

    cout << "Yes";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char* argv[])
{
	int x = 0, y = 0;
	scanf("%d %d", &x, &y);

	if (x > y) {
		int tmp = x;
		x = y;
		y = tmp;
	}

	while (1) {
		int mod = x % y;
		if (mod == 0) {
			break;
		} else {
			x = y;
			y = mod;
		}
	}
	printf("%d\r\n", y);

	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=100010;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,t[maxn],ans;
string str[maxn],s;
int main(){
	cin>>n;
	FOR(i,1,n) cin>>str[i]>>t[i];
	cin>>s;
	ROF(i,n,1){
		if(s==str[i]) break;
		ans+=t[i];
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
long long L[100];
int N;
int main()
{
    cin>>N;
    L[0]=L[1]=1;L[0]++;
    for(int i=2;i<=N;i++)
        L[i]=L[i-1]+L[i-2];
    cout<<L[N];
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
string s;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> s;
    int cnt = 0, left = 0;
    rep(i, 0, n) {
        if (s[i] == '(') cnt++;
        else {
            if (cnt != 0) cnt--;
            else left++;
        }
    }
    rep(i, 0, left) cout << "(";
    cout << s;
    rep(i, 0, cnt) cout << ")";
    cout << '\n';
    return 0;
}


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

const int maxn = 110;

int n;
vector<int> a;
int aScore;
int bScore;

int main() {

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

  cin >> n;
  for (int i = 0; i < n; i++) {
    int temp; cin >> temp;
    a.push_back(temp);
  }

  sort(a.begin(), a.end(), greater<int>());

  for (int i = 0; i < n; i++) {
    if (i%2 == 0) {
      aScore += a[i];
    } else {
      bScore += a[i];
    }
  }

  cout << (aScore - bScore) << endl;

  return 0;
}


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

typedef struct Bomb
{
	int map[8][8];
	int x, y;
} BOMB;

int x_cnt, y_cnt;

Input(BOMB *);
BOMB *explode(BOMB *);	/*Recursion*/

int main()
{
    int input_times, input_cnt;
    BOMB Bomb[50];
    
    scanf("%d", &input_times);
    input_cnt = 0;
    while(input_cnt < input_times)
    {
		Input(&Bomb[input_cnt]);
		explode(&Bomb[input_cnt]);
		input_cnt++;
	}
    
    /*Output*/
    input_cnt = 0;
    while(input_cnt < input_times)
    {
    	printf("Data %d:\n", input_cnt + 1);
    	for(y_cnt = 0; y_cnt < 8; y_cnt++)
		{
			for(x_cnt = 0; x_cnt < 8; x_cnt++)
			{
				printf("%d", Bomb[input_cnt].map[x_cnt][y_cnt]);
			}
			printf("\n");
		}
    	input_cnt++;
	}
    

    
    return 0;
} 

Input(BOMB *bomb)
{
	/*Read input map*/
	char dump;		/*Get rid of enter*/
	dump = getchar();
	for(y_cnt = 0; y_cnt < 8; y_cnt++)
	{
		dump = getchar();
		for(x_cnt = 0; x_cnt < 8; x_cnt++)
			bomb->map[x_cnt][y_cnt] = getchar() - 48;	/*ASCII table*/
	}
	/*Read first explosion*/
	scanf("%d", &(bomb->x));
	scanf("%d", &(bomb->y));
	bomb->map[(bomb->x) - 1][(bomb->y) - 1] = 2;
}

BOMB* explode(BOMB* bomb_map)
{
	int explode_cnt;
	for(y_cnt = 0; y_cnt < 8; y_cnt++)
		for(x_cnt = 0; x_cnt < 8; x_cnt++)
		{
			/*Find exploded bomb and process*/
			if(bomb_map->map[x_cnt][y_cnt] == 2)
			{
				bomb_map->map[x_cnt][y_cnt] = 0;
				/*Left*/
				explode_cnt = 1;
				while((x_cnt - explode_cnt) >= 0 && explode_cnt <= 3)
				{
					if((bomb_map->map[x_cnt - explode_cnt][y_cnt]) == 1)
						(bomb_map->map[x_cnt - explode_cnt][y_cnt]) = 2;
					explode_cnt++;
				}
				/*Right*/
				explode_cnt = 1;
				while((x_cnt + explode_cnt) <= 7 && explode_cnt <= 3)
				{
					if((bomb_map->map[x_cnt + explode_cnt][y_cnt]) == 1)
						(bomb_map->map[x_cnt + explode_cnt][y_cnt]) = 2;
					explode_cnt++;
				}
				/*Down*/
				explode_cnt = 1;
				while((y_cnt - explode_cnt) >= 0 && explode_cnt <= 3)
				{
					if((bomb_map->map[x_cnt][y_cnt - explode_cnt]) == 1)
						(bomb_map->map[x_cnt][y_cnt - explode_cnt]) = 2;
					explode_cnt++;
				}
				/*Up*/
				explode_cnt = 1;
				while((y_cnt + explode_cnt) <= 7 && explode_cnt <= 3)
				{
					if((bomb_map->map[x_cnt][y_cnt + explode_cnt]) == 1)
						(bomb_map->map[x_cnt][y_cnt + explode_cnt]) = 2;
					explode_cnt++;
				}
				return explode(bomb_map);
			}
		}
	return bomb_map;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int h,w;
    cin >> h >> w;
    char s[h+1][w+1];
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(s[i][j] == '.'){
                int num = 0;
                if(s[i][j+1] == '#') num++;
                if(s[i+1][j+1] == '#') num++;
                if(s[i+1][j] == '#') num++;
                if(s[i][j-1] == '#') num++;
                if(s[i+1][j-1] == '#') num++;
                if(s[i-1][j] == '#') num++;
                if(s[i-1][j+1] == '#') num++;
                if(s[i-1][j-1] == '#') num++;
                cout << num;
            }else{
                cout << '#';
            }
        }
        cout << endl;
    }
}

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

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template <typename T> using orderMSet =
//tree <T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long llu;
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout)
#define inf 1000000000000000018
#define mod 1000000007
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>

int main()
{
	ll x, ans;
	cin>>x;

	ans = 1000*(x/500);
    x %= 500;

    ans += 5*(x/5);
    x %= 5;

    cout<<ans<<endl;
}


Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int digitsum(int m){
    int z=0;
    while (m!=0){
        z+=m%10;
        m/=10;
    }
    return z;
}
int main()
{
    int n;
    cin>>n;
    int b,k;
    int ans=10000000;
    for (int a=1;a<n;a++){
        b=n-a;
        k=digitsum(b)+digitsum(a);
        if (k<ans){
            ans=k;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
/* Insertion Sort */
#include <stdio.h>

void trace(int A[], int N)
{
    int i;
    for(i=0; i<N; i++){
        if(i>0){ printf(" "); }
        printf("%d", A[i]);
    }
    printf("\n");
}

int main()
{
    int N, i, j, v;
    int A[100];

    scanf("%d", &N);
    for(i=0; i<N; i++){
        scanf("%d", &A[i]);
    }
    trace(A, N);
    for(i=1; i<N; i++){
        v = A[i];
        j = i-1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A, N);
    }
    return 0;
}


Measured memory_bytes: 2040
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> dp(n + 1, n * 2);
    dp[0] = 0;
    dp[1] = 1;
    for (int i = 6; i <= n; i *= 6) {
        dp[i] = 1;
    }
    for (int i = 9; i <= n; i *= 9) {
        dp[i] = 1;
    }
    for (int i = 2; i <= n; ++i) {
        dp[i] = min(dp[i], dp[i - 1] + 1);
        for (int j = 6; i >= j; j *= 6) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
        for (int j = 9; i >= j; j *= 9) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 640
a=int(input())
b=list(input())
c=[]
h=[]
for k in range(0,a-1):
	d=[]
	c.append(b[k])
	for i in range(k+1,a):
		d.append(b[i])
#	print(c)
#	print(d)
	e=[]
	for i in c:
		if i not in e:
			e.append(i)
#	print(e)

	f=[]
	for i in d:
		if i not in f:
			f.append(i)
#	print(f)

	g=0
	for l in range(len(e)):
		for i in range(len(f)):
			if e[l]==f[i]:
				g=g+1
	h.append(g)
#print(h)
print(max(h))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>

#define mod 1000000007
#define REP(i,n) for(int i=0; i<n; i++)

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

int h, w;
char s[55][55];

int neighborSearch(int x, int y){
    int c = 0;
    for(int i = 0; i < 8; i++){
        if(s[x+X[i]][y+Y[i]] == '#'){
            c++;
        }
    }
    return c;
}

void solve() {
    cin >> h >> w;
    for(int i = 1; i < h+1; i++){
        for(int j = 1; j < w+1; j++){
            cin >> s[i][j];
        }
    }

    for(int i = 1; i < h+1; i++){
        for(int j = 1; j < w+1; j++){
            if(s[i][j] == '.'){
                cout << neighborSearch(i, j);
            }else{
                cout << s[i][j];
            }
        }
        cout << endl;
    }
}

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

Measured memory_bytes: 256
a, b, c = map(int, input().split())
# a + b + 2(ab)**0.5 < c
# c - a - b > 2(ab)**-.5
tmp = c - a - b
if tmp < 0 :
    print("No")
    exit()
if tmp ** 2 > 4 * a * b:
    print("Yes")
else:
    print("No")

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

int main() {
	
	//解説PDFを見ました(迫真)
	//速度の様子うかがい

	int N;
	string S;
	cin >> N >> S;

	map<string, int> GOD;

	rep(i, 1 << N) {
		string blue;
		string red;
		rep(ii, N) {
			if (i >> ii & 1) {
				blue += S[ii];
			}
			else {
				red += S[ii];
			}
		}
		GOD[blue + "," + red]++;
	}
	long long kotae = 0;
	rep(i, 1 << N) {
		string blue2;
		string red2;
		rep(ii, N) {
			if (i >> ii & 1) {
				blue2 += S[2 * N - ii - 1];
			}
			else {
				red2 += S[2 * N - ii - 1];
			}
		}
		kotae += GOD[blue2 + "," + red2];
	}
	cout << kotae << "\n";
	Would you please return 0;

}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li n, k;
    cin >> n >> k;
    if (k == 1) {
        cout << 0 << endl;
    } else {
        cout << n - k << endl;
    }

    return 0;
}

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


const int MAXN = 1e5;

std::vector<int> graph[MAXN];
int longest[MAXN];


int computelong(int node)
{
    if (longest[node] == -1)
    {
        longest[node] = 0;
        for (int neighbor : graph[node])
            longest[node] = std::max(longest[node], computelong(neighbor) + 1);
    }
    
    return longest[node];
}

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

    int nodes, edges;
    std::cin >> nodes >> edges;

    std::fill_n(longest, nodes, -1);
    for (int iEdge = 0; iEdge < edges; iEdge++)
    {
        int start, end;
        std::cin >> start >> end;
        graph[start - 1].emplace_back(end - 1);
    }

    int longSize = 0;
    for (int iNode = 0; iNode < nodes; iNode++)
        longSize = std::max(longSize, computelong(iNode));
    std::cout << longSize << '\n';

    return 0;
}


Measured memory_bytes: 7552