akhauriyash/Code-Regression huggingface dataset:
def solve():
    import sys
    input = sys.stdin.readline

    mod = 10 ** 9 + 7
    n, k = map(int, input().split())
    pos, neg = [], []
    for x in map(int, input().split()):
        if x < 0:
            neg.append(x)
        else:
            pos.append(x)

    ans = 1
    neg.sort()
    pos.sort(reverse=True)
    neg_r = neg[::-1]
    lp, ln = len(pos), len(neg)

    if not pos and k & 1:
        for i in range(k):
            ans *= neg_r[i]
            ans %= mod
        print(ans)
        exit()

    x, y = 0, 0
    for i in range(k):
        if y >= ln:
            ans *= pos[x]
            ans %= mod
            x += 1
        elif x >= lp:
            ans *= neg[y]
            ans %= mod
            y += 1
        elif pos[x] >= -neg[y]:
            ans *= pos[x]
            ans %= mod
            x += 1
        else:
            ans *= neg[y]
            ans %= mod
            y += 1

    if n == k:
        print(ans)
        exit()

    if y & 1:
        ans_r = 1
        tmp1, tmp2 = -1, -1
        if y < ln and x != 0:
            tmp1 = neg[y] * neg[y - 1]
        if x < lp and y != 0:
            tmp2 = pos[x] * pos[x - 1]
        if tmp1 > tmp2:
            for i in range(x - 1):
                ans_r *= pos[i]
                ans_r %= mod
            for i in range(y + 1):
                ans_r *= neg[i]
                ans_r %= mod
        elif tmp1 <= tmp2:
            for i in range(x + 1):
                ans_r *= pos[i]
                ans_r %= mod
            for i in range(y - 1):
                ans_r *= neg[i]
                ans_r %= mod
        print(ans_r)
    else:
        print(ans % mod)


solve()


Measured memory_bytes: 104344
#include <bits/stdc++.h>  
using namespace std; 
string s;
bool b[4]={};

int main()  
{  
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='N')
            b[0]=true;
        if(s[i]=='W')
            b[1]=true;
        if(s[i]=='S')
            b[2]=true;
        if(s[i]=='E')
            b[3]=true;
    }
    if((b[0]^b[2])||(b[1]^b[3]))
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    ls = list(input())
    for i,now in enumerate(ls):
        if i%2 == 0:
            if now in ["R","U","D"]:
                pass
            else:
                print("No")
                exit()
        else:
            if now in ["L","U","D"]:
                pass
            else:
                print("No")
                exit()
    print("Yes")
if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
 
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define hello777 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <string>
#define pie 3.14159265358979323846
constexpr int MOD = 1e9+7;
const int MAX= 1e5+5;
using namespace std;


ll gcd(int a, int b)
{ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
// 
//ll lcm(int a, int b)  
// {  
//    return a/gcd(a, b) *b;  
// }
//  
//int prime(int n)
//{
//	rep(i,2,n+1)
//	{
//		if(n%i==0)return i;
//	}
//	
//vector<unordered_set<int> > prime_factors(MAX,unordered_set<int>());
//int primes[MAX];
//int prefix[MAX][6];
//void sieve(){
//    //primes i stores the largest prime factor of a number....
//    for(int i=2;i<MAX;++i){
//        if(primes[i]!=0){
//            continue;
//        }
//        primes[i] = i;
//        for(int j=2*i;j<MAX;j+=i){
//            primes[j] = i;
//        }
//    }
//    
//    for(int i=2;i<MAX;++i){
//        int current = i;
//        
//        while(current!=1){
//            prime_factors[i].insert(primes[current]);
//            current = current/primes[current];
//        }
//    }
//    
//    for(int i=1;i<MAX;++i){
//        for(int k=1;k<=5;++k){
//            prefix[i][k] = prefix[i-1][k] + (prime_factors[i].size()==k);
//        }
//    }
//    
//}
void solve() 
{
	ll n;
	cin>>n;
	ll ans=0,mx=-1,x;
	rep(i,0,n)
	{
		cin>>x;
		if(mx==-1)mx=x;
		else
		{
			if(x<mx)ans+=(mx-x);
		}
		mx=max(mx,x);
	}
	cout<<ans<<endl;
}

int main()
{
	hello777;
	int q=1;
	
//    cin>>q;
    while(q--)
    {   
      solve();
    }
}


Measured memory_bytes: 3640
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
 
using namespace std;
 
int main() {
  int n;
  scanf("%d", &n);
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    b[i] -= i;
  }
  sort(b.begin(), b.end());
  long long c = b[n / 2];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += abs(c - b[i]);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, p, q, na, nb, ra, rb, ta, tb, ans = 0;
  scanf("%lld", &n);
  ll x[n], y[n];
  set<ll> xs, ys;
  set<ll>::iterator it;
  for(i = 0; i < n; ++i) {
    scanf("%lld%lld", &x[i], &y[i]);
    xs.insert(x[i]), ys.insert(y[i]);
  }
  p = xs.size(), q = ys.size();
  ll uf[p + q], nx[p], ny[q], cx[p], cy[q], sx[p + q], sy[p + q], sum[p + q];
  for(i = 0, it = xs.begin(); i < p; ++i, ++it) nx[i] = *it, cx[i] = 0;
  for(i = 0, it = ys.begin(); i < q; ++i, ++it) ny[i] = *it, cy[i] = 0;
  for(i = 0; i < p + q; ++i) uf[i] = i, sx[i] = sy[i] = sum[i] = 0;
  for(i = 0; i < n; ++i) {
    na = lower_bound(nx, nx + p, x[i]) - nx, nb = lower_bound(ny, ny + q, y[i]) - ny;
    cx[na]++, cy[nb]++;
    ta = na, tb = nb + p, ra = rb = 0;
    while(ta != uf[ta]) ta = uf[ta], ra++;
    while(tb != uf[tb]) tb = uf[tb], rb++;
    if(ra < rb) uf[na] = tb, uf[ta] = tb;
    else uf[nb + p] = ta, uf[tb] = ta;
  }
  for(i = 0; i < p + q; ++i) {
    na = i;
    while(uf[na] != na) na = uf[na];
    uf[i] = na;
    if(i < p) sx[na]++, sum[na] += cx[i];
    else sy[na]++, sum[na] += cy[i - p];
  }
  for(i = 0; i < p + q; ++i) ans += sx[i] * sy[i] - sum[i] / 2;
  printf("%lld", ans);
  return 0;
}

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

using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b == 2 ? a : gcd(b, a % b);};
ll poww(ll a, ll b, ll md) {
   return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
const long long MOD = 1e9+7;
const int SIZE = 1e5+10;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    if(n==1) cout<<"0\n";
    else if(n==0) cout<<"1\n";










    return 0;
}




Measured memory_bytes: 3612
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const double PI = acos(-1);
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	lli r, g;
	cin >> r >> g;
	cout << 2*g - r << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int X, N;
  cin >> X >> N;
  if (N == 0)
  {
    cout << X << endl;
    return 0;
  }
  else
  {
    vector<int> p(N);
    for (auto &it : p)
      cin >> it;
    sort(p.begin(), p.end());
    if (!binary_search(p.begin(), p.end(), X))
    {
      cout << X << endl;
      return 0;
    }
    int idx = lower_bound(p.begin(), p.end(), X) - p.begin();
    if (idx == 0)
    {
      cout << X - 1 << endl;
    }
    else if (idx == N)
    {
      if (p[N - 1] != X - 1)
      {
        cout << X - 1 << endl;
        return 0;
      }
      else
      {
        cout << X + 1 << endl;
      }
    }
    else
    {
      int idx1 = idx - 1;
      int idx2 = idx + 1;
      cerr << idx << endl;
      cerr << idx1 << " " << idx2 << endl;
      cerr << p[idx1] << " " << p[idx2] << endl;
      for (int i = 1; i + X < 110; i++)
      {
        if (X - i != p[idx1])
        {
          cout << X - i << endl;
          return 0;
        }
        if (X + i != p[idx2])
        {
          cout << X + i << endl;
          return 0;
        }
        idx1 = max(0, idx1 - 1);
        idx2 = min(N - 1, idx2 + 1);
      }
    }
  }
  return 0;
}


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

public class ABC
{
    public static void Main()
    {
        string S = Console.ReadLine();
        int N = S.Length-1;
        long ans = 0;

        for(long bit = 0; bit < (1 << N); bit++)
        {
            string s = "";
            List<string> sum = new List<string>();

            for(int i = 0 ; i < S.Length ; i++)
            {
                s += S[i];
                if((bit & (1 << i)) == (1 << i))
                {
                    sum.Add(s);
                    s = "";
                }
            }
            sum.Add(s);
            foreach(string ss in sum)
            {
                ans += long.Parse(ss);
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c=0,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN(s);
  SORT(s);
  Yes(s=="abc");
}

Measured memory_bytes: 256
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    int n;
    cin>>n;
    ll xorsm = 0;
    vector<ll> vec(n);
    for(int i = 0; i < n; i++){
        cin>>vec[i];
        xorsm ^= vec[i];
    }
    if(xorsm == 0){
        cout<<"0";
        return ;
    }
    xorsm ^= (vec[0] ^ vec[1]);
    ll andbit = (vec[0]+vec[1]) - xorsm;
    // cout<<andbit;
    if(andbit < 0 || andbit/2 > vec[0]){    // andbit/2 the bit that should be present in both the numbers
        cout<<"-1";
        return ;
    }
    andbit /= 2;
    {
        ll fst = andbit;
        for(int i = 42; i >= 0; i--){
            if((xorsm&(1ll<<i)) && (1ll<<i) != andbit && fst + (1ll<<i) < vec[0])
                fst += (1ll<<i);
        }
        if(fst == 0 || (fst^(vec[1]+vec[0]-fst))!=xorsm){
            cout<<"-1";
            return ;
        }
        cout<<vec[0] - fst;
    }

}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

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


int main(){
    int a[3][3];
    rep(i,3){
      rep(j,3){
        cin>>a[i][j];
        
      }
    }
    if(a[1][0]-a[0][0]==a[1][1]-a[0][1]&&a[1][0]-a[0][0]==a[1][2]-a[0][2]&&
       a[2][0]-a[0][0]==a[2][1]-a[0][1]&&a[2][2]-a[0][2]==a[2][1]-a[0][1])
       cout<< "Yes" << endl;
    else cout << "No" <<endl;

   }

Measured memory_bytes: 256
N= int(input())
H=list(map(int, input().split()))
old=H[-1]
flag=0
for h in (reversed(H)):
    new = h
    if new > old:
        new=h-1
    if new > old:
        flag=1
        break
    
    old=new

if flag==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14224
private fun solve(T: List<Long>, A: List<Long>, B: List<Long>, a: Long, b: Long) {
    if (A[0] >= B[0]) {
        println(0)
        return
    }

    val c = a - b
    val m = T[0] * (B[0] - A[0])
    val l = (m + c - 1) / c

    println(2 * l - (if (m % c == 0L) 0 else 1))
}

fun main(args: Array<String>) {
    val T = readLine()!!.split(" ").map{it.toLong()}
    val A = readLine()!!.split(" ").map{it.toLong()}
    val B = readLine()!!.split(" ").map{it.toLong()}

    val a = A[0] * T[0] + A[1] * T[1]
    val b = B[0] * T[0] + B[1] * T[1]

    if (a == b) {
        println("infinity")
        return
    }

    if (a >= b) {
        solve(T, A, B, a, b)
    } else {
        solve(T, B, A, b, a)
    }
}


Measured memory_bytes: 38004
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
using namespace std;

int N, M;
vector<vector<int>> graph(100000);
vector<int> dp(100000, -1);

int search(int n){
  if (dp[n] == -1) {
    int ans = 0;
    for (int x : graph[n]) ans = max(ans, search(x) + 1);
    dp[n] = ans;
  }
  
  return dp[n];
}

int main() {
  cin >> N >> M;
  rep(i, 0, M) {
    int x, y;
    cin >> x >> y;
    graph[x - 1].push_back(y - 1);
  }
  
  int ans = 0;
  rep(i, 0, N) ans = max(ans, search(i));
  
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    int xmax=X, ymin=Y;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        xmax = max(xmax, x);
    }
    for (int i = 0; i < M; i++) {
        int y;
        cin >> y;
        ymin = min(ymin, y);
    }

    if (xmax < ymin) {
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; int K; cin>>N>>K;
  vector<int> S(N);
  for(int i=0; i<N; i++){
    cin>>S.at(i);
  }
  sort(S.begin(),S.end());
  reverse(S.begin(),S.end());
  int L=0;
  for(int i=0; i<K; i++){
    L+=S.at(i);
  }
  cout<<L<<endl;
}

Measured memory_bytes: 3584
from math import sqrt

n = int(input())
while n:
    xa, ya, ra, xb, yb, rb = map(float, input().split())
    d = sqrt((xb - xa) ** 2 + (yb - ya) ** 2)
    if ra > d + rb:
        print(2)
    elif rb > d + ra:
        print(-2)
    elif d > ra + rb:
        print(0)
    else:
        print(1)

    n -= 1

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(m), c(m);
  vector< pair<int, int> > v;
  for (int i = 0; i < m; i++) {
    cin >> b[i] >> c[i];
    v.push_back({c[i], b[i]});
  }
  sort(a.begin(), a.end());
  sort(v.rbegin(), v.rend());
  int ptr = 0;
  for (int i = 0; i < m && ptr < n; i++) {
    while (ptr < n && v[i].second > 0) {
      if (a[ptr] < v[i].first) {
        a[ptr] = v[i].first;
        v[i].second--;
      }
      ptr++;
    }
  }
  long long ans = 0;
  for (auto& x : a) {
    ans += (long long) x;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 2552
#include <stdio.h>

int main(){

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

    if(sum>=h){
        printf("Yes");
        return 0;
    }

    printf("No");

    return 0;
}

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

int main(){
    int h,w;
    bool flag = true;
    cin>>h>>w;
    vector<vector<char>> cam(h+2,vector<char>(w+2));

    for(int i=0; i<h+2; i += h+2){
        for(int j=0; j<w+2; j++){
            cam[i][j] = '.';
        }
    }

    for(int i=0; i<h+2; i++){
        for(int j=0; j<w+2; j+= w+2){
            cam[i][j] = '.';
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>cam[i][j];
        }
    }

    for(int i=1; i<h+1; i++){
        for(int j=1; j<w+1; j++){
            if(cam[i][j] == '#'){
                if(cam[i-1][j] == '.' && cam[i][j-1] == '.'
                    && cam[i+1][j] == '.' && cam[i][j+1] == '.'){
                        flag = false;
                        break;
                    }
            }
        }
    }

    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

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

long long int f(const long long int x){
    long long int res = 0;
    for(int i = 1; i <= 40; ++i){
        long long int n = 1LL<<i;
        long long int c = ((x+1)/n)*(n/2);
        c += max(0LL, ((x+1)%n)-(n/2));

        if(c & 1) res += n>>1;
    }

    return res;
}

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

    long long int ans = f(A-1)^f(B);
    cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    int S[n];
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }
    int q;
    cin >> q;
    int T[q];
    for (int i = 0; i < q; i++) {
        cin >> T[i];
    }

    int c = 0;
    for (int i = 0; i < q; i++) {
        int left = 0, right = n, mid;
        while (left < right) {
            mid = (left + right) / 2;
            if (S[mid] == T[i]) {
                c++;
                break;
            } else if (T[i] < S[mid]) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
    }

    cout << c << endl;

    return 0;
}



Measured memory_bytes: 3608
import java.util.*;

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

    int n = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<>();
    for (int i = 0; i < n; i++){
      list.add(sc.nextInt());
    }

    Collections.sort(list);

    int ans = 0;
    for (int b = 0; b < n; b++){
      for (int a = 0; a < b; a++){
        int key = list.get(b) + list.get(a);
        int idx = ~Collections.binarySearch(list, key, (x,y)->x.compareTo(y)>=0?1:-1);
        if (idx > 0){
	        ans = ans + idx - (b + 1);
        }
      }
    }

    System.out.println(ans);

  }
}

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

using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-8
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
const ll mod = 1e9 + 9;
const ll maxn = 2e5 + 10;
signed main(){
	int n, m;
	cin >> n >> m;
	cout << m * (m-1)/2 + n*(n-1)/2 << endl;
}

Measured memory_bytes: 256
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll N, K;
    cin >> N >> K;
    ll count = 1;
    while (N >= K)
    {
        N = N / K;
        count++;
    }
    cout << count << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,d;
    cin >> h >> w >> d;
    d++;
    int cri = h+w;
    int loop = cri / (d-1) + 1;
    int ln = loop*(d-1);
    vector<vector<int> > vec(ln);
    vector<int> vec1(ln),vec2(ln);
    rep(i,ln/(d-1)){
        if(i % 2 == 0){
            rep(j,d-1){
                vec1[i*(d-1)+j] = 0;
            }
        }else{
            rep(j,d-1){
                vec1[i*(d-1)+j] = 1;
            }
        }
    }
    rep(i,ln/(d-1)){
        if(i % 2 == 0){
            rep(j,d-1){
                vec2[i*(d-1)+j] = 2;
            }
        }else{
            rep(j,d-1){
                vec2[i*(d-1)+j] = 3;
            }
        }
    }
    rep(i,ln/(d-1)){
        if(i % 2 == 0){
            rep(j,d-1){
                vec[i*(d-1)+j] = vec1;
            }
        }else{
            rep(j,d-1){
                vec[i*(d-1)+j] = vec2;
            }
        }
    }
    // rep(i,ln){
    //     rep(j,ln){
    //         cout << vec[i][j];
    //     }
    //     cout << endl;
    // }
    vector<vector<int> > ans(h,vector<int>(w));
    rep(i,h){
        rep(j,w){
            ans[i][j] = vec[i+j][h-1+j-i];
        }
    }
    string ss = "RYGB";
    rep(i,h){
        rep(j,w){
            cout << ss[ans[i][j]];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 17152
using System;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;

class program{
    static void Main(string[] args){
         program p= new program();
         p.Run();
    }
    void Run(){
      int[] ab=Readint();
      int res=ab[1];
      if(ab[0]<6){
        res=0;
      }else if(ab[0]<13){
        res=(int)(res/2);
      }
      WriteLine(res.ToString());
    }
    int[] Readint(){
        
        string[] inp= ReadLine().Split();
        int n=inp.Length;
        int[] res=new int[n];
        for(int i=0;i<n;i++){
             res[i]=int.Parse(inp[i]);
        }
        return res;
    }
}

Measured memory_bytes: 11092
#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>;

int main() {
  int a;
  cin>>a;
  cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {

    ll N;
    cin >> N;

    ll ans = 0;
    ll m = 2000010;
    ll p;
    for (int i = 0; i < N; i++) {
        cin >> p;
        m = min(m, p);
        if (p <= m) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
	for (int x, y; std::cin >> x >> y, x || y;)
	{
		if (x < y)
		{
			std::cout << x << " " << y << std::endl;
		}
		else
		{
			std::cout << y << " " << x << std::endl;
		}
	}
	return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b)
{
    return b ? gcd(b, a % b) : a;
}
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void func(long long A, long long B, long long C, long long X)
{
    int cnt = 0;
    for (int a = 0; a <= A; a++)
        for (int b = 0; b <= B; b++)
            for (int c = 0; c <= C; c++) {
                int total = a * 500 + b * 100 + c * 50;
                if (total == X)
                    cnt++;
            }

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

int main()
{
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    long long X;
    scanf("%lld", &X);
    func(A, B, C, X);
    return 0;
}


Measured memory_bytes: 256
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n = int(input())
    a_s = list(map(int, input().split()))

    ans = [0]
    for i in range(n - 1):
        ans.append((a_s[i] * 2) - ans[i])

    add = a_s[-1] - ans[-1] // 2

    ans = [add]
    for i in range(n - 1):
        ans.append((a_s[i] * 2) - ans[i])

    print(*ans)


# テストクラス


class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
2 2 4"""
        output = """4 0 4"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """5
3 8 7 5 5"""
        output = """2 4 12 2 8"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """3
1000000000 1000000000 0"""
        output = """0 2000000000 0"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 104012
#include <stdio.h>

int main(void){
	int a[100]={0};
	int n;
	int i;
	scanf("%d",&n);
		
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		if(i) printf(" ");
		printf("%d",a[n-i-1]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define ll long long
const long long INF = 1LL << 60;

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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd



int main() {
	ll n;
	ll a[5];
	cin >>n>> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
	ll max = 0;
	for (int i = 0; i < 5; i++) {
		if (n%a[i] != 0) {
			if (max < n / a[i] + 1)max = n / a[i]+1;
		}
		else {
			if (max < n / a[i] )max = n / a[i];
		}
	}
	cout << max + 4;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
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 ll INF = 1LL << 60;

int main(){
	int n, k;
	cin >> n >> k;
	int x[n];
	for(int i = 0; i < n; ++i) cin >> x[i];
	int ans = 0;
	for(int i = 0; i < n; ++i){
		ans += min(x[i], k - x[i]) * 2;
	}
	cout << ans << endl;
}


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

using namespace std;

int main()
{
	double x;
	string u;
	int n;
	double ans = 0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x >> u;
		if (u == "JPY") {
			ans += x;
		}
		else {
			ans += x * 380000.0;
		}
	}

	printf("%lf\n", ans);

	return 0;
}


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

ll M=1e9+7;
ll N=2*(1e5)+10;
vector<ll>fact(N);
vector<ll>ifact(N);
ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power((x*x)%M,n/2);
    else                             //n is odd
        return (x*power((x*x)%M,(n-1)/2))%M;

}
ll comb(ll n,ll r)
{
	if(n==0 && r==0)
	return 1;
	if(n<r || n<0)
	return 0;
	
	ll res= (ifact[n-r]%M*ifact[r]%M)%M;
	return( res*fact[n])%M;
}

int main() {
	// your code goes here
	ll n,k;
	cin>>n>>k;
	
	fact[0]=1;
	ifact[0]=1;
	for(int i=0;i<=N;i++)
	{
		fact[i+1]=(fact[i]*(i+1))%M;
		ifact[i+1]=(ifact[i]*power(i+1,M-2))%M;
	}
	
	ll ans=0;
	k=min(k,n-1);
	for(int i=0;i<=k;i++)
	{
		ans=(ans%M + (comb(n,i)*comb(n-1,i))%M)%M;
	}
	cout<<ans;
	
	
	return 0;
}

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

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

  ll H, W;
  cin >> H >> W;
  if (H == 1 || W == 1)
    cout << 1 << endl;
  else {
    ll ro = (H + 1) / 2;
    ll re = H - ro;
    ll ans = (ro * ((W + 1) / 2)) + (re * (W / 2));
    cout << ans << endl;
  }
}


Measured memory_bytes: 3608
// https://atcoder.jp/contests/abc146/tasks/abc146_d

/*

đồ thị duyệt (check visited) theo cạnh, nhưng bỏ vào & lấy ra queue là 1 pair gồm đỉnh và màu của cạnh đi từ u tới cạnh đang xét đó (vì đây là tree, nên giữa 2 đỉnh chỉ lun có 1 cạnh)
    0 là chưa visit

problem 1 : trùng cạnh
từ đỉnh v, đánh số các cạnh kề nó từ 1 trở lên, nhưng check thêm nếu nó trùng với cạnh u-v thì tăng lên 1 đơn vị

problem 2 : dùng số (đánh)

Note : Do bài này là cây nên BFS dùng đc

*/

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define MAX 100001

vector<pair<int, int> > graph[MAX];
int visited[MAX+1];

int ans = 0;

void BFS(int s)
{
	queue<pair<int, int> > q;

	q.push(make_pair(s, 0));
	// ở đây là duyệt theo cạnh chứ ko phải đỉnh, nên nếu visited(s) = true thì sẽ bị sai

	while(!q.empty())
	{
		int color = 0; // reset

		pair<int, int> u = q.front();
		q.pop();

		for(int i = 0; i < graph[u.first].size(); i++)
		{
			pair<int, int> v = graph[u.first][i];
			if(visited[v.second] == 0)
			{
				color++;
				if(color == u.second)
					visited[v.second] = ++color;
				else
					visited[v.second] = color;
				q.push(make_pair(v.first, color));
			}
		}

		ans = max(ans, color);
	}
}

int main()
{
	int N;

	cin >> N;

	for(int i = 1; i <= N-1; i++)
	{
		int u, v;
		cin >> u >> v;

		graph[v].push_back(pair<int, int>(u, i));
		graph[u].push_back(pair<int, int>(v, i));
	}

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

	BFS(1);

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

	return 0;
}

Measured memory_bytes: 7040
n = int(input())
s = []
for _ in range(n):
    s.append(int(input()))
ans = sum(s) if sum(s) % 10 != 0 else 0
check = 0
for i in range(len(s)):
    check = sum(s[:i]) + sum(s[i+1:])
    ans = max(ans,(check if check % 10 != 0 else 0))
print(ans)

Measured memory_bytes: 9196
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int left = a+b;
  int right = c+d;
  if (left > right) cout << "Left" << endl;
  else if (left == right) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}
 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  	int s;
  	cin >> s;
	string n;
  	cin >> n;
  	if (size(n) <= s) cout << n;
  	else {for(int i=0;i<s;i++)cout << n.at(i);
   cout <<"..."<<endl;
         }
	}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

//方針
//前からずっとシミュレーションして、
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> num(n, vector<int>(26));
    rep(i, n)
    {
        string hoge;
        cin >> hoge;
        rep(j, 26)
        {
            num[i][j] = 0;
        }
        rep(j, hoge.size())
        {
            num[i][(int)(hoge[j] - 'a')]++;
        }
    }
    int ans[26] = {0};
    if (DEBUG)
        cout << "fuck" << endl;
    rep(i, 26)
    {
        int huga = INT_MAX;
        rep(j, n)
        {
            huga = min(huga, num[j][i]);
        }
        ans[i] = huga;
    }
    rep(i, 26)
    {
        int huga = ans[i];
        rep(j, huga)
        {
            cout << (char)(i + 'a');
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/

// problink link : https://atcoder.jp/contests/abc063/tasks/arc075_b 

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){ 
    int n,a,b;
    cin >> n >> a >> b ;
    int  s[n];
    for (int &i: s) cin >> i ; 
    int  l = 0, r = 1000000000 ; 
    while (l+1<r){
        int m=(l+r)>>1;
        int sum=0;
        for (int i=0;i<n;i++){
            sum += max(0LL,(s[i]-b*m+(a-b)-1)/(a-b));
        }
        if (sum<=m)  r = m ; 
        else  l = m ; 
    }
    cout << r << endl;
} 

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 4412
import java.util.*;

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

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

		int[][] ans = new int[r+1][c+1];
		for(int i = 0; i < num.length; i++){
			for(int j = 0; j < num[i].length; j++){
				ans[i][j] = num[i][j];
				ans[i][c] += num[i][j];
				ans[r][j] += num[i][j];
				ans[r][c] += num[i][j];
			}
		}
		for(int i = 0; i < ans.length; i++){
			for(int j = 0; j < ans[i].length; j++){
				if(j == ans[i].length - 1){
					System.out.printf("%d\n",ans[i][j]);
				}else{
					System.out.printf("%d ",ans[i][j]);
				}
			}
		}
	}
}




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

long long ans = 0;

void dfs(int v,vector<vector<int>> &map,int n,vector<bool> &seen)
{
    int i;
    bool flag = true;
    for(i = 0;i < n;++i){
        if(!seen.at(i)){
            flag = false;
            break;
        }
    }
    if(flag){
        ++ans;
        return;
    }
    for(int x:map.at(v)){
        if(seen.at(x)){
            continue;
        }else{
            seen.at(x) = true;
            dfs(x,map,n,seen);
            seen.at(x) = false;
        }
    }
    return;
}

int main()
{
    int n,m;
    int i,j;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    for(i = 0;i < m;++i){
        cin >> a.at(i) >> b.at(i);
    }
    vector<vector<int>> map(n);
    for(i = 0;i < m;++i){
        map.at(a.at(i)-1).push_back(b.at(i)-1);
        map.at(b.at(i)-1).push_back(a.at(i)-1);
    }
    vector<bool> seen(n,false);
    seen.at(0) = true;
    dfs(0,map,n,seen);
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  char s[n + 1];
  cin >> s;
  int cnt = 0;
  for(int i = 1; i < n; i++) {
    if (s[i] != 'W') {
      cnt++;
    }
  }
  int min = cnt;
  for(int i = 1; i <= n-1; i++) {
    if (s[i - 1] != 'E') {
      cnt++;
    }
    if (s[i] != 'W') {
      cnt--;
    }
    if (min > cnt) {
      min = cnt;
    }
  }
  cout << min;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,k,s=0;cin>>a>>b>>c>>k;
  if(a>=k)s=k;
  else if(a+b>=k)s=a;
  else s=a-(k-a-b);
  cout<<s<<endl;
}

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

using namespace std;
const int mod=1000000007;

long long modinv(long long a){
	long long b=mod,u=1,v=0;
  	while(b){
      long long t=a/b;
      a-=t*b;
      swap(a,b);
      u-=t*v;
      swap(u,v);
    }
  	u%=mod;
  	if(u<0) u+=mod;
  	return u;
}

long long dev(long long a,long long b){
	return (a*modinv(b))%mod;
}

long long comb(int x,int y){
  long long tmp=1;
	for(int i=0;i<y;i++){
    	tmp=dev(tmp*(x-i)%mod,i+1);
    }	 
  return tmp;
}

int main(){
	long long N,K; cin>>N>>K;
  
  	for(int i=1;i<=K;i++){
    	printf("%lld\n",(comb(N-K+1,i)*comb(K-1,i-1))%mod);
    }
}


Measured memory_bytes: 256
read N M
maru_data=$(cat)


c_d=$(echo $maru_data | grep -o -E "\-?[0-9]+ \-?[0-9]+"|tail -n $M)

echo $maru_data | grep -o -E "\-?[0-9]+ \-?[0-9]+"|head -n $N|
    awk ' {print("mae awk sqt {print(abs("$1"-one) + abs("$2"-two))} sqt ato")}' |
    sed "s/sqt/\'/g" | sed 's/one/$1/g' |sed 's/two/$2/g' | sed 's/abs\(([^\)]*)\)/sqrt((\1)^2)/g'|
    sed "s/mae/echo $(echo $c_d) | grep -o -E '\\\-?[0-9]+ \\\-?[0-9]+' |/g" |
    sed 's/ato/| cat -n | sort -n -s -k 2|head -n 1|cut  -f 1/g' | bash | tr -d " "




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

#define o(output) cout << output << endl
#define priolity_queue pq
#define push p
#define top t

using namespace std;

string s;
int a,b,c,d;
char A,B;

int main(){
  cin>>s;
  cout<<s[0]<<s.size()-2<<s[s.size()-1];
}

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

using namespace std;

int main(){
  int N, M;
  int X[100010];
  int diff[100010];
  int ans=0;
  cin >> N >> M;
  for(int i=0; i<M; i++) cin >> X[i];
  sort(X, X+M);
  for(int i=0; i<M-1; i++) diff[i]=X[i+1]-X[i];
  sort(diff, diff+M-1);
  for(int i=0; i<M-N; i++) ans+=diff[i];
  cout << ans << endl;
  return 0;
}

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

int main() {

  string s,ans;
  int index=0;
  cin >> s;

  for(int i=0; i<s.size(); i++) {
    char key = s[i];
    if(key == '0') {
      ans.insert(index,"0");
      index++;
    }else if(key == '1') {
      ans.insert(index,"1");
      index++;
    }else{
      if(index != 0) {
        index--;
        ans.erase(index,1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 764
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const lint INF=1e18;

int n;
lint L,t;
lint ar[100005];
lint dp[100005];
lint dp2[100005];
int main(){
  cin>>n>>L>>t;
  REP(i,n) scanf("%lld",&ar[i]);
  ar[n]=L;

  ++n;
  REP(i,n+1) dp[i]=dp2[i]=INF;
  dp[0]=ar[0];

  int j=0;
  REP(i,n){
    if(i>0) chmin(dp[i],dp2[i]+ar[i]+ar[i-1]*2);
    chmin(dp2[i+1],dp2[i]);
    while(j+1<n && (ar[j]-ar[i])*2<=t) ++j;
    if(j+1<n){
      chmin(dp2[j+1],dp[i]-ar[i]*3);
    }
    chmin(dp[j],dp[i]+t+ar[j]-ar[i]);
  }
  lint res=dp[n-1];
  cout<<res<<endl;
  return 0;
}





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

using namespace std;
using ll = long long;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

int main() {
  string S;
  cin >> S;
  int mae = stoi(S.substr(0,2));
  int ato = stoi(S.substr(2,2));

  bool mmyy = false, yymm = false;
  if (mae > 0 && mae <= 12) {
    mmyy = true;
  }
  if (ato > 0 && ato <= 12) {
    yymm = true;
  }
  
  if (mmyy&&yymm) {
    cout << "AMBIGUOUS" << endl;
  } else if (mmyy) {
    cout << "MMYY" << endl;
  } else if (yymm) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;



int main(void){
    ll n;
    string s;
    cin>>n>>s;
    map<char,ll>m;
    for(int i=0;i<n;i++)m[s[i]]++;
    ll ans = 1;
    for(auto itr = m.begin();itr!=m.end();++itr){
        ans = (ans*(itr->second+1))%mod;
    }
    cout<<(ans-1+mod)%mod<<endl;
	return 0; 
}

Measured memory_bytes: 512
TRUMP = [[i+1 for i in range(13)] for j in range(4)]
Keep_card =[]
n = int(input())

for _ in range(n):
    Mark,No = input().split()
    No = int(No)
    if Mark == "S":
        TRUMP[0][No-1] = "Keep"

    if Mark == "H":
        TRUMP[1][No-1] = "Keep"    

    if Mark == "C":
        TRUMP[2][No-1] = "Keep"

    if Mark == "D":
        TRUMP[3][No-1] = "Keep"

for Mark_no in range(4):
    for level_no in range(13):
        if not TRUMP[Mark_no][level_no] == "Keep":
            if Mark_no == 0:
                print("S ",end="")
                print(str(TRUMP[Mark_no][level_no]))

            if Mark_no == 1:
                print("H ",end="")
                print(str(TRUMP[Mark_no][level_no]))

            if Mark_no == 2:
                print("C ",end="")
                print(str(TRUMP[Mark_no][level_no]))

            if Mark_no == 3:
                print("D ",end="")
                print(str(TRUMP[Mark_no][level_no]))


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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
import sys
from pprint import pprint
import heapq

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(N, M, inputs):
    jobs = list(map(string_to_int, inputs))
    jobs.sort(key=lambda x: x[0], reverse=True)
    selectable = []
    money = 0
    for day in range(1, M + 1):
        while len(jobs) != 0 and jobs[-1][0] <= day:
            heapq.heappush(selectable, jobs.pop()[1] * -1)
        if len(selectable) != 0:
            money += heapq.heappop(selectable) * -1
    return money


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N, M] = string_to_int(input())
    ret = solve(N, M, inputs(N))
    print(ret)


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

N,X=map(int, input().split())
L=list(map(int, input().split()))

D = 0
for i in range(N):
    D = D + L[i]
    if D > X:
        print(i+1)
        break
    if i == N-1:
        print(i+2)


Measured memory_bytes: 2940