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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll N;
vector<ll> P;
vector<ll> T;

void solve(vector<ll>& x1, vector<ll>& x2){
    set<ll> index;
    index.insert(N);
    for(int p = N-1; p >= 0; p--){
        ll idx = T[p];
        auto iter = index.upper_bound(idx); 
        x1[idx] = *iter;
        auto iter2 = index.upper_bound(*iter);
        if(iter2 == index.end())
            x2[idx] = *iter;
        else
            x2[idx] = *iter2;
        index.insert(idx);
    }
}

int main(){
    cin >> N;
    P.resize(N);
    T.resize(N);
    REP(i,N){
        ll p;
        cin >> p;
        p--;
        P[i] = p;
        T[p] = i;
    }

    vector<ll> L1(N);
    vector<ll> L2(N);
    vector<ll> R1(N);
    vector<ll> R2(N);

    T.push_back(N);
    P.push_back(N);

    solve(R1, R2);

    P.pop_back();
    reverse(P.begin(), P.end());
    P.push_back(N);

    T.pop_back();
    REP(i,N){
        ll p = P[i];
        T[p] = i;
    }
    T.push_back(N);

    solve(L1, L2);
    reverse(L1.begin(), L1.end());
    reverse(L2.begin(), L2.end());
    P.pop_back();
    reverse(P.begin(), P.end());

    REP(i,N){
        L1[i] = N - L1[i];
        L2[i] = N - L2[i];
    }

    ll ans = 0;
    REP(i,N){
        ll p = P[i];
        ll add = 0;
        add += (L1[i] - L2[i]) * (R1[i] - i);
        add += (R2[i] - R1[i]) * (i - L1[i] + 1);
        add *= (p+1);
        ans += add;
        //printf("%d : %lld (%lld %lld) (%lld %lld) %lld %lld\n", i, p+1, L1[i], L2[i], R1[i], R2[i], add, ans);
        //printf("%d : %lld %lld %lld\n", i, p+1, left[i], right[i]);
    }

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


Measured memory_bytes: 9696
#include <bits/stdc++.h>
#define ll uint64_t
#define vi vector <int>
#define vl vector <ll>
#define dl pair <ll, ll>
#define ii pair <ll, ll>
#define vii vector <ii>
#define graph vector <set <int> >
#define inf 1000000000
 
using namespace std;

int f(int x, int y, int z) {
    return x * x + y * y + z * z + x * y + y * z + x * z;
}
 
int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 
    int n;
    cin >> n;
    vi arr(n + 1, 0);
    for (int i = 1; i < 101; i++) {
        for (int j = 1; j < 101; j++) {
            for (int k = 1; k < 101; k++) {
                int temp = f(i, j, k);
                if (temp <= n) arr[temp]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << arr[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3436
let () =
  let rec read () =
    let (name, total, price) = Scanf.sscanf (read_line ()) "%s %d %d" (fun name am pm -> (name, am + pm, am * 200 + pm * 300)) in
    Printf.printf "%s %d %d\n" name total price;
    read ()
  in
  try
    read ()
  with
    End_of_file -> ()


Measured memory_bytes: 2372
class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        else:
            if self.size(x) < self.size(y):
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        x = self.find(x)
        return -self.parent[x]


n, m = map(int, input().split())
bridges = []
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    bridges.append((a, b))

uf = UnionFind(n)

incnv = (n - 1) * n // 2
ans = [None] * m

for i in range(m - 1, -1, -1):
    a, b = bridges[i]
    ans[i] = incnv
    if not uf.same(a, b):
        x = uf.size(a)
        incnv += x * (x - 1) // 2

        x = uf.size(b)
        incnv += x * (x - 1) // 2

        uf.unite(a, b)
        x = uf.size(a)
        incnv -= x * (x - 1) // 2

print(*ans, sep='\n')


Measured memory_bytes: 24048
n,a,b,c,d=map(int,input().split())
a-=1
b-=1
c-=1
d-=1
s=input()
m=[0 for i in range(n)]
#a-c,b-d
#abcd
#abdc
for i in range(n):
  if s[i]=="#":
    m[i]=1
if c<d:#abcd
  if "##" in s[a:d]:
    print("No")
  else:
    print("Yes")
else:#d<c abdc
  if "##" in s[a:c]:
    print("No")
  else:
    if "..." in s[b-1:d+2]:
      print("Yes")
    else:
      print("No")




Measured memory_bytes: 53624
#pragma region Template
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using VP = vector<PII>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX >> 1;
const int INF = INT_MAX >> 1;

template<typename T> inline T sqr(T x) { return (x * x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }
inline int absdiff(int a, int b) { return (a - b) * (static_cast<int>(a > b)*2 - 1); }
int gcd(int a, int b) { // 最大公約数
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
inline int lcm(int a, int b) { return a * b / gcd(a, b); } // 最小公倍数
#pragma endregion

signed main()
{
	int A, B, H, M;
	cin >> A >> B >> H >> M;

	double thetaH = 30.0 * H + M * 0.5;
	double ax = A * sin(2.0 * PI * thetaH / 360.0), ay = A * cos(2.0 * PI * thetaH / 360.0);
	double bx = B * sin(2.0 * PI * 6.0 * M / 360.0), by = B * cos(2.0 * PI * 6.0 * M / 360.0);

	double d = sqrt(sqr(ax - bx) + sqr(ay - by));
	printd(d);
	return 0;
}

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

using namespace std;

#define INF 1e9

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

    int n;
    cin>>n;

    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]-=(i+1);
    }
    sort(a.begin(),a.end());

    long long ans=0;

    for(int i=0;i<n;i++){
        ans+=abs(a[i]-a[n/2]);
    }

    cout<<ans<<endl;
  
}


Measured memory_bytes: 1024
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.regex;

void main() {
    auto re = ctRegex!(`^A?KIHA?BA?RA?$`);
    string s = readln.chomp;
    writeln(s.matchAll(re) ? "YES" : "NO");
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        public long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String s1 = Integer.toString(a);
        String s2 = Integer.toString(b);
//        String sc1 = "";
//        String sc2 = "";
        for (int i = 0; i < b - 1; ++i) {
            s1 += s1.charAt(i);
        }
        for (int i = 0; i < a - 1; ++i) {
            s2 += s2.charAt(i);
        }
//        boolean ok = false;
//        for (int i = 0; i < a ; ++i) {
//            for(int j = 0; j <)
//            if (s1.charAt(i) >= s2.charAt(i)) {
//                ok = true;
//            }
//
//
//        }
//        if (ok == true) {
//            System.out.println(s2);
//        } else {
//            System.out.println(s1);
//        }
         if(a >= b){
             System.out.println(s2);
         }
         else{
             System.out.println(s1);
         }
    }
}


Measured memory_bytes: 37032
n,y=map(int, input().split())
a=-1
b=-1
c=-1
for i in range(n+1):
  for j in range(n-i+1):
    k=n-i-j
    if (i*10000)+(j*5000)+(k*1000)==y:
      a=i
      b=j
      c=k
print(a,b,c)

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

int main(){
    int L, R;
    cin >> L >> R;
    int l = L%2019;
    int r = R%2019;

    if(R-L+1>=2019){
        cout << 0 << endl;
    }else{
        int MIN = 2019;
        for(int i=L;i<R;i++){
            for(int j=i+1;j<=R;j++){
                MIN = min(MIN, ((i%2019)*(j%2019))%2019);
            }
        }
        cout << MIN << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    for(int i=0;i<9;i++){
        if(n/111==i&&n%111!=0){
            cout<<(i+1)*111<<endl;
        }
        else if(n%111==0&&n/111==i+1){
            cout<<n<<endl;
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		int [] cArray = new int [n];
		int [] tArray = new int [n];
		int cmin = 1001;
		for(int i = 0; i < n; i++) {
			cArray[i] = sc.nextInt();
			tArray[i] = sc.nextInt();
			
			if(tArray[i] <= t) {
				if(cmin > cArray[i]) {
					cmin = cArray[i];
				}
			}
		}
		
		if(cmin == 1001) System.out.println("TLE");
		else System.out.println(cmin);
		
		sc.close();
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    string s, t;
    cin >> s >> t;
    vector<string> v(26), w(26);
    rep(i, 26) {
        for (char c : s) v[i] += (c == i + 'a' ? '1' : '0');
        for (char c : t) w[i] += (c == i + 'a' ? '1' : '0');
    }
    sort(all(v));
    sort(all(w));
    cout << (v == w ? "Yes" : "No") << endl;
}


Measured memory_bytes: 10968
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	r, _ := strconv.Atoi(nextLine())
	return r
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	aary := make([]int, n)
	for i := 0; i < n; i++ {
		aary[i] = nextInt()
	}

	max, min := aary[0], aary[0]
	for i := 1; i < n; i++ {
		if max < aary[i] {
			max = aary[i]
		}
		if min > aary[i] {
			min = aary[i]
		}
	}

	fmt.Println(max - min)
}


Measured memory_bytes: 640
/// 0002: Digit Number

use std::io;

fn main() {
    loop {
        let mut buf = String::new();
        let _ = io::stdin().read_line(&mut buf);
        let v: Vec<_> = buf.split_whitespace().collect();

        if v.len() == 0 { break; }

        let a: i32 = v[0].parse().unwrap();
        let b: i32 = v[1].parse().unwrap();
        println!("{}", (a + b).to_string().len())
    }
}

Measured memory_bytes: 5048
N = int(input())
A = [0] + [int(i) for i in input().split()] + [0]

dA = []
for i in range(N+1):
    dA.append(A[i+1] - A[i])

sum = sum([abs(i) for i in dA])

for i in range(N):
    print(sum - abs(dA[i+1]) - abs(dA[i]) + abs(dA[i+1] + dA[i]))


Measured memory_bytes: 14272
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;
typedef long long ll;

int main(){
double A,B,H,M,h,m,z;
cin >> A >> B >> H >> M;
h = H*30+(M/60)*30;
m = M*6;
const double PI = 3.141592653589793238462643383279502884;
z=(h-m)*PI/180.000000000;
cout << setprecision(15)<< sqrt(A*A+B*B-2*A*B*cos(z)) << endl;

}


Measured memory_bytes: 3564
import sys

grid = []
H, W = map(int, input().split(' '))
for i in range(H):
    grid.append(input())

dp = [[0 for i in range(W)] for j in range(H)]
if grid[0][0] == '#':
    dp[0][0] = 1

for i in range(1, H):
    dp[i][0] = dp[i-1][0] + (grid[i][0] == '#' and grid[i-1][0] == '.')

for j in range(1, W):
    dp[0][j] = dp[0][j-1] + (grid[0][j] == '#' and grid[0][j-1] == '.')

for i in range(1, H):
    for j in range(1, W):
        choice_1 = dp[i-1][j] + (grid[i][j] == '#' and grid[i-1][j] == '.')
        choice_2 = dp[i][j-1] + (grid[i][j] == '#' and grid[i][j-1] == '.')
        dp[i][j] = min(choice_1, choice_2)

print(dp[H-1][W-1])

Measured memory_bytes: 3188
//Moh_K_Imar .......
//26/08/2020  ... 3,11.
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll r;
    cin>>r;
    cout<<r*r<<endl;

    return 0;
}



Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str;
ll dp[21][2][2][10000];

int nextl(int a,int l){
	l*=10;
	l+=a;
	l%=10000;
	return l;
}

bool istrue(int l){
	if(l%10!=3)return false;
	l/=100;
	if(l%10!=1)return false;
	l/=10;
	if(l%10!=5)return false;
	return true;
}

int main(void){
	cin >> str;
	int n=str.size();
	memset(dp,0,sizeof(dp));
	dp[0][0][0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				for(int l=0;l<10000;l++){
					int nj,nk,nl;
					if(j==0){
						for(int a=0;a<=(str[i]-'0');a++){
							if(a!=(str[i]-'0'))nj=j+1;
							else nj=j;
							nl=nextl(a,l);
							if(istrue(nl)){
								nk=1;
							}else{
								nk=k;
							}
							dp[i+1][nj][nk][nl]+=dp[i][j][k][l];
						}
					}else{
						for(int a=0;a<=9;a++){
							nj=j;
							nl=nextl(a,l);
							if(istrue(nl)){
								nk=1;
							}else{
								nk=k;
							}
							dp[i+1][nj][nk][nl]+=dp[i][j][k][l];
						}
					}
				}
			}
		}
	}
	ll ans=0;
	for(int i=0;i<2;i++){
		for(int j=0;j<10000;j++){
			ans+=dp[n][i][1][j];
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 9900
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int a[100000];

int main() {
  int N;
  int i;
  int a0, a1, a2, cnt_a0, cnt_a1, cnt_a2;
  scanf ("%d", &N);
  
  for (i=0;i<N;i++) {
      scanf("%d", &a[i]);
  }

  a0 = a[0];
  a1 = -1;
  a2 = -1;
  
  cnt_a0 = 1;
  cnt_a1 = 0;
  cnt_a2 = 0;
  
  for (i=1;i<N;i++) {
      if      (a[i]==a0)           cnt_a0++;
      else if (a1==-1  ) {a1=a[i]; cnt_a1++;}
      else if (a[i]==a1)           cnt_a1++;
      else if (a2==-1  ) {a2=a[i]; cnt_a2++;}
      else if (a[i]==a2)           cnt_a2++;
      else {
          printf("No\n");
          return 0;
      }
  }
  
  if (a1==-1) {
      if (a0==0) printf("Yes\n");
      else       printf("No\n");
  }
  else if (a2==-1) {
      if      ((cnt_a1==cnt_a0*2) && (a0==0)) printf("Yes\n");
      else if ((cnt_a0==cnt_a1*2) && (a1==0)) printf("Yes\n");
      else                                    printf("No\n");
  }
  else {
      if ((cnt_a0==cnt_a1)&&(cnt_a1==cnt_a2)&&((a0^a1^a2)==0)) printf("Yes\n");
      else                                                     printf("No\n");
  }
  
  return 0;
}




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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;





int main() {

	ll a, b, c;
	cin >> a >> b >> c;

	if (a + b >= c) {
		cout << "No" << endl;
		return 0;
	}

	ll d = c - a - b;

	ll e = 4 * a*b;

	d *= d;

	if (d > e) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;



}




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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif

    ll A, B, N;
    cin >> A >> B >> N;

    ll ans;
    ll x = min(B - 1, N);

    ans = A * x / B - A * (x / B);
    cout << ans << "\n";

    cout << flush;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  if(a * b % 2 == 0) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 888
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
 

public class Main{
          
     static int[][] kazoeage = new int[11][550];
    static boolean[] used = new boolean[10];
     
     public static void main(String args[]){
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         try{
             String line;
             func(0,0);
            while((line=br.readLine())!= null){if(line.isEmpty())break;
             String spl[] = line.split(" ");
             int n=Integer.parseInt(spl[0]), s = Integer.parseInt(spl[1]);
           if(n<=0||n>=11||s>=333||s<=-1)System.out.println("0");
           else       System.out.println(kazoeage[n][s]);
            }br.close();
       
         }catch(Exception e){e.printStackTrace();}         
     }
     
     static void func( int dep, int sum){
         kazoeage[dep][sum]++;if(dep>=10){return ;}
         for(int i=0; i<=9;i++){
             if(used[i]){continue;}
             used[i]=true;
             func(dep+1,sum+i*(dep+1));
             used[i]=false;
         }
         return ;         
     }
}
  

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

struct edge { int u,v,cost; };

struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n, -1) { }
  int root(int x) {
    if (par[x]<0) return x;
    else return par[x]=root(par[x]);
  }
  bool issame(int x, int y) {
    return root(x) == root(y);
  }
  void merge(int x, int y) {
    x=root(x); y=root(y);
    if (x==y) return ;
    if (-par[x]<-par[y]) swap(x, y);
    par[x]+=par[y];
    par[y]=x;
  }
};

const int MAX_E=100000;

edge es[MAX_E+1];
int V,E;

bool comp(const edge& e1, const edge& e2) {
  return e1.cost<e2.cost;
}

int kruskal() {
  sort(es, es+E, comp);
  UnionFind uf(V);
  int res=0;
  for (int i=0; i<E; i++) {
    edge e=es[i];
    if (!uf.issame(e.u, e.v)) {
      uf.merge(e.u, e.v);
      res+=e.cost;
    }
  }
  return res;
}


int main() {
  cin>>V>>E;
  rep(i, E) {
    int s,t,cost;
    cin>>s>>t>>cost;
    es[i]={s,t,cost};
  }
  int res=kruskal();
  cout<<res<<endl;
}



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

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N);
	rep(i, N) cin >> A[i];
	
	vector<ll> tmp(64);
	rep(i, N){
		rep(j, 64){
			tmp[j] += (A[i] >> j) & 1;
		}
	}
	
    ll ans = 0;
	rep(i, 64){
        ll one = tmp[i];
        ll zero = (N - tmp[i]);
		ans = ans % MOD + ((one * zero % MOD) * (((ll)1 << i) % MOD)) % MOD;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9;
const long long LLINF = 1e18;

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

    int mx=0;
    int cnt=0;
    REP(i, 0, n){
        if(s[i]=='I') cnt++;
        else cnt--;
        mx=max(mx, cnt);
    }
    cout<<mx<<endl;
    return 0;
}

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

using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int inf = 2e18;
const ld eps = 1e-9;
const int NN = 2003;


string to_string(string s) {
      return '"' + s + '"';
}
string to_string(const char* s) {
      return to_string((string) s);
}
string to_string(bool b) {
      return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
      return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
      bool first = true;  string res = "{";
      for (const auto &x : v) {
            if (!first) { res += ", "; }
            first = false; res += to_string(x);
      }
      res += "}";	  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
      cerr << " " << to_string(H);
      debug_out(T...);
}

// #define TRACE

#ifdef TRACE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

vpi a;

int dp[NN][NN];

int recur(int i, int j) {
      int left = j - i + 1;
      debug(i, j, left);
      if(left == 0) {
            return 0;
      }

      if(dp[i][j] != -1)
            return dp[i][j];
      int idx = a[left - 1].se;
      int v1 = abs(j - idx) * a[left-1].fi + recur(i, j - 1);
      int v2 = abs(idx - i) * a[left-1].fi + recur(i + 1, j);
      debug(i, j, v1, v2);
      return dp[i][j] = max(v1, v2);     
}


void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0;
      cin >> n;
      // vpi a(n);
      a.resize(n);
      fr(i, 0, n) {
            cin >> a[i].fi;
            a[i].se = i;
      } 
      memset(dp, -1, sizeof(dp));

      sort(all(a), [](pii &a, pii &b) {
            if (a.fi == b.fi) return a.se < b.se;
            return a.fi < b.fi;
      });
      debug(a);
      cout << recur(0, n - 1) << el; 

}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }

      return 0;
}

Measured memory_bytes: 35192
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int N=100010;
struct node
{
	int x,y;
}bb[N];
bool cmp(node a,node b)
{
	return atan2(a.y,a.x)<atan2(b.y,b.x);
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d %d",&bb[i].x,&bb[i].y);
	}
	sort(bb,bb+n,cmp);
	ll maxx=0;
	for(int i=0;i<n;i++)
	{
		ll x=bb[i].x,y=bb[i].y;
		maxx=max(maxx,x*x+y*y);
		for(int j=(i+1)%n;j!=i;j=(j+1)%n)
		{
			x+=bb[j].x,y+=bb[j].y;
			maxx=max(maxx,x*x+y*y);
		}
	} 
	printf("%.10lf",sqrt(maxx));
}

Measured memory_bytes: 384
use std::io::*;

fn main() {
  let stdin = stdin();
  let mut lines = stdin.lock().lines();

  let word = lines.next().unwrap().unwrap().to_lowercase();

  let mut count = 0;

  for line in lines {
    let line = line.unwrap();
    if line == "END_OF_TEXT" { break; }

    let line = line.to_lowercase();
    let words = line.split_whitespace();

    count += words.filter(|&w| w == word).count();
  }

  println!("{}", count);
}



Measured memory_bytes: 5056
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main() {
	string s;
	stack<int> st;

	while (cin >> s) {
		if (s == "+" || s == "-" || s == "*") {
			int n1, n2;
			n1 = st.top();
			st.pop();
			n2 = st.top();
			st.pop();
			if (s == "+") {
				st.push(n1 + n2);
			}
			else if (s == "-") {
				st.push(n2 - n1);
			}
			else if (s == "*") {
				st.push(n1 * n2);
			}
		}
		else {
			st.push(stoi(s));
		}
	}
	cout << st.top() << endl;

	return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
int main(){
    long cnt=0;
    string s;
    cin >> s;
    for(int i=0;i<(1<<(s.size()-1));i++){
        bitset<10> a(i);
        string cur;
        cur += s.at(0);
        for(int j=0;j<s.size()-1;j++){
            if(a.test(j)){
                cnt += stol(cur);
                cur = {};
            }
            cur += s.at(j+1);
        }
        cnt += stol(cur);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>

using namespace std;

typedef long long ll;

#ifdef ONPC
    mt19937 rnd(228);
#else
    mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = 2e7 + 7;
const int M = 1e9 + 7;

inline int add(int a, int b)
{
    a += b;
    if (a >= M) a -= M;
    return a;
}

inline int mul(int a, int b)
{
    return (a * (ll) b) % M;
}

inline int bin(int a, int n)
{
    int res = 1;
    while (n)
    {
        if (n % 2 == 0)
        {
            a = mul(a, a);
            n /= 2;
        }
        else
        {
            res = mul(res, a);
            n--;
        }
    }
    return res;
}

inline int inv(int x)
{
    return bin(x, M - 2);
}

int dp[N][3];
int s[N][3];
int fact[N];
int rfact[N];

int odp[N][3];
int os[N][3];

int C(int n, int k)
{
    if (n < k) return 0;
    return mul(fact[n], mul(rfact[k], rfact[n - k]));
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    fact[0] = 1;
    for (int i = 1; i < N; i++)
    {
        fact[i] = mul(fact[i - 1], i);
    }
    rfact[N - 1] = inv(fact[N - 1]);
    for (int i = N - 2; i >= 0; i--)
    {
        rfact[i] = mul(rfact[i + 1], i + 1);
    }
    dp[0][0] = 1;
    for (int i = 0; i + 1 < N; i++)
    {
        for (int t = 0; t <= 2; t++)
        {
            if (t == 1)
            {
                os[i][t] = add(os[i][t], dp[i][t]);
            }
            if (t == 2)
            {
                s[i][t] = add(s[i][t], dp[i][t]);
            }
            for (int nt = t; nt <= 2 && nt <= t + 1; nt++)
            {
                os[i + 1][nt] = add(os[i + 1][nt], os[i][t]);
                s[i + 1][nt] = add(s[i + 1][nt], s[i][t]);
                dp[i + 1][nt] = add(dp[i + 1][nt], dp[i][t]);
            }
        }
    }
    int h, w, k;
    cin >> h >> w >> k;
    int ans = mul(k, mul(C(h + w, k), fact[k]));
    if (k >= 2)
    {
        int cur = mul(C(h + w - 2, k - 2), fact[k - 2]);
        cur = mul(cur, (h * (ll) w) % M);
        cur = mul(cur, mul(2, s[k][2]));
        ans = add(ans, cur);
    }
    if (k >= 1)
    {
        int cur = mul(C(h + w - 1, k - 1), fact[k - 1]);
        cur = mul(cur, h + w);
        cur = mul(cur, os[k][1]);
        ans = add(ans, cur);
    }
    cout << ans << '\n';
}


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

bool is_number(string const& s) {
    bool res = false;
    for(auto c : s) {
        res |= isdigit(c);
    }
    return res;
}

int main() {
    cout << fixed << setprecision(10);
    string line;
    while(getline(cin, line)) {
        stack<double> st;
        string s;
        stringstream ss(line);
        while(ss >> s) {
            if(is_number(s)) {
                st.push(stoi(s));
            } else {
                double op1 = st.top(); st.pop();
                double op2 = st.top(); st.pop();
                if(s[0] == '+') {
                    st.push(op2 + op1);
                } else if(s[0] == '-') {
                    st.push(op2 - op1);
                } else if(s[0] == '/') {
                    st.push(op2 / op1);
                } else if(s[0] == '*') {
                    st.push(op2 * op1);
                }
            }
        }
        cout << st.top() << endl;
    }
}


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

using namespace std;

int main(){

  int d,e;

  while(cin>>d>>e,d||e){

	double x=0;
	double y=d;
	double min = 100000;
	double sum; 
	
	while(x != d){

	  sum=fabs(sqrt(x*x+y*y)-e);

	  if(sum<min)
		min = sum;

	  x++;
	  y--;
	}

	cout<<min<<endl;
	
  }

}



Measured memory_bytes: 3248
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <fstream>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;
#define int long long

const int INF = 2e9 + 7;

int get(int bad, int k) {
    if (k < bad) return k;
    else return k + 1;
}

int mid1(int n) {
    if (n % 2) return (n + 1) / 2;
    else return n / 2;    
}

int mid2(int n) {
    if (n % 2) return (n + 1) / 2;
    else return n / 2 + 1;
}

int solve(int a, int b) {
    int l = 0;
    int r = INF;
    while (l < r - 1) {
        int m = (l + r) / 2;
        if (get(a, mid1(m)) * get(b, mid2(m)) < a * b && get(a, mid2(m)) * get(b, mid1(m)) < a * b) {
            l = m;
        }
        else {
            r = m;
        }
    }
    return l;
}

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

    int q;
    cin >> q;

    for (int i = 0; i < q; ++i) {
        int a, b;
        cin >> a >> b;
        cout << solve(a, b) << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
import heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
def min(a,b):
	if a < b:
		return a
	return b

while t > 0:
	t -= 1
	# a,b = map(int,input().split())
	n = int(input())
	v = list(map(int,input().strip().split()))[0:n]
	i = 0
	ans = 0
	while i < n:
		j = i
		while j+1 < n and v[j+1] <= v[j]:
			j += 1
		l = j-i+1
		ans = max(ans,l)
		i = j+1
	print(ans-1) 

Measured memory_bytes: 86216
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	int n,a;cin>>n>>a;
	if(n%500==0||n%500<=a)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
 #pragma GCC optimize("Ofast")
 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define int long long 
using namespace std;
map<int,map<int,int> >mm;
vector<vector<int> >adj;
int mx=0;

void dfs(int ver,int p,int color)
{
    int cnt=1;
    mm[ver][p]=color;
    mm[p][ver]=color;
    mx=max(mx,color);    
    for(auto i:adj[ver])
    {
        if(i!=p)
        {
            if(cnt==color)
                cnt++;
            dfs(i,ver,cnt++);
        }
    }
}

signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif


// -------------------------------------Code starts here--------------------------------------------------------------------- 

    int n;
    cin>>n;
    adj.resize(n+1);
    pair<int,int>p[n-1];
    int x,y;
    for(int i=0;i<n-1;i++)
    {        
        cin>>x>>y;
        p[i]={x,y};
        adj[x].push_back(y);
        adj[y].push_back(x);
        
        mm[x][y]=1;
        mm[y][x]=1;
    }
    dfs(1,0,0);
    cout<<mx<<"\n";
    for(int i=0;i<n-1;i++)
        cout<<mm[p[i].first][p[i].second]<<"\n";

    

// -------------------------------------Code ends here------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
     clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

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

namespace EDPC_A
{
    class Program
    {
        static int[] _minCost;
        static int[] _height;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            _height = new int[n];

            string[] strH = Console.ReadLine().Split();

            for (int i = 0; i < n; ++i)
            {
                _height[i] = int.Parse(strH[i]);
            }

            _minCost = new int[n];
            for (int i = 0; i < n; ++i) { _minCost[i] = int.MaxValue; }

#if false
            _minCost[0] = 0;
            _minCost[1] = Math.Abs(_height[0] - _height[1]);

            for (int i = 2; i < n; ++i)
            {
                //ChangeMin(ref minCost[i], Math.Min(Math.Abs(h[i] - h[i - 2]) + minCost[i - 2], Math.Abs(h[i] - h[i - 1]) + minCost[i - 1]));
                _minCost[i] = Math.Min(Math.Abs(_height[i] - _height[i - 2]) + _minCost[i - 2], Math.Abs(_height[i] - _height[i - 1]) + _minCost[i - 1]);
            }
#endif
            int ans = MinCostRec(n - 1);

            Console.WriteLine("{0}", ans);
        }

        static int MinCostRec(int index)
        {
            int minCost = _minCost[index];
            if (minCost != int.MaxValue) { return minCost; }

            if (index == 0) { return 0; }

            minCost = Math.Abs(_height[index] - _height[index - 1]) + MinCostRec(index - 1);
            if (2 <= index) { minCost = Math.Min(minCost, Math.Abs(_height[index] - _height[index - 2]) + MinCostRec(index - 2)); }

            return (_minCost[index] = minCost);
        }
#if false
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int[] h = new int[n];

            string[] strH = Console.ReadLine().Split();

            for (int i = 0; i < n; ++i)
            {
                h[i] = int.Parse(strH[i]);
            }

            int[] minCost = new int[n];
            for (int i = 0; i < n; ++i) { minCost[i] = int.MaxValue; }

            minCost[0] = 0;
            minCost[1] = Math.Abs(h[0] - h[1]);

            for (int i = 2; i < n; ++i)
            {
                //ChangeMin(ref minCost[i], Math.Min(Math.Abs(h[i] - h[i - 2]) + minCost[i - 2], Math.Abs(h[i] - h[i - 1]) + minCost[i - 1]));
                minCost[i] = Math.Min(Math.Abs(h[i] - h[i - 2]) + minCost[i - 2], Math.Abs(h[i] - h[i - 1]) + minCost[i - 1]);
            }

            int ans = minCost[n - 1];

            Console.WriteLine("{0}", ans);
        }


        static bool ChangeMin<T>(ref T a, T b)
            where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }

            return false;
        }

        static bool ChangeMax<T>(ref T a, T b)
            where T : IComparable
        {
            if (a.CompareTo(b) < 0)
            {
                a = b;
                return true;
            }

            return false;
        }
#endif
    }
}


Measured memory_bytes: 23520
import math

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

if a*a*b*(1/2) >= x:
    degree = math.degrees(math.atan(a*b*b/(2*x)))
else:
    degree = math.degrees(math.atan((2.0*(b-(x/(a*a))))/a))

print(degree)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>

using namespace std;

vector <int> v[123456];
int dp[123456][11];

void dfs(int k,int d,int c) {
    dp[k][d]=c;
    if(d==0) return;
    for(auto x:v[k]){
        if(dp[x][d-1]==0) dfs(x,d-1,c);
    }
    if(dp[k][d-1]==0) dfs(k,d-1,c);
}

int main() {
    int n,m;
    scanf("%d %d",&n,&m);
    memset(dp,0,sizeof(dp));
    for(int i=0;i<m;i++) {
        int a,b;
        scanf("%d %d",&a,&b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int q;
    scanf("%d",&q);
    int voo[123456],d[123456],c[123456];
    for(int i=0;i<q;i++) {
        scanf("%d %d %d",voo+i,d+i,c+i);
    }
    for(int i=q-1;i>=0;i--) {
        if(dp[voo[i]][d[i]]==0) dfs(voo[i],d[i],c[i]);
    }
    for(int i=1;i<=n;i++) printf("%d\n",dp[i][0]);
    return 0;
}


Measured memory_bytes: 13560
import qualified Data.ByteString.Char8 as B
import Data.List
main=do
    [n,k]<-map read.words<$>getLine
    as<-unfoldr(B.readInt.B.dropWhile(==' '))<$>B.getLine
    putStrLn $ sol k as
sol k as
    | k<=m && k`mod`l==0 = "POSSIBLE"
    | otherwise = "IMPOSSIBLE"
    where
        l = foldl1 gcd as
        m = maximum as

Measured memory_bytes: 8700
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll d[15][2005], dp[15][2005];

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

	vector<int> id, v[2005];

	rep(i, n) {
		int a, b;
		cin >> a >> b;

		id.push_back(b-1);
		v[b-1].push_back(a);
	}

	sort(id.begin(), id.end());
	id.erase(unique(id.begin(),id.end()),id.end());

	rep(i, id.size()) {
		int j = id[i];
		sort(v[j].begin(), v[j].end(), greater<int>() );
	}

	memset(d, 0, sizeof(d));

	rep(i, id.size()) {
		int j = id[i];

		REP(k, 1, v[j].size()+1) {
			d[j][k] += d[j][k-1] + v[j][k-1] + (k-1) * 2;
		}
	}

	memset(dp, 0, sizeof(dp));

	rep(i, id.size()) {
		rep(j, K + 1) {
			ll res = dp[i][j];
			rep(k, v[id[i]].size() + 1) {
				if(j >= k) {
					res	= max(res, dp[i][j - k] + d[id[i]][k]);
				}
			}

			dp[i+1][j] = res;
		}
	}

	cout << dp[ id.size()][K] << endl;

	return 0;
}

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
#define P pair<int, int>
struct data{
	int place;
	int cost;

	bool operator<(const data &ri) const{
		return cost < ri.cost;
	}
	bool operator>(const data &ri) const{
		return cost > ri.cost;
	}
};
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};



int main(){
	int n;
	map<int, int> a,b;
	int in;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> in;
		if(i%2)a[in]++;
		else b[in]++;
	}

	int amaxi[2] = {0, 0}, bmaxi[2] = {0, 0};
	set<int> an, bn;
	for(auto it = a.begin(); it != a.end(); it++){
		if(amaxi[0] < it->second){
			amaxi[1] = amaxi[0];
			amaxi[0] = it->second;
			an.clear();
			an.insert(it->first);
		}else if(amaxi[0] == it->second){
			an.insert(it->first);
		}else{
			amaxi[1] = max(amaxi[1], it->second);
		}
	}
	for(auto it = b.begin(); it != b.end(); it++){
		// cout << it->first << " " << it->second << endl;
		if(bmaxi[0] < it->second){
			bmaxi[1] = bmaxi[0];
			bmaxi[0] = it->second;
			bn.clear();
			bn.insert(it->first);
		}else if(bmaxi[0] == it->second){
			bn.insert(it->first);
		}else{
			bmaxi[1] = max(bmaxi[1], it->second);
		}
	}

	// cout << *an.begin() << " " << *bn.begin() << endl;
	// cout << n << " " << amaxi[0] << " " << amaxi[1] << " " << bmaxi[0] << " " << bmaxi[1] << endl;
	if(an.size() == bn.size() && an.size() == 1 && *an.begin() == *bn.begin()){
		cout << n - max(amaxi[0] + bmaxi[1], amaxi[1] + bmaxi[0]) << endl;
	}else cout << n - amaxi[0] - bmaxi[0] << endl;

	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
int main()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	
	ll ans=0;
	if(a<=k)
	{
		ans=a;
		k=k-a;
	}
	else
	{
		ans=k;
		cout<<ans;
		return 0;
	}
	
	if(b<=k)
	{
		k=k-b;
	}
	else
	{
		cout<<ans;
		return 0;
	}
	
	if(c<=k)
	{
		ans=ans-c;
		
	}
	else
	ans=ans-k;
	cout<<ans;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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


int main(){
    int a, b, c; cin >> a >> b >> c;
    cout << max(c-(a-b), 0) << endl;
    return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int no = 1;
            int count = 0;
            foreach (int i in a) {
                if ((no % 2 == 1) && (i % 2 == 1)) {
                    count++;
                }
                no++;
            }
            Console.WriteLine(count);
        }
    }
}


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

int main() {
  int R,G,B,N;
  std::cin >> R >> G >> B >> N;

  if (R+G+B == 3) {
    std::cout << (N+2)*(N+1)/2 << '\n';
    return 0;
  }

  int ans = 0;
  for (size_t i = 0; i < N+1; i++) {
    for (size_t j = 0; j < N+1; j++) {
      for (size_t k = 0; k < N+1; k++) {
        if (R*i+B*j+G*k == N) {
          ans++;
        } else if (R*i+B*j+G*k > N) {
          break;
        }
      }
    }
  }

  std::cout << ans << '\n';
 }


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000


int main()
{
unsigned short *A,*B;
int C[VMAX+1],n,i,j;


scanf("%d",&n);

A = malloc(sizeof(short)*n+1);
B = malloc(sizeof(short)*n+1);


for(i=0;i<=VMAX;i++)
  {
C[i] = 0;
}

for(i=0;i<n;i++)
  {
scanf("%hu",&A[i+1]);
C[A[i+1]]++;
}

for(i=1;i<=VMAX ;i++)
  {
C[i]=C[i] + C[i-1];
}

for(j=1;j<=n;j++)
  {
B[C[A[j]]] = A[j];
C[A[j]]--;
}

for(i=1;i<=n;i++)
  {
if(i>1)
  {
printf(" ");
}
printf("%d",B[i]);
}
printf("\n");
return 0;




}



Measured memory_bytes: 9636
#include <bits/stdc++.h>
 
using namespace std;
 
struct comp {
  double re, im;
 
  comp(double x = 0, double y = 0) : re(x), im(y) {}
 
  comp operator+(const comp& a) { return comp(re + a.re, im + a.im); }
  comp operator-(const comp& a) { return comp(re - a.re, im - a.im); }
  comp operator*(const comp& a) { return comp(re * a.re - im * a.im, re * a.im + im * a.re); }
};
 
const double pi = acos(-1);
 
void fft(vector<comp>& x) {
  int n = x.size();
  for (int i = 1, k = 0; i < n; ++i) {
    for (int bit = n >> 1; (k ^= bit) < bit; bit >>= 1) {}
    if (i < k) {
      swap(x[i], x[k]);
    }
  }
  for (int k = 1; k < n; k <<= 1) {
    comp wlen(cos(pi / k), sin(pi / k));
    for (int i = 0; i < n; i += (k << 1)) {
      comp w(1);
      for (int j = 0; j < k; ++j) {
        comp tmp = w * x[i + j + k];
        x[i + j + k] = x[i + j] - tmp;
        x[i + j] = x[i + j] + tmp;
        w = w * wlen;
      }
    }
  }
}
 
template<class T> vector<T> mul(vector<T>& a, vector<T>& b) {
  int n = max(a.size(), b.size());
  int lg = 31 - __builtin_clz(n);
  n = 1 << (lg + 1 + (n != (1 << lg)));
  vector<comp> fa(n), fb(n);
  for (int i = 0; i < a.size(); ++i) {
    fa[i] = a[i];
  } for (int i = 0; i < b.size(); ++i) {
    fb[i] = b[i];
  }
  fft(fa);
  if (a == b) {
    fb = fa;
  } else {
    fft(fb);
  }
  for (int i = 0; i < n; ++i) {
    fa[i] = fa[i] * fb[i];
  }
  fft(fa);
  reverse(fa.begin() + 1, fa.end());
  vector<T> c(n);
  for (int i = 0; i < n; ++i) {
    c[i] = (T)(fa[i].re / n + (fa[i].re > 0 ? 0.5 : -0.5));
  }
  return c;
}
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
 
  int n;
  long long m;
  cin >> n >> m;
  vector<long long> cnt((int)1e6 + 1);
  while (n--) {
    int x;
    cin >> x;
    ++cnt[x];
  }
  cnt = mul(cnt, cnt);
  long long ans = 0;
  for (int i = cnt.size() - 1; m > 0 and i >= 0; --i) {
    ans += i * min(cnt[i], m);
    m -= min(cnt[i], m);
  }
  cout << ans;
 
  return 0;
}

Measured memory_bytes: 89984
#include<iostream>
using namespace std;
int main(){
	string s;
	cin >> s;
	int x=0;
	if(s[0]=='R')
		x++;
	if(s[1]=='R')
		x++;
	else{
		x=0;
	}
	if(s[2]=='R')
		x++;
	if(s[0]=='R' && x==0)
		x++;
	cout << x << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

lint powmod(lint a, lint n, lint mod) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;

	cout << K * powmod(K - 1, N - 1, MOD);

	return 0;
}

Measured memory_bytes: 256