akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

void print(vector<int> array)
{
  for(int i=0;i<array.size()-1;i++){
    cout<<array[i]<<" ";
  }
  cout<<array[array.size()-1]<<endl;
}
void swap(int& a,int& b)
{
  if(a>=b){
    int tmp=a;
    a=b;
    b=tmp;
  }
}

vector<int> marge(vector<int>& list,int& count)
{
  int n=list.size();
  vector<int> result(0);
  int i=0,j=0;
  int half;
  vector<int> left(0);
  vector<int> right(0);
  if(n==1){
    return list;
  }else if(n==2){
    swap(list[0],list[1]);
    count+=2;
    return list;
  }else{
    half=n/2;

    for(i=0;i<half;i++){
      left.push_back(list[i]);
    }

    for(i=half;i<n;i++){
      right.push_back(list[i]);
    }

    left=marge(left,count);
    right=marge(right,count);
    i=0; j=0;
    while(result.size()<n){
      if(i==left.size()){
	while(j<right.size()){
	  result.push_back(right[j]);
	  j++;
	  count++;
	}
	break;
      }else if(j==right.size()){
	while(i<left.size()){
	  result.push_back(left[i]);
	  i++;
	  count++;
	}
	break;
      }
      if(left[i]<=right[j]){
	result.push_back(left[i]);
	i++;
	count++;
      }else{
	result.push_back(right[j]);
	j++;
	count++;
      }
    }
  }
  return result;
}

int main()
{
  int n,count=0;
  cin>>n;
  vector<int> list(n);
  for(int i=0;i<n;i++){
    cin>>list[i];
  }
  list=marge(list,count);
  print(list);
  cout<<count<<endl;
  return 0;
}



Measured memory_bytes: 10532
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int d, x;
	cin >> d >> x;
	int cnt = 1;
	rep(i, d) {
		cnt *= 100;
	}
	if (x == 100) {
		x++;
	}
	cout << cnt*x << endl;
	return 0;
}

Measured memory_bytes: 256
li = input()
count = 0
if len(li) % 2 == 0:
    for i in range(int(len(li)/2)):
        if li[i] != li[len(li)-i-1]:
            count += 1
else:
    for i in range(int((len(li)-1)/2)):
        if li[i] != li[len(li)-i-1]:
            count += 1
print(count)


Measured memory_bytes: 3060
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #define S second
    using namespace std;
     
    int n, s;
    pair<int, int> a[100005];
    int main()
    {
    	int i;
    	cin >> n;
    	for (i =0; i < n; i++) {
    		scanf ("%d", &a[i].first);
    		a[i].S = i % 2;
    	}
    	sort(a, a + n);
    	for (i = 0; i < n; i++) {
    		if (a[i].S != i % 2) s++;
    	}
    	cout << s/2;
        return 0;
    }

Measured memory_bytes: 1024
N = int(input())
N2 = 2**N
S = list(map(int, input().split()))
S.sort(reverse=True)

slimes = [S[0]]
S[0] = float('inf')
num = 1
min_idx = 1
for i in range(N):
  slimes.sort()
  n = num
  idx = min_idx
  is_continuous = True
  while n and idx<=N2-1:
    if S[idx] < slimes[n-1]:
      slimes.append(S[idx])
      S[idx] = float('inf')
      idx += 1
      n -= 1
      min_idx += is_continuous
    else:
      if S[idx] < float('inf'):
        is_continuous = False
      idx += 1
      min_idx += is_continuous
  
  if n:
    print('No')
    quit()
  
  num *= 2

print('Yes')

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

istream& operator>>(istream &in, vector<int> &arr) {
    for(int i = 0; i < arr.size(); i++) {
        in >> arr[i];
    }
    return in;
}

int A_prefix[102], B_prefix[102];

int main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.in", "r", stdin);
    int n;
    cin >> n;
    vector<int> A(n), B(n);
    cin >> A >> B;
    int A_sum = 0, B_sum = 0;
    for(int i = 0; i < n; i++) {
        A_sum += A[i];
        A_prefix[i + 1] = A_sum;
        B_sum += B[i];
        B_prefix[i + 1] = B_sum;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        int cur = A_prefix[i] + B_prefix[n] - B_prefix[i - 1];
        ans = max(ans, cur);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <functional>
using namespace std;

int main()
{
	int a,b;

	cin >> a >> b;

	if(a <= 5){
		cout << 0 << endl;
		return 0;
	}

	if(6 <= a && a <= 12){
		cout << (int)b/2 << endl;
		return 0;
	}

	if(13 <= a){
		cout << b << endl;
		return 0;
	}



	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
int main() {
	ll cnt[18] = {};
	ll m = 10;
	rep(i, 18) {
		ll memo = m - 1;
		ll thr = memo / 3 - memo / 30;
		ll fiv = memo / 5 - memo / 50;
		ll fif = memo / 15 - memo / 150;
		thr -= fif; fiv -= fif;
		cnt[i] += (ll)4 * thr+(ll)4*fiv+(ll)8*fif;
		ll r = m - m / 10 - thr - fiv - fif;
		cnt[i] += r * (i + 1);
		m *= (ll)10;
	}
	ll s; cin >> s;
	int chk = 0;
	while (s - cnt[chk] >= 0) {
		s -= cnt[chk]; chk++;
	}
	ll now = 1;
	rep(i, chk) {
		now *= (ll)10;
	}
	ll ter = (ll)32 + (ll)8 * (chk + 1);
	ll a = s / ter;
	ll b = s % ter;
	if (b == 0&&a>0) {
		b = ter; a--;
	}
	now += (ll)15 * a;
	string u = "";
	for(ll i=now;i<(ll)35+now;i++) {
		if (i % 15 == 0)u += "FizzBuzz";
		else if(i % 3 == 0)u += "Fizz";
		else if (i % 5 == 0)u += "Buzz";
		else u += to_string(i);
	}
	if (b == 0 && a == 0) {
		cout << "z";
		rep(i, 19)cout << u[i];
		cout << endl;
	}
	else {
		string out = u.substr((int)b - 1, 20);
		cout << out << endl;
	}
	return 0;
}


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

public class Main {

	private static void solve(){
		//Implement solution here.
		int n = ni();
		int notax = (int)((double)n / 1.08D);
		if((int)(notax * 1.08) == n) {
			System.out.println(notax);
		}else if((int)((notax + 1) * 1.08) == n) {
			System.out.println(notax + 1);
		}else {
			System.out.println(":(");
		}
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string s = Console.ReadLine();
		int si = 0;
		int sa = 1;
		string s1 = "";
      	string s2 = "";
		int ans = 0;
		while(si<s.Length){
			s1 += s.Substring(si,1);
			if(s1 == s2){
				si++;
				if(si>=s.Length){
					break;
				}
			} else {
				ans++;
				si++;
             	s2 = s1;
         		s1 = "";
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 15712
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

template <int M> class ModInt {
    int x;

  public:
    constexpr ModInt() : x(0) {}
    constexpr ModInt(int64_t y) : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}
    constexpr ModInt &operator+=(const ModInt p) {
        if((x += p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt p) {
        if((x += M - p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt p) {
        x = (int)(1LL * x * p.x % M);
        return *this;
    }
    constexpr ModInt &operator/=(const ModInt p) {
        *this *= p.inverse();
        return *this;
    }
    constexpr ModInt operator-() const { return ModInt(-x); }
    constexpr ModInt operator+(const ModInt p) const {
        return ModInt(*this) += p;
    }
    constexpr ModInt operator-(const ModInt p) const {
        return ModInt(*this) -= p;
    }
    constexpr ModInt operator*(const ModInt p) const {
        return ModInt(*this) *= p;
    }
    constexpr ModInt operator/(const ModInt p) const {
        return ModInt(*this) /= p;
    }
    constexpr bool operator==(const ModInt p) const { return x == p.x; }
    constexpr bool operator!=(const ModInt p) const { return x != p.x; }
    constexpr ModInt inverse() const {
        int a = x, b = M, u = 1, v = 0, t = 0;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    constexpr ModInt pow(int64_t k) const {
        ModInt ret(1), mul(x);
        while(k > 0) {
            if(k & 1) ret *= mul;
            mul *= mul;
            k >>= 1;
        }
        return ret;
    }
    constexpr friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    constexpr friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t = 0;
        is >> t;
        a = ModInt(t);
        return (is);
    }
};
using mint = ModInt<Mod>;

int a, b, c, d;

mint dp[3009][3009];
bool flag[3009][3009];

mint f(int x, int y) {
    if(x < a || y < b) return 0;
    if(x == a && y == b) return 1;

    if(flag[x][y]) return dp[x][y];

    flag[x][y] = 1;
    dp[x][y] += f(x - 1, y) * y;
    dp[x][y] += f(x, y - 1) * x;
    dp[x][y] -= f(x - 1, y - 1) * (x - 1) * (y - 1);

    return dp[x][y];
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> a >> b >> c >> d;

    cout << f(c, d) << endl;

    return 0;
}

Measured memory_bytes: 48156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for(auto& i:mp)

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

  if ((s[s.size() - 1]-'0') == 3) cout << "bon" << endl;
  else if ((s[s.size() - 1]-'0') == 2 || (s[s.size() - 1]-'0') == 4 || (s[s.size() - 1]-'0') == 5 || (s[s.size() - 1]-'0') == 7 || (s[s.size() - 1]-'0') == 9) cout << "hon" << endl;
  else cout << "pon" << endl;

  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <stack>
#include <list>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

ll res = 0;

int main() {
  string s;
  cin >> s;
  char t = s[0];
  for(ll i=1; i < s.size(); i++) {
    if(s[i] != t) {
      t = s[i];
      res++;
    }
  }

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

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % mod;
		x = x * x % mod; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 17;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}



void solve(){
	int n; cin >> n;
	vector<int> a(n); rep(i, n)cin >> a[i];
	int ans = 0;
	rep(i, n) {
		if (i % 2 == 0 && a[i] % 2)ans++;
	}
	cout << ans << "\n";
}




signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//cout << grandy(2, 3, false, false) << "\n";
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}

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

using namespace std;

int visit[9];
double res(0.);
int cnt(0);

void dfs(int visitcount, int limit, double has, vector<int> now, vector<vector<int>> &crd);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int n; cin >> n;
    
    vector<vector<int>> coord(n);

    for (int i = 0; i < n; ++i)
    {
        int x, y;
        cin >> x >> y;
        
        vector<int> part{x, y};
        coord[i] = part;
    }
    
    for (int i = 0; i < n; ++i)
    {
        memset(visit, 0, sizeof visit);
        visit[i] = 1;
        dfs(1, n, 0.0, coord[i], coord);
    }
    cout << setprecision(16) << res / cnt;
}

void dfs(int visitcount, int limit, double has, vector<int> now, vector<vector<int>> &crd)
{
    if (visitcount > limit)
        return;
    
    for (int i = 0; i < limit; ++i)
    {
        if (visit[i])
            continue;
        
        visit[i] = 1;
        
        double m(now[0]), n(now[1]), x(crd[i][0]), y(crd[i][1]);
        double another = has + sqrt((y - n) * (y - n) + (x - m) * (x - m));

        dfs(visitcount + 1, limit, another, crd[i], crd);
        
        visit[i] = 0;
    }

    if (visitcount == limit)
    {
        ++cnt;
        res += has;
        return;
    }
}

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

typedef long long ll;

#define v(T) vector<T>
#define ttt(T) tuple<T, T, T>
#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define poiu(n) for(int i=0; i < n; i++)
#define MOD (int)10e9+7
#define endl '\n'

template<typename T>
void max_self(T& a, T b) { a=a>b?a:b; }
template<typename T>
void min_self(T& a, T b) { a=a<b?a:b; }

using namespace std;

const int mxN = 1e5+5;

int n;
int h, temp;

int dp[mxN];
int stones[mxN];
int main() {
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    memset(dp, 0x3f, sizeof(int)*mxN);
    
    int k;
    cin >> n >> k;

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

    for(int i=0; i<n; i++) {
        for(int x=i+1; x<=i+k&&x<n; x++) {
            min_self(dp[x], dp[i]+abs(stones[i]-stones[x]));
        }
    }
    cout << dp[n-1] << endl;
    


    return 0;

}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include<cmath>
using namespace std;
#define ll (long long)
#define PI (acos(-1))

int main()
{
  int N,M;
  cin >> N >> M;

  vector<int> A(M);

  int sum = 0;
  for(int i=0; i<M; i++){
    cin >> A[i];
    sum += A[i];
  }

  if(N < sum){
    cout << -1;
  }else{
    cout << N-sum;
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int n, k; cin>>n>>k;
    vector<int> h(n+10);
    for(int i=0; i<n; i++) cin>>h[i];

    vector<int> dp(n+10, 1e9);
    dp[0]=0;
    for(int i=0; i<n; i++){
        for(int j=1; j<=k; j++){
            if(0<=i-j) dp[i]=min(dp[i], dp[i-j]+abs(h[i-j]-h[i]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll N,K,ans=INF;
  cin>>N>>K;
  ll x[N];
  for(ll i=0;i<N;i++) cin>>x[i];
  for(ll i=0;i+K-1<N;i++){
    if(x[i]*x[i+K-1]<0) ans=min(ans,abs(x[i])+abs(x[i+K-1])+min(abs(x[i]),abs(x[i+K-1])));
    else ans=min(ans,max(abs(x[i]),abs(x[i+K-1])));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

N,X=rl()
L=list(rl())
ans = 1
D = 0
for l in L:
    D += l
    if D <= X:
        ans += 1
    else:
        break

print(ans)

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = 1000000007;

ll n, k;
vector<vector<ll>> vs;

ll dfs(ll current, ll parent) 
{
	ll colors = k - 1;
	if (parent >= 0) {
		colors = k - 2;
	}
	ll sum = 1;
	for (auto e : vs[current]) {
		if (e == parent) continue;
		sum *= colors;
		sum %= mod;
		colors--;
	}
	for (auto e : vs[current]) {
		if (e == parent) continue;
		sum *= dfs(e, current);
		sum %= mod;
	}
	return sum;
}

int main(void)
{
	cin >> n >> k;
	vs.resize(n);
	rep(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		vs[a].push_back(b);
		vs[b].push_back(a);
	}
	int root = -1;
	rep(i,n) {
		if (vs[i].size() == 1) {
			root = i;
			break;
		}
	}
	ll sum = k * dfs(root, -1);
	sum %= mod;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 11904
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    int odp = k;
    for (int i = 1; i < n; ++i)
        odp *= k - 1;
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, k; cin >> n >> k;
    vint h(n);
    rep(i,n) cin >> h[i];
    sort(all(h));
    ll sum = 0;
    if (k >= n) cout << 0 << endl;
    else {
        for (int i = 0; i < n-k; i++) {
            sum += h[i];
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

ll num[ten52];

int main(void)
{
    ll m,n,i,j,k=1,d,sum=0;
    string s;
    cin>>n>>m;
    for(i=0;i<n;i++)
        cin>>num[i];
    for(i=0;i<n-1;i++)
    {
        if(num[i]+m<=num[i+1])
            sum+=m;
        else
            sum+=(num[i+1]-num[i]);
    }
    sum+=m;
    cout<<sum;
    return 0;
}


Measured memory_bytes: 5024
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N=1e5+10;
int a[N];
int main()
{
    int n,x;
    while(~scanf("%d%d",&n,&x))
    {
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        long long sum=0;
        long long tmp=0;
        long long cc;
        for(int i=0;i<n;i++)
        {
            cc=0;
            if(tmp+a[i]>x) cc=tmp+a[i]-x;
            tmp=a[i]-cc;
            sum+=cc;
        }
        printf("%lld\n",sum);
    }
    return 0;
}


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

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

        int x = sc.NextInt();
        int y = sc.NextInt();

        int[] group1 = new int[] { 1, 3, 5, 7, 8, 10, 12 };
        int[] group2 = new int[] { 4, 6, 9, 11 };

        bool ok = (group1.Contains(x) && group1.Contains(y)) || (group2.Contains(x) && group2.Contains(y));

        string answer = ok ? "Yes" : "No";

        Console.WriteLine(answer);
    }

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

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

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

            return _line[_index++];
        }

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

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

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

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

// constexpr long MOD = 998244353;
constexpr long MOD = 1000000007;
vector<long> fact, inv;

long mpow(long a, long b) {
  long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return res;
}

void init(int n) {
  fact.push_back(1);
  inv.push_back(1);
  for (int i = 0; i < n; i++) {
    fact.push_back(fact.at(i) * (i + 1) % MOD);
    inv.push_back(mpow(fact.at(i + 1), MOD - 2));
  }
}

long qcom(long n, long r) {
  if (n - r < 0) return 0;
  return fact.at(n) * inv.at(r) % MOD * inv.at(n - r) % MOD;
}

long com(long n, long r) {
  long x = 1, y = 1;
  for (int i = 1; i <= r; i++) {
    x = x * (n - i + 1) % MOD;
    y = y * i % MOD;
  }
  return x * mpow(y, MOD - 2) % MOD;
}

int main() {
  int N, K;
  cin >> N >> K;
  init(100000);
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  long ans = 0;
  for (int i = 0; i + 1 < N; i++) {
    ans += (qcom(N, K) - qcom(i + 1, K) - qcom(N - i - 1, K)) * (A.at(i + 1) - A.at(i));
    ans %= MOD;
  }
  while (ans < 0) ans += MOD;
  cout << ans << "\n";
}

Measured memory_bytes: 2156
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<pair<double,double>> hoge(n);
  for(int i=0; i<n; i++){
    cin>>hoge.at(i).first>>hoge.at(i).second;
  }

  long long int a=hoge.at(0).first,b=hoge.at(0).second;
  for(int i=1; i<n; i++){
    long long int x,y;
    x=hoge.at(i).first;
    y=hoge.at(i).second;
    long long int prex,prey;
    prex=a/x;
    if(a%x!=0){
      prex++;
    }
    prey=b/y;
    if(b%y!=0){
      prey++;
    }
    long long int m=max(prex,prey);
    a=m*x;
    b=m*y;
  }
  cout<<a+b<<endl;
}

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

int main() {
    string s;
    cin >> s;
    int count = 1;
    int L_start = 0;
    bool flag = true;
    int a[s.length()];
    int loop = 0;

    for(int i = 0; i < s.length(); i++) {
        a[i] = 0;
    }

    for(int i = 0; i < s.length(); i++) {
        if(s[i] == 'R') {
            if(s[i+1] == 'R') {
                count++;
            } else {
                for(int j = 0; j < count; j++) {
                    if(j % 2 == 0) {
                        a[i]++;
                    } else {
                        a[i+1]++;
                    }
                }
                count = 1;
            }
        } else if(s[i] == 'L') {
            if(flag) {
                L_start = i;
                flag = false;
            }
            if(i == s.length()-1) {
                for(int j = 0; j < count; j++) {
                    if(j % 2 == 0) {
                        a[L_start]++;
                    } else {
                        a[L_start-1]++;
                    }  
                }
                count = 1;
                flag = true;
            } else if(s[i+1] == 'R') {
                for(int j = 0; j < count; j++) {
                    if(j % 2 == 0) {
                        a[L_start]++;
                    } else {
                        a[L_start-1]++;
                    }  
                }
                count = 1;
                flag = true;
            } else {
                count++;
            }
        }
    }

    for(int i = 0; i < s.length(); i++) {
        cout << a[i] << " ";
    }
}


Measured memory_bytes: 1024
#168C
#:(Colon)

import math

a,b,h,m=map(int,input().split())
d=0

minute_h=60*h+m

rad_a=math.pi*minute_h/360
rad_b=math.pi*m/30
rad_dif=abs(rad_a-rad_b)

d=(a**2+b**2-2*a*b*math.cos(rad_dif))**0.5
print(d)

Measured memory_bytes: 9416
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
using namespace std;
#define ll long long

int dfs(vector<vector<int>> &v, int key, vector<int> &t, int p){
    int now=p;
    t[key]=now;
    for(int i=0; i<v[key].size(); ++i){
        if(t[v[key][i]]==0){
            now=dfs(v, v[key][i], t, now+1);
        }
    }
    return now;
}

int main() {
	int N; cin >> N;
	vector<vector<int>> g(N+1);
	for(int i=1; i<N; ++i){
	    int a, b;
	    cin >> a >> b;
	    g[a].push_back(b);
	    g[b].push_back(a);
	}
	vector<int> c(N);
	int sum=0;
	for(int i=0; i<N; ++i){
	    cin >> c[i];
	    sum += c[i];
	}
	sort(c.begin(), c.end(), greater<int>());
	cout << sum-c[0] << endl;
	vector<int> ans(N+1, 0);
	dfs(g, 1, ans, 1);
	cout << c[ans[1]-1];
	for(int i=2; i<=N; ++i) cout << ' ' << c[ans[i]-1];
	cout << endl;
	return 0;
}


Measured memory_bytes: 1408
/*
 * @author Raj Sharma
 */

import java.io.*;
 
class Main{
    public static void main (String[ ] args) throws IOException{
 
        BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
        boolean sift[] = new boolean[1000000];
        int prim[] = new int[1000000];
        int cnt=0;
        String str;
 
        sift[0] = false;
        sift[1] = false;
        prim[0]=0;
 
        for(int i = 2;i < 1000000;i++){
            sift[i] = true;
        }
 
        for(int i = 1;i < 1000000;i++){
            if(sift[i] == true){
                cnt++;
                for(int j = i*2;j < 1000000;j+=i){
                    sift[j]=false;
                }
            }
        prim[i]=cnt;
        }
 
        while((str = in.readLine()) != null){
            System.out.println(prim[Integer.parseInt(str)]);
        }
    }
}

Measured memory_bytes: 30020
#include <stdio.h>
#include <string.h>

int main() {
    while (true) {
        char str[201];
        scanf("%s", str);
        if (strcmp(str, "-") == 0) {
            break;
        }
        int m;
        scanf("%d", &m);
        int h[100];
        for (int i = 0; i < m; i++) {
            scanf("%d", h + i);
        }

        for (int i = 0; i < m; i++) {
            char str2[201];
            strcpy(str2, str);
            for (int j = 0; j < strlen(str) - h[i]; j++) {
                str[j] = str2[j + h[i]];
            }
            for (int j = strlen(str) - h[i]; j < strlen(str); j++) {
                str[j] = str2[j + h[i] - strlen(str)];
            }
        }
        printf("%s\n", str);
    }
    return 0;
}


Measured memory_bytes: 2748
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    int N;
    std::cin >> N;

    const int num = 3 * N;
    std::vector<int> a(num);
    for (int i = 0; i < num; ++i) {
        std::cin >> a[i];
    }
    
    std::sort(a.begin(), a.end(), std::greater<int>());

    long long ret = 0;
    for (int i = 0; i < N; ++i) {
        ret += a[2 * i + 1];
    }

    std::cout << ret << std::endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

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 long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
ll ab[25000][2500];
int main() {
	ll x;
	cin >> n >> x;
	vector<ll> l(n);
	rep(i, n) {
		cin >> l[i];
	}
	ll res = 1;
	ll cnt = 0;
	rep(i, n) {
		cnt += l[i];
		if (cnt > x) {
			break;
		}
		res++;
	}
	cout << res << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n , k;
string s;
char z(char ch){
	if(ch=='A') return 'a';
	if(ch=='B') return 'b';
	if(ch=='C') return 'c';
}
int main(){
	cin >> n >> k >> s;
	s[k-1]=z(s[k-1]);
	cout<<s<<'\n';
	return 0;
}

Measured memory_bytes: 3484
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int, input().split()))
ans = [-1]*n
for i, a in enumerate(A):
    ans[a-1] = i+1
    #print(i, a)
print(*ans)

Measured memory_bytes: 88232
#include <bits/stdc++.h>
#define int long long
using namespace std;

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

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (a[a[i]] == i) {
      ans++;
    }
  }

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

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	char m[101][101];
	int W, H, N;
	cin >> W >> H >> N;
	fill_n(*m, 101 * 101, '*');
	for (int i = 0; i < N; i++) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1) {
			for (int z = 1; z <= x; z++) {
				for (int j = 1; j <= H; j++) {
					m[j][z] = '!';
				}
			}
		}
		else if (a == 2) {
			for (int z = x+1; z <= W; z++) {
				for (int j = 1; j <= H; j++) {
					m[j][z] = '!';
				}
			}
		}
		else if (a == 3) {
			for (int z = 1; z <= W; z++) {
				for (int j = 1; j <= y; j++) {
					m[j][z] = '!';
				}
			}
		}
		else if (a == 4) {
			for (int z = 1; z <= W; z++) {
				for (int j = y+1 ;j <= H; j++) {
					m[j][z] = '!';
				}
			}
	
	}
	}
	int ans = 0;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (m[i][j] == '*') {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a>9 || b>9){
  cout << -1 << endl;
  }
  if(a<10 && b<10){
    cout << a*b << endl;
  }
  return 0;
}

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

#define INF 0x334334334334

typedef long long int LLI;

int n;
int m;
int R;
int z[1419];
LLI dp[1145][1419];
LLI mindL[1145][1419];
LLI mindS[1145][1419];

int main() {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0) return 0;

    fill(mindL[0], mindL[n+1], INF);
    fill(mindS[0], mindS[n+1], INF);
    for (int i=1; i<=n; i++) {
      mindL[i][i] = 0;
      mindS[i][i] = 0;
    }

    for (int i=0; i<m; i++) {
      char sl;
      int x, y;
      LLI t;
      scanf("%d%d%lld %c", &x, &y, &t, &sl);
      if (sl == 'L') {
        mindL[x][y] = min(mindL[x][y], t);
        mindL[y][x] = min(mindL[y][x], t);
      } else if (sl == 'S') {
        mindS[x][y] = min(mindS[x][y], t);
        mindS[y][x] = min(mindS[y][x], t);
      } else assert(0);
    }

    for (int k=1; k<=n; k++) {
      for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
          mindL[i][j] = min(mindL[i][j], mindL[i][k] + mindL[k][j]);
          mindL[j][i] = min(mindL[j][i], mindL[j][k] + mindL[k][i]);
          mindS[i][j] = min(mindS[i][j], mindS[i][k] + mindS[k][j]);
          mindS[j][i] = min(mindS[j][i], mindS[j][k] + mindS[k][i]);
        }
      }
    }

    scanf("%d", &R);
    fill(dp[0], dp[R+1], INF);

    scanf("%d", &z[0]);
    dp[0][z[0]] = 0;
    for (int i=1; i<R; i++) {
      scanf("%d", &z[i]);
      for (int j=1; j<=n; j++) {
        for (int k=1; k<=n; k++) {
          LLI t = dp[i-1][j] + mindL[z[i-1]][j] + mindS[j][k] + mindL[k][z[i]];
          dp[i][k] = min(dp[i][k], t);
          if (j == k) {
            t = dp[i-1][j] + mindL[z[i-1]][z[i]];
            dp[i][k] = min(dp[i][k], t);
          }
        }
      }
    }

    LLI ans = INF;
    for (int i=1; i<=n; i++) ans = min(ans, dp[R-1][i]);
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 18696
N, Q = map(int, input().split())
S = input()
wa = [0] * (N + 1)
flag = "X"
for i in range(N):
    if S[i] == "A":
        flag = "A"
        wa[i+1] = wa[i]
    elif flag == "A" and S[i] == "C":
        wa[i+1] = wa[i] + 1
        flag = "X"
    else:
        flag = "X"
        wa[i+1] = wa[i]
        
for q in range(Q):
    left,  right = map(int, input().split())
    print(wa[right] - wa[left])

Measured memory_bytes: 6084
def move(dice,dir)
  case dir
  when "N" then dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0]
  when "S" then dice[0],dice[1],dice[5],dice[4] = dice[4],dice[0],dice[1],dice[5]
  when "E" then dice[0],dice[2],dice[5],dice[3] = dice[3],dice[0],dice[2],dice[5]
  when "W" then dice[0],dice[2],dice[5],dice[3] = dice[2],dice[5],dice[3],dice[0]
  end
  dice
end

  
def isSame(d1, d2) 
yn = false  
for i in 1..6
  d = Marshal.load(Marshal.dump(d2))
  case i
  when 2 then d = move(d,"S")
  when 3 then d = move(move(d,"W"),"S")
  when 4 then d = move(d,"N")
  when 5 then d = move(move(d,"E"),"S")
  when 6 then d = move(move(d,"S"),"S")
  end

  next if d[1] != d1[1]
  next if d[4] != d1[4]
  for j in 1..4
    d = move(d,"W")
    yn = (d == d1)
 break if yn 
  end
 break if yn 
end
yn 
end
  
n = gets.to_i
ds = Array.new(n){gets.split(" ").map{|i| i.to_i}}
yn = false

for i in 1..n-1
  for j in 0..i-1
    yn = isSame(ds[i],ds[j])
    break if yn == true 
  end
  break if yn == true
end

puts(yn ? "No" : "Yes")


Measured memory_bytes: 7828
#include <bits/stdc++.h>
#define MOD 100000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main(){
    ll H, count = 0, ans = 0;
    cin >> H;

    while(H > 1){
        H /= 2;
        count++;
    }

    for (int i = 1; i <= count; i++){
        ans += pow(2, i);
    }

    cout << ans + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 2e5 + 20;
const int mod = 1e9 + 7;

int n;
int a[20][20];
ll dp[(1 << 16) + 100];
int was[(1 << 16) + 100];
ll func[(1 << 16) + 100];

ll go(int mask) {
	if (was[mask]) re dp[mask];
	if (mask == 0) re 0;
	was[mask] = 1;
	ll ans = 0;
	for (int s = mask; s; s = (s - 1) & mask) 
		ans = max(ans, func[s] + go(mask ^ s));			 	
	
	re dp[mask] = ans;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> a[i][j];
	for (int s = 1; s < (1 << n); s++) 
		for (int i = 0; i < n; i++)
		    for (int j = i + 1; j < n; j++)
				if ((s & (1 << i)) && (s & (1 << j)))
					func[s] += a[i][j];
	cout << go((1 << n) - 1);	
}

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

int main()
{
string v[3];
cin >> v[0] >> v[1] >> v[2] ;
sort(v,v+3);
do{
bool a[5000]={};
bool b[5000]={};
bool c[5000]={};
ll aa=v[0].size();
ll bb=v[1].size();
ll cc=v[2].size();
rep(i,aa)rep(j,bb)if(i+j<aa&&v[0][i+j]!='?'&&v[1][j]!='?'&&v[0][i+j]!=v[1][j]){a[i]=1;}
rep(i,aa)rep(j,cc)if(i+j<aa&&v[0][i+j]!='?'&&v[2][j]!='?'&&v[0][i+j]!=v[2][j]){b[i]=1;}
rep(i,bb)rep(j,cc)if(i+j<bb&&v[1][i+j]!='?'&&v[2][j]!='?'&&v[1][i+j]!=v[2][j]){c[i]=1;}

rep(i,2001)rep(j,2001){
  ll f[3]={aa,bb+i,cc+i+j};
  sort(f,f+3);
  if(!a[i]&&!b[i+j]&&!c[j])ans=min(ans,f[2]);
}
}while(next_permutation(v,v+3));
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
/* ex3_3
   kohei_suzuki */

#include <stdio.h>
#include <math.h>

int main(void){
    int sin_10, sin_k; //10進数の整数sin_10,進数sin_k
    int dig = 0; //桁数dig

    scanf("%d %d",&sin_10, &sin_k); //sin_10,sin_k入力

    while(sin_10 >= pow(sin_k,dig)){ //sin_10とsin_k^digを比較して桁数を求める
        dig += 1; //digを1ずつ増やして繰り返し比較する
    }

    printf("%d\n",dig); //桁数digを出力

    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        if((Math.abs(a - c)<=d) ||(Math.abs(a - b)<=d && Math.abs(b - c)<=d)) {
        	System.out.println("Yes");
        	
        }
        else {
        System.out.println("No");
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<int, int> mii;

#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define clr(a) memset(a,0,sizeof(a))
#define SET(a,b) memset(a,b,sizeof(a))

#define trace(x) cout << '>' << #x << ':' << x << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
const int oo = 0x3f3f3f3f;

template<class T> inline T gcd(T a,T b) //NOTE:__gcd(0,0) gives exception
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

/*bool sortby(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
    return (a.second < b.second);
}*/

const int MAX_N = 3*123456;

//int arr[MAX_N];

int main(){
    int N,M,X,Y,x;
    scanf("%d%d%d%d",&N,&M,&X,&Y);
    vi vx,vy;
    for(int i=0;i<N;i++){
        scanf("%d",&x);
        vx.PB(x);
    }
    SORT(vx);
    for(int i=0;i<M;i++){
        scanf("%d",&x);
        vy.PB(x);
    }
    SORT(vy);
    bool flag=1;
    for(int i=X+1;i<Y+1;i++){
        if(vx[N-1]<i && vy[0]>=i){
            flag=0;
            printf("No War\n");
            break;
        }
    }
    if(flag)
        printf("War\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repe(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define mst(a, b)   memset((a), (b), sizeof(a))
#define gc() gutchar()
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pr;
typedef long long ll;
const double eps = 1e-5;
const int inf = 0x3f3f3f3f;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const ll mod = 1e9+7;
const int N = 2e5+5;

int h[N];
ll sum;

bool cmp(int x, int y)
{
	return x > y;
}

int main()
{
	int n, k;
	cin >> n >> k;
	rep(i, 0, n){
		scanf("%d", &h[i]);
		sum += h[i];
	}
	if (n <= k)	puts("0");
	else
	{
		sort(h, h + n, cmp);
		rep(i, 0, k){
			sum -= h[i];
		}
		printf("%lld\n", sum);
	}
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = list(map(int,input().split()))
ans = -1000000000000000
dp = [{} for _ in range(n)]
dp[0][1] = s[0]
dp[1][1] = s[1]
if n >= 3:
    dp[2][1] = s[2]
for i in range(n):
    for x in dp[i].keys():
        y = dp[i][x]
        if x == n//2:
            ans = max(ans,y)
        else:
            if (n-(i+2)+1)//2 >= n//2-(x+1) and i+2 <= n-1:
                if x+1 in dp[i+2].keys():
                    dp[i+2][x+1] = max(dp[i+2][x+1],dp[i][x] + s[i+2])
                else:
                    dp[i+2][x+1] = dp[i][x] + s[i+2]
            if (n-(i+3)+1)//2 >= n//2-(x+1) and i+3 <= n-1:
                if x+1 in dp[i+3].keys():
                    dp[i+3][x+1] = max(dp[i+3][x+1],dp[i][x] + s[i+3])
                else:
                    dp[i+3][x+1] = dp[i][x] + s[i+3]
            if (n-(i+4)+1)//2 >= n//2-(x+1) and i+4 <= n-1:
                if x+1 in dp[i+4].keys():
                    dp[i+4][x+1] = max(dp[i+4][x+1],dp[i][x]+s[i+4])
                else:
                    dp[i+4][x+1] = dp[i][x]+s[i+4]
print(ans)


Measured memory_bytes: 149904