akhauriyash/Code-Regression huggingface dataset:
import sys
a=input()
a0=a.split()
x=int(a0[0])
n=int(a0[1])
if n==0:
    print(x)
    sys.exit()
p=input()
pl=list()
p=p.split()
k=-1
for i in range(n):
    pl.append(int(p[i]))
for i in range(102):
    q=i in pl
    if q==False :
        if abs(i-x)<abs(k-x):
            k=i
        else:
            print(k)
            sys.exit()
print(k)

Measured memory_bytes: 9140
#include<stdio.h>
int main(i){
  float s[2];
  int d[2][4]={};
  
  while(scanf("%f%f",&s[0],&s[1])!=EOF){
    for(i=0;i<2;i++){
      if(s[i]>=1.1)
	d[i][0]++;
      else if(s[i]>=0.6)
	d[i][1]++;
      else if(s[i]>=0.2)
	d[i][2]++;
      else
	d[i][3]++;
    }
  }
  printf("%d %d\n%d %d\n%d %d\n%d %d\n"
	 ,d[0][0],d[1][0],d[0][1],d[1][1],d[0][2],d[1][2],d[0][3],d[1][3]);
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, x[100], y[100], h[100];

int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) cin >> x[i] >> y[i] >> h[i];
	ll x1, y1, h1;
	REP(i, n) if (h[i] != 0) {
		x1 = x[i]; y1 = y[i]; h1 = h[i];
		break;
	}
	REP(cx, 101) REP(cy, 101) {
		ll ch = h1 + abs(x1 - cx) + abs(y1 - cy);
		bool ok = true;
		REP(i, n) ok &= (max((ll)0, ch - abs(x[i] - cx) - abs(y[i] - cy)) == h[i]);
		if (ok) {
			cout << cx << " " << cy << " " << ch << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner

import scala.annotation.tailrec
import scala.collection.mutable.{Map => MMap}

object Main extends App {
  val sc = new Scanner(System.in)
  val (s, t) = (sc.next.toCharArray, sc.next.toCharArray)
  val s2t = MMap.empty[Char, Char]
  val t2s = MMap.empty[Char, Char]
  val arr = s zip t
  var result = true

  @tailrec
  def lp(idx: Int): Unit = {
    if (idx < arr.length) {
      val (ss, tt) = arr(idx)
      val last_s2t = s2t.put(ss, tt)
      val last_t2s = t2s.put(tt, ss)
      if (last_s2t.exists(_ != tt) || last_t2s.exists(_ != ss)) {
        result = false
      } else {
        lp(idx + 1)
      }
    }
  }

  lp(0)

  println(if (result) "Yes" else "No")
}


Measured memory_bytes: 43264
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define DEBUG true
#define $(x) {if (DEBUG) {cout << #x << " = " << (x) << endl;}}

inline LL minMult(LL x, LL n) { return (x / n + (x % n == 0 ? 0 : 1)); }

int main() {
    LL N;
    cin >> N;
    LL tmin = 1, amin = 1;
    REP(i, N) {
        LL t, a;
        cin >> t >> a;
        LL tm = minMult(tmin, t);
        LL am = minMult(amin, a);
        LL m = max(tm, am);
        tmin = t * m;
        amin = a * m;
    }
    cout << tmin + amin << endl;
	
    return 0;
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

#define INF 2e9

ll N,i;

int main(){

    scanf("%lld", &N);

    N--;

    printf("%lld" , N*(N+1)/2);

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001

const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    int n = s.size();
    rep(i,n){
        if(s[i] == 'o') cnt++;
    }
    cnt += 15 - n;
    if(cnt >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
	long long n,k,i;
	long long s=0;
	scanf("%lld%lld",&n,&k);
	for(i=k;i<=n+1;i++)
	{
		s=(s+(n-i+1)*i+1)%1000000007;
	}
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 1736
N = input()
l = len(N)
K = int(input())
dp = [[[0]*2 for i in range(K+1)] for j in range(l)]
dp[0][0][0] = 1
dp[0][1][0] = int(N[0])-1
dp[0][1][1] = 1
for i in range(l-1):
    for j in range(K+1):
        for d in range(10):
            if d == 0:
                dp[i+1][j][0] += dp[i][j][0]
                if N[i+1] == '0':
                    dp[i+1][j][1] += dp[i][j][1]
                else:
                    dp[i+1][j][0] += dp[i][j][1]
            else:
                if j==K:
                    continue
                dp[i+1][j+1][0] += dp[i][j][0]
                if int(N[i+1])>d:
                    dp[i+1][j+1][0] += dp[i][j][1]
                elif int(N[i+1])==d:
                    dp[i+1][j+1][1] += dp[i][j][1]
print(dp[-1][-1][0]+dp[-1][-1][1])



        


Measured memory_bytes: 41200
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	x := make([]int, N)
	sum := 0
	for i := 0; i < N; i++ {
		x[i] = getInt()
		sum += x[i]
	}
	ave := (sum + N>>1) / N
	ans := 0
	for i := 0; i < N; i++ {
		diff := x[i] - ave
		ans += diff * diff
	}
	out(ans)
}


Measured memory_bytes: 640
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	var nums []int
	for i := 0; i < n; i++ {
		var num int
		fmt.Scan(&num)
		nums = append(nums, num)
	}

	sort.Ints(nums)

	var ans int
	for i := 0; i < len(nums); i++ {
		if i == len(nums)-1 {
			ans += nums[i] / 2
		} else {
			ans += nums[i]
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        String[] s = new String[N];
        int ans = 0;
        int cntA = 0;
        int cntB = 0;
        int cnt = 0;
        for(int i = 0; i < N; i++){
            s[i] = sc.next();
            for(int j = 0; j < s[i].length()-1; j++){
                if(s[i].charAt(j)=='A' && s[i].charAt(j+1)=='B')
                    ans++;
            }
            if(s[i].charAt(s[i].length()-1) == 'A' && s[i].charAt(0) != 'B'){
                cntA++;
            }
            if(s[i].charAt(0) == 'B' && s[i].charAt(s[i].length()-1) != 'A'){
                cntB++;
            }
            if(s[i].charAt(s[i].length()-1) == 'A' && s[i].charAt(0) == 'B')
                cnt++;
        }
        sc.close();

        int min = Math.min(cntA, cntB);
        if(cnt != 0){
            if(cntA + cntB == 0)
                min += (cnt-1);
            else
                min += cnt;
        }
        System.out.println(ans+min);
    }
}

Measured memory_bytes: 29824
using System;
using System.Linq;

class p{
  static void Main(){
    int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int K = n[0];
    int S = n[1];
    int ans = 0;
    for(int x = 0; x <= K&&x <= S; x++){
      for(int y = 0; y <= S - x&&y <= K; y++){
        if(S - x - y >= 0&&S - x - y <= K) ans++;
      }
    }
    Console.WriteLine(ans);
  }
}

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

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 1e5 + 10, Mod = 1e9 + 7;
int f[31];
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>(), m = gi<int>();
	f[0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < 30; j++)
			f[j] = (f[j - 1] + f[j]) % Mod;
	int ans = 1;
	for (int i = 2; m > 1; i++)
		if (m % i == 0) {
			int cnt = 0;
			while (m % i == 0) m /= i, cnt++;
			ans = 1ll * ans * f[cnt] % Mod;
		}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M, A := nextInt(), nextInt(), []int{}
	for i := 0; i < N; i++ {
		A = append(A, nextInt())
	}

	fmt.Printf("%d\n", ABC141D(M, A))
}

// ABC141D ...
func ABC141D(M int, A []int) (res int) {
	ih := &intHeap{}
	heap.Init(ih)
	for i := 0; i < len(A); i++ {
		heap.Push(ih, A[i])
	}

	for i := 0; i < M; i++ {
		max := heap.Pop(ih).(int)
		heap.Push(ih, max/2)
	}

	for ih.Len() > 0 {
		res += heap.Pop(ih).(int)
	}

	return
}

type intHeap []int

func (h intHeap) Len() int           { return len(h) }
func (h intHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h intHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}
func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

Measured memory_bytes: 8368
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <numeric>
#include <climits>

using namespace std;

int main()
{
    int A, B, M;
    cin >> A>>B>>M;
    vector<int> valueA(A);
    vector<int> valueB(B);
    vector<int> setx(M);
    vector<int> sety(M);
    vector<int> waribiki(M);
    for (int a = 0; a < A; ++a)
    {
        cin >> valueA.at(a);
    }
    for (int b = 0; b < B; ++b)
    {
        cin >> valueB.at(b);
    }

    for (int m = 0; m < M; m++)
    {
        cin >> setx.at(m)>> sety.at(m)>> waribiki.at(m);
    }

    int minA;
    if (valueA.size() == 1)
    {
        minA = valueA.at(0);
    }
    else{
        minA = *min_element(valueA.begin(), valueA.end());
    }

    int minB;
    if(valueB.size() == 1){
        minB = valueB.at(0);
    }
    else{
        minB = *min_element(valueB.begin(), valueB.end());
    }
    long minvalue = minA + minB;

    for (int m = 0; m < M; ++m)
    {
        long value = valueA.at(setx.at(m) - 1) + valueB.at(sety.at(m) -1 ) - waribiki.at(m);
        if(minvalue>value){
            minvalue = value;
        }
    }
    cout << minvalue << endl;
}

Measured memory_bytes: 2176
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
S = [[], [], []]
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            S[i].append(1)
        else:
            S[i].append(0)

t = 0


for i in range(3):
    if sum(S[i]) == 3:
        t = 1
    for j in range(3):
        if sum([S[i][j] for i in range(3)]) == 3:
            t = 1
if S[0][0] + S[1][1] + S[2][2] == 3 or S[0][2] + S[1][1] + S[2][0] == 3:
    t = 1

if t:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
N = int(input())
ac = 0
tle = 0
wa = 0
re = 0
for i in range(N):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "TLE":
        tle += 1
    elif s == "WA":
        wa += 1
    else:
        re += 1

print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)

Measured memory_bytes: 9200
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		long A = nextLong();
		long B = nextLong();
		int  C = nextInt();
		int  D = nextInt();

		long Anum=0,Bnum=0;

		//lcm
		long lcm = C/gcd(C,D)*D;
		A--;
		Anum = A - A/C - A/D + A/lcm;
		Bnum = B - B/C - B/D + B/lcm;

		out.println(Bnum-Anum);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}

}

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

int main() {
  int N, K; cin >> N >> K;
  double p = 0;
  for (int d = 1; d <= N; d++) {
    int score = d;
    double coin_p = 1.0;
    while (score < K) {
      coin_p *= 0.5; score *= 2;
    }
    p += coin_p/N;
  }
  cout << setprecision(12) << p << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; in(N);

  vi A(N);
  rep(i, N) {
    in(A[i]);
  }
  sort(all(A));

  vi p(N);
  rep(i, N-1) {
    if (i % 2 == 0) {
      ++p[i]; --p[i+1];
    } else {
      --p[i]; ++p[i+1];
    }
  }
  sort(all(p));
  ll sum = 0, sum2 = 0;
  rep(i, N) {
    sum += p[i] * A[i];
    sum2 -= p[i] * A[N-1-i];
  }
  out(max(sum, sum2));

  return 0;
}


Measured memory_bytes: 1024
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());




int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		// reverse(a.begin(),a.end());
		cin>>s;
		n=s.length();
		// ll a[n];
		rep(i,n-1)
		{
			if(s[i]==s[i+1])
			{
				cout<<"Bad";
				return 0;
			}
		}
		
		
		cout<<"Good";
		
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x, y;
    cin >> x >> y;
    if (x == 2) cout << "No" << endl;
    else if (x == 4 || x == 6 || x == 9 || x == 11) {
        if (y == 4 || y == 6 || y == 9 || y == 11) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
const int mod1=998244353;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	vector<pair<ll,ll>> b(m);
	rep(i,m) cin >> b.at(i).second >> b.at(i).first;
	sort(a.rbegin(),a.rend());
	sort(b.rbegin(),b.rend());
	ll ans=0,cnt=0;
	int i=0,j=0;
	while(true){
		if(j>=m || (a.at(i)>b.at(j).first && i<n)){
			ans+=a.at(i);
			cnt++;
			i++;
		}
		else{
			ans+=min(n-cnt,b.at(j).second)*b.at(j).first;
			cnt+=min(n-cnt,b.at(j).second);
			j++;
		}
		if(cnt==n) break;
	}
	cout << ans << endl;
}


Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;
int main() {
	int a,b,c;
	cin >> a>>b>>c;
	int ans = (a - b) % c;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(scanner.next());
        }
        Arrays.sort(A);
        int sum = 0;
        for (int i = 0; i < N - 1; i++) {
            sum += A[i];
        }
        sum += A[N - 1] / 2;

        System.out.println(sum);
    }

}



Measured memory_bytes: 23764
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        A: u64,
        _B: u64,
        _C: u64,
        _D: u64,
        E: u64,
        K: u64,
    }
    println!("{}", if E-A<=K{"Yay!"}else{":("});
}


Measured memory_bytes: 4352
module mod_tree
  implicit none
  type arraylist
    integer :: num = 0
    integer, pointer :: arr(:) => null()
  end type
  type tree
    type(arraylist), pointer :: egs(:) => null()
    integer, pointer :: dist(:) => null()
  contains
    procedure :: add => add
    procedure :: dfs => dfs
  end type
  interface tree
    module procedure :: newt
  end interface tree
contains
  subroutine appende(a)
    integer, pointer, intent(inout) :: a(:)
    integer :: n
    integer, allocatable :: tmp(:)
    n = size(a)
    allocate(tmp(n))
    tmp = a
    deallocate(a)
    allocate(a(2*n))
    a(1:n) = tmp
    deallocate(tmp)
  end
  subroutine adde(list,e)
    class(arraylist), intent(inout) :: list
    integer, intent(in) :: e
    if (.not.associated(list%arr)) allocate(list%arr(1))
    if (list%num == size(list%arr)) call appende(list%arr)
    list%num = list%num+1
    list%arr(list%num) = e
  end
  function gete(list,i) result(ret)
    class(arraylist), intent(inout) :: list
    integer, intent(in) :: i
    integer :: ret
    ret = list%arr(i)
  end
  function newt(n) result(ret)
    integer, intent(in) :: n
    type(tree) :: ret
    allocate(ret%egs(n))
    allocate(ret%dist(n))
    ret%dist = 0
  end
  subroutine add(this,fm,to)
    class(tree), intent(inout) :: this
    integer, intent(in) :: fm, to
    call adde(this%egs(fm),to)
  end
  recursive subroutine dfs(this,v,p,d)
    class(tree), intent(inout) :: this
    integer, intent(in) :: v, p, d
    integer :: n, i, u
    this%dist(v) = d
    n = this%egs(v)%num
    do i = 1, n
      u = gete(this%egs(v),i)
      if (u == p) cycle
      call dfs(this,u,v,d+1)
    end do
  end
end module mod_tree
program playing_tag_on_tree
  use mod_tree
  integer :: n, u, v, a, b, i, x = 0
  integer, dimension(100000) :: du = 0, dv = 0
  type(tree) :: t
  read(*,*) n, u, v
  t = tree(n)
  do i = 1, n-1
    read(*,*) a, b
    call t%add(a,b)
    call t%add(b,a)
  end do
  call t%dfs(u,-1,0)
  du(1:n) = t%dist(1:n)
  call t%dfs(v,-1,0)
  dv(1:n) = t%dist(1:n)
  do i = 1, n
    if (t%egs(i)%num > 1) cycle
    if (du(i) < dv(i)) x = max(x,dv(i)-1)
  end do
  write(*,'(i0)') x
end program playing_tag_on_tree

Measured memory_bytes: 16384
import java.util.Scanner;
import java.lang.Math;

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

		int n = sc.nextInt();
		int[] x = new int[n];
		for(int i = 0; i < n; i++){
			x[i] = sc.nextInt();
		}
		int ave = 0;
		for(int data: x){
			ave += data;
		}
		ave = (int)Math.rint((double)ave / n);
		int sum = 0;
		for(int data: x){
			sum += Math.pow((data - ave), 2);
		}
		System.out.println(sum);

	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int a[3][3];
    bool open[3][3];
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> a[i][j];
            open[i][j] = false;
        }
    }

    int n; cin >> n;
    for(int i=0; i<n; i++){
        int b; cin >> b;
        for(int ii=0; ii<3; ii++){
            for(int jj=0; jj<3; jj++){
                if(a[ii][jj] == b) open[ii][jj] = true;
            }
        }
    }

    bool bingo = false;
    if(open[0][0] == true && open[0][1] == true && open[0][2] == true) bingo = true;
    if(open[1][0] == true && open[1][1] == true && open[1][2] == true) bingo = true;
    if(open[2][0] == true && open[2][1] == true && open[2][2] == true) bingo = true;
    if(open[0][0] == true && open[1][0] == true && open[2][0] == true) bingo = true;
    if(open[0][1] == true && open[1][1] == true && open[2][1] == true) bingo = true;
    if(open[0][2] == true && open[1][2] == true && open[2][2] == true) bingo = true;
    if(open[0][0] == true && open[1][1] == true && open[2][2] == true) bingo = true;
    if(open[2][0] == true && open[1][1] == true && open[0][2] == true) bingo = true;

    if(bingo) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

// const int di[] = {-1,0,1,0};
// const int dj[] = {0,-1,0,1};

pair<int, int> dhw[] = { // <h, w>
        { 1, 0},
{ 0,-1},        { 0, 1},
        {-1, 0},
{ 2,-2},{ 2,-1},{ 2, 0},{ 2, 1},{ 2, 2},
{ 1,-2},{ 1,-1},        { 1, 1},{ 1, 2},
{ 0,-2},                        { 0, 2},
{-1,-2},{-1,-1},        {-1, 1},{-1, 2},
{-2,-2},{-2,-1},{-2, 0},{-2, 1},{-2, 2}
};

int main() {
  int h, w; cin>>h>>w;
  int si, sj; cin>>si>>sj;
  int ti, tj; cin>>ti>>tj; --si; --sj; --ti; --tj;
  vector<string> s(h); rep(i,h) cin>>s[i];

  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  dist[si][sj] = 0;
  deque<P> q;
  q.emplace_back(si,sj);

  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    // if (dist[i][j] != d) continue;

    rep(v,4) {
      // int ni = i+di[v], nj = j+dj[v];
      int ni = i+dhw[v].first, nj = j+dhw[v].second;
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }

    // for (int ei = -2; ei <= 2; ++ei) {
    //   for (int ej = -2; ej <= 2; ++ej) {
		for(int v=4; v<24; ++v){
			// int ni = i+ei, nj = j+ej;
      int ni = i+dhw[v].first, nj = j+dhw[v].second;
			if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
			if (s[ni][nj] == '#') continue;
			if (dist[ni][nj] <= d+1) continue;
			dist[ni][nj] = d+1;
			q.emplace_back(ni,nj);
      // }
    }

  }

  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 9520
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,u,sum=0,a[1001]={0};
    cin>>n>>u;
    for(int i=1;i<=n;i++)
	{
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
	{
        if(a[i]<=u/2) 
		sum+=a[i]*2;
        else 
		sum+=(u-a[i])*2;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
loop do
  n = gets.chomp.to_i
  break if n == 0

  scores = gets.chomp.split.map(&:to_f)

  m = scores.inject(&:+) / scores.length

  sigma = scores.map { |s_i| (s_i - m) **2 }.sum

  puts Math.sqrt(sigma / n)
end



Measured memory_bytes: 6964
#include <stdio.h>

int compare_long(const void *a, const void *b) {
	long *x = (long *)a;
	long *y = (long *)b;

	if(*x > *y) {
		return -1;
	} else if(*x < *y) {
		return 1;
	} else {
		return 0;
	}
}

int main() {
	long N;
	long *A, *cpy_A;
	long i;

	scanf("%ld", &N);

	A = (long *)malloc(sizeof(long) * N);
	cpy_A = (long *)malloc(sizeof(long) * N);

	for(i = 0; i < N; i++) {
		scanf("%ld", &A[i]);
	}

	memcpy(cpy_A, A, sizeof(long) * N);

	qsort(A, N, sizeof(A[0]), compare_long);
	
	for(i = 0; i < N; i++) {
		if(A[0] == cpy_A[i]) {
			printf("%ld\n", A[1]);
		} else {
			printf("%ld\n", A[0]);
		}
	}

	return 0;
}



Measured memory_bytes: 4860
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>
 
#define N 200005
#define M 8000005
 
#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)
 
#define mk make_pair
#define pb push_back
#define fi first
#define se second
 
#define Mo 1000000007
 
using namespace std;
 
int i,j,m,n,p,k,s[N],q,l,r,g[N];
 
vector<int>v[N];
 
int f[N],tree[N*4];
 
int ask(int ll,int l,int r,int t)
{
		if (l==r) return tree[t];
		else 
		{
				if (ll<=mid) return min(tree[t],ask(ll,l,mid,ls));
				else return min(tree[t],ask(ll,mid+1,r,rs));
		}
}
 
void insert(int ll,int rr,int c,int l,int r,int t)
{
		if (ll<=l&&r<=rr) tree[t]=min(tree[t],c);
		else 
		{
				if (ll<=mid) insert(ll,rr,c,l,mid,ls);
				if (rr>mid)  insert(ll,rr,c,mid+1,r,rs);
		}
}
 
 
void build_tree(int l,int r,int t)
{
		tree[t]=(int)1e9;
		if  (l==r) return;
		build_tree(l,mid,ls);
		build_tree(mid+1,r,rs);
}
 
int main()
{
		scanf("%d",&n);
		for (i=1;i<=n;++i) scanf("%d",&s[i]),s[i]+=s[i-1];
		scanf("%d",&q);
		for (i=1;i<=q;++i) 
			scanf("%d%d",&l,&r),v[r].pb(l);
		memset(f,60,sizeof(f));
		memset(g,60,sizeof(g));
		f[0]=0; g[0]=0;
		build_tree(0,n,1);
		for (i=1;i<=n;++i)
		{
				g[i]=min(g[i-1],f[i-1])+(s[i]-s[i-1]==1);
				int G;
				for (int j: v[i])
					G=min(g[j-1]+(i-s[i])-(j-1-s[j-1]),(i-s[i])+ask(j-1,0,n,1)),
					insert(j,i,-(i-s[i])+G,0,n,1),
					f[i]=min(f[i],G);
		}
		printf("%d\n",min(f[n],g[n]));
}

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

int main(){
  int n;
  cin >> n;
  vector<long long int> a(n);
  for(int i=0; i<n; i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  long long int ans=0;
  long long int ans2=0;
  if(n>=4){
  if(n%2 == 0){
    for(int i=0; i<n; i++){
      if(i+1<n/2){
        ans -= a.at(i)*2;
      }
      if(i+1 == n/2){
        ans -= a.at(i);
      }
      if(i+1 == n/2+1){
        ans += a.at(i);
      }
      if(i+1 > n/2+1){
        ans += a.at(i)*2;
      }
    }
  }else{
    for(int i=0; i<n; i++){
      if(i+1<(n-1)/2){
        ans -= a.at(i)*2;
      }
      if(i+1 == (n-1)/2){
        ans -= a.at(i);
      }
      if(i+1 == (n+1)/2){
        ans -= a.at(i);
      }
      if(i+1 > (n+1)/2){
        ans += a.at(i)*2;
      }
      
      if(i+1<(n+1)/2){
        ans2 -= a.at(i)*2;
      }
      if(i+1 == (n+1)/2){
        ans2 += a.at(i);
      }
      if(i+1 == (n+3)/2){
        ans2 += a.at(i);
      }
      if(i+1 > (n+3)/2){
        ans2 += a.at(i)*2;
      }
    }
  }
  }
  if(n == 2){
    ans = a.at(1)-a.at(0);
  }
  if(n == 3){
    ans = max(a.at(1)-a.at(0)+a.at(2)-a.at(0),a.at(2)-a.at(1)+a.at(2)-a.at(0));
  }
  cout << max(ans,ans2) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		ULL ans = 0;
		UL p = 1;
		rep(i, N) {
			UL t = (A[i] - 1) / p;
			if (p == 1 || A[i] == p) {
				p++;
			}
			ans += t;
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 640
N, K = (int(i) for i in input().split())
S = list(input())
K -= 1
x = S.pop(K)

if x == 'A':
  x = 'a'
elif x == 'B':
  x = 'b'
else:
  x = 'c'
S.insert(K, x)
ans = ''
for i in S:
  ans += i
print(ans)

Measured memory_bytes: 3064
import collections
n=int(input())
v=list(map(int, input().split()))
v1=v[0:n:2]
v2=v[1:n:2]
v10=collections.Counter(v1)
v11=v10.most_common()
v20=collections.Counter(v2)
v21=v20.most_common()
if v11[0][0]==v21[0][0] and v11[0][1]==n//2 and v21[0][1]==n//2:
    print(n//2)
elif v11[0][0]==v21[0][0]:
    x1=n//2-v11[0][1]
    x2=n//2-v11[1][1]
    y1=n//2-v21[0][1]
    y2=n//2-v21[1][1]
    print(min(x1+y2,x2+y1))
    
else:
    x1=n//2-v11[0][1]
    y1=n//2-v21[0][1]
    print(x1+y1)

Measured memory_bytes: 21952
n = int(input())
ls = list(map(int, input().split()))

count = 0
for i in range(1, n-1):
  if ls[i-1] < ls[i] and ls[i] < ls[i+1]:
    count += 1
  elif ls[i-1] > ls[i] and ls[i] > ls[i+1]:
    count += 1

print(str(count))
    

Measured memory_bytes: 3060
n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())

import itertools
import math

allx = list(itertools.permutations(x,2))
ally = list(itertools.permutations(y,2))


anslist = []

for (a,b) in zip(allx,ally):
    anslist.append(math.sqrt(pow(a[0] - a[1],2) + pow(b[0] - b[1],2)))

nn = n - 1
lastans = sum(anslist) * nn / len(anslist)

print(lastans)

Measured memory_bytes: 38256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp90 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Console.WriteLine(a.Sum() - N);


        }
    }
}

Measured memory_bytes: 11384
/*秒単位の時間 S を、h:m:s の形式へ変換して出力する*/

#include <stdio.h>

int main(){
    
    int S;
    int h,m,s;
    
    do{
        scanf("%d",&S);
    }while(S<0 || S>=86400); /*0≤S<86400を満たすまで繰り返される*/
    
    h  = S/3600;
    m = (S%3600)/60;
    s  = (S%3600)%60;  /*1時間(3600秒)で割り、その余りを1分(60秒)で割った余り*/
    
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

int main() {
	ll numRoom, numRoad;
	cin >> numRoom >> numRoad;
	vector<vector<ll>> adjacentList;
	vector<ll> milestone;
	adjacentList.resize(numRoom + 1);
	milestone.resize(numRoom + 1, -1);
	for (ll i = 0; i < numRoad; i++) {
		ll a, b;
		cin >> a >> b;
		adjacentList[a].push_back(b);
		adjacentList[b].push_back(a);
	}
	queue <ll> Q;
	Q.push(1);
	milestone[1] = 0;
	while (!Q.empty()) {
		ll now = Q.front();
		Q.pop();
		for (auto itr = adjacentList[now].begin(); itr != adjacentList[now].end(); itr++) {
			if (milestone[*itr] == -1) {
				milestone[*itr] = now;
				Q.push(*itr);
			}
		}
	}
	cout << "Yes" << endl;
	for (ll i = 2; i <= numRoom; i++) {
		cout << milestone[i] << endl;
	}

	
} 

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

int bubbleSort(int values[], int n) {
  bool flag = true;
  int switch_count = 0;
  while(flag) {
    flag = false;
    for (int j = n - 1; j > 0; j--) {
      if (values[j] < values[j - 1]) {
        int values_j = values[j];
        values[j] = values[j - 1];
        values[j - 1] = values_j;
        flag = true;
        switch_count++;
      }
    }
  }
  return switch_count;
}

int main() {
  int n;
  cin >> n;
  int values[n];

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

  int switch_count = bubbleSort(values, n);

  for (int j = 0; j < n - 1; j++) {
    cout << values[j] << " ";
  }
  cout << values[n - 1] << endl;
  cout << switch_count << endl;

}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
    //-----------------
    string s;
    cin >> s;
    int n = 0;
    int size = s.size();
    ull wn = 0;
    ull wnn = 0;
    REP(i, size)
    {
        if( s[i] == 'W' )
        {
            ++wn;
            wnn += i;
        }
    }
    cout << wnn - ( wn * ( wn - 1 ) ) / 2 << endl;
    //----------------
return 0;
}

Measured memory_bytes: 640
#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>;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
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 (b<a) {a=b; return 1;} return 0;}

vector<ll> enum_div(ll n) {
    vector<ll> result;
    for (ll i = 1; i*i <= n; i++) {
        if (n % i == 0) {
            result.push_back(i);
            if (i*i != n) {
                result.push_back(n/i);
            }
        }
    }
    return result;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n;
    cin >> n;
    vll div = enum_div(n);
    ll ans = 0;
    rep(i, div.size()) {
        ll m = div[i]-1;
        if (m == 0) continue;
        if (n / m == n % m) ans += m;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>

int main() {
	std::string str,tmp;
	std::cin >> str;
	
	
	for (size_t i{ 0 }; i < str.size(); i++) {
		if (str[i] == 'B') {
			if(tmp.size()>0)tmp.pop_back();
		}
		else {
			tmp += str[i];
		}
	}
	std::cout << tmp << "\n";
		return 0;
	
}


Measured memory_bytes: 256
h, w = map(int,input().split())

maze = []
for i in range(h):
    t = list(input())
    maze.append(t)
    
dx = [1, 0]
dy = [0, 1]


dp = [[10000]*w for i in range(h)]
if maze[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

for x in range(w):
    for y in range(h):
        for dxi, dyi in zip(dx, dy):
            if not (0<=x+dxi<w and 0<=y+dyi<h):
                continue
            dp[y+dyi][x+dxi] = min(dp[y+dyi][x+dxi], dp[y][x]+(maze[y][x]=="." and maze[y+dyi][x+dxi]=="#"))
            
#print(*dp)
print(dp[h-1][w-1])

Measured memory_bytes: 74340
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
int n,m,ans=0,cnt=1;
string s;
int main(){
    scanf("%d%d",&n,&m);
    cin>>s;
    char pre=s[0];
    for(int i=1;i<n;i++){
        if(s[i]==pre)ans++;
        else pre=s[i],cnt++;
    }

    if(cnt-m*2>=1)cnt-=m*2;
    else cnt=1;
    printf("%d\n",n-cnt);
    return 0;
}

Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
void func(int cnt);
int MAX;
int r,c;
int senbe[11][10001];
int main(void){
	int i,j;
	while(1){
		MAX=-1;
		cin>>r>>c;
		if(r==0&&c==0)	break;
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				cin>>senbe[i][j];
			}
		}
		func(0);
		cout<<MAX<<endl;
	}
	return 0;
}
void func(int cnt){
	int i,j;
	int cost;
	int cost1;
	//cout<<" cnt= "<<cnt<<endl;
	if(cnt==r){
		int sum=0;
		/*for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				cout<<senbe[i][j];
			}
			cout<<endl;
		}
		cout<<endl;
		for(i=0;i<c;i++){
			for(j=0;j<r;j++){
				cout<<senbe[j][i];
			}
			cout<<endl;
		}
		cout<<endl;
		*/
		for(i=0;i<c;i++){
			cost1=0;
			cost=r;
			for(j=0;j<r;j++){
				//cout<<senbe[j][i]<<endl;
				cost-=senbe[j][i];
				//cout<<"cost3 "<<cost<<endl;
				cost1+=senbe[j][i];
			}
			if(cost<cost1){
			//	cout<<"cost1 "<<cost1<<endl;
				sum+=cost1;
			}
			else if(cost>cost1){
			//	cout<<"cost "<<cost<<endl;
				sum+=cost;
			}
			else{
			//	cout<<"cost "<<cost<<endl;
				sum+=cost;
			}
		}
		//cout<<"SUM="<<sum<<endl;
		MAX=max(MAX,sum);
	}
	else{
		for(i=0;i<2;i++){
			if(i==0){
				for(j=0;j<c;j++){
					if(senbe[cnt][j]==1){
						senbe[cnt][j]=0;
					}
					else{
						senbe[cnt][j]=1;
					}
				}
				func(cnt+1);
				for(j=0;j<c;j++){
					if(senbe[cnt][j]==0){
						senbe[cnt][j]=1;
					}
					else{
						senbe[cnt][j]=0;
					}
				}
			}
			else{
				//cout<<" check "<<endl;
				func(cnt+1);
			}
		}
	}
}
						


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

long long t1,t2,a1,a2,b1,b2;
long long d1,d2;
long long down,up;

int main() {
	cin>>t1>>t2>>a1>>a2>>b1>>b2;
	d1=t1*(a1-b1);
	d2=t2*(a2-b2);
	if(d1==(-d2)) {
		cout<<"infinity"<<endl;
		return 0;
	}
	down=min(min(down,d1),d1+d2);
	up=max(max(up,d1),d1+d2);
	long long ans=0;
	if(d1+d2>0) {
		ans+=((-down)/(d1+d2)+1)*2;
		if(ans>0) --ans;
		if((-down)%(d1+d2)==0) --ans;
	}
	else {
		ans+=(up/(-d1-d2)+1)*2;
		if(ans>0) --ans;
		if(up%(-d1-d2)==0) --ans;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  int N; cin >> N;
  queue<string> a,b,ba,other;
  rep(i,N){
    string s; cin >> s;
    if(s[0]=='B' && s[s.size()-1]=='A') ba.push(s);
    else if(s[0]=='B') b.push(s);
    else if(s[s.size()-1]=='A') a.push(s);
    else other.push(s);
  }
  string S="";
  string s;
  if(!a.empty()){
    s=a.front();
    S=S+s;
    a.pop();
  }
  while(!ba.empty()){
    s=ba.front();
    S=S+s;
    ba.pop();
  }
  if(!b.empty()){
    s=b.front();
    S=S+s;
    b.pop();
  }
  while(!a.empty() && !b.empty()){
    s=a.front();
    S=S+s;
    a.pop();
    s=b.front();
    S=S+s;
    b.pop();
  }
  while(!a.empty()){
    s=a.front();
    S=S+s;
    a.pop();
  }
  while(!b.empty()){
    s=b.front();
    S=S+s;
    b.pop();
  }
  while(!other.empty()){
    s=other.front();
    S=S+s;
    other.pop();
  }
  //cout << S << endl;
  int size=0,ans=0;
  rep(i,S.size()+1){
    if(i+1<S.size() && S[i]=='A' && S[i+1]=='B'){
      size++;
      i++;
    }
  }
  cout << size << endl;
  return 0;
}


Measured memory_bytes: 1020
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		/*
		 * Scannerで値取得。
		 */
		Scanner sint = new Scanner(System.in);

		//値取得
		int numN = sint.nextInt();

		sint.close();
		
		//計算可能な値上限
		final int KEISANKANOU = 10;

		int waru = 0;
		int sho = 0;
//		割り切れるか判定→割れれば割ってみる
		for(waru = 1; waru < KEISANKANOU; waru++) {
			if(numN % waru == 0) {
				sho = numN / waru;
			}
		}
		//shoが１０未満か判定
		if(sho < KEISANKANOU) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 22996
//参考:http://kmjp.hatenablog.jp/entry/2019/06/17/0930  ムズかしい.....><
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(x,to) for(x=0;x<(to);x++)
const ll MOD = 1000000007;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(void){
    int n,m; cin>>n>>m;
    vector <ll> s(n), t(m);
    for(int i=0;i<n;i++) cin>>s[i];
    for(int i=0;i<m;i++) cin>>t[i];
    vector <vector<ll>> dp(2019 ,vector <ll>(2019 ));
    vector <vector<ll>> sum(2019 ,vector <ll>(2019));
    rep(i,2019) sum[i][0]=sum[0][i]=1;
    ll ans = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i]==t[j]) {dp[i+1][j+1] = (sum[i][j])%MOD;  dp[i+1][j+1]%=MOD; ans += dp[i+1][j+1]%MOD;}
            sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] + MOD + dp[i+1][j+1] - sum[i][j]) %MOD;
        }
    }
    cout<<sum[n][m]%MOD<<endl;
    //cout<<ans%MOD<<endl;
	
}


Measured memory_bytes: 64128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n ; cin>> n;   
    bool checker = false ;
    for(int i = 1 ; i < 50001 ; i++)
    {
        int a = i*1.08 ;
        if(a==n)
        {
            checker = true;
            cout << i << endl;
            break;
        }
        if(a>n) break;
    }
    if(!checker) cout << ":(" << endl;
    return 0 ;
}

Measured memory_bytes: 3600
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


a, b, c, d = LI()
ans = max(a*c, a*d, b*c, b*d)
print(ans)


Measured memory_bytes: 9196