akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

// 0->バンの数, 1->パティの数
ll dp[55][2] = {};

// パティの数を返す
ll bg(ll level, ll sou) {
  if (level == 0) return 1;

  if (sou == 1)
    return 0;
  else if (sou < dp[level - 1][0] + 2)
    return bg(level - 1, sou - 1);
  else if (sou == dp[level - 1][0] + 2)
    return dp[level - 1][1] + 1;
  else if (sou < dp[level][0])
    return dp[level - 1][1] + 1 + bg(level - 1, sou - dp[level - 1][0] - 2);
  else
    return dp[level][1];
}

int main() {
  ll level, sou;
  cin >> level >> sou;

  dp[0][0] = 1;
  dp[0][1] = 1;
  for (int i = 1; i <= level; i++) {
    dp[i][0] = dp[i - 1][0] * 2 + 3;
    dp[i][1] = dp[i - 1][1] * 2 + 1;
  }

  cout << bg(level, sou) << endl;
}


Measured memory_bytes: 256
var
  n,i,max,mmaaxx:longint;
  s:string;
begin
 max:=0;mmaaxx:=0;
  readln(n);
   readln(s);
    for i:=1 to n do
     begin
      if s[i]='I' then inc(max)
       else dec(max);
        if mmaaxx<max then mmaaxx:=max;
     end;
      if mmaaxx<=0 then 
       begin
        writeln(0);
        halt;
       end;
        writeln(mmaaxx);
end.


Measured memory_bytes: 128
t = input()
ans = list(t)

if ans[-1] == '?':
  ans[-1] = 'D'

tl = len(t)
for i in range(-2, -tl-1, -1):
  if ans[i] == '?':
    if ans[i+1] == 'P':
      ans[i] = 'D'
    else:
      if i != -tl and ans[i-1] == 'P':
        ans[i] = 'D'
      else:
        ans[i] = 'P'
print(''.join(ans))

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}
#define yes cout<<"Yes"<<nl
#define no cout<<"No"<<nl
#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  int n;
  cin>>n;
  if(n<4)
  {
    no;
    return;
  }
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=n;j++)
    {
      if(4*i+7*j==n)
      {
        yes;
        return;
      }
    }
  }
  no;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

template<class T>bool chmax(T &a, const T &b) { if( a < b ) { a = b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if( b < a ) { a = b; return 1; } return 0;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

int c[10][10];
int dmin[10];
const int INT_INF = 2147483647;

int dijkstra(int s) {
	queue<int> que;
	que.push(s);
	for (int i = 0; i < 10; i++) {
		dmin[i] = INT_INF/2;
		if (i != s)que.push(i);
	}
	dmin[s] = 0;

	while (!que.empty()) {
		int u = que.front();
		que.pop();
		for (int v = 0; v < 10; v++) {
			if (dmin[v] > dmin[u] + c[u][v]) {
				dmin[v] = dmin[u] + c[u][v];
			}
		}
	}
	return dmin[1];
}

int main() {
	int cx[10];
	int W, H;
	scanf("%d %d", &H, &W);
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			scanf("%d", &c[i][j]);
		}
	}
	// for (int i = 0; i < 10; i++) {
	// 	cx[i] = dijkstra(i);
	// 	eprintf("cx[%d]=%d\n", i, cx[i]);
	// }	
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (c[i][j] > c[i][k] + c[k][j]) c[i][j] = c[i][k]+c[k][j];
			}
		}
	}
	for (int i = 0; i < 10; i++) {
		cx[i] = c[i][1];
	}
	int sum = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int Aij;
			scanf("%d", &Aij);
			if (Aij*Aij != 1) sum += cx[Aij];
		}
	}

	printf("%d\n", sum);
}


Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
count = 0
for i in range(1,n-1):
    c=[p[i-1],p[i],p[i+1]]
    c.sort()
    if c[1] == p[i]:
        count+=1
    """
    if c[i]>c[i-1] and c[i]<c[i+1]:
        count +=1"""
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, ans = 1;
  cin >> n;
  
  string s;
  cin >> s;

  
  for(int i = 0; i < s.size() - 1; i++){
    if(s.at(i) != s.at(i + 1))
      ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 512
N,M = map(int,input().split())
if N == 2 or M == 2:
    print(0)
elif N == 1 or M == 1:
    if N*M == 1:
        print(1)
    else:
        print(M*N - 2)
else:
    print( (N-2) * (M-2) )

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static  ll INF = 1e9;
using namespace std;

signed main(){
	int n;
	cin>>n;
	int cnt=0;
	vector<int>p(n);
	rep(i,n)cin>>p[i];
	rep(i,n){
		if(p[i]!=(i+1))++cnt;
	}
	if(cnt==0||cnt==2)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  vector<int> count(N);
  for(int j=0;j<M;j++){
    cin >> a.at(j);
    cin >> b.at(j);
    for(int i=0;i<N;i++){
      if(a.at(j)==i+1){
        count.at(i)++;
      }
      if(b.at(j)==i+1){
        count.at(i)++;
      }
    }
  }
  for(int k;k<N;k++){
    cout << count.at(k) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public void plus(int x, int y){

		int ans = x + y;
		System.out.println(ans);
	}
	public void minus(int x, int y){

		int ans = x - y;
		System.out.println(ans);
	}
	public void times(int x, int y){

		int ans = x * y;
		System.out.println(ans);
	}
	public void divide(int x, int y){

		int ans = x / y;
		System.out.println(ans);
	}
	public static void main(String[] args) {

		Main n = new Main();
		Scanner scan = new Scanner(System.in);

		for(;;){

			int x = scan.nextInt();
			char ch = scan.next().charAt(0);
			int y = scan.nextInt();

			switch(ch){
			case '+':
				n.plus(x, y);
				break;
			case '-':
				n.minus(x, y);
				break;
			case '*':
				n.times(x, y);
				break;
			case '/':
				n.divide(x, y);
				break;
			default:
				scan.close();
				System.exit(0);
			}
		}
	}
}

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

int main() {
  vector<int> vec(3);
for (int i = 0; i < 3; i++) {
  cin >> vec.at(i);
}
  sort(vec.begin(),vec.end());
  
  if(vec.at(2)==vec.at(0)+vec.at(1)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
namespace B___754
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var a = new List<int>();
            var min = int.MaxValue;
            for (var i = 0; i + 2 < s.Length; i++)
            {
                a.Add(int.Parse(s.Substring(i, 3)));
            }
            for (var i = 0; i < a.Count; i++)
            {
                var b=Math.Abs(753 - a[i]);
                min=Math.Min(min, b);
            }
            Console.WriteLine(min);
        }
    }
}

Measured memory_bytes: 11092
#include <string>
#include <iostream>
using namespace std;
  
int w,h,ans,dx[]={0,-1,0,1}, dy[]={-1,0,1,0};
char c[22][22];
 
void solve(int x,int y){
    ans++;
    c[x][y]='#';
    for(int i=0;i<4;i++){
        int nx=x+dx[i], ny=y+dy[i];
        if(0<=nx && nx<w && 0<=ny && ny<h && c[nx][ny]=='.')solve(nx,ny);
    }
}
 
int main(){
    while(cin>>w>>h, w){
        ans=0;
        int x,y;
        for(int i=0;i<h;i++){
            for(int j=0; j<w; j++){
                cin>>c[j][i];
                if(c[j][i]=='@')x=j,y=i;
            }
        }
        
        solve(x,y);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1172
from collections import defaultdict

N = int(input())
a = [int(i) for i in input().split()]

b = defaultdict(lambda : [float('inf'), 0])
for i in range(N) :
    b[a[i]][0] = min(b[a[i]][0], i)
    b[a[i]][1] += 1

# [value, first_appearance, count]
c = [(0, 0, 0)]
for k, v in b.items() :
    c.append((k, v[0], v[1]))
c.sort()

ret = [0] * N
pre_v, pre_i, pre_c = c.pop()
while c :
    cur_v, cur_i, cur_c = c.pop()
    ret[pre_i] += (pre_v - cur_v) * pre_c
    cur_c += pre_c
    pre_v, pre_i, pre_c = cur_v, min(pre_i, cur_i), cur_c
    
for r in ret :
    print(r)

Measured memory_bytes: 95084
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Map.Entry;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, Integer> an = new HashMap<Integer, Integer>();
        for (int i = 0; i < n; i++) {
            int k = sc.nextInt();
            if (an.containsKey(k)) {
                an.put(k, Integer.parseInt(an.get(k).toString()) == 1 ? 0 : 1);
            } else {
                an.put(k, 1);
            }
        }

        int c = 0;
        for (Entry<Integer, Integer> e : an.entrySet()) {
            if (e.getValue() == 1) {
                c += 1;
            }
        }

        System.out.println(c);
    }

}

Measured memory_bytes: 60432
#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++)
typedef long long ll;

int main(){
    ll a,b,x,ans=0;
    cin >> a >> b >> x;
    ll amari=a%x;
    ll nokori=(x-amari)%x;
    a=a+nokori;
    if(a>b){
        cout << ans << endl;
    }else{
        ans++;
        ans+=(b-a)/x;
        cout << ans << endl;
    }
    
    return 0;
}







Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(pii& a, pii& b) {
	return a.first < b.first;
}

int xbackcomp(pii& a, pii& b) {
	return a.first > b.first;
}
#define XSORT(c) sort((c).begin(),(c).end(),xcomp)
#define XBACKSORT(c) sort((c).begin(),(c).end(),xbackcomp)

LL digit(LL n){
  LL sum = 0;
  REP(i,18){
    if((n&(1<<i))>0){
      sum++;
    }
  }
  return sum;
}

int main() {
  LL N;
  cin >> N;
  LL N_cnt = 1 << N;
  vector<pii> A(N_cnt);
  vector<pii> AA(N_cnt);
  vector < vector<LL> > B(N+1,vector<LL>(0));//各ビットをもつやつ
  vector<vector<LL> > C(N+1, vector<LL>(0)); //それまでのやつ
  vector<vector<pii> > D(N+1, vector<pii>(0));//立ってる桁数
  vector<pair<pii,pii> > E(N_cnt);
  REP(i, N_cnt)
  {
    LL a;
    cin >> a;
    A[i] = make_pair(a, i);
    AA[i] = A[i];
    if (i == 0)
    {
      E[0] = make_pair(make_pair(A[0].first,0),make_pair(A[0].first,0));
    }
  }
  XBACKSORT(A);
  REP(i,N_cnt){
    REP(j,N+1){
      if((A[i].second&(1<<j))>0){
        B[j].push_back(A[i].first);
      }
      if(A[i].second<(1<<j)){
        C[j].push_back(A[i].first);
      }
    }
    D[digit(A[i].second)].push_back(A[i]);
  }
  REP(i, D.size())
  {
    if(i==0){

    }else{
      REP(j,D[i].size()){
        pii M = D[i][j];
        LL M_dig = digit(M.second);
        vector<pii> hoge(0);
        REP(k, N+1)
        {
          LL MM = M.second ^ (1 << k);
          if (M_dig == (digit(MM)) + 1)
          {
            hoge.push_back(E[MM].first);
            hoge.push_back(E[MM].second);
          }
        }
        hoge.push_back(M);
        XBACKSORT(hoge);
        pii fir = hoge[0];
        FOR(k,1,hoge.size()){
          if(hoge[k].second!=fir.second){
            E[M.second] = make_pair(fir,hoge[k]);
            break;
          }
        }
      }
    }
  }
  LL upper = 0;
  FOR(i, 1, N_cnt)
  {
    if(i>=2){
      LL dig;
      REP(j, 1000)
      {
        if((i>>j)==0){
          dig = j;
          break;
        }
      }
      LL hoge = max(E[i].first.first + E[i].second.first, C[dig - 1][0] + C[dig - 1][1]);
      if(hoge>upper){
        upper = hoge;
      }
      cout << upper << endl;
    }
    else
    {
      cout << AA[0].first + AA[1].first << endl;
    }
  }
}


Measured memory_bytes: 49528
#include<stdio.h>
 #include<string.h>
 int main(void)
 {
     char S[11];
     int i,j=0,k=0,s=0;

     scanf("%s",S);
     s=strlen(S);

     if(S[0]=='A')
       for(i=0;i<=s-4;i++){
         if(S[i+2]=='C')
           j++;
       }

     if(j==1){
       for(i=0;i<s;i++){
         if((S[i]>='a')&&(S[i]<='z'))
           k++;
       }
     }

     if(k==s-2) printf("AC\n");
     else printf("WA\n");

     return 0;
 }


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

long long int ketasu(long long int a){
	int count=0;
	while(1){
	if(a/10==0){
		return count+1;
	}else{
		a = a/10;
		count++;
	}
	}
}

long long int zyo(long long int a,long long int b){
	long long int ans = 1;
	for(int i=0;i<b;i++){
		ans = ans*a;
	}
	return ans;
}

int main() {
	long long int N;
	long long int sum = 0;
	scanf("%lld",&N);
	int keta = ketasu(N);
	int n[keta];
	for(int i=0;i<keta;i++){
		n[keta-1-i] = N%10;
		N = N/10;
	}
	for(int i=0;i<keta;i++){
		for(int j=1;j<=keta-i;j++){
			if(j==keta-i){
				sum += n[i]*zyo(10,j-1)*zyo(2,keta-j);
			}else{
			sum += n[i]*zyo(10,j-1)*zyo(2,keta-j-1);
			}
			
			//数の桁数＊通り
			//}
		}
	}
	
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n= readLine()!!.toInt()
    var a = readLine()!!.split(" ").map{i -> i.toInt()}.sorted().reversed()
    var alice = 0
    var bob = 0

    for( i in 0..n-1){
        if(i % 2 == 0) alice += a[i] else bob += a[i]
    }
    println(alice - bob)
}

Measured memory_bytes: 37780
#include <stdio.h>



int main()
{
	int H1, H2, M1, M2, k, tH, tM;
	scanf("%d %d %d %d %d", &H1, &M1, &H2, &M2, &k);
	tH = H2 - H1;
	tM = M2 - M1;
	tH = ((tH * 60) + tM) - k ;
	
	printf("%d", tH);
	return 0;
}

Measured memory_bytes: 3248
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.14159265358;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  if(N <= 5){
    vector<int> A = {2,5,63,20,30};
    for(int i=0; i<N; i++){
      cout << A[i] << " \n"[i+1==N];
    }
    return 0;
  }
  int sum = 0;
  vector<int> ans;
  vector<int> vec = {2,3,4,6};
  int now = 0;
  while(1){
    if(ans.size() == N) break;
    for(int i=0; i<4; i++){
      if(ans.size() == N) break;
      ans.emplace_back(now + vec[i]);
      sum += now + vec[i];
      sum %= 6;
    }
    now += 6;
  }
  if(sum == 2){
    ans.erase(ans.begin()+4);
    ans.emplace_back(30000);
  }else if(sum == 3){
    ans.erase(ans.begin()+5);
    ans.emplace_back(30000);
  }else if(sum == 5){
    ans.erase(ans.begin()+5);
    ans.emplace_back(30000-2);
  }
  for(int i=0; i<ans.size(); i++){
    cout << ans[i] << " \n"[i+1==ans.size()];
  }
  return 0;
}

Measured memory_bytes: 3740
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())

int main(){
  int n;
  cin>>n;
  vll a(n);
  REP(i,n){
    cin>>a[i];
  }
  ll count=0;
  while(count<n-1){
    sort(a.begin(),a.end());
    FOR(i,1,n){
      if(a[i]!=INT_MAX){
        a[i]%=a[0];
        if(a[i]==0){a[i]=INT_MAX;count++;}
      }
    }
  }
  cout<<a[0]<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;
    repr(h, 1, 3501){
        if(4*h*3500*3500 < 3500*3500*N + h*3500*N + h*3500*N){
            continue;
        }
        repr(n, h, 3501){
            if(4*h*n*3500 < n*3500*N + h*3500*N + h*n*N){
                continue;
            }
            repr(w, n, 3501){
                if(4*h*n*w > n*w*N + h*w*N + h*n*N){
                    break;
                }else if(4*h*n*w == n*w*N + h*w*N + h*n*N){
                    cout << h << " " << n << " " << w << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
//解説コピー
//テスト用　自力では無い

#include <bits/stdc++.h>

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;
const ll INF = 1LL<<60;

int main() {
    int N,M;
    cin>>N>>M;
    vector<pair<int,ll>> tonari[1001];
    for(int i = 0; i < M; ++i) {
        int a,b; ll w;
        cin>>a>>b>>w;
        tonari[a-1].push_back({b-1,-w});
    }

    bool heikei=false;
    vector<ll> dist(N,INF);
    dist[0]=0;
    for(int i=0;i< 2*N ;i++){
        for(int v=0;v<N;v++) {
            if (dist[v] >= INF) continue;
            for (auto next:tonari[v]) {
                if (dist[next.first] > dist[v] + next.second) {
                    dist[next.first] = dist[v] + next.second;
                    if (next.first == N - 1 &&i > N) heikei=true;
                }
            }
        }
    }
    if(heikei) cout<<"inf"<<endl;
    else cout<<-dist[N-1]<<endl;

    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

bool f(string S){
    int N = S.size();
    bool flg = true;
    REP(i, N/2) if(S[i] != S[N-1-i]) flg = false;
    return flg;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    string S, S2, S3;
    cin >> S;
    int N = S.size();
    S2.resize(N/2), S3.resize(N/2);
    REP(i, (N-1)/2) S2[i] = S[i];
    REP(i, (N-1)/2) S3[i] = S[i + (N-1)/2 + 1];
    bool flg1 = f(S);
    bool flg2 = f(S2);
    bool flg3 = f(S3);
    if(flg1 && flg2 && flg3) cout << "Yes";
    else cout << "No";

    return 0;
}

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

int main()
{
        int n, m, l;

        cin >> n >> m >> l;

        long a[n][m], b[m][l], c[n][l];

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

        for(int j = 0; j < m; j++) {
                for(int k = 0; k < l; k++) {
                        cin >> b[j][k];
                }
        }

        for(int i = 0; i < n; i++) {
                for(int j = 0; j < l; j++) {
                        c[i][j] = 0;
                }
        }

        for(int i = 0; i < n; i++) {
                for(int j = 0; j < l; j++) {
                        for(int k = 0; k < m; k++) {
                                c[i][j] += a[i][k]*b[k][j];
                        }
                        if(j == l-1) {
                                cout << c[i][j] << endl;
                        } else {
                                 cout << c[i][j] << ' ';
                        }
                }
        }

        return 0;
}


Measured memory_bytes: 3304
n = gets.to_i
a = (1..n).map{ gets.split.map(&:to_i) }
accum = a.map{|row|
    row.inject([0]){|s, x| s + [s[-1] + x]} 
}

max = 0 
(1..n).to_a.repeated_combination(2){|i, j|
    sum = 0 
    (0..n-1).each{|k|
        sum += accum[k][j] - accum[k][i-1]
        max = sum if sum > max
        sum = 0 if sum < 0
    }
}

a.flatten!
p a.any?{|x| x >= 0} ? max : a.max

Measured memory_bytes: 7808
n = int(input())
s = input()
answer = ["a"] * len(s)

for i in range(len(s)):
    #print(s[i])
    if((ord(s[i])+n)<=90):
        answer[i] = chr(ord(s[i])+n)
    else:
        answer[i] = chr(ord(s[i])+n-26)

answer=''.join(answer)
print(answer)

Measured memory_bytes: 3064
import math

line = input().split()
a = int(line[0])
b = int(line[1])
c = int(line[2])
x = int(line[3])
y = int(line[4])

m = max(x, y)
price = a * x + b * y

for i in range(1 ,m + 1):
  tx = max(x - i, 0)
  ty = max(y - i, 0)  
  tprice = i * 2 * c + a * tx + b * ty
  if tprice < price:
    price = tprice

print(price)


Measured memory_bytes: 3064
def roll(dice,dir)
  case dir
  when "N" then dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0]
  when "S" then dice[0],dice[1],dice[5],dice[4] = dice[4],dice[0],dice[1],dice[5]
  when "E" then dice[0],dice[2],dice[5],dice[3] = dice[3],dice[0],dice[2],dice[5]
  when "W" then dice[0],dice[2],dice[5],dice[3] = dice[2],dice[5],dice[3],dice[0]
  end
  dice
end

d1 = gets.split(" ").map{|i| i.to_i}
d2 = gets.split(" ").map{|i| i.to_i}

yn = false    
for i in 1..6
  d = Marshal.load(Marshal.dump(d2))
  case i
  when 2 then d = roll(d,"S")
  when 3 then d = roll(roll(d,"W"),"S")
  when 4 then d = roll(d,"N")
  when 5 then d = roll(roll(d,"E"),"S")
  when 6 then d = roll(roll(d,"S"),"S")
  end
  next if d[1] != d1[1]
  for j in 1..4
    d = roll(d,"W")
    yn = (yn || d == d1)
  end
end

puts(yn ? "Yes" : "No")

Measured memory_bytes: 8720
N = int(input())
if N % 4 == 0:
    print('Yes')
    exit(0)
if N % 7 == 0:
    print('Yes')
    exit(0)

for j in range(0,101):
    if N - 4 * j > 0:
        if (N - 4 * j) % 7 == 0:
            print('Yes')
            exit(0)
    else:
        break
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
using namespace std;
int main(void){
   int a,b;
   cin>>a>>b;
   for(int c=1;c<=3;c++){
       if(a*b*c%2){
           cout<<"Yes"<<endl;
           return 0;
       }
   }
cout<<"No"<<endl;

}

Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Console.WriteLine(a[0]<=999 ? "ABC" : "ABD");
        }
    }
}



Measured memory_bytes: 13396
h, w = map(int, input().split())
a = [input() for _ in range(h)]
r = [False]*h
c = [False]*w
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            r[i] = True
            c[j] = True
for i in range(h):
    if r[i]:
        for j in range(w):
            if c[j]:
                print(a[i][j], end = "")
        print()

Measured memory_bytes: 4468
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

#define MAXV 1000000000
#define MOD 1000000007
using ll = long long;

bool operator<(const pair<int, int>& a, const pair<int, int>& b) {
	if (a.first == b.first) {
		return a.second < b.second;
	}
	return a.first < b.first;
}



void rec(int x, int y, vector<string>& v) {
	v[y][x] = '0';

	for (int i = 1; i <= 3; ++i) {
		int nx = x - i;
		if (nx >= 0 && v[y][nx]=='1') {
			rec(nx, y, v);
		}
	}

	for (int i = 1; i <= 3; ++i) {
		int nx = x + i;
		if (nx <8 && v[y][nx] == '1') {
			rec(nx, y, v);
		}
	}

	for (int i = 1; i <= 3; ++i) {
		int ny = y - i;
		if (ny >=0 && v[ny][x] == '1') {
			rec(x, ny, v);
		}
	}

	for (int i = 1; i <= 3; ++i) {
		int ny = y + i;
		if (ny <8 && v[ny][x] == '1') {
			rec(x, ny, v);
		}
	}
}
int main() {

	int N;
	cin >> N;
	//cin.ignore();
	for (int i = 0; i < N; ++i) {
        cout << "Data " << i+1 << ":" << endl;
		vector<string> v;
		for (int j = 0; j < 8; ++j) {
			string s;
            cin >> s;
			v.push_back(s);
		}

		int X, Y; cin >> X >> Y;

		X--;
		Y--;
        //cout << X << " " << Y << endl;
		rec(X, Y, v);

		for (int j = 0; j < 8; ++j) {
			for (int k = 0; k < 8; ++k) {
				cout << v[j][k];
			}
			cout << endl;
		}
        //cout << endl;
	}
}


Measured memory_bytes: 3160
local n = io.read("*n")
local nodecol = {}
local edgecol = {}
local edge = {}
for i = 1, n do
  nodecol[i] = 0
  edge[i] = {}
end
for i = 1, n - 1 do
  edgecol[i] = 0
  local a, b = io.read("*n", "*n")
  edge[a][b] = i
  edge[b][a] = i
end
local snode = 0
for i = 1, n do
  local edgecnt = 0
  for k, v in pairs(edge[i]) do
    edgecnt = edgecnt + 1
  end
  if edgecnt == 1 then
    snode = i
    break
  end
end
nodecol[snode] = 1
local tasknode = {}
for dstnode, edgeid in pairs(edge[snode]) do
  nodecol[dstnode] = 1
  edgecol[edgeid] = 1
  table.insert(tasknode, dstnode)
end
local maxcol = 1
local mma = math.max
for i = 1, n - 1 do
  local srcnode = tasknode[i]
  local srccol = nodecol[srcnode]
  local curcol = 1
  for dstnode, edgeid in pairs(edge[srcnode]) do
    if nodecol[dstnode] == 0 then
      if curcol == srccol then curcol = curcol + 1 end
      nodecol[dstnode] = curcol
      edgecol[edgeid] = curcol
      maxcol = mma(maxcol, curcol)
      table.insert(tasknode, dstnode)
      curcol = curcol + 1
    end
  end
end
print(maxcol)
for i = 1, n - 1 do
  print(edgecol[i])
end


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

int main() {
  int N;
  cin >> N;
  vector<string> V(N);
  set<string> S;
  for (int i=0; i<N; i++) {
    cin >> V[i];
    S.insert(V[i]);
  }
  
  string ans="Yes";
  for (int i=0; i<N-1; i++) {
    if (V[i][V[i].size()-1]!=V[i+1][0]) {
      ans="No";
      break;
    }
  }
  if (S.size()!=V.size()) {
    ans="No";
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
//https://blog.csdn.net/hesorchen
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <set>
#include <queue>
#include <string>
#include <cstring>
using namespace std;
#define ll long long
#define lowbit (a & (-a))
#define endl "\n"
#define PI acos(-1.0)
#define mod 1000000009
#define INF 0x3f3f3f3f
#define MAX 200010

int main()
{
    ll a, b;
    cin >> a >> b;
    cout << a * a - b << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1e+7
#define int long long
#define garou ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
signed main() {
    garou;
    int n;
    cin>>n;
    map<string,int> m;
    while(n--){
    string s;
    cin>>s;
    m[s]++;
    }
    cout<<m.size();
}

Measured memory_bytes: 19244
N,K = map(int,input().split())
A = list(map(int,input().split()))

sa = sum(A)
m = 1
divs = set()
while m*m <= sa:
    if sa%m == 0:
        divs.add(m)
        divs.add(sa//m)
    m += 1

for d in sorted(divs,reverse=True):
    mods = []
    for a in A:
        mods.append(a%d)
    mods.sort()
    if all(m==0 for m in mods):
        print(d)
        exit()

    cump = [0]
    for m in mods:
        cump.append(cump[-1] + m)
    cumm = [0]
    for m in reversed(mods):
        cumm.append(cumm[-1] + (d-m))
    for i in range(1,N):
        if cump[i] == cumm[N-i] and cump[i] <= K:
            print(d)
            exit()

Measured memory_bytes: 3188
n = int(input())

dp = [True]*(n*1000000)
dp[n] = False
res =1
while n <1000001:
    res +=1
    if n % 2 ==1:
        n = n*3+1
    else:
        n = n//2
    
    if dp[n]:
        dp[n] = False
    else:
        print(res)
        exit()

Measured memory_bytes: 789996
while 1:
    W,H = map(int,raw_input().split())
    if W == H == 0: break
    wall = [map(int,raw_input().split()) for _ in range(2*H-1)]
    
    dist = [[0]*W for _ in range(H)]
    dist[0][0] = 1
    que = [[0,0]]
    while que:
        x,y = que.pop(0)
        d = dist[y][x]
        for dx,dy in zip([1,0,-1,0],[0,1,0,-1]):
            nx,ny = x+dx, y+dy
            if 0 <= nx < W and 0 <= ny < H:
                if dy == 0:
                    if wall[2*y][min(x,nx)] == 1 or dist[ny][nx] > 0: continue
                if dx == 0:
                    if wall[2*min(y,ny)+1][x] == 1 or dist[ny][nx] > 0: continue
                dist[ny][nx] = d+1
                que.append([nx,ny])
    print dist[-1][-1]                    

Measured memory_bytes: 4304
#include<cstdio>
int main(){
	int a,b,c,d;
	while(~scanf("%d %d %d %d",&a,&b,&c,&d))
	{
		long long sum1,sum2;
		sum1=a*b;
		sum2=c*d;
		if(sum1>sum2){
			printf("%lld\n",sum1);
		}else {
			printf("%lld\n",sum2);
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount _builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace __gnu_pbds;
using namespace std;
//typedef
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
//constants
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
//
#define forn(i, n)for(ll i=0;i<n;i++)
// gcd of a and b
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
// distance between (a,b) and (c,d)
long double dis(long long a,long long b,long long c,long long d){return sqrt( ((a)-(c))*((a)-(c))+((b)-(d))*((b)-(d)) );}
// simple prime check
bool isprime(long long a){
if(a==2)return 1;
if(!(a&1))return 0;
for(ll i=3;i*i<=a;i+=2){
	if(a%i==0)return 0;
}
return 1;
}
// fast expo
long long mpow(long long base,long long exponent,long long modulus){
if(modulus==1)return 0;
long long result = 1;
base=base%modulus;
while(exponent){
		if(exponent%2 == 1)
			result=(result*base)%modulus;
		exponent=exponent>>1;
		base=(base*base)%modulus;
	}
return result;
}
// modular inverse
ll minv(ll a,ll mod){
	ll _gcd=gcd(a,mod);
	assert(_gcd==1);
	return mpow(a,mod-2,mod);
}

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*
ll dx[]={1,0,-1,0,1,1,-1,-1};
ll dy[]={0,-1,0,1,1,-1,-1,1};
*/

/*
void sieve(int N){
	for(int i=0;i<=N;i++){
		spf[i]=i;
	}
	for(int i=2;i*i<=N;i++){
		if(spf[i]==i){
			for(ll j=i*i;j<=N;j+=i){
				spf[j]=min(spf[j],i);
			}
		}
	}
	return;
}
*/

/*
void nCr(ll n,ll k){
	ll i,j;
	for(i=0;i<=n;i++){
		for(j=0;j<=min(i,k);j++){

			if(j==0 or j==i)C[i][j]=1LL;
			else  C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}
	}
	return;
}
*/
/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll a,b;
int main(){FAST;
cin>>a>>b;
cout<<max({2*a-1,2*b-1,a+b});
return 0;
}




Measured memory_bytes: 256
/*
ID: wangyuxi20040901
TASK:  ()
LANG: C++
DATE: 20200419 19:22:44
*///using CRLF, UTF-8

#include <cstdio>
#include <algorithm>
#include <cstring>
#define pr printf
#define F(i, j, k) for(register int i = j, kkllkl = k; i <= kkllkl; ++i)
#define G(i, j, k) for(register int i = j, kkllkl = k; i >= kkllkl; --i)
#define clr(a, v) memset((a), v, sizeof(a))
using namespace std;
typedef long long ll;

#define isd(x) (('0' <= (x) && (x) <= '9') || (x) == '-')
int rd() {
    int ans = 0, sign = 1; char c = getchar();
    while(!isd(c)) c = getchar();
    if(c == '-') sign = -1, c = getchar();
    while(isd(c)) ans = (ans << 3) + (ans << 1) + c - '0', c = getchar();
    return sign == 1 ? ans : -ans;
}

/* --------------------------CSYZ1921------------------------- */
#include <cmath>
int r;
double ans = acos(-1);

int main() {
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    scanf("%d", &r);
    ans *= 2 * r;
    pr("%lf\n", ans);
    return 0;
}
/*
*/

Measured memory_bytes: 1744
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

char buff[2][40][40];
int w,h;

int d2i[300];
const char i2d[4] = {'E', 'N', 'W', 'S'};
const int dx[4]   = {1,0,-1,0};
const int dy[4]   = {0,-1,0,1};

#define OK(x,y) (x>=0 && x<w && y>=0 && y<h && (board[y][x] == '.' || board[y][x] == 'X'))

int main(){
  REP(i,300) d2i[i] = -1;
  REP(i,4) d2i[i2d[i]] = i;

  while(scanf("%d%d ",&w,&h),w+h){
    char (*board)[40] = buff[0];
    char (*next)[40]  = buff[1];
    REP(i,h) fgets(board[i],sizeof(board[i]),stdin);
    int t = 0;
    while(++t <= 180){
      int cnt[40][40] = {{0}};
      int rest = 0;

      //ü«ðÏ¦é
      REP(i,h) REP(j,w){
        if(d2i[board[i][j]] != -1){
          int direct = (d2i[board[i][j]] + 3) % 4;
          rest++;
          REP(k,4){
            int x = j + dx[direct];
            int y = i + dy[direct];
            if(OK(x,y)){
              cnt[y][x]++;
              board[i][j] = i2d[direct];
              break;
            }
            direct = (direct + 1) % 4;
          }
        }
      }

      //fobO
      /*
      printf("rest = %d\n",rest);
      REP(i,h){ REP(j,w) printf("%d",cnt[i][j]); puts(""); }
      */

      //{[hÌRs[
      REP(i,h) REP(j,w)
        next[i][j] = (d2i[board[i][j]] == -1 ? board[i][j] : '.');

      bool flag[40][40] = {{false}};
      //ÀÛÉÚ®
      REP(i,h) REP(j,w){
        if(cnt[i][j] > 0){
          REP(k,4){
            int x = j + dx[k];
            int y = i + dy[k];
            if(x < 0 || y < 0) continue;
            if(x >=w || y >=h) continue;
            if(d2i[board[y][x]] != -1 && k == (d2i[board[y][x]] + 2) % 4){
              flag[y][x] = true;
              if(next[i][j] == 'X'){
                rest--;
              }else{
                next[i][j] = board[y][x];
              }
              break;
            }
          }
        }
      }

      //Ú®µÈ©Á½lÌ
      REP(i,h) REP(j,w){
        if(!flag[i][j] && d2i[board[i][j]] != -1){
          next[i][j] = board[i][j];
        }
      }

      //fobO
      //REP(i,h){ REP(j,w) printf("%c",next[i][j]); puts(""); }

      if(rest == 0) break;

      //ÌæÌüêÖ¦
      swap(board, next);
    }
    if(t <= 180) printf("%d\n",t);
    else puts("NA");
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }

int main(){
  ll inf = pow(10,5);
  // 各数について使うマッチ棒の数を記憶
  umap<int,int> mp;
  mp[1] = 2;
  mp[2] = 5;
  mp[3] = 5;
  mp[4] = 4;
  mp[5] = 5;
  mp[6] = 6;
  mp[7] = 3;
  mp[8] = 7;
  mp[9] = 6;
  
  int N,M; cin>>N>>M;
  int a[M]; CINA(a,M);
  sort(a,a+M,greater<int>());
  
  // i本使い切った時の最大桁数をdpで求める
  int dp[N+1]; FILL(dp,N+1,-inf);
  dp[0] = 0LL;
  for(int i=1;i<=N;++i){
    REP(j,M){
      int x = a[j];
      int num = mp[x];
      if(i-num>=0){ chmax(dp[i],dp[i-num]+1); }
    }
  }
  // 上位の桁から順に、条件を満たす最大の数を並べていく
  while(N>0){
    REP(j,M){
      int x = a[j];
      int num = mp[x];
      if( N-num<0){ continue;}
      if( dp[N-num] == dp[N]-1 ){
        cout << x;
        N -= num;
        break;
      }
    }
  }
  cout << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=1e6+10;
const ll mod=1e9+7;
ll spec=0;
ll dp[mn];
int main(){
    ll n,h,d,i;
    cin>>n>>h>>d;
    dp[0]=1;
    ll f=1;
    for(i=1;i<=n;i++)f=f*i%mod,spec=(spec+f)%mod;
    ll sum=0;
    for(i=1;i<=h;i++){
        sum+=dp[i-1];
        if(i-d-1>=0)sum-=dp[i-d-1];
        sum%=mod;
        if(i!=h)dp[i]=sum*spec%mod;
        else dp[i]=sum;
    }
    for(i=1;i<=n;i++)dp[h]=dp[h]*i%mod;
    if(dp[h]<0)dp[h]+=mod;
    printf("%lld",dp[h]);
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back
#define fi first
#define be begin()
#define en end()
#define se second

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

map<int,int> prime_factor(int n){
  map<int,int> res;
  for (int i(2);i*i<=n;i++){
    while(n%i==0){
      ++res[i];
      n/=i;
    }
  }
  if (n!=1) res[n]=1;
  return res;
}

int main(){
	int N,A[10000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>A[i];
  if (N == 1){
    cout << 1 << endl;
    return 0;
  }
  vector<map<int,int>> a(N);
  ll s[1000000] = {0};
  for (int i(0);i<N;i++){
    a[i] = prime_factor(A[i]);
    for (auto e:a[i]){
      if (s[e.first] < e.second){
        s[e.first] = e.second;
      }
    }
  }
  ll tmp(1);
	for (int i(2);i<1000000;i++){
    if (s[i] != 0){
      ll tmpi = pow(i,s[i]);
      tmpi %= MOD;
      tmp *= tmpi;
      tmp %= MOD;
    }
	}
  ll ans(0);
  //cout << tmp << endl;
  for (int i(0);i<N;i++){
    ans += (tmp * modinv(A[i]) % MOD);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 10880
n=int(input())
p_list = tuple(list(map(int,input().split())))
q_list = tuple(list(map(int,input().split())))

import itertools
count = 0
count_p = 0
count_q = 0

for i in itertools.permutations((range(1, n+1))):
    count += 1
    if i == p_list:
        count_p = count
    if i == q_list:
        count_q = count

print(abs(count_p - count_q))

Measured memory_bytes: 3064
A, B, C = map(int, input().split())
K = int(input())

cnt = 0
if A >= B:
    while A >= B:
        B *= 2
        cnt += 1

if B >= C:
    while B >= C:
        C *= 2
        cnt += 1

if cnt <= K:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int t1 = H1 * 60 + M1, t2 = H2 * 60 + M2;
	cout << t2 - t1 - K << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


#define PRINT(s) cout << (s);
#define PRINTLN(s) cout << (s) << endl;

typedef long long int ll;

using namespace std;

// #define REP(i,N) for(int i = 0; i < N; i++)

int getyouso(string str,char ch){
    int sum = 0;
    for(int i = 0; i < str.size(); i++){

        if(str[i] == ch) sum++;
//        cout << "not_error" << i << "回目" << endl;

    }

    return sum;
}

int main(){
    stack<char> char_stack;
    int n;
    string str;
    cin >> n;
    cin >> str;

    for(int i = 0; i < n; i++){
        char tmp = str[i];
        if(tmp == '('){
            char_stack.push('(');
        }
        if(tmp == ')'){
            if(!char_stack.empty()){
                char_stack.pop();
            }
        }
    }
//    str += ')' * char_stack.size();
    int cnt = char_stack.size();
    for(int i = 0; i < cnt; i++){
        str += ')';
    }


    cnt = (getyouso(str,')') - getyouso(str,'('));

    string front = "";
//    string front = "(" * (getyouso(str,')') - getyouso(str,'('));
    for(int i = 0; i < cnt; i++){
        front += "(";
    }
    cout << front << str << endl;

}


Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-05-30
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long a, b;
    cin >> a >> b;
    cout << (a * b) / __gcd(a, b) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 100005
#define Mod 1000000007
#define Val(x) ((((long long)x) % Mod + Mod) % Mod)
using namespace std;
int x[maxn],y[maxn];
int arr[maxn],brr[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++) {
		cin >> x[i];
		if(i > 1)	arr[i-1] = x[i] - x[i-1];
	}
	for(int i=1;i<=m;i++) {
		cin >> y[i];
		if(i > 1)	brr[i-1] = y[i] - y[i-1];
	}
	n--;	m--;
	int sum1 = 0 , sum2 = 0;
	for(int i=1;i<=n;i++)
		arr[i] = Val(arr[i] + arr[i-1]) , sum1 = Val(sum1 + arr[i]);
	for(int i=1;i<=m;i++)
		brr[i] = Val(brr[i] + brr[i-1]) , sum2 = Val(sum2 + brr[i]);
	
	int a = 0 , b = 0;
	for(int i=1;i<=n;i++) {
		a = Val(a + sum1);
		sum1 = Val(sum1 - (long long)(arr[i] - arr[i-1]) * (n - i + 1));
	} 
	for(int i=1;i<=m;i++) {
		b = Val(b + sum2);
		sum2 = Val(sum2 - (long long)(brr[i] - brr[i-1]) * (m - i + 1));
	}
	cout << Val(a * b) << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define mrp(i,n) for(int i=n-1;i>=0;i--)
#define mrep(i,m,n) for(int i=m;i>=n;i--)
#define mlrp(i,n) for(long long i=n;i>=0;i--)
#define mlrep(i,m,n) for(long long i=m;i>=n;i--)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define abs(a,b) (a-b>0?a-b:b-a)

int main(){
    ll n;
    cin >> n;
    ll ans=1;
    lrep(i,1,n){
        ans *= i;
        ans = ans%1000000007;
    }
    
    cout << ans << endl;

}


Measured memory_bytes: 256