akhauriyash/Code-Regression huggingface dataset:
import sys
class Line:
    def __init__(self,p1,p2):
        if p1[1] < p2[1]:self.s=p2;self.e=p1
        elif p1[1] > p2[1]:self.s=p1;self.e=p2
        else:
            if p1[0] < p2[0]:self.s=p1;self.e=p2
            else:self.s=p2;self.e=p1

def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def dot(a,b):return a[0]*b[0]+a[1]*b[1]
def dif(a,b):return [x-y for x,y in zip(a,b)]
def dist(a,b):return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
def isec(l,m):
    a = dif(l.e,l.s);b = dif(m.e,l.s);c = dif(m.s,l.s)
    d = dif(m.e,m.s);e = dif(l.e,m.s);f = dif(l.s,m.s)
    g = lambda a, b : cross(a,b)==0 and dot(a,b)>0 and dot(b,b)<dot(a,a)
    if g(a,b) or g(a,c) or g(d,e) or g(d,f):return True
    elif l.s == m.e or l.s == m.s or l.e == m.e or l.e == m.s:return True
    elif cross(a,b) * cross(a,c) >= 0 or cross(d,e) * cross(d,f) >= 0:return False
    else:return True
def plus(a,b):return [x+y for x,y in zip(a,b)]
def projection(a,b):return [x*dot(a,b)/dot(a,a) for x in a]
def proj(A,B,C,D):
    AB = dif(B,A) ; AC = dif(C,A) ; AD = dif(D,A)
    CD = dif(D,C) ; CA = dif(A,C) ; CB = dif(B,C)
    _A = plus(projection(CD,CA),C) 
    _B = plus(projection(CD,CB),C)
    _C = plus(projection(AB,AC),A)
    _D = plus(projection(AB,AD),A)
    return [_A,_B,_C,_D]
def Order(a,b):
    crs = cross(a,b)
    if abs(crs) < 1.0e-10 : crs = 0.0
    if crs > 0 : return "COUNTER_CLOCKWISE"
    elif crs < 0 : return "CLOCKWISE"
    else:
        if dot(a,b) < 0 : return "ONLINE_BACK"
        elif dot(a,a) < dot(b,b) : return "ONLINE_FRONT"
        else : return "ON_SEGMENT"

q = int(input())
for i in range(q):
    a,b,c,d,e,f,g,h = [int(i) for i in input().split()]
    A = [a,b] ; B = [c,d] ; C = [e,f] ; D = [g,h]
    l = Line(A,B) ; m = Line(C,D)
    if isec(l,m):
        print(0.0)
        continue
    _A,_B,_C,_D = proj(A,B,C,D)
    AB = dif(B,A) ; CD = dif(D,C)
    A_C = dif(_C,A) ; A_D = dif(_D,A) ; C_A = dif(_A,C) ; C_B = dif(_B,C)
    DIST = [dist(A,C),dist(A,D),dist(B,C),dist(B,D),dist(_A,A),dist(_B,B),dist(_C,C),dist(_D,D)]
    fun = lambda x : x != "ON_SEGMENT"
    if fun(Order(CD,C_A)) : DIST[4] = sys.maxsize
    if fun(Order(CD,C_B)) : DIST[5] = sys.maxsize
    if fun(Order(AB,A_C)) : DIST[6] = sys.maxsize
    if fun(Order(AB,A_D)) : DIST[7] = sys.maxsize
    print(min(DIST))

Measured memory_bytes: 8008
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(void) {
  int n;
  cin>>n;
  vector<int> v;
  for(int i=0; i<n; i++) {
    int x;
    cin>>x;
    v.push_back(x);
  }
  sort(v.begin(), v.end(), greater<int>());
  int a=0;
  int b=0;
  for(int i=0; i<n; i++) {
    if(i%2==0) {
      a+=v[i];
    } else {
      b+=v[i];
    }
  }
  cout<<a-b<<endl;
  return 0;
}


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

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

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  string s, t, u ;
  cin >> s >> t >> u ;
  
  cout <<s.at(0)<<t.at(0)<<u.at(0)<<endl ;
  
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(int i =(a);i<(n);i++)
#define urep(i,a,n) for(int i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

ll W, H, N,ans,a,b;
ll A[200000];
int main() {
	cin >> a >> b;
	if (a + b == 15)cout << "+" << endl;
	else if (a*b == 15)cout << "*" << endl;
	else cout << "x" << endl;
	cin >> ans;
	return 0;
}

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

const int MX = 100001;

int main() {
    int n;
    cin >> n;
    vector<ll> cnt(MX);
    rep(i, n) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    ll tot = 0;
    rep(i, MX) tot += i*cnt[i];

    int q;
    cin >> q;
    rep(i, q) {
        int b, c;
        cin >> b >> c;
        tot -= b*cnt[b];
        tot -= c*cnt[c];
        cnt[c] += cnt[b]; cnt[b] = 0;
        tot += b*cnt[b];
        tot += c*cnt[c];
        cout << tot << endl;
    }
    return 0;
}

Measured memory_bytes: 4040
#include "bits/stdc++.h"

using namespace std;

int main(){
    int cnt = 0;
    int N;
    cin >> N;
    for(int i=0; i<N; i++){
        int x;
        cin >> x;
        if(x != i+1){
            cnt++;
        }
    }
    
    if(cnt == 0 || cnt == 2){
        cout << "YES" << endl;
    }else cout << "NO" << endl;
}   

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rrep1(i,n) for(int i=n;i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase(unique(all(v)), v.end())
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 (a>b) { a = b; return 1; } return 0; }
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

ll ans = 0;
ll n, k;
vl a;
vl sum;

void solve(int l, int r) {
	if (r == l + 1) {
		if (a[l] >= 0) {
			ans++;
		}
		return;
	}
	int m = (l + r) / 2;
	solve(l, m); solve(m, r);
	vl sumr(r - m);
	REP(i, m, r) {
		sumr[i - m] = sum[i + 1];
	}
	sort(all(sumr));
	REP(i, l, m) {
		ans += (sumr.end() - lower_bound(all(sumr), sum[i]));
	}
	
}

int main() {
	fio();
	cin >> n >> k;
	a.resize(n);
	sum.resize(n + 1);
	sum[0] = 0;
	rep(i, n) {
		cin >> a[i];
		a[i] -= k;
		sum[i + 1] = sum[i] + a[i];
	}
	solve(0, n);
	cout << ans << endl;
}


Measured memory_bytes: 4532
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll aa , bb;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->aa - ((fr*)q)->aa;}

int main(void){
    // char ;
    ll n,k,ans=INF;
    scanf("%lld%lld",&n,&k);
    ans=n%k;
    ans = min2(ans,k-ans);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
#define out(a) printf("%d ",a)
#define ln printf("\n")
const int N=2e5+50;
const int MOD=1e9+7;
const int inf=0x7f7f7f7f;
using namespace std;
int n,x,y,m;
int a[N],head[N];
int tot=0;
int dep[N];
struct node
{
	int to,nxt;
}edge[N<<1];
void add(int x,int y)
{
	edge[++tot].to=y;
	edge[tot].nxt=head[x];
	head[x]=tot;
}
void dfs(int u,int fa)
{
	dep[u]=dep[fa]+a[u];
	for (int i=head[u];i;i=edge[i].nxt){
	  int v=edge[i].to;
	  if (v==fa) continue;
	  dfs(v,u);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<n;i++){
	  scanf("%d%d",&x,&y);
	  add(x,y); add(y,x);
    }
    for (int i=1;i<=m;i++)
      scanf("%d%d",&x,&y),a[x]+=y;
    dfs(1,0); 
    for (int i=1;i<=n;i++)
      out(dep[i]);
	return 0;
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int a, b;
  cin >> a >> b;
  if (b % a == 0) cout << a+b << endl;
  else cout << b-a << endl;
}

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

int main() {
    int w, h;
    string a[100];
    bool xd[100] = {false};
    bool yd[100] = {false};
    
    cin >> h >> w;
    
    for (int i = 0; i < h; i++) {
        cin >> a[i];
    }
    
    for (int i = 0; i < h; i++) {
        for (int ii = 0; ii < w; ii++) {
            if (a[i][ii] == '#') {
                xd[ii] = true;
                yd[i] = true;
            }
        }
    }
    
    for (int i = 0; i < h; i++) {
        if (yd[i]) {
            for (int ii = 0; ii < w; ii++) {
                if (xd[ii]) {
                    cout << a[i][ii];
                }
            }
            
            cout << endl;
        }
        
    }
    
    return 0;
}

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

int main()
{
    string s;
    cin>>s;
    int n;
    cin>>n;
    int f=0;
    int x=s.length()/n;
    if(x*n!=s.length())
    {
        f=1;
        x++;
    }
    for(int i=0;i<s.length();i++)
    {
        if(i%n==0)
        {
            cout<<s[i];
        }
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
// #define int long long
typedef long long ll;
#define fi first
#define se second
#define pii pair<int,int>
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define y1 fdfbvfds
typedef long double f80;
#define all(x) x.begin(), x.end()
typedef long double f80;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l,ll r){
    uniform_int_distribution<ll> uid(l, r);
    return uid(rng);
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = sz(s);
    ll k;
    cin >> k;
    char ch = s[0];
    vector<pair<char,int>> v;
    fr(i, 0, n - 1) {
    	int j = i;
    	while(j < n && s[j] == s[i]) j++;
    	v.pb({s[i], j - i});
    	i = j - 1;
    }
    if(sz(v) == 1) {
    	cout << (n * k) / 2;
    }
    else if(v[0].fi == v.back().fi) {
    	int pre = v[0].se;
    	int suf = v.back().se;
    	ll ans = ((pre + suf) / 2) * (k - 1);
    	ans += pre / 2;
    	ans += suf / 2;
    	fr(i, 1, sz(v) - 2) {
    		ans += (v[i].se / 2) * k;
    	}
    	cout << ans;
    }
    else {
    	ll ans = 0;
    	for(auto x : v) {
    		ans += x.se / 2;
    	}
    	cout << ans * k;
    }
	return 0;
}

Measured memory_bytes: 256
def Main():
    N = int(input())
    H = list(map(int, input().split()))
    ans = 0
    maxi = 0
    for h in H:
        if maxi <= h:
            ans += 1
        maxi = max(maxi, h)

    print(ans)
    
if __name__ == "__main__":
    Main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    while (n) {
        n /= k;
        cnt++;
    }
    cout << cnt << "\n";
}

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

struct Edge {
    int from, to, cost;
    Edge(int a, int b, int c) : from(a), to(b), cost(c) {}
    bool operator<(const Edge &x) const {
        return cost < x.cost;
    }
};

struct UnionFind {
    int node[1010];
    UnionFind() {
        memset(node, -1, sizeof(node));
    }
    int find(int x) {
        return node[x] < 0 ? x : node[x] = find(node[x]);
    }
    int size(int x) {
        return -node[find(x)];
    }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return false;
        if(size(x) > size(y)) swap(x, y);
        node[y] += node[x];
        node[x] = y;
        return true;
    }
};

int main() {
    int N, M;
    while(1) {
        scanf("%d%d", &N, &M);
        if(!N) break;
        vector<Edge> edges;
        for(int i=0; i<M; i++) {
            int s, t, c;
            scanf("%d%d%d", &s, &t, &c); s--; t--;
            edges.push_back(Edge(s, t, c));
        }

        sort(edges.begin(), edges.end());
        vector<int> use_cost;
        UnionFind uf;
        for(int i=0; i<M; i++) {
            Edge e = edges[i];
            if(uf.unite(e.from, e.to)) {
                use_cost.push_back(e.cost);
            }
        }
        int mid = (N-1) / 2;
        printf("%d\n", use_cost[mid]);
    }
    return 0;
}


Measured memory_bytes: 2732
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    char *c[7] = { "SUN","MON","TUE","WED","THU","FRI","SAT" };

    string s;
    cin >> s;

    for (int i = 0; i < 7; i++) {
        if (s == c[i]) {
            cout << 7 - i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}   

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;

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

template<class T, class U> inline bool chmax(T& a, U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a, U b) { if (a > b) { a = b; return 1; } return 0; }

// 第一引数 == 第二引数 ? true : false
template<class T, class U>
bool check(T first, U second) {
    return (first == second);
}

// 約数列挙
vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


// 数字和
template<class T>
T digitSum(T num) {
    T dig;
    T sum = 0;
    while (num) {
        dig = num % 10;
        sum += dig;
        num /= 10;
    }
    return sum;
}

string background_black(string s) { return "\x1b[40m" + s; }
string background_red(string s) { return "\x1b[41m" + s + "\x1b[40m"; }
string background_green(string s) { return "\x1b[42m" + s + "\x1b[40m"; }
string background_yellow(string s) { return "\x1b[43m" + s + "\x1b[40m"; }
string background_bleu(string s) { return "\x1b[44m" + s + "\x1b[40m"; }
string background_white(string s) { return "\x1b[47m" + s + "\x1b[40m"; }

string black(string s) { return "\x1b[30m" + s + "\x1b[37m"; }
string red(string s) {return "\x1b[31m" + s + "\x1b[37m"; }
string green(string s) { return "\x1b[32m" + s + "\x1b[37m"; }
string yellow(string s) { return "\x1b[33m" + s + "\x1b[37m"; }
string blue(string s) { return "\x1b[34m" + s + "\x1b[37m"; }
string white(string s) { return "\x1b[37m" + s + "\x1b[37m"; }

const int ten = 10;
const int hundred = 100;
const int thousand = 1000;

typedef long long ll;
typedef unsigned long long ull;

string tolower(string s) {
  string c;
  for (int i = 0; i < s.size(); i++) {
    if ((s[i] >= 'A') && (s[i] <= 'Z')) {
        c.push_back((s[i] + 0x20));
    } else {
        c.push_back(s[i]);
    }
  }
  return c;
}
#include <cstdlib>
string solve() {
  string str = "";
// int->string: to_string, string->int: stoi
//=============================================================================


  ull n;
  cin>>n;
  vector<unsigned int > a(n);
  for (int i = 0; i < a.size(); i++) {
    cin >> a[i];
  }

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

  bool flg = false;
  for (int i = 0, j = 1; i < a.size()-1;i++, j++) {
    if (a[i] == a[j]) {
      str += "NO";
      flg = true;
      break;
    }
  }

  if (!flg) {
    str += "YES";
  }



//=============================================================================
  str += "\n";
  return str;
}

int main() {	
  std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
  cout << solve() << endl;
}


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

using namespace std;

typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (int& val : v) cin >> val;
	sort(begin(v), end(v));
	ll ans = 0;
	for (int i = 0; i < n - k; i++) {
		ans += v[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  string s;
  cin >> s;
  bool flag=true;
  if(s.substr(0,s.size()/2)!=s.substr(s.size()/2+1)) {
    flag=false;
  }
  else {
    for(ll i=0;i<s.size()/2/2;i++) {
      if(s[i]!=s[s.size()/2-i-1]) {
        flag=false;
      }
    }
  }
  if(flag) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << 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;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#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 {
#ifdef LOCAL
~debug() { cerr << endl; }
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
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
ll power(ll a,ll n)
{
    ll p;
    if(n==0)
    {
        return 1;
    }
    p=power(a,n/2);
    p=((p%mod)*(p%mod))%mod;
    if(n%2==1)
    {
        p=(p%mod)*(a%mod);
    }
    return p;
}
int main()
{
	fastIO;
    ll n;
    cin>>n;
    string str[n];
    map<map<char,ll>,ll>m;
    for(int i=0;i<n;i++)
    {
        cin>>str[i];
    }
    for(int i=0;i<n;i++)
    {
        map<char,ll>s;
        for(int j=0;j<str[i].size();j++)
        {
            s[str[i][j]]++;
        }
        m[s]++;
    }
    ll val,val1,ans=0;
    for(auto itr=m.begin();itr!=m.end();itr++)
    {
        val=itr->se;
        val--;
        val1=((val)*(val+1))/2;
        ans+=val1;
    }
    cout<<ans<<endl;
}

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

int main(){
  int ah,am,as;
  int bh,bm,bs;
  int ch,cm,cs;
  int sh,sm,ss;
  int eh,em,es;
  int s,e;
  
  scanf(" %d %d %d %d %d %d",&sh,&sm,&ss,&eh,&em,&es);
  s = ((sh*60)+sm)*60+ss;
  e = ((eh*60)+em)*60+es;
  e-=s;
  as = e%60;
  am = (e%(60*60))/60;
  ah = e/(60*60);
  
  scanf(" %d %d %d %d %d %d",&sh,&sm,&ss,&eh,&em,&es);
  s = ((sh*60)+sm)*60+ss;
  e = ((eh*60)+em)*60+es;
  e-=s;
  bs = e%60;
  bm = (e%(60*60))/60;
  bh = e/(60*60);

  scanf(" %d %d %d %d %d %d",&sh,&sm,&ss,&eh,&em,&es);
  s = ((sh*60)+sm)*60+ss;
  e = ((eh*60)+em)*60+es;
  e-=s;
  cs = e%60;
  cm = (e%(60*60))/60;
  ch = e/(60*60);
  
  printf("%d %d %d\n",ah,am,as);
  printf("%d %d %d\n",bh,bm,bs);
  printf("%d %d %d\n",ch,cm,cs);

  return 0;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
# define sz(x) (int)((x).size())
#define int long long

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

const ll inf = 0x3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 2e5 + 11;

int dp[N],dp1[N],a[105],v,w,n,k,x;
//vector<int>v[N];

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0);

    cin >> n >> k;

    dp[0] = 1;


    forn(i,1,n){
        cin >> a[i];
        forn(j,1,k)dp[j] += dp[j-1], dp[j] %= mod;
        forn(j,0,k){
            int l = max(0ll,j-a[i]);
            int r = j;
            dp1[r] = dp[r] - (l == 0 ? 0 : dp[l-1]);
            dp1[j] = (dp1[j] + mod)%mod;

        }forn(j,0,k)dp[j] = (dp1[j] + mod)%mod;

    }


    rc(dp[k]);
return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n,m;cin>>n>>m;
  vector<pi> sc(m);
  rep(i, m)cin>>sc[i].first>>sc[i].second;

  rep(i, 1000){
    string s = to_string(i);
    if(s.size()!=n) continue;

    bool f = true;
    for(auto p: sc){
      if( s[p.first-1]!=(char)('0'+p.second) )f=false;
    }
    if(f){ cout<<i;return 0;}
  }

  cout<<-1;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> P(N), idx(N);
    REP(i,N){
        cin >> P[i];
        --P[i];
    }
    REP(i,N) idx[P[i]] = i;
    set<ll> st;
    ll ans = 0;
    for(int x=N-1;x>=0;x--){
        int i = idx[x];
        vector<ll> l(2, -1);
        vector<ll> r(2,N);
        st.insert(i);
        auto itr = st.find(i);
        REP(j, 2){
            if(itr == st.begin()) break;
            --itr;
            l[j] = *itr;
        }
        itr = st.find(i);
        REP(j,2){
            ++itr;
            if(itr == st.end()) break;
            r[j] = *itr;
        }
        ll c = (i - l[0]) * (r[1] - r[0]) + (l[0] - l[1]) * (r[0] - i);
        ans += c * (x + 1);
    }
    cout << ans << endl;
}


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

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

using namespace std;

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

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

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

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

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

void solve(ll N, vector<ll> a) {
  int p = 0;
  REP(i,N+10) {
    if (p == 1) { cout << i << endl; return; }
    p = a[p] - 1;
  }
  cout << -1 << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	vector<ll> a(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &a[i]);
	}
	solve(N, a);
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    string s,t;
    cin >> s >> t;
    cout << t << s << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stack>
#include<map>
#include<vector>
#include<utility>
using namespace std;
typedef long long ll;

ll h,w,n,a,b;
typedef pair<long long,long long> p;

int main(void)
{
  cin >> h >> w >> n;
  map<p,ll> m;
  vector <ll> black(10,0);
  for(int i=1;i<=n;i++)
    {
      cin >> a >> b;
      for(int j=b-2;j<=b;j++)
	{
	  for(int k=a-2;k<=a;k++)
	    {
	      if(1<=k && k<=h-2 && 1<= j && j<= w-2)m[p(k,j)]++;
	    }
	}
    }
  for(auto it=m.begin(); it !=m.end();it++) black[it->second]++;
  black[0]=(h-2)*(w-2)-m.size();
  for(int i=0;i<=9;i++)
    {
      cout << black[i] << endl;
    }
  return 0;
  
}


Measured memory_bytes: 56448
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long k = Long.parseLong(str[2]);

		if (a + b <= k) {
			System.out.println("0 0");
		} else {
			long c = k - a;
			long d = b;

			if (c >= 0) {
				d -= c;
			}

			a -= k;

			System.out.println(((a >= 0) ? a : 0) + " " + ((d >= 0) ? d : 0));
		}
	}
}


Measured memory_bytes: 36904
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
const int maxn = 1e5 + 50;
const int inf = 0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long n,t;
	cin >> n >> t;
	long long minx;
	long long a;
	cin >> a;
	minx = a;
	map<long long,int> m;
	long long ans = 0;
	for(int i = 2; i <= n; i++)
	{
		cin >> a;
		if(minx < a) 
		{
			m[a-minx]++;
			ans = max(ans,a-minx);
		}
		else
		{
			minx = a;
		}
	}
	cout << m[ans] << endl;
	return 0;
}

Measured memory_bytes: 6528
#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>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;

int main(){
    int n; ll W; cin >> n >> W;
    vector<ll> w(n),v(n);
    rep(i,n) cin >> w[i] >> v[i];

    ll dp[105][100005];
    rep(i,105) rep(j,100005) dp[i][j] = 1e12;
    dp[0][0] = 0;

    rep(i,n) {
        rep(j,100005) {
            if(j >= v[i]) dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]] + w[i]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    int ans = 0;
    rep(i,100005) {
        if(dp[n][i] <= W) ans = i;
    }
    
    cout << ans << endl;
}

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

int main(){
	// sengen
	long long n,a,b;
	// nyuryoku
	cin >> n >> a >> b;
	long long wari,amari;
	wari = n/(a+b);
	amari = n%(a+b);
	// keisan
	if(amari >= a){
		cout << wari*a + a;
	}else{
		cout << wari*a + amari;
	}
	// syutsuryoku
}

Measured memory_bytes: 256
import Foundation

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")

let x = Int(split[0])!
let y = Int(split[1])!
let a = y - 2*x

if(a % 2 == 0 && a >= 0 && a <= 2*x){
  print("Yes")
}else{
  print("No")
}

Measured memory_bytes: 14072
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;

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

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

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;

const int N_MAX=300010;
const int M_MAX=300010;
ll fact[N_MAX];
ll finv[N_MAX];
//modの掛け算
ll mul(ll x, ll y){
	return (x%mod)*(y%mod)%mod;
}
//xのy乗%mod（繰り返し二乗法)
ll powll(ll x, ll y){
	ll res=1LL;
	while(y){
		if(y&1LL){
			res*=x;
		}
		res%=mod;
		x=(x*x)%mod;
		y>>=1LL;
	}
	return res;
}
//x*(yの逆元)
ll divll(ll x,ll y){
	return (x*powll(y,mod-2))%mod;
}
//nPr%mod
ll nPr(ll n,ll r){
	if(n<r || r<0)return 0;
	return mul(fact[n],finv[n-r]);
}
//nCr%mod
ll nCr(ll n, ll r){
	if(n<r || r<0)return 0;
	return mul(mul(fact[n],finv[r]),finv[n-r]);
}
//初期化
void init(int N){
	fact[0]=finv[0]=1;
	for(int i=1;i<=N;i++){
		fact[i]=(fact[i-1]*i)%mod;
		finv[i]=divll(finv[i-1],i);
	}
}

int main(){
	char c;
	cin>>c;
	cout<<char(c+1)<<endl;
	return 0;
}



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

void fail(){
    cout << -1 << endl;
    exit(0);
}

int main(){
    string S;
    cin >> S;
    int N = S.size();
    S = "0" + S;
    if(S[1] == '0') fail();
    for(int i=1; i<=N; i++) if(S[i] != S[N-i]) fail();

    vector<pair<int, int>> ans;
    int r = 1;
    for(int i=1; i<N; i++){
        if(S[i] == '1'){
            ans.emplace_back(r, i+1);
            r = i+1;
        }else{
            ans.emplace_back(r, i+1);
        }
    }
    for(auto& p : ans) cout << p.first << " " << p.second << endl;
}

Measured memory_bytes: 2416
#include<bits/stdc++.h>
using namespace std;
int main(){
   int N,L;
   cin>>N>>L;

   int taste_left=L;
   int taste_right=L+N-1;

   if(taste_left==0 || taste_right==0){
      cout<<N*(taste_left+taste_right)/2<<endl;
   }
   else if(taste_left<0 && 0<taste_right){
      cout<<N*(taste_left+taste_right)/2<<endl;
   }
   else if(taste_left<0 && taste_right<0){
      cout<<(N-1)*(taste_left+(taste_right-1))/2<<endl;
   }
   else if(0<taste_left && 0<taste_right){
      cout<<(N-1)*((taste_left+1)+taste_right)/2<<endl;
   }
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()

	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
		b[i] = nextInt()
		c[i] = nextInt()
	}

	dp := make([][]int, n)
	for i := 0; i < n; i++ {
		dp[i] = make([]int, 3)
		dp[i][0] = -1
		dp[i][1] = -1
		dp[i][2] = -1
	}

	// 1日目の幸福度を初期値として入れる
	dp[0][0] = a[0]
	dp[0][1] = b[0]
	dp[0][2] = c[0]

	for i := 1; i < n; i++ {
		// 行動Aを選ぶ場合
		dp[i][0] = int(math.Max(float64(dp[i-1][1]), float64(dp[i-1][2]))) + a[i]
		// 行動Bを選ぶ場合
		dp[i][1] = int(math.Max(float64(dp[i-1][0]), float64(dp[i-1][2]))) + b[i]
		// 行動Cを選ぶ場合
		dp[i][2] = int(math.Max(float64(dp[i-1][0]), float64(dp[i-1][1]))) + c[i]
	}

	ans := int(math.Max(float64(dp[n-1][0]), float64(dp[n-1][1])))
	ans = int(math.Max(float64(ans), float64(dp[n-1][2])))
	fmt.Println(ans)
}


Measured memory_bytes: 8704
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef double DB;

#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define R(i,n) for(int i=0;i<(n);++i)
#define fill(a,b) memset(a,b,sizeof(a))

const LL INF = 0x3f3f3f3f3f3f3f3fLL;
LL n,s;

LL cal(LL n,LL b)
{
	if(b == 1) return n;
	LL res = 0;
	while(n)
	{
		res += n%b;
		n /= b;
	}
	return res;
}


int main()
{
	//freopen("test.txt","r",stdin);
	scanf("%lld %lld",&n,&s);
	if(s > n)
	{
		puts("-1");
		return 0;
	}
	if(n == s)
	{
		printf("%lld\n",n+1);
		return 0;
	}
	for(LL i=2;i*i<= n;++i)
		if(cal(n,i) == s)
		{
			printf("%lld\n",i);
			return 0;
		}
	LL b = INF;
	for(LL i=1;i*i<=n - s;++i) if((n-s)%i==0)
	{
		if(cal(n,i+1) == s)
		{
			b = min(b,i+1);
		}
		if(cal(n,(n-s)/i+1) == s)
		{
			b = min(b,(n-s)/i+1);
		}
	}
	if(b == INF)
		puts("-1");
	else
		printf("%lld\n",b);
	return 0;
}


Measured memory_bytes: 256
def main():
    S = input()
    T = input()
    N = len(S)
    M = len(T)

    t = M
    for i in range(N - M + 1):
        b = 0
        for j in range(M):
            if S[i + j] != T[j]:
                b += 1
        t = min(t, b)
    print(t)


if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
	int n,k;
	char str[10];

	scanf("%d",&n);
	scanf("%s",str);
	scanf("%d",&k);
	k--;

	for(int i=0;i<n;i++){
		if(str[i]!=str[k]){
			str[i]='*';
		}
	}

	printf("%s",str);

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
R, S, P = map(int, input().split())  # R=0, S=1, P=2
T = input()

_score = {'r': P, 's': R, 'p': S}
s = [P, R, S]
hand = {'r': 0, 's': 1, 'p': 2}
H = [' '] * N

dp = [[0] * 3 for _ in range(N + 1)]
for sub in range(1, K + 1):
    i = sub
    while i <= N:
        h = hand[T[i - 1]]
        for j in range(3):
            score = s[j] if j == h else 0
            dp[i][j] = max(dp[max(i - K, 0)][(j + 1) % 3], dp[max(i - K, 0)][(j + 2) % 3]) + score
        i += K

ans = 0
for k in range(K):
    ans += max(dp[N - k])

print(ans)


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

struct AB{
  long long a;
  long long b;
};

bool asc(const AB& left,const AB& right){
  return left.a < right.a;
}


int main() {
  int N,M,tmp1,tmp2,get;
  long long cost;
  AB tmp_AB;
  vector<AB> v;
  
  cin >> N >> M;
  for(int i=0;i<N;i++){
    cin >> tmp1 >>tmp2;
    tmp_AB.a=tmp1;
    tmp_AB.b=tmp2;
    v.push_back(tmp_AB);
  }
  
  cost=0;
  get=0;
  int min=0,tmp_num;
  sort(v.begin(),v.end(),asc);
  while(get<M){
    tmp_num = v[min].b;
    if((M-get) <= tmp_num){//終了できるとき
      cost += v[min].a*(M-get);
      break;
    }else{
      cost += v[min].a * v[min].b;
      get += v[min].b;
    }
    min++;
  }

  cout << cost;
}


Measured memory_bytes: 2420
#include<cstdio>

const int MAXN=1e5;

int h[MAXN+5];

int n,m,bad[MAXN+5];

signed main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d",&h[i]);
	for(int i=1,u,v;i<=m;++i){
		scanf("%d %d",&u,&v);
		if(h[v]<=h[u])bad[v]=1;
		if(h[u]<=h[v])bad[u]=1;
	}
	int ans=n;
	for(int i=1;i<=n;++i)if(bad[i])
		--ans;
	printf("%d\n",ans);
	return 0;
}

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

long long int N;
long long int A[100007];

int main(){
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }

    int stop = 0;
    int continueing = 0;
    int mode = 0; // 0 = わからない -1 = 単調非増加 1 = 単調非減少

    if(N != 1){
        for(int i = 0;i < N-1;i++){

            if( (A[i] > A[i+1] && mode == 1) || (A[i] < A[i+1] && mode == -1) ){
                stop++;
                mode = 0;
                continue;
            }

            if(A[i] > A[i+1]){
                mode = -1;
            }
            if(A[i] < A[i+1]){
                mode = 1;
            }
        }
    }

    cout << (stop + 1) << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	char s[15];
	getchar();
	for(int i=0;i<a;i++){
		s[i]=getchar();
		if(s[i]>'9'||s[i]<'0'){
			cout<<"No";
			return 0;
		}
	}
	s[a]=getchar();
	if(s[a]!='-'){
		cout<<"No";
		return 0;
	}
	for(int i=a+1;i<a+b;i++){
		s[i]=getchar();
		if(s[i]>'9'||s[i]<'0'){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;	
}


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

int main() {
  int n;
  
  while(cin >> n && n) {
    int ans = 0;
    for(int i=0; i*i<=n; i++) {
      if(i*i>n) break;
      for(int j=i; j*j<=n; j++) {
	if(i*i+j*j>n) break;
	for(int k=j; k*k<=n; k++) {
	  if(i*i+j*j+k*k>n) break;
	  for(int l=k; l*l<=n; l++) {
	    if(i*i+j*j+k*k>n) break;
	    if(n == i*i+j*j+k*k+l*l) ans ++;
	  }
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  for(int i = 0; i < 3; i++){
    if(s.at(i) == '1'){
      s.at(i) = '9';
    }
    else if(s.at(i) == '9'){
      s.at(i) = '1';
    }
  }
  cout << s;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  LINT Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;

  LINT anseven = min(8*Q, min(4*H, min(2*S, D)));
  LINT ansodd = min(4*Q, min(2*H, S));
  cout << (N/2)*anseven + (N%2)*ansodd << endl;


  return 0;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
typedef long long lint;

struct Point {
	int x, y;
	Point operator - (const Point& p) const { return Point{x - p.x, y - p.y}; }
};

int m;
Point p[16];

int cross(Point& a, Point& b) { return a.x * b.y - a.y * b.x; }
bool is_para(Point& a, Point& b) { return cross(a, b) == 0; }

int calc(vector< int >& a, vector< int >& b) {
	int res = 0;
	for_(i,0,m/2) for_(j,i+1,m/2) {
		Point ai = p[a[i]] - p[b[i]];
		Point bi = p[a[j]] - p[b[j]];
		res += is_para(ai, bi);
	}
	return res;
}

int rec(int i, vector< int >& a, vector< int >& b, vector< bool >& used) {
	if (i == m) return calc(a, b);
	if (used[i]) return rec(i+1, a, b, used);
	
	int ret = 0;
	
	a.push_back(i);
	used[i] = true;
	
	for_(j,0,m) {
		if (used[j]) continue;
		b.push_back(j);
		used[j] = true;
		ret = max(ret, rec(i+1, a, b, used));
		b.pop_back();
		used[j] = false;
	}
	
	a.pop_back();
	used[i] = false;
	
	return ret;
}

int main() {
	cin >> m;
	for_(i,0,m) cin >> p[i].x >> p[i].y;	
	vector< int > a, b;
	vector< bool > used(m, false);
	cout << rec(0, a, b, used) << endl;
}

Measured memory_bytes: 3164
N,K=map(int,input().split())
cnt=0
total=0
p=0
q=0
for i in range(1,N+1):
  total=i
  while total<K:
    total=total*2
    q=q+1
  p=p+(1/N)*(1/2)**q
  q=0
print(float(p)) 

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

const string V = "Vacant";
const string M = "Male";
const string F = "Female";

string a[7] = { M, F, M, F, M, F, V };

string ask(int n){
#ifdef LOCAL
	cerr << n << " " << a[n] << endl;
	return a[n];
#endif

	cout << n << endl;
	string ret;
	cin >> ret;
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N;
	cin >> N;

	string head = ask(0);
	if(head[0] == 'V') return 0;

	int L = 0, R = N;
	while(abs(L - R) > 3){
		int m = (L + R) / 2;
		if(abs(L - m) % 2) m++;
		string res = ask(m);
		if(res[0] == 'V') return 0;
		if(res == head) L = m;
		else R = m;
	}
	while(1){
		L++;
		string res = ask(L);
		if(res[0] == 'V') return 0;
	}
}


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

using namespace std;
using ll=long long;

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int d,n;cin>>d>>n;
  //100 縺ｧ縺｡繧・≧縺ｩ D 蝗槫牡繧翫″繧後ｋ豁｣縺ｮ謨ｴ謨ｰ縺ｮ荳ｭ縺ｧ
  //N 逡ｪ逶ｮ縺ｫ蟆上＆縺・ｂ縺ｮ繧貞・蜉帙＠縺ｪ縺輔＞.
  int cnt=0,val=0,x;
  while(cnt<n){
    ++val;
    x=val;
    int ret=0;
    while(x%100==0){
      x/=100;
      ++ret;
    }
    if(ret==d)++cnt;
  }
  cout<<val<<endl;
}


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

#define ll long long
#define pb push_back
#define N 1000000007
#define pll pair<ll,ll>
#define vec vector<ll> 
#define Adj vector<vector<ll>> 
#define fill_nums(A,n) for(int i=0;i<n;i++) cin>>A[i];
#define fill_edges(adj,m) for(int i=0;i<m;i++) {int a, b; cin>>a>>b; adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(int i=0;i<m;i++) {int a, b; cin>>a>>b; adj[a-1].pb(b-1);}

void dfs(Adj &adj, vec &vals, vec &indegree, int idx, vector<bool> &visited) {

	visited[idx] = 1;
	for(auto i:adj[idx]) {
		indegree[i]--;
		vals[i] = max(vals[i], vals[idx]+1);
		if(!indegree[i]) {
			dfs(adj,vals,indegree,i,visited);
		}
	}
}

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

    Adj adj(n,vec());
    vec indegree(n,0);

    for(int i=0;i<m;i++) {
    	int a, b; 
    	cin>>a>>b; 
    	adj[a-1].pb(b-1);
    	indegree[b-1]++;
    }

    vec vals(n,0);
    vector<bool> visited(n,0);
	for(int i=0;i<n;i++) {
		if(!visited[i] && indegree[i]==0)
			dfs(adj,vals,indegree,i,visited);
	}

	cout<<(*max_element(vals.begin(),vals.end()))<<endl;

    return 0;
}




Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
int n,a[2003],ans,l,r,mid;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
	cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=2;i<=n;i++)
	for(int j=i+1;j<=n;j++)
	{
	    l=1,r=i-1;
	    while(l<=r)
	    {
		mid=(l+r)/2;
		if(a[mid]+a[i]>a[j])
		    r=mid-1;
		else
		    l=mid+1;
	    }
	    ans+=i-l;
	}
    cout<<ans;
    return 0;
}


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

int main() {
  int n;
  string s,alp;
  cin >>n>> s;
  alp="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i=0;i<s.size();i++){
    for(int j=0;j<26;j++){
      if((s.at(i)==alp.at(j))&&(j<=25-n)){
        cout<<alp.at(j+n);
      }
      if((s.at(i)==alp.at(j))&&(j>25-n)){
        cout<<alp.at(j+n-26);
      }
    }
   }
  }

Measured memory_bytes: 384
import sys

# import re
# import math
import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
import copy
# import heapq
# import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
MOD2 = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    k = ni()
    s = input()
    l = len(s)

    if l <= k:
        print(s)
    else:
        print(s[:k]+"...")

if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a;
  for(int i=0;i<n;i++) {
    int b;
    cin >> b;
    a.push_back(b);
  }

  int result = 0;
  
  for(int i=0;i<n;i++) {
    int b = a[i];
    while(1) {
      if (b % 2 == 0) {
        b /= 2;
        result++;
      } else {
        break;
      }
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 384