akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int s, w;
    cin >> s >> w;
    if (w>=s) puts("unsafe");
    else puts("safe");
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;
int a[123455];
int main() {
    int N;
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> a[i];
    }
    int ans =0;
    for(int i = 1; i <= N; i++) {
        int oth = a[i];
        if(a[oth] == i) {
            ans++;
        }
    }
    cout << ans /2<< "\n";
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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 ll INF = 1LL << 60;


ll fac[MAX], finv[MAX], inv[MAX];

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

ll COM(ll n, ll k){
    ll res = 1;
    Rep(i, n-k+1, n+1) res = res * i % MOD;
    res = res * finv[k] % MOD;
    return res;
}

ll binarypow(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 n, a, b; cin >> n >> a >> b;
    COMinit();
    ll ans = binarypow(2, n);
    ans = (ans + MOD - 1) % MOD;
    ans = (ans + MOD - COM(n, a)) % MOD;
    ans = (ans + MOD - COM(n, b)) % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 15600
#include <bits/stdc++.h>
#define PI 3.14159265359
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
typedef vector<pair<ll,ll> > vpii;
typedef vector<ll> vi;
const ll INF=1e17+7;
void input(ll *a,ll n){
    for(ll i=0;i<n;i++)cin>>a[i];
}
ll lcm(ll a,ll b){return (a*b)/__gcd(a,b);}
bool isprime(ll n){
    if(n==1)return false;
    if(n==2 || n==3)return true;
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0)return false;
    }
    return true;
}
//ll x[100001]={0};
ll a[200001]={0};
//ll b[200001]={0};
//bool c[100000001]={0};
//vector<pair<ll,ll> > adj[100001];
//vector<ll> adj[100001];
//vpii edges;
//bool visited[100001]={0};
//bool color[100001]={0};
//ll dist[100001]={0};
ll binary_expon(ll a,ll b){
    ll res=1;
    while(b){
        if(b%2)res=(res*a)%INF;
        a=(a*a)%INF;
        b/=2;
    }
    return res%INF;
}

void sieve(ll n,bool *a)
{
    for (ll p=2; p*p<=n; p++){
        if (!a[p]){
            for (ll i=p*p;i<=n;i+=p)
                a[i]=true;
        }
    }
}

ll fact(ll n){
    ll res=1;
    for(ll i=1;i<=n;i++)res*=i;
    return res;
}

double distance(ll x1,ll y1,ll x2,ll y2){
    return (sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}

/*void tree_dfs(ll curr,ll prev){
    for(auto u:adj[curr]){
        if(u!=prev){
            tree_dfs(u,curr)+1;
        }
    }
}*/

/*void dfs(ll x,ll y,ll px,ll py,char color){
    if(x<0 || y<0 || x>=n || y>=m)return;
    if(grid[x][y]!=color)return;

    if(visited[x][y]){
        f=true;
        return;
    }
    visited[x][y]=true;

    if(px!=(x+1) || py!=y)
        dfs(x+1,y,x,y,color);
    if(px!=(x-1) || py!=y)
        dfs(x-1,y,x,y,color);
    if(px!=(x) || py!=y+1)
        dfs(x,y+1,x,y,color);
    if(px!=(x) || py!=y-1)
        dfs(x,y-1,x,y,color);
}*/

/*bool isVowel(char c){
    return(c=='a'||c=='e'||c=='i'||c=='o'||c=='u');
}*/
//ll grid[1001][1001]={0};

/*void dfs(ll s,bool colr){
    if(visited[s])return;
    visited[s]=true;
    color[s]=colr;
    for(auto u:adj[s]){
        dfs(u,!colr);
    }
}*/
//set<pair<ll,ll> >edges;
/*vector<ll> z(string s) {
    ll n=s.length();
    vector<ll> z(n);
    ll x=0,y=0;
    for(ll i=1;i<n;i++) {
        z[i]=max(0ll,min(z[i-x],y-i+1));
        while(i+z[i]<n&&s[z[i]]==s[i+z[i]]){
            x = i; y = i+z[i]; z[i]++;
        }
     }
    return z;
}*/

void solve(){
    ll n;cin>>n;
    string ans;

    while(n){
        ll digit=n%26;
        if(digit==0){
            ans+='z';
            n/=26;n--;
        }
        else{
            ans+=(char)(('a'+digit)-1);
            n/=26;
        }
        //ans+=(char)(('a'+digit)-1);
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //sieve(10000001,c);
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++){
        solve();
    }
}


Measured memory_bytes: 3676
import sys

n,m = map(int, input().split())
a = list(map(int, input().split()))

def gcd(a,b):
	if b == 0:
		return a
	return gcd(b,a%b)

GCD = 1
t = a[0]
cond = 0
while t%2 == 0:
	t //= 2
	cond += 1
	
mod = 2**cond
for i in range(len(a)):
	t = a[i]
	t_div, t_mod = divmod(t,mod)
	if t_div == 0 or t_mod > 0:
		print(0)
		sys.exit()
	if t_div % 2 == 0:
		print(0)
		sys.exit()

	GCD = GCD*a[i] // gcd(GCD,a[i])
	
A = (2*m) // GCD
if A%2 == 1:
	A+=1

print(A//2)

Measured memory_bytes: 14244
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        final int N=scanner.nextInt();
        final String string=scanner.next();

        String alphabet="abcdefghijklmnopqrstuvwxyz";
        String[] strings=string.split("");
        int max=Integer.MIN_VALUE;
        for(int i=1;i<N;i++){
            boolean[] booleans1=new boolean[alphabet.length()];
            boolean[] booleans2=new boolean[alphabet.length()];
            for(int j=0;j<N;j++){
                if(j<i){
                    booleans1[alphabet.indexOf(strings[j])]=true;
                }else{
                    booleans2[alphabet.indexOf(strings[j])]=true;
                }
            }
            int subMax=0;
            for(int j=0;j<booleans1.length;j++){
                if(booleans1[j]&&booleans2[j]) subMax++;
            }
            if(max<subMax) max=subMax;
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int x;
  cin >> x;
  if(x == 3 || x == 5 || x == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

int main() {
  string a, b;
  cin >> a >> b;

  if (a.size() > b.size())
    cout << "GREATER" << endl;
  else if (a.size() < b.size())
    cout << "LESS" << endl;
  else if (a.size() == b.size()) {
    if (a > b)
      cout << "GREATER" << endl;
    else if (a < b)
      cout << "LESS" << endl;
    else if (a == b)
      cout << "EQUAL" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int mod=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,s;cin >> n >> s;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ll dp[n+1][s+1]={};
    for(int i=0;i<n;i++){
        if(a[i]<=s){
            (dp[i+1][a[i]]+=i+1)%=mod;
        }
        for(int j=1;j<s;j++){
            (dp[i+1][j]+=dp[i][j])%=mod;
            if(j+a[i]<=s){
                (dp[i+1][j+a[i]]+=dp[i][j])%=mod;
            }
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        (ans+=dp[i][s]*(n+1-i)%mod)%=mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 70656
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void push(int );
int pop(void);
int S[100];
int top = 0;

int main(){
  int x,y;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      x = pop() + pop();
      push(x);
      
    }
    else if ( s[0] == '-' ){
      y = pop();
      x = pop() - y;
      push(x);

    }
    else if ( s[0] == '*' ){
      x = pop() * pop();
      push(x);
      
    }

    else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",S[1]);
  return 0;
}

void push(int x)
{
  if(top > 99) printf("??¨??????(?????????????????????)\n");
  else{
    top++;
    S[top] = x;
  }
}

int pop()
{
  if(S[top] == 0) printf("??¨??????(??¢??????????????????)\n");
  else{
    top--;
    return S[top+1];
  }
}

Measured memory_bytes: 548
#!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input

cross=lambda a,b: (a.conjugate()*b).imag
dot=lambda a,b: (a.conjugate()*b).real

def solve(poly, p):
	f=False
	for i in range(len(poly)):
		a=poly[i]-p
		b=poly[(i+1)%len(poly)]-p
		if a.imag>b.imag: a,b=b,a
		if a.imag<=0 and 0<b.imag and cross(a,b)<0: f=not f
		if cross(a,b)==0 and dot(a,b)<=0: return 1
	return 2 if f else 0

checkio=lambda data: solve([complex(*e) for e in data[0]],complex(*data[1]))

n=int(raw_input())
poly=[[float(e) for e in raw_input().split()] for i in range(n)]
n=int(raw_input())
try:
	for i in range(n):
		print(checkio([poly,[float(e) for e in raw_input().split()]]))
except EOFError:
	pass

Measured memory_bytes: 4320
program main;
var 
    a, b, i, k, ans, temp : integer;
    ar : array[1..1000] of integer;
begin
    ans := 0;
    readln(a, b);
    for i := 1 to a do 
        read(ar[i]);
    for i := 1 to a do 
        for k := 1 to a-1 do 
            if ar[k] > ar[k+1] then 
                begin 
                    temp := ar[k];
                    ar[k] := ar[k+1];
                    ar[k+1] := temp;
                end;
    for i := 1 to b do 
        ans := ans + ar[i];
    writeln(ans);
end.

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

int w,h;
int c[51][51];
bool used[51][51];

void dfs(int x,int y) {
    used[x][y]=1;
    for(int dx=-1; dx<=1; ++dx) {
        for(int dy=-1; dy<=1; ++dy) {
            int xx=x+dx;
            int yy=y+dy;
            if(x+dx < 0 || x+dx >=h) continue;
            if(y+dy < 0 || y+dy >=w) continue;
            if(used[xx][yy] || c[xx][yy]==0) continue;
            dfs(xx,yy);
        }
    }
}

int main() {
    while(true) {
        int ans=0;
        cin>>w>>h;
        if(!w) return 0;
        for(int i=0; i<h; ++i) {
            for(int j=0; j<w; ++j) {
                cin>>c[i][j];
                used[i][j]=0;
            }
        }
        for(int i=0; i<h; ++i) {
            for(int j=0; j<w; ++j) {
                if(used[i][j] || c[i][j]==0) continue;
                //cerr<<i<<" "<<j<<endl;
                dfs(i,j);
                ans++;
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3280
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind tree(N);

    for(int i = 0; i < M; i++) {
        int  x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1); // xの木とyの木を併合する
    }

    int cnt=0;
    for(int i=0;i<N;i++){
        if(!tree.same(0,i)){
            tree.unite(0, i);
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int x;
    cin>>x;
    if(x==3||x==5||x==7)cout << "YES" << endl;
    else cout<<"NO"<<endl;
}

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


int main(){
	
	int h,n;
	cin>>h>>n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	vector<int> dp(h+1,1000000000);
	dp[0] = 0;
	for(int j=0;j<n;j++){
		for(int i=0;i<=h;i++){
			int k = min(h,i+a[j]);
			dp[k] = min(dp[k], dp[i] + b[j]);
		}
	}
	
cout<<dp[h];

}

//4 - 2 2 - 1 1 2 - 1 1 1 1 - 

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

#define fast ios::sync_with_stdio(false);cin.tie(NULL)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define eb emplace_back

int n;

int main() {
	fast;
	cin >> n;
	cout << n * n * n;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[63][2][2][2][2];
int a[63],b[63],f[10];

int main(void){
	int i,j,k;
	ll l,r,ans=0ll;
	cin >> l >> r;
	for(i=0; i<60; ++i){
		b[i] = l&1; l >>= 1;
		a[i] = r&1; r >>= 1;
	}
	reverse(a,a+60);
	reverse(b,b+60);
	dp[0][1][1][0][1] = 1ll;
	for(i=0; i<60; ++i){
		for(j=0; j<64; ++j){
			for(k=0; k<6; ++k){
				f[k] = ((j&(1<<k))?1:0);
			}
			if(f[4] == 0 && f[5] == 1){
				continue;
			}
			if(f[0] && f[4]>a[i]){
				continue;
			}
			if(f[1] && f[5]<b[i]){
				continue;
			}
			if(f[3] && f[2]>f[5]){
				continue;
			}
			add_mod(dp[i+1][((f[0]&&(f[4]==a[i]))?1:0)][((f[1]&&(f[5]==b[i]))?1:0)][f[4]][((f[3] && (f[2]==f[5]))?1:0)],dp[i][f[0]][f[1]][f[2]][f[3]]);
		}
	}
	for(j=0; j<16; ++j){
		for(k=0; k<4; ++k){
			f[k] = (j&(1<<k))?1:0;
		}
		if(f[3]){
			continue;
		}
		add_mod(ans,dp[60][f[0]][f[1]][f[2]][f[3]]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
# from fractions import gcd
# mod = 10 ** 9 + 7
# N = int(input())
# a = list(map(int,input().split()))
# a,b,c = map(int,input().split())
# ans = [0] * N
# math.ceilで切り上げ
# dp = [[0] * 4 for i in range(3)] #2次元配列初期化
# dp = [[[0] * 2 for i in range(3)] for j in range(5)]
# (ord('A'))でASCII出力 Aは65
import math
import numpy as np
import statistics
import string
import sys
from array import array
from collections import deque

def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  # xからyまでの階乗をzで割ったあまりを求める
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True
def hcfnaive(a,b):#最大公約数 math.gcdが使えない時の手段として入れとく。pythonが更新されたらいらなくなるはず
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

N = intinput()
tmp = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(tmp[N-1])

Measured memory_bytes: 22548
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n, k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0; i<n; i++)
  {
    cin>>a[i];
  }
  int res = 0;
  sort(a.begin(), a.end());
  for(int i=0; i<k; i++)
    res+=a[i];
  cout<<res<<endl;
}


Measured memory_bytes: 3616
n = int(input())
s = input()
li_s = list(s)

import collections
c = collections.Counter(li_s)
cci = c.items()
#print(cci)
tmp = 1
for cc in cci:
    #print(cc[1])
    tmp *= (cc[1]+1)
print((tmp-1)%(10**9+7))

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

using namespace std;
using ll = long long;

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

int main() {
  int l;
  cin >> l;
  double ans = (l / 3.0) * (l / 3.0) * (l / 3.0);
  printf("%.15f\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

const int P=1000000007;
inline int mul(const int &a,const int &b){return 1ll*a*b%P;}
inline int add(int a,const int &b){a+=b;return(a>=P)?a-P:a;}
inline int sub(int a,const int &b){a-=b;return (a<0)?a+P:a;}
int qsm(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=mul(ans,a);
		a=mul(a,a);
		b>>=1;
	}
	return ans;
}
int n,m,head[100001],nxt[200001],b[200001],v[200001],k,f[100001];
struct point{int u,v,w;}num[100001];
bool cmp(point a,point b){return a.w<b.w;}
void push(int s,int t,int val){
	nxt[++k]=head[s];
	head[s]=k;
	b[k]=t;
	v[k]=val;
}
int find(int x){return f[x]?f[x]=find(f[x]):x;}
long long val[100001],sum,x;
void dfs(int x,int f){
	for(int i=head[x];i;i=nxt[i])
		if(b[i]!=f){
			sum+=v[i];
			val[b[i]]=val[x]+v[i];
			dfs(b[i],x);
		}
}
int get(int x,int f,int end){
	if(x==end)return 0;
	for(int i=head[x];i;i=nxt[i])
		if(b[i]!=f){
			if(b[i]==end)return v[i];
			int tem=get(b[i],x,end);
			if(~tem)return std::max(tem,v[i]);
		}
	return -1;
}
int main(){
	scanf("%d%d%lld",&n,&m,&x);
	for(int i=1;i<=m;i++)scanf("%d%d%d",&num[i].u,&num[i].v,&num[i].w);
	std::sort(num+1,num+m+1,cmp);
	for(int i=1;i<=m;i++){
		int fu=find(num[i].u),fv=find(num[i].v);
		if(fu==fv)continue;
		f[fu]=fv;
		push(num[i].u,num[i].v,num[i].w);
		push(num[i].v,num[i].u,num[i].w);
	}
	dfs(1,0);
	if(sum>x){puts("0");return 0;}
	int a=0,b=0;
	for(int i=1;i<=m;i++){
		long long v=sum-get(num[i].u,0,num[i].v)+num[i].w;
		if(v>x)++a;
		else if(v==x)++b;
	}
	if(sum==x)printf("%d\n",mul(qsm(2,a),sub(qsm(2,b),2)));
	else printf("%d\n",mul(qsm(2,a),mul(2,sub(qsm(2,b),1))));
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define l long 
#define ll long long 
#define ld long double 
#define INF 1000000000000000
#define MOD 1000000007
#define MAX_N 1000006
#define f first
#define s second
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULLL);
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    l n,cnt=0;
    cin>>n;
    l a[n][n];
    for(l i=0;i<n;i++)
    {
        for(l j=0;j<n;j++)
        {
            cin>>a[i][j];
        }
    }
    ll mask=1LL<<n,x=1LL;
    vector<ll> dp(mask);
    for(ll ms=0;ms<mask;ms++)
    {
        cnt=0;
        x=1LL;
        while(x<mask)
        {
            if((x&ms)!=0)
            cnt++;
            x<<=1;
        }
        if(cnt==0)
        {
            dp[ms]=1;
            continue;
        }
        for(l i=0;i<n;i++)
        {
            x=1LL<<i;
            if((x&ms)!=0)
            {
                if(a[i][cnt-1]==1)
                    dp[ms]=(dp[ms]+dp[(ms^x)])%MOD;
            }
        }
    }
    if(dp[mask-1]<0)
    dp[mask-1]+=MOD;
    cout<<dp[mask-1]<<endl;
}

Measured memory_bytes: 19596
#include <bits/stdc++.h>
using namespace std;
  int main () {
  int A , B , C ,X;
    
  cin >> A >> B >> C;
   X =  C - (A - B);
    
  if (X >= 0){
  cout <<  X;
  }
  
  else{
  cout << 0;
  }
  }

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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

ll a,b,c,d;
map<ll,ll> mp;

ll solve(ll n){
	if(n==0) return 0;
	else if(n==1) return d;
	if(mp.find(n)!=mp.end()) return mp[n];
	ll ans=1e18+10;
	if(n<=1e18/d){
		ans=n*d;
	}
	if(n%2==0){
		ans=min(ans,solve(n/2)+a);
	}else{
		ans=min(ans,solve(n/2)+(n-n/2*2)*d+a);
		ans=min(ans,solve((n+1)/2)+abs(n-(n+1)/2*2)*d+a);
	}
	if(n%3==0){
		ans=min(ans,solve(n/3)+b);
	}else {
		ans=min(ans,solve(n/3)+(n-n/3*3)*d+b);
		ans=min(ans,solve((n+2)/3)+abs(n-(n+2)/3*3)*d+b);
	}
	if(n%5==0){
		ans=min(ans,solve(n/5)+c);
	}else{
		ans=min(ans,solve(n/5)+(n-n/5*5)*d+c);
		ans=min(ans,solve((n+4)/5)+abs(n-(n+4)/5*5)*d+c);
	}
	return mp[n]=ans;
}

int main() {
	IOS;
	int t;
	cin>>t;
	while(t--){
		ll n;
		cin>>n>>a>>b>>c>>d;
		mp.clear();
		cout<<solve(n)<<"\n";
		//dbg(mp);
	}
}

Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
int main(){
    string s,t;cin >> s >> t;
    vector<set<int>> a(26);
    for(int i=0;i<s.size();i++){
        a[s[i]-'a'].insert(i);
    }
    int pre=-1;
    int cnt=0;
    for(int i=0;i<t.size();i++){
        if(a[t[i]-'a'].size()==0){
            cout << -1 << endl;
            return 0;
        }
        auto p=a[t[i]-'a'].upper_bound(pre);
        if(p!=a[t[i]-'a'].end()) pre=*p;
        else{
            cnt++;
            pre=*a[t[i]-'a'].lower_bound(-1);
        }
    }
    cout << s.size()*cnt+pre+1 << endl;
    return 0;

}

Measured memory_bytes: 5120
#include <iostream>

int main()
{
    char a, b;
    std::cin >> a >> b;

    if (a == 'H' && b == 'H' || a == 'D' && b == 'D') {
        std::cout << "H" << std::endl;
    } else {
        std::cout << "D" << std::endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

// template {{{
using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))

using int64 = long long;

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

bool in_field(int W, int H, int x, int y) {
  return (0 <= x && x < W) && (0 <= y && y < H);
}

// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

// }}}

// url: https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_a

int A, B, C;

int main() {
  cin >> A >> B >> C;

  int ma = max(A, B);
  int mi = min(A, B);
  if (mi < C && C < ma) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

// vim: foldmethod=marker


Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        string s = Console.ReadLine();
        if (s.Contains("a") && s.Contains("b") && s.Contains("c")) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }

}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int Cin()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
}


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

const int N = 100 + 5;
const int K = 100000 + 5;
const int MOD = 1000000000 + 7;

int add(int a, int b){
	return (a + b) % MOD;
}

int n;
int k;
int a[N];
bool vis[N][K];
int memo[N][K];

int main(){
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	memo[0][0] = 1;
	memo[0][1] = -1;
	for(int i = 0; i <= n; i++){
		for(int j = 1; j <= k; j++){
			memo[i][j] = add(memo[i][j], memo[i][j - 1]);
		}
		if(i == n) break;
		for(int j = 0; j <= k; j++){
			int l = j;
			int r = min(k + 1, j + a[i] + 1);
			memo[i + 1][l] = add(memo[i + 1][l], memo[i][j]);
			memo[i + 1][r] = add(memo[i + 1][r], MOD - memo[i][j]);
		}
	}
	printf("%d\n", memo[n][k]);
	return 0;
}


Measured memory_bytes: 43136
s = gets.chomp.to_s.split(//)
q = gets.to_i
ary = []
q.times do
  ary << gets.split(' ')
end

num = 0
flag = true

ary.each do |x|
  if x[0] == "1"
    num += 1
    flag = !flag
  elsif x[0] == "2"
    if flag
      if x[1] == "1"
        s.unshift(x[2])
      elsif x[1] == "2"
        s.push(x[2])
      end
    else
      if x[1] == "1"
        s.push(x[2])
      elsif x[1] == "2"
        s.unshift(x[2])
      end
    end
  end
end

if num.odd?
  s = s.reverse
end

puts s.join


Measured memory_bytes: 70908
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n, k;
	cin >> n >> k;
	int ans = 1;
	rep(i, 0, n) {
		ans = min(ans * 2, ans + k);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = 10000000000


def main():
    N, X, M = list(map(int, input().split()))     # スペース区切り連続数字

    dp = [0]
    dp.append(X)
    rp = 0
    rps = 0
    rps2 = 0
    for i in range(2, N+1):
        dp.append(dp[i-1]**2 % M)
        for j in range(1, i):
            if dp[i] == dp[j]:
                rp = 1
                rps = j
                rps2 = i
                break
        if rp != 0:
            break

    result = 0
    if rps > 0:
        for i in range(1, rps):
            result += dp[i]

        rc = (N - rps + 1) // (rps2 - rps)
        rpSum = 0
        for i in range(rps, rps2):
            rpSum += dp[i]
        result += rpSum * rc

        rca = (N - rps + 1) % (rps2 - rps)
        for i in range(rps, rps+rca):
            result += dp[i]
    else:
        for i in range(1, N+1):
            result += dp[i]

    # ------ 出力 ------#
    print("{}".format(result))

if __name__ == '__main__':
    main()


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
int h[maxn];
int sum[maxn];
void run_case()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }
    int ans = 0;
    for (int i = n - 1; i >= 1; i--)
    {
        if (h[i] >= h[i + 1])
        {
            sum[i] = sum[i + 1] + 1;
            ans = max(ans, sum[i]);
        }
        else
        {
            sum[i] = 0;
        }
        //DBG(sum[i]);
    }
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

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

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"
#define NUM             100005

const int INF = 1e9+5;

typedef long long ll;

int a[NUM],dp[NUM];

long long solve(ll n, ll k)
{
    for(ll i=0;i<n;i++)
        dp[i] = INF;

    dp[0] = 0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<=i+k;j++)
        {
            if(j<n)
                dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]));
        }
        //cout<<dp[i]<<" ";
    }

    return dp[n-1];
}

int main()
{
    ll n,k;

    cin>>n>>k;

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

    cout<<solve(n,k);
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;
using namespace std;

vector<bool> visited(8, false);
vector<vector<int>> edges;

bool all_visited(int num){
    rep(i, num){
        if(! visited[i]){
            return false;
        }
    }
    return true;

}

int dfs(int now, int num){
    int ans = 0;
    if(all_visited(num)){
        return 1;
    }
    rep(i, edges[now].size()){
        int e = edges[now][i];
        if(! visited[e]){
            visited[e] = true;
            ans += dfs(e, num);
            visited[e] = false;
        }
    }
    return ans;
}

int main(){
    int N, M;
    cin >> N >> M;
    edges.resize(N);
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a --;
        b --;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    visited[0] = true;
    int ans = dfs(0, N);
    cout << ans << endl;
    return 0;
}


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

int main() {
 vector<string> vec(200);
 vector<int> num(200);
 
 int N, M, i, j;
 string S;
 int size=0, judge=0;
 
 cin >> N;
 
 for (i=0; i<N; i++) { // 初めのN個に対してのループ（残りはMの値とM個の文字列）
   cin >> S;
   for (j=0; j<size+1; j++) { // 一つ余分に見ている
     if (S == vec.at(j)){ // もしvecに一致したものがあればnumをプラスする
       num.at(j)++;
       judge++;
       break;
     }
   }
   if(judge == 0){ // リストに一致しなかったとき；上のifが実行されなくてもこのifは必ず実行される
     vec.at(size) = S;
     num.at(size)++;
     size++;
   }
   judge=0;
 }
 
 cin >> M;
  
 for (i=0; i<M; i++){
   cin >> S;
   for (j=0; j<size+1; j++){
     if (S == vec.at(j)){ // もしvecに一致したものがあればnumをマイナスする
       num.at(j)--;
       judge++;
       break;
     }
   }
   if(judge == 0){ // リストに一致しなかったとき；上のifが実行されなくてもこのifは必ず実行される
     vec.at(size) = S;
     num.at(size)--;
     size++;
     }   
   judge=0;
 }
  
 sort(num.begin(), num.end());
 reverse(num.begin(), num.end());
  
 cout << num.at(0) << endl;   
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 100;
const int MOD = 1000000007;

void doc() {
    freopen("OB.inp","r",stdin);
    freopen("OB.out","w",stdout);
}

int n, cha[maxN], h[maxN];
vector<int> a[maxN];

void DFS(int u){
    for(int v : a[u]){
        if (v == cha[u]) continue;
       // cha[v] = u;
        h[v] = h[u] + 1;
        DFS(v);
    }
}

void solve() {
    cin >> n;
    int root = -1;
    memset(cha, -1, sizeof(cha));
    for(int i = 0; i < n; i++){
        int x, K;
        cin >> x >> K;
        //if (root == -1) root = x;
        for(int j = 0; j < K; j++){
            int y;
            cin >> y;
            a[x].push_back(y);
            cha[y] = x;
        }
        //if (a[x].size() != 0 && root == -1) root = x;
    }

    root = 0;
    while (cha[root] != -1) root++;

    //cha[root] = -1;
    DFS(root);

    string s[3] = {"root", "internal node", "leaf"};

    for(int u = 0; u < n; u++){
        int pa = cha[u], dep = h[u], type = 1;
        if (u == root) type = 0;
        else
            if (a[u].size() == 0) type = 2;
        cout << "node " << u << ": parent = " << pa << ", depth = " << dep << ", " << s[type] << ", [";
        vector<int> c;
        c.clear();
        for(int v : a[u]){
            if (v == pa) continue;
            c.push_back(v);
        }
        if (c.size() != 0){
            for(int j = 0; j < c.size() - 1; j++)
                cout << c[j] << ", ";
            cout << c.back();
        }
        cout << "]" << '\n';
    }
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    //doc();
    solve();
}



Measured memory_bytes: 7128
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

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); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n = 0;
	string s;
	cin >> s;
	for(int i = 0;i < 4;i++){
		if(s[i] == '+') n++;
		else n--;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,m = mi()
A = []
for _ in range(n):
    a,b = mi()
    A.append([a,b])
A.sort()

import heapq
a = []
ima = 0
ans = 0
for i in range(1,m+1):
    while True:
        if ima == n:
            break
        if A[ima][0] <= i:
            heapq.heappush(a,-A[ima][1])
            ima += 1
        else:
            break
    if a:
        ans += heapq.heappop(a)*-1
print(ans)




Measured memory_bytes: 72536
#include <iostream>

using namespace std;

int main(){
	int a, b;
	char input;

	cin >> a;
	cin >> input;
	cin >> b;

	switch(input){
		case '+':
			cout << a + b << endl;
			break;
		case '-':
			cout << a - b << endl;
			break;
		default:
			break;
	}
	return 0;
}


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

int main() {
    std::vector<char> S;
    char x;
    for (int i = 0; i < 3; ++i) {
        std::cin >> x;
        S.push_back(x);
    }
    std::sort(S.begin(), S.end());
    S.erase(std::unique(S.begin(), S.end()), S.end());
    std::cout << (S.size() == 3 ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x)     		(x).begin(),(x).end()
#define ub    			upper_bound
#define lb 				lower_bound
#define ins				insert
#define int 			long long
#define endl			'\n'
#define ff              first
#define ss              second
#define ull				unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si 				set<int>
#define usi 			unordered_set<int>		
#define mii             map<int,int>
#define umii			unordered_map<int ,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)		for(int i=a;i<n;++i)
#define repd(i,a,n)		for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define deb(x)			cout<<#x <<"="<<x<<endl;
#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
int log(int x){return 64-__builtin_clzll(x)-1;}

void c_p_p()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
}
struct Node
{
	int a,b,c,d;
	
};
bool cmp(Node A,Node B)
{
	return A.a<B.a;
}
const int Max=1e5+1;

int32_t main()
{
	c_p_p();
	int n,k,ans=0;
	cin>>n>>k;
	int A[n];
	rep(i,0,n)cin>>A[i];
	sort(A,A+n);
	rep(i,0,k)
	ans+=A[i];
	cout<<ans;
	return 0;
}
	

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define per(i,a,b) for(int i = a; i >= b; i--)
#define inf 9000000000000000000
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto& a : x)

int main(){
  ios::sync_with_stdio(0);
  ll n,a,b; cin >> n >> a >> b;
  cout << min(a,b) << " " << max(ll(0),a+b-n) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define pb push_back
#define lowbit(x) x&(-x)
using namespace std;
typedef long long ll;
typedef pair <ll,ll> PAIR;
const int N = 2e5+7;
const int M = 2019;
const int INF = 0x3f3f3f3f;

map <int,int> mp;

int main(){
	string s;
	cin >> s;
	
	mp[0]++;
	int len = s.size();
	int base = 1;
	int now = 0;
	
	ll ans = 0;
	for(int i = len-1;i >= 0;--i){
		(now += base%M*(s[i]-'0')%M) %= M;
		ans += mp[now];
		mp[now]++;
		(base *= 10%M) %= M;
	}
	
	printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

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


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

int main(){
  int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
  int x3,y3,x4,y4;
  x3 = x2+(y1-y2);
  y3 = y2+(x2-x1);
  x4 = x1+(y1-y2);
  y4 = y1+(x2-x1);
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next(), T = sc.next();
		sc.close();
		char s[] = new char[S.length()];
		char t[] = new char[T.length()];
		for(int i=0;i<S.length();i++) s[i]=S.charAt(i);
		for(int i=0;i<T.length();i++) t[i]=T.charAt(i);
		
		int n = s.length, m = t.length;
		int dp[][] = new int[n+1][m+1];// dp[N][M]:= sのN文字目、tのM文字目までにおける、最大一致数
		for(int i=1;i<n+1;i++) {
			for(int j=1;j<m+1;j++) {
				if(s[i-1] == t[j-1])dp[i][j] = dp[i-1][j-1]+1;
				else dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
			}
		}
		
		//dp配列から文字を復元する
		int len = dp[n][m];
		int now = len - 1;
		char ret[] = new char[len];
		for(int i = n, j = m; i > 0 && j > 0;) {
			if(s[i-1] == t[j-1]) { //これは誤り -> if(dp[i-1][j-1] == dp[i][j] - 1)
				ret[now--] = s[i-1];
				i--; j--;
			}
			else if(dp[i-1][j] == dp[i][j])i--;
			else j--;
		}
		String ans = new String(ret);
		System.out.println(ans);
		
	}
}


Measured memory_bytes: 81356
#include <bits/stdc++.h>
using namespace std;
int m,n,mp[101];

int cal(){
  int res,a=mp[0],b=mp[n-1];
  for(int i=1;i<n;i++) a+=!mp[i];
  for(int i=n-2;i>=0;i--) b+=!mp[i];

  res=max(a,b);
  for(int i=1;i<n-1;i++){
    int cnt=mp[0]+mp[n-1]+mp[i];
    for(int j=1;j<i;j++)cnt+=!mp[j];
    for(int j=n-2;j>i;j--)cnt+=!mp[j];
    res=max(res,cnt);
  }
  return res;
}

int main(){
  cin>>m>>n;
  for(int i=0;i<n;i++) cin>>mp[i];
  int ans=cal();
  for(int i=1;i<m;i++){
    for(int j=0;j<n;j++) cin>>mp[j],mp[j]=!mp[j];
    ans+=cal();
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 1164
n = int(input())

S = list(map(int, input().split()))

q = int(input())

T = list(map(int, input().split()))

C = 0

for i in range(q):
  left = 0

  right = n

  while left < right:
    mid = (left + right) // 2
    if S[mid] == T[i]:
      C += 1
      break
    elif T[i] < S[mid]:
      right = mid
    else:
      left = mid + 1

print(C)


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

// #include <boost/multiprecision/cpp_int.hpp>

using namespace std;
// namespace mp = boost::multiprecision;

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

  int n;
  cin >> n;

  // mp::int128_t ans = 1;
  // bool ok = true;
  // for (int i = 0; i < n; ++i) {
  //   mp::int128_t a;
  //   cin >> a;
  //   if (a == 0) {
  //     ans = 0;
  //     break;
  //   }
  //   if (ok) {
  //     ans *= a;
  //     if (ans > 1000000000000000000) {
  //       ans = -1;
  //       ok = false;
  //     }
  //   }
  // }

  int64_t ans = 1;
  bool ok = true;
  for (int i = 0; i < n; ++i) {
    int64_t a;
    cin >> a;
    if (a == 0) {
      ans = 0;
      break;
    }
    if (ok) {
      if (ans > 1000000000000000000 / a) {
        ans = -1;
        ok = false;
      } else {
        ans *= a;
      }
    }
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3668
def solve(V,E,r,edges):
    cost=[-float('inf')]*V
    cost[r]=0
    for _ in range(V-1):
        for edge in edges:
            s=edge[0]
            t=edge[1]
            d=edge[2]
            if cost[t]<cost[s]+d:
                cost[t]=cost[s]+d
    ans=cost[V-1]
    for _ in range(V-1):
        for edge in edges:
            s=edge[0]
            t=edge[1]
            d=edge[2]
            if cost[t]<cost[s]+d:
                cost[t]=cost[s]+d
    if ans!=cost[V-1]:
        return float('inf')
    return ans
            



V,E=map(int,input().split())
edges=[]
for _ in range(E):
    s,t,d=map(int,input().split())
    s-=1
    t-=1
    edges.append(tuple((s,t,d)))
ans=solve(V,E,0,edges)
if ans==float('inf'):
    print("inf")
else:
    print(ans)

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

const int N = 53;
long long C[N+1][N+1];

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	C[0][0] = 1;
	for (int n = 1; n <= N; ++n) {
		C[n][0] = C[n][n] = 1;
		for (int k = 1; k < n; ++k)
			C[n][k] = C[n-1][k-1] + C[n-1][k];
	}
}


long long v[N];
map<long long, int> m, used;

long long count() {
	long long num = 1;
	for (const auto &e: used) {
		int k = e.second;
		if (k > m[e.first]-k) k = m[e.first]-k;
		if (e.second) num *= C[m[e.first]][k];
	}
	return num;
}

void solve() {
	int n, a, b; scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i < n; ++i) {
		scanf("%lld", v+i);
		++m[v[i]];
	}
	sort(v, v+n, greater<long long>());
	long long s = 0;
	set<long long> z;
	for (int i = 0; i < a; ++i) {
		s += v[i];
		++used[v[i]];
		z.insert(v[i]);
	}
	double ans = 1.0*s/a;
	long long cnt = count();
	if (z.size() == 1) {
		while (used[v[0]] < m[v[0]] && used[v[0]] < b) {
			++used[v[0]];
			cnt += count();
		}
	}
	printf("%.10lf\n%lld", ans, cnt);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
	char name[100];
	int t;
}P;

P Q[LEN];
int head, tail, n;


void enqueue(P x)
{
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}


P dequeue()
{
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}


int min(int a, int b) {return a<b ? a : b;}


int main(void)
{
	int elaps = 0, c;
	int i, q;
	P u;
	scanf("%d %d", &n, &q);
	
	for(i=1; i<=n; i++){
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	head = 1; tail = n+1;
	
	while(head != tail){
		u = dequeue();
		c = min(q, u.t);
		u.t -= c;
		elaps += c;
		if(u.t > 0) enqueue(u);
		else
		{
			printf("%s %d\n", u.name, elaps);
		}
	}
	
	return 0;
}


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

static const int MAX_N = 100;

int main()
{

	int n, m;
	int a[MAX_N][MAX_N], b[MAX_N], c[MAX_N];

	memset( c, 0, sizeof( c ) );

	cin >> n >> m;
	for( int i = 0; i < n; i++ ) {
		for( int j = 0; j < m; j++ ) cin >> a[i][j];
	}
	for( int i = 0; i < m; i++ ) cin >> b[i];

	for( int i = 0; i < n; i++ ) {
		for( int j = 0; j < m; j++ ) c[i] += ( a[i][j] * b[j] );
	}

	for( int i = 0; i < n; i++ ) cout << c[i] << endl;

	return 0;

}

Measured memory_bytes: 1200
s = input()
n = len(s)

for i in range(2, n, 2):
  flag = 1
  for j in range(n-i-1, int((n-i)/2-1),-1):
    if s[j] != s[j-int((n-i)/2)]:
      flag = 0
      break
  if flag == 1:
    break
    
print(n-i)


Measured memory_bytes: 81440