akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<string> VS;
//template
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;}
//repetition
#define FOR(i,a,b) for(int i=int(a); i<int(b); ++i)
#define FORD(i,a,b) for(int i=int(a); i<int(b); --i)
#define REP(i,N) for(int i=0; i<int(N); ++i)
#define REPS(i,N) for(int i=0; i<=int(N); ++i)
#define REPD(i,N) for(int i=0; i<int(N); --i)
//container util
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//constant
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //配列の最大のrenge
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
    string s;
    cin >> s;
    if (s[(int)s.size() - 1] == 's') s = s + "es";
    else s = s + 's';
    cout << s << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <iomanip> //cout << fixed << setprecision(12) << ans << endl;
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define rloop(i, l, r) for(int i = l; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vec_i;

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;
const int MOD = 1e9+7;

int main()
{
	string s;
	cin >> s;
	bool flag = true;
	for(int i=0;i<s.size();i++){
		if(i%2){
			if(s[i]=='R'){
				flag = false;
				break;
			}
		}else{
			if(s[i]=='L'){
				flag = false;
				break;
			}
		}
	}
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100100100;//10^17
const ll MOD = 1000000007;


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

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

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



int main(){
    int max = 100000;
    vector<bool> isPrime(max, true);
    isPrime[0] = false;
    isPrime[1] = false;//0と1は素数じゃない
    for(int i = 2; i * i <= max; i++){
        if(isPrime[i] == true){//もしiが素数だったら
            for(int j = 2; i * j <= max; j++){
                isPrime[j * i] = false;//max以下のiの倍数は素数じゃない
            }
        }
    }
    //まず累積和の構築
    vector<int> s(max + 1);
    s[0] = 0;
    for(int i = 1; i <= max; i++){
        if(isPrime[i] == true && isPrime[(i + 1) / 2] == true)s[i] = s[i - 1] + 1;
        else s[i] = s[i - 1];
    } 
    int Q;
    cin >> Q;
    vector<int> ans(Q);
    rep(i, Q){
        int l, r;
        cin >> l >> r;
        ans[i] = s[r] - s[l - 1];
    }
    rep(i, Q)cout << ans[i] << endl;
} 

Measured memory_bytes: 1408
N, K = map(int, input().split())

AList = []
emptyList = []

for i in range(K):
    d = int(input())
    AList.append(list(map(int, input().split())))

for i in AList:
    for j in range(1, N+1):
        if j in i:
            emptyList.append(j)

print(N-len(list(set(emptyList))))


Measured memory_bytes: 9132
N,M = (int(x) for x in input().split())
A_arr = [int(x) for x in input().split()]
BC_arr = [[0,0] for _ in range(M)]
for i in range(M):
    b,c = (int(x) for x in input().split())
    BC_arr[i][0] = b
    BC_arr[i][1] = c

A_arr.sort()
BC_arr.sort(key=lambda x:x[1], reverse=True)

break_th = False
j_count = 0
for BC in BC_arr:
    Bi = BC[0]
    Ci = BC[1]
    for j in range(Bi):
        if A_arr[j_count] >= Ci:
            break_th = True
            break
        A_arr[j_count] = Ci
        j_count += 1
        if j_count == N:
            break_th = True
            break
    if break_th:
        break
print(sum(A_arr))


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

int main(void){
  int a, b, n;
  while(cin >> a >> b >> n){
    int sum = 0, f_pl;
    a = a * 10;
    for(int i = 0; i < n; i++){
      sum += (a / b) % 10;
      a = a % b;
      a = a * 10;
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
#define nl '\n'
#define eb emplace_back
#define f(i,start,n) for(int i=start; i<=n; i++)


int main()
{
    FASTIO;
        int n; cin >> n;
        n = n%10;
        if(n==2||n==4||n==5||n==7||n==9){
            cout << "hon\n";
        }
        else if(n==0||n==1||n==6||n==8){
            cout << "pon\n";
        }
        else{
            cout << "bon\n";
        }
    
    return 0;
}



Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

int main(void)
{
    int n, m;

    cin >> n >> m;

    long long temp;
    priority_queue<long long> a;

    for (int i = 0; i < n; i ++) {
        cin >> temp;
        a.push(temp);
    }
    //sort(a.begin(), a.end(), std::greater<int>());
    for (int i = 0; i < m; i++) {
        temp = a.top();
        temp /= 2;
        a.pop();
        a.push(temp);
    }
    
    long long ans = 0;
    for (; !a.empty(); ) {
        ans += a.top();
        a.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int f[4][4],a,b,c;
void print(){
	for(register int j = 1;j <= 3;j ++){
		for(register int k = 1;k <= 3;k ++){
			printf("%d ",f[j][k]);
		}
		printf("\n");
	}
}
int main(){
    scanf("%d%d%d",&f[1][1],&f[1][2],&f[2][2]);
    a=f[2][2]*3;
    f[1][3]=a-f[1][1]-f[1][2];
    f[3][1]=a-f[1][3]-f[2][2];
    f[3][3]=a-f[1][1]-f[2][2];
    f[2][1]=a-f[1][1]-f[3][1];
    f[2][3]=a-f[2][1]-f[2][2];
    f[3][2]=a-f[1][2]-f[2][2];
    for(register int i=1;i<=3;i++){
        for(register int j=1;j<=3;j++){
            printf("%d ",f[i][j]);
        }
        printf("\n"); 
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

      String a = s.substring(0, n/2);
      String b = s.substring(n/2+1, n);

      boolean ans = isKaibun(a) && isKaibun(b) && isKaibun(s);
      System.out.println(ans ? "Yes" : "No");
    } finally {
      sc.close();
    }
  }

  private static boolean isKaibun(String s) {
    boolean ans = true;
    for (int i = 0; i < s.length() / 2; i++) {
      if (s.charAt(i) != s.charAt(s.length() - 1 - i)) ans = false;
    }
    return ans;
  }
}


Measured memory_bytes: 35676
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		int cnt[] = new int[100];
		
		while (input.hasNext()){
			int n = input.nextInt();
			cnt[--n]++;
		}
		
		int max = 0;
		for (int n : cnt){
			if (max < n){
				max = n;
			}
		}
		
		for (int i = 0; i < cnt.length; i++){
			if (cnt[i] == max){
				System.out.println(i + 1);
			}
		}
	}
}

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

int main() {
  while (true) {
    int n, k, m;
    cin >> n >> k >> m;
    if (n == 0 && k == 0 && m == 0) return 0;

    bool check[n + 1];
    for (int i = 0; i < n + 1; i++) {
      check[i] = true;
    }

    check[m] = false;
    int current = m;
    for (int i = 2; i < n; i++) {
      int next = k % (n - i + 1);
      if (next == 0) next = k;
      int count = 0;
      for (int j = current; ; j++) {
	if (j == n + 1) j = 1;
	if (check[j]) count++;
	if (count == next) {
	  current = j;
	  check[j] = false;
	  break;
	}
      }
    }

    for (int i = 1; i <= n; i++) {
      if (check[i]) {
	cout << i << endl;
	break;
      }
    }
  }
}

Measured memory_bytes: 3068
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll H, N; cin >> H >> N;
    vll a(N), b(N);
    rep(i, 0, N){
        cin >> a[i] >> b[i];
    }    
    ll dp[H+10001];
    dp[H+10000] = 0;
    rrep(i, H+9999, -1){
        ll t = INF;
        rep(j, 0, N){
            if(i + a[j] > H + 10000){
                continue;
            }
            t = min(dp[i+a[j]] + b[j], t);
        }
        dp[i] = t;
    }
    ll k = INF;
    rep(i, 0, 10001){
        k = min(dp[i], k);
    }
    prt(k);
}





Measured memory_bytes: 3800
import java.util.List;
import java.util.ArrayList;
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String str = sc.next();
        String[] strArray = str.split("");

        while (!str.equals("-")) {

            Queue<String> queue = new ArrayDeque<>();

            for (int i = 0; i < strArray.length; i++) {
                queue.add(strArray[i]);
            }

            int m = sc.nextInt();
            List<Integer> h = new ArrayList<>();

            for (int i = 0; i < m; i++) {
                h.add(sc.nextInt());
            }

            for (int i = 0; i < h.size(); i++) {
                for (int j = 0; j < h.get(i); j++) {
                    queue.add(queue.poll());
                }
            }

            for (int i = 0; i < strArray.length; i++) {
                System.out.print(queue.poll());
            }

            System.out.print("\n");

            str = sc.next();
            strArray = str.split("");
        }

        sc.close();
    }
}


Measured memory_bytes: 26376
// AtCoderを信じる！！

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

int main() {
  int N;
  string A[3];

  cin >> N;
  cin >> A[0] >> A[1] >> A[2];
  int ret = 0;
  for(int i = 0; i < N; i++) {
    if(A[0][i] == A[1][i] && A[1][i] == A[2][i]) continue;
    if(A[0][i] == A[1][i] || A[0][i] == A[2][i] || A[1][i] == A[2][i]) ++ret;
    else ret += 2;
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
using namespace std;
 
int main(){
    
    int S,A=0,B=0;
    bool a=0,b=0;

    cin >> S;

    A=floor(S/100);
    B=S-(A*100);

    if(A>=1&&A<=12){
        a = 1;
    }

    if(B>=1&&B<=12){
        b = 1;
    }

    if(a==1&&b==1){
        cout << "AMBIGUOUS" <<endl;
    }else if(a==1&&b==0){
        cout << "MMYY" <<endl;
    }else if(a==0&&b==1){
        cout << "YYMM" <<endl;
    }else{
        cout << "NA" <<endl;
    }



    
    return 0;

}

Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int sum = 0;
		int max = 0;

		for(int i=0;i<N;i++) {
			int val = sc.nextInt();
			if(val >= max) {
				max = val;
				//max_index = i;
			}
			sum += val;
		}
		if (sum > 2*max) System.out.println("Yes");
		else System.out.println("No");
		//System.out.println(sum > 2*max);
	}
}

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

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PN() putchar('\n')
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define MT make_tuple

using PII = pair<int, int>;
using TI3 = tuple<int, int, int>;
using LL = long long;
using ULL =  unsigned long long;
using MAT = array<array<LL, 2>, 2>;

void RI() {}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d", &head);
    RI(tail...);
}
void RLL() {}
template<typename... T>
void RLL( LL& head, T&... tail ) {
    scanf("%lld", &head);
    RLL(tail...);
}
void print() {putchar('\n');}
template<typename T, typename... U>
void print(T head, U... tail) {
    cout << head << " ";
    print(tail...);
}

const int MOD = 1000000007;
#define MAX_N 100005

LL A[MAX_N];

int main()
{
    int K;
    RI(K);
    REP(i, K) {
        RLL(A[i]);
    }
    LL n = 2, n2 = 2;
    REP(i, K-1, -1, -1) {
        LL a = A[i];
        n = (n + a - 1) / a * a;
        if(n > n2) {
            printf("-1\n");
            return 0;
        }
        n2 = n2 - n2 % a + a - 1;
    }
    printf("%lld %lld\n", n, n2);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

int dp[105][4][2];

int main(){
  string s;
  cin >> s;
  int K;
  cin >> K;
  int n=s.size();
  dp[0][0][0]=1;
  rep(i,n)rep(j,K+1)rep(k,2){
    int nd = s[i]-'0';
    rep(d,10){
      int ni = i+1;
      int nj = j;
      int nk = k;
      if(d!=0)nj++;
      if(nj>K)continue;
      if (k == 0) {
        if (d > nd) continue;
        if (d < nd) nk = 1;
      }
      dp[ni][nj][nk]+=dp[i][j][k];
    }
  }
  cout << dp[n][K][1]+dp[n][K][0] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <stack>
#include <string>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    stack<int> st;
    string s;
    while (cin >> s) {
        if (s == "+" || s == "-" || s == "*") {
            int b = st.top(); st.pop();
            int a = st.top(); st.pop();
            if (s == "+") {
                st.push(a + b);
            }
            else if (s == "-") {
                st.push(a - b);
            }
            else if (s == "*") {
                st.push(a * b);
            }  
        }
        else {
            st.push(stoi(s));
        }
    }
    cout << st.top() << endl;
    return 0;
}

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

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 100;
int adj_matrix[N_MAX][N_MAX];

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

    int n;
    cin >> n;

    int id, k, v;
    FOR(i,0,n) {
        cin >> id;
        cin >> k;
        FOR(j,0,k) {
            cin >> v;
            adj_matrix[id-1][v-1] = 1;
        }
    }
    FOR(i,0,n) {
        FOR(j,0,n) {
            if (j > 0) { cout << " "; }
            cout << adj_matrix[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3172
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	vector<LLONG> as(N); REP(i, N) cin >> as[i];
	LLONG ans = 0;
	// 貪欲にペアを作っていく
	for (int i = 0; i < N - 1; ++i)
	{
		// i 同士のペア
		ans += as[i] / 2;
		as[i] %= 2;
		// i + 1 とのペア
		LLONG num = min(as[i], as[i + 1]);
		ans += num;
		as[i + 1] -= num;
	}
	// 残った as[N - 1] でペアを作る
	ans += as.back() / 2;
	cout << ans << endl;
}

Measured memory_bytes: 4040
n = input()
*a, = map(int, input().split())
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
b = [i for i in d.keys() if d[i] >= 2]
if len(b) == 0:
    print(0)
elif len(b) == 1:
    if d[b[0]] >= 4:
        print(b[0]**2)
    else:
        print(0)
else:
    b.sort()
    if d[b[-1]] >= 4:
        print(b[-1]**2)
    else:
        print(b[-1]*b[-2])


Measured memory_bytes: 18064
#include <stdio.h>
#include <math.h>
int main(void){
    int num,i,p,h,w,ans;
    double dif,sign;
    for(;sign=100.0,scanf("%d",&num),num;){
        for(i=0;i<num;i++){
            scanf("%d %d %d",&p,&h,&w);
            dif=fabs(1.0*w/h/h*10000-22.0);
            if(sign > dif){
                sign=dif;
                ans=p;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

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

using ll = long long;

using namespace std;

ll gcd(ll C, ll D) {
	if (C < D) gcd(D, C);

	if (C%D == 0)return D;
	else return gcd(D, C%D);
}

const int MOD = 1000000007;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	ll sum = 0;
	rep(i, N) {
		cin >> A[i];
		sum += A[i];
		sum %= MOD;
	}
	ll ans = 0;

	rep(i, N) {
		sum -= A[i];
		if (sum < 0) sum += MOD;
		ans += A[i] * sum;
		ans %= MOD;
	}

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






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

int main(void){
 
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s[0] == 'a' && s[1] == 'b' && s[2] == 'c'){
        cout <<"Yes" <<endl;
    }
    else{
        cout << "No" <<endl;
    }
}

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

int main(){
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='o') cnt++;
    }
    cout<<700+(100*cnt)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b;
    char c;
    cin >> a >> c >> b;
    if (c == '+') cout << a + b;
    else cout << a - b;
}


Measured memory_bytes: 256
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val numbers = readLine()!!.split(" ").map { it.toLong() }
    val numberCount = mutableMapOf<Long, Long>()
    for(i in numbers) {
        numberCount[i] = (numberCount[i]?:0) + 1
    }
    var ans = 0L
    for(num in numberCount.keys) {
        numberCount[num]?.let {
            if(it > num) {
                ans += it - num
            } else if(it < num) {
                ans += it
            }
        }
    }
    println(ans)
}



Measured memory_bytes: 60172
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n, k;
  cin >> n >> k;
  V l(n);
  int res = 0;
  for (int i = 0; i < n; i++) cin >> l[i];
  sort(l.begin(), l.end());
  for (int i = n-k; i < n; i++) res += l[i];
  dump(res);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
  if a[i] % 2 == 0:
    if a[i] % 3 != 0 and a[i] % 5 != 0:
      print("DENIED")
      break
  else:
    pass
  if i == n-1:
    print("APPROVED")

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
  fastio;
  string s, t;
  set<int> pos[27];
  cin >> s >> t;
  for(int i = 0; i < len(s); i++){
    pos[s[i]-'a'].insert(i);
  }
  ll ans = 0;
  int p = -1;
  for(int i = 0; i < len(t); i++){
    if(pos[t[i]-'a'].empty()){
      cout << -1 << endl;
      return 0;
    }
    auto it = pos[t[i]-'a'].upper_bound(p);
    if(it == pos[t[i]-'a'].end()){
      ans += 1LL*(len(s) - p) + *pos[t[i]-'a'].begin(); // pega tudo + 1° ocorrencia
      p = *pos[t[i]-'a'].begin();  // vai pra la
    }else{
      ans += *it - p; // anda pra *it
      p = *it; // vai pra it
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 5200
/*input
BWBWBW
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main()
{
	IOS;
	string s;
	cin>>s;
	ll ans=0;
	int cnt=0;
	for(char c:s){
		if(c=='B') cnt++;
		else ans+=cnt;
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 720
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string s;
int l;
int main()
{
    cin>>s;
    l=s.size();
    for(register int i=0;i<l;i++)
        if(s[i]=='C')
            for(register int j=i+1;j<l;j++)
                if(s[j]=='F')
                {
                    cout<<"Yes";
                    return 0;
                }
    cout<<"No";
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  rep(i, m) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  rep(i, 1000) {
    string str = to_string(i);
    if (str.size() != n) continue;
    bool ok = true;
    rep(i, m) {
      if (str[s[i]] != c[i] + '0') {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> void chmax(T& a,const T& b){if(a < b) a = b;}
template<typename T> void chmin(T& a,const T& b){if(b < a) a = b;}
typedef long long ll;

int N = 16;
string S("CODEFESTIVAL2016"),T;

int main()
{
	cin >> T;

	int ans = 0;
	FOR(i,0,N){
		ans += (S [i] != T [i]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int d[] = new int[N];
    for(int i = 0; i < N; i++){
        d[i] = sc.nextInt();
    }
    int count = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            count += d[i] * d[j];
        }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;

  if(S.at(0) == S.at(1))
  {
    cout << "Bad" << endl;
  }
  else if(S.at(1) == S.at(2))
  {
    cout << "Bad" << endl;
  }
  else if(S.at(2) == S.at(3))
  {
    cout << "Bad" << endl;
  }
  else
  {
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Input:
6
D 3
H 2
D 1
S 3
D 2
C 1

Output:
Not stable / Stable
D 1
C 1
D 2
H 2
D 3
S 3
"""
import sys
import copy


def partition(_array, start, end):
    x = int(_array[end][2:])
    i = start - 1
    assert start <= end
    for j in range(start, end):
        if int(_array[j][2:]) <= x:
            i += 1
            _array[i], _array[j] = _array[j], _array[i]
    _array[i + 1], _array[end] = _array[end], _array[i + 1]
    return i + 1


def quick_sort(_array, start, end):
    if start < end:
        cursor = partition(_array, start, end)
        quick_sort(_array, start, cursor - 1)
        quick_sort(_array, cursor + 1, end)
    return _array


def merge(_array, left, mid, right):
    array_left = _array[left:mid] + ['N ' + str(int(1e9 + 1))]
    array_right = _array[mid:right] + ['N ' + str(int(1e9 + 1))]

    i, j = 0, 0

    for k in range(left, right):
        if int(array_left[i][2:]) <= int(array_right[j][2:]):
            _array[k] = array_left[i]
            i += 1
        else:
            _array[k] = array_right[j]
            j += 1

    return None


def merge_sort(_array, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(_array, left, mid)
        merge_sort(_array, mid, right)
        merge(_array, left, mid, right)
    return _array


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(lambda x: x.strip(), _input[1:]))
    # assert len(array) == array_length

    merge_array = copy.deepcopy(array)
    merge_result = merge_sort(_array=merge_array, left=0, right=array_length)
    # print(*merge_result, sep='\n')
    quick_result = quick_sort(_array=array, start=0, end=array_length - 1)

    if quick_result != merge_result:
        print('Not stable')
    else:
        print('Stable')
    print(*quick_result, sep='\n')

Measured memory_bytes: 23900
n = int(raw_input())
h = raw_input()
h_list = map(int,h.split(' '))

class PathToPoint(object):
	def __init__(self,index,height):
		self.i = index
		self.h = height
		if self.i==0:
			self.distance = 0
			self.previous = -1
		else:
			self.distance = -1 #we don't know it yet

	def set_distance(self):
		if self.i==0:
			return
		if self.i==1:
			self.distance = abs(self.h-Paths[self.i-1].h)
			self.previous = 0
			return
		distance1 = abs(self.h-Paths[self.i-1].h)+Paths[self.i-1].distance
		distance2 = abs(self.h-Paths[self.i-2].h)+Paths[self.i-2].distance
		if distance1<distance2:
			self.previous = self.i-1
			self.distance = distance1
		else:
			self.previous = self.i-2
			self.distance = distance2
Paths = []
for i in range(n):
	Paths.append(PathToPoint(i,h_list[i]))
for path in Paths:
	path.set_distance()

print Paths[-1].distance

Measured memory_bytes: 49024
#include <iostream>
#include <cmath>

using namespace std;

int main(void) {
  int A, B;
  double ans;
  cin >> A >> B;
  ans = (A+B)/2.0;
  if(ceil(ans) == floor(ans)) {
    cout << (int)(ans) << endl;
   } else {
     cout << "IMPOSSIBLE" << endl;
   }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
struct edge {
    int to; T cost;
    edge(int to, T cost) : to(to), cost(cost) {}
};


template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

int main() {
    int n;
    while(cin >> n, n){
        vector<int> id(n), xs(n), ys(n);
        map<int, int> A, Ainv;
        for (int i = 0; i < n; ++i) {
            scanf("%d %d %d", &id[i], &xs[i], &ys[i]);
            A[i] = id[i];
            Ainv[id[i]] = i;
        }
        vector<vector<edge<double>>> G(n);
        for (int i = 0; i < n; ++i) {
            for (int j = i+1; j < n; ++j) {
                if((xs[i]-xs[j])*(xs[i]-xs[j])+(ys[i]-ys[j])*(ys[i]-ys[j]) <= 2500){
                    G[i].emplace_back(j, hypot(xs[i]-xs[j], ys[i]-ys[j]));
                    G[j].emplace_back(i, hypot(xs[i]-xs[j], ys[i]-ys[j]));
                }
            }
        }
        int m;
        cin >> m;
        while(m--){
            int s, g;
            cin >> s >> g;
            vector<double> dist(n, 1e18);
            vector<int> prev(n);
            GPQ<pair<double, int>> Q;
            s = Ainv[s]; g = Ainv[g];
            Q.emplace(0, s);
            while(!Q.empty()){
                double cost; int i;
                tie(cost, i) = Q.top(); Q.pop();
                if(dist[i] < cost) continue;
                for (auto &&e : G[i]) {
                    auto cost2 = cost + e.cost;
                    if(dist[e.to] <= cost2) continue;
                    dist[e.to] = cost2;
                    Q.emplace(dist[e.to], e.to);
                    prev[e.to] = i;
                }
            }
            if(dist[g] > 1e16) {
                puts("NA");
                continue;
            }
            vector<int> ans;
            while(g != s){
                ans.emplace_back(g);
                g = prev[g];
            }
            ans.emplace_back(s);
            reverse(ans.begin(),ans.end());
            for (int i = 0; i < ans.size(); ++i) {
                printf(i ? " %d" : "%d", A[ans[i]]);
            }
            puts("");
        }
    }
    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
  int d, n, ans = 1;
  cin >> d >> n;
  for (int i = 0; i < d; i++)
    ans *= 100;
  cout << (n != 100 ? ans * n : ans * (n + 1)) << endl;
}

Measured memory_bytes: 256
def main():
  n = int(input())
  #s = list(input())
  #s = input().split()
  #a,b = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  while n >= 5:
    if n >= 500:
      ans += 1000
      n -= 500
    elif n >= 5:
      ans += 5
      n -= 5
  print(ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CAlchemist solver = new CAlchemist();
        solver.solve(1, in, out);
        out.close();
    }

    static class CAlchemist {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            PriorityQueue<Double> pq = new PriorityQueue<>();
            for (int i = 0; i < n; i++) pq.add((double) in.nextInt());
            while (pq.size() != 1) pq.add((pq.poll() + pq.poll()) / 2);
            out.println(pq.peek());
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 21460
#include <stdio.h>
#define MAX 50100
int n;
int p[MAX];
int prime[10000];
int main(){
  int i,j,count=0;

  for(i=0;i<MAX;i++){
    p[i]=1;
  }
  for(i=2;i*i<MAX;i++){
    if(p[i]==1){
      for(j=i+i;j<MAX;j=j+i){
	p[j]=0;
      }
    }
  }
  for(i=2;i<MAX;i++){
    if(p[i]==1){
      prime[count]=i;
      count++;
    }
  }
  while(scanf("%d",&n)!=EOF){
    for(i=0;i<count;i++){
      if(n==prime[i]){printf("%d %d\n",prime[i-1],prime[i+1]);break;}
      if(n<prime[i]){printf("%d %d\n",prime[i-1],prime[i]);break;}
    }
  }
  return 0;
}

Measured memory_bytes: 808
def message(numbers):
    numbers=str(numbers)
    message=""
    while(len(numbers)>0):
        num=numbers[:2]
        if len(num)==1:
            return "NA"
        if int(num[0])>6 or int(num[0])<=0:
            return "NA"
        if int(num[1])>5 or int(num[1])<=0:
            return "NA"
        code=(int(num[0])-1)*5+int(num[1])
        if code>30:
            return "NA"
        if code==27:
            message+="."
        elif code==28:
            message+="?"
        elif code==29:
            message+="!"
        elif code==30:
            message+=" "
        else:
            message+=chr(code-1+ord('a'))
        numbers=numbers[2::]
    return message


while True:
    try:
        n=input()
        print(message(n))
    except EOFError:
        break



Measured memory_bytes: 5596
N = int(input())
a = [int(x) for x in input().split()]
memo = [0]*(10**5+2)
ans = 1
for i in range(N):
  memo[a[i]] += 1
  memo[a[i]+1] += 1
  memo[a[i]-1] += 1
print(max(memo))

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

int main() {
    char c; cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define ll long long
const int MAX=1e6;
const int MOD=1e9+7;
vector<ll> fact(MAX),inv(MAX),finv(MAX);
int X,Y;

void COMinit(){
    fact[0]=fact[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(int i=2;i<MAX;i++){
        fact[i]=fact[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll COM(int n,int k){
    if(n<0||k<0||n<k) return 0;
    return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll solve(int X,int Y){
    if(2*Y-X<0||2*X-Y<0) return 0;
    if((2*Y-X)%3!=0||(2*X-Y)%3!=0) return 0;
    int N=(2*Y-X)/3;
    int M=(2*X-Y)/3;
    return COM(N+M,N);
}

int main(){
    COMinit();
    cin>>X>>Y;
    cout<<solve(X,Y)<<endl;
    return 0;
}

Measured memory_bytes: 23680
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cctype>
#include<string>
using namespace std;

int main(){
    string str, str1, str2;
    int m;
    int h;

    while(cin >> str){
        if("-" == str){
            break;
        }
        cin >> m;

        // cout << str << " " << endl;
        // cout << m << " " << endl;

        for(int i = 0; i < m; i++){
            cin >> h;
            // cout << h << " ";

            str1 = str.substr(0, h);
            str2 = str.substr(h, str.size());

            str = str2 + str1;

            // cout << str1 << endl;
            // cout << str2 << endl;
        }

        // cout << endl;

        cout << str << endl;

    }

    return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
int minthis(int a, int b){
if(a < b){
return a;
}
return b;
}
int maxthis(int a, int b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return temp * temp;  
    else
    {  
        if(y > 0)  
            return x * temp * temp;  
        else
            return (temp * temp) / x;  
    }  
}  
 /*
const int mxN = 200005;
int father[mxN] = {}, level[mxN] = {}, subtree[mxN] = {}, count_sons[mxN] = {};vector<int> e[mxN];priority_queue<pair<int,int>> pq; 
 
 
void dfs(int node, int fr){
	father[node] = fr;
	for(auto x : e[node]){
		if(x != fr){
			count_sons[node]++;
			level[x] = level[node]+1;
			dfs(x,node);
		}
	}
	if(count_sons[node] == 0){
		
		pq.push({node, level[node]});
		cout << node << endl;
	}
} 
	
 */
 
 int MEX(int arr[],int n, int j){
	int x = 0;
	sort(arr,arr+n);
	for(int i = 0 ; i < n ; i++){
		if(arr[i] > x){
			return x;
		}
		x++;
	}
	return x;
 }
 
void solve(){	
	string arr[6];
	int n,m,k;int count = 0 ;
	cin >> n >> m >> k;
	for(int i = 0 ; i < n ; i++){
		cin >> arr[i];
	}
	for(int i = 0 ; i < (1<<n) ; i++){
		for(int j = 0 ; j < (1<<m) ; j++){
			int ans = 0;
			for(int a = 0 ; a < n ; a++){
				for(int b = 0 ; b < m ; b++){
					if((i&(1<<a)) | (j&(1<<b))) continue;
					else ans += (arr[a][b] == '#');
				}
			}
			if(ans == k){
				count++;
			}
		}
	}
	cout << count << "\n";
	
}
  
int main(){ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;    
    //cin >> t;
    while(t--){
		solve();
	}
    return 0; 
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> drink(N);
    for(int i = 0; i < N; i++) {
        cin >> drink[i].first >> drink[i].second;
    }
    sort(drink.begin(), drink.end());
    int i = 0;
    long money = 0;
    while(M > drink[i].second) {
        M -= drink[i].second;
        money += (long) drink[i].first * drink[i].second;
        i++;
    }
    for(i; M > 0; ) {
        M--;
        money += (long) drink[i].first;
    }
    cout << money << endl;
    return 0;
}

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

using namespace std;

int main() {
    float a, b;
    cin >> a >> b;
    int x1 = ceil(a/0.08);
    int x2 = ceil((a+1)/0.08) - 1;
    int y1 = ceil(b/0.1);
    int y2 = ceil((b+1)/0.1) - 1;
    if(x1<=y2 && y1 <= x2)
    {
        cout << max(x1, y1) << '\n';
    }
    else
    cout << -1 << '\n';
}

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

int main(){
    int n, refW;
    std::cin >> n >> refW;

    std::vector<int> values(n);
    std::vector<int> weights(n);
    for(int i = 0; i < n; ++i){
        std::cin >> values.at(i) >> weights.at(i);
    }

    std::vector< std::vector<int> > dp(n + 1, std::vector<int> (refW + 1, 0));
    for(int i = 0; i < n; ++i){
        for(int w = 0; w <= refW; ++w){
            if(w >= weights.at(i)){
                dp.at(i + 1).at(w) = std::max(dp.at(i).at(w - weights.at(i)) + values.at(i), dp.at(i).at(w));
            }else{
                dp.at(i + 1).at(w) = dp.at(i).at(w);
            }
        }
    }

    std::cout << dp.at(n).at(refW) << std::endl;

    return 0;
}



Measured memory_bytes: 6828
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
INF = float('inf')


def main():
   N, K = map(int, readline().split())
   P = list(map(int, readline().split()))
   P.sort()
   ans = 0
   for i in range(K):
       ans += P[i]
   print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9168
n = int(input())
n += 1

import copy

ans = 0
ans_c = 0

for i in reversed(range(n)):
    check = copy.copy(i)
    div = 0
    count = 0

    while div == 0:
        div = (i % 2)
        i = i // 2
        if div == 0:
            count += 1
        if i == 0:
            break
    if ans_c < count:
        ans = check
        ans_c = count
if ans == 0:
     ans += 1
        
print(ans)

Measured memory_bytes: 3572
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)


int main() {
  int n, ans; cin >> n;
  vector<int> A(n);
  rep(i, n){
      int num; cin >> A[i];
  }
  sort(all(A));
  vector<int> B;
  int num = 2;
  if(n % 2 == 1) B.push_back(0);
  else num--;
  for(num; num < n; num += 2){
    B.push_back(num);
    B.push_back(num);
  }
  bool flag = true;
  rep(i, n){
      if(A[i] != B[i]){
          flag = false;
          break;
      }
  }
  
  if(!flag) ans = 0;
  else{
      ans = 1;
      int k = n / 2;
      rep(i, k){
          ans = ans * 2 % MOD;
      }
  }
  cout << ans  % MOD << ln;
}

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

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}

int main() {
    int n; cin >> n;
    int k; cin >> k;
    std::vector<int> a(n);
    for (int& x: a) {
        cin >> x;
    }
    std::map<int, int> b;
    for (int x: a) {
        b[x] += 1;
    }
    std::sort(a.begin(), a.end(), [&](int u, int v) {
        if (b[u] != b[v]) {
            return b[u] < b[v];
        }
        return u < v;
    });
    a.erase(std::unique(a.begin(), a.end()), a.end());

    int m = (int)b.size() - k;
    int ans = 0;
    for (int i = 0; i < m; ++i) {
        ans += b[a[i]];
    }
    cout << ans << endl;
}


Measured memory_bytes: 10368
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, M;
int A[100111];
LL S[200111];

void MAIN() {
    scanf("%d%d", &N, &M);
    REP (i, N) scanf("%d", A+i), A[i]--;

    LL ans = 0;
    for (int i=1; i<N; i++) {
	int cur = A[i-1], nxt = A[i];
	if (nxt <= cur) nxt += M;
	ans += nxt - cur;
	S[cur+2]++;
	S[nxt+1] -= nxt - cur;
	S[nxt+2] += nxt - cur - 1;
    }
    REP (i, 2 * M+2) S[i+1] += S[i];
    REP (i, 2 * M+2) S[i+1] += S[i];

    LL ma = 0;
    REP (i, M) amax(ma, S[i] + S[i+M]);
    printf("%lld\n", ans - ma);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 2176
#include<iostream>
using namespace std;
int main(){
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(x>=0 && y>=0 && x+r<=w && y+r<=h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

#define N_MAX 402
#define ll long long

using namespace std;

const ll INF = 1000000000000000001;

int n;

ll a[N_MAX];

ll sp[N_MAX];

ll dp[N_MAX][N_MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sp[i] = sp[i - 1] + a[i];
    }
    for(int i = n; i >= 1; i--)
        for(int j = i + 1; j <= n; j++)
        {
            ll mi = INF;
            for(int k = i; k < j; k++)
                mi = min(mi, dp[i][k] + dp[k + 1][j]);
            dp[i][j] = mi + sp[j] - sp[i - 1];
        }
    cout << dp[1][n] << "\n";
    return 0;
}


Measured memory_bytes: 1536
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	A := make([]int, N)
	tot := 0
	for i := range A {
		fmt.Scan(&A[i])
		tot += A[i]
	}
	sum := 0
	for i := range A {
		if A[i] >= (tot+4*M-1)/(4*M) {
			sum++
		}
	}
	if sum >= M {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int ans;
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		int a,b;cin>>a>>b;
		ans+=b-a+1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import collections

h, w, m = map(int, input().split())
h_li = []
w_li = []

for i in range(m):
    _h, _w = map(int,input().split())
    h_li.append(_h)
    w_li.append(_w)

h_bomb = [0] * (h+1)
w_bomb = [0] * (w+1)

h_counter = collections.Counter(h_li)
w_counter = collections.Counter(w_li)

for i in range(1, h+1):
    h_bomb[i] = h_counter.get(i, 0)

for i in range(1, w+1):
    w_bomb[i] = w_counter.get(i, 0)
    
ans = max(h_bomb) + max(w_bomb)
allow_count = h_bomb.count(max(h_bomb)) * w_bomb.count(max(w_bomb))

s = 0
cnt = 0
for i in range(m):
    _h, _w = h_li[i], w_li[i]
    if h_bomb[_h] + w_bomb[_w] == ans:
        cnt += 1
    
if cnt < allow_count:
    print(ans)
else:
    print(ans-1)


Measured memory_bytes: 68164