akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
 
using namespace std;
 
typedef pair<int,int>P;
typedef pair<ll,ll>pll;
 
const int MAX_N = 40;
 
ll w[MAX_N];
ll v[MAX_N];
ll W;
int n;
pll ps[1<<(MAX_N/2)];
 
void solve()
{
    int n2 = n/2;
    rep(i,1<<n2){
        ll sw =0,sv=0;
        rep(j,n2){
            if(i&(1<<j)){
                sw += w[j];
                sv += v[j];
            }
        }
        ps[i] = pll(sw,sv);
    }
    sort(ps,ps+(1<<n2));
    int m=1;
    for(int i=1;i<(1<<n2);i++){
        if(ps[m-1].second < ps[i].second){
            ps[m++] = ps[i];
        }
    }
    ll res = 0;
    rep(i,1<<(n-n2)){
        ll sw=0,sv=0;
        rep(j,n-n2){
            if((i>>j)&1){
                sw += w[n2+j];
                sv += v[n2+j];
            }
        }
        if(sw <= W){
            ll tv = (lower_bound(ps,ps+m,pll(W-sw,INF))-1)->second;
            res = max(res,sv+tv);
        }
    }
    printf("%lld\n",res);
}
 
int main()
{
    cin >> n >> W;
    rep(i,n){
        cin >> v[i] >> w[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 19612
a,b,c = map(int,(input().split()))
ans = 0
if a%2 + b%2 + c%2 == 1:
    if a%2 == 0:
        a += 1
    if b%2 == 0:
        b += 1
    if c%2 == 0:
        c += 1
    ans += 1
if a%2 + b%2 + c%2 == 2:
    if a%2 == 1:
        a += 1
    if b%2 == 1:
        b += 1
    if c%2 == 1:
        c += 1
    ans += 1

A = max(a,b,c) -a
B = max(a,b,c)- b
C = max(a,b,c) -c

print(ans+(A+B+C)//2)

Measured memory_bytes: 38384
#include<stdio.h>
#include<string.h>
 
int main()
{
    int i=0 ;
    int lenw=0 ,lent=0 ;
    int flg=0 ;
    char w[11] = {0} ;
    char t[1001] = {0} ;
 
    scanf("%s",w) ;
    lenw=strlen(w) ;
 
    for (i=0 ;i<lenw ;i++)
    {
        if (w[i] >= 'A' && w[i] <= 'Z')
        {
            w[i] = w[i] + 32 ;
        }
    }
 
    while (1)
    {
        scanf("%s",t) ;
 
        if (strcmp(t ,"END_OF_TEXT") == 0) break ;
 
        lent=strlen(t) ;
        for (i=0 ;i<lent ;i++)
        {
            if (t[i] >= 'A' && t[i] <= 'Z')
            {
                t[i] = t[i] + 32 ;
            }
        }
 
        if (strcmp(t ,w) == 0) flg++ ;
 
    }
 
    printf("%d\n",flg) ;
 
    return 0 ;
}



Measured memory_bytes: 2024
#n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
c1=input()
c2=input()
c3=input()
print(c1[0]+c2[1]+c3[2])

Measured memory_bytes: 8908
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>
#include <memory.h>

// pi = atan(1)*4;

#define INTMAX 2100000000

using namespace std;

int main(void)
{
	string s, t;
	string res = "UNRESTORABLE";

	cin >> s >> t;

	
	for (int i = 0; i < s.length(); i++)
	{
		for (int j = 0; j < t.length(); j++)
		{
			if (t[j] == s[i] || s[i]=='?')
			{
				string temp;
				temp = s;
				int start = i - j;
				if (start < 0 || start >= s.length())
				{
					continue;
				}
				int k;
				for (k = 0; k < t.length(); k++)
				{
					if (start + k >= temp.length())
					{
						break;
					}
					if (temp[start + k] == '?' || temp[start + k] == t[k])
					{
						temp[start + k] = t[k];
					}
					else
					{
						break;
					}
				}
				if (k == t.length())
				{
					for (int i = 0; i < temp.length(); i++)
					{
						if (temp[i] == '?')
						{
							temp[i] = 'a';
						}
					}

					if (res == "UNRESTORABLE")
					{
						res = temp;
					}
					else
					{
						if (res > temp)
						{
							res = temp;
						}
					}
				}
			}
		}
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 256
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function ftAdd(ft::Array{Int,1},k::Int,x::Int)
	t = k
	n = length(ft)
	while t<=n
		ft[t] += x
		t += t&(-t)
	end
	ft
end

function ftSum(ft::Array{Int,1},ll::Int,rr::Int)
	l = ll
	r = rr
	s = 0
	while r>0
		s += ft[r]
		r -= r&(-r)
	end
	while l>0
		s -= ft[l]
		l -= l&(-l)
	end
	s
end

function main()
	n,q = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	ft = zeros(Int,n)
	for i in 1:n
		ftAdd(ft,i,a[i])
	end
	for query in 1:q
		x,y,z = readline() |> split |> parseMap
		if x == 0
			ftAdd(ft,y+1,z)
		else
			println(ftSum(ft,y,z))
		end
	end
end

main()

Measured memory_bytes: 230184
#include <bits/stdc++.h>
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()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int N, M; 
const int limit = 100010;
vector<vector<ll>> graph;
vector<pair<ll, ll>> depth;

void dfs(int v, int p, ll path) {
  if(depth[v].first > path) depth[v] = make_pair(path, p);
  for(auto &e : graph[v]) {
    if(depth[e].first <= path + 1) continue;
    if(path + 1 >= N) continue;
    dfs(e, v, path + 1);
  }
}

int main() {
  cin >> N >> M;
  graph.resize(N + 1);
  depth.assign(limit, make_pair(-1, 0));
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  queue<int> que;
  que.push(1);
  depth[0] = make_pair(0, 0);
  while (!que.empty()) {
      int v = que.front(); que.pop();
      for (auto nv : graph[v]) {
          if (depth[nv].first == -1) {
              depth[nv] = make_pair(depth[v].first + 1, v);
              que.push(nv);
          }
      }
  }

  // dfs(1, -1, 0);
  cout << "Yes" << endl;
  for(int i = 2; i <= N; ++i) {
    cout << depth[i].second << endl;
  }
}


Measured memory_bytes: 13452
#include <iostream>
#include <vector>
#include <map>
// #include <algorithm>
// #include <set>
// #include <cmath>
// #include <string>
 
#define MOD 1000000007

using namespace std;
typedef unsigned long long ull;
 
ull pow_mod(ull x, ull y) {
    if (y == 0) {
        return 1;
    } else if (y % 2 == 0) {
        return pow_mod(x*x % MOD, y/2);
    } else {
        return x * pow_mod(x, y-1) % MOD;
    }
}

int main(int argc, char const *argv[]) {
    int N, K;
    cin >> N >> K;
 
    vector<ull> count(K+1);
    for (int i = K; i >= 1; i--) {
        ull c = pow_mod(K / i, N);
        for (int j = i*2; j <= K; j+=i) {
            c = (c + MOD - count[j]) % MOD;
        }
        count[i] = c;
    }

    ull ans = 0;
    for (int i = 1; i <= K; i++) {
        ans = (ans + count[i] * i) % MOD;
    }

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

Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int L;
  cin >> L;
  double l = (double)L / 3;
  cout << setprecision(20) << l * l * l << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m, n, x, y, z, k;
ll val = 50;

int main()
{
    cin >> k;
    ll m = k / val;

    ll n = k % val;
    cout << val << endl;
    for(ll i = m, j = 1; j <= val; i++, j++) {
        if(j <= val - n) cout << i << ' ';
        else cout << i + 1 << ' ';
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
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; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int N;
  cin >> N;
  cout << (N-1)*N/2 << endl;
  return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
a=[]
dp=[[] for i in range(h)]
for i in range(h):
  for j in range(w):
    dp[i].append(0)
for i in range(h):
  b=input()
  a.append(b)
for i in range(h):
  if a[i][0]=="#":
    break
  dp[i][0]=1
for i in range(w):
  if a[0][i]=="#":
    break
  dp[0][i]=1
for i in range(1,h):
  for j in range(1,w):
    if a[i][j]=="#":
      continue
    else:
      dp[i][j]=dp[i-1][j]+dp[i][j-1]
ans=dp[h-1][w-1]
while(ans>1000000007):
  ans=ans%1000000007
print(ans)

Measured memory_bytes: 158452
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[1000001];
char str[1010][1010];
vector<pair<int,int> > pc[5];
int ABS(int a){return max(a,-a);}
int main(){
    int a[3];
    int max=0,min=101;
    for(int i=0;i<3;i++){
        cin>>a[i];
        if(max<a[i]) max=a[i];
        if(min>a[i]) min=a[i];
    }
    cout<<max-min<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
int main(void)
{
	int sum=0,mx=-1,ss,s,pl;
	char pp[5]={'A','B','C','D','E'};
	while(1) {
		cin>>s>>ss;
		mx=s+ss;pl=0;
		if(s==0 && ss==0) break;
		for(int i=1;i<5;i++) {
			sum=0;
			cin>>s>>ss;
			sum=s+ss;
			if(mx<sum) {mx=sum;pl=i;}
		}
		cout<<pp[pl]<<" "<<mx<<endl;
	}
}
	

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

int main(){
    int n;
    int a,b,c;
    cin>>n;
    int dp[n][3];
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
    for (int i = 1; i <=n ; i++) {
        /* code */
        cin>>a>>b>>c;
        dp[i][0]=a+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

# PyPyだと再帰が遅いので注意
# BEGIN CUT HERE
sys.setrecursionlimit(100000)
class UnionFind():
    '''UnionFind木'''
    def __init__(self,n):
        self.data = [-1] * n
    
    def unite(self, x, y):
        '''x と y を結合'''
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.data[x] < self.data[y]:
            x, y = y, x  # swap
        self.data[x] += self.data[y]
        self.data[y] = x
    
    def find(self, x):
        '''ノード x の親を返す'''
        if self.data[x] < 0:
            return x
        self.data[x] = self.find(self.data[x])
        return self.data[x]

    def same(self, x, y):
        '''x と y が同じグループに属するか判定'''
        return self.find(x) == self.find(y)
    
    def size(self, x):
        '''x を含むグループのノード数を返す'''
        return self.data[self.find(x)]
        
# END CUT HERE

def ABC120_D():
    n, m = mi()
    a = [0] * m
    b = [0] * m
    for i in range(m):
        a[i], b[i] = mi()
        
    uf = UnionFind(n)
    ans = [0] * (m + 1)
    ans[m] = n * (n - 1) // 2

    for i in range(m - 1, -1, -1):
        a[i] -= 1
        b[i] -= 1
        ans[i] = ans[i + 1]
        if uf.same(a[i], b[i]):
            continue
        
        x = uf.size(a[i])
        y = uf.size(b[i])
        ans[i] -= x * y
        
        uf.unite(a[i],b[i])
    
    for i in range(1, m + 1):
        print(ans[i])

# verified on 2019/06/23
# Python3:616ms https://atcoder.jp/contests/abc120/submissions/6094323

def ABC126_E():
    N, M = mi()
    uf = UnionFind(N)
    for i in range(M):
        _X, _Y, _Z = mi()
        uf.unite(_X - 1, _Y - 1)
    ans = 0
    for i in range(N):
        if uf.find(i) == i:
            ans += 1
    print(ans)


if __name__ == '__main__':
    # ABC120_D()
    ABC126_E()

Measured memory_bytes: 36164
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split(' ');
        var num = int.Parse(input[0]);
        var c = long.Parse(input[1]);
        var xv = new long[num + 2][];
        xv[0] = new[] { 0L, 0 };
        for (var i = 1; i <= num; i++)
            xv[i] = Input.arL;
        xv[num + 1] = new[] { c, 0 };
        var sum = new long[num + 2];
        var calc = 0L;
        for (var i = 1; i <= num; i++)
        {
            calc += xv[i][1];
            calc -= xv[i][0] - xv[i - 1][0];
            sum[i] = Max(calc, sum[i - 1]);
        }
        var sumr = new long[num + 2];
        calc = 0;
        for (var i = num; i > 0; i--)
        {
            calc += xv[i][1];
            calc -= xv[i + 1][0] - xv[i][0];
            sumr[i] = Max(calc, sumr[i + 1]);
        }
        var res = 0L;
        for (var j = num; j >= 0; j--)
        { 
            res = Max(res, sum[j] + sumr[j+1] -(c - xv[j+1][0]));
            res = Max(res, sum[j] + sumr[j+1] - xv[j][0]);
        }
        WriteLine(res);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 26168
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

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

	int ans = 0;

	for (int i = 1; i < 101; i++)	//高さ１からスタート
	{
		for (int j = 0; j < N; j++)	//花を選択
		{
			if (h[j] >= i)
			{
				ans++;
				while (h[j] >= i)	j++;
			}
		}
	}

	cout << ans;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


ll A,B,C,D;

ll hoge(ll v) {
	return v-v/C-v/D+v/(C*D/__gcd(C,D));
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C>>D;
	cout<<hoge(B)-hoge(A-1)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0:
        break
    cnt = [0] * 10

    for i in range(n):
        a = int(input())
        cnt[a] += 1

    for a in cnt:
        if a == 0:
            print('-')
        else:
            print('*'*a)


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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<ll> sum(n + 1, 0);
    for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];
    ll ans = 1e18;
    for (int i = 1; i <= n; i++) {
        ans = min(ans, abs(sum[i] - (sum[n] - sum[i])));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int main()
{
        int i;
        cin>>i;
        int a,b,c,d;
        a=i/1000;
        b=i%1000/100;
        c=(i-1000*a-100*b)/10;
        d=i%10;
        if(a+b+c+d==7) {cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;}
        else if(a+b+c-d==7) {cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;}
        else if(a+b-c+d==7) {cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;}
        else if(a-b+c-d==7) {cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;}
        else if(a-b+c+d==7) {cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;}
        else if(a-b-c+d==7) {cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;}
        else if(a+b-c-d==7) {cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;}
        else if(a-b-c-d==7) {cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;}
}


Measured memory_bytes: 256
S = list(input())

for i in range(len(S)-1):
        if S[i] == 'P' and S[i+1] == '?':
                S[i+1] = 'D'



for i in S:
        if i == '?':
                print('D', end = "")
        else:
                print(i, end = "")
print()



Measured memory_bytes: 10576
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

ll mod=1000000007, dp[100010];
ll modpow(ll a, ll b, ll m){
    ll res=1, p=0, now=a%m;
    b %= (m-1);
    for(int i=0; b>p; ++i){
        if(b&((ll) 1<<i)){
            res=(res*now)%m;
            p |= ((ll) 1<<i);
        }
        now=(now*now)%m;
    }
    return res;
}

int main(void){
    int N, K;
    cin >> N >> K;
    ll ans=0;
    for(int i=K; i>0; --i){
        dp[i]=modpow(K/i, N, mod);
        for(int j=2; i*j<=K; ++j){
            (dp[i] += mod-dp[i*j]) %= mod;
        }
        (ans += (dp[i]*i)%mod) %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4376
"use strict";

const main = arg => {
  arg = arg.trim().split("\n");
  const N = parseInt(arg[0]);
  const A = arg[1].split(" ").map(n=>parseInt(n));

  const totalSum = A.reduce((m,n)=>m+n);
  
  let left  = A[0];
  let right = totalSum - A[0];
  
  let answer = Infinity;
  
  for(let i=0; i<N - 1; i++) {
    let diff = Math.abs(right - left);
    answer = Math.min(answer, diff);
    
    right -= A[parseInt(i) + 1];
    left  += A[parseInt(i) + 1];
  }
  
  console.log(answer);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 34360
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

int main(){
    int n, k;
    cin >> n >> k;
    cout << n-k+1 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {
	
	public static void main(String[] args) {
		Task task = new Task();
		task.solve();
	}

	public static class Task {
		static final long MOD = (long) 1e9 + 7;

		public void solve() {
			Scan sc = new Scan();
			long n = sc.scanLong();
			long res = 0;
			if(n > 1){
				for(long div = 1, lim = (long)Math.sqrt(n); div <= lim; ++div){
					if((n-div)%div == 0){
						long cand = (n-div)/div;
						if(n/cand == n%cand)
							res += cand;
					}
				}
			}
			System.out.println(res);
		}
	}

	public static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


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

int main(){
  string S,T,U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  
  if (S == U){
    A--;
  }
  else{
    B--;
  }
  cout << A << " " << B;
  return 0;
}
  


Measured memory_bytes: 256
(defun receive-inputs (current stop)
    (if (< current stop)
        (cons (read-line) (receive-inputs (1+ current) stop))))

(defun add-sharp (lists)
    (princ "#")
    (princ (first lists))
    (princ "#")
    (princ #\LineFeed)
    (if (second lists)
        (add-sharp (cdr lists))))

(defun print-sharp (current stop)
    (if (>= current stop)
        (princ #\LineFeed)
        (progn (princ "#")
               (print-sharp (1+ current) stop))))

(setq h (read))
(setq w (read))
(print-sharp 0 (+ w 2))
(add-sharp (receive-inputs 0 h))
(print-sharp 0 (+ w 2))

Measured memory_bytes: 13024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set =
tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int mod=1e9+7;
int memo[1000010][13];
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string a;
    cin>>a;
    memo[0][0]=1;
    for(int i=0;i<a.length();i++){
        for(int c=0;c<=9;c++){
            int r=a[i]-'0';
            if(a[i]=='?')
                r=c;
            for(int d=0;d<=12;d++){
                memo[i+1][((10*d)+r)%13]+=memo[i][d]%mod;
                memo[i+1][((10*d)+r)%13]%=mod;
            }
            if(a[i]!='?')
                break;
        }
    }
    cout<<memo[a.length()][5]%mod;
}

Measured memory_bytes: 6608
#include<bits/stdc++.h>
using namespace std;
const int N=250050;
int n,a[N],dx[4]={-1,0,0,1},dy[4]={0,1,-1,0},d[N],q[N],l,r,ans;bool vis[N];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n*n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            d[(i-1)*n+j]=min(min(i-1,n-i),min(j-1,n-j));
    for(int i=1;i<=n*n;i++){
        q[l=r=1]=a[i];ans+=d[a[i]];vis[a[i]]=1;
        while(l<=r){
            int id=q[l++],x=(id-1)/n+1,y=(id-1)%n+1;
            for(int j=0;j<4;j++){
                int xx=x+dx[j],yy=y+dy[j],iid=(xx-1)*n+yy;
                if(xx&&xx<=n&&yy&&yy<=n&&d[iid]>d[id]+!vis[id])
                    d[iid]=d[id]+!vis[id],q[++r]=iid;
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }

int main() {
    init();

    int n; cin >> n;
    int i = 0;
    for (int sum = 0; sum < n; ++i)sum += i + 1;
    for (; 0 < i; --i) {
        if (i <= n) {
            print(i);
            n -= i;
        }
    }
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int h,w,ans=0,cnt,dx[4]={1,0,-1,0},dy[4]={0,1,0,-1},dist[25][25]={};
string s[25]={};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  for(int i=0; i<h; i++) {
    cin >> s[i];
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if(s[i][j]=='.') {
        for(int k=0; k<h; k++) {
          for(int l=0; l<w; l++) {
            dist[k][l]=inf;
          }
        }
        queue<P> q;
        q.push(P(i,j));
        dist[i][j]=0;
        cnt=0;
        while(q.size()) {
          P p=q.front();
          q.pop();
          for(int k=0; k<4; k++) {
            int nx=p.second+dx[k],ny=p.first+dy[k];
            if(0<=nx&&nx<=w&&0<=ny&&ny<=h&&s[ny][nx]=='.'&&dist[ny][nx]==inf) {
              q.push(P(ny,nx));
              dist[ny][nx]=dist[p.first][p.second]+1;
              cnt=max(cnt,dist[ny][nx]);
            }
          }
        }
        ans=max(ans,cnt);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
program sample
    implicit none
  
    integer(8) :: i,j,m,n,k,t
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) k,t
    allocate(x(t))
    read(*,*)x
    m=maxval(x)
    n=sum(x)-m
    if (m-n-1<0)then
        write(*,*)0
    else
    write(*,*) m-n-1
    end if
  
    stop
end program sample
  



Measured memory_bytes: 2836
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int main()
{
    _fast_
    ll t = 1;
  //  cin>>t;
    while(t--){
    ll n;
    cin>>n;
    ll h[n+1];
    h[0] = 0;
    for(ll i = 1;i<=n;i++)
    {
        cin>>h[i];
    }
    ll dp[n+1];
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    for(ll i  = 3;i<=n;i++)
    {
        dp[i] = min(dp[i-1]+ abs(h[i]-h[i-1]),dp[i-2]+ abs(h[i]-h[i-2]));
    }
    cout<<dp[n]<<"\n";

    
    }
    return 0;
}

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

using namespace std;

int main(void)
{
    int N;
    cin >>N;
    string S;
    cin >> S;

    for(int i=0;i<S.length();i++){
        int num = (S.at(i) - 'A' +N)%26;
        char res = num+'A';
      
        cout<<res;
    }
  cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 2e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0',  ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };

vector<ll> ans;
ll Map[maxn];

int main()
{
    ll n = read(), k = read(), d = read();
    string s;
    cin>>s;
    ll cnt = 0;
    for(int i=0; i<s.size(); i++)
    {
        //cout<<i<<endl;
        if(s[i]=='o')
        {
            Map[i] = 1;
            i += d;
            cnt++;
        }
       // if(cnt>=k) break;
    }
    if(cnt>=k+1) return 0;
    cnt = 0;
    for(int i=s.size()-1; i>=0 ;i--)
    {
        if(s[i]=='o')
        {
            if(Map[i]) ans.pb(i);
            i -= d;
            //cnt++;
        }
       // if(cnt>=k) break;
    }
    sort(ans.begin(), ans.end());
    for(int i=0; i<ans.size(); i++)
    cout<<ans[i]+1<<'\n';
    return 0;
}


Measured memory_bytes: 6624
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {

		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int r0 = sc.nextInt();
			int w0 = sc.nextInt();
			int c = sc.nextInt();
			int r = sc.nextInt();

			if ((r0 | w0 | c | r) == 0) {
				break;
			}
			System.out.println(solve(r0, w0, c, r));
		}
	}

	// find min X s.t. (R0 + X R) / (W0 + Y) = c
	long solve(int r0,int w0,int c,int r){
		return Math.max(0, (w0 *c - r0 +(r-1))/r);
	}

}



Measured memory_bytes: 26396
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(i);
// sort(arr, arr+n, greater<int>());
// const long double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	string s;
	cin>>s;
	string t;
	cin>>t;
	if(s+t[t.size-1]==t)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main(){
    char s;
    cin >>s;
    switch(s){
        case 'A': 
            cout <<"T"<<endl;
            break;
        case 'C': 
            cout <<"G"<<endl;
            break;
        case 'T': 
            cout <<"A"<<endl;
            break;
        case 'G': 
            cout <<"C"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  //  freopen("in.txt","r",stdin);
    unsigned long long s;
    cin>>s;
    unsigned long long ans=0;
    if(s%2==0)
    {

        unsigned long long a=10;
        while(s>=a)
        {
            ans+= s/a;
            a*=5;
           // cout<<ans<<" "<<a<<endl;
        }
    }
        cout<<ans;


    return 0;
}


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

#define DEBUG 1

#if (DEBUG == 1)

#endif

int main()
{

  int N;
  cin >> N;

  set<int> d;
  for (int i = 0; i < N; i++) {
    int input;
    cin >> input;

    d.insert(input);
  }

  cout << d.size() << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

const int MOD = 1000000007;
const int MX = 777777 + 5;
int fac[MX+5],inv[MX+5];
 
int power(int x,int y,int p){
	int res=1;
	x=x%p;
	while(y){
		if(y&1)res=(res*x)%p;
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    int A[N]; rep(i,N) cin >> A[i];
    int D[N];
    rep(i,N){
        if(!i){
            if(A[i]%2==0){
                D[i]=1;
            } else {
                D[i]=2;
            }
        } else {
            if(A[i]%2==0){
                D[i]=D[i-1]*2+power(3,i,MOD);
            } else {
                D[i]=D[i-1]+2*power(3,i,MOD);
            }
        }
    }
    cout << D[N-1] << endl;
}

Measured memory_bytes: 256
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N,M;
	cin >> N>>M;
	vector<P> AB;
	REP(i,N){
		ll a,b;cin>>a>>b;
		AB.pb(make_pair(a,b));
	}
	
	// 解法
	sort(AB.begin(), AB.end());
	// REP(i,N){
	// 	printf("%lld %lld\n", AB[i].first, AB[i].second);
	// }
	ll count = M;
	ll cost = 0;
	ll i = 0;
	while (count>0 & i<N){
		if (AB[i].second>count){
			cost += AB[i].first * count;
			count = 0;
		}
		else{
			cost += AB[i].first * AB[i].second;
			count -= AB[i].second;
		}
		// printf("i: %lld, count: %lld, cost: %lld\n", i, count, cost);
		i++;
	}
	//出力
	cout << cost << endl;
	// printf("%lld\n", ans); // lld としないとオーバーフローする
	// if (ans) printf("Yes\n");
	// else printf("No\n");
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

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

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> L) {
  LL maxim = 0;
  LL sum = 0;
  for (int i = 0; i < L.size(); i++) {
    maxim = max(L[i], maxim);
    sum += L[i];
  }
  if (maxim * 2 < sum) {
    cout << YES << endl;

  } else
    cout << NO << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> L(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &L[i]);
  }
  solve(N, std::move(L));
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<math.h>
#include<set>
#include<iomanip>
#include<stdio.h>
#include<deque>
#include<stack>
#include<map>
#include<queue>
#include<cstring>
#define M 1000000007
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;cin>>n;
	int l[n],i,j,o=0;
	for(i=0;i<n;i++)
		cin>>l[i];
	sort(l,l+n);
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			int a=l[i];
			int b=l[j];
			int k=lower_bound(l,l+n,a+b)-l;
			if(k>j)
				o+=k-j-1;
		}
	}
	cout<<o<<endl;
}

Measured memory_bytes: 256
s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
S = 'DEFGHIJKLMNOPQRSTUVWXYZABC'
x = input()
a = []
for i in range(len(x)):
    for j in range(len(s)):
      if x[i] == S[j]:
         print(s[j], end='')
      else:
         pass
print()


Measured memory_bytes: 5716
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		if (N == M) {
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
	}
}

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

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

    map <string,int> cnt;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        cnt[s]++;
    }

    cout << "AC x " << cnt["AC"] << endl;
    cout << "WA x " << cnt["WA"] << endl;
    cout << "TLE x " << cnt["TLE"] << endl;
    cout << "RE x " << cnt["RE"] << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <bits/stdc++.h>
#include <deque>
#include <vector>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
    int a,b,c,d,e,k,z=0;
    cin>>a>>b>>c>>d>>e>>k;
    if(e-a>k) z++;
    if(z==0) cout<<"Yay!";
    else cout<<":(";
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int isp[1000000];
vector<int> p;
int main() {
    fill(isp, isp+1000000, 1);
    isp[0]=isp[1]=0;
    for (int i=2; i<1000000; i++) {
        if (!isp[i]) continue;
        p.push_back(i);
        for (int j=i*2; j<1000000; j+=i) isp[j]=0;
    }
    int n;
    while (scanf("%d",&n)) {
        if (!n) break;
        int res=0;
        for (int i=0; i<p.size()&&n-p[i]>=p[i];i++) {
            if (isp[n-p[i]]) res++;
        }
        printf("%d\n",res);
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define P pair<int,int>
using namespace std;

int a[100];
bool dp[300001];
signed main() {
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i <= k; i++) {
		if(!dp[i])
		for (int j = 0; j < n; j++) {
			dp[i + a[j]] = true;
		}
	}
	if (dp[k])puts("First");
	else puts("Second");
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
from heapq import heapify, heappop, heappush
from collections import defaultdict
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

N, K = inpl()
A = sorted(inpl())
F = sorted(inpl(), reverse=True)

OK = 10**13
NG = -1

def check(m):
    tmp = 0
    for i in range(N):
        tmp += max(0, A[i] - m//F[i])
    
    return tmp <= K

while abs(OK - NG) > 1:
    m = (OK + NG)//2
    if check(m):
        OK = m
    else:
        NG = m
    
print(OK)

Measured memory_bytes: 122188
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]


curr = 0
arr = []
visited = [False]*n
while(not visited[curr]):
    visited[curr] = True
    arr.append(curr)
    curr = a[curr]-1

visited = [False]*n
cycleSize = 0
while(not visited[curr]):
    visited[curr] = True
    cycleSize+=1
    curr = a[curr]-1

pathSize = len(arr) - cycleSize

if(pathSize>=k):
    print(arr[k]+1)
else:
    print(arr[(k-pathSize)%cycleSize+pathSize]+1)

Measured memory_bytes: 32316
#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;
const double pi = acos(-1.0);

int main() {
    int r; cin >> r;
    if(r < 1200) cout << "ABC" << endl;
    else if(r < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}

Measured memory_bytes: 3624