akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
int l[110];
int main(){
    int i,j,k,ans = 0,n; cin >> n;
    for(i=0;i<n;i++) cin >> l[i];
    sort(l,l + n);
    for(i=0;i<n;i++){
        for(j=i + 1;j<n;j++){
            for(k = j + 1;k<n;k++){
                if(l[i]==l[j] || l[j]==l[k]) continue;
                if(l[k]<l[i] + l[j]) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
import math
import fractions
import sys
input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################


h,w,n = list(map(int, input().split()))
painted = []
for i in range(n):
    t = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            painted.append([t[0]-2+j, t[1]-2+k])
    
painted.sort(key = lambda x : x[1])
painted.sort(key = lambda x : x[0])

p2 = []

for i in painted:
    if(i[0]>=1 and i[0]<h-1 and i[1]>=1 and i[1]<w-1):
        p2.append(i)

#print(p2)
ans = [0 for i in range(10)]
chain=0
if(len(p2)>0):
    before = p2[0]
    chain = 1
for ii in range(len(p2)-1):
    i = ii+1
    if(p2[i][0] == before[0] and p2[i][1] == before[1]):
        chain += 1
    else:
        ans[chain]+=1
        chain=1
        before[0],before[1] = p2[i]
if(len(p2)>0): ans[chain]+=1

ans[0] = (h-2)*(w-2) - sum(ans[1:])
for i in ans:
    print(i)






































Measured memory_bytes: 223812
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int A,B;cin>>A>>B;
    if(A<=9&&B<=9){
        cout<<A*B<<endl;
        return 0;
    }
    else {
        cout<<-1<<endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, m, p, y;
    cin >> n >> m;
    vector<vector<int>> arr;
    unordered_map<int, vector<int>> rec;
    unordered_map<int, unordered_map<int, string>> tab;
    for(int i = 0; i < m; i++) {
        cin >> p >> y;
        arr.push_back({p, y});
        rec[p].push_back(y);
    }
    for(auto& p: rec) {
        auto& v = p.second;
        sort(v.begin(), v.end());
        for(int i = 0; i < v.size(); i++) {
            char tmp[7];
            sprintf(tmp, "%06d", i+1);
            tab[p.first][v[i]] = string(tmp);
        }
    }
    for(int i = 0; i < m; i++) {
        p = arr[i][0];
        char tmp[7];
        sprintf(tmp, "%06d", p);
        cout << tmp << tab[p][arr[i][1]] << endl;
    }
    return 0;
}




Measured memory_bytes: 35412
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int main(){
  ll x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<ll> red,gr;
  for(int i=0;i<a;i++){
    ll m;
    cin>>m;
    red.push_back(m);
  }
  for(int i=0;i<b;i++) {
    ll m;
    cin>>m;
    gr.push_back(m);
  }
  sort(red.begin(),red.end(),greater<ll>());
  sort(gr.begin(),gr.end(),greater<ll>());
  priority_queue<ll,vector<ll>,greater<ll>> pque;
  for(int i=0;i<x;i++) pque.push(red[i]);
  for(int i=0;i<y;i++) pque.push(gr[i]);
  priority_queue<ll> nocol;
  for(int i=0;i<c;i++){
    ll m;
    cin>>m;
    nocol.push(m);
  }
  while(!nocol.empty()){
    ll minv=pque.top();
    ll maxv=nocol.top();
    if(minv<maxv){
      pque.pop();
      nocol.pop();
      pque.push(maxv);
    }
    else break;
  }
  ll ans=0;
  while(!pque.empty()){
    ans+=pque.top();
    pque.pop();
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4976
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,M; cin>>N>>M; //N:num of switches, M:num of lights

    vector<vector<int>> L(M);
    rep(m,0,M){
        int K; cin>>K;
        rep(k,0,K){
            int s; cin>>s;
            L.at(m).push_back(s);
        }
    }

    vector<int> P(M);
    rep(m,0,M) cin>>P.at(m);

    int64_t ans=0;
    rep(i,0,1<<N){
        bitset<10> b=i;

        bool satisfy=true;
        rep(m,0,M){
            int sumOn=0;
            for(auto l:L.at(m)){
                if(b.test(l-1)) sumOn++;
            }
            if(sumOn%2!=P.at(m)){
                satisfy=false;
                break;
            }
        }

        if(satisfy) ans++;
    }

    cout<<ans<<endl;
}

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

// varibable settings {{{
#define infile "../test/sample-1.in"
#define int long long
const int INF=1e18;
const int MOD=1e9+7;
// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#endif
//}}}

int solve(){
  int r,d,xx;cin>>r>>d>>xx;

  int x = xx;
  rep(i, 1, 11){
    x = r*x - d;
    cout << x << endl;
  }
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

// 回文ならばtrueを返す関数

bool Get_is_palindrome(string s) {
    bool result = true;
    for (int i = 0; i < s.size() / 2; i++) {
        if (s[i] != s[s.size() - i - 1]) {
            result = false;
        }
    }
    return result;
}

int main() {

    int a, b; cin >> a >> b;
    int ans = 0;
    for (int i = a; i <= b ; i++) {
        if (Get_is_palindrome(to_string(i))) ans++;
    }

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

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    l=[0]*N
    for x in range(1,101):
        for y in range(1,101):
            for z in range(1,101):
                tot=x**2+y**2+z**2+x*y+y*z+z*x
                if tot<=N:
                    l[tot-1]+=1
    for i in range(N):
        print(l[i])






if __name__ == "__main__":
    main()

Measured memory_bytes: 74212
<>;
@a=sort{$a-$b}glob<>;
@b=sort{$a-$b}glob<>;
@c=sort{$a-$b}glob<>;
for(@b){
	$a++while$a<@a&&$a[$a]<$_;
	$c++while$c<@c&&$c[$c]<=$_;
	$x+=$a*(@c-$c);
}
print$x,$/


Measured memory_bytes: 49668
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {

    int n,k;
    cin>>n>>k;
    vector<int> v(n);
   // ll sum=0;

    rep(i,n){
        cin>>v[i];
        //sum+=v[i];
    }

    int ans=0;
    int lim=min(n,k);
    for(int l=0;l<=lim;l++){

        for(int r=0;r<=lim-l;r++){

            vector<int> te;
            int sum=0;

        for(int i=0;i<l;i++){
            sum+=v[i];
            if(v[i]<0) {
                te.push_back(v[i]);
            }
        }
            for(int i=0;i<r;i++){
                sum+=v[n-i-1];
                if(v[n-i-1]<0) {
                    te.push_back(v[n - i - 1]);
                }
            }

            int a=k-(l+r);
            int b=te.size();
            sort(te.begin(),te.end());

            for(int tt=0;tt<min(a,b);tt++){
             //if(tt!=0){
                 sum-=te[tt];
             //}
             //cout<<l<<" "<<r<<" "<<sum<<endl;
            }
            ans=max(sum,ans);
        }
    }

    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 256
N,K = list(map(int, input().split()))
D = set(input())

#print(D)
#print(set(str(N)))

#&はどちらも満たすとき
#N&Dは、NとDのどちらのリストにもある要素
#print(set(str(N))&D)

#NとDの共通要素がある間はNに数字を足す
while set(str(N))&D:
  N+=1
print(N)

Measured memory_bytes: 2940
from collections import Counter

n = int(input())
V = list(map(int, input().split()))
X = Counter([V[i] for i in range(0, n, 2)]).most_common()
Y = Counter([V[i] for i in range(1, n, 2)]).most_common()

ans = 0

if X[0][0] != Y[0][0]:
    ans = n - X[0][1] - Y[0][1]
else:
    if len(X) == 1 and len(Y) == 1:
        ans = n // 2
    elif len(X) == 1 and len(Y) != 1:
        ans = n // 2 - Y[1][1]
    elif len(X) != 1 and len(Y) == 1:
        ans = n // 2 - X[1][1]
    else:
        a = n - X[0][1] - Y[1][1]
        b = n - X[1][1] - Y[0][1]
        ans = min(a, b)
        
print(ans)

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

const int N = 1e5 + 10;

int a[N];

int main(){
	int n;
	long long sum, tot;
	scanf("%d",&n);
	sum = 0;
	for (int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		sum += a[i];
	}
	if (n == 1){
		printf("YES\n");
		return 0;
	}
	if (sum % (1LL * n * (n + 1) / 2)){
		printf("NO\n");
		return 0;
	}
	tot = sum / (1LL * n * (n + 1) / 2);
	if (tot + a[n] - a[1] < 0 || (tot + a[n] - a[1]) % n > 0){
		printf("NO\n");
		return 0;
	}
	for (int i = 1; i < n; i++){
		if (tot + a[i] - a[i + 1] < 0 || (tot + a[i] - a[i + 1]) % n > 0){
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi c(n-1), s(n-1), f(n-1);
    rep(i, n-1) cin >> c[i] >> s[i] >> f[i];
    rep(i, n) {
        int t = 0;
        for (int j=i; j<n-1; ++j) {
            t = max(t, s[j]);
            t = (t + f[j] - 1) / f[j] * f[j] + c[j];
        }
        cout << t << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int taxchange(int val, int x){
    return (int)ceil((val * 100) /(100.0+x));
}

int main() {
    int x, y, s;
    int maxim;
    for(;;){
        cin >> x >> y >> s;
        if(x == 0) break;
        maxim = 0;
        for(int i=1 ; i<s ; i++){
            if((taxchange(i,x)*(100+x))/100 != i) continue;
            if((taxchange(s-i,x)*(100+x))/100 != s-i) continue;
            maxim = max(maxim,(taxchange(i,x)*(100+y))/100 + (taxchange(s-i,x)*(100+y))/100 );
        }
        cout << maxim << endl;
    }
    return 0;
}



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

int main()
{
    string N;
    int sum = 0;

    cin >> N;

    for (char c : N)
    {
        sum += (int)(c - '0');
    }

    if (stoi(N) % sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String[] A = sc.next().split("");
		String[] B = sc.next().split("");
		String[] C = sc.next().split("");

		int result = 0;
		for (int i = 0; i < N; i++) {
			Map<String, Integer> map = new HashMap<String, Integer>();
			map.put(A[i], 0);
			if (map.get(B[i]) == null) {
				map.put(B[i], 0);
			} else {
				map.put(B[i], map.get(B[i]) + 1);
			}

			if (map.get(C[i]) == null) {
				map.put(C[i], 0);
			} else {
				map.put(C[i], map.get(C[i]) + 1);
			}

			if (map.size() == 3) {
				result += 2;
			} else if (map.size() == 2) {
				result++;
			}
		}

		System.out.println(result);

	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    cin >> a;
    rep3(i, k, n) {
        if (a[i - k] < a[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 4788
//38
#include<iostream>
#include<string>

using namespace std;

int main(){
  string s;
  cin>>s;
  int n;
  cin>>n;
  int ans=0;
  while(n--){
    string t;
    cin>>t;
    ans+=(t+t).find(s)!=string::npos;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  long long a[n];
  REP(i, n) cin>>a[i];
  
  typedef pair<long long, int> P;
  vector<P> vec;
  REP(i, n) vec.push_back(P(a[i], i));
  sort(ALL(vec)); reverse(ALL(vec));
  
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, -INF));
  dp[0][0] = 0;
  for(int s = 0; s < n; s++){
    for(int x = 0; x <= s; x++){
      int y = s - x;
      int i = vec[x + y].second;
      int p_i = x;
      dp[x + 1][y] = max(dp[x + 1][y], dp[x][y] + a[i] * (long long)(i - p_i));
      p_i = n - (y + 1);
      dp[x][y + 1] = max(dp[x][y + 1], dp[x][y] + a[i] * (long long)(p_i - i));
    }
  }
  long long ans = 0;
  REP(x, n + 1) REP(y, n + 1) if(x + y == n) ans = max(ans, dp[x][y]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 34692
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll cnt = 0;
  rep(i, n) {
    if (a[i] < b[i]) {
      cnt += (b[i] - a[i]) / 2;
    } else {
      cnt -= a[i] - b[i];
    }
  }
  if(cnt < 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REPEACH(itr, k) for (auto &&itr : k)
#define MOD 1000000007

using namespace std;
typedef long long ll;

const ll INF = 1LL<<60;
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;}

int main()
{
    int n,k;
    cin >> n >> k;
    vector<ll> v;
    ll ans=INF;
    REP(i,n){
        int input;
        cin >> input;
        v.push_back(input);
        if(i>=k-1){
            chmin(ans, min(abs(v[i]),abs(v[i-k+1]))+abs(v[i]-v[i-k+1]));
        }
    }
    cout << ans << endl;
}

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

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ
int main()
{
    int a, b;
    cin >> a >> b;
    if ((a % 2 == 0 && b % 2 == 0) || (a % 2 == 1 && b % 2 == 1))
        cout << (a + b) / 2;
    else
        cout << (a + b) / 2 + 1;
}

Measured memory_bytes: 256
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
	ll N;
	cin >> N;
	string s;
	ll pow = 0;
	while (true) {
		if (((N % 2) + 2) % 2 == 1) {
			s.push_back('1');
			N -= (pow % 2 == 0) ? 1 : (-1);
		} else {
			s.push_back('0');
		}
		N /= 2;
		if (N == 0) {
			break;
		}
		pow++;
	}
	reverse(s.begin(), s.end());
	cout << s << endl;
}


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

using namespace std;

int CardNumber[100];

int main() {
	int len, sum;
	string str;
	stringstream ss;

	while (1) {
		getline(cin, str);
		if (str.size() == 1 && str[0] == '0') {
			break;
		}
		memset(CardNumber, 0, sizeof(CardNumber));
		len = 0;
		ss << str;
		while (ss >> CardNumber[len]) {
			len++;
		}
		sort(CardNumber, CardNumber + len);

		/*cout << len << endl;
		for (int i = 0; i < len; i++) {
			cout << CardNumber[i] << ends;
		}
		cout << endl;*/

		sum = 0;
		for (int i = len - 1; i > -1; i--) {
			if (CardNumber[i] != 1) {
				sum += min(CardNumber[i], 10);
			}
			else {
				if (sum + i < 11) {
					sum += 11;
				}
				else {
					sum++;
				}
			}
		}

		sum = sum > 21 ? 0 : sum;
		cout << sum << endl;
		
		ss.clear();
		str = "";
	}

	return 0;
}


Measured memory_bytes: 3088
/*Author: Gautam*/


#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#define MODULO 1000000007
#define ull unsigned long long int
#define newline cout<<endl


/* TYPE DEFINITIONS */
typedef		long long		ll;
typedef		vector<int>		vi;
typedef		pair<int,int>	pi;



/* ALGEBRA */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

/* MACROS */

#define  all(A)			(A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)		(A).rbegin() , (A).rend()
#define  sz(A)			(int)(A).size()
#define  pb				push_back
#define  ppb			pop_back
#define  mp				make_pair
#define  ln(X)			(int)(X).length()
#define  square(X)		((X)*(X))
#define  cube(X)		((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)	for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 
bool painted[10005];
void solve()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(c-(a-b)<0)cout<<0;
    else cout<<c-(a-b)<<endl;
}

int main()
{
	FastIO;
	ll t=1;
    //cin>>t;
	while(t--)
    {
        
        solve();
    }
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))

p = sum(x)//n
ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += (x[i]-p) ** 2

for i in range(n):
    ans2 += (x[i]-(p+1)) ** 2

print(min(ans1, ans2))

Measured memory_bytes: 3064
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

string calc(string s){
    long long ans = 0;
    for(long long i = 0; i < s.size(); i++){
        ans += ll(s[i] - '0');
    }
    string t = to_string(ans);
    return t;
}

int main(){
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    string n; cin >> n;

    while(1){
        n = calc(n);
        if(n.size() < 18){
            long long a = stoll(n);
            if(a % 9 == 0){
                cout << "Yes";
            }
            else {
                cout << "No";
            }
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3780
import Control.Monad
main=do
 [h,w]<-map read.words<$>getLine
 a<-replicateM h ((\x->'#':x++"#\n")<$>getLine)
 putStrLn((\x->x++"\n"++(concat a)++x)(f w))
  where f 0 = "##"
        f w = '#':(f (w-1))

Measured memory_bytes: 1404
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();
        
        if(s.equals(u)){
            a--;
        }
        else{
            b--;
        }
        
        System.out.println(a+" "+b);
    }
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
bool cmp(int k,int l){
	return k>l;
}
int main() {
	long long int n,m;
	cin>>n>>m;
	long long int a[n+1],sum=0;
	a[0]=1e9;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	sort(a+1,a+n+1,cmp);
	double least=sum*(1.0/(4*m));
	if(a[m]>=least){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;

int main() {
    ll n, a, b; cin >> n >> a >> b;
    if (a > b || (n == 1 && a != b)) {cout << 0 << endl; return 0;}
    cout << ((n - 1) * b + a - ((n - 1) * a + b)) + 1 << endl;
        
}


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

list_button_coin_1 = [A, B]
list_button_coin_2 = [A-1, B-1]
list_total_coin = []

for i in list_button_coin_1:
	for j in list_button_coin_2:
		list_total_coin.append(i+j)
		
list_total_coin.append(A+B)

print(max(list_total_coin))

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

int main(){long N, M;
cin >> N >> M;
vector<long> a(M + 1);
vector<long> b(M + 1);
erep(i, M) cin >> a.at(i) >> b.at(i);
vector<long> c(N + 1);
erep(i, M){
    c.at(a.at(i))++;
    c.at(b.at(i))++;
}
erep(i, N) cout << c.at(i) << endl;



// cout << v.at(0) << endl;
return 0;
}




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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    vector<int> memo(n);
    for(int i = 0; i < n; ++i) {
        memo[i] = (s[i] == 'R' ? i+1 : i-1);
    }
    for(int i = 0; i < 100; ++i) {
        vector<int> newMemo = memo;
        for(int j = 0; j < n; ++j) {
            newMemo[j] = memo[memo[j]];
        }
        memo = newMemo;
    }
    vector<int> res(n,0);
    for(int i = 0; i < n; ++i) {
        ++res[memo[i]];
    }
    for(int i = 0; i < n; ++i) {
        cout << res[i] << ' ';
    }
    cout << '\n';
}


Measured memory_bytes: 2116
#[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")
    };
}

fn main() {
    input!{
        n:i64,
        k:i64,
    }
    let mut ans = 0;
    if k==1 {
        ans = 0;
    }else{
        ans = n - k;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:05:16 2020

@author: asaka
"""

N = int(input())
ans = [0]*4

for n in range(N):
    h = input()
    if h == "AC":
        ans[0] += 1
    elif h == "WA":
        ans[1] += 1
    elif h == "TLE":
        ans[2] += 1
    elif h == "RE":
        ans[3] += 1
        
print("AC x ", ans[0])
print("WA x ", ans[1])
print("TLE x ", ans[2])
print("RE x ", ans[3])


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

int main() {
  int n; cin >> n;
  string str[36],str2[36];
  
  for ( int i = 0; i < n; i++ ) {
    cin >> str[i];
    str2[i] = str[i];
  }
  
  for ( int i = 0; i < n-1; i++ ) {
    for ( int j = n-1; j >= i+1; j-- ) {
    int num1,num2;
    num1 = str[j][1] - '0';
    num2 = str[j-1][1] - '0';
      
    if ( num1 < num2 ) swap(str[j],str[j-1]);
  
    }
  }

  for ( int i = 0; i < n; i++ ) {
    int minj = i;
    for ( int j = i; j < n; j++ ) {
      int num1,num2;
      num1 = str2[j][1] - '0';
      num2 = str2[minj][1] - '0';
      if ( num1 < num2 ) minj = j;

    }
    swap(str2[i],str2[minj]);

  }
  
  for ( int i = 0; i < n-1; i++ ) cout << str[i] << " ";
  cout << str[n-1] << endl;
  cout << "Stable" << endl;
  
  for ( int i = 0; i < n-1; i++ ) cout << str2[i] << " ";
  cout << str2[n-1] << endl;
  
  bool flag = true;
  for ( int i = 0; i < n; i++ ) {
    if ( str[i] != str2[i] ) flag = false;
  }

  if ( flag == true ) cout << "Stable" << endl;
  else cout << "Not stable" << endl;

  return 0;
}

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

int main(){
    int n;
    cin >> n;
    int A[n+1];
    for(int i=1;i<=n;i++) cin >> A[i];
    for(int i=1;i<=n;i++){
        cout << "node " << i << ": key = " << A[i] << ", ";
        if(i/2<=n&&i/2>=1) cout <<  "parent key = " << A[i/2] << ", ";
        if(2*i<=n&&2*i>=1) cout << "left key = " << A[2*i] << ", ";
        if(2*i+1<=n&&2*i+1>=1) cout << "right key = " << A[2*i+1] << ", ";
        cout << endl;
    }
    return 0;
}





Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int ans = 0;
    for(int l = 40; l >= 0; l--){
        int x = 0;
        for(int i = 40; i >= 0; i--){
            if(i >= l && k & (1LL << i)){
                x += 1LL << i;
                continue;
            }
            int c0 = 0, c1 = 0;
            rep(j, 0, n){
                if(a[j] & (1LL << i)){
                    c1++;
                }else{
                    c0++;
                }
            }
            if(c0 > c1){
                int tmp = x + (1LL << i);
                if(tmp <= k) x = tmp;
            }
        }
        int tmp = 0;
        rep(i, 0, n){
            tmp += x ^ a[i];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int fr = 0;
string s;
void getBase() {
	cout << 0 << "\n" << flush;
	cin >> s;
	if (s[0] == 'F')
		fr = 1;
	if (s[0] == 'V')
		exit(0);
	return;
}
bool isval(int md) {
	cout << md << "\n" << flush;
	cin >> s;
	int kn = 0;
	if (s[0] == 'F')
		kn = 1;
	if (s[0] == 'V')	
		exit(0);
//	cout << "kn = " << kn << " md = " << md << endl;
	if (md % 2 == 0) {
		if (kn == fr) 
			return true;
	}
	else {
		if (kn != fr)
			return true;
	}
	return false;
}
int main() {
	int n;
	cin >> n;
	getBase();
	int dw = 0, up = n - 1;
//	cout << "fr = " << fr << endl;
	while (up - dw > 1) {
		int md = (up + dw) / 2;
//		cout << "Up = " << up << " Dw = " << dw << endl;
		if (isval(md)) {
//			cout << "TRUE\n";
			dw = md;
		}
		else {
//			cout << "FALSE\n";
			up = md;
		}
	}
	cout << up << "\n" << flush;
	return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	double sum=0;
	cin>>n;
	REP(i,n){
		double n;
		string s;
		cin>>n>>s;
		if(s=="JPY"){
			sum+=n;
		}else{
			sum+=(n*380000);
		}
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
def min(list):
	min=10000000000
	for i in range(len(list)):
		if list[i]<min:
			min=list[i]
		else:
			pass
	return min

N,x=map(int,input().split())
a=list(map(int,input().split()))
C=0
p=0
while C<x:
	if p==N:
		C=x
		p=p-1
	elif C+min(a)<=x:
		C=C+min(a)
		a.remove(min(a))
		p=p+1
	else:
		C=x
print(p)

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

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


int main()
{
    ll n,ans=0;
    cin>>n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    /*
    sort(all(a));
    for (int i = 0; i < n; i++)
    {
        //cout<<i<<" "<<a[i]<<endl;//
        bool ok=true;
        if(i==0 && n>1 && a[i]==a[i+1])
        {
            ok=false;
        }
        for (int j = 0; j < i; j++)
        {
            if(a[i]%a[j]==0)
            {
                //cout<<"false "<<a[j]<<endl;//
                ok=false;
                break;
            }
        }
        if(ok) ans++;
    }
    */

    unordered_map<ll, ll> mp;
    for (int i = 0; i < n; i++)
    {
        if(mp.find(a[i])==mp.end())
        {
            mp.emplace(make_pair(a[i],1LL));
        }
        else
        {
            mp[a[i]]++;
        }        
    }
    for (int i = 0; i < n; i++)
    {
        bool ok=true;
        auto div=divisor(a[i]);
        for (int j = 0; j < div.size(); j++)
        {
            if(mp.find(div[j])!=mp.end())
            {
                if(div[j]!=a[i])
                {
                    ok=false;
                    break;
                }
                else
                {
                    if(mp[div[j]]>1)
                    {
                        ok=false;
                        break;
                    }
                }
                
            }
        }
        if(ok) ans++;
    }
    
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12944
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [usize; n],
    }

    a.sort();

    let mut ans = a[n - 1];
    let mut cnt = 1;
    for ai in a.iter().rev().skip(1) {
        if cnt < n - 2 {
            cnt += 2;
            ans += 2 * ai;
        } else if cnt == n - 2 {
            cnt += 1;
            ans += ai;
        } else {
            break;
        }
    }

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


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

using namespace std;
#define BUF (53)
#define INF (100)

int N,M;

int A[BUF][BUF];
int c[BUF][BUF];
int a[BUF];
int b[BUF];


void wf(void){
    for(int k=1;k<=N;k++) for(int i=1;i<=N;i++) for(int j=1;j<=N;j++){
        if(c[i][j] > c[i][k]+c[k][j]) c[i][j] = c[i][k]+c[k][j];   
    }
}

int ans = 0;
int main(void){
	cin >> N >> M;
	for(int i=0;i<BUF;i++)for(int j=0;j<BUF;j++) A[i][j]=INF;
	for(int i=1;i<=M;i++){
		cin >> a[i] >> b[i];
		A[a[i]][b[i]] = 1;
		A[b[i]][a[i]] = 1;
	}

	for(int i=1;i<=M;i++){
		for(int i=0;i<BUF;i++)for(int j=0;j<BUF;j++) c[i][j]=A[i][j];
		c[a[i]][b[i]]=INF;
		c[b[i]][a[i]]=INF;
		wf();
		if(c[a[i]][b[i]]==INF) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, x;
  cin >> N >> x;

  if(x == 1 || x == 2*N-1){
    No;
    return 0;
  }
  if(N == 2){
    if(x == 1) No;
    else{
      Yes;
      cout << 1 << endl;
      cout << 2 << endl;
      cout << 3 << endl;
    }
    return 0;
  }

  vector<int> ans(2*N-1, 0);
  vector<bool> used(2*N, false);
  if(x == 2){
    ans[N-2+0] = 4;
    ans[N-2+1] = 2;
    ans[N-2+2] = 1;
    ans[N-2+3] = 3;

    used[1] = true;  used[2] = true;  used[3] = true;  used[4] = true;
  }else{
    ans[N-2+0] = x-1;
    ans[N-2+1] = x+0;
    ans[N-2+2] = x+1;
    ans[N-2+3] = x-2;

    used[x-2] = true;  used[x-1] = true;  used[x+0] = true;  used[x+1] = true;
  }
  
  int c = 1;
  REP(i, N*2-1){
    if(ans[i]) continue;
    while(used[c]) c++;
    ans[i] = c++;
  }

  Yes;
  REP(i, N*2-1) cout << ans[i] << endl;

  return 0;
}

Measured memory_bytes: 3072
while True:
    t = int(input())
    if t==0:
        break
    n = (1000-t)//500+((1000-t)%500)//100+((1000-t)%100)//50+((1000-t)%50)//10+((1000-t)%10)//5+((1000-t)%5)
    print(n)



Measured memory_bytes: 5592
using System;
using System.Linq;
class A
{
    static void Main()
    {
        string S = Console.ReadLine();
        int F = int.Parse(S.Substring(0, 2));
        int B = int.Parse(S.Substring(2, 2));
        if (F == 00 && B == 00) Console.WriteLine("NA");
        else if (F >= 13 && B == 00) Console.WriteLine("NA");
        else if (B >= 13 && F == 00) Console.WriteLine("NA");
        else if (1 <= F && F <= 12 && B >= 1 && B <= 12) Console.WriteLine("AMBIGUOUS");
        else if (B <= 12 && F == 00) Console.WriteLine("YYMM");
        else if (F <= 12 && B == 00) Console.WriteLine("MMYY");
        else if (B <= 12) Console.WriteLine("YYMM");
        else if (F <= 12) Console.WriteLine("MMYY");
        else Console.WriteLine("NA");
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int I=X;I<Y;I++)
#define REP(I,X,Y) for(int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

int main(){
  long long N,ans=0;
  cin >> N;
  long long DP[N];
  vector<long long> A(N),B(N),C(N);
  FOR(i,0,N)cin >> A[i];
  FOR(i,0,N)cin >> B[i];
  FOR(i,0,N)cin >> C[i];
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  FOR(i,0,N)DP[i] = C.end() - upper_bound(C.begin(),C.end(),B[i]);
  REP(i,0,N-1)DP[i] += DP[i+1];
  FOR(i,0,N)if(0 < B.end() - upper_bound(B.begin(),B.end(),A[i]))ans += DP[upper_bound(B.begin(),B.end(),A[i]) - B.begin()];
  cout << ans << endl;
}


Measured memory_bytes: 3328
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdio.h>

using namespace std;




int x[200005];
int y[200005];
int main()
{
    int n;
	cin>>n;
	for(int i=1;i<=n;i++) 
	{
		scanf("%d",&x[i]);
		y[i] = x[i];
	}
	sort(y+1,y+1+n);
	int temp=(y[n/2]+y[n/2+1])/2;
	for(int i=1;i<=n;i++)
	{
		if(x[i]>temp)printf("%d\n",y[n/2]);
		else printf("%d\n",y[n/2 +1]);
	}

    return 0;
}  

Measured memory_bytes: 3712