akhauriyash/Code-Regression huggingface dataset:
N, M, Q = list(map(int,input().split()))
L = []
R = []
for i in range(M):
    in1, in2 = map(int,input().split())
    L.append(in1 - 1)
    R.append(in2 - 1)
p = []
q = []
for i in range(Q):
    in1, in2 = map(int,input().split())
    p.append(in1 - 1)
    q.append(in2 - 1)
    
a = [[0 for _ in range(N)] for _ in range(N)]
for i in range(M):
    a[L[i]][R[i]] += 1
    
#da[i][j]:(0,0)~(i,j)の長方形の和
def da_gen(a):
    w = len(a[0])
    h = len(a)
    da = [[0] * w for j in range(h)]
    da[0][0] = a[0][0]
    for i in range(1, w):
        da[0][i] = da[0][i - 1] + a[0][i]
    for i in range(1,h):
        cnt_w = 0
        for j in range(w):
            cnt_w += a[i][j]
            da[i][j] = da[i - 1][j] + cnt_w
    return da

#da_calc(p,q,x,y):(p,q)~(x,y)の長方形の和
def da_calc(da, p, q, x, y):
    if p > x or q > y:
        return 0
    if p == 0 and q == 0:
        return da[x][y]
    if p == 0:
        return da[x][y] - da[x][q - 1]
    if q == 0:
        return da[x][y] - da[p - 1][y]
    return da[x][y] - da[p - 1][y] - da[x][q - 1]+da[p - 1][q - 1]

ret = da_gen(a)
for i in range(Q):
    ans = da_calc(ret, p[i], p[i], q[i], q[i])
    print(ans)

Measured memory_bytes: 116916
fun main(args: Array<String>) {
  val S = readLine()!!
  val days = arrayOf("SUN","MON","TUE","WED","THU","FRI","SAT").reversed()
  for (i in days.indices) {
    if (days[i] == S) {
      println(i+1)
      break
    }      
  }
}

Measured memory_bytes: 33912
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v.at(i);
	}
	sort(v.begin(), v.end());

	cout << v.at(N - 1) - v.at(0) << endl;
}

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

#define inn(n)         int n; cin >> n;
typedef long long      ll;
typedef vector<int>    vi;
typedef pair<int, int> pi;

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

    inn(n);

    printf("%.12f", n*n*n/27.0);
    return 0;
}



Measured memory_bytes: 256
#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;
#define AB_BHI_NI_DEGI                \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
//int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double

#define ordered_set tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update>

int32_t main()
{
	AB_BHI_NI_DEGI
	//freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int ans = a[n - 1];
	int cnt = 1;
	for (int i = n - 2; i >= 0; i--)
	{
		if (cnt == n - 1)
			break;
		ans += a[i];
		cnt++;
		if (cnt == n - 1)
			break;
		ans += a[i];
		cnt++;
		if (cnt == n - 1)
			break;
	}
	cout << ans << "\n";
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

int main(){
    int N; cin >> N;
    vector<int> A(N); REP(i, N) cin >> A[i];

    int cnt = 0;
    REP(i, N) {
        if(A[i] % 2 == 1) {
            cnt++;
        }
    }

    // 奇数の数値が偶数個あればYES
    if(cnt % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

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

    vector<int> x(n);
    rep(i, 0, n) cin >> x[i];

    long long min_score = 1e9;
    rep(i, 1, 101) {
        int cur = 0;
        rep(j, 0, n) {
            cur += pow(x[j] - i, 2);
        }
        if (min_score > cur) {
            min_score = cur;
        }
    }

    cout << min_score << endl;
    
    return 0;
}

Measured memory_bytes: 256
import numpy as np

A=[]
for i in range(0,3):
    input_1= list(map(int, input().split()))
    A.extend(input_1)
    
N=int(input())

Bingo=[]
for i in range(0,N):
    Bingo.append(int(input()))

for i in range(0,9):
    for j in range(0,N):
        if Bingo[j]==A[i]:
            A[i]=0
    
np_arr1 = np.array([[A[0], A[1], A[2]], [A[3], A[4], A[5]], [A[6], A[7], A[8]]])
#print(np_arr1)

list_horizontal_1=sum([A[0], A[1], A[2]])
list_horizontal_2=sum([A[3], A[4], A[5]])
list_horizontal_3=sum([A[6], A[7], A[8]])

list_vertical_1=sum([A[0], A[3], A[6]])
list_vertical_2=sum([A[1], A[4], A[7]])
list_vertical_3=sum([A[2], A[5], A[8]])

list_closs_1=sum([A[0], A[4], A[8]])
list_closs_2=sum([A[2], A[4], A[6]])

if list_horizontal_1==0 or list_horizontal_2==0 or list_horizontal_3==0 or list_vertical_1==0 or list_vertical_2==0 or list_vertical_3==0 or list_closs_1==0 or list_closs_2==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 12512
L,R = map(int,input().split())

ans = 0
min_mod = 2019

if R-L+1<2019 :
  if R % 2019 > 0:
    if R-L == 1:
      min_mod = (L*R) % 2019
    else :
      for i in range(L,R) :
        for j in range(i+1,R+1):

          if min_mod > (i*j) % 2019:
            min_mod = (i*j) % 2019
      
    
    ans = min_mod
    
print(ans)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


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

    ll n;
    cin >> n;
    ll c[n], v[n];
    F0R(i,n) cin >> v[i];
    F0R(i,n) cin >> c[i];
    ll sum = 0;
    F0R(i,n){
      if(v[i] - c[i] > 0) sum += v[i] - c[i];
    }
    cout << sum << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<cstdio>

int main(){
	int a, b, c, d, e, f, g, h, i;
	scanf("%d %d %d", &a, &b, &c);
	if(a>b){
		d = b, e = a;
	}else{
		d = a, e = b;
	}
	if(e>c){
		f = c, g = e;
	}else{
		f = e, g = c;
	}
	if(d>f){
		h = f, i = d;
	}else{
		h = d, i = f;
	}
	printf("%d %d %d\n", h, i, g);

	return 0;
}

Measured memory_bytes: 1024
N = int(input())
d = [0] * N
stack = []

for i in range(N):
  d[i] = int(input())
d = sorted(d, reverse=True)

ans = 0
for i in range(N):
  if len(stack) == 0:
    stack.append(d[i])
  elif stack[-1] == d[i]:
    continue
  elif stack[-1] > d[i]:
    stack.append(d[i])
  else:
    ans = max(ans, len(stack))
    stack = [d[i]]

ans = max(ans, len(stack))
print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#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 ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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 (b<a) { a=b; return 1; } return 0; }

int main(){
    string s; cin >> s;
    string t; cin >> t;
    int l = s.size();
    int r = t.size();
    if(s == t.erase(l) && l +1 == r) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3624
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    int K,S;
    cin >> K >> S;
    int count = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            if( 0 <= S-i-j && S-i-j <= K){
                count++;
            }
        }
    }
    cout << count << endl;
}


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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return x;}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in(),K=in();
	auto A=vecin(N);

	REP(n,min(K,50ll)){
		vector<ll> V(N+1,0);
		REP(i,N){
			int L=max(0ll,i-A[i]);
			int R=min(N,i+A[i]+1ll);
			V[L]++;
			V[R]--;
		}
		A[0] = V[0];
		REP(i,N-1){
			A[i+1] = V[i+1]+A[i];
		}
	}
	
	PRINTALL(A);
	return 0;
}


Measured memory_bytes: 6360
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[,]A = new int[N-1,2];
		for(var i=0;i<N-1;i++){
			string[] str2 = Console.ReadLine().Split();
			A[i,0] = int.Parse(str2[0]);
			A[i,1] = int.Parse(str2[1]);
		}
		int[,]B = new int[M,2];
		int[]Q = new int[N];
		for(var i=0;i<M;i++){
			string[] str2 = Console.ReadLine().Split();
			B[i,0] = int.Parse(str2[0]);
			B[i,1] = int.Parse(str2[1]);
			Q[B[i,0]-1] += B[i,1];
		}
		int[]Ans = new int[N];
		var list = new List<int>[N];
		for(var i=0;i<N;i++){
			list[i] = new List<int>();
		}
		for(var i=0;i<N-1;i++){
			list[A[i,0]-1].Add(A[i,1]-1);
		}
		int[]F = new int[N];
		var listA = new List<int>();
		listA.Add(0);
		while(listA.Count>0){
			var list2 = new List<int>(listA);
			listA.Clear();
			foreach(var i in list2){
				int q1 = Ans[i]+Q[i];
              	Ans[i] = q1;
				F[i] = 1;
				foreach(var j in list[i]){
					if(F[j] == 0){
                      	Ans[j] = q1;
						listA.Add(j);
					}
				}
			}
		}
		Console.Write(Ans[0]);
		for(var i=1;i<N;i++){
			Console.Write(" "+Ans[i]);
		}
	}
}

Measured memory_bytes: 44028
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		long ans = 0;//答え
		int n = sc.nextInt();
		Map<String, Integer> s = new HashMap<String,Integer>();//文字列と個数のマップ
		String sn;//読み込んだ文字列
 		String si;//並べ替えた文字列
		char sm[] = new char[10];//並べ替え用
		
		
		for(int i = 0;i < n;i++) {
			sn = sc.next();
			//読み込んだ文字列の並べ替え
			sm = sn.toCharArray();
			Arrays.sort(sm);
			si = new String(sm);
			
			if(s.containsKey(si)) {
				//同じものがあったら
				int m = s.get(si);
				ans += m+1;
				s.put(si, m + 1);
				
			}else {
				//なかったら
				s.put(si, 0);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 52308
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc129_a

p, q, r = map(int, input().strip().split())

res = 0
if p < q:
    if q < r:
        res = p + q
    else:
        res = p + r
else:
    if p < r:
        res = p + q
    else:
        res = q + r
print(res)


Measured memory_bytes: 9108
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        String str = new Scanner(System.in).nextLine();
        String strs[]= str.split(" ");
        int a =Integer.parseInt(strs[0]);
        int b =Integer.parseInt(strs[1]);
        System.out.println(a*b+" "+2*(a+b));
    }
}


Measured memory_bytes: 26048
from collections import deque

n, m = map(int,input().split())

graph = [[] for _ in range(n+1)]

for i in range(m):
    a,b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

# dist = [-1]*(n+1)
# dist[0] = 0
# dist[1] = 0
mark = [-1]*(n+1)
mark[0] - 0
mark[1] = 0


d = deque()
d.append(1)

while d:
    v = d.popleft()
    for i in graph[v]:
        if mark[i] != -1:
        # if dist[i] != -1:
            continue
        mark[i] = v
        # dist[i] = dist[v] + 1
        d.append(i)

if '-1' in mark:
    print('No')
else:
    print('Yes')
    print(*mark[2:], sep='\n')


Measured memory_bytes: 35556
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

main :: IO ()
main = do
    [n, d] <- getIntList
    xl <- getIntNList n
    putStrLn (show (length [x | x <- map (\a -> snd (properFraction (distance (a !! 0) (a !! 1)))) (combination 2 xl), x == 0.0]))


distance :: (Integral a, Show a) => [a] -> [a] -> Float
distance i j = sqrt (fromIntegral(sum (zipWith (\x y -> (x-y) * (x-y)) i j)))

combination :: Int -> [a] -> [[a]]
combination 0 _ = [[]]
combination _ [] = []
combination n (x:xs) = (zipWith (:) (repeat x) (combination (n - 1) xs)) ++ (combination n xs)

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine


Measured memory_bytes: 508
def solve():
    N, M = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    A.sort()
    ans = 0
    cnt = 0
    for a in A:
        if cnt + a[1] <= M:
            ans += a[1]*a[0]
            cnt += a[1]
        else:
            ans += a[0]*(M-cnt)
            break
    return ans
print(solve())

Measured memory_bytes: 27756
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
struct s{
    long long int a;
    long long int b;
};
bool f (s x,s y){
    if (x.a>y.a) return false;
    else return true;
}
using namespace std;
int main () {
     long long int n;
     cin>>n;
     s t[n];
     for (long long int i=0;i<n;i++) {cin>>t[i].a;t[i].b=i+1;}
     sort(t,t+n,f);
     for (long long int i=0;i<n;i++) {
         cout<<t[i].b<<" ";
     }
     cout<<endl;
}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
typedef long long ll;
using namespace std;
const int mod=1e9+7;
ll power(ll a,ll b){
    if(b == 0) return 1;
    if(b%2) return (a*power(a,b-1))%mod;
    ll r=power(a,b/2);
    return ((r*r)%mod);
}
ll solve(){
    ll n;
    cin>>n;
    return (power(10,n)-2*power(9,n)+power(8,n)+mod*3ll)% mod;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--) cout<<solve()<<'\n';
    //while(t--) solve(),cout<<'\n';
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main{

    private static long max;

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

        long n = sc.nextLong();
        Map<Long, Integer> map = primeFactorization(n);
        int count = 0;

        for(long l : map.keySet()){
            for(int i = 1; map.get(l) >= i; i++){
                map.put(l, map.get(l) - i);
                count++;
            }
        }
        System.out.println(count);
    }

    static boolean isPrime(long n){
        if(n == 2){
            return true;
        }
        if(n < 2 || n % 2 == 0){
            return false;
        }
        long sqrt = (long)Math.sqrt(n);
        for(long i = 3; i <= sqrt; i += 2){
            if(n % i == 0){
                return false;
            }

        }
        return true;
    }

    static Map<Long, Integer> primeFactorization(long n){
        Map<Long, Integer> result = new TreeMap<>();
        if(isPrime(n)){
            result.put(n, 1);
            return result;
        }
        for(long i = 2; i * i <= n; i++){
            if(n % i != 0){
                continue;
            }
            int p = 0;
            while(n % i == 0){
                p++;
                n /= i;
            }
            result.put(i, p);
        }
        if(n != 1){
            result.put(n, 1);
        }
        return result;
    }

}


Measured memory_bytes: 35808
H, W = map(int, input().split())

if H==1 or W==1:
    result = 1
elif W%2==0:
    result = (W/2)*H
else:
    if H%2==0:
        result=W*(H/2)
    else :
        result=W*(H-1)/2+(W+1)/2
print(str(round(result)))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	int x = 0, a, b;
	cin >> a >> b;
	for(int i = 2; i < n; i++) {
		int t;
		cin >> t;
		x ^= t;
	}
	if(a == b && x == 0) return cout << 0 << endl, 0;
	int z = a + b - x;
	if(z < 0 || z & 1) {
		cout << -1 << endl;
		return 0;
	}
	z /= 2;
	// aa ^ bb = x, aa & bb = z
	vi v(60);
	for(int j = 0; j < 60; j++) {
		int sa = x >> j & 1;
		int na = z >> j & 1;
		if(sa == 0 && na == 0){
			// must 0
			v[j] = 0;
		}
		else if(sa == 0 && na == 1) {
			// must 1
			v[j] = 1;
		} else if(sa == 1 && na == 0) {
			// both
			v[j] = 2;
		} else {
			// no way
			cout << -1 << endl;
			return 0;
		}
	}

	int j;
	for(j = 59; j >= 0; j--) {
		int bit = a >> j & 1;
		if(bit == 1 && v[j] == 0) break;
		if(bit == 0 && v[j] == 1) break;
	}
	if(j == -1) return cout << 0 << endl, -1;
	int bit = a >> j & 1;
	if(bit == 1 && v[j] == 0) {
		int aa = 0;

		for(int i = 59; i > j; i--) {
			aa |= (a >> i & 1) << i;
		}
		for(int i = j - 1; i >= 0; i--) {
			if(v[i]) aa |= 1LL << i;
		}
		if(aa == 0) return cout << -1 <<endl, 0;
		cout << a - aa << endl;
	} else {
		int i;
		for(i = j + 1; i < 60; i++) {
			if(v[i] != 1 && (a >> i & 1)) break;
		}

		if(i == 60) return cout << -1 << endl, 0;
		j = i;
		int aa = 0;
		for(int i = 59; i > j; i--) {
			aa |= (a >> i & 1) << i;
		}
		for(int i = j - 1; i >= 0; i--) {
			if(v[i]) aa |= 1LL << i;
		}
		if(aa == 0) return cout << -1<< endl, 0;
		cout << a - aa << endl;
	}


}





Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    string S;
    cin >> S;
    int s=S.size();
    map<char,ll> m;
    rep(i,s){
        m[S[i]]++;
    }
    ll ans=0;
    for (auto x:m){
        ll c=x.second;
        ans+=c*(s-c);
    }
    ans/=2;
    ans++;
    cout << ans << endl;
}

Measured memory_bytes: 640
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;

namespace AtCoder
{
    class Program
    {

        const int BiggestMod = 998244353;

        public static void Main()
        {

            var args = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var tgt = args[1];
            args = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            Array.Sort(args);
            var ans = 0;

            for (int i = 0; i < tgt; i++)
                ans += args[i];

            Console.WriteLine(ans);
            

        }

    }

}

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

int main(){
    string s = "abcdefghijklmnopqrstuvwxyz";
    string str;
    cin >> str;
    set<char> st;

    for(int i=0;i<s.size();i++){
        st.insert(s[i]);
    }

    for(int i=0;i<str.size();i++){
      st.erase(str[i]);
    }

    if(st.size()==0){
        cout << "None" << endl;
    }else{
        cout << (*st.begin()) << endl; 
    }
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
zn[100001] = {0,0};
bl[100001] = {0,0};
temp[100001];
int main()
{
	for (int i = 1; i <= 100000; i+=2)
		zn[i] = 1;
	int n, a,b,count=0;
	scanf("%d", &n);
	for (int i = 1; i <= 100000; i+=2)
	{
		for (int k = 2; k <= sqrt(i) ; k++)
		{
			if (i % k == 0||((i+1)/2)%k==0)
			{
				zn[i] = 0;
				break;
			}
			

		}

	}
	
	zn[1] = 0;

	for (int i = 1; i <= 100000; i++)
	{
		bl[i] = zn[i]+bl[i-1];
	 }
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &a, &b);
		
		temp[i] = bl[b] - bl[a-1];
	}
	for (int i = 1; i <= n; i++)
	{
		printf("%d\n", temp[i]);
	}

	
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		if(A>B) {
			System.out.println(A+(A-1));
		}else if(A==B) {
			System.out.println(A+B);
		}else {
			System.out.println(B+(B-1));
		}
	}

}

Measured memory_bytes: 35824
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++ i)
#define per(i,a,b) for(int i = (a); i >= (b); -- i)
#define pb push_back
#define VI vector<int>
#define VVI vector<VI>
#define Pii pair<int,int>
#define Pll pair<ll,ll>
#define Pli pair<ll,int>
#define fi first
#define se second
#define Ppi pair<Pii,int>
#define VII vector<Pii>

using namespace std;

typedef long long ll;
typedef int (*funI_I) (int);
typedef int (*funI_II) (int, int);

constexpr int N = 4000100;

int a[N], n, dp[N][2];

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    reverse(s.begin(),s.end());

    memset(dp, 0x3f3f3f3f, sizeof dp);

    n = s.size();
    rep(i, 0 , s.size()-1) {
        a[i] = s[i] - '0';
    }
    dp[0][0] = a[0];
    dp[0][1] = 10-a[0];
    rep(i, 1, n-1) {
        dp[i][0] = min(dp[i][0], dp[i-1][0] + a[i]);
        dp[i][0] = min(dp[i][0], dp[i-1][1] + a[i] + 1);
        dp[i][1] = min(dp[i][1], dp[i-1][0] + 10 - a[i]);
        dp[i][1] = min(dp[i][1], dp[i-1][1] + 10 - (a[i]+1));
    }

    cout << min(dp[n-1][0], dp[n-1][1] + 1) << "\n";
}


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

using namespace std;
//using namespace atcoder;
 
#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif

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

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

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

#define int long long
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)


void solve(){
    int N;
    cin >> N;
    int ans = 0;
    
    for(int a=1; a<=N-1; a++){
        ans += (N-1)/a;
    }
    cout << ans << endl;

}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed;
    solve();
}


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

int n,m,ans;
int a[100];

int main()
{
	scanf("%d %d",&n,&m);
	for (int i=1,x,y;i<=n;i++)
	{
		scanf("%d",&x);
		for (int j=1;j<=x;j++)
		{
			scanf("%d",&y);++a[y];
		}
	}
	for (int i=1;i<=m;i++) if (a[i]==n) ++ans;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
def main():
    n,t = map(int,input().split())
    a = list(map(int,input().split()))
    res = t
    for i in range(1,n):
        if a[i-1]+t <= a[i]:
            res += t
        else:
            res += t - (a[i-1]+t-a[i])
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 85328
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;


int main() {
    

    
    ll n, t, a;
    cin >> n;
    
    ll pt = 0;
    ll pa = 0;
    
    for (int i = 0; i < n; ++i)
    {
        cin >> t >> a;
        if (pt <= t && pa <= a)
        {
            pt = t;
            pa = a;
        }
        else if (pt > t && pa <= a)
        {
            ll m = pt / t;
            if (pt % t)
            {
                m += 1ll;
            }
            pt = t * m;
            pa = a * m;
        }
        else if (pa > a && pt <= t)
        {
            ll m = pa / a;
            if (pa % a)
            {
                m += 1ll;
            }
            pt = t * m;
            pa = a * m;
        }
        else
        {
            ll mt = pt / t;
            ll ma = pa / a;
            if (pt % t)
            {
                mt += 1ll;
            }
            if (pa % a)
            {
                ma += 1ll;
            }
            ll m = max(mt, ma);
            pt = t * m;
            pa = a * m;
        }
    }
    
    cout << pt + pa << endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        var tmp = ReadIntArray();
        int h = tmp[0]; // w = tmp[1];
        for (int i = 0; i < h; i++)
        {
            string s = ReadLine();
            WriteLine(s); WriteLine(s);
        }
    }
}

Measured memory_bytes: 13396
import std.algorithm;
import std.range;
import std.math;
import std.regex;
import std.array;
import std.container;
import std.stdio;
import std.string;
import std.conv;

string[] readStrs() { return readln.chomp.split(' '); }
T[] readInts(T)() { return readln.chomp.split(' ').map!(to!T).array(); }
T readInt(T)() { return readln.chomp.to!T; }


void main()
{
    writeln(solve());
}

long solve()
{
    int N = readInt!int;
    int[] As = readInts!int;

    int[] vs = new int[N];
    foreach(i; 0 .. N)
        vs[As[i]] += 1;

    if(N % 2 == 0){
        foreach(i; 0 .. N){
            if(vs[i] != 0 && i % 2 != 1) return 0;
            if(vs[i] != 0 && vs[i] != 2) return 0;
        }

        return computeABP(2, N/2, 1_000_000_007);
    }else{
        foreach(i; 0 .. N){
            if(vs[i] != 0 && i % 2 != 0) return 0;
            if(i != 0 && vs[i] != 0 && vs[i] != 2) return 0;
            if(i == 0 && vs[i] != 1) return 0;
        }

        return computeABP(2, N/2, 1_000_000_007);
    }
}


long computeABP(int a, int b, int p)
{
    if(b == 0) return 1;
    else if(b % 2 == 0){
        long d = computeABP(a, b/2, p);
        return (d * d) % p;
    }else{
        return (a * computeABP(a, b-1, p)) % p;
    }
}


Measured memory_bytes: 3900
x,y=map(int,input().split())
if y%2!=0:
    print('No')
elif (y-2*x)//2 < 0 or (4*x-y)//2 < 0:
    print('No')
elif (y-2*x)//2 == 0 and (4*x-y)//2==0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9184
#include <iostream>

using namespace std;

int main(){
  string W;
  string T;
  int cnt=0;

  cin >> W;

  for (size_t i = 0; i < W.size(); ++i)
    {
      if (isupper(W[i]))
        {
          W[i] = tolower(W[i]);
        }
    }

  while(cin >> T , T!= "END_OF_TEXT")
    {
      for (size_t i = 0; i < T.size(); ++i)
        {
          if (isupper(T[i]))
            {
              T[i] = tolower(T[i]);
            }
        }

      if(W==T) ++cnt;
    }

  cout << cnt << endl;
}

Measured memory_bytes: 1192
#include <stdio.h>

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;

// returns false when it is last combination
static bool Next(vector<int>& x, int M) {
  int p = x.size() - 1;
  if (x[p] < M) {
    ++x[p];
    return true;
  }
  x[p] = 1;
  --p;
  while (p >= 0) {
    if (x[p] < M) {
      int t = ++x[p];
      for (int j = p + 1; j < x.size(); ++j) {
          x[j] = t;
      }
      return true;
    }
    --p;
  }
  return false;
}

void CManyRequirements(std::istream& in, std::ostream& out) {
  int N, M, Q;
  in >> N >> M >> Q;
  vector<vector<int>> v(Q);
  for (int i = 0; i < Q; ++i) {
    v[i].resize(4);
    in >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
  }

  vector<int> a(N);
  fill(a.begin(), a.end(), 1);
  llong max_score = 0;
  do {
    llong score = 0;
    for (int i = 0; i < Q; ++i) {
      if (a[v[i][1] - 1] - a[v[i][0] - 1] == v[i][2])
        score += v[i][3];
    }
    max_score = max(max_score, score);
  } while (Next(a, M));
  out << max_score << "\n";
}

int main(int argc, char** argv) { CManyRequirements(cin, cout); return 0; }

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

void solve(long long N, vector<long long> a){
	vector<long long> v(N + 1);
	for(int i = 0; i < N; ++i) {
		v[i + 1] = v[i] + a[i];
	}
	long long res = (long long)1e+18;
	for(int i = 1; i < N; ++i) {
		res = min(res, abs(v[i] - (v[N] - v[i])));
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> a(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	solve(N, a);
	return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  vector<int> b;
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    if(a.at(i)%2==0){
      b.push_back(a.at(i));
    }
  }
  bool ok = true;
  for(int i=0;i<b.size();i++){
    if(b.at(i)%3!=0 && b.at(i)%5!=0){
      ok = false;
    }
  }
  if(ok){
    cout<<"APPROVED"<<endl;
  }
  else{
    cout<<"DENIED"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  int n;cin>>n;
  string s,t;cin>>s>>t;
  REP(i,n) {
    cout << s[i];
    cout << t[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;


    ll  ans =0;
    if(k%2==0)
    {
        ans += pow((int)(n/k), 3);
        int cnt=0;
        for(int x=1; x<=n; x++)
        {
            if(x%k == k/2)
            {
                cnt++;
            }
        }
        d(cnt)
        ans+=pow(cnt, 3);
    }
    else
    {
        ans = pow((int) (n/k), 3);
    }

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

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,d,s1,s2;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a>=c)
    s1=a;
    else
    s1=c;
    
    if(b>=d)
    s2=d;
    else
    s2=b;
    
    if((s2-s1)>0)
    printf("%d",s2-s1);
    else
    printf("0");
}

Measured memory_bytes: 1716
L, R = gets.split.map(&:to_i)

ans = 2 << 60
(L..([L + 2019, R - 1].min)).each do |l|
  ((L + 1)..([L + 1 + 2019, R].min)).each do |r|
    a = l * r % 2019
    ans = a if a < ans
  end
end
puts ans


Measured memory_bytes: 3836
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<cmath>

#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e12

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 (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

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

    cout << n % k;

}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,dp[2003][2003],a[6003],ans,tg,MX[2003],cur;
vector<int>A,B,C;
void add(int x,int y,int z){A.push_back(x),B.push_back(y),C.push_back(z);}
int main(){
	cin>>n;
	for(int i=1;i<=3*n;i++)cin>>a[i]; 
	memset(dp,-1,sizeof(dp));
	memset(MX,-1,sizeof(MX));
	dp[a[1]][a[2]]=dp[a[2]][a[1]]=MX[a[1]]=MX[a[2]]=cur=0;
	for(int i=3;i<3*n;i+=3){
		if(a[i]==a[i+1]&&a[i]==a[i+2]){tg++;continue;}
		A.clear(),B.clear(),C.clear();
		sort(a+i,a+i+3);
		if(a[i]==a[i+1])for(int j=1;j<=n;j++)if(dp[j][a[i]]>=0)add(j,a[i+2],dp[j][a[i]]+1);
		if(a[i+1]==a[i+2])for(int j=1;j<=n;j++)if(dp[j][a[i+1]]>=0)add(j,a[i],dp[j][a[i+1]]+1);
		if(dp[a[i]][a[i]]>=0)add(a[i+1],a[i+2],dp[a[i]][a[i]]+1);
		if(dp[a[i+1]][a[i+1]]>=0)add(a[i],a[i+2],dp[a[i+1]][a[i+1]]+1);
		if(dp[a[i+2]][a[i+2]]>=0)add(a[i],a[i+1],dp[a[i+2]][a[i+2]]+1);
		add(a[i],a[i+1],cur),add(a[i+1],a[i+2],cur),add(a[i],a[i+2],cur);
		for(int j=i;j<i+3;j++)for(int k=1;k<=n;k++)if(MX[k]>=0)add(a[j],k,MX[k]);
		for(int j=0;j<(int)A.size();j++)if(dp[A[j]][B[j]]<C[j])
			dp[A[j]][B[j]]=dp[B[j]][A[j]]=C[j],MX[A[j]]=max(MX[A[j]],C[j]),MX[B[j]]=max(MX[B[j]],C[j]),cur=max(cur,C[j]);

	}
	
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++)if(dp[i][j]>=0)ans=max(ans,dp[i][j]);
		if(dp[i][i]>=0)if(i==a[3*n])ans=max(ans,dp[i][i]+1);
	}
	printf("%d",ans+tg);
}


Measured memory_bytes: 19608
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            int x = ReadInt();
            switch (x)
            {
                case 3:
                case 5:
                case 7:
                    Console.WriteLine("YES");
                    break;
                default:
                    Console.WriteLine("NO");
                    break;
            }
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph = vector<vector<ll>>;
int main(){
  ll A;
  cin>>A;
  ll b=0;
  vector<ll>vec(100000+1,0);
  for(ll i=0;i<A;i++){
    ll a;
    cin>>a;
    vec.at(a)+=1;
    b+=a;
  }
  
  ll K;
  cin>>K;
  for(ll i=0;i<K;i++){
    ll c,d;
    cin>>c>>d;
    b+=(d-c)*vec.at(c);
    vec.at(d)+=vec.at(c);
    vec.at(c)=0;
    cout<<b<<endl;
  }
}
    


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

int main() {
  int k, t;
  cin >> k >> t;
  vector<int> a(t);
  rep(i, t) cin >> a[i];
  sort(a.rbegin(), a.rend());
  int sum = a[0];
  for (int i = 1; i < t; i++) sum -= a[i];
  cout << max(0, sum - 1) << endl;
  return 0;
}


Measured memory_bytes: 3608
$<.each_line do |l|
  ps = l.split.map(&:to_i)
  cs = [1, 2, 1, 2, 1, 4, 1, 4]
  m = nil
  mins = []
  8.times do |i|
    c = 8.times.map {|j| [ps[j] - cs[(i+j)%8], 0].max }.inject :+
    if !m || m > c
      m = c
      mins = [i]
    elsif m == c
      mins << i
    end
  end
  puts mins.map {|i| 8.times.map {|j| cs[(i+j)%8] }.join ' ' }.sort.first
end

Measured memory_bytes: 8964
#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;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)

const int L=1e6+7;
ll a[L][3], dp[L][3], n;
ll solve(int i, int prev)
{
	if(i > n)return 0LL;
	if(prev!=-1 && dp[i][prev] != 0)return dp[i][prev];
	FOR(j,0,3)
	{
		if(prev == j)continue;
		dp[i][prev] = max(dp[i][prev],  solve(i+1, j) + a[i][j]);
	}
	return dp[i][prev];
}
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	cin >> n;
	 	FOR(i,1,n+1)
	 		cin >> a[i][0] >> a[i][1] >> a[i][2];
	 	cout<<solve(0, -1);
		return 0;
}

Measured memory_bytes: 16256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   ll w, h, x, y;
   int can_mult_split = 0;
   cin >> w >> h >> x >> y;
   double area = w * h / 2.0;
   if (2 * x == w && 2 * y == h)
      can_mult_split = 1;
   printf("%.9lf %d\n", area, can_mult_split);
   return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])

a,b,c = mint()
judge(c%gcd(a,b)==0,['YES','NO'])

Measured memory_bytes: 65568
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
ll ans;
void compute(string s){
    ll i,temp=0;
    f(i,0,s.length(),1)
        if (s[i]=='0')
            continue;
        else if (s[i]=='+'){
            ans+=temp;
            temp=0;
        }
        else
            temp=temp*10+(s[i]-'0');
    ans+=temp;
}
void solve(){
    string s,sub="";
    set<string> st;
    ll i,j,n;
    cin>>s;
    n=s.length();
    f(i,0,s.length()-1,1)
        sub=sub+s[i]+'0';
    sub=sub+s[i];
    for (i=1;i<(1<<(2*n-1));i++){
        for (j=0;j<(2*n-1);j++)
            if (i&(1<<j) && sub[j]=='0')
                sub[j]='+';
        if (st.find(sub)==st.end()){
            compute(sub);
            st.insert(sub);
        }
        sub="";
        f(j,0,s.length()-1,1)
            sub=sub+s[j]+'0';
        sub=sub+s[j];
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3684
pub mod contest {
    pub mod input {
        use std::io;
        use std::str::FromStr;
        use std::fmt::Debug;

        pub fn read_line<F>() -> F
        where F: FromStr, <F as FromStr>::Err: Debug {
            let mut input = String::new();
            io::stdin().read_line(&mut input).unwrap();
            input.trim().parse().unwrap()
        }

        pub fn read_words<F>() -> Vec<F>
        where F: FromStr, <F as FromStr>::Err: Debug {
            let mut input = String::new();
            io::stdin().read_line(&mut input).unwrap();
            input
                .split_whitespace()
                .map(|i| i.parse().unwrap())
                .collect()
        }

        pub fn read_matrix<F>(num_lines: usize) -> Vec<Vec<F>>
        where F: FromStr, <F as FromStr>::Err: Debug {
            (0..num_lines).map(|_| read_words()).collect()
        }
    }
}

fn count_2(x: i32) -> usize {
    let mut i = x;
    let mut num_2s = 0;
    loop {
        if i % 2 == 0 {
            num_2s += 1;
            i /= 2;
        } else {
            break;
        }
    }
    num_2s
}

fn solve(n: i32) -> i32 {
    (1..n+1).max_by_key(|i| count_2(*i)).unwrap()
}

#[test]
fn test_solve() {
    assert_eq!(solve(7), 4);
    assert_eq!(solve(32), 32);
    assert_eq!(solve(1), 1);
    assert_eq!(solve(100), 64);
}

fn main() {
    let n: i32 = contest::input::read_line();
    println!("{}", solve(n));
}


Measured memory_bytes: 4352
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue> 
#define P pair<int ,int >
#define pb push_back
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define db double
//#define int LL
using namespace std;
const int N   = 2e5+233;
//const int mod = ;
const int INF =numeric_limits<int >::max();

#define rep(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}
int n,a[N],ans;
int vis[N];
signed main()
{
	read(n);
	rep(i,1,n) read(a[i]);
	sort(a+1,a+1+n);
	for (LL k=1ll<<30;k>=1;k>>=1)
	  	  {
	  	  	if (k==16)
	  	  	{
	  	  		++k;--k;;
	  	  	}
	  	  	int r=n;
	  	  		rep(i,1,n) if (!vis[i])
	  			{	
	  				while (r>i&&(vis[r] ||a[i]+a[r]>k) ) --r;
	  				
	  				if (!vis[r]&&r>i&&a[i]+a[r]==k ) 
	  				{
	  					vis[r]=vis[i]=1;
	  					++ans;
	  				}
	  			}	
	  	  }
	printf("%d",ans);
	return 0;
}

    

Measured memory_bytes: 1792