akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

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

ll MOD = 1000000007;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int A = in() * 100;
	int B = in() * 100;
	int C = in();
	int D = in();
	int E = in();
	int F = in();
	
	vint water(3010), sugar(3010);
	for (int i = 0; i <= F; i += A) water[i] = 1;
	for (int i = 0; i + B <= F; i++) if (water[i]) water[i + B] = 1;
	for (int i = 0; i <= F; i += C) sugar[i] = 1;
	for (int i = 0; i + D <= F; i++) if (sugar[i]) sugar[i + D] = 1;
	
	vint s;
	rep(i,F+1) if(sugar[i]) s.pb(i);
	s.pb(INF);
	
	int answ = A;
	int anss = 0;
	rep(i,F+1) if(i && water[i]) {
		int maxsugar = i / 100 * E;
		maxsugar = min(maxsugar, F - i);
		int ss = *(upper_bound(s.begin(), s.end(), maxsugar) - 1);
		if ((double)ss / i > (double)anss / answ) {
			answ = i;
			anss = ss;
		}
	}
	
	cout << answ + anss << " " << anss << endl;
	
	return 0;
}


Measured memory_bytes: 256
implicit none

integer n,i,j,k,m
integer,allocatable,dimension(:) :: l
integer :: res=0


read(5,*) n
allocate(l(n))
read(5,*) l(1:n)


do i=1,n
 do j=i+1,n
  do k=j+1,n
   m=max(l(k),max(l(i),l(j)))
   if(m.lt.l(i)+l(j)+l(k)-m) then
   res=res+1
   endif
  enddo
  enddo
  enddo

write(6,*) res

end

Measured memory_bytes: 384
class NullNode():
    def __init__(self):
        self.id = None

null_node = NullNode()
class Node():
    def __init__(self, id):
        global null_node
        self.id = id
        self.parent = null_node
        self.left = null_node
        self.right =  null_node

def preorder(node, out_list=[]):
    if node.id is not None:
        out_list.append(str(node.id))
        out_list = preorder(node.left, out_list)
        out_list = preorder(node.right, out_list)
    return out_list

def inorder(node, out_list=[]):
    if node.id is not None:
        out_list = inorder(node.left, out_list)
        out_list.append(str(node.id))
        out_list = inorder(node.right, out_list)
    return out_list

def insert(node, root_node):
    temp_node_parent = root_node.parent
    temp_node = root_node

    while temp_node.id is not None:
        temp_node_parent = temp_node
        if node.id < temp_node.id:
            temp_node = temp_node.left
        else:
            temp_node = temp_node.right

    node.parent = temp_node_parent
    if node.id < temp_node_parent.id:
        temp_node_parent.left = node
    else:
        temp_node_parent.right = node

def find(id,root_node):
    node = root_node
    while node.id is not None:
        if id < node.id:
            node = node.left
        elif id > node.id:
            node = node.right
        else:
            print('yes')
            break
    else:
        print('no')

def delete(id, root_node):
    # 作成中
    global null_node
    type = ''
    node = root_node
    node_parent = null_node
    while node.id != id:
        node_parent = node
        if id < node.id:
            node = node.left
            type = 'L'
        else:
            node = node.right
            type = 'R'
    if node.right is not None:
        node.right.parent = node_parent
    elif node.left is not None:
        node.left.parent = node_parent
    else:
        node.parent = null_node

    if type == 'L':
        node_parent.left = null_node
    else:
        node_parent.right = null_node

import sys
# import cProfile
# import pstats
# c_profile = cProfile.Profile()
# c_profile.enable()


n = int(sys.stdin.readline())
input_lines = sys.stdin.readlines()
root_node = NullNode()
for i in range(n):
    input_line = input_lines[i].split()
    command = input_line[0]
    if command == 'insert':
        id = int(input_line[1])
        id_node = Node(id)
        if root_node.id is None:
            root_node = id_node
        else:
            insert(id_node, root_node)

    elif command == 'find':
        id = int(input_line[1])
        find(id, root_node)

    elif command == 'delete':
        id = int(input_line[1])
        delete(id, root_node)
    else:
        inorder_list = inorder(root_node, [])
        preorder_list = preorder(root_node, [])
        out = ' ' + ' '.join(inorder_list)
        print(out)
        out = ' ' + ' '.join(preorder_list)
        print(out)


# c_profile.disable()
# c_stats = pstats.Stats(c_profile)
# c_stats.sort_stats('tottime').print_stats(10)




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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _i64 x, y;
        while(cin >> x && cin >> y && !(x == 0 && y == 0)) {
            cout << min(x, y) << " " << max(x, y) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define ll long long
#define N 200010
using namespace std;

int n, a[N], b[N], ans;
int rev[35];
vector<int> va, vb;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++) scanf("%d", &a[i]);
    for(int i = 1; i <= n; i ++) scanf("%d", &b[i]);
    rev[0] = 1;
    for(int i = 1; i <= 30; i ++) rev[i] = rev[i - 1] << 1;
    for(int k = 0; k <= 29; k ++)
    {
        int tans = 0;
        va.clear(), vb.clear();
        for(int j = 1; j <= n; j ++) va.push_back(a[j] % rev[k + 1]);
        for(int j = 1; j <= n; j ++) vb.push_back(b[j] % rev[k + 1]);
        sort(va.begin(), va.end());
        sort(vb.begin(), vb.end());
        for(int i = va.size() - 1; i >= 0; i --)
        {
            int l = lower_bound(vb.begin(), vb.end(), rev[k] - va[i]) - vb.begin();
            int r = lower_bound(vb.begin(), vb.end(), rev[k + 1] - va[i]) - vb.begin();
            tans = (tans + r - l) % 2;
            l = lower_bound(vb.begin(), vb.end(), rev[k] + rev[k + 1] - va[i]) - vb.begin();
            tans = (tans + vb.size() - l) % 2;
        }
        if(tans & 1) ans += rev[k];
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 4084
#include<bits/stdc++.h>
#define ff first
#define ss second
#define INF (int)2e9
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(void){
	ios::sync_with_stdio(false); cin.tie(NULL);
	int a,b; cin>>a>>b;
	if(b==1){
		cout<<0;
		return 0;
	}
	if(a>=b){
		cout<<1;
		return 0;
	}
	cout<<1+(b-2)/(a-1);
	return 0;
}

Measured memory_bytes: 256
using System;

class A{
  static void Main(){
    string N = Console.ReadLine();
    int ans = 753,temp = 0;
    for (int i = 0; i < N.Length - 2; i++){
      temp = int.Parse(N.Substring(i, 3));
      ans = Math.Min(ans, Math.Abs(temp - 753));
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 27552
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      if(n <= 9) System.out.println(n);
      else if(n <= 99) System.out.println(9);
      else if(n <= 999) System.out.println(n-90);
      else if(n <= 9999) System.out.println(909);
      else if(n <= 99999) System.out.println(n-9090);
      else System.out.println(90909);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <stack> 
#include <map>
#include <queue>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
#define pb 					push_back
#define FAST_IO          ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
template<typename T,typename S>
ostream& operator <<(ostream& os, pair<T, S> input) {
	os<<"("<<input.first<<", "<<input.second<<")";
	return os;
}
template<typename T>
ostream& operator <<(ostream& os, vector<T> input) {
	for(auto t: input)
		os << t <<"\n";
	return os;
}
template<typename T>
ostream& operator <<(ostream& os, set<T> input) {
	for(auto t: input)
		os << t <<"\n";
	return os;
}

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

Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a,b=0, c=0, n, k;
string s,t;
//cout<<<<endl;


int main()
{
	cin >> n;
	vector<int> A(n);
	rep(i, n)
		cin >> A.at(i);
	sort(all(A));
	rep(i, n - 1)
	{
		if (A[i] == A[i + 1])
			b++;
	}
	if (b > 0)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
	
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h.at(i);
    }
    int count = 0;
    for(int i = 0; i < n; i++){
        if(h.at(i) >= k){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 640
import java.util.*

fun main() {
    val sc = Scanner(System.`in`)

    // j > i

    // ai + aj = j - i
    // ai + i = j - aj
    val n = sc.nextInt()
    val arr = LongArray(n+1)
    val m = HashMap<Long,Int>()
    for(i in 1..n) {
        arr[i] = sc.nextLong()
        val d = i - arr[i]
        m[d] = (m[d]?:0) + 1
    }
    var ans = 0L
    for(i in 1..n) {
        val d = i + arr[i]
        ans += m[d]?:0
    }
    print(ans)
}

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

using usize = ::std::size_t;
using u64 = ::std::uint_least64_t;

static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;


int main(int argc, char *argv[])
{
    
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    u64 N, cnt = 0;
    cin >> N;
    
    for (u64 i = 1, a; i <= N; i++) {
        cin >> a;
        if (i % 2 && a % 2) {
            cnt++;
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 3644
//Big Array

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,k;cin>>n>>k;
    map<int,int>m{};
    rep(i,0,n){
        int a,b;cin>>a>>b;
        m[a]+=b;
    }
    irep(i,m){
        k-=i->second;
        if(k<=0){
            cout<<i->first;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 7564
from collections import deque

# 命令数入力
n = int(input())
# 命令入力
# order_list = [input().split() for i in range(n)]


# 双方向連結リスト
doubly_linked_list = deque()

for _ in range(n):
    
    order = input().split()
    
    if order[0] == "insert":
        doubly_linked_list.appendleft(order[1])
    
    elif order[0] == "delete":
        if order[1] in doubly_linked_list:
            doubly_linked_list.remove(order[1])
    
    elif order[0] =="deleteFirst":
        doubly_linked_list.popleft()
    
    elif order[0] == "deleteLast":
        doubly_linked_list.pop()
        
# 最終結果出力
print(*doubly_linked_list)


Measured memory_bytes: 69736
N = int(input())
D = {}
for i in range(N):
  S = input()
  if S in D:
    D[S] += 1
  else:
    D[S] = 1
M = max(D[i] for i in D)
L = []
for i in D:
  if D[i] == M:
    L.append(i)
L.sort()
for i in range(len(L)):
  print(L[i])


Measured memory_bytes: 32096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=2e5;
int n;
ll a[maxn+10];
ll b[maxn+10];
ll sum[maxn+10];
int main()
{
    while(cin>>n)
    {
        for(int i=1; i<=n; i++)
            cin>>a[i],b[i]=a[i]-i+1;

        sort(b+1,b+1+n);
        for(int i=1; i<=n; i++)
            sum[i]=sum[i-1]+b[i];//printf("%lld\n",b[i]);
       // printf("\n\n\n");
        ll ans=1e18;
        for(int i=1; i<=n; i++)
        {
            int m=upper_bound(b+1,b+1+n,0)-b-1;
            int mm=upper_bound(b+1,b+1+n,a[i]-i+1)-b-1;
            //cout<<a[i]<<" "<<m<<" "<<mm<<endl;
            ll aa=a[i]-i+1;
            //cout<<aa<<endl;
            if(aa>=0)
            {
                ll ret=abs(sum[m]-m*aa);
                ret+=aa*(mm-m) - (sum[mm]-sum[m]);
                ret+=sum[n]-sum[mm]-aa*(n-mm);
                ans=min(ans,ret);
                //cout<<ret<<endl;
            }
            else
            {
                ll ret=abs(sum[mm]-mm*aa);
                ret+=abs(aa*(m-mm))+(sum[m]-sum[mm]);
                ret+=sum[n]-sum[m]-aa*(n-m);
                ans=min(ans,ret);//cout<<ret<<endl;

            }

        }
        cout<<ans<<endl;

    }
    return 0;
}

Measured memory_bytes: 4992
#include<iostream>

using namespace std;

int main(){
    int A[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << A[K - 1] << endl;
}

Measured memory_bytes: 256
def LI():return list(map(int,input().split()))
def II():return int(input())
def yes():return print("Yes")
def no():return print("No")
INF=float("inf")
from collections import deque, Counter
from heapq import heappop, heappush
from itertools import product, combinations
from functools import reduce, lru_cache
from math import pi, gcd
from decimal import Decimal

# class Combination:
#     """
#     O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
#     n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
#     使用例：
#     comb = Combination(1000000)
#     print(comb(5, 3))  # 10
#     """
#     def __init__(self, n_max, mod=10**9+7):
#         self.mod = mod
#         self.modinv = self.make_modinv_list(n_max)
#         self.fac, self.facinv = self.make_factorial_list(n_max)

#     def __call__(self, n, r):
#         return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

#     def make_factorial_list(self, n):
#         # 階乗のリストと階乗のmod逆元のリストを返す O(n)
#         # self.make_modinv_list()が先に実行されている必要がある
#         fac = [1]
#         facinv = [1]
#         for i in range(1, n+1):
#             fac.append(fac[i-1] * i % self.mod)
#             facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
#         return fac, facinv

#     def make_modinv_list(self, n):
#         # 0からnまでのmod逆元のリストを返す O(n)
#         modinv = [0] * (n+1)
#         modinv[1] = 1
#         for i in range(2, n+1):
#             modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
#         return modinv

# class Unionfind:
#     def __init__(self, N):
#         self.p = list(range(N))
#         self.rank = [0] * N
#         self.size = [1] * N

#     def root(self, x):
#         if self.p[x] != x:
#             self.p[x] = self.root(self.p[x])

#         return self.p[x]

#     def same(self, x, y):
#         return self.root(x) == self.root(y)

#     def unite(self, x, y):
#         u = self.root(x)
#         v = self.root(y)

#         if u == v: return

#         if self.rank[u] < self.rank[v]:
#             self.p[u] = v
#             self.size[v] += self.size[u]
#             self.size[u] = 0
#         else:
#             self.p[v] = u
#             self.size[u] += self.size[v]
#             self.size[v] = 0

#             if self.rank[u] == self.rank[v]:
#                 self.rank[u] += 1

#     def count(self, x):
#         return self.size[self.root(x)]























n=II()
a=LI()
b=LI()
c=b[::-1]
bb=deque(b)
ac=Counter(a)
bc=Counter(b)

for i in range(n):
    if ac[i]+bc[i]>n:
        print("No")
        exit()

import time
# import random
t1=time.time()
for i in range(10000000):
    if time.time()-t1>1.5:
        print("No")
        exit()        
    tmp=bb.popleft()
    bb.append(tmp)
    if any(d==e for d,e in zip(a,bb)):
        continue
    print("Yes")
    print(*bb)
    exit()


Measured memory_bytes: 173776
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;

int main(){
    int N;
    cin>>N;
    int c=0;
    bool f=false;
    for(int i=0;i<N;i++){
        int D1,D2;
        cin>>D1>>D2;
        if(D1==D2) c++;
        else c=0;
        if(c==3) f=true;
    }

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


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vs s(n);
  set<string> st;
  rep(i, n) {
    cin >> s[i];
    st.insert(s[i]);
  }
  bool ans = true;
  if(st.size() < n) ans = false;
  rep(i, n - 1) if(s[i].back() != s[i + 1][0]) ans = false;
  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 aa, bb;
	cin >> aa >> bb;
	cout << 6 - aa - bb << endl;
	return 0;
}

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


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
class SegmentTree
{
private:
  using Fn = function<T(T, T)>;
  int N;
  vector<T> dat;
  T unit;
  Fn func;

public:
  SegmentTree() {}
  SegmentTree(int n_, Fn func_, T unit_) : func(func_), unit(unit_)
  {
    N = 1;
    while (N < n_)
      N *= 2;
    dat.assign(2 * N - 1, unit);
  }
  SegmentTree(const vector<T> &v, Fn func_, T unit_) : func(func_), unit(unit_)
  {
    N = 1;
    int sz = v.size();
    while (N < sz)
      N *= 2;
    dat.resize(2 * N - 1);
    for (int i = 0; i < N; ++i)
      dat[i + N - 1] = (i < sz ? v[i] : unit);
    for (int i = N - 2; i >= 0; --i)
      dat[i] = func(dat[i * 2 + 1], dat[i * 2 + 2]);
  }

  // k 番目の要素を a に変更
  void update(int k, T a)
  {
    k += N - 1;
    dat[k] = a;
    while (k > 0)
    {
      k = (k - 1) / 2;
      dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  // k 番目の要素を取得
  T get(int k) { return dat[k + N - 1]; }

  // 区間 [l, r) の和を取得
  T query(int l, int r)
  {
    T vl = unit, vr = unit;
    for (l += (N - 1), r += (N - 1); l < r; l >>= 1, r >>= 1)
    {
      if ((l & 1) == 0)
        vl = func(vl, dat[l]);
      if ((r & 1) == 0)
        vr = func(vr, dat[--r]);
    }
    return func(vl, vr);
  }
};
int main(){
    ll n;
    cin>>n;
    auto c=[](ll a,ll b) { return __gcd(a,b); };
    SegmentTree<ll> sg(n,c,0);
    rep(i,n) {
        ll x;
        cin>>x;
        sg.update(i,x);
    }
    ll ans=0;
    rep(i,n) {
        ll kotae= __gcd(sg.query(0, i), sg.query(i+1,n));
        if(ans<kotae){
          ans=kotae;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2304
// I want to AC  


#include <vector>
#include<stdio.h>
#include<string.h>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#include<cstring>
#include<queue>
#include<assert.h>
#define ll long long
#define MODD 1000000007
#define  pii  pair<int,int>
#include<stdio.h>
#include<string.h>
//#define  ll long long
using namespace std;
const int maxn = 1e6;


ll exgcd(ll a, ll b, ll &x, ll &y) {
 if (b == 0) { x = 1; y = 0; return a; }
 ll ret = exgcd(b, a % b, y, x);
 y -= a / b * x;
 return ret;
 }
ll inv(ll a, ll M) {
 static ll x, y;
 assert(exgcd(a, M, x, y) == 1);
 return (x % M + M) % M;
 }
//void gcd(ll a,ll b,ll &d,ll &x,ll &y){
//    if(!b){
//        d=a;x=1;y=0;
//    }else{
//        gcd(b,a%b,d,y,x);
//        y-=x*(a/b);
//    }
//}
//ll inv(ll a,ll n){
//    ll d,x,y;
//    gcd(a,n,d,x,y);
//    return d==1?(x+n)%n:-1;
//}
// LL get_inv(LL a, LL M) {
// static LL x, y;
// assert(exgcd(a, M, x, y) == 1);
// return (x % M + M) % M;
// }

//欧拉函数
ll euler(ll n)
{
    ll rt = n;
    for (int i = 2; i * i <= n; i++)
        if (n % i == 0)
        {
            rt -= rt / i;
            while (n % i == 0)
                n /= i;
        }
    if (n > 1)
        rt -= rt / n;
    return rt;
}

bool st[1000005];
int primes[50005];
void prime(int n)
{
    int cnt =0 ;
	for(int i=2;i<=n;i++)
	{
		if(!st[i])
		{
			primes[cnt++]=i;
		}
		for(int j=0;j<cnt&&i*primes[j]<=n;j++)
		{
			st[primes[j]*i]=true;
			if(i%primes[j]==0)
			{
				break;
			}
		}
	}

}


vector<int > div(int x){
	vector<int > res;
	for(int i=1 ;i<=x/i;i++) {
		if(x%i==0){
			res.push_back(i);
			if(i!=x/i) res.push_back(x/i);
		}
	}
	sort(res.begin(), res.end());
	return res;
}
ll mod = 1e9+7;
inline void read(int &x){
    x=0;int f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x*=f;
}


int cnt =0 ;
int dp[maxn],ar[maxn];
char ch [2500][2500];
int main() {
  	
	string s;cin>>s;
	int len = s.size();
	for(int i=0;i<len;i++){
		cout<<"x";
	}cout<<endl;
    return 0;



}

Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, R := sc.nextInt(), sc.nextInt()
	var ans int
	if N < 10 {
		ans = R + 100*(10-N)
	} else {
		ans = R
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<numeric>
#include<algorithm>
using namespace std;

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

	vector<int> m(N);
	for(int i=0; i<N; i++)
		cin >> m[i];

	int ret = N;
	X -= accumulate(m.begin(), m.end(), 0);

	ret += X / *min_element(m.begin(), m.end());

	cout << ret << endl;

	return 0;
}


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

bool vowel(char c){
	return c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o';
}

void solve(int n){
	vector<string> v;
	for(int i=0; i<n; ++i){
		string s;
		cin >> s;
		string t;
		t.push_back(s[0]);
		for(int j=1; j<s.size(); ++j)
			if(vowel(s[j-1]))
				t.push_back(s[j]);
		v.push_back(t);
	}
//	for(int i=0; i<n; ++i)
//		cout << v[i] << "\n";
	sort(v.begin(), v.end());
	int ans = 1;
	for(int i=0; i+1<v.size(); ++i){
		if(v[i] == v[i+1]){
			ans = 100;
		}else{
			int tmp = v[i].size()+1;
			for(int j=1; j<=v[i].size(); ++j)
				if(v[i].substr(0, j) != v[i+1].substr(0, j)){
					tmp = j;
					break;
				}
			ans = max(ans, tmp);
		}
	}
	if(ans == 100) cout << -1 << "\n";
	else cout << ans << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n;
		cin >> n;
		if(n == 0) return 0;
		solve(n);
	}
}


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int M = scan.nextInt();
		int X = scan.nextInt();
		int[] C = new int[N];
		int[][] A = new int[N][M];
		int answer = Integer.MAX_VALUE;

		for (int i = 0; i < N; i++) {
			C[i] = scan.nextInt();
			for (int k = 0; k < M; k++) {
				A[i][k] = scan.nextInt();
			}
		}

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

			int price = 0;
			int[] values = new int[M];

			for (int j = 0; j < N; j++) {
				if ((1&i>>j) == 1) {
					price += C[j];

					for (int k = 0; k < M; k++) {
						values[k] += A[j][k];
					}
				}
			}

			boolean flag = true;
			for (int k = 0; k < M; k++) {
				if (values[k] < X) {
					flag = false;
					continue;
				}
			}
			if (flag) answer = Math.min(answer, price);
		}

		System.out.println(answer == Integer.MAX_VALUE ? -1 : answer);
 	}
}

Measured memory_bytes: 37528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int P[1005];
int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int a;
	cin >> a;
	int even = 0;
	int sum = 0;
	for (int i = 0; i < a; i++)
	{
		cin >> P[i];
		if (P[i] % 2 == 0)
		{
			even++;
			if (P[i] % 3 == 0 || P[i] % 5 == 0)
			{
				sum++;
			}
		}
	}
	if (even==sum)
	{
		cout << "APPROVED" << '\n';
	}
	else
	{
		cout << "DENIED" << '\n';
	}

	
	return 0;
}

Measured memory_bytes: 256
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashMap;

fn main() {
    input!(n: i64, p: i64);
    let factors = prime_factorize(p);

    let mut ans = 1;
    for (&prime, &count) in &factors {
        ans *= prime.pow(count as u32 / n as u32);
    }

    println!("{}", ans);
}

use std::collections::BTreeMap;

pub fn prime_factorize(x: i64) -> BTreeMap<i64, usize> {
    let mut map = BTreeMap::new();
    let mut x = x;
    for prime in 2.. {
        if prime * prime > x {
            break;
        }

        while x % prime == 0 {
            *map.entry(prime).or_insert(0) += 1;
            x /= prime;
        }
    }
    if x != 1 {
        *map.entry(x).or_insert(0) += 1;
    }
    map
}


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

class Cube{
public:
  int f[6];
  Cube(){}
  void roll_z(){ roll(1, 2, 4, 3);}
  void roll_y(){ roll(0, 2, 5, 3);}
  void roll_x(){ roll(0, 1, 5, 4);}
  void roll(int i, int j, int k, int l){
    int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
  }
  void move(char ch){
    if ( ch == 'E') for ( int i = 0; i < 3; i++ ) roll_y();
    if ( ch == 'W') roll_y();
    if ( ch == 'N') roll_x();
    if ( ch == 'S') for ( int i = 0; i < 3; i++ ) roll_x();
  }
};

int main(){
  Cube c;
  string com;
  
  for ( int i = 0; i < 6; i++ ) cin >> c.f[i];
  cin >> com;
  
  for ( int i = 0; i < com.size(); i++ ) c.move(com[i]);
  
  cout << c.f[0] << endl;
  
  return 0;
}


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

import collections
dic = collections.Counter(A)

for _ in range(M):
    b, c = map(int, input().split())
    if c in dic:
        dic[c] += b
    else:
        dic[c] = b

ans, k = 0, 0
l = sorted(list(dic.keys()), key=lambda x: -x)
for a in l:
    if k + dic[a]<= N:      
        k += dic[a]  
        ans += a*dic[a]
    else:
        ans += a*(N-k)
        break

print(ans)

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int h, w, k;
  cin >> h >> w >> k;

  int a[h][w];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char c;
      cin >> c;

      a[i][j] = (c == '1');
    }
  }

  int ans = INT_MAX;
  for (int i = 0; i < (1<<(h-1)); ++i) {
    int sum[15], cnt = 0;
    memset(sum, 0, sizeof sum);

    bool over = 0;
    for (int j = 0; j < w; ++j) {
      for (int l = 0, cur = 0; l < h; ++l) {
        sum[cur] += a[l][j];
        if (sum[cur] > k) over = 1;
        if ((i>>l)&1) cur++;
      }
      if (over) {
        cnt++;
        memset(sum, 0, sizeof sum);
        for (int l = 0, cur = 0; l < h; ++l) {
          sum[cur] += a[l][j];
          if (sum[cur] > k) cnt = 1e6;
          if ((i>>l)&1) cur++;
        }
        over = 0;
      }
    } 
    ans = min(ans, cnt + __builtin_popcount(i));
  }

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


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

using namespace std;

const double EPS = 1e-7;
const int N = 20, M = 1e4+5, OO = 0x3f3f3f3f;

int r,sum;

int main(){
    scanf("%d", &r);
    printf("%d" , (r*r)/1);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

const int MAX_N = 20;
vector<pair<int, int> > G[MAX_N]; /* G[u][v] := u->v's weight */
int dp[(1 << MAX_N)][MAX_N];
// int prev[MAX_N];
void Traveling_Salesman(int n){ /* n := Number of vertices */
	rep(i, (1 << n))rep(j, n)dp[i][j] = INF; /* Initialization */
	dp[0][0] = 0;
	for (int mask = 0; mask < (1 << n); ++mask){
		for (int u = 0; u < n; ++u){ /* Current vertex */
			for(auto p : G[u]){ /* Next vertex */
				int v = p.first, w = p.second;
				if((mask & (1 << v)) == 0){
					if(dp[mask | (1 << v)][v] > dp[mask][u] + w){
						dp[mask | (1 << v)][v] = dp[mask][u] + w;
						// prev[v] = (int)u;
					}
				}
			}
		}
	}
}

int main(void){
	int v, e;
	scanf("%d %d", &v, &e);
	rep(i, e){
		int s, t, d; scanf("%d %d %d", &s, &t, &d);
		G[s].pb(mp(t, d));
	}
	Traveling_Salesman(v);
	int ret = dp[(1 << v) - 1][0];
	if(ret == INF){
		printf("-1\n");
	}else{
		printf("%d\n", ret);
	}

	return 0;
}

Measured memory_bytes: 5680
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    vector<ll> asum(n+1), bsum(m+1);
    rep(i, n) asum[i+1] = asum[i] + a[i];
    rep(i, m) bsum[i+1] = bsum[i] + b[i];
    int ans = 0;
    rep(i, n+1) {
        if (asum[i] > k) break;
        int idx = upper_bound(all(bsum), k - asum[i]) - bsum.begin();
        chmax(ans, i + idx-1);
    }
    cout << ans << endl;
}


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

using namespace std;

int a[2005];

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	long long res = 0;
	
	sort(a, a + n, greater<int>());
	
	for (int i = 0; i < n; i++) {
		int p = n - 1;
		
		for (int j = i + 1; j < n; j++) {
			//a[i] < a[j] + a[k]
			//a[k] > a[i] - a[j]
			while (p > j && a[p] <= a[i] - a[j]) p--;
			
			if (p <= j) break;
			
			res += p - j;
		}
	}
	
	printf("%lld\n", res);
}


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

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

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

int main(){
  char c[2] = {0};
  
  scanf( "%s", c);
  
  if( strcmp(c, "A") == 0){
    printf("T");
  }
  else if( strcmp(c,"T") == 0){
    printf("A");
  }
  else if( strcmp(c,"C") == 0){
    printf("G");
  }
  else{
    printf("C");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;cin >> n;
    int bef=-INF;
    int ans=0;
    int t=0;
    rep(i,n){
        int a;cin >> a;
        if(bef>=a){
            //cout << "bef" << endl;
            t++;
        }else{
            //cout << "ans" << endl;
            ans = max(ans,t);
            t = 0;
        }
        bef = a;
    }
    ans = max(ans,t);
    cout << ans << endl;
}

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

int checkList(int A[], int n) {
	int i, result;
	for(i=0,result=0;i<n;i++) {
		if(A[i] != 0) {
			if(result != 0)
				return -1;
			result = A[i];
		}
	}
	
	return result;
}

int main(void) {
	int n,m,i,j,t,result,ofs;
	int A[10000];
	
	while(scanf("%d %d\n", &n, &m)==2) {
		if(n==0 && m==0) break;

		for(i=0;i<n;i++) A[i] = i + 1;

		i=-1; j=0;
		while(1) {
			i = (i+1) % n;
			if(A[i] != 0) {
				j++;
				if(j==m) {
					j = 0;
					A[i] = 0;
					result = checkList(A,n);
					if(result != -1) {
						printf("%d\n", result);
						break;
					}
				}
			}
		}			
	}
	
	return 0;
}

Measured memory_bytes: 616
#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>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

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

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

struct sushi {
  priority_queue<long> ds;
  long maxd;

  sushi(long d): maxd(d) {
    ds.push(d);
  };

  bool operator>(sushi other) const {
    return maxd > other.maxd;
  }

  void push(long d) {
    ds.push(d);
    maxd = ds.top();
  }

  long pop() {
    long res = maxd;
    ds.pop();
    maxd = ds.empty()?-1:ds.top();
    return res;
  }
};

int cnts[100005];

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

  long n, k;
  cin >> n >> k;

  map<int, sushi> sm;

  rep(i, n) {
    int t;
    long d;
    cin >> t >> d;
    if (sm.count(t)) {
      sm.find(t)->second.push(d);
    } else {
      sm.insert({t, sushi(d)});
    }
  }

  vector<sushi> smv;
  for(auto x: sm) {
    smv.push_back(x.second);
  }
  sort(smv.begin(), smv.end(), greater<sushi>());
  vector<long> tops;
  vector<long> amari;
  for(auto x: smv) {
    tops.push_back(x.pop());  
    while(x.maxd != -1) {
      amari.push_back(x.pop());
    }
  }
  sortvinv(tops);
  sortvinv(amari);
  long shurui = min((long)tops.size(), k);
  long amariCur = min((long)amari.size()-1, k-2);
  while (shurui + amariCur + 1 > k) {
    if (amari[amariCur] >= (shurui-1)*2+1+tops[shurui-1]) {
      shurui--;
    } else {
      amariCur--;
    }
  }
  long dd = 0;
  rep(i, shurui) {
    dd += tops[i];
  }
  rep(i, amariCur + 1) {
    dd += amari[i];
  }

  cout << dd+shurui*shurui << endl;
}

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

int dp[20][20];
bool map[20][20];



int main(){
	int a,b,n;
	
	while(cin>>a>>b,a!=0||b!=0){
		cin>>n;
		int x,y;
		for(int i=0;i<20;i++){
			for(int j=0;j<20;j++){
				dp[i][j]=map[i][j]=0;
			}
		}
		for(int i=0;i<n;i++){
			cin>>x>>y;
			map[x][y]=1;
		}
		dp[1][1]=1;
		for(int i=1;i<=a;i++){
			for(int j=1;j<=b;j++){
				if(map[i][j]!=1)dp[i][j]+=dp[i-1][j]+dp[i][j-1];
			}
		}
		
		
		cout<<dp[a][b]<<endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
ll a,b,c,d;
ll gcd(ll x,ll y)
{
    if(y==0)  return x;
    return gcd(y,x%y);
}
ll lcm(ll x,ll y)
{
    return x*(y/gcd(x,y));
}
ll solve(ll x)
{
    if(x==0)  return 0;
    return x-(x/c+x/d-x/lcm(c,d));
}
int main()
{
    cin>>a>>b>>c>>d;
    ll ans=solve(b)-solve(a-1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
//g++ -std=c++11
//g++ -std=c++1z 

using namespace std;

typedef long long ll;
const long long INF = 1e18+10;

int main() {
 
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
 
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);

    set <string> myset;

    int n;
    cin >> n;

    string s;

    for (int i=0; i<n; i++) {
    	cin >> s;
    	myset.insert(s);
    }

    cout << myset.size() << endl;
    
    return 0;
}


Measured memory_bytes: 19272
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <math.h>
#include <iterator>
using namespace std;
int main() {
	while (true) {
		int n, y;
		int greatest_bank = 0;
		double  greatest_interest = 0;
		scanf("%d", &n);
		if (n == 0) goto end;
		scanf("%d", &y);
		for (int i = 0;i < n;++i) {
			double   r;
			int b,t;
			scanf("%d%lf%d", &b, &r, &t);
			if (t == 1) {
				if (1 + ((r*y)/100) > greatest_interest) {
					greatest_bank = b;
					greatest_interest = (1 + ((r*y) / 100));
				}
			}
			else {
				double money = (1+(r/100));
				for (int q = 1;q < y;++q) {
					money = money*(1 + (r/100));
				}
				if (money > greatest_interest) {
					greatest_bank = b;
					greatest_interest = money;
				}
			}
		}
		printf("%d\n", greatest_bank);
	}
end:;
}


Measured memory_bytes: 1056
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)
            Console.WriteLine(GetWinner());
        }

        static char GetWinner()
        {
            //A,B,Cが持っているカード
            var a = new Queue<char>(Console.ReadLine());
            var b = new Queue<char>(Console.ReadLine());
            var c = new Queue<char>(Console.ReadLine());

            //最初に引くカード
            var card = a.Dequeue();

            while (true)
            {
                switch (card)
                {
                    case 'a':
                        if (a.Count == 0)
                        {
                            return 'A';
                        }
                        else
                        {
                            card = a.Dequeue();
                        }
                        
                        break;
                    case 'b':
                        if (b.Count == 0)
                        {
                            return 'B';
                        }
                        else
                        {
                            card = b.Dequeue();
                        }

                        break;
                    case 'c':
                        if (c.Count == 0)
                        {
                            return 'C';
                        }
                        else
                        {
                            card = c.Dequeue();
                        }

                        break;
                }
            }
        } 
    }
}


Measured memory_bytes: 11220
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
class UnionFind {
private:
    int sz;
    vector<int> par, size_;
public:
    UnionFind(){}
    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x == y) return;
        if(size_[x] < size_[y]) swap(x,y);
        par[y] = x;
        size_[x] += size_[y];
    }
    int size(int x){
        x = find(x);
        return size_[x];
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    while(m--){
        int a, b;
        cin >> a >> b;
        a--;b--;
        uf.unite(a,b);
    }
    int cnt = 0;
    rep(i,n)if(uf.find(i) == i)cnt++;
    cout << max(0,cnt - 1)<< endl;
}


Measured memory_bytes: 3968
#人数
N = int(input())

ans = 0

#証言テーブル
syo = [ [] for i in range(N)]

for i in range(N):
    Ai = int(input())
    for j in range(Ai):
        xi,yi = map(int,input().split())
        #xiは添字とずれるので -1 する
        xi -= 1
        syo[i].append([xi,yi])

#bit全探索
for i in range(2**N):
    mujun = True
    for j in range(N):
        #j番目の人が正直者(1)のとき
        if ( (i >> j) & 1):
            #syo[j]に格納された証言の検証を行う
            #証言があっているか
            for x,y in syo[j]:
                if (i >> x) & 1 != y:
                    mujun = False
                    break
    if mujun:
        ans = max(ans,bin(i)[2:].count("1"))

print(ans)



Measured memory_bytes: 3064