akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	deque<int>deq;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		if (i % 2 == 0)deq.push_back(a[i]);
		else deq.push_front(a[i]);
	}
	if (n % 2 != 0) {
		for (int i = n - 1;i >= 0;--i) {
			cout << deq[i] << endl;
		}
	}
	else {
		rep(i, n) {
			cout << deq[i] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3840
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    char s[10000],s1[10000],s2[10000];
    int i,j=0,n;

    scanf("%s",s);
    for(i=0;i<(strlen(s)-1)/2;i++){
        s1[i]=s[i];
    }
    s1[i]='\0';
    
    for(i=(strlen(s)+1)/2;i<strlen(s);i++){
        s2[j]=s[i];
        j++;
    }
    s2[j]='\0';
    
    if(strcmp(s1,s2)==0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << "{";
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i] << ",}"[i == vec.size() - 1];
  }
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << "{" << p.first << " " << p.second << "}";
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

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

  int h, w, n; cin >> h >> w >> n;

  // (x, y) を中心とする 3 x 3 の正方形内に何個黒があるか
  map<pii, int> mp;
  
  for (int i = 0; i < n; ++i) {
    int a, b; cin >> a >> b;
    for (int j = -1; j <= 1; ++j) {
      for (int k = -1; k <= 1; ++k) {
        if (a + j <= 1 || a + j >= h || b + k <= 1 || b + k >= w) continue;
        ++mp[{a + j, b + k}];
      } 
    }
  }

  int64 ans[10] = {};
  ans[0] = static_cast<int64>(h - 2) * static_cast<int64>(w - 2);

  for (auto it = mp.begin(); it != mp.end(); ++it) {
    ++ans[it->second];
  }

  int64 sum = 0;
  for (int i = 1; i < 10; ++i) {
    sum += ans[i];
  }

  ans[0] -= sum;

  for (int i = 0; i < 10; ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}

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

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

    char a;
    int b;
    int X[4][13] = {{}};
    char M[4] = {'S', 'H', 'C', 'D'};
    for (int n=0; n<N; n++){
        cin >> a >> b;
        for (int i=0; i<4; i++){
            for (int j=0; j<13; j++){
                if (a==M[i] && b==j+1) X[i][j]++;
            }   
        }   
    }   
        
    for (int i=0; i<4; i++){
       for (int j=0; j<13; j++){
           if (X[i][j]==0) cout << M[i] << ' ' << j+1 << endl;
       }   
    }   
}

Measured memory_bytes: 1160
let h = ref 0

let parent i = int_of_float (floor (float_of_int i) /. 2.)

let left i = 2*i

let right i = 2*i + 1

let swap i j t = let tmp = t.(i) in t.(i) <- t.(j); t.(j) <- tmp

let extract (t : int array) =
  let rec max_heapify i =
    let l = left i in
    let r = right i in
    let m = if l <= !h && t.(l) > t.(i) then l else i in
    let m = if r <= !h && t.(r) > t.(m) then r else m in
    if i <> m then begin
      swap i m t;
      max_heapify m
    end in
  let ret = t.(1) in
  t.(1) <- t.(!h);
  decr h;
  max_heapify 1;
  ret

let insert x (t : int array) =
  let rec doit i =
    if i > 1 && t.(parent i) < t.(i) then begin
      swap i (parent i) t;
      doit (parent i)
    end in
  incr h;
  t.(!h) <- x;
  doit !h

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let t = Array.make 2000001 0 in
  let rec doit () =
    match split_on_char ' ' (read_line ()) with
    | ["extract"] -> Printf.printf "%d\n" (extract t); doit ()
    | ["insert"; n] -> insert (int_of_string n) t; doit ()
    | _ -> () in
  doit ()

Measured memory_bytes: 20376
def rain_flows_into_dams(N: int, A: list)->list:
    x = [0] * N
    x[0] = (sum(A[0::2])-sum(A[1::2])) // 2

    for i in range(1, N):
        x[i] = A[i-1] - x[i-1]

    return [2*y for y in x]


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]

    ans = rain_flows_into_dams(N, A)
    print(' '.join(map(str, ans)))


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    if(n==1){
        cout << "Yes" << endl;
        cout << 2 << endl;
        cout << 1 << " " << 1 << endl;
        cout << 1 << " " << 1 << endl;
        return 0;
    }
    else if(n==3){
        cout << "Yes" << endl;
        cout << 3 << endl;
        cout << 2 << " " << 1 << " " << 2 << endl;
        cout << 2 << " " << 2 << " " << 3 << endl;
        cout << 2 << " " << 3 << " " << 1 << endl;
        return 0;
    }
    vector<ll> a(100010, 0);
    for(ll i=4; i<=100000; i++){
        if(i*(i-1)/2>100000) break;
        a[i]=i*(i-1)/2;
    }

    bool is_yes=false;
    int num, sizes;
    for(int i=4; i<=100000; i++){
        if(n==a[i]){
            sizes=i;
            num=a[i];
            is_yes=true;
        }
    }

    if(is_yes==false){
        cout << "No" << endl;
    }
    else{
        vector<vector<int>> S(sizes);
        int number=1;
        for(int i=0; i<sizes; i++){
            for(int j=i+1; j<sizes; j++){
                S[i].emplace_back(number);
                S[j].emplace_back(number);
                number++;
            }
        }

        cout << "Yes" << endl;
        cout << sizes << endl;
        for(int i=0; i<sizes; i++){
            cout << S[i].size() << " ";
            for(int j=0; j<S[i].size(); j++){
                cout << S[i][j] << " ";
            }
            cout << endl;
        }

    }
    
}

Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		sc.close();

		int ans = 0;
		for (int i = 1; i < n; i++) {
			if (s[i] == 'E') {
				ans++;
			}
		}

		int val = ans;
		for (int i = 0; i < n - 1; i++) {
			if (s[i] == 'W') {
				val++;
			}
			if (s[i + 1] == 'E') {
				val--;
			}
			ans = Math.min(ans, val);
		}
		System.out.println(ans);
	}
}


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

using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define PI  3.14159265358979323846264338327950L
#define mod 1000000007
#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"

void solve(){
	string s;
	cin>>s;
	for(char c:s){
		if(c=='?'){
			cout<<'D';
		}else{
			cout<<c;
		}
	}
	cout<<"\n";
}

int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	// cin>>_;
	_=1;
	while(_--){
        solve();
    }
	return 0;
}

/*
   check for overflows int long long
   correct size of array
*/

Measured memory_bytes: 3772
# 入力 : 横並びの数字N個（リスト内包表記で）
N, K = map(int, input().split())
set_D = {str(int(x)) for x in input().split()}

ans = N

while True :
    if set(str(ans)).intersection(set_D) :
        ans += 1
    else :
        break

print(ans)


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

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = 0,ans2=0,ans3=0,ans4=0;
    ans = max(a*c,a*d);
    ans2 = max(b*c,b*d);
    
    cout << max(ans,ans2) << endl;


    return 0;
}

Measured memory_bytes: 3632
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    n,t = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    ab.sort(key=lambda x: x[1])
    ab.sort(key=lambda x: x[0])
    dp = [-1]*(t+1)
    dp[0] = 0
    for a, b in ab:
        for j in range(t-1, -1, -1):
            if dp[j] >= 0:
                if j+a<=t:
                    dp[j+a] = max(dp[j+a], dp[j]+b)
                else:
                    dp[-1] = max(dp[-1], dp[j]+b)
    print(max(dp))

if __name__ == '__main__':
    main()

Measured memory_bytes: 41840
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint N,M;
    cin >> N >> M;
    lint A[M];
    rep(i,M) cin >> A[i];
    lint sum=accumulate(A,A+M,0LL);
    lint ans=N-sum;
    if(ans<0) cout << -1 << endl;
    else cout << ans << endl;
}

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

using namespace std;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) (int)a.size()
#define fi first
#define se second
#define ar array

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int > pii;
const ll MOD =1e9+7;

void solve(){
	ll k;
	string s; cin >> s >> k;
	for(int i = 0; i < min(1LL*sz(s),k); ++i){
		if(s[i]!= '1'){
			cout<<s[i];return;
		}
	}
	cout<<1;
}
int main(){
	int t=1;
	//cin >> t;
	while(t--){
		solve();
		cout <<'\n';
	}
}


Measured memory_bytes: 3608
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int mi=120;
    int mx=-120;
    int ay[110];
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>ay[i];
        mi=min(mi,ay[i]);
        mx=max(mx,ay[i]);
    }
    int ans=1e9;
    for(int i=mi;i<=mx;++i)
    {
        int sum=0;
        for(int j=0;j<n;++j)
        {
            sum+=(ay[j]-i)*(ay[j]-i);
        }
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//ΔARC 095C
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 15;
int n,m,p[N];
char a[N][N];
string l[N],r[N];
int main()
{
	srand(19260817);
	int i,j,x,f,o=100000;
	cin>>n>>m;
	for(i=1;i<=n;i=i+1)
		scanf("%s",a[i]+1);
	while(o--){
		for(j=1;j<=m;j=j+1)
			l[j]="",r[j]="";
		for(i=1;i<=n;i=i+1)
			p[i]=i;
		random_shuffle(p+1,p+n+1);
		for(i=1;i<=n;i=i+1){
			x=p[i];
			for(j=1;j<=m;j=j+1)
				l[j]=l[j]+a[x][j],r[j]=a[x][j]+r[j];
		}
		for(j=1;j<=m;j=j+1)
			p[j]=0;
		f=m&1;
		for(j=1;j<=m;j=j+1){
			if(p[j])
				continue;
			p[j]=1;
			x=1;
			while(p[x]||x<=m&&l[j]!=r[x]){
				x++;
			}
			if(x<=m)
				p[x]=1;
			else{
				if(l[j]==r[j]&&f)
					f--;
				else
					break;
			}
		}
		if(j>m){
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i++)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

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


signed main(){
  int a,b,c,d;
  char q,w,e,r;
  cin >> q >> w >> e >> r;
  a = q - '0';
  b = w - '0';
  c = e - '0';
  d = r - '0';
  
  int nowi;
  vector<char> op(3);
  rep(i,0,8){
    int ans = a;
    nowi = i;
    
    rep(j,0,3){
      if(nowi%2==0) op[j] = '+';
      else op[j] = '-';
      nowi /= 2;
    }
    
    if(op[0]=='+') ans += b;
    if(op[0]=='-') ans -= b;
    if(op[1]=='+') ans += c;
    if(op[1]=='-') ans -= c;
    if(op[2]=='+') ans += d;
    if(op[2]=='-') ans -= d;
    
    if(ans==7){
      cout << a << op[0] << b << op[1] << c << op[2] << d << "=7" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
fun main() {
	val (n,k) = readLine()!!.split(" ").map {it.toInt()}
	var a = (1..n).toMutableSet()
	for(i in 1..k) {
		readLine()
		readLine()!!.split(" ").map {it.toInt()}.forEach {a.remove(it)}
	}
	println(a.size)
}


Measured memory_bytes: 39108
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		//キーボード入力メソッド
		Scanner sc = new Scanner(System.in);

		//入力
		int x = sc.nextInt();

		//処理
		for(int i=1; i<=x; i++) {
			String str_i = String.valueOf(i);
			String serch_num = "3";
			if(str_i.indexOf(serch_num) != -1) {
				//3のつく数字を表示(数値を文字列化し、文字検索を行う)
				System.out.print(" " + i);
			}else if(i%3==0) {
				//3の倍数のみを表示
				System.out.print(" " + i);
			}
		}
		System.out.println();
	}
}



Measured memory_bytes: 30144
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int MAXN=2e5+5,Mod=1e9+7,Inv2=Mod+1>>1;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}
inline void Add(int&x,int y){x+=y,x>=Mod?x-=Mod:0;}
int n,a[MAXN],val1[MAXN],val2[MAXN],cnt[MAXN],D[MAXN],InvD[MAXN],zero[MAXN],S[MAXN],tot,ans;
inline int lowbit(int x){return x&-x;}
inline void add(int x,int v){for(;x<=n;x+=lowbit(x))Add(val1[x],v),Add(val2[x],1);}
inline int ask1(int x){int ans=0;for(;x;x-=lowbit(x))Add(ans,val1[x]);return ans;}
inline int ask2(int x){int ans=0;for(;x;x-=lowbit(x))Add(ans,val2[x]);return ans;}
inline int Fp(int x,int k){int ans=1;for(;k;k>>=1,x=1ll*x*x%Mod)if(k&1)ans=1ll*ans*x%Mod;return ans;}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read();Rep(i,1,n)cnt[a[i]=read()]++;
	Red(i,n,1)cnt[i]+=cnt[i+1];S[0]=D[0]=1;
	tot=1;Rep(i,1,n)tot=1ll*tot*(cnt[i]-=n-i)%Mod;
	if(!tot){puts("0");return 0;}
	Rep(i,1,n){
		int x=1ll*(cnt[i]-1)*Fp(cnt[i],Mod-2)%Mod;
		if(!x)S[zero[i]=zero[i-1]+1]=i,D[i]=D[i-1];
		else zero[i]=zero[i-1],D[i]=1ll*D[i-1]*x%Mod;
		InvD[i]=Fp(D[i],Mod-2);
	}
	Rep(i,1,n)ans=(ans+1ll*(ask1(a[i])-ask1(S[zero[a[i]]]-1)+Mod)*D[a[i]]%Mod*tot%Mod*Inv2)%Mod,add(a[i],InvD[a[i]]);
	memset(val1,0,sizeof(val1)),memset(val2,0,sizeof(val2));
	Red(i,n,1)ans=(ans-1ll*(ask1(a[i]-1)-ask1(S[zero[a[i]]]-1)+Mod)*D[a[i]]%Mod*tot%Mod*Inv2%Mod+Mod)%Mod,ans=(ans+1ll*ask2(a[i]-1)*tot)%Mod,add(a[i],InvD[a[i]]);
	cout<<ans<<'\n';
	return 0;
}




Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

// #define int ll

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define fst first
#define pb push_back

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

signed main() {
    int N, M;

    cin >> N >> M;

    map<P, bool> mp;
    REP(i, M) {
        int A, B;
        cin >> A >> B;

        P p1 = make_pair(A, B);
        mp[p1] = true;

        P p2 = make_pair(B, A);
        mp[p2] = true;
    }

    int ans = 0;
    vector<int> vec;
    // 2~Nの(N-1)個 (インデックスは0~N-2)
    FORE(i, 2, N) {
        vec.pb(i);
    }

    do {
        // cerr << "perm" << endl;
        // for (auto node : vec) {
        //     cerr << node << " ";
        // }
        // cerr << endl;
        // hyphen();

        // その通り方が実行できたらOK
        // 1 → 1個目
        P p1 = make_pair(1, vec.at(0));
        if (!mp.count(p1)) {
            cerr << "not edge : " << 1 << " " << vec.at(0) << endl;
            continue;
        }

        // 1個目 → 2個目
        // ...
        // (N-2) → (N-1)
        bool ok = true;
        FORE(i, 1, N-2) {
            P p3 = make_pair(vec.at(i-1), vec.at(i));
            if (!mp.count(p3)) {
                ok = false;
                cerr << "not edge : " << vec.at(i-1) << " " <<  vec.at(i) << endl;
                break;
            }
        }
        if (!ok) {
            continue;
        }

        // カウントしたパスを出力
        cerr << "1 ";
        for (auto node : vec) {
            cerr << node << " ";
        }
        cerr << endl;

        ans += 1;
    } while (next_permutation(ALL(vec)));

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long ll;

int main(){
  int n;  cin >> n;
  int mul2 = 0, mul4 = 0;
  rep(i, 0, n){
    int tmp;  cin >> tmp;
    if(tmp%4 == 0){
      mul4++;
    }
    else if(tmp%2 == 0){
      mul2++;
    }
  }
  if(mul4 + mul2/2 >= n/2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
	return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

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


	if (s.size() < 3){
		cout << 0 << endl;
		return 0;
	}
	
	ll cnt = 0;
	ll ans = 0;

	bool f = false;

	for (int i = 0; i < s.size() - 1; i++){
		if (s[i] == 'A'){
			cnt++;
			continue;
		}


		if (s[i] == 'B' && s[i + 1] == 'C'){
			ans += cnt;
			i++;
		} else {
			cnt = 0;
		}
	}

	cout << ans << endl;

	
} 


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

const long long MOD=1000000007;

typedef long long ll;

ll mod_pow(ll x, ll n){ //べき乗
    ll ans=1;
    while(n!=0){
        if(n&1) ans=ans*x%MOD;
        x=x*x%MOD;
        n=n>>1;
    }
    return ans;
}

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    sort(a,a+N);
    if(N%2==1){
        int tmp=2;
        bool ans=false;
        if(a[0]!=0){
            cout << 0 << endl;
            return 0;
        }
        for(int i=1;i<N;i+=2){
            if(a[i]!=tmp||a[i+1]!=tmp){
                cout << 0 << endl;
                return 0;
            }
            tmp+=2;
        }
        cout << mod_pow(2,N/2) << endl;
    }else{
        int tmp=1;
        for(int i=0;i<N;i+=2){
            if(a[i]!=tmp||a[i+1]!=tmp){
                cout << 0 << endl;
                return 0;
            }
            tmp+=2;
        }
        cout << mod_pow(2,N/2) << endl;
    }

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch GoldenApple | diff GoldenApple.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address GoldenApple.cpp && ./a.out

/*
 
 7/20/2019
 
 5:01-
 
 */

int N,D;

void solve() {
  int res=(N+2*D)/(2*D+1);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>D;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int cnt = 0;
  for( int i=0;4*i<=N;i++)
    {
      if((N-4*i)%7 == 0)
	{
	  cout << "Yes" << endl;
	  return 0;
	}
    }
  cout << "No" << endl;
}


Measured memory_bytes: 256
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch

#include<bits/stdc++.h>

using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define inf INT_MAX/3
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
int stu[1000000];
int ord[1000000];

int main()
{
    ios_base::sync_with_stdio(0);
    //ll n,c,cnt=0,prev;
    int n,m,x,y;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>stu[i];
    }for(int i=0; i<n; i++)
    {
        ord[stu[i]-1]=i+1;
    }
    for(int i=0; i<n; i++)
    {
        cout<<ord[i]<<" ";
    }
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT;
    int N, T;
    cin >> N >> T;
    vector<int> c(N);
    vector<int> t(N);
    int mi = 10e8;
    bool check = false;
    for(int i = 0; i < N; i++){
        cin >> c.at(i);
        cin >> t.at(i);
        if(t.at(i) <= T){
            mi = min(mi, c.at(i));
            check = true;
        }
    }
    if(check)cout << mi << endl;
    else cout << "TLE" << endl;
    return 0;
}

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

int main() {
    int n, k, x, y, sum = 0;
    cin >> n >> k >> x >> y;

    for (int i = 1; i <= n; i++) {
        if (i <= k) sum += x;
        else sum += y;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    test = [[] for _ in range(N)]
    for i in range(N):
        num = int(input())
        for j in range(num):
            p,h = map(int,input().split())
            test[i].append((p-1,h))
    hon = 0
    for i in range(2**N):
        tf = [None for _ in range(N)]
        count = 0
        ans = True
        for j in range(N):
            if (i>>j)&1:
                tf[j] = True
                count += 1
            else:
                tf[j] = False
        for k in range(N):
            if tf[k]:
                for p,h in test[k]:
                    if (tf[p] == True and h == 1) or (tf[p] == False and h == 0):
                        continue
                    else:
                        ans = False
                        break
            else:
                continue
        if ans:
            hon = max(hon,count)
            
    print(hon)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static boolean[][] path = new boolean[8][8];

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    boolean[] visit = new boolean[N];
    visit[0] = true;
    for (int i = 1; i < N; i++) {
      visit[i] = false;
    }
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        path[i][j] = false;
      }
    }
    for (int i = 0; i < M; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      path[a][b] = true;
      path[b][a] = true;
    }
    System.out.println(dfs(0, N, visit));
  }

  public static int dfs(int point, int N, boolean[] visit) {
    boolean allVisit = true;
    for (int i = 0; i < N; i++) {
      if (!visit[i]) {
        allVisit = false;
      }
    }
    if (allVisit) {
      return 1;
    }
    int ret = 0;
    for (int i = 0; i < N; i++) {
      if (path[point][i] && !visit[i]) {
        visit[i] = true;
        ret += dfs(i, N, visit);
        visit[i] = false;
      }
    }
    return ret;
  }
}

Measured memory_bytes: 23636
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <cassert>
#include <time.h>
#include <numeric>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef vector<int> vi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define ll long long int
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i, a, b) for(int i = a; i < b; i++)


#define trarr(a,n) forn(i,0,n) cerr<<a[i]<<" \n"[i==n-1];
#define trmat(g,n,m) forn(i,0,n)forn(j,0,m) cerr<<g[i][j]<<" \n"[i==m-1];
#define tr(...) cerr<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const ld PI = acos(-1);
const ld EPS = 1e-9;
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int P = 1e9+7;
const int N = 4e2+10;

void solve(int _t){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	ll dp1[N][N] = {0};//stores cost
	ll dp2[N][N] = {0};//stores value
	rep(i, 0, n) rep(j, 0, n) dp1[i][j] = dp2[i][j] = INF;
	for(int i = 0; i < n; i++) dp1[i][i] = 0, dp2[i][i] = a[i];
	for(int l = 2; l <=n; l++){
		for(int i = 0; i+l-1 < n; i++){
			int j = i+l-1;
			for(int k = i; k < j; k++){
				if(dp1[i][k] + dp1[k+1][j] + dp2[i][k] + dp2[k+1][j] < dp1[i][j]){
					dp1[i][j] = dp1[i][k] + dp1[k+1][j] + dp2[i][k] + dp2[k+1][j];
					dp2[i][j] = dp2[i][k]+dp2[k+1][j];
				}
			}
		}
	}
	cout<<dp1[0][n-1]<<endl;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	// cin >> t;
	rep(test, 1, t+1){
		solve(test);
	}
	return 0;
}  

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

int main() {
	int S, h = 0, m = 0, s = 0;
	cin >> S;
	h = S/3600;
	S -= h*3600;
	m = S/60;
	S -= m*60;
	s = S;
	cout << h << ":" << m << ":" << s << endl;
}


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

int main() {
    int n, q, sum=0;
    cin >> n >> q;
    REP(i,q){
        int c, k;
        cin >> c >> k;
        if(c==0){
            cout << (sum+k-1)%n+1 << endl;
        }
        else {
            sum = (sum+k)%n;
        }
    }
    return 0;
}



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

int H, W, C, M, s, t, res;
int cap[310][310];
bool used[310];
enum { source = 300, sink, nwin, nwout, ncin, ncout, nmio };

bool dfs(int v)
{
    used[v] = true;
    for(int i = 0; i < 310; ++i)
        if(cap[v][i] > 0 && !used[i])
            if(i == sink || dfs(i)) {
                --cap[v][i]; ++cap[i][v]; return true;
            }
    return false;
}

int main()
{
    while(cin >> H >> W >> C >> M && H >= 0)
    {
        memset(cap, 0, sizeof(cap));
        cin >> cap[nwin][nwout] >> cap[ncin][ncout] >> cap[nmio][sink];

        for(int i = 0; i < H; ++i)
            cap[source][i] = cap[i][nwin] = 1;
        for(int i = 0; i < W; ++i) {
            cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[t-1][50+i] = 1; }
            cap[50+i][100+i] = cap[100+i][ncin] = 1;
        }
        for(int i = 0; i < C; ++i) {
            cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[100+t-1][150+i] = 1; }
            cap[nwout][150+i] = cap[150+i][200+i] = cap[200+i][nmio] = 1;
        }
        for(int i = 0; i < M; ++i) {
            cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[200+t-1][250+i] = 1; }
            cap[ncout][250+i] = cap[250+i][sink] = 1;
        }

        res = 0;
        do fill_n(used, 310, false); while(dfs(source) && ++res);
        cout << res << endl;
    }
}

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

using namespace std;

long long A[100005];
long long B[100005];

int main(){
	int N;
	scanf("%d", &N);
	
	for(int i = 0; i <= N; i ++){
		scanf("%lld", &A[i]);
	}
	
	for(int i = 0; i < N; i ++){
		scanf("%lld", &B[i]);
	}
	
	long long ans = 0;
	for(int i = 0; i < N; i ++){
		long long temp1 = min(A[i], B[i]);
		A[i] -= temp1;
		B[i] -= temp1;
		ans += temp1;
		
		long long temp2 = min(A[i+1], B[i]);
		A[i+1] -= temp2;
		B[i] -= temp2;
		ans += temp2;
	}
	
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define Int uint64_t

using namespace std;

int main() {
	Int INF = 1e18;
	int N;
	cin >> N;
	vector<Int> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }

	sort(a.begin(), a.end());
	if (a[0] == 0) {
		cout << "0\n";
		return 0;
	}

	Int ans = 1;
	for (int i = 0; i < N; ++i) {
		if (INF / a[i] >= ans) {
			ans *= a[i];
		} else {
			cout << "-1\n";
			return 0;
		}
	}
	cout << (INF >= ans ? ans : -1) << endl;

	return 0;
}


Measured memory_bytes: 3988
#include <stdio.h>

int main(void)
{
	int H, W,i,j;

	while (1)
	{
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0)
		{
			break;
		}
		else
		{

			for (i = 0; i < H; i++)
			{
				for (j = 0; j < W; j++)
				{
					printf("#");
				}
				printf("\n");

			}
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}


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

//INSERT ABOVE HERE
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> st(h);
  for(Int i=0;i<h;i++) cin>>st[i];

  vector<Int> us,vs;
  for(Int i=0;i<h;i++){
    for(Int j=0;j<w;j++){
      if(st[i][j]!='B') continue;
      us.emplace_back(i+j);
      vs.emplace_back(i-j);
    }
  }
  sort(us.begin(),us.end());
  sort(vs.begin(),vs.end());

  cout<<max(us.back()-us.front(),vs.back()-vs.front())<<endl;
  return 0;
}



Measured memory_bytes: 3228
/* vo00_03.cpp */
#include <iostream>
#include <cmath>
#include <queue>
using namespace std;

int main()
{
	const char *y = "YES";
	const char *n = "NO";

	priority_queue<int> que;

	int N;
	int s;

	double s1, s2, s3;

	cin >> N;

	for (; N; --N) {

		for (int i = 0; i < 3; ++i) {
			cin >> s;
			que.push(s);
		}

		s1 = que.top(); que.pop();
		s2 = que.top(); que.pop();
		s3 = que.top(); que.pop();

		if (pow(s1, 2) == pow(s2, 2) + pow(s3, 2)) cout << y << '\n';
		else cout << n << '\n';


		while (!que.empty()) que.pop();	//	キューを空にする
	}

	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
 
#define INT_INF (2 * 1e9)
#define LL_INF  (2LL * 1e18)
#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#endif
 
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9 + 7;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }

const int MAX_N = 1e4 + 6;

const int cost[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int best_dig[10];

void solve()
{
	int n, m;
	cin >> n >> m;

	set<int> a;

	for(int i = 0; i < m; ++i)
	{
		int el;
		cin >> el;
	
		best_dig[cost[el]] = max(best_dig[cost[el]], el);
		el = cost[el];

		a.insert(el);
	}

	if(a.find(2) != a.end() && a.find(4) != a.end())
		a.erase(a.find(4));

	if(a.find(2) != a.end() && a.find(6) != a.end())
		a.erase(a.find(6));

	if(a.find(3) != a.end() && a.find(6) != a.end())
		a.erase(a.find(6));

	vector<int> cnt(a.size(), 0);
	string ans;

	vector<int> aa;

	for(auto el: a)
		aa.push_back(el);

	while(cnt[0] <= n)
	{
		int sm = 0;

		for(int i = 0; i < cnt.size(); ++i)
			sm += aa[i] * cnt[i];

		if(sm == n)
		{
			string lans;

			for(int i = 0; i < cnt.size(); ++i)
			{
				int k = aa[i];

				for(int j = 0; j < cnt[i]; ++j)
					lans += (char)(best_dig[k] + '0');
			}

			sort(lans.rbegin(), lans.rend());

			DBG(lans);

			if(lans.size() > ans.size() || lans > ans)
				ans = lans;
		}
		
		{
			int j = cnt.size() - 1;
			bool done = false;

			while(j > 0)
			{
				if(cnt[j] < 20)
				{
					++cnt[j];
					done = true;
					break;
				}

				cnt[j--] = 0;
			}

			if(!done)
				++cnt[j];
		}
	}

	sort(ans.rbegin(), ans.rend());

	cout << ans << endl;
}

int main(int argc, char** argv)
{
	fast_io();
	solve();

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

void exec(){
  ll a, b, k;
  ll result = 0;
  cin >> k >> a >> b;

  ll diff = b - a;

  if (diff <= 2 || k < a){
    cout << 1 + k << endl;
    return;
  }

  result = a;
  k -= a - 1;
  ll count = k / 2;

  result += count * diff;
  k %= 2;
  result += k;
  cout << result << endl;

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h,w,n,c,sum,x[9999],y[9999];
main(){cin>>h>>w>>n;x[0]=1;y[0]=1;
for(int i=1;i<=n;i++){cin>>x[i]>>y[i];}
for(int i=1;i<n;i++){
if((x[i+1]>=x[i]&&y[i+1]>=y[i])||(x[i+1]<=x[i]&&y[i+1]<=y[i])){c=max(abs(x[i+1]-x[i]),abs(y[i+1]-y[i]));}
else{c=abs(x[i]-x[i+1])+abs(y[i]-y[i+1]);}
sum += c;}
cout<<sum<<endl;}

Measured memory_bytes: 1176
m = {}
m['AC'] = 0
m['WA'] = 0
m['TLE'] = 0
m['RE'] = 0

for __ in range(int(input())):
  m[input()] += 1

print('AC x ' + str(m['AC']))
print('WA x ' + str(m['WA']))
print('TLE x ' + str(m['TLE']))
print('RE x ' + str(m['RE']))

                

Measured memory_bytes: 69844
val = input()
val = val.split(" ")
val = [int(i) for i in val]  # 全部intに変換

ans = 0


if(val[0] > val[3]):
    ans = 1 * val[3]
    print(ans)
elif((val[0] >= val[3]) or (val[0]+val[1] >= val[3])):
    ans = 1 * val[0]
    print(ans)
else:
    ans = 1 * val[0] - 1*(val[3]-val[0]-val[1])
    print(ans)


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

int main(){
    string x,ans="No";
    int total=0;
    cin >> x;
    for(int i=0;i<x.size();i++){
        total+=(int)(x.at(i)-'0');
    }
    if(stoi(x)%total==0) ans="Yes";
    cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  string s;
  cin >> s;
  ll res = 0;
  REP(i,4)s[i] == '+' ? res++ : res--;
  cout << res << endl;


  

  return 0;
}


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

using namespace std;
int main(void){
    pair<pair<string,int>,int> rests[110];
    int N, P;
    string S;
    std::cin >> N;
    
    
    for(int i=0; i<N; ++i){
        std::cin >> S >> P;
        rests[i]=make_pair(make_pair(S,-P),i+1);
    }
    
    std::sort(rests, rests+N);
    for(int i=0;i<N;i++)
        cout << rests[i].second<< endl;
    
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    char S[100000];
    int tmp=0;
    int count1=0;
    int count2=0;
    char flg='0';
    int i=0;
    scanf("%s",S);
    while(S[i]=='1'||S[i]=='0'){
        if(S[i]==flg){
            count1++;
            if(flg=='1'){
                flg='0';
            }else{
                flg='1';
            }
        }else{
            count2++;
            if(flg=='1'){
                flg='0';
            }else{
                flg='1';
            }
        }
        i++;
    }
    if(count1<count2){
        printf("%d\n",count1);
    }else{
        printf("%d\n",count2);
    }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)
#define MAX_N (100010)
using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

typedef struct G {
    int v;
    int w;
}Graph;

int N;
vector<Graph> u[MAX_N];
int node[MAX_N];
bool used[MAX_N];

int bfs(int s,int color) {
    for(int i = 0;i < u[s].size();i++) {
        if(used[u[s][i].v])
            continue;
        used[u[s][i].v] = true;

        if(u[s][i].w % 2 == 0) {
            node[u[s][i].v] = color;
            bfs(u[s][i].v, color);
        } else {
            if (color == 0) {
                node[u[s][i].v] = 1;
                bfs(u[s][i].v, 1);
            } else {
                node[u[s][i].v] = 0;
                bfs(u[s][i].v, 0);
            }
        }
    }

    return 0;
}

int main(void) {
    cin>>N;

    for(int i = 1;i < N;i++) {
        Graph g1,g2;
        int ui,vi,wi;
        cin>>ui>>vi>>wi;
        g1.v = vi;
        g1.w = wi;
        g2.v = ui;
        g2.w = wi;
        u[ui].push_back(g1);
        u[vi].push_back(g2);
    }

    int c = 0;
    node[1] = c;
    bfs(1,c);

    for(int i = 1;i <= N;i++) {
        cout<<node[i]<<endl;
    }

    return 0;
}


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

int main(void){
	ll a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	ll diff=c-a-b;
	if(diff<=0){
		printf("No\n");
		return 0;
	}else{
		printf("%s\n",diff*diff>4LL*a*b?"Yes":"No");
	}
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
from heapq import heapify, heappop, heappush
from math import ceil
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]

heapify(A)

for i in range(M):
    min_A = heappop(A)
    heappush(A, ceil(min_A/2))

print(-sum(A))



Measured memory_bytes: 19956
#include<iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    
    int a[3*N];
    for(int i=0; i<3*N; i++) cin >> a[i];

    sort(a, a+3*N, greater<int>());
    
    long int sum = 0;
    for(int i=0; i<2*N; i+=2){
        sum += a[i+1];
    }
    cout << sum;

}

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

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

    string s;
    cin >> s;

    int nsum = 0;

    for (const auto d : s) {
        const int x = d - '0';
        nsum += x;
        nsum %= 9;
    }

    cout << (nsum == 0 ? "Yes" : "No") << '\n';

    return 0;
}


Measured memory_bytes: 3744
import sys

def main():
    l1 = sys.stdin.readline()
    lst = l1.split()
    height = int(lst[0])
    width = int(lst[1])

    l2 = sys.stdin.readline()
    lst = l2.split()
    h = int(lst[0])
    w = int(lst[1])

    ans = height * width - h * width - w * height + h * w
    print(ans)

    return 0

if __name__ == '__main__':
    sys.exit(main())


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    if (A == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = (N / (A + B)) * A;
    ll s = N % (A+B);
    if(s > A) ans += A;
    else ans += s;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256