akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll a,b;
	cin>>a>>b;
	(a>9 || b>9)?cout<<"-1\n":cout<<a*b<<"\n";
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 3612
# https://atcoder.jp/contests/abc126_e
import collections

N, M = map(int, input().split())
triples = [tuple(map(int, input().split())) for _ in range(M)]

connected = collections.defaultdict(list)
for (a, b, _) in triples:
    connected[a].append(b)
    connected[b].append(a)

nodes = set(range(1, N + 1))
seen = set()
cnt = 0

for i in nodes:
    if i not in seen:
        cnt += 1
        stack = [i]
        while stack:
            state = stack.pop()
            for new_state in connected[state]:
                if new_state not in seen:
                    seen.add(new_state)
                    stack.append(new_state)

print(cnt)


Measured memory_bytes: 50544
N = int(input())
L_P = []
num = N
ans = 0
if N == 1:
    print(ans)
else:
    for i in range(2,int(-(-num**0.5//1))+1):
        if num % i == 0:
            cnt = 0
            while num % i == 0:
                cnt += 1
                num //= i
            L_P.append(cnt)
        if num == 1:
            break
    else:
        L_P.append(1)
    for x in L_P:
        for i in range(1,100):
            if i*(i+1)//2 > x:
                ans += i-1
                break
    print(ans)     

Measured memory_bytes: 9476
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int main() {
	string n; cin >> n;
	int a=atoi(n.substr(0,1).c_str()), b = atoi(n.substr(1, 1).c_str()), c = atoi(n.substr(2, 1).c_str()), d = atoi(n.substr(3, 1).c_str());
	if (a + b + c + d == 7) {
		cout << a << "+" << b << "+" << c << "+" << d << "=7";
		return 0;
	}
	if (a + b + c - d == 7){
		cout << a << "+" << b << "+" << c << "-" << d << "=7";
		return 0;
	}
	if (a + b - c - d == 7){
		cout << a << "+" << b << "-" << c << "-" << d << "=7";
		return 0;
	}
	if (a - b - c - d == 7){
		cout << a << "-" << b << "-" << c << "-" << d << "=7";
		return 0;
	}
	if (a + b - c + d == 7) {
		cout << a << "+" << b << "-" << c << "+" << d << "=7";
		return 0;
	}
	if (a - b + c + d == 7){
		cout << a << "-" << b << "+" << c << "+" << d << "=7";
		return 0;
	}
	if (a - b + c - d == 7) {
		cout << a << "-" << b << "+" << c << "-" << d << "=7";
		return 0;
	}
	if (a - b - c + d == 7){
		cout << a << "-" << b << "-" << c << "+" << d << "=7";
		return 0;
	}
	
	cout << endl;
	return 0;
}

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


int n, a[100001], b[100001], c[2][100001];
vector<int> v[100001];

int main(){
	cin >> n;
	for(int i = 0; i < n-1; i++){
		cin >> a[i] >> b[i];
		v[a[i]].push_back(b[i]);
		v[b[i]].push_back(a[i]);
	}
	
	for(int i = 0; i <= n; i++){
		c[0][i] = INF;
		c[1][i] = INF;
	}
	
	queue<pair<int,int>> q;
	q.push(make_pair(0, 1));
	while(q.size()){
		pair<int,int> p = q.front();
		q.pop();
		c[0][p.second] = p.first;
		for(int i = 0; i < v[p.second].size(); i++){
			if(c[0][v[p.second][i]] <= p.first) continue;
			q.push(make_pair(p.first+1, v[p.second][i]));
		}
	}
	q.push(make_pair(0, n));
	while(q.size()){
		pair<int,int> p = q.front();
		q.pop();
		c[1][p.second] = p.first;
		for(int i = 0; i < v[p.second].size(); i++){
			if(c[1][v[p.second][i]] <= p.first) continue;
			q.push(make_pair(p.first+1, v[p.second][i]));
		}
	}
	
	int ans[2] = {0};
	for(int i = 1; i <= n; i++){
		if(c[0][i] <= c[1][i]) ans[0]++;
		else ans[1]++;
	}
	if(ans[0] > ans[1]) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
	
	return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    string S;
    cin >> S;

    int a[S.length()];
    int b[S.length()];
    int aa = 0;
    int bb = 1;
    for (int i = 0; i < S.length(); i++) {
        a[i] = aa % 2;
        b[i] = bb % 2;
        aa++;
        bb++;
    }

    int temp1 = 0;
    int temp2 = 0;
    for (int i = 0; i < S.length(); i++) {
        int temp = (S[i] == '0') ? 0 : 1;
        if (a[i] != temp) temp1++;
        if (b[i] != temp) temp2++;
    }

    if (temp1 < temp2) {
        cout << temp1 << endl;
    } else {
        cout << temp2 << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
N,K,Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]
points = [K-Q for _ in range(N)]

for a in A:
  a -= 1
  points[a] += 1
  
for point in points:
  if point > 0: print('Yes')
  else: print('No')

Measured memory_bytes: 58200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define Pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define MOD (ll)1000000007

const int N = 1e5 + 5;

int n;
int a[N];

signed main()
{
    IOS;

      int n,k;
      cin >> n;
      string s;
      pair<string,int> p[n];
      for(int i=0;i<n;i++)
      {
        cin >> s >> k;
        p[i]={s,k};
      }
      string ss;
      cin >> ss;
      int sum=0;
      for(int i=0;i<n;i++)
      {
        if(p[i].ff == ss)
        {
          for(int j=i+1;j<n;j++)
          {
            sum+=p[j].ss;
          }
          cout << sum;
          return 0;
        }
      }
    return 0;
}


Measured memory_bytes: 256
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (int i = 0; i < (n); ++i)	

int max(ll a, ll b) {
	ll max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(ll a, ll b) {
	ll min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main() {
	string s;
	cin >> s;
	bool can = true;
	rep(i, s.size()) {
		if (i % 2 == 0){
			if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
				can = false;
			}
		}
		else {
			if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
				can = false;
			}
		}
	}
	cout << (can ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int n,lens,a[27],ac[27];
int main(){
	memset(ac,127,sizeof(ac));
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s;
		lens=s.size();
		memset(a,0,sizeof(a));
		for(int j=0;j<lens;j++)
			a[s[j]-'a']++;
		for(int j=0;j<26;j++)
			if(a[j]<ac[j])ac[j]=a[j];
	}
	for(int i=0;i<26;i++)
		for(int j=1;j<=ac[i];j++)
			printf("%c",i+97);
	cout<<endl;
}

Measured memory_bytes: 256
// 2013/09/09 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int w;
		cin >> w;

		if(w==-1)
			break;

		int b;
		if(w<=10){
			b = 1150;
		}
		else if(w<=20){
			b = 1150+(w-10)*125;
		}
		else if(w<=30){
			b = 1150+10*125+(w-20)*140;
		}
		else{
			b = 1150+10*125+10*140+(w-30)*160;
		}

		cout << 4280-b << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 1e5+5;
const dd eps = 1e-8;
const int mod = 1e9+7;

int h,w,k,ans;
char table[20][20],a[20][20];

int main(){
  // freopen("input.txt","r",stdin);
  cin>>h>>w>>k;
  for(int i = 1;i <= h;i++){
    for(int j = 1;j <= w;j++){
      cin>>table[i][j];
      a[i][j] = table[i][j];
    }
  }
  for(int sta = 0;sta < (1<<(h+w));sta++){
    for(int x = 1;x <= h;x++){
      for(int y = 1;y <= w;y++) a[x][y] = table[x][y];
    }
    for(int i = 1;i <= h;i++){
      if(sta & (1<<(i-1))){
	for(int j = 1;j <= w;j++) a[i][j] = 'R';
      }
    }
    for(int j = 1;j <= w;j++){
      if(sta & (1<<(j+h-1))){
	for(int i = 1;i <= h;i++) a[i][j] = 'R';
      }
    }
    int now = 0;
    for(int i = 1;i <= h;i++){
      for(int j = 1;j <= w;j++){
	if(a[i][j] == '#') now++;
      }
    }
    if(now == k) ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<typename Num>
        constexpr Num mypow(Num a, long long b) {
            if(b==0)return 1;
            if (a==0)return 0;
            Num x = 1;
              while (b > 0) {
                if(b & 1)x*=a;
                a*=a;
                b >>= 1;
              }
              return x;
        }

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        string s;
        cin>>n>>s;
        ll l,r;
        l=r=0;
        string L="";
        string R="";
        rep(i,n){
            if(s[i]=='(')l++;
            else r++;
            if(l<r){
                l++;
                L=L+'(';
            }
        }
        rep(i,l-r)R=R+')';
        cout<<L+s+R<<endl;
    }

Measured memory_bytes: 3664
N = int(input())
sqrtN = int(N ** 0.5)
fac = []
for i in range(1, sqrtN+1):
    if N % i == 0:
        fac.append(i)
        if i ** 2 != N:
            fac.append(N//i)
ans = 0
div = 0
for p in fac[1:]:
    div = p - 1
    if N // div == N % div:
        # print(i, N//i, N%i)
        ans += div
print(ans)


Measured memory_bytes: 3276
n=int(input())
arr=list(map(int,input().split()))
while len(arr)>1: #最後の1つになるまで操作を続ける
 arr=sorted(arr) #配列を昇順ソート
 v1=arr.pop(0) #最小の2数を取り出し、それらを合成したものを配列に追加する
 v2=arr.pop(0)
 arr.append((v1+v2)/2)
print(arr[0]) #最後に残ったものが答えとなる


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  string s, t;
  cin >> s >> t;
  cout << t + s << endl;
}

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

Measured memory_bytes: 3584
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]

import math
def main():
    H = int(input())
    R = int(math.log2(H)) + 1
    print(2 ** R - 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 1400;
bool T[MAX][MAX];
int main() {
	int H, W;
	int dp[MAX][MAX];
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> T[i][j];
			dp[i][j] = (not T[i][j]);
		}
	}
	int maxw = 0;
	for (int i = 1; i < H; i++) {
		for (int j = 1; j < W; j++) {
			if (T[i][j]) {
				dp[i][j] = 0;
			}
			else {
				dp[i][j] = min(dp[i - 1][j - 1], min(dp[i][j - 1], dp[i - 1][j])) + 1;
				maxw = max(maxw, dp[i][j]);
			}
		}
	}
	if (H == 1 or W == 1) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				maxw = max((int)(not T[i][j]), maxw);
			}
		}
	}
	cout << maxw*maxw << endl;
}

Measured memory_bytes: 12680
var N,i,j,f:Longint;
s,t:String;
begin
readln(N);
readln(s);
readln(t);
i:=N;
while True do begin
f:=0;
for j:=1 to i do begin
if s[N-i+j]<>t[j]then f:=1;
end;
if f=0 then break;
dec(i);
end;
writeln(2*N-i);
end.

Measured memory_bytes: 128
n, t = gets.split.map(&:to_i)
hs = (1..n).map { gets.to_i }
delay = 0
cycle = 0
hs.each do |h|
  cycle = h > cycle ? h : cycle;
  k = (t - delay) / cycle + 1
  k += 1 if (t - delay) % cycle >= h
  puts [k, 1].max
  delay += h
end



Measured memory_bytes: 7784
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <numeric>

using namespace std;

int main(){
    int a, b, c, x, ret = 0;
    cin >> a >> b >> c >> x;
    for(int i = 0; i <= a; i++)
        for(int j = 0; j <= b; j++)
            for(int k = 0; k <= c; k++)
                if(i * 500 + j * 100 + k * 50 == x) ret++;
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0 }, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 
#define lo long long int
#define  NN cout << "No"<<endl;
#define  YY cout << "Yes"<<endl;

lo r;



int main() {
	cin >> r;
	if (r < 1200) { cout << "ABC"; }
	else if (r < 2800) { cout << "ARC"; }
	else { cout << "AGC"; }
	
	
	
	
	//system("pause");
	return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp
{
    char name[100];
    int  t;
}P;

P Q[LEN];
int head,tail,n;


void enqueue(P p)
{
    Q[tail]=p;
    tail=(tail+1)%LEN;

}


P dequeue()
{
    P p=Q[head];
    head=(head+1)%LEN;
    return p;
}

int min(int a,int b)
{
    return a<b?a:b;//???????°????
}
int main()
{
    int elaps=0,c;
    int i,q;
    P p;
    scanf("%d %d",&n,&q);
    for( i=1;i<=n;i++)
    {
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    head=1,tail=n+1;
    while(head!=tail)
    {
        p=dequeue();
        c=min(q,p.t);
        p.t-=c;
        elaps+=c;
        if(p.t>0)
            enqueue(p);
        else{
            printf("%s %d\n",p.name,elaps);
        }
    }

    return 0;


}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
using namespace std;

int main() {
    int n;
    cin >> n;
    if(n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9) cout << "hon" << endl;
    if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) cout << "pon" << endl;
    if(n % 10 == 3) cout << "bon" << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi v(n);
	rep(i, n) cin >> v[i];
	sort(all(v));
	double ans = 0;
	rep(i, n) rep(j, i) {
		int k = n - 1, l = n - 1;
		while(k == i || k == j) k--;
		while(l == i || l == j || l == k) l--;
		ans = max(ans, (v[k] + v[l]) * 1.0 / (v[i] - v[j]));
	}
	printf("%.20f\n", ans);
	return 0;
}


Measured memory_bytes: 3280
#include <stdio.h>
 
int N;
int parent[100001];
int sibling[100001];
int degree[100001];
 
int calcDepth(int i) {
  if(parent[i] == -1) return 0;
  return calcDepth(parent[i]) + 1;
}
 
int calcHeight(int i) {
  int j, h;
  h = 0;
  for(j = 0; j < N; ++j) {
    if(parent[j] == i) {
      int tmp = calcHeight(j) + 1;
      if(tmp > h) h = tmp;
    }
  }
  return h;
}
 
int main() {
  int i,j;
  scanf("%d", &N);
  for(i = 0; i < N; ++i) {
    parent[i] = -1;
    sibling[i] = -1;
    degree[i] = 0;
  }
  for(i = 0; i < N; ++i) {
    int id, left, right;
    scanf("%d %d %d", &id, &left, &right);
    if(left != -1) {
      parent[left] = id;
      sibling[left] = right;
      ++degree[id];
    }
    if(right != -1) {
      parent[right] = id;
      sibling[right] = left;
      ++degree[id];
    }
  }
 
  for(i = 0; i < N; ++i) {
    int depth = calcDepth(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
           i, parent[i], sibling[i], degree[i], depth, calcHeight(i));
    if(depth == 0) {
      printf("root\n");
    } else if(degree[i] == 0) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }
  return 0;
}

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  ll n;
  cin >> n;
  vll u(n - 1), v(n - 1);
  rep(i, n - 1) {
    cin >> u[i] >> v[i];
    if (u[i] > v[i])
      swap(u[i], v[i]);
  }
  ll ans = (n + 2) * (n + 1) * n / 6;
  rep(i, n - 1) ans -= u[i] * (n - v[i] + 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6344
#include<stdio.h>
int main(){
int n,k,i,a,b;
int c[1000];
scanf("%d",&n);
scanf("%d",&k);
for(i=0;i<k;i++){
scanf("%d %d",&a,&b);
if(a>b) a=n+1-a;
else if(a<=b) b=n+1-b;
if(a>b) c[i]=b%3;
else if(a<=b) c[i]=a%3;
if(c[i]==0) c[i]=3;
}
for(i=0;i<k;i++) printf("%d\n",c[i]);
return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e6+5;
int a[N];
int cnt[N];
int f[N];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        cnt[a[i]]++;
    }
    for(int i=1;i<=n;i++)
        if(cnt[i])
            for(int j=max(0,i-cnt[i]);j<i;j++)
                f[j]++;
    int ans=0;
    for(int i=0;i<n;i++)
        if(f[i]==0)
            ans++;
    for(int i=1;i<=m;i++){
        int x,y,z;
        scanf("%d%d",&z,&y);
        x=a[z];
        a[z]=y;
        if(x-cnt[x]>=0){
            f[x-cnt[x]]--;
            if(f[x-cnt[x]]==0)
                ans++;
        }
        cnt[x]--;
        cnt[y]++;
        if(y-cnt[y]>=0){
            if(f[y-cnt[y]]==0)
                ans--;
            f[y-cnt[y]]++;
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <algorithm>

constexpr int MAX_N=50,INF=50;

int n;

int cnt[26];
int min[26];

int main() {
    std::cin>>n;
    std::string str;
    std::fill(min,min+26,INF);
    for(int i=0;i<n;++i){
        std::cin>>str;
        std::fill(cnt,cnt+26,0);
        for(int i=0;i<str.size();++i)
            ++cnt[int(str[i]-'a')];
        for(int i=0;i<26;++i){
            min[i]=std::min(min[i],cnt[i]);
        }
    }
    for(int i=0;i<26;++i){
        for(int j=0;j<min[i];++j)
            std::cout<<char('a'+i);
    }
    std::cout<<std::endl;
    return 0;
}

Measured memory_bytes: 256
def check(x, y): 
    z = [0, 1, 2]
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
                break
            if x[j] == y[z[j]]:
                order[j] = 1 
                if x[j] == x[-j-1]:
                    order[j] = 2 
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
        z = [z[2], z[0], z[1]]
        if i == 2:
            z = [z[0], z[2], z[1]]
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = input().split()
for i in range(n):
    for j in range(i+1, n, 1): 
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Measured memory_bytes: 7812
a = int(input())
b = int(input())
c = int(input())
x = int(input())
counter = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      total = 500*(i) + 100*(j) + 50*(k)
      if (total == x):
        counter += 1
print(counter)

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

class State{
public:
    pair<int, int> p;
    int cost;
    bool is_black;
    State(pair<int, int> p, int cost, bool is_black): p(p), cost(cost), is_black(is_black) {};
    inline bool operator<(State const &rhs) const{
        return cost < rhs.cost || (cost == rhs.cost && p < rhs.p);
    }
};


int main(){
    int H, W;
    string tmp;
    cin >> H >> W;
    vector<string> grid;
    vector<vector<bool>> visited;
    for (int i=0; i<H; i++){
        cin >> tmp;
        grid.emplace_back(tmp);
        visited.emplace_back(vector<bool>(W, false));
    }
    priority_queue<State> Q;
    if (grid[0][0] == '#'){
        Q.emplace(State(pair<int, int>(0, 0), -1, true));
    }
    else{
        Q.emplace(State(pair<int, int>(0, 0), 0, false));
    }
    int ans = 0;
    while (!Q.empty()){
        State s = Q.top();
        Q.pop();
        visited[s.p.first][s.p.second] = true;
        if (s.p.first == H - 1 && s.p.second == W - 1){
            ans = -s.cost;
            break;
        }
        if (s.p.first + 1 < H && grid[s.p.first+1][s.p.second] == '#' && !visited[s.p.first+1][s.p.second]){
            State tmp2(pair<int, int>(s.p.first+1, s.p.second),
                       s.cost -(int)(!s.is_black),
                       true);
            Q.emplace(tmp2);
        }
        else if (s.p.first + 1 < H && !visited[s.p.first+1][s.p.second]){
            State tmp2(pair<int, int>(s.p.first+1, s.p.second),
                       s.cost,
                       false);
            Q.emplace(tmp2);
        }
        if (s.p.second + 1 < W && grid[s.p.first][s.p.second+1] == '#' && !visited[s.p.first][s.p.second+1]){
            State tmp2(pair<int, int>(s.p.first, s.p.second+1),
                       s.cost -(int)(!s.is_black),
                       true);
            Q.emplace(tmp2);
        }
        else if (s.p.second + 1 < W && !visited[s.p.first][s.p.second + 1]){
            State tmp2(pair<int, int>(s.p.first, s.p.second+1),
                       s.cost,
                       false);
            Q.emplace(tmp2);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
struct P {
	long long time, from, to;
};
bool operator<(P a, P b) { return a.time < b.time; }
bool operator>(P a, P b) { return a.time > b.time; }
bool a[20001];
P p[20000];
int main() {
	long long n, m;
	while (cin >> n >> m&&(n != 0 ||m != 0)) {
		for (long long i = 1; i <= n; i++) a[i] = false;
		a[1] = true;
		for (long long i = 0; i < m; i++) {
			cin >> p[i].time >> p[i].from >> p[i].to;
		}
		sort(p, p + m);
		long long sum = 1;
		for (int i = 0; i < m; i++) {
			if (a[p[i].from]) {
				if (!a[p[i].to]) sum++;
				a[p[i].to] = true;
			}
		}
		if(n!=0)cout << sum << endl;
		else cout << 0 << endl;
	}
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<string>
#include<utility>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)

int A,B;




int main() {
	cin>>A>>B;
	int count = 0;
	for(int i=A;i<=B;i++){
		string j;
		j =to_string(i);
		if(j[0]==j[4] && j[1]==j[3]){
			count++;
		}
		
	}
	cout<<count<<endl;
	
	
	
	return 0;
}

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

typedef struct {
  char mark;
  int value;
} KARD;

int isStable(KARD,KARD);

int main()
{
  int i,j,N,minj,a,b,f = 0;
  scanf("%d",&N);
  KARD C[N],sub,D[N];
  for(i = 0;i < N;i++)
    {
      scanf("%c%c%d",&C[i].mark,&C[i].mark,&C[i].value);
    }
  /*for(i = 0;i < N;i++)
    {
      printf("\n%c%d\n",C[i].mark,C[i].value);
      }*/
  for(i = 0;i < N;i++)
    {
      D[i] = C[i];
    }
  
  for(i = 0;i < N;i++)//bubble
    {
      for(j = N - 1; j >= i + 1;j--)
	{
	  if(C[j].value < C[j-1].value)
	    {
	      sub = C[j];
	      C[j] = C[j - 1];
	      C[j - 1] = sub;
	    }	    
	}
    }
  for(i = 0;i < N;i++)
    {
      printf("%c%d",C[i].mark,C[i].value);
      if(i != N- 1)
	{
	  printf(" ");
	}
      else{ printf("\n");}
    }
  for(i = 0;i < N;i++)
    {
      for(j = i + 1;j < N;j++)
	{
	  for(a = 0;a < N;a++)
	    {
	      for( b = a + 1;b < N;b++)
		{
		  if(D[i].value == D[j].value && D[i].mark == C[b].mark &&D[i].value == C[b].value && D[j].mark == C[a].mark && D[j].value == C[a].value)
		    {
		       printf("Not stable\n");
		       f = 1;
		    }
		}
	    }
	}
    }
  if(f == 0)
    {
      printf("Stable\n");
    }
  
  f = 0;
  for(i = 0;i < N;i++)
    {
      C[i] = D[i];
    }
  for(i = 0;i < N - 1;i++)//selection
    {
      minj = i;
      for(j = i;j < N;j++)
	{
	  if(C[j].value < C[minj].value)
	    {
	      minj = j;
	    }
	}
      sub = C[i];
      C[i] = C[minj];
      C[minj] = sub;
    }

for(i = 0;i < N;i++)
    {
      printf("%c%d",C[i].mark,C[i].value);
      if(i != N- 1)
	{
	  printf(" ");
	}
      else{ printf("\n");}
    }
  for(i = 0;i < N;i++)
    {
      for(j = i + 1;j < N;j++)
	{
	  for(a = 0;a < N;a++)
	    {
	      for( b = a + 1;b < N;b++)
		{
		  if(D[i].value == D[j].value && D[i].mark == C[b].mark &&D[i].value == C[b].value && D[j].mark == C[a].mark && D[j].value == C[a].value)
		    {
		      f ++;
		      if(f == 1)
			{
			  printf("Not stable\n");
			}
		    }
		}
	    }
	}
    }
  if(f == 0)
    {
      printf("Stable\n");
    }
 return 0;
}



Measured memory_bytes: 2104
import itertools


def main():
    n, k, c = [int(x) for x in input().split()]
    s = input()
    interval = c + 1

    def greedy_working(s):
        i = 0
        li = []
        while len(li) < k:
            if s[i] == 'o':
                li.append(i)
                i += interval
            else:
                i += 1
        return li

    earl = greedy_working(s)
    # 働ける日の文字列を反転すれば後ろから日付を選べる。それをまた反転し，
    # 最終日から引くことで実際の労働日を算出。
    late = [n - d - 1 for d in greedy_working(s[::-1])[::-1]]

    # 最初はsetでやろうとしていた。しかし，最速と最遅の共通の日付を
    # 取るだけだと，何番目の労働日か問わなくなってしまう。
    # ちゃんと1ケースでWAが出る。
    must_work = []
    for i, j in zip(earl, late):
        if i == j:
            must_work.append(i + 1)
    if len(must_work) == 0:
        return
    for i in must_work:
        print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 28652
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	n, _ := sc.NextInt()
	s, _ := sc.NextInt()
	a, _ := sc.NextInts(n)
	ans := solve(n, s, a)
	fmt.Println(ans)
}

const mod = 998244353

func solve(n, s int, a []int) (ans int) {
	dp, prev := make([]int, s+1), make([]int, s+1)
	dp[0] = 1
	for i := 0; i < n; i++ {
		copy(prev, dp)
		for j := 0; j <= s; j++ {
			dp[j] = 2 * prev[j]
			dp[j] %= mod
			if j-a[i] >= 0 {
				dp[j] += prev[j-a[i]]
				dp[j] %= mod
			}
		}
	}
	return dp[s]
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}

// NextInts reads n integers from io stream.
func (sc *Scanner) NextInts(n int) (arr []int, e error) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		v, e := sc.NextInt()
		if e != nil {
			return nil, e
		}
		arr[i] = v
	}
	return arr, nil
}


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


using namespace std;

#define ll long long

int main(){
#ifndef ONLINE_JUDGE
  freopen ("input.txt", "r", stdin);
  freopen ("outt.txt", "w", stdout);
#endif


ll n;
cin>>n;
ll ans = 0LL;

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

  ans+= (n-i)*(i+1);

}

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

   ll a,b;
   cin>>a>>b;
   if(a>b)  swap(a,b);
   a--;
   b--;
  
   ans-= (a+1)*(n-b);

}


cout<<ans;

}

Measured memory_bytes: 3552
def main():
    Q,H,S,D = map(int,input().split())
    N = int(input())
    mincos = min(4*Q,2*H,S)
    t1 = N*mincos
    t2 = (N//2)*D + (N%2)*mincos
    print(min(t1,t2))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	long long int z, w, a[2000];
	scanf("%d %lld %lld", &n, &z, &w);
	for(int i=0; i<n; i++){
		scanf("%lld", &a[i]);
	}
	if(n==1){
		printf("%lld\n", abs(a[0]-w));
	}else if(abs(a[n-1]-w)>abs(a[n-2]-a[n-1])){
		printf("%lld\n", abs(a[n-1]-w));
	}else{
		printf("%lld\n", abs(a[n-2]-a[n-1]));
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

const int inf = 1<<29;
int H, W;
vector<vector<char>> fi(25, vector<char>(25, '#'));
vector<vector<int>> dist(25, vector<int>(25, 0));

int d1[4] = {1,-1,0,0};
int d2[4] = {0,0,1,-1};

void input() {
    cin >> H >> W;
    repr(i, 1, H+1) repr(j, 1, W+1) cin >> fi[i][j];
}

void bfs(int sh, int sw) {
    repr(i, 1, H+1) repr(j, 1, W+1) dist[i][j] = inf;
    dist[sh][sw] = 0;

    queue<pair<int, int>> qu;
    qu.push(make_pair(sh, sw));

    while(!qu.empty()) {
        auto now = qu.front(); qu.pop();
        int x = now.first; int y = now.second;
        rep(k, 4) {
            int nx = x+d1[k]; int ny = y+d2[k];
            if (1<=nx && nx<=H && 1<=ny && ny<=W && fi[nx][ny]=='.' && dist[nx][ny]==inf) {
                dist[nx][ny] = dist[x][y] + 1;
                qu.push(make_pair(nx, ny));
            } 
        }
    }
}

void solve() {
    int ans = 0;

    repr(sh, 1, H+1) repr(sw, 1, W+1) if (fi[sh][sw] == '.') {
        repr(gh, 1, H+1) repr(gw, 1, W+1) if (fi[gh][gw] == '.') {
            bfs(sh, sw);
            chmax(ans, dist[gh][gw]);
        }
    }
    cout << ans << endl;
}

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

    input();
    solve();

    return 0;
}

Measured memory_bytes: 256
/*
        FFFFFFFFFFFFFFFFFFFFFF
        F::::::::::::::::::::F
        F::::::::::::::::::::F
        FF::::::FFFFFFFFF::::F
          F:::::F       FFFFFF
          F:::::F
          F::::::FFFFFFFFFF
          F:::::::::::::::F
          F:::::::::::::::F
          F::::::FFFFFFFFFF
          F:::::F
          F:::::F
        FF:::::::FF
        F::::::::FF
        F::::::::FF
        FFFFFFFFFFF
*/
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define int long long
#define mod 1000000007 //998244353
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define nl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<nl
#define cout2(a,b) cout<<a<<" "<<b<<nl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<nl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<nl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<nl
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define ms(v,n) memset((v),n,sizeof(v));
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod 
#define ad(a,b)  (a%mod+b%mod+mod)%mod
#define inf 1e18
#define cases ll T;cin>>T;while(T--)
#define BLOCK 500
//const double PI = 3.141592653589793238460;
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;


int32_t main()
{
    
	fast
	ll k;
	cin>>k;
	ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	
	
	
	cout<<a[k-1];
	
	

	



    

	return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	string a;
	cin>>a;
	int ans=0;
	for(int i=1;i<=n-1;i++)
	{
		if(a[i]=='R'&&a[i-1]=='R')
		{
			ans++;
		}
	}
	for(int i=n-2;i>=0;i--)
	{
		if(a[i]=='L'&&a[i+1]=='L')
		{
			ans++;
		}
	}
	cout<<min(ans+k*2,n-1);
	return 0;
}

Measured memory_bytes: 512
n, a, b = map(int, input().split())

total = 0
for i in range(n+1):
    str_i = str(i)
    sub_total = 0
    for s in str_i:
        sub_total += int(s)
    if a <= sub_total and sub_total <= b:
        total += i

print(total)

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

class Solver {
  public:
    bool solve() {
        ll K; cin >> K;

        if(K == 0) {
            cout << 2 << endl;
            cout << 1 << " " << 1 << endl;
        }
        else if(K == 1) {
            cout << 3 << endl;
            cout << 1 << " " << 0 << " " << 3 << endl;
        }
        else {
            ll N = 50;
            ll a = N + (K / N);
            cout << N << endl;
            vector<ll> v(N);
            rep(i, K % N) v[i] = a;
            repeat(i, K % N, N) v[i] = a - (K % N + 1);
            rep(i, N) {
                cout << v[i] << (i == N - 1 ? "\n" : " ");
            }
        }
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
def g(a,b):
    if a*b:
        if a>b:
            return g(a-b,b)
        elif(a<b):
            return g(a,b-a)
        else:
            return a
    else:
        if(a*b):
            return max(a,b)
        else:
            return 1
n=int(input())
print(360//g(n,360))

Measured memory_bytes: 9228
n=int(input())
m=['M','A','R','C','H']
d={}
for _ in range(n):
    s=input()[0]
    if s in m:
        if s in d:d[s]+=1
        else:d[s]=1
d=list(d.values())
r=0
l=len(d)
for i in range(l):
    for j in range(i+1,l):
        for k in range(j+1,l):
            r+=d[i]*d[j]*d[k]
print(r)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;
ll a[N],d[N];

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int ans=0;
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]%2==1 && i%2==1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

int array[10];
int n;
int i,j;
bool ans;

void dfs(int de,int b,int c)
{
	ans = false;

		if(de >= 10){
			ans = true;
			return;
		}

		if(b < array[de])
			dfs(de+1,array[de],c);
		if(c < array[de])
			dfs(de+1,b,array[de]);
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
	{
	for(j=0; j<10; j++)
		cin >> array[j];

		dfs(0,0,0);

	if(ans)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int N,check=0;
	cin>>N;
	for(int i=0;i<26;i++){
		for(int j=0;j<16;j++){
			if(4*i+7*j==N){
				check=1;
				break;
			}
		}
	}
	if(check==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getchar();
	return f * x;
}

int n, m, k;
char s[100003];

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	scanf("%s", s + 1); k = gi(); n = strlen(s + 1);
	for (int i = 1; i <= n; i+=1)
	{
		int o = s[i] - 'a';
		if (k >= (26 - o) && o != 0)
		{
			s[i] = 'a';
			k -= (26 - o);
		}
	}
	k %= 26;
	int o = s[n] - 'a';
	o = (o + k) % 26;
	//cout << o << endl;
	s[n] = 'a' + o;
	for (int i = 1; i <= n; i+=1) printf("%c", s[i]);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int A, B;
  cin >> A >> B;

  if(A == B) {
    cout << "Draw" << endl;
  }
  else if(A == 1) {
    cout << "Alice" << endl;
  }
  else if(B == 1) {
    cout << "Bob" << endl;
  }
  else if(A > B) {
    cout << "Alice" << endl;
  }
  else {
    cout << "Bob" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
using namespace std;

const double inf = 1e10;

struct D {
    vector<double> l, r;
    D():l(3,inf),r(3,-inf) {}
    void add(double x, int v) {
        ++v;
        mins(l[v],x);
        maxs(r[v],x);
    }
    double get(double t) {//幅
        double nl = inf, nr = -inf;
        rep(i,3) {
            mins(nl, l[i]+i*t);
            maxs(nr, r[i]+i*t);
        }
        return nr-nl;
    }
    vector<double> events() {
        vector<double> ts;
        rep(i,3)rep(j,i) { // j < i
            {
            double t = (l[j]-l[i])/(i-j);
            if (t > 0) ts.push_back(t);
            }
            {
            double t = (r[j]-r[i])/(i-j);
            if (t > 0) ts.push_back(t);
            }
        }
        return ts;
    }
};

int main() {
    int n;
    cin >> n;
    D xd, yd;
    rep(i,n) {
        int x, y;
        char d;
        cin >> x >> y >> d;
        if (d == 'L') xd.add(x,-1), yd.add(y,0);
        if (d == 'R') xd.add(x,1), yd.add(y,0);
        if (d == 'U') xd.add(x,0), yd.add(y,1);
        if (d == 'D') xd.add(x,0), yd.add(y,-1);
    }
    vector<double> ts;
    ts.push_back(0);
    //ts.push_back(inf);
    {
    auto nts = xd.events();
    ts.insert(ts.end(),nts.begin(),nts.end());
    }
    {
    auto nts = yd.events();
    ts.insert(ts.end(),nts.begin(),nts.end());
    }
    sort(ts.begin(),ts.end());
    double ans = 1e18;
    for (double t : ts) {
        double now = xd.get(t)*yd.get(t);
        mins(ans,now);
    }
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main(){
  int a, b, ans;
  cin >> a >> b;
  b = b * 2;
  if (b >= a){
    ans = 0;
  }
  else{
    ans = a - b;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import heapq

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
h = []
for a in A:
    heapq.heappush(h, -a)

for _ in range(M):
    a = -heapq.heappop(h)
    a //= 2
    heapq.heappush(h, -a)

print(-sum([heapq.heappop(h) for x in range(len(h))]))


Measured memory_bytes: 14180
T1, T2 = gets.chomp.split(" ").map(&:to_i)
A1, A2 = gets.chomp.split(" ").map(&:to_i)
B1, B2 = gets.chomp.split(" ").map(&:to_i)

R1 = A1 - B1
R2 = A2 - B2
DR1 = R1 * T1
DR2 = R2 * T2
DR = DR1 + DR2

if DR.zero?
  puts "infinity"
  exit
end
if DR1 * DR > 0
  puts 0
  exit
end

n, m = DR1.divmod(DR)
if m.zero?
  puts 1 + (n.abs - 1) * 2 + 1
else
  puts 1 + (n.abs - 1) * 2
end


Measured memory_bytes: 1788