akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

bool pairCompare(const pair<string, ll>& firstElof, const pair<string, ll>& secondElof)
{
    if(firstElof.first != secondElof.first){
        return firstElof.first < secondElof.first;
    }else{
        return firstElof.second > secondElof.second;
    }
}

int main() {
    ll n, m;
    cin >> n >> m;

    ll s [15][15] = {0};
    ll k [15] = {0};
    ll p [15] = {0};

    for (int i = 0; i < m; ++i) {
        cin >> k[i];
        for (int j = 0; j < k[i]; ++j) {
            cin >> s[i][j];
        }
    }

    for (int i = 0; i < m; ++i) {
        cin >> p[i];
    }

    ll ans = 0;
    for (ll bit = 0; bit < pow(2, n); ++bit) {
        vector<int> v;
        bool ok = true;

        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                v.push_back(i);
            }
        }

        // gyou
        for (int i = 0; i < m; ++i) {
            // retu
            ll cnt = 0;
            for (int j = 0; j < k[i]; ++j) {

                // on
                if (find(v.begin(), v.end(), s[i][j] - 1) != v.end()) {
                    cnt++;
                }

            }
            if (cnt % 2 != p[i]) {
                ok = false;
            }
        }

        if (ok) {
            ans++;
        }
    }

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


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

a = 0
b = sum(cards)
min_diff = float('inf')
for i in range(n - 1):
    a += cards[i]
    b -= cards[i]
    min_diff = min(min_diff, abs(a - b))
print(min_diff)


Measured memory_bytes: 23800
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int a, b, c, d;
    int ans = 0;
    int calc;
    while (cin >> a >> b >> c >> d) {
        if (a >= c && b <= d)
            calc = b - a;
        else if (a < c && b < d)
            calc = b - c;
        else if (a > c && b > d)
            calc = d - a;
        else
            calc = d - c;
        if (calc > ans)
            ans = calc;
        cout << ans << endl;
        ans = 0;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define MAXK 26
#define MAXX 15000006
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll h,w,n,x,y;
string A, B;
struct player { ll L=0, R=0, U=0, D=0; } one, two;
string ans = "YES";
int main()
{
	FAST
	cin>>h>>w>>n;
	cin>>x>>y;
	cin>>A>>B;
	swap(x,y);
	for(ll i=0;i<siz(A);++i) { 
		if(A[i] == 'L') one.L ++;
		if(A[i] == 'R') one.R ++;
		if(A[i] == 'U') one.U ++;
		if(A[i] == 'D') one.D ++;
		
		if(A[i] == 'L') { 
			if(one.L - two.R >= x) {
				ans = "NO";
			}
		}
		if(A[i] == 'R') {
			if(one.R - two.L >= (w-x+1)) { 
				ans = "NO";
			}
		}
		if(A[i] == 'U') {
			if(one.U - two.D >= y) {
				ans = "NO";
			}
		}
		if(A[i] == 'D') {
			if(one.D - two.U >= (h-y+1)) {
				ans = "NO";
			}
		}
		
		if(B[i] == 'L') two.L ++;
		if(two.L-one.R >= x) two.L = x+one.R-1;
		if(B[i] == 'R') two.R ++;
		if(two.R-one.L >= (w-x+1))  two.R = (w-x+1)-1+one.L;
		if(B[i] == 'U') two.U ++;
		if(two.U-one.D >= y) two.U = y-1+one.D;
		if(B[i] == 'D') two.D ++;
		if(two.D-one.U >= (h-y+1)) two.D = (h-y+1)-1+one.U;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
using pii = pair<int, int>;
using vi=vector<int>;
using vvi=vector<vector<int>>;

int p,q,a,n;
map<vector<int>,int>dp;

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

int dfs(int x,int y,int z,int w,int last){
    vi arg={x,y,z,w,last};
    //if(dp.count(arg))return dp[arg];
    if(z==n){
        if(x==0)return 1;
        else return 0;
    }
    if(x<0)return 0;
    if(x==0)return 1;
    // x/y - (n-z)*(1/last)>0
    if(x*last>(n-z)*y)return 0;

    int ret=0;
    for(int i=last;i*w<=a;i++){
        // x/y - 1/i
        // int bunbo=lcm(y,i);
        // int bunshi=bunbo/y*x - bunbo/i*1;
        // int g=gcd(bunbo,bunshi);
        // bunbo/=g;
        // bunshi/=g;

        ret+=dfs(x*i-y,y*i,z+1,i*w,i);
    }

    //return dp[arg]=ret;
    return ret;
}

signed main() {
    while(cin>>p>>q>>a>>n, p or q or a or n){
        dp.clear();
        int g=gcd(p,q);
        p/=g;
        q/=g;
        cout<<dfs(p,q,0,1,1)<<endl;
    }
}


Measured memory_bytes: 3056
import java.util.Scanner;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    while(sc.hasNext()){
      int a=sc.nextInt(); //秒
      int b=sc.nextInt(); //枚数
      int t=sc.nextInt();
      int total;
      total=(int)(t+0.5)/a;
      System.out.println(total*b);
    }
  }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll a,b,c;
    cin >>a>>b>>c;
    bool flg=false;
    for (int i = 0; i < b; ++i) {
        if((a*i)%b==c)flg=true;
    }
    if(flg)puts("YES");
    else puts("NO");
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct st{
    int x,y;
}a[100005];
bool cmp(st a,st b){return a.x<b.x;}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i].x);
        a[i].y=i+1;
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++)printf("%d ",a[i].y);
}

Measured memory_bytes: 1536
N, Y = map(int, input().split())

l = 0

for i in range(N + 1):
    for j in range(N + 1):
        k = N - i - j
        if 1000*i + 5000*j + 10000*k == Y and k <= N and k >= 0:
            print(k, j, i)
            l = 1
            break
    else:
        continue
    break

if l == 0:
    print("-1 -1 -1")

Measured memory_bytes: 9180
N,W = map(int,input().split())

stuff = [[] for _ in range(4)]

w1,v1 = map(int,input().split())

stuff[0].append(v1)

for _ in range(N-1):
    w,v = map(int,input().split())
    stuff[w-w1].append(v)

for i in stuff:
    i.sort(reverse=True)

ans = 0
for a in range(len(stuff[0])+1):
    for b in range(len(stuff[1])+1):
        for c in range(len(stuff[2])+1):
            for d in range(len(stuff[3])+1):

                if w1*a + (w1+1)*b + (w1+2)*c + (w1+3)*d <= W:
                    ans = max(ans,sum(stuff[0][:a])+sum(stuff[1][:b])+sum(stuff[2][:c])+sum(stuff[3][:d]))
        
print(ans)

Measured memory_bytes: 3188
import sys
from collections import defaultdict
import bisect
from itertools import product


sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    s = S()
    d = defaultdict(list)
    for i, c in enumerate(s):
        d[int(c)].append(i)

    strs = [i for i in range(10)]
    lens = [len(d[i]) for i in strs]
    ans = 0

    for i, j, k in product(strs, strs, strs):
        if lens[i] == 0 or lens[j] == 0 or lens[k] == 0:
            continue
        index_i = 0
        index_j = bisect.bisect_right(d[j], d[i][index_i])
        if index_j == lens[j]:
            continue
        index_k = bisect.bisect_right(d[k], d[j][index_j])
        if index_k == lens[k]:
            continue
        ans += 1
    print(ans)




if __name__ == '__main__':
    main()

Measured memory_bytes: 4856
check [] = True
check (h0:h) = snd $ foldl step (h0, True) h
    where step (k, a) x = (if k < x then x-1 else k, a && k <= x)

main = do
  n <- readLn :: IO Int
  h <- map read . words <$> getLine :: IO [Integer]
  putStrLn $ if check h then "Yes" else "No"


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

string s;

int main()
{
    cin >> s;
    for(int i = 0;i < s.size();i++)
    {
        for(int j = i + 1;j < s.size();j++)
        {
            if(s[i] == 'C' && s[j] == 'F')
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define for1(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define endl '\n'
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int x;
    cin >> x;
    int i = 0;
    while(true) {
        if (x <= i * (i + 1) / 2) {
            cout << i << endl;
            return 0;
        }
        i++;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  
  if (N/1000 == N/100-N/1000*10 && N/100-N/1000*10 == N/10-N/100*10) {
    cout<<"Yes"<<endl;
  }
  
  else if (N/100-N/1000*10 == N/10-N/100*10 && N/10-N/100*10 == N-N/10*10) {
    cout<<"Yes"<<endl;
  }
    
  else if (!(N/1000 == N/100-N/1000*10 && N/100-N/1000*10 == N/10-N/100*10)) {
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3632
module WeightedDirectedGraph
  (Weight : sig
    type t
    val inf : t (* オーバーフローの恐れはないので，max_intとか突っ込んでも良い *)
    val zero : t
    val neg_inf : t (* オーバーフローの恐れはないので，min_intとか突っ込んでも良い *)
    val ( + ) : t -> t -> t
    val compare : t -> t -> int
  end) :
sig
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  val warshall_floyd :
    (* 頂点の数n *)
    int ->
    (* 辺のリスト *)
    (* 頂点は0からn-1までの整数でなくてはならない *)
    (int * int * Weight.t) church_list ->
    (* 辿り着けなければinf，負閉路を含む経路があればneg_infを返す関数 *)
    (int -> int -> Weight.t)
end =
struct
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  let warshall_floyd n es =
    let d = Array.make_matrix n n Weight.inf in
    for v = 0 to n - 1 do
      d.(v).(v) <- Weight.zero
    done;
    es.fold (fun (u, v, c) () ->
      (* c < d.(u).(v) *)
      if 0 < Weight.compare d.(u).(v) c
      then d.(u).(v) <- c) ();
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
        for k = 0 to n - 1 do
          let open Weight in
          if 
            (* 経路がない場合は更新しない *)
            0 < Weight.compare inf d.(j).(i)
            && 0 < Weight.compare inf d.(i).(k)
            (* d.(j).(i) + d.(i).(k) < d.(j).(k) *)
            && 0 < Weight.compare d.(j).(k) (d.(j).(i) + d.(i).(k))
          then d.(j).(k) <- d.(j).(i) + d.(i).(k)
        done
      done
    done;
    for i = 0 to n - 1 do
      (* 頂点iを通る負閉路がある *)
      if 0 < Weight.compare Weight.zero d.(i).(i) then
        for j = 0 to n - 1 do
          for k = 0 to n - 1 do
            (* 負閉路を通る経路があれば，最短距離を負の無限大で更新 *)
            let open Weight in
            if 0 < Weight.compare inf d.(j).(i) && 0 < Weight.compare inf d.(i).(k)
            then d.(j).(k) <- Weight.neg_inf
          done
        done
    done;
    fun u v -> try d.(u).(v) with _ -> Weight.inf
end

module G = WeightedDirectedGraph (struct
  type t = int
  let zero = 0
  let ( + ) = ( + )
  let inf = max_int
  let neg_inf = min_int
  let compare = compare
end)

let select f =
  let rec select trace acc = function
    | [] -> acc
    | x :: xs -> select (x :: trace) (f trace x xs acc) xs in 
  select []

let perm f =
  let rec perm trace n xs acc =
    match n, xs with
    | 0, _ -> f trace acc
    | _, [] -> acc
    | _, _ :: _ ->
        select (fun xs x ys ->
          perm (x :: trace) (n - 1) @@ List.rev_append xs ys) acc xs in
  perm []

let () = Scanf.scanf "%d %d %d\n" @@ fun n m r ->
  let rs = Array.init r @@ fun _ -> Scanf.scanf "%d " pred in
  let abcs = Array.init m @@ fun _ -> Scanf.scanf "%d %d %d\n" @@ fun a b c -> a - 1, b - 1, c in
  let d = G.warshall_floyd n { G.fold = fun f -> Array.fold_right (fun ((a, b, c) as e) acc -> f (b, a, c) @@ f e acc) abcs } in
  Printf.printf "%d\n" @@
  perm (fun (r :: rs) acc ->
    min acc @@
    snd @@
    List.fold_left (fun (r, a) s -> (s, d r s + a)) (r, 0) rs) r (Array.to_list rs)  max_int


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>


int main() {
	long long n, c, k;

	std::cin >> n >> c >> k;

	std::vector<long long> v(n);
	for (int i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}

	std::sort(v.begin(), v.end());

	int ans = 1, cc = 1;
	long long start = v[0];
	for (int i = 1; i < n; i++)
	{
		if (v[i] - start > k || cc >= c) {
			ans++;
			start = v[i];
			cc = 0;
		}
		cc++;
	}

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

Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=0
for i in range(n):
    d=min(a[i],b[i])
    b[i]-=d
    ans+=d
    d=min(a[i+1],b[i])
    a[i+1]-=d
    ans+=d
print(ans)

Measured memory_bytes: 19244
#include<bits/stdc++.h>
using namespace std;
const int N=600005;
char s[N];
int a[N],n,sum;
void update(int x,int y){
	sum-=a[x];
	a[x]+=y;
	sum+=a[x];
	if (a[x]>=10){
		sum-=10;
		if (n==x)n++;
		a[x]-=10;
		update(x+1,1);
	}
}
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for (int i=1;i<=n;i++)a[i]=s[n-i+1]-'0';
	for (int i=1;i<=n;i++)a[i]*=9;
	for (int i=1;i<=n;i++)a[i+1]+=a[i]/10,a[i]%=10;
	if (a[n+1])n++;
	sum=0;
	for (int i=1;i<=n;i++)sum+=a[i];
	for (int k=1;;k++){
		update(1,9);
		if (k*9>=sum){
			printf("%d\n",k);
			return 0;
		}
	}
}


Measured memory_bytes: 2688
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int cnt = 0;
    if (a == b) {
        cnt = 1;
        if (b != c) {
            cnt = 2;
        }
    } else {
        cnt = 2;
        if (a != c && b != c) {
            cnt = 3;
        }
    }

    printf("%d\n", cnt);

    return 0;
}

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

class in {
  int n;
public:
  in() {}
  in(int n_) : n(n_){};
  template <class T> operator T() { T ret; cin >> ret; return ret; }
  template <class T> operator vector<T>() { vector<T> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; }
};

template <std::uint_fast64_t Mod> class modint {
  using u64 = std::uint_fast64_t;
  u64 a;
  friend ostream& operator<<(ostream& os, const modint& m);
public:
  constexpr modint(const u64 x = 0) noexcept : a(x % Mod) {}
  constexpr u64 val() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
  constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
  constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
  constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
  constexpr bool operator==(const modint rhs) const noexcept { return modint(*this).val() == rhs.val(); }
  modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; }
  modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; }
  modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Mod; return *this; }
  modint &operator/=(modint rhs) noexcept { u64 exp = Mod - 2; while (exp) { if (exp % 2) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; }
};
const ll mod=(ll)1e9+7;
using mint = modint<mod>;
ostream& operator<<(ostream& os, const mint& m){ return os << m.a; }
//}}}

const int kMaxBit = 64;
int bit0[kMaxBit];
int bit1[kMaxBit];

int main(){
  int N = in();
  vector<ll> A = in(N);

  mint ans = 0;
  rep(i, N){
    rep(b, kMaxBit){
      bit0[b] += ((A[i] >> b) & 1) == 0;
      bit1[b] += ((A[i] >> b) & 1) == 1;
    }
  }
  rep(i, N){
    rep(b, kMaxBit){
      if(((A[i] >> b) & 1)){
        bit1[b]--;
        ans += (bit0[b] % mod) * ((1LL << b) % mod);
      }else{
        bit0[b]--;
        ans += (bit1[b] % mod) * ((1LL << b) % mod);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll sump[100005], sumq[100005], sumr[100005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    rep(i,c) cin >> r[i];
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    sort(r.rbegin(), r.rend());
    rep(i,a+1) sump[i+1] = sump[i] + p[i];
    rep(i,b+1) sumq[i+1] = sumq[i] + q[i];
    rep(i,c+1) sumr[i+1] = sumr[i] + r[i];
    ll ans = sump[x]+sumq[y];
    int px = x-1, py = y-1, pz = 0;
    while(1){
        if(px >= 0 && py >= 0){
            if(p[px] < q[py]){
                if(r[pz] <= p[px]) break;
                ans -= p[px];
                ans += r[pz];
                px--;
                pz++;
            }
            else{
                if(r[pz] <= q[py]) break;
                ans -= q[py];
                ans += r[pz];
                py--;
                pz++;
            }
        }
        else if(px >= 0){
            if(r[pz] <= p[px]) break;
            ans -= p[px];
            ans += r[pz];
            px--;
            pz++;
        }
        else if(py >= 0){
            if(r[pz] <= q[py]) break;
            ans -= q[py];
            ans += r[pz];
            py--;
            pz++;
        }
        else break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
N = int(input())
data = []
ans = []
for i in range(1, N+1):
  city, score = input().split()
  score = int(score)
  data.append([city, score, i])
city_list = [x[0] for x in data]
score_list = [x[1] for x in data]
num_list = [x[2] for x in data]
city_unique = sorted(set(city_list))

for city_u in city_unique:
  city_index = [i for i, x in enumerate(city_list) if x == city_u]
  for score in sorted([score_list[x] for x in city_index], reverse=True):
    print(num_list[score_list.index(score)])

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k, mx = INT_MIN;
    cin >> k >> n;
    int arr[n];
    int i = 0;
    while(i < n) {
        cin >> arr[i];
        i++;
    }
    for(int i = 1; i < n; i++) {
        mx = max(mx, abs(arr[i] - arr[i-1]));
    }
    if(abs(arr[n-1]-arr[0]) > abs(arr[n-1] - arr[0]-k)) {
        mx = max(mx, abs(arr[n-1] - arr[0]-k));
    } else {
        mx = max(mx, abs(arr[n-1] - arr[0]));
    }
    cout << k - mx << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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;
}

double dp[305][305][305] = {0.0};

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

    int N;
    cin >> N;
    vector<double> a(N);
    REP(i, N) { cin >> a.at(i); }

    vector<int> c(4, 0);
    REP(i, N) { c[a[i]]++; }

    FOR(k, 0, N + 1) {
        FOR(j, 0, N + 1) {
            FOR(i, 0, N + 1) {
                double sum = i + j + k;
                if (sum == 0)
                    continue;
                dp[i][j][k] = 1.0 * N / sum;
                if (i)
                    dp[i][j][k] += dp[i - 1][j][k] * i / sum;
                if (j)
                    dp[i][j][k] += dp[i + 1][j - 1][k] * j / sum;
                if (k)
                    dp[i][j][k] += dp[i][j + 1][k - 1] * k / sum;
            }
        }
    }

    cout << setprecision(10) << dp[c[1]][c[2]][c[3]] << endl;

    return 0;
}


Measured memory_bytes: 219392
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define fs first
#define sc second
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef tuple<int, int, int> iii;
typedef tree<int, null_type, less<int>, rb_tree_tag,
    tree_order_statistics_node_update> ost;

const int N=60;
const int A=60;
ll x[N], nw[N*A+1][N+1];

int main() {
    ll i, j, k, n, a, ans;
    scanf("%lld%lld", &n, &a);
    for(i=0; i<n; i++) scanf("%lld", &x[i]);
    nw[0][0]=1;
    for(i=0; i<n; i++)
        for(j=n*a; j>=x[i]; j--) for(k=n; k>=1; k--)
            nw[j][k]+=nw[j-x[i]][k-1];
    ans=0;
    for(i=1; i<=n; i++) ans+=nw[i*a][i];
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <numeric>

using namespace std;

#define INF 210000000
#define int long long

static long long gcd(long long a, long long b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

static long long lcm(long long a, long long b) { return a * b / gcd(a, b); }

signed main() {
    int a[3] = {0};
    int sum = 0;
    int max = 0;
    for (int i=0;i<3;i++){
        cin >> a[i];
        sum += a[i];
        if(max < a[i]){
            max = a[i];
        }
    }
    cout << sum - max;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> A(N+1), B(N+1), C(N);
    for (size_t i = 1; i < N+1; i++)
    {
        cin >> A.at(i);
    }
    for (size_t i = 1; i < N+1; i++)
    {
        cin >> B.at(i);
    }
    for (size_t i = 1; i < N; i++)
    {
        cin >> C.at(i);
    }
    int ans=0;
    for (size_t i = 1; i < N+1; i++)
    {
        ans += B.at(A.at(i));
        if (i!=N && A.at(i)+1==A.at(i+1))ans += C.at(A.at(i));
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<string.h>
#include<vector>
using namespace std;
typedef unsigned long long ll;
#pragma GCC optimize(2)
//vector<ll> a;
int main()
{
    string s;
    ll i=0,a;
    cin>>s;
    a=s[s.length()-1]-'0';
    if(a==2||a==4||a==5||a==7||a==9)
    {
        cout<<"hon"<<endl;
    }
    if(a==0||a==1||a==6||a==8)
        cout<<"pon"<<endl;
    if(a==3)
        cout<<"bon"<<endl;
}


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

int main() {
  int a,b,c;cin>>a>>b>>c;
  if(a>b){
    int t=a;
    a=b;
    b=t;
  }
  vector <int>m;
  for(int i=1;i<=a;++i){
    if(a%i==0 && b%i==0) m.push_back(i);
  }
  cout<<m[m.size()-c]<<endl;
  return 0;
}

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

int main() {
  string s;
  cin >>s;
  int n=s.size();
  int flag=0;
  
  for(int i=0; i<n-1; i++){
    if(s[i]==s[i+1]){
      cout << i+1 << " " << i+2 << endl;
      flag++;
      break;
    }
  }
  
  if(flag==0){
    for(int i=0; i<n-2; i++){
      if(s[i]==s[i+2]){ 
        cout << i+1 << " " << i+3 << endl;
        flag++;
        break;
      }
    }
  }
  
  if(flag==0) cout << -1 << " " << -1 << endl;
}

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

using namespace std;

int kq,n,a[105],x;

void    init()
{
    freopen("b.inp","r",stdin);
    freopen("b.out","w",stdout);
}

void    nhap()
{
    scanf("%d%d",&n,&x);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
}

void    xuly()
{
    kq=0;
    for (int i=1;i<=n;i++)
    {
        x-=a[i];
        kq++;
    }
    sort(a+1,a+n+1);
    kq+=x/a[1];
}

void    xuat()
{
    printf("%d",kq);
}

int     main()
{
    //init();
    nhap();
    xuly();
    xuat();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long int li;
typedef long long ll;
typedef long double ld;

void solve()
{
	int n;
	cin >> n;
	if (n >= 30)
		cout << "Yes\n";
	else
		cout << "No\n";
}

int main()
{
	int n = 1;
	// cin >> n;
	while (n-- > 0)
		solve();
}


Measured memory_bytes: 3632
/*<----------------------------------------------------------------------->

<-------------------------------------------------------------------------->
            _           __                _      _____ _____ _____ 
  ___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
 / __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ /    / /   / /   / / 
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /  
 \___|\__,_|_.__/ \___|_| |_|  \___|\__,_|_|\_\  /_/   /_/   /_/   

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
typedef unordered_map <ll,ll> umap ; 
//#pragma GCC optimize "trapv"
#define loop(i,a,b) for(ll i=a ;i<b;i++)
#define For(i,n) for(int i=0;i<(ll)n;i++)
#define Rev(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(),(v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a,b) make_pair(a,b)
#define pf(n) cout<<n<<"\n"
#define pff(n) cout << n << " " ; 
long const M=1e9+7;
const long mxN =1e5+2 ;
const long mxNN =1e6+2 ;
ll p[mxN],q[mxN],r[mxN],ans=0;
int x,y,a,b,c ;multiset<ll> X,Y ;
void solve(){
    cin >> x >> y >> a >> b >> c ;
    For(i,a)cin >> p[i] ;
    For(i,b)cin >>q[i] ;
    For(i,c)cin >> r[i] ;
    sort(p,p+a,greater<int>()) ;
    sort(q,q+b,greater<int>()) ;
    sort(r,r+c,greater<int>()) ;
    For(i,x)
        X.insert(p[i]) ;
    For(i,y)
        Y.insert(q[i]) ;
    For(i,c){
        auto it_x=X.begin() ;
        auto it_y=Y.begin() ;
        if(*it_y>*it_x && r[i]>*it_x){
            X.erase(it_x) ;
            X.insert(r[i]) ;
            continue ;
        }
        if(*it_x>=*it_y && r[i]>*it_y){
            Y.erase(it_y) ;
            Y.insert(r[i]) ;
        }
    }
    for(auto x :X)
        ans+=x ;
    for(ll x:Y)
        ans+=x ;
    pf(ans) ;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve() ;
    //ll t ; cin >> t ; while(t--)solve();
	return 0;
}


Measured memory_bytes: 11008
#include <cstdio>

const int MN = 1005;

int N;
char Ans[MN][MN];

void Solve(int n, int x, int y, char c) {
	if (n == 3) {
		Ans[x + 1][y + 1] = c;
		Ans[x + 1][y + 2] = c;
		Ans[x + 2][y + 3] = c;
		Ans[x + 3][y + 3] = c;
	} else if (n == 4) {
		Ans[x + 1][y + 1] = c;
		Ans[x + 1][y + 2] = c;
		Ans[x + 1][y + 3] = c + 2;
		Ans[x + 1][y + 4] = c;
		Ans[x + 2][y + 1] = c + 1;
		Ans[x + 2][y + 2] = c + 1;
		Ans[x + 2][y + 3] = c + 2;
		Ans[x + 2][y + 4] = c;
		Ans[x + 3][y + 1] = c;
		Ans[x + 3][y + 2] = c + 2;
		Ans[x + 3][y + 3] = c + 1;
		Ans[x + 3][y + 4] = c + 1;
		Ans[x + 4][y + 1] = c;
		Ans[x + 4][y + 2] = c + 2;
		Ans[x + 4][y + 3] = c;
		Ans[x + 4][y + 4] = c;
	} else if (n == 5) {
		Ans[x + 1][y + 1] = c;
		Ans[x + 1][y + 2] = c;
		Ans[x + 1][y + 3] = c + 1;
		Ans[x + 1][y + 4] = c + 1;
		Ans[x + 1][y + 5] = c;
		Ans[x + 2][y + 1] = c + 1;
		Ans[x + 2][y + 2] = c + 2;
		Ans[x + 2][y + 3] = c + 2;
		Ans[x + 2][y + 5] = c;
		Ans[x + 3][y + 1] = c + 1;
		Ans[x + 3][y + 4] = c + 2;
		Ans[x + 3][y + 5] = c + 1;
		Ans[x + 4][y + 1] = c;
		Ans[x + 4][y + 4] = c + 2;
		Ans[x + 4][y + 5] = c + 1;
		Ans[x + 5][y + 1] = c;
		Ans[x + 5][y + 2] = c + 1;
		Ans[x + 5][y + 3] = c + 1;
		Ans[x + 5][y + 4] = c;
		Ans[x + 5][y + 5] = c;
	} else if (n == 7) {
		Ans[x + 1][y + 2] = c;
		Ans[x + 1][y + 3] = c;
		Ans[x + 1][y + 4] = c + 1;
		Ans[x + 1][y + 5] = c + 1;
		Ans[x + 1][y + 6] = c;
		Ans[x + 1][y + 7] = c;
		Ans[x + 2][y + 1] = c;
		Ans[x + 3][y + 1] = c;
		Ans[x + 4][y + 1] = c + 1;
		Ans[x + 5][y + 1] = c + 1;
		Ans[x + 6][y + 1] = c;
		Ans[x + 7][y + 1] = c;
		Ans[x + 2][y + 2] = c + 2;
		Ans[x + 2][y + 3] = c + 2;
		Ans[x + 2][y + 5] = c + 2;
		Ans[x + 2][y + 6] = c + 2;
		Ans[x + 3][y + 4] = c + 2;
		Ans[x + 3][y + 7] = c + 2;
		Ans[x + 4][y + 4] = c + 2;
		Ans[x + 4][y + 7] = c + 2;
		Ans[x + 5][y + 2] = c + 2;
		Ans[x + 5][y + 3] = c + 2;
		Ans[x + 5][y + 5] = c + 2;
		Ans[x + 5][y + 6] = c + 2;
		Ans[x + 6][y + 4] = c + 2;
		Ans[x + 6][y + 7] = c + 2;
		Ans[x + 7][y + 4] = c + 2;
		Ans[x + 7][y + 7] = c + 2;
	} else if (n % 2 == 0) {
		Solve(n / 2, x, y, 'a');
		Solve(n / 2, x, y + n / 2, 'd');
		Solve(n / 2, x + n / 2, y, 'd');
		Solve(n / 2, x + n / 2, y + n / 2, 'a');
	} else {
		Ans[x + 1][y + 1] = c;
		Ans[x + 1][y + 2] = c;
		Ans[x + 2][y + 1] = c + 1;
		Ans[x + 2][y + 2] = c + 1;
		Ans[x + 1][y + n - 1] = c;
		Ans[x + 1][y + n] = c + 1;
		Ans[x + 2][y + n - 1] = c;
		Ans[x + 2][y + n] = c + 1;
		Ans[x + n - 1][y + 1] = c;
		Ans[x + n - 1][y + 2] = c + 1;
		Ans[x + n][y + 1] = c;
		Ans[x + n][y + 2] = c + 1;
		Ans[x + n - 1][y + n - 1] = c;
		Ans[x + n - 1][y + n] = c;
		Ans[x + n][y + n - 1] = c + 1;
		Ans[x + n][y + n] = c + 1;
		Solve(n - 4, x + 2, y + 2, c);
	}
}

int main() {
	scanf("%d", &N);
	if (N == 2) return puts("-1"), 0;
	for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) Ans[i][j] = '.';
	Solve(N, 0, 0, 'a');
	for (int i = 1; i <= N; ++i) printf("%s\n", Ans[i] + 1);
	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

double R;
int main(void){
    cin >> R;
    cout << 2*R*3.141592 << endl;
    return 0;
}



Measured memory_bytes: 3784
stack=[]
data=input().split()
for str in data:
    if(str =='+'):
        stack.append(stack.pop()+stack.pop())
    elif(str =="-"):
        stack.append(-stack.pop()+stack.pop())
    elif(str =="*"):
        stack.append(stack.pop()*stack.pop())
    else:
        stack.append(int(str))
print(stack[0])


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

using namespace std;

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

	int max = 0;
	for(int b=1;b <=100;b++){
		for(int p=2;p<=10;p++){
			int tmp = pow(b,p);
			if(tmp <= X){
				if(max < tmp){
					max = tmp;
				}
			}
		}
	}

	cout << max << endl;

	return 0;
}


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

int main(){
  int n,k,i,j,ans;
  cin >> n >> k;
  if(k>(n-1)*(n-2)/2){
    cout << -1; return 0;
  }else{
    ans=n-1+((n-1)*(n-2)/2-k);
    cout << n-1+((n-1)*(n-2)/2-k) << endl;
    for(i=1; i<n; i++){
      cout << i << ' ' << n << endl;
    }
    k=n-1;
    while(ans>k){
      for(i=1; i<n; i++){
        for(j=i+1; j<n; j++){
          cout << i << ' ' << j << endl;
          k++;
          if(ans==k) break;
        }
        if(ans==k) break;
      }
      if(ans==k) break;
    }
  }
}
  
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

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

    int n, w, h;
    cin >> h >> w >> n;
    int x = max(h, w);
    cout << (n + x - 1) / x << endl;
}   


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <limits>

using namespace std;

using lint = long long;
using ldouble = long double;

constexpr int INF = numeric_limits<int>::max() / 2;

bool solve() {
    int n;
    cin >> n;
    if (n == 0) return false;

    vector<pair<int, int>> bals(n);
    for (auto& b : bals) cin >> b.first >> b.second;
    bals.emplace(bals.begin(), 0, 0);

    vector<vector<int>> dp(n + 1, vector<int>(4, INF));
    // i個バルーンを回収済み 今k個持っていて座標piにいるような最短移動距離
    dp[0][0] = 0;

    for (int i = 0; i < n; ++i) {
        int dt = bals[i + 1].second - bals[i].second;
        int x1 = bals[i].first, x2 = bals[i + 1].first;

        // 家に戻らず回収
        for (int k = 0; k < 3; ++k) {
            int d = abs(x2 - x1);
            if (d * (k + 1) <= dt) {
                dp[i + 1][k + 1] = min(dp[i + 1][k + 1], dp[i][k] + d);
            }
        }

        // 家に戻ってから回収
        for (int k = 1; k <= 3; ++k) {
            if (x1 * (k + 1) + x2 <= dt) {
                dp[i + 1][1] = min(dp[i + 1][1], dp[i][k] + x1 + x2);
            }
        }
    }

    int ans = INF;
    for (int k = 0; k <= 3; ++k) {
        ans = min(ans, dp[n][k] + bals[n].first);
    }

    if (ans < INF) {
        cout << "OK " << ans << endl;
    } else {
        for (int i = 1; i <= n; ++i) {
            bool judge = true;
            for (int k = 0; k <= 3; ++k) {
                if (dp[i][k] < INF) judge = false;
            }

            if (judge) {
                cout << "NG " << i << endl;
                break;
            }
        }
    }
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> L(n), R(n);
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &L[i], &R[i]);

		L[i]--;
	}
	
	// prepare
	auto calc = [&](int L, int R) { return std::max(0, R - L); };
	
	std::vector<std::pair<int, int>> vec;
	for(int i = 0; i < n; i++) vec.emplace_back(L[i], R[i]);
	sort(begin(vec), end(vec)); reverse(begin(vec), end(vec));

	std::vector<std::pair<int, std::pair<int, int>>> X, Y;
	for(int i = 0; i < n; i++) {
		X.push_back({-L[i], {R[i] - L[i], i}});
		Y.push_back({ R[i], {R[i] - L[i], i}});
	}
	sort(begin(X), end(X)); sort(begin(Y), end(Y));

	// solve
	int ans = 0;
	{ // パターン 1
		int x = X[0].second.second, y = Y[0].second.second;
		for(int i = 0; i < n; i++) {
			if(i == x or i == y) continue;

			ans = std::max(ans, calc(L[x], R[y]) + calc(L[i], R[i]));
		}
	}

	{ // パターン 2
		int tmp = vec[0].second, LM = -X[0].first, Rm = Y[0].first;
		for(int k = 1; k < n; k++) {
			ans = std::max(ans, calc(LM, tmp) + calc(vec[k].first, Rm));

			tmp = std::min(tmp, vec[k].second);
		}
	}
	
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 5488
import Control.Arrow
import qualified Data.List as L
import qualified Data.Map as M

main = interact $ 
  lines >>> tail >>> head >>> words >>> map read 
  >>> solve 
  >>> map show >>> unlines

solve :: [Int] -> [Int]
solve a = zipWith (-) 
            (take len $ repeat total)
            $ map 
              (\v -> case v of 
                Nothing -> 0
                (Just x) -> x - 1)
              [ M.lookup x ga | x <- a ]
  where
    len = length a
    ga :: M.Map Int Int
    ga = M.fromListWith (+) [ (x, 1) | x <- a ] 
    total = sum $ map choose2 $ map (\v -> snd v) $ M.toList ga

choose2 :: Int -> Int
choose2 n = (n * (n - 1)) `div` 2

Measured memory_bytes: 101628
object Main extends App {
  val primes: Stream[Int] = Stream.cons(2, Stream.from(3, 2) filter { i =>
    (i > 1) && primes.takeWhile(_ <= Math.sqrt(i)).forall(i % _ != 0)
  })

  def primeFactorization(n: Int): List[(Int, Int)] =
    primeFactorization(n, primes)

  def primeFactorization(n: Int, primes: Stream[Int]): List[(Int, Int)] = {
    if (n == 1) List.empty
    else {
      val (count, vn) = trialDivision(n, primes.head, 0)
      if (count == 0) primeFactorization(vn, primes.tail)
      else (primes.head, count) :: primeFactorization(vn, primes.tail)
    }
  }

  def trialDivision(n: Int, p: Int, e: Int): (Int, Int) = {
    if (n % p != 0) (e, n)
    else trialDivision(n / p, p, e + 1)
  }

  val n = io.StdIn.readInt
  var map = Map.empty[Int, Int]
  for (i <- 2 to n) {
    primeFactorization(i).toMap.foreach(t => {
      val v = map.getOrElse(t._1, 0)
      map = map + (t._1 -> (v + t._2))
    })
  }
  println(map.foldLeft(1L) { (acc, t) =>
    (acc * (t._2 + 1L)) % 1000000007L
  })
}


Measured memory_bytes: 30212
Q,H,S,D=map(int,input().split())
N=int(input())
oneL=[4*Q,2*H,S]
if min(oneL)*2 <= D:
  print(N*min(oneL))
elif N%2==0:
  print(int(N/2)*D)
else:
  print(min(oneL)+int((N-1)/2)*D)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <set>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<vector<int>> children;
  vector<int> hukasa;
  vector<int> kazu;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    kazu = vector<int>(n,1);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
      kazu.at(rx) += kazu.at(ry);
    }
    else{
      par.at(rx) = ry;
      kazu.at(ry) += kazu.at(rx);
    }
  }
  void newkazu(){
    int n = kazu.size();
    for(int i=0;i<n;i++){
      kazu.at(i) = kazu.at(root(i));
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
void hukasa(vector<vector<int>> s,vector<vector<int>> table,int &ans,pii frm,int n,int m){
  int x,y;
  tie(x,y) = frm;
  set<pii> se;
  if(x-1 >= 0)se.insert(pii(x-1,y));
  if(x+1 < n)se.insert(pii(x+1,y));
  if(y-1 >= 0)se.insert(pii(x,y-1));
  if(y+1 < m)se.insert(pii(x,y+1));
  for(auto t:se){
    int tx,ty;
    tie(tx,ty) = t;
    if(s.at(tx).at(ty) && table.at(tx).at(ty) == -1){
      table.at(tx).at(ty) = table.at(x).at(y) + 1;
      ans = max(ans,table.at(tx).at(ty));
      hukasa(s,table,ans,t,n,m);
      table.at(tx).at(ty) = -1;
    }
  }
}
void daiku(int frm,vector<vector<pii>> g,vector<int> &cost,int n){
  priority_queue<pii,vector<pii>,greater<pii>> q;
  q.push(pii(cost.at(frm),frm));
  vector<bool> kakutei(n,false);
  while(!q.empty()){
    pii now = q.top();
    q.pop();
    int n1,n2;
    tie(n1,n2) = now;
    if(kakutei.at(n2))continue;
    kakutei.at(n2) = true;
    for(auto t:g.at(n2)){
      int tx,ty;
      tie(tx,ty) = t;
      if(cost.at(tx) > n1 + ty){
        cost.at(tx) = n1 + ty;
        q.push(pii(cost.at(tx),tx));
      }
    }
  }
}

int main(){
  string s;
  cin >> s;
  if(s.at(s.size()-1) == 's'){
    s += "es";
  }
  else{
    s += 's';
  }
  cout << s << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;
typedef long long  ll;
typedef long double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> multi_set;
#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 2E5+7;

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



Measured memory_bytes: 256
from itertools import accumulate
N,M=map(int,input().split())
L = [0]*(N+1)
for _ in range(M):
  l,r = map(lambda x:int(x)-1,input().split())
  L[l]+=1
  L[r+1]-=1

L = list(accumulate(L))
print(L.count(M))

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

int main(){

    int n;
    cin >> n;

    int k = 1;
    int ans = 0;
    for(int i = 1; i < n+1; ++i){
        int a;
        cin >> a;

        if(a == k)++k;
        else ++ans;
    }

    if(ans == n)ans = -1;

    cout << ans << endl;

}

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

int main(int argc, char const *argv[]) {
  int a, b;
  cin >> a >> b;
  if (a * b % 2 == 0)
    cout << "Even" << endl;
  else
    cout << "Odd" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 1005
int pre[MAX],rank[MAX];
struct node
{
    int u,v,cost;
}edge[MAX*10];
void make_set(int x)
{
    pre[x]=x;
    rank[x]=0;
}
int find(int x)
{
    if (x!=pre[x])
        pre[x]=find(pre[x]);
    return pre[x];
}
int cmp(node x,node y)
{
    return x.cost<y.cost;
}
void unionone(int a,int b)
{
    int len1=find(a);
    int len2=find(b);
    if (rank[len1]>rank[len2])
        pre[len2]=len1;
    else
        pre[len1]=len2;
}
int kruskal(int n,int min)
{
    int i,j;
    int cnt=0;
    for(i=0;i<n;i++)
    {
        if (find(edge[i].u)!=find(edge[i].v))
        {
            cnt++;
            unionone(edge[i].u,edge[i].v);
            if (cnt==min)
                return i;
        }
    }
}
int main()
{
    int m,n;
    while(scanf("%d%d",&m,&n)&&(m+n))
    {
        int i,j;
        int min=m/2;
        for(i=1;i<=m;i++)
            make_set(i);
        for(i=0;i<n;i++)
        {
            scanf("%d%d%d",&edge[i].u,&edge[i].v,&edge[i].cost);
        }
        sort(edge,edge+n,cmp);
        int cnt=kruskal(n,min);
        printf("%d\n",edge[cnt].cost);
    }
    return 0;
}

Measured memory_bytes: 1336
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;
int main (){
    int n;
    cin >> n;
    int x[n],y[n];
    for (int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    double s=0;
    double nn=1;
    for (int i = 0; i < n-1; i++){
        for (int j = i+1; j < n; j++){
            s+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }
    s=s*2/n;
    cout << fixed << setprecision(10)<< s << "\n";
}

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

using namespace std;
int main() {
    string s_dash;
    string s;
    string t;
    int len_s;
    int len_t;
    bool match;

    cin >> s_dash >> t;

    len_s = s_dash.size();
    len_t = t.size();

    s = s_dash;
    for (int i = len_s-len_t; i >= 0 ; i--) {
        match = true;
        s = s_dash;
        for (int j = 0; j < len_t; j++) {
            if (s_dash[i+j] != '?' &&
                s_dash[i+j] != t[j]) {
                match = false;
                break;
            }
            s[i+j] = t[j];
        }

        if (match) {
            for (int j = 0; j < len_s; j++) {
                if (s[j] == '?') {
                    s[j] = 'a';
                }
            }
            break;
        }
    }

    if (!match) {
        s = "UNRESTORABLE";
    }
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  vector<int> a(32);
  a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int N;
  cin >> N;
  cout << a.at(N-1) << endl;
  return 0;
}

Measured memory_bytes: 3584