akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
using static Atcoder.IO;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        static long n;
        static long k;
        static long[] a;

        public static void Answer()
        {
            var nk = IO.RSLong;
            n = nk[0];
            k = nk[1];
            a = IO.RSLong;

            if (k == 0)
            {
                WriteLine(a.Max());
                return;
            }

            long ng = 0;
            long ok = long.MaxValue - 1;

            while (ok - ng > 1)
            {
                long mid = (ok + ng) / 2;
                if (IsOK(mid))
                    ok = mid;
                else
                    ng = mid;
            }
            WriteLine(ok);
            //WriteLine(ng);
        }

        public static bool IsOK(long mid)
        {
            long totalCnt = 0;
            for (int i = 0; i < n; i++)
            {
                long cnt = (long)(a[i] / mid);
                if (a[i] % mid == 0) cnt--;
                totalCnt += cnt;
            }
            return totalCnt <= k;
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 45388
N = int(input())

import numpy as np
import math as m
M = m.ceil(m.sqrt(N))
numbers = np.zeros(N)
for i in range(M):
    for j in range(M):
        for k in range(M):
            x = i + 1
            y = j + 1
            z = k + 1
            fn = x*x + y*y + z*z + x*y + y*z + z*x
            if fn >= 1 and fn <= N:
                numbers[fn - 1] += 1
for i in range(N):
    print(int(numbers[i]))

Measured memory_bytes: 27404
N, *XY = map(int, open(0).read().split())
XY = list(zip(*[iter(XY)] * 2))

S = set((x + y) % 2 for x, y in XY)
if len(S) == 2:
    print(-1)
    quit()
mod = S.pop()

D = [2 ** i for i in reversed(range(32))] + [1] * (mod == 0)
print(len(D))
print(*D)

for x, y in XY:
    A = []
    for d in D:
        if 0 <= x - y and 0 <= x + y:
            A.append("R")
            x -= d
        elif x - y < 0 and 0 <= x + y:
            A.append("U")
            y -= d
        elif 0 <= x - y and x + y < 0:
            A.append("D")
            y += d
        else:
            A.append("L")
            x += d

    print("".join(A))

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
signed main() {
	int memo = 0;
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = 100; i >= 1; i--) {
		if (a % i == 0 && b % i == 0) {
			memo++;
		}
		if (memo == k) {
			cout << i << endl;
			ggr
		}
	}
	ggr
}


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

int main() {
  int num, tmp, dig, sum = 0;
  cin >> num;
  tmp = num;
  
  while (num) {
    dig = num % 10;
    sum += dig;
    num /= 10;
  }
  
  cout << (tmp % sum == 0 ? "Yes" : "No") << endl;
  
  return 0;
}


Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define VECV(a,n,m) vector<vector<int>> a(n, vector<int>(m));
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin>>N;
  int A[N-1];
  int B[N];
  rep(i,N-1){
    cin>>A[i];
  }
  rep(i,N){
    B[i]=0;
  }
  rep(i,N-1){
    B[A[i]-1]+=1;
  }
  rep(i,N){
    cout<<B[i]<<endl;
  }
  

}


Measured memory_bytes: 5168
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n, k;
string s;

bool addNewSeg(int i) {
    return (i == 0 && s[i] == '0') || (i + 1 < n && s[i] == '1' && s[i + 1] == '0');
}

bool delOldSeg(int i) {
    return s[i] == '0' && (i == n - 1 || s[i + 1] == '1');
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    cin >> s;

    int j = 0;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        while(j < n - 1 && k - addNewSeg(j) >= 0)
            k -= addNewSeg(j++);
        ans = max(ans, j - i + 1);
        k += delOldSeg(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int h, w;

    cin >> h >> w;

    int n;

    cin >> n;

    vector<int> a(n);

    for(int i = 0; i < n; i++)
        cin >> a[i];

    vector<vector<int> > v(h, vector<int>(w));
    int pos = 0;

    for(int i = 0; i < h; i++) {
        if(i % 2) {
            for(int j = w - 1; j >= 0; j--) {
                v[i][j] = pos + 1;
                a[pos]--;
                if(a[pos] == 0)
                    pos++;
            }
        } else {
            for(int j = 0; j < w; j++) {
                v[i][j] = pos + 1;
                a[pos]--;
                if(a[pos] == 0)
                    pos++;
            }
        }
    }

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++)
            cout << v[i][j] << " ";
        cout << endl;
    }

    return 0;
}


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

int N;
vector<int> G[100010];
int cnt;
int dp[100010];
int MAX = 0;

int DFS(int v,int p)
{
    int res = (G[v].size() == 2);
    int tmp = 0;
    for(int i = 0; i < G[v].size(); i++)
    {
        int now = G[v][i];
        if(now == p)continue;
        res += DFS(now,v);
        MAX = max(MAX,tmp + dp[now] + (G[v].size() == 2));
        tmp = max(tmp,dp[now]);
    }
    dp[v] = tmp + (G[v].size() == 2);
    return res;
}

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N - 1; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for(int i = 1; i <= N; i++)if(G[i].size() == 1)cnt++;

    DFS(1,0);

    printf("%d\n",cnt + MAX);
    return 0;
}


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

using namespace std;

const int N = 801;
const int INF = 1e9 + 239;
const vector<int> dx = {0, 0, 1, -1};
const vector<int> dy = {-1, 1, 0, 0}; 

int n, m;
int a[N][N];
int d[N][N];

bool ok(int i, int j) {
	return 0 <= i && i < n && 0 <= j && j < m && !a[i][j];
}

void bfs(int si, int sj) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			d[i][j] = INF;
		}
	}
	queue<pair<int, int>> q;
	d[si][sj] = 0;
	q.push({si, sj});
	while (!q.empty()) {
		int i, j;
		tie(i, j) = q.front();
		q.pop();
		for (int k = 0; k < 4; k++) {
			int ni = i + dx[k];
			int nj = j + dy[k];
			if (ok(ni, nj) && d[ni][nj] > d[i][j] + 1) {
				d[ni][nj] = d[i][j] + 1;
				q.push({ni, nj});
			}
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int k;
	cin >> n >> m >> k;
	int si = -1;
	int sj = -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			if (c == 'S') {
				si = i;
				sj = j;
			} else if (c == '#') {
				a[i][j] = 1;
			}
		}
	}
	bfs(si, sj);
	int ans = INF;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (d[i][j] <= k) {
				int v = min({i, n - 1 - i, j, m - 1 - j});
				ans = min(ans, 1 + (v + k - 1) / k);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 8192
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

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

  if (N == "SUN") cout << 7 << endl;
  else if (N == "MON") cout << 6 << endl;
  else if (N == "TUE") cout << 5 << endl;
  else if (N == "WED") cout << 4 << endl;
  else if (N == "THU") cout << 3 << endl;
  else if (N == "FRI") cout << 2 << endl;
  else if (N == "SAT") cout << 1 << endl;
  
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int number[1000000], l;
string a;

int substruct()
{
	sort(number, number + l, greater<int>());
	int max_num = 0, min_num = 0;
	for(int i = 0; i < l; i++){
		max_num += number[i] * pow(10, (l-1-i));
		min_num += number[l-1-i] * pow(10, (l-1-i));
	}
	int ans = max_num - min_num;
	return ans;
}

void numbertoarray()
{
	int x = l - a.length();
	if(x > 0){
		for(int i = 0; i < l; i++){
			if (i < x) number[i] = 0;
			else number[i] = a[i - x] - '0';
		}
	} else {
		for(int i = 0; i < l; i++){
			number[i] = a[i] - '0';
		}
	}
}

string IntToString(int number)
{
	stringstream ss;
	ss << number;
	return ss.str();
}

int main()
{
	int result[21];
	while(1){
		cin >> a >> l;
		if(a == "0" && l == 0) break;
		int cnt = 1, gotanswer = 0;
		result[0] = stoi(a);
		while(1){
			numbertoarray();
			result[cnt] = substruct();
			for(int i = cnt - 1; i >= 0; i--){
				if(result[i] == result[cnt]){
					cout << i << ' ' << result[cnt] << ' ' << cnt - i << endl;
					gotanswer = 1;
					break;					  
				}
			}
			if(gotanswer == 1) break;
			a = IntToString(result[cnt]);
			cnt++;
		}
	}
	return 0;
}

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

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

for (int i = 0; i < s.size(); i++) {  
  if (s.at(i) == '0') {
    s_out += '0';
  }
  else if (s.at(i) == '1') {
    s_out += '1';
  }  
  else if (s.at(i) == 'B' && s_out.empty() == 0) {
    s_out.erase(s_out.size()-1);
  }   
}
  cout << s_out << endl;
}


Measured memory_bytes: 256
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
#define PI 3.14159265359
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int f[n + 1] = {0};
        int a[n];
        loop(0, n - 1) {
            cin >> a[i];
            f[a[i]]++;
        }
        loop(1, n + 1) {
            cout << f[i] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 6620
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	vector<long long> a(x), b(y), c(z);

	for (int i = 0; i < x; i++) { cin >> a[i]; }
	for (int i = 0; i < y; i++) { cin >> b[i]; }
	for (int i = 0; i < z; i++) { cin >> c[i]; }

	sort(a.begin(), a.end(), greater<long long>());
	sort(b.begin(), b.end(), greater<long long>());
	sort(c.begin(), c.end(), greater<long long>());

	vector<long long> sum_abc;
	for (int ia = 0; ia < x; ia++) {
		for (int ib = 0; ib < y; ib++) {
			int tmp = (ia + 1) * (ib + 1);
			if (tmp > k) {
				break;
			}

			for (int ic = 0; ic < z; ic++) {
				if (tmp * ic > k) {
					break;
				}

				sum_abc.emplace_back(a[ia] + b[ib] + c[ic]);
			}
		}
	}

	sort(sum_abc.begin(), sum_abc.end(), greater<long long>());
	if (sum_abc.size() > k) {
		sum_abc.resize(k);
	}

	for (auto abc: sum_abc) {
		cout << abc << endl;
	}

	return 0;
}


Measured memory_bytes: 1404
n,m=map(int, input().split()) 
s=[list(map(int, input().split())) for i in range(m)]
s.sort(key = lambda x:x[1])
x=[0]
count=0
for i in range(m):
    if s[i][0]<=x[-1]:
        pass
    else:
        x.append(s[i][1]-1)
        count+=1
print(count)

Measured memory_bytes: 29084
#include <iostream>
#include <cmath>
#define ll long long
using namespace std;

ll root5(ll x){
  ll y=1; ll pow5=1;
  while(true){
    y++;
    pow5=pow(y,5);
    if(pow5>x){y--; break;}
    else if(pow5==x){break;}
  }
  return y;
}

int main(){
  ll X; cin>>X;
  ll max = root5(X);
  ll a,b; a=0;
  while(a<=max){
    ll b5 = X-pow(a,5);
    b = root5(b5);
    if(pow(b,5)==b5){
      cout<<a<<' '<<-b; return 0;
    }
    else{a++;}
  }
  
  b=0;
  while(true){
    ll buf=X+pow(b,5);
    a = root5(buf);
    if(pow(a,5)==buf){
      cout<<a<<' '<<b; return 0;
    }
    else{b++;}
  }
  
  return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,n) for(ll i=0;i<n;i++)
#define SORT(a) sort(a.begin(),a.end())
 
int main() {
	
	//string ans="No";
	//vector<int> c(30,0);
	//cout << a << b << endl;
	
	long double a,b,x;
	
	cin >> a >> b >> x;
	long double ans;
	
	//cout << a << b << x << endl;
	
	//vector<int> a(n);
	
	long double h=x/(a*a);
	
	if(h*2>=b){
		long double d=b-h;
		
		//cout << d << endl;
		
		long double tan=2*d/a;
		
		ans=atan(tan);
		
		ans*=180;
		ans/=M_PI;
	}
	else{
		long double tan=2*x/a/b/b;
		
		 ans=atan(tan);
		
		 ans=M_PI/2-ans;
		
		ans*=180;
		ans/=M_PI;
	}
	
    cout << setprecision(10) << ans << endl;
    
    return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	string X;
	cin >> X;

	string ans;
	for( int i = 0; i < X.size(); ++i ) {
		if( X[i] == 'S' ) {
			ans.push_back( 'S' );
		}
		else if( X[i] == 'T' ) {
			if( ans.empty() || ans.back() == 'T' ) {
				ans.push_back( 'T' );
			}
			else if( ans.back() == 'S' ) {
				ans.pop_back();
			}
		}
	}

	cout << ans.size() << endl;
	return 0;
}


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

struct swimmer {
    int t, c, sum;
    bool operator<(swimmer const& s) {
        return t < s.t;
    }
};

int main() {
    int n;
    while(cin >> n, n) {
        queue<swimmer> que[2];
        for(int i=0; i<n; ++i) {
            int t, c;
            cin >> t >> c;
            que[0].push(swimmer{t, c, 0});
        }
        int res = 0;
        while(!que[0].empty() || !que[1].empty()) {
            bool f = que[0].empty() || (!que[1].empty() && que[1].front().sum < que[0].front().sum);
            res = que[f].front().sum;
            vector<swimmer> next;
            while(!que[f].empty() && que[f].front().sum <= res) {
                next.push_back(que[f].front());
                que[f].pop();
            }
            sort(next.begin(), next.end());
            for(int i=0; i<next.size(); ++i) {
                if(next[i].c > 0) {
                    que[f^1].push(swimmer{next[i].t, next[i].c - f, res + next[i].t});
                }
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3112
n,k = map(int,input().split())
r,s,p = map(int,input().split())
a = list(input())

hand = {"r":p,"s":r,"p":s}
ans = 0
for i in range(n):
    if a[i-k] == a[i] and i-k >= 0:
        a[i] = "0"
    else:
        ans += hand[a[i]]
print(ans)


Measured memory_bytes: 4084
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=map(int,input().split())
    from collections import Counter
    c=Counter(A)
    ans=0
    first=0
    second=0
    for k,v in c.items():
        if v>=4: ans=max(ans,k*k)
        if v>=2:
            if k>first:
                first,second=k,first
            elif k>second:
                second=k
    print(max(ans,first*second))
resolve()

Measured memory_bytes: 63216
k = int(input())
from collections import deque
queue = deque(range(1,10))
count = 0

while count < k:
  count += 1
  tmp = queue.popleft()
  tail = tmp % 10
  if tail!=0:
    queue.append(tmp*10+tail-1)
  queue.append(tmp*10+tail)
  if tail!=9:
    queue.append(tmp*10+tail+1)
  
print(tmp)

Measured memory_bytes: 11956
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(D: int, T: int, S: int):
    return YES if D / S <= T else NO


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    D = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    print(solve(D, T, S))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9184
a, b, h, m = gets.split.map(&:to_i)
hdeg = (h + m.to_f / 60) / 12
mdeg = m.to_f / 60
cos = Math.cos(2 * Math::PI * (hdeg - mdeg).abs)
puts Math.sqrt(a * a + b * b - 2 * a * b * cos)


Measured memory_bytes: 14748
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int n,m;
  while(cin >> n >> m, n){
    int ans = 0;
    vi a(n);
    rep(i,n)  cin >> a[i];
    rep(i,n)rep(j,n){
      if(i != j && m - ans >= m - a[i] - a[j] && m >= a[i] + a[j])
        ans = max(ans,a[i] + a[j]);
    }
    if(ans == 0)  cout << "NONE" << endl;
    else  cout << ans << endl;
  }
}



Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int N = 21;
const int M = 1e9+7;
int dp[N][1<<N];
bool g[N][N];
int n;

int lg2(int x) { return 31-__builtin_clz(x); }

int f(int id, int mask) {
    if (id == n) return 1;
    int &r = dp[id][mask];
    if (r != -1) return r;
    
    r = 0;
    for (int aux = mask; aux; aux &= aux-1) {
        int j = lg2(aux & -aux);
        if (g[id][j]) {
            int next = mask^(1<<j);
            r = (r + f(id+1, next)) % M;
        }
    }
    return r;
    
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> n;
    forn(i, 0, n) {
        forn(j, 0, n) {
            cin >> g[i][j];
        }
    }
    
    memset(dp, -1, sizeof dp);
    cout << f(0, (1<<n)-1) << endl;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int ans=0;
    vector <int> s(4);
    s[0]=a;
    s[1]=a-1;
    s[2]=b;
    s[3]=b-1;
    sort(s.begin(),s.end());
    cout << s[2]+s[3] << endl;

    

    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    ll h;
    cin>>h;
    ll cur = 1;
    ll ans = 0;
    while(h > 0)
    {
        ans += cur;
        h /= 2;
        cur *= 2;
    }
    cout<<ans<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,a,b = nm()
mod = 10**9 + 7
s = pow(2,n,mod) - 1

def fur(n,r):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * pow(q,mod-2,mod) % mod

print((s - fur(n,a) - fur(n,b)) % mod)


Measured memory_bytes: 3064
H = int(input())
W = int(input())
N = int(input())
cnt=wcnt=hcnt=0

while N>0:
    a = max(H-hcnt, W-wcnt)
    N -= a
    cnt+=1
    if a==W:
        H-=1
        hcnt+=1
    elif a==H:
        W-=1
        wcnt+=1
print(cnt)

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

const vector<VI> cnsw ={
	{1,3},  {0,2,4},  {1,5},
	{0,4,6},{1,3,5,7},{2,4,8},
	{3,7},  {4,6,8},  {5,7}
};

const VI pps = {1,2,3,4,5,6,7,8,0};
int main(){
	
	VI ba(9); int wi;
	rep(i,3) rep(j,3) {cin >> wi; ba[i*3+j] = wi;}

	map<VI, int> usd;
	queue<VI> q;
	q.emplace(pps);
	usd[pps] = 0;
	int ct=0;
	while(!q.empty()){
		auto cv = q.front(); q.pop();
		int crz, oc = usd[cv]; 
		rep(i,9) if(cv[i]==0){crz=i; break;}
		for(auto p: cnsw[crz]){
			swap(cv[crz], cv[p]);
			if(!usd.count(cv) ){
				q.emplace(cv);
				usd[cv] = oc +1;
			}
			swap(cv[crz], cv[p]);
		}
	}
	
	
	
	cout << (usd.count(ba)? usd[ba]: -1) <<"\n";
	
	/*for(auto& x: usd){
		cout << x.second <<" :: ";
		for(int z: x.first) cout << z <<" ";
		cout <<"\n";
	}*/
	
	return 0;
}



Measured memory_bytes: 26172
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};

int cnt[1000011];

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

    ll n;
    cin>>n;
    ll ans = 0;
    for(int i=2;i<n;i++){
        cnt[i]++;
        for(int j=i;j<=n;j+=i){
            cnt[j]++;
        }
        ans += cnt[i];
        //cerr << i << " " << cnt[i] << endl;
    }
    ans += 1;
    cout << ans << endl;


}

Measured memory_bytes: 7552
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const long long INF=4000000000000000000LL;
typedef pair<long long,int> P;
int N;
long long a[100];

int main(){
	a[0]=2;
	a[1]=1;
	cin>>N;
	for(int i=2;i<=N;++i){
		a[i]=a[i-1]+a[i-2];
	}
	cout<<a[N]<<endl;
	return 0;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

signed main(){
  int n, m; cin >> n >> m;
  vi ks(m);
  vvi s(m);
  rep(i,m){
    cin >> ks[i];
    s[i].resize(ks[i]);
    rep(j,ks[i])
      cin >> s[i][j];
  }
  int ans = 0;
  vi p(m);
  rep(i,m) cin >> p[i];

  // 全探索
  rep(i,1<<n){
    // 全てのランプが付いているか確認
    bool f = true;
    rep(j,m){
      int tmp = 0;
      rep(k,s[j].size()){
	//s[j][k]があるか
	if((i>>(s[j][k]-1))&1) tmp++;
      }
      if(tmp % 2 != p[j]) f = false;
    }
    if(f) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
S=input()
list = [-1]
list2 = []

for i in range(len(S)):
    if S[i] != 'A' and S[i] != 'T' and S[i] != 'G' and S[i] != 'C':
        list.append(i)

list.append(len(S))

i=0
while i<len(list)-1:
    list2.append(list[i+1]-list[i]-1)
    i += 1

for i in range(len(list2)):
    for j in range(i,len(list2)):
        if list2[i]<list2[j]:
            temp = list2[i]
            list2[i] = list2[j]
            list2[j] = temp
            
print(list2[0])

Measured memory_bytes: 3064
def comb(n, k):
  c = 1
  for i in range(k):
    c *= n-i
    c //= i+1
  return c

n = [int(i) for i in input()]
l = len(n)
k = int(input())
count = 0
for i in range(l):
  if n[i] > 0:
    # n[:i] 0 {1..9}*k 0*(l-i-1-k)
    count += 9 ** k * comb(l-i-1, k)
    # n[:i] {1..(n[i]-1)} {1..9}*(k-1) 0*(l-i-1-k)
    if k >= 1:
      count += 9 ** (k-1) * comb(l-i-1, k-1) * (n[i]-1)
    else:
      break
    # Next is n[:i+1] {1..9}*(k-1) 0*(l-i-k)
    k -= 1
  if i == l-1 and k == 0:
    count += 1
print(count)

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

#define repo(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;


ll aaa(ll n, ll k){
    ll a = n - k;
    if(a == 0){
        return 0;
    }
    if(a < 0){
        a *= -1;
        return min(a,n);
    }

   return aaa(a,k); 
}


int main(){
    ll N,K;
    cin >> N >> K;
//     if(K == 1){
//         cout << 0 << endl;
//         return 0;
//     }
    ll yo = N/K;
    ll ama = N % K;
    if(ama == 0){
        cout << 0 << endl;
        return 0;
    }


    if(yo > 0){
        ll yyy = N - (yo * K);
        cout << min(yyy, -1*(yyy -K)); 
        return 0;
    }
    
    cout << min(N,-1*(N-K)) << endl;
    

    
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
#define int long long 
const int N=300009;
int ver[N<<1],nxt[N<<1],h[N],tot;
int n,m,col[N],cnt[2];
bool vis[N];

inline void add(int x,int y)
{
	ver[++tot]=y,nxt[tot]=h[x],h[x]=tot;
}

void dfs(int u,int fa)
{
	if(col[u]==col[fa])
	{
		printf("%lld",n*(n-1)/2-m);
		exit(0);
	}
	if(col[u]==!col[fa]) return;
	col[u]=col[fa]^1;
	cnt[col[u]]++;
	vis[u]=true;
	for(int i=h[u];i;i=nxt[i])
	{
		int v=ver[i];
		if(v==fa) continue;
		dfs(v,u);
	}
}

signed main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=m;i++) 
	{
		int x,y;
		scanf("%lld%lld",&x,&y);
		add(x,y),add(y,x);
	}
	memset(col,-1,sizeof col);
	col[0]=0;
	dfs(1,0);
	// puts("Debug");
	printf("%lld",cnt[0]*cnt[1]-m);
	return 0;
}

Measured memory_bytes: 8348
#include<stdio.h>
 
int main(){
   int n;
  long long int k;
  scanf("%d%lld",&n,&k);
 
  long long int num[100001] = {0};
  for(int i = 1; i <=n; i++){
    int a,b;
    scanf("%d%d",&a,&b);
    num[a] += b;
  }
  for(int i = 1; i <= 100000; i++){
    k = k-num[i];
    if( k <= 0 ){
      printf("%d",i);
      return 0;
    }
  }
 
  return 0;
 
}

Measured memory_bytes: 896
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n;
    cin>>n;
    int ans =0;
    ans+=(1000* (n/500));
    n%=500;
    ans+=(5*(n/5));
    cout<<ans;


    printclock;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: str):
    return S + 's' if S[-1] != 's' else S + 'es'


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    print(solve(S))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9104
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };





signed main() {
	int n;
	string s, t, e;

	cin >> n >> s >> t;


	for (int i = 0; i < n; i++) {
		e += s[i];
		e += t[i];
	}

	cout << e << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

struct Job {
	int a, b;
};

int n, m;
vector<int> job[100043];
priority_queue<int> q;
int ans;

int main(int argc, char const *argv[]) {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		int day, reward;
		scanf("%d%d", &day, &reward);
		if (day <= m) {
			job[m - day].push_back(reward);
		}
	}

	for (int day = m; day >= 0; --day) {
		for (int i = 0; i < job[day].size(); ++i) {
			q.push(job[day][i]);
		}
		if (!q.empty()) {
			ans += q.top();
			q.pop();
		}
	}

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

	return 0;
}


Measured memory_bytes: 5632
// B - Judge Status Summary
#include <bits/stdc++.h>
using namespace std;
string in(){string x;cin>>x;return x;}

int main(){
	int N; cin>>N;
	map<string,int> S;
	while(N--) S[in()]++;
	for(auto k:{"AC","WA","TLE","RE"})
		cout<< k <<" x "<< (S.count(k)? S[k]:0) <<endl;
}


Measured memory_bytes: 3584
#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;

typedef long long ll;
typedef pair<int, int> P;

// O(N log N)
int solve2(vector<int> v){

	int N = (int)v.size();
	map<int,int> cnt; cnt.clear();
	rep (i, N){
		++cnt[v[i]];
	} // end rep

	vector<P> rank; rank.clear();
	map<int,int>::iterator it = cnt.begin();
	for (; it != cnt.end(); ++it){
		int n = (*it).first;
		int c = (*it).second;
		rank.push_back(P(-c,n));
	} // end for
	
	sort(ALL(rank));

	int res = N;
	if (rank.size() == 1){
		res = min(res, N / 2);
	}else
	if (rank.size() >= 2){
		vector<int> n((int)min(7, N), 0);
		rep (i, (int)min(7,N)) n[i] = rank[i].second;
		sort(ALL(n));
		do{
			int curr = 0;
			rep (i, N){
				if (i % 2 == 0){
					curr += (int)(v[i] != n[0]);
				}else{ // if (i % 2 == 1)
					curr += (int)(v[i] != n[1]);
				} // end if
			} // end rep
			res = min(res, curr);
		}while(next_permutation(ALL(n)));
	} // end if

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

	int N; cin >> N;
	vector<int> v(N,0);
	rep (i, N){
		cin >> v[i];
	} // end rep

	int res = solve2(v);

	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 6908
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>



using namespace std;
typedef long long ll;
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}

int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}









int main() {
  int A,B;
  cin>>A>>B;
  string S;
  cin>>S;
  bool ok=true;
  for(int i=0;i<A;i++){
    if(S.at(i)>='0'&&S.at(i)<='9'){

    }else{
      ok=false;
    }
  }
  if(S.at(A)!='-'){
    ok=false;
  }
  for(int i=A+1;i<A+B+1;i++){
    if(S.at(i)>='0'&&S.at(i)<='9'){

    }else{
      ok=false;
    }

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





  

  


  

    


  

  
  
  
  
}


  
  

  

  

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#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 <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

int main(){
  string S;
  int K;
  cin >> S >> K;
  int N=S.length();

  S=S+S;
  int count=0;
  int temp=1;
  srep(i,1,2*N){
    if(S[i-1]==S[i]){
      temp++;
    }
    if(S[i-1]!=S[i] || i==2*N-1){
      count+=temp/2;
      temp=1;
    }
  }

  int count2=0;
  temp=1;
  srep(i,1,N){
    if(S[i-1]==S[i]){
      temp++;
    }
    if(S[i-1]!=S[i] || i==N-1){
      count2+=temp/2;
      temp=1;
    }
  }

  temp=1;
  srep(i,1,N){
    if(S[i-1]==S[i]){
      temp++;
    }
  }
  if(temp==N){
    printf("%lld\n", (ll)N*K/2);
  }
  else{
    int bound=count-count2;
    ll ans=count2+(ll)bound*(K-1);

    printf("%lld\n", ans);
  }


}


Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
 
count = 0
 
for i in range(n):
    a = list(map(int,input().split()))
    A= [a[i] * b[i] for i in range(m)]
 
    if(sum(A) + c > 0):
        count+= 1
 
print(count)

Measured memory_bytes: 3060
from math import sqrt

n = int(input())
points = []
for i in range(n):
    x, y = map(float, input().split())
    points.append((x, y))

lower = 0
upper = 10000


def get_cross_point(p1, p2, r):
    x, y = p2
    x -= p1[0]
    y -= p1[1]
    a = (x ** 2 + y ** 2) / 2
    if (x ** 2 + y ** 2) * r ** 2 - a ** 2 < 0:
        return None
    x1 = (a * x + y * sqrt((x ** 2 + y ** 2) * r ** 2 - a ** 2)) / (x ** 2 + y ** 2)
    y1 = (a * y - x * sqrt((x ** 2 + y ** 2) * r ** 2 - a ** 2)) / (x ** 2 + y ** 2)
    x2 = (a * x - y * sqrt((x ** 2 + y ** 2) * r ** 2 - a ** 2)) / (x ** 2 + y ** 2)
    y2 = (a * y + x * sqrt((x ** 2 + y ** 2) * r ** 2 - a ** 2)) / (x ** 2 + y ** 2)
    x1 += p1[0]
    x2 += p1[0]
    y1 += p1[1]
    y2 += p1[1]
    return (x1, y1), (x2, y2)


def square_dist(p0, p1):
    return ((p0[0] - p1[0]) ** 2) + ((p0[1] - p1[1]) ** 2)


def check_all_in_r(p, r):
    for q in points:
        if square_dist(p, q) > (r ** 2) + 0.0000001:
            return False
    return True


def check(r):
    for i in range(n):
        for j in range(i + 1, n):
            cross_points = get_cross_point(points[i], points[j], r)
            if cross_points is None:
                return False
            for p in cross_points:
                if check_all_in_r(p, r):
                    return True

    return False


for _ in range(100):
    middle = (upper + lower) / 2
    if check(middle):
        upper = middle
    else:
        lower = middle
print(middle)


Measured memory_bytes: 52440
import math
import numpy

A, B, H, M = map(int, input().split())

RA = math.radians(360 * H / 12 + 30 * M / 60)
RB = math.radians(360 * M / 60)

XA = A*math.cos(RA)
YA = A * math.sin(RA)

XB = B*math.cos(RB)
YB = B*math.sin(RB)

XYA = numpy.array([XA, YA])
XYB = numpy.array([XB, YB])
U = XYB - XYA
print(numpy.linalg.norm(U))


Measured memory_bytes: 27336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,c;cin>>n>>c;
  ll x[n],v[n];
  ll rk[n],lk[n],rm[n],lm[n],rs=0,ls=0;
  for(ll i=0;i<n;i++){
    cin>>x[i]>>v[i];
    rs+=v[i];
    rk[i]=rs-x[i];
    if(i==0)rm[i]=rk[i];
    else rm[i]=max(rm[i-1],rk[i]);
  }
  if(n==1){
    ll ty=max(v[0]-x[0],v[0]-c+x[0]);
    cout<<max((ll)0,ty)<<endl;
    return 0;
  }
  for(ll i=n-1;i>=0;i--){
    ls+=v[i];
    lk[i]=ls-c+x[i];
    if(i==n-1)lm[i]=lk[i];
    else lm[i]=max(lm[i+1],lk[i]);
  }
  //for(ll i=0;i<n;i++)cout<<rk[i]<<" "<<rm[i]<<endl;
  //for(ll i=n-1;i>=0;i--)cout<<lk[i]<<" "<<lm[i]<<endl;return 0;
  ll ans=0;
  for(ll i=0;i<n;i++){
    ll ho=rk[i];
    if(i==n-1){
      ans=max(ho,ans);
      break;
    }
    ll hen=ho-x[i];
    hen+=lm[i+1];
    //cout<<ho<<" "<<hen<<endl;
    ll dotti=max(ho,hen);
    ans=max(dotti,ans);
  }
  for(ll i=n-1;i>=0;i--){
    ll ho=lk[i];
    if(i==0){
      ans=max(ho,ans);
      break;
    }
    ll hen=ho-(c-x[i]);
    hen+=rm[i-1];
    ll dotti=max(ho,hen);
    ans=max(dotti,ans);
  }
  cout<<ans<<endl;
}
                         

Measured memory_bytes: 4992