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

int main() {
    int n;
    cin >> n;
    vector<vector<int>>a(n,vector<int>(2));
    for (int i = 0; i <n ; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            cin >> a[i][j];
        }
        
    }
    double ans=0.0;
    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            ans +=sqrt((a[i][0]-a[j][0])*(a[i][0]-a[j][0])+(a[i][1]-a[j][1])*(a[i][1]-a[j][1]));
        }
    }
    int e;
    e=1;
    for(int i=1; i<=n; ++i){
        e *=i;
    }  
    int c;
    c=1;
    for(int i=1; i<=n-1; ++i){
        c *=i;
    }
    double b; 
    b=ans*c;
    double d;
    d=b/e;
    cout << fixed << setprecision(10) << d <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
ll mod= 1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll a[110000];
main(){
    ll n,ans=0;
    string s;
    cin>>s;
    bool p=true;
    if(s[0]!='A')p=false;
    bool q=false;
    bool r=true;
    ll x=0,pos=0;
    rep(i,2,s.length()-1)if(s[i]=='C'){x++;pos=i;}
    if(x==1)q=true;
    rep(i,1,s.length()){
      if(i!=pos){
        if(s[i]<0x61||s[i]>0x7A)r=false;
      }
    }
    if(p&&q&&r)cout<<"AC";
    else cout<<"WA";

}

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


#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
    int n,x;
void pre(){
    
    vector<int>v;
    f(n) {
       
        cin >> x;
        v.push_back(x);
    }
    ll ans = 0;
    map<int,int>mp;
    for (int i = 0 ; i < n ; i++) {
        int x = v[i] - (n - i);
        int tar = i - v[i] - n;
        if (mp.count(tar)) {
           
            ans += mp[tar];
        }
        mp[x]++;
    }
    cout << ans << endl;
}


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

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

string s;

int main(){
    cin >> s;
    int t = s.size();
    int a = (t-1)/2, b = t/2;
    int ans = (t+1)/2;
    if (a == b){
        a--;
        b++;
    }
    while (a >= 0) {
        if (s[a] == s[b] && s[a] == s[a+1]) {
            ans++;
            a--;
            b++;
        } else {
            break;
        }
    }
    cout << ans << endl;
}
































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

#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int main(){
    CIN1(n)
    string ans="Yes";
    set<string> v;
    char tmp;
    rep(i,n){
        string s;cin>>s;
        if(i && tmp!=s.front()){ans = "No";}
        if(v.count(s)>0){ans = "No";}
        tmp = s.back();
        v.insert(s);
    }

    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

inline int at(ll x, int k){ return (x >> k) & 1; }
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)

int main(){
  ll a,b;
  cin >> a >> b;
  cout << a*b << endl;

}


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

int main(){
  int N, T, A;
  cin >> N >> T >> A;
  int cc=1000000000;
  int res=0;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
    int d=abs(A*1000-T*1000+H.at(i)*6);
    if(cc>d){
      cc=d;
      res=i;
    }
  }
  res++;
  cout << res << endl;
}


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

typedef long long ll;
typedef pair<ll,ll> P;

const int INF = 1001001001;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)


int main() {
    ll n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    //vector<P> v(q);
    vector<ll> v(n,0);
  //  vector<ll, vector<ll>> V(n,vector<ll>(n));
    int cnt=0;
    rep(i,n-1){
      if (s[i]=='A' and s[i+1]=='C') {
        cnt++;
        }
        v[i+1]=cnt;
      //  cout<<i<<' '<<cnt<<endl;

    }

    rep(i,q){
      ll l1,r1;
      cin>>l1>>r1;
      l1--;r1--;
      cout<<v[r1]-v[l1]<<endl;
    }




}


Measured memory_bytes: 1792
import sys
# import numpy as np 
 
def main():
    a, b = map(int, sys.stdin.read().split())
 
    if 0 < a:
        ans = 'Positive'
    elif 0 <= b:
        ans = 'Zero'
    else:
        if (b - a + 1) % 2 == 0:
            ans = 'Positive'
        else:
            ans = 'Negative'
    
    print(ans)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @a,@b,@c=gets.to_s.split.map{ |v| v.to_i }
  end
 
  def solve
    q1 && q2
  end
 
  def q1
    4 * a * b < (c - a - b) ** 2
  end
 
  def q2
    0 < c - a - b
  end
 
  def show(ans)
    puts ans ? "Yes" : "No"
  end
end
 
Problem.new.instance_eval do
  show(solve)
end

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

using namespace std;

int a[200005][2];

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 1; i <= n; ++i){
        a[i][0] = a[i - 1][0];
        a[i][1] = a[i - 1][1];
        if (s[i - 1] == '.') a[i][0]++;
        else a[i][1]++;
    }
    int ans = a[n][0];
    for (int i = 1; i <= n; ++i) ans = min(ans, a[i][1] + a[n][0] - a[i][0]);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int dp[3005][3005], n, k;
int arr[1005];
string a, b;
ll mod = 1e9 + 7;
int solve(int i, int j) {
	if (i >= a.size() || j >= b.size())
		return 0;
	if (~dp[i][j])
		return dp[i][j];
	if (a[i] == b[j])
		return dp[i][j] = 1 + solve(i + 1, j+1);
	return dp[i][j] = max(solve(i + 1, j), solve(i, j + 1));
}
void build (int i, int j){
	if (i >= a.size() || j >= b.size())
		return;
	if (a[i] == b[j]){
		cout << a[i];
		build(i + 1, j + 1);
	}
	else if (solve(i, j) == solve(i + 1, j)){
		build(i + 1, j);
	}
	else
		build(i, j + 1);
}
int main() {
	IO
	cin >> a >> b;
	memset(dp, -1, sizeof dp);
	solve(0, 0);
	build(0, 0);
	return 0;
}


Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
 
struct UnionFind{
 int N;
 vector<int> parent;
 vector<int> siz;
 
 UnionFind(int N) : parent(N), siz(N, 1){
  for (int i = 0; i < N; i++) parent[i] = i;
 }
 
 int root(int x){
  if(parent[x] == x) return x;
  else return parent[x] = root(parent[x]);
 }
 
 void unite(int x, int y){
  x = root(x), y = root(y);
  if(x == y) return;
  if(siz[x] < siz[y]) swap(x, y);
  parent[y] = x;
  siz[x] += siz[y];
  siz[y] = 0;
 }
 
 bool same(int x, int y){
  return root(x) == root(y);
 }
 
 int size(int x){
  return siz[root(x)];
 }
};
 
int main(){
 int N, M, K, i;
 scanf("%d%d%d", &N, &M, &K);
 vector<int> count(N, 0);
 UnionFind uf(N);
 for(i = 0; i < M; i++){
  int A, B;
  scanf("%d%d", &A, &B);
  A--;
  B--;
  count[A]++;
  count[B]++;
  uf.unite(A, B);
 }
 for(i = 0; i < K; i++){
  int C, D;
  scanf("%d%d", &C, &D);
  C--;
  D--;
  if(uf.same(C, D)){
   count[C]++;
   count[D]++;
  }
 }
 for(i = 0; i < N; i++){
  printf("%d ", uf.size(i) - count[i] - 1);
 }
 printf("\n");
 return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,n;
    cin>>n;
    a=n/100;
    b=n%100;
    if(a<=0||b<=0){
        if(a<=0&&b<=12&&0<b) cout<<"YYMM\n";
        else if(b<=0&&a<=12&&0<a) cout<<"MMYY\n";
        else cout<<"NA\n";
    }else{
        if(a<=12){
            if(b<=12) cout<<"AMBIGUOUS\n";
            else cout<<"MMYY\n";
        }else{
            if(b<=12) cout<<"YYMM\n";
            else cout<<"NA\n";
        }
    }
}

Measured memory_bytes: 256
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))


ans = 0
for b in B:
    a_index = bisect.bisect_left(A, b)
    c_index = bisect.bisect_right(C, b)
    ans += a_index*(N-c_index)
print(ans)

Measured memory_bytes: 29320
#include <iostream>

using namespace std;


int main()
{
	int N, cnt = 0;
	char c, d;
	cin >> N;
	cin >> c;
	for (int i = 0; i < N - 1; i++)
	{
		cin >> d;

		if (c != d)
		{
			c = d;
			cnt++;
		}
	}

	cout << cnt + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    
    ll  n,i,j,ma = 0,ans=LLONG_MAX;
    cin>>n;
    ll a[n+2];
    for(i=0;i<n;i++) cin>>a[i],ma = max(ma,a[i]);
    for(i=1;i<=ma+1;i++)
    {
    	ll tsum = 0;
    	for(j=0;j<n;j++)
    	{
    		tsum += (a[j] - i) * (a[j] - i);
    	}
    	ans = min(ans,tsum);
    }
    cout<<ans;
}

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

int main(){
    int X;
    cin >> X;
    int res = X / 500 * 1000;
    int x = X % 500;
    cout << res + x / 5 * 5 << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		if (a[i]%2!=0)
		{
			cout<<"first"<<endl;
			return 0; 
		}
	}
	cout<<"second"<<endl;
	return 0;
} 


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	ll h,n;
	cin>>h>>n;
	vector<ll> t(n);
	ll sum=0;
	for(int i=0;i<n;++i) {
		cin>>t[i]; 
		sum+=t[i];
	}
	
	cout<<(sum>=h?"Yes":"No")<<"\n";
	return 0;
}


Measured memory_bytes: 1024
n, y = gets.chomp.split(" ").map(&:to_i)
# 難しい
a = [n,y / 10000].min
b = [n,y / 5000].min
c = y / 1000
(0..a).each do |i|
    (0..b).each do |e|
        k = n - ( i + e )
        if k >= 0 && i * 10 + e * 5 + k == c then
            puts "#{i} #{e} #{k}"
            exit
        end
    end
end
puts "-1 -1 -1"

Measured memory_bytes: 1788
'use strict';
function Main(input) {
  input.trim();
  input = input.split(" ");
  var a = parseInt(input[0], 10);
  var b = parseInt(input[1], 10);
  var c = parseInt(input[2], 10);
  var count = 3;
  
  if(a == b || a == c){
    count -= 1;
  }
  if(b == c){
    count -= 1;   
  }
  console.log(count);
}  
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 22076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007, N = 1e5 + 5;

ll a[N], fact[N], ifact[N], ans = 0;

ll powmod(ll a,ll b, ll m = MOD) {ll res=1; assert(b>=0); for(;b;b>>=1){if(b&1)res=(res*a)%m;a=(a*a)%m;}return res%m;}

ll inv(ll x) {
  return powmod(x, MOD-2);
}

void pre() {
  fact[0] = fact[1] = ifact[0] = ifact[1] = 1LL;
  for (ll i = 2; i < N; i++) {
    fact[i] = fact[i-1] * i % MOD;
    ifact[i] = inv(fact[i]);
  }
}

ll ncr(ll x, ll y) {
  if (x < y) return 0;
  ll res = fact[x] * ifact[y] % MOD * ifact[x - y] % MOD;
  return res;
}

int main() {
  pre();
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a+n+1);
  for (int i = k-1; i < n; i++) {
    ans = (ans + ncr(i, k-1) * a[i+1] % MOD) % MOD;
  }
  reverse(a + 1, a+n+1);
  for (int i = k-1; i < n; i++) {
    ans = (ans - ncr(i, k-1) * a[i+1] % MOD) % MOD;
    if (ans < 0) ans += MOD;
  }
  cout << ans % MOD << "\n";
  return 0;
}

Measured memory_bytes: 2560
N,M = map(int,input().split())
"""
mat = [[0]*M for _ in range(N)]
dx = [-1,0,1,-1,0,1,-1,0,1]
dy = [1,1,1,0,0,0,-1,-1,-1]
for i in range(N):
    for j in range(M):
        for k in range(9):
            if 0 <= i+dy[k] <= (N-1) and 0 <= j+dx[k] <= (M-1):
                mat[i+dy[k]][j+dx[k]] += 1
print(mat)
"""
if N == M == 1:
    print(1)
elif N == 1 or M == 1:
    print(N*M-2)
else:
    print(N*M-2*(N+M-2))

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

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

  // cout << K << ", " << A << ", " << B << endl;
  // A~Bの間にKの倍数が存在するか調べる
  bool existMultipleK = 0;
  for (int i = A; i < B + 1; i++) {
    if (i % K == 0) {
      existMultipleK = 1;
      break;
    }
  }

  if (existMultipleK) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}


Measured memory_bytes: 3592
#include <iostream>
using namespace std;
#define rep(v,n) for(int v=0;v<=n;v++)
int main(){
int r,g,b,n;
cin>>r>>g>>b>>n;
int sum=0;
rep(i,3000){
if(n<i*r)continue;
rep(j,3000){
if(n<i*r+j*g)continue;
if((n-r*i-j*g)%b==0){
sum++;
}
}
}
cout<<sum;
return 0;
}


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

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

    for(char c = 'a'; c <= 'z'; c++){
        if(s.find(c)  == string::npos){
            printf("%c\n", c);
            return 0;
        }
    }
    printf("None\n");
    return 0;
}

Measured memory_bytes: 3776
n,a,b = map(int,input().split())

if abs(a-b)%2==0:
    print(abs(a-b)//2)
else:
    memo = ((n-a)+(n-b+1))//2
    memo2 = ((a)+(b-1))//2
    memo3 = max(a-1,b-1)
    memo4 = max((n-a),(n-b))
    
    print(min(memo,memo2,memo3,memo4))

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

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

    return 0;
}

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

using namespace std;

int a[2019], b[2019];

int main()
{
    long long ans = 0LL;
    char g = getchar();
    while (g > '0' && g <= '9')
    {
        int x = g - '0';
        ++b[x];
        for (int i = 0; i < 2019; ++i)
            b[(i * 10 + x) % 2019] += a[i];

        ans += 1LL * b[0];
        for (int i = 0; i < 2019; ++i)
            a[i] = b[i], b[i] = 0;
        g = getchar();
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <iomanip>

int main(int argc, char *argv[])
{
    int n, x, t;

    std::cin >> n >> x >> t;

    const int ans = t * (n / x + (n % x > 0 ? 1 : 0));

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
ll A[100005];
ll sum[100005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i <= N; i++) cin >> A[i];
    sum[N] = A[N];
    for(int i = N-1; i >= 0; i--){
        sum[i] = sum[i+1]+A[i];
    }
    ll ans = 0;
    ll cur = 1;
    for(int i = 0; i <= N; i++){
        ans += cur;
        // cout << cur << ' ' << sum[i+1] << endl;
        if(cur < A[i]){
            cout << -1 << endl;
            return 0;
        }
        cur -= A[i];
        if(cur*2 <= sum[i+1]){
            cur *= 2;
        }else{
            cur = sum[i+1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5172
_,b = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
num=0
h={}
x.each do
    if h.has_key?(_1)
        h[_1]+=1
    else
        num+=1
        h[_1]=1
    end
end
if b >= num
    puts "0"
elsif b < num
    ha=h.sort {|a,b| a[1]<=>b[1]}
    ans=0
    (num-b).times do
        ans+=ha[_1][1]
    end
    puts ans
end

Measured memory_bytes: 47104
#include <iostream>
#include <iomanip>
#include <climits>
#include <string>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
const int N = 1e2 + 5;

int n, ans;
int a[N];

void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i < n - 1; i++) {
        for(int j = i + 1; j < n; j++) {
            for(int k = j + 1; k <= n; k++) {
                if(a[i] + a[j] > a[k]) {
                    if(a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) {
                        if(a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i])
                            ans++;
                    }
                }
            }
        }
    }
    cout << ans << "\n";
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
#define OFFSET 200000



vector< vector<int> > pl_d(400001);
vector< vector<int> > pl_r(400001);
vector< vector<int> > pl_u(400001);
vector< vector<int> > pl_l(400001);
vector< vector<int> > df_u(400001);
vector< vector<int> > df_d(400001);
vector< vector<int> > df_r(400001);
vector< vector<int> > df_l(400001);
vector< vector<int> > xs_u(200001);
vector< vector<int> > xs_d(200001);
vector< vector<int> > ys_l(200001);
vector< vector<int> > ys_r(200001);


int minimum_col(const vector<int> &v1,const vector<int> &v2,int rat){
  if(!(v1.size() > 0 && v2.size() > 0))return 10000000;
  int j = 0;
  int ret = 10000000;
  REP(i,v1.size()){
    int x_ = v1[i];
    //cerr<<x_<<" "<<v2[j]<<endl;
    while(x_ > v2[j]){
      //cerr<<"dbg "<<x_<<" "<<v2[j]<<endl;
      j++;
      if(j == v2.size())return ret*rat;
    }
    ret = min(ret,v2[j] - x_);
  }
  return ret*rat;
}


int main(){
  int x[200000],y[200000];
  char u[200000];

  int n;
  cin>>n;
  REP(i,n){
    cin>>x[i]>>y[i]>>u[i];
    switch(u[i]){
      case 'U':
        pl_u[x[i]+y[i]].push_back(x[i]);
        df_u[x[i]-y[i]+OFFSET].push_back(x[i]);
        xs_u[x[i]].push_back(y[i]);
        break;
      case 'D':
        pl_d[x[i]+y[i]].push_back(x[i]);
        df_d[x[i]-y[i]+OFFSET].push_back(x[i]);
        xs_d[x[i]].push_back(y[i]);
        break;
      case 'L':
        pl_l[x[i]+y[i]].push_back(x[i]);
        df_l[x[i]-y[i]+OFFSET].push_back(x[i]);
        ys_l[y[i]].push_back(x[i]);
        break;
      case 'R':
        pl_r[x[i]+y[i]].push_back(x[i]);
        df_r[x[i]-y[i]+OFFSET].push_back(x[i]);
        ys_r[y[i]].push_back(x[i]);
        break;
    }
  }
  int ret = 10000000;

  for(auto &e : pl_u){
    sort(ALL(e));
  }
  for(auto &e : pl_d){
    sort(ALL(e));
  }
  for(auto &e : df_u){
    sort(ALL(e));
  }
  for(auto &e : df_d){
    sort(ALL(e));
  }
  for(auto &e : pl_l){
    sort(ALL(e));
  }
  for(auto &e : pl_r){
    sort(ALL(e));
  }
  for(auto &e : df_r){
    sort(ALL(e));
  }
  for(auto &e : df_l){
    sort(ALL(e));
  }
  for(auto &e : xs_u){
    sort(ALL(e));
  }
  for(auto &e : xs_d){
    sort(ALL(e));
  }
  for(auto &e : ys_l){
    sort(ALL(e));
  }
  for(auto &e : ys_r){
    sort(ALL(e));
  }

  REP(i,400001)ret = min(ret,minimum_col(pl_d[i],pl_l[i],10));
  REP(i,400001)ret = min(ret,minimum_col(df_u[i],df_l[i],10));
  REP(i,400001)ret = min(ret,minimum_col(pl_r[i],pl_u[i],10));
  REP(i,400001)ret = min(ret,minimum_col(df_r[i],df_d[i],10));
  REP(i,200001)ret = min(ret,minimum_col(xs_u[i],xs_d[i],5));
  REP(i,200001)ret = min(ret,minimum_col(ys_r[i],ys_l[i],5));
  
  if(ret >= 10000000)cout<<"SAFE"<<endl;
  else cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 117440
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int64_t A, V, B, W, T;
  
  cin >> A >> V >> B >> W >> T;
  
  int D;
  
  if(B < A){
  	D = abs(A - B);
  }else{
  	D = abs(B - A);
  }
  
  int64_t vw = (V - W) * T; 
  
  if(V > W && vw >= D){
  	cout << "YES" << endl;
  }else{
  	cout << "NO" << endl;
  }
  
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long N,D,A;
    cin>>N>>D>>A;
    vector<pair<long long,long long> > monster;
    for(long long i = 0;i<N;i++)
    {
        long long coord,health;
        cin>>coord>>health;
        monster.push_back(make_pair(coord,health));
    }
    sort(monster.begin(),monster.end());
    long long cost=0;
    long long ileodjac=0;
    priority_queue<pair<long long,long long>,vector<pair<long long,long long> >,greater<pair<long long,long long> > > iledodac;
    for(long long i = 0;i<N;i++)
    {
        while(!iledodac.empty()&&iledodac.top().first<monster[i].first)
        {
            ileodjac-=iledodac.top().second;
            iledodac.pop();
        }
        monster[i].second-=ileodjac;
        if(monster[i].second<=0)continue;
        long long costac=(monster[i].second-1)/A+1;
        cost+=costac;
        ileodjac+=costac*A;
        iledodac.push(make_pair(monster[i].first+2*D,costac*A));
    }
    cout<<cost;
}


Measured memory_bytes: 7020
#include <stdio.h>

int main(void)
{
	double r, S, L;
	scanf("%lf", &r);
	
	S = (double)r * r * 3.141592653589;
	L = (double)r * 2 * 3.141592653589;
	
	printf("%f %f", S, L);
	
	return 0;
}

Measured memory_bytes: 648
n, *a = [int(i) for i in input().split()]
abc = "ABC"
xy = []
for _ in range(n):
    xy.append([abc.index(i) for i in input()])
i = 0
ans = []
while i < n:
    if a[xy[i][0]] == 1 and a[xy[i][1]] == 1:
        j = list(set([0, 1, 2])-set(xy[i]))[0]
        if i == n - 1 or a[j] != 0 or xy[i] == xy[i+1]:
            if a[xy[i][0]] > a[xy[i][1]]:
                ans.append(abc[xy[i][1]])
                a[xy[i][0]] -= 1
                a[xy[i][1]] += 1
            else:
                ans.append(abc[xy[i][0]])
                a[xy[i][1]] -= 1
                a[xy[i][0]] += 1
            i += 1
        else:
            k = list(set(xy[i + 1])-set([j]))[0]
            ans.append(abc[k])
            a[k] += 1
            a[list(set(xy[i]) - set([k]))[0]] -= 1
            i += 1

    else:
        if a[xy[i][0]] > a[xy[i][1]]:
            ans.append(abc[xy[i][1]])
            a[xy[i][0]] -= 1
            a[xy[i][1]] += 1
        else:
            ans.append(abc[xy[i][0]])
            a[xy[i][1]] -= 1
            a[xy[i][0]] += 1
        i += 1
    if min(a) < 0:
        print("No")
        exit()
print("Yes")
for i in ans:
    print(i)


Measured memory_bytes: 94024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  long long dp[11][1010];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for(int i = 0 ; i <= 100 ; i++){
    for(int j = 9 ; j >= 0 ; j--){
      for(int k = 0 ; k <= 1000 - i ; k++){
	dp[j+1][k+i] += dp[j][k];
      }
    }
  }
  
  int n, s;  
  while(cin >> n >> s, n|s){
    cout << dp[n][s] << endl;
  }
  return 0;
}

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

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

    long long n, m;
    cin >> n >> m;

    if(n == 1 and m == 1){
        cout << 1 << endl;
        return 0;
    }

    // int A[n][m] = {};
    // int dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
    // int dy[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};

    // for(int i = 0; i < n; i++){
    //     for(int j = 0; j < m; j++){
    //         for(int k = 0; k < 9; k++){
    //             int nx = i + dx[k];
    //             int ny = j + dy[k];
    //             if(nx < 0 or ny < 0 or nx >= n or ny >= m) continue;
    //             A[nx][ny]++;
    //         }
    //     }
    // }

    // for(int i = 0; i < n; i++){
    //     for(int j = 0; j < m; j++){
    //         cout << A[i][j] % 2 << ' ';
    //     }
    //     cout << endl;
    // }

    if(n == 1 or m == 1){
        cout << max(0LL, n - 2) + max(0LL, m - 2) << endl;
    }else{
        cout << (n - 2) * (m - 2) << endl;
    }

    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL

using namespace std;
using llong = long long;

int main()
{
	IOS; 
	
	
	long long n, m, k;
	cin >> n >> m >> k;
	vector<long long> asum(n+1), bsum(m+1);
	int i, j;

	for (i = 1; i <= n; i++)
	{
		long long t;
		cin >> t;
		asum[i] = asum[i - 1] + t;
	}
	for (i = 1; i <= m; i++)
	{
		long long  t;
		cin >> t;
		bsum[i] = bsum[i - 1] + t;
	}
	long long maxBooks = 0;
	for (i = 0; i <= n; i++)
	{
		if (asum[i] > k) break;
		long long bBooks = upper_bound(bsum.begin(), bsum.end(), k - asum[i]) - bsum.begin();
		if (maxBooks < i + bBooks - 1) maxBooks = i + bBooks - 1;
	}
	cout << maxBooks;
	return 0;
}


Measured memory_bytes: 6364
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int divideByPivot(int A[],int left,int right,int pivot){
	int start = left,end = right;
	while(true){
		while(A[start] < pivot && start <= right) start++;
		while(A[end] >= pivot && end >= left) end--;
		if(start >= end){
			break;
		}else{
			swap(A[start],A[end]);
		}
	}
	for(int i = left; i<= right; i++){
		if(A[i] >= pivot) return i;
	}
	return -1;	//must not reach here
}

int findPivot(int A[],int left,int right){
	int pivot_candidate = A[left];
	for(int i = left + 1; i <= right; i++){
		if(A[i] != pivot_candidate)
			return (A[i] > pivot_candidate)?A[i]:pivot_candidate;
	}
	return -1;
}


void quickSort(int A[],int left,int right){
	int pivot = findPivot(A,left,right);
	if(pivot != -1){
		int div_point = divideByPivot(A,left,right,pivot);
		if(left+1 < div_point)	quickSort(A,left,div_point-1);
		quickSort(A,div_point,right);
	}
}


int main(){

	int n,array[10000];
	long long sum;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		sum = 0;

		for(int i = 0; i < n; i++){
			scanf("%d",&array[i]);
		}

		quickSort(array,0,n-1);

		for(int i = 0; i <= n-2; i++){
			sum += (n-1-i)*array[i];
		}

		printf("%lld\n",sum);
	}

	return 0;
}

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

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

int find(string s, char ss){
    int c=0;
    for(int i=0; i<s.size(); i++) {
        if(s[i] == ss)
            c++;
    }
    return c;
}

int main() {
    string s;
    cin >> s;
    cout << min(find(s, '0'), find(s, '1'))*2;
}


Measured memory_bytes: 512
#include <iostream>

using std::cin;
using std::cout;

int n, i;
long long v, s, a;
const long long m = 1e9 + 7;

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (i = 0; i != n; ++i) {
    cin >> v;
    a = (a + v * s) % m;
    s = (s + v) % m;
  }
  cout << a;
  return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <limits>
using namespace std;

typedef pair< int, int > Pii;
const int kInf = numeric_limits< int >::max() / 2;

int H, W, S, T;
int u[33][33], sum[33][33];
Pii f[33][33][33][33];
bool vst[33][33][33][33];

void read_plate(void);
void preprocess(void);
void solve(void);
Pii & dp(int, int, int, int);

int main() {
  while (cin >> H >> W >> S, H + W + S) {
    read_plate();
    preprocess();
    solve();
  }

  return 0;
}

void read_plate(void) {
  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; ++j)
      cin >> u[i][j];
}

void preprocess(void) {
  fill(&sum[0][0], &sum[H + 1][0], 0);
  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; ++j)
      sum[i][j] = u[i][j] + sum[i][j - 1];
  for (int i = 1; i <= W; ++i)
    for (int j = 1; j <= H; ++j)
      sum[j][i] += sum[j - 1][i];
  T = sum[H][W];
}

void solve(void) {
  fill(&vst[0][0][0][0], &vst[H + 1][0][0][0], false);
  Pii &res = dp(1, 1, H, W);
  cout << res.first << " " << res.second << "\n";
}

Pii & dp(int x1, int y1, int x2, int y2) {
  if (vst[x1][y1][x2][y2])  return f[x1][y1][x2][y2];

  int rd, msd;
  Pii &c = f[x1][y1][x2][y2];

  vst[x1][y1][x2][y2] = true;
  c = make_pair(-kInf, -kInf);
  rd = sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
  msd = T - rd;
  if (msd <= S)
    c = make_pair(1, S - msd);

  for (int i = x1 + 1; i <= x2; ++i) {
    Pii &r1 = dp(x1, y1, i - 1, y2), &r2 = dp(i, y1, x2, y2);
    if (r1.first + r2.first > c.first)
      c.first = r1.first + r2.first, c.second = min(r1.second, r2.second);
    else if (r1.first + r2.first == c.first &&
             min(r1.second, r2.second) > c.second)
      c.second = min(r1.second, r2.second);
  }

  for (int i = y1 + 1; i <= y2; ++i) {
    Pii &r1 = dp(x1, y1, x2, i - 1), &r2 = dp(x1, i, x2, y2);
    if (r1.first + r2.first > c.first)
      c.first = r1.first + r2.first, c.second = min(r1.second, r2.second);
    else if (r1.first + r2.first == c.first &&
             min(r1.second, r2.second) > c.second)
      c.second = min(r1.second, r2.second);
  }

  return c;
}

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

using namespace std;

#define cin_desync()                                                           \
    do {                                                                       \
        ios_base::sync_with_stdio(false);                                      \
        cin.tie(0);                                                            \
    } while (0)

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

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

const int max_N = 1e5 + 10;
int H[max_N];
int dp[max_N];

int main() {
    cin_desync();

    int N, K;
    cin >> N >> K;
    for (int i = 1; i <= N; ++i) {
        cin >> H[i];
    }

    const int inf = 1e9 + 45;
    for (int i = 2; i <= N; ++i) {
        dp[i] = inf;
    }

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= K && (i + j) <= N; ++j) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(H[i] - H[j + i]));
        }
    }

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


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[30],b[28];
	for(int i=1;i<=30;i++){
		a[i-1]=i;
	}
	for(int i=0;i<28;i++){
		cin>>b[i];
	}
	sort(b,b+28);
	int c[2]={0},j=-1,k=-1;
	for(int i=0;i<28;i++){
		j++;
		if(a[i]!=b[j]){
			k++;
			c[k]=a[i];
			j--;
		}
		if(j==27){
			break;
		}
	}
	if(c[0]==0){
		c[0]=29;
	}
	if(c[1]==0){
		c[1]=30;
	}
	cout<<c[0]<<endl<<c[1]<<endl;
	return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;


int main() {
	int n;
	cin >> n;
	vector<vector<int>> d(n, vector<int>(n, -1));
	rep(i, n) {
		int a;
		cin >> a;
		rep(j, a) {
			int x, y;
			cin >> x >> y;
			x--;
			d[i][x] = y;
		}
	}

	int ans = 0;
	rep(bit, 1 << n) {
		vector<int> c(n);
		int now = 0;
		rep(i, n) {
			if (bit >> i & 1) {
				c[i] = 1;
				now++;
			}
		}
		bool ok = true;
		rep(i, n) {
			if (c[i] == 1) {
				rep(j, n) {
					if (d[i][j] == -1)continue;
					if (d[i][j] != c[j]) {
						ok = false;
						break;
					}
				}
			}
		}
		if (ok) ans = max(ans, now);
	}
	cout << ans << endl;
}


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

#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
	vector<bool> vec(30); int temp;
	while (cin >> temp) { vec[temp - 1] = true; }
	rep(i, 30) if (!vec[i]) cout << i + 1 << endl;
	return 0;
}


Measured memory_bytes: 3096
using System;
using System.Collections.Generic;

namespace RotN
{
    class Program
    {
        static void Main(string[] args)
        {
            List<char> alphabet = new List<char>("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
            var inputN = int.Parse(Console.ReadLine());
            var inputS = Console.ReadLine().ToCharArray();
            List <char>outputList = new List<char>();

            foreach(char letter in inputS)
            {
                int letterIndex = alphabet.FindIndex(x => x == letter);
                if (letterIndex + inputN > alphabet.Count - 1)
                {
                    int difference = inputN - (alphabet.Count - letterIndex);
                    outputList.Add(alphabet[0 + difference]);
                    continue;
                }
                outputList.Add(alphabet[letterIndex + inputN]);
            }

            string printOutput = string.Join("", outputList);          
            Console.WriteLine(printOutput);
        }
    }
}

Measured memory_bytes: 13312
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
   ll n, a, b;
   cin >> n >> a >> b;

   ll dif = b - a;
   
   if(!(dif&1)){
       cout << dif/2 << endl;
       return 0;
   }

   ll k1 = n-b;
   ll k2 = a-1;
   ll dif1 = n - (a+k1);
   ll dif2 = b-k2 - 1;

   if(dif1&1)dif1++;
   if(dif2&1)dif2++;

   dif1 /= 2;
   dif2 /= 2;
   cout << min(dif1+k1, dif2+k2) << endl;



}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline

def main():
    S = input().strip()
    K = int(input())
    D = [[] for _ in range(26)]
    for i,c in enumerate(S):
        d = D[ord(c)-ord("a")]
        for j in range(5):
            s = S[i:i+j+1]
            if s != "" and s not in d:
               d.append(s)
    for d in D:
        d.sort()

    k = 1
    for d in D:
        for s in d:
            if k == K:
                print(s)
                return
            k += 1

if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {

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

        if(a == b && b == c) {
        	System.out.println("No");
        }
        else if((a != b && b != c) && a != c) {
        	System.out.println("No");
        }
        else {
        	System.out.println("Yes");
        }

        sc.close();

	}

}

Measured memory_bytes: 35732
# coding: utf-8
# Your code here!
#wnmoabrbdxjqlwyrshyjpjrbhw
s=input()[::-1]
mincount=99999999
for i in range(len(s)):
    
    check=s[i]
    count=0
    _count=-1
    for j in range(i+1,len(s)):
        if s[j]!=check:
            count+=1
        else:
            _count=max(_count,count,i)
            count=0
    _count=max(_count,count,i)
    if _count!=-1:
        mincount=min(mincount,_count)
print(mincount)


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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

int n;
ll x;
ll a[100010];

int main(void){
	cin>>n>>x;
	for (int i = 0; i < n; i++) cin>>a[i];

	ll cnt = 0;
	for (int i = 0; i + 1 < n; i++) {
		if (x < a[i] + a[i + 1]) {
			cnt += a[i] + a[i + 1] - x;
			a[i + 1] = max(x - a[i], (ll)0);
		}
	}

	printf("%lld\n", cnt);
	
	return 0;
}

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

using ll = long long;

ll n, k;
vector<ll> w;

bool check(ll P) {
    ll sum;
    int idx = 0;
    for (int i = 0; i < k; ++i) {
        sum = 0;
        while (w.at(idx) + sum <= P) {
            sum += w.at(idx);
            ++idx;
            if (idx == n) return true;
        }
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    w.resize(n);
    ll sumw = 0;
    for (int i = 0; i < n; ++i) {
        cin >> w.at(i);
        sumw += w.at(i);
    }
    ll left = -1;
    ll right = sumw + 1;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        if (check(mid)) {
            right = mid;
        } else {
            left = mid;
        }
    }
    cout << right << endl;

    return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, y, k;
string s, t;

// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	vll a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(all(a));
	cout<<(ll)(a[0] * a[1] * 0.5);
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    COMinit();
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    cins(all(a));
    SORT(a);
    ll l = 0,r = 0;
    rep(i,n){
        (l += COM(n-i-1,k-1)*a[i])%=MOD;
        (r += COM(i,k-1)*a[i])%=MOD;
    }
    PRINT((r+MOD-l)%MOD);
}


Measured memory_bytes: 3328
#include<iostream>
#include<cstring>
//#include<bits/stdc++.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#define  si(a)       scanf("%d",&a)
#define  sl(a)       scanf("%lld",&a)
#define  sii(a,b)    scanf("%d%d",&a,&b)
#define  sll(a,b)    scanf("%lld%lld",&a,&b)
#define  queues      priority_queue
#define mod 998244353
#define mem(a)  memset(a,0,sizeof(a));
#define def(a) ((a)&(-a))
#define fi  first
#define se  second
#define mp  make_pair
#define  pb push_back
#define mem(a,b) memset(a,b,sizeof(a));
typedef long long ll;
//priority_queue<ll,vector<ll >,greater<ll > >q;
const int INF=0x3f3f3f3f;
//const double E=exp(1);
//const double PI=acos(-1);
using namespace std;
//__builtin_popcount
//priority_queue
const ll MAX=100000;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll kc(ll a,ll b)
{
    ll c=1;
    while(b)
    {
        if(b&1)c=(c*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return c;
}
bool cmp(double x,double y)
{
    return x>y;
}
ll F[50003*3];
ll Find(ll a)
{
    return F[a]<0?a:F[a]=Find(F[a]);
}
ll same(ll a,ll b)
{
    if(Find(a)==Find(b))return 1;
    return 0;
}
ll up1(ll a,ll b)
{
    ll x,y;
    x=Find(a);
    y=Find(b);
    if(x!=y)
        F[x]=y;
    return 0;
}
int read() {
    int x=0,f=1;char s=getchar();
    for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
    for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
    return x*f;
}ll a[100003];
ll  b[100003];
int main()
{
   // ios::sync_with_stdio(false);
    int t;
  cin>>t;
   for(int i=1;i<=t+1;i++)
    cin>>a[i];
    ll sum=0;
   for(int i=1;i<=t;i++)
   {
       cin>>b[i];
   }
   for(int i=1;i<=t;i++)
   { ll z=min(a[i],b[i]);
       sum+=z;b[i]-=z;
        z=min(a[i+1],b[i]);
       sum+=z;a[i+1]-=z;
 
   }cout<<sum;
}

Measured memory_bytes: 1792
s= input()

ans = 0
count = 0
for i in range(len(s)):
    if s[i]=='A':
        count+=1
    elif s[i]=='C':
        count+=1
    elif s[i]=='G':
        count+=1
    elif s[i]=='T':
        count+=1
    else:
        count=0
    ans = max(ans,count)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<s.size()-1;i++){
        if(s.at(i)!=s.at(i+1)){
            cnt++;
        }
    }
    cout<<cnt<<endl;





    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>

int main(){
	int n, p;
	std::cin >> n >> p;
	std::vector<int> v(n);
	int even = 0;
	int odd = 0;
	for(int i = 0; i < n; i++){
		std::cin >> v[i];
		if(v[i] % 2 == 0)even++;
		else odd++;
	}

	long long ans = 0;
	std::vector<long long> dp(50001, 0);
	

	dp[0] = true;
	for(int i = 0; i < n; i++){
		for(int j = 50000; j >= 0; j--){
			if(dp[j] > 0)dp[j + v[i]] += dp[j];
		}
	}

	for(int i = 0; i < 50001; i++){
		if(dp[i] && i % 2 == p)ans += dp[i];
	}
	std::cout << ans << std::endl;

}


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

int main(){
	char b;
	cin >> b;
	switch(b){
		case 'A':
			cout << 'T' << endl;
			break;
		case 'T':
			cout << 'A' << endl;
			break;
		case 'C':
			cout << 'G' << endl;
			break;
		case 'G':
			cout << 'C' << endl;
			break;
	}
	return 0;
}


Measured memory_bytes: 256
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
d=gets.chomp.split.map(&:to_i)

if (a.include?(d[0]) && a.include?(d[1]))||(b.include?(d[0]) && b.include?(d[1]))||(d[0]==d[1])
    puts "Yes"
else
    puts "No"
end



Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main(string[] args)
    {
        var vals = Console.ReadLine().ToCharArray();
        if (vals.Where(x => x == 'A').Count() == 3 || vals.Where(x => x == 'B').Count() == 3)
        {
            Console.WriteLine("No");
            return;
        }
        Console.WriteLine("Yes");
    }
}

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

using namespace std;

typedef long long ll;

ll s;
ll d = ((ll)1e9);

int main(){
  cin >> s;
  if(s == ((ll)1e18)){
    cout << 0 << " " << 0 << " ";
    cout << d << " " << 0 << " ";
    cout << 0 << " " << d << endl;
    return 0;
  }

  cout << 0 << " " << 1 << " ";
  cout << ((ll)1e9) << " " << 0 << " ";
  ll x = s%d;
  ll y = s/d;
  cout << x << " " << y+1 << endl;


}


Measured memory_bytes: 256
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))

ans = []
e = f = g = 0

for i in p:
    if i <= a:
        e += 1
    elif i >= a and i <= b:
        f += 1
    else:
        g += 1
ans.append(e)
ans.append(f)
ans.append(g)

print(min(ans))

Measured memory_bytes: 3064