akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int w[100010],b[100010],n,a,ans,tasu;

int main(){

    while(1){

    cin >> n;
    if(n==0)break;
    cin >> a;
    if(a==0){
        w[1]=1;
    }else{
        b[1]=1;
    }
    //printf("i=1 b=%d w=%d\n",b[1],w[1]);

    for(int i=2;i<=n;i++){
        cin >> a;
        if(i%2==0){
            if(a==1){
                if(w[i-1]>0){
                    b[i]=w[i-1]+1;
                    w[i-1]=0;
                    //printf(" b[i-b[i]]=%d\n b[i]=%d\n",b[i-b[i]],b[i]);

                    tasu=b[i-b[i]];
                    b[i-b[i]]=0;
                    b[i]+=tasu;
                }else if(b[i-1]>0){
                        b[i]=b[i-1]+1;
                        b[i-1]=0;
                    }else {
                        b[i]++;
                    }
            }else{
                if(b[i-1]>0){
                    w[i]=b[i-1]+1;
                    b[i-1]=0;
                    //printf("w[i-w[i]]=%d\n",w[i-w[i]]);
                    tasu=w[i-w[i]];
                    w[i-w[i]]=0;
                    w[i]+=tasu;
                }else if(w[i-1]>0){
                        w[i]=w[i-1]+1;
                        w[i-1]=0;
                    }else {
                        w[i]++;
                    }

            }
        }else{
            if(a==1){
                if(b[i-1]>0){
                    b[i]=b[i-1]+1;
                    b[i-1]=0;
                }else b[i]++;
            }else{
                if(w[i-1]>0){
                    w[i]=w[i-1]+1;
                    w[i-1]=0;
                }else w[i]++;

            }
        }
        //printf("i=%d b=%d w=%d\n",i,b[i],w[i]);
    }

    for(int i=1;i<=n;i++){
   //     cout << w[i] << endl;
  //  printf("i=%d b=%d w=%d\n",i,b[i],w[i]);
        if(w[i]>0)ans+=w[i];
    }

    cout << ans << endl;

    ans=0;
    for(int i=0;i<=n;i++){
        b[i]=0;
        w[i]=0;
    }

    }


return 0;
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int r, D;
int x[5001];

int32_t main()
{
	IOS;
	cin >> r >> D >> x[2000];
	for(int i = 2001; i <= 2010; i++)
	{
		x[i] = r * x[i - 1] - D;
		cout << x[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
*/
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)
 
#define pb              push_back
#define mp              make_pair
 
#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))
 
#define ff              first
#define ss              second
 
#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)
 
#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())
 
#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )
#define RFOR(i,e,s)     for( LL i = e ; i>=s ; i-- )
         
 
#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("WA.txt","w",stdout)
 
#define DEBUG(x)        cerr<<#x<<" = "<<x<<endl
#define PRINTALL(v)     {cerr<<endl<<"Printing: "<<#v<<endl;for(LL i = 0 ; i<v.size(); i++) DEBUG(v[i]); cerr<<endl;}
 
#define sz(v)			((LL)v.size())
#define pi 				(acos(-1.0));
using namespace std;

LL a[110];

int main(){ 
	
	LL N;
	SL(N);
	FOR(i,1,N) SL(a[i]);
	sort(a+1,a+N+1);
	LL ans = 0;
	FOR(i,1,N){
		FOR(j,i,N){
			if( a[i] == a[j]  ) continue;
			FOR(k,j,N){
				if( a[i] == a[k] || a[j] == a[k] ) continue;
				if( a[i] + a[j]>a[k] ) ans++;
			}
		}
	}
	
	cout<<ans<<endl;
	
	
return 0;}



Measured memory_bytes: 3724
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()

	list := make([]bool, 1e6)
	K := sc.NextInt()
	l := 7
	i := 1

	t := l
	for {

		if t%K == 0 {
			fmt.Println(i)
			return
		}
		if list[t] {
			fmt.Println(-1)
			return
		}
		list[t] = true
		i++
		l *= 10
		l %= K
		t += l
		t %= K
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 2804
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    adj = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(n-1):
        c,b = map(int, input().split())
        adj[c-1].append(b-1)
        adj[b-1].append(c-1)

    # 頂点1も含む
    res = [0]*n
    res[0] = 1

    def dfs(v, par, L):
        if v != 0:
            if a[v] > L[-1]:
                temp = -1
                L.append(a[v])
            else:
                temp = bisect_left(L, a[v])
                pre = L[temp]
                L[temp] = a[v]
        res[v] = len(L)
        for nv in adj[v]:
            if nv == par:
                continue
            dfs(nv, v, L)
        if v != 0:
            if temp == -1:
                L.pop(-1)
            else:
                L[temp] = pre

    L = [a[0]]
    dfs(0, -1, L)
    for i in range(n):
        print(res[i])

if __name__ == '__main__':
    main()


Measured memory_bytes: 364248
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#define mp make_pair
#define pb push_back
#define ll long long
#define kl k<<1
#define kr k<<1|1
using namespace std;
inline ll read(){ll s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
void put1(){ puts("YES") ;}void put2(){ puts("NO") ;}void put3(){ puts("-1"); }
ll qp(ll a,ll b, ll p){ll ans = 1;while(b){if(b&1){ans = (ans*a)%p;--b;}a =
(a*a)%p;b >>= 1;}return ans%p;}

using namespace std;
const int maxn=1e5+5;
ll cnt[3][maxn];
map<char,int> m;
map<int,char> m1;
char s[maxn];
int main()
{
    ll len,ans=0;
 	cin>>len>>s;
 	m['R']=0,m['G']=1,m['B']=2;
 	m1[0]='R',m1[1]='G',m1[2]='B';
 	for(int i=len-1;i>=0;i--){
 		for(int j=0;j<3;j++)
			cnt[j][i]=cnt[j][i+1];
		cnt[m[s[i]]][i]++;
    }
	for(int i=0;i<len-2;i++){
		for(int j=i+1;j<len-1;j++){
			if(s[i]==s[j]) continue;
			else{
				int k=3-m[s[i]]-m[s[j]];
				ans+=cnt[k][j+1];
				if(s[j+(j-i)]==m1[k]) ans--;
			}
		}
    }
	cout<<ans;
 	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int sen = n / 1000;
  int hyaku = (n - sen * 1000) / 100;
  int zyuu = (n - sen * 1000 - hyaku * 100) / 10;
  int iti = n - sen * 1000 - hyaku * 100 - zyuu * 10;
  if ((sen == hyaku && sen == zyuu) || (hyaku == zyuu && hyaku == iti)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main(){
    
    long long X; cin >> X;
    
    bool ok = false;
    
    for(long long a=1; a<1000; a++){
        //long int sum = llpow(a,5);
        long long sum =a*a*a*a*a;
        //cout << sum << endl;
        for(long long b=-a; b<=a; b++){
            long long ans = sum - b*b*b*b*b;
            if(ans == X){
                cout << a << " " << b << endl;
                ok = true;
                break;
            }
            if(ans < X)break;
        }
        if(ok)break;
    }
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////


struct tower{
    ll w,s,v;
};
bool comp(tower t1,tower t2){
    if(t1.w+t1.s<t2.w+t2.s)return true;
    else return false;
}

int main(){
    ll n;cin>>n;
    tower t[n];
    rep(i,0,n-1){
        cin>>t[i].w>>t[i].s>>t[i].v;
    }
    sort(t,t+n,comp);
    ll N=30005;
    ll dp[n+1][N];
    memset(dp,0,sizeof(dp));
    rep(i,0,n-1){
        rep(j,0,N-1){
            dp[i+1][j]=dp[i][j];
            if(0<=j-t[i].w&&j-t[i].w<=t[i].s)Max(&dp[i+1][j],dp[i][j-t[i].w]+t[i].v);
        }
    }
    /*rep(i,0,n){
        rep(j,0,20){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    ll ans=0;rep(i,0,N-1)Max(&ans,dp[n][i]);
    cout<<ans<<endl;
    return 0;
}






Measured memory_bytes: 234880
#include<stdio.h>

#define INFTY 1000000000

int p;

void merge(int A[], int left, int mid, int right){
  int n1,n2,i,j,k;

  n1 = mid - left;
  n2 = right - mid;

  int L[n1], R[n2];

  for(i=0; i<n1; i++) L[i]=A[left+i];
  for(i=0; i<n2; i++) R[i]=A[mid+i];

  L[n1] = INFTY;
  R[n2] = INFTY;

  i=0,j=0;

  for(k=left; k<right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
    p++;
  }
}


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

int main(void){
  int n,i;
  p = 0;
  scanf("%d",&n);

  int S[n];
  for(i=0; i<n; i++) scanf("%d", &S[i]);

  mergeSort(S, 0, n);

  for(i=0; i<n-1; i++){
    printf("%d ",S[i]);
  }
  printf("%d\n",S[n-1]);
  printf("%d\n",p);

  return 0;
}



Measured memory_bytes: 5644
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

const int mod = 2019;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res=res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int n,i;
	cin >> n >> i;
	cout << n - i + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(a,i,n) for(int i=(a);i<(n);i++)

using namespace std;

int diff(int a,int b){
	return (a>b)?a-b:b-a;
}

int main(){
	int k,n;
	cin >> k;
	cin >> n;
	int a[n];
	rep(0,i,n){
		cin >> a[i];
	}
	int b[n];
	rep(0,i,n-1){
		b[i] = diff(a[i],a[i+1]);
	}
	b[n-1] = k-a[n-1]+a[0];
	sort(b,b+n);
	cout << k-b[n-1] << endl;
}

Measured memory_bytes: 1792
n,a,b,c = gets.split.map(&:to_i)
l = n.times.map{gets.to_i}
ans = 100000
[0,1,2,3].repeated_permutation(n) do |arr|
    ret = 0
    x = [0,0,0]
    y = [0,0,0]
    n.times do |i|
        next if arr[i] == 3
        x[arr[i]] += l[i]
        y[arr[i]] += 1
    end
    next if y.any?{|i|i == 0}
    ret += (y.inject(:+)-3)*10
    ret += (a-x[0]).abs+(b-x[1]).abs+(c-x[2]).abs
    ans = ret if ans > ret
end
puts ans

Measured memory_bytes: 1916
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  
  int N;
  cin >> N;
  
  vector<int> H(N);
  int cnt = 0;
  int hh = 0;
  int ans = 0;
  for(int i=0; i<N; i++)
  {
    int h;
    cin >> h;
    
    if(h<=hh)
    {
      cnt++;
      ans = max(ans, cnt);
    }else{
      cnt = 0;
    }
    
     hh = h;
  }
  
  
  cout << ans << endl;
  
  return 0;
}



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

int main(void) {
  ios::sync_with_stdio(false);
  int S;
  cin >> S;
  vector<int64_t> DP(2001, 0);
  const int64_t mod = 1e9 + 7;
  DP[0] = 1;
  for (int j = 0; j <= 2000; ++j) {
    for (int i = 3; i <= 2000; ++i) {
      if (j - i < 0) continue;
      DP[j] = (DP[j] + DP[j - i]) % mod;
    }
  }
  cout << DP[S] << endl;
  return 0;
}


Measured memory_bytes: 3664
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BSs {
public:
    void solve(std::istream &in, std::ostream &out) {
        string S;
        in >> S;
        int res = 0;
        FOR(l, 0, sz(S) / 2) {
            if (S.substr(0, l) == S.substr(l, l)) {
                res = 2 * l;
            }
        }
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BSs solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <numeric>
#include <limits>

const int INF = 1 << 30;
const int V = 10;
struct edge { int to, cost; };
std::vector<edge>v[100];
typedef std::pair<int, int>p;

int main() {
	int n, a[100000];
	std::cin >> n;
	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
	}
	std::sort(a, a + n);
	int b[100010] = {};
	for (int i = 0;i < n;i++) {
		b[a[i]] += 1;
	}
	int ans = 0;
	for (int i = 0;i <= 99998;i++) {
		if (b[i] + b[i + 1] + b[i + 2] > ans) {
			ans = b[i] + b[i + 1] + b[i + 2];
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1024
<?php

fscanf(STDIN,"%d",$N);
$a_list = explode(" ",trim(fgets(STDIN)));


sort($a_list);

for($i=0;$i<$N;$i++){
  if($a_list[$i] == $a_list[$i+1] && $i != $N-1){
    echo "NO\n";
    break;
  }
}

if($i == $N){
  echo "YES\n";
}

Measured memory_bytes: 23028
import sys
from io import StringIO
import unittest
import os
import math

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n, k = map(int, input().split())
    a_s = list(map(int, input().split()))

    right = 1000000001
    left = 0

    # ループ数に意味はない
    for i in range(100):

        middle = (left + right) // 2

        if middle == 0:
            break

        # middleより長い木を切る(切るべき回数の合計を取得する)
        cnt = 0
        for a in a_s:
            if a > middle:
                # 4/2 = 2    なら1回切る必要がある
                # 4/3 = 1.33 なら1回切る必要がある
                # 7/3 = 2.33 なら2回切る必要がある
                cnt += math.ceil(a / middle) - 1

        if cnt < k:
            # 最大値を下げる=小さい方に寄せる
            right = middle
        elif cnt > k:
            # 最小値を上げる=大きい方に寄せる
            left = middle
        else:
            # 最大値を下げる=小さい方に寄せる
            right = middle

    print(middle + 1)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """2 3
7 9"""
        output = """4"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3 0
3 4 5"""
        output = """5"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202"""
        output = """292638192"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_1original_1(self):
        test_input = """2 4
2 3"""
        output = """1"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 104448
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll MOD=(ll)1e9+7;
//}}}

int main(){
  int ans = 0;
  rep(6){
    char c;
    cin >> c;
    if(c == '1') ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

int main() {
	long long a, b; std::cin >> a >> b;
	if (a <= 0 && b >= 0)
		std::cout << "Zero" << std::endl;
	else if (a > 0 && b > 0)
		std::cout << "Positive" << std::endl;
	else {
		if (std::abs(a - b) % 2 == 0)
			std::cout << "Negative" << std::endl;
		else
			std::cout << "Positive" << std::endl;
	}

	return 0;
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    string S, T;
    cin >> S >> T;
    cout << T << S << endl;
    return 0;
}


Measured memory_bytes: 3596
import java.util.*;

public class Main {

    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        List<Integer> elem[] = new ArrayList[m];

        for (int i=0; i<m; i++){
            int k = sc.nextInt();
            elem[i] = new ArrayList<>();
            for (int j=0; j<k; j++){
                elem[i].add(sc.nextInt()-1);
            }
            }

        int p[] = new int[m];
        for (int i=0; i<m; i++) p[i] = sc.nextInt();

        int pattern = 0;

        for (int mask=0; mask<(1<<n); mask++){
            boolean light = true;
            for (int i=0; i<m; i++){
                int count_on = 0;
                for (int j: elem[i]){
                    if ((mask & (1<<j)) != 0){
                        count_on++;
                    }
                }
                if (count_on%2 != p[i]) light = false;
            }
            if (light) pattern++;
        }

        System.out.println(pattern);

        }

    }


Measured memory_bytes: 23892
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;


int gcd(int x, int y) {
  if (x == 0) return y;
  if (x > y) swap(x, y);
  return gcd(y % x, x);
}

int main() {
  int K;
  cin >> K;
  ll sum = 0;
  for (int a = 1; a <= K; ++a) {
    for (int b = 1; b <= K; ++b) {
      int tmp = gcd(a, b);
      for (int c = 1; c <= K; ++c) {
  	sum += gcd(tmp, c);
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long n,k;
	cin >> n >> k;
	//a,b b > k
	if(k == 0) {
		cout << n*n;
		return 0;
	}
	long long cnt = 0;
	for(int b = k + 1;b <= n;b++) {
		cnt += n / b * (b - k);
		if(n % b >= k) cnt += n % b - k + 1;
	}
	cout << cnt;
}

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

using namespace std;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


struct Mo {

  int width;
  vector< int > left, right, order;
  vector< bool > v;

  Mo(int N, int Q) : width((int) sqrt(N)), order(Q), v(N) {
    iota(begin(order), end(order), 0);
  }

  void add(int l, int r) { /* [l, r) */
    left.emplace_back(l);
    right.emplace_back(r);
  }

  template< typename ADD, typename DEL, typename REM >
  void run(const ADD &add, const DEL &del, const REM &rem) {
    assert(left.size() == order.size());
    sort(begin(order), end(order), [&](int a, int b) {
      int ablock = left[a] / width, bblock = left[b] / width;
      if(ablock != bblock) return ablock < bblock;
      if(ablock & 1) return right[a] < right[b];
      return right[a] > right[b];
    });
    int nl = 0, nr = 0;
    auto push = [&](int idx) {
      v[idx].flip();
      if(v[idx]) add(idx);
      else del(idx);
    };
    for(auto idx : order) {
      while(nl > left[idx]) push(--nl);
      while(nr < right[idx]) push(nr++);
      while(nl < left[idx]) push(nl++);
      while(nr > right[idx]) push(--nr);
      rem(idx);
    }
  }
};

int main() {
  int N, Q;
  cin >> N >> Q;
  vector< int > A(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector< int > f(1000001);
  Mo mo(N, Q);
  for(int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    mo.add(--l, r);
  }
  int ret = 0;
  auto add = [&](int idx) { if(f[A[idx]]++ == 0) ret++; };
  auto del = [&](int idx) { if(f[A[idx]]-- == 1) --ret; };
  vector< int > ans(Q);
  auto rem = [&](int idx) { ans[idx] = ret; };
  mo.run(add, del, rem);
  for(int i = 0; i < Q; i++) {
    cout << ans[i] << "\n";
  }
}


Measured memory_bytes: 17676
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;

int ca,cb,cc,wa,wb;
LL ans,res;

int main(){
	scanf("%d%d%d%d%d",&ca,&cb,&cc,&wa,&wb);
	res=2ll*cc*max(wa,wb);
	if(ca+cb>2*cc){
		int tmp=min(wa,wb);
		ans+=tmp*2*cc;
		wa-=tmp,wb-=tmp;
	}
	ans+=wa*ca+wb*cb;
	printf("%lld\n",min(res,ans));
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdbool.h>


typedef struct {
    int year, month, date;
} Date;

typedef struct {
    const char * name;
    Date begin_date;
} Era;


const Era ERAS[] = {
    {"meiji", {1868, 9, 8}},
    {"taisho", {1912, 7, 30}},
    {"showa", {1926, 12, 25}},
    {"heisei", {1989, 1, 8}}
};

const int ERAS_SIZE = sizeof(ERAS) / sizeof(Era);

const int ERA_PRE_MEIJI = -1;
const int ERA_MEIJI = 0;
const int ERA_TAISHO = 1;
const int ERA_SHOWA = 2;
const int ERA_HEISEI = 3;

const int ERA_BEGIN_YEAR[] = {1868, 1912, 1926, 1989}; 
const int ERA_BEGIN_MONTH[] = {9, 7, 12, 1};
const int ERA_BEGIN_DATE[] = {8, 30, 25, 8};

int compare_date(Date d1, Date d2); 
const Era* era_of_date(Date date);
void print_date(const Era *era, Date date);

int main()
{
    int year, month, day;
    while (scanf("%d%d%d", &year, &month, &day) != EOF) {
        const Date date = {year, month, day}; //ここにconstをつけてるのは完全に趣味です
        const Era *era = era_of_date(date);   //ここにconstをつけてるのは趣味じゃありません
        print_date(era, date);
    }

    return 0;
}


// d1 と d2 を比較し、前者が早ければ負、後者が早ければ正、同じなら0を返す
// ポインタ渡しのほうがいいかな？
int compare_date(Date d1, Date d2)
{

    if (d1.year < d2.year) {
        return -1;
    } else if (d1.year > d2.year) {
        return 1;
    }

    //以下、年が同じである場合
    if (d1.month < d2.month) {
        return -1;
    } else if (d1.month > d2.month) {
        return 1;
    }

    //以下、年と月が同じである場合
    if (d1.date < d2.date) {
        return -1;
    } else if (d1.date > d2.date) {
        return 1;
    }

    //同じ日付である場合
    return 0;
}

//pre-meijiを特別扱いする方法は結構悩ましい
//ここではpre_meijiならNULLを返すことにする
//bool era_of_date(Era *era, Date date); ともいいと思う
const Era* era_of_date(Date date)
{
    //元号の線形探索を行う
    //平成から順に比較したほうがpre-meijiの処理が綺麗になる
    for (int era_index = ERAS_SIZE - 1; era_index >= 0; era_index--) {
        const int compare_result = compare_date(ERAS[era_index].begin_date, date); //ここにconstをつけてるのは完全に趣味です
        if (compare_result <= 0) {
            return &ERAS[era_index]; //ポインタ演算は邪悪だと思うけど
        }
    }

    return NULL;
}

//正直ここでnullを渡すとpre-meijiになるという仕様は気持ち悪い
//すべては代数的データ構造のないCが悪い
void print_date(const Era *era, Date date)
{
    if (era == NULL) {
        printf("pre-meiji\n");
        return;
    }

    const int era_begin_year = era->begin_date.year;  //ここらへんにconstをつけてるのは完全に趣味です
    const int era_year = date.year - era_begin_year + 1;

    printf("%s %d %d %d\n", 
            era->name,
            era_year, date.month, date.date
          );
}

Measured memory_bytes: 1036
def solve():
    N = int(raw_input())
    ret = 0
    for i in range(2, int(N**0.5 + 1)):
        if N % i == 0:
            inv_i = N//i
            if N % (inv_i - 1) == N / (inv_i - 1):
                ret += inv_i - 1
    if N > 2:
        ret += N -1
    print str(ret)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 29420
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

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

	long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] x = new long[n];
		long[] y = new long[m];
		for (int i = 0; i < n; ++i) {
			x[i] = sc.nextLong();
		}
		for (int i = 0; i < m; ++i) {
			y[i] = sc.nextLong();
		}
		System.out.println(cnt(x) * cnt(y) % MODULO);

	}

	long cnt(long[] arr) {
		int n = arr.length;
		long ret = 0;
		for (int i = 0; i < arr.length; ++i) {
			ret = ret + arr[i] * (-(n - 1 - i) + i) % MODULO;
			ret %= MODULO;
		}
		return ret;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 92028
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int a,b,c;

main(){
	cin>>a>>b>>c;
	dump(max({c-(a-b),0ll}));
}

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

s = []

min_Ai, *_, max_Ai = sorted(range(N), key=lambda x: A[x])
min_A, max_A = A[min_Ai], A[max_Ai]
if abs(min_A) < abs(max_A):
    for i in range(N):
        if i == max_Ai:
            continue
        A[i] += max_A
        s.append((max_Ai, i))
    A[max_Ai] += max_A
    s.append((max_Ai, max_Ai))
    # print(A)
    for i in range(N-1):
        if A[i] > A[i+1]:
            A[i+1] += A[i]
            s.append((i, i+1))
else:
    for i in range(N):
        if i == min_Ai:
            continue
        A[i] += min_A
        s.append((min_Ai, i))
    A[min_Ai] += min_A
    s.append((min_Ai, min_Ai))
    # print(A)
    for i in range(N-2, -1, -1):
        if A[i] > A[i+1]:
            A[i] += A[i+1]
            s.append((i+1, i))

print(len(s))
for a, b in s:
    print(a+1, b+1)


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

int main(){
    int N,K; cin>>N>>K;
    vector<int> l(N,0);
    for(int i=0;i<N;i++){
        cin>>l[i];
    }
    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    int ans=0;
    for(int i=0;i<K;i++){
        ans=ans+l[i];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
  ll n;
  cin >> n;
  vector<char>s(n);
  for(ll i=0;i<n;i++){
    cin >> s[i];
  }
  ll ans=0;
  for(ll i=0;i<n-2;i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
function main()
	N,M=map(x->parse(Int,x),split(readline()))
	D=ones(Int,N,N)*1145141919810
	for i=1:N D[i,i]=0 end
	E=Tuple{Int,Int,Int}[]
	for s=readlines()
		a,b,c=map(x->parse(Int,x),split(s))
		push!(E,(a,b,c))
		D[a,b]=D[b,a]=c
	end
	for k=1:N,i=1:N,j=1:N
		D[i,j]=min(D[i,j],D[i,k]+D[k,j])
	end
	println(sum(!any(D[s,a]+c==D[s,b] for s=1:N) for (a,b,c)=E))
end
main()


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

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

using namespace std;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	printf("%d\n",n*(n-1)/2+m*(m-1)/2);
	return 0;
}


Measured memory_bytes: 256
K, A, B = map(int, input().split())

if B <= A + 2:
    print(K+1)
    exit()

if K <= A:
    print(K+1)
    exit()

x = (K-(A+1)) // 2
y = (K-(A+1)) % 2
print(B + x * (B-A) + y)

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{   /*
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout); /**/
    int n, m;
    cin >> n >> m;
    int ans = (1 << m);
    ans *= 1900 * m + 100 * (n - m);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;

bool isPrime(int n){
	if(n<=1 || n%2==0&&n!=2)return false;
	for(int i=2;i*i<=n;i++)if(n%i==0)return false;
	return true;
}
vector<int> primes(int n){
	vector<int> res;
	while(res.size()<100){
		n++;
		if(isPrime(n))res.push_back(n);
	}
	return res;
}

struct A{
	int sum,n,i;
	A(){}
	A(int a,int b,int c):sum(a),n(b),i(c){}
	bool operator<(const A &a)const{return sum<a.sum;}
};
int main(){
	int n,p;
	while(cin>>n>>p,~n&&~p){
		multiset<A> ms;
		vector<int> v=primes(n);
		int ans=-1;
		ms.insert(A(0,0,0));
		while(1){
			A a=*ms.begin();
			ms.erase(ms.begin());
			if(a.n==2){
				if(--p==0){
					ans=a.sum;
					break;
				}
			}else{
				for(int i=a.i;i<v.size();i++){
					ms.insert(A(a.sum+v[i],a.n+1,i));
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int a, b, n;
    cin >> a >> b;
    if (b <= 9) n = 10 * a + b;
    else if (b <= 99) n = 100 * a + b;
    else n = 1000 * a + b;
    bool f = 0;
    for (int i = 1; i <= 330; i++) {
        if (n == i * i) f = 1;
    }
    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

int main()
{
    double a,b,c;
    int a1,b1;
    cin>>a>>b;
    a1 = a;
    b1 = b;
    cout<<(a1/b1)<<' '<<(a1%b1)<<' ';
    printf ("%0.6lf\n",(a/b));
    return 0;

}



Measured memory_bytes: 3280
#include<stdio.h>


int main()
{
	int n, x, N, i, j, k;

	
        while(1){
            scanf("%d %d", &n, &x);
            if(n==0 && x==0){
                  break;
            }
	N = 0;

	for (i = 1; i<n - 1; i++) {
		for (j = i + 1; j<n; j++) {
			for (k = j + 1; k<n + 1; k++) {
				if (i + j + k == x)
					N = N + 1;
			}
		}
	}
	printf("%d\n", N);

    }
    return 0;
}

Measured memory_bytes: 1820
from collections import defaultdict
n,k= map(int, input().split()) 
a = list(map(int, input().split()))
# n = int(input())
# a = [int(input()) for _ in range(n)]

ans = 1
c = set()
c.add(1)
for i in range(k):
    ans = a[ans-1]
    if ans in c:
        break
    else:
        c.add(ans)
count = 0
tmp=1
for i in range(k):
    tmp = a[tmp-1]
    if tmp == ans:
        val = i +1
        break
k = k - val
if (len(c)- val) == 0:
    s = k % len(c)
else:
    s = k % (len(c) - val)

for i in range(s):
    tmp = a[tmp-1]

print(tmp)




Measured memory_bytes: 33912
#include<bits/stdc++.h>
using namespace std;
#define maxn 55
#define int long long
int n,m,w,ans,a[maxn],f[maxn][maxn * maxn];
signed main(){
//	freopen("date.in","r",stdin);
//	freopen("date.out","w",stdout);
	f[0][0] = 1;
	scanf("%lld%lld",&n,&m);
	for(int i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
		w += a[i];
	}
	for(int i = 1; i <= n; i++){
		for(int j = i; j >= 1; j--){
			for(int k = w; k >= a[i]; k--){
				f[j][k] += f[j - 1][k - a[i]];
			}
		}
	}
	for(int i = 1; i <= n; i++){
		ans += f[i][i * m];
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 4960
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	int n=1;
	cin >> n;
	string s = "";
	cin >> s;

	if (n % 2 == 1) {
		cout << "No";
		return 0;
	}

	for (int i = 0; i < n / 2; i++) {
		if (s[i] != s[i + n/2]) {
			cout << "No";
			return 0;
		}
	}

	cout << "Yes";

	return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> // swap
using namespace std;

int h, w, n;
char TS[40][40];
char T[40][40];

void rakka() {
  for (auto i=h-2; i>=0; i--) {
    for (auto j=0; j<w; j++) {
      if (T[i][j] != '.') {
	int temp = 1;
	for ( ; i+temp < h && T[i+temp][j]=='.'; temp++) {
	}
	swap(T[i][j], T[i+temp-1][j]);
      }
    }
  }  
}

const int D[2][2] = { {0,1}, {1,0} };

int kesu() { // 消した数を返す。
  bool E[40][40]; // 消すものを一旦ここにチェック。
  int ans = 0;
  fill(&E[0][0], &E[0][0]+40*40, false);
  for (auto i=0; i<h; i++) {
    for (auto j=0; j<w; j++) {
      if (T[i][j] == '.') continue;
      for (auto k=0; k<2; k++) {
	if ( i+(n-1)*D[k][0] >= h || j+(n-1)*D[k][1] >= w ) continue;
	for (auto l=1; l<n; l++) {
	  if (T[i][j] != T[i+l*D[k][0]][j+l*D[k][1]]) goto EXIT;
	}
	// この場合消えるのでチェック。
	for (auto l=0; l<n; l++) {
	  E[i+l*D[k][0]][j+l*D[k][1]] = true;
	}
      EXIT: continue;
      }
    }
  }
  for (auto i=0; i<h; i++) {
    for (auto j=0; j<w; j++) {
      if (E[i][j]) {
	T[i][j] = '.';
	ans++;
      }
    }
  }
  return ans;
}

void reset() {
  for (auto i=0; i<h; i++) {
    for (auto j=0; j<w; j++) {
      T[i][j] = TS[i][j];
    }
  }
}

void show() {
  for (auto i=0; i<h; i++) {
    for (auto j=0; j<w; j++) {
      cout << T[i][j];
    }
    cout << endl;
  }
}

int main() {
  string S;
  cin >> h >> w >> n;
  int num = 0; // ブロックの数。
  for (auto i=0; i<h; i++) {
    cin >> S;
    for (auto j=0; j<w; j++) {
      TS[i][j] = S[j];
      if (TS[i][j] != '.') num++;
    }
  }
  for (auto i=0; i<h; i++) {
    for (auto j=0; j<w-1; j++) {
      reset();
      if (T[i][j] == T[i][j+1]) continue;
      swap(T[i][j], T[i][j+1]);
      rakka();
      int sum = 0;
      int temp;
      while ((temp = kesu()) > 0) {
	// cerr << "erase " << temp << " blocks at (" << i << "," << j << ")" << endl;
	// if (i == 4 && j == 1) show();
	sum += temp;
	if (sum == num) goto SUCCESS;
	rakka();
	// if (i == 4 && j == 1) show();
      }
    }
  }
  cout << "NO" << endl; return 0;
 SUCCESS: cout << "YES" << endl; return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int k_list[20000] = {0};

int main(){
	int N,X,Y;
	cin>>N>>X>>Y;

	for(int i = 1; i <= N-1; i++){
		for(int j = i+1; j <= N; j++){

			int distance1 = j - i;
			
			int distance2_X = abs(i - X);
			int distance2_Y = abs(i - Y);
			int distance2 = -1;
			if(distance2_X < distance2_Y){
				distance2 = distance2_X + 1 + abs(j-Y);
			}
			else{
				distance2 = distance2_Y + 1 + abs(j-X);
			}

			int short_distance = min(distance2,distance1);
			k_list[short_distance] += 1;
		}
	}

	for(int i = 1; i < N; i++){
		cout<<k_list[i]<<endl;
	}
	return 0;

}



Measured memory_bytes: 256
N = int(input())
*A, = map(int, input().split())

count = dict()
if N % 2:
	for a in A:
		if a % 2:
			print(0)
			exit()
		if a in count:
			count[a] += 1
		else:
			count[a] = 1
	if count[0] != 1:
		print(0)
		exit()
	del count[0]
	for c in count.values():
		if c != 2:
			print(0)
			exit()
else:
	for a in A:
		if not(a % 2):
			print(0)
			exit()
		if a in count:
			count[a] += 1
		else:
			count[a] = 1
	for c in count.values():
		if c != 2:
			print(0)
			exit()

mod = 10**9+7
print(2**(N//2) % mod)


Measured memory_bytes: 14436
from copy import *
import sys
S=sys.stdin.readlines()

def init(N,node,unit,func):
  n=1
  while n<N:
    n<<=1
  for i in range(n*2-1):
    if len(node)<=i:
      node.append(deepcopy(unit))
    else:
      node[i]=deepcopy(unit)
  node.append(func)
  node.append(unit)
  node.append(n)

def upd(node,x,a):
  y=node[-1]+x
  node[y-1]=a
  while y>1:
    y=y>>1
    node[y-1]=node[-3](node[(y<<1)-1],node[y<<1])

def query(node,l,r):
  x,y=l,r
  z=node[-1]-1
  r=node[-2]
  while True:
    if x==y:
      return r
    if x&1:
      r=node[-3](r,node[x+z])
      x+=1
    if y&1:
      r=node[-3](r,node[y+z-1])
    x>>=1
    y>>=1
    z>>=1
    if z==0:
      return r

def bis_min_k(node,k,cond):
  x=k+1
  while True:
    if node[-1]<=x:
      return x-node[-1]
    if cond(node[(x<<1)-1]):
      x=x<<1
    else:
      x=(x<<1)+1

def bis_min(node,l,r,cond):
  x,y=l,r
  z=node[-1]-1
  for i in range(30):
    if x+(1<<i)>y:
      break
    if x&(1<<i):
      if cond(node[z+(x>>i)]):
        return bis_min_k(node,z+(x>>i),cond)
      x+=(1<<i)
    if z==0:
      break
    z>>=1
  for i in range(29,-1,-1):
    if i and ((node[-1]-1)>>(i-1))==0:
      continue
    if x+(1<<i)>y:
      continue
    if (y-x)&(1<<i):
      if cond(node[((node[-1]-1)>>i)+(x>>i)]):
        return bis_min_k(node,((node[-1]-1)>>i)+(x>>i),cond)
      x+=(1<<i)
  return node[-1]

N,Q=map(int,S[0].split())
A=list(map(int,S[1].split()))
X=[]
init(N+1,X,-1,lambda x,y:max(x,y))
for i in range(N):
  upd(X,i,A[i])
t,a,b=0,0,0
for i in range(Q):
  t,a,b=map(int,S[i+2].split())
  if t==1:
    upd(X,a-1,b)
  elif t==2:
    print(query(X,a-1,b))
  else:
    a=bis_min(X,a-1,N,lambda x:b<=x)
    if a>N:
      print(N+1)
    else:
      print(a+1)


Measured memory_bytes: 157632
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

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

int main() {
  int N;
  cin >> N;
  if(N%2==0) cout << N << endl;
  else cout << N*2 << endl;

}


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

int main() {
    string s;
    int64_t k;
    cin >> s >> k;
    int r = 0;
    char c = '1';
    rep(i,s.size()) {
        if (s[i] == '1') r++;
        else {
            c = s[i];
            break;
        }
    }
    char ans = '1';
    if (r < k) ans = c; 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[69];
int  main(){
	int n,k,ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=n-1;i>=n-k;i--){
		ans+=a[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

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

dp = None

def main():
    N = int(input())

    ans = 0
    for i in range(math.ceil(N**0.5), 0, -1):
        if i * i <= N:
            ans = i * i
            break

    print(ans)

main()


Measured memory_bytes: 4928
require 'prime'

def phi(n)
  return 1 if n == 1
  Prime.each(n - 1) do |p|
    next unless n % p == 0
    b = n
    j = 0
    while b % p == 0
      b /= p
      j += 1
    end
    return p**(j - 1) * (p - 1) * phi(b)
  end
  n - 1
end
input = gets.to_i

puts phi(input)


Measured memory_bytes: 84680