akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector< vector<ll> >;

int N, L, Q;
int x[100000];
vector<P> query;
int nxt[20][100000];
int NUM;
const int INF = 1000000000;

int calc(int a, int key) {
  int temp = a;
  for(int i = NUM; i >= 0; i--) {
    if((key>>i) & 1) {
      temp = nxt[i][temp];
      if(temp == INF) return temp;
    }
  }
  return temp;
}

int isOk(int a, int b, int key) {
  if(calc(a, key) >= b) return true;
  return false;
}

int lower_search(int a, int b) {
  int l = -1, r = N;
  while(r - l > 1) {
    int half = (r + l) / 2;
    if(isOk(a, b, half)) r = half;
    else l = half;
  }
  return r;
}

int main() {
  cin >> N;
  NUM = floor(log2(N));
  rep(i, NUM+1) {
    rep(j, N) {
      nxt[i][j] = INF;
    }
  }
  rep(i, N) {
    cin >> x[i];
  }
  cin >> L;
  cin >> Q;

  rep(i, Q) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    query.push_back({a, b});
  }

//尺取り法で１日で移動できる場所を求める。
  int srt = 0;
  int end = 1;
  while(true) {
    if(srt == N-1) break;
    if(x[end]-x[srt] > L) {
      nxt[0][srt] = end-1;
      srt++;
    } else {
      if(end != N-1) {
        end++;
      } else if(end == N-1) {
        nxt[0][srt] = end;
        srt++;
      } 
    }
  }

  // rep(i, N) {
  //   if(i == N-1) continue;
  //   int temp = 0;
  //   for(int j = i+1; j < N; j++) {
  //     int cand = temp;
  //     temp += x[j] - x[j-1];
  //     if(temp > L) {
  //       nxt[0][i] = j-1;
  //       break;
  //     } 
  //   }
  //   if(temp <= L) nxt[0][i] = N-1;
  // }

  rep(i, NUM) {
    rep(j, N) {
      if(nxt[i][j] == INF) nxt[i+1][j] = INF;
      else {
        nxt[i+1][j] = nxt[i][nxt[i][j]];
      }
    }
  }

  rep(i, Q) {
    int u = query[i].first;
    int v = query[i].second;
    if(u > v) swap(u, v);
    cout << lower_search(u, v) << endl;
  }

  // rep(i, NUM+1) {
  //   rep(j, N) {
  //     cout << nxt[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  return 0;
}

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

#define MAX (1000)

int updown(const void *x, const void *y){ return ((*((int *)x)) - (*((int *)y))); }
int main(void)
{
	int data[MAX];
	int minCost;
	int n, m;
	int i;
	
	while (1){
		scanf("%d %d", &n, &m);
		if (!(n * m)) break;
		for (i = 0; i < n; i++) scanf("%d", &data[i]);
		qsort(data, n, sizeof(int), updown);
		for (i = n % m; i < n; i += m) data[i] = 0;
		
		minCost = 0;
		for (i = 0; i < n; i++) minCost += data[i];
		
		printf("%d\n", minCost);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

string S;
int K;
cin >> S >> K;

rep(i, 0, min(K, (int)S.size())) 
    if (S[i] != '1') {
        cout << S[i] - '0' << endl;
        return 0;
    }
cout << "1\n";

}

// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<int,int> >p(n);
  int i;
  priority_queue<int>salary;
  for(i=0;i<n;i++){
    cin >> p[i].first >> p[i].second;
  }
  long ans = 0;
  sort(p.begin(),p.end());
  int tmp = 0;
  for(i=1;i<=m;i++){
    while(tmp<n && p[tmp].first<=i){
      salary.push(p[tmp].second);
      tmp ++;
    }
    // if(!salary.empty()){
    //   ans += salary.top();
    //   cout << salary.top()<<endl;
    //   salary.pop();
    // }

    if(!salary.empty()){
      ans += salary.top();
      salary.pop();
    }

  }
  cout << ans << endl;

}


Measured memory_bytes: 1660
class Node:
    def __init__(self, key=-1, parent=-1, left=-1, right=-1):
        self.key = key
        self.parent = parent
        self.left = left
        self.right = right


def insert(t, z):
    x, y = t, -1
    while x != -1:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y

    if y == -1:
        t = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

    return t


def print_tree(t):
    def in_order(z):
        if z == -1:
            return

        in_order(z.left)
        print(" {}".format(z.key), end="")
        in_order(z.right)

    def pre_order(z):
        if z == -1:
            return

        print(" {}".format(z.key), end="")
        pre_order(z.left)
        pre_order(z.right)

    in_order(t)
    print()
    pre_order(t)
    print()


def main():
    n = int(input())
    bst = -1

    for i in range(n):
        order = input().split()
        if order[0][0] == "i":
            node = Node(key=int(order[1]))
            bst = insert(bst, node)
        else:
            print_tree(bst)


if __name__ == '__main__':
    main()



Measured memory_bytes: 105272
import java.util.*;
class Main{
    public static void main(String[] args) {
        Scanner sc  = new Scanner (System.in);
        String s = sc.next();
        int len = s.length();
        boolean easyP = true;
        for(int i = 0;i<len;i++){
            if(i%2==0){
                if(s.charAt(i)=='R'||s.charAt(i)=='U'||s.charAt(i)=='D'){
                
                }
                else{
                    easyP = false;
                    break;
                }
        }
        if(i%2!=0){
            if(s.charAt(i)=='L'||s.charAt(i)=='U'||s.charAt(i)=='D'){
                
            }
            else{
                easyP = false;
                break;
            }
        }
        }
        System.out.println(easyP?"Yes":"No");
        }

       
    }


Measured memory_bytes: 35636
#include<stdio.h>
long int m(long int a,long int b){return a<b?a:b;}
long int mm(long int a,long int b,long int c){
  long int x=a<b?a:b,y=a>b?a:b;
  x=x<c?x:c;y=y>c?y:c;
  return y-x;
}
int main(){
  long int h,w,min,i,j,k;
  scanf("%ld%ld",&h,&w);
  j=h%3==2;k=h%3!=0;
  min=mm(h/3L*w,(h/3L+j)*w,(h/3L+k)*w);
  for(i=0;i<=h%3;i++)min=m(min,mm((h/3L+i)*w,(h-(h/3L+i))*(w/2),(h-(h/3L+i))*(w-w/2)));
  h^=w;w^=h;h^=w;
  j=h%3==2;k=h%3!=0;
  min=m(min,mm(h/3L*w,(h/3L+j)*w,(h/3L+k)*w));
  for(i=0;i<=h%3;i++)min=m(min,mm((h/3L+i)*w,(h-(h/3L+i))*(w/2),(h-(h/3L+i))*(w-w/2)));
  printf("%ld",min);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n ; i++)

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

    int count = 0;
    int min = 10000;
    int dmin = 10000;

    rep(i, N){
        int a;
        cin >> a;
        count = 0;
        while(a % 2 == 0){
            a = a / 2;
            count++;
        }
        // dmin = min(dmin, count);
        if(count < min){
            min = count;
        }
    }

    cout << min << endl;

}

Measured memory_bytes: 3628
import java.util.Scanner;

class Main{
  public static void main(String[] args){
  Scanner scanner=new Scanner(System.in);
  int a = scanner.nextInt();
  int b = scanner.nextInt();
  int c = scanner.nextInt();
if(a==b && a==c){
  System.out.println(1);
  }else if(a==b || a==c || b==c){
    System.out.println(2);
      }else{System.out.println(3);
      }
}
}

Measured memory_bytes: 9044
class Solution:
    def solve(self, X: int, A: int) -> str:

        if X < A:
            return 0
        else:
            return 10


if __name__ == '__main__':

    # standard input
    X, A = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(X, A))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
using namespace std;
 
bool a[107];
 
int main(){
  int n, k, ans=0;
  cin>>n>>k;
  for(int i=0;i<k;i++){
    int x; cin>>x;
    for(int j=0;j<x;j++){
      int y; cin>>y;
      a[y]=1;
    }
  }
  for(int i=1;i<=n;i++){
    if(!a[i]) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<queue>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  
  ll c = a + b;

  ll n1 = n/c;
  ll n2 = n%c;
  ll d;

  if (n2 > a) {
    d = a;
  } else {
    d = n2;
  }

  ll ans = a * n1 + d;

  cout << ans << endl;
  return 0;

} 


Measured memory_bytes: 256
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn sum(v: Vec<i32>) -> i32 {
	let mut m =0;
	for i in v.iter() {
		m+=*i
	}
	m
}
fn main() {
	let s = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<String>>();
	let N = s[0].trim().parse::<i32>().unwrap();
	let A = s[1].trim().parse::<i32>().unwrap();
	let B = s[2].trim().parse::<i32>().unwrap();
	let mut v = vec!();
	for i in 1..(N+1) {
		let c = i;
		if i.to_string().chars().count() >= 2 {
			let s = c.to_string();
			let r = s.split("").collect::<Vec<&str>>();
			let k = r[1..(r.len() - 1)].iter().map(|e|e.parse().unwrap())
			.collect::<Vec<i32>>();
			let sum = sum(k);
			if  A <= sum && sum <= B {
					v.push(i);
				}
		}else{
			if  A <= i && i <= B {
					v.push(i);
				}
		}
	}
	println!("{:?}",sum(v));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
  int res = 1;
  x = x % p;
  while (y > 0)
  {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
 
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  tc = 1;
  //cin >> tc;
  while(tc--)
  {
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m;i++){
      int a;
      cin >> a;
      sum += a;
    }
    if(sum>n){
      cout << -1 << endl;
    }
    else{
      cout << n - sum << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int factorial(int n) 
{ 
    return (n==1 || n==0) ? 1: n * factorial(n - 1);  
} 
int main()
{
    int n,count=0;
    cin>>n;
    vector<int> l(n);
    for(int i=0; i<n; i++){
    	cin>>l[i];
	}
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(l[j]==l[i])
				continue;
			for(int k=j+1; k<n; k++){
				if(l[j] !=l[k] && l[k] !=l[i]){
					if(l[i]+l[j] > l[k] && l[j]+l[k]>l[i] && l[k]+l[i]>l[j])
						count++;
				}
			}
		}
	}

    cout<<count<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);

	int n;
    cin>>n;

    int x = n/1.08;
  
  	int x1 = x*1.08;
  int x2 = (x+1)*1.08;
    if(x1 == n)
      cout<<x;
  	else if(x2 == n)
      cout<<x+1;
  	else
      cout<<":(";
    

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int s,w;
    cin >> s >> w;
    if(w>=s)cout << "unsafe"<<endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    H = [int(input()) for _ in range(N)]
    H.sort()
    print(min([H[i+K-1]-H[i] for i in range(N-K+1)]))

main()


Measured memory_bytes: 11288
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string niloy(int i){
        string S;
        while(i){
          int d = i%10;
          i /= 10;
          S += d+'0';    
        }
        reverse(S.begin(), S.end());
        return S;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, K;
  cin >> N >> K;
  vector<char> D;
  int ar[10];
  memset(ar, 0, sizeof(ar));
  for (int i = 0; i < K; i++){
    int A;
    cin >> A;
    ar[A]++;
  }
  int Ans;
  for (int i = 0; i <=9; i++)
    if (ar[i] == 0)
      D.push_back(i+'0');
  for (int i = N; ; i++){
    string S = niloy(i);
    bool use = true;
    for (int j = 0; j < S.size(); j++){
      bool ok = false;
      for (int k = 0; k < D.size(); k++){
        if (D[k] == S[j])
          ok = true;
      }
      if (ok == false)
        use = false;
    }
    if (use){
      Ans = i;
      break;   
    }
  }
  cout << Ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<int>;
using A = array<int, 2>;
using P = pair<int, int>;
constexpr int MOD{1000000000 + 7};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr array<int, 4> dx{1, 0, -1, 0}, dy{0, 1, 0, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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;
}
constexpr int div_roundup(int a, int b)
{
    return (a + b - 1) / b;
}

// vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));

// *****************************************************************************

void solve()
{
    int n, d;
    cin >> n >> d;
    cout << div_roundup(n, 2 * d + 1) << endl;
}

// *****************************************************************************

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

    solve();
}


Measured memory_bytes: 256
L=list(map(int, input().split()))
N=L[0]
K=L[1]
m0=0
m1=0
m2=0
m3=0
m=0

if N==K:
    print(0)
else:
    m0=N
    m1=abs(N % K)
    m2=abs((N % K) - K)
    m3=abs(N-K)
    m=min(m0,m1,m2,m3)
    print(m)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
const long long size=1e5+10;
long long x[size],n;
int main()
{
	int a,b,c;
	a=b=c=0;
	cin>>n;
	if(n<2||n>1e5)
	return -1;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
		if(x[i]%4==0) a++;
		else if(x[i]%2==0) b++;
		else c++;
	}
	
	if(!b) c--;
	cout<<(a>=c?"Yes":"No");
	return 0;
 } 

Measured memory_bytes: 1024
#include <iostream>
#include <bitset>
#include <vector>
#include <cmath>
using namespace std;

int main() {

    long A, B, C; // それぞれの値段 
    long X, Y;    // 必要枚数

    cin >> A >> B >> C >> X >> Y;

    // 2C = A + B

    long kyotsu_mai = min(X, Y);
    long saidai_mai = max(X, Y);
    long tarinai = 0;
    if(X > Y){
        tarinai = X - kyotsu_mai;
    }else{
        tarinai = Y - kyotsu_mai;
    }

    //cout << "kyotsu_mai: " << kyotsu_mai <<endl;
    //cout << "tarinai   : " << tarinai << endl;

    long sum = 0;

    //まとめ買いが安い
    if (2 * C  < A + B){

        //int sum = 0;
        sum += (2 * C) * kyotsu_mai;
        //cout << "sum 01   : " << sum << endl;
        if(X > Y){
            
            sum += tarinai * A;
            //cout << "sum 02   : " << sum << endl;
        }
        else{
            
            sum += tarinai * B;
            //cout << "sum 03   : " << sum << endl;
        }

        int sum_2 = saidai_mai * (2 * C);
        if (sum > sum_2){
            sum = sum_2;
        }

    }else if (2 * C >= A + B){

        //int sum = 0;
        sum += A * X + B * Y ;

    }



    cout << sum << endl;




}

Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    string s; cin >> s;
    // app .. appear
    vector<bool> app(26, false);
    rep(i,s.size()) {
        app[s[i]-'a'] = true;
    }
    rep(i,26) {
        if (!app[i]) {
            // 'a' == 97
            cout << char(i+'a') << endl;
            return 0;
        }
    }
    cout << "None\n";
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <numeric>
#define ll long long

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define pb emplace_back
#define mp make_pair


using namespace std;

const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

typedef pair<ll, ll> P;

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll R, C, N, M, K, Q;

vector<int> v[200005];
vector<int> res;

void dfs(int node, int p = 0){
    PRINT(node)
    PRINT(res[node])
    rep(i,v[node].size()){
        if(v[node][i] == p) continue;
        res[v[node][i]] += res[node];
        dfs(v[node][i], node);
    }
    return;
}

signed main() {
    //cout << fixed << setprecision(10);
    cin >> N >> Q;

    rep(i, N-1){
        int from,to; cin >> from >> to;
        from --;
        to --;
        v[from].pb(to);
        v[to].pb(from);
    }
    res.assign(N,0); 
    rep(i,Q){
        int node, val; cin >> node >> val;
        res[--node] += val;
    }
    dfs(0);

    rep(i, N){
        cout << res[i] << " ";
    }
    cout << endl;

    //cout << max << endl;
}


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

    def Find_Root(self,x):
        if self.root[x]<0:return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def size(self,x):
        return -self.root[self.Find_Root(x)]

    def members(self,x):
        root=self.Find_Root(x)
        return [i for i in range(self.n) if self.Find_Root(i)==root]

    def roots(self):
        return[i for i,j in enumerate(self.root) if j<0]

    def group_members(self):
        return {i:self.members(i) for i in self.roots()}

    def group_count(self):
        return len(self.roots())


N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))

UnionFind=UnionFind(N+1)
for i in range(N):
    UnionFind.Unite(i+1,P[i])

D=UnionFind.group_members()
E=[]
for i in D:
    A,length=D[i],len(D[i])
    if A[0]==0:continue
    index,F=A[0]-1,[]
    while len(F)!=length:
        index=P[index]-1
        F.append(C[index])
    E.append(F)

ans=-float("inf")
for A in E:
    length=len(A)
    if sum(A)<0:
        A=A*2
        for i in range(length):
            point=0
            for j in range(min(K,length)):
                point +=A[i+j]
                ans=max(ans,point)
    else:
        div,mod=divmod(K,length)
        base=(div-1)*sum(A)
        A=A*3
        for i in range(length):
            point=0
            ans=max(ans,base)
            for j in range(mod+length):
                point +=A[i+j]
                ans=max(ans,base+point)
print(ans)

Measured memory_bytes: 75816
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //int cnt = Integer.parseInt(scan.next());
        //int total = Integer.parseInt(scan.next());
        //long input = scan.nextLong();
        String first = scan.next();
        String second = scan.next();
        //for (int i = 1; i <=input; i++) {
        //}
        System.out.println(second+first);
    }
}


Measured memory_bytes: 21588
#include <cstdio>
#include <algorithm>
#include <utility>

using namespace std;

int N,M,H,K;

typedef int start_t;
typedef int end_t;

start_t src[1002];//下っ端と対応する上端
end_t target[1002];//上端と対応する
int scores[1002];
pair<int,int> yokobou[100002];
pair<start_t,start_t> swp[100002];

void init(){
    for(int i=1;i<=N;i++) scanf("%d",scores+i),src[i]=i;
    for(int i=1;i<=M;i++) scanf("%d%d",&yokobou[i].second,&yokobou[i].first);
}

int main(){
    while(scanf("%d%d%d%d",&N,&M,&H,&K)&&N&&M&&H&&K){
        init();
        sort(yokobou+1,yokobou+1+M);
        for(int i=1;i<=M;i++){
            end_t index=yokobou[i].second;
            swp[i].first=min(src[index],src[index+1]);
            swp[i].second=max(src[index],src[index+1]);
            swap(src[index],src[index+1]);
        }

        int sum=0;
        for(int i=1;i<=N;i++) {
            sum+=src[i]<=K?scores[i]:0;
            target[src[i]]=i;
        }

        int ans=sum;
        for(int i=1;i<=M;i++){
            if (swp[i].first<=K&&swp[i].second>K){
                int a=scores[target[swp[i].first]],b=scores[target[swp[i].second]];
                ans=min(ans,sum-a+b);
            }
        }

        printf("%d\n",ans);
    }

    return 0;
}


Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	deque<int> b;
	bool rev = false;
	for (int i = 0; i < n; ++i) {
		int a;
		scanf("%d", &a);
		if (!rev) b.push_back(a);
		else b.push_front(a);
		rev = !rev;
	}
	vector<int> ans(b.begin(), b.end());
	if (rev) reverse(ans.begin(), ans.end());
	for (int a : ans) printf("%d ", a);
}


Measured memory_bytes: 4864
#include <algorithm>
#include <bits/stdc++.h>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/cumsum.hpp
#ifndef CUMSUM_HPP
#define CUMSUM_HPP


/*
usage:

std::vector<std::vector<std::int_fast64_t>> a;
const std::vector<std::vector<std::int_fast64_t>> cumsum = tools::cumsum(a);
*/

namespace tools {
  template <typename T, typename OP>
  std::vector<T> cumsum(const std::vector<T>& source, const T& init, const OP& op) {
    std::vector<T> result({init});
    result.reserve(source.size() + 1);
    for (const T& x : source) {
      result.push_back(op(result.back(), x));
    }
    return result;
  }

  template <typename T>
  std::vector<T> cumsum(const std::vector<T>& source) {
    return cumsum<T>(source, static_cast<T>(0), std::plus<T>());
  }

  template <typename T, typename OP>
  std::vector<std::vector<T>> cumsum(const std::vector<std::vector<T>>& source, const T& init, const OP& op) {
    if (source.empty()) return std::vector<std::vector<T>>({std::vector<T>({init})});
    const std::size_t n1 = source.size();
    const std::size_t n2 = source.front().size();
    std::vector<std::vector<T>> result(n1 + 1, std::vector<T>(n2 + 1, init));
    for (std::size_t i = 0; i < n1; ++i) {
      for (std::size_t j = 0; j < n2; ++j) {
        result[i + 1][j + 1] = op(result[i + 1][j], source[i][j]);
      }
    }
    for (std::size_t j = 0; j < n2; ++j) {
      for (std::size_t i = 0; i < n1; ++i) {
        result[i + 1][j + 1] = op(result[i][j + 1], result[i + 1][j + 1]);
      }
    }
    return result;
  }

  template <typename T>
  std::vector<std::vector<T>> cumsum(const std::vector<std::vector<T>>& source) {
    return cumsum<T>(source, static_cast<T>(0), std::plus<T>());
  }
}

#endif

// main.cpp

int main() {
  u64 N;
  std::cin >> N;
  std::vector<u64> A;
  tools::read(A, N);

  const std::vector<u64> cumxor = tools::cumsum<u64>(A, 0, std::bit_xor<u64>());
  const std::vector<u64> cumsum = tools::cumsum(A);

  u64 answer = 0;
  u64 r = 0;
  for (u64 l = 0; l < N; ++l) {
    for (; r < N && (cumxor[r + 1] ^ cumxor[l]) == (cumsum[r + 1] - cumsum[l]); ++r);
    answer += r - l;
    if (l == r) ++r;
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 4992
#!/usr/bin/env python3

s = input()


def min_shrink(a):
    ind = [-1] + [i for i, x in enumerate(s) if x == a] + [len(s)]
    x = []
    for i in range(len(ind)-1):
        x.append(ind[i+1]-ind[i]-1)
    # print(a, max(x))
    return max(x)

ans = 1000
for a in "abcdefghijklmnopqrstuvwxyz":
    ans = min(ans, min_shrink(a))

print(ans)


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

const int MAX = 200000;
int main() {
	int N;
	static int A[MAX];
	cin >> N;
	for (int i = 0;i < N;i ++) cin >> A[i];
	if (A[0] != 0) { // 不可能操作
		cout << -1;
		return 0;
	}
	int64_t operate = 0;
	for (int i = 1;i < N;i ++) {
		if (A[i - 1] + 1 < A[i]) { // これも不可能な形
			cout << -1;
			return 0;
		} else if (A[i - 1] >= A[i]) {
			operate += A[i - 1];
		}
	}
	operate += A[N - 1];
	cout << operate;
	
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、X_iは単調増加であるから操作回数は上限が当然ある
まず、X_1に操作する手段は無いのでこれは0でない限り不可能
また、A_i + 1 < A_i+1 も不可能なので-1でおｋ
次に、まず簡単な操作を考える つまり、X_Nから順に操作すると、どう考えてもΣA_i回で操作が終わる
次に、そうでない時を考える
例えば0 1 2 3 3 2 3において、0 1 2 3 0 0 0と0 0 1 2 3 0 0と0 0 0 0 1 2 3の操作が存在することが分かる
言い換えると、A_i + 1 == A_i+1ならA_iの操作は考えず、そうでないならA_iの数が操作回数になる
解けた
*/

Measured memory_bytes: 1024
"""
https://atcoder.jp/contests/abc177/tasks/abc177_b
"""

def solve(s, t):
    def calc_diff_words(s0, s1):
        cnt = 0
        for w0, w1 in zip(s0, s1):
            if w0 != w1:
                cnt += 1
        return cnt

    def extract_sub(s, t, i):
        return s[i:i + len(t)]

    min = len(s)
    for i in range(len(s) - len(t) + 1):
        ss = extract_sub(s, t, i)
        dw = calc_diff_words(ss, t)
        if dw < min:
            min = dw

    return min

s = input()
t = input()
print(solve(s, t))

Measured memory_bytes: 9148
#include<bits/stdc++.h>
#define mod 1000000007
#define MOD(x) ((x)%mod)
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int n;
ll A,B;
int a[5005];
ll dp[2][5005];
int now,last;
int high[5005],low[5005];
int main()
{
	scanf("%d%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		for(int j=1;j<i;j++)
			if(a[j]>a[i]) high[i]++;
				else low[i]++;
	}
	for(int i=1;i<=n;i++)
	{
		last=now;
		now=!last;
		memset(dp[now],-1,sizeof dp[now]);
		dp[now][a[i]]=A*high[i]+B*low[i];
		for(int j=1;j<=n;j++)
		{
			if(dp[last][j]==-1) continue;
			if(a[i]>j) dp[now][j]=dp[last][j]+A;
			if(a[i]<j) dp[now][j]=dp[last][j]+B;
			if(a[i]>j) dp[now][a[i]]=min(dp[now][a[i]],dp[last][j]);
		}
	}
	ll ans=dp[now][1];
	for(int i=1;i<=n;i++)
		ans=min(ans,dp[now][i]);
	printf("%lld",ans);
	return 0;
}



Measured memory_bytes: 384
#include <stdio.h>

#define N 101

int main(){

  int A[N];
  int n,i,j,flag=1,tmp,cout=0;

  scanf("%d",&n);

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

 
   while(flag){
      flag=0;
      for(j=n-1;j>0;j--){
      if(A[j]<A[j-1]){
	tmp=A[j];
	A[j]=A[j-1];
	A[j-1]=tmp;
	flag=1;
	cout++;
      }
    }
  }
  
   for(i=0;i<n;i++){
     printf("%d",A[i]);
     if(i==n-1){ printf("\n");
     }else printf(" ");
     }

   printf("%d\n",cout);
   
   return 0;
  }

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

int main(){
  int x,y,n;

  while(1){
    cin >> x >> y;
    if(x==0 && y==0)
      break;

    if(x>y){
      n=x;
      x=y;
      y=n;
    }

    cout << x << " " << y << endl;
  }

  return 0;
}



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

using namespace std;

int main(){
  int a,b,c,d;
  double n;
  cin>>a>>b>>c>>d>>n;

  long long l2 = min({a*8,b*4,c*2,d});
  long long l1 = min({a*4,b*2,c});
  long long l05 = min(a*2,b);
  long long l025 = a;
  
  long long ans=0;
  
  while(n!=0){
    if(n>=2){
      ans += l2;
      n-=2;
    }else if(n>=1){
      ans += l1;
      n-=1;
    }else if(n>=0.5){
      ans += l05;
      n-=0.5;
    }else if(n>=0.25){
      ans += l025;
      n-=0.25;
    }
  }

  cout<<ans<<endl;
  

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int count=0;
	for(int i=0;i<n;i++)
		if(s[i]=='R')
			count++;
	cout << (count>n/2 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
from collections import Counter
import bisect
N = int(input())
A = list(map(int,input().split()))



cnt = Counter(A)
A.sort()
ans = 0
P = [0] * (10**6+1)
#print(cnt)
for a in A:
    if P[a]==0:
        for i in range(10**7):
            x = a*i
            if x>10**6:
                break
            P[x] = 1
        if cnt[a]==1:
            ans +=1

print (ans)




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

long long n, x;
long long memo[55][2] = {0};

long long solve(long long now, long long p);

int main() {
  cin >> n >> x;
  memo[0][0] = memo[0][1] = 1;
  for(int i = 1; i <= n; ++i) {
    memo[i][0] = memo[i - 1][0] * 2 + 1;
    memo[i][1] = memo[i - 1][1] * 2 + 3;
  }
  cout << solve(n, x) << endl;
  return 0;
}

long long solve(long long now, long long p) {
  if(now == 0) return p == 1;
  if(p < 2) return 0;
  if(memo[now][1] - 1 <= p) return memo[now][0];
  if(memo[now][1] / 2 + 1 == p) return memo[now - 1][0] + 1;
  if(memo[now][1] / 2 + 1 < p)
    return solve(now - 1, p - (memo[now][1] / 2) - 1) +
           memo[now - 1][0] + 1;
  else
    return solve(now - 1, p - 1);
}


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

using namespace std;

typedef long long ll;
const int Maxn = 1e9 + 10;
const int N = 1e5 + 10;
const int INF=(0x7fffffff)/2;
const int MOD = 1000000007;
const int MaxN = 1e5;
int a[N], b[N],c[N];
int main(){
	int n;
	scanf("%d", &n);
	memset(b, 0, sizeof(b));
	memset(a, 0, sizeof(a));
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++){
		c[i] = abs(a[i] - a[i - 1]);
	}
	c[n + 1] = abs(a[n] - 0);
	ll sum = 0;
	for(int i = 1; i <= n + 1; i++)
		sum += c[i];
	for(int i = 1; i <= n; i++){
		b[i] = sum - c[i] - c[i + 1];
	}
	for(int i = 1; i <= n; i++)
		b[i] += abs(a[i + 1] - a[i - 1]);
	for(int i = 1; i <= n ; i++)
		printf("%d\n", b[i]);
}


Measured memory_bytes: 2432
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader((new InputStreamReader(System.in)));
        while(true){
            String[] line = reader.readLine().split(" ");
            int x = Integer.parseInt(line[0]);
            float y = (float)Integer.parseInt(line[1]);
            int s = Integer.parseInt(line[2]);
            if(x==0 && y==0 && s==0){
                break;
            }
            int max = 0;
            for(int i=1; i<s*100/(100+x)+1; i++){
                int _i = (int)Math.floor(i*(100+x)/100);
                int j = s - _i;
                while((int)Math.floor(i*(100.0+x)/100)+(int)Math.floor(j*(100.0+x)/100) > s) {
                    j--;
                }
                if((int)Math.floor(i*(100.0+x)/100)+(int)Math.floor(j*(100.0+x)/100) != s) continue;
                int tmp = (int)(Math.floor(i*(100f+y)/100)+Math.floor(j*(100f+y)/100));
                if(max < tmp) max = tmp;
            }
            System.out.println(max);
        }
    }
}

Measured memory_bytes: 19656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll now[26],ans[26];
int main() {
	string s;
	cin>>s;
	for(ll i=0;i<26;i++){
		now[i]=-1;
	}
	for(ll i=0;i<s.size();i++){
		ll no=s[i]-'a';
		ans[no]=max(ans[no],i-now[no]-1);
		now[no]=i;
	}
	ll ans2=inf;
	for(ll i=0;i<26;i++){
		ll no=s.size()-1-now[i];
		ans[i]=max(ans[i],no);
		ans2=min(ans2,ans[i]);
	}
	cout <<ans2;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const N = numList0[0];
    const A = numList0[1];
    const B = numList0[2];
    console.log(Math.min(N * A, B));
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22080
#include <stdio.h>

int main(void)
{
	int n, m;
	int flag[1001], dice[1001];
	int p, c;
	int i;
	
	while (scanf("%d %d", &n, &m), n && m){
		p = 1;
		c = 0;
	
		for (i = 0; i < n; i++){
			scanf("%d", &flag[i]);
		}
		for (i = 0; i < m; i++){
			scanf("%d", &dice[i]);
		}
		for (i = 0; p < n; i++){
			p += dice[i];
			p += flag[p - 1];
			c++;
		}
		printf("%d\n", c);
	}
	
	return (0);
}

Measured memory_bytes: 604
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long int ll;
ll n;

int main()
{
    cin >> n;
    string s = "";
    while (n != 0)
    {
        n--;
        s += string(1, 'a' + n % 26);
        n /= 26;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}

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

int main() {
	int a, b, r;
	while(1){
		int count=1;
		cin >> a >> b;
		if(a == 0 && b == 0) break;
		if(a<b){
			int tmp = a;
			a = b;
			b = tmp;
		}
		r = a%b;
		while(r != 0){
			a = b;
			b = r;
			r = a%b;
			count++;
		}
		cout << b << ' ' << count << endl;
	}
	return 0;
}


Measured memory_bytes: 3012
#include <cstdio>


int main()
{
    int N; 
    scanf ("%d", &N);
    
    if (N == 1)
    {
        printf ("Hello World");
    }
    else
    {
        int A, B; 
        scanf ("%d %d", &A, &B);
        printf ("%d", A+B);
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
using namespace std;

int main(){
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  int d = max(a,b);
  cout << max(d,c)*pow(2,n) + a + b + c - max(d,c) << endl;
}
  

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31))

ll a[200010];
ll left[200010],right[200010];

int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%lld",a+i);
	rep(i,0,n){
		ll temp=i-1;
		while(temp!=-1&&a[temp]>a[i])temp=left[temp];
		left[i]=temp;
	}
	for(int i=n-1;i>=0;i--){
		ll temp=i+1;
		while(temp!=n&&a[temp]>a[i])temp=right[temp];
		right[i]=temp;
	}
	ll ans=0;
	rep(i,0,n)ans+=a[i]*(i-left[i])*(right[i]-i);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


typedef long long ll;

using namespace std;

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

	ll res = 0, ret_val = -1;
	
	int nums[n];
	
	for (int i = 0; i < n; i++) cin >> nums[i];

	for (int j = 1; j <= 100; j++) {
		res = 0;
		for (int i = 0; i < n; i++){
			res += (((nums[i] - j)) * ((nums[i] - j)));
		}

		if (ret_val == -1){
			ret_val = res;
		} else {
			if (res < ret_val){
				ret_val = res;
			}
		}
	}

	cout << ret_val << endl;

	return 0; 
} 


Measured memory_bytes: 256
open System

let calc (a: int) (b: int): int =
    if a <= 5 then
        0
    else if a <= 12 then
        b / 2
    else
        b

[<EntryPoint>]
let main _ =
    let input = Console.ReadLine()
    let [| a; b |] = input.Split(' ') |> Array.map Int32.Parse
    printfn "%d" <| calc a b
    0


Measured memory_bytes: 11984
#include <cstdio>
using namespace std;
 
int a[4];
int c[8];
int k;
 
int calc(){
    int op = c[k++];
    int ret = 0;
    if(op >= 0){
        ret = op;
    }
    else if(op >= -3){
        int x = calc();
        int y = calc();
        if(op == -1){
            ret = x + y;
        }
        else if(op == -2){
            ret = x - y;
        }
        else{
            ret = x * y;
        }
    }
    else{
        throw 0;
    }
    return ret;
}
 
void print(){
    int op = c[k++];
    if(op >= 0){
        printf("%d", op);
    }
    else{
        char ch;
        if(op == -1){ ch = '+'; }
        else if(op == -2){ ch = '-'; }
        else{ ch = '*'; }
 
        putchar('(');
        print();
        printf(" %c ", ch);
        print();
        putchar(')');
    }
}

const int brnum = 100000;
 
void solve(int i, int S, int oprem, int numrem){
    if(i == 6){
        for(int j = 0; j < 4; ++j){
            if(S >> j & 1){
                c[6] = a[j];
            }
        }
        try{
            k = 0;
            if(calc() == 10 && k == 7){
                k = 0;
for(int j=0;j<brnum;++j)putchar('(');
                print();
for(int j=0;j<=brnum;++j)putchar(')');
                puts("");
                throw "";
            }
        }catch(int){}
        return;
    }
 
    if(oprem > 0){
        for(int op = -1; op >= -3; --op){
            c[i] = op;
            solve(i + 1, S, oprem - 1, numrem + 1);
        }
    }
 
    if(numrem > 0){
        for(int j = 0; j < 4; ++j){
            if(S >> j & 1){
                c[i] = a[j];
                solve(i + 1, S ^ 1 << j, oprem, numrem - 1);
            }
        }
    }
}
 
int main(){
    while(1){
        for(int i = 0; i < 8; ++i){
            c[i] = -9;
        }
        for(int i = 0; i < 4; ++i){
            scanf("%d", &a[i]);
        }
        if(a[0] == 0){ break; }
        try{
            solve(0, 15, 3, 0);
            puts("0");
        }catch(...){}
    }
}

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

int main(){
   int n,k;
   cin >> n >> k;
   vector<int> s(n);
   for (int i = 0; i < n; i++){
       cin >> s.at(i);
   }
   sort(s.begin(), s.end());
   int ans = 0;

   for (int i = 0; i < k; i++){
       ans += s.at(i);
   }
   cout << ans << endl;

   return 0;
   
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
//#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repm(i, a, n) for (int i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vs vector<string>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define vd vector<double>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define reverse_v(a) reverse(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    (c) ? (cout << "Yes" << endl) : (cout << "No" << endl);
}

void Print(bool c)
{
    (c) ? (cout << "YES" << endl) : (cout << "NO" << endl);
}

//最小公倍数
template <typename T>
T gcd(T a, T b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

//最大公約数
template <typename T>
T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}
//セカンドキー->ファーストキーの順ソート
bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

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

int main(void)
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    // // map<char, int> mp;
    // // rep(i, 0, n) mp[s[i]]++;
    // ll ans = mp['R'] * mp['G'] * mp['B'];
    ll a = 0, b = 0, c = 0;
    rep(i, 0, n)
    {
        if (s[i] == 'R')
            a++;
        if (s[i] == 'G')
            b++;
        if (s[i] == 'B')
            c++;
    }
    ll ans = a * b * c;
    rep(i, 0, n)
    {
        rep(j, i + 1, n)
        {
            int k = j + (j - i);
            if (k >= n)
                break;
            if (s[i] != s[j] && s[k] != s[j] && s[i] != s[k])
                ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		int k = sc.nextInt();
		// 出力
		System.out.println( k <= 1 ? 0 : n-k);
	}
}

Measured memory_bytes: 23508
#define _CRT_SECURE_NO_WARNINGS
#define TASK "C-large"
#pragma comment(linker, "/STACK:1710886400")
#include <stdio.h>
#include <iostream>
#include <iomanip> 
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <assert.h>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <complex>
using namespace std;

const int MOD = 1000000007;
const int INF = 1000000007;
const long double EPS = 1e-6;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
mt19937_64 rnd(1);

double workTime() {
	return double(clock()) / CLOCKS_PER_SEC;
}

void my_return(int code) {
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << workTime() << endl;
#endif
	exit(code);
}

int n, m, a[200010];
int cnt[200010], cov[200010], ans;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);*/
#endif

	scanf("%d %d", &n, &m);
	ans = n;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		++cnt[a[i]];
		int foo = a[i] - cnt[a[i]];
		if (foo >= 0) {
			if (cov[foo] == 0) {
				--ans;
			}
			++cov[foo];
		}
	}
	for (int i = 1; i <= m; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		int foo = a[x] - cnt[a[x]];
		if (foo >= 0) {
			--cov[foo];
			if (cov[foo] == 0) {
				++ans;
			}
		}
		--cnt[a[x]];
		a[x] = y;
		++cnt[a[x]];
		int bar = a[x] - cnt[a[x]];
		if (bar >= 0) {
			if (cov[bar] == 0) {
				--ans;
			}
			++cov[bar];
		}
		printf("%d\n", ans);
	}

	my_return(0);
}

Measured memory_bytes: 3840
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll Q,H,S,D,N; cin>>Q>>H>>S>>D>>N;
  vector<PP> yen(4);
  N *= 100;
  yen[0] = PP(Q * 8, P(Q, 25));
  yen[1] = PP(H * 4, P(H, 50));
  yen[2] = PP(S * 2, P(S, 100));
  yen[3] = PP(D * 1, P(D, 200));
  sort(yen.begin(), yen.end());
  ll ans = 0;
  FOR(i,0,4) {
    if(N <= 0) break;
    ans += (N / yen[i].second.second) * yen[i].second.first;
    N -= (N / yen[i].second.second) * yen[i].second.second;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(n):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1

print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)


Measured memory_bytes: 9200
#include <stdio.h>
#define lint long long

int N = 301 ;
double dp[301][301][301] ;
int n ;

double solve(int cnt1, int cnt2, int cnt3)
{
    int total = cnt1 + cnt2 + cnt3 ;
    if(total <= 0) return 0.0 ;
    double ans = dp[cnt1][cnt2][cnt3] ;
    if(ans != -1.0) return ans ;
    double EV = (double)n/(total);
    double child = 0 ;
    int moves = 0 ;
    if(cnt1 > 0)
    {
        moves += cnt1 ;
        child += cnt1 * solve(cnt1 - 1, cnt2, cnt3);
    }
    if(cnt2 > 0)
    {
        moves += cnt2 ;
        child += cnt2 * solve(cnt1 + 1, cnt2 - 1, cnt3);
    }
    if(cnt3 > 0)
    {
        moves += cnt3 ;
        child += cnt3 * solve(cnt1, cnt2 + 1, cnt3 - 1);
    }
    ans = EV + (child)/(double) moves ;
    return dp[cnt1][cnt2][cnt3] = ans ;
}

int main()
{
    int x, i = 0, j = 0, k = 0 ;
    for(i = 0; i < N; i++)
        for(j = 0; j < N; j++)
            for(k = 0; k < N; k++)
                dp[i][j][k] = -1 ;

    scanf("%d", &n); int cnt1 = 0, cnt2 = 0, cnt3 = 0 ;
    for(i = 0; i < n; i++)
    {
        scanf("%d", &x);
        if(x == 1) cnt1++ ;
        else if(x == 2) cnt2++ ;
        else cnt3++ ;
    }
    printf("%0.9f", solve(cnt1, cnt2, cnt3)) ;
}


Measured memory_bytes: 213248
#pragma warning (disable:4996)
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#define inf 0X7f7f7f7f
#define MS_I(x) memset(x,-inf,sizeof(x))
#define MS(x) memset(x,0,sizeof(x))
#define MSI(x) memset(x,inf,sizeof(x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int h[1005];

int main()
{
	int n;
	double t, a;
	int flag = 0;
	scanf("%d", &n);
	scanf("%lf %lf", &t, &a);
	double temp, mich = inf;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &h[i]);
		temp = t - 0.006 * h[i];
		if (mich > fabs(a - temp))
		{
			flag = i + 1;
			mich = fabs(a - temp);
		}
	}
	cout << flag;
	return 0;
}

Measured memory_bytes: 256