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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define INF 1e18

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vector<vll> v(3,vll(n));
    rep(i,n){
        rep(j,3) cin>>v[j][i];
    }
    ll ans=-INF;
    vector<vll> dp(n+1,vll(m+1));
    rep(c,8){
        rep(i,n+1)rep(j,m+1) dp[i][j] = -INF;
        dp[0][0] = 0;
        rep(i,n)rep(j,m+1){
            if (j>0){
                ll temp=0;
                rep(k,3){
                    if (c>>k&1) temp += v[k][i];
                    else temp -= v[k][i];
                }
                dp[i+1][j] = max(dp[i][j],dp[i][j-1]+temp);
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
        chmax(ans,dp[n][m]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

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

	vector<int> a(n);
	vector<pair<int, int>> bc(m);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < m; ++i) {
		cin >> bc[i].first >> bc[i].second;
	}

	// sort asc
	sort(a.begin(), a.end());

	// sort desc
	sort(bc.begin(), bc.end(), [](const pair<int, int>& x, const pair<int, int>& y) { return x.second > y.second; });

	int bcIndex = 0, count = 0;
	for (int ai = 0; ai < n; ++ai) {
		if (a[ai] < bc[bcIndex].second) {
			a[ai] = bc[bcIndex].second;
			if (++count >= bc[bcIndex].first) {
				if (bc.size() <= ++bcIndex) break;
				count = 0;
			}
		}
	}

	long long res = 0;
	for (auto value : a) {
		res += value;
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main()
{
  double a, b, c, h, lc;
  cin >> a >> b >> c;
  c = c * 3.14159265 / 180;

  h = b * sin( c );
  lc = sqrt( a * a + b * b - 2 * a * b * cos( c ));

  cout << fixed << setprecision(6) << a * h / 2 << endl;
  cout << fixed << setprecision(6) << a + b + lc << endl;
  cout << fixed << setprecision(6) << h << endl;
  
  return 0;
}

Measured memory_bytes: 1284
from math import atan, degrees
a,b,x = map(int, input().split())
if a**2 * b / 2 < x:
    x = a**2 * b - x
    print('{:.10f}'.format(degrees(atan(x*2 / a/a/a ))))
else:
    print('{:.10f}'.format(90-degrees(atan(2 * x / a / b / b ))))


Measured memory_bytes: 3188
def main():
	n = int(input())
	arr = list(map(int,input().split()))
	arr2 = list(map(int,input().split()))
	cnt = 0
	if arr2[0]>arr[0]:
		cnt+=arr[0]
		arr2[0]-=arr[0]
	else:
		cnt+=arr2[0]
		arr2[0]=0
	for i in range(1,len(arr)-1):
		if arr[i]<(arr2[i]+arr2[i-1]):
			cnt+=arr[i]
			arr[i]-=arr2[i-1]
			if arr[i]>0:
				arr2[i]-=arr[i]
		else:
			cnt+=(arr2[i]+arr2[i-1])
			arr2[i]=0
	if arr2[-1]>arr[-1]:
		cnt+=arr[-1]
		arr2[-1]-=arr[-1]
	else:
		cnt+=arr2[-1]
		arr2[-1]=0
	print(cnt)

main()



Measured memory_bytes: 81892
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << (a-c)*(b-d) << endl;	
}

Measured memory_bytes: 256
#include<stdio.h>
#define K 100000

int A[K];

int partition(int p,int r){
  int x,i,j,v;
  x = A[r];
  i = p - 1;
  for(j = p;j < r;j++){
    if(A[j] <= x){
      i = i + 1;
      v = A[i];
      A[i] = A[j];
      A[j] = v;
    }
  }
  v = A[i + 1];
  A[i + 1] = A[r];
  A[r] = v;
  return i+1;
}

int main(){
  int n,i,q;

  scanf("%d",&n);

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

  q = partition(0,n-1);

  for(i = 0;i < n;i++){
    if(i > 0) printf(" ");
    if(i == q) printf("[");
    printf("%d",A[i]);
    if(i == q) printf("]");
  } printf("\n");
  return 0;
}



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

int main() {
  int N;
  scanf("%d", &N);
  vector<ll> L = {2, 1};
  if(N == 1) {
    printf("%d", L.at(1));
  }
  else {
    for(int i = 2; i < 87; i++) {
      L.push_back(L.at(i - 1) + L.at(i - 2));
      if(i == N) {
        printf("%lld", L.at(i));
      }
    }
  }  
}

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

int main() {
	long long N,A,B;
	cin >>N>>A>>B;
	if(A==0){
		cout <<0;
	}
	else if(B==0){
		cout <<N;
	}
	else{
		if(N%(A+B)<A){
		cout <<(N/(A+B))*A+(N%(A+B));	
		}
		else{
			cout << (N/(A+B))*A+A;
		}
		
	}
}

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

int main(){
    int n;
    cin>>n;
    int max=0;
    int cnt=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a>=max){
            cnt++;
            max=a;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int h, n;
  cin >> h >> n;

  int sum = 0;
  for (int i = 0, x; i < n; ++i) {
    cin >> x;
    sum += x;
  }

  if (sum >= h) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	int n,k;
	cin >> n >> k;
	vector <int> a(n);
	for(int i = 0;i < n;++i) cin >> a[i];
	sort(a.begin(),a.end());
	int summ = 0;
	for(int i = 0;i < k;++i) summ += a[i];
	cout << summ << newl;

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


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

int n, m;
int c[30];
int memo[51000];

int rec(int x) {
    if (memo[x]!=-1) return memo[x];
    if (x==0) return memo[x] = 0;
    
    int res = 100000;
    
    for (int i=0; i<m; i++) {
        if (x-c[i]<0) continue;
        res = min(res, rec(x-c[i])+1);
    }
    
    return memo[x] = res;
}

int main() {
    cin >> n >> m;
    for (int i=0; i<m; i++) cin >> c[i];
    for (int i=0; i<=n; i++) memo[i] = -1;
    cout << rec(n) << endl;
}


Measured memory_bytes: 5636
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
const int INF = INT_MAX;


int main() {
  int N,K;
  cin  >> N >> K;
  vint A(N);
  int minA=INF;
  int minidx = -1;
  repeat(i,N){
    cin >> A[i];
    if(minA > A[i]){
      minA = A[i];
      minidx = i;
    }
  }
  int ans = 0;
  for(int i=0;i<N;i+=K-1){
    ans++;
    if(i+K-1 < N && i <= minidx && minidx < i+K-1){
      i++;
    }
  }

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


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

int main(){
    int D;
    cin >> D;
    map<int , string> eve;

    eve[25] = "Christmas";
    eve[24] = "Christmas Eve";
    eve[23] = "Christmas Eve Eve";
    eve[22] = "Christmas Eve Eve Eve";

    cout << eve[D] << endl;
}

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

int a[15][15];
int main() {
	int n;
	while (cin >> n, n) {
		rep(i, n) {
			rep(j, n) {
				scanf("%d", &a[i][j]);
			}
		}
		rep(i, n) {
			int cnt = 0;
			rep(j, n)cnt += a[i][j];
			a[i][n] = cnt;
		}
		rep(i, n) {
			int cnt = 0;
			rep(j, n)cnt += a[j][i];
			a[n][i] = cnt;
		}
		a[n][n] = 0;
		rep(i, n)a[n][n] += a[i][n];
		rep(i, n + 1) {
			rep(j, n + 1) {
				printf("%5d", a[i][j]);
				if (j == n)printf("\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

string str; 
int N, K;

void solve() {
	cin >> str;
	N = sz(str);
	cin >> K;
	rep(i, 0, N) {
		int mv = (26 - (str[i] - 'a')) % 26;
		if(K - mv >= 0) {
			K -= mv;
			str[i] = 'a';
		}
	}
	str[N - 1] = (str[N - 1] - 'a' + K) % 26 + 'a';
	cout << str << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 592
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
		public static void main(String[] args){
			
			for(int i =0;scan.hasNextLine();i++){
				int test = scan.nextInt();
				if(test != 0){
					System.out.println("Case "+(i+1)+": "+test);
				}else{
					break;
				}
			}
		}
}



Measured memory_bytes: 65520
N = int(input())
h = [int(i) for i in input().split()]

dp=[0 for i in range(N)]
dp[1] = abs(h[1] - h[0])

for i in range(N-2):
  dp[i+2]=min(dp[i+1]+ abs(h[i+2]-h[i+1]), dp[i]+ abs(h[i+2]-h[i]))
print(dp[N-1])


Measured memory_bytes: 13928
import math
import sys
from collections import defaultdict
from itertools import product, permutations, combinations

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


N = int(input())
if N % 2:
    print(0)
    exit()
else:
    N //= 2

ans = 0
while N > 0:
    N //= 5
    ans += N
print(ans)



Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N, M, R;
int r[8];
int dis[210][210];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M >> R;
  REP(i, R) {
    cin >> r[i];
    r[i]--;
  }
  fill_n((int*)dis, 210*210, INF);
  REP(i, N) dis[i][i] = 0;
  REP(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    dis[a][b] = dis[b][a] = c;
  }
  REP(k, N) REP(i, N) REP(j, N) {
    chmin(dis[i][j], dis[i][k]+dis[k][j]);
  }
  sort(r, r+R);
  int ans = INF;
  do {
    int s = 0;
    REP(i, R-1) s += dis[r[i]][r[i+1]];
    chmin(ans, s);
  } while (next_permutation(r, r+R));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
# 単調非減少とは？（多分、小さくなっていなければいいってこと）
# それぞれ1低く出来る、つまり、前のやつより2以上小さくなっている箇所があったらその時点でNo
# 他のNoパターンは？3,2,1もだめ、これを一般化すると？
# 一番大きい数より2以上小さくなっている数が後から出てくるとダメ？

n = int(input())
h = list(map(int, input().split()))
highest = h[0]

for i in h:    
    if highest - i > 1:
        print("No")
        exit()
    highest = max([i,highest])

print("Yes")

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

ll n, t[100005], a[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    rep(i, 0, n) cin >> t[i] >> a[i];
    ll x = 1, y = 1, k = 1;
    rep(i, 0, n) {
      k = max((x + t[i] - 1) / t[i], (y + a[i] - 1) / a[i]);
      x = k * t[i], y = k * a[i];
    }
    cout << x + y << endl;
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<vector<bool>> a(n, vector<bool>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int w;
      cin >> w;
      a.at(i).at(j) = w;
    }
  }
  vector<vector<int64_t>> dp(n + 1, vector<int64_t>(1 << n));
  dp.at(0).at(0) = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (!a.at(i).at(j)) continue;
      for (int s = 0; s < (1 << (n - 1)); s++) {
        int s1 = ((s >> j) << (j + 1)) | (s & ((1 << j) - 1));
        dp.at(i + 1).at(s1 + (1 << j)) += dp.at(i).at(s1);
        if (i % 2) dp.at(i + 1).at(s1 + (1 << j)) %= 1000000007;
      }
    }
  }
  cout << dp.at(n).at((1 << n) - 1) % 1000000007 << endl;
}


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

ll a, b;

ll f0(ll num) {
    if (num <= 0) return 0;
    int edge = num%2;
    string res = to_string((num+1)%4>=2);
    num >>= 1;
    while(num) {
        if (num&1 && !edge) res += "1";
        else res += "0";
        num >>= 1;
    }
    reverse(res.begin(), res.end());
    return stoll(res, NULL, 2);
}

int main() {
    cin >> a >> b;
    ll res = f0(a-1) ^ f0(b);
    cout << res << endl;
}

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

int main(int argc, char *argv[])
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

    if (A > 9 || B > 9) {
        cout << -1;
    }
    else {
        cout << A * B;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   
    
    int t,i,j,sum,cnt,k=0,s;
      string s1,s2;
    cin>>s1>>s2;
        if (s1.size()<s2.size()){
          cout<<"LESS\n";
         }
       else if(s1.size()>s2.size()){
      cout<<"GREATER\n";
    }
    else{
       if(s1==s2){cout<<"EQUAL\n";}
        else{
          for(i=0;i<s1.size();i++){
        if(s1[i]!=s2[i]){k=i;break;}
        }
       if(s1[k]>s2[k]){cout<<"GREATER\n";}
         else{cout<<"LESS\n";}
       }
    }
  
            
        
    }

   



Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int N; std::cin >> N;
    std::vector<int> A(N);
    for(int i(0); i < N; ++i) std::cin >> A[i];
    long long ans(1000), cur(1000), st(0);
    bool decre(true);
    for(int i(0); i < N; ++i){
        std::vector<std::pair<int, int>> add;
        if(decre && (i < N-1 && A[i] < A[i+1])){
            decre = false;
            st += cur / A[i];
            cur %= A[i];
        }else if(i == N-1 || (!decre && A[i] > A[i+1])){
            decre = true;
            cur += st * A[i];
            st = 0;
            chmax(ans, cur);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(void){
    int N,K,ans=0;
    cin>>N>>K;
    vector<int> p(N);
    for(int i=0;i<N;i++){
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    for(int i=0;i<K;i++){
        ans+=p[i];
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3612
use proconio::input;

mod Prime {
    pub fn is_prime(n: i64) -> bool {
        if n == 1 {
            return false;
        }
        for i in 2..n {
            if i * i > n {
                break;
            }
            if n % i == 0 {
                return false;
            }
        }
        return true;
    }

    pub fn prime_division(n: i64) -> Vec<(i64, i64)> {
        let mut v = n;
        let mut pf = Vec::new();
        if v == 0 {
            return pf;
        }
        if v < 0 {
            v = -v;
            pf.push((-1, 1));
        }
        for p in 2..n {
            if p * p > n {
                break;
            }
            let mut count = 0;
            while v % p == 0 {
                v /= p;
                count += 1;
            }
            if count > 0 {
                pf.push((p, count));
            }
            if v <= p {
                break;
            }
        }

        if v > 1 {
            pf.push((v, 1));
        }
        return pf;
    }
}

fn main() {
    input! {
        n: i64,
    }

    let pf = Prime::prime_division(n);
    let ans = pf.into_iter().fold(0, |acc, (base, exp)| {
        if base == 1 {
            acc
        } else {
            let mut x = exp;
            let mut count = 1;
            while x >= count {
                x -= count;
                count += 1;
            }
            acc + count - 1
        }
    });

    println!("{}", ans);
}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, -1, sizeof(a))
#define DIG(a) char(a + '0')
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int R, C;
int a[11][10010];
int b[11][10010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> R >> C, R) {
    REP(i, R) REP(j, C) cin >> a[i][j];
    int ans = 0;
    REP(ms, Bit(R)) {
      int sum = 0;
      REP(i, R) REP(j, C) {
        b[i][j] = a[i][j] ^ ((ms & Bit(i)) ? 1 : 0);
      }
      REP(j, C) {
        int tmp = 0;
        REP(i, R) tmp += b[i][j];
        sum += max(tmp, R-tmp);
      }
      chmax(ans, sum);
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 4576
def main():
    n,m = map(int,input().split())
    ab = sorted([list(map(int,input().split())) for _ in range(n)], key=lambda x:(x[0],x[1]))
    res = 0
    for a,b in ab:
        if m == 0:
            break
        buy = min(m,b)
        res += a*buy
        m -= buy
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 66520
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long LL;
const int maxn=222222;
int V[maxn];
char ss[maxn];
int main()
{
	scanf("%s",ss+1);
	int N=strlen(ss+1);ss[N+1]=ss[N+2]=0;
	LL ans=0;
	for(int i=1;i<=N;++i)
	{
		if(ss[i]=='A') ++V[i];
		else continue;
		if(ss[i+1]=='A') 
		{
			V[i+1]+=V[i];
			continue;
		}
		if(ss[i+2]=='A') continue;
		if(ss[i+1]=='B'&&ss[i+2]=='C') ans+=V[i],ss[i+2]='A',V[i+2]=V[i]-1;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1280
#a,b,x=map(int,input().split())

n=int(input())
s=[input() for i in range(n)]

ans=0
ab=0
xa=0
bx=0
for i in range(n):
    ans+=s[i].count('AB')

    if s[i][-1]=='A' and s[i][0]=='B':
        ab+=1
    elif s[i][-1]=='A':
        xa+=1
    elif s[i][0]=='B':
        bx+=1

cnt=min(ab+xa,ab+bx) if (xa!=0 or bx!=0) else ab-1
print(ans+cnt if cnt>0 else ans)

Measured memory_bytes: 3700
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}

Node treeSearch(Node u, int k){
  while(u != NIL){
  if(u->key == k) return u;
  else if(u->key > k) u = u->left;
  else u = u->right;
  }
  return NIL;
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

Node treeSuccessor(Node x){
  Node y;
  
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node p;
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  p = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == p->left) p->left = x;
  else p->right = x;

  if(y != z) z->key = y->key;
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
     if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
     } 
     else if ( com[0] == 'i' ){
       scanf("%d", &x);
       insert(x);
     } else if ( com[0] == 'p' ){
       inorder(root);
       printf("\n");
       preorder(root);
      printf("\n");
     }
     else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  
  return 0;
}




Measured memory_bytes: 20532
<?php 
  
fscanf(STDIN,"%s%s",$s,$t);
fscanf(STDIN,"%d%d",$a,$b);
fscanf(STDIN,"%s",$u);

if($s==$u){
  $a--;
}else{
  $b--;
  
}


  echo $a." ".$b."\n";


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

using namespace std;
typedef long long ll;

const int N=2e5+100;
bool check(string s)
{
    if(s[0]==s[1]||s[1]==s[2]||s[0]==s[2]) return true;
    return false;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    string s;cin>>s;
    if(s.size()<2) cout<<-1<<" "<<-1;
    else if(s.size()==2){
        if(s[0]==s[1]) cout<<1<<" "<<2;
        else cout<<-1<<" "<<-1;
    }
    else{
        for(int i=0;i<s.size()-2;i++){
             string ss=s.substr(i,3);
            if(check(ss)){
                cout<<i+1<<" "<<i+1+2;
                 return 0;
            }
        }
        cout<<-1<<" "<<-1;
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int h, w, k;
int x1, yy1, x2, y2;
vector<string> a;
vector<vector<int>> d;
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};

int bfs(){
    if (a[x1][yy1] == '@')
        return -1;
    queue<pii> Q;
    Q.push({x1, yy1});
    d[x1][yy1] = 0;
    pii target = {x2, y2};

    int lim = min(k, max(h, w));
    while(Q.size()){
        auto u = Q.front(); Q.pop();
        if (u == target){
            return d[u.first][u.second];
        }
        FOR(k, 4){
            FOR1(t, lim){
                int xx = u.first + t * di[k];
                int yy = u.second + t * dj[k];
                if (xx >= 0 && xx < h && yy >=0 && yy < w
                    && a[xx][yy] == '.'){
                        if (d[xx][yy] == -1) {
                            d[xx][yy] = d[u.first][u.second] + 1;
                            Q.push({xx, yy});
                        }
                        else if (d[xx][yy] <= d[u.first][u.first]+1)
                            break;
                }
                else
                    break;
            }
        }
    }
    return -1;
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

//#define TEST
#ifndef TEST
    cin >> h >> w >> k;
    cin >> x1 >> yy1 >> x2 >> y2;
    x1--; yy1--; x2--; y2--;
#else
    h = 1e3; w = 1e3; k = 1e3;
    x1 = 0; yy1 = 0; x2 = h-1; y2 = w-1;
#endif
    a.resize(h);
    d.resize(h, vector<int>(w, -1));
#ifndef TEST
    FOR(i, h) cin >> a[i];
#else
    FOR(i, h) a[i] = string(w, '.');
    FOR(i, h) FOR(j, w) {
        int x = rand()%2;
        if (x == 0) a[i][j] = '@';
    }
#endif
    int ret = bfs();
//    FOR(i, h){
//        FOR(j, w)
//        cout << d[i][j] << " ";
//        cout << endl;
//    }
    cout << ret << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

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

int x,y;
bool ans;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>x>>y;
	for(int i = 0;i <= x;i++){
		if(i * 2 + 4 * (x - i) == y){
			cout<<"Yes"<<endl;
			ans = true;
			break;
		}
	}
	if(!ans) cout<<"No"<<endl;
}

Measured memory_bytes: 3644
n = int(input())
digit = len(str(n))

score = 0

for i in range(1,n+1):
    if str(i)[-1] != '0':
        first = str(i)[-1]
        end = str(i)[0]
        if first == end:
            count = 1
        else:
            count = 2
        while count < digit:
            if count <= 2:
                score += 1
            else:
                score += 10**(count - 2)
            count += 1
        if first < str(n)[0]:
            score += 10**(count - 2)
        elif first == str(n)[0]:
            if len(str(n)) == 1:
                score += 1
            elif end > str(n)[-1]:
                score += int(str(n)[1:])//10
            else:
                score += int(str(n)[1:])//10 + 1
print(score)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll a;
    cin >> a;
    vector<ll> z(a);
    for (int i = 0; i < a; i++) {
        cin >> z[i];
    }
    sort(z.begin(), z.end());
    double ans = 1.0*z[0];
    for (int i = 1; i < a; i++) {
        ans = (ans + 1.0 * z[i]) / 2.0;
    }
    cout << fixed << setprecision(15) << ans <<endl;
}

Measured memory_bytes: 3768
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    ll x;
    std::cin >> x;
    ll result = 0;
    result += (x/11)*2;
    if(x%11==0){
        std::cout << result << std::endl;
    }else if(x%11<=6){
        std::cout << result+1 << std::endl;
    }else{
        std::cout << result+2 << std::endl;
    }
}


Measured memory_bytes: 256
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    S = input()
    S = [int(c) for c in S]

    print(min(S.count(1), S.count(0))*2)

resolve()

Measured memory_bytes: 44764
#include<iostream>
#include <algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

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

  if(N>=10) cout << R << endl;
  else cout << R+100*(10-N) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int n,i,m;
	char s[100000];

	scanf("%d%s",&n,s);
	m=strlen(s);
	for(i=0;i<m;i++){
		s[i]-='A';
		s[i]=(s[i]+n)%26;
		putchar(s[i]+'A');
	}
	putchar('\n');
	return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int);
void inorder(Node);
void preorder(Node);

int main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ )
    {
      scanf("%s", com);
      
      
      if ( com[0] == 'i' ){
	scanf("%d", &x);
	insert(x);
      }
      else if ( com[0] == 'p' )
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
    
    }

  return 0;
}



void insert(int k)
{
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL)
    {
      y = x;
      if(z->key < x->key)
	{
	  x = x->left;
	}
      else
	{
	  x = x->right;
	}
    }
  z->parent = y;
  if(y==NIL)
    {
      root=z;
    }
  else
    {
      if(z->key < y->key)
	{
	  y->left = z;
	}
      else
	{
	  y->right = z;
	}
    }


}

void inorder(Node u){
  if(u == NIL)
    return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

}
void preorder(Node u){
  if(u == NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}





Measured memory_bytes: 25136
#include <bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c,ans=0,d,e;
  cin>>a>>b>>c;
  d=b-a;
  e=a;
  for(int i=0;i<d+1;i++){
    if(c%e==0){
      ans++;
    }
    e++;
  }
  cout<<ans<<"\n";



  return 0;
}



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


 
int main() {
  long n,m,o;
  cin >> n >> m;
  
  o = n%m;
  cout << min(o, abs(o-m)) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	//入力される数字
	int suuti;
	//各桁の数字
	int dig;
	//カウント
	int count = 0;

	scanf("%d", &suuti);
	
  	//処理
	while (suuti)
	{
		dig = suuti % 10;
		count += dig;
		suuti = suuti / 10;
	}

	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    if (a < b) {
        cout << "a < b\n";
    } else if (a > b) {
        cout << "a > b\n"; 
    } else if (a == b) {
        cout << "a == b\n";
    }
    return 0;
}


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

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

int main()
{
	ll n,P;
	scanf("%lld %lld",&n,&P);
	ll ret=1;
	for(ll i=2;i*i<=P;i++)
	{
		if(P%i==0)
		{
			ll cnt=0;
			while(P%i==0)
			{
				P/=i;
				cnt++;
			}
			ll t=cnt/n;
			while(t--) ret=ret*(ll) i;
		}
	}
	if(n==1) ret=ret*P;
	printf("%lld\n",ret);
	return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
	int n, k;
	cin >> n >> k;
	ll cnt = 0;
	for(int i = 1; i <= n; i++){
		if(i % k == 0) cnt++;
	}

	ll cnt_2 = 0;
	for(int i = 1; i <= n; i++){
		if(i % k == (k / 2)) cnt_2++;
	}

	ll ans = cnt * cnt * cnt;
	
	if(k % 2 == 0){
		ans += cnt_2 * cnt_2 * cnt_2;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	X, N = getlist()
	P = getlist()
	P = sorted(P)
	ans = None
	dif = INF
	for i in range(102):
		if not (i in P):
			if abs(X - i) < dif:
				ans = i
				dif = abs(X - i)

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 64808
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static int[] segment;
        static int size;

        static void Main(string[] args)
        {
            string[] input1 = Console.ReadLine().Split(' ');
            int n = int.Parse(input1[0]);
            int q = int.Parse(input1[1]);

            Init(n);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < q; i++)
            {
                string[] input2 = Console.ReadLine().Split(' ');
                int c = int.Parse(input2[0]);
                int x = int.Parse(input2[1]);
                int y = int.Parse(input2[2]);

                if (c == 0) Update(x - 1, y);
                else
                {
                    sb.AppendLine(Query(x - 1, y, 0, 0, size).ToString());
                }
            }
            Console.Write(sb);
        }

        static void Init(int n)
        {
            size = 1;

            while (size < n) size *= 2;

            segment = new int[2 * size];
        }

        static void Update(int i, int a)
        {
            i += size - 1;
            segment[i] += a;

            while (i > 0)
            {
                i = (i - 1) / 2;
                segment[i] += a;
            }
        }

        static int Query(int a, int b, int k, int l, int r)
        {
            if (r <= a || b <= l) return 0;

            if (a <= l && r <= b) return segment[k];
            else
            {
                int vl = Query(a, b, k * 2 + 1, l, (l + r) / 2);
                int vr = Query(a, b, k * 2 + 2, (l + r) / 2, r);

                return vl + vr;
            }
        }
    }
}

Measured memory_bytes: 14960
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}
 
fn main() {
  let ss: Vec<String> = read_vec();
  let ans: Vec<char> = ss.iter()
    .map(|s| s.chars().next().unwrap())
    .collect();
  println!("{}{}{}", ans[0], ans[1], ans[2]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int nxt = 1, preIndex = -1;
    int ans = 0;
    bool ok = false;
    rep(i,n){
        if (a[i] == nxt){
            ans += (i - preIndex - 1);
            preIndex = i;
            nxt++;
            ok = true;
        }
    }
    if (preIndex != n-1) ans += (n - 1 - preIndex);

    if (ok) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main()
{   
	int a,b,c,d;
	int left = 0,right = 0;
	 
	scanf(" %d %d %d %d",&a,&b,&c,&d);
	left = a + b;
	right = c + d;
	if(left<right){
	printf("Right");
	}
	if(right<left){
		printf("Left");
	}
	if(left == right){
	printf("Balanced");
	}
	return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int x;
  cin >> x;
  if (x == 3 || x == 5 || x == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall() x.begin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it!=m.end(); it++)

const char nl = '\n';
int main(){
  ll d, t, s; cin >> d >> t >> s;
  if(t*s >= d) cout << "Yes";
  else cout << "No";
  

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  vi r,g,b;
  ll n,cnt=0,mid,las,fir;
  cin >> n;
  char c;
  rep(i,n){
    cin >> c;
    if(c == 'R'){
      r.push_back(i);
    }else if(c == 'B'){
      b.push_back(i);
    }else{
      g.push_back(i);
    }
  }
  for(ll x:r){
    for(ll y:g){
      cnt+=b.size();
      las = 2*y-x;
      fir = 2*x-y;
      if((x+y)%2==1){
        for(ll z:b){
          if(z==las||z==fir){
            cnt--;
          }
        }
      }else{
        mid = (x+y)/2;
        for(ll z:b){
          if(z==mid||z==las||z==fir){
            cnt--;
          }
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


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

int main() {
  ll x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> r(a);
  vector<ll> g(b);
  vector<ll> t(c);
  vector<ll> dp(x+y+c);
  
  rep(i,a) cin >> r[i];
  rep(i,b) cin >> g[i];
  rep(i,c) cin >> t[i];
  
  sort(r.begin(),r.end());
  reverse(r.begin(),r.end());
  sort(g.begin(),g.end());
  reverse(g.begin(),g.end());
  
  rep(i,x) dp[i] = r[i];
  rep(i,y) dp[x+i] = g[i];
  rep(i,c) dp[x+y+i] = t[i];
  
  sort(dp.begin(),dp.end());
  reverse(dp.begin(),dp.end());
  
  ll ans=0;
  
  rep(i,x+y) ans += dp[i];
  
  cout << ans << endl;
  
  return(0);
}

Measured memory_bytes: 7680
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var s = o.a(1);
  var x = "keyence";
  var N = "NO";
  for(var i = 0; i <= x.length; i++){
    if(s.match("^"+x.slice(0,i)+".*"+x.slice(i)+"$"))return "YES";
  }
  return "NO";
}

Measured memory_bytes: 21064
#include <iostream>

using namespace std;

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string s = "";
    for(int i = 0; i < ty - sy; i++){
        s = s + "U";
    }
    for(int i = 0; i < tx - sx; i++){
        s = s + "R";
    }
    for(int i = 0; i < ty - sy; i++){
        s = s + "D";
    }
    for(int i = 0; i < tx - sx; i++){
        s = s + "L";
    }
    s = s + "L";
    for(int i = 0; i < ty - sy + 1; i++){
        s = s + "U";
    }
    for(int i = 0; i < tx - sx + 1; i++){
        s = s + "R";
    }
    s = s + "D";
    s = s + "R";
    for(int i = 0; i < ty - sy + 1; i++){
        s = s + "D";
    }
    for(int i = 0; i < tx - sx + 1; i++){
        s = s + "L";
    }
    s = s + "U";
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 384
#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>;
const int INF = 1000000007;

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  mp["AC"] = 0;
  mp["WA"] = 0;
  mp["TLE"] = 0;
  mp["RE"] = 0;
  rep(i, n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <set>

using namespace std;

int main() {
    set<string> st;
    int N;
    cin >> N;
    for(int n=0; n<N; n++) {
        string str;
        cin >> str;
        st.insert(str);
    }
    cout << st.size() << endl;


    return 0;
    
}

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

use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    a: usize,
    b: usize,
    c: usize
    }
    if c < a + b {
        print!("No");
        return;
    }
    let ans = if 4 * a * b < (c - a - b).pow(2) { "Yes" } else { "No" };
    println!("{}", ans);
}


Measured memory_bytes: 2172