akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << (char)toupper(s1[0]) << (char)toupper(s2[0]) << (char)toupper(s3[0])
       << endl;
  return 0;
}

Measured memory_bytes: 3556
#include <stdio.h>

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

	scanf("%d %d %d", &a ,&b ,&c);

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

	printf("%d %d %d\n", a, b, c);

	return 0;
}


Measured memory_bytes: 2048
K, N = map(int, input().split())
A = list(map(int, input().split()))
cnt = 1
a = 0
B = []
if (max(A)-min(A)) <= K//2:
    print(max(A)-min(A))
else:
    for i in A:
        if i/cnt == K/N:
            a += 1
        cnt += 1
    
    if a == N:
        print(max(A)-min(A))
    else:
        for j in range(N):
            if j == N-1:
                haba = K-(A[j]-A[0])
            else:
                haba = A[j+1]-A[j]
            B.append(haba)
        print(K-max(B))

Measured memory_bytes: 26444
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
m = int(readline())
ans = 0
chk = -1
for i in range(m):
  d,c = map(int,readline().split())
  ans += c
  chk += d*c
  if chk > 8:
    ans += chk//9
    chk %= 9
print(ans-1)

Measured memory_bytes: 9144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,s,e) for(int i=s;i<e;i++)
#define endl '\n'

int main(){
    ll N;cin>>N;
    ll sum=0;
    rep(i,1,N+1){
        ll Y=(ll)N/i;
        sum+=Y*(Y+1)*i/2;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3468
#include <iostream>
#include <string>
#include <map>

typedef long long ll;
int N, Q;
ll A[100005];

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);

  std::cin >> N;
  ll sum = 0;
  std::map<ll, ll> cnt;
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
    sum += A[i];
    cnt[A[i]]++;
  }

  std::cin >> Q;
  while (Q--) {
    ll b, c;  std::cin >> b >> c;
    ll d = c - b;
    sum += d * cnt[b];
    std::cout << sum << "\n";
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }

  return 0;
}


Measured memory_bytes: 10332
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
//typedef vector<int> vi;
//typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

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

	ll N; cin >> N;
	vl A(N); FOR(i, 0, N) cin >> A[i];
	const ll MOD = 1e9 + 7;

	vl b = A;
	sort(b.begin(), b.end());

	ll m;
	if (N % 2 == 1) {
		m = (N - 1) / 2;
		if (b[0] != 0) {
			cout << 0 << endl;
			return 0;
		}
		for (int i = 1; i < N; i += 2) {
			if (b[i] == i + 1 && b[i] == b[i + 1]) continue;
			cout << 0 << endl;
			return 0;
		}
	}
	else {
		m = N / 2;
		for (int i = 0; i < N; i += 2) {
			if (b[i] == i + 1 && b[i] == b[i + 1]) continue;
			cout << 0 << endl;
			return 0;
		}
	}
	
//	ll ans = pow(2, m);
	ll ans = 1;
	FOR(i, 0, m) {
		ans *= 2;
		ans %= MOD;
	}

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


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n,q;
vector<int>v[2000];
int z,t,x;
int main(){
    cin>>n>>q;
    while(q--){
        cin>>z>>t;
        if(z==0){
            cin>>x;
            v[t].push_back(x);
        }
        if(z==1){
            rep(i,v[t].size()){
                cout<<v[t][i];
                if(i!=v[t].size()-1)cout<<" ";
            }
            cout<<endl;
        }
        if(z==2)v[t].clear();
    }
    return 0;
}


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

typedef complex<double> P;

const double eps = 1e-8;

bool equals(double a, double b) {
  return abs(a-b) < eps;
}

double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}

double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}

int ccw(P p, P a, P b) {
  a -= p;
  b -= p;
  if(cross(a, b) > eps) return 1;
  if(cross(a, b) < -eps) return -1;
  if(dot(a, b) < -eps) return 2;
  if(norm(b) - norm(a) > eps) return -2;
  return 0;
}

P getCrossP(P a1, P a2, P b1, P b2) {
  P a = a2 - a1;
  P b = b2 - b1;
  return a1 + a * cross(b, b1 - a1) / cross(b, a);
}

vector<P> convex_cut(vector<P> ps, P p1, P p2, int dir = -1) {
  vector<P> v;
  for(int i = 0; i < ps.size(); ++i) {
    P a = ps[i];
    P b = ps[(i+1)%ps.size()];
    if(ccw(p1, p2, a) != dir) v.push_back(a);
    if(ccw(p1, p2, a)*ccw(p1, p2, b) == -1)
      v.push_back(getCrossP(a, b, p1, p2));
  }
  return v;
}

double getArea(const vector<P> &ps) {
  int n = ps.size();
  double res = 0;
  for(int i = 0; i < n; ++i) {
    res += cross(ps[i], ps[(i+1)%n]);
  }
  return res / 2.0;
}

int main() {
  for(int N, M; cin >> N >> M && (N|M); ) {
    vector<P> ps(N);
    for(int i = 0; i < N; ++i) {
      cin >> ps[i].real() >> ps[i].imag();
    }
    if(getArea(ps) < 0.0) reverse(ps.begin(), ps.end());
    vector<P> C(M);
    for(int j = 0; j < M; ++j) {
      cin >> C[j].real() >> C[j].imag();
    }

    for(int i = 0; i < M; ++i) {
      vector<P> g = ps;
      for(int j = 0; j < M; ++j) {
	if(i == j) continue;
	P p1, p2, base, base2;
	base = C[j] - C[i];
	base2 = P(-base.imag(), base.real());
	p1 = (C[i] + C[j]) / 2.0;
	p2 = p1 + base2;
	g = convex_cut(g, p1, p2);
      }
      printf("%.10f\n", getArea(g));
    }

  }
  return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const ll MOD=1e9+7;

int main(){
    int a; cin >> a;
    cout << a+pow(a, 2)+pow(a, 3) << endl;
    return 0;
}

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


int main()
{
       string str;
        int len;
        int i,j;
        while (1) {
              getline(cin,str);
               if (cin.eof())
                      break ;

              len = str.length();
              for ( j = 0; j < len; j++ ) {
                  if ( 'a' <= str[j] && str[j] <= 'z' ) {
						str[j] += 'A' - 'a';                    
				  }
              }
			cout << str << endl;
		}


        return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
 
using namespace std;
 
typedef long long int ll;
typedef vector<long long int> VL;
typedef vector<VL> VVL;
 
int main() {
    while(1) {
        string s;
        ll res = 0;
        cin >> s;
        if(s.length() <= 1 && s[0] == '0') {
            break;
        }
         
        for(int i=0; i<s.length(); i++) {
            char temp = s[i];
            res += temp-'0';
        }
         
        cout << res << endl;
    }
     
    return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

#define INF 1 << 20

struct node {
	int kind, h, step;

	node() { this -> kind = this -> h = this -> step = 0; }
	node(int kind, int h, int step) : kind(kind), h(h), step(step) { }
};

int main() {
	int H;
	while (cin >> H, H) {
		vector< vector<int> > state(2, vector<int>(H+1, 0));
		for (int i = 0; i < 2; ++i)
			for (int j = 0; j < H; ++j)
				cin >> state[i][j];

		vector< vector<int> > steps(2, vector<int>(H));
		for (int i = 0; i < 2; ++i)
			for (int j = 0; j < H; ++j)
				steps[i][j] = -1;

		int ans = -1;

		queue<node> que;
		que.push( node(0, 0, 0) );
		que.push( node(1, 0, 0) );
		while ( !que.empty() ) {
			node n = que.front(); que.pop();

			if (n.h >= H) continue;

			if ( state[n.kind][n.h] == 2 )
				while (state[n.kind][--n.h] == 2);

			else if (state[n.kind][n.h] == 1) {
				while (state[n.kind][++n.h] == 1);
				--n.h;
			}

			if (n.h == H-1) {
				ans = n.step;
				break;
			}

			if (steps[n.kind][n.h] >= 0) continue;
			steps[n.kind][n.h] = n.step;

			que.push( node(!n.kind, n.h,   n.step+1) );
			que.push( node(!n.kind, n.h+1, n.step+1) );
			que.push( node(!n.kind, n.h+2, n.step+1) );
		}
		if (ans >= 0) cout << ans << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N;

	cin >> N;

	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			if(i*j==N)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val M = sc.next().toInt()
        val AB = Array(N) { Pair(sc.next().toLong(), sc.next().toInt()) }
            .sortedBy { it.first }
        var ans = 0L
        var m = M
        var i = 0
        while (m > 0) {
            val n = min(AB[i].second, m)
            ans += AB[i].first * n
            m -= n
            i++
        }
        pw.println(ans)
    }
}


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

int main(){
    int X;
    cin >>X;
    
    if(X<100){
        cout << 0;
        return 0;
    }

    int all=X/100;

    if(X%10>5){
        all=all-2;
    }
    if(X%10<=5&&X%10>0){
        all=all-1;
    }

    all=all-(X%100-X%10)/5;
    if(all<0){
        cout << 0;
    }else{
        cout << 1;
    }
   
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var s string
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%s", &s)
	chars := strings.Split(s, "")

	var K int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &K)

	set := NewStrSet()
	for i := 0; i < len(chars); i++ {
		for k := 1; k <= 5 && i+k <= len(chars); k++ {
			str := strings.Join(chars[i:i+k], "")
			set.Add(str)
		}
	}
	//fmt.Println(set.Entries())

	records = make([]Record, set.Size())
	index := 0
	for str, _ := range set.Entries() {
		records[index] = Record{str}
		index++
	}
	sort.Sort(records)
	//fmt.Println(records)
	fmt.Println(records[K-1].str)

}

var records Records

type Record struct {
	str string
}

type Records []Record

func (r Records) Len() int {
	return len(r)
}
func (r Records) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func (r Records) Less(i, j int) bool {
	return r[i].str < r[j].str
}

type StringSet struct {
	set map[string]struct{}
}

func NewStrSet() *StringSet {
	return &StringSet{
		set: make(map[string]struct{}),
	}
}

func (s *StringSet) Add(str string) {
	s.set[str] = struct{}{}
}

func (s *StringSet) Contains(str string) bool {
	_, e := s.set[str]
	return e
}

func (s *StringSet) Size() int {
	return len(s.set)
}

func (s *StringSet) IsEmpty() bool {
	return s.Size() == 0
}

func (s *StringSet) Entries() map[string]struct{} {
	return s.set
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vc vector
#define a first
#define b second
#define pb push_back
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)

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

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

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

void Main(){
  int H, W, N;
  cin >> H >> W >> N;
  cout << N / max(H, W) + (N % max(H, W) ? 1 : 0) << endl;

  return;
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

#define INF 99999999
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#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;

int main(void){
    int n;
    cin >> n;
    vector<int> t(n);
    REP(i,n)
        cin >> t[i];
    
    int m;
    cin >> m;
    vector<int> p(m);
    vector<int> x(m);
    
    REP(i,m){
        cin >> p[i] >> x[i];
        p[i]--;
    }
    
    
    int total = 0;
    REP(i,n)total+=t[i];
    REP(i,m){
        cout << total - t[p[i]] + x[i] << endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 256
import std.stdio,
       std.string,
       std.conv,
       std.algorithm;

void main() {
  int[] a;
  for (int i = 0; i < 4; i++) {
    a ~= readln.chomp.to!(int);
  }

  writeln(min(a[0], a[1]) + min(a[2], a[3]));
}


Measured memory_bytes: 256
/* Code by : Suraj (@suraj1611) */

#include<bits/stdc++.h>
#include <string>

using namespace std;

#define ll long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mx INT_MAX
#define mn INT_MIN
#define md 1000000007
#define pb push_back
#define mp make_pair
#define maxsize 1100005
#define lb cout<<endl;
#define endl "\n"
#define F first
#define S second
#define label cout<<"hello!"<<endl
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

std::vector<ll> v[maxsize];
ll dp[maxsize];
ll n,m;

ll dfs(ll x)
{
	ll ans=0;
	if(dp[x]!=-1)
		return dp[x];
	for(auto i:v[x])
	{
		ans=max(ans,dfs(i)+1);
	}
	return dp[x]=ans;
}

ll power(ll x, ll  y) 
{ 
	ll m=md;
   	ll ans=1;
    while (y > 0) 
    {
        if (y & 1)
            ans = (ans * x) % m;
        x = (x * x) % m;
        y >>= 1;
    }
    return ans;
} 

int main()
{
	IOS
	


	cin>>n>>m;
	rep(i,m)
	{
		ll x,y;
		cin>>x>>y;
		v[x].pb(y);
	}
	ll ans=0;
	memset(dp,-1,sizeof(dp));
	rep1(i,n)
	{
		ans=max(ans,dfs(i));
	}
	cout<<ans<<endl;



    return 0;
}

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

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

  vector<string> a(n);
  vector<string> b(m);
  for(int i=0;i<n;i++) {
    cin >> a[i];
  }
  for(int i=0;i<m;i++) {
    cin >> b[i];
  }

  bool yes = false;

  for(int i=0;i<n-m+1;i++) {
    for(int j=0;j<n-m+1;j++) {
      bool same = true;
      for(int k=i;k<i+m;k++) {
        string sub = a[k].substr(j, m);
        if(sub == b[k-i]) continue;
        else {
          same = false;
          break;
        }
      }

      if(same) {
        yes = true;
        break;
      }
    }

    if(yes) {
      break;
    }
  }

  if(yes) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    printf("%s\n",((a==b && a==5 && c==7) or (a==c && a==5 && b==7) or (a==7 && b==5 && b==c))?"YES":"NO");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int main(){
  int Q;
  char s[9];
  int bin[32];
  scanf("%d", &Q);
  while(Q--){
    scanf("%s", s);
    for(int i = 0; i < 8; i++){
      switch(s[i]){
      case '0':
	bin[i*4] =  bin[i*4+1] = bin[i*4+2] = bin[i*4+3] = 0;
	break;
      case '1':
	bin[i*4] = bin[i*4+1] = bin[i*4+2] = 0;
	bin[i*4+3] = 1;
	break;
      case '2':
	bin[i*4] = bin[i*4+1] = bin[i*4+3] = 0;
	bin[i*4+2] = 1;
	break;
      case '3':
	bin[i*4] = bin[i*4+1] = 0;
	bin[i*4+2] = bin[i*4+3] = 1;
	break;
      case '4':
	bin[i*4] = bin[i*4+2] = bin[i*4+3] = 0;
	bin[i*4+1] = 1;
	break;
      case '5':
	bin[i*4] = bin[i*4+2] = 0;
	bin[i*4+1] = bin[i*4+3] = 1;
	break;
      case '6':
	bin[i*4] = bin[i*4+3] = 0;
	bin[i*4+1] = bin[i*4+2] = 1;
	break;
      case '7':
	bin[i*4] = 0;
	bin[i*4+1] = bin[i*4+2] = bin[i*4+3] = 1;
	break;
      case '8':
	bin[i*4+1] = bin[i*4+2] = bin[i*4+3] = 0;
	bin[i*4] = 1;
	break;
      case '9':
	bin[i*4+1] = bin[i*4+2] = 0;
	bin[i*4] = bin[i*4+3] = 1;
	break;
      case 'a':
	bin[i*4+1] = bin[i*4+3] = 0;
	bin[i*4] = bin[i*4+2] = 1;
	break;
      case 'b':
	bin[i*4+1] = 0;
	bin[i*4] = bin[i*4+2] = bin[i*4+3] = 1;
	break;
      case 'c':
	bin[i*4+2] = bin[i*4+3] = 0;
	bin[i*4] = bin[i*4+1] = 1;
	break;
      case 'd':
	bin[i*4+2] = 0;
	bin[i*4] = bin[i*4+1] = bin[i*4+3] = 1;
	break;
      case 'e':
	bin[i*4+3] = 0;
	bin[i*4] = bin[i*4+1] = bin[i*4+2] = 1;
	break;
      case 'f':
	bin[i*4] = bin[i*4+1] = bin[i*4+2] = bin[i*4+3] = 1;
	break;
      }
    }

    //    puts(s);
    //    rep(i, 32) printf(i%4?"%d":" %d", bin[i]); puts("");

    double res = 0;
    for(int i = 25, j = 1; i < 32; i += 1, j += 1)
      res += pow(0.5, j) * bin[i];

    for(int i = 1, j = 23; i < 25; i += 1, j -= 1)
      res += pow(2.0, j) * bin[i];

    if(bin[0]) res *= -1;

    //    if((s[6] == '0' || s[6] == '8') && s[7] == '0') printf("%.1lf\n", res);
    if(bin[31] == 1) printf("%.7lf\n", res);
    else if(bin[30] == 1) printf("%.6lf\n", res);
    else if(bin[29] == 1) printf("%.5lf\n", res);
    else if(bin[28] == 1) printf("%.4lf\n", res);
    else if(bin[27] == 1) printf("%.3lf\n", res);
    else if(bin[26] == 1) printf("%.2lf\n", res);
    else printf("%.1lf\n", res);
  }
  return 0;
}

Measured memory_bytes: 1232
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal

INF = 1 << 100


def run():
    N, K = map(int, sysread().split())
    P = list(map(int, sysread().split()))
    C = list(map(int, sysread().split()))
    P = [p-1 for p in P]

    loops = []
    checked = [0] * N
    loop = [0]
    for i in range(N):
        current = i
        while True:
            if not checked[current]:
                checked[current] = 1
                loop.append(C[current])
                current = P[current]
            else:
                if len(loop) == 1:break
                loops.append(loop)
                loop = [0]
                break
    loopSums = []
    for loop in loops:
        val = 0
        tmp = []
        for l in loop:
            val += l
            tmp.append(val)
        loopSums.append(tmp)
    #print(loops)
    #print(loopSums)
    ans = -INF
    for loop, loopSum in zip(loops, loopSums):
        for i in range(1, len(loop)):
            val = 0
            if loopSum[-1] <= 0 or len(loop)-1 > K:
                j = i
                max_val = -INF
                iter = 0
                while iter < K:
                    iter += 1
                    j += 1
                    if j == len(loop):
                        j = 1
                    val += loop[j]
                    max_val = max(max_val, val)
                    if i == j:
                        break
                #print(max_val)
                ans = max(ans, max_val)
                continue


            rest = K
            #if K <= len(loop) - i - 1:
            #    val += loopSum[i + K - 1] - loopSum[i]
            #    ans = max(ans, val)
            #    continue
            rest -= len(loop) - i - 1
            val += loopSum[-1] - loopSum[i]
            if rest // (len(loop)-1):
                val1 = val + (rest // (len(loop)-1)) * loopSum[-1]
                rest1 = rest % (len(loop) - 1)
                if rest1:
                    val1 += max(loopSum[1:rest1+1])
                val2 = val + (rest // (len(loop)-1) - 1) * loopSum[-1]
                val2 += max(loopSum[1:])
                val = max(val1, val2)
            else:
                if rest:
                    val += max(loopSum[1:rest+1])
            ans = max(ans, val)

    print(ans)

if __name__ == "__main__":
    run()

Measured memory_bytes: 69984
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <stdio.h>

using namespace std;

int main() {
	int N,R;
	cin >> N >> R;
	
	if (N < 10) {
		R += 100 * (10 - N);
	}

	cout << R << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int selsort(int *A,int n){
    int min,temp,cnt;
    cnt=0;
    for(int i=0;i<n;i++){
        min=i;
        for(int j=i;j<n;j++){
            if(A[min]>A[j]){
                min=j;
            }
        }
        if(i!=min){
            temp=A[i];
            A[i]=A[min];
            A[min]=temp;
            cnt++;
        }
    }
    return cnt;
}

int main(void){
    int n,ret;
    cin>>n;
    int A[n];
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    ret = selsort(A,n);
    for(int i=0;i<n;i++){
        cout<<A[i];
        if(i<n-1)cout<<' ';
    }
    cout<<endl;
    cout<<ret<<endl;
}



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


int main() {
	int n, count = 0;
	string s, temp;
	cin >> n >> s;

	for (int i = 0; i < n-2; i++){
		temp = s.substr(i, 3);
		if (temp == "ABC")
			count++;
	}

	cout << count;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

class List{
public:
    struct node{
        node* front;
        node* back;
        ll a;
        
        node(node* x,node* b,ll A=-1){
            front=x;
            back=b;
            a=A;
        }
        
        node(){
            front=NULL; back=NULL; a=-1;
        }
    };
    
    vector<node*> M;
    
    node root;
    
    List(vector<ll> A):root(NULL,NULL){
        M.resize(A.size()+1,NULL);
        node* L=&root;
        for(int i=0;i<A.size();i++){
            node* w=(node*)malloc(sizeof(node));
            (*L).back=w;
            (*w).front=L;
            (*w).a=A[i];
            M[A[i]]=w;
            L=w;
        }
        root.front=L;
        (*L).back=&root;
    }
    
    void swap(ll q){
        node* B=M[q];
        node* AL=(*B).front;
        node* AS=root.back;
        node* CS=(*B).back;
        node* CL=root.front;
        if(CS==&root){
            root.front=AL;
            root.back=B;
            (*AL).back=&root;
            (*B).front=&root;
            (*B).back=AS;
            (*AS).front=B;
        }
        else if(AL==&root){
            (*B).back=&root;
            root.front=B;
            (*CS).front=&root;
            root.back=CS;
            (*CL).back=B;
            (*B).front=CL;
        }
        else{
            (*CL).back=B;
            (*B).front=CL;
            (*AS).front=B;
            (*B).back=AS;
            (*AL).back=&root;
            root.front=AL;
            (*CS).front=&root;
            root.back=CS;
        }
    }
    
    void show(){
        node* where=root.back;
        cout<<(*where).a;
        where=(*where).back;
        while(where!=&root){
            cout<<" "<<(*where).a;
            where=(*where).back;
        }
        cout<<endl;
    }
};




int main(){
    ll n,q;
    cin>>n>>q;
    vector<ll> a(n);
    if(n==1){cout<<1<<endl; return 0;}
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    List L(a);
    //L.show();
    while(q--){
        ll Q;
        cin>>Q;
        //cout<<q<<endl;
        L.swap(Q);
    }
    //cout<<"!"<<endl;
    L.show();
    
    return 0;
}



Measured memory_bytes: 8400
import Data.List
import Control.Monad

count :: Int -> String -> String -> Int
count acc [] ls = acc
count acc (x:xs) ls = if x `elem` ls then count (acc+1) xs ls' else count acc xs ls'
	where
		ls' = nub ls

main = do
	line <- fmap (\x -> read x :: Int) getLine
	str <- getLine
	counts <- forM [1..(line-1)] $ \x -> do
		let split = splitAt x str
		return $ count 0 (nub (fst split)) (snd split)
	putStrLn $ show $ maximum counts

Measured memory_bytes: 1020
import java.util.Scanner;


public class Main {
	static int[] max;
	static int num;

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while(read()){
			solve();
		}

	}

	public static boolean read(){
		num = sc.nextInt();
		if(num == 0) return false;

		max = new int[num];

		for(int i=0; i<num; i++){
			for(int j=0; j<5; j++){
				max[i] += sc.nextInt();
			}
		}

		return true;
	}

	public static void solve(){
		int min_sum = 600;
		int max_sum = 0;

		for(int i=0; i<num; i++){

			if(max[i] < min_sum){
				min_sum = max[i];
			}

			if(max[i] > max_sum){
				max_sum = max[i];
			}
		}

		System.out.println(max_sum + " " + min_sum);

	}

}

Measured memory_bytes: 12000
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;
use num::*;


fn main() {
    input! {
    n:usize,
    b:usize,
    mut a:[String;n],
    }
    a.sort();
    let z = a.join("");
    println!("{}",z);
}

Measured memory_bytes: 2088
// https://atcoder.jp/contests/arc091/tasks/arc091_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, k, cnt = 0;
    cin >> n >> k;
    if (k == 0) {
        cout << n * n << endl;
    } else {
        // 割る数を固定
        for (int i = k + 1; i <= n; i++) {
            ll group = (n + 1) / i;
            ll rem = (n + 1) - (group * i);
            ll add = max(rem - k, 0LL);
            cnt += (i - k) * group + add;
        }
        cout << cnt << endl;
    }

    return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define EPS (1e-7)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

struct Data{
  double theta;
  int cost;
  Data(double theta=IINF,int cost=IINF):theta(theta),cost(cost){}
  bool operator < (const Data& a)const{
    if(equals(theta,a.theta)) return cost < a.cost;
    return theta > a.theta;
  }
};

int H,W;
char f[619][619];

int main(){
  cin.tie(0);
  std::ios::sync_with_stdio(0);
  cin >> H >> W;
  rep(i,H)rep(j,W)cin >> f[i][j];

  vector<Data> vec;
  rep(i,H)rep(j,W){
    if( f[i][j] == '#' && ( j-1 <  0 || f[i][j-1] == '.' ) && ( i-1 <  0 || f[i-1][j] == '.' ) ) vec.push_back(Data(atan2(H-i,j),1));
    if( f[i][j] == '#' && ( j+1 >= W || f[i][j+1] == '.' ) && ( i+1 >= H || f[i+1][j] == '.' ) ) vec.push_back(Data(atan2(H-i-1,j+1),-1));
    if( f[i][j] == '#' && ( j+1 <  W && f[i][j+1] == '#' ) && ( i+1 <  H && f[i+1][j] == '#' ) ) vec.push_back(Data(atan2(H-i-1,j+1),1));
    if( f[i][j] == '#' && ( j-1 >= 0 && f[i][j-1] == '#' ) && ( i-1 >= 0 && f[i-1][j] == '#' ) ) vec.push_back(Data(atan2(H-i,j),-1));
  }

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

  int area = 1, ans = 1;
  rep(i,vec.size())ans = max(ans,(area+=vec[i].cost));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 18544
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i <= g; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1e9 + 7;

struct eratosthenes
{
    int n;
    vector<int> f;
    vector<P> primes;

    eratosthenes(int n) : f(n + 1)
    {
        ll i, j;
        f[0] = f[1] = -1;
        for (i = 2; i <= n; i++)
        {
            if (!f[i])
            {
                f[i] = i;
                primes.push_back(P(i, 0));
                for (j = i * i; j <= n; j += i)
                {
                    if (!f[j])
                    {
                        f[j] = i;
                    }
                }
            }
        }
    }

    vector<int> genosis(int x)
    {
        vector<int> g;

        while (x != 1)
        {
            g.push_back(f[x]);
            x /= f[x];
        }

        return g;
    }

    vector<P> genosiscount(int x)
    {
        vector<P> gc;
        vector<int> g = genosis(x);

        if (g.empty() == 1)
        {
            return {};
        }

        gc.push_back(P(f[x], 0));

        for (auto &i : g)
        {
            if (gc.back().first == i)
            {
                gc.back().second++;
            }
            else
            {
                gc.push_back(P(i, 1));
            }
        }

        return gc;
    }
};

ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = (ans * x) % 1000000007;
        x = (x * x) % 1000000007;
        y >>= 1;
    }
    return ans;
}

int main(void)
{
    eratosthenes a(1e6 + 1);
    int N;
    int A[10010];
    int i, j;
    ll ans = 0;
    ll lcm = 1;

    cin >> N;

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

        for (auto &j : a.genosiscount(A[i]))
        {
            for (auto &k : a.primes)
            {
                if (j.first == k.first && j.second > k.second)
                {
                    k.second = j.second;
                }

                if (j.first < k.first)
                {
                    break;
                }
            }
        }
    }

    for (auto &x : a.primes)
    {
        lcm = lcm * power(x.first, x.second) % 1000000007;
    }

    for (i = 0; i < N; i++)
    {
        ll add = lcm * power(A[i], 1000000005) % 1000000007;
        ans = (ans + add) % 1000000007;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5368
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner stdin = new Scanner(System.in);
		String readNum = stdin.nextLine();
		String[] twoNum = readNum.trim().split("\\s+");
		int a = Integer.parseInt(twoNum[0]);
		int b = Integer.parseInt(twoNum[1]);
		if ((a >= -1000 && a <= 1000) && (b >= -1000 && b <= 1000)) {
			if (a < b) {
				System.out.println("a < b");
			} else if (a > b) {
				System.out.println("a > b");
			} else if (a == b) {
				System.out.println("a == b");
			}
		}
	}
}

Measured memory_bytes: 26296
#include <stdio.h>
#include <stdlib.h>

#define MAX 100
#define NIL -1
#define INFTY (1<<21);

int M[MAX][MAX];
int *key, *p;
int n;

void input() {
	int i, j;

	scanf("%d", &n);

	for (i = 0; i < n; i++){
		for (j = 0; j < n; j++){
			scanf("%d", &M[i][j]);
			if (M[i][j] == NIL) {
				M[i][j] = INFTY;
			}
		}
	}
}

void init() {
	int i;

	key = (int *)malloc(sizeof(int) * n);
	p = (int *)malloc(sizeof(int) * n);

	for (i = 0; i < n; i++) {
		key[i] = INFTY;
		p[i] = NIL;
	}

	key[0] = 0;
}

int MSTPrim() {
	int i, j, k, u, sum = 0;

	init();

	while (1) {
		u = NIL;

		for (i = 0; i < n; i++) {
			if (p[i] == 1) continue;
			if (u == NIL || key[i] < key[u]) {
				u = i;
			}
		}

		if (u == NIL) break;
		p[u] = 1;
		for (i = 0; i < n; i++) {
			if (key[i] > M[u][i] && p[i] == NIL) {
				key[i] = M[u][i];
			}
		}
	}

	for (i = 0; i < n; i++) {
		sum += key[i];
	}

	return sum;
}

void Free() {
	free(key);
	free(p);
}

main() {

	input();
	printf("%d\n", MSTPrim());
	Free();

	return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    int sum = 0;
    vector<int> a(N);
    for(int i = 0; i < N; ++i){
        cin >> a[i];
        sum ^= a[i];
    }
    for(int i = 0; i < N; ++i){
        cout << (a[i]^sum) << endl;
    }
    return 0;
}

Measured memory_bytes: 3980
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int n;
	vector<vector<int>>list(100, vector<int>(200, 0));

	cin >> n;

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < s.length(); j++) {
			list[i][(int)s[j]]++;
		}
	}

	string ss;

	for (int i = 0; i < 200; i++) {
		int minn = 999999;

		for (int j = 0; j < n; j++) {
			minn = min(list[j][i], minn);
		}

		if (minn > 0) {
			for (int k = 0; k < minn; k++) {
				ss += (char)i;
			}
		}
	}

	cout << ss << endl;


	return 0;
}

Measured memory_bytes: 384
data = input()
tmp = data.replace("x", "")
c1 , c2, num = 0, -1, 0
if tmp == tmp[::-1]:
    while(c1 < len(data) + c2):
        if data[c1] == data[c2]:
            c1+=1
            c2-=1
        elif data[c2]=="x":
            c2-=1
            num+=1
        else:
            c1+=1
            num+=1
else:
    num = -1
print(num)

Measured memory_bytes: 3316
inp=input()
(H,W)=map(int,inp.split(" "))

if (H==1 or W==1) :
    print(1)
else:
    m1=int((W+1)/2)
    m2=int(W/2)

    n1=int((H+1)/2)
    n2=int(H/2)

    print(m1*n1+m2*n2)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int N; cin >> N;
	string S; cin >> S;
	int count = 1;
	char befo = S[0];
	for (int i = 1; i < N; i++) {
		if (S[i] != befo) count++;
		befo = S[i];
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int x[5], i;

  for(i=0; i<5; i++)
    scanf("%d", &x[i]);

  for(i=0; i<5; i++){
    if(x[i]==0){
      printf("%d\n", i+1);
    }
  }

  return 0;
}


Measured memory_bytes: 1732
def main():
    n = int(input())
    ac = 0
    wa = 0
    tle = 0
    re = 0

    for i in range(n):
        s = input()

        if s == "AC":
            ac += 1
        elif s == "WA":
            wa += 1
        elif s == "TLE":
            tle += 1
        else:
            re += 1

    print("AC x " + str(ac))
    print("WA x " + str(wa))
    print("TLE x " + str(tle))
    print("RE x " + str(re))
if __name__ == "__main__":
    main()


Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

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

    if ( N == 1 ) { cout << "Hello World" << endl; return 0;  }

    int A,B;
    cin >> A >> B;

    cout << A+B << endl;


    return 0;
}

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

int main(void)
{
	int i, j, n, x;
	char T[1001], t[1001], W[11];
	
	scanf("%s", W);
	x = strlen(W);
	
	n = 0;
	while(1){
		scanf("%s", T);
		if(!memcmp(T, "END_OF_TEXT", strlen("END_OF_TEXT"))) break;
		for(i = 0, j = 0; ; i++){
			if((T[i] != ' ') && (T[i] != 0x00)){
				t[j++] = T[i];
				continue;
			}
			if((j == x) && (!strncasecmp(t, W, x))) n++;
			if(T[i] == 0x00) break;
			j = 0;
		}
	}
	printf("%d\n", n);
	
	return(0);
}



Measured memory_bytes: 1812
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;

int main() {
    string s; cin >> s;
    int n = s.size();
    vector<vector<int>> dp(n + 1, vector<int>(13));
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        if (s[i - 1] == '?') {
            for (int d = 0; d < 10; d++) {
                for (int r = 0; r < 13; r++) {
                    (dp[i][(r * 10 + d) % 13] += dp[i - 1][r]) %= MOD;
                }
            }
        } else {
            int d = s[i - 1] - '0';
            for (int r = 0; r < 13; r++) {
                (dp[i][(r * 10 + d) % 13] += dp[i - 1][r]) %= MOD;
            }
        }
    }
    cout << dp[n][5] << endl;
    return 0;
}

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

int H,W;
int dp[1001][1001][4][4][4];
char fie[1001][1002];
bool F[1001][1001];

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int db[]={2,1,3,3};

bool posc(int y,int x){
  return x < 0 || y < 0 || x >= W || y >= H;
}

void ume(int y,int x,int f,bool v){
  if( posc(y,x) ) return;
  F[y][x] = v;
  if( f & 1 ) F[y][x+1] = v;
  if( f >>1 ) F[y+1][x] = v;
}

int solve(int y,int x,int st,int f1,int f2){
  if( dp[y][x][st][f1][f2] != -1 ) return dp[y][x][st][f1][f2];
  int nt1 = st >> 1;
  int nt2 = st & 1;
  ume( y - dy[nt1], x - dx[nt1], f1, true );
  ume( y - dy[nt1] - dy[nt2], x - dx[nt1] - dx[nt2], f2, true );

  int sum = 0;
  int dc[4];
  if( !F[y][x] && fie[y][x] != '.' ) sum+=fie[y][x]-'0';
  for(int i=0;i<4;i++){
    int ny = y+dy[i], nx = x + dx[i];
    dc[i] = 0;
    if( posc(ny,nx) ) continue;
    if( !F[ny][nx] && fie[ny][nx] != '.' ) {
      sum += fie[ny][nx]-'0';
      dc[i] = fie[ny][nx]-'0';
    }
  }
 
  ume( y - dy[nt1], x - dx[nt1], f1, false );
  ume( y - dy[nt1] - dy[nt2], x - dx[nt1] - dx[nt2], f2, false ); 

  if( H-1 == y && W-1 == x ){
    int ret = sum;
    for(int i=0;i<4;i++){
      ret = min( ret,sum-dc[i] );    
    }
    return ret;
  }

  int ret = INT_MAX;
  for(int i=0;i<4;i++){
    for(int j=0;j<2;j++){      
      int ny = y+dy[j], nx = x + dx[j];
      if( posc(ny,nx) ) continue;
      int nst = st>>1;
      nst |= (j<<1);
      // cout << y << "," << x << " -> " << ny << "," << nx <<"  = " << sum-dc[i] << endl;
      ret = min( ret,solve( ny,nx, nst, db[i], f1 )+sum-dc[i] );
    }
  }
  return dp[y][x][st][f1][f2] = ret;
}

int main(){
  scanf("%d%d",&H,&W);
  for(int i=0;i<H;i++)
    scanf("%s",fie[i]);
  memset(dp,-1,sizeof(dp));

  cout << solve(0,0,0,0,0) << endl;

  
}

Measured memory_bytes: 253984
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, k = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    d = defaultdict(int)
    for e in a:
        d[e] += 1
    b = [(d[k], k) for k in d]
    b.sort()
    ans = 0
    i = 0
    m = len(b)
    while m - i > k:
        ans += b[i][0]
        i += 1
    print(ans)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""


Measured memory_bytes: 42544
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldouble = long double;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;


int main()
{
	for (ll i = 0; i < 3; i++)
	{
		string s;
		cin >> s;

		print((char)(s[0] & 0xdf));
	}

	println("");
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 1e3+5;
LL A[maxn][3], sum[maxn];

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    ios::sync_with_stdio(false);
    int N,M;
    while (cin >> N >> M) {
        FOR(i,0,N)
            cin >> A[i][0] >> A[i][1] >> A[i][2];
        LL ans = 0;
        FOR(mask,0,1<<3) {
            FOR(i,0,N) {
                sum[i] = 0;
                FOR(j,0,3) {
                    if (mask & (1<<j))
                        sum[i] += A[i][j];
                    else
                        sum[i] -= A[i][j];                    
                }
            }
            sort(sum,sum+N); reverse(sum,sum+N);
            LL res = 0;
            FOR(i,0,M)
                res += sum[i];
            ans = max(res,ans);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 512
/*
 * atcoder/abc101/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * 最小値とインデックスnを求める.
 * その最小値nを含めるようにKを選択.
 * (K-1)/N-n + (K-1)/n
 *
 * 問題は、K=2より大きい時に最初のKのとり方が複数あること
 * 全部試してもO(K)なので全探索
 */
int N, K;
vector<int> A;

void solve() {
  cin >> N >> K;
  int a;
  int min_ = 200000, idx = -1;
  loop(n,0,N) {
    cin >> a;
    A.push_back(a);
    if (chmin(min_, a)) idx = n;
  }

  min_ = 200000;
  for (int k=max(0, idx-K+1); k<=idx; k++) {
    int cost = 1, cost_l = 0, cost_r = 0;
    int left = k-1, right = k+K;
    if (left>=0) cost_l = (int)ceil((left+1)/(double)(K-1));
    if (right<=N) cost_r = (int)ceil((N-right)/(double)(K-1));
    chmin(min_, cost_l + cost + cost_r);
    // cout << "k=" << k << " : " << cost_l << " " << cost << " " << cost_r << endl;
  }
  cout << endl << min_ << endl;
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


Measured memory_bytes: 892
N,M = list(map(int,input().split()))
import math
if N <= 1:
    n = 0
else:
    n = math.factorial(N)/(2*(math.factorial(N-2)))
if M <= 1:
    m = 0
else:
    m = math.factorial(M)/(2*(math.factorial(M-2)))
print(int(n + m))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 10001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int,int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 1e9;
const ll INF = 1e18;
#define B 100

int a[MAX], dp[2][MAX][2];
int main(){
	int n, t1, t2;
	scanf("%d", &n);
	rep(i,2)rep(j,MAX)rep(k,2)dp[i][j][k] = inf;
	for(int i = 2;i <= n;i++)scanf("%d", &a[i]);
	dp[0][0][0] = dp[0][0][1] = 0;
	
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n/2+1;j++){
			dp[i%2][j][0] = min(dp[(i-1)%2][j-1][0], dp[(i-1)%2][j-1][1]+a[i]);
			dp[i%2][j][1] = min(dp[(i-1)%2][j][1], dp[(i-1)%2][j][0]+a[i]);
		}
		rep(j,n)rep(k,2)dp[(i-1)%2][j][k] = inf;
	}
	
	printf("%d\n", min(dp[n%2][n/2][0], dp[n%2][n/2][1]));
	return 0;
}

Measured memory_bytes: 3412
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long money = 100;
    long year = 0;
    while (true) {
      money = (long)(money * 1.01);
      year++;
      if (money >= x) {
        break;
      }
    }
    System.out.println(year);
  }
}


Measured memory_bytes: 35792
# -*- coding:utf-8 -*-

def solve():
    N, K = list(map(int, input().split()))
    L = list(map(int, input().split()))
    L.sort(reverse=True)

    # 長いものからK本選べばよい
    ans = sum(L[0:K])
    print(ans)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
const int MAX = 100001;

int main() {
	int a, N, max = 0;
	static int num[MAX];
	cin >> N;
	for (int i = 0;i < MAX;i ++)num[i] = 0;
	for (int i = 0;i < N;i ++) {
		cin >> a;
		if (a > 0) num[a - 1] ++;
		num[a] ++;
		num[a + 1] ++;
	}
	for (int i = 0;i < MAX;i ++) {
		if (max < num[i]) max = num[i];
	}
	cout << max;
	return 0;
}

Measured memory_bytes: 640