akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
#define Rep(i, j, k) for(R int i = (j); i >= (int) (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 211;
const ll INF = 5e16;
const ll P = 1e9 + 7;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x), putchar(' '); }

	inline void wln ( ll x ) { write(x), putchar('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	/*
		最小的用掉后答案就不会变了。 
		设 f[i][0/1] 表示做了 i 次， 
		最小的被用掉/没被用掉的答案。 

		枚举 s[n] 在什么时候被用掉。 
		对于每个 pos, 其他有 (n - 1)! 种排列 
		方式。 
		但只有前 pos - 1 个会对答案造成贡献， 
		所以考虑怎么选择这前 pos - 1 个。 
		每次操作就是把 X % s[i] 
		
		前面的思路都是对的！就是不会设计状态了。 
		
		设 f[i][j] 表示做了 i 次，当前数为 j 。 
		f[i][j % a[i]] = f[i - 1][j] * (n - i + 1)
	*/
	
	const ll M = 100011;
	
	ll n, X, Ans, s[N], f[N][M];
	
	inline void Add ( ll &a, ll b ) { (a += b) >= P && (a -= P); }
	
	int main() {
		n = read(), X = read();
		For ( i, 1, n ) s[i] = read();
		sort(s + 1, s + n + 1, greater <ll> ());
		
		f[0][X] = 1;
		For ( i, 1, n ) For ( j, 0, X ) 
			(f[i][j % s[i]] += f[i - 1][j]) %= P,
			(f[i][j] += f[i - 1][j] * (n - i)) %= P;
		For ( i, 1, X ) Add(Ans, f[n][i] * i % P);
		return wln(Ans), 0;
	}
	
}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	return Cesare :: main();
}

/*

*/






Measured memory_bytes: 157184
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int i,ns=0,nt=0,res;
  string s;
  cin >> s;
  for(i=0;i<s.size();i++)
    if(s[i]=='S'){
      ns++;
    }else{
      if(ns>0)
        ns--;
      else
        nt++;
    }
  res=ns+nt;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 640
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
fact_l=[1]*(N+10)
mod = 10**9+7
for i in range(2,N+1):
  fact_l[i]=(fact_l[i-1]*i)%mod
  
fact_inv_l = [1]*(N+10)
for i in range(2,N+1):
  fact_inv_l[i]=pow(fact_l[i],mod-2,mod)
ans = 0
for i in range(1,N-K+2):
  b = N-i
  c = K-1
  ans -= A[i-1]*fact_l[b]%mod*fact_inv_l[b-c]%mod*fact_inv_l[c]%mod
  ans += A[-i]*fact_l[b]%mod*fact_inv_l[b-c]%mod*fact_inv_l[c]%mod
    
print(ans%mod)


Measured memory_bytes: 63344
#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef   long long int ll;
using namespace std;
const int N=1e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
ll n,m;
vector<ll> adj[N];
ll cnt[N];
ll ans;
ll dfs(ll u)
{
    ll &g=cnt[u];
    if(g!=-1)
    return g;
    g=0;
    for(auto f : adj[u])
    {
        g=max(g,dfs(f)+1);
    }
    return g;
}
int main()
{
   cin>>n>>m;
   for(ll i=1;i<=n;++i)
   cnt[i]=-1;
   for(ll i=0;i<m;++i)
   {
       ll u,v;cin>>u>>v;
       adj[u].pb(v);
       //adj[v].pb(u);
   }
   for(ll i=1;i<=n;++i)
   {
       if(cnt[i]==-1)
       {
           ans=max(ans,dfs(i));
       }
   }
   //cout<<endl;
   //for(ll i=1;i<=n;++i)
   //cout<<cnt[i]<<" ";
   cout<<ans;
}

Measured memory_bytes: 11700
N = gets.to_i
AS = gets.chomp.split.map(&:to_i)

MAX = 10**5 + 1
m = Array.new(MAX, 0)
minus = 0

AS.each do |a|
  m[a] += 1
  m[a+1] += 1
  if a - 1 < 0
    minus += 1
  else
    m[a-1] += 1
  end
end

p [m.max, minus].max

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

vector<string> make(string s)
{
    vector<string> v{""};
    for(char c:s)
    {
        if(c=='\"')
        {
            v.push_back("");
        }
        else
        {
            v.back()+=c;
        }
    }
    return v;
}

const string dif="DIFFERENT",ide="IDENTICAL",clo="CLOSE";

main()
{
    string s1,s2;
    while(cin>>s1>>s2)
    {
        if(s1==".") break;
        vector<string> v1=make(s1),v2=make(s2);
        if(v1.size()!=v2.size()) cout<<dif<<endl;
        else
        {
            int n=v1.size();
            int err=0;
            for(int i=0;i<n;i++)
            {
                if(v1[i]!=v2[i])
                {
                    if(~i&1) err++;
                    err++;
                }
            }
            if(err>1) cout<<dif<<endl;
            else if(err==1) cout<<clo<<endl;
            else cout<<ide<<endl;
        }
    }
}



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

int main() {
  int L, L_, N, M, R;
  cin >> L;
  
  N = 0;
  M = -2;
  L_ = L;
  
  while(L_!=0) {
    N++;
    M += 2;
    L_ /= 2;
  }
  
  R = L-pow(2,N-1);
  for(int i=0; i<N; i++) {
    if (R & (1<<i)) {
      M++;
    }
  }
  
  cout << N << " " << M << endl;
  
  for(int i=0; i<N-1; i++) {
    cout << i+1 << " " << i+2 << " " << 0 << endl;
    cout << i+1 << " " << i+2 << " " << pow(2,i) << endl;
  }
  
  int res = pow(2,N-1);
  for(int i=N-1; i>=0; i--) {
    if (R & (1<<i)) {
      cout << i+1 << " " << N << " " << res << endl;
      res = res + pow(2,i);
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.array, std.algorithm;

void main()
{
    auto abc = readln.chomp.split(" ").map!(to!int);

    writeln(
        abc.count!"a==5" == 2 && abc.count!"a==7" == 1 ? "YES" : "NO"
    );
}

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

bool rangeCheck(ll y, ll x, ll h, ll w) {
  if (y < 0 || x < 0 || y >= h || x >= w) {
    return false;
  } else {
    return true;
  }
}

void outputDone(ll h, ll w, vector<vector<ll>> a) {
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      printf("%3d", a[i][j]);
    }
    cout << endl;
  }
  return;
}

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (ll i = 0; i < h; i++) {
    cin >> s[i];
  }

  ll ans = 0;
  vector<vector<ll>> done(h, vector<ll>(w, -1));
  stack<pair<ll, ll>> st;
  ll dirY[] = {1, 0, -1, 0};
  ll dirX[] = {0, 1, 0, -1};
  ll cnt = 0;
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (s[i][j] == '.' || done[i][j] != -1) {
        continue;
      }
      ll blackCnt = 0, whiteCnt = 0;
      bool flag;
      pair<ll, ll> xy;
      xy.first = i;
      xy.second = j;
      st.push(xy);
      while (!st.empty()) {
        xy = st.top();
        st.pop();
        //printf("y=%d x=%d\n",xy.first,xy.second);
        if (done[xy.first][xy.second] != -1) {
          continue;
        }
        if (s[xy.first][xy.second] == '#') {
          flag = false;
        } else {
          flag = true;
        }
        flag ? whiteCnt++ : blackCnt++;
        done[xy.first][xy.second] = cnt;
        for (ll k = 0; k < 4; k++) {
          ll ny = xy.first + dirY[k];
          ll nx = xy.second + dirX[k];
          bool flag2;

          if (!rangeCheck(ny, nx, h, w)) {
            continue;
          }
          if (done[ny][nx] != -1) {
            continue;
          }
          if (s[ny][nx] == '#') {
            flag2 = false;
          } else {
            flag2 = true;
          }
          if (flag == flag2) {
            continue;
          }
          pair<ll, ll> temp;
          temp.first = ny;
          temp.second = nx;
          st.push(temp);
        }
      }
      cnt++;
      ans += blackCnt * whiteCnt;
    }
  }
  // outputDone(h,w,done);
  cout << ans << endl;
  return 0;
}

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

int main() {
  int W,H,x,y;
  cin >> W >> H >> x >> y;
  
  int ans = 0;
  if((x == W / 2.0) && (y == H / 2.0)) ans = 1;
  
  cout << (double)W * H / 2.0 << " " << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

#include<ctime>
#include <random>
#include <limits>

using namespace std;

// #define int __int128
#define int long long
#define endl "\n"

int  power(int  x, int  n, int mod){
	int  ans = 1;
	while(n){
		if(n&1) ans *= x;
		n >>= 1;
		x *= x;
		x %= mod;
		ans %= mod;
	}
	return ans;
}

bool Miller_Rabin(int num){
	if(num <= 1)        return false;
	else if(num == 2)   return true;
	else if(num%2 == 0) return false; 
	else if(num == 3) return true;
	else if(num%3 == 0) return false;
	int  s = 0, d = 0;
	
	for(int n = num-1;;){
		if(n%2){ 
			d = n; break;
		} else s++, n >>= 1;
	}
	
	for(int  i = 2; i <= 7; i += 2){
		if(i >= num) break;
		int  a = i, n = d, a2 = 1;
		bool flag = true;
		
		a2 = power(a, d, num);
		
		if(a2 == 1) continue;
		
		for(int r = 0, two = 1; r < s; r++, two <<= 1){
			a2 = power(a, two*d, num);
			
			if(a2 == num-1){
				flag = false;
				break;
			}
		}
		
		if(flag) return false;
		if(i == 2) i--;
	}
	
	return true;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	long long x, n, con = 0;
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>x;
		if(Miller_Rabin(x)) con++;
	}
	
	cout<<con<<endl;
	
	return 0;
}


Measured memory_bytes: 3200
#include <iostream>

using namespace std;

int main()
{
	int n;

	cin >> n;

	int *L = new int[n];

	int sum = 0;
	int max = 0;

	for (int i = 0; i < n; i++) {
		cin >> L[i];
		if (max < L[i]) {
			sum += max;
			max = L[i];
		}
		else {
			sum += L[i];
		}
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
const ll MOD = 1e9;

int main(){
  ll k,t;
  cin>>k>>t;
  ll ma=0;
  for(int i=0;i<t;i++){
	ll a;
	cin>>a;
	ma=max(ma,a);
  }
  cout<<max(0LL,ma-(k-ma)-1)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <list>
#include <vector>
typedef long long ll;
typedef long double ld;

using namespace std;

void solve(long long A, long long B, long long C){
    if(!(A%2 && B%2 && C%2)){
        printf("%d", 0);
        return;
    }

    vector<ll> v = {A, B, C};
    sort(v.begin(), v.end());
    printf("%lld", v[0]*v[1] );
}

int main(){

    //FILE* fp_in = freopen("/Users/kokinakamura/atcoder-workspace/agc004/A/in_3.txt", "r", stdin);

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);

    return 0;
}

Measured memory_bytes: 256
D,G = map(int, raw_input().split())
p = [0]*D
c = [0]*D
for i in range(D):
  p[i],c[i] = map(int, raw_input().split())

ans = sum(p)
for b in range(1<<D):
  s = 0
  a = 0
  for i in range(D):
    if b>>i&1:
      s += p[i]*(i+1)*100 + c[i]
      a += p[i]
  for i in range(D)[::-1]:
    if not b>>i&1:
      if s>=G:
        break
      t = min(p[i], (G-s+(i+1)*100-1)/((i+1)*100))
      s += t*(i+1)*100
      a += t
  ans = min(ans, a)
print ans


Measured memory_bytes: 2696
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=[0]+a
vis={}
cnt=0
cur=1
total=0
while True:
    if cur in vis:
        break
    vis[cur]=True
    cur=a[cur]
    total += 1
vis = {}
cycle=0
while True:
    if cur in vis:
        break
    vis[cur]=True
    cur=a[cur]
    cycle += 1
if k>total:
    k -= (total-cycle)
    k=k%cycle
    while k>0:
        cur=a[cur]
        k -= 1
    print(cur
    )
else:
    cur=1
    while k>0:
        cur=a[cur]
        k -= 1
    print(cur)

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

int main() {
    int N; cin >> N;
    using P = pair<int64, int64>;
    priority_queue<P, vector<P>, greater<P>> que;
    rep(i, N) {
        int64 X, L;
        cin >> X >> L;
        que.emplace(X + L, X - L);
    }
    int64 ans = 0, t = -12345678900;
    while(!que.empty()) {
        int64 e, s;
        tie(e, s) = que.top();
        que.pop();
        if(s >= t) {
            t = e;
            ++ans;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 2420
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[h,w]=i2()
a=""
for i in range(h):
    a+=input()
from collections import Counter
c=Counter(list(a))
c=list(c.values())
b2=0
b4=0
b1=0
if h%2==1 and w%2==0:
 b2=w//2
if w%2==1 and h%2==0:
 b2=h//2
if w%2==1 and h%2==1:
 b1=1
 b2=w//2+h//2
s="Yes"
b4=(h*w-b2*2)//4
for i in c:
    if i%4==0:
     if b4-i//4>=0:
        b4-=i//4
     elif b2-(i-4*b4)//2>=0:
        b2-=(i-4*b4)//2
        b4=0
     else:
        s="No"
    elif i%2==0:
      if i>=4:
          if b4-i//4>=0:
             b4-=i//4
             if b2-i%4//2>=0:
                 b2-=i%4//2
             else:
                 s="No"
          elif b2-i//2>=0:
             b2-=i//2
          else:
             s="No"
      elif i==2 and b2>=1:
          b2-=1
      else:
          s="No"
    else:
        if b1==1:
          b1=0
          t=i-1
          if t>0:
            if t%4==0:
             if b4-t//4>=0:
                b4-=t//4
             elif b2-(t-b4*4)//2>=0:
                t-=4*b4
                b4=0
                b2-=t//2
             else:
                s="No"
            elif t%2==0:
              if t>=4:
                  if b4-t//4>=0:
                     b4-=t//4
                     if b2-t%4//2>=0:
                         b2-=t%4//2
                     else:
                         s="No"
                  elif b2-(t-b4*4)//2>=0:
                     t-=4*b4
                     b4=0
                     b2-=t//2
                  else:
                     s="No"
              elif t==2 and b2>=1:
                  b2-=1
              else:
                  s="No"

        else:
           s="No"
print(s)


Measured memory_bytes: 38916
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, c, k;
    cin >> n >> c >> k;
    vi t(n);
    rep(i, n) cin >> t[i];

    sort(t.begin(), t.end());
    int ans = 0;
    int passenger = 0;
    int time = 0;
    rep(i, n) {
        if (i == 0) {
            time = t[i];
            passenger++;
            ans++;
        } else {
            if (t[i] <= time + k && passenger + 1 <= c) {
                passenger++;
            } else {
                time = t[i]; 
                passenger = 1;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

void solve(void){
  int A, B;
  cin >> A >> B;
  if(max(A, B) > 8) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}

int main(void){
  solve();
  return 0;
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	An := make(map[int]int)
	var sum int
	for i := 0; i < N; i++ {
		A := nextInt()
		An[A]++
		sum += A
	}
	// fmt.Println(An, sum)
	Q := nextInt()
	for i := 0; i < Q; i++ {
		B, C := nextInt(), nextInt()
		nums := An[B]
		sum += (C - B) * nums
		An[C] += An[B]
		An[B] = 0
		fmt.Println(sum)
	}
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 9748
#include <cassert>
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

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

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

const int MOD = 100 * 1000 * 1000 + 7;

ll dp[2001][2001];

ll comb(int n, int k) {
    assert(n >= k);
    assert(n > 0);

    if (dp[n][k] > 0) {
        return dp[n][k];
    } else if (k == 1) {
        return n;
    } else if (k == 0) {
        return 1;
    } else if (n == k) {
        return 1;
    }

    dp[n][k] = (comb(n - 1, k - 1) + comb(n - 1, k)) % MOD;
    return dp[n][k];
}

int main(void) {
    int r, c, a1, a2, b1, b2;
    cin >> r >> c >> a1 >> a2 >> b1 >> b2;

    int m = min(abs(b1 - a1), r - abs(b1 - a1));
    int n = min(abs(b2 - a2), c - abs(b2 - a2));

    ll answer = comb(m + n, m);
    if (r % 2 == 0 && m == r / 2) {
        answer = 2 * answer % MOD;
    }
    if (c % 2 == 0 && n == c / 2) {
        answer = 2 * answer % MOD;
    }
    cout << answer << endl;
    
    return 0;
}



Measured memory_bytes: 9088
#include<iostream>
#include<algorithm>

using namespace std;


int main() {
	int x;
	cin >> x;

	int ans = 1;

	for (int i = 2; i <= x;i++){
		if (i * i > x) {
			break;
		}

		int num = i;

		while (num*i <= x) {
			num *= i;
		}
		 
		ans = max(ans, num);

	}

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




Measured memory_bytes: 636
N,W = map(int,input().split())
array = []
for i in range(N):
    wv = list(map(int,input().split()))
    array.append(wv)
dp = [[0 for i in range(W+1)] for j in range(N+1)]
for i in range(N):
    for j in range(W+1):
        if j-array[i][0] >= 0:
            dp[i+1][j] = max(dp[i][j],dp[i][j-array[i][0]]+array[i][1])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[-1][-1])

Measured memory_bytes: 171572
#include<bits/stdc++.h>
using namespace std ;
 
class dice
{
public:
  int number[6] ;
  void x_axis()
  {
    int cmp = number[0] ;
    number[0] = number[1] ;
    number[1] = number[5] ;
    number[5] = number[4] ;
    number[4] = cmp ;
  }
  void y_axis()
  {
    int cmp = number[1] ;
    number[1] = number[2] ;
    number[2] = number[4] ;
    number[4] = number[3] ;
    number[3] = cmp ;
  }
  void z_axis()
  {
    int cmp = number[0] ;
    number[0] = number[2] ;
    number[2] = number[5] ;
    number[5] = number[3] ;
    number[3] = cmp ;
  }
};
dice d[100] ;
 
class check
{
public:
  bool all( int a,int b )
  {
    int Count = 0 ;
    for ( int i = 0 ; i < 6 ; i++ )
    {
      if ( d[a].number[i] == d[b].number[i] ) Count++ ;
    }
    if ( Count == 6 ) return true ;
    return false ;
  }
  bool x_axis( int a,int b )
  {
    int Count = 0 ;
    if ( d[a].number[0] == d[b].number[0] ) Count++ ;
    if ( d[a].number[1] == d[b].number[1] ) Count++ ;
    if ( d[a].number[4] == d[b].number[4] ) Count++ ;
    if ( d[a].number[5] == d[b].number[5] ) Count++ ;
    if ( Count == 4 ) return true ;
    return false ;
  }
  bool y_axis( int a,int b )
  {
    int Count = 0 ;
    if ( d[a].number[1] == d[b].number[1] ) Count++ ;
    if ( d[a].number[2] == d[b].number[2] ) Count++ ;
    if ( d[a].number[3] == d[b].number[3] ) Count++ ;
    if ( d[a].number[4] == d[b].number[4] ) Count++ ;
    if ( Count == 4 ) return true ;
    return false ;
  }
  bool z_axis( int a,int b )
  {
    int Count = 0 ;
    if ( d[a].number[0] == d[b].number[0] ) Count++ ;
    if ( d[a].number[2] == d[b].number[2] ) Count++ ;
    if ( d[a].number[3] == d[b].number[3] ) Count++ ;
    if ( d[a].number[5] == d[b].number[5] ) Count++ ;
    if ( Count == 4 ) return true ;
    return false ;
  }
};
 
check check ;
int n ;
bool flg ;
 
int main()
{
  cin >> n ;
  for ( int i = 0 ; i < n ; i++ )
  {
    for ( int j = 0 ; j < 6 ; j++ )
    {
      cin >> d[i].number[j] ;
    }
  }
  for ( int i = 1 ; i < n ; i++ )
  {
    for ( int j = 0 ; j < 50 ; j++ )
    {
      if ( check.all(0,i) )
      {
        flg = true ;
        break ;
      }
      for ( int k = 0 ; k < 36 ; k++ )
      {
        if ( check.x_axis(0,i) ) break ;
        if ( k == 3  || k == 7  || k == 11 || k == 15 ) d[i].y_axis() ;
        if ( k == 19 || k == 23 || k == 27 || k == 31 ) d[i].z_axis() ;
        d[i].x_axis() ;
      }
      for ( int k = 0 ; k < 50 ; k++ )
      {
        if ( check.y_axis(0,i) ) break ;
        d[i].y_axis() ;
      }
      for ( int k = 0 ; k < 50 ; k++ )
      {
        if ( check.z_axis(0,i) ) break ;
        d[i].z_axis() ;
      }
    }
    if ( flg ) break ;
  }
  if ( !flg ) puts("Yes") ;
  else puts("No") ;
  return 0 ;
}



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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	string s;
	cin >> s;
	cin >> s;

	cout << "A" << s[0] << "C" << endl;
	
	return 0;
}


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

int main()
{
  int n;
  long long MAX = 200000;
  cin >> n;
  vector<int> a(n);
  vector<int> b;
  vector<int> c;

  for (int i = 0; i < n; i++)
  {
    cin >> a.at(i);
  }

  for (int i = 0; i < n; i++)
  {
    if (i % 2 == 0)
    {
      b.insert(b.begin(), a.at(i));
    }
    else
    {
      b.push_back(a.at(i));
    }
  }
  if (b.size() > 1 && b.size() % 2 == 0)
  {
    reverse(b.begin(), b.end());
  }

  for (int i = 0; i < n; i++)
  {
    if (i)
    {
      cout << " ";
    }
    cout << b.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 5064
box = Array.new(3)
box[0], box[1], box[2], n = gets.split.map(&:to_i)
count = 0
box.sort.reverse!


for i in 0..(n/box[0])
  for j in 0..((n-box[0]*i)/box[1])
    count += 1 if (n - box[0]*i - box[1]*j) % box[2] == 0
  end
end

puts count

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    cout << n / 2 + n % 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1e18;
void chmin(int &a,int b){
    if( a > b) a = b;
}
signed main(){
    int n;cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    vector<int> dp(n+1,INF);
    dp[1] = 0;
    for(int i = 1;i <= n;i++){
        if(i+2 < n+1)chmin(dp[i+2],dp[i] + abs(a[i+1] - a[i-1]));
        if(i+1 < n+1)chmin(dp[i+1],dp[i] + abs(a[i] - a[i-1]));
    }
    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 4844
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

    int N = S.size();
    long long ans = 0;
    long long count_B = 0;
    for (int i=0; i<N; i++) {
        if(S[i]=='B'){
            count_B++;
            //if(S[i+1]=='W'){
                //S[i+1-count_B]='W';
                //S[i+1]='B';
                //ans+=count_B;
                //i++;
            }
             else{
                 ans+=count_B;
            }
        //}
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)



int field[100000];

int root(int x) {
	if (field[x] == x) {
		return x;
	}
	else {
		return field[x] = root(field[x]);
	}
}

bool isame(int x, int y) {
	return root(x) == root(y);
}

void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y) return;

	field[x] = y;
}


int main() {

	int n, m;
	cin >> n >> m;
	VI p(n);
	REP(i, n) {
		int t;
		cin >> t;
		p[i] = t - 1;
	}
	
	REP(i, n) {
		field[i] = i;
	}

	REP(i, m) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		unite(x, y);
	}

	int ans = 0;
	REP(i, n) {
		if (isame(i, p[i])==true) {
			ans++;
		}
	}
	ANS(ans);

	return 0;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define   ll  long long
ll wt[105],val[105],dp[105][100005];
int main()
{
    ll i,j,n,w,v=0,mx=0;
    cin>>n>>w;
    for(i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
        v+=val[i];
    }
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=v;j++)
        {
            dp[i][j]=1e14;
        }
    }
    dp[0][0]=0;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=v;j++)
        {
            if(j-val[i-1]>=0)
            {
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-val[i-1]]+wt[i-1]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    for(i=0;i<=v;i++)
    {
        if(dp[n][i]<=w)
        {
            mx=i;
        }
    }
    cout<<mx<<"\n";
    return 0;
}



Measured memory_bytes: 80128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	char a[10000];
	f(i, 10000)a[i] = 0;
	int z[10000];
	vector<int>xs;
	vector<int>ys;
	int sx = 0;
	int sy = 0;
	int k;
	int n, m;	bool v = true;
	int x, y;
	int ans = 0;

	scanf("%s", a);
	n = strlen(a);

	scanf("%d %d", &x,&y);

	k = 0;
	m = 0;
	f(i, n){
		if (a[i] == 'T'){
			if (m == 0){
				xs.push_back(k);
				sx += k;
			}
			else{
				ys.push_back(k);
				sy += k;
			}
          m=(m+1)%2;
		k=0;
		}
		else{
			k++;
			if (i == n - 1){
				if (m == 0){
					xs.push_back(k);
					sx += k;
				}
				else{
					ys.push_back(k);
					sy += k;
				}
			}
		}
	}
	if (sx >= x && (sx - x) % 2 == 0)x = (sx - x) / 2;
	else v = false;
	if (sy >= y && (sy - y) % 2 == 0)y = (sy - y) / 2;
	else v = false;

	f(i, 10000)z[i] = 0;
	z[0] = 1;
	f(i,xs.size()-1){
		for (int j = 8000; j >= 0; j--){
			if (z[j] >0 && j + xs[i+1] <= 8000)z[j + xs[i+1]] = 1;
		}
	}
	if (z[x] == 0)v = false;

	f(i, 10000)z[i] = 0;
	z[0] = 1;
	f(i, ys.size()){
		for (int j = 8000; j >= 0; j--){
			if (z[j] >0 && j + ys[i] <= 8000)z[j + ys[i]] = 1;
		}
	}
	if (z[y] == 0)v = false;

	if (v)printf("Yes\n");
	else printf("No\n");

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF (int)1e9
#define MOD (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n,a,b;
	cin>>n>>a>>b;
	
	cout<<min(n*a,b)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  int b[102];
  for (int i = 1; i <= N; i ++) {
    cin >> b[i];
    if (b[i] > i) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int ans[101];
  for (int i = N; i > 0; i --) {
    for (int j = i; j > 0; j --) {
      if (b[j] == j) {
        ans[i] = j;
        for (int k = j; k < i; k ++) b[k] = b[k + 1];
        break;
      }
    }
  }
  for (int i = 1; i <= N; i ++) cout << ans[i] << endl;
}
  

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

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<D> l = new ArrayList<>();
        for(int i=0; i<n; i++) {
            long p = sc.nextLong();
            int num = sc.nextInt();
            l.add(new D(num, p));
        }
        Collections.sort(l);
        long res = 0;
        for(D d : l) {
            if(m > d.num) {
                res += d.num * d.p;
                m -= d.num;
            } else {
                res += m * d.p;
                break;
            }
        }
        System.out.println(res);

    }

    static class D implements Comparable<D> {
        int num;
        long p;
        D(int num, long p) {
            this.num = num;
            this.p = p;
        }

        @Override public int compareTo(D o) {
            if(p<o.p) return -1;
            if(p>o.p) return 1;
            return 0;
        }
    }
}


Measured memory_bytes: 81092
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int k,s,ans = 0;
	scanf("%d %d",&k,&s);
	for(int x=0;x<=k;x++){
		for(int y=0;y<=k;y++){
			int z = s - x - y;
			if(z>=0&&z<=k) ans++;
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) ;
#endif


typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)((x).size())
#define pb push_back
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
//#define debug(x) cerr << #x << " : " << (x) << " "
const double PI = 3.14159265358979323846;
const double eps = (1e-8);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MOD = 998244353;
int mult(int x, int y)
{
    return (1LL * x * y)%MOD;
}

int power(int base, int exp)
{
    int ret = 1;
    for (; exp; exp >>= 1, base = mult(base, base))
        if (exp&1)
            ret = mult(ret, base);
    return ret;
}

int add(int x, int y)
{
    x += y;
    if (x >= MOD)
        x -= MOD;
    return x;
}

int modInverse(int x)
{
    return power(x, MOD - 2);
}

int Divide(int x, int y)
{
    return mult(x, modInverse(y));
}

const int MAX_N = 3005;
int a[MAX_N], n, s;
int mem[MAX_N][MAX_N];

int solve(int i, int sum)
{
    if (sum > s)
        return 0;
    if (i == n)
        return (sum == s) * power(2, n);
    int &ret = mem[i][sum];
    if (~ret)
        return ret;
    ret = solve(i + 1, sum);
    ret = add(ret, Divide(solve(i + 1, sum + a[i]), 2));
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> s;
    rep(i,0,n)
        cin >> a[i];

    clr(mem, -1);
    cout << solve(0,0) << '\n';
}

Measured memory_bytes: 39120
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  
  vector<vector<bool>> check(N,vector<bool>(N,false));
  for(int i=0; i<M; i++){
    int a, b;
    cin >> a >> b;
    check.at(a-1).at(b-1)=true;
    check.at(b-1).at(a-1)=true;
  }
  
  vector<int> p(0);
  for(int i=1; i<=N; i++){
    p.push_back(i);
  }
    
  int num=1;
  for(int i=1; i<N; i++){
    num*=i;
  }
  
  int ans=0;
  for(int i=0; i<num; i++){
    if(i>0){
      next_permutation(p.begin(), p.end());
    }
    for(int j=0; j<N-1; j++){
      int x=p.at(j)-1, y=p.at(j+1)-1;
      if(check.at(x).at(y)==false) break;
      if(j==N-2){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vl a(n);
	FOR(i,0,n) cin >> a[i];

	ll m = 1e6 + 10;
	vl cnt(m);
	FOR(i,0,n) cnt[a[i]]++;
	
	bool pw = true, sw = true;
	FOR(i,2,m) {
		ll cur = 0;
		for (ll j = i; j < m; j += i) cur += cnt[j];
		if (cur > 1) pw = false;
		if (cur == n) sw = false;
	}
	
	if (pw) cout << "pairwise ";
	else if (sw) cout << "setwise ";
	else cout << "not ";

	cout << "coprime" << endl;
}



Measured memory_bytes: 18744
from copy import copy
def dfs(x,v,s):
    for y,i in tree[x]:
        if parent[x] != y:
            parent[y] = x
            s.add(i)
            dfs(y,v,s)
            s.remove(i)
    if x == v:
        cons.append(s.copy())
    

N = int(input())
tree = [[] for _ in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    tree[a].append((b,i))
    tree[b].append((a,i))
M = int(input())
uv = []
cons = []
for i in range(M):
    u,v =  map(int,input().split())
    uv.append((u,v))
    parent = [-1]*(N+1)
    dfs(u,v,set())
bit = [0]*(N-1)
for i in range(N):
    for j in range(M):
        if i in cons[j]:
            bit[i] += 1 << j
dp = [0]*(1 << M)
dp[0] = 1
for i in range(N-1):
    for j in range(1 << M)[::-1]:
        dp[j|bit[i]] += dp[j]
print(dp[-1])

Measured memory_bytes: 76872
#include "bits/stdc++.h"
#define readInt(x) scanf_s("%d", &x)
#define readStr(x) scanf_s("%s", x)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmax(x, y) (x > (y) ? x : x = (y))
#define chmin(x, y) (x < (y) ? x : x = (y))
#define write(x) cout << (x) << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1 << 29;
const int MAX = 1e5 + 10;

int A, B, C, D, E, F;
int swmax;
int smax;

inline int cmp(int sw, int s) {
    return s * swmax - smax * sw;
}

inline bool isSoluble(int sw, int s) {
    return s * (100 + E) <= E * sw;
}

int main()
{
    cin >> A >> B >> C >> D >> E >> F;
    swmax = 100 * A;
    smax = 0;

    int slimit = F / 2 / C + 5;
    for (int addw = 1; addw < F / A; addw++) {
        for (int addB = 0; addB <= addw; addB++) {
            int wnow = (addw - addB) * 100 * A + addB * 100 * B;

            for (int adds = 1; adds < slimit; adds++) {
                for (int addD = 0; addD <= adds; addD++) {
                    int snow = (adds - addD) * C + addD * D;
                    int swnow = wnow + snow;
                    if (swnow > F)
                        break;
                    if (cmp(swnow, snow) > 0) {
                        if (isSoluble(swnow, snow)) {
                            swmax = swnow;
                            smax = snow;
                        }
                        else {
                            break;
                        }
                    }
                }
            }
        }
    }
    cout << swmax << " " << smax << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

ll fastPow(ll a, ll b) {
	ll ret = 1;
	while(b) {
		if(b & 1) ret = ret * a % MOD;
		a = a * a % MOD, b >>= 1;
	}
	return ret;
}

ll arr[maxN], yv[maxN];
int n;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	ll one = 0, two = 0;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		auto inve = fastPow(i, MOD - 2);
		ll nq = ll(i) * i % MOD;
		one = (one + inve) % MOD;
		two = (two + (i - 1) * inve) % MOD;
		yv[i] = 1 * one % MOD;
	}

	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	ll ans = 0;
	for(int i = 1; i < n; i++) {
		ans = (ans + (arr[i] - arr[i - 1]) * yv[i]) % MOD;
	}
	for(int i = 1; i <= n; i++) LOG << yv[i] << ' '; LOG << '\n';
	for(int i = 1; i <= n - 1; i++) ans = ans * i % MOD;
	cout << ans << '\n';
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g)
{
  for (int i = g; i < n; i++)
  {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v)
    {
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }
}

void shellSort(int A[], int n)
{
  // 数列G
  for (int h = 1;;)
  {
    if (h > n)
      break;
    G.push_back(h);
    h = 3 * h + 1;
  }

  for (int i = G.size() - 1; i >= 0; i--)
  {
    insertionSort(A, n, G[i]);
  }
}

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> A[i];
  }
  cnt = 0;

  shellSort(A, n);

  cout << G.size() << endl;
  for (int i = G.size() - 1; i >= 0; i--)
  {
    cout << G[i];
    if (i)
    {
      cout << " ";
    }
  }
  cout << endl;
  cout << cnt << endl;
  for (int i = 0; i < n; i++)
  {
    cout << A[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 6996
#include <iostream>
#include <vector>
#include <tr1/unordered_map>
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;

int X,Y;
struct NODE{
	int x,y,z,cost,fc;
	NODE(int x,int y,int z,int cost,int fc):
	x(x) , y(y) , z(z) , cost(cost) , fc(fc) {}
};
bool operator < (const NODE &a,const NODE &b){
	return a.cost != b.cost ? a.cost > b.cost : a.fc > b.fc;
}

int x[5][1000];
int y[5][1000];
int sz[5];
int main(){
	while(cin >> X >> Y && X){
		int sx,sy,gx,gy;
		for(int i = 0 ; i < 5 ; i++) sz[i]=0;
		
		for(int i = 0 ; i < Y ; i++)
			for(int j = 0 ; j < X ; j++){
				char c; scanf(" %c",&c);
				if(c == 'S'){
					sx = j , sy = i;
				}else if( c == 'G'){
					gx = j , gy = i;
				}else if( c != '.'){
					c = c - '1';
					x[c][sz[c]] = j;
					y[c][sz[c]++] = i;			
				}
			}
		priority_queue<NODE> Q;
		for(int i = 0 ; i < 5 ; i++){
			Q.push(NODE(sx,sy,(i+1)%5,0,i));
		}
		tr1::unordered_map< int , int > memo[5][5];
		
		while(Q.size()){

			NODE q = Q.top(); Q.pop();

			
			if(q.z == 10){
				cout << q.fc+1 << " " << q.cost << endl;
				goto exit;
			}
			if(memo[q.z][q.fc][(q.x<<12)|q.y] < q.cost) continue;
			if(q.z == q.fc){
				Q.push(NODE(gx,gy,10,q.cost+abs(q.x-gx)+abs(q.y-gy),q.fc));
			}else{
				for(int i = 0 ; i < sz[q.z] ; i++){
					NODE t = NODE(x[q.z][i],y[q.z][i],(q.z+1)%5,q.cost+abs(q.x-x[q.z][i])+abs(q.y-y[q.z][i]),q.fc);
					if( !memo[t.z][t.fc].count((t.x<<12)|t.y) || t.cost < memo[t.z][t.fc][(t.x<<12)|t.y])
						memo[t.z][t.fc][(t.x<<12)|t.y] = t.cost,Q.push(t);
				}
			}
		}
		cout << "NA" << endl;
		exit:;
	}
		
}

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

bool re(string& S) {
	if (S.size() <= 3) return false;
	int N = S.size();
	vector<int> cnt(3);
	for (int i = 0; i < N; i++) {
		cnt[S[i] - 'A']++;
	}
	int d = N + 1;
	char c = 'A';
	for (int i = 0; i < 3; i++) {
		if (cnt[i] < d) {
			d = cnt[i];
			c = 'A' + i;
		}
	}
	bool ex = false;
	string res;
	for (int i = 0; i < N; i++) {
		if (i + 2 < N && S.substr(i, 3) == "ABC") {
			ex = true;
			res.push_back(c);
			i += 2;
		}
		else if (S[i] == c) {
			return false;
		}
		else {
			res.push_back(S[i]);
		}
	}
	S = res;
	return ex;
}

int main()
{
	string S;
	cin >> S;
	while (re(S));
	puts(S == "ABC" ? "Yes" : "No");
	return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, M;
int P[110000], Y[110000];
vpint Yi[110000];
pint ans[110000];
signed main() {
    cin >> N >> M;
    rep(i, M) {
        cin >> P[i] >> Y[i];
        Yi[P[i]].push_back({Y[i], i});
    }
    reps(i, N) {
        sort(all(Yi[i]));
        rep(j, Yi[i].size()) { ans[Yi[i][j].second] = {i, j + 1}; }
    }
    rep(i, M) { printf("%06d", ans[i].first), printf("%06d\n", ans[i].second); }
}


Measured memory_bytes: 10368
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String[] sl = s.split(" ");
            int N = Integer.parseInt(sl[0]);
            int K = Integer.parseInt(sl[1]);

            System.out.println(K * (int)Math.pow(K - 1, N - 1));
        }
    }
}


Measured memory_bytes: 21204
N = int(input())
cards = list(map(int, input().split()))
A = 0
B = 0
while len(cards) > 0:
  A += max(cards)
  cards.pop(cards.index(max(cards)))
  if len(cards) > 0:
    B += max(cards)
    cards.pop(cards.index(max(cards)))
print(A - B)

Measured memory_bytes: 3060