akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException; 
import java.io.InputStream; 
import java.io.PrintWriter; 

class Main{ 

	static void solve(){
		int n = ni(), k=ni();
		long ans = 0;
		long[] cnt = new long[k];
		for(int i=1;i<=n;++i)cnt[i%k]++;
		for(int i=0;i<k;++i){
			if(i*2%k==0)ans += cnt[i]*cnt[i]*cnt[(k-i)%k];
		}
		System.out.println(ans);
 
	} 
 
 
 
 
	public static void main(String[] args){ 
		 solve(); 
		 out.flush(); 
	 } 
	 private static InputStream in = System.in; 
	 private static PrintWriter out = new PrintWriter(System.out); 
 
	 private static final byte[] buffer = new byte[1<<15]; 
	 private static int ptr = 0; 
	 private static int buflen = 0; 
	 private static boolean hasNextByte(){ 
		 if(ptr<buflen)return true; 
		 ptr = 0; 
		 try{ 
			 buflen = in.read(buffer); 
		 } catch (IOException e){ 
			 e.printStackTrace(); 
		 } 
		 return buflen>0; 
	 } 
	 private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} 
	 private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} 
	 private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} 
 
	 private static double nd(){ return Double.parseDouble(ns()); } 
	 private static char nc(){ return (char)skip(); } 
	 private static String ns(){ 
		 StringBuilder sb = new StringBuilder(); 
		 for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); 
		 return sb.toString(); 
	 } 
	 private static int[] nia(int n){ 
		 int[] res = new int[n]; 
		 for(int i=0;i<n;++i)res[i]=ni(); 
		 return res; 
	 } 
	 private static long[] nla(int n){ 
		 long[] res = new long[n]; 
		 for(int i=0;i<n;++i)res[i]=nl(); 
		 return res; 
	 } 
	 private static int ni(){ 
		 int res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	 } 
	 private static long nl(){ 
		 long res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	} 
} 



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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

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

  ll k, n;
  cin >> k >> n;

  vector<ll> a(n);

  ll first;

  REP(i, n) { cin >> a[i]; }
  first = a[0];
  REP(i, n) { a[i] -= first; }

  ll large = 0;
  REP(i, n) {
    if (i == n - 1) {
      large = max(large, k - a[i]);
    } else {
      large = max(large, a[i + 1] - a[i]);
    }
  }

  cout << k - large << "\n";
}

Measured memory_bytes: 1792
class Main {
    private void qq() {
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                System.out.println(i + "x" + j + "=" + (i * j));
            }
        }
    }

    public static void main(String[] args) {
        (new Main()).qq();
    }
}

Measured memory_bytes: 9336
n = int(input())
x = [0]*100001
a = list(map(int,input().split()))
m = 0
ma = 0
for i in range(n):
    x[a[i]]+=1
for i in range(100001-2):
    m=x[i]+x[i+1]+x[i+2]
    if m>ma:
        ma=m
print(ma)


Measured memory_bytes: 14856
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

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

	for (int i = 0; i < 100000; i++)
	{
		int a = (int)(i * 1.08);
		if (a == N)
		{
			cout << i << endl;
			return 0;
		}
	}

	cout << ":(" << endl;
}



Measured memory_bytes: 256
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let length = s.trim().parse().unwrap();
    s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let input = s.trim();
    if input.chars().count() > length {
        for (i, c) in input.chars().enumerate() {
            if i < length {
                print!("{}", c);
            } else {
                println!("...");
                break;
            }
        }
    } else {
        println!("{}", input);
    }
}


Measured memory_bytes: 2164
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(int n, int k) {
    auto m = new long[k];
    for (int i = 1; i <= n; i++)
        m[i % k]++;

    long ans = 0;
    for (int i = 1; i <= n; i++) { // a を固定
        int a = i % k;
        int b = (k - a) % k;
        int c = (k - a) % k;
        if ((b + c) % k == 0) {
            ans += m[b] * m[c];
        }
    }
    return ans;
}

void main() {
    int n, k; scan(n, k);
    writeln(calc(n, k));
}


Measured memory_bytes: 3452
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
#define mod 1000000007;

int main (void) {
	int n,s,c[101],t[101],i,min;
	cin >> n >> s;
	min=10000;
	for(i=1;i<=n;i++) {
		cin >> c[i] >> t[i];
		if(t[i]<=s&&c[i]<min) min=c[i];
	}
	if(min==10000) cout << "TLE" << endl;
	else cout << min << endl;
	return 0;
}

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

int main() {
    int N;
    scanf("%d", &N);
    vector<int> A(N);
    vector<int> B(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    int count = 0;
    for (int j=N; j>=1; j--){
        if(N/j == 1){
            B[j-1] = A[j-1];
        }else{
            int k = j;
            B[j-1] = A[j-1];
            k += j;
            while(k <= N){
                B[j-1] = B[j-1] ^ B[k-1];
                k += j;
            }
        }

        if (B[j-1] == 1){
            count ++;
        }
    }

    cout << count << endl;
    for (int j=1; j<=N; j++){
        if(B[j-1] == 1){
            printf("%d",j);
            count --;
            if (count > 0){
                printf(" ");
            }
        }
    }
    

}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
string s,p;
set<string>v;
int main()
{
    ft
    int t,i,j,n,m,x=0,k;
    cin>>s>>k;
    n=s.size();
    for(i=0; i<n; i++)
    {
        p.clear();
        m=min(i+k,n);
        for(j=i; j<m; j++)
        {
            p+=s[j];
            v.insert(p);
        }
    }
    for(auto cc:v)
    {
        x++;
        if(x==k)
        {
            cout<<cc<<"\n";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
#define vvl vector<vector<ll>>
#define vll vector<ll>
#define vpll vector<pll>
ll inf = 1e18;
ll p = 1e9 + 7;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x ;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i, j, y, x,  z, w, g, key,  k, n, m, a, b, t, c, d;
    ll t2, t3, t4, t1, t5, t6;
    ll s;
    cin >> s;
    if (s <= 2)
    {
        cout << 0;
        return 0;
    }
    vll dp(s + 1, 0);
    dp[0] = 1;
    for (i = 3; i <= s; i++)
    {
        for (j = i - 3; j >= 0; j--)
        {
            dp[i] = (dp[i] + dp[j]);
            dp[i] %= p;
        }
    }
    cout << dp[s];
    return 0;
}

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

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


Measured memory_bytes: 1792
/*
sonu_verma1
*/
#include <bits/stdc++.h>
// For policy based data structure
/*#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
/*using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set;*/
 
#define MD 1000000007
#define X first
#define Y second
#define pb push_back
#define debug(val, ch) cout <<val <<ch
#define FOR(i, st, en, ch) for(register int i = (st); i <= (en) ; i += (ch))
#define RFOR(i, st, en, ch) for(register int i = (st); i >= (en) ; i -= (ch))
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
 
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<int, bool> pib;
typedef pair<bool, int> pbi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
/*********************************************************************/
void test(int r)
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int f=0;
	while(b<=a)
	{
		f++;
		b*=2;
	}
	while(c<=b)
	{
		c*=2;
		f++;
	}
	if(f<=k)
		cout<<"Yes";
	else
		cout<<"No";
	

}
/***********************************************************************/
int main()
{
	fast();
    int t=1,r;
    // cin>>t;
    for(r=1;r<=t;r++)
        test(r);
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N;cin>>N;
  map<string,int> m;
  while(N--){
    string s;cin>>s;
    sort(s.begin(),s.end());
    m[s]++;
  }
  int ans=0;
  for(auto p:m)ans+=p.second*(p.second-1)/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 11136
"""
                            pppppppppppppppppppp
                         ppppp  ppppppppppppppppppp
                      ppppppp    ppppppppppppppppppppp
                      pppppppp  pppppppppppppppppppppp
                      pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
       ppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppp
      pppppppppppppppppppppppppppppppppppppppppppppppp  ppppppppppppppppppppp
     ppppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppppp
    ppppppppppppppppppppppppppppppppppppppppppppppp    pppppppppppppppppppppppp
   pppppppppppppppppppppppppppppppppppppppppppppp     pppppppppppppppppppppppppp
  ppppppppppppppppppppppppppppppppppppppppppppp      pppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppppppp               pppppppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppp     pppppppppppppppppppppppppppppppppppppppppppppp
  ppppppppppppppppppppppppppp    pppppppppppppppppppppppppppppppppppppppppppppppp
    pppppppppppppppppppppppp  pppppppppppppppppppppppppppppppppppppppppppppppppp
     ppppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppppp
      pppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppp
       ppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
                              pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppp  pppppppp
                              ppppppppppppppppppppp    ppppppp
                                 ppppppppppppppppppp  ppppp
                                    pppppppppppppppppppp
"""


import sys
from functools import lru_cache, cmp_to_key
from collections import defaultdict as dd, deque, Counter as C
from bisect import bisect_left as bl, bisect_right as br, bisect
from math import sqrt
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var, end="\n"): sys.stdout.write(str(var)+end)
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n = int(data())
if n % 2 == 0 or n % 5 == 0:
    print(-1)
f = 7
cnt = 1
while cnt <= 2 * 10 ** 6:
    if f % n == 0:
        out(cnt)
        break
    cnt += 1
    f = f * 10 + 7
    f %= n


Measured memory_bytes: 68320
class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n
        self.rank = [1] * n
        self.count = [1] * n

    def get_root(self, i):
        while self.parent[i] != -1:
            i = self.parent[i]
        return i

    def is_same_tree(self, i, j):
        return self.get_root(i) == self.get_root(j)

    def merge(self, i, j):
        i = self.get_root(i)
        j = self.get_root(j)
        if i == j:
            return

        if self.rank[i] > self.rank[j]:
            self.parent[j] = i
            self.rank[i] = max(self.rank[i], self.rank[j] + 1)
            self.count[i] += self.count[j]
        else:
            self.parent[i] = j
            self.rank[j] = max(self.rank[j], self.rank[i] + 1)
            self.count[j] += self.count[i]

n,m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
    a,b = [int(i)-1 for i in input().split()]
    uf.merge(a,b)
print(max(uf.count))

Measured memory_bytes: 80588
#include <iostream>

using namespace std;
int main(){
	int i,j,m,d,cnt = 0;
	cin >> m >> d;
	for(i=1;i<=m;i++){
		for(j=1;j<=d;j++){
			int x = j/10,y = j%10;
			if(x<2 || y<2) continue;
			if(x*y==i) cnt++;
		}
	}
	cout << cnt << endl;
}

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

#define nmax 105
#define wmax 10005
#define diagonal 1
#define top 0
using namespace std;

struct goods{
    int value;
    int weight;
};

int N,W;

goods items[nmax];
int c[nmax+1][wmax+1],g[nmax+1][wmax+1];

void compute(int &max_value,vector<int> &selection){
    //????§????
    for (int i = 0; i <=W; ++i) {
        c[0][i]=0;
        g[0][i]=diagonal;
    }
    for (int j = 1; j <=N; ++j) {
        c[j][0]=0;
    }

    //??????c[][]
    for (int i = 1; i <=N; ++i) {
        for (int j = 1; j <=W ; ++j) {
            c[i][j]=c[i-1][j];//??????i
            g[i][j]=top;
            if (items[i].weight>j)
                continue;
            if (c[i-1][j-items[i].weight]+items[i].value>c[i-1][j]){
                //??????i???????????´??§,??????i
                c[i][j]=c[i-1][j-items[i].weight]+items[i].value;
                g[i][j]=diagonal;
            }
        }
    }

    max_value=c[N][W];
    selection.clear();
    for (int i = N, j=W; i >=1 ; i--) {
        if (g[i][j]==diagonal){
            selection.push_back(i);
            j-=items[i].weight;
        }
    }

    reverse(selection.begin(),selection.end());

}

int main() {
    int max_value;
    vector<int> selection;
    cin>>N>>W;
    for (int i = 1; i <=N; ++i) {
        cin>>items[i].value>>items[i].weight;
    }
    compute(max_value,selection);

    cout<<max_value<<endl;
    return 0;
}

Measured memory_bytes: 11036
#include <stdio.h>
int main(void)
{
	int i,n,num,min=1000001,max=-1000001;
	long sum=0;
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&num);
		sum+=num;
			
		if(min>num){
			min=num;
		}
		
		if(max<num){
			max=num;
		}
	}
	printf("%d %d %ld\n",min,max,sum);
	return 0 ;
}

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

int main() {
  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  for(int i=0;i<1000;i++) {
    bool i0=false,i1=false,i2=false;
    string I="";
    if(i<100) I+='0';
    if(i<10) I+='0';
    I+=to_string(i);
    for(int j=0;j<n;j++) {
      if(s[j]==I[2]&&i0&&i1) i2=true;
      if(s[j]==I[1]&&i0) i1=true;
      if(s[j]==I[0]) i0=true;
    }
    if(i0&&i1&&i2) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3740
#include <iostream>
#include <string>
#include <sstream>
#include <math.h>
using namespace std;
int main(){
    int N,c;
    c = 1;
    cin >> N;
    for (int i = 0; i <= N/7; i ++){
        if((N - i * 7) % 4 == 0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;

int main()
{
    int n;
    int a[100],ti=0;
    memset(a,0,sizeof(a));
    cin >> n;
    if(n==0)
    {
        printf("0\n");
        return 0;
    }
    if(n>0)
    {
        while(n) a[ti++]=n%2,n>>=1;
        for(int i=0;i<=ti;i++)
        {
            if(i&1)
            {
                if(a[i]==1) a[i+1]++;
                if(a[i]==2) a[i+1]++,a[i]=0;
            }
            if(a[i]==2) a[i+1]++,a[i]=0;
        }
    }
    else
    {
        n*=-1;
        while(n) a[ti++]=n%2,n>>=1;
        for(int i=0;i<=ti;i++)
        {
            if(!(i&1))
            {
                if(a[i]==1) a[i+1]++;
                if(a[i]==2) a[i+1]++,a[i]=0;
            }
            if(a[i]==2) a[i+1]++,a[i]=0;
        }
    }
    if(a[ti+1])
    {
        printf("1");
        if(a[ti]) printf("1");
        else printf("0");
    }
    else if(a[ti]) printf("1");
    for(int i=ti-1;i>=0;i--) printf("%d",a[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int s;
  cin >> s;
  int cnt = 1;
  vector<int> x(300);
  x[s] = 1;
  for(;;) {
    cnt++;
    if (s%2==0) s = s/2;
    else s = 3 * s + 1;
    if (x[s]) break;
    else x[s]++;
  }
  cout << cnt << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define f0r(a, b) for (long long a = 0; a < (b); ++a)
#define f1r(a, b, c) for (long long a = (b); a < (c); ++a)
#define f0rd(a, b) for (long long a = (b); a >= 0; --a)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); --a)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define fix(prec) {cout << setprecision(prec) << fixed;}
#define mp make_pair
#define f first
#define s second
#define presum(p, a, n) {p[0] = a[0]; for (int i = 1; i < (n); i++) p[i] = a[i] + p[i-1];}
#define all(v) v.begin(), v.end()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define readgraph(list, edges) for (int i = 0; i < edges; i++) {int a, b; cin >> a >> b; a--; b--; list[a].pb(b); list[b].pb(a);}
#define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
#define ain(a, lb, rb) for (int ele = lb; ele <= rb; ele++) cin >> a[ele];
#define ao(a, n) {for (int ele = 0; ele < (n); ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
#define aout(a, lb, rb) {for (int ele = (lb); ele <= (rb); ele++) { if (ele > (lb)) cout << " "; cout << a[ele]; } cout << '\n';}
typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
 
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}
 
mt19937 rng(steady_clock::now().time_since_epoch().count());
// mt19937 rng(61378913);
/* usage - just do rng() */
 
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}
 
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;

ll n, m;

void solve(int tc) {
  cin >> n >> m; ll a[n];
  f0r(i, n) cin >> a[i];
  sort(a, a + n);
  ll s = 0;
  f0r(i, n - m) s += a[i];
  cout << s << '\n';
}
 
int main() {
  send help
 
  // usaco("file");

  
 
  int tc;
  tc = 1;
  // cin >> tc;
  for (int t = 0; t < tc; t++) solve(t);
} 

Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N;
    double p[3020];
    double dp[3020][3020]={};
  	dp[0][0]=1.0;
    cin >> N;
    REP(i,N){
        cin >> p[i];
    }
    REP(i,N){
      REP(j,i+1){
        dp[i-j+1][j]+=p[i]*dp[i-j][j];
      }
      REP(j,i+1){
        dp[i-j][j+1]+=(1.0-p[i])*dp[i-j][j];
      }
    }
    double Ans=0.0;
  	REP(i,(N+1)/2){
      Ans+=dp[N-i][i];
    }
  	printf("%.10f\n",Ans);
  
    return 0;
}   


Measured memory_bytes: 71552
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a,b=mp()
if a==1 and b==1:
    print("Draw")
    exit()
if a==1:
    print("Alice")
    exit()
if b==1:
    print("Bob")
    exit()
if a==b:
    print("Draw")
    exit()
if a>b:
    print("Alice")
    exit()
if b>a:
    print("Bob")
    exit()


Measured memory_bytes: 10388
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

int main(){
    int n, k; cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
    ll ans = 0;
    rep(i, n - k) ans += h[i];
    cout << ans << endl;
}


Measured memory_bytes: 1024
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    P = list(map(int,input().split()))

    least = 2 * 10 ** 5 + 1
    res = 0

    for i in range(N):
        if least >= P[i]:
            res += 1
        least = min(least,P[i])

    print(res)



main()


Measured memory_bytes: 25992
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
		if(Math.abs(x - a) > Math.abs(x - b)) {
			System.out.print("B");
		}else {
			System.out.print("A");
		}
		
	}
}

Measured memory_bytes: 21844
n = gets.chomp.to_i
ary = []
n.times do
    ary << gets.chomp
end

ab_count = 0
a_count = 0
b_count = 0
ba_count = 0
ary.each do |str|
    # 文字列に含まれるABの数をcountします
    for i in 0..(str.length-1)
        if str[i] == "A"
            if str[i+1] == "B"
                ab_count += 1
            end
        end
    end
    if str[-1] == "A" and str[0] == "B"
        ba_count += 1 
    elsif str[-1] == "A"
        a_count += 1
    elsif str[0] == "B"
        b_count += 1
    end
end
# p [ab_count,a_count, b_count]
if a_count != 0 and ba_count != 0
    b_count_flag = true
end
if b_count != 0 and ba_count != 0
    a_count += 1
end
if b_count_flag
    b_count += 1
end
min = [a_count, b_count].min
# min -= 1 if min == n
if ba_count == 0
    ans = ab_count + min
else
    ans = ab_count + min + ba_count -1 
end
puts(ans)

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

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 ll INF = 1LL << 60;

//---main---------------------------------------------
int main(){
    //main
    int N;
    cin >> N;

    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(),A.end(), greater<ll>());
    //rep(i,N) cout << A[i]; 

    ll ans = A[0];

    rep(i,(N-2)/2){
        ans += 2* A[i+1];
        //cout << i << " " << ans << endl;
    }
    if((N-2)%2==1) ans += A[(N-1)/2];
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, x = 0;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        x ^= a[i];
    }
    int y = x ^ a[0] ^ a[1], y2 = 0;
    int X = (a[0] + a[1] - y);
    bool we = 1;
    if(X & 1)
        we = 0;

    for(int i = 1; i < 61; i++){
        if(X & (1LL << i)){
            if(y & (1LL << (i-1)))
                we = 0;
            else
                y2 |= (1LL << (i-1));
        }
    }
    int ans = y2;
    for(int i = 60; i >= 0; i--){
        if(ans + (1LL << i) <= a[0]){
            if(y & (1LL << i))
                ans |= (1LL << i);
        }
    }
    if((!we) || (ans > a[0]) || (ans == 0)){
        cout << "-1\n";
        return 0;
    }
    cout << a[0] - ans << '\n';
}

Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N;
    cin>>N;
    int ans=0;
    int MA=0;
    REP(i,N){
        int a;
        cin>>a;
        MA=max(MA,a);
        if(a>=MA)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
check=[[0 for _ in range(W+2)] for _ in range(H+2)]
canvas=[['.' for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
    s=list(input())
    for j in range(W):
        canvas[i+1][j+1]=s[j]

for i in range(H):
    for j in range(W):
        if canvas[i+1][j+1]=='#':
            if canvas[i+1][j]=='#' \
            or canvas[i+1][j+2]=='#' \
            or canvas[i][j+1]=='#' \
            or canvas[i+2][j+1]=='#' :
                check[i+1][j+1]=1
ans='Yes'
for i in range(H):
    for j in range(W):
        if canvas[i+1][j+1]=='#':
            if check[i+1][j+1]==0:
                ans='No'
                break
            else:
                continue
            break
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int maxn = 2e5 + 5;
typedef long long ll;
typedef uint64_t HT;
const int mod = 1e9 + 7;
int main() {
    string s, t;
    cin >> s >> t;
    int lens = s.length();
    int lent = t.length();
    int ans = 0x3f3f3f3f;
    for (int i = 0; i <= lens - lent; i++) {
        int cnt = 0;
        int pos = 0;
        while (pos < lent) {
            if (t[pos] != s[i + pos]) {
                cnt++;
            }
            pos++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int a,b;
string s;
signed main()
{
	cin>>s;
	rep(i,3){
		if(s[i]==s[i+1]){
			cout<<"Bad";
			return 0;
		}
	}
	cout<<"Good";
}

Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

ans = 0
a = []
for i in range(n):
    if t[i] == 'r':
        tmp = p
        a.append('p')
    elif t[i] == 's':
        tmp = r
        a.append('r')
    elif t[i] == 'p':
        tmp = s
        a.append('s')
    ans += tmp

    if i >= k and a[i] == a[i - k]:
        ans -= tmp
        a.pop()
        a.append('x')

print(ans)


Measured memory_bytes: 4212
def main():
    N = int(input())
    p_list = []
    for _ in range(N):
        p_list.append(list(map(int, input().split())))

    # initialize dp table
    dp = [[0]*3 for _ in range(N+2)]

    for i in range(N):
        for j in range(3):
            for k in range(3):
                if j == k: continue # can't seclect same choice
                tmp_cost = dp[i][j] + p_list[i][k]
                if dp[i + 1][k] < tmp_cost:
                    dp[i + 1][k] = tmp_cost

    # every chain has maximize sum
    res = 0
    for j in range(3):
        if res < dp[N][j]:
            res = dp[N][j]
    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 50100
#include<random>
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
#include<ctime>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<fstream>

using namespace std;
typedef long long ll;
#define MP make_pair
#define mod 1000000007

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

    int minn=10000,tmp;

    for (int i = 0; i < s.size()-t.size()+1; i++) {
        tmp=0;
        for (int j = 0; j < t.size(); j++) {
            if(s[i+j]!=t[j])tmp++;
        }
        minn=min(minn,tmp);
    }

    cout<<minn<<"\n";
    
    return 0;
}

Measured memory_bytes: 3584
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int N;
    cin >> N;
    cout << (N+1) / 2 << endl;


	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            Console.WriteLine((n + 1)/ 2);

            Console.Out.Flush();
        }
    }
}


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

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

void read() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		char x;
		cin >> x;
		if (x != s[i]) {
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

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

counter=0
for i in range(N):
  if B[i]>=A[i]:
    counter+=A[i]
    B[i]-=A[i]
    
    if B[i]>=A[i+1]:
      counter+=A[i+1]
      A[i+1]=0
    else:
      counter+=B[i]
      A[i+1]-=B[i]
      
  else:
    counter+=B[i]
    
print(counter)

Measured memory_bytes: 82020
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    while (1)
    {
        int n;
        cin >> n;
        if (n == 0)
            break;
        int M;
        cin >> M;
        vector<int> X(M), Y(M);
        rep(i, M) cin >> X[i] >> Y[i];
        vector<int> rX(M), rY(M);
        rep(i, M) rX[i] = X[M - i - 1], rY[i] = Y[M - i - 1];
        for (int i = M - 1; i >= 0; i--)
        {
            X[i] -= X[0], Y[i] -= Y[0];
            rX[i] -= rX[0], rY[i] -= rY[0];
        }
        vector<int> ans;
        rep(i, n)
        {
            int m;
            cin >> m;
            vector<int> x(m), y(m);
            rep(j, m) cin >> x[j] >> y[j];
            for (int j = m - 1; j >= 0; j--)
                x[j] -= x[0], y[j] -= y[0];
            if (m != M)
                continue;
            bool f = false;
            for (int j = 0; j < 4; j++) //4方向
            {
                bool F = true;
                rep(k, m) if (X[k] != x[k] || Y[k] != y[k])
                    F = false;
                if (F)
                    f = true;
                F = true;
                rep(k, m) if (rX[k] != x[k] || rY[k] != y[k])
                    F = false;
                if (F)
                    f = true;
                vector<int> nx(m), ny(m);
                rep(k, m) nx[k] = -y[k], ny[k] = x[k];
                x = nx, y = ny;
            }
            if (f)
                ans.push_back(i + 1);
        }
        rep(i, ans.size()) cout << ans[i] << endl;
        cout << "+++++" << endl;
    }
}



Measured memory_bytes: 3116
// ~zaletaet~

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define bpc __builtin_popcountl
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
struct chash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + RANDOM);
  }
};

const ll N = 1e6 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const db EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

bool w[N];

int32_t main() {
  fre("");
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  
  int n;
  cin >> n;
  int a[n + 1];
  set<int> s;
  gp_hash_table<int, int, chash> cnt;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    s.insert(a[i]);
  }

  for (int i = 1; i <= (int)1e6; i++) {
    if (!s.count(i))
      continue;
    if (cnt[i] >= 2) {
      w[i] = true;
    }
    for (int j = i + i; j <= (int)1e6; j += i) {
      if (s.count(j)) {
        w[j] = true;
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += !w[a[i]];
  }
  cout << ans;

  return 0;
}

// uniform_int_distribution<int>(l, r)(rng) -> random in range [l, r]
// assert(condition) -> if (condition == false) Runtime Error
// order_of_key(x) -> number of elements smaller than x
// *find_by_order(k) -> k-th element in 0-based indexation
// gp_hash_table<T, U, chash> -> fast unordered_map
// m.count(x) <-> (m.find(x) != m.end())


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

#define null				""
#define all(dat)			dat.begin(), dat.end()
#define over(msg)			cout << msg << endl, exit(0);
#define loop(i, to)			for (int i = 0; i < to; ++i)
#define cont(i, to)			for (int i = 1; i <= to; ++i)
#define foreach(i, dat)		for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long			num;

using namespace std;

int n;
num inf = 1e15, sz[50005], w[5005], dp[2][5005][5005], tmp[2][5005];
vector<int> g[5005];

void dfs(int u, int p) {
	sz[u] = 1;
	cont (s, 5000) {
		dp[0][u][s] = dp[1][u][s] = inf;
	}
	dp[0][u][1] = w[u] < 0 ? inf : w[u];
	dp[1][u][1] = w[u];
	for (int v : g[u]) {
		if (v == p)  continue;
		dfs(v, u);
		cont (s, sz[u] + sz[v]) {
			tmp[0][s] = tmp[1][s] = inf;
		}
		cont (s1, sz[u]) {
			cont (s2, sz[v]) {
				int s = s1 + s2;
				if (dp[0][v][s2] < inf) {
					tmp[0][s] = min(tmp[0][s], dp[0][u][s1]);
					tmp[1][s] = min(tmp[1][s], dp[1][u][s1]);
//					cout << u << ':' << s << ' ' << tmp[0][s] << ' ' << tmp[1][s] << endl;
				}
				if (dp[1][v][s2] < 0) {
					tmp[0][s] = min(tmp[0][s], dp[0][u][s1]);
					tmp[1][s] = min(tmp[1][s], dp[1][u][s1]);
//					cout << u << ':' << s << ' ' << tmp[0][s] << ' ' << tmp[1][s] << endl;
				}
				tmp[0][s - 1] = min(tmp[0][s - 1], dp[0][u][s1] + dp[0][v][s2]);
				tmp[1][s - 1] = min(tmp[1][s - 1], dp[1][u][s1] + dp[1][v][s2]);
//				cout << u << ':' << s - 1 << ' ' << dp[1][u][s1] << ',' << dp[1][v][s2] << endl;
			}
		}
		sz[u] += sz[v];
		cont (s, sz[u]) {
			dp[0][u][s] = tmp[0][s];
			dp[1][u][s] = tmp[1][s];
//			cout << "  " << u << ":" << s << ' ' << tmp[0][s] << ' ' << tmp[1][s] << endl;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	cont (i, n) {
		cin >> w[i];
	}
	cont (i, n - 1) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1, -1);
//	cont (u, n) {
//		cout << u << ": " << endl;
//		cont (cnt, sz[u]) {
//			cout << "  " << cnt << ": " << endl;
//			cout << "    ";
//			loop (mem, 2) {
//				cout << dp[mem][u][cnt] << ' ';
//			}
//			cout << endl;
//		}
//		cout << endl;
//	}
	cont (cnt, n) {
//		cout << dp[0][1][cnt] << ' ' << dp[1][1][cnt] << endl;
		if (dp[0][1][cnt] < inf || dp[1][1][cnt] < 0) {
			cout << cnt - 1 << endl;
			break;
		}
	}
}


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

int N;
string s;

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

    int x = 0;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'I'){
            x += 1;
            ans = max(x, ans);
        }else{
            x -= 1;
            ans = max(x, ans);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();

        long c = n / (a + b);
        long d = n % (a + b);
        System.out.println(c * a + Math.min(d, a));
    }

}

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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()


int main() {
            int N,K;
        string S;
        cin >> N;
        cin >> S;
        cin >> K;


        REP(i,N){
            if(S[K-1]!=S[i]){
                cout << "*";
            }else{
                cout << S[K-1];
            }
        }

        cout << endl;
}



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

int N, M;
string B[514];
bool E[514];
int dp[1 << 24][2];

// N < M
void mode1() {
    int ans = 0;
    rep(i, 1 << N) {
        rep(j, M) E[j] = false;
        int cnt = 0;
        rep(j, N) {
            if(i >> j & 1) { // use No.j
                cnt++;
                rep(k, M) {
                    if(B[j][k] == '1') E[k] = !E[k];
                }
            }
        }
        bool flag = true;
        rep(j, M) if(E[j]) flag = false;
        if(flag) ans = max(ans, cnt);
    }
    cout << ans << endl;
}

// N >= M
void mode2() {
    rep(i, 1 << M) dp[i][0] = -1;
    dp[0][0] = 0;
    bool k = 1;
    rep(i, N) {
        int W = 0;
        int d = 1;
        rep(j, M) { //入力を2進数に変換
            W += d * (B[i][M - j - 1] == '1');
            d *= 2;
        }
        rep(j, 1 << M) dp[j][k] = dp[j][!k];
        rep(j, 1 << M) {
            if(dp[j][!k] >= 0) {
                int x = j ^ W;
                dp[x][k] = max(dp[j][!k] + 1, dp[x][k]);
            }
        }
        k = !k;
    }
    cout << dp[0][!k] << endl;
}

int main() {
    while(true) {
        cin >> N >> M;
        if(N == 0 && M == 0) return 0;
        rep(i, N) cin >> B[i];
        if(N < M)
            mode1();
        else
            mode2();
    }
}


Measured memory_bytes: 35996
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    cout.precision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    return 0;
}
vector<int> frq;
map<int, int> mp;
void solve() { 
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		int x;
		cin >> x;
		mp[x]++;
	}
	if ((int) mp.size() <= k) {
		cout << 0;
		return;
	}
	for (auto &i: mp) {
		frq.push_back(i.second);
	}
	sort(frq.begin(), frq.end());
	int have = frq.size();
	int ans = 0;
	for (int i = 0; ; ++i) {
		--have;
		ans += frq[i];
		if (have == k) {
			break;
		}
	}
	cout << ans;
}

Measured memory_bytes: 14964
s=input()
k=int(input())
ans,bns=0,0
for i in range(len(s)):
    if s[i]!="1":
        ans=s[i]
        break
    else:
        bns+=1 #0の連続
if k<=bns: #k=何番目
    print(1)
else:
    print(ans)

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



int main(){	
	long long B;
	long long C;
	long long D;
	long long N;
	long long A;
	scanf("%lld",&N);
	scanf("%lld",&A);
	scanf("%lld",&B);
	scanf("%lld",&C);
	scanf("%lld",&D);
	bool flg = false;
	for (int i=0; i<=N-1; i++) {
		if (C*i-D*(N-1-i) <= B-A && B-A <= D*i-C*(N-1-i)) {
			flg = true;
			// cout << i << endl;
		}
	}
	if (flg) cout << "YES" << endl; else cout << "NO" << endl;
	return 0;
}



Measured memory_bytes: 256
from copy import deepcopy
n, m, *AB = map(int, open(0).read().split())
graph = [[] for _ in range(n)]
for a, b in zip(AB[::2], AB[1::2]):
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

complete_paths = []
stack = [0]
paths = [[]]
c = 0
while stack:
    current_node = stack.pop()
    path = paths.pop()
    path.append(current_node)
    next_nodes = [n for n in graph[current_node] if n not in path]
    if next_nodes:
        for next_node in next_nodes:
            stack.append(next_node)
            paths.append(deepcopy(path))
    else:
        if len(path) == n:
            complete_paths.append(path)
print(len(complete_paths))

Measured memory_bytes: 4212
import java.util.*;
import java.lang.Math.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int d=sc.nextInt();
		int n=sc.nextInt();
		int ans=0;
		for(int i=0;i<n;i++)ans+=sc.nextInt();
		if(ans>d)System.out.println(-1);
		else System.out.println(d-ans);
	}
}

Measured memory_bytes: 38008
#include<iostream>
#include<cmath>
#include<algorithm>
#include <iomanip> 
#include<vector>
#define fo(i,n) for(int i=0;i<n;i++)
#define f(i,n) for(int i=2;i<=n;i++)
#define ll long long
/*Elegizip, elegizip otken sol bir shaktar-ai
 Elendeter zamanymnyn otip bara zhatkanny-ai
Umytylmas-Umytylmas Kairan esil shaktar-ai
Zamanymnyn kolyn bulgap otip bara jatkany-ai
 kairan esil , kairan esil shaktar-ai
kolyn bulgap zamanymnyn otip bara jatkany-ai;*/
using namespace std;

int main()
{ios::sync_with_stdio(0);
ll n,m, r=0,c=0;
cin>>n>>m;
ll a[n];
fo(i,n){
    cin>>a[i];
    r+=a[i];
}

fo(i,n){
    if(a[i]*4*m>=r){
        c++;
    }
}
if(c>=m){
    cout<<"Yes";

}
else cout<<"No";
}





Measured memory_bytes: 256
round = int(raw_input())
score = {"taro":0, "hanako":0}
counter = 0
while counter < round:
    [taro,hanako] = raw_input().split()
    if taro < hanako:
        score["hanako"] += 3
    elif taro > hanako:
        score["taro"] += 3
    else:
        score["taro"] += 1
        score["hanako"] += 1
    counter += 1

print score["taro"], score["hanako"]

Measured memory_bytes: 6416