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

using namespace std;
const int N=1e3+5,INF=1e9+5;
int dp[N][10*N];
int a[N],b[N];
int n;
int solve(int idx,int H)
{
    if(H<=0) return 0;
    if(idx==n) return INF;
    int &ret=dp[idx][H];
    if(~ret) return ret;
    ret=solve(idx+1,H);
    ret=min(ret,solve(idx,H-a[idx])+b[idx]);
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    memset(dp,-1,sizeof dp);
    int h;
    cin>>h>>n;
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i];
    cout<<solve(0,h)<<endl;
    return 0;
}


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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }
#define MOD = 1000000007;
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N, x; cin >>N >> x;
    vector<int> a(N); cin >> a;
    sort(ALL(a));

    int ans;
    rep(i, N) {
        x -= a[i];
        if (x == 0) {
            ans = i + 1;
            break;
        } else if (x < 0) {
            ans = i;
            break;
        }
    }
    if (x > 0)
        ans = N - 1;

    cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  string s, t;
  cin >> s >> t;
  
  int res = 10000000;
  for (int i = 0; i < N; i++){
    bool flag = false;
    for (int j = 0; j < N; j++){
      if (i + j >= N){
        res = min(i + N, res);
        break;
      }
      if (s[i + j] != t[j]) {
        flag = true;
        break;
      }
    }
    if (flag == false) res = min(i + N, res);
  }
  if (res == 10000000) res = N * 2;
  
  cout << res << endl;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		int train = n * a;

		if (train > b) {
			System.out.println(b);

		} else {
			System.out.println(train);
		}

	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/







void _main() {
    int B;
    while (cin >> B) {
        if (B == 0) return;

        int ans1 = B, ans2 = 1;
        rep(n, 2, 101010) {
            ll sm = 1LL * n * (n + 1) / 2;
            if (B < sm) break;

            int d = B - sm;
            if (d % n == 0) {
                ans1 = d / n + 1;
                ans2 = n;
            }
        }

        printf("%d %d\n", ans1, ans2);
    }
}



Measured memory_bytes: 3156
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>

using namespace std;
string str;

int main()
{
    priority_queue<string,vector<string>,greater<string> >q;
    int n,l;

    cin >>n >> l;
    for(int i=0;i<n;i++)
    {
        cin >> str;
        q.push(str);
    }
    for(int i=0;i<n;i++)
    {
        cout << q.top();
        q.pop();
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
int ct[10000005];
int main(){
    int n;
    scanf("%d",&n);
    for (int i = 1; i <= n; i++){
        for (int j = i; j <= n; j+=i) ans += j;
    }
    printf("%lld",ans);

}


Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s[0]=='R'){
    if(s[1]=='R'){
      if(s[2]=='R') cout<<3<<endl;
      else cout<<2<<endl;
    }
    else cout<<1<<endl;
  }
  else{
    if(s[1]=='R'){
      if(s[2]=='R') cout<<2<<endl;
      else cout<<1<<endl;
    }
    else{
      if(s[2]=='R') cout<<1<<endl;
      else cout<<0<<endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3192
# https://atcoder.jp/contests/abc152/submissions/9619555

import sys
readline = sys.stdin.readline

import numpy as np

N = int(readline())
AB = list(list(map(int, readline().split())) for _ in range(N - 1))
M = int(readline())
UV = list(list(map(int, readline().split())) for _ in range(M))

graph = [[] for _ in range(N + 1)]
for i, (a, b) in enumerate(AB):
    graph[a].append((b, i))
    graph[b].append((a, i))


def get_path(U, V):
    INF = 100
    visited = [False] * (N + 1)
    pred = [None] * (N + 1)
    stack = [U]
    visited[U] = True
    while stack:
        v = stack.pop()
        for w, i in graph[v]:
            if visited[w]:
                continue
            visited[w] = True
            pred[w] = (v, i)
            stack.append(w)
    path = 0
    w = V
    while w != U:
        v, i = pred[w]
        w = v
        path += 1 << i
    return path


condition_path = [get_path(u, v) for u, v in UV]


def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff)
    return c


S = np.zeros(1 << M, np.int64)
sgn = np.ones(1 << M, np.int64)
for i in range(M):
    S[1 << i:1 << (i + 1)] = S[:1 << i] | condition_path[i]
    sgn[1 << i:1 << (i + 1)] = -sgn[:1 << i]

n_edges = popcnt(S)
x = 1 << (N - 1 - n_edges)
answer = (x * sgn).sum()
print(answer)


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

string s, t, u;
int a, b;

int main(){
  cin >> s >> t >> a >> b >> u;
  if(s == u){
    a--;
  }else{
    b--;
  }
  cout << a << " " << b << endl;
  return 0;
}


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

using namespace std;

int main() {
    int N;
    scanf("%d", &N);
    {
        int d;
        scanf("%d", &d);
        if(d!=0) {
            printf("0\n");
            return 0;
        }
    }
    vector<int> D;
    for(int n=1; n<N; ++n) {
        int d;
        scanf("%d", &d);
        if(d==0) {
            printf("0\n");
            return 0;
        }
        D.push_back(d);
    }
    sort(D.begin(), D.end());
    int before = 0;
    int beforeCount = 1;
    int count = 1;
    long long result = 1;
    for(int d : D) {
        if(before==d) {
            ++count;
            result = (result * beforeCount) % 998244353;
        }
        else if(before+1==d) {
            before = d;
            beforeCount = count;
            result = (result * beforeCount) % 998244353;
            count = 1;
        }
        else {
            result = 0;
        }
    }
    printf("%d\n", (int)result);
    return 0;
}


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

main(){
	int n,i=0;
	cin>>n;
	long long a[n];
	for(;i<n;cin>>a[i],i++);
	sort(a,a+n);
	for(;i-1;(*a*=__gcd(a[n-i+1],n-i+1ll))%=998244353,i--);
	cout<<*a<<endl;
}


Measured memory_bytes: 1152
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count = 0;
		long[] a = new long[n];
		for(int i=0; i<n; i++){
			a[i] = scan.nextLong();
			if(a[i]%2!=0){count++;}
		}
		if(count%2==0){System.out.println("YES");}
			else{System.out.println("NO");}

	}
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    string s,t; cin>>s>>t;
    int a,b; cin>>a>>b;
    string u; cin>>u;

    if(s == u){
        a--;
    }
    else{
        b--;
    }
    cout << a << " " << b<<endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

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

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

    int res = 0;  // 答えを格納
    for (int i = 1; i <= 100; ++i) {  // 1 <= d[i] <= 100 なので 1 から 100 まで探索
        if (num[i]) {  // 0 より大きかったら
            ++res;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(n: int, v: "List[int]"):
    a = {-1: 0}
    b = {-1: 0}
    for vv in v[::2]:
        if vv in a:
            a[vv] += 1
        else:
            a[vv] = 1
    for vv in v[1::2]:
        if vv in b:
            b[vv] += 1
        else:
            b[vv] = 1
    ai = sorted(list(a.keys()), key=lambda x: a[x], reverse=True)
    bi = sorted(list(b.keys()), key=lambda x: b[x], reverse=True)
    if ai[0] == bi[0]:
        ans1 = sum([a[x] for x in ai[1:]]) + sum([b[x] for x in bi])-b[bi[1]]
        ans2 = sum([a[x] for x in ai]) + sum([b[x] for x in bi[1:]])-a[ai[1]]
        print(min(ans1, ans2))

    else:
        ans = sum([a[x] for x in ai[1:]]) + sum([b[x] for x in bi[1:]])
        print(ans)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23588
#include<bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int,int>P;
     
#define F first
#define S second
     
int main(){
  string s,t,ans;
  bool flg=false;
  cin>>s;
  cin>>t;
     
  for(int i=0;i<s.size();i++){
    if(s[i]=='?') ans[i]='a';
    else ans[i]=s[i];
  }
      
  for(int i=s.size()-t.size();i>=0;i--){
    if(s[i]==t[0]||s[i]=='?'){
      for(int j=0;j<t.size();j++){
    	if(s[i+j]!=t[j]&&s[i+j]!='?') break;
    	if(j==t.size()-1&&!flg){
    	  for(int k=0;k<t.size();k++){
    	    ans[k+i]=t[k];
    	  }
    	  flg=true;
    	}
      }
    }
  }
     
  if(flg){
    for(int i=0;i<s.size();i++){
      cout<<ans[i];
    }
    cout<<'\n';
  }else{
    cout<<"UNRESTORABLE\n";
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var X = int.Parse(ReadLine());

        var ans = (X == 7 || X == 5 || X == 3) ? "YES" : "NO";

        WriteLine(ans);
    }
}


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

a = list(map(int, input().split()))
a.append(0)
a.insert(0,0)
a_abs = []
for i in range(n+1):
    a_abs.append(abs(a[i]-a[i+1]))

a_abs_max = sum(a_abs)
for i in range(1,n+1):
    ans = a_abs_max - abs(a[i]-a[i+1]) - abs(a[i]-a[i-1]) + abs(a[i+1]-a[i-1])
    print(ans)

Measured memory_bytes: 14040
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long
ll gcd(ll a,ll b){
    ll s=1,c;
    while(a&&b){
        if((~a&1)&&(~b&1))
            a>>=1,b>>=1,s<<=1;
        else if(~a&1)a>>=1;
        else if(~b&1)b>>=1;
        else if(a>b)a=a-b;
        else c=b-a,b=a,a=c;
    }
    if(!a)return b*s;
    if(!b)return a*s;
}
using namespace std;
int fun(string s){
	int n=s.length();
	for(int i=0;i<n/2;i++){
		if(s[i]!=s[n-i-1])
			return 0;
	}
	return 1;
}
int main(){
	char s[100];
	cin>>s;
	int n=strlen(s);
	char s1[100];
	strcpy(s1,&s[(n+2)/2]);
	//cout<<s1<<endl;
	if(fun(s)&&fun(s1)){
		cout<<"Yes";
	}
	else
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define joi "JOI" 
#define ioi "IOI" 
int main(){
  int n , i , j , total=0 , result=0 ;
  string str ;
  while( cin >> str ){
    total = 0;
    result = 0;
  string st = "";
  for( i=0 ; i<str.size()-2 ; i++ ){
    st="";
    for( j=0 ; j<3 ; j++ )
     st += str[i+j];
    if( st == joi)
      total++;
    else if( st == ioi )
      result ++;
  }
  cout << total << endl << result << endl;
}
}

Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){
	
	int y,m,d;
	string s;
	
	while(cin>>y>>m>>d){
		if(y<1868)
			s="pre-meiji";
		else if(y==1868){
			if(m<9)
			s="pre-meiji";
			else if(m==9){
				if(d<8)
				s="pre-meiji";
				else{
				s="meiji";
					y=1;
				}
			}
			else{
				s="meiji";
				y=1;
			}	
		}
		else if(y<1912){
			s="meiji";
			y=y-1868+1;
		}
		else if(y==1912){
			if(m<7){
				s="meiji";
				y=y-1868+1;
			}
			else if(m==7){
				if(d<=29){
					s="meiji";
					y=y-1868+1;
				}
				else{
					s="taisho";
					y=1;
				}
			}
			else{
				s="taisho";
				y=1;
			}
		}
		else if(y<1926){
			s="taisho";
			y=y-1912+1;
		}
		else if(y==1926){
			if(m<12){
				s="taisho";
				y=y-1912+1;
			}
			else{
				if(d<=24){
					s="taisho";
					y=y-1912+1;
				}
				else{
					s="showa";
					y=1;
				}
			}
		}
		else if(y<1989){
			s="showa";
			y=y-1926+1;
		}
		else if(y==1989){
			if(m==1){
				if(d<=7){
					s="showa";
					y=y-1926+1;
				}
				else{
					s="heisei";
					y=1;
				}
			}
				else{
					s="heisei";
					y=1;
				}
			}
		else{
			s="heisei";
			y=y-1989+1;
		}
		if(s=="pre-meiji")
			cout<<s<<endl;
		else
			cout<<s<<" "<<y<<" "<<m<<" "<<d<<endl;
		}
	
}

Measured memory_bytes: 1208
#include<iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

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

int a,b,c,d;

int main(){

  cin >> a >> b >> c >> d;
  string ans = "";

  int d_ac = abs(a-c);
  int d_bc = abs(b-c);
  int d_ab = abs(a-b);

  if(d_ac<=d||(d_ab<=d && d_bc <= d )){
    ans = "Yes";
  }else{
    ans = "No";
  }

  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
money = 1000
num = 0
flag = False
a.append(a[n - 1])
for i in range(n):
    #print(num, money)
    if a[i] < a[i + 1]:
        num += money // a[i]
        money -= a[i] * num
        money += num * a[i + 1]
        num = 0
print(money)

Measured memory_bytes: 9084
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

vector<bool> b(100005, false);
vector<ll> v(100005, 0);

int main(int argc, char const *argv[])
{
    ll n, m;
    cin >> n >> m;
    ll _wa = 0;
    ll seitou = 0;

    for (ll i = 0; i < m; i++)
    {
        ll p;
        string s;
        cin >> p >> s;
        if (!b[p])
        {
            if (s == "AC")
            {
                b[p] = true;
                seitou++;
                _wa += v[p];
            }
            else
            {
                v[p]++;
            }
        }
    }

    cout << seitou << " " << _wa << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
  fastio() {
    ios::sync_with_stdio(false);
    cout << setprecision(10) << fixed;
    cin.tie(0);
  }
};
fastio _fast_io;

int n, a, b, c, q;

int main() {
  cin >> n;
  ll sum = 0;
  unordered_map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    sum += a;
    ++mp[a];
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> b >> c;
    if (mp.count(b)) {
      ll cnt = mp[b];
      mp[c] += cnt;
      mp[b] = 0;
      sum += (c - b) * cnt;
    }
    cout << sum << endl;
  }
  return 0;
}

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

int main() 
{
  int a, b, c, tmp;

  cin >> a >> b >> c;

  if (a > b) {
    tmp = b;
    b = a;
    a = tmp;
  }
  if (a > c) {
    tmp = c;
    c = a;
    a = tmp;
  }
  if (b > c) {
    tmp = c;
    c = b;
    b = tmp;
  }

  cout << a << " " << b << " " << c << endl;

  return 0;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int X, K, D; cin>>X>>K>>D;
    X = abs(X);

    // XからDずつ移動したときに、最小の絶対値になる座標の位置を求める
    int min_positive = X%D;
    int min_negative = abs(X%D-D);

    // min_positiveまで到達できなければそこが死に場所
    if(K<X/D){
        cout<<X-K*D<<endl;
        return 0;
    }
    // min_postiveに最初に到達できるのはX/D回移動した後
    if((K-X/D)%2==0){
        cout<<min_positive<<endl;
    }else{
        cout<<min_negative<<endl;
    }






    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>


#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define int long long
using namespace std;

signed main() {
    FAST_IO;

    int n;
    cin >> n;
    int work[n][3];
    for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> work[i][j];

    int dp[n + 1][3];
    for (int i = 0; i < 3; i++) dp[0][i] = work[0][i];

    for (int i = 1; i < n; i++) {
        int x, y;
        for (int j = 0; j < 3; j++) {
            if (j == 0) x = 1, y = 2;
            else if (j == 1) x = 0, y = 2;
            else x = 0, y = 1;
            dp[i][j] = work[i][j] + max(dp[i - 1][x], dp[i - 1][y]);
        }
    }

    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

string imp = "UNRESTORABLE";

signed main() {
	string S, T;
	cin >> S >> T;

	if (S.size() < T.size()) {
		cout << imp << endl;
		return 0;
	}

	string ret = S;

	bool flag = false;
	for (int i = S.size() - T.size(); i >= 0; i--) {
		bool ok = true;
		rep(j, T.size()) {
			if (S[i + j] != '?' && S[i + j] != T[j]) {
				ok = false;
				break;
			}
		}
		if (!ok) {
			if (S[i] == '?') ret[i] = 'a';
			continue;
		}
		rep(j, T.size()) {
			ret[i + j] = T[j];
		}
		flag = true;
		break;
	}

	if (!flag) {
		cout << imp << endl;
		return 0;
	}

	rep(i, S.size()) {
		if (ret[i] == '?') ret[i] = 'a';
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define MOD 1000000007
typedef long long ll;
const char sp = ' ';


using namespace std;
ll dp[200000][13], di=1;
int main(void){
    
    string S;
    cin>>S;
    MEMSET(dp, 0);
    dp[S.size()][0]=1;
    rep(i, S.size()){
        ll th=S.size()-1-i;
        if(S[th]=='?'){
            rep(j, 13) rep(k, 10){
                dp[th][(di*k+j)%13]+=dp[th+1][j];
                dp[th][(di*k+j)%13]%=MOD;
            }
        }
        else{
            rep(j, 13){
                dp[th][(di*(S[th]-'0')+j)%13]+=dp[th+1][j];
                dp[th][(di*(S[th]-'0')+j)%13]%=MOD;
            }
        }
        di*=10;
        di%=13;
    }
    /*rep(i, S.size()+1){
        rep(j, 13) cout<<dp[i][j]<<"\t";
        cout<<endl;
    }*/
    cout<<dp[0][5]<<endl;
    return 0;
}


Measured memory_bytes: 20736
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
 
    try (Scanner sc = new Scanner(System.in)) {
        int w = sc.nextInt();
        int n = sc.nextInt();
        int[] values = new int[w];
        for (int i = 0; i < w; i++) {
            values[i] = i + 1;
        }
        for (int i = 0; i < n; i++) {
            String str = sc.next();
            String[] ab = str.split(",");
            int a = Integer.parseInt(ab[0]) - 1;
            int b = Integer.parseInt(ab[1]) - 1;
            int c = values[a];
            values[a] = values[b];
            values[b] = c;
        }
        for (int i = 0; i < values.length; i++) {
            System.out.println(values[i]);
        }
    }
    }
}


Measured memory_bytes: 26312
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int t = kbd.nextInt();
	    int p = kbd.nextInt();
	    int r = kbd.nextInt();
	    if(t!=0 && p!=0 && r!=0){
		int[][] times = new int[t][p];
		int[][] score = new int[t][3];//0チーム、1正答数、2タイム
		int i, j;
		for(i=0; i<t; i++){
			score[i][0] = i+1;
		}

		//ここからログ読み出し
		while(r>0){
		    int tN = kbd.nextInt();
		    int pN = kbd.nextInt();
		    int tT = kbd.nextInt();
		    String mm = kbd.next();

		    if(mm.equals("CORRECT")){
			times[tN-1][pN-1] += tT;
			score[tN-1][1] += 1;
			score[tN-1][2] += times[tN-1][pN-1];
			//System.out.println(score[tN-1][0]+" "+score[tN-1][1]+" "+score[tN-1][2]);
		    }
		    else{
			times[tN-1][pN-1] += 1200;
		    }
		    r--;
		}

		sort(score, t);
		for(i=0; i<t; i++){
		    System.out.println(score[i][0]+" "+score[i][1]+" "+score[i][2]);
		}
	    }
	}
    }

    static void sort(int[][] score, int t){
	int[] c = new int[3];
	int i=0, j=0;
	for(; i<t; i++){
	    int max = i;
	    for(j=i; j<t; j++){
		if(score[max][1]<score[j][1]) max=j;
		else if(score[max][1]==score[j][1]){
		    if(score[max][2]>score[j][2]) max=j;
		    else if(score[max][2]<score[j][2]) ;
		    else {
			if(score[max][0]>score[j][0]) max=j;
		    }
		}	    
		else ;
	    }
	    c = score[i];
	    score[i] = score[max];
	    score[max] = c;
	}
    }
}

Measured memory_bytes: 62356
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll N;
ll memo[MAX];

ll rec(ll m) {
    if(m==0) return 0;
    if(memo[m]!=-1) return memo[m];
    
    ll res=m;
    
    for(ll i=1; i<=m; i*=6) {
        res=min(res, rec(m-i)+1);
    }
    
    for(ll i=1; i<=m; i*=9) {
        res=min(res, rec(m-i)+1);
    }
    
    return memo[m]=res;
}



int main(void) {
    cin >> N;
    memset(memo, -1, sizeof(memo));
    pr(rec(N));
    
}

























Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
#define rep(i,m,n) for(int i = m;i<(int)n;i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main()
{
	int N;
	cin >> N;
	ll max = 0;
	for (ll i = 1; i*i <= N; i++) {
		max = i*i;
	}
	cout << max << endl;
	return 0;
}

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

using namespace std;

struct st
{
    int c, x;
}a[5000];
char str[2];

int sum[2][2010][4010];
int dp[2010][2010];
int addr[2][2010];
int main()
{
    int n, x;
    scanf("%d", &n);
    for(int i=1; i<=2*n; i++)
    {
        scanf("%s %d", str, &x);
        if (str[0] == 'W') a[i].c = 0; else a[i].c = 1;
        a[i].x = x;
        addr[a[i].c][a[i].x] = i;
    }

    memset(sum, 0, sizeof(sum));
    for(int i=1; i<=n; i++)
    {
        for(int j=2*n; j>=1; j--)
        {
            if (a[j].x <= i)
            {
                sum[a[j].c][i][j] = 1;
            }
            sum[0][i][j] += sum[0][i][j+1];
            sum[1][i][j] += sum[1][i][j+1];
        }
    }

    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=n; j++)
        {
            int dp1 = -1, dp2 = -1;
            if (i != 0)
                dp1 = dp[i-1][j] + addr[0][i] - i - j + sum[0][i-1][addr[0][i]] + sum[1][j][addr[0][i]];
            if (j != 0)
                dp2 = dp[i][j-1] + addr[1][j] - i - j + sum[0][i][addr[1][j]] + sum[1][j-1][addr[1][j]];

            if (dp1 == -1 && dp2 == -1) {dp[i][j] = 0; continue;}
            if (dp1 == -1) dp[i][j] = dp2;
            if (dp2 == -1) dp[i][j] = dp1;
            if (dp1 != -1 && dp2 != -1) dp[i][j] = min(dp1, dp2);

        }
    }

    cout<<dp[n][n]<<endl;
}

Measured memory_bytes: 79104
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] monster = new Integer[n + 1];
        for (int i = 0; i < n + 1; i++) {
            monster[i] = sc.nextInt();
        }
        Integer[] bravePower = new Integer[n];
        for (int i = 0; i < n; i++) {
            bravePower[i] = sc.nextInt();
        }

        long result = 0;
        for (int i = 0; i < n; i++) {
            if (monster[i] >= bravePower[i]) {
                result += bravePower[i];
            } else {
                result += monster[i];
                bravePower[i] -= monster[i];
                result += Math.min(bravePower[i], monster[i + 1]);
                monster[i + 1] = Math.max(0, monster[i + 1] - bravePower[i]);
            }
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 96648
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		int strlength = str.length();

		String str1 = str.substring(0, (strlength-1)/2);
		String str2 = str.substring((strlength-1)/2 +1,strlength);
		
		if(kaibunHantei(str) && kaibunHantei(str1) && kaibunHantei(str2)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}
	
	public static boolean kaibunHantei(String str) {
		int strlength = str.length();
		String str1;
		String str2;
		if(strlength%2==1) {
			str1 = str.substring(0, (strlength-1)/2);
			str2 = str.substring((strlength-1)/2 +1,strlength);
		}else {
			str1 = str.substring(0, (strlength)/2);
			str2 = str.substring((strlength)/2 ,strlength);			
		}
		
		for(int i =0; i<str1.length(); i++) {
			char a = str1.charAt(i);
			char b =str2.charAt(str1.length()-1-i);
			if(a!=b) {
				return false;
			}
		}
		return true;		
	}
}

Measured memory_bytes: 21972
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

long long modpow(long long x, long long n, long long mod) {
    if (n == 0) return 1;
    long long res = modpow(x * x % mod, n / 2, mod);
    if (n & 1) res = res * x % mod;
    return res; 
}

//--------------------------- Solve ---------------------------//

void solve() {
    int N; string X;
    cin >> N >> X;

    int popcount = 0;
    for (int i = 0; i < N; i++) {
        if (X[i] == '1') popcount++;
    }

    int popcount_plus = popcount + 1;
    int popcount_minus = popcount - 1;

    int mod_plus = 0;
    int mod_minus = 0;

    for (int i = 0; i < N; i++) {
        if (popcount_minus <= 0) break;
        if (X[i] == '1') {
            mod_plus += modpow(2, N-i-1, popcount_plus);
            mod_plus %= popcount_plus;
            mod_minus += modpow(2, N-i-1, popcount_minus);
            mod_minus %= popcount_minus;
        }
    }

    for (int i = 0; i < N; i++) {
        int x = 0;
        int fx = 0;
        if (X[i] == '1') { 
            if (popcount_minus > 0) {
                x = mod_minus - modpow(2, N-i-1, popcount_minus);
                if (x < 0) x += popcount_minus;
                fx++;
            }
        }
        else {
            x = mod_plus + modpow(2, N-i-1, popcount_plus);
            x %= popcount_plus;
            fx++;
        }
        while (x != 0) {
            x %= __builtin_popcount(x);
            fx++;
        }
        cout << fx << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

Measured memory_bytes: 3780
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define mp make_pair
#define MAX 20000
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<ii> vii;
#define EPS 1e-9
#define LSOne(S) (S & (-S))
#define INF 1000*1000*1000+889
const int N = 1e5+10;
int h[N];
int dp[N];
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i = 1; i <= n; ++i)
    {
        cin>>h[i];
    }
    for(int i = 2; i <= n; ++i)
    {
        if(i-2>0)
            dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        else
            dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
    }
    cout<<dp[n];
}


Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N = I()
    A = LI()
    Q = I()
    AI = [0]*(10**5+1)
    ans = 0
    for a in A:
        AI[a] += 1

    for i in range(10 ** 5 + 1):
        ans += i * AI[i]
    for _ in range(Q):
        B, C = MI()
        ans = ans - B * AI[B] + C * AI[B]
        AI[C] += AI[B]
        AI[B] = 0
        print(ans)


if __name__ == '__main__':
    main()

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

int n;
int d[200000];
int m;
int t[200000];

int main() {
	int i;
	map<int, int> dict1;
	map<int, int> dict2;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> d[i];
	cin >> m;
	for (i = 0; i < m; i++) cin >> t[i];
	
	for (i = 0; i < n; i++) {
		if (dict1.find(d[i]) == dict1.end()) dict1[d[i]] = 0;
		dict1[d[i]]++;
	}
	
	for (i = 0; i < m; i++) {
		if (dict2.find(t[i]) == dict2.end()) dict2[t[i]] = 0;
		dict2[t[i]]++;
	}
	
	for (map<int, int>::iterator it = dict2.begin(); it != dict2.end(); it++) {
		if (dict1.find((*it).first) == dict1.end() || (*it).second > dict1[(*it).first]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 20608
#include <stdio.h>
#include <string.h>
#define N 100000
#define INF 1000000000

int ceil(int a, int b) {
	if(a%b==0) return a/b;
	else return a/b + 1;
}

int main(int argc, char const* argv[])
{
	int i, n;
	int temp=0, max=0;
	int h[100000];
	scanf("%d",&n);
	for(i=0; i<n; i++) {
		scanf("%d", h+i);
		if(i>0) {
			if(h[i] <= h[i-1]) {
				temp++;
			} else {
				if(max < temp) max = temp;
				temp = 0;
			}
		}
	}
	if(max < temp) max = temp;
	printf("%d\n", max);

	return 0;
}


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

int main(){
  int a[4];
  int b[4];
  int appear[10];
  int i;
  int hit, blow;

  for(i=0; i<10; i++) appear[i]=0;
  while(cin>>a[0]){
    hit=0; blow=0;
    appear[a[0]]=1;
    for(i=1; i<4; i++){
      cin>>a[i];
      appear[a[i]]=1;
    }
    for(i=0; i<4; i++) cin>>b[i];

    for(i=0; i<4; i++){
      if(a[i]==b[i]) hit++;
      else blow+=appear[b[i]];
    }

    for(i=0; i<4; i++) appear[a[i]]=0;
    printf("%d %d\n", hit, blow);
  }

  return 0;
}

Measured memory_bytes: 0
n = gets.to_i
a = gets.split.map{|s|s.to_i}

lcm = 1
a.each do |ai|
  lcm = lcm.lcm(ai)
end

m = lcm - 1

ans = a.inject(0) do |s, ai|
  s += m.modulo(ai)
end

puts ans

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

#define ll long long
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define fir(a,b) for(int i=a;i>b;i--)
#define fjr(a,b) for(int j=a;j>b;j--)
#define test int t;cin>>t;while(t--)
#define fast ios::sync_with_stdio(NULL); cin.tie(NULL)

int main(){
    fast;
    int a,b;
    cin >> a >> b;
    if (a<=5)
        cout << 0;
    else if(a>=6 && a<=12)
        cout << b/2;
    else
        cout << b;

    return 0;
}


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

ll bd[3100][3100], dp[3100][3100][5];

int main(void){
    int r, c, K;
    cin >> r >> c >> K;

    // ll bd[3100][3100];
    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            bd[i][j] = 0;
        }
    }

    for(int i = 0; i < K; i++){
        int nr, nc; cin >> nr >> nc;
        ll nval; cin >> nval;
        bd[nr][nc] = nval;
    }

    // ll dp[3100][3100][5];
    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            for(int k = 0; k <= 3; k++){
                dp[i][j][k] = 0;
            }
        }
    }

    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            for(int k = 0; k <= 3; k++){
                // 下向きへの遷移(kの値は0にリセットされる)
                if(i-1 >= 0){
                    // (i, j) で「取らない」
                    dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][k]);
                    // (i, j) で「取る」(何もないところを0にしておいたので、いつでもとってok)
                    dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][k] + bd[i][j]);
                }
                // 右向きへの遷移(kの値によって状態が拡張されている)
                if(j-1 >= 0){
                    // (i, j) で「取らない」
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k]);
                    // (i, j) で「取る」
                    if(k-1 >= 0){
                        dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + bd[i][j]);
                    }
                }
            }
        }
    }

    ll ans = 0;
    for(int i = 0; i <= 3; i++){
        ans = max(ans, dp[r][c][i]);
    }
    cout << ans << endl;


    return 0;
}

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

typedef long long ll;
typedef pair<int, int> ii;

int main()
{
    int n, k, q;
    scanf("%d %d %d", &n, &k, &q);
    int cnt[n] = {0};
    for (int i = 0; i < q; i++) {
        int num;
        scanf("%d", &num);
        num--;
        cnt[num]++;
    }

    for (int i = 0; i < n; i++) {
        if (k - (q - cnt[i]) > 0)
            printf("Yes\n");
        else
            printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{	
	int n,k,a;
	map<int,int>m;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		m[a]++;
	}
	vector<pair<int,int>>v;
	for(auto i=m.begin();i!=m.end();i++) 
	{
		v.push_back(make_pair(i->second,i->first));
	}
	sort(v.begin(),v.end());
	int size=v.size(),sum=0;
	for(int i=0;i<v.size();i++)
	{
		if(size>k)
		{
			sum+=v[i].first;
			size--;
		}
		else break;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 11768
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn hoge(n: u64) -> u64{
    if n < 2{
        return 1;
    }

    return n* hoge(n-2);
}


fn main(){
    let mut n: u64 = read_as_vec()[0];

    if n%2 == 1{
        println!("0");
        return;
    }

    let mut ans: u64 = 0;

    let mut pow5 = 10;
    while pow5 <= n{
        ans += n/pow5;
        pow5 *= 5;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 1000000007
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
		string s, t;
		cin >> s >> t;
		int ss = s.size(), ts = t.size();

		vector<vector<int>>a(ss + 1, vector<int>(ts + 1));
		rep(i, 0, ss)a[i][0] = 0;
		rep(j, 0, ts)a[0][j] = 0;
		rep(i, 1, ss + 1) {
			rep(j, 1, ts + 1) {
				if (s[i - 1] == t[j - 1])a[i][j] = a[i - 1][j - 1] + 1;
				else {
					if (a[i - 1][j] > a[i][j - 1])a[i][j] = a[i - 1][j];
					else a[i][j] = a[i][j - 1];
				}
			}
		}

		string ans;
		while (ss && ts) {
			if (a[ss][ts] != a[ss][ts - 1]&&a[ss][ts] != a[ss-1][ts]) {
				ans += t[ts - 1];
				ss--;
				ts--;
				continue;
			}
			if (a[ss][ts] == a[ss][ts - 1]) {
				ts--;
				continue;
			}
			if (a[ss][ts] == a[ss - 1][ts]) {
				ss--;
				continue;
			}
		}
		reverse(ans.begin(), ans.end());
		if (ans.size() == 0)cout << " " << endl;
		else cout << ans << endl;
}


Measured memory_bytes: 38588
n, k = (int(i) for i in input().split())
mod = 10**9 + 7
c = [[1], [1,1]]
for i in range(2,n+10):
    c.append([1] + [(c[i-1][j-1] + c[i-1][j]) % mod for j in range(1,i)] + [1])

for i in range(1, k + 1):
    if n - k + 1 < i or k < i:
        print("0")
    else:
        step1 = c[n-k+1][i]
        step2 = c[k-1][i-1]
        ans = (step1 * step2) % mod
        print(int(ans))

Measured memory_bytes: 83468
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
  	  Scanner sc = new Scanner(System.in);
  	  int n = sc.nextInt();  	  
  	  for(int i=1;i<=n;i++){
  		  if(i%3 == 0){
  			  System.out.printf(" %d",i);
  		  } else{
  			  function(i,i);
  		  }
  	  }
	System.out.println("");
    }
  	  
  	  public static void function(int i,int j){
  		  if(j%10 == 3){
  			  System.out.printf(" %d",i);
  		  } else if(j>0){
  			  function(i,j/10);
  		  }
  	  }
    }

Measured memory_bytes: 38540
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
	int n;
	cin >> n;
	long long int place[200010];
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		place[a] = i;
	}
	set<int> s;
	long long int ans = 0;
	s.insert(place[1]);
	ans += (place[1] + 1) * (n - place[1]);
	for (long long int i = 2; i <= n; i++) {
		// cout << ans << endl;
		auto itr = s.upper_bound(place[i]);
		if (itr == s.begin()) {
			ans += i * (place[i] + 1) * (*itr - place[i]);
		} else if (itr == s.end()) {
			itr--;
			ans += i * (place[i] - *itr) * (n - place[i]);
		} else {
			auto previtr = itr;
			previtr--;
			ans += i * (place[i] - *previtr) * (*itr - place[i]);
		}
		s.insert(place[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
import math

n = int(input())

dots = [[0,0],[100,0]]
for _ in range(n):
    producedDots = []
    for i in range(len(dots)-1):
        pointA = [dots[i][0] + (dots[i+1][0]-dots[i][0])/3, dots[i][1] + (dots[i+1][1]-dots[i][1])/3]
        pointB = [dots[i][0] + (dots[i+1][0]-dots[i][0])*2/3, dots[i][1] + (dots[i+1][1]-dots[i][1])*2/3]

        producedDots.append(dots[i])
        producedDots.append(pointA)

        arrow = [pointB[0]-pointA[0], pointB[1]-pointA[1]]
        cos60 = math.cos(math.radians(60))
        sin60 = math.sin(math.radians(60))
        newArrow = [arrow[0]*cos60 - arrow[1]*sin60, arrow[0]*sin60 + arrow[1]*cos60]
        pointC = [pointA[0] + newArrow[0], pointA[1] + newArrow[1]]
        producedDots.append(pointC)

        producedDots.append(pointB)
    dots = producedDots
    dots.append([100,0])

for _ in dots:
    print(" ".join(map(str,_)))


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

using namespace std;

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


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

int w, h;

int dfs(vector<vector<char>> &a, int ii, int jj) {
  int cnt = 1;
  a[ii][jj] = '#';
  rep (k, 4) {
    if (in(ii + dx[k], 0, h) && in(jj + dy[k], 0, w) && a[ii + dx[k]][jj + dy[k]] == '.') {
      cnt += dfs(a, ii + dx[k], jj + dy[k]);
    }
  }
  return cnt;
}

int main() {
  while (true) {
    cin >> w >> h;
    if (h == 0) return 0;
    vector<vector<char> > a(h, vector<char>(w));
    int si, sj;
    rep (i, h) {
      rep (j, w) {
        cin >> a[i][j];
        if (a[i][j] == '@') {
          si = i;
          sj = j;
        }
      }
    }

    cout << dfs(a, si, sj) << endl;
    
  }
}



Measured memory_bytes: 3132