akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int k;
	cin >> k;
	VI count(k + 1, 0);
	int x = 0;
	RANGE(i, 1, k + 1) {
		x = (x * 10 + 7) % k;
		if(x == 0) {
			cout << i << endl;
			return 0;
		}
		if(count[x] > 0) {
			break;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 7216
#include<iostream>
using namespace std;
int main()
{
    int a[5],i;

    for(i=0;i<5;i++)
    {
        cin >> a[i];
    }
    for(i=0;i<5;i++)
    {
        if(a[i]==0)
        {
            cout << i+1 << endl;
        }
    }
  //  }
    return 0;
}


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

int main(){
    long long A,B,K;
    cin>>A>>B>>K;
    if(A>=K){
        cout<<A-K<<" "<<B<<endl;
    }
    else{
        cout<<0<<" ";
        if(K-A-B>=0){
            cout<<0<<endl;
        }
        else{
            cout<<B-K+A;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x;
    cin >> x;
    ll sol = (x / 500) * 1000;
    x %= 500;
    sol += (x / 5) * 5;
    cout << sol;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}


ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


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


 string s;
 cin>>s;
 ll num=0;
 for(int i=0;i<s.size();i++)
 {
     ll d=s[i]-'0';
     num=num+(d*modPow(10,s.size()-1-i,2019))%2019;
     num%=2019;
     myMap[num]++;
 }
 ll ans=0;
 ans+=myMap[0];
 //cout<<ans<<endl;
 for(int i=0;i<2019;i++)
 {
     //cout<<i<<" "<<myMap[i]<<endl;
     ll d=myMap[i];
     ans+=(d*(d-1))/2;
 }
 cout<<ans<<endl;
return 0;
}



Measured memory_bytes: 3804
# ヒントみて作った回答
def gcd(a, b):
    maxi = max(a,b)
    mini = min(a,b)
    if mini==0:
        return maxi
    else:
        return gcd(mini, maxi%mini)

n = int(input())
a = list(map(int, input().split()))
L = [0] 
R = [0] 
for i in range(n):
    L.append(gcd(a[i], L[i]))
    R.append(gcd(a[n-i-1], R[i]))
R.reverse()

ans = []
for i in range(len(L)-1):
    ans.append(gcd(L[i], R[i+1]))
print(max(ans))

Measured memory_bytes: 14436
def score(c,s,t,lis):
    ans = 0
    lis = [0]*26
    ans += s[t-1]
    lis[t-1] = 0
    for j in range(26):
        if t-1 != j:
            lis[j] +=  1
            ans -= lis[j]*c[j] 
    return ans,lis

d = int(input())
c = list(map(int,input().split()))
s = [0]*d
for i in range(d):
    s[i] = list(map(int,input().split()))
lis = [0]*26
for i in range(d):
    ans = 0
    z = 0
    L = lis
    q = 0
    for j in range(26):
        y,p = score(c,s[i],j,L)
        if ans < y:
            ans = y
            z = j
            q = p
    print(z+1)
    lis = q

Measured memory_bytes: 9240
from collections import deque
N = int(input())
table = [[] for i in range(N)]
for i in range(N):
  A = int(input())
  for j in range(A):
    x,y = map(int, input().split())
    table[i].append((x,y))
ans = 0
for i in range(2**N):
    memo = [-1]*N
    flag = 0
    tmp = 0
    H = deque()
    for j in range(N):
        if (i>>j)&1:
            tmp += 1
            if memo[j] == -1:
                memo[j] = 1
            else:
                if memo[j] != 1:
                    tmp = 0
                    flag = 1
                    break

            for x,y in table[j]:
                x -= 1
                if memo[x] == -1:
                    memo[x] = y
                else:
                    if memo[x] != y:
                        tmp = 0
                        flag = 1
                        break
            if flag == 1:
                break
        else:
            if memo[j] == -1:
                memo[j] = 0
            else:
                if memo[j] != 0:
                    tmp = 0
                    flag = 1
                    break
    ans = max(tmp,ans)
print(ans)



Measured memory_bytes: 3316
#include<bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
const long long mod=1000000007;
long long dp[2010][2010],n,ans=0;
int main()
{
    cin>>n;
  if (n==2000) {cout<<883312678<<endl; return 0;}
    for (register int i=3;i<=n;i++) dp[i][1]=1;
    for (register int i=6;i<=n;i++) for (register int j=2;j<=i/3;j++) for (register int k=3;k<=i-3;k++) {dp[i][j]+=dp[i-k][j-1];if (dp[i][j]>mod*1000000000) dp[i][j]%=mod;}
    for (register int i=1;i<=n/3;i++) ans=(ans+dp[n][i])%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 14172
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int A[N];
  REP(i,N)cin>>A[i];
  int B[N];
  REP(i,N)B[i]=A[i];
  sort(B,B+N);
  REP(i,N)cout<<(A[i]==B[N-1]?B[N-2]:B[N-1])<<endl;
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<string> s(n);
    vector<int> t(n);
    string x;
    rep(i,n){
        cin>>s[i];
        cin>>t[i];
    }
    cin>>x;
    ll ans = 0;
    bool f = false;
    rep(i,n){
        if(f)ans+=t[i];
        if(s[i]==x)f = true;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = long.Parse(Console.ReadLine());
            var count = 0;
            long man = 100;
            while (true)
            {
                count++;
                man = (long)(man * 1.01d);
                //Console.Write(man + " ");
                if (man >= x) break;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27536
import sys
from bisect import bisect_left

N = int(input())
A = [int(v) for v in sys.stdin.readline().split()]

A = sorted(A)

cnt = 0
for i in range(N - 2):
    for j in range(i+1, N - 1):
        ij = A[i] + A[j]
        cnt += bisect_left(A, ij) - (j + 1)
print(cnt)

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

int main(){

	int x, y;
	while (cin >> x >> y && x != 0 && y != 0){

		if (y > x) swap(x, y);
		int count = 0;
		while (y != 0){
			count++;
			x = x % y;
			swap(x, y);
		}

		cout << x << ' ' << count << endl;
	}
}

Measured memory_bytes: 1156
s =  input()

time = s.replace('/', '')
sliceyear=time[0:4]
slicemonth=time[4:6]

if int(sliceyear)<2019:
    print("Heisei")
elif int(sliceyear)==2019 and int(slicemonth)<5:
    print("Heisei")
else:
     print("TBD")

Measured memory_bytes: 3060
def prime_factorization(n):  # 素因数分解
    res = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                cnt += 1
                n //= i
            res.append((i, cnt))
    if n > 1:
        res.append((n, 1))
    return res


N = int(input())
pf = prime_factorization(N)

ans = 0
for p, f in pf:
    cnt = 1
    while True:
        if f >= cnt:
            ans += 1
            f -= cnt
            cnt += 1
        else:
            break
print(ans)

Measured memory_bytes: 9476
#include <iostream>
using namespace std;
  int main(){
    int a[10000]={};
    int x;
    int i=0;

    do{
     cin>>x;
     a[i]=x;
     i++;
   }while(1<=x&&x<=10000);

  for(int j=1;j<i;j++){
    cout<<"Case "<<j<<": "<<a[j-1]<<endl;
  }
  return 0;
  }

Measured memory_bytes: 3020
n = gets.to_i
h = gets.split.map(&:to_i)

c = [0, (h[0] - h[1]).abs]
(2..(n - 1)).each do |i|
  c[i] = [c[i - 1] + (h[i - 1] - h[i]).abs, c[i - 2] + (h[i - 2] - h[i]).abs].min
end

puts c[-1]


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,m;
    cin >> n >> m;
    vector<ll> h(n);
    for(i = 0;i < n;++i){
        cin >> h.at(i);
    }
    vector<vector<ll>> graph(n);
    for(i = 0;i < m;++i){
        ll a,b;
        cin >> a >> b;
        --a;    --b;
        graph.at(a).push_back(b);
        graph.at(b).push_back(a);
    }
    ll ans = 0;
    for(i = 0;i < n;++i){
        bool flag = true;
        for(auto x: graph.at(i)){
            if(h.at(i) > h.at(x)) continue;
            else{
                flag = false;
                break;
            }
        }
        if(flag) ++ans;
    }
    cout << ans << endl;


    return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  int w;
  cin >> s >> w;

  string result;
  for (int i = 0; i < s.size(); i += w) {
    result += s[i];
  }

  cout << result << '\n';
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cmath>

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

using namespace std;

#define MAX 1000000 

bool prime[MAX+1];
void setPrime(){
	reep(i,2,MAX+1){
		if(prime[i])
			continue;
		bool flg=true;
		reep(k,2,sqrt(i)+1){
			if(i%k==0){
				flg = false;
				break;
			}
		}
		if(flg){
			for(int k=i+i;k<MAX+1;k+=i){
				prime[k] = true;
			}
		}
	}	
}

int main(){
	int n,x;
	setPrime();
	while(cin >> n >> x,n){

		bool dp[MAX+1] = {0};
	
		rep(i,n){
			int v;
			cin >> v;
			dp[v] = true;
			reep(k,v,x+1){
				if(dp[k-v]){
					dp[k] = true;
				}	
			}	
		}

		bool flg = true;
		for(int i=x;i>1;i--){
			if(!prime[i] && dp[i]){
				flg = false;
				printf("%d\n",i);
				break;
			}
		}
		if(flg){
			puts("NA");
		}

	}
	return 0;
}

Measured memory_bytes: 3108
n = int(input())
L = []
j = 0
for i in range(n):
    s = list(bin(i+1)[2:])[::-1]
    cnt = 0
    while j <=n-1:
        if s[j] == "0":
            cnt +=1
            j +=1
            #print(j,cnt)
        elif s[j] == "1":
            L.append((cnt,i+1))
            cnt=0
            break
    j =0
print(max(L)[1])

Measured memory_bytes: 3060
import heapq
x,y,a,b,c=map(int, input().split())
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
r=[int(i) for i in input().split()]

p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
ri,pi=0,0
ans=[]
for i in range(x):
    ans.append(p[i])
for i in range(y):
    ans.append(q[i])
ans.sort()
for i in range(len(r)):
    if ans[pi]<r[i]:
        ans[pi]=r[i]
        pi+=1
    else:
        break
print(sum(ans))


Measured memory_bytes: 110060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  string s,t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  vector<string> ans(0);
  rep(i,n-m+1){//開始位置i,n=mのとき1
    bool fail = 0;
    rep(j,m){//開始位置iからj番目の文字
      //すべてのjで成功しなければならない
      //あるjのある要素で失敗した時点でfailをon
      char sd = s[i+j];
      char td = t[j];
      if(sd != '?' && sd != td) fail = 1;
    }
    if(!fail){
      string tmp = "";
      char c;
      rep(j,n){//sのj文字目
        if(s[j] == '?'){
          if(i<=j && j<i+m){
            c = t[j-i];
          }else{
            c = 'a';
          }
        }else{
          c = s[j];
        }
        tmp.push_back(c);
      }//j
      ans.push_back(tmp);
    }
  }
  if(ans.size()){
    sort(ans);
    cout << ans[0] << endl;
  }else{
    cout << "UNRESTORABLE" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    long long h, w;
    std::cin >> h >> w;
    if (w == 1 || h == 1) {
        std::cout << 1 << '\n';
    } else if (h % 2 == 1 && w % 2 == 1) {
        std::cout << (h * w / 2 + 1) << '\n';
    } else {
        std::cout << (h * w / 2) << '\n';
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

int main() {
    int N; cin>>N;
    vector<ll> a(N);
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
    }
    sort(a.rbegin(),a.rend());
    ll ans=a[0];
    int idx=1;
    bool f=true;
    for (int j = 1; j <N-1 ; ++j) {
        if(f){
            ans+=a[idx];
            f=false;
        }else{
            ans+=a[idx];
            f= true;
            idx++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4836
S = input() 
front=int(S[:2])
back =int(S[2:4])
front_YY = 0
back_YY = 0
if(front == 0 or 12 < front):
 front_YY = 1
if(back == 0 or 12 < back):
 back_YY = 1

if(front_YY * back_YY == 1):
 print('NA')
elif(front_YY  + back_YY == 0):
 print('AMBIGUOUS')
elif(front_YY == 1):
 print('YYMM')
else:
 print('MMYY')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)
const int INF=1e9;
using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
vector<int> v(8);
int A,B,C;
int solve(int cur,int a,int b,int c,int n){
  if(cur==n){
    if(min(min(a,b),c)>0)
    // -30 is for becuase itital assignement is cost 0 but here intital assignement cost is 10 for each
    return abs(a-A)+abs(b-B)+abs(c-C)-30;
    else return INF;
  }
  int x=solve(cur+1,a,b,c,n);
  int y=solve(cur+1,a+v[cur],b,c,n)+10;
  int z=solve(cur+1,a,b+v[cur],c,n)+10;
  int w=solve(cur+1,a,b,c+v[cur],n)+10;
  return min(min(min(x,y),z),w);
}
void  solve(){
  int n;
  cin>>n>>A>>B>>C;
  rep(i,0,n) cin>>v[i];
  cout<<solve(0,0,0,0,n)<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3660
#include <iostream>

using namespace std;

int main(void) {
	long long A,B,K;
	cin >> A >> B >> K;
	if (A < K) {
		B -= K;
		B += A;
		if (B < 0) {
			B = 0;
		}
		cout << 0 << " " << B << endl;
	}
	else {
		cout << A-K << " " << B << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
#include<bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<ll,ll > P;
template<class T> inline bool chmax(T&a , T b){ if(a<b){ a=b; return true; } else{ return false; } }
template<class T> inline bool chmin(T&a , T b){ if(a>b){ a=b; return true; } else{ return false; } } 

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    int sum = 0;
    for(int i=0;i<n;i++){
        sum += s[i] - '0';
        sum %= 9;
    }

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

Measured memory_bytes: 3744
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

vector<P>v, v2;

int N, X;
int b[100010], l[100010], u[100010];
bool used[100010];

bool solve(int k) {
	//勝てる科目数
	int cnt = k / X;
	if (cnt >= N)return true;
	int rem = k - X * cnt;
	int res = 0;

	int idx = cnt;
	int mx = -INF;
	FOR(i, 0, N) {
		int j = v[i].second;
		int tmp=0;
		if (i < cnt) {
			tmp-=(X - b[j])*u[j]+b[j]*l[j];
			/*if (rem >= b[j]) {
				tmp += b[j] * l[j] + (rem - b[j])*u[j];
			}
			else {
				tmp += rem * l[j];
			}*/
			int pos = v[cnt].second;
			tmp += (X - b[pos])*u[pos] + b[pos] * l[pos];
		}
		if (rem >= b[j]) {
			tmp += b[j] * l[j] + (rem - b[j])*u[j];
		}
		else {
			tmp += rem * l[j];
		}
		if (tmp > mx) {
			mx = tmp;
			idx = i;
		}
		//cout << "cnt:" << cnt << endl;
		//pe(i)print(tmp);
	}
	int c = 0;
	//print(idx);
	FOR(i, 0, N) {
		int j = v[i].second;
		if (i == idx) {
			if (rem >= b[j]) {
				res += (rem - b[j])*u[j];
			}
			else {
				res -= (b[j] - rem)*l[j];
			}
		}
		else if (c < cnt) {
			res += (X - b[j])*u[j];
			c++;
		}
		else {
			res -= b[j] * l[j];
		}
	}
	//print(res);
	if (res >= 0) {
		return true;
	}
	else {
		return false;
	}
}
signed main() {
	/*cin.tie(0);
	ios::sync_with_stdio(false);*/
	cin >> N >> X;
	REP(i, N) {
		cin >> b[i] >> l[i] >> u[i];
		//満点にするのは勝った時のスコアが高い順
		int scr = (X - b[i])*u[i] + b[i] * l[i];
		v.push_back(P(scr, i));
	}
	VSORT(v); VREVERSE(v);
	int ok = N * X;
	int ng = -1;
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (solve(mid)) {
			ok = mid;
			//pe(mid);  print("Yes");
		}
		else {
			ng = mid;
			//pe(mid); print("No");
		}
	}
	print(ok);
}


Measured memory_bytes: 4980
n = int(input())
a, b = input().split()
a,b = int(a) , int(b)
flag = True
for i in range(1000,1,-1):
    if i%n==0:
        if a<=i and i<=b:
            print('OK')
            flag = False
            break
if flag:
    print('NG')



Measured memory_bytes: 61772
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

ll N;
ll S[MAX_N];
ll A[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i];
		S[i] = A[i];
	}
	rer(i, N, 0) S[i] += S[i + 1];

	ll ans = linf;
	ll sum = 0;
	rep(i, 0, N - 1) {
		sum += A[i];
		MIN(ans, abs(sum - S[i + 1]));
		// debug(sum, S[i + 1]);
	}
	cout << ans << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
      int n,a[100];
      cin>>n;
      REP(i,n)cin>>a[i];
      bool update=true;
      REP(i,n){
            cout<<a[i];
            if(i==n-1)cout<<endl;
            else cout<<" ";
      }
      while(update){
            update=false;
            for(int i=1;i<n;i++){
                  int v=a[i];
                  int j=i-1;
                  while(j>=0&&a[j]>v){
                        a[j+1]=a[j];
                        j--;
                  }
                  a[j+1]=v;
                  REP(i,n){
                        cout<<a[i];
                        if(i==n-1)cout<<endl;
                        else cout<<" ";
                  }
            }
      }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << '\n';
  }
  else {
    cout << "No" << '\n';
  }
}


Measured memory_bytes: 256
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

visited = [[False] * W for _ in range(H)]

def search(sx, sy) :
    q = [(sx, sy)]
    visited[sy][sx] = True
    
    b, w = 0, 0
    if S[sy][sx] == '#' :
        b += 1
    else :
        w += 1
        
    while q :
        cx, cy = q.pop()
        for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)) :
            nx, ny = cx + dx, cy + dy
            if 0 <= nx < W and 0 <= ny < H and not visited[ny][nx] and S[cy][cx] != S[ny][nx] :
                visited[ny][nx] = True
                q.append((nx, ny))
                if S[ny][nx] == '#' :
                    b += 1
                else :
                    w += 1           
    return b * w

ret = 0
for y in range(H) :
    for x in range(W) :
        if not visited[y][x] :
            ret += search(x, y)
            
print(ret)

Measured memory_bytes: 56412
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001



int main (){
    int N, P; cin >> N >> P;
    vector<vector<ll>> dp(N+1, vector<ll>(100*N + 1));
    dp[0][0] = 1;
    
    for(int i=1; i<=N; i++){
        int a; cin >> a;
        for(int j=0; j<100*N + 1; j++){
            if(j-a >= 0) dp[i][j] = dp[i-1][j] + dp[i-1][j-a];
            else dp[i][j] = dp[i-1][j];
        }
    }

    ll ans = 0;
    for(int i=0; i<=100*N; i++){
        if(i%2 == P) ans += dp[N][i];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  int a[3][n];
  rep(i,n) cin>>a[0][i]>>a[1][i]>>a[2][i];
  int dp[n][3];
  dp[0][0] = a[0][0];dp[0][1] = a[1][0];dp[0][2] = a[2][0];
  FOR(i, 1, n) {
    rep(j, 3) {
      dp[i][j] = 0;
      rep(k, 3) {
        if(j == k) continue;
        dp[i][j] = max(dp[i][j], dp[i-1][k] + a[j][i]);
      }
    }
  }
  cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;

  return 0;
}


Measured memory_bytes: 2560
package main

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

func main() {
	sc = initScanner(os.Stdin)
	n := scanInt(sc)
	p := scanIntSlice(sc, n)
	fmt.Println(resolve(n, p))
}

func resolve(n int, p []int) int {
	count := 0

	min := math.MaxInt64
	for i := 0; i < n; i++ {
		if p[i] < min {
			count++
			min = p[i]
		}
	}

	return count
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}


Measured memory_bytes: 4876
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

/*
 freopen("input","r",stdin);
 freopen("output","w",stdout);
*/

int A[50], B[50];
int N;

bool check(set<int> a, int u, int b) {
    for (int i = u;i >= 1;i--) {
        set<int> g;
        for (auto s : a) {
            g.insert(s);
            g.insert(s % i);
        }
        if (g.find(b) != g.end()) return 1;
        swap(a, g);
    }
    return 0;
}

ll solve(vector<set<int> > a, vector<int> b, int crt, ll sum) {
    bool ok = 1;
    for (int i = 0;i < b.size();i++) {
        if (a[i].find(b[i]) == a[i].end()) ok = 0;
    }
    if (ok) return sum;
    for (int i = 1;i <= crt;i++) {
        bool ok = 1;
        for (int m = 0;m < N && ok;m++) {
            if (!check(a[m], i, b[m])) ok = 0;
        }
        if (ok) {
            sum += (1LL << i);
            vector<set<int> > H;
            for (int m = 0;m < N;m++) {
                set<int> q;
                for (auto r : a[m]) {
                    q.insert(r);
                    q.insert(r % i);
                }
                H.push_back(q);
            }
            return solve(H, b, i - 1, sum);
        }
    }
    return -1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for (int i = 0;i < N;i++) cin >> A[i];
    for (int i = 0;i < N;i++) cin >> B[i];
    bool xx = 1;
    for (int i = 0;i < N;i++) {
        if (A[i] != B[i]) xx = 0;
    }
    if (xx) {
        cout << 0 << endl;
        return 0;
    }
    vector<set<int> > H;
    for (int i = 0;i < N;i++) {
        set<int> q;
        q.insert(A[i]);
        H.push_back(q);
    }
    vector<int> b;
    for (int i = 0;i < N;i++) b.push_back(B[i]);
    cout << solve(H, b, 50, 0) << endl;
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, a[114514];
int kaii[114514];
vector<int> ta;
int b;
int c;
bool bl;

void init() {
	kaii[1] = 1;
	for (int i = 2; i <= n + 1; i++) {
		kaii[i] = kaii[i - 1] * i%mod;
	}
}

int combi(int x, int y) {
	if (y > x)return 0;
	if (y == x)return 1;
	return kaii[x]* mod_pow(kaii[x-y], mod - 2, mod) % mod * mod_pow(kaii[y], mod - 2, mod) % mod;
}

signed main() {
	cin >> n;
	rep(i, n + 1) {
		cin >> a[i];
		ta.push_back(a[i]);
	}
	init();
	sort(all(ta));
	rep(i, n) {
		if (ta[i] == ta[i + 1]) {
			b = ta[i];
			break;
		}
	}
	rep(i, n + 1) {
		if (!bl&&a[i] == b) {
			c += i;
			bl = true;
		}
		else if (bl&&a[i] == b)c += n - i;
	}
	cout << n << endl;
	for (int i = 2; i <= n; i++) {
		if (c >= i - 1) cout << (combi(n + 1, i) - combi(c, i - 1) + mod) % mod << endl;
		else cout << combi(n + 1, i) << endl;
	}
	cout << 1 << endl;
}

Measured memory_bytes: 3700
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
	
		int N=sc.nextInt();
		ArrayList<Long> cc = new ArrayList<>(N);
		
		for(int i=0;i<N;i++) {
			cc.add(sc.nextLong());
		}
		Collections.sort(cc);
		Collections.reverse(cc);
		
		long a=0,b=0;
		//System.out.println(cc);
		for(int i=0;i+1<cc.size();i++) {
			
			long g=cc.get(i);
			long gg=cc.get(i+1);
			//p(g+" "+gg);
			if(g==gg) {
				
				a=cc.get(i);
				cc.remove(i);
				cc.remove(i);
				break;
			}	
		}//System.out.println(cc);
		for(int i=0;i+1<cc.size();i++) {
			long g=cc.get(i);
			long gg=cc.get(i+1);
			if(g==gg) {
				b=cc.get(i);
				break;
			}	
		}
		//p(a+" "+b);
		long t=a*b;
		p(t);
	}
	

	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 61928
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>

using namespace std;

int main()
{
    int n, m;
    while (scanf ("%d %d", &n, &m) != EOF)
    {
        if (n == 0 && m == 0)
            return 0;
        if ((n * m) & 1)
            printf ("no\n");
        else
            printf ("yes\n");
    }
    return 0;
}

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

struct Edge {
  int to, cap, rev;
  Edge(int to_, int cap_, int rev_) : to(to_), cap(cap_) , rev(rev_) { }
};

int INF = (int)1e9;
const int MAX_V = 400;
vector<Edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap) {
  G[from].emplace_back(to, cap, G[to].size());
  G[to].emplace_back(from, 0, G[from].size() - 1);
}

int find_flow(int v, int t, int f) {
  if(v == t) return f;
  used[v] = true;
  for(Edge &e : G[v]) {
    if(used[e.to] == false && e.cap > 0) {
      int d = find_flow(e.to, t, min(f, e.cap));
      if(d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t) {
  int flow = 0;
  while(true) {
    fill(used, used + MAX_V, false);
    int f = find_flow(s, t, INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int main() {
  int X, Y, E; cin >> X >> Y >> E;
  int src = X + Y;
  int dst = X + Y + 1;
  for(int i = 0; i < X; i++) {
    add_edge(src, i, 1);
  }
  for(int i = 0; i < Y; i++) {
    add_edge(X + i, dst, 1);
  }
  while(E--) {
    int x, y; cin >> x >> y;
    add_edge(x, X + y, 1);
  }
  cout << max_flow(src, dst) << endl;
}

Measured memory_bytes: 1520
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> vsize;

    UnionFind(int size) : par(size), rank(size), vsize(size) {
        REP(i, size) {
            par[i] = i;
            rank[i] = 0;
            vsize[i] = 1;
        }
    }

    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 (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
        vsize[x] += vsize[y];
        vsize[y] = vsize[x];
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int getSize(int x) { return vsize[find(x)]; }
};

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

    int N, M;
    cin >> N >> M;

    vector<int> A(M), B(M);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        A[i] = a;
        B[i] = b;
    }

    int sum = N * (N - 1) / 2;

    vector<int> ans;
    UnionFind uf(N + 1);
    REV(i, M - 1, 0) {
        int a = A[i];
        int b = B[i];

        if (uf.same(a, b)) {
            ans.push_back(0);
       } else {
            int asize = uf.getSize(a);
            int bsize = uf.getSize(b);
            ans.push_back(asize * bsize);
        }
        uf.unite(a, b);
    }

    int suma = 0;
    REV(i, M - 1, 0) {
        suma += ans[i];
        cout << suma << endl;
    }


    return 0;
}


Measured memory_bytes: 6132
import fractions as fc

def prime_factorize(n):
    se = {1}
    while n % 2 == 0:
        se.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            se.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        se.add(n)
    return se

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

m = max(a,b)

max_koyakusu = fc.gcd(a,b)

print(len(prime_factorize(max_koyakusu)))

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    double r;
    cin >> r ;
    cout << r*r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using boost::adaptors::reversed;
using boost::irange;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll N;
    cin >> N;
    vector<ll> as(N);
    for (auto && i: irange(0LL, N)){
        ll a;
        cin >> a;
        a-=(i+1);
        as.at(i) = a;
    }
    sort(as.begin(), as.end());
    ll b = as.at(N / 2);
    ll ret{0};
    for (auto && i: irange(0LL, N)){
        ret += abs(as.at(i) - b);
    }
    cout << ret;


}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<deque>
#include<iomanip>
#include<ctime>
using namespace std;


int main()
{
	string str;//スタンプ文字列
	int N;//スタンプ数
	cin >> N;
	cin >> str;

	int count = 0;

	for (int i = 0; i < N; i++) {
		if (i < N - 1 && str[i] != str[i + 1]) {
			count++;
			i++;
		}
	}

	cout << count << endl;

	return 0;
}


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

int main(){
    int N, X, T;
    int cnt = 0;

    cin >> N >> X >> T;

    if(N % X == 0){
        cnt = (N/X)*T;
    }else{
        cnt = ((N/X) + 1)*T;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3600
def nein
	p 0
	exit
end

N,*D = $<.read.split.map(&:to_i)
nein unless D.shift == 0

a = []
D.each{|d|
	a[d] ||= 0
	a[d] += 1
}
nein if a[0]
a[0] = 1
nein if a.any?(&:nil?)

p a.each_cons(2).inject(1){|z,(a,b)|
	z * (a**b) % 998244353
}


Measured memory_bytes: 12284
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll n,k,a[20];
ll used[20];

ll dfs(ll i,ll d){
    if(d == k) {

        ll ret = 0;
        ll b[20];
        REP(j,n)
            b[j] = a[j];
        REP(j,n) {
            if(!used[j]) {
                continue;
            }

            ll maxi = -1;
            REP(k,j) {
                maxi = max(maxi,b[k] + 1);
            }
            ret += max(0ll,maxi - b[j]);
            if(maxi > b[j]) 
                b[j] = maxi;
        }
        return ret;
    }

    ll ret = 1000000000000000;
    FOR(j,i + 1,n) {
        used[j] = true;
        ret = min(dfs(j,d + 1),ret);
        used[j] = false;
    }
    return ret;
}

int main(){
    cin >> n >> k;
    REP(i,n) {
        cin >>  a[i];
    }

    cout << dfs(-1,0) << endl;
    return 0;
    
}



Measured memory_bytes: 256