akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
ll dp1[400][400];
ll dp2[400][400];
const ll INF = 1ll<<60;
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n; cin >> n;
   rep(i,n){
      cin >> dp1[i][i];
   }
   for (int size = 1; size < n; size++){
      for (int left = 0; left < n-size; left++){
         int right = left+size;
         dp1[left][right] = dp1[left][left]+dp1[left+1][right];
      }
   }
   for (int size = 1; size < n; size++){
      for (int left = 0; left < n-size; left++){
         int right = left+size;
         dp2[left][right] = INF;
         for (int k = 0; left+k < right; k++){
            dp2[left][right] = min(dp2[left][right], dp2[left][left+k]+dp2[left+k+1][right]+dp1[left][right]);
         }
      }
   }
   cout << dp2[0][n-1] << endl;
}

Measured memory_bytes: 6132
//============================================================================
// Name        : d
// Date        : Wed Feb 20 09:23:06 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define pvi(x, v) if(v) pvar(x); fora(a, x) cout << a << " "; cout << "\n"
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"

#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

// dp[i][v] the maximum value we can get if the last consideration is ith item
// and the capacity is `v`.

void amax(ll &a, ll b) {
    a = max(a, b);
}

void solve() {
    int n, w; cin >> n >> w;
    vi vv(n + 1), ww(n + 1);
    fori (i, 1, n + 1) {
        cin >> ww[i] >> vv[i];
    }

    vector<vl> dp(n + 1, vl(w + 1, 0));
    fori (i, 1, n + 1) {
        fori (v, 0, w + 1) {
            amax(dp[i][v], dp[i - 1][v]);
            if (v - ww[i] >= 0) {
                amax(dp[i][v], dp[i - 1][v - ww[i]] + vv[i]);
            }
        }
    }
    output(dp[n][w]);
}

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



Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main(){
ll x;
cin>>x;
if(x>=30){
    cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}

ll N, K, X;

void printnum(ll i, ll n){
    ll bit;
    printf("%lld:", i);
    for(ll j=0; j<n; j++){
        if(i&(1<<j)) printf(" %d", j);
    }
    printf("\n");
}

void iter(ll x, ll bit){
    // cout << "x=" << x << ", bit=" << bit << endl;
    // cout << bitset<32>(x) << endl;
    // cout << bitset<32>(1<<bit) << endl;
    // cout << bitset<32>(X) << endl;
    if(bit<0){
        printnum(x, N);
        return;
    }
    // printf("%d\n", X & (1<<bit));
    // if((X & (1<<bit))==0) {
    //     printf("returned\n");
    //     return;
    // }
    //unuse
    iter(x, bit-1);

    // use
    if((X & (1<<bit))!=0) {
        iter(x|(1<<bit), bit-1);
    }
    
}
 
int main()
{
    cin >> N;
    cin >> K;
    ll tmp;
    rep(i, K){
        cin >> tmp;
        X |= (1 << tmp);
    }

    iter(0, N);

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int64_t> L(N+1);
  L.at(0)=2;
  L.at(1)=1;
  for(int i=2;i<N+1;i++){
    L.at(i)=L.at(i-1)+L.at(i-2);
  }
  cout << L.at(N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,s,t,l1,l2,l,m,r,f;
    char str1[1005];
    char str2[1006];
    scanf("%s",str1);
    scanf("%s",str2);
    l1 = strlen(str1);
    l2 = strlen(str2);
    t = 0;
    for(i = 0;i <= (l1 - l2);i++){
        s = 0;
        r = 0;
        for(j = 0,l = i;j < l2;l++,j++){
            if(str1[l] == str2[j]){
                s++;
            }
        }
        if(s > t){
            t = s;
            m = i;
        }
        //printf("%d\n",t);
    }
    f = l2 - t;
    //printf("%d\n",m);
    //r = 0;
    //for(i = m,j = 0;j < l2;i++,j++){
      //  if(str1[i] != str2[j]){
        //    r++;
        //}
    //}
    printf("%d\n",f);
    return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int len(int n, int a){
  if(a>=n){
    return a-n*(a/n);}
  else{ return a;}
}

int main(){
 int n;
  cin>>n;
  char grid[n][n];
  rep(i, n){
    rep(j, n){
      cin>>grid[i][j];
    }
  }
  
  int cnt=0;
  for(int b=0;b<n;b++){
    bool pos=true;
    for(int i=1;i<n;i++){
      for(int j=0;j<i;j++){
        if(grid[len(n, i+b)][j]!=grid[len(n, j+b)][i]){
          pos=false;
          break;}
      }
      if(!pos)
        break;
    }
    
    if(pos)
      cnt++;
  }
  
  cout<<cnt*n<<endl;
  
  
  
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

 

int main(){
    vector<int> integer(3);
    rep(i,3){
        cin >> integer[i];
    }
    sort(all(integer));
    
    int max_num = integer[2];
    
    int lack = 0;
    rep(i,3){
        lack += max_num - integer[i];
    }
    
//    cout << lack << endl;
    if(!(lack&1)){
        cout << lack/2 << endl;
        return 0;
    }
    cout << lack/2 + 2 << endl;
    
    
 

    
    
    
    
    
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> k(m);
    vector<vector<int> > s(m);
    vector<int> p(m);
    for(int i=0;i<m;i++){
        cin>>k[i];
        for(int j=0;j<k[i];j++){
            int tmp;
            cin>>tmp;
            s[i].push_back(tmp-1);
        }
    }
    for(int i=0;i<m;i++){
        cin>>p[i];
    }
    vector<string> c;
    for(int i=0;i<1<<n;i++){
        string tmp="";
        for(int j=0;j<n;j++){
            tmp+=((bool)((1<<j)&i))+'0';
        }
        c.push_back(tmp);
    }
    int ans=0;
    for(int i=0;i<c.size();i++){
        //cout<<c[i]<<endl;
        int count=0;
        for(int j=0;j<m;j++){
            int mod=0;
            for(int l=0;l<k[j];l++){
                //cout<<c[i][s[j][l]]-'0'<<endl;
                mod+=c[i][s[j][l]]-'0';
            }
            //cout<<mod<<endl;
            if(mod%2==p[j])count++;
        }
        if(count==m)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;cin >> N;
    vector<int> A(N);
    rep(i,N)cin >> A[i];
    int res = 0;
    rep(i,N){
        if(A[i]%2)res++;
    }
    if(res%2)cout <<"NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 640
def count_inv(lst):
    ret = 0
    for i in range(len(lst)):
        for j in range(i + 1, len(lst)):
            if lst[i] > lst[j]:
                ret += 1
    return ret


def count_smaller_elements(lst):
    ret = 0
    for i in range(len(lst)):
        tmp = 0
        for j in range(len(lst)):
            if i != j and lst[i] > lst[j]:
                tmp += 1
        ret += tmp
    return ret


def main():
    N, K = map(int, input().split())
    lst_A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7

    a = count_inv(lst_A)
    num1 = a * K % MOD

    b = count_smaller_elements(lst_A)
    num2 = b * (K * (K - 1) // 2) % MOD

    ans = (num1 + num2) % MOD
    print(ans)


if __name__ == "__main__":
    main()

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

int main()
{
  int N;
  cin >> N;
  
  vector<int> A(N);
  for(int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  
  int times = 0;
  
  while(1)
  {
    for(int i = 0; i < N; i++)
    {
      if (A.at(i) % 2 == 0)
      {
        A.at(i) = A.at(i) / 2;
      }
      else
        goto Result;
    }
    times++;
  }
  
Result:
  cout << times << endl;
}

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

bool f(int x)
{
    int keta = 0;
    while (x)
    {
        keta++;
        x /= 10;
    }
    return keta % 2 == 1;
}

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (f(i))
            ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  char c;
  cin >> c;
  cout << (char)(c + 1) << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s;
    cin >> s;
    int n = sz(s);
    string ans = "Yes";


    rep(i,0,n-1){
        if(i%2==0 && s[i] != 'h')ans = "No";
        if(i%2==1 && s[i] != 'i')ans = "No";

    }
    if(n%2==1)ans = "No";

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include <math.h>
#include <string>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
typedef long long int ll;
const ll INF =1LL << 62;
using namespace std;
int MAX_E=1000010;
ll dp[1000010];
void split(string s, vector<string> &v){
	v.clear();
	s +='"';
	string str="";
	for(int i=0;i<s.size();i++){
		if(s[i]=='"'){
			v.push_back(str);
			str="";
		}
		else{
			str+=s[i];
		}
	}
}
int main(){
	while(1){
		string s1,s2; cin >>s1;
		if(s1==".")break;
		cin >> s2;
		if(s1==s2){
			cout << "IDENTICAL"<< endl;
		}
		else{
			vector<string> v1,v2;
			split(s1,v1);
			split(s2,v2);
			if(v1.size()!=v2.size()){
				cout << "DIFFERENT" << endl;
			}
			else{
				bool a=false;
				int cnt=0;
				for(int i=0;i<v1.size();i++){
					if(i%2==0){
						if(v1[i]!=v2[i])a=true;
					}
					else{
						if(v1[i]!=v2[i])cnt++;
					}
				}
				if(a){
					cout << "DIFFERENT" << endl;
				}
				else if(cnt>1){
					cout << "DIFFERENT" << endl;
				}
				else{
					cout << "CLOSE" << endl;
				}
			}
		}
	}
}


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

int gcd(int a, int b) {
	if (!b)return a;
	return gcd(b, a%b);
}
int b[500], r[500];
vector<int>E[1000];
bool used[1000];
int match[1000];

bool dfs(int u) {
	used[u] = true;
	for (int v : E[u]) {
		int w = match[v];
		if (w == -1 || (!used[w] && dfs(w))) {
			match[u] = v; match[v] = u;
			return true;
		}
	}
	return false;
}
int main() {
	int m, n;
	while (scanf("%d%d", &m, &n), m) {
		rep(i, 1000)E[i].clear();
		rep(i, m)scanf("%d", &b[i]);
		rep(i, n)scanf("%d", &r[i]);
		rep(i, m)rep(j, n) {
			if (gcd(b[i], r[j]) != 1)E[i].push_back(m + j);
		}
		memset(match, -1, sizeof(match));
		int ans = 0;
		rep(i, m) {
			if (match[i] == -1) {
				memset(used, 0, sizeof(used));
				if (dfs(i))ans++;
			}
		}
		printf("%d\n", ans);
	}
}

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

int main(void)
{
    int N;
    cin >> N;
    vector<long> A(N);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    long ans=A[0];
    int c=N-2;
    int k=1;
    while (c>0)
    {
        if (c>=2)
        {
           ans+=A[k]*2;
           c-=2; 
        }else
        {
            ans+=A[k];
            c--;
        }
        k++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  ll A[N], B[N];
  for (int i = 0; i <= N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  ll s = 0;
  for (int i = 0; i < N; i++) {
    s += min(A[i], B[i]);
    B[i] -= min(A[i], B[i]);
    A[i] -= min(A[i], B[i]);
    s += min(A[i + 1], B[i]);
    A[i+1] -= min(A[i + 1], B[i]);
  }
  cout << s << "\n";
  return 0;
}

Measured memory_bytes: 5136
def factorint(n):
    d = {}
    for factor in range(2, int(n ** 0.5) + 1):
        if n % factor == 0:
            power = 0
            while n % factor == 0:
                power += 1
                n /= factor
            d[factor] = power
    if n != 1:
        d[n] = 1
    return d

def sum_dicts(*dicts):
    d = {}
    for dict in dicts:
        for key in dict:
            try:
                d[key] += dict[key]
            except KeyError:
                d[key] = dict[key]
    return d

n = int(input())
d = {}
for i in range(1, n + 1):
    d = sum_dicts(d, factorint(i))
p = 1
for i in d.values():
    p *= i + 1
    p %= 10 ** 9 + 7
print(p)

Measured memory_bytes: 9368
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define MOD 1000000007 //10^9+7
#define INF 1000000000 //10^9

int main ()
{
    int n;
    vector<int> l;
    cin>>n;
    
    for (int i=0; i<n; i++) {
        l.clear();
        for (int i=0; i<3; i++) {
            int d;
            cin>>d;
            l.push_back(d);
        }
        sort(l.begin(), l.end());
        if (l[0]*l[0]+l[1]*l[1]==l[2]*l[2]) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 0
def main():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    c = list(map(int, input().split()))
    ans=0
    pre=-1
    for i,(a,b) in enumerate(zip(aa,bb)):
        ans+=b
        if a==pre+1:
            ans+=c[a-2]
        pre=a
    print(ans)

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int n;
	cin >> n;
	vecll a(n);
	rep(i, n) cin >> a[i];
	ll min = a[0];
	ll sum = 0;
	REP(i, 1, n)
	{
		if (min > a[i])
			sum += min - a[i];
		min = max(min, a[i]);
	}
	cout << sum << endl;
	return 0;
}

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

int main() {
    int sum = 0;
    for(int i=0;i<4;i++) {
        int t;
        cin >> t;
        sum += t;
    }
    cout << sum/60 << endl;
    cout << sum%60 << endl;
    return 0;
}



Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int serch(int p,int q,int a,int low,int n){
  int i,count,high;
  count = 0;
  if(p == 0) return 1;  
  if(n == 0) return 0;
 if(low < q / p) low = q / p ;
  if(a > q * n / p) high = q * n / p;
  else high = a;
  for(i = low;i <= high;i++){
   count +=  serch(p*i-q,q*i,a / i,i,n-1);
  }
  return count;
}

int main(){
  int p,q,a,n;
  while(1){
     scanf("%d%d%d%d",&p,&q,&a,&n);
       if(!(p|q|a|n)) break;
      cout << serch(p,q,a,1,n) << endl;
  }
return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

//最大公約数
ll gcd(ll a,ll b){
    if(b == 0LL) return a;
    return gcd(b , a % b);
}

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

}

//前後を比較
bool compare(int pos,vector<int>& a){
    if(a[pos] == a[pos + 1]) return true;
    else return false;
}

int main(){

    int N,M,Q;

    cin >> N >> M >> Q;

    vector<int> L(M);
    vector<int> R(M);
    vector<int> p(Q);
    vector<int> q(Q);

    for(int i = 0;i < M;i++) cin >> L[i] >> R[i];
    for(int i = 0;i < Q;i++) cin >> p[i] >> q[i];
    //二次元累積和
    vector<vector<int>> a(N + 1,vector<int>(N + 1,0));
    vector<vector<int>> sum(N+1,vector<int>(N + 1,0));
    //二次元の各マスに格納する
    for(int i=0;i < M;i++){
        //a[L[i]][R[i]]++;
        sum[L[i]][R[i]]++;
    }
    
    
    for(int i = 0;i < N;i++){
        for(int j = 0;j < N;j++){
            sum[i + 1][j + 1] += sum[i][j+1];
            sum[i + 1][j + 1] += sum[i + 1][j];
            sum[i + 1][j + 1] -= sum[i][j];

        }

    }

    //クエリ
    for(int i=0;i < Q;i++){
        cout << sum[q[i]][q[i]] - sum[q[i]][p[i]-1] - sum[p[i]-1][q[i]] + sum[p[i]-1][p[i]-1] << endl;

    }


}

Measured memory_bytes: 5248
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e9
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){

    int n,t,ans = INF;
    cin >> n >> t;
    vector<int> co(n),ti(n);
    REP(i,n){
        cin >> co[i] >> ti[i];
    }

    for(int i = 0;i < n;i++){
        if(ti[i] <= t){
            ans = min(ans,co[i]);
        }
    }
    if(ans == INF){
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
    }
  
    return 0;
}

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

const int maxn = 1e5 + 50;
int a[maxn];

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

    return 0;
}

Measured memory_bytes: 640
N, Y = map(int, input().split())

for a in range(N+1):
    y = Y - 10000*a
    if y < 0:
        break
    for b in range(N-a+1):
        z = y - 5000*b - 1000*(N-a-b)
        if z == 0:
            print("{} {} {}".format(a, b, N-a-b))
            break
    if z == 0:
        break
if z != 0:
    print("-1 -1 -1")


Measured memory_bytes: 3060
import heapq

N,K = map(int, input().split())
A = [int(a) for a in input().split()]

L = [0]*(N+1)
for i in range(N):
    L[A[i]] += 1
    
h = []
for i in range(N+1):
    if L[i] > 0:
        heapq.heappush(h, L[i])
        
ans = 0
while len(h) > K:
    ans += heapq.heappop(h)
    
print(ans)

Measured memory_bytes: 86992
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>

using namespace std;

using ll = long long;

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

  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  sort(va.begin(), va.end());

  vector<bool> memo(va.back() + 1, false);

  for (int i = 0; i < va.size(); i++) {
    ll a = va[i];
    for (ll j = a; j <= va.back(); j += a) {
      bool ex_r = i == va.size() - 1
                      ? false
                      : binary_search(va.begin() + i + 1, va.end(), j);
      if (ex_r) {
        memo[j] = true;
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i < va.size(); i++) {
    ll a = va[i];
    ans += !memo[a];
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 4844
n = int(input())
X = input()
int_x = int(X, 2)
mod = 998244353


def divisors(num):
    array = []
    limit = int(num ** 0.5) + 1
    for i in range(1, limit):
        if num % i == 0:
            div1 = i
            div2 = num//i
            array.append(div1)
            if div1 != div2:
                array.append(div2)
    array.sort()
    return array


def is_repeatable(block):
    """
    分割したブロックの個数から、繰り返し可能か判定
    ブロック数は１以外の奇数の時に繰り返し可能
    :param block: 全体の長さnを等間隔に分割した時の、ブロック数
    :return: 繰り返し可能ならTrue そうでないならFalse
    """
    if block == 1:
        return False
    else:
        if block % 2 == 1:
            return True
        else:
            return False


def get_small_repeatable_list(length):
    """
    ブロックの長さを引数として受け取り、
    この長さを元にして、さらに小さい繰り返し配列が作成可能かどうかを確認し、
    小さく繰り返し配列のブロック長さをリストで返す
    （ダブルカウントのチェック）
    例　長さ6のブロックを繋いだ　6_6^_6　の配列の場合
    　　(2_2^_2)_(2^_2_2^)_(2_2^_2)の繰り返し配列が作成できる
    :param length: ブロックの長さ
    :return: ダブルカウントしてしまっているもののリスト
    """
    small_blocks = divisors(length)
    small_length_list = []
    for small_block in small_blocks:
        if is_repeatable(small_block):
            small_length = length//small_block
            small_length_list.append(small_length)

    return small_length_list


ans = (2 * n * (int_x+1)) % mod
div_list = divisors(n)

blocks = []
for div in div_list:
    block = div
    if is_repeatable(block):
        blocks.append(block)

blocks.sort(reverse=True)
done = {}
for block in blocks:
    length = n // block
    forward = X[:length]
    reverse = 2**length-1 - int(forward, 2)
    reverse = format(reverse, '0'+str(length)+'b')
    count = int(forward, 2) + 1
    for i in range(1, block):
        if i % 2 == 1:
            compare = reverse
        else:
            compare = forward

        check = X[length*i:length*(i+1)]
        if compare == check:
            continue
        elif compare > check:
            count -= 1
            break
        elif compare < check:
            break

    small_repeatable_list = get_small_repeatable_list(length)
    for small_length in small_repeatable_list:
        double_count = done[small_length]
        count -= double_count

    done[length] = count
    ans -= 2*n*count
    ans += 2*length*count
    ans %= mod

print(ans)


Measured memory_bytes: 4032
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005
ll n,arr[3000];
ll dp1[3000][3000],dp2[3000][3000];
ll solve2(int,int);
ll solve1(int left,int right)
{
	if(left==right)
		return arr[left];
	else if(dp1[left][right]!=-1)
		return dp1[left][right];
	else
	{
		ll ans;
		ans=max(arr[left]+solve2(left+1,right),arr[right]+solve2(left,right-1));
		dp1[left][right]=ans;
		return ans;
	}
}
ll solve2(int left,int right)
{                              
	if(left==right)
		return -arr[left];
	else if(dp2[left][right]!=-1)
		return dp2[left][right];
	else
	{
		ll ans;
		ans=min(-arr[left]+solve1(left+1,right),-arr[right]+solve1(left,right-1));
		dp2[left][right]=ans;
		return ans;
	}
}
int main()
{
    fastread;
    cin>>n;
    for(int i=0;i<3000;i++)
    	for(int j=0;j<3000;j++)
    	{
    		dp1[i][j]=dp2[i][j]=-1;
    	}
    for(int i=0;i<n;i++)
    	cin>>arr[i];
    cout<<solve1(0,n-1)<<endl;
    return 0;
}

Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N, M;
    cin >> N >> M;
    vector<pll> v(N);
    ll a, b;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        v[i] = pll(a, b);
    }
    sort(v.begin(), v.end());
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll cnt = min(M, v[i].second);
        M = max(M - cnt, 0LL);
        ans += cnt * v[i].first;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 4812
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 30
int N,M;
int graph[MAX][MAX];
void solve(int *ans,int *stamp,int k){
    int f = 1;
    stamp[k] = 1;
    for(int i=1;i<=N;i++){
        if(stamp[i] == 0){
            f = 0;
            break;
        } 
    }
    if(f){
        (*ans)++;
        return;
    }

    for(int i=1;i<=N;i++){
        if(stamp[i] == 0 && (graph[k][i] || graph[i][k])){
            solve(ans,stamp,i);
            stamp[i] = 0;
        }
    }
}
int main(){
    int a[MAX],b[MAX];
    int stamp[MAX]={0};
    memset(graph,0,sizeof(graph));
    scanf("%d %d",&N,&M);
    for(int i=1;i<=M;i++){
        scanf("%d %d",a+i,b+i);
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = 1; 
    }
    int ans = 0;
    solve(&ans,stamp,1);
    printf("%d",ans);
}


Measured memory_bytes: 1732
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;
    string ans = "";
    
    for (int i = 0; i < k; i++) {
        if (s[i] != '1') {
            ans += s[i];
            cout << ans << endl;
            return 0;
        }
    }
    cout << "1" << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 256
module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Array
import           Data.Char

main = do
  n <- (read :: String -> Int) <$> getLine
  s <- getLine 
  let (fst, snd) = splitAt (n `div` 2) s
  putStrLn $ if fst == snd then "Yes" else "No"


Measured memory_bytes: 508
import fractions
def mygcd(N,A,S):
    if S == 'R':
        A.reverse()
    ans = [0, A[0]]
    for i in range(1, N):
        ans.append(fractions.gcd(ans[i],A[i]))
    if S == 'R':
        ans.reverse()
    return ans

def GCDonBlack(N,A):
    L = mygcd(N,A,'L')
    R = mygcd(N,A,'R')
    M = [fractions.gcd(L[i], R[i+1])  for i  in range(0,N)]
    return max(M)

N = int(input())
A = list(map(int, input().split()))
print(GCDonBlack(N,A))

Measured memory_bytes: 16144
N, K = map(int, input().split())
V = list(map(int, input().split()))
s = 0
for i in range(min(K, N)+1):
    r = K - i
    for j in range(i+1):
        k = i - j
        Q = sorted(V[:j] + V[N-k:])
        m = sum([q < 0 for q in Q])
        s = max(s, sum(Q[min(m, r):]))
print(s)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
main()
{
	long long a,b,x;
  cin >> a >> b >> x;

  long long c;
  if(a % x == 0){
    cout << b/x - a/x + 1 << "\n";
  } else {
    cout << b/x - a/x << "\n";
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int x, y;
	while(1) {
		cin >> x >> y;
		if ((x == 0) && (y == 0))
			break;
	
		if (x < y)
			cout << x << " " << y << endl;
		else
			cout << y << " " << x << endl;

	}

	return 0;
}




Measured memory_bytes: 3032
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = (int)3e18;
const int maxn = 2000100;



int main(){
        _
        int n; cin >> n;

        vll a(n);
        for(int i = 0; i<n; i++){
            cin >> a[i];
        }
        bool f = 0;
        ll mn = a[n-1];
        ll mx = inf;
        for(int i = n-2; i>=0; i--){
            if(a[i]>mn){
               if((a[i]-1)>mn){
                    cout<<"No"<<endl;
                    return 0;
               }
            }
            mn = min(mn,a[i]);
        }
        cout<<"Yes"<<endl;

return 0;
}




Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <limits.h>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll H[100007];
ll N,A,B;
priority_queue<ll> PQ;

bool check(ll X){
  ll cnt=0;
  rep(i,N){
    ll Y=H[i]-B*X;
    if(Y>0){
      cnt+=(Y+(A-B)-1)/(A-B);
    }
  }
  //cout << cnt << " ";
  if(cnt<=X){
    return 0;
  }
  else{
    return 1;
  }
}

int main(){
  cin >> N >> A >> B;
  rep(i,N){
    cin >> H[i];
    PQ.push(H[i]);
  }
  sort(H,H+N);
  reverse(H,H+N);
  ll ng=10000000001,ok=0;
  while(ng-ok>1){
    ll mid = (ok+ng)/2;
    //cout << mid << " " << check(mid) << endl;
    if(check(mid)){
      ok = mid;
    }
    else{
      ng = mid;
    }
  }
  cout << ng << endl;
}

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

#define ll long long

int main()
{
    ll n,ans=0;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
            ans+=i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;
using ld=long double;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

const int mod = TEN(9)+7;

int N;
int A, B;
vi v;
int comb[55][55];

void init()
{
	comb[0][0] = 1;
	for (int i = 1; i <= 50; ++i) {
		comb[i][0] = 1;
		for (int j = 1; j <= 50; ++j) {
			comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
		}
	}
}

signed main()
{
	cin >> N >> A >> B;
	v.resize(N);

	init();

	map<int, int> counter;
	
	rep(i, N) {
		cin >> v[i];
		counter[v[i]]++;
	}

	sort(all(v), greater<int>());
  
	int ans = 0;
	map<int, int> uses;

	for (int i = A; i <= B; ++i) {
		uses.clear();

		for (int j = 0; j < i; ++j) {
			uses[v[j]]++;
		}

		ans += comb[counter[v[i - 1]]][uses[v[i - 1]]];
		if (v[0] != v[i]) break;
	}

	printf("%.10f\n", (double)accumulate(begin(v), begin(v) + A, 0ll) / A);
	printf("%lld\n", ans);

	// A / i == B / j
}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    if(n%2 == 1){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0, div = 10;
    while(div <= n){
        ans += n / div;
        div *= 5;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N, K; cin >> N >> K;
  vector<int> l(N); rep(i, 0, N){ cin >> l[i]; }
  sort(all(l));
  cout<<accumulate(l.end()-K,l.end(),0ll)<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
	//Implement solution here.
		int max = -1;
		int min = Integer.MAX_VALUE;
		for(int i = 0; i < 5; i++) {
			int v = ni();
			max = Math.max(v, max);
			min = Math.min(v, min);
		}
		
		int k = ni();
		if(max - min > k) {
			System.out.println(":(");
		}else {
			System.out.println("Yay!");
		}
	}

    //Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
            	br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main() {
    int n,d;
    cin >> n >> d;
    int cur = 2 * d + 1;
    int ans = 1;
    while(n > cur){
        ans++;
        cur += 2 * d + 1;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
package main

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

var (
	scanner = bufio.NewScanner(os.Stdin)
	w       = bufio.NewWriter(os.Stdout)
)

func readInt() (read int) {
	scanner.Scan()
	read, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return
}

func main() {
	scanner.Split(bufio.ScanWords)
	defer w.Flush()

	n := readInt()
	k := readInt()
	p := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = readInt()
	}

	sort.Ints(p)

	ans := 0
	for i := 0; i < k; i++ {
		ans += p[i]
	}
	fmt.Println(ans)
}

Measured memory_bytes: 1780
#include <stdio.h>

int main() {
  
  //a:doing b:sleeping c:down time
  
  int a,b,c;
  int i,j,k,time;
  int flag,t;  
  int sts,gtime;
  
  scanf("%d %d %d",&a,&b,&c);

  flag = 0;
  time = 0;
  i=0;
  sts = 0;
  gtime = c;
  t = -1;
  k = 0;

  if(a - c >=0) time = c;
  else {

    while(1) {  
      k++;
      if(k > 6000) {
	flag = 1;
	break;
	} 
      
      if(sts == 0 && gtime == time) {
	break;
     
      } else if(sts == 1 && gtime == time) {
	time += 60/(a+b) * (a+b)-1;
	//	printf("%d\n",time);
	i--;
	gtime += 60;
      }
      
      if(i == a && sts == 0) {
	i = 0;
	sts = 1;
      }
      if(i == b && sts == 1) {
	i=0;
	sts = 0;
      }
     
      i++;
      time++;
    }
  }

  //  printf("k = %d\n",k);

  if(flag == 1) printf("-1\n");
  else printf("%d\n",time);

  return 0;

}

Measured memory_bytes: 596
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    a_list = [int(i) for i in input().split()]
    b_list = [int(i) for i in input().split()]

    cnt = 0
    for i, b in enumerate(b_list):
        a = a_list[i]
        if a <= b:
            combo = a
            b = b - a
            a = a_list[i + 1]
            if a <= b:
                combo += a
                a = 0
            else:
                combo += b
                a -= b
            a_list[i + 1] = a
        else:
            combo = b

        cnt += combo
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19228
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
  int A, B;
  cin >> A >> B;
  if (A == 0) {
    cout << "! " << string(B, '0') << endl;
    return 0;
  }
  if (A <= B) {
    cout << "Impossible" << endl;
    return 0;
  }
  const int N = A + B;
  int honto = 0, y = 0, n = 0;
  for (int i = 1; i < N; ++i) {
    cout << "? " << i << " " << honto << endl;
    string s;
    cin >> s;
    if (s == "Y") ++y;
    else ++n;
    if (n > y) {
      honto = i;
      y = 0; n = 0;
    }
  }
  vector<int> res(N);
  res[honto] = 1;
  REP(i,N) {
    if (i == honto) continue;
    cout << "? " << honto << " " << i << endl;
    string s;
    cin >> s;
    if (s == "Y") res[i] = 1;
    else res[i] = 0;
  }
  cout << "! ";
  REP(i,N) cout << res[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 848
s = input()

for i in range(len(s)):
  if i % 2 == 0:
    if s[i] == 'L':
      print('No')
      break
  else:
    if s[i] == 'R':
      print('No')
      break
  
  if len(s)-1 == i:
    print('Yes')

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

int main() {
	int H,W,D,A,Q,L,R;
	cin >> H >> W >> D;
	vector<vector<int>> m(H, vector<int>(W,0));
	vector<P> p(H*W);

	rep(i,H)
		rep(j,W) {
			cin >> A;
			p.at(A-1) = P(i,j);
		}

	rep(i,D) {
		int x=i+D;
		while(x < H*W) {
			int sy=p.at(x-D).first, sx=p.at(x-D).second, ty=p.at(x).first, tx=p.at(x).second;
			m.at(ty).at(tx) = m.at(sy).at(sx) + abs(sy-ty) + abs(sx-tx);
			x += D;
		}
	}

	// rep(i,H) {
	// 	rep(j,W)
	// 		cout << m.at(i).at(j) << " ";
	// 	cout << endl;
	// }

	cin >> Q;
	rep(i,Q) {
		cin >> L >> R;
		--L, --R;
		cout << m.at(p.at(R).first).at(p.at(R).second)-m.at(p.at(L).first).at(p.at(L).second) << endl;
	}
}

Measured memory_bytes: 2176