akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long N = scn.nextInt();
		long K = scn.nextInt();
		long num_k = N/K;
		long num_k_2 = (K%2 == 0)?(N + K/2)/K:0;
		long ans = num_k * num_k * num_k;
		ans += num_k_2* num_k_2 * num_k_2;
		System.out.println(ans);
	}

}


Measured memory_bytes: 23252
N = int(raw_input())
S = str(raw_input())
opt_num = 0
dict = {}
dict2 = {}
for i in range(N-1):
    first = S[:i+1]
    latter = S[i+1:]
    for l in S:
        dict[l] = 0
    dict2 = {}
    cnt = 0
    for f in first:
        dict[f] = 1
    for l in latter:
        if dict[l]:
            dict2[l] = 1
    if opt_num < len(dict2):
        opt_num = len(dict2)
print(opt_num)


Measured memory_bytes: 2568
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

int main()
{
	int N;
	cin >> N;
	vector<int> h(N + 1);
	rep(i, N) {
		cin >> h[i + 1];
	}
	vector<int> dp(N + 1);
	rep1(i, N) {
		if (i > 2)
			dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
		else if (i > 1)
			dp[i] = abs(h[i] - h[i - 1]);
	}
	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 1024
N, K = map(int, input().split())
X = list(map(int, input().split()))

MOD = 10 ** 9 + 7

if K % 2 == 1 and all(v < 0 for v in X):
    # Minimize abs
    X.sort(key=lambda x: -x)
    ans = 1
    for i in range(K):
        ans = ans * X[i] % MOD
    print(ans)
elif K == N:
    ans = 1
    for i in range(K):
        ans = ans * X[i] % MOD
    print(ans)
else:
    pos = sorted(v for v in X if v >= 0)
    neg = sorted(-v for v in X if v < 0)

    ans = 1
    if K % 2 == 1:
        ans *= pos.pop()

    cand = []
    while len(pos) >= 2:
        tmp = pos.pop() * pos.pop()
        cand.append(tmp)

    while len(neg) >= 2:
        tmp = neg.pop() * neg.pop()
        cand.append(tmp)

    cand.sort(reverse=True)
    for i in range(K // 2):
        ans = ans * cand[i] % MOD

    print(ans)


Measured memory_bytes: 114412
"""素数を求める。

以下の性質を用いる。
合成数 x は p <= sqrt(x) を満たす素因子 pをもつ。
"""

import math


def is_prime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    for i in range(3, math.floor(math.sqrt(x)) + 1):
        if x % i == 0:
            return False
    return True


N = int(input())
data = [int(input()) for i in range(N)]
cnt = 0
for d in data:
    if is_prime(d):
        cnt += 1
print(cnt)



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

# In[17]:


from sys import stdin
input = stdin.readline

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


# In[18]:


class Node:
    def __init__(self, nb, data): #コンストラクタ
        self.nb = nb
        self.data = data #ノードがもつ数値
        self.parent = -1 # nodeがrootのとき-1、それ以外番号
        #self.childs = [] # childになるnode classが入る
        
    #def connect_childs(self, child_class_):
    #    self.childs.append(child_class_)


# In[19]:


nodes = [Node(_+1, 0) for _ in range(N)]


# In[12]:


for i in range(N-1):
    a, b = map(int, input().split())
    #nodes[a-1].connect_childs(nodes[b-1])
    nodes[b-1].parent = a-1


# In[13]:


for i in range(Q):
    p, x = map(int, input().split())
    nodes[p-1].data += x


# In[14]:


def sum_data_to_childs(nodes):
    datas = [0]*N
    
    datas[0] = nodes[0].data
    
    for i in range(1, N):
        nodes[i].data += nodes[nodes[i].parent].data
        #print(nodes[i].data)
        datas[i] = nodes[i].data
        
    return datas


# In[15]:


datas = sum_data_to_childs(nodes)


# In[16]:


print(' '.join(map(str, datas)))


# In[20]:


#datas = [0] * N


# In[21]:


#child = [[]] * N


# In[22]:


#print(child)


# In[ ]:






Measured memory_bytes: 76476
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  while(A > 0 && C > 0) {
    C -= B;
    A -= D;
  }
  
  if(A > 0) cout << "Yes" << endl;
  else if(A <= 0 && C <= 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define ll long long int
#define repeat(n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()

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

    int mabs = 178;
    for (int i = 1; i <= mabs; ++i) {
        if (x % i != 0) continue;
        for (int a = -mabs; a <= mabs; ++a) {
            for (int b = i - a; b <= mabs && b >= -mabs; ++b) {
                if (a * a * a * a * a - b * b * b * b * b == x) {
                    cout << a << " " << b;
                    return 0;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3508
line = gets.split('').map(&:to_i)
t = 0
k = line.size - 1

#puts line[4]
k.times do |i|
  if line[i] == 1
    t += 1
  end
#  puts "#{i},#{t}"
end

t_counter = k-t
if t > t_counter then
  u = t - t_counter
else
  u = t_counter - t
end

puts k-u


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

int main() {
  int64_t n,m,x;
  cin >> n >> m >> x;

  int h = 0;
  int l =0;
  vector<int> a(m);
  for (int i=0;i<m;i++){
    cin >> a.at(i);
    if (a.at(i) > x){
      h++;
    }else{
      l++;
    };
  }
  int ans = min(h,l);
    cout << ans << endl;
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int main(){
  ll n; cin>>n;
  string ans = "";
  char add = 'a';
  while(n){
      n--;
      char now = add + (n%26);
      ans = now+ans;
      n /= 26;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 5e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
int a,b,c,d;
void work(){
    scanf("%d%d%d%d",&a,&b,&c,&d);
    int yes=1;
    while(a>0&&c>0){
        if(yes){
            c-=b;
        }
        else{
            a-=d;
        }
        yes=1-yes;
    }
    if(a<=0) printf("No\n");
    else printf("Yes\n");
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}









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

#include <iostream>
using namespace std;
int main() {
  int c[3][3];
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> c[i][j];
    }
  }

  bool result = false;
  int a2, a3, b1, b2, b3;
  for (int a1 = 0; a1 < 100; ++a1) {
    b1 = c[0][0] - a1;
    b2 = c[0][1] - a1;
    b3 = c[0][2] - a1;
    a2 = c[1][0] - b1;
    a3 = c[2][0] - b1;
    if (c[1][1] == a2 + b2 && c[2][1] == a3 + b2 && c[1][2] == a2 + b3 &&
        c[2][2] == a3 + b3) {
      result = true;
    }
  }

  if (result) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
V = get_ints

odds = V.filter.with_index { |v, i| i % 2 == 1 }
evens = V.filter.with_index { |v, i| i % 2 == 0 }

ans = 0

odds_hash = Hash.new { |h, k| h[k] = 0 }

odds.each do |n|
  odds_hash[n] += 1
end

odds_sorted_hash = odds_hash.sort { |a, b| a[1] <=> b[1] }

events_hash = Hash.new { |h, k| h[k] = 0 }

evens.each do |n|
  events_hash[n] += 1
end

evens_sorted_hash = events_hash.sort { |a, b| a[1] <=> b[1] }

odd_ans = odds_sorted_hash.pop
even_ans = evens_sorted_hash.pop

if odd_ans[0] == even_ans[0]
  o = odds_sorted_hash.pop
  e = evens_sorted_hash.pop

  if o.nil?
    even_ans = [0, 0]
  elsif o[1] > e[1]
    odd_ans = o
  else
    even_ans = e
  end
end

puts odds.length - odd_ans[1] + evens.length - even_ans[1]


Measured memory_bytes: 27180
import sys
input = sys.stdin.readline

import copy

def main(): 

    N, K = map(int,input().split())
    S=input().split()
    S=list(S[0])

    list_01 = []
    now=1
    count=0
    for i in range(N):
        if int(S[i]) != now:
            list_01.append(count)
            now=1-now
            count=1
        else:
            count+=1
    if count != 0: list_01.append(count)
    if len(list_01)%2==0: list_01.append(0)
    
    Add = 2*K+1
    left = 0
    right = 0
    ans=0
    i=0
    tmp = 0
    while i < len(list_01):
        nextleft = i
        nextright = min(i+Add,len(list_01))

        while left < nextleft:
            tmp-=list_01[left]
            left+=1
        while right < nextright:
            tmp+=list_01[right]
            right+=1
        ans=max(tmp,ans)
        i+=2
    print(ans)
if __name__ == "__main__":
    main()
    

Measured memory_bytes: 5176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int n,m,a[200002],v[200002],vis[200002];
int main() {
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) {
	scanf("%d",&a[i]);
	v[a[i]]++;
    }
    for (int i=1;i<=n;i++)
	for (int j=i;j>=i-v[i]+1&&j>=1;j--) vis[j]++;
    int ans=0;
    for (int i=1;i<=n;i++) if (vis[i]==0) ans++;
    for (int i=1;i<=m;i++) {
	int x,y;
	scanf("%d%d",&x,&y);
	if (a[x]-v[a[x]]+1>0) {
	    vis[a[x]-v[a[x]]+1]--;
	    if (!vis[a[x]-v[a[x]]+1]) ans++;
	}
	v[a[x]]--;
	if (y-v[y]>0) {
	    vis[y-v[y]]++;
	    if (vis[y-v[y]]==1) ans--;
	}
	v[y]++;
	a[x]=y;
	printf("%d\n",ans);
    }
    return 0;
}	    


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

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main() {
  long n, m;
  cin >> n >> m;
  long a[m], b[m];
  UnionFind tree(n);
  
  for (long i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    tree.unite(a[i]-1, b[i]-1);
  }
  
  long cnt = 0;
  for (long i = 0; i < n; i++) {
    if (!tree.same(0, i)) {
      tree.unite(0, i);
      cnt++;
    }
  }
  
  cout << cnt;
  
  return 0;
}

Measured memory_bytes: 5192
import sys
sys.setrecursionlimit(10000)
n = int(input())
*A, = map(int, input().split())
A = [(a, i) for i, a in enumerate(A)]
A.sort(reverse=True)
DP = [[None for r in range(n+1)] for l in range(n+1)]

def dp(l, r):
    if l == r:
        DP[l][r] = 0
    if DP[l][r] != None:
        return DP[l][r]
    a, i = A[n-(r-l)]
    x = dp(l+1, r)+a*abs(i-l)
    y = dp(l, r-1)+a*abs(i-(r-1))
    DP[l][r] = max(x, y)
    return DP[l][r]

print(dp(0, n))

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

int main() {

  long long int n;
  cin >> n;

  long long int ans = 0;
  long long int cnt = 0;
  long long int co = -1;

  for ( long long int i = 0; i <= n; i++ ) {

    long long int in;
    if ( i < n ) {
      cin >> in;
    } else {
      in = -1;
    }

    if ( in == co ) {
      cnt++;
    } else {
      ans += cnt / 2;
      cnt = 1;
      co = in;
    }

  }

  cout << ans << endl;

  return 0;

}


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

int main() {
  int x,a,b;
  cin >> x >> a >> b;
  
  if((x - a)*(x - a) > (x - b)*(x - b)){
    cout << "B" << endl;
  }
  
  else{
    cout << "A" << endl;
  }
}


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

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

  vector<int> P(N), Q(N);
  for(int i = 0; i < N; i++){
    cin >> P[i];
  }
  for(int i = 0; i < N; i++){
    cin >> Q[i];
  }

  vector<int> perm(N);
  for(int i = 1; i <= N; i++){
    perm[i - 1] = i;
  }

  int i = 0, p_num, q_num;
  do{
    if(perm == P){
      p_num = i;
    }
    if(perm == Q){
      q_num = i;
    }
    i++;
  }while(next_permutation(perm.begin(), perm.end()));

  cout << abs(p_num - q_num) << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    long mod = 1000000000+7;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    long solve(){
        // it's all about implementation
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt();
        if(k>(n-1)*(n-2)/2) return -1;
        int m = n-1,diff = (n-1)*(n-2)/2-k;
        m += diff;
        out.println(m);
        // first print the star, setting "1" as the center
        for(int i=2;i<=n;i++) out.println(String.format("%d %d",1,i));
        // then connect the resulting map diff times
        while(diff>0){
            for(int i=2;i<n&&diff>0;i++){
                for(int j=i+1;j<=n&&diff>0;j++){
                    out.println(String.format("%d %d",i,j));
                    diff--;
                }
            }
        }
        out.flush();
        System.exit(0);
        return -1;
    }
}



Measured memory_bytes: 30368
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
#include <random>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<bool> vbool;
typedef vector<string> vstr;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
template <typename _Ty> _Ty ipow(_Ty x, _Ty n) { _Ty ret = _Ty(1); for (_Ty i = _Ty(0); i < n; i++) ret *= x; return ret; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false




int main()
{
	//clock_t start, end;
	//start = clock();

	ll N, H;
	vector<ll> vec;
	vec.push_back(INT64_MAX);
	cin >> N >> H;

	ll maxa = 0, sumb = 0;
	for (int i = 0; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		vec.push_back(b);

		maxa = max(maxa, a);
		sumb += b;
	}

	sort(all(vec), greater<ll>());
	// z 個投げるといくつダメージを与えられるか？
	for (int i = 1; i < vec.size() - 1; i++) {
		vec[i + 1] += vec[i];
	}
	//cout << vec << endl;

	ll ans = INT64_MAX;
	for (int i = 1; i < vec.size(); i++) {
		ll HPrem = max(0LL, H - vec[i]);
		ll x = (HPrem + maxa - 1) / maxa;
		ans = min(ans, i + x);
	}
	cout << ans << endl;

	//end = clock();
	//printf("%d msec.\n", end - start);
}


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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> a(26,0);
    for(char c : s){
        a[c - 'a']++;
    }

    int k = -1;
    rep(i,26){
        if(a[i] == 0){
            k = i;
            break;
        }
    }
    if(k == -1) cout << "None" << endl;
    else {
        char ans = 'a'+k;
        cout << ans << endl;
    }
}

Measured memory_bytes: 512
import itertools
N, M, Q = map(int, input().split())
info = []
for _ in range(Q):
    a, b, c, d = map(int, input().split())
    info.append((a, b, c, d))

num = [i for i in range(1, M+1)]
# print(num)
ans = 0

for v in itertools.combinations_with_replacement(num, N):
    # print(v)
    vsum = 0
    for i in range(Q):
        # print(info[i][0], info[i][1], info[i][2], info[i][3])
        if v[info[i][1]-1] - v[info[i][0]-1] == info[i][2]:
            vsum += info[i][3]
    # print(vsum)
    ans = max(ans, vsum)

print(ans)


Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    int A[N];
    int L;
    int sum=0,ans=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        sum+=A[i];
    }
    for(int i=0; i<N; i++){
        if(A[i]*4*M>=sum){
            ans++;
        }
    }
    if(ans>=M){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
import sys
x = int(input())
i = 2
INF = 100000000
while (i <= x):
    if (x%i == 0 and x != i):
        break
    if (x % i == 0 and x == i):
        print(x)
        sys.exit()
    i += 1

while (x < INF):
    i = 2
    while(i <= x):
        if (i % 2 == 0):
            i += 1
            continue

        if (x % 2 == 0):
            x += 1
            continue

        if (x % i == 0 and x != i):
            x += 1
            break

        if (x % i == 0 and x == i):
            print(x)
            sys.exit()

        else:
            i += 2

    x += 1

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define rev(r) reverse(r.begin(),r.end())
#define SORT(ar) sort(ar.begin(), ar.end())
#define sz(x) (int)(x).size()
#define len(x) (int)x.length()
#define in(a) scanf("%d",&a)
#define pr(x) printf("%d ",x)
#define endl '\n'
#define read(v,n) for(int h=0;h<n;h++) cin>>v[h];
#define fo(i,a,b) for(i=a;i<b;i++)
#define fi(i,a,b) for(i=a;i>=b;i--)
#define mo 1000000007
#define N 200007
ll a[50][50],res[50][50],t[50][50],n,k;

void multi(ll c[50][50], ll b[50][50])
{
    int i,j,r;
    fo(i,0,n)
    {
        fo(j,0,n)
        {
            t[i][j]=0;
            fo(r,0,n)
            {
                t[i][j]=(t[i][j] + ((c[i][r])*(b[r][j]))%mo)%mo;
            }
        }
    }
    fo(i,0,n)
    {
        fo(j,0,n) c[i][j]=t[i][j];
    }
}

void power()
{
    int i,j,r;
    fo(i,0,n) res[i][i]=1;
    while (k > 0)
    {
       if (k & (1ll)){
            multi(res,a);
       }
        k = k>>(1ll);
        multi(a,a);
    }
}

int main()
{
    ll i,j,x,y,ans=0;
    cin>>n>>k;
    fo(i,0,n)
    {
        fo(j,0,n) cin>>a[i][j];
    }
    power();
    fo(i,0,n)
    {
        fo(j,0,n) ans=(ans + res[i][j])%mo;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3688
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;
typedef long long ll;

constexpr ll MOD = 1e9 + 7;

ll calc_pow(ll x, ll pow) {
    if (pow == 0) return 1;
    ll a = calc_pow(x, pow / 2);
    a = a * a % MOD;
    if (pow % 2 == 1) a *= x;
    return a % MOD;
}

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

    ll zero = 0;
    ll x = 0, y = 0;
    map<pair<ll, ll>, int> ma;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        if (a == 0 && b == 0)zero++;
        else if (a == 0)x++;
        else if (b == 0)y++;
        else {
            ll GCD = __gcd(abs(a), abs(b));
            a /= GCD, b /= GCD;
            if (a < 0)a *= -1, b *= -1;
            ma[{a, b}]++;
        }
    }

    ll ret = 1;
    for (auto now:ma) {
        ll partner = 0;
        if (now.first.second > 0) {
            if (ma.find({now.first.second, -now.first.first}) != ma.end()) {
                partner = ma[{now.first.second, -now.first.first}];
            }
        } else {
            if (ma.find({-now.first.second, now.first.first}) != ma.end()) {
                partner = ma[{-now.first.second, now.first.first}];
            }
        }

        if (now.first.second > 0 || partner == 0) {
            ret *= calc_pow(2, now.second) + calc_pow(2, partner) - 1;
            ret %= MOD;
        }
    }
    ret *= calc_pow(2, x) + calc_pow(2, y) - 1, ret %= MOD;

    cout << (ret + zero + MOD * 100 - 1) % MOD << endl;
    return 0;
}

Measured memory_bytes: 15992
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
typedef pair<ll, ll> pint;

const int MOD = 1000000007;
void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }
}

int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i, N) {
        cin >> A[i];
    }

    ll ans = 0;
    map<ll, ll> m;
    map<ll, ll> m2;
    rep(i, N) {
        ll now = i+1 - A[i];
//        cout << m[now] << endl;
        ans += m[now];

        now = i + 1+ A[i];
//        cout << ans << endl;
        m[now] += 1;

//        cout << m[now] << endl;
    }
////
//    for (int i = N-1; i >= 0; i--) {
//        ll now = A[i] + i;
//        if (m2.find(now) != m2.end() ) {
//            cout << m2[now] << " " << i << endl;
//            ans += m2[now];
//        }
//        now = i - A[i];
//        if (m2.find(now) != m2.end() ) {
//            m2[now] += 1;
//        } else{
//            m2[now] = 1;
//        }
//    }

    cout << ans << endl;


}

Measured memory_bytes: 27024
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::*;
use std::ops::*;
use std::*;

// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused)]
fn rl() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused)]
fn rw<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|word| T::from_str(word).unwrap())
        .collect()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

#[allow(unused)]
macro_rules! debug {
    ($($arg:expr),*) => {
        let entries = &[
            $((
                &stringify!($arg).to_string() as &fmt::Debug,
                &($arg) as &fmt::Debug,
            )),*
        ];
        eprintln!("{:?}", DebugMap(entries));
    };
}

#[allow(unused)]
struct DebugMap<'a>(&'a [(&'a fmt::Debug, &'a fmt::Debug)]);

impl<'a> std::fmt::Debug for DebugMap<'a> {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        let mut m = fmt.debug_map();
        for &(key, value) in self.0.iter() {
            m.entry(key, value);
        }
        m.finish()
    }
}

// -----------------------------------------------
// Polyfill
// -----------------------------------------------

#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

#[allow(unused)]
macro_rules! eprintln {
    ($($arg:expr),*) => { _eprintln(format_args!($($arg),*)) }
}

fn _eprintln(args: fmt::Arguments) {
    let err = std::io::stderr();
    let mut err = err.lock();
    err.write_fmt(args).unwrap();
    err.write(b"\n").unwrap();
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn main() {
    let N = rl().parse::<usize>().unwrap();
    let A = rw::<i32>();

    let mut min_cost = std::i32::MAX;
    for b in -100..100 + 1 {
        let mut s = 0;
        for a in A.iter().cloned() {
            s += (a - b).abs() * (a - b).abs();
        }
        min_cost = min(min_cost, s);
    }
    println!("{}", min_cost);
    return;
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_ok() {
        assert_eq!(7, 1 + 2 * 3);
    }
}


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

int n,L,a[200100],cntl,cntr;
long long ans,nw;

int main()
{
	scanf("%d%d",&L,&n);
	for (int i=1; i<=n; i++) scanf("%d",&a[i]);
	if (n==1) return printf("%d\n",max(a[1],L-a[1])),0;
	if (n==2) return printf("%lld\n",max(1ll*max(a[2],L-a[1]),a[1]+1ll*L-a[2]+max(a[1],L-a[2]))),0;
	ans=nw=L-a[1],cntr=0,cntl=n,a[0]=0,a[n+1]=L;
	for (int i=1; i<=n; i++)
	{
		if (cntr<cntl)
		{
			if (cntr==cntl-1) nw+=a[i]-(L-a[i]);
			else nw+=2ll*a[i]-(L-a[i])-(L-a[i+1])+2ll*(L-a[2*i+1])+2ll*(L-a[2*i]);
		} else nw+=a[i]+a[i-1]-2ll*a[n-(n-i)*2-1]-2ll*a[n-(n-i)*2-2]-2ll*(L-a[i]);
		cntr++,cntl--,ans=max(ans,nw);
		if (cntl==cntr) nw+=(L-a[i+1])-a[i],ans=max(ans,nw);
	}
	ans=max(ans,nw=a[1]+2ll*(L-a[2])),cntr=1,cntl=n-1;
	for (int i=2; i<n; i++)
	{
		if (cntr<cntl)
		{
			if (cntr==cntl-1) nw+=-2ll*(L-a[i])-(L-a[i+1])+2ll*a[i]+a[i-1]-2ll*a[1]+2ll*(L-a[n]);
			else nw+=a[i]+a[i-1]-2ll*(L-a[i])+2ll*(L-a[2*i-1])+2ll*(L-a[2*i]);
		} else nw+=2ll*a[i]-(L-a[i])-(L-a[i+1])-2ll*a[n-2*(n-i)]-2ll*a[n-2*(n-i)-1];
		cntr++,cntl--,ans=max(ans,nw);
		if (cntl==cntr) nw+=a[i]-(L-a[i+1]),ans=max(ans,nw);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill(name, val) memset(name, val, sizeof(name));
#define vll vector<ll>
#define vvll vector<vll>

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

ll n, dp[1001][10001];	vvll a(1001, vll(3));
bool cmp(vll& a, vll& b){
	return a[0] + a[1] < b[0] + b[1];
}
ll calc(ll i, ll w){
	if(i == n || w > 10000)	return 0;
	if(dp[i][w] != -1)	return dp[i][w];
	dp[i][w] = calc(i+1, w);
	if(a[i][1] >= w)	dp[i][w] = max(dp[i][w], a[i][2] + calc(i+1, w + a[i][0]));
	return dp[i][w];
}
int main(){
	cin>>n;	fill(dp, -1);
	for(ll i = 0; i < n; i++)	cin>>a[i][0]>>a[i][1]>>a[i][2];
	sort(a.begin(), a.begin() + n, cmp);
	cout<<calc(0, 0);
}

// Time: O()

Measured memory_bytes: 81932
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprev(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pc(c) putchar_unlocked(c)
typedef long long ll;

char arr[11];
int n;

// tは今まで登場した種類数
void dfs(int cou, int t)
{
  if (cou == n)
  {
    cout << arr << endl;
    return;
  }

  rep(i, t)
  {
    arr[cou] = 'a' + i;
    dfs(1 + cou, t);
  }
  // new!!初登場
  arr[cou] = 'a' + t;
  dfs(++cou, ++t);
}

int main()
{
  cin >> n;
  arr[n] = '\0';
  dfs(0, 0);
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<long long> a(N, 0LL), b(N, 0LL), c(M, 0LL), d(M, 0LL);
    for (int i = 0; i != N; ++i) cin >> a[i] >> b[i];
    for (int i = 0; i != M; ++i) cin >> c[i] >> d[i];
    for (int n = 0; n != N; ++n){
        long long dist = 1000000000;
        int ans = 0;
        for (int m = 0; m != M; ++m){
            long long tmp = abs(a[n] - c[m]) + abs(b[n] - d[m]);
            if (tmp < dist) {
                dist = tmp;
                ans = m;
            }
        }
        cout << ans + 1 <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

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

	private void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		int[] ball = new int[N];
		for (int i = 0; i < N; i++) {
			ball[i] = sc.nextInt();
		}
		Arrays.sort(ball);

		HashMap<Integer, LinkedList<Integer>> index = new HashMap<>();
		for (int i = 0; i < N; i++) {
			if (!index.containsKey(ball[i])) {
				index.put(ball[i], new LinkedList<Integer>());
			}
			index.get(ball[i]).add(i);
		}
		boolean[] used = new boolean[N];

		int p = 1;
		while (p <= ball[N - 1]) {
			p *= 2;
		}

		int i = N - 1;
		int pairs = 0;
		while (i >= 0 && p > 1) {
			while (i >= 0 && ball[i] >= (p / 2)) {
				int diff = p - ball[i];
				if (used[i] == false && index.containsKey(diff)) {
					LinkedList<Integer> l = index.get(diff);
					used[i] = true;
					if (l.peekLast() == i) {
						l.removeLast();
					}
					if (l.size() > 0) {
						used[l.removeLast()] = true;
						pairs++;
						if (l.isEmpty()) {
							index.remove(diff);
						}
					}
				}
				i--;
			}
			p = p / 2;
		}
		System.out.println(pairs);
		sc.close();
	}

}


Measured memory_bytes: 115060
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, W;
	cin >> N >> W;
	vector<int> w(N);
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	int res = 0;
	int INF = (int)1 << 50;
	vector<int> dp(W + 1, -INF);
	vector<int> ndp(W + 1);
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j + w[i] <= W; j++) {
			ndp[j + w[i]] = max(ndp[j + w[i]], dp[j] + v[i]);
		}

		dp = ndp;
	}
	for (int i = 0; i < dp.size(); i++) {
		res = max(res, dp[i]);
	}
	cout << res << endl;
}

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

int main()
{
  int n,m;
  double c;
  cin >> n >> m;
  vector<int> a(n);
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  double sum = 0;
  int counter = 0;
  for(int i = 0;i < n;i++){
    sum += a[i];
  }
  c = sum / (4*m);
  //cout << c << endl;
  for(int i = 0;i < n;i++){
    if(a[i] < c){
      counter += 0;
    }
    else{
      counter += 1;
    }
  }
  //cout << counter << endl;
  if(counter >= m){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s{a, b, c};
    cout << s.size() << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

N = int(input())
edge = [[] for _ in range(N)]
cnt = [[0,i] for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a)
    cnt[a][0] += 1
    cnt[b][0] += 1


cnt.sort(reverse=True)
start = cnt[0][1]
C = list(map(int, input().split()))
C.sort(reverse=True)
nodes = [0] * N

#print(nodes)
cidx = -1
ans = []
def dfs(v, pv, w):
    global cidx
    cidx += 1
    nodes[v] = C[cidx]
    ans.append(min(w, C[cidx]))
    for nv in edge[v]:
        if pv == nv: continue
        dfs(nv, v, C[cidx])

dfs(start, 0, 0)
print(sum(ans))
print(*nodes, sep=" ")


Measured memory_bytes: 201888
n = int(input())
p = list(map(int, input().split()))
ans = 0

for i in range(2, n):
    p1 = i - 2
    p2 = i - 1
    p3 = i
    if p[p1] <= p[p2] <= p[p3] or p[p1] >= p[p2] >= p[p3]:
        ans += 1

print(ans)

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello
{

    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        string ans = "error";
        if (int.Parse(s[0]) + int.Parse(s[1]) < 10) ans = (int.Parse(s[0]) + int.Parse(s[1])).ToString();
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {

		Scanner inScanner = new Scanner(System.in);

		 int n  = inScanner.nextInt();
		 
		 if (n==0) {
			System.out.println(1);
		}else if (n==1) {
			System.out.println(0);
		} 
		
		
		
	}

}

Measured memory_bytes: 35600
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayDeque;

public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        ArrayDeque<Integer> stack = new ArrayDeque<Integer>();
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < t.length; i++){
            if( t[i].equals("+") || t[i].equals("-") || t[i].equals("*") ){
                int ope1 = stack.pop();
                int ope2 = stack.pop();
                if(t[i].equals("+") ){
                    stack.push(ope1 + ope2);
                }else if(t[i].equals("-") ){
                    stack.push(ope2 - ope1);
                }else if(t[i].equals("*") ){
                    stack.push(ope1 * ope2);
                }
            }else{
                int ope = Integer.parseInt(t[i]);
                stack.push(ope);
            }
        }
        int ans = stack.pop();
        System.out.println(ans);
    }

}

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

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


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

  int n;
  long long C;
  cin >> n >> C;
  vector<long long> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  vector<long long> dp(n);
  vector<int> dq(n);
  int s = 0, t = 0;

  auto f = [&](int i, int x) {
    long long a = -2 * h[i];
    long long b = dp[i] + h[i] * h[i];
    return a * x + b;
  };

  auto cmp = [&](int f1, int f2, int f3) {
    long long a1 = -2 * h[f1], b1 = dp[f1] + h[f1] * h[f1];
    long long a2 = -2 * h[f2], b2 = dp[f2] + h[f2] * h[f2];
    long long a3 = -2 * h[f3], b3 = dp[f3] + h[f3] * h[f3];
    return (b1 - b2) * (a2 - a3) > (b2 - b3) * (a1 - a2);
  };

  for (int i = 1; i < n; i++) {
    while (t - s > 1 && cmp(dq[t - 1], dq[t - 2], i - 1)) t--;
    dq[t++] = i - 1;
    while (t - s > 1 && f(dq[s], h[i]) > f(dq[s + 1], h[i])) s++;
    dp[i] = f(dq[s], h[i]) + C + h[i] * h[i];
  }
  debug(dp);
  cout << dp[n - 1] << '\n';
  return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int i;

int main()
{
    string s;
    bool can = false;

    cin >> s;

    string rev_s = s;
    reverse(rev_s.begin(), rev_s.end());

    if (rev_s == s)
    {
        string t = s.substr(0, (s.size() - 1) / 2);
        string rev_t = t;
        reverse(begin(rev_t), end(rev_t));
        if (rev_t == t)
        {
            string u = s.substr((s.size() + 3 / 2 - 1));
            string rev_u = u;
            reverse(begin(rev_u), end(rev_u));
            if (rev_u == u)
            {
                can = true;
            }
        }
    }

    if (can == true)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
W = read().decode('utf8').split()
temp = W[0][-1]
Ws = set(W)
f = True
if len(Ws) != N:
    f = False

else:
    for w in W[1:]:
        if temp == w[0]:
            temp = w[-1]
        else:
            f = False
            break
print("Yes" if f else "No")


Measured memory_bytes: 3064
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int n;
ll K;
vector<int>A;
vi nums[214514];
int sent[214514];//[j,n]での先頭の数字
int sent_ind[214514];//ind->ind [i,n-1]での戦闘のindex
int nexnum[214514];
int main(){
	cin>>n>>K;
	rep(i,214514)nexnum[i]=-1;
	rep(i,n){
		int x;
		cin>>x;
		A.pb(x);
		int sz=nums[x].size();
		if(sz>0){
			nexnum[nums[x][sz-1]]=i;
		}
		nums[x].pb(i);
		
	}
	sent[n+1]=-1;
	sent[n+2]=-1;
	sent_ind[n]=-1;
	sent_ind[n+1]=-1;
	for(int i=n;i>0;i--){
		if(nexnum[i-1]==-1){
			sent[i]=A[i-1];
			sent_ind[i-1]=i-1;
		}else{
			sent[i]=sent[nexnum[i-1]+2];
			sent_ind[i-1]=sent_ind[nexnum[i-1]+1];
		}
	}
	vi ans;
	ans.pb(0);
	int now=0;
	while(1){
		int x=sent[now+1];
		if(x==-1)break;
		ans.pb(x);
		int ind=nums[x][0];
		now=ind+1;
	}
	ll hoge=ans.size();
	ll fuga=K%hoge;
	/*rep(i,ans.size())cout<<ans[i]<<" ";
	cout<<endl;*/
	if(fuga==0){
		cout<<endl;
	}else{
		int y=fuga-1;
		int num2=ans[y];
		int ind2;
		if(num2==0)ind2=-1;
		else ind2=nums[num2][0];
		int x=ind2+1;
		while(sent_ind[x]!=-1){
			cout<<A[sent_ind[x]]<<" ";
			x=sent_ind[x]+1;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 16884
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;

#define MAX_N 1000011
int par1[MAX_N];
int rank1[MAX_N];
LL size[MAX_N];

//初期化
void init(int n){
   for(int i=0;i<n;i++){
       par1[i]=i;
       rank1[i]=0;
   	size[i]=1;
   }
}
//木の根を求める
int find(int x){
    if(par1[x]==x){
       return x;
    }else{
       return par1[x]=find(par1[x]);
    }
}
//xとyの属する集合を併合
void unite(int x,int y){
   x=find(x);
   y=find(y);
   if(x==y) return;
	size[x]+=size[y];
	size[y]=size[x];
   if(rank1[x]<rank1[y]){
        par1[x]=y;
   }else{
        par1[y]=x;
        if(rank1[x]==rank1[y]){
             rank1[x]++;
        }
   }
}
//xとyが同じ集合に属するか否か
bool same(int x,int y){
     return find(x) == find(y);
}

LL N,M;
int A[1000001];
int B[1000001];
LL ans[1000001];
int main(){
	cin>>N>>M;
	REP(i,M){
		cin>>A[i]>>B[i];
		A[i]--;
		B[i]--;
	}
	LL now=N*(N-1)/2;
	init(N+10);
	for(int i=M-1;i>=0;i--){
		ans[i]=now;
		if(same(A[i],B[i])==false){
			int a=find(A[i]);
			int b=find(B[i]);
			now-=size[a]*size[b];
			unite(A[i],B[i]);
		}
	}
	REP(i,M){
		cout<<ans[i]<<endl;
	}
}

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

using ll = long long;
const int mod = 1e9 + 7;
const double PI = 3.1415926535;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    double R;
    scanf("%lf", &R);
    printf("%lf\n", 2 * R * PI);
}

Measured memory_bytes: 3836
<?php

list($n, $k) = LineIO::read();

$n = intval($n);
$k = intval($k);

$res = 0;

for ($b = $k + 1; $b <= $n; $b++)
{
    $total = 0;
    $h = intval($n / $b);
    $total += $h * ($b - 1 - $k + 1);

    $offset = $n - $h * $b + 1;
    if ($offset > 0)
    {
        $total += max($offset - $k, 0);
    }

    $res += $total;

    // k=0のときのみ、a=0のときが混じってしまうので-1
    if ($k === 0)
    {
        $res --;
    }

}

LineIO::write($res);


class LineIO
{
    public static function read() {
        return explode(' ', trim(fgets(STDIN)));
    }

    public static function write($str = '') {
        echo $str . PHP_EOL;
    }
}


Measured memory_bytes: 4728
def calc(s, l, c, x, y):
    pat1 = s*x + l*y
    pat2 = 2*c*y
    pat3 = 2*c*x + l*(y-x)
    return min(pat1,pat2,pat3)

A,B,C,X,Y = map(int, input().split())
if X < Y:
    print(calc(A,B,C,X,Y))
else:
    print(calc(B,A,C,Y,X))

Measured memory_bytes: 3060
n,h = map(int, raw_input().split())
l = [map(int, raw_input().split()) for _ in range(n)]
m = []
for a,b in l:
    m.append((b,0))
    m.append((a,1))
m.sort()
m.reverse()
i = 0
while h > 0 and m[i][1] == 0:
    h -= m[i][0]
    i += 1
if h <= 0:
    print i
else:
    print i + (h + m[i][0] - 1) / m[i][0]


Measured memory_bytes: 37492
def main():
    """
    |s| <= 2 * 10 ** 5
    """
    s = input()

    for i, c in enumerate(s):
        if c == "A":
            start = i
            break

    for i, c in enumerate(s[start + 1:], start + 1):
        if c == "Z":
            end = i

    ans = end - start + 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3516
import math

def combi(n ,k):
    return math.factorial(n)//(math.factorial(k)*math.factorial(n-k))

N,K = map(int,input().split())
R = N - K

for i in range(1,K+1):
    if R + 1 >= i:
        tmp = combi(R+1,i) * combi(K-1,i-1)
    else:
        tmp = 0
    print(tmp % (10**9+7))


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

int main(void){
  std::vector<int> a(6);
  for (int i=0; i<6; i++) {
    cin >> a[i];
  }
  if((a[4]-a[0]) <= a[5]){
    cout << "Yay!";
  } else {
    cout << ":(";
  }
  return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int N;
    cin >> N;
    vector<int> v(N + 1, 0);
    REP(i, N - 1) {
        int a;
        cin >> a;
        v[a]++;
    }
    FOR(i, 1, N + 1) {
        cout << v[i] << endl;
    }
    return 0;
}


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

using namespace std;

const int MaxN = 1e5 + 15;
const int INF = 1e9;
const int MOD = 1e9 + 7;



int main()
{
//    freopen("input.txt", "r", stdin);

    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin >> s;

    int ans = 0;
    for(int i = 0; i < s.size(); ++i)
        ans += s[i] - '0';

    ans = max(ans, 9 * (int)(s.size() - 1));

    int cur = 0;
    for(int i = 0; i < s.size(); ++i)
    {
        if(!(i == 0 && s[i] == '1') || s[i] == '0')
        {
            ans = max(ans, (int)cur + s[i] - '1' + 9 * ((int)s.size() - 1 - i));
        }
        cur += s[i] - '0';
    }

    cout << ans << '\n';

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int n;
  n = s.length();
  for (int i=0; i < n;i++){
    if (i%2 == 0 && s[i] == 'L'){
      cout << "No" << endl;
      return 0;
    }
    if (i%2 == 1 && s[i] == 'R'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 384