akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int N, K;
    vector<int> H = {};

    cin >> N;
    cin >> K;

    int bufH;
    long hsum = 0;

    for (int i = 0; i < N; i++)
    {
        cin >> bufH;
        H.push_back(bufH);
    }

    sort(H.begin(), H.end(), greater<int>());


    if (H.size() <= K)
        cout << 0;

    else
    {
        for (int i = K; i < H.size(); i++)
        {
            hsum += H[i];
        }
        cout << hsum;
    }

    return 0;
}

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

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

    int minv = 1e18;
    for(int i = 1; i * i <= n; i++){
        if(n % i == 0){
            int p = n / i;
            minv = min(minv, p + i);
        }
    }
    cout << minv - 2 << endl;
}


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

ans = "Yes"

for i in range(1, -1, -1):
    C0i = C[0][2] - C[0][i]
    C1i = C[1][2] - C[1][i]
    C2i = C[2][2] - C[2][i]
    
    if C0i != C1i or C0i != C2i:
        ans = "No"
        
print(ans)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int x, y; cin >> x >> y;
  REP(a, 100) REP(b, 100) {
    if (a + b == x && 2 * a + 4 * b == y) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		int count [] = new int[26];
		for (int i = 0; i < s.length(); i++) {
			count[s.charAt(i)-'A']++;
		}

		if((count['N'-'A'] > 0 && count['S'-'A'] == 0) || (count['N'-'A'] == 0 && count['S'-'A'] > 0)){
			System.out.println("No");
		}else if((count['W'-'A'] > 0 && count['E'-'A'] == 0) || (count['W'-'A'] == 0 && count['E'-'A'] > 0)){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}

	}
}


Measured memory_bytes: 9684
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>

int main(){
	int x, y, z, k;

	std::vector<long long> aList;
	std::vector<long long> bList;
	std::vector<long long> cList;
	std::vector<long long> abList;
	std::vector<long long> abcList;

	std::cin>>x>>y>>z>>k;
	aList.resize(x);
	bList.resize(y);
	cList.resize(z);
	abList.resize(x*y);
	abcList.resize(k*k);

	for(int i=0; i<x; i++)
		std::cin>>aList[i];

	for(int i=0; i<y; i++)
		std::cin>>bList[i];

	for(int i=0; i<z; i++)
		std::cin>>cList[i];

	for(int i=0; i<x; i++)
		for(int j=0; j<y; j++)
			abList[i*y+j]= aList[i]+bList[j];

	std::sort(abList.begin(), abList.end(), [](long long a, long long b){return a>b;});
	std::sort(cList.begin(), cList.end(), [](long long a, long long b){return a>b;});

	int len1= std::min(k, x*y);
	int len2= std::min(k, z);
	int len3= std::min(k, len1*z);

	for(int i=0; i<len1; i++)
		for(int j=0; j<len2; j++)
			abcList[i*len2+j]= abList[i]+cList[j];

	std::sort(abcList.begin(), abcList.end(), [](long long a, long long b){return a>b;});

	for(int i=0; i<len3; i++)
		std::cout<<abcList[i]<<std::endl;

	return 0;
}

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

using namespace std;

int main()
{
    int a[5];
    int k;
    for(int i = 0;i <5;i++){
        cin>>a[i];
    }
    cin>>k;
    sort(a,a+5);
    cout<<((a[4]-a[0] > k)?":(":"Yay!");
}


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

const long long mod = 1e9 + 7;

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

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

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

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

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

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

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vi l(q), r(q);
    rep(i, q) cin >> l[i] >> r[i];
    vi sum(n+1);
    rep1(i, n-1) {
        if (s[i-1]=='A' && s[i]=='C') sum[i+1] = sum[i] + 1;
        else sum[i+1] = sum[i];
    }
    rep(i, q) {
        cout << (sum[r[i]]-sum[l[i]]) << endl;
    }
    return 0;
}


Measured memory_bytes: 4572
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }


    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var input = Reads();
        var n = input[0];
        var l = new long[n];
        var input1 = Reads();
        long add = 0;
        for (int i = 0; i < n; i++)
        {
            l[i] = input1[i];
            add += l[i];
        }
        var max = l.Max();
        if (max < add - max)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");



        Console.Out.Flush();
    }
}

Measured memory_bytes: 13524
#include<bits/stdc++.h>
#define boost ios::sync_with_stdio(false); cin.tie(0)
#define ll              long long int
#define ld              long double
#define mk              make_pair
#define pb              push_back
#define f               first
#define s               second
#define fo(i,a,b)       for(i=a;i<b;i++)
#define foe(i,a,b)      for(i=a;i<=b;i++)
#define all(x)          x.begin(),x.end()
// #define vi               vector<int>
#define vl              vector <long long int>
// #define pii          pair <int,int>
#define pll             pair <long long int, long long int>
// #define vpii         vector< pair<int,int> >
#define vpll            vector < pair <long long int,long long int> >
#define MOD             1000000007
using namespace std;
const int inf = INT_MAX;
const ll inf64 = LLONG_MAX;

ll ac, wa, tle, re;
int main()
{
    boost;
    ll n;
    cin >> n;
    while (n--)
    {
        string s;
        cin >> s;
        if (s == "AC")ac++;
        if (s == "TLE")tle++;
        if (s == "WA")wa++;
        if (s == "RE")re++;
    }
    cout << "AC x " << ac << '\n';
    cout << "WA x " << wa << '\n';
    cout << "TLE x " << tle << '\n';
    cout << "RE x " << re << '\n';



    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  string S; cin >> S;
  char dir = 'R';
  ll count = 0;
  vector<ll> x;
  for(char c:S) {
    if(c == dir) {
      ++count;
    } else {
      dir = c;
      x.push_back(count);
      count = 1;
    }
  }
  x.push_back(count);
  vector<ll> y;
  for(ll i=0; i<x.size()-1; i+=2) {
    ll tmp = x[i]+x[i+1];
    if(tmp%2 == 0) {
      y.push_back(tmp/2);
      y.push_back(tmp/2);
    } else {
      if(x[i]%2==0) {
        y.push_back(tmp/2);
        y.push_back(tmp/2+1);
      } else {
        y.push_back(tmp/2+1);
        y.push_back(tmp/2);
      }
    }
  }
  for(ll i=0, j=0; i<S.size(); ++i) {
    if(i-1 >= 0 && S[i] == 'L' && S[i-1] == 'R') {
       cout << y[j++] << " ";
    } else if(i+1 < S.size() && S[i] == 'R' && S[i+1] == 'L') {
       cout << y[j++] << " ";
    } else {
      cout << "0 ";
    }
  }
}

Measured memory_bytes: 2676
#include<stdio.h>

int main(){
  long long  i,j,k;
  long long s,t=100000000000000000000;
  long long int A,B;
  
  scanf("%lld %lld",&A,&B);
  
  for(i=A;i<B;i++){
    for(j=i+1;j<=B;j++){
      s= (i*j) % 2019;
      if(s < t)
        t=s;
      if(t == 0){
        puts("0");
        return 0;
      }
    }
  }
  printf("%lld\n",t);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<set>
using namespace std;
set<int> st;
set<int>::iterator it;
int main(){
	int n;
	cin>>n;
	while(n--){
		int a;
		cin>>a;
		it=st.find(a);
		if(it!=st.end()) st.erase(a);
		else st.insert(a);
	}
	int ans=0;
	for(int i=0;i<st.size();i++) ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
#define newline std::cout<<'\n';
#define newlinedx(num) for(int i=0;i<num;i++)std::cout<<'\n';
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ui = uint64_t;

//----------------library in this time--------------------------------
template <class T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <class T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <class T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}

long long squareTwo(const long long a,const long long b) {
    return (b == 1) ? a : squareTwo(a * 2, b - 1);
}

template <class T>
inline T Max(const T a,const T b) {
    return (a >= b) ? a : b;
}

template <class T>
inline T Min(const T a,const T b) {
    return (a <= b) ? a : b;
}


//------------------------main function-------------------------------
void Main(){
    int n, a, b; cin >> n >> a >> b;
    cout << min(b, n*a) << endl;
}

//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
     
    Main();
    return 0;
}


Measured memory_bytes: 256
N = int(input())
 
BA = []
 
for _ in range(N):
    a, b = list(map(int, input().split()))
    BA.append([b, a])
 
BA.sort()
 
a = 0
 
flg = False
for ba in BA:
    b = ba[0]
    a += ba[1]
    if b < a:
        flg = True
        break
 
if flg:
    print("No")
else:
    print("Yes")

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

ll comb[99][99];

int main(){
  comb[0][0] = 1;
  for(int i=1;i<=60;i++){
    comb[i][0] = comb[i][i] = 1;
    for(int j=1;j<i;j++)comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
  }

  ll n,m;
  while(cin >> n >> m, n){
    m--;
    int k = 0;
    while(comb[n][k]<=m){
      m -= comb[n][k]; k++;
    }

    string res = "";
    for(int i=0;i<n;i++){
      if(n-i == k){
	for(int j=0;j<k;j++)res += "1";
	break;
      }else{
	int rem = n-i-1;
	if(comb[rem][k]<=m){
	  m -= comb[rem][k]; k--;
	  res += "1";
	}else{
	  res += "0";
	}
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;
  vl a(n);
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  
  cerr << sum << endl;
  ll ans = sum;

  ll c = 0;
  rep(i, n) {
    c += a[i];
    cmin(ans, abs(sum-2*c));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
std::istream& operator>>(std::istream &is, std::vector<T> &v)
{
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

using namespace std;

const uint64_t M = 26;

int main()
{
  uint64_t D;
  cin >> D;

  vector<int64_t> c(M);
  cin >> c;

  vector<vector<int64_t>> s(D, vector<int64_t>(M));
  N_TIMES(d, D) {
    cin >> s[d];
  }

  vector<int64_t> t(D);
  cin >> t;
  N_TIMES(d, D) { --t[d]; }

  vector<set<uint64_t, greater<uint64_t>>> last(M);
  N_TIMES(m, M) { last[m].insert(0); }

  vector<int64_t> dissatisfied(M, 0);

  auto calc_score = [&](const vector<int64_t> &t) {
    int64_t score = 0;
    N_TIMES(d, D) {
      score += s[d][t[d]];
      last[t[d]].insert(d + 1);
      N_TIMES(m, M) {
        int64_t val = c[m] * ((d + 1) - *last[m].lower_bound(d + 1));
        dissatisfied[m] += val;
        score -= val;
      }
    }
    return score;
  };

  int64_t S = calc_score(t);

  uint64_t Q;
  cin >> Q;

  auto query = [&](uint64_t d, uint64_t q) {
    int64_t T = 0;

    T -= s[d][t[d]];
    last[t[d]].erase(d + 1);

    T += dissatisfied[t[d]];
    dissatisfied[t[d]] = 0;
    N_TIMES(i, D) {
      dissatisfied[t[d]] += c[t[d]] * ((i + 1) - *last[t[d]].lower_bound(i + 1));
    }
    T -= dissatisfied[t[d]];

    t[d] = q;

    T += s[d][q];
    last[q].insert(d + 1);
    
    T += dissatisfied[q];
    dissatisfied[q] = 0;
    N_TIMES(i, D) {
      dissatisfied[q] += c[q] * ((i + 1) - *last[q].lower_bound(i + 1));
    }
    T -= dissatisfied[q];

    S += T;

    return S;
  };

  N_TIMES(i, Q) {
    uint64_t d, q;
    cin >> d >> q;
    --d; --q;

    cout << query(d, q) << endl;
  }

  return 0;
}

Measured memory_bytes: 3576
package main

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

var sc = bufio.NewScanner(os.Stdin)

type st struct {
	ind int
	min int64
}

func main() {
	var N int
	var X int
	var T int
	fmt.Scan(&N)
	fmt.Scan(&X)
	fmt.Scan(&T)

	// sc.Split(bufio.ScanWords)
    s := N/X
    ss := N %X
    if ss !=0{
        s++
    }
    fmt.Println(T *s)
}
func bc(s string, pos int) string {
	ch := "1"
	if string(s[pos]) == "1" {
		ch = "0"
	}
	pre := string(s[:pos])
	post := ""
	if pos != len(s)-1 {
		post = string(s[pos+1:])
	}
	tmp := pre + ch + post
	return tmp
}
func popCount(n string) int {
	count := 0
	for _, s := range n {
		if string(s) == "1" {
			count++
		}
	}
	return count
}
func chc(m [][]bool, p int) [][]bool {
	ret := make([][]bool, len(m))
	for i, l := range m {
		tmp := []bool{}
		for _, c := range l {
			if i == p {
				tmp = append(tmp, false)
			} else if c == true {
				tmp = append(tmp, true)
			} else {
				tmp = append(tmp, false)
			}
		}
		ret[i] = tmp
	}
	return ret
}
func chl(m [][]bool, p int) [][]bool {
	ret := make([][]bool, len(m))
	for j, l := range m {
		tmp := []bool{}
		for i, c := range l {
			if i == p {
				tmp = append(tmp, false)
			} else if c == true {
				tmp = append(tmp, true)
			} else {
				tmp = append(tmp, false)
			}
		}
		ret[j] = tmp
	}
	return ret
}
func helper(ma [][]bool) int {
	count := 0
	for _, l := range ma {
		for _, c := range l {
			if c == true {
				count++
			}
		}
	}
	return count
}
func nextLine() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int64 {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return int64(i)
}
func MySort(a []int) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

}
func SortedBinaryAppend(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinaryDelete(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinarySearch(sortedArr []int, targetValue int) int {
	post := len(sortedArr) - 1
	pre := 0
	for {
		div := (post + pre) / 2
		tim := sortedArr[div]
		if tim == targetValue {
			return pre + div
		} else if tim > targetValue {
			post = tim
		} else {
			pre = tim
		}
		if pre == post {
			return -1
		}
	}
}
func Abs(i int) int {
	if i < 0 {
		return -1 * i
	}
	return i
}
func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func CalcNum(tate int, yoko int, A int, B int, dp *map[[2]int]int) int {
	if (*dp)[[2]int{tate, yoko}] != 0 {
		return (*dp)[[2]int{tate, yoko}]
	}
	return yoko*CalcNum(tate-1, yoko, A, B, dp) + tate*CalcNum(tate, yoko-1, A, B, dp)
}
func arrSum(arr []int) int {
	sum := 0
	for _, a := range arr {
		sum += a
	}
	return sum
}
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}
func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}


Measured memory_bytes: 1772
a,b,c = map(int,input().split())
k = int(input())

ans = 'No'
d = 0

for i in range(1,k+1):
    if b <= a:
        d = d + 1
        b = b * 2
    else:
        d = d
        b = b

if d == k:
    if c > b:
        ans = 'Yes'

f = k - d
g = 1

for j in range(1,f+2):
    if c <= b:
        c = c * 2
    else:
        ans = 'Yes'

print(ans)


Measured memory_bytes: 9192
#include <bits/stdc++.h>
     
#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()
     
using namespace std;
using ll = long long;
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( a > b ) { a = b; return 1; } return 0; }
     
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main(){
  int N; cin >> N;
  vector<P> job( N );
  REP( i, N ) cin >> job[i].second >> job[i].first;

  sort( ALL( job ) );

  bool ok = true;
  ll sum = 0;
  REP( i, N ){
    sum += job[i].second;
    if( sum > job[i].first ) ok = false;
  }

  if( ok ) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


typedef pair<double,double> Pd;


int partition(vector<int> &a, int p, int r){
  int x = a[r];
  int i = p-1;
  for (int j=p; j<r; j++){
    if (a[j] <= x){
      i++;
      swap(a[i], a[j]);
    }
  }
  swap(a[i+1], a[r]);
  return i+1;
}

int main() {
  int n; cin >>n;
  vector<int> a(n); rep(i, n) cin >>a[i];
  int v = partition(a, 0, n-1);
  rep(i, n){
    if (i > 0) cout <<" ";
    if (i == v) cout <<"[";
    cout <<a[i];
    if (i == v) cout <<"]";
  }
  cout <<endl;
}


Measured memory_bytes: 3164
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int x, y;
    cin >> x >> y;
    int sum = 0;
    if( x == 3 ) sum += 1;
    if( x == 2 ) sum += 2;
    if( x == 1 ) sum += 3;
    if( y == 3 ) sum += 1;
    if( y == 2 ) sum += 2;
    if( y == 1 ) sum += 3;
    if( x == y && x == 1 ) sum += 4;
    cout << sum * 100000 << endl;
    return 0;
}



Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    n, *abc = map(int, input().split())
    query = []
    for _ in [0] * n:
        s = input()
        query.append((ord(s[0]) - ord('A'), ord(s[1]) - ord('A')))
    query.append((0, 1)) # 番兵

    ans = ['A'] * n
    for i in range(n):
        a, b = query[i]
        if abc[a] == 0 and abc[b] == 0:
            print("No")
            return
        elif abc[a] == 0:
            abc[a] += 1
            abc[b] -= 1
            ans[i] = chr(ord('A') + a)
        elif abc[b] == 0:
            abc[a] -= 1
            abc[b] += 1
            ans[i] = chr(ord('A') + b)
        else:
            if a in query[i+1]:
                abc[a] += 1
                abc[b] -= 1
                ans[i] = chr(ord('A') + a)
            else:                
                abc[a] -= 1
                abc[b] += 1
                ans[i] = chr(ord('A') + b)
    print("Yes")
    print(*ans, sep=('\n'))

main()

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

int n;
int a[200001];
int maxi=1<<31;
int maxii=-1;
int maxi2=1<<31;
int maxii2=-1;

void solve(){
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(a[i]>maxi2){
            maxi2=a[i];
            maxii2=i;
        }
        if(maxi2>maxi){
            swap(maxi,maxi2);
            swap(maxii, maxii2);
        }
    }
    for(int i=0; i<n; i++){
        if(i==maxii){
            cout<<maxi2<<endl;
        }
        else{
            cout<<maxi<<endl;
        }
    }

}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007



int main (){
    ll n ;
    cin >> n ;
    ll tot = (n + 1)*n/2 ;
    tot -= n ;
    if(n < 0) tot = 0 ;
    cout << tot << endl ; 
}


Measured memory_bytes: 3628
from collections import deque
a,b = map(int,input().split())
p = deque()
for i in range(a):
    v = input().split()
    p.append({v[0] : int(v[1])})

ans = 0
ans_list = []
while True:
    v = p.popleft()
    for k,i in v.items():
        if i - b <= 0:
            ans = ans + i
            l = {k:ans}
            ans_list.append(l)
        else:
            i = i -b
            v[k] = i
            p.append(v)
            ans = ans + b

    if len(p) == 0:
        break

for v in ans_list:
    for k,i in v.items():
        print('{} {}'.format(k,i))



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

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

    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


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

void split(string s, vector<string>&v){
    s+='"';
    v.clear();
    string tmp = "";
    for(int i=0;i<s.size();i++){
        if(s[i]=='"'){
            v.push_back(tmp);
            tmp="";
        }
        else{
            tmp+=s[i];
        }
    }
}

int main(){
    for(string s1, s2;cin>>s1;){
        if(s1==".")break;
        cin>>s2;
        vector<string>v1, v2;
        split(s1, v1);
        split(s2, v2);
        int cnt = 0;
        if(v1.size() != v2.size()){
            cout<<"DIFFERENT"<<endl;
            continue;
        }
        int fail = 0;
        for(int i=0;i<v1.size();i++){
            if(i%2==0){
                if(v1[i] != v2[i])fail=1;
            }
            else{
                if(v1[i] != v2[i])cnt++;
            }
        }
        if(fail){
            cout<<"DIFFERENT"<<endl;
            continue;
        }
        if(cnt==0){
            cout<<"IDENTICAL"<<endl;
            continue;
        }
        if(cnt==1){
            cout<<"CLOSE"<<endl;
            continue;
        }
        cout<<"DIFFERENT"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
long long mapp[305][305];

int main(){
  int n,m,l;
  cin>>n>>m>>l;
  long long inf = 1e17;
  for(int i=1; i<=n; i++)  for(int j=1; j<=n; j++){  
  if(i==j) mapp[i][j]=0;  
  else mapp[i][j]=inf;}
  for(int i=1; i<=m; i++){  
    int a,b,c;cin>>a>>b>>c;
    if(c>l)continue;
    mapp[a][b]=c; mapp[b][a]=c;
  }  
  for(int k=1; k<=n; k++)  
      for(int i=1; i<=n; i++)  
          for(int j=1; j<=n; j++)  
              if(mapp[i][k]+mapp[k][j]<mapp[i][j]){  
                  mapp[i][j] = mapp[i][k]+mapp[k][j];
              }
  for(int k=1; k<=n; k++)  
      for(int i=1; i<=n; i++)   
              if(mapp[i][k]<=l){  
                  mapp[i][k] = 1;
                  mapp[k][i] = 1;
              }else{
              	  mapp[i][k] = inf;
              	  mapp[k][i] = inf;
              }
  for(int k=1; k<=n; k++)  
      for(int i=1; i<=n; i++)  
          for(int j=1; j<=n; j++)  
              if(mapp[i][k]+mapp[k][j]<mapp[i][j]){  
                  mapp[i][j] = mapp[i][k]+mapp[k][j];
              }

  int q;cin>>q;
  for(int i=0;i<q;++i){
    int f,t;cin>>f>>t;
    if(mapp[f][t]==inf){
      cout<<-1<<endl;
    }else{
      cout<< mapp[f][t]-1 <<endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 1280
s = int(input())
a = s
i = 1
s_ = set()
s_.add(a)
while True:
  i += 1
  if a%2 == 0:
    a = a//2
  else:
    a = 3*a+1
  if a in s_:
    print(i)
    exit()
  else:
    s_.add(a)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
map<string, int> M;
int main() {
	M["RRR"] = 3;
	M["RRS"] = 2;
	M["SRR"] = 2;
	M["SSR"] = 1;
	M["SRS"] = 1;
	M["RSS"] = 1;
	M["RSR"] = 1;
	M["SSS"] = 0;
	string s;
	cin >> s;
	cout << M[s];
	return 0;
}

Measured memory_bytes: 3632
N = int(input())
a = list(map(int,input().split()))

GRAY = 400
BROWN = 800
GREEN = 1200
CYAN = 1600
BLUE = 2000
YELLOW = 2400
ORANGE = 2800
RED = 3200

colors = []
over3200 = 0

for i in a:
    if i < GRAY:
        colors.append(GRAY)
    elif i < BROWN:
        colors.append(BROWN)
    elif i < GREEN:
        colors.append(GREEN)
    elif i < CYAN:
        colors.append(CYAN)
    elif i < BLUE:
        colors.append(BLUE)
    elif i < YELLOW:
        colors.append(YELLOW)
    elif i < ORANGE:
        colors.append(ORANGE)
    elif i < RED:
        colors.append(RED)
    else:
        over3200 += 1

colornum = len(set(colors))
mincolor = max(colornum, 1)
maxcolor = colornum + over3200

print(' '.join([str(mincolor),str(maxcolor)]))

Measured memory_bytes: 3064
def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a

def cul(n,x):
    l=len(x)
    b=[x[i] for i in range(l)]
    b.pop(n)
    tmp=b[0]
    for i in range(1,l-1):
        tmp=gcd(tmp,b[i])
    return tmp

import sys
p=100
N=int(input())
a=list(map(int,input().split()))
if N<=p:
    ans=0
    
    for i in range(N):
        tmp=cul(i,a)        
        if tmp>ans: ans=tmp
    print(ans)
    sys.exit()

ans=0
for i in range(p):
    s=cul(i,a[:p])
    if s>ans: ans=s

print(ans)

Measured memory_bytes: 14488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))




int main(){
	ll n,m,k;
	set<ll> se;
	cin >> n;
	FOR(i,0,n){
		cin >> k;
		se.insert(k);
	}
	cin >> m;
	FOR(i,0,m){
		cin >> k;
		if(se.count(k)){
			se.erase(k);
		}else{
			se.insert(k);
		}
	}
	for(auto x:se){
		cout << x << endl;
	}
}



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

#define ll long long
#define mp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)

using namespace std;

typedef pair<int, int> pii;
typedef double db;
const int N = 1e6 + 50;
int n, m, q, a[2010][2010];
char s[2010][2010];
inline int read(){
	int x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar();}
	while(ch >='0' && ch <='9') { x = (x<<3)+(x<<1)+(ch^48); ch = getchar();}
	return x*f;
}
int f[2010][2010], g[2010][2010];
void getf(){
	rep(j, 1, m) f[1][j] = f[1][j-1] + a[1][j];
	rep(i, 2, n){
		f[i][1] = f[i-1][1] + a[i][1]; 
		rep(j, 2, m) f[i][j] = f[i][j-1] + f[i-1][j] - f[i-1][j-1] + a[i][j];
	}
}
void getg(){
	rep(j, 2, m) {
		g[1][j] = g[1][j-1];
		if(a[1][j] == 1 && a[1][j-1] == 1) g[1][j] += 1; 
	} 
	rep(i, 2, n) {
		g[i][2] = g[i-1][2];
		if(a[i][2] == 1 && a[i-1][2] == 1) g[i][2] += 1;
		if(a[i][2] == 1 && a[i][1] == 1) g[i][2] += 1; 
		rep(j, 3, m) {
			g[i][j] = g[i-1][j] + g[i][j-1] - g[i-1][j-1];
			if(a[i][j] == 1 && a[i-1][j] == 1) g[i][j] += 1;
			if(a[i][j] == 1 && a[i][j-1] == 1) g[i][j] += 1; 
		}
	}
}
int lin[2010][2010], row[2010][2010];
void getp(){
	rep(j, 2, m){
		lin[1][j] = lin[1][j-1];
		if(a[1][j] == 1 && a[1][j-1] == 1) lin[1][j] += 1;  
	}
	rep(i, 2, n) {
		lin[i][2] = 0;
		if(a[i][2] == 1 && a[i][1] == 1) lin[i][2] += 1;
		rep(j, 3, m) {
			lin[i][j] = lin[i][j-1];
			if(a[i][j-1] == 1 && a[i][j] == 1) lin[i][j] += 1;
		} 
	} 
	rep(i, 2, n) {
		row[i][1] = row[i-1][1];
		if(a[i][1] == 1 && a[i-1][1] == 1) row[i][1] += 1;
	}
	rep(j, 2, m) {
		row[2][j] = 0;
		if(a[2][j] == 1 && a[1][j] == 1) row[2][j] += 1;
		rep(i, 3, n) {
			row[i][j] = row[i-1][j];
			if(a[i-1][j] == 1 && a[i][j] == 1) row[i][j] += 1;
		}
	} 
}
void init(){
	n = read(), m = read(), q = read();
	rep(i, 1, n) rep(j, 1, m) cin >> s[i][j];
	rep(i, 1, n) rep(j, 1, m) a[i][j] = int(s[i][j] - '0');
	getf(); getg(); getp();
	rep(i, 1, q) {
		int x1 = read(), y1 = read(), x2 = read(), y2 = read();
		int ans1 = f[x2][y2] - f[x1-1][y2] - f[x2][y1-1] + f[x1-1][y1-1];
		int ans2 = g[x2][y2] - g[x1][y2] - g[x2][y1] + g[x1][y1] + row[x2][y1] - row[x1][y1] + lin[x1][y2] - lin[x1][y1];   
		printf("%d\n", ans1 - ans2); 
	}
} 
int main(){
//	freopen("input.in","r",stdin);
//	freopen("output.out","w",stdout);
	init(); 
	return 0;
}


Measured memory_bytes: 84608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define INF_MAX INT_MAX
#define INF_MIN ((int)1<<31)-1
using namespace std;
class Segtree{
    vector<int> tree;
    int n=1,m,Inf;
    void Set(vector<int> vec){
        rep(i,n*2-2)tree[i+1]=Inf;
        rep(i,vec.size())tree[i+n]=vec.at(i);
        update(0,n-1);
    }
    int sum(int a,int b){
        if(m==0)return max(a,b);
        else if(m==1)return min(a,b);
        else if(m==2)return a+b;
        else return a*b;
    }
    int query(int a,int b,int x,int l,int r){
        if(r<a||b<l)return Inf;
        if(a<=l&&b>=r)return tree[x];
        return sum(query(a,b,x*2,l,(l+r)/2),query(a,b,x*2+1,(l+r)/2+1,r));
    }
    void update(int l,int r){
        l+=n,r+=n;
        l/=2,r/=2;
        while(1){
            if(l==0)break;
            int xl=l;
            for(;xl<=r;xl+=2){
                tree[xl]=sum(tree[xl*2],tree[xl*2+1]);
            }
            l/=2,r/=2;
        }
    }
public:
    void Max(vector<int> vec){
        m=0;
        Inf=INF_MAX;
        Set(vec);
    }
    void Min(vector<int> vec){
        m=1;
        Inf=INF_MIN;
        Set(vec);
    }
    void Add(vector<int> vec){
        m=2;
        Inf=0;
        Set(vec);
    }
    void Multiply(vector<int> vec){
        m=3;
        Inf=1;
        Set(vec);
    }
    Segtree(int in){
        for(;in>n;n*=2);
        tree.resize(n*2);
    }
    void Set(int a,int b){
        tree[a+n]=b;
        update(a,a);
    }
    int query(int a,int b){
        return query(a,b,1,0,n-1);
    }
};
class Union_Find{
private:
    vector<int> t,s;
public:
    Union_Find(int max_length){
        rep(i,max_length+1){
            t.push_back(i);
            s.push_back(1);
        }
    }
    void Union(int x,int y){
        if(same(x,y))return;
        int tx=Find(x),ty=Find(y);
        if(s[tx]<s[ty]){
            s[ty]+=s[tx];
            t[tx]=ty;
        }
        else if(s[tx]>s[ty]){
            s[tx]+=s[ty];
            t[ty]=tx;
        }
        else if(tx>ty){
            t[tx]=ty;
            s[ty]+=s[tx];
        }
        else{
            t[ty]=tx;
            s[tx]+=s[ty];
        }
    }
    int Find(int n){
        if(t[n]==n)return n;
        else return t[n]=Find(t[n]);
    }
    bool same(int x,int y){
        return Find(x)==Find(y);
    }
};
signed main(){
    int n,m,x[100000],ans=0,memo[100000];
    scanf("%d%d",&n,&m);
    rep(i,m){
        scanf("%d",x+i);
    }
    sort(x,x+m);
    if(m==1)printf("0");
    else{
        rep(i,m-1){
            memo[i]=x[i+1]-x[i];
            ans+=x[i+1]-x[i];
        }
        sort(memo,memo+m-1);
        rep(i,n-1){
            ans-=memo[m-i-2];
        }
        printf("%d",ans);
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int cnt = 0;
	for (int i = a; i <= b; i++)
	{
		if (c % i == 0)cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>

int main(){
 using namespace std;
  int d1,w1,a1;
  int d2,w2,a2;
  
  cin>>d1>>w1>>d2>>w2;
  a1=d1*w1;
  a2=d2*w2;
  
  a1<a2? cout<<a2:cout<<a1;
  return 0;
}

Measured memory_bytes: 3624
while true
    n = gets.to_i
    break if n == 0

    arr, min = [], nil
    gets.chomp.split.map(&:to_i).each{|x|
        arr << x if x.even?
        min = x if x.odd? && (min.nil? || min > x)
    }
    arr.sort!
    m = Math.sqrt(arr[0] * arr[1] / min).to_i
    puts m
    puts arr.map{|x| x / m}.join(" ")
end


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL x, a, b; cin >> x >> a >> b;
	LL ans = abs(x - a) <= abs(x - b);
	cout << (ans ? "A" : "B") << endl;

	return 0;
}


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

using i64 = long long;

const int N = 2005;

i64 x, val, ant;
int n;

i64 a[N], t[2][N];

static void fix(int &p) {
	if (p <= 0) p = n + p;
	if (p > n) p-= n; }


int main() {
#ifdef HOME
	freopen("agc4b.in", "r", stdin);
	freopen("agc4b.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n >> x;
	for (int i = 0; i < n; ++i) {
		cin >> a[i], t[0][i] = a[i];
		ant+= a[i]; }

	for (int i = 1; i < n; ++i) {
		val = i * x;
		for (int j = 0; j < n; ++j) {
			t[1][j] = min(t[0][j], a[(j - i + n) % n]);
			val+= t[1][j]; }

		ant = min(ant, val);
		swap(t[0], t[1]); }

	cout << ant << endl;

	return 0; }


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

vector<int>E[1000];
int d[1000][1000];
int main() {
	int n;
	while(scanf("%d",&n),n){
		rep(i,n)E[i].clear();
		int s,t,m;scanf("%d%d%d",&s,&t,&m);s--;t--;
		vector<P>v;
		rep(i,m){
			int a,b;scanf("%d%d",&a,&b);a--;b--;
			v.push_back(P(a,b));
			E[a].push_back(b);
		}
		memset(d,0x3f,sizeof(d));
		rep(i,n){
			queue<int>que;
			d[i][i]=0;que.push(i);
			while(!que.empty()){
				int p=que.front();que.pop();
				for(int v:E[p]){
					if(d[i][v]==INF){
						d[i][v]=d[i][p]+1;que.push(v);
					}
				}
			}
		}
		int Min=d[s][t],id=0;
		rep(i,m){
			int a=d[s][v[i].second]+1+d[v[i].first][t];
			if(Min>a){
				Min=a;id=i+1;
			}
		}
		printf("%d %d\n",Min,id);
	}
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    for (int k = 0; k < A.size()-1; k++) {
            cout << A[k] << " ";
        }
        cout << A[N-1] << endl;
    
    for (int i = 1; i < N; i++) {
        int v = A[i];
        int j = i-1;
        while (j>=0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;

        for (int k = 0; k < A.size()-1; k++) {
            cout << A[k] << " ";
        }
        cout << A[N-1] << endl;
    }
}



Measured memory_bytes: 3088
#include<stdio.h>
int main(){
  int n,c;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    c=0;
    while(n!=1){
      if(n%2==0)n/=2;
      else      n=3*n+1;
      c++;
    }
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

int main(){
    int cardsize;
    cin >> cardsize;
    vector<int> cards(cardsize);
    for(int i = 0;i < cardsize;i++)cin >> cards[i];

    
    sort(cards.begin(),cards.end());
    reverse(cards.begin(),cards.end());
    
    int alice = 0;
    int bob = 0;
    
    for (size_t i = 0;;)
    {
        if(i < cardsize){
            alice += cards[i];
            i++;
        }
        if(i < cardsize){
            bob += cards[i];
            i++;
        }
        if(i >= cardsize)break;
    }
    cout <<  alice - bob << endl;
    return 0;
}


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

using namespace std;

const long long INF = 1e18;
const int N = 1e5;

const double PI = acos(-1);



int main() {
    int n, k, q;
    cin >> n >> k >> q;
    int a[q];
    for (int& x : a)
        cin >> x;
    int pl[n];
    for (int& x : pl)
        x = k;
    for (int x : a) {
        pl[x - 1]++;
    }
    for (int x : pl) {
        if (x - q > 0)
            cout << "Yes";
        else
            cout << "No";
        cout << endl;
    }
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

/* -- template -- */
int cnt[100];
int main() {
    int N; cin >> N;
    rep(i, N) {
        int temp = i + 1;
        for(int j = 2;j * j <= temp; ++j) {
            if(temp % j == 0){
                cnt[j]++;
                temp /= j;
                j = 1;
            }
        }
        ++cnt[temp];
    }
    sort(cnt, cnt + 100, greater<int>());
    int cnt74 = 0, cnt24 = 0, cnt14 = 0, cnt4 = 0, cnt2 = 0;
    rep(i, N) {
        if(cnt[i] >= 74)++cnt74;
        if(cnt[i] >= 24)++cnt24;
        if(cnt[i] >= 14)++cnt14;
        if(cnt[i] >= 4)++cnt4;
        if(cnt[i] >= 2)++cnt2;
    }
    cout << cnt74 + cnt24 * (cnt2 - 1) + cnt14 * (cnt4 - 1) + cnt4 * (cnt4 - 1) * (cnt2 - 2) / 2 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

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

        while(true){
            int n = sc.nextInt();
            int r = sc.nextInt();
            if(n == 0 && r == 0) break;

            ArrayList<Integer> num = new ArrayList<Integer>();
            for(int i = n; i > 0; i--){
                num.add(i);
            }

            for(int i = 0; i < r; i++){
                int p = sc.nextInt();
                int c = sc.nextInt();
                for(int j = 0; j < c; j++){
                    num.add(0, num.remove(p + c - 2));
                }
            }

            result.add(num.get(0));
        }

        for(int i : result){
            System.out.println(i);
        }

        sc.close();
    }
}


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

int main(int argc, char *argv[]){
    int n,k,d,a;
    cin >> n >> k;
    int h[n];
    for(int i=0;i<n;i++) h[i]=0;
    for(int i=0;i<k;i++){
        cin >> d;
        for(int j=0;j<d;j++){
            cin >> a;
            if(h[a-1]==0){
                n--;
                h[a-1]=1;
            }
        }
    }
    cout << n << endl;
    return 0;
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    i32 k;
    cin >> k;

    i64 ans = 0;
    for (i32 a = 1; a <= k; a++) {
        for (i32 b = 1; b <= k; b++) {
            i32 t = gcd(a, b);
            for (i32 c = 1; c <= k; c++) {
                ans += gcd(t, c);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
def main():
    N, M = map(int, input().split())

    Nlist = [0] * N
    Mlist = [1] * M

    Nlist.extend(Mlist)

    count = 0
    for i in range(0, len(Nlist)):
        for j in range(i+1, len(Nlist)):
            if (Nlist[i] + Nlist[j]) % 2 == 0:
                count += 1

    print(count)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060