akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int h,w,n;
char mp[1003][1003];
char vis[1003][1003];
int ans;
struct pt{
	int x,y;
	int st;	
};
pt st;
pt dl[1000005];
int front,back;
pt cun[21];
int dx[5]={0,0,0,1,-1};
int dy[5]={0,1,-1,0,0};
void bfs(int a)
{
	front=back=1;
	dl[back]=cun[a];
	back++;
	memset(vis,0,sizeof(vis));
	while(front<back)
	{
		pt ls=dl[front];
		front++;
		if(mp[ls.x][ls.y]=='0'+a+1)
		{
			ans+=ls.st;
			break;	
		}
		for(int i=1;i<=4;i++)
		{
			int xx=ls.x+dx[i];
			int yy=ls.y+dy[i];
			if(xx>0&&yy>0&&xx<=h&&yy<=w)
			{
				if(mp[xx][yy]!='X'&&vis[xx][yy]==0)
				{
					dl[back]=(pt){xx,yy,ls.st+1};
					back++;
					vis[xx][yy]=1;	
				}
			}
		}
	}
}
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=h;i++)
	{
		scanf("%s",mp[i]+1);
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(mp[i][j]=='S')
			{
				cun[0]=(pt){i,j,0};	
			}else if(mp[i][j]<'9'&&mp[i][j]>'0')
			{
				cun[mp[i][j]-'0']=(pt){i,j,0};	
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		bfs(i);
	}
	printf("%d\n",ans);
	return 0;
}










Measured memory_bytes: 9760
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

/** Problem0157 : Russian Dolls **/

bool cmp(const PII &a, const PII &b)
{
	return a.first > b.first;
}

bool cmp2(const PII &a, const PII &b)
{
	return a.second > b.second;
}

int main()
{
	int N, M;
	while (cin>>N, N) {
		vector<PII> dolls;
		rep(i, N) {
			int a, b;
			cin>>a>>b;
			dolls.emplace_back(a, b);
		}
		cin>>M;
		rep(i, M) {
			int a, b;
			cin>>a>>b;
			dolls.emplace_back(a, b);
		}
		N += M;
		
		int ans=0;
		vector<int> dp(N);
		sort(dolls.begin(), dolls.end(), cmp);
		for (int i=0; i<N; i++) {
			dp[i] = 1;
			for (int j=0; j<i; j++) {
				if (dolls[i].first < dolls[j].first && dolls[i].second < dolls[j].second)
					dp[i] = max(dp[j]+1, dp[i]);
			}
		}
		ans = max(ans, dp[N-1]);
		
		fill(dp.begin(), dp.end(), 0);
		sort(dolls.begin(), dolls.end(), cmp2);
		for (int i=0; i<N; i++) {
			dp[i] = 1;
			for (int j=0; j<i; j++) {
				if (dolls[i].first < dolls[j].first && dolls[i].second < dolls[j].second)
					dp[i] = max(dp[j]+1, dp[i]);
			}
		}
		ans = max(ans, dp[N-1]);
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second)return a.second < b.second;
    else return a.first < b.first;
}


void solve(long long N, string  S){
    ll ans=0;
    for(int i=0; i <= 999; i++){
        string str = to_string(i);
        if(str.length()==1)str= "00"+str;
        else if(str.length()==2)str="0"+str;
        ll idx=0;
        rep(j, N){
            if(idx==3)break;
            if(str[idx]==S[j])idx++;
        }
        if(idx>2)ans++;
    }cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    string S; cin>>S;
    solve(N, S);
    return 0;
}


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

int main(){
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;

  int count = 0;
  for (int i = 0; i < 3; i++)
  {
    if(S[i] == T[i])
      count++;
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


using namespace std;

int main(){
  int N;
  cin>>N;
  vector<int> d(N);
  for(int& e:d){
    cin>>e;
  }
  sort(d.begin(), d.end());
  int answer=0;
  int temp=0;
  for(int e:d){
    if(temp==e)continue;
    temp=e;
    answer++;
  }
  cout<<answer;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
vector<ll> v;

struct C
{
    ll x, y, h;
};
int cnt = 0;
int N;

ll arr[100010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);

    int K;
    cin >> N >> K;

    REP(i, N)
    {
        cin >> arr[i];
    }
    sort(arr, arr + N);

    ll minV = 1000000000;

    for (int i = 0; i <= N - K; ++i)
    {
        minV = min(minV, arr[i + K - 1] - arr[i]);
    }
    cout << minV << endl;
    return 0;
}


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

using namespace std;

#ifdef Adrian
#include "debug.h"
#else
#define debug(...) 9999
#endif

typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second
#define ii pair<ll,ll>
template <typename G>
struct triple{G F, S, T;};
#define iii triple<int>



int main()
{

#ifdef Adrian
    //freopen("test.txt", "r", stdin);
#else
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#endif


    const ll mod = 998244353;
    int a, b, c, d;
    cin>>a>>b>>c>>d;

    vector<vector<ll>> dp(c + 1, vector<ll>(d + 1));
    dp[a][b] = 1;
    for(int i=a; i<=c; i++)
        for(int j=b; j<=d; j++)
        {
            if(i == a && j == b)
                continue;
            dp[i][j] = dp[i][j - 1] * i % mod + dp[i - 1][j] * j % mod;
            dp[i][j] -= (i - 1) * (j - 1) * dp[i - 1][j - 1] % mod;
            dp[i][j] %= mod;
            if(dp[i][j] < 0)
                dp[i][j] += mod;
            debug(i, j, dp[i][j]);
        }

    cout<<dp[c][d]<<'\n';


    return 0;
}


Measured memory_bytes: 73648
#include <cstdio>

int main(){
  int k,c;
  while(1){
    scanf("%d",&k);
    if(k==0)
      break;
    int sum=0;
    for(int i=0;i<k*(k-1)/2;i++){
      scanf("%d",&c);
      sum+=c;
    }
    printf("%d\n",sum/(k-1));
  }
  return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,m,ch[200010];
	cin>>n>>m;
	vector<ll>a[200010];
	for(ll i=0;i<n;i++){
		ch[i]=-1;
	}
	for(ll i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	ch[0]=0;
	queue<ll>q;
	q.push(0);
	while(q.size()!=0){
		ll now=q.front();
		q.pop();
		for(ll i=0;i<a[now].size();i++){
			ll next=a[now][i];
			if(ch[next]!=-1){
				continue;
			}
			ch[next]=now+1;
			q.push(next);
		}
	}
	cout << "Yes"<<endl;
	for(ll i=1;i<n;i++){
		cout <<ch[i]<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 15384
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

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

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


Measured memory_bytes: 3656
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int, int>;
//加算代入演算子は+=！！！！！

int n, k;
vector<bool> flag(10, false);

bool check(int n)
{
    while (n > 0)
    {
        if (flag.at(n % 10) == true)
        {
            return false;
        }
        else
        {
            n /= 10;
        }
    }
    return true;
} //桁が全部falseになると抜けられる

int main()
{
    cin >> n >> k;
    vector<int> vec(k);
    rep(i, k) {
        cin >> vec.at(i);
    }
    rep(i, k) {
        flag.at(vec.at(i)) = true;
    }

    int ans;
    for (ans = n; ans < 100000; ans++)
    {
        if (check(ans) == true)
        {
            break;
        }
    }

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

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			string n = cin.Next();
			int k = cin.Int();

			int m = n.Length;

			var dp0 = new long[m, k + 1];
			var dp1 = new long[m, k + 1];
			dp0[0, 0] = 1;
			dp0[0, 1] = n[0] - '0' - 1;
			dp1[0, 1] = 1;

			for (int i = 1; i < m; i++) {
				for (int j = 0; j < k + 1; j++) {
					if (n[i] == '0') {
						dp0[i, j] += dp0[i - 1, j];
						dp1[i, j] += dp1[i - 1, j];
		
						if (j + 1 <= k) {
							dp0[i, j + 1] += dp0[i - 1, j] * 9;
						}
					} else {
						dp0[i, j] += dp0[i - 1, j] + dp1[i - 1, j];
						int num = n[i] - '0' - 1;
						if (j + 1 <= k) {
							dp0[i, j + 1] += dp0[i - 1, j] * 9;
							dp0[i, j + 1] += dp1[i - 1, j] * num;
							dp1[i, j + 1] += dp1[i - 1, j];
						}
					}
				}
			}

			long ans = dp0[m - 1, k] + dp1[m - 1, k];
			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 11220
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using ll = long long;


int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char> > vec(h, vector<char>(w));
	rep(i, h) {
		rep(j, w) cin >> vec.at(i).at(j);
	}
	string res = "Yes";
	rep(i, h) {
		rep(j, w) {
			int cnt = 0;
			if (vec.at(i).at(j)=='#') {
				if (i>0) {
					if (vec.at(i-1).at(j)=='#') cnt++;
				}
				if (i<h-1) {
					if (vec.at(i+1).at(j)=='#') cnt++;
				}
				if (j<w-1) {
					if (vec.at(i).at(j+1)=='#') cnt++;
				}
				if (j>0) {
					if (vec.at(i).at(j-1)=='#') cnt++;
				}
				if (cnt==0) res = "No";
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 3600
data = input().split(' ')
result = 0
if int(data[0]) == 1:
    result += 300000
elif int(data[0]) == 2:
    result += 200000
elif int(data[0]) == 3:
    result += 100000
if int(data[1]) == 1:
    result +=300000
elif int(data[1]) == 2:
    result += 200000
elif int(data[1])== 3:
    result += 100000

if int(data[0])== 1 and int(data[1]) == 1:
    result += 400000

print(result)

Measured memory_bytes: 3064
s = input()
t = input()
slist,tlist = [],[]
for i in s:
	slist.append(i)
for i in t:
	tlist.append(i)
slist.sort()
tlist.sort()
tlist = tlist[::-1]
for j in range(min(len(slist),len(tlist))):
	if ord(slist[j]) < ord(tlist[j]):
		print("Yes")
		break
	elif ord(slist[j]) > ord(tlist[j]):
		print("No")
		break
	else:
		if j == min(len(slist),len(tlist))-1:
			if len(slist) < len(tlist): print("Yes")
			else: print("No")

Measured memory_bytes: 3064
from collections import defaultdict
H, W, N, *L = map(int, open(0).read().split())
dic = defaultdict(int)
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[(i,j)] += 1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
  ans[dic[k]] += 1
  ans[0] -= 1
print(*ans,sep='\n')
        

Measured memory_bytes: 168388
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<int> ac(100100); // 1e5
vector<int> wa(100100); // 1e5

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

  int n,m;
  cin >> n >> m;

  ac.resize(n);
  wa.resize(n);

  rep(i,m) {
    int p;
    string s;
    cin >> p >> s;
    p--;
    if (ac.at(p) == 0) {
      if (s == "AC") {
        ac.at(p) += 1;
      }
      if (s == "WA") {
        wa.at(p) += 1;
      }
    }
  }

  int wan = 0;
  rep(i, n) {
    if (ac.at(i) == 1) {
      wan += wa.at(i);
    }
  }
  cout << accumulate(all(ac), 0) << " " << wan << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        final int N = sc.nextInt();
        int[] A = new int[N];
        int flag = 0;

        for (int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            if(A[i] % 2 == 0){
                if(A[i] % 3 != 0 && A[i] % 5 != 0){
                    flag = 1;
                    break;
                }
            }
        }

        if(flag == 0){
            System.out.println("APPROVED");
        }else{
            System.out.println("DENIED");
        }
        
        
    }
}

Measured memory_bytes: 23252
from collections import deque

# 入力
H, W = [int(a) for a in input().split()]
S = [None for _ in range(H)]
for i in range(H):
    S[i] = list(input())


UNVISITED = -1

dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)



def bfs(sy, sx):
    dist = [[UNVISITED for _ in range(W)] for _ in range(H)]
    que = deque() # 座標
    que.append((sx, sy))
    dist[sy][sx] = 0

    while(len(que) > 0):
        x, y = que.popleft()
        for i in range(4): # 上下左右に移動
            nx = x + dx[i]
            ny = y + dy[i]

            if (0 <= nx < W) and (0 <= ny < H) and S[ny][nx] == '.' and dist[ny][nx] == UNVISITED:
                que.append((nx, ny))
                dist[ny][nx] = dist[y][x] + 1
    return( max( [max(dist[i]) for i in range(H)]))

m = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            m = max(m, bfs(i, j))

print(m)


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

int main(void){
    long double a = 0, b = 0; 

    scanf("%lf%lf", &a, &b);
    if(a > b){
        printf("GREATER\n");
    }else if(a < b){
        printf("LESS\n");
    }else if(a == b){
        printf("EQUAL\n");
    }

    return 0;

} 


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a[][]=new int[4][4];
    for (int i=1;i<=3;i++) {
      for (int j=1;j<=3;j++) {
        a[i][j]=sc.nextInt();
      }
    }
    int n=sc.nextInt();
    ArrayList<Integer>b=new ArrayList<Integer>();
    for (int i=0;i<n;i++) {
      b.add(sc.nextInt());
    }

    for (int i=1;i<=3;i++) {
      for (int j=1;j<=3;j++) {
       if (b.contains(a[i][j])) {
         a[i][j]=0;
       }
      }
    }

    if(a[1][1]==0&&a[1][2]==0&&a[1][3]==0||a[2][1]==0&&a[2][2]==0&&a[2][3]==0||a[3][1]==0&&a[3][2]==0&&a[3][3]==0
    ||a[1][1]==0&&a[2][2]==0&&a[3][3]==0||a[1][3]==0&&a[2][2]==0&&a[3][1]==0||a[1][1]==0&&a[2][1]==0&&a[3][1]==0||
    a[1][2]==0&&a[2][2]==0&&a[3][2]==0||a[1][3]==0&&a[2][3]==0&&a[3][3]==0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }

  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k;
    long int add=0;
    cin >> n >> k;
    int p[n];
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    sort(p,p+n);
    for(int i=0;i<k;i++){
        add += p[i];
    }
    cout << add << endl;
}

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(ll)(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,((n)+1))
#define repst(i,s,n) reps(i,s,((n)+1))
#define reprt(i,n,t) for(ll (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, s, r = linf;

ll f(ll b, ll n) {
	if (n<b) return n;
	else return f(b,n/b)+n%b;
}

signed main() {
	cin >> n >> s;
	if (n==s) {
		cout << n+1 << ln;
		return 0;
	}
	for (ll b = 2; b*b <= n; ++b) {
		if (f(b,n)==s) {
			cout << b << ln;
			return 0;
		}
	}
	// √n<b<=nのときnのb進表記は必ず2桁
	// 上位桁をp、下位桁をqとするとpb+q=n また題意よりp+q=s ∴ b=(n-s)/p+1
	// つまりbはpのみに依存するからpだけ全探索すればいい
	for (ll p = 1; p*p <= n-s; ++p) {
		if ((n-s)%p) continue;
		ll b = (n-s)/p + 1;
		if (f(b,n)==s) chmin(r,b);
	}
	cout << (r==linf ? -1 : r) << ln;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = []
a[0] = 0

for i in 1..n do
  if(i%3 == 0 && i%5 == 0)
    a[i] = 0
  elsif(i%3 == 0 || i%5 == 0)
    a[i] = 0
  else
    a[i] = i
  end
end

puts a.sum



Measured memory_bytes: 22088
#include<bits/stdc++.h>
using namespace std;
namespace Ogiso_Setsuna{
	int a,b,c,d,e,f;
	set<int> sugar,water;
	set<int>::iterator it1,it2;
	void solve(){
		ios::sync_with_stdio(false);
		cin>>a>>b>>c>>d>>e>>f;
		for(int i=0,s,t;i<=f;++i){
			if((s=i*100*a)>f)break;
			for(int j=0;j<=f;++j){
				if(s+(t=j*100*b)>f)break;
				water.insert(s+t);
			}
		}
		for(int i=0;i<=f;++i){
			if(i*c>f)break;
			for(int j=0;j<=f;++j){
				if(i*c+j*d>f)break;
				sugar.insert(i*c+j*d);
			}
		}
		int Kitahara_Setsuna=1,Zhuge_Setsuna=1;
		double Setsuna_Party=INT_MIN;
		for(it1=sugar.begin();it1!=sugar.end();++it1){
			for(it2=water.begin();it2!=water.end();++it2){
				int s=(*it1),w=(*it2);
				if(s+w<=f&&w/100.0*e>=s){
					if(Setsuna_Party<(100.0*s)/(s+w)){
						Setsuna_Party=(100.0*s)/(s+w);
						Kitahara_Setsuna=s;
						Zhuge_Setsuna=w;
					}
				}
			}
		}
		cout<<Kitahara_Setsuna+Zhuge_Setsuna<<" "<<Kitahara_Setsuna<<endl;
	}
}
int main(){
	Ogiso_Setsuna:: solve();
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n; cin >> n;
  vector<vector<int>> g(n);
  REP (i, n - 1) {
    int u, v; cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> c(n); REP (i, n) cin >> c[i];
  sort(ALL(c));

  int pt = 0;
  vector<int> ans(n);
  function<void(int, int)> dfs = [&](int v, int p) {
    for (int s : g[v]) if (s != p) {
      dfs(s, v);
    }
    ans[v] = c[pt];
    pt++;
  };
  dfs(0, -1);
  int sum = 0;
  REP (i, n - 1) sum += c[i];
  cout << sum << endl;
  REP (i, n) cout << ans[i] << " ";
  cout << endl;
}


Measured memory_bytes: 1664
#include <iostream>
using namespace std;
void ABC110(void);
void ABC111(void);
void ABC112(void);
void ABC113(void);
void ABC114(void);
void ABC115(void);
void ABC116(void);
void ABC117(void);
void ABC118(void);
void ABC119(void);

int main(void){
    ABC111();
}

void ABC111(){
    string s;
    cin>>s;
    for(int i=0;i<=2;++i){
        if(s[i]=='1')s[i]='9';
        else if(s[i]=='9')s[i]='1';
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
/**********************************************
 *Author*        :XzzF
 *Created Time*  : 2018/7/15 21:52:05
 *Ended  Time*  : 2018/7/15 22:09:15
*********************************************/

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;

int n;
char s[50];

struct S {
	string red, blue;
	S () {}
	S (string _red, string _blue) {
		red = _red; blue = _blue;
	}
	friend bool operator < (const S A, const S B) {
		if(A.red == B.red) return A.blue < B.blue;
		return A.red < B.red;
	}
};

string R, B;

map <S, LL> cnt;

int main()
{
	while(scanf("%d", &n) != EOF)
	{
		scanf("%s", s);
		for(int i = 0; i < (1 << n); i++) {
			R = ""; B = "";
			for(int j = 0; j < n; j++) {
				if(i & (1 << j)) R += s[j];
				else B += s[j];
			}
			cnt[S(R, B)]++;
		}
		LL ans = 0LL;
		for(int i = 0; i < (1 << n); i++) {
			R = ""; B = "";
			for(int j = n - 1; j >= 0; j--) {
				if(i & (1 << j)) R += s[n + j];
				else B += s[n + j];
			}
			ans += cnt[S(B, R)];
		}
		printf("%lld\n", ans);
		cnt.clear();
	}
    return 0;
}

Measured memory_bytes: 91904
n = int(input())
L = [int(input()) for _ in range(n)]
sortedL = sorted(L)
max1 = sortedL[-1]
max2 = sortedL[-2]

count = L.count(max1)

if count == 1:
    for i in range(n):
        print(max2 if L[i] == max1 else max1)
else:
    for i in range(n):
        print(max1)


Measured memory_bytes: 14152
a, b, c, d = map(int, input().split())

def kaisuu(atk, hp):
    if (hp/atk) > (hp//atk):
        return hp//atk + 1
    else:
        return hp//atk

if kaisuu(b,c) <= kaisuu(d,a):
    print("Yes")
else:
    print("No")

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

int soya(int n,int s[],int p,int num) {
	int ans = 1;
	int k = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] > p) return num;
		else if (k + s[i] <= p) {
			k += s[i];
		}
		else {
			ans++;
			k = 0;
			k = s[i];
		}
	}
	return ans;
}

int binarysearch(int min,int s[], int num,int n, int k) {
	int left = min;
	int right = num;
	int mid = 0;
	int num1;
	while (left != right) {
		mid = (left + right) / 2;
		num1 = soya(n, s, mid,num);
		if (num1 <= k) {
			right = mid;
		}
		else {
			left = mid + 1;
		}
	}
	return left;
}

int main()
{
	int num=0;
	int min=1000;
	int s[100000];
	int n, k;
	int ans1234;

	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		cin >> s[i];
		num += s[i];
		if (min > s[i])min = s[i];
	}
	ans1234 = binarysearch(min,s, num, n, k);

	cout << ans1234 << endl;
	return 0;
}


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

using ll = long long;
using pii = pair<int, int>;

#define     endl               "\n"
#define     fast_io            ios::sync_with_stdio(false); cin.tie(0);
#define     file_io            freopen("input.txt", "r", stdin);   \
                               freopen("output.txt", "w", stdout);
#define     all(x)             begin(x), end(x)
#define     debug(x)           cerr <<"Line "<< __LINE__ <<" : "<< #x " = "<< x <<endl;
 
template<typename T, typename TT>
ostream& operator<<(ostream &os, const pair<T, TT> &t) { return os<<"("<<t.first<<", "<<t.second<<")"; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &t) { for(auto& i: t) os<<i<<" "; return os; }
 



int main(int argc, char** argv) {
    fast_io
   
	int a, b;
	while(cin >> a >> b && (a || b)) {
		for(int i = 0; i < a; ++i) {
			bool flag = i&1;
			for(int j = 0; j < b; ++j) {
				cout << (flag? '.' : '#');
				flag^=1;
			}
			cout << endl;
		}
		cout << endl;
	}
	

    return 0;
}























Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    int x,n;
    cin>>x>>n;
    int p[n];
    rep(i,n)cin>>p[i];
    int b=x,s=x;
    bool b_flag,s_flag;
    while(1){
        b_flag=false;
        s_flag=false;
        rep(i,n){
            if(s==p[i]){
                s_flag=true;
            }
            if(b==p[i]){
                b_flag=true;
            }
        }
        if(!s_flag){
            cout<<s<<endl;
            break;
        }
        else if(!b_flag){
            cout<<b<<endl;
            break;
        }
        b++;
        s--;
    }

    return 0;
}


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

int main() { 
  int N,p=1,i,j;
  cin >> N;
  
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  
  for(i=1;i<N;i++){
    if(vec.at(i-1) == vec.at(i)){
      p = 0;
      break;
    }
  }
  if(p){
    cout << "YES";
  }else{
    cout << "NO";
  }
  cout << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<math.h>
#include<climits>
#define ll long long
#define VAL 100
using namespace std;
int finder(vector<int>&arr,int sum)
{
    int count=0;
    for(int i=0;i<arr.size();i++)
    {
        if(arr[i]>=sum)
        {
            break;
        }
        else
        count++;
    }
    return count;
}
int main()
{
    int i,j,t,x,n;
    //map<unsigned long int,int>mapper;
    //unordered_map<unsigned long int,bool>visit;
    vector<int>arr;
    //set<int>qrr;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        arr.push_back(x);
    }
    sort(arr.begin(),arr.end());
    long long total=0;
    //cout<<frr.size()<<qrr.size();
    for(int i=0;i<arr.size();i++)
    {
        for(int j=i+1;j<arr.size();j++)
        {
            long long int sum=arr[i]+arr[j];
            if(arr[i]==arr[j])
            {
                continue;
            }
            for(int x=j+1;x<arr.size();x++)
            {
                if((arr[x]!=arr[i])&&(arr[x]!=arr[j]))
                {
                    if((arr[x]<sum)&&(arr[x]>arr[j]))
                    {
                        //cout<<arr[i]<<" "<<arr[j]<<" "<<arr[x]<<endl;
                        total++;
                    }
                }


            }
        }
    }
    cout<<total;

    return 0;
}



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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = A == 1 ? B == 2 ? 3 : 2 : A == 2 ? B == 3 ? 1 : 3 : B == 1 ? 2 : 1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include <math.h>
#include <cstdio>
#include <string.h>
using namespace std;
int main(void){
	string t,s,ans[300000];
	int k,i,j,n=0,x,f;
	cin>>s>>k;
  
	for(i=0;i<s.size();i++){
		for(j=1;j<=k;j++){
			t=s.substr(i,j);
			f=1;
			for(x=0;x<n;x++){
				if(t==ans[x]) f=0;
			}
			if(f){
				ans[n]=t;
				n++;
			}
		}
	}
	sort(ans,ans+n);
	cout<<ans[k-1]<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout<<s,0
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}
const int N = 2e5 + 9;
const int mod = 1e9 + 7;
ll inv[N];
ll nCr(int n, int r) {
	if (r > n)
		return 0;
	ll ans = 1, div = 1, i = r + 1;
	while (i <= n) {
		ans = (ans * i) % mod;
		ans = (ans * inv[div]) % mod;
		div++;
		i++;
	}
	return ans;
}

ll power(ll x, ll y) {
	if (y == 0)
		return 1;
	if (y == 1)
		return x;
	ll r = power(x, y >> 1);
	return ((r * r) % mod * power(x, y & 1)) % mod;
}

// nCr(n,r) == nCr(b,n - r)
int main() {
	run();
	inv[1] = 1;
	for (int i = 2; i < N; i++) {
		inv[i] = mod - (inv[mod % i] * (mod / i) % mod);
	}
	ll n, a, b;
	cin >> n >> a >> b;
	ll res = power(2, n);
	res = (res + mod - nCr(n, max(n - a, a))) % mod;
	res = (res + mod - nCr(n, max(n - b, b))) % mod;
	res = (res + mod - 1) % mod;
	cout << res;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

ll A,B,C,X,Y;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> A >> B >> C >> X >> Y;
    A = min(A,2*C), B = min(B,2*C);
    ll Z = min(X,Y);
    cout << Z*min(A+B,2*C)+A*(X-Z)+B*(Y-Z);
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int ans[200005];

int solve(int v){
	if(ans[v]!=-1){
		return ans[v];
	}
	if(v==0){
		return 0;
	}
	return ans[v]=(solve(v%__builtin_popcount(v))+1);
}

string x;
ll val[2][200005];
ll sum[2];

int main(void){
	memset(ans,-1,sizeof(ans));
	for(int i=1;i<=200000;i++){
		solve(i);
	}
	ans[0]=0;
	scanf("%d",&n);
	cin >> x;
	int cnt=0;
	for(int i=0;i<n;i++){
		if(x[i]=='1'){
			cnt++;
		}
	}
	ll tgt=cnt+1,tgt2=cnt-1;
	val[0][0]=1%tgt;
	if(tgt2>=1)val[1][0]=1%tgt2;
	for(int i=1;i<n;i++){
		val[0][i]=val[0][i-1]*2LL;
		val[1][i]=val[1][i-1]*2LL;
		val[0][i]%=tgt;
		if(tgt2>=1){
			val[1][i]%=tgt2;
		}
	}
	for(int i=0;i<n;i++){
		if(x[i]=='1'){
			sum[0]+=val[0][n-i-1];
			sum[0]%=tgt;
			if(tgt2>=1){
				sum[1]+=val[1][n-i-1];
				sum[1]%=tgt2;
			}
		}
	}
	for(int i=0;i<n;i++){
		if(x[i]=='0'){
			ll su=sum[0]+val[0][n-i-1];
			su%=tgt;
			printf("%d\n",ans[su]+1);
		}else{
			if(tgt2<=0){
				printf("0\n");
				continue;
			}
			ll su=sum[1]-val[1][n-1-i];
			if(su<0){
				su+=tgt2;
			}
			su%=tgt2;
			printf("%d\n",ans[su]+1);
		}
	}
	return 0;
}


Measured memory_bytes: 7812
#include<iostream>
#include<string>
#include<vector>
#include <cstdlib>
#include<cctype>
#include <algorithm>    
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define VCOUT(num) for(auto& num:vec)
#define GET_ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
#define LLINF 1000000000000000000//10^18
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000
#define MAX 100
#define MX 10

//int main(int argc, char const* argv[]){

int main(){ 
    vector<int>vec;
     vector<char>cvec;
      vector<string>svec;
    
   int a,b,x,y,z,count=0;
   string answer;
   cin>>a;
   cin>>b;
   cin>>x;
   if((a<b)&&(b<x)) answer="Yes";
    else answer="No";
  
   
    
  
  cout<<answer<<endl;
    return 0;
}


Measured memory_bytes: 3156
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 998244353;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {   
    int menu[5]; rep(i, 5) cin >> menu[i];

    vector<int> index{0,1,2,3,4};
    int res = INF;
    do{
        int sum = 0;
        rep(i, 4){
            sum += menu[index[i]];
            if(menu[index[i]]%10 != 0) sum += (10 -(menu[index[i]]%10));
        }
        sum += menu[index[4]];
        chmin(res, sum);

    }while(next_permutation(all(index)));
    cout << res << ln;
}



Measured memory_bytes: 256
import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0:
  if zero and k%2:
    ans = 0
  else:
    if k%2:
      minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)

Measured memory_bytes: 31856
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::fastout;
use proconio::input;
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
use rand::Rng;
//use std::collections::HashSet;
//use std::cmp::*;
//use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        D:usize,
        C:[i64;26],
        S:[[i64;26];D]
    }
    let mut ans = 0;
    let mut rng = rand::thread_rng();
    let mut T = vec![0; D];
    let mut Tmax = vec![0; D];
    let mut cnt = 0;
    let start = std::time::Instant::now();
    loop {
        for i in 0..D {
            T[i] = rng.gen::<usize>() % 26;
        }
        let mut last = vec![vec![0i64; 26]; D];
        for d in 0..D {
            let i = T[d];
            last[d][i] = d as i64 + 1;
            for e in d + 1..D {
                if T[e] != i {
                    last[e][i] = d as i64 + 1;
                } else {
                    break;
                }
            }
        }
        let mut x = 0;
        for d in 0..D {
            let i = T[d];
            x += S[d][i];
            //println!("ss{}", x);
            for j in 0..26 {
                x -= C[j] * (d as i64 + 1 - last[d][j]);
                //println!("C[{}]={} -> {}", j, C[j], x);
            }
        }
        if ans < x {
            for k in 0..D {
                ans = x;
                Tmax[k] = T[k];
            }
        }
        //        if cnt > 100 {
        //            break;
        //        }
        //        cnt += 1;
        let duration = start.elapsed();
        if duration > std::time::Duration::from_millis(1800) {
            break;
        }
    }
    for i in 0..D {
        println!("{}", Tmax[i] + 1);
    }
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

bool is_prime(int v) {
    if (v == 1) return false;
    for (int i = 2; i * i <= v; i++) {
        if (v % i == 0) return false;
    }

    return true;
}

int main() {
    int N;
    cin >> N;
    vector<int> ans;

    for (int i = 2; i <= 55555; i++) {
        if (is_prime(i) && i % 5 == 1) {
            ans.push_back(i);
            if (ans.size() == N) break;
        }
    }

    rep(i, ans.size()) cout << ans[i] << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;

#[fastout]
fn main() {
    input!{
        A: i128,
        B: i128,
        C: i128,
        mut K: i128,
    }

    let mut ans: i128 = 0;

    if K > A {
        ans += A;
        K -= A;
        if K > B {
            K -= B;

            ans -= K; 
            println!("{}", ans)
            
        } else {
            println!("{}", ans)
        }
    } else {
        ans = K;
        println!("{}", ans)
    }
}


Measured memory_bytes: 2152
// Tue Jun 30 14:06:52 IST 2020  
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)        for(int ii = (int)a ; ii < (int)b  ; ii++ )
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long    
#define MOD                998244353 
#define pb                 push_back
#define f1                 first 
#define s1                 second    
#define all(x)             (x).begin(),(x).end() 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
#define tough_nut          numeric_limits<int64>::min()

const double pi = 3.141592653589793238;
using namespace  std ;       
using namespace __gnu_pbds;
 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
const int N = 3e5+7; 
const int INF = INT_MAX;
struct comp{
    bool operator()(const pair<int,int> A,const pair<int,int>& B)const{
        if(A.first == B.first)
            return A.second < B.second ;
        return A.first > B.first;
    } 
};    
int tests(){
    int n;
    cin >> n;
    map <string,int> m;
    m["AC"] = 0;
    m["WA"] = 0;
    m["TLE"] = 0;
    m["RE"] = 0;
    vector <string> v(n);
    for(auto &x :v)
        cin >> x,m[x]++;
    cout << "AC" << " x " << m["AC"] << '\n';
    cout << "WA" << " x " << m["WA"] << '\n';
    cout << "TLE" << " x " << m["TLE"] << '\n';
    cout << "RE" << " x " << m["RE"] << '\n';

    return 0;
}
int32_t main(){
    I__O ;     
    int cases = 1 ;  
    // cin >> cases ;  
    while(cases--) 
        tests(); 
     
    return 0 ; 
}


Measured memory_bytes: 6352
#include<bits/stdc++.h>
#define rep(i,N) for(ll i=0; i<N; i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    ll n, k; cin >> n >> k;
    ll h[n]; rep(i,n) cin >> h[i];

    ll ans = 0;
    rep(i,n){
        if(h[i] >= k) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
import numpy as np
N = int(input())

def f(x):
  a = x%10
  b = 0
  while x > 0:
    b = x
    x //= 10
  return a,b

freq = np.zeros((10,10), dtype=int)
for k in range(1,N+1):
  a,b = f(k)
  freq[a,b] += 1

print((freq*freq.T).sum())

Measured memory_bytes: 12504
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll INF =  1LL << 60;
const int inf = 1 << 20;
int n, m, x, y, q, d,z, w = 0, sum, ans = 0;
vector<int>a;
const int MAX = 510000;
const int MOD = 1000000007;
int main(void) {
	cin >> n; deque<int> d;
	rep(i, n) {
		cin >> m;
		if (i % 2 == 0) {
			d.push_back(m);
		}
		else {
			d.push_front(m);
		}
	}
	if (n % 2 == 0) {
		for (int i : d) cout << i << " ";
		cout << endl;
	}
	else {
		rrep(i, n) cout << d[i] << " ";
		cout << endl;
	}
}

Measured memory_bytes: 4424
#include <stdio.h>
#define SIZE 100

int main(void)
{
	int n, k, b, err;
	int i, j;
	int s[SIZE];

	while (1) {
		scanf("%d%d", &n, &k);
		if (n == 0 && k == 0) break;
		err = 0;
		for (i  = 0; i < SIZE; i++)
			s[i] = 0;
		for (i = 0; i < k; i++)
			scanf("%d", &s[i]);
		for (i = 0; i < n; i++) 
			for (j = 0; j < k; j++) {
				scanf("%d", &b);
				s[j] -= b;
			}
		for (i = 0; i < k; i++)
			if (s[i] < 0) {
				err = 1;
				break;
			}
		if (err) 
			puts("No");
		else
			puts("Yes");
	}

	return 0;
}

Measured memory_bytes: 584
[print("Yes") if not "##" in S[A-1:C-1] and not "##" in S[B-1:D-1]  and (C<D or  "..." in S[B-2:min(D+1,N)]) else print("No") for N,A,B,C,D,S in [list(map(int,input().split()))+[input()]]]


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

long D[31][31];
int main()
{
    int N, C; cin>>N>>C;
    for(int i=0; i<C; ++i) for(int j=0; j<C; ++j) cin>>D[i][j];

    map<int, int> x[3];
    for(int i=0; i<N; ++i) for(int j=0; j<N; ++j) {
        int c; cin>>c;
        x[(i+j)%3][c-1]++;
    }

    long res=LONG_MAX;
    for(int i=0; i<C; ++i) for(int j=0; j<C; ++j) if (i!=j)
    for(int k=0; k<C; ++k) if (i!=k && j!=k) {
        long t=0;
        for(auto& e: x[0]) t+=D[e.first][i]*e.second;
        for(auto& e: x[1]) t+=D[e.first][j]*e.second;
        for(auto& e: x[2]) t+=D[e.first][k]*e.second;
        res=min(res, t);
    }
    cout<<res<<endl;
}


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


#define all(container) container.begin(), container.end()
#define yn(cond) cond ? cout << "Yes" << endl : cout << "No" << endl
#define YN(cond) cond ? cout << "YES" << endl : cout << "NO" << endl


int main(void) {

    string S;
    cin >> S;
    sort(all(S));
    yn(S == "abc");

    return 0;
}

Measured memory_bytes: 256