akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main  {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if(map.containsKey(a)) {
				map.put(a, map.get(a)+1);
			} else {
				map.put(a, 1);
			}
		}
		List<Entry<Integer,Integer>> list_entries = new ArrayList<Entry<Integer,Integer>>(map.entrySet());
		Collections.sort(list_entries, new Comparator<Entry<Integer,Integer>>() {
			public int compare(Entry<Integer, Integer> obj1, Entry<Integer, Integer> obj2) {
                //降順
                return obj1.getValue().compareTo(obj2.getValue());
            }
		});
		int count = 0;
		int m = 0;
		for(int i = k; i < list_entries.size(); i++) {
			count += list_entries.get(m).getValue();
			m++;
		}
		System.out.println(count);
	}
}

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

using ll = long long;

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

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	ll a,b,c,k;
	cin>>a>>b>>c>>k;

	ll ans=0LL;

	ans += min(k,a);
	k -= min(k,a);

	k -= min(k,b);

	ans -= min(k,c);

	cout << ans << endl;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
#define MIN INT_MIN
#define MAX INT_MAX
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define BG begin()
#define EN end()
#define E "\n"
#define frep(i,j,k,inc) for(int i=j;i<k;i+=inc)
#define rrep(i,j,k,dec) for(int i=j;i>k;i-=dec)
#define arep(elm,obj) for(auto elm:obj)
#define all(x) x.begin(),x.end()
#define revv(v) reverse(all(v))
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int>pii;
const ll mod=1000000007;
void solve();
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    int t;
//    cin>>t;
//    while(t--)
    	solve();

    return 0; 
}

int mima(vi vec,int f){
	int mi=vec[0],ma=vec[0];
	frep(i,1,vec.size(),1){
		mi=min(mi,vec[i]);
		ma=max(ma,vec[i]);
	}
	if(f){return ma;}
	else{return mi;}
}


void solve(){
	int n;
	cin>>n;
	vi arr(n);
	frep(i,0,n,1){cin>>arr[i];}
	sort(all(arr));revv(arr);
	ll ans=arr[0];
	int cnt=1;
	for(int i=1;i<n && cnt<n-1;++i){
		if(cnt<n-2){cnt+=2;ans+=(2*arr[i]);}
		else{cnt++;ans+=arr[i];}
	}
	cout<<ans<<E;
}


Measured memory_bytes: 3988
import numpy as np

n = int(input())
playlist = []
for i in range(n):
  s, t = input().split()
  playlist.append([s, int(t)])
x = input()

arr = np.array(playlist)
position = tuple(nd[0] for nd in np.where(arr == x))[0]

arr_num = arr[:, 1].astype(int)

if position - 1 == n:
  print(0)
else:
  print(arr_num[position + 1:].sum())


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

int main()
{
    int n;
    int max,first;
    bool flag=false;
    while(cin>>n,!cin.eof()){
        for(int i=2;i<n;i++){
            for(int j=2;j<i;j++){
                if(i%j==0){
                    break;
                }
                if(i/2<j){
                    max=i;
                    break;
                }
            }
        }
        if(n==3){
            max=2;
        }
        cout<<max<<' ';
        bool flag=false;
        for(int i=n+1;;i++){
            for(int j=2;j<i;j++){
                if(i%j==0){
                    break;
                }
                if(i/2<j){
                    first=i;
                    flag=true;
                    break;
                }
            }
            if(flag)break;
        }
        cout<<first<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
N,M = map(int,input().split())
a_list = list(map(int,input().split()))
list_n = [0]*(N+1)
for i in range(M):
  
  a,b = map(int,input().split())
  a_n = a_list[a-1]
  b_n = a_list[b-1]
  if a_n == b_n:
    list_n[a]-=10000
    list_n[b]-=10000
  elif a_n>b_n:
    list_n[a] +=1
    list_n[b] -= 10000
  elif a_n<b_n:
    list_n[b] +=1
    list_n[a] -= 10000
count =0
for i in range(1,N+1):
  if list_n[i]>=0:
    count+=1
print(count)

Measured memory_bytes: 20068
def wareru(x,y,z):
  if x%z == 0:
    return y//z - x//z + 1
  else:
    return y//z - x//z

import fractions

a,b,c,d = map(int,input().split())
e = c*d//(fractions.gcd(c,d))
c_hoge = wareru(a,b,c)
d_hoge = wareru(a,b,d)
e_hoge = wareru(a,b,e)
print(b-a+1-c_hoge-d_hoge+e_hoge)

Measured memory_bytes: 5048
from itertools import accumulate

INF = float('inf')

N = int(input())
As = list(map(int, input().split()))

accAs = [0] + list(accumulate(As))

dp = [[0] * (N) for _ in range(N)]
for num in range(2, N+1):
    for i in range(N-num+1):
        cost = INF
        for j in range(1, num):
            cost = min(cost, dp[i][i+j-1] + dp[i+j][i+num-1])
        dp[i][i+num-1] = accAs[i+num] - accAs[i] + cost

print(dp[0][N-1])


Measured memory_bytes: 45180
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int main()
{
	int n;
	std::cin >> n;
	int x = 800 * n;
	int y = n / 15 *200;
	std::cout << x - y << std::endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define _GLIBCXX_DEBUG
#define INF 100000010
 #define PI 3.14159265359

using namespace std;
const int64_t mod = 1000000007;
const int64_t tmpMod = 998244353;

int main() {
 
  int64_t ans=0,a,b,c;
  cin>>a>>b>>c;
  //vector<int64_t> A(N);
  for(int i=a; i<=b; i++){if(i%c==0)ans++;}
  //vector<vector<int> > A(N,vector<int>(M));
  //for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
  //sort(A.begin(),A.end());
  //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  cout << ans << endl;
}


Measured memory_bytes: 3588
count = int(input())
t, h = 0, 0
for line in range(count):
    s1,s2 = input().split()
    if s1 > s2:
        t += 3
    elif s1 < s2:
        h += 3
    else:
        t += 1
        h += 1
print(t, h)

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
const ll T = 2e5 + 100;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m; cin >> m >> n;
    vector<vector<ll>> S(n, vector<ll>(T, 0));
    rep(i, m) {
        ll s, t, c; cin >> s >> t >> c; --c;
        S[c][2*s]++;
        S[c][2*t+2]--;
    }
    rep(i, n) rep(j, 1, T) {
        S[i][j] += S[i][j-1];
    }
    rep(i, n) rep(j, T) {
        chmin(S[i][j], 1LL);
    }
    ll ans = 0;
    rep(i, T) {
        ll a = 0;
        rep(j, n) {
            a += S[j][i];
        }
        chmax(ans, a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 48768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()


int main(){
  string s;cin>>s;
  bool flag=false;
  int ans1,ans2;
  rep(i,s.size()-1){
    if(i<s.size()-2 && s[i]==s[i+2]){
      flag=true;
      ans1 = i;
      ans2 = i+2;
    }
    if(s[i]==s[i+1]){
      flag=true;
      ans1 = i;
      ans2 = i+1;
    }
  }
  if(flag) cout << ans1+1 << " " << ans2+1 << endl;
  else cout << -1 << " " << -1 << endl;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

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

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    int a,b,c,d;
    cin >> a>> b>>c >> d;
    for(int i=0;;i++){
        a-=d;
        c-=b;
        if(c<=0){
            cout << "Yes" << endl;
            return 0;
        }
        if(a<=0){
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    string S, T;
    cin >> S >> T;

    cout << T << S << "\n";

    return 0;
}


Measured memory_bytes: 256
# 2019/07/31

# 考え方
# 素因数分解した数 p を n個に分割 残りの数を適当な項に入れる
# eg.
# input
"""
4 972439611840
"""
# output
"""
206
"""
# 素因数分解=> 
# 2   :6
# 103 :4
# 3   :3
# 5   :1

# n個に分割
"""
//////////////////////
 1   2   3   4
----------------
 2   2   2   2
 *   *   *   *
103 103 103 103
 *
2^2
 *
103^0
 *
3^3
 *
5^1
----------------
111240  206  206  206
=972439611840
/////////////////////
"""


from fractions import gcd
from collections import Counter

n,p=map(int,input().split())

def trial_div(n):
    
    prime=Counter()

    for i in range(2,int(pow(n,0.5)+2)):
        while n%i==0:
            n//=i
            prime[i]+=1
    if n>1:prime[n]+=1
    
    return prime

res=trial_div(p)
ans=1
for k,v in res.items():
    tmp=k**(v//n)
    ans*=tmp

print(ans)

Measured memory_bytes: 5304
import numpy as np
h, w = map(int, input().split())
a = np.zeros([h, w], dtype=int)
idx_h = []
idx_w = []
for i in range(h):
    s = input()
    v = list(map(int, s.replace('.', '1 ').replace('#', '-1 ').split()))
    if sum(v) != w:
        a[i, :] = v
        idx_h.append(i)
aa = np.sum(a, axis=0)
for i in range(w):
    if aa[i] != len(idx_h):
        idx_w.append(i)
for i in idx_h:
    s = ''
    for j in idx_w:
        if a[i, j] == 1:
            s += '.'
        elif a[i, j] == -1:
            s += '#'
    print(s)

Measured memory_bytes: 14300
#include <stdio.h>

#define MAX_N 1000
#define MAX_DEPTH MAX_N
#define MAX_LINE_LEN 50
typedef char line_t[MAX_DEPTH + MAX_LINE_LEN + 1];

void convert(int n, line_t line[])
{
  int i, j, p;
  for (i = 0; i < n; i++) {
    for (p = 0; line[i][p] == '.'; p++) { }
    if (p > 0) {
      line[i][p - 1] = '+';
      for (j = i - 1; j >= 0; j--) {
        if (line[j][p - 1] != '.') break;
        line[j][p - 1] = '|';
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (p = 0; line[i][p] != '\0'; p++) {
      if (line[i][p] == '.') line[i][p] = ' ';
    }
  }
}

int main()
{
  static line_t line[MAX_N];
  int n, i;
  for (;;) {
    scanf("%d", &n);
    if (n == 0) break;
    for (i = 0; i < n; i++) {
      scanf("%s", line[i]);
    }
    convert(n, line);
    for (i = 0; i < n; i++) {
      printf("%s\n", line[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
 
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
	fast;
	ll h = 1;
	//cin >> h;
	while(h--){
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	string out;
	for(int i=0;i<n;i++){
		out+=s[i];
		out+=t[i];
	}
	cout << out;
	}}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int k, s;
    cin >> k >> s;
    ll cnt = 0;
    FOR(x, 0, k)
        FOR(y, 0, k)
            if(s - x - y >= 0 && s - x - y <= k) cnt ++;
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
D = int(input())
c = [0]+list(map(int, input().split()))
s = [[0]]+[[0]+list(map(int, input().split())) for _ in range(D)]
t = [0]+[int(input()) for _ in range(D)]
ans = 0
last = [0]*(27)
for d in range(1,D+1):
    ans += s[d][t[d]]
    last[t[d]] = d
    for i in range(1,27):
        ans -= c[i] * (d-last[i])
    print(ans)

Measured memory_bytes: 9396
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int cnt = 0;
  while( A > 0 && C > 0 ){
    if( cnt%2 == 0 ) C -= B;
    else A -= D;
    if( A <= 0 ){
      cout << "No" << endl;
      return 0;
    }else if( C <= 0 ){
      cout << "Yes" << endl;
      return 0;
    }
    cnt++;
  }
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String args[]) {
        FastReader sc = new FastReader();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a + b >= c) System.out.println("Yes");
        else System.out.println("No");
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21460
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
char c[100010];
int main(){
	scanf("%s",c+1);
	n=strlen(c+1);
	for(register int i=1;i<=n;i++){
		if(i%2==1 && c[i]=='L'){puts("No");return 0;}
		if(i%2==0 && c[i]=='R'){puts("No");return 0;}
	}
	puts("Yes");
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin>>n;
	int arr[n+5];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	int gcd=arr[0];
	for(int i=1;i<n;i++)
	{
		gcd=__gcd(gcd,arr[i]);
	}
	cout<<gcd<<endl;

	return 0;
}

Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<double,P> PP;
struct edge { int to; int cost; };
int imos[100006];
signed main() {
	int a, b; cin >> a >> b;
	if (a >= 13)cout << b << endl;
	else if (a >= 6)cout << b / 2 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    string S;
    int ans;
    cin >> S;
    if(S == "SUN") ans = 7;
    if(S == "MON") ans = 6;
    if(S == "TUE") ans = 5;
    if(S == "WED") ans = 4;
    if(S == "THU") ans = 3;
    if(S == "FRI") ans = 2;
    if(S == "SAT") ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[107];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    int sum=0;
    for(int i=1;i<n;i++){
        sum+=a[i];
    }
    if(sum>a[n])
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 256
n,h=map(int,input().split())
a=[]
b=[]
count=0
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
max_a=max(a)
b.sort(reverse=True)

for i in b:
    if max_a>i:
        break
    else:
        count+=1
        h-=i
        if h<=0:
            print(count)
            exit()
count+=h//max_a if h%max_a==0 else h//max_a+1
print(count)

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

int main(){
	string sa,sb;
	int ca=0,cb=0;
	while(getline(cin,sa),getline(cin,sb)){
		if(sa[0]==sb[0]){ca++;}
		if(sa[2]==sb[2]){ca++;}
		if(sa[4]==sb[4]){ca++;}
		if(sa[6]==sb[6]){ca++;}
		
		if(sa[0]==sb[2]||sa[0]==sb[4]||sa[0]==sb[6]){cb++;}
		if(sa[2]==sb[0]||sa[2]==sb[4]||sa[2]==sb[6]){cb++;}
		if(sa[4]==sb[0]||sa[4]==sb[2]||sa[4]==sb[6]){cb++;}
		if(sa[6]==sb[0]||sa[6]==sb[4]||sa[6]==sb[2]){cb++;}
		
		cout<<ca<<" "<<cb<<endl;
		ca=0;cb=0;
		}
		return 0;
	}

Measured memory_bytes: 2960
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let a: i32 = get();
    let b: i32 = get();
    if a <= 8 && b <= 8 {
        println!("Yay!");
    } else {
        println!(":(");
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	n, k := scanInt(sc), scanInt(sc)
	hs := nextIntSlice(sc, n)
	sort.Sort(sort.IntSlice(hs))

	min := math.MaxInt32
	for i := 0; i+k <= len(hs); i++ {
		v := hs[i+k-1] - hs[i]
		if v < min {
			min = v
		}
	}
	return min
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

func loop0(n int) chan int {
	return loop(0, n-1, 1)
}

func loop1(n int) chan int {
	return loop(1, n, 1)
}

func loop(s, e, d int) chan int {
	ch := make(chan int)
	go func() {
		for i := s; i <= e; i += d {
			ch <- i
		}
		close(ch)
	}()
	return ch
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

#define ull unsigned long long
#define ll long long
#define imei(...)   "[ "<< #__VA_ARGS__ <<" = "<< __VA_ARGS__ <<" ] "

using namespace std;

void solve(int t) {
    int n;
    cin >> n;
}

int main(int argc, char *argv[])
{
    vector<int> rec;
    int n;
    cin >> n;

    rec.resize(n, 0);

    //R:1, W:0
    for (int i = 0; i < n; i++) {
        char c;
        cin >> c;
        if (c == 'R')
            rec[i] = 1;
    }

    int l = 0, r = n - 1, ans = 0;
    while(l < r) {
        while(l < r && rec[l])
            l++;
        while(l < r && !rec[r])
            r--;
        if (l < r)
            ans++;
        l++;
        r--;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 4044
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a, b, c, times, sum, maxnum;
  	cin >> a >> b >> c >> times;
  	sum = a + b + c;
  	maxnum = max({a, b, c});
  	sum -= maxnum;
  	for (int i = 0; i < times; i++){
    	maxnum *= 2;
    }
  	sum += maxnum;
  	cout << sum;
}

Measured memory_bytes: 256
// AOJ ALDS1_13_B 8 Puzzle
// 2018.5.8 bal4u

#include <stdio.h>

typedef unsigned char uchar;

#define HASHSIZ 300007 // 543217
typedef struct { unsigned s; char x, v; } HASH;
HASH hash[HASHSIZ+3], *hashend = hash+HASHSIZ;

int lookup(unsigned s, int x)
{
	long long t = ((long long)x << 32) + s;
	HASH *hp = hash + (int)(t % HASHSIZ);
	while (hp->s) {
		if (hp->s == s && hp->x == x) return hp->v;
		if (++hp == hashend) hp = hash;
	}
	return 0;
}

void insert(unsigned s, int x, char v)
{
	long long t = ((long long)x << 32) + s;
	HASH *hp = hash + (int)(t % HASHSIZ);
	while (hp->s) {
		if (hp->s == s && hp->x == x) { hp->v = v; break; }
		if (++hp == hashend) hp = hash;
	}
	hp->s = s, hp->x = x, hp->v = v;
}

#define QMAX 30000
typedef struct { unsigned s; char x, v; } T;
T s[QMAX+3]; int top, end;
int hi[9] = {2,3,2,3,4,3,2,3,2};
int to[9][4] = {{1,3},{0,2,4},{1,5},{0,4,6},{1,3,5,7},{2,4,8},{3,7},{4,6,8},{5,7}};

void toArray(char *nine, unsigned s, int x)
{
	int i;
	
	for (i = 8; i >= 0; i--) {
		if (i == x) nine[i] = 0;
		else nine[i] = s & 0xf, s >>= 4;
	}
}

unsigned swap(char *nine, int zero, int nx)
{
	int i;
	unsigned res;
	
	res = 0;
	for (i = 0; i < 9; i++) {
		if      (i == zero) res <<= 4, res |= nine[nx];
		else if (i != nx)   res <<= 4, res |= nine[i];
	}
	return res;
}

#define MAGIC 21

int main()
{
	int i, x, nx, v, nv, t;
	unsigned a, na;
	unsigned gs; int gx;	// goal
	char nine[9];
	
	gs = 0; for (i = 0; i < 9; i++) {
		scanf("%d", &t);
		if (t == 0) gx = i;
		else gs <<= 4, gs |= t;
	}
	s[0].s = 0x12345678, s[0].x = 8;
	s[1].x = -1;
	top = 0, end = 2;
	insert(s[0].s, s[0].x, 0);
	v = 0;
	while (top != end) {
		a = s[top].s, x = s[top].x;
		if (++top == QMAX) top = 0; 
		if (x < 0) {
			if (v == MAGIC) break;
			v++;
			s[end].x = -1; if (++end == QMAX) end = 0;
			continue;
		}
		if (x == gx && a == gs) goto done;
		if (lookup(a, x) < v) continue;

		toArray(nine, a, x);
		for (i = 0; i < hi[x]; i++) {
			nx = to[x][i];
			na = swap(nine, x, nx), nv = v+1;
			t = lookup(na, nx);
			if (!t || nv < t) {
				s[end].s = na, s[end].x = nx;
				if (++end == QMAX) end = 0;
				insert(na, nx, nv);
			}
		}
	}

	s[0].s = gs, s[0].x = gx, s[1].x = -1;
	top = 0, end = 2;
	v = 0;
	while (top != end) {
		a = s[top].s, x = s[top].x;
		if (++top == QMAX) top = 0; 
		if (x < 0) {
			v++;
			s[end].x = -1; if (++end == QMAX) end = 0;
			continue;
		}
		if ((t = lookup(a, x)) > 0) { v += t; break; }

		toArray(nine, a, x);
		for (i = 0; i < hi[x]; i++) {
			nx = to[x][i];
			na = swap(nine, x, nx), nv = v+1;
			t = lookup(na, nx);
			if (!t || nv < t) {
				s[end].s = na, s[end].x = nx;
				if (++end == QMAX) end = 0;
			}
		}
	}
done:
	printf("%d\n", v);
	return 0;
}



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

#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()  
{ 
    FAST_INP;
    int x; 
    cin >> x;
    for(int i=-118;i<=119;i++){
        for(int j=-119;j<=118;j++){
            if(pow(i,5)-pow(j,5)==x) {
                cout << i << " " << j << "\n";
                return 0;
            }
        }
    }
    return 0;
} 

Measured memory_bytes: 4044
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n;cin>>n;int i;
    for(i=0;;i++){
        if(i*i>n)break;
    }
    cout<<(i-1)*(i-1)<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






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

#define M 1000000
#define L 13

char Hash[M][L];

int h1(int key){
	return key % M; 
}

int h2(int key){
	return 1 + (key % (M-1)); 
}

int getChar(char str){
	if(str == 'A') return 1;
	else if(str == 'C') return 2;
	else if(str == 'G') return 3;
	else if(str == 'T') return 4;
}

int getKey(char str[]){
	int sum = 0, p = 1;
	for(int i = 0 ; i < strlen(str) ; i++){
		sum += p * (getChar(str[i]));
		p *= 5;
	}
	
	return sum;
}

int insert(char str[]){
	int key, h;
	int x, y;
	key = getKey(str);
	x = h1(key);
	y = h2(key);
	for(int i = 0 ; i < M ; i++){
		h = (x + i * y) % M;
		if(strcmp(Hash[h], str) == 0) return 1;
		else if(strlen(Hash[h]) == 0){
			strcpy(Hash[h], str);
			return 0;
		}
	}
	
	return 0;
}

int find(char str[]){
	int key, h;
	int x, y;
	
	key = getKey(str);
	
	x = h1(key);
	y = h2(key);
	
	for(int i = 0 ; i < M ; i++){
		h = (x + i * y) % M;
		if(strcmp(Hash[h], str) == 0) return 1;
		else if(strlen(Hash[h]) == 0) return 0;;
	}
	
	return 0;
}

int main(){
	int n, h;
	char str[L], status[7];
	
	for(int i = 0 ; i < M ; i++){
		Hash[i][0] = '\0';
	}
	
	scanf("%d", &n);
	
	for(int i = 0 ; i < n ; i++){
		scanf("%s %s", status, str);
		
		if(status[0] == 'i'){
			insert(str);
		}else{
			if(find(str)){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 13880
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;

int N, A, B, C;
vector<int> take;

// calc 
int calc (int a, int b, int c) {
	if (a <= 0 || b <= 0 || c <= 0) {
		return 65535;
	}
	return abs(A - a) + abs(B - b) + abs(C - c) -30;
};

//dfs
int dfs(int depth, int a, int b, int c) {
	if (depth == N) {
		return calc(a, b, c);
	}
	int retA = dfs(depth + 1, a + take[depth], b, c) + 10;
	int retB = dfs(depth + 1, a, b + take[depth], c) + 10;
	int retC = dfs(depth + 1, a, b, c + take[depth]) + 10;
	int ret0 = dfs(depth + 1, a, b, c);
	return min({retA, retB, retC, ret0});
};

int main() {
	cin >> N >> A >> B >> C;
	for (size_t i = 0; i < N; i++) {
		int a = 0;
		cin >> a;
		take.push_back(a);
	}

	int ans = dfs(0,0,0,0);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;



long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}



bool mode;//trueでx,falseでy
int  H, W, ans, N, A,B, num,sum,now, mx[4000],my[4000];
string s,t,tt,ss;

int main() {
	cin >> N >> A >> B;
	for (int i = 0; i <= N ; i++) {
		now = i;
		sum = 0;
		num = 0;
		while (now) {
			num = now % 10;
			sum += num;
			now /= 10;
		}
		if (sum >= A && sum <= B) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 256
s = list(input())
t = list(input())
if s==t:
    print('No')
    exit()

s = sorted(s)
s = ''.join(s)
t = sorted(t, reverse=1)
t = ''.join(t)
l = [s,t]
k = sorted(l)
if l==k:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
	int n; 
	int m; 
	int a, b, c, d, s, g, V, P;
	int cost, reward;
	scanf("%d%d", &n, &m);
	int K[n][n];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)
			K[i][j] = 100010010;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		a--; b--;
		K[a][b] = c;
		K[b][a] = d;
	}
	// FoyldWarshall
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (K[i][j] > K[i][k] + K[k][j])
					K[i][j] = K[i][k] + K[k][j];
			}
		}
	}
	scanf("%d,%d,%d,%d", &s, &g, &V, &P);
	s--; g--;
	cost = K[s][g] + K[g][s];
	reward = V - P - cost;
	cout << reward << endl;
}


Measured memory_bytes: 3232
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};


int main(){
  int N;
  int K;
  double ans = 0;
  cin >> N >> K;
  rep(i,N){
    double pt = i+1;
    double f = 1;
    while(pt < K){
      f/=2;
      pt*=2;
    }
    ans += f;
  }
  ans/=N;
  printf("%.12lf\n",ans);
}



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

using namespace std;
int main()
{
	string s;
	cin >> s;
	bool ans = true;
	if(s[0] != 'A') ans = false;
	int cnt = 0;
	for(int i=2; i<s.length()-1; i++){
		if(s[i] == 'C')
			cnt++;
	}
	if(cnt != 1) ans = false;
	int big = 0;
	for(int i=0; i<s.length(); i++){
		if('A' <= s[i] && s[i] <= 'Z')
			big++;
	}
	if(big != 2) ans = false;
	
	if(ans){
		cout << "AC" << endl;
	}else{
		cout << "WA" << endl;
	}
	
	return 0;
}



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

typedef long long ll;

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	ll n,m;
	cin >> n >> m;
	if(n >= m / 2){
		ANS(m / 2);
		return 0;
	}
	ll ans = n;
	m -= n * 2;
	ans += m / 4;
	ANS(ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;
constexpr double EPS = 1e-10;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> a(N),b(N);
    REP(i,N) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a.rbegin(), a.rend());
    REP(i,N) {
        if(b[i]==a[0]) {
            cout << a[1] << '\n';
        } else {
            cout << a[0] << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = 1e9+7;

int main(void)
{
	ll n; cin >> n;
	vector<ll> a(n); rep(i, n) cin >> a[i];
	ll sum = 0;
	rep(i, n) sum += a[i];
	bitset<4000050> dp;
	dp[0] = 1;
	rep(i, n) {
		auto dp1 = dp;
		dp1 <<= a[i];
		dp |= dp1;
	}
	repi(i, (sum + 1) / 2, sum + 1) {
		if (dp[i]) {
			cout << i << endl;
			return 0;
		}
	}
}


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

using namespace std;

typedef long long ll;

int solve()
{
  return 0;
}

int main()
{
  int H, W;
  scanf("%d %d", &H, &W);
  vector<string> board;
  for (int i = 0; i < H; ++i) {
    string s;
    cin >> s;
    board.push_back(s);
  }
  bool ok = true;
  for (int r = 0; r < H; ++r) {
    for (int c = 0; c < W; ++c) {
      if (board[r][c] == '.') { continue; }
      bool found = false;
      for (int dr = -1; dr <= 1; ++dr) {
        for (int dc = -1; dc <= 1; ++dc) {
          if (abs(dr) + abs(dc) != 1) { continue; }
          int nr = r + dr, nc = c + dc;
          if (0 <= nr && nr < H && 0 <= nc && nc < W && board[nr][nc] == '#') {
            found = true;
            break;
          }
        }
        if (found) { break; }
      }
      if (!found) {
        ok = false;
        break;
      }
    }
    if (!ok) { break; }
  }

  printf("%s\n", ok ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long K, long long R, long long S, long long P, string T){
	ll res = 0;
	rep(i, K) {
		bool oldr = false, olds = false, oldp = false;
		for (ll j = i; j < N; j += K) {
			if (T[j] == 'r') {
				if (!oldr) {
					// cout << j << endl;
					res += P;
					oldr = true;
					olds = false;
					oldp = false;
				} else {
					oldr = false;
				}
			}
			if (T[j] == 's') {
				if (!olds) {
					// cout << j << endl;
					res += R;
					oldr = false;
					olds = true;
					oldp = false;
				} else {
					olds = false;
				}
			}
			if (T[j] == 'p') {
				if (!oldp) {
					// cout << j << endl;
					res += S;
					oldr = false;
					olds = false;
					oldp = true;
				} else {
					oldp = false;
				}
			}
		}
	}
	cout << res << endl;
}

int main(){	
	long long S;
	long long R;
	long long P;
	string T;
	long long K;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&K);
	scanf("%lld",&R);
	scanf("%lld",&S);
	scanf("%lld",&P);
	cin >> T;
	solve(N, K, R, S, P, T);
	return 0;
}



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

using pii = pair<int, int>;

int main() {
    int n; cin >> n;
    vector<pii> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i + 1;
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < n; ++i) {
        cout << a[i].second << " \n"[i + 1 == n];
    }
}


Measured memory_bytes: 1536
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<char> >v(n,vector<char>(m));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>v[i][j];
        }
    }
    bool no=false;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++){
            if(v[i][j]=='#')
            {
                int count=0;
                if(i>0&&v[i-1][j]=='#'){
                    count++;
                }
                if(i<n-1&&v[i+1][j]=='#'){
                    count++;
                }
                if(j>0&&v[i][j-1]=='#'){
                    count++;
                }
                if(j<m-1&&v[i][j+1]=='#'){
                    count++;
                }
                if(count==0)
                {
                    no=true;
                    break;
                }
            }
            if(no)
            {
                break;
            }
        }
    }
    if(no){
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 3628
N = 3
dx = [0,-1,0,1]
dy = [1,0,-1,0]
limit = 0
t = [[0 for i in range(N)] for j in range(N)]

def getH():
    sum = 0
    x = int(0)
    for i in range(N):
        for j in range(N):
            if t[i][j]==0:continue
            x=t[i][j]-1
            sum += abs(int(x/N)-i)+abs((int(x%N)-j))
    return sum

def dfs( depth, prev,py,px):
    h=getH()
    if h == 0 :return True 
    if depth+h > limit: return False
    for i in range(4):
        if abs(i-prev) == 2 : continue
        tx=px+dx[i]
        ty=py+dy[i]
        if tx<0 or ty<0 or tx>=N or ty>=N:continue
        t[ty][tx],t[py][px] = t[py][px],t[ty][tx]
        if dfs(depth+1,i,ty,tx) :return True
        t[ty][tx],t[py][px] = t[py][px],t[ty][tx]
    return False

def Solve(py, px):
    global limit
    limit =0
    while True:
        if dfs(0,99,py,px):
            print(limit)
            return 
        limit += 1
 
if __name__=='__main__':
    for i in range(N):
        tmp =list(map(int, input().split()))
        for j in range(N):
            t[i][j]=tmp[j]
            if t[i][j]==0:
                py=i
                px=j
    Solve(py,px)




Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;//×Ô¶¯È¡Ä£2^64 
const double pi=acos(-1.0);
const int mod = 1e9+7; // 998244353;
const int inf = 0x7fffffff;//2^31-1	
const ll INF = 0x7fffffffffffffff;
const int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
//double begin_time=clock();    double end_time=clock();printf("time= %lf ms\n",end_time-begin_time);
//bool operator < (const mmp &a) const{return x<a.x||x==a.x&&y<a.y;}       //map<int,map<int,int> >z;
//map<int,int>::iterator it;for(it=z.begin();it!=z.end();it++)printf("%d %d\n",it->first,it->second);
//ll pow(ll a,ll b){ll s=1;while(b){if(b&1){s=(s*a)%mod;b--;}b/=2;a=a*a%mod;}return s;}  //¿ìËÙÃÝÈ¡Ä£ 
//lower_bound(begin,end,num); µÚÒ»¸ö>=numµÄÊý×Ö upper_bound(begin,end,num); µÚÒ»¸ö>numµÄÊý×Ö,·µ»ØµØÖ·
//freopen("input.in","r",stdin);     freopen("output.out","w",stdout);      //ÎÄ¼þ¶ÁÐ´Ìá½» 
//reverse(s.begin(),s.end());   //·­×ª×Ö·û´® ||        floor(); ÏòÏÂÈ¡Õû  ceil(); ÏòÉÏÈ¡Õû
//x&(x-1)==0 //ÊÇ2µÄN´Î·½||         x%9 //x¸÷¸öÎ»µÄºÍ||           log10(x)+1   //xµÄÎ»Êý|| 
//ÊýÖáÉÏµÄn¸öµãÒÆ¶¯µ½Í¬Ò»Î»ÖÃ£¬ÒÆ¶¯µ½¸Ã×éÊý×ÖµÄÖÐÎ»ÊýµÄ×Ü¾àÀë×î¶Ì



int main()
{
	int a,b,c,d,e,T;
//	scanf("%d",&T);
//	while(T--)
	{
		char z[105];
		char x[105];
		scanf("%s%s",z,x);
		a=1;
		for(int i=0;i<strlen(z);i++)
		{
			if(z[i]!=x[i])a=0;
		}		 
		if(a)printf("Yes\n");
		else printf("No\n");

		 
		
	}
}




 



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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    for (int i=0; i<n; i++) cin >> l[i];
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());

    int sum = 0;
    for (int i=0; i<k; i++) sum += l[i];
    cout << sum << endl;

    return 0;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    vector<P> cb(m);
    rep(i, m){
        int b, c;
        cin >> b >> c;
        cb[i].first = c;
        cb[i].second = b;
    }
    sort(cb.rbegin(), cb.rend());
    int k = n;
    for(auto i: cb){
        vector<int> x(i.second, i.first);
        a.insert(a.end(), x.begin(), x.end());
        k -= i.second;
        if(k < 0) break;
    }
    sort(a.rbegin(), a.rend());
    ll ans = 0;
    rep(i, n) ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 3312
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long a, b, c;
    scanf("%ld%ld%ld", &a, &b, &c);

    set<long> z;
    z.insert(a);
    z.insert(b);
    z.insert(c);
    printf("%ld\n", (long)z.size());

    return 0;
}


Measured memory_bytes: 256