akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
    int a[100];
    int n,i,j,x=0,mini;
    int temp;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0; i<n; i++)
            scanf("%d",&a[i]);
        x=0;
        for(i=0; i<n-1; i++)
        {
            mini=i;
            for(j=i+1; j<n; j++)
            {
                if(a[j]<a[mini])
                {
                    mini=j;
                }
            }
            if(mini!=i)
            {
                temp=a[i];
                a[i]=a[mini];
                a[mini]=temp;
                x++;
            }
        }
         for(i=0; i<n-1; i++)
                printf("%d ",a[i]);
            printf("%d\n",a[n-1]);
            printf("%d\n",x);
    }
    return 0;
}



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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    ll N;
    cin >> N;
    ll ans = 0;
    ll lastm = 0;
    for(ll m = 1; m * m <= N; m++) {
        if (N / m == N % m) {
            ans += m;
        }
        lastm = m;
    }

    // s := [N / m]
    for(ll s = 1; s * s < N; s++) {
        ll minm = N / (s + 1) + 1;
        if ((N % minm) >= s && (N % minm) % s == 0) {
            ans += minm + ((N % minm) - s) / s;
        }
    }

    cout << ans << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  // vector<int> d;
  while (n > 0) {
    // d.push_back(n%k);
    n /= k;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())
def ten(i):
  wa = 0
  while i != 0:
     wa += i%10
     i = i//10
  return(wa)  

result = 0
for i in range(n + 1):
  if a <= ten(i) and ten(i)<=b:
    result += i
print(result)    


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	void main() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int [n];
		
		for(int i = 0; i <a.length; i++) {
			a[i] = sc.nextInt();
		}
		System.out.print(a[a.length-1]);
		for(int i = a.length-2; i >=0; i--) {
			System.out.print(" " + a[i]);
		}
		System.out.println();
	}
	
	public static void main(String[] args) {
		new Main(). main();
	}

}




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

int main() {
	int N;
	cin >> N;
	size_t M;
	cin >> M;
	vector<int> tmp(M);
	for (int i = 0; i < N; ++i) {
		int K;
		cin >> K;
		for (int j = 0; j < K; ++j) {
			size_t A;
			cin >> A;
			++tmp[A - 1];
		}
	}
	int ans = 0;
	for (size_t i = 0; i < M; ++i) {
		if (N == tmp[i]) ++ans;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
const double EPS = 1e-10;//sample:if((double)>=(double)+EPS)
#define CLR(a) memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)  cerr << #x << " = " << (x) << endl;//debug
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

int cnt=0;
using namespace std;
void merge(int A[], int left, int mid, int right){
  int n1=mid-left,n2=right-mid,L[300000],R[300000];
  for(int i=0;i<n1;i++)L[i] = A[left+i];
  for(int i=0;i<n2;i++)R[i] = A[mid+i];
  L[n1]=R[n2]=INT_MAX;
  int i=0,j=0;
  for(int k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]) A[k]=L[i++];
    else A[k]=R[j++];
  }
}
void mergeSort(int A[], int left, int right){
  if(left+1<right){
    int mid = (left + right) / 2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){
  int n;
  cin>>n;
  int S[500000];
  for(int i=0;i<n;i++)cin>>S[i];
  mergeSort(S,0,n);
  for(int i=0;i<n-1;i++)cout<<S[i]<<" ";
  cout<<S[n-1]<<endl;
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 7012
from collections import Counter

n = int(input())

kw = Counter()
for i in range(n):
    s = input()
    kw[s] += 1

v = max(kw.values())
ans = []

for key, value in kw.most_common():
    if value == v:
        ans.append(key)

for s in sorted(ans):
    print(s)


Measured memory_bytes: 43548
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

vector<int> v;

void init_uf(int n){
    v.assign(n,-1);
}

int find_(int x){
    if(v[x]<0) return x;
    v[x]=find_(v[x]);
    return v[x];
}

int same_(int a,int b){
    if(find_(a)==find_(b)) return 1;
    return 0;
}

void union_(int a,int b){
    if(same_(a,b)) return;
    int a_p=find_(a),b_p=find_(b);
    if(a_p>b_p) swap(a_p,b_p);
    v[a_p]+=v[b_p]; v[b_p]=a_p;
}

void print_v(){
    rep(i,v.size()) cout<<v[i]<<" ";
    cout<<endl;
}

int size_(int a){
    return -v[find_(a)];
}

int main(){
    int n,m; cin>>n>>m;
    init_uf(n);
    rep(i,m){
        int u,v; cin>>u>>v;
        union_(u-1,v-1);
    }
    int ans=0;
    rep(i,n) ans=max(ans,size_(i));
    cout<<ans<<endl;
}

Measured memory_bytes: 3992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderE
{
    static void Main()
    {
        var sc = new Scanner();

        int x = sc.NextInt();
        int y = sc.NextInt();
        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();
        int[] p = sc.IntArray();
        int[] q = sc.IntArray();
        int[] r = sc.IntArray();

        p = p.OrderByDescending(n => n).ToArray();
        q = q.OrderByDescending(n => n).ToArray();
        r = r.OrderByDescending(n => n).ToArray();

        p = p.Take(x).ToArray();
        q = q.Take(y).ToArray();

        int[] all = p.Concat(q).Concat(r).ToArray();
        all = all.OrderByDescending(n => n).ToArray();


        long answer = 0;
        for (int i = 0; i < x + y; i++)
        {
            answer += all[i];
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 51884
/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#ifndef ONLINE_JUDGE
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#else
#define DBG(x)
#endif

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;

#define int long long

void solve() {
    int x, k, d;
    cin>>x>>k>>d; /// k is the total no. of moves
    x = abs(x); /// considering that we are on +ve x-axis
    int steps = x/d; /// no. of steps we are away from origin
    if(k <= steps) x -= k*d; ///if k<=steps, we will try to move as close to origin as
                             ///possible
    else { ///if we are forced to move more steps than required
        k -= steps; ///now k is the extra steps which we are condemned to move
        if(k%2==0) x -= d*steps; ///if extra steps is even, we can simply waste them by
                              ///moving 1 step forward and 1 step backward again and again
        else { ///if odd, we will cross origin (atleast) once as we have no other choice
            x -= d*(steps+1);
        }
    }
    x = abs(x); //finally getting the distance from origin
    cout<<x<<"\n";
    return;
}

int32_t main()
{
    optimizeIO();

    solve();

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}




Measured memory_bytes: 3564
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,cc,n) for(int i=cc;i<(n);++i)
#define dreps(i,cc,n) for(int i=cc;i>(n);--i)
#define llreps(i,cc,n) for(long long i=cc;i<(n);++i)
#define ALL(v) begin(v),end(v)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

int main()
{
	int n;
	ll max = 0;
	cin >> n;
	vector<ll> a(n);
	rep(i,n)
	{
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());

	max += a[0];
	reps(i,1, n/2)
		max += a[i]*2;
	if(n%2==1)
	max += a[n/2];

	/*
	vector<ll> b;
	max = 0;
	b.push_back(a[0]);
	max += a[0];
	b.push_back(a[1]);
	sort(b.rbegin(),b.rend());
	reps(i,2, n)
	{
		//sort(b.rbegin(),b.rend());
		max += min(b[i],b[1]);
		
			b.push_back(a[i]);
	}
	*/

	cout << max << endl;
	return 0;
}

Measured memory_bytes: 4836
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
#define fs first
#define sc second
#define mp make_pair
#define L(x) (1<<x)
#define next Next
using namespace std;
const int inf=1e9+10;
const ll llinf=1e16+10;
const int maxn=2e5+10;
const int maxm=1e3+10;
const int mod=1e9+7;
int n;
vector<int> v[30];
char s[maxn];
int dp[maxn];
int nch=26;
int querry(int pos,int ch)
{
    vector<int>::iterator it;
    it=lower_bound(v[ch].begin(),v[ch].end(),pos);
    if(it==v[ch].end()) return n;
    else return *it;
}
void solve()
{
    dp[n+1]=0;
    for(int i=n-1;i>=0;i--)
    {
        for(int j=0;j<nch;j++)
            dp[i]=min(dp[i],dp[querry(i,j)+1]+1);
    }
    int pos=0;
    //for(int i=0;i<n;i++)
    //    printf("%d ",dp[i]);
    while(pos<n)
    {
        //printf("[%d]",pos);
        for(int j=0;j<nch;j++)
        {
            int t=querry(pos,j)+1;
            if(dp[pos]==dp[t]+1)
            {
                printf("%c",j+'a');
                pos=t;
                break;
            }
        }
    }
    printf("\n");
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%s",s))
    {
        for(int i=0;i<nch;i++)
            v[i].clear();
        n=strlen(s);
        for(int i=0;i<=n;i++)
            dp[i]=inf;
        for(int i=0;i<n;i++)
            v[s[i]-'a'].pb(i);
        solve();
    }
    return 0;
}


Measured memory_bytes: 2304
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
 
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
  if i >= k-1:
    ans += l[i]*cmb(i,k-1,mod)
  j = n-1-i
  if j >= k-1:
    ans -= l[i]*cmb(j,k-1,mod)
  ans %= mod
  
print(ans%mod)

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

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String a = sc.next();
            String b = sc.next();
            System.out.println(lcs(a, b));
        }
    }
    public static int lcs(String a, String b) {
        a = ' ' + a;
        b = ' ' + b;
        int m = a.length();
        int n = b.length();
        int max = 0;
        int[][] c = new int[m][n];
        for (int i = 1; i < m; i++) c[i][0] = 0;
        for (int j = 1; j < n; j++) c[0][j] = 0;

        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                if (a.charAt(i) == b.charAt(j)) {
                    c[i][j] = c[i - 1][j - 1] + 1;
                } else {
                  c[i][j] = Math.max(c[i - 1][j], c[i][j - 1]);
                }
                max = Math.max(max, c[i][j]);
            }
        }
        return max;
    }
}


Measured memory_bytes: 65624
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long A = long.Parse(str[0]);
		long B = long.Parse(str[1]);
		long C = long.Parse(str[2]);
		long ans = Math.Min(A*B,C);
		Console.WriteLine(ans);
	}
}

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

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

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

/* -----  2019/01/27  Problem: nikkei_2019_qual E / Link: __CONTEST_URL__  ----- */
/* ------問題------



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



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

template<typename M>
struct UnionFind {
	using t = typename M::t;
	vector<int> data;
	vector<t>Mdata;
	UnionFind(int n) { data.assign(n, -1); Mdata.assign(n, M::id()); }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			Mdata[x] = M::op(Mdata[x], Mdata[y]);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	t query(int x) { return Mdata[root(x)]; }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
	void add(int x, const t val) { x = root(x); Mdata[x] = M::op(Mdata[x], val); }
	void update(int x, const t val) { x = root(x); Mdata[x] = M::upd(Mdata[x], val); }
};

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

	LL N, M; cin >> N >> M;
	VL W(N);
	FOR(i, 0, N) {
		cin >> W[i];
	}
	using tp = tuple<LL, int, int>;
	vector<tp>edges(M);
	FOR(i, 0, M) {
		int a, b, y;
		cin >> a >> b >> y;
		a--, b--;
		edges[i] = tp(a, b, y);
	}


	struct D {
		using t = struct A { LL wsum; int edgesum; A(LL w, int e) :wsum(w), edgesum(e) {} };
		static t id() { return A(0, 0); }
		static t op(const t& a, const t& b) {
			return A(a.wsum + b.wsum, a.edgesum + b.edgesum);
		}
		static t upd(const t& a, const t& b) {
			return A(a.wsum + b.wsum, b.edgesum);
		}
	};
	UnionFind<D>uf(N);
	FOR(i, 0, N) {
		uf.update(i, D::A(W[i], 0));
	}
	sort(ALL(edges), [](const tp &a, const tp &b) {
		return get<2>(a) < get<2>(b);
	});

	LL cnt = 0;
	FOR(i, 0, M) {
		int a, b; LL y;
		tie(a, b, y) = edges[i];
		uf.unionSet(a, b);
		uf.add(a, D::A(0, 1));
		D::A uniona = uf.query(a);
		if (uniona.wsum >= y) {
			cnt += uniona.edgesum;
			uf.update(a, D::A(0, 0));
		}
	}


	LL ans = M - cnt;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 4608
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;


int main() {
	IOS;
	int a, b;
	cin >> a >> b;
	bool ans;
	if (a % 2 && b % 2) ans = true;
	else ans = false;
	dump(ans ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	string s;
	cin >> s;
	int res = 0;
	bool f = true;
	FOR(i,1,s.size()) {
		if(s[i] != '9') f = false;
		res += 9;
	}
	if(f) res += s[0]-'0';
	else res += s[0]-'0'-1;
	cout << res << endl;
	return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
void dump(){cout<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
void solve1();void solve2();
int main(){solve1();return 0;}

std::vector<std::pair<ll,ll>> prime_factorization(ll n){
  std::vector<std::pair<ll,ll>> factor;
  for(ll p=2;p*p<=n;++p){
    if(n%p!=0)continue;
    ll num=0;
    while(n%p==0){
      num++;
      n/=p;
    }
    factor.emplace_back(p,num);
    if(n==1)return factor;
  }
  if(n!=1)factor.emplace_back(n,1);
  return factor;
}
std::vector<ll> divisor(ll n){
  std::vector<ll> div;
  for(ll p=1;p*p<=n;++p){
    if(n%p==0){
     div.push_back(p);
     if(p*p!=n)div.push_back(n/p);
    }
  }
  return div;
}

ll mypow(ll n,ll p){
  ll ans = 1LL;
  while(p){
    if(p&1)ans*=n;
    n*=n;p>>=1;
  }
  return ans;
}

void solve2(){
  ll n,p;
  cin>>n>>p;
  ll ans = 0;
  auto div = divisor(p);
  sort(div.begin(),div.end());
  auto is_contain =[](vector<ll>const& v,ll n){
    auto itr = lower_bound(v.begin(),v.end(),n);
    return *itr==n;
  };
  for(ll i=1;mypow(i,n)<=p;++i){
    if(is_contain(div,i))ans = i;
  }
  cout<<(ans)<<endl;
}

void solve1(){

  ll n,p;
  cin>>n>>p;

  auto a = prime_factorization(p);
  auto b = divisor(p);
  sort(a.begin(),a.end(),greater<>());
  sort(b.begin(),b.end());
  auto is_contain =[](vector<ll>const& v,ll n){
    auto itr = lower_bound(v.begin(),v.end(),n);
    return *itr==n;
  };
  ll ans = 1LL;
  using pll = pair<ll,ll>;
  priority_queue<pll> que;
  for(auto const& elm:a)que.emplace(elm);
  while(!que.empty()){
    pll elm = que.top();
    que.pop();
    if(elm.second>=n&&pow(ans*elm.first,n)<=p&&is_contain(b,ans*elm.first)){
      ans*=elm.first;
      if(elm.second-n>=n)que.emplace(pll(elm.first,elm.second-n));
    }
  }
  cout<<(ans)<<endl;

}

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

struct Node {
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node)); // *zはinsert関数内でしか存在しないのでmallocの必要あり
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;

  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
};

Node * find(Node *u, int k) {
  while(u != NIL && k != u->key) {
    if (k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
};

Node * treeMinimum(Node *x) {
  while (x->left != NIL) {
    x = x->left;
  }
  return x;
};

// inorderでの次節点
Node * treeSuccessor(Node *x) {
  if (x->right != NIL) {
    return treeMinimum(x->right);
  }
  Node *y = x->parent;
  while(y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
};

void treeDelete(Node *z) {
  Node *y; // 削除する対象
  Node *x; // yの子

  // 削除する節点を決める
  if (z->left == NIL || z->right == NIL) y = z; // 両方またはどちらかが確定NIL
  else y = treeSuccessor(z); // y.leftは確定NIL

  if (y->left != NIL) {
    x = y->left;
  } else {
    x = y->right;
  }

  if (x != NIL) {
    x->parent = y->parent;
  }

  if (y->parent == NIL) {
    root = x;
  } else {
    if (y == y->parent->left) {
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }

  if (y != z) {
    z->key = y->key;
  }

  free(y);
};

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
};

void preorder(Node *u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
};

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    cin >> com;
    if (com[0] == 'f') {
      scanf("%d", &x);
      Node *t = find(root, x);
      if (t != NIL) printf("yes\n");
      else printf("no\n");
    } else if (com == "insert") {
      scanf("%d", &x);
      insert(x);
    } else if (com == "print") {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    } else if (com == "delete") {
      scanf("%d", &x);
      treeDelete(find(root, x));
    }
  }

  return 0;
};



Measured memory_bytes: 22016
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

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

int main()
{
    int n, m;
    cin >> n >> m;
    cout << (n-1) * (m-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <malloc.h>


using namespace std;

struct Node {
	int key;
	Node *pa, *le, *ri;
};

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node*)malloc(sizeof(Node));

	z->key = k;
	z->le = NIL;
	z->ri = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->le;
		}
		else {
			x = x->ri;
		}
	}

	z->pa = y;

	if (y == NIL) {
		root = z;
	}
	else if(z->key < y->key){
		y->le = z;
	}
	else {
		y->ri = z;
	}
}

void pre(Node *a) {
	if (a == NIL) {
		return;
	}

	int number = a->key;
	
	cout << " " << number;
	pre(a->le);
	pre(a->ri);
}

void ino(Node *a) {
	if (a == NIL) {
		return;
	}

	int number = a->key;

	ino(a->le);
	cout << " " << number;
	ino(a->ri);
}


int main()
{
	int n, num;
	string order;

	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> order;
		if (order == "insert") {
			cin >> num;
			insert(num);
		}
		else if (order == "print") {
			ino(root);
			cout << endl;
			pre(root);
			cout << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 26500
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  init();

  int X;
  cin >> X;
  out(360 / gcd(360, X));
}


Measured memory_bytes: 3652
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


S = sys.stdin.buffer.readline().decode().rstrip()
K = int(sys.stdin.buffer.readline())

i = 0
while i < len(S) and S[i] == '1':
    i += 1
if K <= i or i == len(S):
    print('1')
else:
    print(S[i])


Measured memory_bytes: 13576
#include <bits/stdc++.h>
//Remove below header file if c++ version greater than 14
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define ll long long int
#define pb push_back
#define mp make_pair
#define all(X) X.begin(), X.end()
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)

using namespace std;
using mii=map<int, int>;
using mll=map<ll, ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int mod = 1000000007;

ll desc(ll x, ll y)
{
    return x > y;
}

int main() {
    fastIO
    int n, i, k;
    cin >> n >> k;
    vi arr(n, 0);

    fo(i, n)
    cin >> arr[i];

    int res = 0;
    for(int i =0 ; i < n; i++)
    {
        if(arr[i] >= k)
            res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int n;
	int x, y, h, w;
	int i;
	int size;
	int all;
	
	while (1){
		
		scanf("%d" , &n);
		if(n == 0){
			break;
		}
	
		all = 0;
		
		for (i = 0; i < n; i++){
			scanf("%d %d %d %d", &x, &y, &h, &w);
		
		size = x + y + h;
		
			if ((size <= 60) && (w <= 2)){
				all += 600;
			}
		
			else if ((size <= 80) && (w <= 5)){
				all += 800;
			}
		
			else if ((size <= 100) && (w <= 10)){
				all += 1000;
			}
		
			else if((size <= 120) && (w <= 15)){
				all += 1200;
			}
		
			else if((size <= 140) && (w <= 20)){
				all += 1400;
			}
		
			else if ((size <= 160) && (w <= 25)){
				all += 1600;
			}
		}
		
		printf("%d\n", all);
	}
	
	return (0);
}

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



int main() {
  double l;
  cin >> l;
  double x = l/3;
  double ans = pow(x, 3);
  printf("%.10f\n", ans);
  return 0;
}


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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long N, std::vector<long long> a) {
  ll ans = 0;
  REP(i, N) {
    if (i % 2 == 0 && a[i] % 2 == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


struct RollingHash{
  using ull = unsigned long long;
  vector<ull> hash,p;
  RollingHash(){}
  RollingHash(const string &s,ull B=1000000007LL){
    int n=s.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(int i=0;i<n;i++){
      hash[i+1]=hash[i]*B+s[i];
      p[i+1]=p[i]*B;
    }
  }
  //S[l, r)
  ull find(int l,int r){
    return hash[r]-hash[l]*p[r-l];
  }
};

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans=n+1;

  RollingHash rh(s);
  for(int a=1;a*3<n;a++){
    if((n-a*3)&1) continue;
    int b=(n-a*3)/2;
    using ull = RollingHash::ull;
    ull u=rh.find(0,a);
    ull v=rh.find(a,a+b);
    ull w=rh.find(a+b,a+b+a);
    ull x=rh.find(a+b+a,a+b+a+b);
    ull y=rh.find(a+b+a+b,a+b+a+b+a);
    if(u==w&&w==y&&v==x) chmin(ans,a+b);
  }

  if(ans<=n) cout<<"Love "<<s.substr(0,ans)<<"!"<<endl;
  else cout<<"mitomerarenaiWA"<<endl;
  return 0;
}



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

int a[200000];
int main(){
	int n;scanf("%d",&n);
	rep(i,n)scanf("%d",&a[i]);
	sort(a,a+n);
	int Max=0;
	int id=-1;
	rep(i,n-1){
		if(Max<min(a[n-1]-a[i],a[i])){
			Max=min(a[n-1]-a[i],a[i]);
			id=i;
		}
	}
	cout<<a[n-1]<<' '<<a[id]<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main(void) {
	int num, i;
	ll ans = 0, s;
	cin >> num;
	vector<ll> a(num), b(num);
	for (i = 0; i < num; i++)
		scanf("%d%d", &a[i], &b[i]);
	for (i = num - 1; i >= 0; i--) {
		s = b[i] - a[i] - ans;
		s %= b[i];
		if (s < 0)
			s += b[i];
		ans += s;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main () {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);
    
    int S = A[0];
    for (int i = 1; i < N; i++) {
        S = S ^ A[i];
    }

    for (int i = 0; i < N; i++) {
        if (i) cout << " ";
        cout << (S ^ A[i]);
    }
    cout << endl;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxV = 90010;
const int maxN = 2e5+10;
const int MOD = 1e9+7;
const ll INF = 1000000000000000010LL;
const int inf = 1e9+10;
#define X first;
#define Y second;

vector<int> v[maxN];
int main() {
	int a,b,x;
	scanf("%d %d %d",&a,&b,&x);
	double y = (double)(2*x)/a/(b*b);
	double z = (double)(a*a*a)/(a*a*b-x)/2;
	double ans;
	if(a <= b*z)
	{
		ans = atan(z);
	}
	else
	{
		ans = atan(y);
	}
	printf("%.10f\n",90-ans*180/3.14159265358979323);
	return 0;
}

Measured memory_bytes: 4992
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC120_1 solver = new ABC120_1();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC120_1 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();

            if (B / A > C) {
                out.println(C);
                return;
            }
            out.println((int) Math.floor(B / A));

        }

    }
}



Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
const int maxn=5+2e5;
int a[maxn];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
		if(a[i]==a[i+1]){
			cout<<"NO\n";
			return 0;
		}
	cout<<"YES\n";	
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int f = 0;
    if(n % 10 == 7)
        f = 1;
    n /= 10;
    if(n % 10 == 7)
        f = 1;
    n /= 10;
    if(n == 7)
        f = 1;
    if(f)
        puts("Yes");
    else
    {
        puts("No");
    } 
    return 0;
}

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

enum inf = 10^^9 + 7;

void main() {
    int n, w;
    scan(n, w);

    auto dp = new long[](w + 1);

    foreach (i ; 0 .. n) {
        int wi, vi;
        scan(wi, vi);
        foreach_reverse (j ; 0 .. w - wi + 1) {
            dp[j + wi] = max(dp[j + wi], dp[j] + vi);
        }
    }

    writeln(dp[w]);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    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: 2684
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int dp[110][5100];
int b[110];
int c[110];
map<vector<int>,int> m;
vector<int>rev[5100];
int ABS(int a){return max(a,-a);}
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",b+i);
	}
	for(int i=0;i<a;i++)scanf("%d",c+i);
	for(int i=0;i<110;i++)for(int j=0;j<5100;j++)
		dp[i][j]=-999999999;
	vector<int> perm(7);
	for(int i=0;i<7;i++){
		perm[i]=i;
	}
	int sz=0;
	do{
		rev[sz]=perm;
	/*	printf("%d:",sz);
		for(int i=0;i<7;i++)printf(" %d",perm[i]);
		printf("\n");
	*/	m[perm]=sz++;
		int tmp=0;
		for(int i=0;i<7;i++){
			for(int j=i+1;j<7;j++){
				if(ABS(perm[i]-perm[j])<=b[perm[i]])tmp+=c[perm[i]];
			}
		}
		dp[7][sz-1]=tmp;
	}while(next_permutation(perm.begin(),perm.end()));
	for(int i=7;i<a;i++){
		for(int j=0;j<sz;j++){
			for(int k=0;k<8;k++){
				vector<int>to;
				for(int l=0;l<k;l++){
					if(rev[j][l]>=1)to.push_back(rev[j][l]-1);
				}
				to.push_back(6);
				for(int l=k;l<7;l++){
					if(rev[j][l]>=1)to.push_back(rev[j][l]-1);
				}
				int val=dp[i][j];
				for(int l=0;l<k;l++){
					if(ABS(rev[j][l]-7)<=b[rev[j][l]+i-7])val+=c[rev[j][l]+i-7];
				}
				for(int l=k;l<7;l++){
					if(ABS(rev[j][l]-7)<=b[i])val+=c[i];
				}
	/*			if(m.count(to)==0){
					printf("%d %d %d\n",i,j,k);
					for(int l=0;l<to.size();l++)printf("%d ",to[l]);
					printf("\n");
				}*/
				dp[i+1][m[to]]=max(dp[i+1][m[to]],val);
			}
		}
	}
	int ret=0;
	for(int i=0;i<sz;i++)ret=max(ret,dp[a][i]);
	printf("%d\n",ret);
}

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

int edge[800][800];

int main(){
  int n, k; cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int a, b; cin >> a >> b;
    edge[a][b]++; edge[b][a]++;
  }
  vector<int> bimap(n+1, -1);
  vector<pair<int, int> > v;
  for (int d = 1; d <= n; d++) {
    if (bimap[d] == -1) {
      int t[2]; t[0] = 0; t[1] = 0;
      bimap[d] = 1; t[1]++;
      queue<int> q; q.push(d);
      while(!q.empty()) {
        int c = q.front(); q.pop();
        for (int i = 1; i <= n; i++) {
          if (c == i) continue;
          if (edge[c][i] == 0) {
            if (bimap[i] == -1) {
              bimap[i] = !bimap[c];
              t[bimap[i]]++;
              q.push(i);
            } else {
              if (bimap[i] != !bimap[c]) {
                cout << -1 << endl;
                return 0;
              }
            }
          }
        }
      }
      v.push_back(make_pair(t[0], t[1]));
    }
  }
  vector<int> ans(n+1, 0); ans[0] = 1;
  for (int i = 0; i < v.size(); i++) {
    vector<int> tmp(n+1, 0);
    int x = v[i].first; int y = v[i].second;
    for (int j = n; j >= 0; j--) {
      if (j-x >= 0 && ans[j-x] > 0) tmp[j]++;
      if (j-y >= 0 && ans[j-y] > 0) tmp[j]++;
    }
    swap(ans, tmp);
  }
  int answer = 1e9;
  for (int i = 0; i <= n; i++) {
    if (ans[i] > 0) {
      answer = min(answer, (i * (i-1)) / 2 + ((n-i) * (n-i-1)) / 2);
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 2432
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int N;
    cin >> N;
    vector<string> W(N);
    for(int i = 0; i < N; i++) cin >> W[i];
    bool ok = true;
    for(int i = 0; i < N - 1; i++){
        if(W[i][W[i].size()-1] != W[i + 1][0]) ok = false;
    }
    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            if(W[i] == W[j]) ok = false;
        }
    }
    if(ok) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 3616
n=int(input())
eat=list(map(int,input().split()))
point=list(map(int,input().split()))
extra=list(map(int,input().split()))

total=sum(point)
for i in range(n-1):
  if eat[i+1]==eat[i]+1:
    total+=extra[(eat[i]-1)]

print(total)

Measured memory_bytes: 3064
s = input()
k = int(input())
co1 = 0
co2 = 0
co3 = 0
ju = True

for i in range(len(s)-1):
    if s[i+1] == s[i] and ju:
        co1 += 1
        ju = False
    else:
        ju = True

s2=s+s
ju=True
for i in range(len(s2)-1):
    if s2[i+1] == s2[i] and ju:
        co2 += 1
        ju = False
    else:
        ju = True

s3 = s2+s
ju = True
for i in range(len(s3)-1):
    if s3[i+1] == s3[i] and ju:
        co3 += 1
        ju = False
    else:
        ju = True

addeven=co2-co1
addodd=co3-co2
print(co1+addeven*(k//2)+addodd*((k-1)//2))


Measured memory_bytes: 3064
n = 0
n = int(input())
ls = []
for i in range(n):
    x = list(input().split())
    ls.append(x)

score1 = 0;score2 = 0
for i in range(n):
    s1 = ls[i][0];s2 = ls[i][1]
    if s1==s2:
        score1 += 1;score2 += 1
        continue
    len1,len2 = len(s1),len(s2)
    flag = 0
    for i in range(min(len1,len2)):
        if s1[i] > s2[i]:
            flag = 1 
            score1 += 3
            break;
        elif s1[i] < s2[i]:
            flag = 1
            score2 += 3
            break
    if flag == 0 and len1!=len2:
        if len1>len2:
            score1 += 3
        else:
            score2 += 3
    
print(score1,score2)


Measured memory_bytes: 5720
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int A = Integer.parseInt(S[0]);
    int B = Integer.parseInt(S[1]);
    int AB = Integer.parseInt(S[2]);
    int X = Integer.parseInt(S[3]);
    int Y = Integer.parseInt(S[4]);
    
    int dif = Math.abs(X-Y);
    int ans = 0;
    if(A+B > AB*2){
      ans += Math.min(X, Y) * AB * 2;
      if(A < AB*2 && X > Y){
        ans += A * dif;
      }else if(B < AB*2 && X < Y){
        ans += B * dif;
      }else{
        ans += AB * dif * 2;
      }
    }else{
      ans += A*X;
      ans += B*Y;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n, m; cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;
    return 0;
}

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

using namespace std;

int main() {
  int A, B, C; cin >> A >> B >> C;

  bool f = false;
  for (int i = 1; i < B+1; i++) {
    if ((A * i) % B == C) {
      f = true;
      break;
    }
  }

  if(f) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
ll a[200009];
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    cin>>n;
    for(i=2;i<=n;i++)
    {
        cin>>x;
        a[x]++;
    }
    for(i=1;i<=n;i++)
        cout<<a[i]<<endl;
    return 0;
}



Measured memory_bytes: 5156
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N, D;

	cin >> N >> D;
	vector<vector<int>> X(N, vector<int>(D));
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < D; j++)
		{
			cin >> X[i][j];
		}
	}
	int ans = 0;

	for (int i = 0; i < N; i++)
	{
		for (int j = i+1; j < N; j++)
		{
			int norm = 0;

			for (int k = 0; k < D; k++)
			{
				int diff = X[i][k] - X[j][k];

				norm += diff * diff;
			}
			for (int k = 0; k <= norm; k++)
			{
				if (k * k == norm)
				{
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}



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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  lli n;
  while (cin >> n) {
    lli a[n];
    lli b[n];
    for (int i = 0; i < n; ++i) {
      cin >> a[i] >> b[i];
    }
    reverse(a, a + n);
    reverse(b, b + n);
    lli sum = 0;
    for (int i = 0; i < n; ++i) {
      a[i] += sum;
      lli y = (a[i] / b[i]) + (bool)(a[i] % b[i]);
      lli x = y * b[i] - a[i];
      sum += x;
      a[i] += x;
      // cout << "x: " << x << endl;
    }
    // for (int i = 0; i < n; ++i) cout << a[i] << ' ' ; cout << endl;
    // for (int i = 0; i < n; ++i) cout << b[i] << ' ' ; cout << endl;
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 1792