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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    double ret = 0;
    REP(i, n) ret += 1.0/a[i];
    cout << fixed << setprecision(9) << 1.0/ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, m;
    cin >> n >> m;
    map<ll, ll> mp;
    rep(i, n) {
        ll a;
        cin >> a;
        mp[a]++;
    }
    rep(i, m) {
        ll b, c;
        cin >> b >> c;
        mp[c] += b;
    }
    vector<pair<ll, ll>> v;
    for (auto p : mp) {
        v.push_back(p);
    }
    reverse(v.begin(), v.end());
    ll ans = 0;
    rep(i, sz(v)) {
        if (n <= 0) break;
        ans += v[i].fi * min(v[i].se, n);
        n -= v[i].se;
    }
    cout << ans << endl;
}

Measured memory_bytes: 18288
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    VI a(n);
    rep(i,n) cin >> a[i];
    int sum = 0;
    rep(i,n) sum += a[i];

    ll ans = INF;
    rep(i, 2){
        ll mid;
        if (i == 0) mid = floor((double)sum / n);
        else mid = ceil((double)sum / n);
        ll cost = 0;
        rep(j, n) cost += (a[j] - mid) * (a[j] - mid);
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
using System;
using System.Linq;

namespace Small_Large_Equal
{
    class Comparison
    {
        public static void Main()
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            if (a < b)
            {
                Console.WriteLine("a < b");
            }
            else if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else
            {
                Console.WriteLine("a == b");
            }
        }
    }
}



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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<int> d = new List<int>();
            string[] input = Console.ReadLine().Split(' ');
            for (int i = 0; i < N; i++)
            {
                d.Add(int.Parse(input[i]));
            }
            d.Sort();
            int K = d[d.Count/2] - d[d.Count / 2-1];
            Console.WriteLine(K.ToString());
        }
    }
}

Measured memory_bytes: 19552
use proconio::input;
fn main() {
    input! {
        n: usize,
        s: String,
        q: usize,
    }
    let w=n.next_power_of_two();
    let mut t=vec![0;w*2];
    for (i,c) in s.bytes().enumerate() {
        t[i+w]=1<<c-b'a';
    }
    for k in (0..w).rev() {
        t[k]=t[k*2]|t[k*2+1];
    }
    for _ in 0..q {
        input! { q: usize }
        if q==1 {
            input! {
                i: usize,
                c: String,
            }
            let mut k=i+w-1;
            t[k]=1<<c.as_bytes()[0]-b'a';
            while k>0 {
                k/=2;
                t[k]=t[k*2]|t[k*2+1];
            }
        }
        else {
            input! {
                l: usize,
                r: usize,
            }
            println!("{}",f(&t,1,0,w,l-1,r).count_ones());
        }
    }
}
fn f(t: &Vec<u32>, k: usize, a: usize, b: usize, l: usize, r: usize) -> u32 {
    if a==l && b==r {
        t[k]
    }
    else {
        let w=(b-a)/2;
        if l>=a+w {
            f(t,k*2+1,a+w,b,l,r)
        }
        else if r<=a+w {
            f(t,k*2,a,a+w,l,r)
        }
        else {
            f(t,k*2,a,a+w,l,a+w) | f(t,k*2+1,a+w,b,a+w,r)
        }
    }
}

Measured memory_bytes: 7288
#include <stdio.h>

int main(void)
{
int a,b,c,d,e,f,i;
double x[2];
while(scanf("%d %d %d %d %d %d\n",&a,&b,&c,&d,&e,&f)!=EOF)
{
x[0]=((double)(c*e-b*f))/(a*e-b*d),x[1]=((double)(a*f-c*d))/(a*e-b*d);
for(i=0;i<2;i++)
{
if(x[i]>=0) x[i]=((int)(1000*x[i]+0.5))/1000.0;
else x[i]=-((int)(-1000*x[i]+0.5))/1000.0;
}
printf("%.3f %.3f\n",x[0],x[1]);
}
return 0;
}

Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FS reader = new FS();
		String s = reader.next();
		System.out.println(s.substring(0, 4) + " " + s.substring(4, 12));
		// write reader
	}

	public static void solver(int N, int[][] costs) {
	}

	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}

		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}

Measured memory_bytes: 7892
import numpy as np

S = np.array(list(input()))

count=0
if S[0] == "R":
    count+=1

if S[1] == "R":
    count+=1
elif S[2] == "S":
    count+=0
else:
    count=0
    
if S[2] == "R":
    count+=1
    
    
print(count)

Measured memory_bytes: 27136
from itertools import combinations
x = int(input())
n = 1000
c = []
for i in range(n):
    c.append(i**5)
for (i, j) in combinations(range(n), 2):
    if c[j] - c[i] == x:
        print(j, i)
        break
    if c[j] + c[i] == x:
        print(j, -i)
        break

Measured memory_bytes: 69724
//#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------



int main(){
  int n,m,x,countR=0,countL=0;
  cin>>n>>m>>x;
  int a[m];
  REP(i,m) cin>>a[i];
  REP(i,m){
    if(x>a[i]){
      ++countL;
    }else{
      ++countR;
    }
  }
  cout<<min(countL,countR);
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int k = sc.nextInt();
      Queue<String> queue = new LinkedList<>();
      for(long i = 1; i <= 9; i++)
        queue.offer(String.valueOf(i));

      while(k > 1) {
        String num = queue.poll();
        k--;
        int lastDigit = num.charAt(num.length()-1) - '0';
        for(int i = 1; i >= -1; i--) {
          int newDigit = lastDigit - i;
          if(newDigit < 0 || newDigit > 9) continue;
          queue.offer(num + String.valueOf(newDigit));
        }
      }
      System.out.println(queue.peek());
  }
}

Measured memory_bytes: 63908
#include <iostream>
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
using ll = long long;

const int MAX_N=200005;
const int INF = 1001001001;

int n;
vector<int> a,ans;
vector<int> to[MAX_N];
int dp[MAX_N];

void dfs(int v,int p=-1){
    int i = lower_bound(dp,dp+MAX_N,a[v]) - dp;
    int old = dp[i];
    dp[i] = a[v];
    ans[v] = i;
    if(p != -1) ans[v] = max(ans[v],ans[p]);
    for(int u :to[v]){
        if(u == p) continue;
        dfs(u,v);
    }
    dp[i] = old;
}

int main(){
    cin >> n;
    a = ans = vector<int>(n);
    int u,v;
    rep(i,n) cin >> a[i];
    rep(i,n-1){
        cin >> u >> v;
        u--; v--;
        to[u].push_back(v);
        to[v].push_back(u);
    }
    rep(i,MAX_N) dp[i]=INF;
    dp[0] = -INF;
    dfs(0);

    rep(i,n){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 30848
#include<iostream>
#include<vector>

using namespace std;

int main(){
  int h,n,ans=0;
  cin >> h >> n;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    ans += a;
  }
  if(ans >= h){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>  // std::sort, std::unique
using namespace std; 

int main() {
    int n,m,l;
    int i,j,k;
    long long tmp;
    cin >> n >> m >> l;
    vector<vector<int>> a(n,vector<int>(m));
    vector<vector<int>> b(m,vector<int>(l));
    for ( i = 0; i < n; i++)
    {
        for ( j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
        
    }
    for ( i = 0; i < m; i++)
    {
        for ( j = 0; j < l; j++)
        {
            cin >> b[i][j];
        }
        
    }
    
    for ( i = 0; i < n; i++)
    {
        for ( j = 0; j < l; j++)
        {
            tmp = 0;
            for ( k = 0; k < m; k++)
            {
                tmp += a[i][k]*b[k][j];
            }
            cout << tmp;
            if(j < l-1) cout << " ";
        } 
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3180
MOD = 998244353
k, n = map(int, input().split())

list_size = 5000

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

def power(n, x):
	if x == 1:
		return n
	elif x % 2 == 0:
		return power(int((n * n) % MOD), int(x / 2))
	else:
		return int((n * power(n, x - 1)) % MOD)

f_r_list[-1] = power(f_list[-1], MOD - 2)

for i in range(2, list_size + 1):
	f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD)

def comb(n, r):
	if n < r or r < 0:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

ans = []
for i in range(2, k+2):
	num = 0
	if i%2 == 1:
		for j in range(0, i//2+1):
			num += comb(i//2, j) * pow(2, j, MOD) * comb(n+k-i, k-i+j)
			num %= MOD
	else:
		for j in range(0, i//2):
			num += comb(i//2-1, j) * pow(2, j, MOD) * comb(n+k-i, k-i+j)
			num += comb(i//2-1, j) * pow(2, j, MOD) * comb(n+k-i-1, k-i+j)
			num %= MOD
	ans.append(num)

print(*ans, sep="\n")
ans = reversed(ans[:k-1])
print(*ans, sep="\n")

Measured memory_bytes: 57836
var line, i_zero, i, j, util;

line = require('fs').readFileSync('/dev/stdin', 'ascii').split("\n");
i_zero = line.lastIndexOf('0');
line = line.slice(0, i_zero);
util = require('util');
j = 1;
for (i in line) {
	line[i] = util.format("Case %d: %s", j, line[i]);
	j++;
}
console.log(line.join("\n").trim());

Measured memory_bytes: 20736
module Main where

import Control.Applicative
import Control.Monad
import Data.List

f :: [[Int]] -> [[Int]] -> [Int] -> Int
f fss pss as = sum $ zipWith3 g fss pss (repeat as)
  where
    g fs ps xs = ps !! (sum $ zipWith (*) fs xs)

main :: IO ()
main = do
    n <- readLn
    fss <- replicateM n $ fmap read . words <$> getLine :: IO [[Int]]
    pss <- replicateM n $ fmap read . words <$> getLine :: IO [[Int]]
    let ass = tail $ sequence $ replicate 10 [0, 1]
    let ans = maximum $ fmap (f fss pss) ass
    print ans

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int res = -1;
    for (int i = 0; i < 10000; i++) {
        int to = 60 * i + c;
        if (to % (a + b) <= a) {
            res = to;
            break;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>

int n, t;

int a[200004];

int main() {
	scanf("%d%d", &n, &t);
	int lastTime = -1;
	int totalTime = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++) {
		if (a[i] >= lastTime) {
			lastTime = a[i] + t;
			totalTime += t;
		}
		else {
			totalTime += (t - (lastTime - a[i]));
			lastTime = (a[i] + t);
		}
	}
	printf("%d\n", totalTime);
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
 
int main()
{
    int hotel[4][3][10],i,j,k,test,b,f,r,v;
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                hotel[i][j][k]=0;
            }
        }
    }
    scanf("%d",&test);
    for(i=0;i<test;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        hotel[b-1][f-1][r-1]+=v;
    }
    for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf(" %d",hotel[0][j][k]);
            }
            printf("\n");
        }
    for(i=1;i<4;i++){
        printf("####################\n");
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf(" %d",hotel[i][j][k]);
            }
            printf("\n");
        }
    }
    return 0;
}


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

int main(){
int k ,a ,b;
cin >> k >> a >> b;
bool can=false;
rep(i,1000){
    if(a<=k*(i+1) && k*(i+1)<=b) can=true;
}
if(can) cout << "OK" << endl;
else cout << "NG" << endl;

}

Measured memory_bytes: 3636
/*
 	hunati






 */

#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string 
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e9 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}

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

vector<pii> vii;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
cout << (a+b)*c/2<< endl;
    return 0;
}


Measured memory_bytes: 256
n, m, k = [int(x) for x in input().split()]
li = [[int(x) for x in input().split()] for _ in range(n)]
prices = []
for bit in range(1, 2 ** n):
    index_list = []
    for i in range(n):
        if bit & 1 << i:
            index_list.append(i)
    c = 0
    for t in range(1, m + 1)        :
        s = 0
        for i in index_list:
            s += li[i][t]
        if s >= k:
            c += 1
        else:
            break
    if c == m:
        p = 0
        for i in index_list:
            p += li[i][0]
        prices.append(p)
if prices:
    print(min(prices))
else:
    print(-1)


Measured memory_bytes: 9220
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(a+b,min(b+c,c+a))<<endl;
	return 0;
}

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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1e8;

void Main() {
  int n, m;
  cin >> n >> m;
  int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  vector<int> A(m);
  rep(i, m) cin >> A[i];
  sort(A.begin(), A.end(), greater<int>());
  vector<int> dp(n+1, -INF);
  dp[0] = 0;
  REP(i, 1, n+1) {
    for(int a : A) {
      if (i-num[a] >= 0) dp[i] = max(dp[i], dp[i-num[a]] + 1);
    }
  }
  int nn = dp[n];
  rep(i, nn) {
    for(int a : A) {
      if (n-num[a] < 0) continue;
      if (dp[n] - dp[n-num[a]] == 1) {
        n -= num[a];
        cout << a;
        break;
      }
    }
  }
  cout << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
x, k, d = [int(w) for w in input().split()]
x = abs(x)

t = x//d

ans = 0
if k <= t:
    ans = x-k*d
else:
    ans = x-d*t
    k -= t
    if k % 2 == 1:
        ans -= d

print(abs(ans))


Measured memory_bytes: 9172
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll w,h,x,y;
    cin >> w >> h >> x >> y;
    double ans = w*h/2.0;
    cout << ans << " ";
    //if(w%2==0&&h%2==0&&w/2==x&&h/2==y)cout << 1 << endl;
    if(x*2==w&&y*2==h)cout << 1 << endl;
    else cout << 0 << endl;    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int tops = 700;
	string str;
	cin >> str;
	if(str[0] == 'o') tops += 100;
	if(str[1] == 'o') tops += 100;
	if(str[2] == 'o') tops += 100;

	cout << tops <<	endl;
}


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

using namespace std;
const int N = 1e5 + 3;
int parent[N], rnk[N], sz[N];
void init() {
	memset(rnk, 0, sizeof rnk);
	for (int i = 0; i < N; ++i) {
		parent[i] = i;
		sz[i] = 1;
	}
}
int root(int node) {
	if (parent[node] == node)
		return node;
	return parent[node] = root(parent[node]);
}
bool join(int u, int v) {
	u = root(u);
	v = root(v);
	if (u == v)
		return false;
	if (rnk[u] < rnk[v])
		swap(u, v);
	rnk[u] += rnk[u] == rnk[v];
	sz[u] += sz[v];
	parent[v] = u;
	return true;
}
int main() {
//	freopen("input.in", "r", stdin);
	int n, m;
	scanf("%d %d", &n, &m);
	init();
	int c = n;
	while (m--) {
		int u, v, z;
		scanf("%d %d %d", &u, &v, &z);
		if (join(u, v))
			--c;
	}
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 1408
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

inline double sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
// }}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<vector<int> > dp(n,vector<int>(3));
	rep(i,n){
		int a,b,c;
		cin >> a >> b >> c;
		if(i == 0){
			dp[0][0] = a;
			dp[0][1] = b;
			dp[0][2] = c;
		}
		else{
			dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a;
			dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b;
			dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c;
		}
	}
	cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) << '\n';
	return 0;	
}


Measured memory_bytes: 5760
#include <cstdio>
using namespace std;
double arr[1010];
int main() {
    int n;
    double m;
    scanf("%d %lf", &n, &m);
    double sum = 0;
    for(int i = 0; i < n; i ++) {
        scanf("%lf", &arr[i]);
        sum += arr[i];
    }
    int num = 0;
    for(int i = 0; i < n; i ++) {
        if(arr[i] >= sum / 4 / m) {
            num ++;
        }
    }
    if(num >= m) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << endl
#else
const bool test = false;
#define dump(x) 
#endif

#else
const bool test = false;
#define dump(x) 
#endif

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}

void solve();

class Solver {
public:
    int N;
    void solve() {
        cin >> N;
        rep(i, 30) {
            if (1 << (i + 1) > N) {
                cout << (1 << i) << endl;
                return;
            } 
        }
    }
};

signed main()
{
    cout << fixed << setprecision(20);
    auto ptr = new Solver();
    ptr->solve();
    delete ptr;
    // while (true) {    
    //     auto ptr = new Solver();
    //     ptr->solve();
    //     delete ptr;
    // }
    return 0;
}

// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'




Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == n) return cout << "Yes", 0;
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printaa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ for(int j = 0; j < (sizeof(x[0])/sizeof(x[0][0])); j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R;
    cin >> R;
    if(R < 1200){
        print("ABC");
    }else if(R < 2800){
        print("ARC");
    }else{
        print("AGC");
    }
}


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

char f(char c){
    if( c == '(' )
        c = ')';
    else if( c == ')' )
        c = '(';
    else if( c == '{' )
        c = '}';
    else if( c == '}' )
        c = '{';
    else if( c == '[' )
        c = ']';
    else if( c == ']' )
        c = '[';
    return c;
}

inline int first(int n){
    return ((1 << n) - 1);
}
inline int nextSet(int x){
    int small, ripple, newSmall,ones;
    small = x & -x;
    ripple = x + small;
    newSmall = ripple & -ripple;
    ones = (( newSmall / small ) >> 1) - 1;
    return (ripple | ones);
}

string setComb(int s, int n){
    string c;
    for(int i=0 ; i<n ; i++){
        if( s & 1 ) c.push_back( str[i] );
        s >>= 1;
    }
    return c;
}

int main(){
    int n, k, x, size, ans = 0;
    string c;
    cin >> str;
    size = str.size();
    n = size;
    for(int i_=1 ; i_ <= size ; ++i_ ){
        k = i_;
        x = first(k);
        while( !(x & ~first(n) ) ){
            c = setComb( x , n );
            bool flag = true;
            if( c.find("iwi") != string::npos && count( c.begin() , c.end() , 'i' ) == 2 && 
                count( c.begin() , c.end() , 'w' ) == 1 ){
                
                for(unsigned int j=0 ; j < c.size()/2 ; ++j ){
                    if( c[j] != f(c[c.size()-j-1]) ){
                        flag = false;
                    }
                }
            }else{
                flag = false;
            }
            if( flag ){
               ans = max( ans , (int) c.size() );
            }
            x = nextSet( x );
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 0
import java.util.*;
     
    public class Main {
     
        static List<ban> bans;
     
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            int C = scan.nextInt();
            bans = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                bans.add(new ban(scan.nextInt() * 2,scan.nextInt() * 2,scan.nextInt()));
            }
            bans.sort(Comparator.comparingInt(x -> x.s));
     
            for (int i = 1; i <= C; i++) {
                boolean success = func(i);
                if (success) {
                    System.out.println(i);
                    return;
                }
            }
        }
     
        private static boolean func(int num) {
            List<tv> tvs = new ArrayList<>();
            for (int i = 0; i < num; i++) {
                tvs.add(new tv(-1, -1));
            }
            for (int i = 0; i < bans.size(); i++) {
                int now = bans.get(i).s;
                int can = bans.get(i).c;
                Optional<tv> tmp = tvs.stream().filter(x -> x.c == -1 || (x.c == can && x.t <= now) || x.t <= now - 1).findAny();
                if(tmp.isPresent()) {
                    tv temp = tmp.get();
                    temp.t = bans.get(i).t;
                    temp.c = can;
                }
                else {
                    return false;
                }
            }
            return true;
        }
     
        static class tv{
            int t;
            int c;
            public tv(int t, int c) {
                this.t = t;
                this.c = c;
            }
        }
     
        static class ban{
            int s;
            int t;
            int c;
            ban(int s, int t, int c) {
                this.s = s;
                this.t = t;
                this.c = c;
            }
        }
    }

Measured memory_bytes: 99132
#include <iostream>
using namespace std;
int main(){
    long long l,r;
    cin >> l >> r;
    int ans = 3000;
    for(long long i = l; i < l+2019 && i < r; i++){
        for(long long j = i+1; j < l+2020 && j <=r; j++){
            int x = (i*j)%2019;
            ans = min(ans, x);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))
S = list()
for i in range(D):
    tmp_ = list(map(int, input().split()))
    S.append(tmp_)
T = list()
for i in range(D):
    T.append(int(input()))
ret = 0
lastd = [0] * 26
for i in range(D):
    ret += S[i][T[i]-1]
    lastd[T[i] - 1] = i + 1
    for j in range(26):
        ret -= C[j] * (i + 1 - lastd[j])
    print(ret)

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

int main() {
    string x;
    
    while(1) {
        cin >> x;
        if (x == "0") break;
        int sum = 0;
        for (int i=0; i<x.length(); i++) {
            sum += (int)(x[i] - '0');
        }
        cout << sum << endl;
    }
	return 0;
}

Measured memory_bytes: 3108
"use strict";
// inputに入力データ全体が入る
const main = (input) => {
  const [a, b] = input.trim().split(" ").map(Number);
  if (a === b) {
    return "Draw";
  } else if (b === 1) {
    return "Bob";
  } else if (a === 1) {
    return "Alice";
  } else if (a < b) {
    return "Bob";
  } else {
    return "Alice";
  }
};

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
console.log(main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 29508
module WeightedDirectedGraph
  (Weight : sig
    type t
    val inf : t (* オーバーフローの恐れはないので，max_intとか突っ込んでも良い *)
    val zero : t
    val neg_inf : t (* オーバーフローの恐れはないので，min_intとか突っ込んでも良い *)
    val ( + ) : t -> t -> t
    val compare : t -> t -> int
  end) :
sig
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  val bellman_ford :
    (* 頂点数n *)
    int ->
    (* 辺のリスト
       頂点は0からn-1までの整数でなくてはならない *)
    (int * int * Weight.t) church_list ->
    (* 始点 *)
    int ->
    (* 頂点を受け取り，そこまでの距離を返す関数
       頂点に到達するパスが無ければinfを返し，
       そこに到達するまでに負閉路があればneg_infを返す *)
    (int -> Weight.t)
end =
struct
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  let bellman_ford n es s =
    (* 距離を覚えるやつ *)
    let d = Array.make n Weight.inf in
    (* 経路に負閉路が含まれる頂点を覚えるやつ *)
    let neg = Array.make n false in
    (* 始点より終点のインデックスが大きくなる辺を集めた隣接リスト *)
    let inc = Array.make n [] in
    (* 始点より終点のインデックスが小さくなる辺を集めた隣接リスト *)
    let dec = Array.make n [] in
    es.fold (fun ((u, v, c) as e) () ->
      if u <= v
      then inc.(u) <- e :: inc.(u)
      else dec.(u) <- e :: dec.(u)) ();
    d.(s) <- Weight.zero;
    (* 残りの反復回数 *)
    let i = ref n in
    (* 更新が行われたか *)
    let is_modified = ref true in
    (* 各辺の処理 *)
    let f (u, v, c) = 
      let open Weight in
      if neg.(u) && not neg.(v) then (neg.(v) <- true; is_modified := true);
      if
        (* 原点から到達できない頂点は更新しない *)
        0 < Weight.compare inf d.(u)
        (* c は u から v への辺の重さ
           d.(u) + c < d.(v) *)
        && 0 < Weight.compare d.(v) (d.(u) + c)
      then begin
        d.(v) <- d.(u) + c;
        is_modified := true;
        if !i <= succ n lsr 1 then neg.(v) <- true
      end in
    while 0 < !i && !is_modified do
      is_modified := false;
      (* インデックスが増加する辺の処理 *)
      for u = 0 to n - 1 do
        List.iter f inc.(u)
      done;
      (* インデックスが減少する辺の処理 *)
      for u = n - 1 downto 0 do
        List.iter f dec.(u)
      done;
      decr i
    done;
    fun v -> if neg.(v) then Weight.neg_inf else d.(v)
end

module G = WeightedDirectedGraph (struct
  type t = int
  let zero = 0
  let inf = min_int
  let neg_inf = max_int
  let ( + ) = ( + )
  let compare x y = compare y x
end)

let () = Scanf.scanf "%d %d %d\n" @@ fun n m p ->
  let abc = Array.init m @@ fun _ ->
    Scanf.scanf "%d %d %d\n" @@ fun a b c -> a - 1, b - 1, c - p in
  let d = G.bellman_ford n { G.fold = fun f -> Array.fold_right f abc } 0 (n - 1) in
  if max_int <= d
  then print_endline "-1"
  else Printf.printf "%d\n" @@ max 0 d


Measured memory_bytes: 4864
#include <iostream>
typedef long long ll;
using namespace std;

int main()
{
    ll n,x,m,sum=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>x;
        sum+=x;
    }
    if(sum>n)
        cout<<-1;
    else
        cout<<n-sum;
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;
#define  st first
#define  nd second
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define int long long

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef cc_hash_table<int, int, hash<int > > ht;

#define maxn 1000000
#define M   1000000007


int32_t main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int k , x ;
  cin >> k >> x ;
  if(k*500 >= x)
    cout << "Yes" << "\n" ;
  else
    cout << "No" ;
  return 0 ;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< string > S(N);
	rep(i, N) cin >> S[i];
	vector< pii > A, B;
	rep(i, N) {
		int m = 0, l = 0;
		rep(j, S[i].size()) {
			if (S[i][j] == '(') {
				l++;
			} else {
				l--;
				chmin(m, l);
			}
		}
		if (l > 0) {
			A.emplace_back(m, l);
		} else {
			B.emplace_back(m - l, -l);
		}
	}
	int a = 0, b = 0;
	sort(A.rbegin(), A.rend());
	sort(B.rbegin(), B.rend());
	rep(i, A.size()) {
		if (a + A[i].first < 0) {
			cout << "No" << endl;
			return 0;
		} else {
			a += A[i].second;
		}
	}
	rep(i, B.size()) {
		if (b + B[i].first < 0) {
			cout << "No" << endl;
			return 0;
		} else {
			b += B[i].second;
		}
	}
	if (a == b) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 50284
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin >> N;
  int sqrtN=sqrt(N);
  
  int A=1;
  
  for(int i=1; i<sqrtN+1; i++){
    if(N%i==0){
      A=i;
    }
  }
  
  int B=N/A;
  
  
  cout << to_string(B).length() << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    ArrayList<Integer> d = new ArrayList<Integer>(n);
    for (int i = 0; i < n; i++) {
      d.add(sc.nextInt());
    }
    
    int c = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i+1; j < n; j++) {
        c += d.get(i) * d.get(j);
      }
    }
    System.out.println(c);
  }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int a[N][2];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1];
	}
	for(int i=0;i<n-2;i++){
		int s=0;
		for(int j=i;j<=i+2;j++){
			if(a[j][0]==a[j][1]) s++;
		}
		if(s==3) return puts("Yes"),0;
	}
	puts("No"); 
	return 0;
}

Measured memory_bytes: 3668
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	int p[n];
	for (int i = 0; i<n; i++) scanf("%d", &p[i]);
	int c = 0;
	for (int i = 1; i < n-1; i++) {
		if (p[i] < p[i-1] && p[i] > p[i+1]) c++;
		if (p[i] > p[i-1] && p[i] < p[i+1]) c++;
	} 
	printf("%d\n", c);
	return 0;
}
	


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; -i)
#define INF (1 << 30)

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

int main() {
	ll n;
	ll m[10000];
	ll min = INF, max = -INF, total = 0;
	cin >> n;
	rep(i, n) {
		cin >> m[i];
		min = (min > m[i]) ? m[i] : min;
		max = (max < m[i]) ? m[i] : max;
		total += m[i];
	}
	cout << min << " " << max << " " << total << endl;
	return 0;
}

Measured memory_bytes: 3156
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

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

int main(){
    ll n,h,w;
    cin >> n >> h >> w;
    cout << (n-h+1)*(n-w+1) << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


signed main() {
  int n,a,b,c;cin>>n>>a>>b>>c;int l[8];rep(i,n)cin>>l[i];
  int ans = INF;
  rep(i,1<<n){
    vector<int> aa,ua;int suma = 0;
    rep(j,n){
      if(i & 1<<j){
        aa.push_back(l[j]);
        suma += l[j];
      }
      else ua.push_back(l[j]);
    }
    if(aa.size() == 0 || ua.size() == 0)continue;
    rep(k,1<<ua.size()){
      vector<int> bb,ub;int sumb = 0;
      rep(j,ua.size()){
        if(k & 1<<j){
          bb.push_back(ua[j]);
          sumb += ua[j];
        }
        else ub.push_back(ua[j]);
      }
      if(bb.size() == 0 || ub.size() == 0)continue;
      rep(ll,1<<ub.size()){
        vector<int> cc;int sumc = 0;
        rep(j,ub.size()){
          if(ll & 1<<j){
            cc.push_back(j);
            sumc += ub[j];
          }
        }
        if(cc.size() == 0)continue;
        int mp = 0;
        mp += (aa.size() - 1) * 10;
        mp += (bb.size() - 1) * 10;
        mp += (cc.size() - 1) * 10;
        mp += (abs(a-suma) + abs(b-sumb) + abs(c-sumc));
        ans = min(ans, mp);
      }
    }
  }
  cout << endl;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <algorithm>
#include <utility>

using namespace std;

vector< vector<int> > map(100,vector<int>(100,0));
int n,m;

bool check(int x,vector<bool> &used){

    used[x] = true;
    bool flg = true;
    for(int i=0;i<used.size();i++){
	if(!used[i]) flg = false;
    }
    if(flg) return true;

    bool res = false;
    for(int i=0;i<n;i++){
	if(map[x][i] > 0  && !used[i]){
	    res |= check(i,used);
	}
    }

    return res;

}

int main(){

    while(true){
	map = vector< vector<int> >(100,vector<int>(100,0));
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    vector<int> a(m);
    vector<int> b(m);
    vector<int> cost(m);
    vector< pair <  pair<int,int> , pair<int,int> > >  q(m);
    long long int sum = 0;
    for(int i=0;i<m;i++){
	cin >> a[i] >> b[i] >> cost[i];
	sum += cost[i];
	q[i] = pair< pair<int,int>, pair<int,int> >(pair<int,int>(cost[i],a[i]), pair<int,int>(b[i],i));
	map[a[i]][b[i]] = cost[i];
	map[b[i]][a[i]] = cost[i];
    }
    sort(q.rbegin(),q.rend());
    for(int i=0;i<m;i++){
	int x = q[i].first.second ;
	int y = q[i].second.first ;
	int temp = map[x][y];
	map[x][y]  = 0;
	map[y][x]  = 0;
	vector<bool> used1(n,false);
	vector<bool> used2(n,false);
	if(check(x,used1) && check(y,used2)){
	    sum -= temp;
	}else{
	    map[x][y]  = temp;
	    map[y][x]  = temp;
	}
    }
    cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 1308