akhauriyash/Code-Regression huggingface dataset:
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int a[3][3] = {0};

  rep(i,3)
  rep(j,3)
  {
    cin >> a[i][j];
  }

  int n;
  cin >> n;

  rep(i,n)
  {
    int b;
    cin >> b;

    rep(j,3)
    rep(k,3)
    {
      if(a[j][k] == b)
      {
        a[j][k] = 0;
        break;
      }
    }
  }

  if(
      (a[0][0] == a[0][1] && a[0][1] == a[0][2] && a[0][2]== 0)
      ||(a[1][0] == a[1][1] && a[1][1] == a[1][2] && a[1][2] == 0)
      ||(a[2][0] == a[2][1] && a[2][1] == a[2][2] && a[2][2] == 0)
      ||(a[0][0] == a[1][0] && a[1][0] == a[2][0] && a[2][0] == 0)
      ||(a[0][1] == a[1][1] && a[1][1] == a[2][1] && a[2][1] == 0)
      ||(a[0][2] == a[1][2] && a[1][2] == a[2][2] && a[2][2] == 0)
      ||(a[0][0] == a[1][1] && a[1][1] == a[2][2] && a[2][2] == 0)
      ||(a[0][2] == a[1][1] && a[1][1] == a[2][0] && a[2][0] == 0)
  )
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }
  


  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll A1,A2,A3; cin>>A1>>A2>>A3;
    if((A1+A2+A3)>=22){
        cout<<"bust";
    }
    else{
        cout<<"win";
    }
    return 0;
}


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

int main(){
    string str;
    getline(cin,str);
    int i;
    for(i=0;i<str.size();i++){
        if(str[i]>='a'&&str[i]<='z'){
            str[i]+='A'-'a';
        }
        else if(str[i]>='A'&&str[i]<='Z'){
            str[i]+='a'-'A';
        }
    }
    cout<<str<<endl;
    return 0;
}


Measured memory_bytes: 3148
#include <iomanip>
#include <iostream>

using namespace std;

int N;
long double dp[301][301][301];
bool visited[301][301][301];

long double rec(int a, int b, int c) {
    if (visited[a][b][c]) return dp[a][b][c];
    if (a + b + c == 0) return 0;
    visited[a][b][c] = true;

    long double s = a + b + c;
    dp[a][b][c] = N / s;

    if (a > 0) dp[a][b][c] += a / s * rec(a - 1, b, c);
    if (b > 0) dp[a][b][c] += b / s * rec(a + 1, b - 1, c);
    if (c > 0) dp[a][b][c] += c / s * rec(a, b + 1, c - 1);

    return dp[a][b][c];
}

int main() {
    cin >> N;

    int cnt[3] = {0, 0, 0};
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        ++cnt[a - 1];
    }

    cout << fixed << setprecision(10) << rec(cnt[0], cnt[1], cnt[2]) << endl;
    return 0;
}


Measured memory_bytes: 452992
let () = Scanf.scanf "%s\n%d\n" @@ fun s q ->
  let qs = Array.init q @@ fun _ ->
    Scanf.scanf "%d" @@ function
      | 1 -> Scanf.scanf "\n" `Q1
      | 2 -> Scanf.scanf " %d %c\n" @@ fun f c -> `Q2 (f, c) in
  let (h, t) =
    Array.fold_left (fun (h, t) -> function
      | `Q1 -> (t, h)
      | `Q2 (1, c) -> (c :: h, t)
      | `Q2 (2, c) -> (h, c :: t))
    (Array.to_list (Array.init (String.length s) (String.get s)), []) qs in
  List.iter print_char h;
  List.iter print_char (List.rev t);
  print_newline ()

Measured memory_bytes: 25344
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scanf("%d %d\n", &N, &M)
	cities := make([]int, N+1) // 都市0は使わない。
	for i := 0; i < M; i++ {
		a, b := 0, 0
		fmt.Scanf("%d %d\n", &a, &b)
		cities[a]++
		cities[b]++
	}
	for _, c := range cities[1:] {
		fmt.Println(c)
	}
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int n;
    cin>>n;
    vector<double> vs(n);
    rep(i, n) cin>>vs[i];

    sort(vs.begin(), vs.end());
    double ans = vs[0];
    rep(i, n - 1) {
        ans = (ans + vs[i + 1]) / 2.0;
    }
    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
inputs = []

while true
  h, w = $stdin.readline.split(" ").map {|s| s.to_i }

  if h == 0 && w == 0
    break
  end

  inputs.push([h, w])
end

inputs.each do |h, w|
  (1..h).each do |y|
    puts "#" * w
  end

  puts
end



Measured memory_bytes: 6892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " -> " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" -> ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> H(n);
    rep(i, n) cin >> H[i];
    vector<int> G[101010];
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    int ans = 0;
    rep(i, n) {
        bool ii = 1;
        for (auto v : G[i]) {
            if (H[v] >= H[i]) ii = 0;
        }
        ans += ii;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 8748
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
string s;
cin >> s;
if(s.at(2) == s.at(3) && s.at(4) == s.at(5)){
    cout << "Yes" << endl;
}else{
    cout << "No" << endl;
}
 return 0;

}

Measured memory_bytes: 256
a, b = gets.split.map(&:to_i)

arr = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]

if arr.index(a) > arr.index(b)
  puts 'Alice'
elsif arr.index(a) < arr.index(b)
  puts 'Bob'
else
  puts 'Draw'
end

Measured memory_bytes: 1788
// AOJ 2751 Baseball
// 2018.2.2 bal4u

#include <stdio.h>

#define M 1000000007
#define N 4000000

int fact[N+2], inv[N+2], factinv[N+2];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int comb(int n, int k)
{
	if (n < 0 || k < 0) return 0;
	return (int)((long long)fact[n] * factinv[k] % M * factinv[n-k] % M);
}

int H(int n, int k)
{
	if (!n && !k) return 1;
    return comb(n+k-1, k);
}

int main()
{
	int a, b, c, sx, sy, i;
	long long ans, t;

	fact[0] = 1; for (i = 1; i <= N; i++)
		fact[i] = (long long)fact[i-1] * i % M;
	inv[1] = 1; for (i = 2; i <= N; i++)
		inv[i] = M - (M / i) * (long long)inv[M % i] % M;
	factinv[0] = 1; for (i = 1; i <= N; i++)
		factinv[i] = (long long)factinv[i-1] * inv[i] % M;

	while (1) {
		a = in(), b = in(), c = in(), sx = in(), sy = in();
		if ((a|b|c|sx|sy) == 0) break;

		ans = 0;
		for (i = a; i <= sx; i++) {
			t = H(a, i-a);
			t = t * H(b, sy-sx+i-b) % M;
			t = t * H(a+b+c, sx-i) % M;
			ans += t;
			if (ans >= M) ans -= M;
		}
		ans = ans * comb(a+b+c, a) % M;
		ans = ans * comb(b+c, b) % M;
		printf("%d\n", (int)ans);
	}
    return 0;
}


Measured memory_bytes: 48728
M, N = map(int, input().split())
def fraction(N):
  a = N
  for x in range(N-1,1,-1):
    a = a * x % (1000000007)
  return a

p = abs(M - N)
if p < 2:
  print(fraction(M) * fraction(N) * (2 - p) % (1000000007))
else:
  print(0)
        


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long int f(long long int x)
{
	long long int ans=1;
	for(long long int i=1;i<=x;i++)
	{
		ans=(ans*i)%mod;
	}
	return ans%mod;
}
int main()
{
	long long int n,m;
	cin>>n>>m;
	if(fabs(n-m)>1)
	{
		cout<<"0"<<endl;
		return 0;
	}
	if(fabs(n-m)==1)
	{
		cout<<(f(n)*f(m))%mod<<endl;
	}
	else
	{
		cout<<(f(n)*f(n)*2)%mod<<endl;
	}
} 

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

vector<pair<string,int> > p;

int main() {
	string word;
	int page;
	while(cin>>word>>page){
		p.push_back(mp(word,page));
	}
	int i;
	pair<string,int> pp;
	pair<string,int> pre;
	pre.first="";
	bool f=true;
	for(i=0;i<p.size();i++){
		int j,k=0;
		pp=p[0];
		for(j=1;j<p.size()-i;j++){
			if(pp.first>p[j].first||pp.first==p[j].first&&pp.second>p[j].second){
				pp=p[j];
				k=j;
			}
		}
		if(pp.first!=pre.first){
			if(!f)cout<<endl;
			f=false;
			cout<<pp.first<<endl<<pp.second;
		}else{
			cout<<" "<<pp.second;
		}
		pre=pp;
		p[k]=p[p.size()-i-1];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 0
# B - YYMM or MMYY
# https://atcoder.jp/contests/abc126/tasks/abc126_b

months = [_ for _ in range(1, 13)]
years = [_ for _ in range(0, 100)]

flug = [False] * 4

s = input()
l = int(s[0:2])
r = int(s[2:])


if l in years:
    flug[0] = True

if l in months:
    flug[1] = True

if r in years:
    flug[2] = True

if r in months:
    flug[3] = True

l_y = flug[0]
l_m = flug[1]
r_y = flug[2]
r_m = flug[3]

l_l = [flug[0], flug[1]]
r_r = [flug[2], flug[3]]

if all(flug):
    print('AMBIGUOUS')
elif all(l_l) and r_y == True and r_m == False:
    print('MMYY')
elif all(l_l) and r_y == False and r_m == True:
    print('YYMM')
elif all(r_r) and l_y == True and l_m == False:
    print('YYMM')
elif all(r_r) and l_y == False and l_m ==True:
    print('MMYY')
elif l_y == True and l_m == False and  r_y == False and r_m == True:
    print('YYMM')
elif l_y == False and l_m == True and r_y == True and r_m == False:
    print('MMYY')
else:
    print('NA')


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

int main() {
  string s;
  cin >> s;
  int i;
  for (i = 0; i < s.length(); i++) {
    if (i % 2 == 0) {
      cout << s.at(i);
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 512
#!/usr/bin/python3

import sys
import itertools

s = next(sys.stdin).rstrip()
n = len(s)
a = 0
succ = [[] for i in range(n)]
d = {0: 0}

def getStep(a):
    ret = None
    for alt in itertools.chain([1 << rot for rot in range(26)], [0]):
        x = a ^ alt
        if x in d and (ret is None or d[x] + 1 < ret):
            ret = d[x] + 1
    return ret

for i, c in enumerate(s):
    ac = ord(c) - 0x61
    br = 1 << ac
    a = a ^ br
    s = getStep(a)
    if s is None: raise ValueError
    if a not in d or s < d[a]: d[a] = s
print(getStep(a))



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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int a=fsc.nextInt(), b=fsc.nextInt(), x=fsc.nextInt();
        fsc.close();
        if(a<=x && x<=a+b) System.out.println("YES");
        else System.out.println("NO");
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 21460
#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--) //逆ループ

//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;

using namespace std;

//#include "./lib/generic/search.h"

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans=0, sum=0;
    rep(i,n){
        cin >> a[i];
        if(i>=1){
            sum+=a[i];
        }
    }
    for(int i=0; i<n-1; i++){
        ans+=((sum%1000000007)*(a[i]%1000000007))%1000000007;
        if(ans>=1000000007) ans=ans%1000000007;
        sum-=a[i+1];
    }
    ans=ans%1000000007;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4832
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,n,l;
	cin>>n;
	ll ar[n+10];
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	sort(ar+1,ar+n+1);

	k=(n/2); l=(n/2)+1;
	//cout<<ar[k]<<" "<<ar[l]<<endl;
	cout<<(ar[l]-ar[k]);
	return 0;
}

Measured memory_bytes: 1024
def main():
    S = input()
    if(len(set(S)) != 2):
        print("No")
        return
    S_sort = sorted(list(S))
    if (S_sort[1] == S_sort[2]): # ex ['A','B','B','B']
        print("No")
    else:
        print("Yes")

main()



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

#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<ll>>;
#define MAX 1000000007

int main()
{
    int n,m;
    cin >> n >> m;
    int a,b;
    dsu d(n);
    rep(i,m){
        cin >> a >> b;
        d.merge(a-1,b-1);
    }
    set<int> st;
    rep(i,n){
        st.insert(d.leader(i));
    }
    cout << st.size()-1 << endl;

}

Measured memory_bytes: 7468
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;


void solve()
{
	int n,q,x,y;
	cin>>n;
	int a[n],i,sum=0;
	map<int,int> mp;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
		sum+=a[i];
	}
	cin>>q;
	for(i=0;i<q;i++)
	{
		cin>>x>>y;
		int val=mp[x];
		mp[y]+=val;
		mp[x]=0;
		sum+=(y-x)*val;
		cout<<sum<<endl;
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}

Measured memory_bytes: 10300
#include<iostream>

int main(void) {
	int N = 0, H = 0, result = 0;
	int T = 0, A = 0,save = 500000000,B = 0;
	std::cin >> N >> T >> A;
	for (int i = 0; i < N;i++) {
		std::cin >> H;
		B = (T * 1000 - H * 6) - A * 1000;
		if (B < 0) {
			B = B * -1;
		}

		if (B < save) {
			save = B;
			result = i + 1;
		}
	}
	std::cout << result << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
using namespace std;
int main(){

	int n;
	
	while(cin>>n,n!=0){
		int c=0;
		vector<int> s(n);
		for(int i=0;i<n;i++)
			cin>>s[i];
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n-1;j++){
				if(s[j]>s[j+1]){
				swap(s[j],s[j+1]);
					c++;
				}
			}
			
		}
		cout<<c<<endl;
	}
	
	
}

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

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

 int main() {
   int N, K;
   ll ans = 0;
   cin >> N >> K;
   vector<ll> H(N);

   rep(i, N) cin >> H.at(i);
   if (N > K) {
     sort(H.begin(), H.end());
     rep(i, N - K) ans += H.at(i);
   }
   cout << ans << endl;
 }


Measured memory_bytes: 1792
//Problem *
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int dp[N],a[N],n;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=2;i<=n;i++){
		dp[i]=dp[i-1]+abs(a[i-1]-a[i]);
		if(i>2)dp[i]=min(dp[i],dp[i-2]+abs(a[i-2]-a[i]));
	}
	printf("%d",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var sc = new Scanner();
            int r = sc.NextInt();
            int D = sc.NextInt();
            int x = sc.NextInt();

            for (int i = 0; i < 10; i++)
            {
                x = r * x - D;
                Console.WriteLine(x);
            }

        }
    }
}




class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private readonly StreamReader _stream;
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}


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

void max_self(ll& a, ll b) {
    a = min(a, b);
}
const ll INF = 1e18L+1;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    int n, w;
    cin >> n >> w;
    vector<int> weight(n), value(n);
    for(int i=0; i<n; ++i) {
        cin >> weight[i] >> value[i];
    }
    ll sum_value = 0;
    for(auto x: value) {
        sum_value += x;
    }
    vector<ll> dp(sum_value+1, INF);
    dp[0] =0;
    for(int i=0; i < n; ++i) {
        for(int j=sum_value ; j >= value[i]; --j) {
            max_self(dp[j], dp[j-value[i]]+weight[i]);
            /*above line finds out maximum of  dp[j](excluding ith element value) 
      and value + dp[j-weight] (including ith element value and the 
      profit with "KnapSack capacity - ith element weight") */    
        }
    }
        
    ll ans = 0;
    for(int i=0; i<=sum_value; ++i) {
        if(dp[i] <= w) {
            ans = max(ans, (ll)i);
        }
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1024
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

void solve(ll N, std::string S) {
  ll result = 0;
  ll cntR = 0;
  ll cntG = 0;
  ll cntB = 0;

  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'R')
      cntR++;
    if (S.at(i) == 'G')
      cntG++;
    if (S.at(i) == 'B')
      cntB++;
  }

  ll e = 0;

  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      if (S.at(i) == S.at(j))
        continue;
      int k = 2 * j - i;
      if (k < N && S.at(i) != S.at(j) && S.at(j) != S.at(k) &&
          S.at(k) != S.at(i)) {
        e++;
      }
    }
  }

  result = cntR * cntG * cntB - e;

  cout << result << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  std::string S;
  std::cin >> S;
  solve(N, S);
  return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#define ll long long
using namespace std;
ll mod=1000000007;
char grid[1002][1002];
int solve(int n,int m)
{
    ll dp[n+1][m+1];
    dp[n][m]=1;
    for(int i=n;i>=1;i--)
    {
        for(int j=m;j>=1;j--)
        {  
            if(i==n && j==m)
           {
            continue;
           }
            if(grid[i][j]=='#')
            {
                dp[i][j]=0;
            }
            else
            {
                dp[i][j]=(((j==m)?0:dp[i][j+1])+((i==n)?0:dp[i+1][j]))%mod;
            }
        }
    }
    return dp[1][1];
}
int main() {
int n,m;
cin>>n>>m;
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=m;j++)
    {
        cin>>grid[i][j];
    }
  }
  cout<<solve(n,m);
}


Measured memory_bytes: 12324
using System;

namespace diverta2019_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var SD = new int[3];
            int r = 0;

            for (int i = 0; i < N; i++) 
            {
                var s = Console.ReadLine();
                int m = 0;

                if (s.Contains("AB"))
                    for (int j = 0; j < s.Length - 1; j++)
                        if (s[j] == 'A' && s[j + 1] == 'B')
                            r++;
                // *A
                if (s[s.Length - 1] == 'A')
                    m += 1;

                // B*
                if (s[0] == 'B') 
                    m += 2;

                if (m > 0)
                    SD[m - 1]++;
            }

            // *A B*A.. B*
            if (SD[0] > 0 && SD[2] > 0 && SD[1] > 0)
            {
                SD[0]--;
                r += SD[2] + 1;
                SD[1]--;
            }
            // *A B*A..
            else if (SD[0] > 0 && SD[2] > 0)
            {
                SD[0]--;
                r += SD[2];
            }
            // B*A.. B*
            else if (SD[2] > 0 && SD[1] > 0)
            {
                r += SD[2];
                SD[1]--;
            }
            // B*A B*A..
            else if (SD[2] > 0)
            {
                r += SD[2] - 1;
            }

            // *A B* を可能な限りつなげる
            r += Math.Min(SD[0], SD[1]);

            Console.WriteLine(r);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j;
    while(cin>>n>>m)
    {
        if ((n+m)%3==0||n%3==0||m%3==0)
            cout<<"Possible"<<endl;
        else
            cout<<"Impossible"<<endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>

int main(){
   unsigned long int a,b,k,i;
   scanf("%ld %ld %ld",&a,&b,&k);
   if(a>k){
      printf("%ld %ld",a-k,b);
   }else if(a<=k&&a+b>k){
      printf("%d %ld",0,a+b-k);
   }else{
      printf("%d %d",0,0);
   }
   return 0;
}


Measured memory_bytes: 1728
#include <iostream>
using namespace std;
typedef long long ll;
ll n,s[100000],a,ch[32],A,cnt;
ll f(ll n){
    for(int i=31;i>=0;i--){
        if(((n>>i)&1)==1)return i+1;
    }
    return 0;
}
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        ch[f(s[i]^(s[i]-1))]=1;
        A^=s[i];
    }
    for(int i=32;i>=0;i--){
        if(((A>>i)&1)==1){
            if(ch[i+1]){
                A^=((1<<(i+1))-1);
                cnt++;
            }
        }
    }
    if(A==0)cout<<cnt<<endl;
    else cout<<-1<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
typedef long long int ll;

void input(){
   ll n ; cin >> n;
   vector<ll> a(n);
   f(i, n)cin >>a[i];
   ll ans = 0;
   ll temp = 0;
   ll prev = INT_MIN;
   for(int i = n - 1; i >= 0; --i){
        if(a[i] >= prev){
            ++temp;
        }else{
            temp = 1;
        }
            ans = max(ans, temp);
            prev = a[i];
   }
   cout << max(ans - 1, (ll)0) << endl;
}
int main()
{
 input();
 return 0;
}


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

int main()
{
    int n,b=0;
    cin>>n;
    int a[n];
    for(int j=0;j<n;++j)
    cin>>a[j];
for(int i=0;i<=n;++i)
{
    if((a[i]%2!=0)&&((i+1)%2!=0))
    {
    b++;
    }
}
cout<<b;

}


Measured memory_bytes: 3640
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> A(n, vector<int>(m));
    vector<int> b(m);

    rep(i, n) rep(j, m) cin >> A[i][j];
    rep(i, m) cin >> b[i];

    rep(i, n) {
        int t = 0;
        rep(j, m) t += A[i][j] * b[j];
        cout << t << endl;
    }
    return 0;
}


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

long long n,x,v[205],dp[205][100005][2],mod=1e9+7ll;

int main(){

	cin>>n>>x;
	
	for(int i=0;i<n;i++)cin>>v[i];
	sort(v,v+n);
	reverse(v,v+n);
	
	for(long long i=n-1;i>=0;i--){
	    for(int j=0;j<100005;j++){
	        if(i==n-1){
	            dp[i][j][0]=dp[i][j][1]=j%v[i];
                continue;
            }
            
            dp[i][j][1]=(dp[i+1][j%v[i]][1]+dp[i+2][j%v[i]][0])%mod;
            
            dp[i][j][0]=((dp[i][j][1]+dp[i+1][j][0])*(n-i))%mod;
        }
    }

    cout<<(dp[0][x][1]+dp[1][x][0])%mod<<endl;

return 0;
}


Measured memory_bytes: 313600
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)

static uint32_t calcDigitSum(const uint32_t A, const uint32_t B) {
	uint32_t sum = 0;
	uint32_t dividedA = A;
	uint32_t dividedB = B;

	while (dividedA > 0) {
		sum += dividedA % 10;
		dividedA /= 10;
	}
	while (dividedB > 0) {
		sum += dividedB % 10;
		dividedB /= 10;
	}

	return sum;
}

int main(void) {
	uint32_t N;
	uint32_t min = UINT32_MAX;

	scanf("%"PRIu32, &N);

	for (uint32_t A = 1; A < N; A++) {
		const uint32_t B = N - A;
		const uint32_t digitSum = calcDigitSum(A, B);
		if (digitSum < min) {
			min = digitSum;
		}
	}

	printf("%"PRIu32, min);

	return 0;
}


Measured memory_bytes: 128
def c_daydream(S):
    # Sを逆にしたものから除いていき、空文字にできるか？
    s = S[::-1]
    word = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
    ans = 'YES'
    while s:
        for w in word:
            if s.startswith(w):  # 先頭が文字列wで始まっていたら、取り除く
                s = s.replace(w, '', 1)
                break
        else:
            ans = 'NO'
            break
    return ans

S = input().strip()
print(c_daydream(S))

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){
    int N;
    cin>>N;
    int h[N+1];
    rep2(i,N){
        cin>>h[i];
    }
    vector<long long>dp(N+1,INF);
    dp[1]=0;
    dp[2]=dp[1]+abs(h[2]-h[1]);
    for(int i=3;i<=N;i++){
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<dp[N]<<endl;

    return 0;

}
/*


*/


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,p,f[200009],pl,aa,pas,x,y,sm[200009],xar[200009];
map <long long, long long> m;
string s;
long long mod(long long q){
    if(q>=0) return q%p; else return (p-(abs(q)%p))%p;
}
/*long long xar(long long q, long long w){
    if(w==0) return 1;
    long long hj=xar(q,w/2);
    if(w%2==0) return (hj*hj)%p; else return ((hj*hj)%p*q)%p;
}
long long dv(long long q, long long w){
    return q*xar(w,p-2);
}*/
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a>>p;
    cin>>s;
    for(b=1; b<=a; b++) f[b]=s[b-1]-'0';
    if(p==2){
        for(b=1; b<=a; b++){
            if(f[b]%2==0){
                pas+=b;
            }
        }
        cout<<pas;
        return 0;
    }
    if(p==5){
        for(b=1; b<=a; b++){
            if(f[b]%5==0){
                pas+=b;
            }
        }
        cout<<pas;
        return 0;
    }
    xar[0]=1;
    for(b=1; b<=a+2; b++){xar[b]=xar[b-1]*10;xar[b]%=p;}
    for(b=a; b>=1; b--){
        sm[b]=sm[b+1]+f[b]*xar[a-b];
        sm[b]%=p;
    }
    /*for(b=1; b<=a; b++) cout<<sm[b]<<" ";
    cout<<endl;*/
    for(b=a; b>=0; b--){
        pas+=m[sm[b]];
        m[sm[b]]++;
    }
    //for(b=1; b<=a; b++) if(f[b]%p==0) pas++;
    cout<<pas;
    return 0;
}

Measured memory_bytes: 5780
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

char S[200050];

int main() {
  scanf("%s", S);
  for (int i = 0; S[i]; ++i) {
    if (S[i] == '?') {
      putchar('D');
    } else {
      putchar(S[i]);
    }
  }
  puts("");

  return 0;
}


Measured memory_bytes: 3876
#include <iostream>

using namespace std;

int main()
{
     
	int N;
	int c[4] = {};
	cin >> N;
	string i;

	while (1) {

		cin >> i;

		if (i == "AC")c[0]++;
		else if (i == "WA")c[1]++;
		else if (i == "TLE")c[2]++;
		else if (i == "RE")c[3]++;

		N--;
		if (N == 0)break;
	}

	cout << "AC" << " x " << c[0]<<endl;
	cout << "WA" << " x " << c[1] << endl;
	cout << "TLE" << " x " << c[2] << endl;
	cout << "RE" << " x " << c[3] << endl;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#ifdef _DEBUG
#define dd(x) cout << #x << " : " << x << endl
#else
#define dd(x)
#endif
using namespace std;
using ll = int64_t;

char get_best_action(char tc) {
    if(tc == 'r') {
        return 'p';
    } else if(tc == 's') {
        return 'r';
    } else {
        return 's';
    }
}

int main(){
    int n, k; cin >> n >> k;
    int r, s, p; cin >> r >> s >> p;
    string t; cin >> t;

    string h = "";
    int ans = 0;
    int tsize = t.size();
    rep(i, tsize) {
        char tc = get_best_action(t[i]);
        if(i < k) {
            h += tc;
            if(tc == 'p') ans += p;
            else if(tc == 's') ans += s;
            else ans += r;
        } else {
            if(h[i-k] == tc) {
                if(i+k < tsize) {
                    char tc2 = get_best_action(t[i+k]);
                    if(tc == 'p' && tc2 == 'p') h += 's';
                    else if(tc == 'p' && tc2 == 'r') h += 's';
                    else if(tc == 'p' && tc2 == 's') h += 'r';
                    else if(tc == 's' && tc2 == 's') h += 'r';
                    else if(tc == 's' && tc2 == 'r') h += 'p';
                    else if(tc == 's' && tc2 == 'p') h += 'r';
                    else if(tc == 'r' && tc2 == 'r') h += 'p';
                    else if(tc == 'r' && tc2 == 'p') h += 's';
                    else if(tc == 'r' && tc2 == 's') h += 'p';
                } else {
                    if(tc == 'p') h += 's';
                    else if(tc == 's') h += 'r';
                    else h += 'p';
                }
            } else {
                h += tc;
                if(tc == 'p') ans += p;
                else if(tc == 's') ans += s;
                else ans += r;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3732
#binary_search
def isOK(lis, index, key):
    if lis[index] > key:
        return True
    else:
        return False
def binary_search(lis, key):
    ng = -1
    ok = len(lis)
    while abs(ok - ng) > 1:
        mid = int((ok + ng)/2)
        if isOK(lis, mid, key):
            ok = mid
        else:
            ng = mid
    return ok

N = int(input())
A = sorted([int(a) for a in input().split()])
B = sorted([int(b) for b in input().split()])
C = sorted([int(c) for c in input().split()])
COUNT = [0]
total = 0
for b in B[::-1]:
    index = binary_search(C, b)
    total += (N - index)
    COUNT.append(total)
COUNT = COUNT[::-1]
counter = 0
for a in A:
    index = binary_search(B, a)
    counter += COUNT[index]
print(counter)

Measured memory_bytes: 112228
#include <bits/stdc++.h>
using namespace std;
 
const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;


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

    vec x_count(100001, 0);
    vec m_count(M, 0);
    for(int i=0;i<N;i++){
        int x;
        cin >> x;
        x_count[x]++;
        m_count[x % M]++;
    }

    int ans = 0;
    // for(int i=0;i<M;i++){
    //     cout << m_count[i];
    // }
    // cout << endl;
    for(int i=0;i<M;i++){
        if(i == 0 || 2 * i == M){
            int use = m_count[i];
            if(use <= 1) continue;
            if(use % 2 == 1) use--;
            m_count[i] -= use;
            ans += use / 2;
        }else{
            int use = min(m_count[i], m_count[M - i]);
            if(use <= 0) continue;
            m_count[i] -= use;
            m_count[M - i] -= use;
            ans += use;
            // cout << i << " " << M - i <<  " " << use << endl;
        }
    }
    // cout << ans << endl;
    // for(int i=0;i<M;i++){
    //     cout << m_count[i];
    // }
    // cout << endl;

    for(int i=1;i<=100000;i++){
        if(m_count[i % M] >= 2 && x_count[i] >= 2){
            int use = min(m_count[i % M], x_count[i]);
            if(use % 2 == 1) use--;
            x_count[i] -= use;
            m_count[i % M] -= use;
            ans += use / 2;
        }
    }

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


Measured memory_bytes: 1024
//atcoder clange
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void){
    int N,D;
  
     scanf("%d", &N);//数値の取得
   scanf("%d", &D);//数値の取得

  int i=0;
  int j=0;
  int X[N][D];
  for(i=0;i<N;i++){
	for(j=0;j<D;j++){
  	 scanf("%d", &X[i][j]);//数値の取得
    }
  }
  
  
  double ans[10000];
  int k=0;
  int count = 0;
  for(i=0;i<N-1;i++){
	for(j=i+1;j<N;j++){
      for(k=0;k<D;k++){
  	 ans[count] = ans[count] + abs(X[i][k] - X[j][k]) * abs(X[i][k] - X[j][k]);
    }
      count++;
      //printf("count:%d",count);
    //  printf("ans[%d]:%lf\n",count,ans[count-1]);
    }
    
  }
  int num = (N*(N-1))/2;
 //printf("N:%d",N);
 // printf("num:%d",num);
  double ans2[num];
  int anscount = 0;
  
  for(i=0;i<num;i++){
    //printf("ans[%d]:%lf\n",i,ans[i]);
	ans2[i] = sqrt(ans[i]);
   // printf("ans2:%lf\n",ans2[i]);
  if(ceil(ans2[i]) == floor(ans2[i])){
    anscount++;
  }
    
  }
  printf("%d",anscount);
 
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <climits>
#include <numeric>
#include <cstring>
#include <utility>
#include <bitset>
#include <ctime>
#include <cmath>
#include <complex>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef vector<vector<int> > vvint;

typedef long double D;
typedef complex<D> P;
typedef const P &rP;

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

#define MOD 1000000007LL
#define INF 1010101010


LL powmod(LL x, LL y){
	LL a = 1;
	while(y){
		if(y & 1){ a = a * x % MOD; }
		y >>= 1;
		x = x * x % MOD;
	}
	return a;
}


struct UF{
	vector<int> par;

	UF(int n) : par(n + 1){
		for(int i = 1; i <= n; ++i){
			par[i] = i;
		}
	}

	int find(int x){
		return x != par[x] ? par[x] = find(par[x]) : x;
	}

	bool unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y){ return false; }
		if(rand() & 512){ swap(x, y); }
		par[x] = y;
		return true;
	}
};


int main(){
	srand(time(0));
	
	int n, m, a, b;
	while(scanf("%d%d", &n, &m), n){
		UF uf(n);
		for(int i = 0; i < m; ++i){
			scanf("%d%d", &a, &b);
			uf.unite(a, b);
		}

		int c = 0;
		for(int i = 1; i <= n; ++i){
			if(uf.find(i) == i){ ++c; }
		}

		LL ans = 0;

		if(c == n){
			ans = powmod(2, n);
		}
		else{
			ans = (powmod(2, c) + 1) % MOD;
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 1600
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
template<class T> inline bool Cmax(T &x,T y) {return x<y?x=y,1:0;}
const int maxn=1e6+50;
int n;
int sum[maxn],mx[maxn];
bool mark[maxn];
char S[maxn];
int f(int M) {
	static int s[maxn]; s[0]=0;
	for(int i=1,cnt=0;i<=n;++i) {
		if(mark[i]) {
			if(mx[i]+2*(cnt+1)<=M) s[i]=1,++cnt;
			else s[i]=-1;
		}
		else s[i]=S[i]=='0'?-1:1;
	}
	for(int i=1;i<=n;++i) s[i]+=s[i-1];
	return *min_element(s,s+n+1);
}
int main() {
	scanf("%s",S+1),n=strlen(S+1);
	for(int i=1;i<=n;++i) {
		if(S[i]=='?') mark[i]=1;
		if(S[i]=='1') sum[i]=sum[i-1]+1;
		else sum[i]=sum[i-1]-1;
	}
	for(int i=n;i>=0;--i) {
		mx[i]=sum[i];
		if(i!=n) Cmax(mx[i],mx[i+1]);
	}
	int Z=mx[0];
	printf("%d\n",min(Z-f(Z),(Z+1)-f(Z+1)));
	return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    ll n, w;
    cin >> n >> w;
    P things[n];
    rep(i, n) cin >> things[i].fi >> things[i].se;
    ll w1;
    w1 = things[0].fi;
    sort(things, things + n); reverse(things, things + n);
    ll sum[4][100] = {}, idx[4] = {1, 1, 1, 1};
    rep(i, n) {
        ll j = things[i].fi - w1;
        sum[j][idx[j]] = sum[j][idx[j] - 1] + things[i].se;
        idx[j]++;
    }
    ll maxi = 0;
    rep(a, idx[0])rep(b, idx[1])rep(c, idx[2])rep(d, idx[3]) {
        if (a * w1 + b * (w1 + 1) + c * (w1 + 2) + d * (w1 + 3) <= w) {
            maxch(maxi, sum[0][a] + sum[1][b] + sum[2][c] + sum[3][d]);
        }
    }
    cout << maxi << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N ;
  bool possible = false;

  for (int i=0;i<=N/4;i++){
    for (int j=0;j<=N/7;j++){
      if (4*i+7*j == N) possible = true;
      else if(4*i+7*j>N) break;
    }
  }
  cout << (possible ? "Yes" : "No") << endl;

}

  
  

Measured memory_bytes: 256
#include<map>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int n,w;
  map<int,int> a;
  map<int,int>::iterator it;
  while(cin>>n&&n){
    a.clear();
    for(i=0;i<n;i++){
      int p,q,r;
      cin>>p>>q>>r;
      a[q]+=p;
      a[r]-=p;
    }
    w=0;
    for(it=a.begin();it!=a.end();it++){
      w+=(*it).second;
      if(w>150)
	break;
    }
    if(w>150)
      cout<<"NG"<<endl;
    else
      cout<<"OK"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#                         author:  kagemeka 
#                         created: 2019-11-09 11:51:37(JST)
### modules
## from standard library
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   
# import scipy.misc      
# import numpy as np 

def main():
    n, k = (int(x) for x in sys.stdin.readline().split())
    print(0 if n % k == 0 else 1) 



if __name__ == "__main__":
    # execute only if run as a script
    main()


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

int main() {
    int n;
    cin >> n;
    vector<int> abc(3);
    for (auto& e : abc) {
        cin >> e;
    }
    vector<int> l(n);
    for (auto& e : l) {
        cin >> e;
    }

    int ans = 1e9;
    for(size_t i = 1; i <= n-2; i++) {
        for(size_t j = 1; j <= n-i-1; j++) {
            for(size_t k = 1; k <= n-i-j; k++) {
                vector<int> sel;
                for(size_t as = 0; as < i; as++) sel.push_back(0);
                for(size_t bs = 0; bs < j; bs++) sel.push_back(1);
                for(size_t cs = 0; cs < k; cs++) sel.push_back(2);
                for(size_t ns = 0; ns < n-i-j-k; ns++) sel.push_back(3);
                do {
                    int can = 0;
                    vector<vector<int>> tmp(4);
                    for(size_t i = 0; i < n; i++) {
                        tmp[sel[i]].push_back(l[i]);
                    }
                    for(size_t i = 0; i < 3; i++) {
                        can += (tmp[i].size() - 1) * 10;
                        can += abs(accumulate(tmp[i].begin(), tmp[i].end(), 0) - abc[i]);
                    }
                    ans = min(ans, can);
                } while(next_permutation(sel.begin(), sel.end()));
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A=scanner.nextInt();
        int B=scanner.nextInt();
        int C=scanner.nextInt();
        int D=scanner.nextInt();
        while(true){
            if(A<=0){
                System.out.println("No");
            break;
            }
            C=C-B;
            if(C<=0)
            {
                System.out.println("Yes");
                break;
            }
            A=A-D;
        }
    }
}


Measured memory_bytes: 35504