akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

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

int main() {
    int n;
    ll k;
    cin >> n >> k;
    ll INF = ll(1e18) + 1;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll lhs = -INF;
    ll rhs = INF;
    while (rhs - lhs > 1){
        ll x = (lhs + rhs) / 2;
        ll tot = 0;
        rep(i, n) {
            if (a[i] < 0){
                int l = -1, r = n;
                while (r - l > 1){
                    int cent = (l + r) / 2;
                    if (a[i] * a[cent] < x){
                        r = cent;
                    }else{
                        l = cent;
                    }
                }
                tot += (n - r);
            }else {
                int l = -1, r = n;
                while (r - l > 1) {
                    int cent = (l + r) / 2;
                    if (a[i] * a[cent] < x) {
                        l = cent;
                    } else {
                        r = cent;
                    }
                }
                tot += (l + 1);
            }
            if (a[i] * a[i] < x){
                tot--;
            }
        }
        tot /= 2;
        if (tot < k){
            lhs = x;
        }else {
            rhs = x;
        }
    }
    cout << lhs << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n, x, m;
    cin, n, x, m;
    const int sz = 100010;
    vector<P> arr(sz, P(-1, -1));
    ll sum = 0;
    REP(i, 1, m + 2) {
        sum += x;
        x = (x * x) % m;
        if (arr[x].first != -1) {
            ll loop = i - arr[x].first;
            ll tail = arr[x].first;
            ll rest = (n - tail) % loop;
            ll diff = sum - arr[x].second;
            ll tails = arr[x].second;
            sum = tails + (n - tail) / loop * diff;
            REP(j, 0, rest) {
                sum += x;
                x = (x * x) % m;
            }
            break;
        }
        arr[x] = P(i, sum);
        if (i == n) break;
    }
    print(sum);
    return 0;
}


Measured memory_bytes: 4744
N,M = map(int,input().split())
G = [[0]*(N+1) for i in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    G[a][b] = 1
    G[b][a] = 1
    
import itertools
zero = [i for i in range(2,N+1)]
ans = 0
for i in itertools.permutations(zero,N-1):
    flag = 1
    if G[1][i[0]]!=1:
        flag = 0
    for j in range(len(i)-1):
        if G[i[j]][i[j+1]] != 1:
            flag = 0
    if flag == 1:
        ans += 1
print(ans)

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

namespace A___One_out_of_Three
{
    class Program
    {
        static void Main(string[] args)
        {
            var A_B_C = Console.ReadLine().Split();

            Console.WriteLine(A_B_C.GroupBy(x => x).Single(x => x.Count() == 1).First());
        }
    }
}


Measured memory_bytes: 13524
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int A, B;
    char op;
    cin >> A >> op >> B;
    if(op == '+') {
        cout << A + B << endl;
    } else {
        cout << A - B << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
**   Contest : Educational DP Contest
**   Problem : F - LCS
**
**    Author : Dhiraj Govindvira
**      Date : 05-Jun-2020 ~ Friday
**      Time : 03:42:34 PM
*/

#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  long long int
#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename T> 
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U> 
inline void inp(T &a, U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(ll &T)
{
    string s1,s2;
    cin>>s1>>s2;

    ll l1 = s1.length();
    ll l2 = s2.length();

    s1 = "0" + s1;
    s2 = "0" + s2;

    ll dp[l1+1][l2+1];
    loop(i,0,l1+1)
    {
        loop(j,0,l2+1)
        {
            if(i==0 or j==0) 
                dp[i][j] = 0;
            else if(s1[i]==s2[j])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    // cout<<dp[l1][l2]<<endl;

    string ans;
    ll i = l1, j = l2;
    while(i>0 && j>0)
    {
        if(s1[i]==s2[j])
        {
            ans.push_back(s1[i]);
            i--,j--;
        }
        else
        {
            if(dp[i-1][j]==dp[i][j]) 
                i--;
            else if(dp[i][j-1]==dp[i][j]) 
                j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

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

    int t = 1;
    loop(Case,1,t+1)
    {
        cerr<<"Case #"<<Case<<'\n';
        solve(Case);
    }
    return 0;
}

Measured memory_bytes: 70656
import collections

def useOne(a, b, c, n):
    count = 0
    if n%a == 0: count += 1
    if n%b == 0: count += 1
    if n%c == 0: count += 1
    return count

def useTwo(a, b, n):
    a, b = sorted([a, b])
    count = 0
    maxCountOfA = n//a
    maxCountOfB = n//b
    
    startCount = 1
    for i in range(maxCountOfA, 0, -1):
        for j in range(startCount, maxCountOfB+1):
            _sum = i*a + j*b
            if _sum == n:
                count += 1
                startCount = j+1
                break
            if _sum > n:
                startCount = j
                break
    return count

def useThree(a, b, c, n):
    a, b, c = sorted([a, b, c])
    maxCountOfA = n//a
    maxCountOfB = n//b
    maxCountOfC = n//c
    count = 0
    for i in range(1, maxCountOfA+1):
        startCountOfC = maxCountOfC
        for j in range(1, maxCountOfB+1):
            _sum = i*a + j*b
            if _sum >= n:
                maxCountOfB = j
                break
            for k in range(startCountOfC, 0, -1):
                _sum = i*a + j*b + k*c
                if _sum == n:
                    count += 1
                    startCountOfC = k-1
                    break
                if _sum < n:
                    startCountOfC = k
                    break
    return count

def answer(a, b, c, n):
    count = useOne(a, b, c, n)
    count += useTwo(a, b, n)
    count += useTwo(a, c, n)
    count += useTwo(b, c, n)
    count += useThree(a, b, c, n)
    return count
    
a, b, c, n = map(int, input().split())
print(answer(a, b, c, n))

Measured memory_bytes: 41712
#include <bits/stdc++.h>
#define MAX 10000007
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

using namespace std;
typedef long long ll ;
const int INF= 1e9+7;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    int n;
    cin>>n;

    int a[n][3];
    for(int i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }

    int dp[n][3];//dp[i][j] -> max happiness at current day i for activity j
    MEM(dp,-INF);

    for(int i=0;i<3;i++)
         dp[0][i]=a[0][i];

    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2]) + a[i][0];
        dp[i][1]=max(dp[i-1][2],dp[i-1][0]) + a[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0]) + a[i][2];
    }

    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;

    return 0;
}


Measured memory_bytes: 2560
*p="%d %d %d %d %d\n";M(int*a){return*1[&a]-*a;}s[];main(){scanf(p,s,s+1,s+2,s+3,s+4);qsort(s,5,4,M);printf(p,*s,s[1],s[2],s[3],s[4]);exit(0);}

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001;
using namespace std;
typedef long long ll;

int n;
int p[10100];

int main(){
  std::cin >> n;
  rep(i,1,n+1)std::cin >> p[i];
  sort(p+1, p+n+1);
  int res=0;
  rep(i,1,n){
    res += p[i];
  }
  res += p[n]*0.5;
  std::cout << res << '\n';
}


Measured memory_bytes: 256
#include <regex>
#include <iostream>
#include <string>
using namespace std;
main(){
	int n;
	string s;
	smatch m;
	for(cin>>n,getline(cin,s);n;n--){
		getline(cin,s);
		if(regex_match(s,m,regex(">'(=+)#(=+)~"))&&m[1].length()==m[2].length())cout<<'A'<<endl;
		else if(regex_match(s,regex(">^(Q=)+~~")))cout<<'B'<<endl;
		else cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 1272
#include<stdio.h>

int main(void){
  int a,b,i,k;
  scanf("%d %d %d",&a,&b,&k);
  for(i=a;i<=b;i++){
    if((i<a+k) || (b-k<i)){
      printf("%d\n",i);
    }
  }
  return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String args[]) throws IOException{
               BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));	
		int n= Integer.parseInt(reader.readLine());
		long[] list = Arrays.stream(reader.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
		int q = Integer.parseInt(reader.readLine());
		HashMap<Long,Long> hm = new HashMap<>();
		long sum = 0;
		for(long o:list){
			hm.put(o,hm.getOrDefault(o,(long)0)+1);
			sum+=o;
		}
		for(int i=0;i<q;i++){
			String[] pol = reader.readLine().split(" ");
			long a = Long.parseLong(pol[0]);
			long b = Long.parseLong(pol[1]);
			if(hm.containsKey(a)){
				long p = hm.get(a);
				hm.put(b,hm.getOrDefault(b,(long)0)+p);
				hm.remove(a);
				sum-=p*a;
				sum+=p*b;
			}
			System.out.println(sum);
		}		
	}
}


Measured memory_bytes: 70976
import array

class Solver:

  def solve(self):
    n, k = map(int, raw_input().split())
    x = map(int, raw_input().split())
    y = [0] * (100100 - len(x))
    dp = array.array('i', [1<<30] * 100100)
    dp[0] = 0
    h = array.array('i', x + y)

    for i in xrange(n):
      dpi = dp[i]
      hi = h[i]
      for kk in xrange(k):
        j = kk + 1
        v = dpi + abs(hi - h[i+j])
        if dp[i+j] > v:
          dp[i+j] = v

    print dp[n-1]

Solver().solve()

Measured memory_bytes: 11196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

struct UnionFind {
    vector<int> par;
    UnionFind(int N) : par(N) {
        rep(i, N) par[i] = -1;
    }
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return -par[root(x)];
    }
};


int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> S(H, vector<char>(W));
    rep(i, H) rep(j, W) cin >> S[i][j];
    UnionFind UF(H * W);
    vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
    rep(i, H) rep(j, W) rep(k, 4) {
        if (i + dx[k] >= 0 && i + dx[k] < H && j + dy[k] >= 0 && j + dy[k] < W) {
            if (S[i][j] != S[i + dx[k]][j + dy[k]]) {
                UF.unite(i * W + j, (i + dx[k]) * W + j + dy[k]);
            }
        }
    }
    vector<int> cnt(H * W, 0);
    rep(i, H) rep(j, W) {
        if (S[i][j] == '.') {
            ++cnt[UF.root(i * W + j)];
        }
    }
    lint ans = 0;
    rep(i, H) rep(j, W) {
        if (S[i][j] == '#') {
            ans += cnt[UF.root(i * W + j)];
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1664
#include <list>
#include <iostream>
#include <string>

int main()
{
	int changeCount, bookMadeYear, m_count = 0;
	std::string m_string = "kogakubu10gokan";
	bool endIs = false;

	std::cin >> changeCount >> bookMadeYear;

	for( int i = 0; i < changeCount; i++ )
	{
		int tmpYear;
		std::string tmpString;
		std::cin >> tmpYear >> tmpString;

		if (endIs) {
			continue;
		}

		if (m_count <= bookMadeYear 
				&& bookMadeYear < tmpYear) {
			endIs = true;
		} else {
			m_count = tmpYear;
			m_string = tmpString;
		}
	}
	std::cout << m_string << std::endl;

	return 0;
}


Measured memory_bytes: 1208
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
const int N=1505;
int S[N],n,u[N][N],l[2][N],r[2][N],flag[N][N];
char A[N][N];
int main(){
	scanf("%d",&n);
	for (register int i=1;i<=n;++i)scanf("%s",A[i]+1);
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)flag[i][j]=A[i][j]>='0'&&A[i][j]<='9';
	for (register int i=0;i<=n;++i)
		for (register int j=0;j<=n;++j)u[i][j]=flag[i][j]?min(i,min(u[i-1][j],u[i][j-1])):1<<30;
	long long ans=0;
	for (register int x=1;x<=n;++x){
		int t=x&1;
		for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x][j]<=x?A[x][j]-'0':0);
		for (register int j=n+1;j;--j){
			if (flag[x][j]){
				l[t][j]=j;
				r[t][j]=max(r[t][j+1],j);
				if (l[t][j]<=r[t][j])ans+=(A[x][j]-'0')*(S[r[t][j]]-S[l[t][j]-1]-A[x][j]+'0');
			}
			else l[t][j]=1e9,r[t][j]=-1;
		}
		for (register int i=x-1;i;--i){
			int t=i&1;
			for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x][j]<=i?A[x][j]-'0':0);
			for (register int j=n+1;j;--j){
				if (flag[i][j]){
					l[t][j]=min(l[t][j+1],l[t^1][j]);
					r[t][j]=max(r[t][j+1],r[t^1][j]);
					if (l[t][j]<=r[t][j])ans+=(A[i][j]-'0')*(S[r[t][j]]-S[l[t][j]-1]);
				}
				else l[t][j]=1e9,r[t][j]=-1;
			}
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 9344
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
  int a, b, c;
  int rec = 0, rhomb = 0;
  while(~scanf("%d,%d,%d", &a, &b, &c)) {
	if(a * a + b * b == c * c) rec++;
	else if(a == b) rhomb++;
  }
  cout << rec << endl;
  cout << rhomb << endl;
  return 0;
}

Measured memory_bytes: 3136
import sys


fin = sys.stdin.readline
N, M = [int(elem) for elem in fin().split()]
drinks = sorted([tuple(int(elem) for elem in fin().split()) for _ in range(N)], \
    key=lambda drink: (drink[0], -drink[1]))
assert len(drinks[0]) == 2

necessary_money = 0
num_bought_bottles = 0

for price, num_bottles in drinks:
    if num_bought_bottles + num_bottles < M:
        necessary_money += price * num_bottles
        num_bought_bottles += num_bottles
    else:
        necessary_money += price * (M - num_bought_bottles)
        break
print(necessary_money)


Measured memory_bytes: 61020
#include<iostream>
using namespace std;
#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX / 2 + 2], R[MAX / 2 + 2];

llong merge(int A[], int n, int left, int mid, int right) {
	int i, j, k;
	llong cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	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] = SENTINEL;
	i = j = 0;
	for (int k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}

llong mergeSort(int A[], int n, int left, int right) {
	int mid;
	llong v1, v2, v3;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		v1 = mergeSort(A, n, left, mid);
		v2 = mergeSort(A, n, mid, right);
		v3 = merge(A, n, left, mid, right);
		return v1 + v2 + v3;
	}
	else return 0;
}

int main() {
	int A[MAX], n, i;

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

	llong ans = mergeSort(A, n, 0, n);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4652
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i <= n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i <= n; i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std;

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

    v_ll a(n);
    irep(i, n) {
        cin >> a[i];
    }
    
    ll ans = 0;
    irep(i, 60) {
        
        ll x = 0;
        irep(j, n) { 
            if((a[j]>>i)&1) { x++; }
        }
        ll sum = x * (n-x) % IMOD;
        irep(j, i) { 
            sum = (sum * 2) % IMOD; 
        }
        ans += sum; 
        ans %= IMOD;
    }
    
    cout << ans << endl;

    return 0;
}
/** atcodr **/


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <unordered_set>
#include <cstring>

using namespace std;

const int INF = 1e9 + 5;


int main() {

    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; i++) {
        int aval, bval, cval;
        cin >> aval >> bval >> cval;
        a[i] = aval;
        b[i] = bval;
        c[i] = cval;
    }

    vector<vector<int> > dp(n);
    for(int i = 0; i < n; i ++) {
        dp[i] = vector<int>(3);
    }
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i = 1; i < n; i++) {
        dp[i][0] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
        dp[i][1] = max(dp[i-1][0] + b[i], dp[i-1][2] + b[i]);
        dp[i][2] = max(dp[i-1][1] + c[i], dp[i-1][0] + c[i]);
    }

    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;

    return 0;
}

Measured memory_bytes: 6912
n,m=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
#print(X)
l=[]
for i in range(m-1):
    l.append(X[i+1]-X[i])
#print(l)
l.sort()
ans=0
for i in range(m-1-n+1):
    ans+=l[i]
print(ans)

Measured memory_bytes: 13968
#include <string>
#include <iostream>

#pragma warning(disable : 4996)

#define mod 100000

using namespace std;

int H, W, dp[2][1 << 19][2][2], bits[10946], maxbits;

string M[20];

void rec(int pos, int bit)
{
	bits[maxbits++] = bit;

	for (int i = pos + 2; i < W - 1; i++)
	{
		rec(i, bit + (1 << i));
	}
}

int main()
{
	scanf("%d", &H);
	scanf("%d", &W);

	for (int i = 0; i < H; i++) cin >> M[i];

	if (M[0][0] == 'J' || M[0][0] == '?') dp[0][0][0][0] += 1;
	if (M[0][0] == 'O' || M[0][0] == '?') dp[0][0][1][0] += 1;
	if (M[0][0] == 'I' || M[0][0] == '?') dp[0][0][1][0] += 1;

	maxbits = 1; bits[0] = 0;

	for (int i = 0; i < W - 1; i++)
	{
		rec(i, 1 << i);
	}

	for (int i = 0; i < H * W - 1; i++)
	{
		for (int j = 0; j < maxbits; j++)
		{
			dp[(i ^ 1) & 1][bits[j]][0][0] = 0;
			dp[(i ^ 1) & 1][bits[j]][0][1] = 0;
			dp[(i ^ 1) & 1][bits[j]][1][0] = 0;
			dp[(i ^ 1) & 1][bits[j]][1][1] = 0;
		}

		for (int j = 0; j < maxbits; j++)
		{
			char c = M[(i + 1) / W][(i + 1) % W];

			int nxt = (bits[j] << 1) % (1 << (W - 1));

			int sum0 = (dp[i & 1][bits[j]][0][0] + dp[i & 1][bits[j]][1][0]) % mod;
			int sum1 = (dp[i & 1][bits[j]][0][1] + dp[i & 1][bits[j]][1][1]) % mod;

			if (c == 'J' || c == '?')
			{
				dp[(i ^ 1) & 1][nxt][0][0] += sum0;
				dp[(i ^ 1) & 1][nxt][0][1] += sum1;
			}

			if (c == 'O' || c == '?')
			{
				if ((M[i / W][i % W] == 'J' || M[i / W][i % W] == '?') && i % W != W - 1)
				{
					dp[(i ^ 1) & 1][nxt + 1][1][0] += dp[i & 1][bits[j]][0][0];
					dp[(i ^ 1) & 1][nxt + 1][1][1] += dp[i & 1][bits[j]][0][1];

					dp[(i ^ 1) & 1][nxt + 1][1][0] %= mod;
					dp[(i ^ 1) & 1][nxt + 1][1][1] %= mod;

					dp[(i ^ 1) & 1][nxt][1][0] += (sum0 - dp[i & 1][bits[j]][0][0] + mod);
					dp[(i ^ 1) & 1][nxt][1][1] += (sum1 - dp[i & 1][bits[j]][0][1] + mod);
				}
				else
				{
					dp[(i ^ 1) & 1][nxt][1][0] += sum0;
					dp[(i ^ 1) & 1][nxt][1][1] += sum1;
				}
			}

			if (c == 'I' || c == '?')
			{
				if (bits[j] & (1 << (W - 2)))
				{
					dp[(i ^ 1) & 1][nxt][1][1] += sum0;
				}
				else
				{
					dp[(i ^ 1) & 1][nxt][1][0] += sum0;
				}

				dp[(i ^ 1) & 1][nxt][1][1] += sum1;
			}

			dp[(i ^ 1) & 1][nxt][1][0] %= mod;
			dp[(i ^ 1) & 1][nxt][1][1] %= mod;
		}
	}

	int ret = 0;

	for (int i = 0; i < maxbits; i++)
	{
		ret += dp[(H * W - 1) % 2][bits[i]][0][1];
		ret += dp[(H * W - 1) % 2][bits[i]][1][1];

		ret %= mod;
	}

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

	return 0;
}

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

int main() {
  
  int N, K, X;
  cin >> N >> K;
  X = 1;
  for(int i = 0; i < N; i++) {
    if(X < K) {
      X *= 2;
    }
    else {
      X += K;
    }
  }
  cout << X << endl; 
}

Measured memory_bytes: 3632
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static int count=0;
    private static ArrayList<Integer> now=new ArrayList<Integer>();


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

        int[] b = new int[3];
        b[0] = sc.nextInt();
        b[1] = sc.nextInt();
        b[2] = sc.nextInt();

        Arrays.sort(b);

        System.out.println(b[0] + b[1]);


    }
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin >> n;

    float counter = 0;
    for(int i=1; i<=n; i+=2)
        counter++;

    cout << counter/n << "\n";
    return 0;
}


Measured memory_bytes: 256
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    A, B = input_list()
    a = int(A)
    B = str(B)
    B = B.replace(".", "")
    b = int(B)
    ans = a * b
    ans = str(ans)
    ans = ans[:-2]
    if ans == "":
        print(0)
    else:
        print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
	string s;
	cin >> s;
	rep(i,s.size())cout<<'x';cout<<endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<ll, ll>> B(n);
  set<pair<int, int>> B_set;
  for (int i = 0; i < n; i++) {
    cin >> B[i].first >> B[i].second;
    B_set.insert(B[i]);
  }

  sort(B.begin(), B.end());

  set<pair<ll, ll>> cost;    // p, q, cost
  int min_cost = n;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ll p, q;
      p = B[j].first - B[i].first;
      q = B[j].second - B[i].second;
      if (cost.count({p, q})) continue;

      cost.insert({p, q});

      int zero_cost = 0;
      for (int k = 0; k < n; k++) {
        if (B_set.count({B[k].first - p, B[k].second - q})) zero_cost++;
      }

      min_cost = min(n - zero_cost, min_cost);
    }
  }

  cout << min_cost << endl;


  return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-


def main():
    s = input()
    c_count = 0
    s0 = s[0]

    for i in range(2, len(s) - 1):
        if s[i] == 'C':
            c_count += 1

    s = s.replace('A', '', 1)
    s = s.replace('C', '', 1)
    result = s.islower()

    if s0 == 'A' and c_count == 1 and result is True:
        print('AC')
    else:
        print('WA')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
#define G if(++ip==ie)if(fread(ip=ibuf,1,L,stdin))
const int L=1<<19;
char ibuf[L],*ie=ibuf+L,*ip=ie-1;
inline char nc(void){G;return *ip;}
inline int read(void){
	re char opt;re int flag=1,res=0;
	while((opt=getchar())<'0')if(opt=='-')flag=-1;
	while(opt>='0'){res=(res<<3)+(res<<1)+opt-'0';opt=getchar();}
	return res*flag;
}
int n,Case,ans;
inline int qmul(re int a,re int b,re int p){return ((1ll*a*b-(long long)((long double)a*b/p)*p+p)%p);}
inline int qpow(re int a,re int b,re int p){
	re int res=1;
	while(b){if(b&1)res=qmul(res,a,p);a=qmul(a,a,p);b>>=1;}
	return res;
}
inline int Phi(re int n){
	re int i,res=n;
	for(i=2;i*i<=n;++i)if(!(n%i)){while(!(n%i))n/=i;res=res/i*(i-1);}
	if(n>1)res=res/n*(n-1);
	return res;
}
signed main(void){
	re int i,phi;
	scanf("%lld",&n);
	n=9ll*n/__gcd(n,7ll);
	ans=(phi=Phi(n))+1;
	for(i=1;i*i<=phi;++i){
		if(phi%i)continue;
		if(qpow(10,i,n)==1)ans=min(ans,i);
		if(qpow(10,phi/i,n)==1)ans=min(ans,phi/i);
	}
	printf("%lld\n",(ans^(phi+1))?ans:-1);
	return 0;
}


Measured memory_bytes: 3752
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[107];
int main()
{
	gets(a);
	int n = strlen(a),b = -1;
	for(int i = 0;i < n;i++){
		if(a[i] == 'C'){
			b = i;
			break;
		}
	}
	if(b == -1){
		cout << "No";
		return 0;
	}
	for(int i = b;i < n;i++){
		if(a[i] == 'F'){
			cout << "Yes";
		    return 0;
		}
	}
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, n;
  in(n);
  vector<ll> t(n);
  rep(i, n)
    in(t[i]);
  a = 1;
  rep(i, n){
    b = __gcd(a, t[i]);
    a = a / b * t[i];
  }
  out(a);
  memi;
}


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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// #define MULTIPLE_TEST_CASES
void solve() {
  int d, t, s;
  cin >> d >> t >> s;

  cout << (t * s >= d ? "Yes" : "No") << endl;
}

signed main() {
  // freopen(".in", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 3600
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
// #define int ll
#define pll pair<ll, ll> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 998244353
using namespace std;

void dfs(vector<int> adj[], int sv, vector<bool> &vis){
	vis[sv] = true;
	for(int i = 0; i < adj[sv].size(); i++){
		if(!vis[adj[sv][i]]){
			dfs(adj, adj[sv][i], vis);
		}
	}
}
ll power(ll x, ll y){  
	if(x == 1 || y == 0)
		return 1;
    ll res = 1;   
    x = x % mod; 
    if (x == 0) 
		return 0;  
    while (y > 0){  
        if (y & 1)  
            res = (res * x) % mod;  
        y = y >> 1; 
        x = (x * x) % mod;  
    }  
    return res;  
} 

signed main(){
	FASTIO
	string s, t;
	cin >> s >> t;
	int ans = t.size();
	for(int i = 0; i + t.size() <= s.size(); i++){
		int c = 0;
		for(int j = 0; j < t.size(); j++){
			if(s[j+i] != t[j])
				c++;
		}
		ans = min(ans, c);
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <memory>

//#define int long long

using namespace std;

void Main()
{
	int n, x, y;
	cin >> n >> x >> y;

	// 1 <= i < i2 <= n
	// i -> i2
	// i -> x -> y ->i2
	// i -> y -> x ->i2
	vector<int> ans(n, 0);
	for (int i = 1; i <= n - 1; i++) {
		for (int i2 = i + 1; i2 <= n; i2++) {
			int dist1 = i2 - i;
			int dist2 = abs(x - i) + 1 + abs(y - i2);
			int dist3 = abs(y - i) + 1 + abs(x - i2);
			int dist = min(min(dist1, dist2), dist3);
			ans[dist]++;
		}
	}

	for (int i = 1; i <= n - 1; i++) {
		cout << ans[i] << endl;
	}
}

int32_t main()
{
	Main();
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    vector<string> b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    rep(i, n - m + 1) {
        rep(j, n - m + 1) {
            bool flag = true;
            repk(k, j, m + j) {
                if (a[k].substr(i, m) != b[k - j])
                    flag = false;
            }
            if (flag) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
A = tuple(range(10**5))

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)


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

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

ll gcd(ll a, ll b) {
	if (b == 0)return a;

	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> h(n);
	rep(i, n) cin >> h[i];
	sort(h.begin(), h.end());
	reverse(h.begin(), h.end());
	ll cnt = 0;
	for (int i = k; i < n; i++) {
		cnt += h[i];
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define lc (o << 1)
#define rc (o << 1 | 1)
#define mid ((l+r) >> 1)
using namespace std;
typedef pair<int,int> P;

const int maxn = 100009;
int T[maxn<<2], lazy[maxn<<2];
vector<P> q[maxn];
int n, m, cnt = 0, a, b, ans;

inline int read(){
	char ch = getchar(); int x = 0;
	while (ch < '0' || '9' < ch) ch = getchar(); 
	while ('0' <= ch && ch <= '9') { x = x*10+ch-'0'; ch = getchar(); }
	return x;
}

void pushdown(int o, int l, int r){
	if (!lazy[o]) return;
	T[lc] += lazy[o]*(mid-l+1);
	lazy[lc] += lazy[o];
	T[rc] += lazy[o]*(r-mid);
	lazy[rc] += lazy[o];
	lazy[o] = 0;
}

int query(int o, int l, int r, int x){
	if (l == r) return T[o];
	pushdown(o, l, r);
	if (x <= mid) return query(lc, l, mid, x);
	return query(rc, mid+1, r, x);
}

void update(int o, int l, int r, int x, int y){
	if (l == x && y == r){
		T[o] += r-l+1;
		lazy[o]++;
		return;
	}
	pushdown(o, l, r);
	if (x <= mid) update(lc, l, mid, x, min(y, mid));
	if (mid+1 <= y) update(rc, mid+1, r, max(x, mid+1), y);
}

int main(){
	n = read(); m = read();
	for (int i=1; i<=n; i++){
		a = read(); b = read();
		q[b-a+1].push_back(make_pair(a, b));
	}
	for (int i=1; i<=m; i++){
		ans = n-cnt;
		for (int j=i; j<=m; j+=i)
			ans += query(1, 1, m, j);
		printf("%d\n", ans);
		for (int j=q[i].size()-1; j>=0; j--){
			P t = q[i][j];  cnt++;
			update(1, 1, m, t.first, t.second);
		}
	}
	return 0;
}

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

int main(){
  int X,N;
  cin>>X>>N;
  set<int> p;
  for(int i=0;i<N;i++){
    int j;
    cin>>j;
    p.insert(j);
  }
  for(int i=0;i<100;i++){
    if(!(p.count(X-i))){
      cout<<X-i<<endl;
      return 0;
    }else if(!(p.count(X+i))){
      cout<<X+i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int N;
    cin >> N;
    long long h[N];
    int x[N],y[N];
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i] >> h[i];
    }
    for(int i=0; i<N; i++){
        if(h[i]!=0){
            swap(h[0],h[i]);
            swap(x[0],x[i]);
            swap(y[0],y[i]);
            break;
        }
    }
    for(int i=0; i<101; i++){
        for(int j=0; j<101; j++){
            bool judge = true;
            long long height = h[0] + abs(i-x[0]) + abs(j-y[0]);
            for(int k=1; k<N; k++){
                long long t = h[k] + abs(i-x[k]) + abs(j-y[k]);
                if(h[k] == 0 && t < height){
                    judge = false;
                    break;
                }
                if(h[k] != 0 && t != height){
                    judge = false;
                    break;
                }
            }
            if(judge){
                cout << i << ' ' << j << ' ' << height << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
AB=[]
for _ in range(N):
  AB.append([int(x) for x in input().split()])
AB.sort(key=lambda x:x[1])

sum = 0
for a,b in AB:
  sum+=a
  if sum>b:
    print("No")
    break
else:
  print("Yes")

Measured memory_bytes: 88104
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for(int i=0; i<n; i++) {
            int[] it = new int[3];
            it[0] = scanner.nextInt();
            it[1] = scanner.nextInt();
            it[2] = scanner.nextInt();
            Arrays.sort(it);
            if(it[0]*it[0] + it[1]*it[1] == it[2]*it[2]) {
                System.out.println("YES");
            }else {
                System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 33512
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n = int(readline())
s = read().rstrip().decode('utf-8')

a = s.count('AC')
b = s.count('WA')
c = s.count('TLE')
d = s.count('RE')

print("AC x {}".format(a))
print("WA x {}".format(b))
print("TLE x {}".format(c))
print("RE x {}".format(d))


Measured memory_bytes: 9768
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main(){
      
  fastio();
  double T,X;
  cin>>T>>X;
  printf("%.10f",(T/X));
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int X; cin >> X;
  if(X == 1){
    cout << 1 << endl;
    return 0;
  }
  int ma = 0;
  for(int i = 2; i <= X; i++){
    int j;
    for(j = i * i; j <= X; j *= i);
    ma = max(ma, (j / i == i ? -1 : j / i));
  }
  cout << ma << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Dice
    {
        private int[] dicelabel = new int[6];
        private int temp = 0;

        public Dice(string s)//??????????????°????????±???????????????????????????
        {
            var dicenum = s.Split(' ');
            for (int i = 0; i < 6; i++)
            {
                dicelabel[i] = int.Parse(dicenum[i]);
            }
        }

        public void roll(string order)
        {
            for (int i = 0; i < order.Length; i++)
            {
                switch (order[i])
                {
                    case 'N':
                        temp = dicelabel[0];
                        dicelabel[0] = dicelabel[1];
                        dicelabel[1] = dicelabel[5];
                        dicelabel[5] = dicelabel[4];
                        dicelabel[4] = temp;

                        break;
                    case 'S':
                        temp = dicelabel[0];
                        dicelabel[0] = dicelabel[4];
                        dicelabel[4] = dicelabel[5];
                        dicelabel[5] = dicelabel[1];
                        dicelabel[1] = temp;

                        break;
                    case 'E':
                        temp = dicelabel[0];
                        dicelabel[0] = dicelabel[3];
                        dicelabel[3] = dicelabel[5];
                        dicelabel[5] = dicelabel[2];
                        dicelabel[2] = temp;

                        break;
                    case 'W':
                        temp = dicelabel[0];
                        dicelabel[0] = dicelabel[2];
                        dicelabel[2] = dicelabel[5];
                        dicelabel[5] = dicelabel[3];
                        dicelabel[3] = temp;

                        break;
                }
            }
        }

        public int[] getLabel()
        {
            return dicelabel;
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            Dice d = new Dice(input);
            string order = Console.ReadLine();
            d.roll(order);
            int[] answer = d.getLabel();
            Console.WriteLine(answer[0]);
        }
    }
}

Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int main(){
	while (cin>>s){
		int ans=0;
		int flag=0;
		if (s[0]=='B') flag=0;
		else flag=1;
		for (int i=1;s[i];i++){
			if (s[i]=='B' && flag==1){
				ans++;
				flag=0;
			}
			if (s[i]=='W' && flag==0){
				ans++;
				flag=1;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
import collections

n = int(input())
ss = [tuple(sorted(collections.Counter(input()).items())) for i in range(n)]

s_dict = dict()

for s in ss:
  if s not in s_dict:
    s_dict[s] = 1
  else:
    s_dict[s] += 1

count = 0 
for i in s_dict.values():
  count += (i * (i - 1)) // 2
    

print(count)

Measured memory_bytes: 78536
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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




// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int N;
    cin>>N;
    int K;
    cin>>K;
    std::vector<int> p(N);
    for(int i = 0 ; i < N ; i++){
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    long long ans=0;
    rep(i,K){
        ans+=p[i];
    }
    cout<<ans<<endl;

    
    return 0;
}


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

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

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

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_N = 110;
const int MAX_V = 100100;

int N, W;

ll weight[MAX_N];
ll value[MAX_N];
ll dp[MAX_N][MAX_V];

int main() {
  cin >> N >> W;
  for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

  for (int i = 0; i < MAX_N; ++i)
    for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;
  
  dp[0][0] = 0;
  for (int i = 0; i < N; ++i) {
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
      if (sum_v - value[i] >= 0)
        chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
      chmin(dp[i + 1][sum_v], dp[i][sum_v]);
    }
  }

  ll res = 0;
  for (int sum_v = 0; sum_v < MAX_V; ++sum_v)
    if (dp[N][sum_v] <= W) res = sum_v;

  cout << res << endl;
}

Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  int a = 0;
  cin >> str;
  for (int i = 0; i < str.size(); i++){
    if (str[i] == '1'){
      a++;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

long long int getMaximumWeight(long long int weightArray[], long long int valuesArray[], long long int totalItems, long long int maxWeight)
{
    long long int dpArray[totalItems+1][maxWeight+1];
    for(long long int i = 0 ; i <= totalItems ; i++)
    {
        for(long long int j = 0 ; j <= maxWeight ; j++)
        {
            dpArray[i][j] = 0;
        }
    }
    
    for(long long int i = 1 ; i <= totalItems ; i++)
    {
        for(long long int j = 0 ; j <= maxWeight ; j++)
        {
            long long int possibleValue = j >= weightArray[i-1] ? valuesArray[i-1] + dpArray[i-1][j-weightArray[i-1]] : 0;
            dpArray[i][j]               = max(dpArray[i-1][j], possibleValue);
        }
    }
    return dpArray[totalItems][maxWeight];
}

int main(int argc, const char * argv[])
{
    long long int totalItems;
    long long int maxWeight;
    cin>>totalItems>>maxWeight;
    long long int weightArray[totalItems];
    long long int valuesArray[totalItems];
    for(long long int i = 0 ; i < totalItems ; i++)
    {
        cin>>weightArray[i]>>valuesArray[i];
    }
    cout<<getMaximumWeight(weightArray, valuesArray, totalItems, maxWeight)<<endl;
    return 0;
}


Measured memory_bytes: 79104
import itertools

n, m = map(int, input().split())
lis = []
for i in range(m):
    a, b = map(int, input().split())
    lis.append((a, b))

LIS = [i for i in range(2, n + 1)]
big_lis = list(itertools.permutations(LIS))
L = len(big_lis)

ans2 = 0
for j in range(L):
    i = 1
    ans1 = 1
    for k in big_lis[j]:
        if((i, k) not in lis) & ((k, i) not in lis):
            ans1 = 0
        i = k
    ans2 += ans1
print(ans2)


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


using namespace std;


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

  vector<int> A(N);
  for (int i=0;i<N;i++) {
    int a;
    cin >> a;
    A[a-1] = i+1;
  }

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

  return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[210000];
int d[11][11];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<b;i++)for(int j=0;j<a;j++)scanf("%d",&d[i][j]);
	
	int now=c;
	for(int i=0;i<b-1;i++){
		for(int j=0;j<210000;j++)dp[j]=-99999999;
		dp[0]=0;
		int to=now;
	
		for(int k=0;k<a;k++){
			for(int j=0;j<=now;j++){
				dp[j+d[i][k]]=max(dp[j+d[i][k]],dp[j]+d[i+1][k]);
			}
		}
		for(int j=0;j<=now;j++)to=max(to,dp[j]+now-j);
		now=to;
	}
	printf("%d\n",now);
}

Measured memory_bytes: 1852