akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize("O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#include <bits/stdc++.h>

using namespace std;
 
using ll = long long;
using ld = long double;

const int N = 2005;

ll dp[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<ll, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i + 1;
    }
    sort(a.rbegin(), a.rend());
    for (int i = 0; i < n; i++) {
        for (int pref = 0; pref <= i + 1; pref++) {
            if (pref) {
                dp[i + 1][pref] = dp[i][pref - 1] + a[i].first * abs(a[i].second - pref);
            }
            if (pref < i + 1) {
                dp[i + 1][pref] = max(dp[i + 1][pref], dp[i][pref] + a[i].first * abs(n - i + pref - a[i].second));
            }
        }
    }
    cout << *max_element(dp[n], dp[n] + n + 1) << endl;
    return 0;
}

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

long long gcd(long long a, long long b)
{
    long long ta = a, tb = b;
    while(a % b != 0)
    {
        ta = a;
        tb = b;
        a = tb;
        b = ta % tb;
    }
    return b;
}

int main()
{
    long long a,b;
    cin >> a >> b;
    if(a < b)
    {
        long long t;
        t = a;
        a = b;
        b = t;
    }

    long long answer = 1;
    for(long long i = 2; i * i <= a; ++i)
    {
        if(a % i == 0
        && b % i == 0)
        {
            ++answer;
        }
        while(a % i == 0)
        {
            a /= i;
        }
    }
    if(a != 1
    && b % a == 0)
    {
        ++answer;
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
	#include <algorithm>
	#include <iostream>
	#include <iterator>
	#include <numeric>
	#include <sstream>
	#include <fstream>
	#include <cassert>
	#include <climits>
	#include <cstdlib>
	#include <cstring>
	#include <string>
	#include <cstdio>
#include<algorithm>
	#include <vector>
	#include <math.h>
	#include <queue>
	#include<memory>
	#include <deque>
	#include <stack>
	#include <list>
	#include <map>
	#include <set>
	#include <cmath>
	#include <bitset>
	#include<list>
	#include <iomanip>
	using namespace std;
	typedef long long ll;
	int m[200005];
	void go()
	{
		m[0] = 1;
		m[1] = 1;
		for (int i = 2; i < 40000; i++)
		{
			for (int j = i * i; j < 10000; j += i)
			{
				m[j] = 1;
			}
		}
	}


	long long dp[110][100010];
	pair<ll,ll> w[(int)1e5 + 10];
	int a[600][600];
	ll x, y;
	ll solve(ll i,ll sum)
	{
		if (i == x+1)return 0;
		if (dp[i][sum] != -1)return dp[i][sum];
		if(sum+w[i].first <= y)
		return dp[i][sum]=max(w[i].second+solve(i + 1, sum + w[i].first), solve(i + 1, sum));
		else return solve(i + 1, sum);
	}
	int main()
	{

		memset(dp, -1, sizeof dp);
		cin >> x >> y;
		for (int i = 1; i <= x; i++)cin >> w[i].first >> w[i].second;
		cout << solve(1, 0);
		return 0;
	}

Measured memory_bytes: 87168
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iterator>
#include <sstream>

using namespace std;

int main()
{
	int a,b,n;
	while(cin>>a>>b>>n){
		int ans = 0;
		a %= b;
		for (int i = 0; i < n; i++){
			a *= 10;
			ans += a / b;
			a %= b;
		}
		cout << ans <<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb emplace_back
#define x first
#define y second
#define sz(a) ((int)(a).size())
#define rep(i,a,b) for(auto i=(a); i<(b); i++)
#define dec(i,n,a) for(auto i=(n); i>=(a); i--)
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define EPS 3e-11
#define fcin ios_base::sync_with_stdio(false)
#define db(x) cerr << #x << " == " << x << endl
#define _ << " " <<
#define MAXN 202020
#define LOGN 29
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

int v[3], ans;

int main(){
	rep(i,0,3) scanf("%d", v+i);
	sort(v,v+3);
	int k = v[2] - v[1];
	int fim = v[2];
	if((v[2]-(v[0]+k)) % 2 == 1)
		fim++;
	int ans = 3*fim - v[2] - v[1] - v[0];
	assert(ans%2==0);
	ans /= 2;
	printf("%d\n", ans);
}

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

int main() {
  
  int n;
  cin >> n;
  for(int i=0;i<7;i++){
    
    if( pow(2,i) <= n && n < pow(2,i+1) ){
      cout << pow(2,i) << endl;
      break;
    }
    
  }
}

Measured memory_bytes: 4076
X, Y, A, B, C = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]

p = sorted(p, reverse=True)[:X]
q = sorted(q, reverse=True)[:Y]

ans = sum(sorted((p + q + r), reverse=True)[:X + Y])
print(ans)

Measured memory_bytes: 23644
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
arr = na()
s = sum(arr)
res = [0] * (n + 1)

for i in range(1, n + 1)[::-1]:
    sum_res = sum(res[x] for x in range(i, n + 1, i))
    if sum_res % 2 != arr[i - 1]:
        res[i] = 1

print(sum(res))

if sum(res):
    ans = []
    for i, ele in enumerate(res):
        if ele:
            ans.append(i)
    print(*ans)




Measured memory_bytes: 67832
def main():
    input()
    times = 0
    sequence = list(map(int, input().split()))
    for i in range(len(sequence)):
        mini = i
        for j in range(i, len(sequence)):
            if sequence[j] < sequence[mini]:
                mini = j
        if i != mini:
            times += 1
        sequence[i], sequence[mini] = sequence[mini], sequence[i]
    print(' '.join(map(str, sequence)))
    print(times)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5600
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<limits.h>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
using namespace std;

long long  mod = 1000000007;

long max(long x, long y) {
	return x > y ? x : y;
}

long min(long x, long y) {
	return x < y ? x : y;
}

long factorial(long n) {
	if (n == 1) {
		return 1;
	}
	else {
		return n * factorial(n - 1);
	}
}

long long  fel(long long  n,long long  f) {

		if (f == 1) {
			return n % mod;
		}
		else if (f % 2 == 0) {
			return (fel(n,f / 2) * fel(n,f / 2)) % mod;
		}
		else {
			return ((n  * fel(n,f / 2) %mod) * fel(n,f / 2))% mod;
		}
	

}


int main()
{
	long long n,m;
	cin >> n;
	cin >> m;
	
	vector<long long> a(n);
	priority_queue<long long> b;
	for (long long i = 0; i < n; i++) {
		long long s;
		cin >> s;
		b.push(s);
	}
	for (int i=0;i<m;i++){
		long long s;
		s = b.top() / 2;
		b.pop();
		b.push(s);
	}

	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum = sum + b.top();
		b.pop();
	}
   
		
		cout << sum;
	

}


Measured memory_bytes: 2168
import itertools,math

D, G = map(int, input().split())
Q = []
for _ in range(D):
    Q.append(tuple(map(int, input().split())))

ans = 1000  # 制約上の最大値
for t in itertools.product([0, 1], repeat=D):
    score = sum(t[i] * (Q[i][0] * 100 * (i + 1) + Q[i][1]) for i in range(D))
    ans_tmp = sum(t[i] * Q[i][0] for i in range(D))
    if score < G:
        p = D - 1
        while t[p]:
            p -= 1
        addition_q = math.ceil((G - score) / (100 * (p + 1)))
        if addition_q >= Q[p][0]:
            continue
        ans_tmp += addition_q
    ans = min(ans, ans_tmp)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[111][111],n,L[111],R[111];
int dfs(int l,int r){
	if(dp[l][r]>-1)return dp[l][r];
	int res=1e9;
	for(int i=l;i<r;i++){
		res=min(res,dfs(l,i)+dfs(i+1,r)+L[l]*R[i]*R[r]);
	}
	return dp[l][r]=res;
}
main(){
	memset(dp,-1,sizeof(dp));
	r(i,111)dp[i][i]=0;
	cin>>n;
	r(i,n)cin>>L[i]>>R[i];
	cout<<dfs(0,n-1)<<endl;
}


Measured memory_bytes: 3164
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
  if(c - a + b>=0)
	cout << c - a + b << endl;
  else
    cout<<0<<endl;
}


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

int main() {
  int H,W=0;
  cin >> H >> W;
  
  vector<string> A(H);
  for(int i=0 ; i<H ; i++){
    cin >> A.at(i);
  }
  //cout << A.at(0) << endl;
  
  for(int i=0 ; i<W+2 ; i++){
    cout << '#';
  }
  cout << endl;
  
  for(int i=0 ; i<H ; i++){
    cout << '#' << A.at(i) << '#' << endl;
  }
  
  for(int i=0 ; i<W+2 ; i++){
    cout << '#';
  }
  cout << endl;
  

}


Measured memory_bytes: 256
import copy
import heapq

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

n  = ip()
a = input()
m = n//2
b = a[:m]
c = a[m:]
if b==c:j(1)
j(0)

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n, t;
    vector <int> T;
    int x;
    int i;
    int ans = 0;
    
    cin >> n >> t;
    for(i = 0; i < n; i++){
        cin >> x;
        T.push_back(x);
    }
    
    for(i = 0; i < n; i++){
        if(i < n - 1){
            int interval = T[i + 1] - T[i];
            ans += min(t, interval);
        }
        else{
            ans += t;
        }
    }
    
    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 1400
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve(inp):
    import math
    (H, N) = map(int, inp.readline().strip().split(' '))
    A = list(map(int, inp.readline().strip().split(' ')))

    if sum(A) >= H:
        return "Yes"
    else:
        return "No"


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()


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

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

using namespace std;

int main(){
  char x,y;
  cin>>x>>y;
  if((int)(x-'A')>(int)(y-'A')){
    cout<<">";
  }else if((int)(x-'A')<(int)(y-'A')){
    cout<<"<";
  }else{
    cout<<"=";
  }
  return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;

void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}

const int N=2e6+3,M=1e4+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;

int n,m,tc,a[N],c[N],u,v,s[N][26],last[26];

ll sum(int idx){
    ll score = 0;
    for(int i = 0 ; i < n ; i++)
        score += s[i][idx];
    return score;
}

ll calc(int day,int idx){
    ll score = 0;
    for(int i = 0 ; i < 26 ; i++)
        if (i != idx)
            score -= (ll)c[i] * (day - last[i]);
        else
            score += sum(i);
    return score;
}

int main(){
    //IO();
    cin >> n;
    for(int i = 0 ; i < 26 ; i++)
        cin >> c[i];
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < 26 ; j++)
            cin >> s[i][j];
    for(int day = 1 ; day <= n ; day++){
        ll mx_score = -1e18;
        int ans = 0;
        for(int contest = 0 ; contest < 26 ; contest++){
            ll score = calc(day,contest);
            if (score > mx_score){
                mx_score = score;
                ans = contest + 1;
            }
        }
        last[ans - 1] = day;
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3680
s = input()
t = input()
sl = len(s)
tl = len(t)
ans = 1001

for i in range(sl-tl+1):
    cnt = 0
    for sv, tv in zip(s[i:i+tl], t):
        if sv != tv:
            cnt += 1
    ans = min(cnt, ans)

print(ans)


Measured memory_bytes: 9056
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

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

    cout << (ll)(a+b)*0.5 * h << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

const ll M = 1000000000;

signed main() {
    ll S;
    cin >> S;
    ll x1 = 0;
    ll y1 = 0;
    ll x2 = M;
    ll y2 = 1;
    ll y3 = (S + M - 1) / M;
    ll x3 = abs(S - x2 * y3);
    assert(abs(x2 * y3 - y2 * x3) == S);
    cout << 0 << ' ' << 0 << ' ' << x2 << ' ' << y2 << ' ' << x3 << ' ' << y3 << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
    int k;
    cin >> k;
    if( k <= 500 )
    {
        cout << k << endl;
        REP( i, k )
        {
            REP( j, k ) cout << i + 1 << " ";
            cout << endl;
        }
    }
    else
    {
        int kk = 500;
        cout << kk << endl;
        REP( i, kk )
        {
            REP( j, kk )
            {
                int p = ( i % 2 ) * kk + ( j + i ) % kk;
                if( p >= k ) p -= kk;
                cout << p + 1 << " "; 
            }
            cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1152
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i, j;
	char lc1Buf[1024];

	// 条件 - 取得
	int liN, liM;
	int li1No[5];
	char lc1Val[5];
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &liN, &liM);
	for (i = 0; i < liM; i++) {
		int liVal;
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d", &li1No[i], &liVal);
		li1No[i]--;
		lc1Val[i] = liVal + '0';
	}

	// 値範囲
	int liMin, liMax;
	switch (liN) {
	case 1:		liMin = 0;		liMax = 9;		break;
	case 2:		liMin = 10;		liMax = 99;		break;
	case 3:		liMin = 100;	liMax = 999;	break;
	}

	// 条件 - チェック
	for (i = liMin; i <= liMax; i++) {
		sprintf(lc1Buf, "%d", i);
		for (j = 0; j < liM; j++) {
			if (lc1Buf[li1No[j]] != lc1Val[j]) {
				break;
			}
		}
		if (j == liM) {
			return i;
		}
	}

	return -1;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



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

int main(void){
  string w;

  cin >> w;

  sort(w.begin(), w.end());

  for(int i = 0; i < w.size(); i += 2){
    if(w.size() == 1){
      cout << "No" << endl;
      return 0;
    }
    if(w.at(i) != w.at(i+1)){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

int main(){
	int x,y;
	cin>>x>>y;
	if(y< (2*x) || y > (4*x) || (y % 2 !=0 ) ){
		cout<<"No"<<"\n";
	}
	else{
		cout<<"Yes"<<"\n";
	}
}

Measured memory_bytes: 3628
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner InData = new Scanner(System.in);
    int a = InData.nextInt();
    int b = InData.nextInt();
    int c = InData.nextInt();
    if(a>=b || b>=c)
        System.out.println("No");
    else
        System.out.println("Yes");
    }
}

Measured memory_bytes: 26088
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	
	string X;

	cin>>X;
	int K=0,U=0,P=0,C=0;

	for(int i=0;i<X.size();i++)
	{
		if(X[i]=='K')K++;
		if(X[i]=='U')U++;
		if(X[i]=='P')P++;
		if(X[i]=='C')C++;
	}
	int min=K;
	if(min>U)min=U;
	if(min>P)min=P;
	if(min>C)min=C;

	cout<<min<<endl;
	return 0;
}
	

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

void rec (int d, ll now, vector<ll>& vec) {
    //収納
    vec.push_back (now);
    //10桁なら打ち切り
    if (d == 10) return;
    //次の桁へ
    for (int i = -1; i <= 1; i++) {
        int add = (now % 10) + i;
        if (0 <= add && add < 10) rec (d + 1, now * 10 + add, vec);
    }
}

int main() {
    int k;
    cin >> k;
    vector<ll> vec;
    for (int i = 1; i < 10; i++) rec (1, i, vec);
    sort (vec.begin(), vec.end());

    cout << vec[k - 1] << "\n";
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    ll r,s,p;
    cin>>r>>s>>p;
    string t;
    cin>>t;
    ll res=0;
    string t1="";
    for(int i=0;i<n;i++){
        if(i+1<=k){
            if(t[i]=='r')res+=p,t1+="p";
            else if(t[i]=='s')res+=r,t1+="r";
            else res+=s,t1+="s";
        }
        else{
            if(t[i]=='r'){
                if(t1[i-k]=='p')t1+="v";
                else{
                    t1+="p";
                    res+=p;
                }
            }
            else if(t[i]=='s'){
                if(t1[i-k]=='r')t1+="v";
                else{
                    t1+="r";
                    res+=r;
                }
            }
            else if(t[i]=='p'){
                if(t1[i-k]=='s')t1+="v";
                else{
                    t1+="s";
                    res+=s;
                }
            }

        }
    }
    cout<<res<<endl;
    return 0;

}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	for (;;) {
		int a, b;
		char op;
		cin >> a >> op >> b;
		if (op == '?') return 0;
		else if (op == '+') cout << a + b << endl;
		else if (op == '-') cout << a - b << endl;
		else if (op == '*') cout << a * b << endl;
		else cout << a / b << endl;
	}
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25


int main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    
    //割引券を使わない
    int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    //割引券を使う
    rep(i, M){
        int x, y, c;
        cin >> x >> y >> c;
        x--; y--;
        int tmp = a[x] + b[y] - c;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}




Measured memory_bytes: 1024
#include<stdio.h>
int main(){
int ans=0,n,x[110],y[110],z[110],i,a,k;
for(i=0;i<105;i++){
x[i]=0,y[i]=0,z[i]=0;
}
scanf("%d\n",&n);
scanf("%d",&a);
for(i=0;i<a;i++){
scanf("%d",&k);
x[k]++;
}
scanf("\n");
scanf("%d",&a);
for(i=0;i<a;i++){
scanf("%d",&k);
y[k]++;
}
scanf("\n");
scanf("%d",&a);
for(i=0;i<a;i++){
scanf("%d",&k);
z[k]++;
}
for(i=1;i<=n;i++){
if(x[i]==0 && z[i]==1){
ans++;
}
if(y[i]==1 && z[i]==1){
ans++;
}
if(x[i]==0 && y[i]==1 && z[i]==1){
ans--;
}
}
printf("%d\n",ans);
return 0;
}


Measured memory_bytes: 2096
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long int ll;

int main() {
    ll a, b, k; cin >> a >> b >> k;
    ll t = min (a,k);
    k -= t;
    a -= t;
    t = min (k, b);
    b -= t;
    cout << a << " " << b << endl;
    return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<long> A(N);
  bool exist_zero = false;
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
    if (A.at(i) == 0) exist_zero = true;
  }
  long long ans = 1;
  bool is_over = false;
  for (int i = 0; i < N; i++)
  {
    if (ans > 1000000000000000000/A.at(i))
    {
      is_over = true;
      break;
    }
    else ans *= A.at(i);
  }
  if (exist_zero) cout << 0 << endl;
  else if (is_over) cout << -1 << endl;
  else cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;
const ll M=1e9+7;
const ll MAXN=1e6+7;
const ld pi=acos(-1);

#define gi(n) ll n=read()
#define endl '\n'
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define per(i,a,b) for(ll i=b-1; i>=a; --i)

typedef vector<ll> V;
typedef vector<V> VV;
typedef set<ll> S;
typedef pair<ll,ll> pl;
typedef vector<pl> Vp;

#define all(v) v.begin(),v.end()
#define pb push_back
#define fs first
#define sc second

inline ll read(){
	ll x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll pow1(ll p,ll d, ll P){return d?(pow1(p*p%P,d>>1,P)*(d&1?p:1))%P:1;}

void dfs(ll v,ll visited[], vector<ll> &v1,V w[]){ 
	visited[v] = true; 
	v1.pb(v);

	V::iterator i; 
	for(i = w[v].begin(); i != w[v].end(); ++i)
		if(!visited[*i]) 
			dfs(*i, visited,v1,w); 
} 


void doit(){
	gi(n); gi(m);
	ll a[n],b[n];
	V w[n+1],x[n+1];
	rep(i,1,n+1) w[i].pb(i);
	rep(i,0,m){
		gi(p); gi(q);
		w[p].pb(q);
		w[q].pb(p);
	}
	V vis(n+1,0);
	ll visited[n+1]={0},k=0,mm=0;
	rep(i,1,n+1)
		if(w[i].size())
			if(!visited[i])
				dfs(i,visited,x[k],w), k++;
/*	for(auto i:x[0]) cout<<i<<' ';
	cout<<endl;
	for(auto i:x[1]) cout<<i<<' ';
	cout<<endl;*/
	ll s = 0;
	rep(i,0,n+1) s += !x[i].empty();
	cout << s - 1;
	
}
int main(){
//	for(gi(t);t--;cout<<endl)
		doit();
	return 0;
}

Measured memory_bytes: 17728
#include<iostream>

using namespace std;
typedef long long ll;

ll x;

int main() {
	cin >> x;
	ll ans = 0;
	if (x % 11 >= 7)ans += 2;
	else if (x % 11 != 0)ans += 1;
	ans += (x / 11) * 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  int n,m;
  map<string,int> mp;
  cin>>n;
  rep(i,0,n){
    string s;
    cin>>s;
    mp[s]=1;
  }
  cin>>m;
  int cnt=0;
  rep(i,0,m){
    string s;
    cin>>s;
    if(mp[s]&&cnt%2==0){
      cout<<"Opened by "<<s<<endl;
      cnt++;
    }else if(mp[s]!=0&&cnt%2==1){
      cout<<"Closed by "<<s<<endl;
      cnt++;
    }else{
      cout<<"Unknown "<<s<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3204
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==5&&b==5&&c==7)
        cout<<"YES"<<endl;
    else if(a==5&&b==7&&c==5)
        cout<<"YES"<<endl;
    else if(a==7&&b==5&&c==5)
        cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;

}


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

#define TABLE_LEN	1048575
#define TABLE_COL	16
long long int  StrtoInt[TABLE_LEN][TABLE_COL];

long long int Convert( char *Str)
{
	long long int Result = 0;
	for (int i = 0; i < strlen(Str); i++)
	{
		Result += (Str[i] - 'a' + 1);
		Result *= ('z' - 'a' + 1);
	}

	return Result;
}

int main()
{
	char Str[128];

#ifdef _WIN32
	freopen("input.txt", "r", stdin);
#endif

	int N;
	scanf("%d", &N);
	int Result = 0;
	for (int n = 0; n < N; n++)
	{
		scanf("%s", Str);
		long long int StrVal = Convert(Str);
		long long int Hash = StrVal % TABLE_LEN;
		
		for (int i = 0; i < TABLE_COL; i++)
			if ((StrVal == StrtoInt[Hash][i]) )
				break;
			else if (StrtoInt[Hash][i] == 0)
			{
				StrtoInt[Hash][i] = StrVal;
				Result++;
				break;
			}
			
	}
	


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

Measured memory_bytes: 132512
#include <stdio.h>
#include <math.h>

int keta(int i,int a,int b){
int amari = 0,num = i;
while (i != 0) {
	amari += (i % 10);
	i /= 10;
}
if (a <= amari && amari <= b) return num;
else return 0;
}


int main(void) {
	int n, a, b,sum = 0;
	scanf("%d %d %d", &n, &a, &b);
	for (int i = 1; i <= n; i++)
	{
		sum += keta(i,a,b);
	}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
using System;

class ITP1_8_A{
    static void Main(string[] args){
        string str = Console.ReadLine().Trim();
        char[] cs = str.ToCharArray();
        foreach(char s in cs){
            if(char.IsUpper(s)){
                Console.Write(char.ToLower(s));
            } else if(char.IsLower(s)){
                Console.Write(char.ToUpper(s));
            } else {
                Console.Write(s);
            }
        }
        Console.WriteLine();
    }
}


Measured memory_bytes: 15884
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str;
    cin>>str;
    int ans=0;
    int fp=0;
    int bp=str.size()-1;
    while(fp<bp){
        if(str[fp]!=str[bp]){
            if(str[fp]=='x'){
                ++fp;
                ++ans;
            }else if(str[bp]=='x'){
                --bp;
                ++ans;
            }else{
                ans = -1;
                break;
            }
        }else{
            ++fp;
            --bp;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
	string a;
	
	int b[30];
	for (int i = 0;i < 26;i++) { b[i] = 0; }
	int num;
	int ans;
	char ch;
	int n;
	
	while (cin>>ch) {
		if (ch>= 'a'&&ch <= 'z') { num = ch - 'a';b[num]++; }
		else if (ch >= 'A'&&ch <= 'Z') { num = ch - 'A';b[num]++; }
		

	}
	cout << "a : " << b[0] << endl;
	cout << "b : " << b[1] << endl;
	cout << "c : " << b[2]<< endl;
	cout << "d : " << b[3]<< endl;
	cout << "e : " << b[4] << endl;
	cout << "f : " << b[5] << endl;
	cout << "g : " << b[6] << endl;
	cout << "h : " << b[7]<< endl;
	cout << "i : " << b[8] << endl;
	cout << "j : " << b[9]<< endl;
	cout << "k : " << b[10] << endl;
	cout << "l : " << b[11]<< endl;
	cout << "m : " << b[12]<< endl;
	cout << "n : " << b[13]<< endl;
	cout << "o : " << b[14]<< endl;
	cout << "p : " << b[15]<< endl;
	cout << "q : " << b[16]<< endl;
	cout << "r : " << b[17]<< endl;
	cout << "s : " << b[18]<< endl;
	cout << "t : " << b[19]<< endl;
	cout << "u : " << b[20]<< endl;
	cout << "v : " << b[21]<< endl;
	cout << "w : " << b[22]<< endl;
	cout << "x : " << b[23]<< endl;
	cout << "y : " << b[24]<< endl;
	cout << "z : " << b[25]<< endl;
	

	return 0;
}


Measured memory_bytes: 3104
#include<iostream>
int main(){
  long long int a=0,ans,i,n;
  scanf("%lld\n",&n);
  for(i=1;i*i<=n;i++){
    if(n%i==0){
      ans=n/i;
    }
  }
  while(ans>0){
    a++;
    ans=ans/10;
  }
  printf("%lld\n",a);
  return 0;
}

Measured memory_bytes: 384
# coding: utf-8
while 1:
    s=input()
    if s=='#':
        break
    s=s.split('/')
    field=[list(''.join(['b' if c=='b' else '.'*int(c) for c in s[i]]))  for i in range(len(s))]
    a,b,c,d=map(int,input().split())
    field[a-1][b-1],field[c-1][d-1]='.','b'
    print('/'.join(['b'.join('' if len(c)==0 else str(len(c)) for c in ''.join(field[i]).split('b') ) for i in range(len(field))]))


Measured memory_bytes: 5604
#include <iostream>
#include <string.h>

#include <vector>

using namespace std;
using ll = long long;
using vi = vector<int>;


#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

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

  char S[(int)1e5];
  int K;
  scanf("%s%d", S, &K);
  int N = strlen(S);

  vi v(N); // v[i] = S[i]をaにするのに必要なコスト
  REP(i, N) {
    int index = lower_bound(ALL(alphabet), S[i]) - alphabet.begin();
    v[i] = (26 - index) % 26;
  }
  REP(i, N) {
    if (i == N-1)
      cout << alphabet[(26-v[i]+K) % 26];
    else if (K >= v[i]) {
      K -= v[i];
      cout << "a";
    } else
      cout << S[i];
  }
  cout << "\n";

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
void insertionSort(vector<int> array, int n)
{
    for (int i = 1; i < n; i++) {
        int cur = array[i];
        int j = i - 1;
        while (j >= 0 && array[j] > cur) {
            array[j + 1] = array[j];
            j--;
        }
        array[j + 1] = cur;
        rep(k, n)
        {
            cout << array[k];
            if (k != n - 1)
                cout << " ";
        }
        cout << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) { cin >> a[i]; }
    rep(k, n)
    {
        cout << a[k];
        if (k != n - 1)
            cout << " ";
    }
    cout << endl;

    insertionSort(a, n);
    return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3001000;
int a[N],b[N],n,m,K;
char s1[N],s2[N];
stack<pair<int,int> > st;
void init(){
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	while(!st.empty()){
		int w=st.top().first,A=st.top().second>>1&1,B=st.top().second&1;
		//cout<<w<<' '<<A<<' '<<B<<'\n';
		a[w]=A;b[w]=B;st.pop();
	}
}
void print(int*a){
	int len=N;
	while(!a[--len]);
	while(~len) cout<<a[len--];
	cout<<'\n';
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m>>K;
	cin>>s1>>s2;
	for(int i=0;i<n;i++) a[n-i-1]=s1[i]-'0';
	for(int i=0;i<m;i++) b[m-i-1]=s2[i]-'0';
	for(int i=max(n,m)-1;~i;i--){
		if(a[i]+b[i]==1) st.emplace(i,a[i]<<1|b[i]);
		if(a[i]+b[i]<2) continue;
		int now=K,pos=i,x=3;
		stack<pair<int,int> > res;
		while(!st.empty()){
			auto tmp=st.top();
			if(pos==tmp.first){
				st.pop();
				if((x^tmp.second)==3){if((x=3)&&--now<0) break;}
				else{
					if(x^3){pos++;continue;}
					res.emplace(pos,x^tmp.second);
					x&=tmp.second;
				}
				pos++;
			}
			else{
				if(x==3&&(now-=tmp.first-pos)<0||x!=3){
					if(now<0) pos=tmp.first+now;
					break;
				}
				pos=tmp.first;
			}
		}
		if(x==3&&now>0) pos+=now;
		res.emplace(pos,x);
		while(!res.empty()){
			st.push(res.top());res.pop();
		}
	}
	init();
	print(a);
	print(b);
	return 0;
}


Measured memory_bytes: 34560
#include<bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define ll long long
#define ull unsigned long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
const ll M = 1e9+7;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

char s[maxn];
ll f[maxn][2];

int main()
{
    fastio();
    cin>>s+1;
    int n = strlen(s+1);
    f[0][1] = 1;
    rep(i,1,n){
        f[i][0] = f[i-1][0]*3%M;
        f[i][1] = f[i-1][1];
        if(s[i]=='1'){
            f[i][1] = f[i-1][1]*2%M;
            f[i][0] = (f[i][0] + f[i-1][1]) %M;
        }
    }
    cout<<(f[n][0] + f[n][1])%M<<endl;
    return 0;
}


Measured memory_bytes: 5232
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
	double ans1 = 0, ans2 = 0;
	for (int i = 0; i <= f / (100 * a); i++) {
		for (int j = 0; j <= f / (100 * b); j++) {
			for (int k = 0; k <= 100; k++) {
				for (int l = 0; l <= 100; l++) {
					double w = (a*i + b*j) * 100, s = k*c + l*d;
					if (w + s <= f&&w / 100 * e >= s) {
						if (ans2 == 0 || s / (w / 100 * e) > ans2 / (ans1 / 100 * e)) {
							ans1 = w; ans2 = s;
						}
					}
				}
			}
		}
	}
	cout << ans1 + ans2 << ' ' << ans2 << endl;
	return 0;
}

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


int main()
{
	int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define INF 1000000000

void test_case()
{
	int n;
	cin >> n;
	ll a[n], mod = 1e9 + 7;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	ll suffix[n] = {};
	suffix[n - 1] = a[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		suffix[i] = (suffix[i + 1] + a[i]) % mod;
	}
	ll ans = 0;
	for (int i = 0; i < n - 1; i++) {
		ans = (ans + a[i] * suffix[i + 1]) % mod;
	}
	cout << ans;
}


int main()
{
	fastio
	// int t;
	// cin >> t;
	// while (t--)
	test_case();
}


Measured memory_bytes: 6784
N = int(input())
freq = {}
arr = map(int,input().split())
for i in arr:
    try:
        freq[i] += 1
    except KeyError:
        freq[i] = 1

to_multiply = []      
for i in sorted(freq.keys(),reverse=True):
    if freq[i] >= 4:
        to_multiply.append(i)
        to_multiply.append(i)
    elif freq[i] >= 2:
        to_multiply.append(i)
if len(to_multiply) >= 2:
    print(to_multiply[0] * to_multiply[1])
else:
    print("0")


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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N) { cout << N * (N - 1) / 2 << endl; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3700
char s[65536],t[65536];
int main(n,i,r,w,c)
{
	for(;scanf("%d",&n),n;puts(s))
		for(i=!scanf("%s",s);i++<n;t[w]=0,strcpy(s,t))
			for(r=w=0;r<strlen(s);t[w++]=s[r],r+=c){
				for(c=0;s[++c+r]==s[r];);
				for(sprintf(t+w,"%d\0",c);t[++w];);
			}
	exit(0);
}

Measured memory_bytes: 492
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;
        long[] H;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            H = new long[N];
            for (int i = 0; i < N; i++) {
                H[i] = sc.nextLong();
            }
        }
        long[] L = new long[N];
        for (int i = 0; i < N; i++) {
            L[i] = H[i] -1;
        }



        if (H.length == 1) {
            System.out.println("Yes");
            return;
        }
        if (H.length == 2 && H[0] - H[1] <= 1) {
            System.out.println("Yes");
            return;
        }

        long min = H[0];
        for (int i = 1; i < N; i++) {
            if(min >H[i]&& min >L[i]){
                System.out.println("No");
                return;
            }else{
                if(min >H[i]){
                    min = L[i];
                    continue;
                }else if(min >L[i]){
                    min = H[i];
                    continue;
                }
                if(H[i] > L[i]){
                    min = L[i];
                }else{
                    min = H[i];
                }
            }

        }

        System.out.println("Yes");
        return;

    }
}


Measured memory_bytes: 50396
/*
 * p = 1:x[i] - y[i] ?????¶?????????????¨?
 * p = 2:x[i] - y[i] ?????¶???????????????????????????????¨?
 * p = 3:x[i] - y[i] ?????¶???????????????????????????????¨?
 * p = infinity:x[i] - y[i] ?????¶??????????????§???
 */

import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int count = scan.nextInt();
		int[] x = new int[count];
		int[] y = new int[count];
		double p;
		double p_1 = 0;
		double p_2 = 0;
		double p_3 = 0;
		double p_inf = 0;
		
		for(int i = 0;i < count;i++)
		{
			x[i] = scan.nextInt();
		}
		for(int i = 0;i < count;i++)
		{
			y[i] = scan.nextInt();
		}
		
		for(int i = 0;i < count;i++)
		{
			p = Math.abs(x[i] - y[i]);
			p_1 += p;
			p_2 += Math.pow(p, 2);
			p_3 += Math.pow(p, 3);
			if(p > p_inf){p_inf = p;}
		}
		p_2 = Math.sqrt(p_2);
		p_3 = Math.cbrt(p_3);
		
		System.out.printf("%f\n%f\n%f\n%f\n", p_1, p_2,p_3,p_inf);
	}
}

Measured memory_bytes: 20544
import os
import sys
from io import BytesIO, IOBase
# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------------------

def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def toord(c): return ord(c)-ord('a')
def lcm(a, b): return a*b//lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush


# ------------------------------
# f = open('./input.txt')
# sys.stdin = f

def main():
    x = N()
    print('Yes' if x>=30 else 'No')

if __name__ == "__main__":
    main()



Measured memory_bytes: 67456
n,k=map(int,input().split())
xlist=list(map(int,input().split()))

timelist=[]
for i in range(n-(k-1)):
	bpoint=xlist[i+k-1]
	spoint=xlist[i]
	timelist.append(bpoint-spoint+min(abs(bpoint),abs(spoint)))

print(min(timelist))



Measured memory_bytes: 20108
def f1(a)
  [a / (8/100r), (a + 1) / (8/100r)]
end

def f2(b)
  [b / (10/100r), (b + 1) / (10/100r)]
end

def find(a1, a2)
  bgn = [a1[0], a2[0]].max.ceil
  ed = [a1[1], a2[1]].min
  f = if ed == ed.floor
    bgn < ed
  else
    bgn <= ed.floor
  end
  f ? bgn : -1
end

a, b = gets.split.map(&:to_i)
puts find(f1(a), f2(b))

Measured memory_bytes: 3836
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
from itertools import product
l=list(product([1,0],repeat=N))
L=[]
for i in range(N):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        L.append([x,y,i+1])
a=0
for i in l:
    t=N
    for j in L:
        if i[j[2]-1]==1 and j[1]!=i[j[0]-1]:
            break
    else:
        if a<i.count(1):
            a=i.count(1)
print(a)

Measured memory_bytes: 46960
#include<stdio.h>
int a[1000000];
int main(void)
{
	int s,d,f,g,h,i,j;
	a[1]=0;
	for(i=2;i<=999999;i++){
		a[i]=1;
	}
	for(i=2;i*i<=1000000;i++){
		if(a[i]!=0){
			s=2;
			while(i*s<=999999){
				a[i*s]=0;
				s++;
			}
		}
	}
/*	for(i=1;i<=100000;i++){
		if(a[i]==1){
			printf("%d\n",i);
		}
	}*/
	while(scanf("%d",&f)!=EOF){
		g=0;
		for(i=1;i<=f;i++){
		if(a[i]==1){
			g++;
		}
	}
	printf("%d\n",g);
	}
	return 0;
}

Measured memory_bytes: 4928
#include <bits/stdc++.h>
using namespace std;
#define nin(n) int n; cin >> n;
#define kin(k) int k; cin >> k;
 
int main() {
  int n; cin >> n;
  int k; cin >> k;
  int w[n+3];long long v[n+3];
  for(int i=0;i<n;i++){
    cin >> w[i+1] >> v[i+1];
  }
  long long dp[n+10][k+10]={};
  for(int i=1;i<n+1;i++){
    for(int j=0;j<=k;j++){
      if(j-w[i]>=0){
        dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
      }
      dp[i][j]=max(dp[i-1][j],dp[i][j]);
    }
  }
  cout << dp[n][k];
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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

ll seica(ll n){
	ll ret = (n % 4 == 1 || n % 4 == 2);
	for(ll i = 2;i < 60;i++){
		ll a = 1LL << i;
		ll b = 1LL << (i - 1);
		ll tmp = n % a - b + 1;
		if(tmp <= 0)continue;
		if(tmp % 2)ret |= 1LL << (i - 1);
	}
	return ret;
}

int main(){

	ll l, r;cin >> l >> r;
	l = max(0LL, l - 1);

	cout << (seica(l) ^ seica(r)) << endl;
	return 0;
}


Measured memory_bytes: 256