akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

#define M 1000999 /* your task*/
#define NIL (-1)
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
int getKey(char str[]){
  int sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) {
  return key % M;
}
int h2(int key){
  return 1 + key % (M-1);
}

int find(char str[]){

  int i = 0,num;

  while(1){
    num = (h1(getKey(str)) + i * h2(getKey(str))) % M;

    if(H[num][0] == '\0') return 0;    

    if(strcmp(H[num],str) == 0){
      return 1;
    }
  i++;

  }

}

void insert(char str[]){

  int i=0,num;

  while(1){
    num = (h1(getKey(str)) + i *h2(getKey(str))) % M;
    
    if(H[num][0] == '\0'){  
      strcpy(H[num],str);
      return;
    } 
    i++;
  }
  
}


int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 13000
import java.util.Scanner;
  
public class Main {
    public static void main(String[] args){
        int a,b;
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
        a = scanner.nextInt();
        b = scanner.nextInt();
        System.out.println((String.valueOf(a+b).length()));
        }
        scanner.close();
    }
}

Measured memory_bytes: 25980
while True:
    n= int(input())
    if n== 0: break
    ans= 0
    for _ in range(n):
        x, y, h, w= map(int, input().split())
        t= x+y+h
        if t<=60:
            s= "A" if w<=2 else("B" if w<=5 else("C" if w<=10 else("D" if w<= 15 else("E" if w<=20 else("F" if w<=25 else "G")))))
        elif t<=80:
            s= "B" if w<=5 else("C" if w<=10 else("D" if w<=15 else("E" if w<= 20 else("F" if w<=25 else "G"))))
        elif t<=100:
            s= "C" if w<=10 else("D" if w<=15 else("E" if w<=20 else("F" if w<= 25 else "G")))
        elif t<=120:
            s= "D" if w<=15 else("E" if w<=20 else("F" if w<=25 else "G"))
        elif t<=140:
            s= "E" if w<=20 else("F" if w<=25 else "G")
        elif t<=160 and w<=25:
            s= "F"
        else:
            s= "G"
        v= 600 if s=="A" else(800 if s=="B" else(1000 if s=="C" else(1200 if s=="D" else(1400 if s=="E" else(1600 if s=="F" else 0)))))
        ans+= v
    print(ans)

Measured memory_bytes: 7628
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG



int main() {
  string S;
  cin >> S;
  //vector<ll> a(N);
  //vector<vector<int>> data(3, vector<int>(4));

  ll count_A = 0;
  ll count_B = 0;

  for(ll i=0; i<3; i++){
    if(S.at(i) != 'A'){
      count_A++;
    }    
    else count_B++;

  }

  
  if(count_A * count_B == 0){
    cout << "No" << endl;
    return 0;
  }else cout << "Yes" << endl;
  return 0;
}


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

int main(){
  int a,b,c,k;
  cin>>a>>b>>k;
  for(int i=100;i>0;i--){
    if(a%i==0&&b%i==0){
      c=i;
      k--;
      if(k==0) break;
    }
  }
  cout<<c<<endl;
}


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

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
  ll res=1;
  while(b)
  {
    if(b&1LL)
      res=(res*a)%c;
    a=(a*a)%c;
    b>>=1;
  }
  return res;
}

int main()
{
  FASTIO;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll n,x,t;
   cin>>n>>x>>t;

   ll temp= (n+x-1)/x;

   cout<<temp*t<<"\n";

  
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, k;
  cin >> n >> k;
  if (n % k)
    cout << 1 << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int x = 1;
		for (int i = 2; i < n; i++) {
			if (i*i > n)
				break;
			x = i * i;
		}

		System.out.println(x);
	}
}

Measured memory_bytes: 21844
// 最後の1問だけwrong answerになって終了。。

#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

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

    int N;
    int M;

    cin >> N >> M;

    vector<string> ar;
    vector<string> br;

    string s;
    for(int i = 0; i < N; i++){
        cin >> s;
        ar.push_back(s);
    }
    for(int i = 0; i < M; i++){
        cin >> s;
        br.push_back(s);
    }

    bool found = true;
    for(int i_a = 0; i_a < N; i_a++){
        found = true;
        for(int i_b = 0; i_b < M; i_b++){
            int tmp_i_a = i_a;
            size_t bt;
            size_t last_bt = 100;
            bt = ar[tmp_i_a].find(br[i_b]);
            if(bt == string::npos){
                found = false;
                break;
            }else{
                if(last_bt != 100){
                    if(bt != last_bt){
                        found = false;
                        break;
                    }
                }
                ++tmp_i_a;
                continue;
            }
        }
    }

    found ? cout << "Yes" << endl : cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,num,max=0,sum=0;
  vector<int> l;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> num;
    max=(max>num)?max:num;
    sum+=num;
    l.push_back(n);
  }
 if(max<sum-max) cout<<"Yes"<<endl;
 else cout << "No"<<endl;
}



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

int a, b, c, d ;

int main(){
	#define NAME ""
	//freopen( NAME".inp" , "r" , stdin ) ; freopen( NAME".out" , "w" , stdout ) ;

	ios_base :: sync_with_stdio(false) ;

	cin >> a >> b >> c >> d ;

	if(abs(c - a) <= d) return cout << "Yes", 0 ;

	if(abs(b - a) <= d && abs(c - b) <= d) return cout << "Yes", 0 ;

	cout << "No" ;

	return 0 ;
}

Measured memory_bytes: 256
function main(input) {
   input = input.trim();
  const a = input.split(" ").map(Number);
  var an = Math.floor(a[0]/2);
  console.log(a[0]%2==0?an*an:an*(an+1));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

// header area

int main(){
    int A, B, C, K; cin >> A >> B >> C >> K;

    // 
    int sum = 0;
    if(K>A){
        sum += A;
        // A+Bを超えてCに入る場合
        if(K>A+B){
            sum  += -1 * (K-(A+B));
            cout << sum << endl;
        }else{
            cout << sum << endl;
        }
    }else{
        cout << K << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

// B

int penalty[55], accept[55];
int wrong[55][55];

int main(){
    int T,P,R,i;
    int tID, pID, time;
    string msg;
    

    while( cin >> T >> P >> R, T|P|R ){

        memset(accept, 0, sizeof(accept));
        memset(wrong, 0, sizeof(wrong));
        memset(penalty, 0, sizeof(penalty));

        for(i=0; i<R; i++){
            cin >> tID >> pID >> time >> msg;
            if( wrong[tID][pID] >= 0 ){
                if( msg == "CORRECT" ){
                    penalty[tID] += wrong[tID][pID] * 1200 + time;
                    wrong[tID][pID] = -1;
                    accept[tID]++;
                }
                else{
                    wrong[tID][pID]++;
                }
            }
        }

        vector<pair<int, pair<int,int> > > v;
        for(i=1; i<=T; i++){
            v.push_back(make_pair(-accept[i], make_pair(penalty[i], i)));
        }

        sort(v.begin(), v.end());
        for(i=0; i<v.size(); i++){
            cout << v[i].second.second << " " << -v[i].first << " " << v[i].second.first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 940
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;




int main(){

    string S;
    cin >> S;

    string abc = "abc";
    for(auto c : abc){
        if(S.find(c) == string::npos) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
while True:
    H,W = map(int,input().split())
    
    if H == W == 0:
        break
    
    for i in range(H):
        if i == 0 or i == H-1:
            print('#'*W)
        else:
            print('#','.'*(W-2),'#',sep='')
    print('')


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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define loop(i, a, b) for(int i = a; i <= b; i++)
#define pool(i, a, b) for(int i = a; i > b; i--)
#define pb push_back

const int maxn = 1e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

const int nax = 405;
ll dp[nax][nax];

ll sum(vector<ll> prefixsum, int L, int R)
{
	if(L > 0)
	{
		return  prefixsum[R] - prefixsum[L - 1];;
	}
	return prefixsum[R];

}

int main()
{
	int n;
	ll p_sum = 0;
	fastIO;
	scanf("%d", &n);
	vector<int> a(n);
	vector<ll> prefixsum;
	for(int& x: a)
	{
		scanf("%d", &x);
		p_sum += x;
		prefixsum.pb(p_sum);
	}
	// loop(i, 0, n)
	// 	cout << prefixsum[i] << " ";
	// 	cout << "\n";
	// auto sum = [&](int L, int R)
	// {
	// 	ll s = 0;
	// 	loop(i, L, R)
	// 		s += a[i];
	// 	return s;
	// };

	// dp[i][j] represents cost of adding i -> j to a new element
	for(int L = n - 1; L >= 0; L--)
	{
		for(int R = L; R < n; R++)
		{
			if(L == R)
				dp[L][R] = 0;
			ll s = sum(prefixsum,L, R);

			for(int i  = L; i <= R - 1; i++)
			{
				if(!dp[L][R])
				{
					dp[L][R] = dp[L][i] + dp[i + 1][R] + s;
				}
				dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + s);
			}
		}
	}


	// loop(i, 0, n){
	// 	loop(j, 0, n)
	// 		cout << dp[i][j] << " ";
	// 	cout << "\n";
	// }
	cout << dp[0][n - 1];

	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin >> a;
    vector<int> A(a);
    int count = 0;
    for(int i = 0;i<a;i++)
        cin >> A.at(i);
    for(int i = 1;i<a-1;i++){
        if(A.at(i-1) < A.at(i) && A.at(i) < A.at(i + 1))
            count++;
        if(A.at(i-1) > A.at(i) && A.at(i) > A.at(i + 1))
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
color = {
    "000000": "black",
    "0000ff": "blue",
    "00ff00": "lime",
    "00ffff": "aqua",
    "ff0000": "red",
    "ff00ff": "fuchsia",
    "ffff00": "yellow",
    "ffffff": "white"
}
 
while True:
    n = input()
    if n == '0': break
    code = ''
    for f, s in zip(n[1::2], n[2::2]):
        if int(f+s, 16) <= 127:
            code += '00'
        else:
            code += 'ff'
    print(color[code])



Measured memory_bytes: 5564
n = int(input())
c,s,f = [0]*(n-1),[0]*(n-1),[0]*(n-1)
for i in range(n-1): c[i],s[i],f[i] = (int(i2) for i2 in input().split())
for j in range(n):
	answer = 0
	for k in range(j,n-1):
		if answer<s[k]: answer = s[k]
		elif answer%f[k]: answer += f[k]-(answer%f[k])
		answer += c[k]
	print(answer)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll A, B;
    cin >> A >> B;
    if(B == 1) cout << 0 << endl;
    else cout << (B<=A ? 1 :  (B-A-1)/(A-1) + 2) << endl;
    return 0;
}


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

#define MAX_N (100000L)
#define MAX_M (100000L)

long nxtss[MAX_N][26] = {};

long mod(long n, long k) { return n % k >= 0 ? n % k : n % k + k; }

int main(int argc, char *argv[]) {
  // read inputs
  char s[MAX_N + 1], t[MAX_M + 1];
  scanf("%s", s);
  fgets(t, MAX_M + 1, stdin);
  scanf("%s", t);
  const long N = strlen(s), M = strlen(t);
  // printf("%s\n%s\n", s, t);

  // calculate the next occurence of each character
  for (long j = 0; j < 26; j++) {
    nxtss[N - 1][j] = -1;
  }
  for (long i = 0; i < N; i++) {
    const long j = s[i] - 'a';
    if (nxtss[N - 1][j] < 0) {
      nxtss[N - 1][j] = i;
    }
  }
  for (long i = N - 2; i >= 0; i--) {
    for (long j = 0; j < 26; j++) {
      if (s[i + 1] == j + 'a') {
        nxtss[i][j] = i + 1;
      } else {
        nxtss[i][j] = nxtss[i + 1][j];
      }
    }
  }
  // for (long j = 0; j < 26; j++) {
  //   printf("%2c ", j + 'a');
  // }
  // printf("\n");
  // for (long i = 0; i < N; i++) {
  //   for (long j = 0; j < 26; j++) {
  //     printf("%2ld ", nxtss[i][j]);
  //   }
  //   printf("\n");
  // }

  // possible if all characters of t appear in s
  long is_possible = 1;
  for (long i = 0; i < M; i++) {
    if (nxtss[N - 1][t[i] - 'a'] < 0) {
      is_possible = 0;
      break;
    }
  }

  if (!is_possible) {
    printf("-1\n");
    return 0;
  }

  // solve
  long ans = 0, cur = N - 1;
  for (long i = 0; i < M; i++) {
    const long nxt = nxtss[cur][t[i] - 'a'];
    // printf("c = %c, cur = %ld, nxt = %ld\n", t[i], cur, nxt);
    if (nxt == cur) {
      ans += N;
    } else if (nxt > cur) {
      ans += nxt - cur;
    } else {
      ans += nxt - cur + N;
    }
    cur = nxt;
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 20608
N=int(input())
cnt=0
max=10**6
but=0
id=0
for i in range(1,max,1):
    cnt=cnt+i
    if cnt>=N:
        buf=cnt-N
        break
id=i
seq=[i+1 for i in range(id)]
for i in range(len(seq)):
    if seq[i]!=buf:
        print(seq[i])

Measured memory_bytes: 42584
#include<stdio.h>
int a,b;
int main()
{
  scanf("%d %d",&a,&b);
  if(a%3==0)
    {
      printf("Possible\n");
      return 0;
    }
  if(b%3==0)
    {
      printf("Possible\n");
      return 0;
    }
  if((a+b)%3==0)
    {
      printf("Possible\n");
      return 0;
    }
  printf("Impossible\n");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()

int main() {
    int ans = 0;
    rep(i,3) {
        int c;
        scanf("%d", &c);
        ans += c;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3204
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

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

	vector<ll> ans(N, 0);
	for(int i=0; i<N; i++){
		if(i%2 == 0) ans[0] += A[i];
		else 	ans[0] -= A[i];
	}
	ans[0] /= 2;

	for(int i=1; i<N; i++){
		ans[i] = A[i-1] - ans[i-1];
	}

	for(int i=0; i<N; i++){
		cout << 2*ans[i] << " ";
	} cout << endl;

}



Measured memory_bytes: 4812
#include <iostream>
#include <climits>
#include <algorithm>
#define INF (LLONG_MAX>>5)
using namespace std;

int main(){
  int v, e; cin >> v >> e;

  //配列でグラフを表現。配列の初期化
  long long int graph[v][v];
  for(int i=0; i<v; i++){
    for(int j=0; j<v; j++){
      if(i==j) graph[i][j]=0;
      else graph[i][j]=INF;
    }
  }

  int from, to; long long int weight;
  for(int i=0; i<e; i++){
    cin >> from >> to >> weight;
    graph[from][to]=weight;
  }

  for(int k=0; k<v; k++){
    for(int i=0; i<v; i++){
      for(int j=0; j<v; j++){
        graph[i][j] = min(graph[i][k]+graph[k][j], graph[i][j]);
      }
    }
  }

  bool flag=false;
  for(int i=0; i<v; i++) if(graph[i][i]<0) flag=true;

  if(flag) cout << "NEGATIVE CYCLE" << endl;
  if(!flag){
    for(int i=0; i<v; i++){
      for(int j=0; j<v; j++){
        if(graph[i][j]>=(INF>>5)) cout << "INF";
        else cout << graph[i][j];
        if(j!=v-1) cout << " ";
      }
      cout << endl;
    }
  }


  return 0;
}



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

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int total = n * 800;
            int temp = n / 15;
            total = total - (200 * temp);
            System.out.println(total);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 22996
N = int(input())
S, T = input().split()
S_l = [i for i in S]
T_l = [i for i in T]
ans = list()
for i in range(1, 2*N+1):
    if i % 2 == 1:
        a = S[i//2]
    else:
        a = T[i//2-1]
    ans.append(a)
print(''.join(ans))

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


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

  int counterX = 0;
  int counterY = count(S.begin()+1, S.end(), 'E');
  int ans = counterX + counterY;

  for(int i = 1; i < N; i++){
    if(S[i-1] == 'W') {
      counterX++;
    }
    if(S[i] == 'E'){
      counterY--;
    }
    if(ans > counterX+counterY) ans = counterX + counterY;
  }

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

Measured memory_bytes: 900
#include <stdio.h>

int main(void)
{
	int iPencilNum;			// 必要な鉛筆の本数
	int iX, iY;				// セットX、セットYの本数
	int iValueX, iValueY;	// セットX、セットYの価格
	int iCostX, iCostY;		// セットX、セットYを選択した場合の金額
	int iNumX, iNumY;		// セットX、セットYを選択した場合の本数
	int iAns;
	
	// 入力：必要な鉛筆の本数
	scanf("%d", &iPencilNum);
	
	// 入力：セットX
	scanf("%d %d", &iX, &iValueX);
	
	// 入力：セットY
	scanf("%d %d", &iY, &iValueY);
	
	
	// 金額を計算
	iCostX = 0;
	iCostY = 0;
	iNumX = 0;
	iNumY = 0;
	while(iNumX < iPencilNum )
	{
		iCostX += iValueX;
		iNumX += iX;
	}
	while(iNumY < iPencilNum )
	{
		iCostY += iValueY;
		iNumY += iY;
	}
	
	
	// 出力：金額
	if(iCostX < iCostY)
	{
		printf("%d\n", iCostX);
	}
	else
	{
		printf("%d\n", iCostY);
	}
	
	return(0);
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k,n;
    cin>>k>>n;
    vector<ll>ara(n+1);
    vector<ll>cnt(k,0);
    ll dis=LONG_MAX;

    for(ll i=1;i<=n;i++)
    {
        cin>>ara[i];
        cnt[ara[i]]++;
    }

    ll first_data,last_data;
    ll i;

    for(i=0;i<k;i++)
    {
        if(cnt[i]!=0){first_data=last_data=i;break;}
    }

    for(i=i+1;i<k;i++)
    {
        if(cnt[i]!=0)
        {
            if(first_data-i<0)dis=min(last_data-i+k,dis);
            else dis=min(dis,last_data-i);
            last_data=i;
        }
    }

    //cout<<last_data<<" "<<first_data;

    dis=min(dis,last_data-first_data);

    cout<<dis<<endl;


    return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};

using P = Point<long long>;

template<class P>
bool segmentIntersectionQ(P s1, P e1, P s2, P e2) {
	if (e1 == s1) {
		if (e2 == s2) return e1 == e2;
		swap(s1,s2); swap(e1,e2);
	}
	P v1 = e1-s1, v2 = e2-s2, d = s2-s1;
	auto a = v1.cross(v2), a1 = d.cross(v1), a2 = d.cross(v2);
	if (a == 0) { // parallel
		auto b1 = s1.dot(v1), c1 = e1.dot(v1),
		     b2 = s2.dot(v1), c2 = e2.dot(v1);
		return !a1 && max(b1,min(b2,c2)) <= min(c1,max(b2,c2));
	}
	if (a < 0) { a = -a; a1 = -a1; a2 = -a2; }
	return (0 <= a1 && a1 <= a && 0 <= a2 && a2 <= a);
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		P p0, p1;
		cin >> p0.x >> p0.y >> p1.x >> p1.y;
		P p2, p3;
		cin >> p2.x >> p2.y >> p3.x >> p3.y;
		if(segmentIntersectionQ(p0, p1, p2, p3)){
			cout << 1 << '\n';
		} else {
			cout << 0 << '\n';
		}
	}
}


Measured memory_bytes: 3176
#include <iostream>
#define ll long long int
#define N 55
using namespace std;
char s[N][N];
int dir[4][2]={0,1,1,0,0,-1,-1,0};
int a,b;

bool search(int x,int y){
    for(int i=0;i<4;i++){
        int xx = x+dir[i][0];
        int yy = y+dir[i][1];
        if(xx>=0&&xx<a&&y>=0&&y<b){
            if(s[xx][yy]=='#')
                return true;
        }
    }
    return false;
}
int main(){
    cin>>a>>b;
    for(int i=0;i<a;i++)
        for(int j=0;j<b;j++)
            cin>>s[i][j];
    for(int i=0;i<a;i++){
        for(int j=0;j<b;j++){
            if(s[i][j]=='#'){
                bool prime = search(i,j);
                if(!prime){
                    return 0*printf("No\n");
                }
            }
        }
    }
    printf("Yes\n");
    return 0;
}


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

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

// 159 - c
int main(void) {
    int l;
    cin >> l;

    double tmp = l / 3.0;
    double x = tmp;
    double y = tmp;
    double z = l - 2 * tmp;

    double vlm = x * y * z;

    // cout << tmp << endl;
    printf("%lf", vlm);

    return 0;
}

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

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  int n; cin >> n;
  while(n --> 0){
    string ans;
    int apos = 0;
    int pos = 0;
    string str;
    cin >> str;
    ans = str[0];
    pos+=2;
    while(pos < str.size()){
      //printf("str[pos]=%c\n",str[pos]);
      if(str[pos] == '-'){
        apos--;
      }else{
        apos++;
      }
      pos++;
      //printf("%s (apos = %d)\n",ans.c_str(),apos);
      if(apos == -1){
        apos = 0;
        ans = str[pos] + ans;
      }else if(apos == ans.size()){
        ans = ans + str[pos];
      }else{
      }
      pos += 2;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    long long n;
    cin>>n;
    vector<long long>v(n);
    for( int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    auto it=unique(v.begin(),v.end());
    long long ans=0;
    for(auto it2=v.begin();it2!=it;it2++,ans++)
    {
        if(ans!=0)cout<<" ";
        cout<<*it2;
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define  ff first
#define  ss second
#define sz(a) (ll)a.size()
#define lli long long int
#define pb push_back
#define pf push_front
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
#define M 1000000007
#define pi 3.1415926535

int main(){

fast;

ll n;
cin>>n;

ll a[n];
ll sum=0;
vector<ll> v(100001);
for(int i=0;i<n;i++){
	cin>>a[i];
	sum+=a[i];
	v[a[i]]++;
}
ll q;
cin>>q;
while(q--){
	ll b,c;
	cin>>b>>c;
	sum+=(c-b)*v[b];
	v[c]+=v[b];
	v[b]=0;
	cout<<sum<<"\n";
}

return 0;
}


Measured memory_bytes: 4744
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 10000;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
 
void solve()
{
    ll n;
    string s;
    cin >> n >> s;
    ll num = 0;
    num = (s[0]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0');
    n *= num;
    n /= 100;
    cout<<n;
}

int main()
{
     FAST;
     ll t = 1;
   //  cin >> t;
     while(t--)
     {
          solve();
     }
}

Measured memory_bytes: 3648
#include <stdio.h>

int main()
{
  int N, K, P;
  
  scanf("%d %d", &N, &K);
  
  P=0;
  
  while(N != 0){
  	N = N/K;
  	++P;
  }
  
  printf("%d\n", P);
  
 return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();
		int Ma = GetInt();
		int Mb = GetInt();
		int[] a = new int[N+1];
		int[] b = new int[N+1];
		int[] c = new int[N+1];
		int sumA = 0;
		int sumB = 0;
		for(int i = 1; i <= N; i++)
		{
			a[i] = GetInt();
			sumA += a[i];
			b[i] = GetInt();
			sumB += b[i];
			c[i] = GetInt();
		}

		int[,,] dp = new int[N+1, sumA + 1, sumB + 1];
		for(int i = 0; i <= N; i++)
			for(int ca = 0; ca <= sumA; ca++)
				for(int cb = 0; cb <= sumB; cb++)
					dp[i, ca, cb] = 1000000;
		dp[0,0,0] = 0;
		for(int i = 1; i <= N; i++)
		{
			for(int ca = 0; ca <= sumA; ca++)
			{
				for(int cb = 0; cb <= sumB; cb++)
				{
					dp[i, ca, cb] = Math.Min(dp[i, ca, cb], dp[i-1, ca, cb]);

					if((ca + a[i] > sumA) || (cb + b[i] > sumB))
						continue;
					dp[i, ca + a[i], cb + b[i]] = 
						Math.Min(
							dp[i, ca + a[i], cb + b[i]],
							dp[i-1, ca, cb] + c[i]);
				}
			}
		}

		int ans = int.MaxValue;
		for(int ca = 1; ca <= sumA; ca++)
		{
			for(int cb = 1; cb <= sumB; cb++)
			{
				if((ca * Mb != cb * Ma))
					continue;
				ans = Math.Min(ans, dp[N,ca,cb]);
			}
		}
		
		Console.WriteLine((ans >= 1000000) ? -1 : ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 19168
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int ans;
int f[8][8];
int w, h;
struct p {
	int x, y, cnt, stv;
	p(int a, int b, int c, int d) : x(a), y(b), cnt(c), stv(d) {}
};
int chk(int x, int y, bool b[8][8]) {
	if(b[x][y])
		return 0;
	else if(x < 0 || y < 0 || h-1 < x || w-1 < y)
		return 0;
	else {
		b[x][y] = true;
		return f[x][y];
	}
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	while(cin >> w >> h, w|h) {
		queue<p> start, search;
		REP(i, h) REP(j, w) {
			cin >> f[i][j];
			if(f[i][j] == 2) {
				start.push(p(i, j, 0, 5));
				f[i][j] = 1;
			}
		}

		int ans = -1;
		bool flg = false;
		set<pi> s;
		while(start.size()) {
			search.push(start.front());
			start.pop();
			while(search.size()) {
				p p2 = search.front();
				search.pop();
				if(p2.stv == 0)
					continue;
				bool b[8][8] = {};
				b[p2.x][p2.y] = true;
				REP(i, 4) {
					int res = chk(p2.x + dx[i], p2.y + dy[i], b);
					if(res > 0)
						search.push(p(p2.x + dx[i], p2.y + dy[i], p2.cnt + 1, p2.stv - 1));
					if(res == 3) {
						ans = p2.cnt + 1;
						flg = true;
					}
					if(res == 4) {
						if(!s.count(mp(p2.x + dx[i],  p2.y + dy[i]))) {
							s.insert(mp(p2.x + dx[i],  p2.y + dy[i]));
							start.push(p(p2.x + dx[i], p2.y + dy[i], p2.cnt + 1, 5));
						}
					}
				}
				if(flg) break;
			}
			if(flg) break;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
using Number = System.Int32;
namespace Program {
	public class Solver {
		Random rnd = new Random();
		public void Solve() {
			var a = rl;
			var b = rl;
			if ((a + b) % 2 == 0) Console.WriteLine((a + b) / 2);
			else Console.WriteLine("IMPOSSIBLE");
		}

		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		int ri { get { return sc.Integer(); } }
		long rl { get { return sc.Long(); } }
		double rd { get { return sc.Double(); } }
		string rs { get { return sc.Scan(); } }
		public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

		static T[] Enumerate<T>(int n, Func<int, T> f) {
			var a = new T[n];
			for (int i = 0; i < a.Length; ++i) a[i] = f(i);
			return a;
		}
		static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
	}
}

#region main
static class Ex {
	static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
	static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
		return string.Join(st, ie);
	}
	static public void Main() {
		Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
		var solver = new Program.Solver();
		var t = new System.Threading.Thread(solver.Solve, 10000000);
		t.Start();
		t.Join();
		//solver.Solve();
		Console.Out.Flush();
	}
}
#endregion
#region Ex
namespace Program.IO {
	using System.IO;
	using System.Text;
	using System.Globalization;

	public class Printer : StreamWriter {
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	}

	public class StreamScanner {
		public StreamScanner(Stream stream) { str = stream; }

		public readonly Stream str;
		private readonly byte[] buf = new byte[1024];
		private int len, ptr;
		public bool isEof = false;
		public bool IsEndOfStream { get { return isEof; } }

		private byte read() {
			if (isEof) return 0;
			if (ptr >= len) {
				ptr = 0;
				if ((len = str.Read(buf, 0, 1024)) <= 0) {
					isEof = true;
					return 0;
				}
			}
			return buf[ptr++];
		}

		public char Char() {
			byte b = 0;
			do b = read(); while ((b < 33 || 126 < b) && !isEof);
			return (char)b;
		}
		public string Scan() {
			var sb = new StringBuilder();
			for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
			return sb.ToString();
		}
		public string ScanLine() {
			var sb = new StringBuilder();
			for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
			return sb.ToString();
		}
		public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
		public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
		public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
	}
}

#endregion


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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


int main() {

    int N, cnt = 0;
    cin >> N;
    for1(i,N){
        if (1<=i&&i<10 || 100<=i&&i<1000 || 10000<=i&&i<100000) cnt++;
    }
    cout << cnt <<"\n";
}

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

using ll = long long;
int main(int argc, char ** argv)
{
  //
  int n;
  std::cin >> n;

  std::map<std::string, int> m;
  m["AC"] = 0;
  m["WA"] = 0;
  m["TLE"] = 0;
  m["RE"] = 0;

  std::string s;
  for (int i = 0; i < n; i++) {
    std::cin >> s;
    m[s]++;
  }

  std::printf("AC x %d\n", m["AC"]);
  std::printf("WA x %d\n", m["WA"]);
  std::printf("TLE x %d\n", m["TLE"]);
  std::printf("RE x %d\n", m["RE"]);
  return 0;
}


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

int main(){
    int n, w;
    cin >> n >> w;
    int V[n], W[n];
    for(int i = 0; i < n; i++){
        cin >> V[i] >> W[i];
    }

    int dp[n + 1][w + 1];
    for(int i = 0; i <= w; i++){
        dp[0][i] = 0;   //0個選んだ時の重さは0(それはそう)
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= w; j++){
            if(j >= W[i]){
                dp[i + 1][j] = max(dp[i][j], dp[i][j - W[i]] + V[i]);
                /*
                if(dp[i + 1][j] == dp[i][j - W[i]] + V[i]){
                    cout << "aa " << i + 1 << " " << j << " " << dp[i + 1][j] << endl;
                }
                */
            }else{
                dp[i + 1][j] = dp[i][j];   //MAXまで重さきてるから入れられないため更新無し（今までの最大値流用）
            }
        }
    }
    cout << dp[n][w] << endl;


    return 0;
}


Measured memory_bytes: 7064
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define pr(x) prev(x.end())
# define mset multiset
# define umap unordered_map
# define gcd __gcd
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int mod = 1e9+7;//998244353
const int N = 1e5+5;



void solve(){
	int n,k;
	cin>>n>>k;
	map<int,int>m;
	rep(i,n){
		int x;
		cin>>x;
		m[x]++;
	}
	ll ans=0;
	vector<int>v;
	for(auto i:m){
		v.pb(i.S);
	}
	sort(all(v));
	reverse(all(v));
	for(int i=k;i<sz(v);++i){
		ans+=v[i];
	}
	cout<<ans;

}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

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;
}

int main(){
    ll n,x;
    cin >> n >> x;
    ll a[n];
    rep(i,n){
        cin >> a[i];
    }
    ll cnt = 0;
    rep(i,n-1){
        ll sum_candy = a[i] + a[i+1];
        if (sum_candy <= x) continue;
        ll byte = sum_candy - x;
        if ( a[i+1] > byte) a[i+1] -= byte;
        else {
            a[i] -= byte - a[i+1];
            a[i+1] = 0;
        }

        cnt += byte;
    }
    cout << cnt << endl;
    return 0;
}


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

const int INF = 2e9, N_MAX = 3;

int n = 3;
int a[N_MAX + 3];

int ans = INF;

int main()
{
    cin >> a[1] >> a[2] >> a[3];
    for(int i = 1; i <= n; i++)
    {
        int cur = 0;
        for(int j = 1; j <= n; j++)
        {
            if(i == j)
                continue;

            cur += fabs(a[i] - a[j]);
        }

        ans = min(ans, cur);
    }

    cout << ans << '\n';


    return 0;
}


Measured memory_bytes: 256
#define NDEBUG 1

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

typedef long long ll;

struct UnionFind {
    vector<int> par;
    int cnt;
    UnionFind(int size_) : par(size_, -1), cnt(size_) { }
    bool merge(int x, int y){
        x = find(x); y = find(y);
        if (x != y) {
            if (par[y] < par[x]) swap(x, y);
            par[x] += par[y]; par[y] = x;
            cnt--;
        }
        return x != y;
    }
    bool get(int x, int y){
        return find(x) == find(y);
    }
    int find(int x){
        return par[x] < 0 ? x : par[x] = find(par[x]);
    }
    // optional
    int size(int x){
        return -par[find(x)];
    }
    // optional
    int size(){
        return cnt;
    }
};

// UnionFind(size)
// merge(x,y)
// get(x,y)
// find(x)
// size(x)
// size()

int main(){
    int h,w,c;
    while(cin >> h >> w >> c && h){
        c--;
        int g[16][16], gg[16][16];
        auto adrs = [&](int y, int x){ return x + y*w; };
        rep(i,h)rep(j,w){
            cin >> g[i][j];
            g[i][j]--;
        }
        int const pat = 6*6*6*6*6;
        int ans = 0;
        rep(mask,pat){
            rep(i,h)rep(j,w) gg[i][j] = g[i][j];
            // g ha dame
            int t = mask;
            rep(i,5){
                UnionFind uf(h*w);
                rep(y,h)rep(x,w){
                    int dx[] = {0,1};
                    int dy[] = {1,0};
                    rep(d,2){
                        int nx = x+dx[d], ny = y+dy[d];
                        if(nx >= w || ny >= h) continue;
                        if(gg[y][x] == gg[ny][nx]) uf.merge(adrs(y,x), adrs(ny,nx));
                    }
                }
                int cc = t%6;
                rep(y,h)rep(x,w){
                    if(uf.get(0, adrs(y,x))) gg[y][x] = cc;
                }
                t /= 6;
            }
            UnionFind uf(h*w);
            {
                int dx[] = {0,1};
                int dy[] = {1,0};
                rep(y,h)rep(x,w){
                    rep(d,2){
                        int nx = x+dx[d], ny = y+dy[d];
                        if(nx == w || ny == h) continue;
                        if(gg[y][x] == gg[ny][nx]) uf.merge(adrs(y,x), adrs(ny,nx));
                    }
                }
            }
            if(c == gg[0][0]) ans = max(ans, uf.size(0));
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1200
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int h, w; cin >> h >> w;
	int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy;
	--sx, --sy, --gx, --gy;
	vector<string> g(h); rep(i, h)cin >> g[i];
	vector<vector<int>> dp(h, vector<int>(w, 1e9));
	dp[sx][sy] = 0;
	deque<pair<int, int>> q;
	q.push_front(make_pair(sx, sy));
	int d[] = { 0,1,0,-1 };
	while (!q.empty())
	{
		int x, y;
		tie(x, y) = q.front();
		q.pop_front();
		rep(i, 4)
		{
			int nx = x + d[i];
			int ny = y + d[i^1];
			if (nx < 0 || h <= nx || ny < 0 || w <= ny)continue;
			if (g[nx][ny] == '#')continue;
			if (chmin(dp[nx][ny], dp[x][y]))q.push_front({ nx,ny });
		}
		for (int i = -2; i <= 2; ++i)for (int j = -2; j <= 2; ++j)
		{
			int nx = x + i;
			int ny = y + j;
			if (nx < 0 || h <= nx || ny < 0 || w <= ny)continue;
			if (g[nx][ny] == '#')continue;
			if (chmin(dp[nx][ny], dp[x][y] + 1))q.push_back({ nx,ny });
		}
	}
	if (dp[gx][gy] == 1e9)cout << -1 << endl;
	else cout << dp[gx][gy] << endl;
}

Measured memory_bytes: 9536
fn main() {
    let n = read::<usize>();
    let mut r = Vec::new();

    for _ in 0..n {
        r.push(read::<i32>());
    }

    println!("{}", max_profit(r));
}

/// 後戻りできないタイプの最大の差を求める
/// ex. 為替レート 4->3->1 : -2(4と3の-1が最大)
fn max_profit(r: Vec<i32>) -> i32 {
    let len = r.len();
    // jまでにある最小値
    let mut minv = r[0];
    // 一番大きな差
    let mut maxv = r[1] - r[0];
    for j in 1..len {
        if r[j] - minv > maxv { 
            maxv = r[j] - minv;
        }
        if minv > r[j] {
            minv = r[j];
        }
    }
    maxv
}

/// 標準入力から一行を読み取り、指定の型に変換する関数
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}



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

int main(void)
{
    int N;
    string c;
    cin >> N;
    cin >> c;
    
    // <w->r, r->w>
    vector<pe> operations(N+1);
    operations[0] = {0, 0};
    for(int i = 0; i < N; i++){
        
        if(c[i] == 'R'){
            operations[0].second++;
        } else {

        }
        
    }
    for (int i = 1; i < N+1; i++)
    {
        operations[i] = operations[i-1];
        if(c[i-1] == 'R'){
            operations[i].second--;
        } else {
            operations[i].first++;
        }

    }
    
    
    int minOp = N;
    for (int i = 0; i < N+1; i++)
    {
        int first = operations[i].first;
        int second = operations[i].second;
        int diff = max(first, second) - min(first, second);

        int op_req = diff + min(first, second);

        if(op_req < minOp) minOp = op_req;
    }

    cout << minOp << endl;

    return 0;
}


Measured memory_bytes: 5248
#include "bits/stdc++.h" 
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rerep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans;
  ans=a*c;
  ans=max(a*d,ans);
  ans=max(b*c,ans);
  ans=max(b*d,ans);
  cout<<ans<<endl;
  return 0;

}

Measured memory_bytes: 3632