akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int sx=sc.nextInt();
        int sy=sc.nextInt();
        int tx=sc.nextInt();
        int ty=sc.nextInt();
        int x=tx-sx;
        int y=ty-sy;
        for(int i=0;i<y;i++){
            System.out.print("U");
        }
        for(int i=0;i<x;i++){
            System.out.print("R");
        }
        for(int i=0;i<y;i++){
            System.out.print("D");
        }
        for(int i=0;i<=x;i++){
            System.out.print("L");
        }
        for(int i=0;i<=y;i++){
            System.out.print("U");
        }
        for(int i=0;i<=x;i++){
            System.out.print("R");
        }
        for(int i=0;i<=y;i++){
            System.out.print("D");
            if(i==0){
                System.out.print("R");
                System.out.print("D");
            }
        }
        for(int i=0;i<=x;i++){
            System.out.print("L");
        }
        System.out.print("U");
    }
}


Measured memory_bytes: 24516
#include <iostream>
#include <map>

using namespace std;

int main() {
    int n, mxv = 0;
    string s;
    map<string, int> m;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        m[s] += 1;
    }
    for (auto &p:m) if (p.second > mxv) mxv = p.second;
    for (auto it = m.begin(); it != m.end(); it++)if (it->second == mxv)cout << it->first << endl;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
 
#define mod 1000000000
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vs vector<string>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define vsi vector<psi>
#define vii vector<pii>
#define mp make_pair
#define pb push_back
#define rep(n) for(long i=0;i<n;i++)
#define repr(n) for(long i=(n-1);i>=0;i--)
#define fori(i,a,b) for(auto i=a;i<=b;i++)
#define ford(i,b,a) for(auto i=b;i>=a;i--)
#define mset(a,i) memset(a,i,sizeof(a))
#define minv(a) min_element(a.begin(),a.end())
#define maxv(a) max_element(a.begin(),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sotit(a) sort(a.begin(),a.end());
#define sot(a) sort(a,a+n);
#define ff first
#define maxheap(v) priority_queue<v>
#define minheap(v) priority_queue<v, vector<v>, greater<v>>
#define ss second
#define endl "\n"
#define NL cout<<endl;
#define printmat(a,m,n) for(int i=0;i<m;i++){       \
                            for(int j=0;j<n;j++){   \
                                cout<<a[i][j]<<" "; \
                            }                       \
                            cout<<endl;             \
                        }
#define dbgn(x) cout<<" $ "<<x<<" $ "<<endl;
#define dbg(x) cout<<" $ "<<x<<" $ ";
#define all(v) v.begin(),v.end()
#define show(a,n) for(int i=0;i<n;i++){ cout<<a[i]<<" "; } NL
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);cin.tie(NULL);
 
// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val

ll a[300000],b[300000];

bool check(ll mid, ll n, ll k){
    rep(n){
        k-=(a[i]-min(a[i],mid/b[n-i-1]));
        if(k<0){
            return 0;
        }
    }
    return 1;
}


int main() {
    fast_io()
    ll n,k;
    cin>>n>>k;
    rep(n){
        cin>>a[i];
    }
    rep(n){
        cin>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    ll s=0,e=1e13,mid,ans;
    while(s<=e){
        mid = (s+e)/2;
        if(check(mid, n, k)){
            ans=mid;
            e=mid-1;
        }
        else{
            s=mid+1;
        }
    }
    NL
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3840
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
			int n = sc.nextInt();
			int m = sc.nextInt();
			
			calc(n, m);
	}
	double[][] nums ;
	public void calc(int n, int m){
		ArrayList<double[]> list = new ArrayList<double[]>();
		nums = new double[n][n];
		for(int i = 0; i < n; i++){
			double l = sc.nextDouble();
			double a = sc.nextDouble();
			double b = sc.nextDouble();
			list.add(new double[]{l,a,b});
		}
		
		for(int i = 0; i < n; i++){
			for(int j = i+1; j < n; j++){
				double[] item1 = list.get(i);
				double[] item2 = list.get(j);
				nums[i][j] = (item1[0] - item2[0]) * (item1[0] - item2[0]) + 
						(item1[1] - item2[1]) * (item1[1] - item2[1]) + 
						(item1[2] - item2[2]) * (item1[2] - item2[2]);
				nums[j][i] = nums[i][j];
			}
		}
		
		
		
		maxcal(0, new int[m], m, n, 0);
		System.out.println(sum);
	}
	double sum = 0;

	public void maxcal(int k, int[] t , int m, int n, int count){
		if(count == m){
			double s = 0;
			for(int i = 0; i < m; i++){
				for(int j = i+1; j < m; j++){
					s += nums[t[i]][t[j]];
				}
			}
			if(s > sum) sum = s;
		}
		else{
			for(int i = k; i < n; i++){
				t[count] = i;
				maxcal(i+1, t, m,n,  count+1);
			}
		}
	}
	public ArrayList<Double> mergeSort(ArrayList<Double> list){
		if(list.size() > 1){
			int n = list.size() / 2;
			int m = list.size() - n;
			ArrayList<Double> a1 = new ArrayList<Double>();
			ArrayList<Double> a2 = new ArrayList<Double>();
			for(int i = 0; i < n; i++) a1.add(list.get(i));
			for(int j = 0; j < m; j++) a2.add(list.get(j + n));
			a1 = mergeSort(a1);
			a2 = mergeSort(a2);
			return merge(a1, a2);
		}
		else return list;
	}

	
	public ArrayList<Double> merge(ArrayList<Double> a1, ArrayList<Double> a2){
		int i = 0;
		int j = 0;
		ArrayList<Double> a = new ArrayList<Double>();	
		while(i < a1.size() || j < a2.size()){
			if(j >= a2.size() || (i < a1.size() && a1.get(i) < a2.get(j))){
				a.add(a1.get(i));
				i++;
			}
			else{
				a.add(a2.get(j));
				j++;
			}
		}
		return a;
	}

	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 20968
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
#ifndef __VEC2D_INCLUDED_
#define __VEC2D_INCLUDED_
template <typename T>
struct vec2D {
    T x, y;
    vec2D(T x, T y) : x(x), y(y) {}
    bool operator==(const vec2D& v) const { return x == v.x and y == v.yl; }
    bool operator!=(const vec2D& v) const { return not (*this == v); }
    bool operator< (const vec2D& v) const { return x < v.x or (x == v.x and y < v.y); }
    bool operator<=(const vec2D& v) const { return *this < v or *this == v; }
    bool operator> (const vec2D& v) const { return not (*this <= v); }
    bool operator>=(const vec2D& v) const { return *this > v or *this == v; }
    vec2D operator*(const T c) const { return {c * x, c * y}; }
    vec2D operator/(const T c) const { return {x / c, y / c}; }
    vec2D operator+(const vec2D& v) const { return {x + v.x, y + v.y}; }
    vec2D operator-() const { return {-x, -y}; }
    vec2D operator-(const vec2D& v) const { return *this + -v; }
    T operator*(const vec2D& v) const { return x * v.y - y * v.x; } // cross product
    T operator^(const vec2D& v) const { return x * v.x + y * v.y; } // dot product
    vec2D& operator=(const vec2D& v) { x = v.x, y = v.y; return *this; }
    vec2D& operator*=(const T c) { return *this = *this * c; }
    vec2D& operator/=(const T c) { return *this = *this / c; }
    vec2D& operator+=(const vec2D& v) { return *this = *this + v; }
    vec2D& operator-=(const vec2D& v) { return *this = *this - v; }
    T squared_norm() { return *this ^ *this; }
    double norm() { return sqrt(squared_norm()); }
    vec2D normalized() { return *this / norm(); }
    double scalar_project(const vec2D& v) {
        return *this ^ v / v.norm();
    }
    vec2D vector_project(const vec2D& v) {
        return (*this ^ v) / (v ^ v) * v;
    }
    vec2D rotate(T theta) {
        return {cos(theta) * x - sin(theta) * y, sin(theta) * x + cos(theta) * y};
    }
};
template <typename T>
vec2D<T> operator*(const T c, const vec2D<T>& v) { return {c * v.x, c * v.y}; }
template <typename T>
ostream& operator<<(ostream& os, const vec2D<T>& v) { return os << "(" << v.x << ", " << v.y << ")"; }
template <typename T>
istream& operator>>(istream& is, vec2D<T>& v) { return is >> v.x >> v.y; }
#endif
const double pi = acos(-1);
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    auto hour = vec2D<double>(0, a).rotate(2 * pi * (h * 60 + m) / (12 * 60));
    auto minu = vec2D<double>(0, b).rotate(2 * pi * m / 60);
    cout << fixed << setprecision(9) << (hour - minu).norm() << endl;
    return 0;
}

Measured memory_bytes: 4176
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;


namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();
            var A = cin.nextInt();
            var B = cin.nextInt();

            var sa = Math.Abs(A - B);

            

            if(sa % 2 != 0)
            {
                Console.WriteLine("IMPOSSIBLE");
                return;
            }
            var ans2 = sa/2 + Math.Min(A, B);


            Console.WriteLine(ans2);
        }
    }





    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace  std;
typedef long long ll;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll x;
    cin>>x;
    if(x==1)    cout<<0;
    else{
        cout<<1;
    }
    return 0;
}


Measured memory_bytes: 3604
import math

def func(h, a, b, count):
  ans = 0
  for v in h:
    if v > b * count:
      ans += math.ceil((v-b*count) / (a-b))
      
  return ans <= count

n,a,b = map(int, input().split())
h = []

for i in range(n):
  # heapqを最大値を取り出すように使いたいのでマイナスにする
  h.append(int(input()))

start = 1
end = math.ceil(max(h) / b)
middle = (end + start) // 2

# 二分探索する、終了条件はぶっちゃけわからん
while True:
  if(func(h,a,b,middle)):
    end = middle
  else:
    start = middle
    
  middle = (end + start) // 2
  if (end - start) <= 1:
    break
    
print(end)

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

int main() {
    int N;
    cin >> N;
    
    vector<long long> A(N);
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    
    vector<long long> Acnt(N+1,0);
    
    for(auto x: A){
        Acnt.at(x)++;
    }

    long long s=0;
    for (int i = 1; i < N+1; i++){
        if(Acnt.at(i)!=0){
            s=s+Acnt.at(i)*(Acnt.at(i)-1)/2;
        }
    }

    for (auto Ak: A){
        long long ans=s-Acnt.at(Ak)+1;
        printf("%lld\n",ans);
    }
    
    
}

Measured memory_bytes: 6408
#include <iostream>
#define maxn 50005
long long p_lst[maxn];
long long mu[maxn];
bool vis[maxn];
long long pre[maxn];
int p_cnt;

inline void init() {
    mu[1] = 1;
    for (long long i = 2; i <= maxn; i++) {
        if (!vis[i]) (mu[i] = -1),p_lst[++p_cnt] = i;
        for (int j = 1; j <= p_cnt && p_lst[j] * i < maxn; j++) {
            vis[i * p_lst[j]] = true;
            if (i % p_lst[j] == 0) {
                mu[i * p_lst[j]] = 0;
                break;
            } else {
                mu[i * p_lst[j]] = -1 * mu[i];
            }
        }
    }
    for (long long i = 1; i <= maxn; i++) pre[i] = pre[i - 1] + mu[i];
}

int vvis[1005];
int fcnt(int x){
    for(int i = 1; p_lst[i] <=x ; ++ i){
        while (x % p_lst[i] == 0) {
            vvis[p_lst[i]]++;
            x = x / p_lst[i];
        } 
    }
}

int main(){
    int n;
    long long res = 1;
    std::cin >> n;
    init();
    for(int i = 1; i <= n; i ++){
       fcnt(i);
    }
    for(int i = 1; p_lst[i] <= n; i ++){
     //   std::cout << vvis[p_lst[i]] << std::endl;
        res = (res * ((vvis[p_lst[i]]) + 1)) % 1000000007;
    }
    std::cout << res;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define REP1(i,n) for(long long i=1;i<=(n);i++)
#define REP2D(i,j,h,w) for(long long i=0;i<(h);i++) for(long long j=0;j<(w);j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=(h);i++) for(long long j=1;j<=(w);j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) ((a).begin()),((a).end())
#define RANGE(a) (a),((a)+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define ENTER printf("\n")
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<(a)<<endl

#ifdef DEBUG
#define DBPRT(a) cout << "[Debug] - " << #a << " : " << (a) << endl
#define DBSTART if(1){
#define DBEND }
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
#else
#define DBPRT(a) if(0){}
#define DBSTART if(0){
#define DBEND }
#define PRTLST(arr,num) if(0){}
#define PRTLST2(arr2,d1,d2) if(0){}
#define PRTLST2D(arr2,d1,d2) if(0){}
#endif

#define TOSUM(arr,sum,n) {sum[0]=arr[0];REP1(i,n-1) sum[i]=sum[i-1]+arr[i];}

#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 100000
//---------------------

string s;

int main(){
	cin >> s;
	if(s=="AAA" || s == "BBB") PRT("No");
	else PRT("Yes");
	return 0;
}









Measured memory_bytes: 256
// ABC 083 A- Libra

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

int main() {
  int A, B, C, D;

  cin >> A >> B >> C >> D;
  if (A+B > C+D) {
    cout << "Left" << endl;
  }
  else if (A+B < C+D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 3564
"use strict";
function main(input) {
    var line = input.split("\n");
    let K = parseInt(line[0]);
    let line2 = line[1].split(" ");
    let A = parseInt(line2[0]);
    let B = parseInt(line2[1]);
    for(let i=A; i<=B; ++i){
        if(i%K == 0){console.log("OK"); return; };
    }
    console.log("NG");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define rep(i, a, b) for(long long int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define mod 1000000007
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
void solution(){
    int n,m;cin>>m>>n;
    long long int sum=0;
    rep(i,n,m+2){
    ll y= (i*(m + 1 -i))%mod +1;
    sum =(sum%mod + y%mod)%mod;
    }
    cout<<sum%mod<<endl;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	solution();
	return 0;
}

Measured memory_bytes: 3664
#include<stdio.h>
#include<math.h>
int main()
{
    long int N,a=0,i,j,sum3=0,sum2=0,c=0;
    scanf("%ld",&N);
    long int num[N];
    for(i=0;i<N;i++)
    {
        scanf("%ld",&num[i]);
    }
            for(i=0;i<N;i++)
    {if(num[i]>3)
   {

       for(j=2;j<=sqrt(num[i]);j++){
    a=num[i]%j;
       if(a==0)
        c++;
       if(c>0){
          sum2=sum2+1;
          a=0;
          c=0;
          break;
}
continue;
}}
}
sum3=(N-sum2);
printf("%ld\n",sum3);
return 0;
}



Measured memory_bytes: 2072
C = []
import numpy as np
for _ in range(3):
    C.append(list(map(int,input().split())))

for i in range(1,3):
    ALL = []
    for j in range(3):
        a = C[0][j] - C[i][j]
        ALL.append(a)

    if len(set(ALL)) != 1:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 13412
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

ll func(){
  int n = in();
  map<int,int> m;
  rep(i,n){
    ++m[in()];
  }
  if(n&1){
    if(m[0]!=1)return 0;
  }
  for(int i=(n&1)+1;i<n/2;i+=2){
    if(m[i]!=2)return 0;
  }
  return modpow(2,n/2);
}

int main(){
  cout << func() << endl;
}


Measured memory_bytes: 3200
x = int( input() )

for a in range( 10001 ):
    for b in range( a + 1 ):
        if a ** 5 + b ** 5 == x:
            print( str( a ) + " " + str( -b ) )
            exit()
        elif a ** 5 - b ** 5 == x:
            print( str( a ) + " " + str( b ) )
            exit()

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10;
typedef long long ll;
const ll mod = 998244353;
int n, s;
ll f[maxn];
int main()
{
	scanf("%d%d", &n, &s);
	f[0] = 1;
	for(int i = 1; i <= n; ++i)
	{
		int val;
		scanf("%d", &val); 
		for(int j = s; ~j; --j)
		{
			f[j] = f[j] * 2 % mod;
			if(j >= val)
				f[j] = (f[j] + f[j - val]) % mod;
		}
	}
	cout << f[s] << endl;
	return 0;
}
			
	
	 

Measured memory_bytes: 3824
def f(n):
    return (n * (n + 1)) // 2


def main():
    inp = int(input())
    l, u = 0, 1000000
    while l < u:
        mid = (l + u) // 2
        if f(mid) >= inp:
            u = mid
        else:
            l = mid + 1
    print(u)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
map<int,int> me;
int main()
{
	int a,n,out=0;cin>>n;
	rep(i,n){
		cin>>a;me[a]++;
	}
	map<int,int>::iterator it=me.begin();
	for(;it!=me.end(); it++){
		int x=(*it).fi,y=(*it).se;
		if(y<x) out+=y;else out+=y-x;
	}
	cout<<out<<endl;
}

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

const int N = 301, inf = 0x3f3f3f3f3f3f3f3f;

int adj[N][N];

bitset <N> in[N][N], out[N][N];

int32_t main() {
       // freopen("out.txt", "w", stdout);
        ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int n, m, l; cin >> n >> m >> l;

        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                if(i != j) adj[i][j] = inf;
            }
        }

        for(int i = 1; i <= m; i++) {
            int u, v, w; cin >> u >> v >> w;
            adj[u][v] = min(adj[u][v], w);
            adj[v][u] = min(adj[v][u], w);
        }


        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                for(int k = 1; k <= n; k++) {
                    adj[j][k] = min(adj[j][i] + adj[i][k], adj[j][k]);
                }
            }
        }

        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                in[0][j][i] = (adj[i][j] <= l);
                out[0][i][j] = (adj[i][j] <= l);
            }
        }



        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                for(int k = 1; k <= n; k++) {
                    if((out[0][j] &  in[i - 1][k]).count()) {
                        in[i][k][j] = 1;
                        out[i][j][k] = 1;
                    }
                }
            }
        }

        int q; cin >> q;
        while(q--) {
            int s, t, f = 1; cin >> s >> t;
            for(int i = 0; i <= n; i++) if(out[i][s][t]) {
                cout << i << endl;
                f = 0;
                break;
            }
            if(f) cout << -1 << endl;
        }
}


Measured memory_bytes: 8320
import sys
import heapq

if __name__ == "__main__":
    a = []
    heapq.heapify(a)
    for inp in sys.stdin.readlines():
        inp = inp.split()
        if inp[0] == "insert":
            heapq.heappush(a, int(inp[1])*(-1))
        elif inp[0] == "extract":
            print((-1)*heapq.heappop(a))

Measured memory_bytes: 190240
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(u64);

    let mut x = n;
    let mut sum = 0;

    while x > 0 {
        sum += x % 10;
        x /= 10;
    }

    if n % sum == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <iomanip>

using namespace std;
using ll = int64_t;
using VL = vector<ll>;
using VD = vector<double>;
using VVL = vector<VL>;
using VVD = vector<VD>;

#define FOR(i, start, end) for(ll i = (start), (i ## xxxx_end)=(end); i < (i ## xxxx_end); ++i)
#define FORD(i, start, end) for(ll i = (start), (i ## xxxx_end)=(end); i > (i ## xxxx_end); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPD(i, n) FORD(i, n - 1, -1)

#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}

#define INF 1000000000000
#define MOD 1000000007

ll N;
VL A;
vector<VVD> dp;

double f(ll d1, ll d2, ll d3) {
    if(dp[d1][d2][d3] >= 0)
        return dp[d1][d2][d3];

    if(d1 + d2 + d3 == 0.0)
        return 0;

    double ret = N;
    if(d1 > 0) 
        ret += f(d1 - 1, d2, d3) * d1;
    if(d2 > 0)
        ret += f(d1 + 1, d2 - 1, d3) * d2;
    if(d3 > 0)
        ret += f(d1, d2 + 1, d3 - 1) * d3;
    return (dp[d1][d2][d3] = ret / (d1 + d2 + d3));
}

void solve() {
    cin >> N;
    A = VL(4, 0);
    REP(i, N) {
        ll a;
        cin >> a;
        ++A[a];
    }
    dp = vector<VVD>(310, VVD(310, VD(310, -1)));
    printf("%.10lf\n", f(A[1], A[2], A[3]));
}

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

Measured memory_bytes: 237568
fn main() {
    let n = read::<usize>();
    let aa = read_vec::<i64>();
    let mut v = vec![0i64; n + 1];
    for i in 0..n {
        v[i + 1] = v[i] + aa[i];
    }

    let mut ans = 1152921504606846976;
    for i in 1..n {
        let xy = ((v[i] - v[0]) - (v[n] - v[i])).abs();
        ans = std::cmp::min(ans, xy);
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 10996
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    int n;
    cin >> n;
    
    vector<int> vec(100001,0);
    
    long long count=0;
    
    for(int i=0;i<n;i++) {
        int x;
        cin >> x;
        vec[x]++;
        count+=x;
    }
    
    int k;
    cin >> k;
    
    for(int i=0;i<k;i++){
        int x;
        int y;
        cin>> x >> y;
        count+=(y-x)*vec[x];
        
        cout << count <<endl;
        
        vec[y]+=vec[x];
        vec[x]=0;
    }
    
    
}


Measured memory_bytes: 3776
N = int(input())
p = list(map(int,input().split()))

ans = 0
continuous_flag= 0

for n in range(N):
  if p[n] == n+1:
    if continuous_flag == 0:
      ans += 1
      continuous_flag = 1
    else:
      continuous_flag = 0
  else:
    continuous_flag = 0
print(ans)

Measured memory_bytes: 13880
#include<stdio.h>
int min(int a,int b){return a<b?a:b;}
int main(){
	int n,k;
	int a,b,c;
	int i,j;
	scanf("%d",&n);
	scanf("%d",&k);
	for(i=0;i<k;i++){
		scanf("%d %d",&a,&b);
		a--;
		b--;
		if(a>n/2)a=n-a-1;
		if(b>n/2)b=n-b-1;
		c=min(a,b);
		printf("%d\n",c%3+1);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
  int W, H, x, y, r;

  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if ( x-r >= 0 && W-x >= r) {
	if ( y-r >= 0 && H-y >= r) {
	  puts("Yes");
	}
	else {
	  puts("No");
	}
  }
  else {
	puts("No");
  }

  return 0;
}

Measured memory_bytes: 584
import itertools

n=int(input())
list1=list(map(int,input().split()))

q=int(input())
list2=list(map(int,input().split()))

sum1=set()

for i in range(1,n+1):
	x=list(itertools.combinations(list1,i))
	for j in x:
		sum1.add(sum(j))
		
		
for i in list2:
	if i in sum1:
		print("yes")
	else:
		print("no")


Measured memory_bytes: 56264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = (ll)1e18;
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)

void warshall_floyd(vector<vector<ll>> &d) {
	ll N=d.size();
	for (ll k=0; k<N; k++) {
		for (ll i=0; i<N; i++) {
			for (ll j=0; j<N; j++){
				if(d[i][k] != INF && d[k][j] != INF && d[i][k] + d[k][j] < d[i][j]){
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}
}

bool dfs(vector<vector<ll>> &d,ll v,ll p,vector<ll> &seen){
	rep(nextv,d.size()){
		if(d[v][nextv]!=1)continue;
		if(seen[nextv]!=0){
			if(seen[nextv]==seen[v])return false;
			else continue;
		}
		seen[nextv]=-1*seen[v];
		bool b=dfs(d,nextv,v,seen);
		if(!b)return false;
	}
	return true;
}

signed main() {
	ll N;
	cin>>N;
	vector<vector<ll>> d(N, vector<ll>(N, INF));
	for (ll i = 0; i < N; i++) d[i][i] = 0;

	rep(i,N){
		string s;
		cin>>s;
		rep(j,s.size()){
			if(s[j]=='1'){
				d[i][j]=1;
			}
		}
	}

	vector<ll> seen(N,0);
	seen[0]=1;
	bool b=dfs(d,0,-1,seen);
	if(!b){
		cout<<-1<<endl;return 0;
	}

	ll maxval=0;
	warshall_floyd(d);
	for(ll i=0; i<N; i++) {
		for(ll j=0; j<N; j++) {
			maxval=max(maxval,d[i][j]);
		}
	}	
	cout<<maxval+1<<endl;
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.ArrayDeque;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		ArrayDeque<String> q = new ArrayDeque<String>();

		for(int i=0; i<str.length(); i++){
			if(str.charAt(i)=='T' && "S".equals(q.peekLast())){
				String tmp = q.pollLast();
			}else{
				q.offer(str.charAt(i)+"");
			}
		}

		System.out.println(q.size());
	}
}

Measured memory_bytes: 33452
use std::vec::Vec;
use std::collections::BinaryHeap;
use std::cmp::max;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = read_vec();
    let mut dp = vec![(0, 0); 3*n];

    // 一個ずつ仕切りをずらして行き考える
    // 下位n個について,2*nまで行う
    // 下位の和を最大化
    let mut low = BinaryHeap::new();
    let mut low_sum = 0;
    for i in 0..n {
        low.push(-a[i]);
        low_sum += a[i];
    }

    dp[n-1].0 = low_sum;

    // nから2*nまで
    for i in n..2*n {
        let mut min = low.peek_mut().unwrap();
        if a[i] > -*min {
            low_sum += a[i] + *min;
           *min = -a[i];
        }
        dp[i].0 = low_sum;
    }   

    // 上位2*n個について
    let mut high = BinaryHeap::new();
    let mut high_sum = 0;

    for i in 2*n..3*n {
        high.push(a[i]);
        high_sum += a[i];
    }

    dp[2*n].1 = high_sum;

    for i in (n..2*n).rev() {
        let mut max = high.peek_mut().unwrap();
        if a[i] < *max {
           high_sum += a[i] - *max;
           *max = a[i];
        }
     
        dp[i].1 = high_sum;
    }

    let mut ans = std::i64::MIN;
    for i in n-1..2*n {
        ans = max(ans, dp[i].0 - dp[i+1].1);
    }
    println!("{}", ans);

}   


Measured memory_bytes: 16244
use proconio::*;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
        ans: [usize; d],
    };

    let mut res = 0;
    let mut last_helds = [0; 26];

    satisfaction(&ans, &c, &s, d);
}

fn satisfaction(ans: &Vec<usize>, c: &Vec<i64>, s: &Vec<Vec<i64>>, d: usize) -> i64 {
    let mut last_helds = [0; 26];
    let mut res = 0;

    for day in 1..=d {
        res += s[day - 1][ans[day - 1] - 1];
        last_helds[ans[day - 1] - 1] = day as i64;
        for i in 0..26 {
            res -= c[i] * (day as i64 - last_helds[i]);
        }

        println!("{}", res);
    }

    res
}


Measured memory_bytes: 2332
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int l[200010], r[200010];
int main() {
    ios_base::sync_with_stdio(false);

    int n, k, c;
    string s;
    cin >> n >> k >> c;
    cin >> s;

    int trab=0;
    for(int i = 0; i < n;) {
        if(trab>=k) break;
        if(s[i] == 'o') {
            l[trab] = i;
            trab++;
            i += c+1;
        }else {
            i++;
        }
    }
    trab=k-1;
    for(int i = n-1; i >= 0;) {
        if(trab<0) break;
        if(s[i] == 'o') {
            r[trab] = i;
            trab--;
            i -= c+1;
        }else {
            i--;
        }
    }

    for(int i = 0; i < k; i++) {
        if(l[i] == r[i]) {
            cout << l[i]+1 << "\n";
        }
    }
}


Measured memory_bytes: 3348
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
const int MOD = 1000000007;


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
    int n; cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    sort(s.begin(),s.end());

    int ans = 0;
    rep(i,n){
        if(s[i+1] != s[i]){
            ans++;
        }
    }
    cout << ans << endl;
}

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

const ll MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int n;cin>>n;
    int maxlen = 0;
    string ary[n];
    map<string, int> aa;
    for(int i = 0;i < n;++i) {
      string t;
      cin >> t;
      ary[i] = t;
      aa[t] += 1;
    }
    for(auto itr = aa.begin(); itr != aa.end(); ++itr) {
        if(maxlen < itr->second){   // 値を表示
        maxlen = itr->second;
        }}
	vector<string> a;
    for(int i = 0;i < n;++i) {
      if(aa[ary[i]] == maxlen){
a.push_back(ary[i]);
      }
    }
    sort(a.begin(), a.end());
  map<string, int> aa1;
    for(int i = 0;i < a.size();++i) {
      if(aa1[a[i]] == 0  ) cout << a[i] << endl;
      aa1[a[i]] = 1;
    }
}

Measured memory_bytes: 40820
def main():
    A, V = map(int,input().split(' '))
    B, W = map(int,input().split(' '))
    T = int(input())

    if A > B:
        if A-(V*T) <= B-(W*T):
            print('YES')
        else:
            print('NO')
    else:
        if A+V*T >= B+W*T:
            print('YES')
        else:
            print('NO')
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;
typedef struct node{
  int d; vector<int> to;
}node;

node v[100010];

int solve(int n){
  if(v[n].d >= 0) return v[n].d;
  v[n].d = 0;
  rep(i, v[n].to.size()){
    v[n].d = max(v[n].d, solve(v[n].to[i])+1);
  }
  return v[n].d;
}

int main(){
  int n, m; cin >> n >> m;
  rep(i, m){
    int x, y; cin >> x >> y;
    v[x-1].to.push_back(y-1);
  }
  rep(i, n) v[i].d = -1;
  int ans = 0;
  rep(i, n) ans = max(ans, solve(i));
  cout << ans << endl;
}

Measured memory_bytes: 7808
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

N = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, N):
    ans = ans * a[i] // gcd(ans, a[i])

B = []
for i in range(N):
    B.append(ans//a[i])

print(sum(B) % (10**9 + 7))

Measured memory_bytes: 262644
#include "bits/stdc++.h"
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vs>		vvs;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/



int main()
{
	int N, M;
	cin >> N >> M;
	vi A(M);
	cin >> A;
	vi num = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

	sort(all(A), greater<int>());

	vll dp(N + 1, LLONG_MIN);
	dp[0] = 0;

	for (int i = 1; i <= N; i++) {
		for (int idx = 0; idx < M; idx++) {
			if (i - num[A[idx]] < 0) continue;
			dp[i] = max(dp[i], dp[i - num[A[idx]]] + 1);
		}
	}

	//cout << dp << endl;

	string ans;
	while (N > 0) {
		for (int idx = 0; idx < M; idx++) {
			if (N - num[A[idx]] < 0) continue;

			if (dp[N - num[A[idx]]] == dp[N] - 1) {
				ans.push_back(char(A[idx] + '0'));
				N -= num[A[idx]];
				break;
			}
 		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
# coding: utf-8
N = int(input())
a = list(map(int, input().split()))
cnt = 0
half = 0
for i in range(N):
    if a[i] % 4 == 0:
        cnt += 1
    elif a[i] % 2 == 0:
        half += 1
# cnt += half // 2
if half % 2 != 0:
    half -= 1
if cnt >= (N - half)//2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define MAX_T 202
#define MAX_N 100

int N, K;
int A[200000];

/* 配列の要素を交換する */
void Swap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void QSort(int x[], int left, int right,int n)
{
	int i, j;
	int pivot;

	i = left;                      /* ソートする配列の一番小さい要素の添字 */
	j = right;                     /* ソートする配列の一番大きい要素の添字 */

	pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

	while (1) {                    /* 無限ループ */
		if (n > 0) {
			while (x[i] < pivot)       /* pivot より大きい値が */
				i++;                   /* 出るまで i を増加させる */

			while (pivot < x[j])       /* pivot より小さい値が */
				j--;                   /*  出るまで j を減少させる */
		}
		else {
			while (x[i] > pivot)       /* pivot より小さい値が */
				i++;                   /* 出るまで i を増加させる */

			while (pivot > x[j])       /* pivot より大きい値が */
				j--;                   /*  出るまで j を減少させる */
		}
		if (i >= j)                /* i >= j なら */
			break;                 /* 無限ループから抜ける */

		Swap(x, i, j);             /* x[i] と x[j]を交換 */
		i++;                       /* 次のデータ */
		j--;
	}

	if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
		QSort(x, left, i - 1,n);     /* 左の配列を Q ソートする */
	if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
		QSort(x, j + 1, right,n);    /* 右の配列を Q ソートする */
}

void ShowData(int x[], int n)
{
	int i;

	for (i = 0; i < n; i++)
		printf("%d  ", x[i]);
	printf("\n");
}

int main() {
#ifdef DEBUG

#endif

	scanf("%d %d", &N, &K);
	int i;
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	QSort(A, 0, N - 1,1);
	//ShowData(A, N);
	int tmp=A[0];
	int idx = 0;
	int cntK[200000];
	int cnt=0;
	for (i = 0; i < N; i++) {
		if (i == N - 1&&tmp!=A[i]) {
			cntK[idx++] = cnt;
			cntK[idx++] = 1;
			break;
		}
		if (tmp != A[i]) {
			tmp = A[i];
			cntK[idx++] = cnt;
			cnt = 1;
			//ShowData(cntK, idx);
		}
		else {
			cnt++;
			if (i == N - 1)cntK[idx++] = cnt;
		}
	}
	QSort(cntK, 0, idx - 1,0);
	//ShowData(cntK, idx);
	int ans = 0;
	for (i = K; i < idx; i++) {
		ans += cntK[i];
	}

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

Measured memory_bytes: 1664
#include <stdio.h>

int main(void)
{
    int n;
    int a, b, c, d;
    int i;

    while (scanf("%d", &n) != EOF) {
        i = 0;
        for (a = 0; a <= 9; a++) {
            for (b = 0; b <= 9; b++) {
                for (c = 0; c <= 9; c++) {
                    for (d = 0; d <= 9; d++) {
                        if (a + b + c + d == n) {
                            i++;
                        }
                    }
                }
            }
        }

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

    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>



using namespace std;
int n;
int a[200001];
int dp[1000001];
int maxa=0;
int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        maxa = max(maxa,a[i]);
    }
    for(int i=0;i<n;i++){
        if(dp[a[i]] == 1) {
            dp[a[i]] ++;
            continue;
        }
        for(int j=a[i];j<=maxa;j+=a[i]){
            dp[j] ++;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(dp[a[i]] == 1 ) ans ++;
    }
    cout << ans << endl;
    return 0;
}


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

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

  vector<int> a(N);
  for (int i = 0; i < N; i++)
  {
    cin >> a.at(i);
  }

  int count = 0, now = 0;
  while (true)
  {
    if (a.at(now) == -1)
    {
      count = -1;
      break;
    }
    else
    {
      count++;
      if (a.at(now) == 2)
      {
        break;
      }

      int tmp = now;
      now = a.at(tmp) - 1;
      a.at(tmp) = -1;
    }
  }

  cout << count << endl;
}


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

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

  for (int i = 1; i <= 100; i *= 2)
  {
    if (i <= N && N < i * 2)
    {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3640