akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int cnt;
int a[1000000];

void insertionSort( int A[], int n, int g ){
 for( int i=g; i<n; i++ ){
   int v = A[i];
   int j = i-g;
   while( j>=0 && A[j] > v ){
     A[j+g] = A[j];
     j = j-g;
     cnt++;
     A[j+g] = v;
   }
 }
}

void shellSort( int A[], int n ){
 cnt = 0;
 vector<int> G;
 for( int r=1; r<=n; r=3*r+1 ){
   G.push_back(r);
 }

 int m = G.size();
 cout << m << endl;

 for( int h=m-1; h>=0; h-- ){
   if( h!=0 ){
     cout << G[h] << " ";
   }else{
     cout << G[h] << endl;
   }
 }

 for( int i=m-1; i>=0; i-- ){
   insertionSort( A, n, G[i] );
 }
}

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

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

 shellSort( a, n );

 cout << cnt << endl;

 for( int j=0; j<n; j++ ){
   cout << a[j] << endl;
 }

 return 0;
}


Measured memory_bytes: 7032
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
//#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i <= n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i <= n; i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }

map<ll, ll> prime_factorial(ll n) {

    map<ll,ll> ret;

    for(ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while (n % i == 0) {
                ret[i]++;
                n /= i;
            }
        }
    }

    if(n > 1) { ret[n]++; }

    return ret;
}

int main(void)
{
    ll a, b;
    cin >> a >> b;
    
    ll c = gcd(a, b);

    map<ll, ll> ans = prime_factorial(c);

    cout << ans.size() + 1 << endl;
    return 0;
}
/** atcoder **/


Measured memory_bytes: 256
// created on : Tue Jun 23 2020
 
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        int k = in.nextInt();
        String s = in.next();
        if(s.length() <= k){
            println(s);
        }
        else{
            println(s.substring(0, k) + "...");
        }
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static int[] readInt(int N) throws IOException { 
    	int arr[] = new int[N];
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    	return arr;
    }
    
    static long[] readLong(int N) throws IOException { 
    	long arr[] = new long[N];
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    	return arr;
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i] + " "); 
    	} 
    	println(""); 
    }
    
    static void displayRuntime(long startTime){
        long stopTime = System.currentTimeMillis();
        long elapsedTime = stopTime - startTime;
        System.out.println("Runtime: " + elapsedTime / 1000D);
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}


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

using namespace std;

int main()
{
  int K;
  vector<long long> vec;
  cin >> K;
  for(int i=1; i<=9;i++){
    vec.push_back(i);
  }
  for(int i=0;i<K;i++){
    if(vec[i]%10-1!=-1){
      vec.push_back(vec[i]*10+vec[i]%10-1);
    }
    vec.push_back(vec[i]*10+vec[i]%10);
    if(vec[i]%10+1!=10){
      vec.push_back(vec[i]*10+vec[i]%10+1);
    }
  }
  cout << vec[K-1] << endl;
  return 0;
}

Measured memory_bytes: 6384
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

class UnionFind {
  vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
  void init(ll n) {
    par.resize(n, 1); rank.resize(n, 0);
  }
  ll getSize(ll x) {
    return par[find(x)];
  }
  ll find(ll x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(ll x, ll y) {
    return find(x) == find(y);
  }
};
ll N,M;
ll firstL[100010];
int main(){
    cin>>N>>M;
    UnionFind uf;
    uf.init(M);
    for(ll i=0;i<N;i++){
        ll k;cin>>k;
        ll pre;cin>>pre;
        firstL[i]=pre;
        for(ll i=0;i<k-1;i++){
            ll l;cin>>l;
            uf.merge(pre,l);
            pre=l;
        }
    }
    ll group=uf.find(firstL[0]);
    for(ll i=1;i<N;i++){
        if(uf.find(firstL[i])!=group){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}

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

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

using namespace std;



int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> x(n);
    vector<ll> y(m);
    rep(i, n)   cin >> x[i];
    rep(i, m)   cin >> y[i];
    ll mod = pow(10, 9) + 7;

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    ll sum = 0;

    vector<ll> xlens(n);
    rep(ix, n-1)    xlens[ix] = (x[ix+1] - x[ix]) % mod;
    vector<ll> ptXs(n);
    rep(ix, n-1)    ptXs[ix] = ((1+ix) * (n-ix-1)) % mod;

    vector<ll> ylens(m);
    rep(iy, m-1)    ylens[iy] = (y[iy+1] - y[iy]) % mod;
    vector<ll> ptYs(m);
    rep(iy, m-1)    ptYs[iy] = ((1+iy) * (m-iy-1)) % mod;

    ll yRes = 0;
    rep(iy, m-1){
        yRes += (ylens[iy] * ptYs[iy]) % mod;
        yRes %= mod;
    }


    rep(ix, n-1){
        ll tmp = yRes;
        tmp *= xlens[ix];
        tmp %= mod;
        tmp *= ptXs[ix];
        tmp %= mod;
        sum += tmp;
        sum %= mod;
    }

    cout << sum << endl;

    


    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double a, b;
    cin >> a >> b;
    double l = max(a * 100.0 / 8.0, b * 100.0 / 10.0);
    double r = min((a + 1) * 100.0 / 8.0, (b + 1) * 100.0 / 10.0);
    int L, R;
    if(l - (int)l < EPS) {
        L = (int)l;
    } else {
        L = (int)l + 1;
    }
    if(r - (int)r < EPS) {
        R = r - 1;
    } else {
        R = (int)r;
    }
    if(L <= R) {
        cout << L << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
//default
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int N,ans=1,dir=0;
  cin >> N;
  int A[N];
  rep(i,N){
    cin >> A[i];
  }
  if(A[0]<A[1]) dir=1;
  else if(A[0]>A[1]) dir=0;
  else dir=2;
  for(int i=2;i<N;i++){
    if(A[i-1]<A[i]){
      if(dir==0){
        ans++;
        dir=2;
      }
      else dir=1;//up
    }
    if(A[i-1]>A[i]){
      if(dir==1){
        ans++;
        dir=2;
      }
      else dir=0;//down
    }
  }
  answer
  return 0;
}


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

int main()
{
	int N,Y;
	int x,y,z;
	
	cin>>N>>Y;
	
	for(x=0; x<=Y/10000; x++)
	   for(y=0; y<=Y/5000; y++)
	   {
	   	if(N>=x+y)
		{z=N-x-y;
	   	if(x*10000+y*5000+z*1000==Y)
	   	{
	   		cout<<x<<" "<<y<<" "<<z<<endl;
	   		return 0;
	   	}
	    }
	   }
	   
	cout<<"-1 -1 -1"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
 
int main(){
  int N;
  cin>>N;
  vector<string> W(N);
  rep(i,N) cin>>W[i];
  bool ja=true;
  for(int i=1;i<N;i++){
    if(W[i-1][W[i-1].length()-1]!=W[i][0]){
      ja=false;
    }
  }
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(W[i]==W[j]){
        ja=false;
      }
    }
  }
  if(ja){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define pb push_back
#define in(x) int x; cin>>x;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define mod 1000000007
using namespace std;

//int gcd(int a, int b){
//	return b==0 ? a : gcd(b, a%b);
//}

int32_t main(void){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	
	in(n);
	in(m);
	char arr[n+1][m+1];
	int dp[n+1][m+1];
	rep(i, 0, n+1) dp[i][0] = 0;
	rep(j, 1, m+1) dp[0][j] = 0;
	
	rep(i, 1, n+1)
	{
		rep(j, 1, m+1)
		{
			cin>>arr[i][j];
			dp[i][j] = 0;
			if(arr[i][j] != '#')
			{
				if(i == 1 || j == 1)
				{
					if(i == 1 && j == 1) dp[i][j] = 1;
					else if(dp[i-1][j] == 1 || dp[i][j-1] == 1) dp[i][j] = 1;
					else dp[i][j] = 0;
				}
				else dp[i][j] += dp[i-1][j] + dp[i][j-1];
				dp[i][j] = dp[i][j]%mod;
			}
		}
	}
	cout<<dp[n][m]%mod;
}

Measured memory_bytes: 9088
# -*- coding: utf-8 -*-
N, K = map(int, input().split(' '))
X = list(map(int, input().split(' ')))

ans = 10**11
for left in range(N-K+1):
    right = left+K-1

    left, right = X[left], X[right]
    if left < 0 and right > 0:
        dist = min(abs(left), abs(right)) * 2 + max(abs(left), abs(right))
    else:
        dist = max(abs(left), abs(right))

    # print(dist)
    ans = min(ans, dist)

print(ans)


Measured memory_bytes: 57940
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <string>
#include "math.h"

using namespace std;

string checker = "2019/04/30";

int main() {
    
    string a;
    
    cin >> a;
    
    if (a <= checker) {
        cout << "Heisei" <<endl;
    } else {
        cout << "TBD" << endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 256
while True:
    m, f, r = map(int, input().split())
    if m==f==r==-1:
        break
    if m<0 or f<0:
        print('F')
    elif m+f>=80:
        print('A')
    elif m+f>=65:
        print('B')
    elif m+f>=50:
        print('C')
    elif m+f>=30:
        if r>=50:
            print('C')
        else:
            print('D')
    else:
        print('F')



Measured memory_bytes: 5592
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
n = int(input())
b = [int(input()) for i in range(n)]
ans = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
tmp = []
for i in range(3):
    for j in range(len(b)):
        if b[j] == A1[i]:
            A1[i] = 0
        elif b[j] == A2[i]:
            A2[i] = 0
        
        elif b[j] == A3[i]:
            A3[i] = 0


if sum(A1) == 0 or sum(A2) == 0 or sum(A3) == 0:
    print("Yes")

elif A1[0]+A2[0]+A3[0] == 0 or A1[1]+A2[1]+A3[1] == 0 or A1[2]+A2[2]+A3[2] == 0:
    print("Yes")

elif A1[0]+A2[1]+A3[2] == 0 or A1[2]+A2[1]+A3[0] == 0:
    print("Yes")

else:
    print("No")



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;



int main(){
	cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    string s,t;
    cin >> s >> t;
    cout << t+s << endl;
    return 0;
    
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<double,double>P;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    (a+b+c)>21 ? cout<<"bust" : cout<<"win";
}

Measured memory_bytes: 256
def g;gets.split.map &:to_i;end
while(m,n=g)[0]>0
a=(1..g[0]).map{|i|g<<i}
p (1..g[0]).map{d=a+[c=g<<11]
(0..m*n-1).count{|k|i=k/n+1;j=k%n+1
d.min_by{|x,y,t|z=(y-j).abs
[z+[(x-i).abs-(z+(i<x ?1-j%2:j%2))/2,0].max,t]}==c}}.max
end

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

  vector<int> a(n);

  //vectorに全入力値を代入する
  rep(i,n) cin >> a[i];

  rep(i,n) for(int j = i+1; j < n; ++j){
      ans += a[i] * a[j];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
 
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a;
	cin>>a;
	string s;
	cin>>s;
	if(a<3200) cout<<"red"<<endl;
	else cout<<s<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			Map<Character, Long> map = new HashMap<>();

			for (int i = 0; i < n; i++) {
				char s = in.nextString().charAt(0);
				if (s == 'M' || s == 'A' || s == 'R' || s == 'C' || s == 'H') {
					map.merge(s, 1L, Long::sum);
				}
			}

			List<Long> list = new ArrayList<>(map.values());

			long ans = 0;
			int len = list.size();
			for (int i = 0; i < len; i++) {
				for (int j = i+1; j < len; j++) {
					for (int k = j+1; k < len; k++) {
						ans += list.get(i) * list.get(j) * list.get(k);
					}
				}
			}

			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}

Measured memory_bytes: 39384
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
            System.out.println("Case " + (i + 1) + ":");
            int x = Integer.parseInt(br.readLine());
            for (int j = 0; j < 10; j++) {
                String s = String.format("%8s", String.valueOf(x * x)).replaceAll(" ", "0");
                x = Integer.parseInt(s.substring(2, 6));
                System.out.println(x);
            }
        }
    }
}


Measured memory_bytes: 24752
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0)
                break;
            Map<String, Long> price = new HashMap<String, Long>();
            String[] item = new String[n];
            for (int i = 0; i < n; i++) {
                item[i] = sc.next();
                price.put(item[i], sc.nextLong());
            }
            int m = sc.nextInt();
            for (int i = 0; i < m; i++) {
                String o = sc.next();
                int k = sc.nextInt();
                int sum = 0;
                for (int j = 0; j < k; j++) {
                    String name = sc.next();
                    if (price.containsKey(name))
                        sum += price.get(name);
                }
                price.put(o, Math.min(sum, price.get(o)));
            }
            String ord = sc.next();
            System.out.println(price.get(ord));
        }
    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }
}

Measured memory_bytes: 12000
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int a,b,c,d;
  std::cin >> a >> b >> c >> d;
  if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d))printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

Measured memory_bytes: 256
<?php
	$n=fgets(STDIN);
	for($i=0;$i<$n;$i++)$a[]=fgets(STDIN)-1;
	$s=0;
	for($i=0;$i++<$n;)
	{
		$s=$a[$s];
		if($s==1)break;
	}
	echo $i>$n?-1:$i;


Measured memory_bytes: 18036
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = input().strip()
n = int(n[-1])

if n in (2, 4, 5, 7, 9):
    print('hon')

if n in (0, 1, 6, 8):
    print('pon')

if n == 3:
    print('bon')


Measured memory_bytes: 61856
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    double solve(vector<int>& X, vector<int>& Y, string& dir) {
        int n = X.size();

        vector<int> dx(n, 0);
        vector<int> dy(n, 0);
        for (int i = 0; i < n; ++i) {
            if (dir[i] == 'L') {
                dx[i] -= 1;
            } else if (dir[i] == 'R') {
                dx[i] += 1;
            } else if (dir[i] == 'U') {
                dy[i] += 1;
            } else {
                dy[i] -= 1;
            }
        }

        auto calc = [&](double T) {
            const double INF = 1e20;
            double l = INF;
            double r = -INF;
            double t = -INF;
            double b = INF;
            for (int i = 0; i < n; ++i) {
                double x = X[i], y = Y[i];
                x += dx[i] * T;
                y += dy[i] * T;
                l = min(l, x);
                r = max(r, x);
                b = min(b, y);
                t = max(t, y);
            }
            // cout << l << " " << r << " " << t << " " << b << " " << T << endl;
            double res = (r - l) * (t - b);
            return res;
        };

        double res = 1e20;
        double lo = 0, hi = 1e9;
        for (int i = 0; i < 200; ++i) {
            auto l = lo + (hi - lo) / 3;
            auto r = hi - (hi - lo) / 3;

            if (calc(l) >= calc(r)) {
                lo = l;
            } else {
                hi = r;
            }
        }

        res = calc(lo);

        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    vector<int> X(n);
    vector<int> Y(n);
    string D;
    for (int i = 0; i < n; ++i) {
        int x, y;
        char d;
        cin >> x >> y >> d;
        X[i] = x;
        Y[i] = y;
        D += d;
    }

    Solution sol;
    cout << sol.solve(X, Y, D) << "\n";


    return 0;
}

Measured memory_bytes: 2048
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cout << #x << " = " << x << endl;
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();    
    return 0;
}
 
const int MOD = 998244353, MAXN = 5e5 + 10, INF = 1e18 + 10, BASE = 37; 

void solve() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
using namespace std;
string s;
int dp[1<<26],c[1<<18];
main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		c[i+1]=c[i]^(1<<(s[i]-'a'));
	}
	int a=1e9;
	for(int i=0;i<s.size();i++)
	{
		a=dp[c[i+1]]||!c[i+1]?dp[c[i+1]]+1:1e9;
		for(int j=1;j<1<<26;j<<=1)a=dp[c[i+1]^j]||!(c[i+1]^j)?min(a,dp[c[i+1]^j]+1):a;
		dp[c[i+1]]=dp[c[i+1]]||!c[i+1]?min(dp[c[i+1]],a):a;
	}
	cout<<a<<endl;
}


Measured memory_bytes: 263172
#include<bits/stdc++.h>
using namespace std;
int main()
{
   char A,B,C,D,E,F,x,y;
   cin>>x>>y;
   A=10;
   B=11;
   C=12;
   D=13;
   E=14;
   F=15;
if(x>y)
{
    cout<<">";
}
else if(x<y)
{
    cout<<"<";
}
else if(x==y)
{
    cout<<"=";
}




    return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

void compute() {

}

ll sum[1010];
int main() {
  int n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
  }
  sum[0] = a[0];
  REP(i,1,n) sum[i] = sum[i-1] + a[i];
  vector<ll> vec;
  rep(i,n) {
    REP(j,i,n) {
      ll v = sum[j];
      if( i - 1 >= 0 ) v -= sum[i-1];
      vec.push_back(v);
    }
  }
  ll ans = 0;
  for(int bit=40;bit>=0;--bit) {
    vector<ll> nex;
    rep(i,(int)vec.size()){
      if( (vec[i]>>bit) & 1LL ) {
	nex.push_back(vec[i]);
      }
    }
    if( (int)nex.size() >= k ) {
      vec = nex;
      ans = ans | (1LL<<bit);
    }
  }
  cout << ans << endl;
  compute();
  return 0;
}


Measured memory_bytes: 6516
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext())
		{
			int n=sc.nextInt();
			if(n==0)
				return;
			int a[]= new int[n];
			int b[]= new int[n];

			int j=0;
			while(n-->0)
			{
				a[j] = sc.nextInt();
				b[j] = sc.nextInt()*60+sc.nextInt()+sc.nextInt()*60+sc.nextInt()+sc.nextInt()*60+sc.nextInt()+sc.nextInt()*60+sc.nextInt();
				j++;
			}
			
			for(int i=0; i<b.length; i++)
			{
				int m=i;
				for(int k=i+1; k<b.length; k++)
				{
					if(b[m] >b[k])
						m=k;
				}
				int tmp = b[i];
				int tmp2 =a[i];
				b[i]= b[m];
				a[i]=a[m];
				b[m] = tmp;
				a[m]=tmp2;
			}
			System.out.println(a[0]);
			System.out.println(a[1]);
			System.out.println(a[a.length-2]);
		}
	}
}

Measured memory_bytes: 13000
#include<cstdio>
#include<cmath>
int max(int x,int y) {return x>y?x:y;}
int main() 
{
	int n,m,ans=0;scanf("%d%d",&n,&m);
	for(int i=1;i<=sqrt(m);i++)
	if(m%i==0)
	{
		if(i>=n) ans=max(ans,m/i);
		if(m/i>=n) ans=max(ans,i);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int h,w,n;
pair<int,int> p[MAXN]; int np;
bool getp(int x,int y,int &res) {
	if(y==0) { res=x; return true; }
	if(x==h) { res=h+y; return true; }
	if(y==w) { res=h+w+(h-x); return true; }
	if(x==0) { res=h+w+h+(w-y); return true; }
	return false;
}

int pp[2*MAXN]; int npp;

int bit[2*MAXN+1];
int bget(int idx) { ++idx; int ret=-1; while(idx>0) { ret=max(ret,bit[idx]); idx-=idx&-idx; } return ret; }
void bset(int idx,int val) { ++idx; while(idx<=npp) { bit[idx]=max(bit[idx],val); idx+=idx&-idx; } }

void run() {
	np=0;
	scanf("%d%d%d",&h,&w,&n);
	REP(i,n) {
		int sx,sy,tx,ty; scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
		int sp,tp; if(!getp(sx,sy,sp)||!getp(tx,ty,tp)) continue; if(sp>tp) swap(sp,tp);
		p[np++]=MP(sp,tp);		
	}
	npp=0; REP(i,np) pp[npp++]=p[i].first,pp[npp++]=p[i].second; sort(pp,pp+npp); npp=unique(pp,pp+npp)-pp;
	REP(i,np) p[i].first=lower_bound(pp,pp+npp,p[i].first)-pp;
	REP(i,np) p[i].second=lower_bound(pp,pp+npp,p[i].second)-pp;
	sort(p,p+np);
	//REP(i,np) printf("(%d,%d)",p[i].first,p[i].second); puts("");
	memset(bit,0,sizeof(bit));
	for(int i=np-1;i>=0;--i) {
		if(bget(p[i].second)>=p[i].second) { printf("NO\n"); return; }
		bset(p[i].first,p[i].second);
	}
	printf("YES\n");
}

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


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>

#define MAX 100
#define INFTY 1<<30 // 2^30
#define N 4
#define N2 16  // N * N
#define REP(i,n) for(int i=0;i<n;i++)

/*
priority_queue<> pq
 push()  pop() size()  top()
map<>
 find() begin() end() insert(map<>::value_type())
pair<>
sort(.begin(), .end())
sort(arr, arr+N)
sort(a, a+N, greater<int>())
binary_search(vc.begin(), vc.end(), x)  //binary_search???true, false?????????
vector<int>::iterator lit = lower_bound(vc.begin(), vc.end(), x);
  lower_bound?????????????????????"??\???"????????????????????????????????????????????¬???????????????
vector<int>::iterator uit = upper_bound(vc.begin(), vc.end(), x);
  upper_bound????????????????????????"?¶???????"?????????????????????????????????????????¬???????????????
*/


using namespace std;

typedef long long llong;

struct Puzzle
{
  int f[N2];
  int space, MD;
  bool operator < (const Puzzle &p) const
  {
    for(int i = 0; i < N2; i++)
    {
      if(f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

Puzzle state;
int limit;
int path[MAX];
int MDT[N2][N2];

int getAllMD(Puzzle pz)
{
  int sum = 0;
  REP(i,N2)
  {
    if(pz.f[i] == N2) continue;
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}

bool isSolved()
{
  for(int i = 0; i < N2; i++)
    if(state.f[i] != (i + 1)) return false;
  return true;
}

bool dfs(int depth, int prev)
{
  //cout << depth << "  " << prev << endl;
  if(state.MD == 0) return true;
  if(depth + state.MD > limit) return false;

  int sx = state.space / N;
  int sy = state.space % N;
  Puzzle tmp;
  REP(r,4)
  {
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
    if(abs(prev-r) == 2) continue;
    tmp = state;

    state.MD -= MDT[tx*N+ty][state.f[tx*N+ty]-1];
    state.MD += MDT[sx*N+sy][state.f[tx*N+ty]-1];
    swap(state.f[tx*N+ty], state.f[sx*N+sy]);
    state.space = tx*N+ty;
    if(dfs(depth+1,r)){path[depth] = r; return true;}
    state = tmp;
  }
  return false;
}

string iterative_deepening(Puzzle in)
{
  in.MD = getAllMD(in);
  for(limit = in.MD; limit <= MAX; limit++)
  {
    state = in;
    if(dfs(0,-100))
    {
      string ans = "";
      REP(i, limit) ans += dir[path[i]];
      return ans;
    }
  }
  return "unsolvable";
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // FROM HERE
  REP(i,N2)
    REP(j,N2)
      MDT[i][j] = abs(i/N - j/N) + abs(i%N - j%N);

  Puzzle in;
  for(int i = 0; i < N2; i++)
  {
    cin >> in.f[i];
    if(in.f[i] == 0)
    {
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = iterative_deepening(in);
  cout << ans.size() << endl;
  //cerr << ans << endl;
  // END
  return 0;
}

Measured memory_bytes: 1216
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    a = ni()
    print(a+a*a+a*a*a)
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 61624
while True:
    n=int(input())
    if n== 0:
        break
    
    A = list(map(int, input().split()))
    c = [[0]*n for _ in range(n)]
    for i in range(n):
        c[i][i] = 0
        
    for i in range(1, n):
        if i%2==0:
            continue
        for j in range(n-i):
            if i==1 and abs(A[j] - A[j+i])<=1:
                    c[j][j+i] = 1 
            else:
                for k in range(j+1, j+i-1):
                    #print(f'j:{j}, i:{i}, k:{k}, c[j][k]{c[j][k]} and c[k+1][j+i]{c[k+1][j+i]}')
                    if c[j][k] and c[k+1][j+i]:
                        c[j][j+i] = 1
                        break
                if c[j+1][j+i-1] and abs(A[j] - A[j+i])<=1:
                    c[j][j+i] = 1
    
    dp = [[0]*n for _ in range(n)]
    
    for i in range(1):
        for j in range(i, n):
            if c[i][j]:
                dp[i][j] = j-i+1
            else:
                for k in range(i, j):
                    if c[k+1][j]:
                        dp[i][j] = max(dp[i][j], dp[i][k] + j-k)
                if j>i:
                    dp[i][j] = max(dp[i][j], dp[i][j-1])
    
    print(dp[0][n-1])



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

int main()
{
	int n;
	while(cin >> n, n)
	{
		int p,d1,d2;
		int maxp,maxd=-1;
		while(n--)
		{
			cin >> p >> d1 >> d2;
			if(maxd < d1+d2)
			{
				maxp = p;
				maxd = d1+d2;
			}
		}

		cout << maxp << " " << maxd << endl;
	}
}

Measured memory_bytes: 864
#include<iostream>
#include<cctype>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cctype>
#include<cstring>
#include<utility>
#include<cmath>
using namespace std;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b)cout << c << endl;
    else if (b == c)cout << a << endl;
    else if (c == a)cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
a, b = map(int, raw_input().split())
cake = '1234567890123456'
for i in range(8):
	if a != 0:
		cake.replace(cake[2*1], 'o')
		a -= 1
	if b != 0:
		cake.replace(cake[2*1+1], 'x')
		b -= 1
if a != 0 or b != 0:
	print ':('
else :
	print 'Yay!'

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

int main() {
    int x, y; cin >> x >> y;
    for (int i = 0; i <= x; ++i) {
        int j = x - i;
        if (i * 2 + j * 4 == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3672
#include <iostream>
using namespace std;
int main() 
{
	int h[2], m[2], s[2], t, a[3][3], u, i;
	for (i = 0; i < 3; i++)
	{
		cin >> h[0] >> m[0] >> s[0] >> h[1] >> m[1] >> s[1];
		t = h[1]*3600 + m[1]*60 + s[1] - (h[0]*3600 + m[0]*60 + s[0]);
		a[i][0] = t/3600;
		a[i][1] = t%3600 / 60;
		a[i][2] = t%3600 % 60;
	}
	for (i = 0; i < 3; i++)
	{
		cout << a[i][0] << " " << a[i][1] << " " << a[i][2] << endl;
	}
}

Measured memory_bytes: 0
from operator import itemgetter


def main():
    N = int(input())
    SP = []
    for n in range(N):
        s, p = input().split()
        SP.append((n + 1, s, int(p)))
    SP = sorted(SP, key=itemgetter(2), reverse=True)
    SP = sorted(SP, key=itemgetter(1))
    for n, s, p in SP:
        print(n)


main()


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

vector<int> edge[100001];
vector<int> v[100001];
int val,dp[100001];
bool bad;
int dfss(int x,int p){
	int res=0;
	for(int i:edge[x]){
		if(i==p)	continue;
		res+=dfss(i,x);
	}
	return (edge[x].size()-1)/2+res;
}

int dfs(int x,int p){
	v[x].clear();
	for(int i:edge[x]){
		if(i==p)	continue;
		v[x].push_back(dfs(i,x)+1);
	}
	sort(v[x].begin(),v[x].end());
	dp[x]=0;
	if(v[x].size()&1){
		int L=0,R=v[x].size();
		while(L<R){
			int M=(L+R)/2,st=0,en=v[x].size()-1;
			dp[x]=0;
			while(st<en){
				if(st==M){
					st++;
					continue;
				}
				if(en==M){
					en--;
					continue;
				}
				dp[x]=max(dp[x],v[x][st++]+v[x][en--]);
			}
			if(dp[x]>val)
				L=M+1;
			else
				R=M;
		}
		if(R==v[x].size()){
			bad=true;
			return 0;
		}
		else{
			if(v[x][L]>val)
				bad=true;
			return v[x][L];
		}
	}
	else{
		for(int i=0;i<v[x].size();i++)
			dp[x]=max(dp[x],v[x][i]+v[x][v[x].size()-i-1]);
		if(dp[x]>val){
			if(x==1){
				bad=true;
				return 0;
			}
			if(v[x].back()>val){
				bad=true;
				return 0;
			}
			int L=0,R=v[x].size()-1;
			while(L<R){
				int M=(L+R)/2,st=0,en=v[x].size()-2;
				dp[x]=0;
				while(st<en){
					if(st==M){
						st++;
						continue;
					}
					if(en==M){
						en--;
						continue;
					}
					dp[x]=max(dp[x],v[x][st++]+v[x][en--]);
				}
				if(dp[x]>val)
					L=M+1;
				else
					R=M;
			}
			if(R==v[x].size()-1){
				bad=true;
				return 0;
			}
			else{
				return v[x][L];
			}
		}
		else
			return 0;
	}
}

bool check(int x){
	bad=false;
	val=x;
	dfs(1,0);
	if(bad)
		return false;
	else
		return true;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0,u,v;i<n-1;i++){
		cin>>u>>v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	int l=1,r=100000;
	while(l<r){
		int mid=(l+r)/2;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
	}
	cout<<dfss(1,0)+1<<' '<<l<<endl;
}


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

using namespace std;

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

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

ll d, m;

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

    cin >> m >> d;

    ll ans = 0;
    for (int i = 10; i <= d; ++i) {
        ll d1 = i % 10;
        ll d2 = (i / 10) % 10;
        if (d1 * d2 <= m && d1 * d2 != 0 && d1 >= 2 && d2 >= 2)
            ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double pi = acos(-1);

vector<pair<ll, ll>> prime_factor(ll N)
{
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1)
        res.push_back({N, 1});
    return res;
}

int main()
{
    int n;
    cin >> n;
    vector<int> dp(n + 1, INF);
    dp[0] = 0;
    for (int i = 0; i <= n; i++)
    {
        if (i + 1 <= n)
        {
            dp[i + 1] = min(dp[i + 1], dp[i] + 1);
        }
        int tmp = 6;
        for (int j = 0; j <= n; j++)
        {
            if (i + tmp <= n)
            {
                dp[i + tmp] = min(dp[i + tmp], dp[i] + 1);
            }
            else
            {
                break;
            }
            tmp *= 6;
        }
        tmp = 9;
        for (int j = 0; j <= n; j++)
        {
            if (i + tmp <= n)
            {
                dp[i + tmp] = min(dp[i + tmp], dp[i] + 1);
            }
            else
            {
                break;
            }
            tmp *= 9;
        }

        // debug_vec(dp);
    }
    cout << dp[n] << endl;
    // debug_vec(dp);

    return 0;
}


Measured memory_bytes: 3704
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000

int main(){
  string s;
  cin>>s;
  std::vector<ll> m(26,0);

  int n = s.size();
  int ans = n;

  rep(i,26){
    int j = 0;
    int t = 0;
    while(j<n){
      int c = 0;
      while(j<n && s[j] != i+ 'a'){j++;c++;}
      t = max(t,c);
      j++;
    }
    ans = min(ans,t);
  }

  cout<<ans<<endl;
}


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

vector <pair<int,int>> edge;
bool adj[51][51];
bool visited[51];
int n,m,a,b;

void dfs(int now)
{
    visited[now] = true;
    for(int next=1;next<=n;next++)
    {
        if(adj[now][next] && visited[next]==false)
        {
            dfs(next);
        }
    }
}

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

    cin >> n >> m;

    for(int i=0;i<m;i++)
    {
        cin >> a >> b;
        adj[a][b] = true;
        adj[b][a] = true;
        edge.push_back(make_pair(a,b));
    }

    int res = 0;
    int count = 0;
    int cnt = 0;

    memset(visited,false,sizeof(visited));
    for(int i=1;i<=n;i++)
    {
        if(visited[i]==false)
        {
            count++;
            dfs(i);
        }
    }

    for(int i=0;i<m;i++)
    {
        memset(visited,false,sizeof(visited));
        adj[edge[i].first][edge[i].second] = false;
        adj[edge[i].second][edge[i].first] = false;
        cnt = 0;
        for(int j=1;j<=n;j++)
        {
            if(visited[j]==false)
            {
                cnt++;
                dfs(j);
            }
        }
        if(cnt > count)
        {
            res++;
        }
        adj[edge[i].first][edge[i].second] = true;
        adj[edge[i].second][edge[i].first] = true;        
    }

    cout << res << '\n';
    
    return 0;
}


Measured memory_bytes: 256
// ITP1_5_D:   Structured Programming
// 2017.7.27
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

void call(int n)
{
	int i = 1;
	int x;

	do {
		x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
		}
		else {
			do {
				if (x % 10 == 3) {
					printf(" %d", i);
					x = 0;
				}
				else x /= 10;
			} while (x);
		}
	} while (++i <= n);
	putchar('\n');
}

#if 1
int main()
{
	int n;

	scanf("%d", &n);
	call(n);
	return 0;
}
#endif

Measured memory_bytes: 600