akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int INF = 1e9 + 7;
int main()
{
	SPEED
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n&1)
	{
		cout << "No";
		return 0;
	}

	string t1 = "";
	string t2 = "";
	for (int i = 0; i < n/2; ++i)
	{
		t1 += s[i];
	}
	for (int i = n/2; i < n; ++i)
	{
		t2 += s[i];
	}


	bool answer = true;
	for (int i = 0; i < n/2; ++i) 
	{ 
        if (t1[i]!=t2[i])
        {
        	answer = false;
        	break;
        }
    } 

    if (answer)
       	cout << "Yes";
    else
    	cout << "No";

	return 0;
}

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

int main(){
    
    // 1. 入力情報.
    int N, M, K;
    scanf("%d %d %d", &N, &M, &K);
    
    // 2. 黒く塗られたマスの個数をちょうど K個に出来るか.
    // 黒く塗られたマスの個数を保存.
    set<int> s;
    // 1列で, 黒が b個 のものが, j列あったとした場合,
    // 1列で, 黒が (N - b)個 の ものが, (M - j)列あるはず.
    for(int b = 0; b <= N; b++){
        for(int j = 0; j <= M; j++){
            s.insert(b * j + (N - b) * (M - j));
        }
    }
    // for(auto &p : s) printf("%d ", p);
    // printf("\n");
    
    // 3. 出力.
    if(s.count(K) == 1) printf("%s\n", "Yes");
    else                printf("%s\n", "No");
    return 0;
    
}

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

using namespace std;

int main(){
	int ary[4][13] = { 0 };
	int n;
	int num;
	char mark;

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> mark >> num;
		if (mark == 'S'){
			ary[0][num-1] = 1;
		}
		if (mark == 'H'){
			ary[1][num-1] = 1;
		}
		if (mark == 'C'){
			ary[2][num-1] = 1;
		}
		if (mark == 'D'){
			ary[3][num-1] = 1;
		}
	}

	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 13; j++){
			if (ary[i][j] == 0){
				if (i == 0){
					cout << 'S' << ' ' << j + 1 << endl;
				}
				if (i == 1){
					cout << 'H' << ' ' << j + 1 << endl;
				}
				if (i == 2){
					cout << 'C' << ' ' << j + 1 << endl;
				}
				if (i == 3){
					cout << 'D' << ' ' << j + 1 << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import sys

sys.setrecursionlimit(4100000)


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


def solve(inputs):
    [N] = string_to_int(inputs[0])
    A = string_to_int(inputs[1])
    B = string_to_int(inputs[2])

    count = 0
    for i in range(0, N):
        j = i+1
        if A[i] <= B[i]:
            B[i] -= A[i]
            count += A[i]
            A[i] = 0
        else:
            A[i] -= B[i]
            count += B[i]
            B[i] = 0

        if A[j] <= B[i]:
            B[i] -= A[j]
            count += A[j]
            A[j] = 0
        else:
            A[j] -= B[i]
            count += B[i]
            B[i] = 0

    return count


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


if __name__ == "__main__":
    ret = solve(inputs(3))
    print(ret)


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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(false);cin.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define error_old(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl
#ifdef DEBUG
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {it++; cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << " [ "<< *it << " : " << a << " ] "; err(++it, args...); }
#else
#define error(args...)
#endif
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

int n;
const int nax = 17;
int a[nax][nax];
vi dp, pre;

void rec(int idx, vi& not_taken, int score_so_far, int mask, int group){
    if(idx == sz(not_taken)){
        
        dp[mask] = max(dp[mask], score_so_far + pre[group]);
        return;
    }

    rec(idx + 1, not_taken, score_so_far, mask, group);
    rec(idx + 1, not_taken, score_so_far, mask | (1 << not_taken[idx]), group | (1 << not_taken[idx]));
}


void solve(){
    cin >> n;
    rep(i, n){
        rep(j, n){
            cin >> a[i][j];
        }
    }

    int maxn = (1 << n);
    dp.resize(maxn);

    pre.resize(maxn);
    repA(mask, 0, maxn - 1){
        rep(i, n){
            if((mask & (1 << i)) != 0){
                repA(j, i + 1, n - 1){
                    if((mask & (1 << j)) != 0){
                        pre[mask] += a[i][j];
                    }
                }
            }
        }
    }

    rep(mask, maxn){
        vi not_taken;
        rep(i, n){
            if((mask & (1 << i)) == 0){
                not_taken.pb(i);
            }
        }
        rec(0, not_taken, dp[mask], mask, 0);
    }

    cout << dp[maxn - 1] << endl;

}

signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    solve();

    return 0;
}


Measured memory_bytes: 1280
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	inputs := scanNums(N)

	// fmt.Println(inputs)

	maxValue := 0
	secondValue := 0
	maxValueCols := []int{}
	secondValueCols := []int{}
	for i, v := range inputs {
		if maxValue == v {
			maxValueCols = append(maxValueCols, i)
		} else if v > maxValue {
			secondValue = maxValue
			secondValueCols = maxValueCols

			maxValue = v
			maxValueCols = []int{i}

		} else if v > secondValue {
			secondValue = v
			secondValueCols = []int{i}
		} else {
			continue
		}
	}
	// fmt.Println(maxValue, maxValueCols)
	// fmt.Println(secondValue, secondValueCols)
	res := createRes(N, maxValue, secondValue, maxValueCols, secondValueCols)

	for _, v := range res {
		fmt.Println(v)
	}

}

func createRes(N, maxValue, secondValue int, maxValueCols, secondValueCols []int) (res []int) {
	for i := 0; i < N; i++ {
		res = append(res, maxValue)
	}
	if len(maxValueCols) == 1 {
		res[maxValueCols[0]] = secondValue
	}
	return
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
#define fast() ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(i, n) for(int i = n-1; i >= 0; i--)
#define loop(i, a, b) for(int i = a; i <= b; i++)
#define rloop(i, a, b) for(int i = a; i >= b; i--)
#define mem(a, val) memset(a, val, sizeof a);
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define test int t; cin>> t; while(t--)
#define ll long long
#define ld long double
#define mp_ make_pair
#define pb push_back
#define sz(s) (int)s.size()
const int N = 1e3 + 3;
const int inf = 1e9+1;
const ll OO = 1e18;
const int mod = 1e9 + 7;
const double pi = 3.141592653;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main()
{
    int x; cin>> x;
    cout<< (x ^ 1);
    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<cassert>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int H, W;
	cin >> H >> W;
	vector<string>S(H);
	rep(i, H)cin >> S[i];
	vector<vector<int>>v1(H, vector<int>(W, 0));
	vector<vector<int>>v2(H, vector<int>(W, 0));
	rep(i, H) {
		int sw = 0;
		int nw = 0;
		int cnt = 0;
		while (1) {
			if (S[i][nw] == '#') {
				for (int j = 0; j < nw - sw; j++) {
					v1[i][sw + j] = cnt;
				}
				nw++;
				sw = nw;
				cnt = 0;
			}
			else {
				cnt++;
				nw++;
			}
			if (nw == W) {
				for (int j = 0; j < nw - sw; j++) {
					v1[i][sw + j] = cnt;
				}
				break;
			}
		}
	}
	rep(i, W) {
		int sh = 0;
		int nh = 0;
		int cnt = 0;
		while (1) {
			if (S[nh][i] == '#') {
				for (int j = 0; j < nh - sh; j++) {
					v2[sh + j][i] = cnt;
				}
				nh++;
				sh = nh;
				cnt = 0;
			}
			else {
				cnt++;
				nh++;
			}
			if (nh == H) {
				for (int j = 0; j < nh - sh; j++) {
					v2[sh + j][i] = cnt;
				}
				break;
			}
		}
	}
	int ans = 0;
	rep(i, H)rep(j, W) {
		ans = max(ans, v1[i][j] + v2[i][j] - 1);
	}
	cout << ans << endl;
}

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

int min(int a ,int b)
{
	if(a<b)
		return a;
	return b;
}

int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<min(a,b)+min(c,d)<<'\n';
	return 0;
}



Measured memory_bytes: 256
S = input()
ans = [0] * len(S)


# R と Lを別々に考える
cnt = 0
for i in range(len(S) - 1):
    if S[i] == "R":
        cnt += 1
        if S[i + 1] == "L":
            ans[i] += (cnt + 1) // 2
            ans[i + 1] += cnt // 2
    else:
        cnt = 0

cnt = 0
for i in range(len(S) - 1, 0, -1):
    if S[i] == "L":
        cnt += 1
        if S[i - 1] == "R":
            ans[i] += (cnt + 1) // 2
            ans[i - 1] += cnt // 2
    else:
        cnt = 0

print(*ans)


Measured memory_bytes: 6400
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, M;
    cin >> N >> M;
    const int _inf = 1000 * 1000;
    VEC(VEC(int)) dist(N, VEC(int)(N, _inf));
    VEC(VEC(int)) edges;
    FOR(i, 0, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        dist[a][b] = dist[b][a] = min(dist[a][b], c);
        edges.push_back({a, b, c});
    }

    FOR(i, 0, N)
        dist[i][i] = 0;
    FOR(i, 0, N)
        FOR(j, 0, N)
            FOR(k, 0, N)
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);

    int ret = 0;
    FOR(i, 0, M) {
        int u = edges[i][0], v = edges[i][1], c = edges[i][2];
        int good = 0;
        FOR(a, 0, N)
            FOR(b, 0, a)
                if (dist[a][b] == dist[a][u] + c + dist[v][b] ||
                        dist[a][b] == dist[a][v] + c + dist[u][b])
                    good = 1;

        if (!good)
            ret++;
    }

    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
using namespace std;
const int mod=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int a,b;
    cin >> a >> b;
    int ans;
    if(a==1){
        if(b==2)ans=3;
        else ans=2;
    }
    if(a==2){
        if(b==1)ans=3;
        else ans=1;
    }
    if(a==3){
        if(b==2)ans=1;
        else ans=2;
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        cout<<s.substr(0,3)<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,h[100],ans;
  
  cin >> n;
  for (i=0;i<n;i++) cin >> h[i];
  
  ans=h[0];
  for (i=1;i<n;i++){
    if (h[i]>h[i-1]) ans+=h[i]-h[i-1];
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
N, X = map(int, input().split())
a, p = [1], [1]
for i in range(N):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化
  if N == 0:
      return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
      return f(N-1, X-1)
  else:
      return p[N-1] + 1 + f(N-1, X-2-a[N-1])
print(f(N, X))


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int N = Int32.Parse(ReadLine()); //N
        double Result = 0;

        for (int Count = 0; Count < N; Count++) {
            var list = new List<string>(ReadLine().Split(' ')).ToList();
            if (list[1] == "JPY") {
                Result += double.Parse(list[0]);
            } else {
                Result += double.Parse(list[0]) * 380000;
            }
        }

        WriteLine(Result);

        Console.ReadLine();
    }
}


Measured memory_bytes: 13268
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    vector<int> p(n);
    REP(i,n){
        cin>>p.at(i);
    }

    int tcnt = 0;
    REP(i,n){
        if(p.at(i) != i+1) tcnt++;
    }
    if(tcnt == 0 || tcnt == 2){
        cout<<"YES"<<endl;
    } else{
        cout<<"NO"<<endl;
    }


    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	int a[200000]={};
	for(int i=0; i<n; i++){
		int tmp;
		cin >> tmp;
		a[tmp-1]++;
	}
	sort(a, a+n, greater<int>());
	int sum=0;
	for(int i=0; i<k; i++)
		sum+=a[i];
	cout << n-sum << '\n';
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)
int main()
{
    string s;
    cin>>s;
    map<char,lli>frec;
    bool ans=true;
    for(lli i=0;i<s.size();i++)
    {
        frec[s[i]]++;
    }
    for(char a='a';a<='z';a++)
    {
        if(frec[a]%2!=0)
        {
            ans=false;
        }
    }
    if(ans)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)(1e15)

signed main(){
	int N, M, P, i, j, k;
	scanf("%lld%lld%lld", &N, &M, &P);
	vector<vector<int>> g(N, vector<int>(0)), Cs(N, vector<int>(0));
	for(i = 0; i < M; i++){
		int A, B, C;
		scanf("%lld%lld%lld", &A, &B, &C);
		A--;
		B--;
		g[A].push_back(B);
		Cs[A].push_back(C - P);
	}
	vector<int> val(N, -inf), sub(N);
	val[0] = 0;
	for(k = 0; k < N; k++){
		for(i = 0; i < N; i++){
			sub[i] = val[i];
		}
		for(i = 0; i < N; i++){
			for(j = 0; j < g[i].size(); j++){
				val[g[i][j]] = max(val[g[i][j]], val[i] + Cs[i][j]);
			}
		}
	}
	vector<int> old = val;
/*	for(i = 0; i < N; i++){
		printf("old[%lld] = %lld\n", i, old[i]);
	}
	printf("\n");
*/	for(k = 0; k < N; k++){
		for(i = 0; i < N; i++){
			sub[i] = val[i];
		}
		for(i = 0; i < N; i++){
			for(j = 0; j < g[i].size(); j++){
				val[g[i][j]] = max(val[g[i][j]], val[i] + Cs[i][j]);
			}
		}
	}
	vector<int> is_increase(N, 0);
	for(i = 0; i < N; i++){
		if(old[i] < val[i] && val[i] > -inf / 2){
			is_increase[i] = 1;
		}
	}
/*	for(i = 0; i < N; i++){
		printf("is_increase[%lld] = %lld\n", i, is_increase[i]);
	}
	printf("\n");
*/	for(k = 0; k < N; k++){
		for(i = 0; i < N; i++){
			for(j = 0; j < g[i].size(); j++){
				is_increase[g[i][j]] |= is_increase[i];
			}
		}
	}
	if(is_increase[N - 1] == 1){
		printf("-1\n");
	}
	else{
		printf("%lld\n", max(0ll, val[N - 1]));
	}
	return 0;
}

Measured memory_bytes: 640
// Problem Title : Max-Min Sums
// Link : https://atcoder.jp/contests/abc151/tasks/abc151_e
// Date : 03-09-2020 10:04:14

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if(k == 1) {
		cout << 0 << '\n';
		return 0;
	}
	sort(a.begin(), a.end());
	if(k == 2) {
		ll ans = 0;
		ll pre = 0;
		for(int i = 0; i < n; i++) {
			ll sum = (i * a[i]) % MOD;
			sum = (sum - pre) % MOD;
			ans = (ans + sum) % MOD;
			pre = (pre + a[i]) % MOD;
		}
		if(ans < 0) {
			ans += MOD;
		}
		cout << ans << '\n';
		return 0;
	}

	vector<ll>factorials(n);
	factorials[0] = 1;
	for(int i = 1; i < n; i++) {
		factorials[i] = (factorials[i-1] * i) % MOD;
	}

	function<ll(int, int)> rep_pow = [&](int n, int p) {
		if (p == 0) {
			return 1LL;
		}
		if (p % 2 == 0) {
			int t = rep_pow(n, p / 2);
			return (ll)t * (ll)t % MOD;
		} else {
			return n * rep_pow(n, p - 1) % MOD;
		}
	};
	
	function<ll(int , int)> choose = [&](int n, int k) {
		if (n < k || n < 0 || k < 0) {
			return 0LL;
		}
		return factorials[n] * rep_pow(factorials[k], MOD - 2) % MOD * rep_pow(factorials[n - k], MOD - 2) % MOD;
	};

	ll ans = 0, back = 0, front = 0;
	for(int gap = n - 2, sz = 1; gap >= k - 2; gap--, sz++) {
		back = (back + a[n - sz]) % MOD;
		front = (front + a[sz - 1]) % MOD;
		ll sums = (back - front) % MOD;
		ll tot = (sums * choose(gap, k - 2)) % MOD;
		ans = (ans + tot) % MOD;
	}

	if(ans < 0) {
		ans += MOD;
	}

	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 1408
/* 
   AOJ 1154
   Monday-Saturday Prime Factors
   2015/8/23
*/

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

#define MAX_IN 300000

struct node
{
  int val;
  struct node *link;
};

struct node *head;

void init()
{
  head = NULL;
}

int empty()
{
  return head == NULL;
}

void insert_node(int in_val)
{
  struct node *new_node = malloc(sizeof(struct node*)), *next = head, *prev = head;

  new_node->val = in_val;

  if(head == NULL)
    {
      head = new_node;
      new_node->link = NULL;
    }
  else
    {
      while(next != NULL)
	{
	  if(next->val == in_val)
	    {
	      free(new_node);
	      return;
	    }
	  if(next->val > in_val)
	    {
	      if(next == head)
		{
		  new_node->link = head;
		  head = new_node;
		  return ;
		}
	      break;
	    }
	  prev = next;
	  next = next->link;
	}
      prev->link = new_node;
      new_node->link = next;
    }
}

int get()
{
  struct node *get_node = head;
  int get_val = head->val;

  head = head->link;

  free(get_node);

  return get_val;
}

void debug(int input_num)
{
  int i, x;
  time_t timer;
  time(&timer);
  
  srand(timer);
  for(i = 0; i < input_num; i++)
    {
      x = rand() % 100;
      printf("%3d", x);
      insert_node(x);
    }
  printf("\n");
}

void ms_eratos(int *ms_primes)
{
  int i, j;
  ms_primes[0] = 0;
  ms_primes[1] = 0;

  for(i = 2; i <= MAX_IN; i++)
    {
      if(i % 7 == 1 || i % 7 == 6)
	{
	  ms_primes[i] = 1;	  
	}
      else
	{
	  ms_primes[i] = 0;
	}
    }


  for(i = 0; i <= MAX_IN; i++)
    {
      if(ms_primes[i])
	{
	  for(j = i; i * j <= MAX_IN && i * j >= 0; j++)
	    {
	      ms_primes[i * j] = 0;
	    }
	}
    }
}

void ms_factorization(int in_num, int* ms_primes)
{
  int i;
  if(in_num == 1)
    {
      return ;
    }
  for(i = 0; i <= in_num; i++)
    {
      if(ms_primes[i] == 1 && in_num % i == 0)
	{
	  insert_node(i);
	  ms_factorization(in_num / i, ms_primes);
	}
    }
}

int main(void)
{
  int input_num, ms_primes[MAX_IN + 1], i;
  
  ms_eratos(ms_primes);

  /* for(i = 0; i <= MAX_IN; i++) */
  /*   { */
  /*     if(ms_primes[i]) */
  /* 	{ */
  /* 	  printf("%7d", i); */
  /* 	} */
  /*   } */
  /* printf("\n"); */

  while(1)
    {
      init();
      scanf("%d", &input_num);
      if(input_num == 1)
  	{
  	  break;
  	}
      /* debug(input_num); */
      ms_factorization(input_num, ms_primes);
      printf("%d:", input_num);
      while(!empty())
  	{
  	  printf(" %d", get());
  	}
      printf("\n");
    }
  return 0;
}

Measured memory_bytes: 1772
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt()
    val A = Array.fill[Long](N)(sc.nextLong)
    val result = if (A.count(_.<(0)) % 2 == 0) {
      A.map(Math.abs).sum
    } else {
      val absA = A.map(Math.abs)
      absA.sum - 2 * absA.min
    }

    println(result)
  }
}

Measured memory_bytes: 52248
/*  */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000")

#define sti				set<int>
#define stpii			set<pair<int, int> >
#define mpii			map<int,int>
#define vi				vector<int>
#define pii				pair<int,int>
#define vpii			vector<pair<int,int> >
#define rep(i, a, n) 	for (int i=a;i<n;++i)
#define per(i, a, n) 	for (int i=n-1;i>=a;--i)
#define clr				clear
#define pb 				push_back
#define mp 				make_pair
#define fir				first
#define sec				second
#define all(x) 			(x).begin(),(x).end()
#define SZ(x) 			((int)(x).size())
#define lson			l, mid, rt<<1
#define rson			mid+1, r, rt<<1|1
#define getBits(x)		__builtin_popcount(x)
#define getBitIdx(x)	__builtin_ffs(x)

typedef long long LL;
const int maxn = 1e5+5;
pii p[maxn];
int n;
LL K;

void solve() {
	LL tot = 0;
	
	sort(p, p+n);
	rep(i, 0, n) {
		tot += p[i].sec;
		if (K <= tot) {
			printf("%d\n", p[i].fir);
			return ;
		}
	}
}

int main() {
	cin.tie(0); 
	ios::sync_with_stdio(false);
	// #ifndef ONLINE_JUDGE
		// freopen("data.in", "r", stdin);
		// freopen("data.out", "w", stdout);
	// #endif
	
	scanf("%d %lld", &n, &K);
	rep(i, 0, n)
		scanf("%d %d", &p[i].fir, &p[i].sec);
	solve();
	
	// #ifndef ONLINE_JUDGE
		// printf("time = %ldms.\n", clock());
	// #endif
	
	return 0;
}


Measured memory_bytes: 1024
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll a, b, c, k;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
  printf("%lld\n", a + b + c + MAX(MAX(a, b), c) * ((2 << (k - 1)) - 1));
  return 0;
}

Measured memory_bytes: 128
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()
a = na()
g = []
for i in range(n):
    g.append([])
for i in range(n-1):
    x, y = na()
    g[x-1].append(y-1)
    g[y-1].append(x-1)

sys.setrecursionlimit(230000)
import bisect
def dfs(cur, pre, g, lis, la, anss, a):
    ind = bisect.bisect_left(la, a[cur], 0, lis+1)
    old = la[ind]
    la[ind] = a[cur]
    nlis = lis + 1 if ind == lis + 1 else lis
    anss[cur] = nlis

    for e in g[cur]:
        if e == pre: continue
        dfs(e, cur, g, nlis, la, anss, a)

    la[ind] = old

anss = [0] * n
la = [999999999999] * (n+2)
la[0] = 0
dfs(0, -1, g, 0, la, anss, a)
for v in anss:
    print(v)

Measured memory_bytes: 389776
n = int(input())

S = [input() for _ in range(n)]

l = [50]*26
for i in range(n):
    tmp_l = [0]*26
    for j in range(len(S[i])):
        tmp_l[ord(S[i][j]) - 97] += 1

    for k in range(26):
        l[k] = min(l[k], tmp_l[k])

ans = []
for i in range(26):
    ans += chr(97 + i) * l[i]
print(''.join(ans))


Measured memory_bytes: 9168
import java.util.Scanner;
class Main {
	double[][] dp;
	int[] v;
	int[][] event;
	int x,y,z;
	
	public static void main(String args[]){
		Main app = new Main();
		Scanner scan = new Scanner(System.in);
		while(true){
			app.x = scan.nextInt();
			app.y = scan.nextInt();
			app.z = scan.nextInt();
			if(app.x==0 && app.y==0 && app.z==0){
				break;
			}
			app.v = new int[app.x];
			for(int i=0;i<app.x;i++){
				app.v[i] = scan.nextInt();
			}	
			app.event = new int[app.y+1][2];
			for(int i=0;i<app.z;i++){
				int tmp = scan.nextInt();
				app.event[tmp][0] = scan.nextInt();
				app.event[tmp][1] = scan.nextInt();
			}
			app.dp = new double[app.y+1][5001];
			System.out.println(app.LifeGame());
		}
	}
	
	public int LifeGame(){
		dp[0][0] = 1;
		
		for(int i=0;i<y+1;i++){
			for(int j=0;j<5001;j++){
				if(dp[i][j]>0){
					for(int k=0;k<x;k++){
						if(i!=y){
							int num = i+v[k];
							if(num>y){
								num = y;
							}
							int money = j;
							switch(event[num][0]){
							case 1:
								num+=event[num][1];
								if(num>y){
									num = y;
								}
								break;
							case 2:
								money = j+event[num][1];
								break;
							case 3:
								money = j-event[num][1];
								if(money<0){
									money = 0;
								}
								break;
							}
							dp[num][money] += dp[i][j]/x;
						}
					}
				}
			}
		}
		double exp=0;
		for(int i=0;i<5001;i++){
			exp += dp[y][i]*i;
		}
		
		return (int)exp;
	}
}

Measured memory_bytes: 62096
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    auto a = divisor(n);
    int ans = INF;
    for (int i = 0; i < a.size(); i++)
    {
        string s = to_string(a[i]);
        string t = to_string(n / a[i]);
        chmin(ans, (int)max(s.size(), t.size()));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;

namespace atcoder_practice1
{
    class _081A
    {
        static void Main()
        {
            string str;
            int count = 0;
            str = Console.ReadLine();

            for(int i=0; i < str.Length; i++)
            {
                if(str[i] == '1')
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():

    n, k = input().split()
    d = list(map(int,input().split()))
    use = []
    for i in range(0,10):
        if i in d:
            continue
        else:
            use.append(i)

    flag = False
    for i in range(int(n),10*int(n)+1):
        number = str(i)
        for j in range(len(number)):
            if j != len(number)-1:
                if number[j] not in str(use):
                    break
            else:
                if number[j] in str(use):
                    flag = True
                else:
                    break

        if flag:
            print(i)
            break


if __name__ == '__main__':
    main()

Measured memory_bytes: 14176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, M, K;
    cin >> N >> M >> K;

    UnionFind uf(N+1);
    vll cntf(N+1, 0), cntb(N+1, 0);
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        uf.merge(a, b);
        cntf[a]++, cntf[b]++;
    }
    rep(i, K) {
        ll c, d;
        cin >> c >> d;
        if(uf.issame(c, d)) cntb[c]++, cntb[d]++;
    }

    rep(i, N) {
        cout << uf.size(i+1) - 1 - cntf[i+1] - cntb[i+1] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 2816
function Main(input) {
  input = input.trim()
  input = input.split("\n");
  var S = input[1].split("");
  var ans = 0;
  for(var i=0;i<S.length-1;i++){
    if(S[i]=="A"&&S[i+1]=="B"&&S[i+2]=="C"){
      ans++
      i+=2;
    }
  }
  console.log(ans)
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import math
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    ans=0
    for i in range(1,n+1):
        if i%3==0 or i%5==0:
            pass
        else:
            ans+=i
    print(ans)
if __name__ == '__main__':
    do()

Measured memory_bytes: 9172
# for #!/usr/bin/env python
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")

# endregion
class union_find:
    def __init__(self, n):
        self.n = n
        self.rank = [0]*n
        self.parent = [int(j) for j in range(n)]
    
    def union(self,i,j):
        i = self.find(i)
        j = self.find(j)
        if self.rank[i] == self.rank[j]:
            self.parent[i] = j
            self.rank[j] += 1

        elif self.rank[i] > self.rank[j]:
            self.parent[j] = i
        else:
            self.parent[i] = j

    def find(self, i):
        temp = i
        if self.parent[temp] != temp:
            self.parent[temp] = self.find(self.parent[temp])
        return self.parent[temp]
from math import log2, ceil
from collections import deque, Counter as CC, defaultdict as dd
MOD = int(1e9+7)
def main():
# Enter your code here. Read input from STDIN. Print output to STDOUT
    # for t in range(int(input())):
        
        n = int(input())
        l = [int(j) for j in input().split()]
        ans =0 
        l.sort()
        for i in range(n):
            for j in range(i+1, n):
                for k in range(j+1, n):
                    s = [l[i], l[j], l[k]]
                    s.sort()
                    if((s.count(l[i])>1) or (s.count(l[j])>1) or (s.count(l[k])>1)):
                        continue
                    if(s[0]+s[1]>s[2]):
                        ans+=1
        print(ans)













        



if __name__ == "__main__":
    main()

Measured memory_bytes: 68736
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MaxN = 2e5 + 5;
 
int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	LL sum = 0;
	for(int i = k + 1; i <= n; i++) {
		sum += (n/i) * (i - k);
		if(n % i >= k) sum += n % i - k + 1;
	}
	if(k == 0) sum -= n;
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N = int(input())
A = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

dp = [0] * 62
for a in A :
    for i in range(62) :
        if a & (1 << i) :
            dp[i] += 1

ret = 0
for i in range(62) :
    ret += (N * (N - 1) - (N - dp[i]) * (N - dp[i] - 1)) // 2 * (1 << i) % mod
    ret -= dp[i] * (dp[i] - 1) // 2 * (1 << i) % mod
    ret %= mod

print(ret)

Measured memory_bytes: 123132
#include<bits/stdc++.h>
using namespace std;
#define int long long 
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=200005;
const int MOD=2019;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int A[MAXN], N, pref[MAXN], teninv[MAXN], freq[MAXN];

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string S;cin>>S;
	N=S.length();
	FOR(i,1,N) A[i]=(int) S[i-1]-'0';
	teninv[1]=202;
	FOR(i,2,MAXN-1) teninv[i]=(teninv[i-1]*202)%MOD;
	pref[0]=0;
	freq[0]=1;
	FOR(i,1,N){
		pref[i]=(10*pref[i-1]+A[i])%MOD;
		int modclass = (pref[i] * teninv[i])%MOD;
		freq[modclass]++;
		//db(i), db(modclass);
	}
	int ans = 0;
	FOR(i,0,MOD-1){
		ans += freq[i]*(freq[i]-1)/2;
	}
	cout<<ans;
}


Measured memory_bytes: 8412
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;



int main(void) {
    string s;
    cin >> s;
    ll i, j;
    string x, y, z;
    for(i=0; i<s.size(); i++) {
        for(j=i; j<s.size(); j++) {
            x=s.substr(0, i);
            y=s.substr(j, s.size()-j);
            z=x+y;
            if(z=="keyence") {
                puts("YES");
                return 0;
            }
            
        }
    }
    
    puts("NO");
    
    
    
}













Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

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

		if(N == 0){
			System.out.println(0);

		}
		else{
			Deque<Integer> stack = new ArrayDeque<Integer>();

			double tmp = 0;
			for(int i = 1 ; i <= 35 ; i++){
				double bek = Math.pow(-2, i);

				//System.out.println("i : " + i);
				if(N%bek==0){
					//System.out.print(0);
					stack.push(0);
				}
				else{
					if(tmp == 0){
					tmp = N-(bek/(-2));
					}
					else{
						tmp = tmp-(bek/(-2));
					}
					//System.out.println("tmp :" + tmp);
					if(tmp%bek == 0){
						//System.out.print(1);
						stack.push(1);
					}
					else{
						//System.out.print(0);
						stack.push(0);
						tmp = tmp+(bek/(-2));
					}
				}
			}
			int flag = 0;
			int ff = stack.size();
			//System.out.println(ff);
			for(int i = 0 ; i < ff ; i++){
				int a = stack.poll();
				if(flag == 0 && a == 0){
					continue;
				}else{
					System.out.print(a);
					flag++;
				}
			}
		}
	}
}

Measured memory_bytes: 21844
import java.util.*;
public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
          arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int dist = 0;
        int min = Integer.MAX_VALUE;
        for(int p = arr[0]; p <= arr[n-1]; p++) {
            dist = 0;
            for(int i = 0; i < n; i++) {
              dist += Math.pow(arr[i]-p, 2);
            }
            min = Math.min(min, dist);
        }
        System.out.println(min);
    }
}

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

int f(int n) {
  int cnt = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      cnt++;
      if (i * i != n) cnt++;
    }
  }
  return cnt;
}

void solve() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i += 2)
    if (f(i) == 8) ans++;
  cout << ans << endl;
}

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

Measured memory_bytes: 3648
#include <bits/stdc++.h>
 
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define fff(i,a,b) for(int (i)=(a);(i)<=(b);i++)
#define pb push_back
#define len(a) (a).length()
#define all(a) (a).begin(),(a).end()
#define sz(a) (a).size()
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long ,long long > pll;
typedef unsigned long long ull;
typedef long double ld;
 
const int mn=1e6+69;
vector<set<int> > kg(mn);
vector<int> inf(mn);
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int h,w,k;
	cin>>h>>w>>k;
	string  pom;
	int a[h][w];
	for(int i=0;i<h;i++)
	{
		cin>>pom;
		for(int j=0;j<w;j++)
		{
			if(pom[j]=='.') a[i][j]=0;
			else a[i][j]=1;
		}
	}
	int num=0;
	for(int i=0;i<(1<<h);i++)
	{
		set<int> hh;
		int pom=i;
		int koji=0;
		while(pom>0)
		{
			if(pom%2==1) hh.insert(koji);
			pom/=2;
			koji++;
		}
		for(int j=0;j<(1<<w);j++)
		{
			set<int> ww;
			int pomcina=j;
			int sta=0;
			while(pomcina>0)
			{
				if(pomcina%2==1) ww.insert(sta);
				pomcina/=2;
				sta++;
			}
			int kolko=0;
			for(int ii=0;ii<h;ii++)
			{
				for(int jj=0;jj<w;jj++)
				{
					if(!hh.count(ii) && !ww.count(jj) && a[ii][jj]==1) kolko++;
				}
			}
			if(kolko==k)
			{
				num++;
			}
		}
	}
	cout<<num<<endl;
}

Measured memory_bytes: 54136
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> 
#include <cstdlib>
#include <cmath>
#include<map>
#include<string.h>
#include <algorithm>
#include <bits/stdc++.h> 
#include<vector>
using namespace std;
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
//#define viadj[n+1] vector<int>adj[n+1] 
#define sortA(arr)   sort(arr.begin(),arr.end())
#define sortC(arr,n)   sort(arr,arr+n,comparefunc())
#define search(arr,c)  binary_search(arr.begin(),arr,end(),c)
#define pb   push_back
#define ll long long
 
/*struct node{
     int b;long sum;
     string name;
}
 
 
bool comparefunction(node c,node d){
   if(c.b!=d.b)
   return c.b>d.b;
     
}*/
 
 // 
 
  /* void dfs(int v) {
    visited[v] = true;
 
    
    for (int u : adj[v]) {
       if (!visited[u])
            dfs(u);
    }
   
    
}*/
 
 int  gcd(int a,int b)
 {
       // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a%b, b); 
    return gcd(a, b%a); 
 }
   
 
     
 
 
 
 
int main()
{
    
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
   
    int check1=0,check2=0,check3=0;
    int counti=0;
    //int count=0;
    long double pi=3.141592653589793;
    ll sum=0,count=0,n,m,t,k,a,b,c,d;
  //  cin>>t;
  cin>>n>>k;
  int arr[n+1]={0};
    while(counti!=k)
    {
        string str;
        cin>>m;
     rep(i,1,m+1)
    {
        cin>>a;
        arr[a]=1;
        
    }
         counti++;
    } 
    rep(i,1,n+1)
    {
        if(!arr[i])
        count++;
        
    }
    cout<<count;
      
    }
 

 
 
 

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

int main() {

	ll n, m; cin >> n >> m;
	priority_queue<ll> p;
	for (ll i = 0; i < n; i++) {
		ll a; cin >> a;
		p.push(a);
	}
	for (ll i = 0; i < m; i++) {
		ll tmp = p.top();
		tmp /= 2LL;
		p.pop();
		p.push(tmp);
	}
	ll ans = 0;
	while (!p.empty()) {
		ans += p.top();
		p.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4308