akhauriyash/Code-Regression huggingface dataset:
'use strict'

const main = INPUT => {
  const input = INPUT.split('\n')
  const X = Number(input[0].split(' ')[2])
  const Y = Number(input[0].split(' ')[3])
  const x = input[1].split(' ').map(n => Number(n)).sort((a, b) => b - a)[0]
  const y = input[2].split(' ').map(n => Number(n)).sort((a, b) => a - b)[0]
  let ans = 'War'

  for (let i = X + 1; i <= Y; i++) {
    if (x < i && y >= i) {
      ans = 'No War'
    }
  }
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct range{
  ll pl,pr,nl,nr;
};

bool sorter(const range& a,const range& b){
  return a.pl < b.pl;
}

ll n,k;
vector<range> rs;
ll dp[2][70000];

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

  cin>>n>>k;
  for(ll j=1;j*j<=n;j++){
    rs.push_back((range){j,j,1,n/j});
    if(n/j!=j){
      rs.push_back((range){(n/(j+1))+1,n/j,1,j});
    }
  }
  sort(all(rs),sorter);
  ll m=rs.size();
  ll crt=0,nxt=1;
  rep(j,m)dp[crt][j]=(rs[j].pr-rs[j].pl+1);
  rep(i,k-1){
    rep(j,m)dp[nxt][j]=0;
    rep(j,m){
      (dp[nxt][m-1-j]+=dp[crt][j]*(rs[m-1-j].pr-rs[m-1-j].pl+1)%mod)%=mod;
      if(j+1<m)(dp[crt][j+1]+=dp[crt][j])%=mod;
    }
    swap(crt,nxt);
  }
  ll res=0;
  rep(j,m)(res+=dp[crt][j])%=mod;
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 3312
from math import atan, pi
 
a, b, x = [float(x) for x in input().split()]
 
v = a * a * b
 
if v / 2 < x:
    t = atan(2 * (v - x) / (a * a * a))
else:
    # t = atan(v / 2 / x)
    t = pi / 2 - atan(2 * x / (a * b * b))
 
print(t * 180.0 / pi)


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#define MAX 10000
#include<complex>
using namespace std;
typedef complex<double> P;
int main(){
	int n;
	double p[MAX],q[MAX];
	while(cin>>n,n){
		P tab[MAX];
		int ans=1;
		for(int i=0;i<n;i++){
			cin>>p[i]>>q[i];
			tab[i]=P(p[i],q[i]);
		}
		for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++){
			if(   norm(tab[i]-tab[j]) >4.0){
				//cout<<88<<endl;
				continue;
			}
			P temp=(tab[i]-tab[j])*sqrt(1-(((p[i]-p[j])*(p[i]-p[j])+(q[i]-q[j])*(q[i]-q[j]))*0.25))/abs(tab[i]-tab[j]);
			P pre=(tab[i]+tab[j])*0.5+temp*P(0,1);
			int r=2;
			for(int k=0;k<n;k++){
				if(norm(tab[k]-pre)<=1.0&&(i!=k&&j!=k))
				r++;
			}
			ans=max(ans,r);
			temp=(tab[i]-tab[j])*sqrt(1-(   ( (p[i]-p[j])*(p[i]-p[j]) + (q[i]-q[j])*(q[i]-q[j]) )*0.25))/abs(tab[i]-tab[j]);
			pre=(tab[i]+tab[j])*0.5+temp*P(0,1)*P(0,1)*P(0,1);
			r=2;
			for(int k=0;k<n;k++){
				if(norm(tab[k]-pre)<=1.0&&(i!=k&&j!=k))
				r++;
			}
			ans=max(ans,r);
			
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1148
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

A, B, C, K = map(int, input().split())

if A + B < K:
    c = K - A - B
    print(A - c)
elif A > K:
    print(K)
else:
    print(A)


Measured memory_bytes: 72660
#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<queue>
#include<set>
#include<stack>
#include<map>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 
 
typedef pair<int,int >P;
//////////////////////////   
/////////////////////////
int main(){

   
   ll n,m;
   L2(n,m);
   ll ar[ n+ 2];
   for(int i = 1;i<= n;i++){
       L(ar[i]);
   }
   

   ll res = 0;
   ll koto = 0;
   for(ll i = 50; i>= 0;i--){
       ll ko = 0;
       for(ll k = 1;k<=n;k++){
           if( (ar[k] & (1ll<< i)) > 0)ko++;
       }
       ll baki = n - ko;

       if (koto + (1ll<<i) > m || ko >= baki){
            res += (1ll<<i) * ko;
            continue;
        }

        koto += (1ll<<i);
        res += (1ll<<i) * (baki);
   }

   cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
const int N = 2e3+9;
int _count[N];
int main() {
    int n;
    int x,y;
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int dist1 = (j-i);
            int dist2 = abs(x-i)+1+abs(y-j);
            _count[min(dist1,dist2)]++;
        }
    }
    for(int i=1;i<n;i++){
        cout<<_count[i]<<"\n";
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int count = 1;
        Boolean isIncrease = null;
        for (int i = 1; i < n - 1; i++) {
            int left = a[i - 1];
            int right = a[i + 1];
            int center = a[i];

            if (isIncrease == null) {
                isIncrease = left == center ? null : left < center;
            }

            if (isIncrease != null) {
                if (isIncrease && right < center) {
                    count++;
                    isIncrease = null;
                    i++;

                } else if (!isIncrease && center < right) {
                    count++;
                    isIncrease = null;
                    i++;

                }
            }
        }
        int result = count;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 47684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);


  int n,k;cin>>n>>k;
  vector<int> h(n);
  for(int i=0;i<n;i++)cin>>h[i];

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

  for(int i=0;i<k && i < n;i++){
    h[i]=0;
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    ans+=h[i];
  }
  cout<<ans<<endl;
  
  return 0;
}


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

int main(){
    string w,t; cin>>w;

    int ans=0;
    while(1){
        cin>>t;
        if(t=="END_OF_TEXT")break;

        for(int i=0;i<t.size();i++){
            if('A'<=t[i] && t[i]<='Z')t[i]+=32;
        }
        if(t==w)ans++;
    }


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


Measured memory_bytes: 3176
include Math
N = gets.to_i
if N % 2 == 1
  puts 0
else
  order = Math.log(N, 5)
  # puts order
  ans = 0
  (1..order).each do |i|
    ans += N.div(5**i)/2
    #print i.to_s + " "
    #puts ans
  end
  puts ans
end

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

int main() {
  int N, X, T;
  cin >> N >> X >> T;

  if (N % X == 0) {
    cout << N / X * T;
  } else {
    cout << (N / X * T) + T;
  }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;

long long ans;
map<int,map<string, long long > > dp;
int n;
string maap[4] = {"A","T","G","C"};

bool cek(string x){
	if(x.find("AGC")!=string::npos) return 0;
	for(int i =0;i<3;i++){
		swap(x[i],x[i+1]);
		if(x.find("AGC")!=string::npos) return 0;
		swap(x[i],x[i+1]);
	}
	return 1;
}

long long dfs(int pos, string las){
	if(pos==n) return 1;
	if(dp[pos][las]!=0) return dp[pos][las];
	
	string st = las;
	st.erase(0,1);
	
	long long ret = 0;
	
	for(int i =0;i<4;i++){
		if(cek(las+maap[i])) ret = (ret+dfs(pos+1,st + maap[i] ) )%MOD;
	}
	
	return dp[pos][las] = ret;
}

int main(){
	scanf("%d",&n);
	ans = dfs(0,"TTT");
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>

#include <climits>

#define DEBUG if(false)

using namespace std;

int main(){

  int N, ans;
  cin >> N;
  if(N % 2 == 0){
    ans = N;
  }else{
    ans = N*2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [n, a, b] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const ans = () => {
  let total = 0

  for (let i = 1; i <= n; i++) {
    const digits = String(i)
      .split('')
      .map(Number)

    const sum = digits.reduce((p, c) => p + c)

    if (sum >= a && sum <= b) total += i
  }

  console.log(total)
}

ans()


Measured memory_bytes: 10340
// Starting with the name of Allah

#include <bits/stdc++.h>
#define ll long long
#define nl endl
#define PI 3.14159265358979323846264338

using namespace std;
int main()
{
	long double A,B,H,M,arg,len=0;
	cin>>A>>B>>H>>M;
	len=sqrt(A*A+B*B-2*A*B*cos((60*H-11*M)*PI/360));

	cout<<std::setprecision(20)<<len<<endl;
	return 0;
}


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

namespace ABC128
{
	class Program
	{
		static void Main(string[] args)
		{
			var nk = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
			var N = nk[0];
			var K = nk[1] + 1;
			var V = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

			var ans = 0;
			foreach (var a in Enumerable.Range(0, K))
			{
				var queueA = V.Take(a);
				foreach (var b in Enumerable.Range(0, K - a))
				{
					var queueB = queueA.Concat(V.Skip(Math.Max(a, N - b)));
					foreach (var c in Enumerable.Range(0, Math.Min(K - (a + b), queueB.Count() + 1)))
					{
						var queueC = queueB.OrderBy(x => x).Skip(c);
						ans = Math.Max(ans, queueC.Sum());
					}
				}
			}
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 17560
from collections import deque
s = deque(i for i in input())
n = int(input())
l = [[i for i in input().split()] for _ in range(n)]

front = True

for i in l:
    if i[0] == '1':
        front = not front
    else:
        if front ^ (int(i[1]) == 1):
            s.append(i[2])
        else:
            s.appendleft(i[2])
            
ans = ''.join(s)

if front:
    print(ans)
else:
    ans = ans[::-1]
    print(ans)

Measured memory_bytes: 32108
N, M = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)

cost = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = Array.new(N + 1, '')
dp[0] = '0'

ans = 0

N.times do |i|
  next if dp[i] == ''

  A.each do |n|
    total = i + cost[n]
    next if total > N

    str = dp[i] + n.to_s

    s1 = dp[total].size
    s2 = str.size

    if (s1 == s2 && dp[total] < str) || s1 < s2
      dp[total] = str
    end
  end
end

puts dp[N].to_i


Measured memory_bytes: 73340
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i = 0; i < (int)(n); i++)

typedef vector< vector<pair<int, int> > > Graph;

Graph G;
vector<int> ans;
vector<set<int> > rec;
vector<bool> visited;

void dfs(const int cur) {
  visited[cur] = true;
  int num = 1;
  REP(i, G[cur].size()) {
    int to = G[cur][i].first;
    int e = G[cur][i].second;
    if(visited[to]) continue;
    while(true) {
      if(rec[cur].find(num) == rec[cur].end()) {
	ans[e] = num;
	rec[cur].insert(num);
	rec[to].insert(num);
	break;
      }
      num++;
    }
    dfs(to);
  }
}

int main() {
  int N; cin>>N;
  G = Graph(N);
  ans = vector<int> (N-1, -1);
  rec = vector<set<int> > (N);
  visited = vector<bool> (N, false);
  REP(i,N-1) {
    int a, b; cin>>a>>b; a--; b--;
    G[a].push_back(make_pair(b, i));
    G[b].push_back(make_pair(a, i));
  }
  int max_v = 0;
  REP(i,N) {
    max_v = max(max_v, (int)(G[i].size()));
  }
  cout << max_v << endl;
  dfs(0);
  REP(i,ans.size()) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 20992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;
    vector < pair <ll, ll> > points(N);
    vector < ll> sum(N), diff(N);
    for (int i=0; i<N; ++i) 
    {
        cin >> points[i].first >> points[i].second;
        sum[i]=points[i].first+points[i].second;
        diff[i]=points[i].first-points[i].second; 
    }
    sort(sum.begin(), sum.end());
    sort(diff.begin(), diff.end());
    cout << max(abs(sum[N-1]-sum[0]), abs(diff[N-1]-diff[0])) << "\n";
    return 0;
}

Measured memory_bytes: 9524
#include <iostream>
using namespace std;
int main()
{
    int A, B, C, D, E, ans ;
    cin >> A >> B >> C >> D >> E ;
    
    if(A>0){
        ans = (B-A)*E;
        
    }
    else {
        ans = -A * C + D + B * E;
        
    }
    
    
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
const int inf=2100000000;
int a[200000];
int main(){
	int n,mi=inf,ans=-inf;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if(a[i]-mi>ans){
			ans=a[i]-mi;
		}
		if(mi>a[i]){
			mi=a[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3868
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, K, ans;

int main()
{
	in >> N >> K;
	std::vector<LL>x(N), plus(N + 1, 0), minus(N + 1, 0), temp;
	rep(i,N)
	{
	in>>x[i];
	}
	rep(i, N)
	{
		if (x[i] < 0) temp.push_back(x[i]);
	}
	std::sort(temp.rbegin(), temp.rend());
	LL cou1 = 1, cou2 = 1;
	rep(i, N)
	{
		if (x[i] > 0)
		{
			plus[cou1] = x[i];
			++cou1;
		}
		if (x[i] == 0) --K;
	}
	rep(i, temp.size())
	{
		if (temp[i] < 0)
		{
			minus[cou2] = -temp[i];
			++cou2;
		}
	}
	if (K == 0)
	{
		out << 0 << std::endl;
		return 0;
	}
	ans = 11234567890;
	for (int i = 0; i <= std::min<LL>(cou1 - 1, K); ++i)
	{
		if (K != i && minus[K - i] == 0) continue;
		LL res = plus[i] + minus[K - i];
		res += std::min(plus[i], minus[K - i]);
		ans = std::min(ans, res);
	}
	out << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    if(a - b >= 0)
        cout << "delicious" << endl;
    else if(b - a <= x)
        cout << "safe" << endl;
    else
        cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr 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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;



int main() {
    
    int n,k;
    cin>>n>>k;
    vi v(n);
    rep(i,n)cin>>v[i];
    Sort(v);
    int ans=0;
    rep(i,k)ans+=v[i];
    fin(ans);
}

Measured memory_bytes: 3628
h, w, k = map(int, input().split())
g = [input() for _ in range(h)]
ans = 0
for bit in range(2**(h+w)):
    cnt = 0
    for hh in range(h):
        if ((bit >> hh) & 1):
            continue
        for ww in range(w):
            if ((bit >> h + ww) & 1):
                continue
            if g[hh][ww] == '#':
                cnt += 1
    if cnt == k:
        ans += 1
print(ans)


Measured memory_bytes: 9056
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 5000;
const int MOD = int(1E9) + 7;
const int INV2 = (MOD + 1) >> 1;

struct edge{
	edge *nxt; int to;
}edges[2*MAXN + 5], *adj[MAXN + 5], *ecnt = edges;
void addedge(int u, int v) {
	edge *p = (++ecnt);
	p->to = v, p->nxt = adj[u], adj[u] = p;
	p = (++ecnt);
	p->to = u, p->nxt = adj[v], adj[v] = p;
}

int fct[MAXN + 5], ifct[MAXN + 5], coef[MAXN + 5];
void init() {
	fct[0] = 1;
	for(int i=1;i<=MAXN;i++)
		fct[i] = 1LL*fct[i-1]*i%MOD;
	ifct[1] = 1;
	for(int i=2;i<=MAXN;i++)
		ifct[i] = (MOD - 1LL*(MOD/i)*ifct[MOD%i]%MOD);
	ifct[0] = 1;
	for(int i=1;i<=MAXN;i++)
		ifct[i] = 1LL*ifct[i-1]*ifct[i]%MOD;
	int t = INV2;
	for(int i=2;i<=MAXN;i+=2,t=1LL*t*INV2%MOD)
		coef[i] = 1LL*fct[i]*ifct[i/2]%MOD*t%MOD;
}

int dp[MAXN + 5][MAXN + 5], siz[MAXN + 5];
void dfs(int x, int f) {
	dp[x][siz[x] = 1] = 1;
	for(edge *p=adj[x];p;p=p->nxt) {
		if( p->to == f ) continue;
		dfs(p->to, x);
		int t1 = siz[x], t2 = siz[p->to], del = 0;
		for(int i=2;i<=t2;i+=2)
			del = (del + 1LL*dp[p->to][i]*coef[i]%MOD) % MOD;
		del = (MOD - del) % MOD;
		for(int i=t1;i>=1;i--) {
			for(int j=t2;j>=1;j--)
				dp[x][i+j] = (dp[x][i+j] + 1LL*dp[x][i]*dp[p->to][j]%MOD) % MOD;
			dp[x][i] = 1LL*del*dp[x][i] % MOD;
		}
		siz[x] += siz[p->to];
	}
}

int main() {
	int N; init();
	scanf("%d", &N);
	for(int i=1;i<N;i++) {
		int x, y; scanf("%d%d", &x, &y);
		addedge(x, y);
	}
	dfs(1, 0);
	int ans = 0;
	for(int i=1;i<=N;i++)
		ans = (ans + 1LL*dp[1][i]*coef[i]%MOD) % MOD;
	printf("%d\n", ans);
}

Measured memory_bytes: 57868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int h,n;
  cin>>h>>n;
  vector<P> a(n);
  rep(i,0,n){
    cin>>a[i].first;
    cin>>a[i].second;
  }
  int b[h+1];
  b[0]=0;
  rep(i,1,h+1) b[i]=100000000;
  rep(i,0,h+1){
    rep(j,0,n){
      if(i<a[j].first) b[i]=min(b[i],a[j].second);
      else b[i]=min(b[i],a[j].second+b[i-a[j].first]);
    }
  }
  cout<<b[h]<<endl;
}

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

int getTime(int left,int right){
  // 両者正の場合
  if(left>=0 && right>=0){
    return right;
  }

  // 両者負の場合
  if(left<=0 && right<=0){
    return -left;
  }

  // 正負混合の場合
  return (-left > right) ? (-left + right * 2) : (-left * 2 + right);
}

int main(void){
  int N, K;
  vector<int> x;
  cin >> N >> K;
  x.resize(N);

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

  int min = -1;

  for (int i = 0; i < N - K + 1; i++){
    int left = x[i];
    int right = x[i + K - 1];
    int time = getTime(left, right);
    if(min==-1 || min>time){
      min = time;
    }
  }
  cout << min << endl;
}


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

typedef long long ll;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    for (int i = 0; i < N; i++) cin >> V[i];
 
    ll ans = (int)-1E9;
 
    for (int l = 0; l < K+1; l++) {
        for (int r = 0; r < K+1; r++) {
            if (min(K, N) < l + r)
                break;
            vector<int> a;
            for (int i = 0; i < l; i++) { a.push_back(V[i]); }
            for (int i = 0; i < r; i++) { a.push_back(V[N - i - 1]); }
            sort(a.begin(), a.end());
            ll sum = 0;
            for (int i = 0; i < int(a.size()); i++) {
                if (a[i] < 0 && i < K - r - l) {
                } else {
                    sum += a[i];
                }
            }
            ans = max(ans, sum);
        }
    }
 
    cout << ans << endl;;
 
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=105;

int32_t main()
{
	int a,b;
	cin>>a>>b;
	int n=__gcd(a,b);
	int c=1;
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			c++;
			while(n%i==0) n/=i;
		}
	}
	if(n>1) c++;
	cout<<c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 5200
using namespace std;
long long f[N][N];
int p[N],a[N];
int n,l,r;
int main(){	
	scanf("%d%d%d",&n,&r,&l);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)p[a[i]]=i;
	for(int i=1;i<=n;i++){
		long long now=f[i-1][0];
		for(int j=0;j<=n+1;j++){
			now=min(now,f[i-1][j]);
			if(p[i]+1>j)f[i][j]=now+l;
			else if(p[i]+1==j)f[i][j]=now;
			else f[i][j]=now+r;
		}
	}
	long long ans=1000000000000000000LL;
	for(int i=0;i<=n+1;i++)ans=min(ans,f[n][i]);
	printf("%lld\n",ans);
}

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

int fact(int n) {
  if (n == 0) return 1;
  return n * fact(n - 1);
}

int abs(int p, int q) {
  if (p > q) {return p - q;}
  else {return q-p;}
}

int main() {
  int N;
  cin >> N;
  int P[N];
  int Q[N];
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> Q[i];
  }
  
  int sp[N];
  int sq[N];
  
  for (int i = 0; i < N; i++) {
    sp[i] = 0;
    sq[i] = 0;
    for (int j = i + 1; j < N; j++) {
      if (P[i] > P[j]) sp[i]++;
      if (Q[i] > Q[j]) sq[i]++;
    }
  }
  
  int dp = 0; 
  int dq = 0;
  
  for (int i = 0; i < N; i++) {
    dp = dp + sp[i] * fact(N-1-i);
    dq = dq + sq[i] * fact(N-1-i);
  }
  
  cout << abs(dp, dq) << endl;
 

}


Measured memory_bytes: 256
N = int(input())
A = [int(_) for _ in input().split()]

i, j, k = 1, 2, 3
B, C, D, E = A[0], A[1], A[2], sum(A[3:])

result = 10 ** 20

while 1:

    while 1:   
        newB, newC = B + A[i], C - A[i]
        if abs(B - C) < abs(newB - newC):
            break
        i += 1
        B, C = newB, newC

    while 1:   
        newD, newE = D + A[k], E - A[k]
        if abs(D - E) < abs(newD - newE):
            break
        k += 1
        D, E = newD, newE

    r = max(B, C, D, E) - min(B, C, D, E)
    result = min(result, r)

    C, D = C + A[j], D - A[j]
    j += 1
    if j == N - 1:
        break
    
print(result)


Measured memory_bytes: 24668
using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using System.Text;
    using System.Net;

     
    public class Program
    {

        public void Proc() {
            int num = int.Parse(Reader.ReadLine().Replace(" ", ""));
            Dictionary<int, int> cnt = GetDividePrime(num);
            String ans = "Yes";
            if(cnt.Any(a=>a.Value%2!=0)) {
                ans = "No";
            }
            Console.WriteLine(ans);
        }


        private Dictionary<int, int> GetDividePrime(int inpt) {
            List<int> primeList = new List<int>();
            bool[] flag = new bool[inpt+1];
            for(int i=2; i<=inpt; i++) {
                if(flag[i]) {
                    continue;
                }
                for(int j=i; j<=inpt; j+=i) {
                    flag[j] = true;
                }
                primeList.Add(i);
            }
            int num = inpt;
            Dictionary<int, int > primeCount = new Dictionary<int, int>();
            foreach(int prime in primeList) {
                while(num%prime==0) {
                    if(!primeCount.ContainsKey(prime)) {
                        primeCount.Add(prime, 1);
                    } else {
                        primeCount[prime]++;
                    }
                    num = num / prime;
                }                
            }
            return primeCount;
        }



        public class Reader {
            public static bool IsDebug = false;
            private static System.IO.StringReader SReader;
            private static string InitText = @"




100 100






";
            public static string ReadLine() {
                if(IsDebug) {
                    if(SReader == null) {
                        SReader = new System.IO.StringReader(InitText.Trim());
                    }
                    return SReader.ReadLine();
                } else {
                    return Console.ReadLine();
                }
            }
        }
        public static void Main(string[] args)
        {
            #if DEBUG
            Reader.IsDebug = true;
            #endif
            Program prg = new Program();
            prg.Proc();
        }
    }

Measured memory_bytes: 13280
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i=j; i<k; i+=step)
#define loop(i, j, k) for (int i=j; i<k; i++) 
#define rloop1(i, j, k, step) for (int i=j; i>=k; i-=step)
#define rloop(i, j, k) for(int i=j; i>=k; i--)
#define rep(i, k) for(int i = (0); i < (k); i++ )
#define rrep(i, k) for(int i = k-1; i >= 0; i-- )

#define forall(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define endl "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;


void solve()
{
  int x,i,j,k,l;
  cin>>x;
  if(x==0)
    cout<<1<<endl;
  else
    cout<<0<<endl;
}
int  main() 
{
  auto start=clock();
  fast_io;
    int t=1;
    //cin>>t;
    while(t--){
      solve();
    }
    auto stop =clock();
    cerr<<"time taken:"<<double(stop-start)/double(CLOCKS_PER_SEC)<<" s"<<endl;
  return 0; 
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); i++)

int main() {
    /*変数定義，入力*/
    string s;
    int K;
    cin >> K;
    cin >> s;

    //ll A, B;cin >> A >> B;
    //vector<ll> a(N);  rep(i, N) cin >> a[i];
    
    /*演算*/
    if(s.length() <= K){
        cout << s << endl;
    }else{
        cout << s.substr(0, K) << "..." << endl;
    }
   /*終了*/
    return 0;
}

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

void cmin(int& a, const int &b) {
    if (b < a)
        a = b;
}

void cmax(int &a, const int &b) {
    if (b > a)
        a = b;
}

const int INF = (int)1e9 + 239;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int mxa = -INF, mna = INF, mxb = -INF, mnb = INF;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        int a = x + y, b = x - y;
        cmin(mna, a);
        cmax(mxa, a);
        cmin(mnb, b);
        cmax(mxb, b);
    }
    cout << max(mxa - mna, mxb - mnb);
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	long int n,max;
	cin >> n;
	n--;

	if (n % 2 == 0) {
		max = n / 2 * (1 + n);
	}
	else {
		max = (1 + n) / 2 * n;
	}
	cout << max << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 200100
 
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(b>a)
		swap(a,b);
	int k=a+b;
	if(k%2)
		printf("IMPOSSIBLE\n");
	else
		printf("%d\n",k/2);
}
	

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(k,i,n) for(int i = (k); i < (int)(n); i++)
typedef long long ll;
typedef pair<int,int> Pii;

int main() {
    int n,m;
    cin>>n>>m;
    priority_queue<Pii,vector<Pii>,greater<Pii>> que;
    rep(i,m){
        int a,b;cin>>a>>b;
        que.push(Pii(b,a));
    }
    int ma=-1,ans=0;
    rep(i,m){
        int b=que.top().first,a=que.top().second;
        que.pop();
        if(ma>=a) continue;
        ma=b-1;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1400
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	vector<pair<int, int>> P(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &P[i].first, &P[i].second);
	}
	sort(P.begin(), P.end());
	int bestL = 0;
	for (int i = 0; i < n; ++i) {
		if (P[i].first > bestL) ++bestL;
	}
	reverse(P.begin(), P.end());
	multiset<int> RS;
	int j = 0;
	for (int i = bestL; i >= 1; --i) {
		while (j < n && P[j].first >= i) {
			RS.insert(P[j].second);
			++j;
		}
		assert(!RS.empty());
		RS.erase(prev(RS.end()));
	}
	while (j < n) {
		RS.insert(P[j].second);
		++j;
	}
	int bestR = 0;
	for (auto it = RS.rbegin(); it != RS.rend(); ++it) {
		if (m + 1 - *it > bestR) ++bestR;
	}
	db2(bestL, bestR);
	dbv(RS);
	int ans = min(m, bestL + bestR);
	printf("%d\n", n - ans);
}

Measured memory_bytes: 11136
import java.util.*

fun main(args: Array<String>) {
    solve(Scanner(System.`in`))
}

fun pow(a: Int, p: Int): Long = pow(a.toLong(), p)
fun pow(a: Long, p: Int): Long = when {
    p == 0 -> 1L
    p % 2 == 1 -> a * pow(a, p - 1)
    else -> {
        val half = pow(a, p / 2)
        half * half
    }
}

fun bits(n: Int): Int {
    var bits = 0
    for (i in 0..15) {
        if ((1 shl i) and n != 0) {
            bits++
        }
    }
    return bits
}

fun solve(sc: Scanner) {
    val N = sc.nextInt()
    val M = sc.nextInt()
    val S = Array(M) {
        Array(sc.nextInt()) {
            1 shl (sc.nextInt() - 1)
        }.reduce { acc, i -> acc or i }
    }
    val P = Array(M) {
        sc.nextInt()
    }

    var result = 0
    for (switch in 0 until (pow(2, N)).toInt()) {
        var num = 0
        for (i in 0 until S.count()) {
            if ((bits(S[i] and switch) % 2) == P[i]) {
                num++
            }
        }
        if (num == M) {
            result++
        }
    }

    println(result)
}


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

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<ll> X(m); rep(i, m) cin >> X[i];
  sort(all(X));
  vector<ll> D;
  rep(i, m-1) D.push_back(X[i+1]-X[i]);
  sort(all(D));
  cout << accumulate(begin(D), begin(D)+max((m-n), 0), 0LL) << endk;
  return 0;
}


Measured memory_bytes: 5016
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
#define P pair
#define M 998244353
#define fr(i,n) for(int i=0;i<n;i++)
#define M2 1000000007
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define CASES  ll t;cin>>t;while(t--)
#define Take_n ll n; cin>>n;
using namespace std;

int main() 
{
	//your code
	int n,k,i,j;
	cin>>n>>k;
	int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	bool dp[k+1];
	memset(dp,false,sizeof(dp));
	for(i=1;i<=k;i++)
	{
		for(j=0;j<n;j++)
		{
			if(i-a[j]<0)
			{
				dp[i]=false;
			}
			else
			{
				if(dp[i-a[j]]==false)
				{
					dp[i]=true;
					break;
				}
			}
		}
	}
	if(dp[k]==true)
	cout<<"First";
	else
	cout<<"Second";
	return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <cstdlib>
#include <iomanip>

using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
long N;
int K;
long long h[100010];

// DP テーブル
long long dp[100100];

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }

    // dp　初期化
    for (int i = 0; i < 100100; i++) {
        dp[i] = INF;
    }
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j <= i + K; j++) {
            chmin(dp[j], dp[i] + abs(h[i] - h[j]));
        }
    }
    
    cout << dp[N - 1] << endl;
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

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

const ll X[10] = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};

ll N, M;
vi A;

int main()
{
    cin >> N >> M;
    A = vi(M);
    REP(i, M)
    {
        cin >> A[i];
    }
    SORT(A);

    vi dp = vi(N + 1, -INF);
    dp[0] = 0;
    vi use = vi(N + 1);
    for (ll i = 2; i <= N; i++)
    {
        REP(j, M)
        {
            if (X[A[j]] <= i and dp[i - X[A[j]]] + 1 >= dp[i])
            {
                dp[i] = dp[i - X[A[j]]] + 1;
                use[i] = A[j];
            }
        }
    }
    string ans = string(dp[N], '0');
    ll k = N;
    REP(i, dp[N])
    {
        ans[i] = '0' + use[k];
        k -= X[use[k]];
    }
    RSORT(ans);

    OUT(ans);
}

Measured memory_bytes: 384
using System;

namespace ConsoleApp34
{
    class Program
    {
        
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] array = line.Split(' ');

            int n = int.Parse(array[0]);
            int k = int.Parse(array[1]);

            string li = Console.ReadLine();
            string[] arr = li.Split(' ');
            int[] a = new int[n];

            for (int i = 0; i< arr.Length ; i++)
            {
                a[i] = int.Parse(arr[i]);
            }

            Array.Sort(a);
            int sum = 0;
            for(int i = 0; i < k; i++)
            {
                sum += a[i];
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 27612
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <bits/stdc++.h>
using namespace std;

				
int main(){
	string s;
	int k;
	cin>>k>>s;
	int lnth=s.length();
	if(lnth<=k){
		cout<<s<<endl;
		return 0;
	}
	for(int i=0;i<k;i++){
		cout<<s[i];
	}
	cout<<"..."<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    int A;
    string S;
    
    bool operator<( const Data& right ) const {
        return A == right.A ? S < right.S : A < right.A;
        //return A < right.A;
    }
};

int Func(){
    int x = 0;
    return x;
}

int main(){
    int N;
    long long A[1000];
    float f;
    string S;
    
    cin >> S;
    
    for(int i=0;i<3;i++) {
        if (S[i]=='1') {
            cout << 9;
        }
        else cout << 1;
    }
    cout << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(k,n) for(auto i =k; i<n; i++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie();

int main(){
    IOS
    string s ;
    cin>>s; 
    if(s.size()==6){
    if((s[2]==s[3])&&(s[4]==s[5]))cout<<"Yes";
    else{
        cout<<"No";
    }
    }
    else{cout<<"No";}
    return 0;
}

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

int main(){
    int n,cnt;
    int a[100];
    bool flag = true;
    cin >> n;
    cnt = 0;
    for(int i=0; i<n; i++) cin >> a[i];
    while(flag){
        flag = false;
        for(int j=n-1; j>0; j--){
            if(a[j] < a[j-1]){
                swap(a[j],a[j-1]);
                cnt += 1;
                flag = true;
            };
        };
    };
    for(int i=0; i<n-1; i++){
        cout << a[i] << " ";
    };
    cout << a[n-1] << endl << cnt << endl;
    return 0;
}


Measured memory_bytes: 3092
N,M=map(int,input().split())
edges=[[] for _ in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  edges[a-1]+=[b-1]
  edges[b-1]+=[a-1]
vis=[1]+[0]*(N-1)#訪問フラグ

ans=0
def DFS(v):
  global ans
  if vis==[1]*N: 
    ans+=1
    return 0
  for u in edges[v]:
    if vis[u]==0:
      vis[u]=1
      DFS(u)
      vis[u]=0
  else: return 0
DFS(0)
print(ans)

Measured memory_bytes: 3064
N = int(input())
n = [input().split() for _ in range(N)]

all_card = {"S": [], "H": [], "C": [], "D": []}
number = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

for k in n:
    all_card[k[0]].append(int(k[1]))

for c in ["S", "H", "C", "D"]:
    res = list(set(number) - set(all_card[c]))
    res.sort()
    for n in list(res):
        print("{} {}".format(c, n))


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    int ans = 0;

    vi h(n);
    REP(i, n)
    {
        int tmp;
        cin >> tmp;

        if(tmp >= k){
            ans++;
        }
    }


    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<vector>
#include<tuple>
using namespace std;
int main() {
	
	long long N, A, B;
	cin >> N >> A >> B;
	long long sum = A + B;
	if (sum == 0) {
		cout << 0 << endl;
		return 0;
	}
	long long re = N / sum;
	long long amari = N % sum;
	long long ans = re * A;
	if (amari > A) {
		ans += A;
	}
	else {
		ans += amari;
	}
	cout << ans << endl;
	return 0;

}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)

int main() {
  int N;
  cin >> N;
  double ans;
  double n = (double)N;
  if (N % 2 == 0) {
    ans = ((double)1) / ((double)2);
  } else {
    double tmp = (n + (double)1) / ((double)2);
    ans = tmp / n;
  }
  printf("%.7f\n", ans);
};


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

int main()
{

	int a = 0, b = 0;

	cin >> a >> b;

	if((a + b) % 2 == 0)
		cout << (a + b) / 2 << endl;
	else
		cout << (a + b) / 2 + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
using namespace std;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, k; cin >> n >> k;
    if(n%k == 0)cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 3632
import Control.Applicative

main :: IO ()
main = solve <$> f >>= putStrLn
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> String
solve [x1, y1, x2, y2] = unwords . map show $ [y1-y2+x2, x2-x1+y2, y1-y2+x1, x2-x1+y1]


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int count1 = 0;
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        if (A.at(i) == 1) {
            count1++;
        }
    }
    if (count1 >= 1) {
        if (count1 >= 2) {
            cout << 0 << endl;
        }
        else {
            cout << 1 << endl;
        }
        return 0;
    }
    vector<bool> data(1000000, true);
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++) {
        if (data.at(A.at(i) - 1) && (A.at(i) - 1) * 2 < 1000000) {
            for (int j = 2; A.at(i) * j <= 1000000; j++) {
                data.at(A.at(i) * j - 1) = false;
            }
        }
    }
    for (int i = 0; i < N - 1; i++) {
        if (A.at(i) == A.at(i + 1)) {
            data.at(A.at(i) - 1) = false;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (data.at(A.at(i) - 1)) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4304