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

int main(){

    int n,x;
    cin>>n>>x;
    int ans=1;
    vector<int> l(n),d(n+1,0);
    for(int i=0;i<n;i++) cin>>l[i];

    for(int i=1;i<=n;i++){
        d[i]=d[i-1]+l[i-1];
        if(d[i]<=x) ans++;
    }
    cout<<ans<<endl;





    return 0;
}

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

int func(int x) {
    int res = 0;
    while (x % 100 == 0) {
        x /= 100;
        ++res;
    }
    return res;
}

int main() {

    int d, n;
    cin >> d >> n;
    int cnt = 0;
    int val = 0;
    while (cnt < n) {
        ++val;
        if (func(val) == d) ++cnt;
    }
    cout << val << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

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

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N,A,B = II()

if (A-B)%2==0:
    print(abs((A-B)//2))
else:
    a = min(A,B)
    b = max(A,B)
    n1 = a + (b-a-1)//2
    n2 = (N-b+1) + (b-a-1)//2
    print(min(n1,n2))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  ll c = 0;
  rep(i, s.size()) {
    if(c == 0) {
      if(s[i] == 'C') c++;
    } else if(s[i] == 'F')
      c++;
  }
  cout << (c >= 2 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<long long, long long>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename T>
void printvec(vector<T> &ar){
    for(T i: ar) cout << i << " ";
    cout << endl;
}

int main(){
    int a, b; cin >> a >> b;
    int c;
    if (b < 10) c = 10 * a + b;
    else if (b < 100) c = 100 * a + b;
    else c = 1000 * a + b;
    int nc = pow(c,0.5);
    if (nc * nc == c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;



int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	cout << a[n-1] - a[0] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

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

  const double TAX_A = 0.08, TAX_B = 0.1;

  for (double i = 0; i < 10000; i++) {
    if (floor(TAX_A * i) == a && floor(TAX_B * i) == b) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) ((a).begin(), (a).end())
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  rep(i, A) cin >> a[i];
  vector<int> b(B);
  rep(i, B) cin >> b[i];
  vector<int> x(M);
  vector<int> y(M);
  vector<int> c(M);
  rep(i, M) {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--;
    y[i]--;
  }
  int miA = *min_element(a.begin(), a.end());
  int miB = *min_element(b.begin(), b.end());
  int res = miA + miB;
  rep(i, M) {
    int total = a[x[i]] + b[y[i]] - c[i];
    res = min(total, res);
  }
  cout << res << endl;
}

Measured memory_bytes: 2176
n = int(input())
b = list(map(int, input().split()))
a = [0]*n
a[0] = b[0]

for i in range(1, n - 1):
    if b[i - 1] < b[i]:
        a[i] = b[i - 1]
    else:
        a[i] = b[i]
a[n - 1] = b[n - 2] 

print(sum(a))

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

int checkSize( int X );
int F( int A, int B );

int main( void )
{
  long int N;
  int max, min;
  long int A, B;
  
  cin >> N;
  
  min = 1000;

  for( long int i = 1; i * i <= N; i++ ) {
    
    //test
    //cout << i << endl;
    
    if( i * ( N / i ) == N ) {
      A = i;
      B = N / i;
      
      //if( A > B )
      //break;
      if( N % A != 0 ) {
	continue;
      }
      max = F( A, B );
      
      if( max < min )
	min = max;
    }
  }

  cout << min << endl;
}

int F( int A, int B )
{
  A = checkSize( A );
  B = checkSize( B );

  if( A > B )
    return A;
  else
    return B;
}

int checkSize( int X )
{
  int count = 0;
  
  while( X ) {
    X /= 10;
    count++;
  }
  return count;
}


Measured memory_bytes: 3592
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val S = scala.io.StdIn.readLine()

    if (S.groupBy(identity).mapValues(_.length).forall(p => p._2 == 2))
      println("Yes")
    else
      println("No")
  }

}

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

int main() {
    double n, k;
    cin >> n >> k;

    vector<ll> arr(n);
    for (int i = 0; i < n; i++) {
        ll x; cin >> x;
        arr[i] = (x + 1.0) / 2.0;
    }

    ll ans = 0;
    for (int i = 0; i < k; i++) ans += arr[i];
    ll temp = ans;

    for (int i = k; i < n; i++) {
        temp = temp + arr[i] - arr[i-k];
        ans = max(ans, temp);
    }

    printf("%0.7Lf\n", ans);
    return 0;
}


Measured memory_bytes: 6504
import math
import copy

####################
def prime_decomposition(n):
  i = 2
  X = {}
  while i * i <= n:
    while n % i == 0:
      n /= i
      if i in X:
        X[i] = X[i] + 1
      else:
        X[i] = 1
    i += 1
  if n > 1:
    X[n] = 1
  return X

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n;

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p;
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result;

####################
  
N,M = list(map(int, input().split()))

X = prime_decomposition(M)
       
sum = 1
for i in X.values():
  sum = (sum * cmb(i + N - 1, i) % 1000000007) % 1000000007
  
print(sum)

Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++) cin >> A[i];
  
  int min_A = INF;
  int max_A = -INF;
  for(int i=0;i<N;i++){
    min_A = min(min_A, A[i]);
    max_A = max(max_A, A[i]);
  }
  
  int cost = INF;
  for(int i=min_A;i<=max_A;i++){
    int now = 0;
    for(int j=0;j<N;j++){ now += (i-A[j])*(i-A[j]); }
    cost = min(cost, now);
  }
  
  cout << cost << "\n";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Atcoderrrrrr
    {
        static void Main(string[] args)
        {
            string c =　Console.ReadLine();

            if (c[0] == 'a'|| c[0]=='i' || c[0]=='u' || c[0] == 'e' || c[0] == 'o')
            {
                Console.WriteLine("vowel");
            }
            else
            {
                Console.WriteLine("consonant");
            }
        }
    }
}

Measured memory_bytes: 11092
import java.util.Arrays;

import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		 
		int cntNums[] = new int[3];
		 
		 
		for(int i = 0; i <= 2; i++){
		    
			int inputNums = sc.nextInt();
		    cntNums[i] = inputNums;
		 
		}
		 
		Arrays.sort(cntNums);
		 
		System.out.println(cntNums[0] + cntNums[1]);
	
	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

const int MaxN = 100;
const int MaxM = 10000000;
const int MaxNV = MaxN * 2;

int n;
bool f[MaxM + 2];

int nL, qL[MaxNV + 1];
int nR, qR[MaxNV + 1];

bool mat[MaxNV + 1][MaxNV + 1];

bool bookR[MaxNV + 1];
int mateR[MaxNV + 1];

int pri_n, pri[MaxM / 8];
bool book[MaxM + 2];

inline void init_sieve(int n = MaxM + 1)
{
	book[1] = true;
	for (int i = 2; i <= n; ++i)
	{
		if (!book[i])
			pri[pri_n++] = i;

		for (int j = 0; j < pri_n; ++j)
		{
			int p = pri[j], d = i * p;
			if (d > n)
				break;
			book[d] = true;

			if (i % p == 0)
				break;
		}
	}
}

bool match(const int &u)
{
	for (int v = 1; v <= nR; ++v)
		if (mat[u][v] && !bookR[v])
		{
			bookR[v] = true;
			if (!mateR[v] || match(mateR[v]))
			{
				mateR[v] = u;
				return true;
			}
		}
	return false;
}

int main()
{
	init_sieve();

	cin >> n;
	for (int i = 0, x; i < n; ++i)
	{
		cin >> x;
		f[x] = true;
	}

	nL = nR = 0;
	for (int i = 1; i <= MaxM + 1; ++i)
		if (f[i] != f[i - 1])
		{
			if (i & 1)
				qL[++nL] = i;
			else
				qR[++nR] = i;
		}

	for (int i = 1; i <= nL; ++i)
		for (int j = 1; j <= nR; ++j)
			if (!book[abs(qL[i] - qR[j])])
				mat[i][j] = true;

	int n_matches = 0;
	for (int u = 1; u <= nL; ++u)
	{
		for (int v = 1; v <= nR; ++v)
			bookR[v] = false;

		n_matches += match(u);
	}

	int res = n_matches;
	res += (nL - n_matches >> 1) << 1;
	res += (nR - n_matches >> 1) << 1;
	res += 3 * ((nL ^ n_matches) & 1);

	cout << res << endl;

	return 0;
}

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

using namespace std;
using ll=long long;

void solve() {
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    sort(a.begin(), a.end());
    k = min(k,n);
    ll res = 0;
    for (int i = 0; i < n-k; i++) {
        res += a[i];
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


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

char abcde[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

int main(){
    int n;
    cin >> n;
    string s;
    vector<vector<int>> abc(26, vector<int>(n) );

    for (int i = 0; i < n; i++)
    {
        cin >> s;
        for (int j = 0; j < s.size(); j++)
        {
            ++abc.at(s.at(j) - 'a').at(i);
        }
    }

    for (int i = 0; i < 26; i++)
    {
        for (int j = 0; j < *min_element(abc.at(i).begin(), abc.at(i).end() ); j++)
        {
            printf("%c", abcde[i]);
        }
    }
    cout << endl;
    return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// テーブルを作る前処理
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}

// 二項係数計算
long long 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() {
    ll N,W;
    cin >> N >> W;

    vector<ll> val[4];
    ll w1;
    ll v;
    cin >> w1 >> v;
    val[0].push_back(v);

    REP(i,N-1) {
        ll w;
        cin >> w >> v;
        val[w-w1].push_back(v);
    }

    sort(all(val[0]),greater<>());
    sort(all(val[1]),greater<>());
    sort(all(val[2]),greater<>());
    sort(all(val[3]),greater<>());

    vector<ll> sum[4];
    REP(i,4) sum[i].resize(val[i].size()+1,0);
    REP(j,4) REP(i,val[j].size()) sum[j][i+1] += sum[j][i] + val[j][i];

    ll ans = 0LL;
    REP(i1,val[0].size()+1) REP(i2,val[1].size()+1) REP(i3,val[2].size()+1) REP(i4,val[3].size()+1){
        if(w1*i1+(w1+1)*i2+(w1+2)*i3+(w1+3)*i4 > W) continue;

        ll ans_tmp= 0LL;
        ans_tmp += sum[0][i1];
        ans_tmp += sum[1][i2];
        ans_tmp += sum[2][i3];
        ans_tmp += sum[3][i4];

        chmax(ans,ans_tmp);
    }

    pl(ans)

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <iterator>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (int i = 0; i<vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

int SumDigitValues(int x)
{
	int sum = 0;
	while (x)
	{
		sum += x % 10;
		x = x / 10;
	}

	return sum;
}

int Factorial(int n)
{
	if (n < 0) return 0;
	if (n == 0) return 1;
	return n * Factorial(n - 1);
}

int factorial(int n)
{
	if (n > 1)
	{
		return n * factorial(n - 1);
	}
	else
	{
		return 1;
	}
}


int gcd(int a, int b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

vector<int> Divisors(int x)
{
	vector<int> divisors;
	divisors.push_back(1);
	for (int a = 2; a <= x; a++)
	{
		if (x % a == 0) divisors.push_back(a);
	}
	return divisors;
}

vector<int> CommonDivisors(int a, int b)
{
	vector<int> divisorsA = Divisors(a);
	vector<int> divisorsB = Divisors(b);
	vector<int> commonDivisors;
	set_intersection(divisorsA.begin(), divisorsA.end(), divisorsB.begin(), divisorsB.end(), std::back_inserter(commonDivisors));
	return commonDivisors;
}

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

	int cnt = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == t[i]) cnt++;
	}
	cout << cnt << endl;
}

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

using namespace std;

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

    vector<int> p(n);
    vector<int> q(n);

    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

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

    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        v[i] = i + 1;
    }

    int count = 0;
    int a, b;
    do {
        count++;

        bool flaga = true, flagb = true;
        for (int i = 0; i < n; i++) {
            if (p[i] != v[i]) flaga = false;
            if (q[i] != v[i]) flagb = false;
        }

        if (flaga) a = count;
        if (flagb) b = count;
    }
    while(next_permutation(v.begin(), v.end()));

    cout << abs(a - b) << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = sorted([list(map(int, input().split())) for _ in range(n)])
r = a[0][0]+a[0][1]
l = 0
for j in range(1,n):
    i = a[j]
    l = i[0]-i[1]
    if r <= l:
        r = i[0]+i[1]
    else:
        n -= 1
        r = min(r,i[0]+i[1])
print(n)

Measured memory_bytes: 28716
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

const ll MOD = 1000000007;
const int MAX = 200001;

// fac[n]: n!
// finv[n]: (n!)^-1
// inv[n]: nの逆元
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int 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;
  }
}

// 二項係数計算 (combination)
// nCk = (n!) * (k!)^-1 * ((n-k)!)^-1 として計算
ll comb(int n, int k) {
  if (n < k) {
    return 0;
  }
  if (n < 0 || k < 0) {
    return 0;
  }
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll n;
vector<ll> a;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  a.resize(n + 1);
  for (int i = 0; i <= n; i++) {
    cin >> a[i];
  }
  comb_init();

  vector<ll> a2 = a;
  sort(a2.begin(), a2.end());
  ll dup = 0;
  for (ll i = 0; i < n; i++) {
    if (a2[i] == a2[i + 1]) {
      dup = a2[i];
      break;
    }
  }

  ll idx1 = -1, idx2 = -1;
  for (ll i = 0; i <= n + 1; i++) {
    if (a[i] == dup) {
      if (idx1 == -1) {
        idx1 = i;
      } else {
        idx2 = i;
        break;
      }
    }
  }

  ll r = idx1;
  r += (n - idx2);
  cout << n << endl;
  for (ll i = 2; i <= n; i++) {
    ll ans = comb(n+1, i);
    if (i <= r+1) {
      ans = (MOD + ans - comb(r, i-1)) % MOD;
    }
    cout << ans << endl;
  }
  cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define rep(i,a,b) for(i=a;i<=b;i++)
#define rev(i,a,b) for(i=b;i>=a;i--)
#define gcd(a,b) __gcd(a,b)
#define MOD 1000000007
#define scll(t) scanf("%lld",&t)
#define sclf(t) scanf("%lf", &t)
#define scst(t) scanf("%s", &t)
#define max(a,b) (a>=b?a:b)
#define min(a,b) (a<b?a:b)
#define MEM(a,b) memset(a, (b), sizeof(a))
#define all(v) v.begin(), v.end()
const double pi=acos(-1.0);
typedef pair<ll, ll> PII;
typedef vector<ll> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<ll,ll> MPII;
typedef set<ll> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

template <typename T> inline void write(T x)
{
	ll i = 20;
	char buf[21];
	// buf[10] = 0;
	buf[20] = '\n';

	do
	{
		buf[--i] = x % 10 + '0';
		x/= 10;
	}while(x);
	do
	{
		putchar(buf[i]);
	} while (buf[i++] != '\n');
}

void read(ll &x)
{
    bool neg=false;
    register ll c;
    x =0;
    c=getchar();
    if(c=='-')
    {
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}


int main()
{
	ll n;
	cin>>n;
	string s;
	cin>>s;
	
	ll left[n], right[n];
	memset(left,0,sizeof(left));
	memset(right,0,sizeof(right));
	
	if(s[0]=='W')left[0]++;
	else right[0]++;
	for(ll i=1;i<n;i++){
		if(s[i]=='W'){
			left[i] = left[i-1]+1;
			right[i]=right[i-1];
		}
		else{
			right[i] = right[i-1]+1;
			left[i]=left[i-1];
				
		}
	//	cout<<right[i]<<" "<<left[i]<<endl;
	}
	
	
	ll ans = INT_MAX;
	for(ll i=0;i<n;i++){
		if(i==0){
			ans = min(ans, right[n-1]-right[0]);
		}
		else if(i==n-1){
			ans = min(ans, left[n-2]);
		}
		else{
			ans=min(ans, left[i-1] + right[n-1] - right[i]);
		}
//		cout<<ans<<endl;
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}



Measured memory_bytes: 5380
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,T,la=0,ans=0;
    cin>>n>>T;
    for(int i=1,j=1<<30;i<=n;i++) {
	int x=gi();
	if(la<x-j) la=x-j,ans=0;
	if(la==x-j) ++ans;
	j=min(j,x);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pi acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define	inf (ll)1e15
#define mod 1000000007
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

using namespace __gnu_pbds;
using namespace std;

inline string str_inp(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string line_inp(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
typedef pair<ll,ll>pll;

const int S=200100;
ll p2[S+5];

pll Normalize(ll a,ll b)
{
	if(a==0 && b==0)return pll(a,b);
	else if(a<0 && b<0)
	{
		a=-a;
		b=-b;
	}
	else if(b<0)
	{
		a=-a;
		b=-b;
	}

	ll g=__gcd(abs(a),abs(b));
	return pll(a/g,b/g);
}

int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
    p2[0]=1;
	for(int i=1;i<=S;i++)
	{
		p2[i]=p2[i-1]*2;
		p2[i]%=mod;
	}

	int n;
	while(~sf("%d",&n))
	{
		map<pll,ll>mp;
		for(int i=0;i<n;i++)
		{
			ll a,b;
			sf("%lld %lld",&a,&b);
			tie(a,b)=Normalize(a,b);
			mp[pll(a,b)]++;
		}

		ll ans=1,zero=0;
		for(auto e:mp)
		{
			ll a,b;
			tie(a,b)=e.first;
			ll val=e.second;
			
			if(a==0 && b==0)zero=val;
			else
			{
				ll x=0;
				x=p2[val];
				mp[pll(a,b)]=0;
				
				//complement of pair (a,b)
				ll xc=0;

				ll ac,bc;
				if(a>0)ac=-b,bc=a;
				else ac=b,bc=-a;

				xc=mp[pll(ac,bc)];
				xc=p2[xc];
				mp[pll(ac,bc)]=0;

				ll sum=(x+xc-1)%mod;
				ans=(ans*sum)%mod;
			}
		}
		pf("%lld\n",(ans+zero-1+mod)%mod);
	}
    return 0;
}
 






































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

using namespace std;
typedef long long ll;

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

    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++)
        cin >> d[i];
    set<ll> st;
    for (int i = 0; i < n; i++)
    {
        ll tmp = 0;
        for (int j = i; j < min(n, i + 9); j++)
        {
            tmp = tmp * 10 + d[j];
            st.insert(tmp);
            // cout<<tmp<<endl;
        }
    }
    bool flag = true;
    int idx = -1;
    while (flag)
    {
        idx++;
        if (!(st.find(idx) != st.end()))
        {
            flag = false;
        }
    }
    cout << idx << endl;
}


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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define dump(x) cout << #x << " = " << (x) << endl
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

int main() {
    ll n, m, a;
    cin >> n >> m;
    priority_queue<ll> p_que;
    for(ll i = 0; i < n; i++) {
        cin >> a;
        p_que.push(a);
    }
    for(ll i = 0; i < m; i++) {
        ll t = p_que.top();
        p_que.pop();
        p_que.push(t / 2);
    }

    ll sum = 0;
    for(ll i = 0; i < n; i++) {
        sum += p_que.top();
        p_que.pop();
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 4288
n, t, s = gets.split.map(&:to_i)
arr = n.times.map{ gets.split.map(&:to_i) }
dp = 2.times.map{ [0]*(t+1) }
ret = 0
n.times do |i|
  (t-arr[i][1]+1).times do |j|
    dp[1][j + arr[i][1]] = [dp[1][j + arr[i][1]], dp[0][j] + arr[i][0]].max if !(j + arr[i][1] > s && s > j)
  end
  ret = [ret, dp[1].max].max
  dp[0] = dp[1].dup
end
p ret

Measured memory_bytes: 25344
def solve():
    N, K, Q = map(int, input().split())
    l = [K-Q] * N
    for _ in range(Q):
        a = int(input())
        l[a-1] += 1
    for i in l:
        ans = 'Yes' if i > 0 else 'No'
        print(ans)

# print(solve())

# def solve()が@return voidのとき
solve()

Measured memory_bytes: 6608
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

    int N;

    public void solve() {
        N = nextInt();
        int ans = 0;
        for(int i = 0;i < N;i++){
            int a = nextInt();
            int b = nextInt();
            ans += b - a + 1;
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define int long long int
#define ldouble long double

//setprecision()<<

using namespace std;

int alptoint(char alph,string &alp){
    for(int i=0;i<26;i++){
        if(alph==alp.at(i)){
            return i;
        }
    }
    return -1;
}

signed main() {
    string S,T;
    cin>>S>>T;
    string alp="abcdefghijklmnopqrstuvwxyz";
    vector<int> R(26,-1);
    vector<int> r(26,-1);
    int num=S.size();
    for(int i=0;i<num;i++){
        int Si=alptoint(S.at(i),alp);
        int Ti=alptoint(T.at(i),alp);
        if(R.at(Si)>=0){
            if(R.at(Si)!=Ti){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else{
            R.at(Si)=Ti;
        }

        if(r.at(Ti)>=0){
            if(r.at(Ti)!=Si){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else{
            r.at(Ti)=Si;
        }
    }
    cout<<"Yes"<<endl;
return 0;
}

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

int main(){
 ll x; cin >> x;
  for(ll i=-118;i<=119;i++){
    for(ll j=-118;j<=119;j++){
      ll a=i*i*i*i*i;
      ll b=j*j*j*j*j; ll dif=a-b;
      if(dif==x){
        cout << i << ' ' << j <<endl;
        return 0;
      }

    }
  }
}


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

using namespace std;

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

const double pi = acos(-1.0);
int main(){
    while(1){
        int a,b,ans;
        char c;
        cin >> a >> c >> b;
        if(c == '+')ans = a+b;
        else if(c == '-')ans = a-b;
        else if(c == '*')ans = a*b;
        else if(c == '/')ans = a/b;
        else break;
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
#include<iostream>

using namespace std;

int n, x;
int main(){
    while(true){
        cin >> n >> x;
        if(!n && !x) break;
        int count = 0;
        for(int fir = 1; fir < x/2 && fir <= n-2; ++fir){
            for(int sec = fir + 1; sec < x- (fir + sec) && sec <= n-1; ++sec){
                if(x - (fir + sec) <= n) ++count;
            }
        }
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  for(int a=1; a<10; a++){
  int k=n/a;
    if(n%a==0){if(k>0 && k<10){cout<<"Yes"<<endl; return 0;}}
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
a,b=input().split()
#print(a,b)
cnt=0

for j in range(int(a),int(b)+1):
  s=''
  strj=str(j)
  for i in range(len(strj)):
    s+=strj[len(strj)-1-i]
    if strj==s:
      cnt+=1
    
print(cnt)
  



Measured memory_bytes: 2940
import sys
import numpy as np

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def kk(al):
	for i in range(len(al)-1, -1, -1):
		if list(al[i]) == ['.']*len(al[i]):
			al = np.delete(al, i, 0)
	return al

def main():
	#a = int(input())
	h, w = tin()
	#s = input()
	al=[]
	for _ in range(h):
		s=list(input())
		al.append(s)
	al = np.array(al)
	al = kk(al)
	al = kk(al.T)
	al=al.T
	for v in al:
		print(''.join(v))
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int d, g;
vi p, c;
int dfs(int v, int s) {
    if (v == d) {
        int total = 0, cnt = 0;
        repr(i, v) {
            if (s&(1<<i)) {
                total += (i+1) * 100 * p[i];
                total += c[i];
                cnt += p[i];
            }
        }
        int i = v-1;
        while (i >= 0 && s&(1<<i)) --i;
        if (i < 0) return cnt;
        int j = p[i];
        while (total < g) {
            total += (i+1) * 100;
            ++cnt;
            --j;
            if (j == 0) {
                total += c[i];
                --i;
                while (i >= 0 && s&(1<<i)) --i;
                if (i < 0) return cnt;
                j = p[i];
            }
        }
        return cnt;
    }
    if (v == d-1) return dfs(v+1, s);
    s |= (1<<v);
    int cnt = dfs(v+1, s);
    s &= ~(1<<v);
    cnt = min(cnt, dfs(v+1, s));
    return cnt;
}

int main(){
    cin >> d >> g;
    rep(i, d) {
        int pi, ci;
        cin >> pi >> ci;
        p.push_back(pi);
        c.push_back(ci);
    }
    cout << dfs(0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
// 2013/11/06 Tazoe

#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

struct state{
	int p[8];
	int t;
};

int main()
{
	while(true){
		struct state s;

		cin >> s.p[0];

		if(cin.eof())				// ファイルの終りならば
			break;

		for(int i=1; i<8; i++){
			cin >> s.p[i];
		}

		s.t = 0;

		if(s.p[0]==0 && s.p[1]==1 && s.p[2]==2 && s.p[3]==3 && s.p[4]==4 && s.p[5]==5 && s.p[6]==6 && s.p[7]==7){
			cout << s.t << endl;
			continue;
		}

		bool memo[8][8][8][8][8][8][8];		// メモリ節約のため7次元
		for(int i0=0; i0<8; i0++){
		for(int i1=0; i1<8; i1++){
		for(int i2=0; i2<8; i2++){
		for(int i3=0; i3<8; i3++){
		for(int i4=0; i4<8; i4++){
		for(int i5=0; i5<8; i5++){
		for(int i6=0; i6<8; i6++){
			memo[i0][i1][i2][i3][i4][i5][i6] = false;
		}
		}
		}
		}
		}
		}
		}
		memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]] = true;

		queue<struct state> q;
		q.push(s);

		while(true){
			if(q.empty())
				break;

			s = q.front();
			q.pop();

			s.t++;

			int I = 0;
			while(s.p[I]!=0){			// 0の位置を探す
				I++;
			}

			if(0<=I && I<=3){			// 上ならば
				swap(s.p[I], s.p[I+4]);
				if(s.p[0]==0 && s.p[1]==1 && s.p[2]==2 && s.p[3]==3 && s.p[4]==4 && s.p[5]==5 && s.p[6]==6 && s.p[7]==7){
					cout << s.t << endl;
					break;
				}
				if(!memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]]){
					memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]] = true;
					q.push(s);
				}
				swap(s.p[I], s.p[I+4]);
			}

			if(4<=I && I<=7){			// 下ならば
				swap(s.p[I], s.p[I-4]);
				if(s.p[0]==0 && s.p[1]==1 && s.p[2]==2 && s.p[3]==3 && s.p[4]==4 && s.p[5]==5 && s.p[6]==6 && s.p[7]==7){
					cout << s.t << endl;
					break;
				}
				if(!memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]]){
					memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]] = true;
					q.push(s);
				}
				swap(s.p[I], s.p[I-4]);
			}

			if(I!=0 && I!=4){			// 左端でなければ
				swap(s.p[I], s.p[I-1]);
				if(s.p[0]==0 && s.p[1]==1 && s.p[2]==2 && s.p[3]==3 && s.p[4]==4 && s.p[5]==5 && s.p[6]==6 && s.p[7]==7){
					cout << s.t << endl;
					break;
				}
				if(!memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]]){
					memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]] = true;
					q.push(s);
				}
				swap(s.p[I], s.p[I-1]);
			}

			if(I!=3 && I!=7){			// 右端でなければ
				swap(s.p[I], s.p[I+1]);
				if(s.p[0]==0 && s.p[1]==1 && s.p[2]==2 && s.p[3]==3 && s.p[4]==4 && s.p[5]==5 && s.p[6]==6 && s.p[7]==7){
					cout << s.t << endl;
					break;
				}
				if(!memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]]){
					memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]] = true;
					q.push(s);
				}
				swap(s.p[I], s.p[I+1]);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3344
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
static const int MAXN = 100000;
static const int MAX = 1000000007;

int a[50], b[50], c[50], d[50], A[10];
int N, M, Q;

int C(){
    int ans = 0;
    rep(i,Q){
        if(A[b[i]] - A[a[i]] == c[i]){
            ans += d[i];
        }
    }
    return ans;
}

int next(){
    for(int i = N-1; i >= 0; i--){
        if(A[i] < M){
            A[i]++;
            for(int j = i+1; j < N; j++){
                A[j] = A[i];
            }
            return 1;
        }
    }
    return 0;
}


int main(){
    cin >> N >> M >> Q;
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    rep(i,N){
        A[i] = 1;
    }
    int ans = C();
    while(1){
        if( next() == 0 ) break;
        ans = max(ans, C());
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto & i : (a))
#define SZ(x) ((int)(x).size())
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;

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

	int h1, m1, h2, m2, k;
	std::cin >> h1 >> m1 >> h2 >> m2 >> k;

	int t1 = h1*60+m1;
	int t2 = h2*60+m2;

	int have = t2-t1;

	std::cout << std::max(0, have-k) << "\n";

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int k;cin>>k;
    string s;cin>>s;
    int sz=s.size();
    if(sz<=k)cout<<s<<endl;
    else{
        rep(i,k)cout<<s[i];
        cout<<"..."<<endl;
    }
}


Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}

signed main(){
  int a;
  cin>>a;
  int c=0;
  rep1(i,a){
  c+=((1+(a/i))*(a/i)/2)*i;
  }
  out(c);
}

Measured memory_bytes: 3684
#include<stdio.h>
int main()
{
    int p,q,r;
    scanf("%d%d%d",&p,&q,&r);
    int a=p+q;
    int b=p+r;
    int c=q+r;
    if(a<=b &&  a<=c) printf("%d",a);
    else if(b<=a &&  b<=c) printf("%d",b);
    else printf("%d",c);
    return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
D = list(map(str, input().split()))

T = True
while T:
  x = str(N)
  p = 0
  for i in range(len(x)):
    if x[i] in D:
      p = 1
  
  if p == 0:
    T = False
  else:
    N += 1

print(N)




Measured memory_bytes: 9160
N,x=map(int,input().split())
Children=list(map(int,input().split()))
Children.sort(key=lambda x:x)
n=0
S=0
while n<=N-1:
  S+=Children[n]
  if S<x:
    n+=1
  elif S==x:
    n+=1
    break
  elif S>x:
    break
if S<x:
  n+=-1
print(n)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 200000
using namespace std;
int a[N];
int n;
bool cmp(int x,int y){return x>y;}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1,cmp);
	int x=0;
	for (int i=1;i<n;i++)
		if (a[i]==a[i+1]){
			if (!x)x=a[i],i++;
			else{
				cout<<(long long)x*a[i];
				return 0;
			}
		}
	cout<<0;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s1,s2,s3;
string alph2("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s1>>s2>>s3;
    char c=s1[0];
    rep(i,26){
        if(c==alph[i]){
            cout<<alph2[i];
            break;
        }
    }

    c=s2[0];
    rep(i,26){
        if(c==alph[i]){
            cout<<alph2[i];
            break;
        }
    }

    c=s3[0];
    rep(i,26){
        if(c==alph[i]){
            cout<<alph2[i];
            break;
        }
    }
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

using veci = vector<int>;
using pii = pair<int, int>;
using vecii = vector<pii>;
using ll = long long;
using vecl = vector<ll>;
#define fi first
#define se second
#define endl '\n'

void solve() {
    int n;
    cin >> n;

    string s;
    cin >> s;
    for (int i=0; i<s.size(); ++i) {
        int cur = int(s[i]-'A');
        cur = (cur + n) % 26;
        s[i] = char('A'+cur);
    }
    cout << s << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#if defined(LOCAL_TEST)
    (void)argc;
    freopen(string(argv[0]).append("-test.in").c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
    solve();
}


Measured memory_bytes: 256
import sys
s = int(input())
lis = [0 for i in range(1000001)]
lis[s] = lis[s] + 1
def solve(s):
    m = 1
    while True:
        m = m + 1
        if s%2 == 1:
            s = 3*s + 1
        else:
            s = s//2
        if not lis[s] == 0:
            return m
            sys.exit()
        else:
            lis[s] = lis[s]+1
print(solve(s))


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

int main(){
  int h, w;
  cin >> h >> w;
  int c[h][w];
  rep(i,h) rep(j,w) cin >> c[i][j];
  int hist[h][w];
  rep(i,w) hist[0][i] = (c[0][i] == 0 ? 1 : 0);
  for(int i = 1; i < h; i++)  rep(j,w)  hist[i][j] = (c[i][j] == 0 ?  hist[i-1][j] + 1 : 0);
  ll ans = 0;
  rep(x,h) {
    ll l[w], r[w], st[w];
    ll t = 0;
    rep(i,w) {
      while(t > 0 && hist[x][st[t-1]] >= hist[x][i]) t--;
      l[i] = (t == 0 ? 0 : st[t-1]+1);
      st[t++] = i;
    }
    t = 0;
    for(int i = w-1; i >= 0; i--) {
      while(t > 0 && hist[x][st[t-1]] >= hist[x][i]) t--;
      r[i] = (t == 0 ? w : st[t-1]);
      st[t++] = i; 
    }
    rep(i,w) ans = max(ans,hist[x][i]*(r[i]-l[i]));
  }
  cout << ans << endl;
  return 0;
}



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

int main()
{
  vector<int>nums(5);
  int ans=0;
  for(int i=0;i<5;++i)
  {
    cin>>nums[i];
    if(nums[i]==0)
      ans=i+1;
  }
  cout<<ans;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  if ( (a+b) %2==0) {
    cout << (a+b)/2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 888
def d_unbalanced(S):
    S_length = len(S)
    s = S + '##'  # 統一的に扱うため、アルファベットでない文字を番兵とする
    for i in range(S_length):
        # どちらかを満たす文字列をアンバランスなものとして出せばいい
        # 全部調べても成り立たなければ、アンバランスな文字列はない
        if s[i] == s[i + 1]:  # XXと文字が並んでいる
            return '{} {}'.format(i + 1, i + 2)
        elif s[i] == s[i + 2]:  # XYXと文字が並んでいる
            return '{} {}'.format(i + 1, i + 3)
    # アンバランスな文字列はなかった
    return '-1 -1'
 
S = input().strip()
print(d_unbalanced(S))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;


int main()
{
	int mx=0,n;
	long long ans=0;
	scanf("%d",&n);
	while(n--)
	{
		int x;
		scanf("%d",&x);
		mx=max(mx,x);
		ans+=mx-x;
		
	}
	printf("%lld\n",ans);

}


Measured memory_bytes: 3780
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<stdlib.h>
 
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cstdlib>
 
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=1e8+6;//maxn*maxs
const int maxs=1e8+10;
const int mod=998244353;
int f[maxn];
ll pr[maxn];
int main()
{
	ll n,x,m;
	cin>>n>>x>>m;
	for(int i=0;i<m;i++)
		f[i]=-1;
	ll ans=0;
	int a=0;
	while(n){
		n--;
		f[x]=a++;
		pr[x]=ans;
		ans+=x;

		x=x*x%m;
		if(f[x]>=0){
			int b=a-f[x];
			ans+=(ans-pr[x])*(n/b);
			n%=b;
		}
	}
	cout<<ans<<endl; 	
    system("pause");
    return 0;
}
	



Measured memory_bytes: 4364