akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Lesson8C 与えられた英文に含まれる、各アルファベットの数を数えるプログラム なお、小文字と大文字は区別しない
 *
 * @author Internship
 *
 */
public class Main{

	/**
	 * プログラムのエントリポイント
	 *
	 * @param args
	 */
	public static void main(String[] args) {

		// a ~ｚのパターン
		char[] chaAZ = { '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' };

		// a?zのパターンが各何回あるかカウントする場所
		int[] intAZ = new int[26];

		// 各行読み込む
		try {
			BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));

			String strLine = "a";
			while ((strLine = insBR.readLine()) != null) {

				// 大文字は小文字にしておく
				strLine = strLine.toLowerCase();

				// char型に分解
				char[] chaAryLine = strLine.toCharArray();

				// 各a?z何回あるかカウント
				for (int i = 0; i < chaAryLine.length; i++) {
					for (int j = 0; j < intAZ.length; j++) {
						if (chaAryLine[i] == chaAZ[j]) {
							intAZ[j]++;
						}
					}
				}
			}

			// 出力
			for (int i = 0; i < intAZ.length; i++) {
				System.out.println(chaAZ[i] + " : " + intAZ[i]);
			}

		} catch (IOException e) {
			System.out.println(e);
		}

	}
}

Measured memory_bytes: 17884
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace csharp
{
    class Program
    {
        static int[] ReadInts()
            => Console.ReadLine()
                .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => int.Parse(s))
                .ToArray();

        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            Console.WriteLine(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");
        }
    }
}


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

/*
選んだ整数XはAの倍数の総和より、XはAの倍数
X = n * A
これをBでわるとあまりがC

A / Bのあまりを考える？
(A%B) * pのあまりを考えていくとあまりが2, 1, 0ぐらいまで落とせるので、判定可能

あるいは偶数奇数を考える？
奇数を奇数でわると、あまりは偶数
偶数を奇数でわると、あまりは奇数
偶数を偶数でわると、あまりは0
奇数を偶数でわると、あまりは奇数
*/

// int main() {
//     int A, B, C;
//     cin >> A >> B >> C;

//     int mod = A % B;
//     bool res = false;
//     while (mod > 0)
//     {
//         // sleep(1);
//         // cout << "prev " << mod << endl;
//         if (C % mod == 0)
//         {
//             res = true;
//             break;
//         }

//         int i = 1;
//         while (mod * i < B)
//         {
//             i++;
//         }
//         mod = mod * i;
//         // cout << "now " << mod << endl;

//         mod = mod % B;
//     }

//     if (res)
//         cout << "YES" << endl;
//     else
//         cout << "NO" << endl;
// }

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

    bool res = false;
    for (int i = 1; i <= B; i++)
    {
        int c = (i * A) % B;
        if (c == C) {
            res = true;
            break;
        }
    }

    if (res)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;    
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
typedef pair<P, long long int> P2;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;
int const TREE_SIZE = 1 << 20;
long long int seg_tree[TREE_SIZE];
bool is_a[TREE_SIZE];

int getsum(int a, int b, int index, int l, int r){
	
	if(r <= a || b <= l){
		return 0;
	}
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	if(is_a[index]){
		return seg_tree[index] / (r - l) * (min(r, b) - max(l, a));
	}
	int ret = 0;
	ret += getsum(a, b, index * 2, l, (l + r) / 2);
	ret += getsum(a, b, index * 2 + 1, (l + r) / 2, r);
	return ret;
}

int update(int a, int b, int index, long long int num, int l, int r){
	
	// [a, b) を num に変更する
	
	if(r <= a || b <= l){
		return seg_tree[index];
	}
	if(a <= l && r <= b){
		seg_tree[index] = num * (r - l);
		is_a[index] = true;
		return seg_tree[index];
	}
	int ret = 0;
	if(is_a[index]){
		is_a[index * 2] = true;
		seg_tree[index * 2] = seg_tree[index] / 2;
		is_a[index * 2 + 1] = true;
		seg_tree[index * 2 + 1] = seg_tree[index] / 2;
		is_a[index] = false;
	}
	ret += update(a, b, index * 2, num, l, (l + r) / 2);
	ret += update(a, b, index * 2 + 1, num, (l + r) / 2, r);
	return seg_tree[index] = ret;
}

int main(){
	int n, q;
	cin >> n >> q;
	
	for(int i = 0; i < q; i++){
		long long int num, a, b, c;
		cin >> num;
		if(num == 0){
			cin >> a >> b >> c;
			update(a, b + 1, 1, c, 0, TREE_SIZE / 2);
		}else{
			cin >> a >> b;
			cout << getsum(a, b + 1, 1, 0, TREE_SIZE / 2) << endl;
		}
	}
	return 0;
}



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

int main() {
  string S;
  cin >> S;
  char c;
  bool is_easy = true;
  rep(i, S.size()) {
    c = S.at(i);
    if ( c == 'U' || c == 'D' ) {
    }
    else if ( (i+1) % 2 == 1 && c == 'R' ) {
    }
    else if ( (i+1) % 2 == 0 && c == 'L' ) {
    }
    else {
      is_easy = false;
      break;
    }
  }
  string answer = is_easy ? "Yes" : "No";
  cout << answer << endl;
}

Measured memory_bytes: 256
n=int(input())
A=[[0]*2 for i in range(n)]
for i in range(n):
  A[i]=list(map(int,input().split()))
a=0
for i in range(n-1):
  for j in range(i+1,n):
    a=a+((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)**(1/2)
print(a/n*2)

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  vector<pi> ba;
  REP(i, n) {
    int a = read(), b = read();
    ba.PB(MP(b, a));
  }
  sort(ALL(ba));
  int time = 0;
  for (auto p : ba) {
    time += p.second;
    if (time > p.first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

int main() {
  string S; cin >> S;
  int ans = 0;
  int N = S.length();
  for (int i=0; i<N/2; i++) {
    if (S[i] != S[N-i-1]) ans++;
  }
  cout << ans << endl;

  return 0;
}


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


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

  vector<pair<int,int>> py(M);
  vector<vector<int>> vec(N+1,vector<int>(0));
  for(int i = 0;i < M;i++) {
    int P,Y;
    cin >> P >> Y;
    pair<int,int> q = make_pair(P,Y);
    py.at(i) = q;

    vec.at(P).push_back(Y);
  }

  for(int i = 1;i <= N;i++) {
    sort(vec.at(i).begin(),vec.at(i).end());
  }

  for(int i = 0;i < M;i++) {
    int n = py.at(i).first;
    int t = py.at(i).second;
    auto it = lower_bound(vec.at(n).begin(),vec.at(n).end(),t);
    int dis = distance(vec.at(n).begin(),it);
    cout << setfill('0') << right << setw(6) << n;
    cout << setfill('0') << right << setw(6) << dis+1 << endl;
  }

}

Measured memory_bytes: 7808
/*input
12345678 87654321 12345678 87654321
123456789
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <climits>
typedef unsigned long long ll;
using namespace std;

int main() {
	int q,h,s,d,n;
	scanf("%d%d%d%d%d", &q, &h, &s, &d, &n);
	if(q*4 < s) s = q*4;
	if(h*2 < s) s = h*2;
	if(s*2 < d) printf("%lld", s*1ll*n);
	else printf("%lld", 1ll * (n/2) *d + (n%2)*s);
}

Measured memory_bytes: 256
n,m=map(int,input().split())
h=list(map(int,input().split()))
high=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]>h[b-1]:
        high[b-1]=1
    elif h[a-1]<h[b-1]:
        high[a-1]=1
    else:
        high[a-1]=1
        high[b-1]=1
print(high.count(0))

Measured memory_bytes: 20116
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n + 1):
        k = n - i - j
        if k < 0:
            continue
        if i * 10000 + j * 5000 + k * 1000 == y:
            print(i, j, k)
            exit()
print(-1, -1, -1)


Measured memory_bytes: 2940
#include <stdio.h>

int main(void) {
	int N, K;

	scanf("%d %d", &N, &K);
	int saisyou, saidai;
	if (N % K > 0) saidai = N % K + 1;
	else saidai = N % K;
	saisyou = N % K;

	int zettai = saidai - saisyou;

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

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

const int MAX = 100005;
int A[MAX], B[MAX];

int main() {
    string s;
    cin >> s;
    int p = 1;
    char c = s[0];
    for (int i = 0; i < s.size(); i++) {
        if (c != s[i]) {
            p++;
            c = s[i];
        }
        A[p]++;
    }

    for (int i = 1; i <= p; i++) B[i] = B[i-1] + A[i];
    int ans = B[p];
    for (int i = 1; i <= p; i++) {
        ans = min(ans, max(B[i], B[p] - B[i]));
    }
    
    printf("%d\n", ans);

    return 0;
}

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

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

    for(int i = 1; i < b; i++){
        if((a*(1+i))%b == c){
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int r, g, b, n;
	cin >> r >> g >> b >> n;

	ll cnt = 0;
	rep(i, 3001) {
		rep(j, 3001) {
			int k = (n - r * i - g * j);
			if (k >= 0 && k % b == 0) {
				cnt++;
			}
		}
	}

	out(cnt);

	return 0;
}

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

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};



int main(){
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;
	cout << a+b+c+d+e+f-min(min(a,b),min(c,d))-min(e,f) << endl;
	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 100000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

ll dp[30000];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(ll,N);
  str SN = to_string(N);
  ll num = SN.size();
  ll sum = 0LL;
  if(num%2){
    REP(i,num/2){
      sum += 9LL * pow(100,i);
    }
    sum += N - pow(100,num/2) + 1;
  }else{
    REP(i,num/2){
      sum += 9LL * pow(100,i);
    }
  }
  OUT(sum);
}



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

#define IN(a) int a;scanf("%d",&a);
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define STRS(i,str) for(int i=0;(str)[i];i++)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX3(a,b,c) ((a)>(b)?(a)>(c)?(a):(c):(b)>(c)?(b):(c))
#define MIN3(a,b,c) ((a)<(b)?(a)<(c)?(a):(c):(b)<(c)?(b):(c))
#define RANGE(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define RANGE3(a,b,c) ((a)>(b)?(b)>(c)?(a)-(c):(c)>(a)?(c)-(b):(a)-(b):(b)>(c)?(c)>(a)?(b)-(a):(b)-(c):(c)-(a))
#define MINI(a,b) if(a>b)a=b;
#define MAXI(a,b) if(a<b)a=b;

int main(void){
	IN(n);
	int *a;
	a = (int *)malloc(sizeof(int) * n);
	REP(i, n) scanf("%d", a + i);

	long ans;
	long sum = 0, hoge;
	REP(i, n) sum += a[i];
	ans = RANGE(a[0], sum - a[0]);
	hoge = a[0];
	FOR(i, 1, n - 1){
		hoge += a[i];
		MINI(ans, RANGE(hoge, sum - hoge));
	}
	printf("%ld", ans);

	return 0;
}

Measured memory_bytes: 896
N,K = map(int,input().split())
A = list(map(int,input().split()))

L = 40
bc = [0] * L
for i in range(L):
    for a in A:
        if a&(1<<i):
            bc[i] += 1

dp = [[-1,-1] for _ in range(L+1)]
dp[L][0] = 0
for i in range(L-1,-1,-1):
    c = (K>>i)&1
    for l in range(2):
        if dp[i+1][l] < 0: continue
        for d in range(2):
            if l==0 and d > c: continue
            nl = 0 if l==0 and d==c else 1
            dp[i][nl] = max(dp[i][nl], dp[i+1][l] + 2**i * (N-bc[i] if d else bc[i]))

print(max(dp[0]))

Measured memory_bytes: 20604
#include<bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define FF first
#define SS second
using namespace std;
template<typename T> inline void gmax(T &x, T y){x = x > y ? x : y;}
template<typename T> inline void gmin(T &x, T y){x = x < y ? x : y;}
const int MAXN = 2010;
int a[MAXN], b[MAXN];
int n, k, q, ans;
bool check(int l, int r){
	int cnt, i, j, tmp;
	for(cnt = 0, i = 0, j = 0, tmp = 0; i < n; i++){
		if(a[i] < l) cnt += max(0, i - j - tmp - max(k - 1 - tmp, 0)), j = i + 1, tmp = 0;
		else if(a[i] > r) tmp++;
	}
	cnt += max(0, i - j - tmp - max(k - 1 - tmp, 0));
	return cnt >= q;
}
int main(){
	scanf("%d%d%d", &n, &k, &q);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]), b[i] = a[i];
	sort(b, b + n);
	ans = b[n - 1] - b[0];
	for(int i = 0, j = 0; i < n; i++){
		while(j < n && !check(b[i], b[j])) j++;
		if(j == n) break;
		gmin(ans, b[j] - b[i]);
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
    cin >> n;
	vector<int> res(n);
	rep (i, n - 1) {
	  int a;
	  cin >> a;
	  res[a - 1]++;
	}
	rep (i, n) cout << res[i] << endl;
    
    return 0;
}


Measured memory_bytes: 3996
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;

int main(){
	ll a,b;cin>>a>>b;
	if(a==b){
		puts("1");
		return 0;
	}
	bool flag=false;
	ll A=0,B=0,T=0,C=0;
	for(int i=60;i>=0;i--){
		if(!flag&&!(a>>i&1)&&(b>>i&1)){
			flag=true;
			T=1LL<<i;
		}
		if(flag){
			if(B!=0&&C==0&&(b>>i&1))C=(1LL<<(i+1))-1;
			A|=(a>>i&1)<<i;
			B|=(b>>i&1)<<i;
		}
	}
	P X=P(A,T-1);
	P Y=P(T,T+C);
	P XY=P(T|A,(T<<1)-1);
	ll cnt=Y.second-X.first+1+XY.second-XY.first+1;
	if(XY.first<=T+C)cnt-=T+C-XY.first+1;
	cout<<cnt<<endl;
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  string ans;
  int ab = abs(a-b);
  int bc = abs(b-c);
  int ac = abs(a-c);
  if((ab<=d && bc<=d) || ac<=d) ans = "Yes";
  else ans = "No";
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  string S;
  cin >> S;

  // erase(n,m) :: n文字目からm文字削除する
  // n:: 0-S.size()-1;
  // m:: Size() - まで

  bool flg = false;
  for(int n = 0; n <= S.size()-1; n++){
    for(int m = 0; m <= S.size()-n; m++){
      string T = S;
      if(T.erase(n,m) == "keyence"){
        flg = true;
        break;
      }
    }
    if(flg) break;
  }

  cout << (flg ? "YES" : "NO") << endl;

}


Measured memory_bytes: 256
#ifdef _DEBUG
#include ".vscode/debug_print.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>

using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1050000000;
constexpr long long INF64 = 4000000000000000000;
constexpr int MOD7        = 1000000007;
constexpr int MOD53       = 998244353;
constexpr long double PI  = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

void vprint() { std::cout << '\n'; }
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}

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

    int N, M;
    scan(N, M);
    int ans = (N * (N - 1)) / 2 + (M * (M - 1)) / 2;
    print(ans);

    return 0;
}

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

using namespace std;

int main(int argc, char const *argv[]) {
  string str;
  cin >> str;
  int count = 0;

  for (int i = 0; i < 3; i++) if (str[i] == '1') count++;

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
# (買い場,売り場)の候補
import numpy as np
N,T = map(int,input().split())
A = np.array(input().split(),dtype=np.int32)

# 自分より左にある最安値
A_cummin = np.minimum.accumulate(A)
# 差額
profit = A - A_cummin

answer = (profit == profit.max()).sum()
print(answer)

Measured memory_bytes: 32460
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
bool dbg = false;
int N, A[100], B[100], C[100];
void solve()
{
    int ans = 0;
    FORR(i, 1, N)
    {
        ans += B[i];
    }
    FORR(i, 1, N - 1)
    {
        if (A[i] + 1 == A[i + 1]) {
            ans += C[A[i]];
        }
    }
    cout << ans << endl;
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FORR(i, 1, N)
    {
        cin >> A[i];
    }
    FORR(i, 1, N)
    {
        cin >> B[i];
    }
    FORR(i, 1, N - 1)
    {
        cin >> C[i];
    }
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void output(int*,int);
void insertionSort(int*,int);

int main()
{
  int n,i;
  int a[100];

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

  return 0;
}

void output(int *a,int n) /* print */
{
  int i;
  for(i=0; i<n; i++){ 
    printf("%d",a[i]);
    if(i<n-1) printf(" ");
  }
  printf("\n");
}
    
void insertionSort(int *a,int n) /* sort */
{
  int i,j,v;

  for (i=1; i<n; i++){
    v = a[i];
    /* insert a[j] into the sorted sequence a[1,...,j-1] */
    j = i-1;
    while(j >= 0 && a[j] > v) {
      a[j+1] = a[j];
      j--;
    }

    a[j+1] = v;
    output(a,n);
  }
}
    

Measured memory_bytes: 604
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 100000000;

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}

int factrial(int n){
    if(n==0){
        return 1;
    }else{
        return n*factrial(n-1);
    }
}

int main(void){
    int ans = 0;
    int a,b;
    cin >> a >> b;
    for(int i=1;i<=a;++i){
        for(int j=1;j<=13;++j){
            if(i==j){
                ans++;
            }
            if(i==a && j==b){
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



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

#define io ios::sync_with_stdio(false)
#define pb push_back
#define pqueue priority_queue
#define fi first
#define se second
#define ls rt<<1
#define rs rt<<1|1
#define sz(x) (int)(x).size()
#define dbg(x) cout<<#x<<" --- "<<x<<endl
#define mst(x,a) memset(x,a,sizeof(x))
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r; }
const int inf=0x7fffffff;
const int maxn=2e5+10;
pqueue<pii> que;
int a[maxn];
int n;

int main(){
	io;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	ll ans=a[n];
	que.push(pii(a[n-1],a[n]));
	que.push(pii(a[n-1],a[n]));
	for(int i=n-2;i>=1;i--){
		pii u=que.top();que.pop();
		ans+=u.fi;
		que.push(pii(a[i],u.fi));
		que.push(pii(a[i],u.se));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6076
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  string S;
  cin >> S;
  int L = S.size();
  
  string ans = "AC";
  if(S.at(0)!='A'){
    ans = "WA";
  }
  
  int cnt = 0;
  repi(i,1,L-1){
    if(isupper(S.at(i))) {
      if(i==1 || i==L-1 || S.at(i) != 'C'){
        ans = "WA";
      }
      cnt++;
    }
  }
  
  if(cnt != 1) {
    ans = "WA";
  }
  
  cout << ans << endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }

const int maxn = 2e5 + 7;
const ll inf = 1e18;

vector<ll> v(maxn);
vector<ll> mostposs(maxn);

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;

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

    if (n == 0) {
        if (v[0] != 1) out(-1);
        out(1);
    }

    ll activep = 1LL;
    for (int i = 0; i <= n; i++) {
        if (v[i] > activep) out(-1);
        activep -= v[i];
        if (activep <= inf/2LL) activep *= 2LL;
    }

    if (v[0] > 0) {
        out(-1);
    }

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

    activep = 1LL;
    ll ans = 1LL;
    for (int i = 1; i <= n; i++) {
        activep *= 2LL;
        if (v[i] > activep) out(-1);
        ans += v[i]; // add leaves
        activep -= v[i]; // minus leaves bc they can't be parents to next level
        activep = min(mostposs[i+1],activep); // bound # of node that will be parents to next level
        ans += activep; // add parents of this level
    }
    
    out(ans);
    
    return 0;
}


Measured memory_bytes: 6284
#include <stdio.h>

int main(void)
{
	int a, b;

	scanf("%d %d", &a, &b);

	if (a < b) {
		printf("a < b\n");
	}
	else if (a > b) {
		printf("a > b\n");
	}
	else {
		printf("a == b\n");
	}

	return 0;
}

Measured memory_bytes: 580
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
	int n;cin>>n;
	map<int,int> a;
	rep(i,n){
		int b;cin>>b;
		a[b]++;
	}
	vector<int> usable(2,0);
	itr(i,a){
		int k=i->second;
		while(k>=2){
			usable.push_back(i->first);
			k-=2;
		}
	}
	sort(usable.rbegin(),usable.rend());
	cout<<usable[0]*usable[1]<<endl;
}

Measured memory_bytes: 6656
S = input()
if S[0] == 'A':
    if S[1] != 'C' and S[-1] != 'C':
        if S.count('C') == 1:
            S = S.lstrip('A')
            S = S.replace('C','c')
            if S.islower():
                print("AC")
                exit(0)

print('WA')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;

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

struct LintSumLazySegmentTree {
private:
    int n;
    vec<lint> node, lazy;

public:
    LintSumLazySegmentTree(vec<lint> v){
        int size = (int)v.size();
        n = 1;
        while (n < size) n *= 2;
        node.resize(2 * n - 1);
        lazy.resize(2 * n - 1, 0);

        for (int i = 0; i < size; i++) {
            node.at(i + n - 1) = v.at(i);
        }
        for (int i = n - 2; i >= 0; i--) {
            node.at(i) = node.at(2 * i + 1) + node.at(2 * i + 2);
        }
    }

    void eval(int idx, int cur_left, int cur_right) {
        if (lazy.at(idx) != 0) {
            node.at(idx) += lazy.at(idx);

            if (cur_right - cur_left > 1) {
                lazy.at(2 * idx + 1) += lazy.at(idx) / 2;
                lazy.at(2 * idx + 2) += lazy.at(idx) / 2;
            }
            lazy.at(idx)= 0;
        }
    }

    void update(int query_left, int query_right, lint val, int cur_idx=0, int cur_left=0, int cur_right=-1) {
        if (cur_right < 0) cur_right = n;

        eval(cur_idx, cur_left, cur_right);

        if (query_right <= cur_left || cur_right <= query_left) return;

        if (query_left <= cur_left && cur_right <= query_right) {
            lazy.at(cur_idx) += (cur_right - cur_left) * val;
            eval(cur_idx, cur_left, cur_right);
        } else {
            update(query_left, query_right, val, 2 * cur_idx + 1, cur_left, (cur_left + cur_right) / 2);
            update(query_left, query_right, val, 2 * cur_idx + 2, (cur_left + cur_right) / 2, cur_right);
            node.at(cur_idx) = node.at(2 * cur_idx + 1) + node.at(2 * cur_idx + 2);
        }
    }

    lint query(int query_left, int query_right, int cur_idx=0, int cur_left=0, int cur_right=-1) {
        if (cur_right < 0) cur_right = n;
        if (query_right <= cur_left || cur_right <= query_left) return 0;

        eval(cur_idx, cur_left, cur_right);

        if (query_left <= cur_left && cur_right <= query_right) return node.at(cur_idx);
        lint val_from_left = query(query_left, query_right, 2 * cur_idx + 1, cur_left, (cur_left + cur_right) / 2);
        lint val_from_right = query(query_left, query_right, 2 * cur_idx + 2, (cur_left + cur_right) / 2, cur_right);
        return val_from_left + val_from_right;
    }
};

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

    int n, q;
    cin >> n >> q;

    LintSumLazySegmentTree segtree(vec<lint>(n, 0));
    for (int i = 0; i < q; i++) {
        int query;
        cin >> query;
        if (query == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            segtree.update(s - 1, t, x);
        }
        else {
            int s, t;
            cin >> s >> t;
            cout << segtree.query(s - 1, t) << "\n";
        }
    }
}


Measured memory_bytes: 7852
number = int(input())
list_input = list(map(int,input().split()))

hantei = 0


for i in range(number-2):
  if (list_input[i]-list_input[i+1])*(list_input[i+2]-list_input[i+1])<0:
    hantei = hantei +1

print(hantei)

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

vector<ll> a(200000);

int main(void){
    ll n, k;
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    ll l = 1, h = *max_element(a.begin(), a.begin() + n);
    while(l < h){
        ll mid = (l + h) / 2, cnt = 0;
        rep(i, n){
            cnt += a[i] / mid;
            if(a[i] % mid == 0) --cnt;
        }
        if(cnt <= k) h = mid;
        else l = mid + 1;
    }
    cout << h << endl;
    return 0;
}

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

int main(){
    int N;
    scanf("%d", &N);
    int ans = 0;
    int id = 1;
    while (N > ans){
        ans += id;
        id ++;
    }
    for (int i = 1; i < id; i++) {
        if (i == (ans - N)) continue;
        else cout << i << 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)
const int INF=1e9+7;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int A,B,C,K,r=0;
	cin >> A >> B >> C >> K;

	r += min(A,K);
	K -= A;

	if(K > 0)
		K -= B;
	
	if(K > 0)
		r -= min(C,K);

	cout << r << endl;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int n, max1, max2;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> ac(a);
  sort(ac.begin(),ac.end());
  max1=ac[n-1];
  max2=ac[n-2];
  for (int i = 0; i < n; i++)
  {
    if (a[i] == max1) cout << max2 << endl;
    else
      cout << max1 << endl;
  }


  return 0;
}


Measured memory_bytes: 3200
s = gets.to_i

def f(n)
  n.even? ? n / 2 : 3 * n + 1
end

a = { s => 1 } 
prev = s
1000000.times do |m|
  prev = f(prev)
  if a.has_key?(prev)
    puts m + 2
    exit
  end
  a[prev] = 1
end


Measured memory_bytes: 1788
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n = read::<usize>();
    let an = read_vec::<usize>();
    let m = an.iter().max().unwrap();
    let ans = if an.iter().sum::<usize>() - m > *m {
        "Yes"
    } else {
        "No"
    };
    println!("{}",ans);

}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
	cin>>a>>b;
	if(a>0) cout<<"Positive";
	else if(a==0||(a<0)&&(b>0)) cout<<"Zero";
	else if((abs(b)-abs(a))%2) cout<<"Positive";
	else cout<<"Negative";
	return cout<<endl&&0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var shopNum = int.Parse(Console.ReadLine());
        var openList = new int[shopNum, 10];
        var costList = new int[shopNum, 10];

        for (int s = 0; s < shopNum; s++)
        {
            var open = Console.ReadLine().Split(' ');
            for (int t = 0; t < 10; t++)
            {
                openList[s, t] = int.Parse(open[t]);
            }
        }

        for (int s = 0; s < shopNum; s++)
        {
            var cost = Console.ReadLine().Split(' ');
            for (int t = 0; t < 10; t++)
            {
                costList[s, t] = int.Parse(cost[t]);
            }
        }
        
        int maxCost = int.MinValue;
        for (int flag = 1; flag < 1024; flag++)
        {
            int cost = 0;
            for (int s = 0; s < shopNum; s++)
            {
                int openTime = 0;
                for (int t = 0; t < 10; t++)
                {
                    var isOwnOpen = (flag & (int)Math.Pow(2, t)) != 0; // 自分の店をその時間開けるか
                    if (isOwnOpen && (openList[s, t] != 0))
                    {
                        openTime++;
                    }
                }
                cost += costList[s, Math.Min(openTime, 9)];
            }
            maxCost = Math.Max(cost, maxCost);
        }
        Console.WriteLine(maxCost.ToString());
        
    }
}

Measured memory_bytes: 13268
n, k = map(int, input().split())
s = list(input())

right = 0
res = 0
zero_area = 1 if s[0] == '0' else 0
for left in range(n):
    if left > 0:
        if s[left-1] == '0' and s[left] == '1':
            zero_area -= 1
    while right < n-1:
        if s[right] == '1' and s[right+1] == '0':
            if zero_area + 1 > k:
                break
            zero_area += 1
        right += 1
    res = max(res, right - left + 1)

print(res)

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

using namespace std;

const int maxn=1e5;

int n;
int dp[maxn][3], l[maxn][3];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> l[i][0] >> l[i][1] >> l[i][2];
	}
	for(int i=0; i<n; i++){
		if(i==0){
			dp[i][0]=l[i][0];
			dp[i][1]=l[i][1];
			dp[i][2]=l[i][2];
		}
		else{
			dp[i][0]=l[i][0]+max(dp[i-1][1], dp[i-1][2]);
			dp[i][1]=l[i][1]+max(dp[i-1][0], dp[i-1][2]);
			dp[i][2]=l[i][2]+max(dp[i-1][0], dp[i-1][1]);
		}
	}
	cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]);
	return 0;
}

Measured memory_bytes: 2560
def func(x1,y1,x2,y2):
    return abs(x1-x2)+abs(y1-y2)
n,m = map(int,input().split())
g = [list(map(int,input().split())) for _ in range(n)]
c = [list(map(int,input().split())) for _ in range(m)]
index = 0
for k in g:
    num = 10**9
    for i,d in enumerate(c):
        tmp = func(k[0],k[1],d[0],d[1])
        if tmp < num:
            num = tmp
            index = i
    print(index+1)

Measured memory_bytes: 3064
/* ex3_2 
　　　　　sachiyan*/

#include <stdio.h>
int main(void){
    int NUM; //Nを定義
    scanf("%d", &NUM); //入力値Nの読み取り
    if(NUM%10 == 3){ //Nを10で割った余りでNの一の位を与える。一の位が３のとき
        printf("bon\n"); //bonを出力
    }
    else if(NUM%10 == 0 || NUM%10 == 1 || NUM%10 == 6 || NUM%10 == 8){ //一の位が0,1,6,8のとき
        printf("pon\n"); //ponを出力
    }
    else{ //一の位が3,0,1,6,8以外のとき、つまり2,4,5,7,9のとき
        printf("hon\n"); //honを出力
    }
    return 0;
}


Measured memory_bytes: 1588
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
	int k, t;
	cin >> k >> t;
	vector<int> cake(t);
	FOR(i, 0, t) {
		cin >> cake[i];
	}
	sort(cake.begin(), cake.end(), greater<int>());
	int sumx = accumulate(cake.begin() + 1, cake.end(), 0);
	int res = max(0, cake[0] - sumx - 1);
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
// C - Pyramid
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()

#define XMAX 100
#define YMAX 100

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

	vector<tuple<int,int,int>> A;
	vector<tuple<int,int,int>> B;
	rp(i,N){
		int x,y,h; cin>>x>>y>>h;
		if(h!=0) A.emplace_back(x,y,h);
		else B.emplace_back(x,y,h);
	}

	vector<tuple<int,int,int>> P;

	rp(y0, YMAX+1){
		rp(x0, XMAX+1){
			bool exist = true;
			int x,y,h;
			tie(x,y,h) = A[0];
			int manhattan = abs(y0 - y) + abs(x0 - x);
			int h0 = h + manhattan;

			for(int i=1; i<A.size(); ++i){
				tie(x,y,h) = A[i];
				int manhattan = abs(y0 - y) + abs(x0 - x);
				int hi = h + manhattan;
				if(h0 != hi){
					exist = false;
					break;
				}
			}

			if(exist){
				P.emplace_back(x0,y0,h0);
			}

		}
	}

	rp(p,P.size()){
		int x0,y0,h0;tie(x0,y0,h0)=P[p];
		// cout<<x0<<" "<<y0<<" "<<h0<<"\n";

		bool exist = true;
		rp(b,B.size()){
			int x,y,h; tie(x,y,h)=B[b];
			int manhattan = abs(y0 - y) + abs(x0 - x);
			int hi = max(0, h0 - manhattan);
			if(hi!=h){
				exist = false;
				break;
			}
		}

		if(exist) cout<<x0<<" "<<y0<<" "<<h0<<"\n";

	}

}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(),B = sc.nextInt(),C = sc.nextInt();
		for(int i = 1; i <= B; i++) {
			if(A*i%B == C) {
				System.out.println("YES");
				return;
			}
		}
		System.out.println("NO");
	}
}

Measured memory_bytes: 23380
class Dice

  def initialize(dice)
    @top  = dice[0]
    @side   = [ dice[4], dice[2], dice[1], dice[3] ]
    @bottom = dice[5]
  end

  def print_upper(action)
    action.chars do |str|
      b = @bottom
      u = @top
      case str
      when "N"
        @top   = @side[2]
        @bottom  = @side[0]
        @side[2] = b
        @side[0] = u
      when "E"
        @top   = @side[3]
        @bottom  = @side[1]
        @side[3] = b
        @side[1] = u
      when "S"
        @top   = @side[0]
        @bottom  = @side[2]
        @side[0] = b
        @side[2] = u
      when "W"
        @top   = @side[1]
        @bottom  = @side[3]
        @side[1] = b
        @side[3] = u
      end
    end
  end

  def top
    @top
  end

  def bottom
    @bottom
  end

  def north
    @side[0]
  end

  def east
    @side[1]
  end

  def south
    @side[2]
  end

  def west
    @side[3]
  end
end

d = Dice.new(gets.split.map(&:to_i))
d.print_upper(gets.chomp)
puts d.top

Measured memory_bytes: 6116
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int cnt = 0;
        for(int i = 0;i < 3;i++){
            char w = s.charAt(i);
            char wa = t.charAt(i);
            if(w == wa)
            cnt++;
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 22228
n,m = map(int, input().split())
a =  ""
b = ""
for i in range(n):
   a += input()

for i in range(m):
   if not i%2 ==0:
      b += input()[::-1]
   else:
      b += input()

if b in a:
   print("Yes")
else:
   print("No")


Measured memory_bytes: 3444
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[]) {
  ll N;
  cin >> N;
  vector<ll> a(N);
  vector<bool> able_divided_by_only_two(N, false);
  ll num_of_two = 0;
  ll num_of_four = 0;
  vector<bool> able_divided_by_four(N, false);
  for (size_t i = 0; i < a.size(); i++) {
    cin >> a[i];
    if (a[i] % 4 == 0) {
      // able_divided_by_four[i] = true;
      num_of_four++;
    } else if (a[i] % 2 == 0) {
      // able_divided_by_only_two[i] = true;
      num_of_two++;
    }
  }
  // cout << "four;" << num_of_four << " two;" << num_of_two << endl;
if(num_of_two==0){
  if(N-num_of_four>num_of_four+1){
    cout<<"No"<<endl;
    return 0;
  }else{
    cout<<"Yes"<<endl;
    return 0;
  }
}


  if (N - num_of_four - num_of_two > num_of_four ) {
    cout << "No" << endl;
    return 0;
  } else {
    cout << "Yes" << endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 1024
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

-- compulte a^n `mod` p
modpow :: Int -> Int -> Int -> Int
modpow a n p =
  let modpow' a n res | n == 0    = res
                      | otherwise =
                          modpow' (a*a`mod`p)
                                  (n `shiftR` 1)
                                  (if (n .&. 1) == 1 then res * a `mod` p else res)
  in modpow' a n 1

main = do
  n <- getInt
  let p :: Int
      p = 10 ^ 9 + 7

      seta = modpow 8 n p
      setbc = modpow 9 n p
      c = ((setbc + setbc) `mod` p - seta) `mod` p

      ans | n == 1 = 0
          | n == 2 = 2
          | otherwise = ((modpow 10 n p) - c) `mod` p

  print ans


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

void print_vec(vector<int> vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) {
    if (i) {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

int main() {
  map<char, int> ans;

  rep(i, 26) {
    char c = i + 'a';
    ans[c] = 0;
  }

  char ch;

  while (cin >> ch) {
    ans[tolower(ch)]++;
  }

  for (auto &&i : ans) {
    auto k = i.first;
    auto v = i.second;

    if ('a' <= k && k <= 'z') {
      printf("%c : %d\n", k, v);
    }
  }
}



Measured memory_bytes: 3160
package main

import (
        "fmt"
)

func solution(n, m, c int, a [][]int, b []int) int {
        count := 0
        for i := 0; i < n; i++ {
                ans := c
                for j := 0; j < m; j++ {
                        ans += a[i][j] * b[j]
                }
                if ans > 0 {
                        count++
                }
        }
        return count
}

func main() {
        var n, m, c int
        fmt.Scan(&n, &m, &c)
        b := make([]int, 0, m)
        for i := 0; i < m; i++ {
                num := 0
                fmt.Scan(&num)
                b = append(b, num)
        }

        a := make([][]int, n)
        for i := 0; i < n; i++ {
                a[i] = make([]int, 0, m)
                for j := 0; j < m; j++ {
                        num := 0
                        fmt.Scan(&num)
                        a[i] = append(a[i], num)
                }
        }
        fmt.Println(solution(n, m, c, a, b))
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
  
int main(void){
  
    int i;
    int al[26];
    char c;
  
    for(i=0;i<26;i++)al[i]=0;
  
    while(scanf("%c",&c)!=EOF){
  
        if(c>='a'&&c<='z')al[c-'a']++;
        else if(c>='A'&&c<='Z')al[c-'A']++;
  
    }
  
    for(i=0;i<26;i++){
        printf("%c : %d\n",'a'+i,al[i]);
    }
  
    return 0;
  
}
 

 

Measured memory_bytes: 540