akhauriyash/Code-Regression huggingface dataset:
package main
import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	//"math"
)

var sc = bufio.NewScanner(os.Stdin)

func main(){
	for sc.Scan(){
		n := nextInt()
		fmt.Println(calc(n))
	}
}

func calc(n int)int{
	// エラトステネスで数え上げる
	// 最初から999999まで用意しておいて入力のたびO(1)で出すのとどっちが速いのかはわからん
	eratos := make([]bool, n+1)
	c := 0
	for i:=2; i<len(eratos); i++{
		if eratos[i] == false{
			c++
			for j:=i*i; j<len(eratos); j+=i{
				eratos[j]=true
			}
		}
	}
	return c
}

func next()string{
	return sc.Text()
}

func nextInt()int{
	a, _ := strconv.Atoi(next())
	return a
}


Measured memory_bytes: 7076
#include <bits/stdc++.h>
// B - Frog 2

using namespace std;

int h[100005];
int dp[100005];

int main() {
    int N,K,i,j;

    scanf("%d%d",&N,&K);

    memset(dp,0x3f,sizeof(dp));
    dp[0] = 0;
    for (i = 0;i < N;i++) {
        scanf("%d",&h[i]);
        for (j = 1;j <= min(i,K);j++)
            dp[i] = min(dp[i],dp[i - j] + abs(h[i] - h[i - j]));
    }

    printf("%d\n",dp[N - 1]);

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
vector<int> a[200000];
int c;
bool v[200000];
void dfs(int cur){
	v[cur] = true, c++;
	for (int e : a[cur]){
		if (!v[e]) dfs(e);
	}
}
int main(){
	int n, m, x, y, ans = 0;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		scanf("%d %d", &x, &y), x--, y--;
		a[x].emplace_back(y);
		a[y].emplace_back(x);
	}
	for (int i = 0; i < n; i++){
		c = 0;
		if (!v[i]) dfs(i);
		ans = max(ans, c);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 21012
#include<stdio.h>
int main(void){
int i,j,n,a[100],b[100];
scanf("%d",&n);
for(i=0;i < n;i++){
scanf("%d",&a[i]);
}
for(j=0;j < n;j++){
b[j]=a[((n-1)-j)];
printf("%d",b[j]);
if (j != (n-1)){
printf(" ");
}
}
printf("\n");
return 0;
}

Measured memory_bytes: 600
// #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()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int X, Y;
    cin >> X >> Y;
    int a = Y - 2 * X, b = 4 * X - Y;
    if(a >= 0 && a % 2 == 0 && b >= 0 && b % 2 == 0 ) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main()
{
    int n, k;
    string s;
    cin >> n >> k >> s;
    for (int i = 1; i < n && k > 0; )
    {
        while (i < n && s[i] == s[0])
            i++;
        if (i < n)
        {
            int j = i;
            while (j < n && s[j] != s[0])
            {
                s[j] = s[0];
                j++;
            }
            i = j;
            k--;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'L')
        {
            if (i + 1 < n && s[i + 1] == 'L')
                ans++;
        }
        else
        {
            if (i - 1 >= 0 && s[i - 1] == 'R')
                ans++;
        }
    }
    //cout << s << endl;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
from collections import Counter
n = int(input())
def prime_factorize(n):
    # Return list of prime factorized result
    # O(sqrt(n))
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
l = prime_factorize(n)
cnt = Counter(l)

ans = 0
for key in cnt.keys():
    cur = 1
    while True:
        if cnt[key] >= cur:
            cnt[key] -= cur
            ans += 1
            cur += 1
        else:
            break
print(ans)


Measured memory_bytes: 65812
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1010, M = 64;
 
ll a[N];int n;char s[N];
 
ll b[N];
 
ll insert(ll x){
	for(int i=60;~i;i--)if(1&(x>>i)){
		if(!b[i]){b[i]=x;break;}
		else x^=b[i];
	}
	return x;
}
 
void Main()
{
	for(int i=0;i<M;i++)b[i]=0;
	cin >> n;for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	scanf("%s",s+1);
	bool Ans=0;
	for(int i=n;i;i--){
		if(s[i]=='0'){
			insert(a[i]);
		}else{
			ll d=insert(a[i]);
			// cerr << d << "??" << endl;
			Ans|=d!=0;
		}
	}
	printf("%d\n",(int)Ans);
}
 
int main()
{
	int T;cin >>  T;while(T--)Main();
}


Measured memory_bytes: 3792
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>

#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{


    int a, b, k;
    
    cin >> k >> a >> b;
    
    for(int i = a; i <= b; i++)
    {
        if(i % k == 0)
        {
            cout << "OK";
            break;
        }
        if(i == b)
        {
            cout << "NG";
        }
        
    }
    
}

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

int main(void){
	char S[4];
	int counter=0;
	scanf("%3s",S);
	for(int i=0;i<strlen(S);i++){
		if(strncmp(&S[i],"o",sizeof(S[0]))==0) counter++;
		}
	int total=700+100*counter;
	printf("%d\n",total);
}

Measured memory_bytes: 1728
N, Q = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

ans = [0]*N
for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

from collections import deque

visited = [False]*N
d = deque([0])
while len(d)>0:
    v = d.popleft()
    visited[v]= True
    for u in edge[v]:
        if visited[u]==False:
            ans[u] += ans[v]
            visited[u]=True
            d.append(u)

print(*ans, sep=' ')

Measured memory_bytes: 56168
n=int(input())
a=list(map(int,input().split()))[::-1]
if a[0]!=2:
  print(-1)
  exit()
mn,mx=2,2
for j in a:
  if (mn+j-1)//j>mx//j:
    print(-1)
    exit()
  mn=(mn+j-1)//j*j
  mx=mx//j*j+j-1
print(mn,mx)

Measured memory_bytes: 85576
#include <iostream>

using namespace std;

int main();
int point(int n);

int point(int n){
	int sum = 0, diff, i;
	int ans[100000];
	for(i = 1; sum <= n; i++){
		sum += i;
//		cout << i << endl;
		ans[i] = i;
	}
	i = i - 1;
	ans[i + 1] = 0;
	sum = sum - ans[i];
	ans[i] = 0;
	diff = n - sum;
//	cout << diff << endl;
	if(diff != 0){
		for(int j = 1; j <= diff; j++){
			ans[i - j] += 1;
		}
		sum = 0;
		for(i = 1; ans[i] != 0; i++){
			sum += ans[i];
			cout << ans[i] << endl;
		}
	}else{
		for(i = 1; ans[i] != 0; i++){
			cout << ans[i] << endl;
		}
	}
	return sum;
}

int main(){
	int n, ans;
	cin >> n;
	ans = point(n);
//	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<algorithm>

using namespace std;

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

int main() {
	char s[5];
	for (int i = 0; i < 4; i++) { cin >> s[i]; }
	s[4] = '\0';
	int S = atoi(s);
	int first = S / 100;
	int second = S % 100;
	if (first >= 1 && first <= 12) {
		if (second >= 1 && second <= 12) {
			cout << "AMBIGUOUS" << endl;
		}
		else if (second >= 0 && second <= 99) {
			cout << "MMYY" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	else if (first >= 0 && first <= 99) {
		if (second >= 1 && second <= 12) {
			cout << "YYMM" << endl;
		}
		else if (second >= 0 && second <= 99) {
			cout << "NA" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	else {
		cout << "NA" << endl;
	}
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
int a[N],b[N],c[N],n,res,lst,tmp;
int main(){
	scanf("%d",&n);
	for(R int i=1,x;i<=n;++i){
		scanf("%d",&x),a[i]=x,b[i]=-1;
		while(a[i])++b[i],a[i]>>=1;
		c[i]=((x&-x)!=x),res+=b[i]+c[i];
	}
	fp(i,1,n){
		tmp=min(lst,b[i]),res-=tmp,lst-=tmp;
		if(lst&&c[i])--res,--c[i];
		lst=b[i]+c[i];
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1408
def main():
    h, w = map(int, input().split())
    grid = [input() for _ in [0]*h]
    ans_list = []
    for i in range(h):
        for j in range(w):
            if grid[i][j] == ".":
                ans_list.append((i, j))
    m = 0
    for i, j in ans_list:
        q = [(i, j)]
        dist = [[-1]*w for _ in [0]*h]
        cnt = 0
        dist[i][j] = 0
        while q:
            qq = []
            cnt += 1
            while q:
                x, y = q.pop()
                if x > 0:
                    if dist[x-1][y] == -1:
                        if grid[x-1][y] == ".":
                            dist[x-1][y] = cnt
                            qq.append((x-1, y))
                if x < h-1:
                    if dist[x+1][y] == -1:
                        if grid[x+1][y] == ".":
                            dist[x+1][y] = cnt
                            qq.append((x+1, y))
                if y > 0:
                    if dist[x][y-1] == -1:
                        if grid[x][y-1] == ".":
                            dist[x][y-1] = cnt
                            qq.append((x, y-1))
                if y < w-1:
                    if dist[x][y+1] == -1:
                        if grid[x][y+1] == ".":
                            dist[x][y+1] = cnt
                            qq.append((x, y+1))
            q = qq
        m = max(m, max([max([l for l in k]) for k in dist]))
    print(m)


main()


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

#define int long long

const int INF = 1e15;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M, L;
  cin >> N >> M >> L;
  
  int d[N][N];
  int D[N][N];
  fill_n(*d, N*N, INF);
  fill_n(*D, N*N, INF);

  for ( int i = 0; i < N; i++ ) d[i][i] = 0;
  for ( int i = 0; i < N; i++ ) D[i][i] = 0;

  for ( int i = 0; i < M; i++ ) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    d[a][b] = d[b][a] = c;
  }

  for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < N; j++ ) {
      for ( int k = 0; k < N; k++ ) {
	d[j][k] = min(d[j][k], d[j][i] + d[i][k]);	
      }
    }
  }

  for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < N; j++ ) {
      if ( d[i][j] <= L ) D[i][j] = 1;      
    }
  }

  for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < N; j++ ) {
      for ( int k = 0; k < N; k++ ) {
	D[j][k] = min(D[j][k], D[j][i] + D[i][k]);	
      }
    }
  }

  int Q;
  cin >> Q;
  while ( Q-- ) {
    int s, t;
    cin >> s >> t;
    s--; t--;
    if ( D[s][t] == INF ) cout << -1 << endl;
    else {
      if ( d[s][t] <= L ) cout << 0 << endl;      
      else cout << D[s][t]-1 << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 1920
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] arr = new int[m];
        for (int i=0; i<m; i++) arr[i] = sc.nextInt();
        if (m == 1 || n >= m) {
            System.out.println(0);
            return;
        }
        Arrays.sort(arr);

        int sum = arr[m-1] - arr[0];

        int[] diff = new int[m-1];
        for (int i=0; i<m-1; i++) {
            diff[i] = arr[i+1]-arr[i];
        }

        Arrays.sort(diff);

        while (1 < n) {
            sum -= diff[m-2];
            n--;
            m--;
        }


        int l = 0;
        int r = arr.length - 1;



        System.out.println(sum);


    }


}



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>A(1e5+1,0);
	for(int i=0;i<n;++i){
		int a; cin>>a;
		++A.at(a);
	}
	int sum=0;
	for(auto&i:A)if(i>1)sum+=i-1;
	cout<<n-sum-(sum%2)<<"\n"s;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n=0;
	string S;
	cin >> S;
	for (int i = 0;i < 4;i++) {
		if (S[i] == '+')n++;
		else if (S[i] == '-')n--;
	}
	cout << n << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

int main(){
    string s1, s2, s3; cin >> s1 >> s2 >> s3;

    char s1c, s2c, s3c;
    s1c = s1[0] - ('a' - 'A');
    s2c = s2[0] - ('a' - 'A');
    s3c = s3[0] - ('a' - 'A');
    cout << s1c << s2c << s3c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

struct Node
{
	int key;
	Node *parent, *left, *right; 
};

Node *root, *NIL;

void insert(Node *z)
{
	Node *x = root;	//current node.
	Node *y = NIL; //current node's parrent node.

	while(x != NIL) //first time root == NIL?
	{
		y = x;
		if(z->key < x->key)
		{
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}
	z->parent = y;
	
	if(y == NIL) root = z;
	else if(z->key < y->key)
	{
		y->left = z;
	}
	else
	{
		y->right = z;
	}
}

void find(Node *z)
{
	Node *x = root;	//current node.

	while(x != NIL) 
	{
		if(z->key == x->key)
		{
			cout << "yes" << endl;
			break;
		}
		else if(z->key < x->key)
		{
			x = x->left;
		}
		else if(z->key > x->key)
		{
			x = x->right;
		}
	}
	if(x == NIL) cout << "no" << endl;

}


void preParse(Node *u)
{
	if(u == NIL) return;
	cout << " " << u->key;
	preParse(u->left);
	preParse(u->right);
}


void inParse(Node *u)
{
	if(u == NIL) return;
	inParse(u->left);
	cout << " " << u->key;
	inParse(u->right);
}

void print()
{
	inParse(root);
	cout << endl;
	preParse(root);
	cout << endl;
}

int main(){

//	char S[10];  // is this one ok?
	string s;
	int k,v,m;
	
	cin >> m;
	for(int i = 0; i < m; i++)
	{
		cin >> s;
		if(s == "insert")
		{
			cin >> k;
			
			Node *z = new Node;	//Cannot delete!
//			z = (new *)malloc(sizeof(Node));
			z->key = k;
			z->left = NIL;
			z->right = NIL;
			
			insert(z);
//			delete z;
		} 
		else if(s == "print") print();
		else if(s == "find")
		{
			
			cin >> v;
			Node *z = new Node;	//Cannot delete!
//			z = (new *)malloc(sizeof(Node));
			z->key = v;
			z->left = NIL;
			z->right = NIL;
			find(z);
		}
	}
	
	
//	system("pause");
	return 0;
}


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

int main() {
	ll n, k, s;
	cin >> n >> k >> s;
	if (s < n) {
		rep(i, k) cout << s << " ";
		rep(i, n - k)cout << 1000000 << " ";
	}
	else {
		rep(i, k) cout << s << " ";
		rep(i, n - k)cout << 1 << " ";
	}
}

Measured memory_bytes: 1280
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;

long INF = long.max/3;
struct Edge{int fst, snd; long cost;}
void main() {
    int N, M;
    readf("%d %d\n", &N, &M);
    long[][] d = N.iota.map!(i => N.iota.map!(j => i==j?0:INF).array).array;
    Edge[] es = new Edge[M];
    foreach(i; 0..M) {
        int a, b; long c;
        readf("%d %d %d\n", &a, &b, &c);
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
        es[i] = Edge(a, b, c);
    }
    foreach(k; 0..N) {
        foreach(i; 0..N) foreach(j; 0..N) {
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }
    es.count!(
        e => N.iota.all!(
            i => d[i][e.fst] + e.cost != d[i][e.snd]
        )
    ).writeln;
}

// -------------------------------------------
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                return reduce!fun(tuple(seed), r);
            }
        }
    }
}

// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
    auto minElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto minimum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b < minimum) {
                element = a;
                minimum = b;
            }
        }
        return element;
    }
    auto maxElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto maximum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b > maximum) {
                element = a;
                maximum = b;
            }
        }
        return element;
    }
}


Measured memory_bytes: 380
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;

int main()
{
	int Maxcnt=0,cnt=0,Anum=0,Znum=0;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'A'){Anum = i; break;}
	}
	for (int j = s.length(); j >= 0;j--){
		if (s[j] == 'Z') { Znum = j; break; }
	}
	cout << Znum-Anum+1 << endl;
}


Measured memory_bytes: 640
N = gets.to_i
P = Array.new(N)
S = Array.new(N)
for i in 0..N-1 do
    P[i] = gets.to_i
    if i == 0 then
        S[i] = P[i]
    else
        S[i] = S[i-1] + P[i]
    end
end

M = P.max

puts S[N-1] - (M/2)


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;

vector<ll> Box(3);
ll diffMin(ll H, ll W , ll ah){
	ll BCh = H - ah;
	ll d1=0,d2=0;

	{// ptn1:
		ll Bh = (BCh+1)/2;
		ll Ch = BCh-Bh;
		Box[0] = ah * W;
		Box[1] = Bh * W;
		Box[2] = Ch * W;
		sort(Box.begin(),Box.end());
		d1 = Box[2]-Box[0];
	}

	{//ptn2:
		ll Bw = (W+1)/2;
		ll Cw = W - Bw;
		Box[0] = ah * W;
		Box[1] = BCh * Bw;
		Box[2] = BCh * Cw;
		sort(Box.begin(),Box.end());
		d2= Box[2]-Box[0];
	}
	return min(d1,d2);
}


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

	ll H,W;
	cin >> H >> W;

	if ((H%3==0)||(W%3==0)){printf("0\n");return 0;} // 3等分可能

	// H軸上でA ,BC の分割
	ll H_min = LLONG_MAX;
	for(ll i=1;i<H;i++){
		ll m = diffMin(H,W,i);
		H_min = min(H_min , m );
	}

	// W軸上でA ,BC の分割
	ll W_min = LLONG_MAX;
	for(ll i=1;i<=W;i++){
		ll m = diffMin(W,H,i);
		W_min = min(W_min , m );
	}

	printf("%ld\n",min(H_min,W_min) );
	return 0;
}


Measured memory_bytes: 256
n = int(input())
if 1 <= n and n <= 9:
    print(n)
elif 10 <= n and n <= 99:
    print(9)
elif 100 <= n and n <= 999:
    print(9+n-99)
elif 1000 <= n and n <= 9999:
    print(9+999-99)
elif 10000 <= n and n <= 99999:
    print(9+999-99+n-9999)
elif 100000 <= n and n <= 999999:
    print(9+999-99+99999-9999)

Measured memory_bytes: 38424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

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; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

bool is_prime[1000010];
ll check[200010];
int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        a[i]--;
    }
    //set<int> se;
    ll i = 0,it = 0,it2;
    while(1){
        k--;
        if(k == 0){
            cout << a[i]+1 << endl;
            return 0;
        }
        if(check[i] == 0){
            check[i] = it;
            i = a[i];
        }
        else{
            it2 = it - check[i];
            i = a[i];
            break;
        }
        it++;
    }

    ll amari = k%it2;
    while(amari--){
        i = a[i];
    }
    cout << i+1 << endl;
    //cout << (k%3) << endl;
    return 0;
}

Measured memory_bytes: 6480
n = int(input())
'''
s = str(n)
o = s.count('1','3','5','7','9')
e = s.count('0','2','4','6','8')
print(o)
'''
ans = 0
for i in range(1, n+1):
    if len(str(i)) % 2 == 1:
        ans += 1
print(ans)

Measured memory_bytes: 2940
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] a_asArgs)
        {
			int l_iN = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray()[0];

			Console.WriteLine(l_iN / 3);
		}
	}
}


Measured memory_bytes: 13268
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val x = sc.nextInt
  val y = sc.nextInt

  val a = Seq(1,3,5,7,8,10,12)
  val b = Seq(4,6,9,11)
  val c = Seq(2)

  val res = if(isSameGroup(x,y)) "Yes" else "No"

  println(res)

  def isSameGroup(x: Int, y: Int): Boolean ={
    ( a.contains(x) && a.contains(y) ) ||
    ( b.contains(x) && b.contains(y) ) ||
    ( c.contains(x) && c.contains(y) )
  }

}


Measured memory_bytes: 25508
#include <iostream>
int main(void){
	int a,b,n,s;
	while (true){
		std::cin>>a>>b>>n;
		if (std::cin.eof()) break;
		s=0;
		while(n--){
			a=a%b*10;
			s+=a/b;
		}
		std::cout<<s<<"\n";
	}
} 

Measured memory_bytes: 1160
import sys

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

same = 0
for i in range(n):
	if a[i] == b[i]:
		same += 1
	elif b[i]*2 >= a[i]:
		print(-1)
		sys.exit()

if same == n:
	print(0)
	sys.exit()

edges = [[] for _ in range(51)]
for i in range(1, 51):
	for j in range(1, i+1):
		edges[i].append([i%j, j])

available = [True for _ in range(51)]
visited = [False for _ in range(51)]

def dfs(start, goal, cur):
	global visited
	if cur == goal:
		return True
	for e, k in edges[cur]:
		if visited[e] == False and available[k] == True:
			visited[e] = True
			if dfs(start, goal, e) == True:
				return True
	return False

ans = 0
for k in range(50, 0, -1):
	available[k] = False
	ok = True
	for i in range(n):
		visited = [False for _ in range(51)]
		visited[a[i]] = True
		if dfs(a[i], b[i], a[i]) == False:
			ok = False
			break
	if not ok:
		ans += 2**k
		available[k] = True

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define B break
#define R return
#define pb push_back
#define C continue
#define F first
#define S second
using namespace std;
ll mod=1e9+7;
ll poww(ll x,ll y)
{
    if (y==0) R 1;
    if (x==1) R 1;
    if (x==0) R 0;
    if (y==1) R x;
    ll d=poww(x,y/2);
    d%=mod;
    if (y%2) R (((d*d)%mod)*x)%mod;
    R (d*d)%mod;
}
ll a[55],b[55];
int main()
{
 ll n;
 cin>>n;
 for(ll i=0;i<n;i++)
 {
     cin>>a[i];
 }
 for(ll i=0;i<n;i++)
 {
     for(ll j=i+1;j<n;j++)
     {
         b[i]+=a[i]*a[j];
     }
 }
 ll sum=0;
 for(ll i=0;i<n;i++)
 {
     sum+=b[i];
 }
 cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <algorithm>
#include <map>
#include <iostream>
#include <sstream>
#include <queue>
#include <iomanip>

#include <string.h>

using namespace std;

bool dfs(const char* str)
{
	
	if(strlen(str) == 0)
	{
		return true;
	}

	else if(str[0] != 'd' && str[0] != 'e')
	{
		return false;
	}

	else if(strncmp(str, "dreamer", sizeof("dreamer")-1) == 0)
	{
		return dfs(str+5) || dfs(str+7);
	}
	else if(strncmp(str, "dream", sizeof("dream")-1) == 0)
	{
		return dfs(str+5);
	}

	else if(strncmp(str, "eraser", sizeof("eraser")-1) == 0)
	{
		return dfs(str+5) || dfs(str+6);
	}

	else if(strncmp(str, "erase", sizeof("erase")-1) == 0)
	{
		return dfs(str+5);
	}

	return false;
}

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

	const char *str = s.c_str();

	if(strlen(str) > 0 && dfs(str))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#define MAX 500000
#define SENTINEL 2000000000
using namespace std;

int sum=0;

void merge(int A[], int left, int mid, int right){
    int n1,n2;
    n1=mid-left;
    n2=right-mid;
    int L[n1]={0},R[n2]={0};
    for(int i=0;i<n1;i++){
        L[i]=A[left+i];
    }
    for(int i=0;i<n2;i++){
        R[i]=A[mid+i];
    }
    L[n1]=R[n2]=2000000000;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        if(L[i]<=R[j]){
            A[k]=L[i];
            i++;
            sum++;
        }else{
            A[k]=R[j];
            j++;
            sum++;
        }
    }
}


void mergeSort(int A[], int left, int right){
    int mid;
    if(left+1<right){
        int mid=(left+right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(){
    int n;
    int S[500000]={0};
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&S[i]);
    }
    mergeSort(S,0,n);
    for(int i=0;i<n;i++){
        if(i) printf(" ");
        printf("%d", S[i]);
    }
    printf("\n");
    printf("%d\n", sum);
}


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

int main() {
	string str;
	int m, h;
    
	while(cin >> str,str != "-"){
		cin >> m;
		for (int i = 0; i < m; ++i) {
			cin >> h;
			str.append(str.substr(0, h)).erase(0, h);
		}
		cout << str << endl;
	}
    
	return 0;
}



Measured memory_bytes: 3136
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 0
for i in range(60):
    x = [(bool)(ai & 1 << i) for ai in a]
    sx = sum(x)
    count = sx * (n - sx)
    ans += count << i
    ans %= MOD

print(ans)

Measured memory_bytes: 139576
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
int n;
  cin >> n;
  if(n % 2 == 0){
    cout << n << "\n";
  }
  else{
    cout << n * 2 << "\n";
  }
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"

using namespace std;

#define print(s) cout << (s) << endl;

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

    if (0 <= r && r < 1200){
        print ("ABC");
    }

    else if (1200 <= r && r < 2800){
        print ("ARC");
    }

    else {
        print ("AGC");
    }
    return 0;
}

Measured memory_bytes: 256
X,Y,K=map(int,input().split())
if X+K > Y:
  for i in range(X,Y+1):
    print(i)
elif X+K > Y-K:
  for i in range(X,Y+1):
    print(i)
else:
  for i in range(X,X+K):
    print(i)
  for i in range(Y-K+1,Y+1):
    print(i)


Measured memory_bytes: 3060
def main():
    x = int(input())
    numlist = list(map(int, input().split()))
    for i in range(1, x+1):
        if i == x:
            print(numlist[x-i], end="\n")
        else:
            print(numlist[x-i], end=" ")

if __name__ == '__main__':
    main()


Measured memory_bytes: 5600
def gets; ARGF.gets; end

def main
  s = gets.chomp
  k = gets.chomp.to_i

  # 5000兆日後
  #     5000 0000 0000 0000
  # k
  # 100 0000 0000 0000 0000

  pos_to_find = if s.length < k
                  s.length-1
                else
                  k-1
                end

  # 最初の1以外の文字を探す
  0.upto(pos_to_find) do |i|
    if s[i] != "1"
      puts s[i]
      return
    end
  end

  puts "1"

end

if __FILE__ == $0
  main
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 1e5+1;
int a, b, c;

int main(){
   // freopen("read.txt","r",stdin);
    int x[4];
    for(int i = 0 ;i < 3; ++i){
    	 scanf("%d",x+i);
    }
    sort(x,x+3);
    if((x[0] == x[1] && x[0] == x[2]))puts("Yes");
    else puts("No");

  
 	return 0;	
} 

Measured memory_bytes: 256
INF = -float("inf")
 
def Bellmanford(n, e):
  dp = [INF] * n
  dp[0] = 0
  for i in range(n):
    for a, b, c in e:
      if dp[a] != INF and dp[a] + c > dp[b]:
        dp[b] = dp[a] + c
        if i == n-1 and b == n-1:
          return "inf"
  return dp[n-1]

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

abc = []
for i in range(M):
  a, b, c = map(int, input().split())
  abc.append((a-1, b-1, c))

ans = Bellmanford(N, abc) 
print(ans)

Measured memory_bytes: 9296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(n);i++)
#define fori(a,b,i) for(int i=(a);i<=(b);i++)
#define ford(a,b,i) for(int i=(a);i>=(b);i--)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);


#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
typedef long long int llint;


int main(){
	llint cap, n;
	cin>>n>>cap;
	vector <llint> bag(n), val(n);
	loop(i, n) { cin>>bag[i]; cin>>val[i]; }
	llint dp[n+1][cap+1];
	memset(dp, 0, sizeof(dp));
	for(int i = 0; i < n+1; ++i){
		for(int w = 0; w <= cap; ++w){
			if(i == 0 || w == 0) dp[i][w] = 0;
			else if(w - bag[i-1] >= 0) dp[i][w] = max(dp[i-1][w], val[i-1] + dp[i-1][w - bag[i-1]]);
			else dp[i][w] = dp[i-1][w];
			//debug(dp[i][w]);
		}
	}
	cout<<dp[n][cap];
}


Measured memory_bytes: 79104
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int N, M, Q;
    while(cin >> N >> M) {
        const int MAX_N = 1e5 + 10;
        const int MAX_D = 11;
        vector<vector<int>> nexts(N);
        REP(i, M) {
            int a, b;
            cin >> a >> b;
            a--; b--;
            nexts[a].push_back(b);
            nexts[b].push_back(a);
        }

        bool used[MAX_N][MAX_D] = {};

        cin >> Q;
        vector<int> vq(Q);
        vector<int> dq(Q);
        vector<int> cq(Q);
        REP(i, Q) cin >> vq[i] >> dq[i] >> cq[i];

        vector<int> colors(N, -1);
        for(int i = Q-1; i >= 0; i--) {
            int V = vq[i];
            int D = dq[i];
            int C = cq[i];
            V--;
            queue<pair<int, int>> que;
            if(!used[V][D]) {
                que.push(make_pair(V, D));
            }
            while(!que.empty()) {
                auto p = que.front(); que.pop();
                int u = p.first;
                int d = p.second;
                if(colors[u] == -1) {
                    colors[u] = C;
                }
                if(d > 0) {
                    for(int nu : nexts[u]) {
                        if(!used[nu][d-1]) {
                            for(int j = 0; j <= d-1; j++) {
                                used[nu][j] = true;
                            }
                            que.push(make_pair(nu, d-1));
                        }
                    }
                }
            }
        }

        REP(i, N) {
            if(colors[i] == -1) {
                cout << 0 << endl;
            } else {
                cout << colors[i] << endl;
            }
        }

    }

    return 0;
}



Measured memory_bytes: 9608
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    int minimum = 1;
    for(int i = 0; i < N; i++) {
        if(minimum < K) {
            minimum *= 2;
        }
        else {
            minimum += K;
        }
    }
    cout << minimum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main ()
{
  prep();
  int n;
  cin >> n;
  int a[n];
  int b[n];
  bool notequal = false;
  long long sum = 0;
  for (int i=0; i<n; i++){
      cin >> a[i];
      cin >> b[i];
      sum += a[i];
      if (a[i] != b[i]){
          notequal = true;
      }
  }
  if (!notequal){
      cout << 0;
      return 0;
  }
 
  int minnest = 1000000001;
  for (int i=0; i<n; i++){
      if (a[i] > b[i]){
          minnest = min(minnest, b[i]);
      }
  }
  cout << sum-minnest;
  return 0; 
}


Measured memory_bytes: 384
X,N=map(int,input().split())
P=list(map(int,input().split()))
absP=[abs(X-i) for i in P]

def b():
    if(N==0):
        return X
    for n in range(0,N+1):
        a=X-n
        if(a not in P):
            return a
        a=X+n
        if(X+n not in P):
            return a
print(b())

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

int main() {
    int a[5];
    REP(i,5) cin >> a[i];
    cout << min({a[0],a[1],a[2]})+min(a[3],a[4])-50 << endl;
    return 0;
}



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

int main(){
    int n, k, ans=0; cin >> n >> k;
    vector<int>p(n);

    rep(i,n) cin >> p[i];

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

    rep(i,k) ans += p[i];

    cout << ans << endl;

    return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k,x; cin>>k>>x;
  for(int i=-k+1;i<k;i++) cout<<x+i<<' ';
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int N,ct=0;
    double x,y,dist,D;
    cin>>N>>D;
    while(N--)
    {
        cin>>x>>y;
        dist = sqrt(x*x+y*y);
        if(dist<=D)
            ct++;
    }
    cout<<ct<<"\n";
    return 0;
}


Measured memory_bytes: 3868
N,M = map(int,input().split())

A = []

for i in range(N):

    a = list(map(int,input().split()))
    A.append(a)

use = [True] * M

maxind = None
ans = float("inf")

for i in range(M):

    maxind = 0
    x = [0] * M
    
    for j in range(N):
        for k in range(M):
            if use[ A[j][k] - 1 ]:
                x[ A[j][k] - 1 ] += 1
                break

    for j in range(M):
        if x[maxind] < x[j]:
            maxind = j

    ans = min( ans , x[maxind] )
    use[maxind] = False

print (ans)


Measured memory_bytes: 43356
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    int n, t; cin >> n >> t;
    int m = 1<<30, max = 0, cnt = 0;
    while (n--) {
        int a; cin >> a;
        if (a - m > max) { max = a - m; cnt = 1; }
        else if (a - m == max) cnt++;
        m = min(a, m);
    }
    cout << cnt << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 29;
const double EPS = 1e-10;


int main(){
  int a[20];
  int n;
  while(cin >> n && n){
    int res = INF;
    rep(i, n) cin >> a[i];
    rep(i, 1 << n){
      int dif = 0;
      rep(j, n){
	if(i & (1 << j)) dif += a[j];
	else dif -= a[j];
      }
      res = min(res, abs(dif));
    }
    cout << res << endl;
  }
  return 0;
}

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

int main(){
  int n; cin >> n;
  const int limit = 1000009;
  int a[limit] = {};
  for(int i = 0; i < n; ++i){
    int tmp; cin >> tmp;
    if(tmp == 0) {
		a[tmp]++;
        a[tmp+1]++;
    }else {
      	a[tmp]++;
      	a[tmp-1]++;
      	a[tmp+1]++;
    }
  }
  int ans = -1;
  for(auto val: a){
    ans = max(ans, val);
  }
  cout << ans << endl;
  return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


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

    int m = n;
    if(m & 1){
        m /= 2;
        m++;
        cout << setprecision(10) << (double)m / (double)n << endl;
    }else{
        m /= 2;
        cout << setprecision(10) << (double)m / (double)n << endl;
    }

    return 0;
}


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

using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

int x[100001];

signed main(){
  int a,b;
  cin>>a>>b;
  int n=b/4*4;
  int cnt=b%4+1;
  int ans=0;
  //cout<<n<<" "<<cnt<<endl;
  lp(i,cnt){
    if(i==0) ans=n;
    else{
      ans=ans^n;
    }
    n++;
  }
  n=a/4*4;
  cnt=a%4;
  //cout<<n<<" "<<cnt<<endl;
  lp(i,cnt){
    ans=ans^n;
    n++;
  }
  cout<<ans<<endl;
  return 0;
}

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

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

    vector<vector<int>> x(n,vector<int>(d));
    for(int i=0; i<n; i++){
        for(int j=0; j<d; j++){
            cin>>x[i][j];
        }
    }

    int d_int=0;
    double d_double=0;
    int count=0;

    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            for(int k=0; k<d; k++){
                d_int+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                d_double+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            d_int=sqrt(d_int);
            d_double=sqrt(d_double);
            if(d_int==d_double){
                count++;
            }
            d_int=0;
            d_double=0;
        }
    }

    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL dp[MAXN];	

int main(){
  fio();
  int n,k; cin>>n>>k;
  vector <LL> v(n);
  forn(i,n) cin>>v[i];
  dp[0] = 0;
  for1(i,n-1){
  	LL ans = 1e18;
  	for1(j,k){
  		if(i<j) break;
  		ans = min(ans, dp[i-j] + abs(v[i-j]-v[i]));
  	}
  	dp[i] = ans;
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1792
while True:
    n, x = [int(i) for i in input().split()]

    if n == x == 0:
        break

    count = 0
    for s in range(1, n + 1):
        for m in range(s+1, n):
            for e in range(m+1, n+1):
                if x == sum([s, m, e]):
                    count += 1

    print(count)

Measured memory_bytes: 7716
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (n)-1; i > -1; i--)
#define reps(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define sper(i, s, n) for (int i = (s); i >= (int)(n); i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve()
{
    string s;
    cin >> s;
    string key = "keyence";
    bool ok = false;
    rep(i, s.size())
    {
        rep(j, s.size())
        {
            string t = s;
            t.erase(i, j);
            if (t == key)
            {
                cout << "YES" << endl;
                return;
            }
        }
    }
    cout << "NO" << endl;
}

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

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int ggcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,count=0,ans=0;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  rep(i,n){
    if(v[i]>count){
      count=v[i];
      ans=i;
    }
  }
  sort(v.begin(),v.end());
  if(v[v.size()-1]==v[v.size()-2]){
    rep(i,n){
      cout<<v[v.size()-1]<<endl;
    }
  }else{
    rep(i,n){
      if(i==ans){
        cout<<v[v.size()-2]<<endl;
      }else{
        cout<<v[v.size()-1]<<endl;
      }
    }
  }
  
  
  
}
///////////////////////////

Measured memory_bytes: 2432
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}
int main() {
  int D, G; cin >> D >> G;
  G /= 100;
  vector<LL> p(D), all(D);
  for (int i = 0; i < D; ++i) {
    int c; cin >> p[i] >> c;
    all[i] = (i + 1) * p[i] + c/100;
  }

  int cnt_min = 1e9;
  for (int i = 0; i < (1 << D); ++i) {
    bitset<10> b(i);
    int score = 0;
    int cnt = 0;
    vector<int> indices;
    for (int j = 0; j < D; ++j) {
      if (b.test(j)) {
        cnt += p[j];
        score += all[j];
      } else {
        indices.push_back(j);
      }
    }
    for (auto it = indices.rbegin(); it != indices.rend() && score < G; ++it) {
      int j = *it;
      if (score + (j + 1) * (p[j]-1) >= G) {
        while (score < G) {
          score += j + 1; ++cnt;
        }
        break;
      } else {
        score += (j + 1) * (p[j]-1);
        cnt += p[j] - 1;
      }
    }
    if (score < G) continue;
    cnt_min = min(cnt_min, cnt);
  }
  cout << cnt_min << endl;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N;
	cin >> N;

	bool all0 = true;
	int A[100000];
	rep(i, N) {
		cin >> A[i];
		if (A[i]) all0 = false;
	}
	if (all0) {
		co("Yes");
		return 0;
	}
	else if (N % 3 != 0) {
		co("No");
		return 0;
	}

	sort(A, A + N);
	int k = 0;
	int B[3];
	B[0] = A[0];
	B[1] = A[N / 3];
	B[2] = A[N / 3 * 2];
	bool OK = 1;
	rep(i, N) {
		if (A[i] != B[i / (N / 3)]) OK = false;
	}
	if ((B[0] ^ B[1]) != B[2]) OK = false;

	if (OK) co("Yes");
	else co("No");

	Would you please return 0;
}

Measured memory_bytes: 640
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp

def is_prime(n):
	if n==1: return True

	for i in range(2,int(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True

a,b,c=input2()

if a<=b+c:
	print(b+c-a)
else:
	print(0)















Measured memory_bytes: 21168
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    string a,b,c;cin>>a>>b>>c;
    if(a.at(a.size()-1)==b.at(0) && b.at(b.size()-1)==c.at(0)){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 3616
n = int(input())
h = list(map(int,input().split()))

dp= [0]*(n+1)
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2] + abs(h[i]-h[i-2]))

print(dp[n-1])

Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
string nw(string s)
{
  	int f=0;
    int len=s.length();
    int j=s.length()-1;
    while((s[j]=='9' || s[j]==(s[j-1]+1)) && j!=0)
    {
      s.pop_back();
      j--;
    }
    int n=s.length();
  	if(s[0]=='9' && n==1)
    {
      s[0]='1';
      f=1;
    }
    else s[n-1]++;
    while(n!=len)
    {
      char c=max((int)'0',s[n-1]-1);
      s.push_back(c);
      n++;
    }
  if(f)s.push_back('0');
  return s;
}
int main()
{
  vector<string>a(100001);
  string cur;
  cur+="10";
  for(int i=1;i<100001;i++)
  {
    if(i<10)
    {
      string c;
      c.push_back(i+'0');
      a[i]=c;
      continue;
    }
    a[i]=cur;
    cur=nw(cur);
  }
  int k;
  cin>>k;
  cout<<a[k];

 // for(int i=100;i<=500;i++)cout<<a[i]<<endl;
   return 0;
  }

Measured memory_bytes: 6220