akhauriyash/Code-Regression huggingface dataset:
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  reverse(a,a+n);
  ans=a[0];
  cnt=1;
  rrep(i,1,n){
    if(cnt==n-1)break;
    ans+=a[i];
    cnt++;
    if(cnt==n-1)break;
    ans+=a[i];
    cnt++;
    if(cnt==n-1)break;
  }
  Cout(ans);
  return 0;
}


Measured memory_bytes: 5236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17
ll ceil(ll a,ll b){
    if(b==0)return 0;
    return (a+b-1)/b;
}
int main(){
    ll n,k;cin>>n>>k;
    ll a[MAX2];
    rep(i,n)cin>>a[i];
    int max_a=0;
    rep(i,n){
        chmax(max_a,a[i]);
    }
    ll right=max_a;
    ll left=0;
    while(right-left>1){
        ll x=(right+left)/2; //全ての丸太をxいかにできるか
        ll cut=0;
        rep(i,n){
            cut+=ceil(a[i],x)-1;
        }
        if(cut<=k)right=x;
        else left=x;
    }
    cout<<right<<endl;
}

Measured memory_bytes: 5080
S = input()
#N = int(input())
#N = int(input())
#S = input()
#M,N = map(int,input().split())
#M,N = map(int,input().split())
#A = list(map(int,input().split()))
#A = list(map(int,input().split()))


if S.isupper():
    print("A")
else:
    print("a")

Measured memory_bytes: 8960
# ABC138E - Strings of Impurity
from bisect import bisect_left as bs
from collections import defaultdict


def main():
    S, T = tuple(input() for _ in range(2))
    idx, ls = defaultdict(list), len(S)
    for i, s in enumerate(S):
        idx[s] += [i]
    roop, cur = 0, -1
    for t in T:
        tgt = idx[t]
        if tgt == []:  # t not in S
            print(-1)
            return
        x = bs(tgt, cur + 1)
        if x < len(tgt):
            cur = tgt[x]
        else:
            cur = tgt[0]
            roop += 1
    print(roop * ls + cur + 1)


if __name__ == "__main__":
    main()

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

int main()
{
	int a, b, k;

	cin >> a >> b >> k;

	int p = a, q = b, r;

	while (q > 0) {
		r = p % q;
		p = q;
		q = r;
	}

	int j = 0;

	for (int i = p; i > 0; i--) {
		if (p % i == 0)
			j++;

		if (j == k) {
			cout << i << endl;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#define mm(i,v) memset(i,v,sizeof i);
using namespace std;
typedef long long ll;
const int mod=1e9+7;

char s,t;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>s>>t;
	if(s!='H'){
		if(t=='H')
			t='D';
		else
			t='H';
	}
	cout<<t<<"\n";
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	char a[2];
	f(i, 2)a[i] = 0;
	int n;
	bool v = false;
	scanf("%d", &n);
	f(i,n){
		scanf("%s", a);
		if (a[0] == 'Y')v = true;
	}
	if(!v)printf("Three\n");
	else printf("Four\n");
return 0;
}

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

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

typedef long long ll;
using namespace std;

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

  ll R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;
  REP(r, 3001) {
    REP(g, 3001) {
      ll n = N - (R * r + G * g);
      if (n < 0) {
        continue;
      }

      if (n == 0 || n % B == 0) {
        ++ans;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())

#NがA+Bかどうか
#NがA+B以上ならA+Bをわったあまりを判定

if N <= A+B:
  if N<= A:
    print(N)
  else:
    print(A)
    
else:
  if N%(A+B) <= A:
    print((N//(A+B))*A+(N%(A+B))) 
  else:
    print((N//(A+B))*A+A)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll a , b;
  cin >> a >> b;
  if(a==1)a=14;
  if(b==1)b=14;
  if(a>b)
    cout << "Alice" << endl;
  else if(b>a)
    cout << "Bob" << endl;
  else 
    cout << "Draw" << endl;
    
}


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

int main() {
  int N;
  cin >> N;
  char x;
  int y = 0;
  for (int i = 0; i < N; i++) {
  cin >> x;
  if (x == 'Y') {
  y++;
  }
  }
  if (y == 0) {
  cout <<"Three" << endl;
  }
  else  {
  cout << "Four" << endl;
  }
}



Measured memory_bytes: 256
//PseudoName

    #pragma GCC optimize("O3")
    #include <bits/stdc++.h>
/*
	#include <ext/pb_ds/assoc_container.hpp>
	#include <ext/pb_ds/tree_policy.hpp>
	using namespace __gnu_pbds;
	template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
    #define FOR(i,n) for(i=0;i<n;i++)
    #define FOR1(i,n) for(i=1;i<=n;i++)
    #define FOR2(I, A, B) for (int I = (A); I <= (B); ++I)
    #define pb push_back
    #define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
    #define print(v) for(auto it:v)cout<<it<<" ";cout<<endl
    #define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define endl "\n"
    #define min3(a,b,c) min(a,min(b,c))
    #define forr(n) for(int i=0;i<n;i++)
    #define frr(n) for(int i=1;i<=n;i++)
    #define MAX 200005
    #define inf 200008

    using namespace std;

    typedef long long ll;
    typedef long li;
    typedef vector<int> vi;
    typedef vector<ll> vli;
    typedef vector<vi> vvi;
    typedef vector<vli> vvli;
    typedef pair<int,int> pi;
    typedef pair<ll,ll> pli;
    typedef vector<pi> vpi;
    typedef vector<pli> vpli;



    int main() {
       ll n,k;
       cin>>n>>k;
       ll m=n%k;

       cout<<min(abs(m-k),m);




    }


Measured memory_bytes: 256
ss = str(input())
tt = str(input())
#print(ss,tt)
maxmatch = 0
#
for i in range(len(ss)-len(tt)+1):
    nofmatch = 0
    for j in range(len(tt)):
        #print(ss[i + j], tt[j])
        if ss[i+j] == tt[j]:
            nofmatch += 1
    if nofmatch > maxmatch:
        maxmatch = nofmatch

print(len(tt)-maxmatch)

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

int main()
{
  int vec[10];
  for(int i=0; i<10; i++){
  cin >> vec[i];
  }
  sort(vec, vec + 10);
  for(int i=9; i>6; i--){
    cout << vec[i] << endl;
  }
}

Measured memory_bytes: 1176
s = input()
l = len(s)
o = ["R", "U", "D"]
e = ["L", "U", "D"]
x = 1
for i in range(l):
    if i == (2 * int(i / 2)):
        if s[i] not in o:
            x = 0
    else:
        if s[i] not in e:
            x = 0
print("Yes" if x == 1 else "No")

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i++)
#define RFOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i--)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
using ll = long long;

constexpr int lim = 1e5;
ll a[lim+1], l[lim+1], r[lim+1];
ll k;

int main(){
  cin >> k;
  FOR(i, 1, k+1) cin >> a[i];
 
  l[k] = r[k] = 2;

  RFOR(i, k, 0){
    r[i-1] = r[i]/a[i]*a[i] + a[i] - 1;
    l[i-1] = (ll)ceil(l[i]*1.0/a[i]) * a[i];
    if(r[i-1] < l[i-1]){
      cout << -1 << endl;
      return 0;
    }
  }

  cout << l[0] << " " << r[0] << endl;

  return 0;
}


Measured memory_bytes: 2560
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

int n, s, v, mem, t[100], lm[40001];
double ac[40001], ans;

/*
ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}*/



int main(){
	cin >> n;
	s = 0;
	lp(n)
		cin >> t[i];
	lp(n) {
		cin >> v;
		for (int j = s * 2; j <= (s + t[i]) * 2; j++)
			lm[j] = v;
		s += t[i];
	}
	ac[0] = 0;
	lp(s * 2 - 1) {
		ac[i + 1] = (ac[i] + 0.5 > lm[i] ? lm[i] : ac[i] + 0.5);
	}
	ac[s * 2] = 0;
	for (int i = s * 2 - 1; i >= 0; i--) {
		ac[i] = min(ac[i], (ac[i + 1] + 0.5 > lm[i] ? lm[i] : ac[i + 1] + 0.5));
	}
	ans = 0;
	lp(s * 2) {
//		printf("%.1f", double(i) / 2);
//		cout << sp << ac[i] << endl;
		ans += (ac[i] + ac[i + 1]) / 4;
	}
	printf("%.4f",ans);
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <bits/stdc++.h> 
#include <string>

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vi, greater<int>> mpqi;

#define IOS std::ios::sync_with_stdio(false); cin.tie(0);
#define F0R(i,a) for(int i = 0; i < a; i++)
#define R0F(i,a) for(int i = a - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define ins insert
#define ft front()
#define bk back()
#define f first
#define s second
#define trav(a,x) for(auto& a : x)
#define ALL(x) (x).begin(), (x).end()

const int MOD = 1000000007;
const int MX = 1e5+2;
const ll INF = 1000000000000000000;
const ld PI = 4*atan((ld)1);
const pi dir[4] = {{1,0}, {0,1}, {-1,0}, {0,-1}};

// -----------

// ABC 157 D

int n, m, k, a, b;
vi frd[MX];
pi bs[MX];
vi comp[MX];
int compon[MX];
bool visit[MX];
int potent[MX];
int currentComponent;
int ans[MX];

void dfs(int node, int currComp){
    visit[node] = true;
    compon[node] = currComp;
    comp[currComp].pb(node);
    trav(x,frd[node]){
        if(!visit[x]) dfs(x, currComp);
    }
}

int main(){
    IOS;
    cin >> n >> m >> k;
    F0R(i,m){
        cin >> a >> b;
        frd[a].pb(b);
        frd[b].pb(a);
    }
    F0R(i,k){
        cin >> a >> b;
        bs[i] = mp(a,b);
    }
    currentComponent = 1;
    F0R(i,n){
        if(!visit[i+1]){
            dfs(i+1, currentComponent);
            currentComponent++;
        }
        ans[i+1] = 0;
    }
    F0R(i,k){
        if(compon[bs[i].f] == compon[bs[i].s]){
            ans[bs[i].f]--; ans[bs[i].s]--;
        }
    }
    for(int i = 1; i <= n; i++){
        ans[i] += (int)comp[compon[i]].size();
        ans[i] -= (int)frd[i].size();
        cout << ans[i] - 1 << " ";
    }
    return 0;
    // You should actually read the notes to self.
}

/* NOTES TO SELF:
    Int overflow? Array bounds?
    Edge cases? (n = 1, n = 0)
    Don't be dumbosity please pace yourself.
*/

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

using namespace std;

int main(){
	
    string a , b;
    cin >> a >> b;
    
    int i , total = -1;
    for (i =0 ; i<= a.length()-b.length() ; i++ ){
        int count = 0;
        int c = i;
            for(int j = 0 ; j < b.length(); j++,c++){
                if(a[c] == b[j]){
                count ++;
                }
            }
        if(count > total){
            total = count ;
        }
   }
   
   cout << b.length() - total ;
   
   return 0;
}

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

int main(){
    int A, B, K;
    cin >> A >> B;
    int ave = (A + B) / 2;
    int ans = ave;
    if(((A + B) % 2) != 0){
        A = 0;
    }
    if(A != 0){
        cout << ave << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}


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

using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


#define BOOST        ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define AZ(x)        x.begin(),x.end()
#define fi           first
#define se           second
#define pb           push_back
#define emp          emplace_back
#define mp           make_pair
#define mt           make_tuple
#define debug(x)     cerr << #x << " : " << x << endl;
#define For(i,a,n)   for(auto i = a; i < n; i++)


template<typename T> using V = vector<T>;
template<typename T, typename U> using P = pair<T,U>;

typedef long long ll;
typedef long double ld;


template<typename T>
// for super_map add a parameter Y above and replace "null_type" with "Y"

// set with two additional super powers
    // find_by_order(int k) - returns k'th smallest element (0-indexed)
    // order_of_key(int k) - returns number of elements strictly smaller than k.
using super_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


const int mod = 1e9+7, N = 1e5+5;
const ll INF = 1e18;



ll power(ll a,ll b)
{
    a = a%mod;
    ll result = 1;

    while(b)
    {
        if(b&1)
            result = (result*a)%mod;
        b >>= 1, a = (a*a)%mod;
    }
    return result;
}

ll super_rand(ll n) // Random number from set [0,n-1]
{
    uniform_int_distribution<ll> uid(0, n - 1);
    return uid(rng);
}



/*



1. Make sure you're taking all the inputs.
2. In case of nested loops, remember to use different variables.
3. If in doubt, do int -> ll
4. Don't fight the question, try solving the next one.
5. ffs (positon of first set bit), clz (leading 0s, max->32), ctz (trailing 0s), popcount (set bits). Don't use any of these on 0;



*/



// Don't code anything above this //
int dp[105][100005];		
							// dp[i][j] : number of ways to distribute j candies among first i kids;
							// dp[i][j] : dp[i-1][j] + dp[i-1][j-1] + dp[i-1][j-2] +....+ dp[i-1][j - a[i]]
void add_self(int &a, int b)
{
	a += b;
	if( a >= mod )
		a -= mod;
}

void sub_self(int &a, int b)
{
	a -= b;
	if( a < 0)
		a += mod;
}

int main()
{
    BOOST

    int n, k;
    
    cin >> n >> k;
    
    int a[n+1];

    for(int i = 1; i <= n; i++)
    	cin >> a[i];
    
    for(int i = 0; i <= a[1]; i++)
    	dp[1][i] = 1;
    
    for(int i = 2; i <= n; i++)
    {
    	for(int j = 1; j <= k; j++)
    		add_self(dp[i-1][j],dp[i-1][j-1]);
    	
    	for(int j = 0; j <= k; j++)
    	{
    		add_self(dp[i][j],dp[i-1][j]);

    		if(j > a[i])
    			sub_self(dp[i][j],dp[i-1][j-a[i]-1]);
    	}
    }

    // for(int i = 1; i <= n; i++)
    // 	for(int j = 0; j <= k; j++)
    // 		cout << dp[i][j] << " \n"[j == k];

    int ans = 0;
    
    cout << dp[n][k] << "\n";

    return 0;
}



Measured memory_bytes: 40832
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int cards[4][13];
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            cards[i][j]=false;
        }
    }
    int N,rank;
    char ch;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>ch>>rank;
        if(ch=='S'){
            ch=0;
        }
        if(ch=='H'){
            ch=1;
        }
        if(ch=='C'){
            ch=2;
        }
        if(ch=='D'){
            ch=3;
        }
        cards[ch][rank-1]=true;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            if(cards[i][j]==false){
                if(i==0){
                    cout<<'S'<<" "<<j+1<<endl;
                }
                if(i==1){
                    cout<<'H'<<" "<<j+1<<endl;
                }
                if(i==2){
                    cout<<'C'<<" "<<j+1<<endl;
                }
                if(i==3){
                    cout<<'D'<<" "<<j+1<<endl;
                }
            }
        }
    }
}



Measured memory_bytes: 3096
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;


int main() {

	int a[200000];
	int b[200000];
	int last = 0;
	int size;

	cin >> size;

	int method;
	int last2 = 0;

	for (int i = 0; i < size; i++) {
		cin >> method;

		if (method == 0) {
			cin >> method;
			a[last] = method;
			last++;
		}
		else if (method == 1) {
			cin >> method;
			b[last2] = a[method];
			last2++;
		}else if(method == 2){
			last--;
		}else {
			printf("異常終了\n");
			return -1;
		}
	}

	for (int i = 0; i < last2; i++) {
		printf("%d\n", b[i]);
	}

//	system("pause");
	return 0;
}


Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
int num[105];
int main()
{
    int n,m;
    float tot=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>num[i];
        tot+=num[i];
    }
    tot/=4;
    tot/=m;
    sort(num,num+n,greater<int>());
    for(int i=0;i<m;i++)
    {
        if(num[i]<tot){cout<<"No"<<endl;return 0;}
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int k,n,sum=0;
  std::cin >> n >>k;
  int a[n];
  for(int i=0; i<n; i++) std::cin >> a[i];

  sort(a,a+n);
  for(int i=n-1; i>=n-k; i--){
    sum+=a[i];
  }

  std::cout << sum << '\n';
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	string str;
	cin >> n >> str;
	if (n % 2)
	{
		cout << "No" << endl;
	}
	else
	{
		string str1 = str.substr(0, n / 2);
		string str2 = str.substr(n / 2, n / 2);
		if (str1 == str2)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;

		}
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int main(){
  string s,t;
  cin>>s>>t;
  int flag=0;
  vector<int> ind;
  int ans=0;
  for(int i=0;i+t.size()<=s.size();i++){
    if(s[i]==t[0]||s[i]=='?'){
      flag=0;
      for(int j=0;j<t.size();j++){
        if(s[i+j]==t[j]||s[i+j]=='?'){
          flag=1;
        }else{
          flag=0;
          break;
        }
      }
      if(flag==1){
        ind.push_back(i);
        ans=1;
      }
    }
  }
 
  string anss=s;
  string ans2(s.size(),'z');
 
  if(ans==1){
    for(int k=0;k<ind.size();k++){
      for(int i=0;i<s.size();i++){
        if(i<ind[k]||i>=ind[k]+t.size()){
          if(s[i]=='?'){
            anss[i]='a';
          }else{
            anss[i]=s[i];
          }
        }else if(i==ind[k]){
          for(int j=0;j<t.size();j++){
            anss[i+j]=t[j];
          }
          i=ind[k]+t.size()-1;
        }
      }
      ans2=min(ans2,anss);
    }
  }else{
    cout<<"UNRESTORABLE"<<endl;
    return 0;
  }
  cout<<ans2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  char c;
  cin >> c;
  vector<char> vo = {'a','i','u','e','o'};
  bool flag = 1;
  for (int i=0; i<5; i++) {
    if (vo[i] == c) {
      cout << "vowel" << endl;
      flag = 0;
      break;
    }
  }
  if (flag) cout << "consonant" << endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FILEIN freopen("input.txt", "r", stdin)

#define ll long long
#define endl "\n"

int main(){
	// FILEIN;
	map<ll, ll> m;
	ll n, a, flag = 0; cin>>n;
	for(int i = 0; i<n; i++){
		cin>>a;
		if(m[a]){
			flag = 1;
			break;
		}
		m[a]++;
	}
	if(flag){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
}

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

int main()
{
    int n;
    cin >> n;
    int count = 0;
    vector<int> p(n);
    vector<int> q(p.size());
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    copy(p.begin(), p.end(), q.begin());
    sort(q.begin(), q.end());
    for (int i = 0; i < n; i++)
    {
        if (p[i] == q[i])
            count++;
    }
    /*
    for (int i = 0; i < n; i++)
    {
        cout << "p[" << i << "]:" << p[i] << " ";
    }
    cout << "" << endl;

    for (int i = 0; i < n; i++)
    {
        cout << "q[" <<i << "]:" << q[i] << " ";
        }
    cout << "" << endl;
    cout << "x:" << x << endl;
    */
    int x = p.size() - 2;
    if (count - x >= 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = input().split()
    S = 0
    ans = []
    for n in range(N):
        ans.append(0)
        A[n] = int(A[n])
        S += A[n]
    ans[0] = S
    for n in range(N)[1::2]:
        ans[0] -= 2 * A[n]
    for n in range(N)[1:]:
        ans[n] = 2 * A[n - 1] - ans[n - 1]
    for n in range(N):
        if n == N - 1:
            print(ans[n])
        else:
            print(str(ans[n]) + " ", end="")

if __name__ == '__main__':
    main()


Measured memory_bytes: 12336
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<climits>
#include<stack>
#include<unordered_map>
#include<map>
#include<set>

#define loopi(x,y) for(int i = x;i<(y);i++)
#define rloopi(x,y) for(int i = x;i>=(y);i--)
#define rloopj(x,y) for(int j = x;j>=(y);j--)
#define loopj(x,y) for(int j = x;j<(y);j++)


#define nl cout<<"\n";
#define ll long long int
using namespace std;
#define mod  1000000007

ll power(ll a, ll p)
{
	if (p == 0)
		return 1;

	ll t = power(a, p / 2) % mod;

	if (p % 2 == 0)
		return t * t % mod;
	return (a * t % mod) * t % mod;
}

int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(nullptr);
	// ios_base :: sync_with_stdio(false);
	// cin.tie(NULL);

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	int n, W;
	cin >> n >> W;
	vector<int> w(n);
	vector<int> v(n);
	ll max_val = 0;

	loopi(0, n)
	{
		cin >> w[i] >> v[i];
		max_val += v[i];
	}

	vector<int> dp(max_val + 1, 1000000001);
	dp[0] = 0;
	loopj(0, n)
	{
		rloopi(max_val, v[j])
		{
			dp[i] = min(dp[i - v[j]] + w[j], dp[i]);

		}
	}

	int ans;
	rloopi(max_val, 0)
	{
		if (dp[i] <= W)
		{
			ans = i;
			break;
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 640
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;
u64 over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  u64 n, a, b;
  cin >> n >> a >> b;
  u64 prev, x;
  cin >> prev;
  u64 ans = 0;
  for (u64 i = 0; i < n; ++i) {
    cin >> x;
    ans += min((x-prev)*a, b);
    prev = x;
  }
  cout << ans << endl;
  return 0;
}


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

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

  int w[100];
  int v[100];
  for(int i=0; i<N; i++){
    cin >> v[i] >> w[i];
  }


  int DP[N+1][W+1];

  for(int j=0; j<=W; j++)
    DP[0][j] = 0;

  for(int i=1; i<=N; i++)
    for(int j=0; j<=W; j++)
      if(j<w[i-1]){
        DP[i][j] = DP[i-1][j];
      }else{
        if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1])
          DP[i][j] = DP[i-1][j];
        else
          DP[i][j] = DP[i-1][j-w[i-1]]+v[i-1];
        }



  cout << DP[N][W] << endl;

  return 0;
}



Measured memory_bytes: 7028
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>  //setprecision(桁)
using namespace std;
#define pb push_back
#define rep(i,n) for(int i = 0;i < n;i++)
#define INF 1e+9

struct edge {
    int to;
    double cost;
};

// <最短距離, 頂点の番号>
using P = pair<double, int>;

int V;
const int ci = 2e5+ 5;
vector<edge> G[ci];
double d[ci];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) { //cout << "On" << endl;
        P p = que.top();
        que.pop();
        int v = p.second; //cout << "v=" << v << endl;
        if (d[v] < p.first) continue;
        for (int i=0; i<G[v].size(); i++) {
            edge e = G[v][i]; //cout << "koo" << endl;
            if (d[e.to] > d[v] + e.cost) { //cout << e.cost << endl;
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
    string s; cin >> s;
    int n = s.size();
    rep(i,n){
        if(s[i]== '?') s[i] = 'D';
    }
    cout << s << endl;
}

Measured memory_bytes: 8420
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

// mod.m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while(b){
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>=1;
    }
    return res;
}


int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = a*c;
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    cout << ans << endl;
}




Measured memory_bytes: 3632
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B = map(int,read().decode('utf8').split())
print(2*B-A)


Measured memory_bytes: 3060
#include<cstdio>
int main(){
	int n;
	scanf("%d",&n);
	if(n==1){
		int x;
		scanf("%d",&x);
		printf("%d",1);
	}
	else{
		int x;
		x=0;
		int a[100000]={};
		for(int i=0;i<n;i++){
			int c;
			scanf("%d",&c);
			a[c]++;
			a[c-1]++;
			a[c+1]++;
			if(c>x){
				x=c;
			}
		}
		int m;
		m=0;
		m=a[0];
		for(int i=1;i<=x;i++){
			if(a[i]>m){
				m=a[i];
			}
		}
		printf("%d",m);
	}
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    string a,b;
    cin >> a >> b;
    int c,d;
    cin >> c >> d;
    string e; 
    cin >> e;
    if(e==a)
      cout << c-1 <<" " << d << endl;
    else if(e==b)
      cout << c<<" " << d-1 << endl;
    else
    cout << c << " "<< d << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
ll euclidean_gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}


int main() {
  int h, w;
  cin >> h >> w;
  vector<string> c(h);
  rep(i,h) cin >> c[i];
  rep(i,h){
    cout << c[i] << endl;
    cout << c[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long

 int h,w;
 
  string a[2050];
  int mp[2050][2050]={0};
  int ans=0;

signed main(){
  cin>>h>>w;
  int cnt;
  rep(i,h){
    cin>>a[i];
  }
  int nowmx=0;
  int nowx,nowy;
  rep(i,h){
    cnt=0;
    rep(j,w){
      if(a[i][j]=='.'){
	cnt++;
      }
      else{
	repi(k,j-cnt,j){
	  mp[i][k]+=cnt;
	}
	cnt=0;
      }
    }
    repi(k,w-cnt,w){
      mp[i][k]+=cnt;
    }
  }
  cnt=0;
  rep(i,w){
    cnt=0;
    rep(j,h){
      if(a[j][i]=='.'){
	cnt++;
      }
      else{
	repi(k,j-cnt,j){
	  mp[k][i]+=cnt;
	}
	cnt=0;
      }
    }
    repi(k,h-cnt,h){
      mp[k][i]+=cnt;
    }
  }
   
  rep(i,h){
    rep(j,w){
      ans=max(ans,mp[i][j]);
      //  cout<<mp[i][j]<<" ";
    }
    // cout<<endl;
  }
  cout<<ans-1<<endl;
  return 0;
}


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

int T;

int main()
{
	scanf("%d",&T);
	while(T--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(a==b)
		{
			printf("%d\n",a*2-2);
			continue;
		}
		if(a>b)
			swap(a,b);
		long long x=1LL*a*b;
		int l=0,r=b;
		while(r-l>1)
		{
			int m=(l+r)>>1;
			int A=a+1,B=m;
			int C=A+(B-A)/2;
			if(1LL*C*(A+B-C)<x)
				l=m;
			else
				r=m;
		}
		printf("%d\n",a-1+l);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    ll N,K;cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        int b;cin>>b;
        b--;
        A[i] = b;
    }
    vector<bool> a(N,false);
    int to = 0;
    int start;
    while(1){
        if(a[to]==true){
            start = to;
            break;
        }else{
            a[to] = true;
            to = A[to];
        }
    }
    for(int i=0;i<N;i++){
        a[i] = false;
    }
    to = 0;
    bool b_or_a = false;
    if(start==0) b_or_a = true;
    vector<int> aloop;
    vector<int> bloop;
    while(1){
        if(b_or_a){
            if(a[to]) break;
            aloop.push_back(to);
        }else{
            if(to==start){
                b_or_a = true;
                aloop.push_back(to);
            }else{
                bloop.push_back(to);
            }
        }
        a[to] = true;
        to = A[to];
    }
    if(K<=(ll)bloop.size()-1){
        cout << bloop[K] + 1 << endl;
    }else{
        K -= bloop.size();
        K %= aloop.size();
        cout << aloop[K] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 5132
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int ans=0;
    int n,m;
    cin >> n >> m;
    vector<pair<int,bool>> v;
    rep(i,n){
        int a;
        cin >> a;
        v.push_back({a,true});
    }
    rep(i,m){
        int a,b;
        cin >> a >> b;
        if(v[a-1].first>=v[b-1].first){
            v[b-1].second = false;
        }if(v[a-1].first<=v[b-1].first){
            v[a-1].second = false;
        }
    }
    for(auto x:v){
        if(x.second){
            ans++;
        }
    }
    cout << ans << endl;
}


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


int main()
{
    string s, t;
    cin >> s;
    cin >> t;

    vector<set<int>> pos(26);
    for(int i = 0; i < s.size(); ++i) pos[s[i]-'a'].insert(i);

    long long ans = 1;
    int prev_pos;
    for(int i = 0; i < t.size(); ++i){
        int num = t[i]-'a';
        if(pos[num].empty()){
            ans = -1;
            break;
        }else{
            if(i == 0){
                prev_pos = *pos[num].begin();
                ans += prev_pos;
            }else{
                auto itr = pos[num].upper_bound(prev_pos);
                // cout << i << " " << prev_pos << " " << *itr << " ";
                if(itr == pos[num].end()){
                    ans += (long long) s.size()-prev_pos+*pos[num].begin();
                    prev_pos = *pos[num].begin();
                    // cout << " no" << endl;
                }else{
                    ans += (long long) *itr-prev_pos;
                    prev_pos = *itr;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int n;
	string s;
	cin >> s;
	n = s.size();
	
	int ret = 0;
	rep(i,n){
		if(s[i] == 'g')ret ++;
		else ret --;
	}
	ret -= n%2;
	
	cout << ret/2 << endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h> 
using namespace std;
long long n, a[101];
int main(){
  cin >> n;
  int cnt = n;
  for(int i = 0;i < n; i ++){
    cin >> a[i];
	}
    for(int i = n; i > 0; i --){
      for(int j = 0; j < i; j++){
        if(a[i] < a[j]){
        cnt --;
        break;
		}
    }
  }
    cout << cnt+1;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W, K;
  cin >> H >> W >> K;
  string c[H];
  for (int i = 0; i < H; i++) {
    cin >> c[i];
  }
  int ans = 0;
  for (int s = 0; s < (1 << H) - 1; s++) {
    for (int t = 0; t < (1 << W) - 1; t++) {
      int cnt = 0;
      for (int i = 0; i < H; i++) {
        if ((s >> i) & 1) continue;
        for (int j = 0; j < W; j++) {
          if ((t >> j) & 1) continue;
          if (c[i][j] == '#') cnt++;
        }
      }
      if (cnt == K) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std; 

int main()
{
    string name;
    int W, H, x, y, r; // 0+r=x, W-r x
    
    cin >> W >> H >> x >> y >> r;
    if ((x >= r) && (x <= W - r) && (y >= r) && (y <= H - r)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    


}


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

int main(){
  int X, A, B;
  cin >> X >> A >> B;
  
  if(B > A + X){
    cout << "dangerous" << endl;
  }
  else if(B <=  A){
    cout << "delicious" << endl;
  }
  else{
    cout << "safe" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	int n; cin >> n;

	vector<int> as(n);
	for (auto& a : as) {
		cin >> a;
	}

	int sum = 0;
	FOR_LT(i, 0, n) {
		int b; cin >> b;
		sum += b;
	}

	vector<int> cs(n - 1);
	for (auto& c : cs) {
		cin >> c;
	}

	FOR_LT(i, 0, n - 1) {
		if (as[i] + 1 == as[i + 1]) {
			sum += cs[as[i] - 1];
		}
	}

	cout << sum << endl;


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,m,day[1010] = {0},cap[1010] = {0},dp[1010][1010] = {0};
int main()
{
    scanf("%d%d",&n,&m);
    for(int i = 0; i < n; i++)scanf("%d",&cap[i]);
    for(int i = 0; i < m; i++)scanf("%d",&day[i]);
    for(int i = 0; i < m + 1; i++)
    {
        for(int j = 0; j < n + 1; j++)
        {
            if(j == 0)dp[j][i] = 0;
            else if(i < j || i == 0)dp[j][i] = -1;
            else if(dp[j][i - 1] == -1)dp[j][i] = dp[j - 1][i - 1] + (cap[j - 1] * day[i - 1]);
            else dp[j][i] = min(dp[j - 1][i - 1] + cap[j - 1] * day[i - 1],dp[j][i - 1]);
        }
    }
    /*for(int i = 0; i < m + 1; i++)
    {
        for(int j = 0; j < n + 1; j++)
        {
            printf("%d ",dp[j][i]);
        }
        printf("\n");
    }*/
    printf("%d\n",dp[n][m]);
    return 0;
}

Measured memory_bytes: 5888
import copy

def fast_pow(x, n, MOD):
    res = 1
    while n:
        if n & 1:
            res = res * x % MOD
        x = x * x % MOD
        n >>= 1
    return res
  
  
def prepare(n, MOD):
 
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs

MOD = 10**9+7
fact, fact_inv = prepare(2*10**5, MOD)

n, a, b = map(int,input().split())
f = copy.deepcopy(n)
for i in range(1, b+1):
    if i == a:
        nca = f * fact_inv[a] % MOD
    if i == b:
        ncb = f * fact_inv[b] % MOD
        break
    f = f * (n - i) % MOD
print((fast_pow(2, n, MOD) - 1 - nca - ncb) % MOD)



Measured memory_bytes: 89324
#include <bits/stdc++.h>
using namespace std;
 
typedef long long               ll;
typedef long double             ld;
 
 
#define racecar          ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define si(a)            scanf("%d", &a)
#define si2(a,b)         scanf("%d %d", &a,&b)
#define sll(a)           scanf("%I64d",&a)
#define sll2(a,b)        scanf("%I64d %I64d",&a,&b)
#define pb               push_back
#define pi(a)            printf("%d",int(a))
#define pll(a)           printf("%I64d",ll(a))
#define all(x)           (x).begin(),(x).end()
#define rall(x)          (x).rbegin(),(x).rend()
#define ps               printf(" ")
#define nln              printf("\n")
#define ff               first
#define ss               second
#define vi               vector<int>
#define vll              vector<ll>
#define vstr             vector<string>
#define vc               vector<char>
#define pii              pair<int,int>
#define PLL              pair<ll,ll>
#define PI               acos(-1)
#define sq(x)            x*x
#define forr(i,a,b)      for(ll i=ll(a);i<ll(b);i++)
#define forn(i,a,b)      for(ll i=ll(a);i>ll(b);i--)
#define max3(a,b,c)      max(a,max(b,c))
#define max4(a,b,c,d)    max(max3(a,b,c),d)
#define min3(a,b,c)      min(a,min(b,c))
#define mod              1000000007
#define inf              9223372036854775807
 
ll power(ll b,ll n)
{
    if(n==0) return 1;
    else if(n%2) return b*power(b,n/2)*power(b,n/2);
    else return power(b,n/2)*power(b,n/2);
} 
 
ld root(ll n,ll r)
{
    ld dif=0.0001;
    ld guess=n/2.0;
    while(abs(pow(guess,r)-n)>=dif)
    {
        ld temp=pow(guess,r)-n;
        ld tmp=r*pow(guess,r-1);
        guess-=temp/tmp;
    }
    return guess;
}
 
void fileio()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}


int solve()
{
	ll n;
	sll(n);
	vll v;
	forr(i,0,n)
	{
		ll x;
		sll(x);
		v.pb(x);
	}
	ll sum=0;
	forr(i,0,n)
	{
		while(v[i]%2==0) sum++,v[i]/=2;
	}
	
	pll(sum);
	
	return 0;
}
 
int main()
{   
 
//    racecar;
//    cout<<fixed<<setprecision(6);
//    fileio();
    solve();
}
 
 
 
///    Before submission=>
///    ***check for integer overflow,array bounds
///    ***check for n


Measured memory_bytes: 512
// acdart C++
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <cctype>
#include <fstream>
#include <numeric>
#include <utility>
#include <iomanip>
#include <complex>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long ULL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector< vi > vvi;
typedef vector< vd > vvd;
typedef vector< vll > vvll;
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define PI 3.1415926535897932384626433832795
#define mod9 1000000009ll
#define mod7 1000000007ll
#define inf 0x3f3f3f3f
#define inf8  1023456789ll
#define inf16 10000000000000000ll
#define SZ(x) ((int)(x).size())
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for(int i=0;i<sz(v);++i)
#define lp(i, n) for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n) for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n) for(int i=(j);i>=(int)(n);--i)
#define gcd(x, y) __gcd(x, y)
#define lson (id << 1)
#define rson (id << 1 | 1)
#define lowb(x) (x & (-x))
#define eps 1e-7
/*********default*********/
#define maxm
#define maxn

int main()
{
	// ios::sync_with_stdio(false);
	char s[10];
	
	scanf("%s", s);
	int x = strlen(s);
	for (int i = 0; i + 1 < x; i++) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			puts("Yes");
			return 0;
		}
	} 
	puts("No");
}


Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#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 rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

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

    ll ans=-1e18;

    ans = max(a*c,b*d);
    ans = max(ans,a*d);
    ans= max(ans,b*c);
    cout<<ans<<endl;

}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define int64 long long
void solve()
{
   return;
}
int main() {
    int x,n;
    cin>>x>>n;
    if(n==0) cout<<x<<endl;
    else{
        int a[n];
        set<int> st;
    for(int i=0;i<n;i++) {cin>>a[i];st.insert(a[i]);}
    for(int i=0;i<x+1;i++)
    {
        for(int j=-1;j<2;j++)
        {
            int p= x + j*i;
            if(st.count(p)==0)
            {
                cout<<p<<endl;
                return 0;
            }
        }
    }
    



    }
    return 0;
}


Measured memory_bytes: 3612