akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	string str;
	int k;
	cin >> k >> str;
	if(str.size() <= k)
		cout << str;
	else
		cout << str.substr(0, k) << "...";
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
 
class Cube {
private:
    string tmp;
public:
    string d[6];
  
    void rollN() {
	tmp = d[0];
	d[0] = d[1];
	d[1] = d[5];
	d[5] = d[4];
	d[4] = tmp;
    }
  
    void rollW() {
	tmp = d[0];
	d[0] = d[2];
	d[2] = d[5];
	d[5] = d[3];
	d[3] = tmp;
    }
 
    void rotation() {
	tmp = d[1];
	d[1] = d[3];
	d[3] = d[4];
	d[4] = d[2];
	d[2] = tmp;
    }
 
    bool judge(Cube &C) {
	rep(i,6){
	    if(d[i] != C.d[i]){
		return false;
	    }
	}
	return true;
    }
 
    bool equals(Cube &C) {
	rep(i,3){
	    rollN();
	    if(d[0] == C.d[0]){
		break;
	    }
	    rollW();
	    if(d[0] == C.d[0]){
		break;
	    }
	}
	rep(i,4){
	    if(judge(C)){
		return true;
	    }
	    rotation();
	}
	return false;
    }
};
  
int main()
{
    int N;
 
    while (cin >> N, N) {
	Cube cube[N];
	rep (i, N) {
	    rep (j, 6) {
		cin >> cube[i].d[j];
	    }
	}   
	int ans = 0;
	bool used[N];
	memset(used, false, sizeof(used));
	rep (i, N-1) {
	    for (int j = i+1; j < N; j++) {
		if (cube[i].equals(cube[j]) && !used[j]) {
		    used[j] = true;
		    ans++;
		}
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3168
import java.util.Scanner;

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

		int n = Integer.parseInt(sc.next());

		//		int[] d = new int[n];
		//
		//		for (int i = 0; i < n; i++) {
		//			d[i] = Integer.parseInt(sc.next());
		//		}
		//		int ans = 0;
		//
		//		for (int i = 0; i < n; i++) {
		//			for (int j = i+1; j < n; j++) {
		//				ans += d[i] * d[j];
		//			}
		//		}

		System.out.println((n - 1) / 2);
		sc.close();
	}
}

Measured memory_bytes: 24916
def is_prime(n):
    if n <= 1:
        return False
    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1
    return True

def main():
    X = int(input())
    while True:
        if is_prime(X):
            print(X)
            exit()
        X += 1

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
def solve():
    n, k = map(int, input().split())
    a_list = list(map(int, input().split()))
    if n == k:
        return 1
    k = k - 1
    ans = 0
    if k == 1:
        return n - 1
    if n % 2 == 1 and k == 2:
        return int((n - 1) / k)
    if n % k == 0:
        ans = int(n / k)
    else:
        ans = int(n / k) + 1
    return ans


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 13880
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from bisect import bisect_left

N = I()
S = str(input())
d = defaultdict(list)

for i in range(N):
    d[S[i]].append(i)

ans = 0
for i in range(1000):
    now = str(i).zfill(3)
    p = 0
    flag = True
    for j in now:
        p1 = bisect_left(d[j],p)
        if p1>=len(d[j]):
            flag = False
            break
        p = d[j][p1]+1
    if flag:
        ans += 1

print(ans)

Measured memory_bytes: 43244
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef long long ll;
typedef priority_queue<int> pq;
int main(void) {
    int maxi = -1;
    int N, ans=0;
    cin >> N;
    rep(i, N){
        int a;
        cin >> a;
        maxi = max(maxi, a);
        ans += a;
    }
    cout << ans - (maxi/2) << endl;
}

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int a, b;cin >> a >> b;

  int ans = a / b;
  if(ans * b == a) cout << ans << endl;
  else cout << ans + 1 << endl;
}


/*





















*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e+9
#define MOD (int)1e9+7
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void){
    int N; cin >> N;
    int d[100];
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    sort(d, d + N);
    int res = 1;
    for(int i = 0; i < N - 1; i++){
        if(d[i] < d[i + 1]){
            res++;
        }
    }

    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	int N,S;
	scanf("%d %d",&N,&S);

	int* table = new int[N];

	for(int i = 0; i < N; i++)scanf("%d",&table[i]);

	int ans = BIG_NUM,left = 0,right = 0,tmp_sum = 0;

	while(true){
		while(true){
			tmp_sum += table[right];
			if(tmp_sum >= S){
				break;
			}else if(right == N-1){
				break;
			}
			right++;
		}
		if(tmp_sum < S)break;

		while(true){
			ans = min(ans,right-left+1);
			tmp_sum -= table[left];
			left++;
			if(tmp_sum < S){
				break;
			}else if(left == right+1){
				break;
			}
		}
		if(ans == 1 || left == N || right == N-1)break;
		right += 1;
	}

	if(ans == BIG_NUM){
		printf("0\n");
	}else{
		printf("%d\n",ans);
	}

	return 0;
}

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

using namespace std;

int n, m, sx, sy, tx, ty;
int x[1005][1005];
char y[1005][1005];
deque<pair<int, int>> q;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int main() {
	scanf("%d%d%d%d%d%d", &n, &m, &sx, &sy, &tx, &ty);
	for (int i = 1; i <= n; i++)
		scanf("%s", y[i] + 1);
	x[sx][sy] = 1;
	q.emplace_back(sx, sy);
	while (!q.empty()) {
		tie(sx, sy) = q.front();
		q.pop_front();
		for (int i = 0; i < 4; i++) {
			int ta = sx + dx[i];
			int tb = sy + dy[i];
			if (y[ta][tb] == '.' && (!x[ta][tb] || x[sx][sy] < x[ta][tb])) {
				x[ta][tb] = x[sx][sy];
				q.emplace_front(ta, tb);
			}
		}
		for (int i = sx - 2; i <= sx + 2; i++)
			for (int j = sy - 2; j <= sy + 2; j++) {
				if (y[i][j] == '.' && !x[i][j]) {
					x[i][j] = x[sx][sy] + 1;
					q.emplace_back(i, j);
				}
			}
	}
	// for (int i = 1; i <= n; i++) {for (int j = 1; j <= m; j++) printf("%d", x[i][j]); puts("");}
	printf("%d\n", x[tx][ty] ? x[tx][ty] - 1 : -1);
}

Measured memory_bytes: 8768
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	ll a,b,c;
	scanf("%lld %lld.%lld",&a,&b,&c);
	ll ans = a*(b*100+c) ;
	ans /= 100LL;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3728
N=int(input())
P=list(map(int,input().split()))

num=P[0]
ans=1
for i in range(1,N):
    if num>=P[i]:
        ans+=1
        num=P[i]
print(ans)
'''
re=1
for i in range(1,N):
    if P[i]<=P[i-1]:
        print(P[i],P[i-1])
        re+=1
print(re)
'''

Measured memory_bytes: 24744
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 100005;
int n,a,p[MX],c;
bool f1=true,f2;
P as[2][MX];
int find(int x){return (p[x] < 0 ? x : p[x] = find(p[x]));}
void uni(int x, int y){
	x = find(x); y = find(y);
	if(x != y){
		if(p[x] > p[y]) swap(x, y);
		p[x] += p[y];
		p[y] = x;
	}else c++;
}
int main(){
	scanf("%d", &n);
	rep(o,2){
		rep(i,n){
			scanf("%d", &a);
			as[o][i] = {a,i};
		}
		sort(as[o],as[o]+n);
	}
	rep(i,n){
		if(as[0][i].first>as[1][i].first) f1=false;
		if(i&&as[0][i].first<=as[1][i-1].first) f2=true;
	}
	fill(p, p+n, -1);
	rep(i,n) uni(as[0][i].second,as[1][i].second);
	puts(f1&&(f2||c>1) ? "Yes" : "No");
}

Measured memory_bytes: 2176
#include <stdio.h>

int main(void) {
  int x, y;
  scanf ("%d %d", &x, &y);
  while (!(x == 0 && y == 0)) {
    if(x < y) printf ("%d %d\n", x, y);
    else printf ("%d %d\n", y, x);
    scanf ("%d %d", &x, &y);
  }
  return 0;
}



Measured memory_bytes: 2052
/**
 * ??????????????????
??????????????????????????????????????¨?????????????????????Bubble???????°´??¢???????????£???????????????????????????????´??????????????????????????????????????????????????¬???????????????¢?????´???????????§??°????????????????????????????????????

1 bubbleSort(A, N) // N ??????????´?????????? 0-????????????????????? A
2   flag = 1 // ????????£??\????´?????????¨??????
3   while flag
4     flag = 0
5     for j ??? N-1 ?????? 1 ?????§
6       if A[j] < A[j-1]
7         A[j] ??¨ A[j-1] ?????????
8         flag = 1
??°??? A
??????????????????????????????????????§?????????????????????????????????????????°?????????????????????????????????????????????????????????????????§????????????????´???????????????°?????±????????????????????????

??\???
??\??????????????????????????°?????????????????¨?????´??° N ???????????????????????????????????????N
????????´??°????????????????????§?????????????????????

??????
????????? 2 ??????????????????????????????????????´??????????????°?????? 1
???????????????????????????????????°????????£?¶???????????´?????????????????????§????????£??????????????????????????????2
????????????????????°??????????????????????????????

??¶?´?
1 ??? N ??? 100
0 ??? A ???????´? ??? 100
??\?????? 1
5
5 3 2 4 1
????????? 1
1 2 3 4 5
8

??\?????? 2
6
5 2 4 6 1 3
????????? 2
1 2 3 4 5 6
9
 */

#include <iostream>
#include <sstream>

void printArray(unsigned int Array[], unsigned int length) {
  std::ostringstream oss;
  for (size_t i = 0; i < length - 1; i++) {
    oss << Array[i] << " ";
  }
  oss << Array[length - 1];
  std::cout << oss.str() << std::endl;
}

unsigned int bubbleSort(unsigned int *A, unsigned int N) {
  // N ??????????´?????????? 0-????????????????????? A
  int flag = 1; // ????????£??\????´?????????¨??????
  unsigned int count = 0;
  while (flag) {
    flag = 0;
    for (size_t j = N - 1; j >= 1; j--) {
      if (A[j] < A[j - 1]) {
        std::swap(A[j], A[j - 1]);
        flag = 1;
        count++;
      }
    }
  }
  return count;
}

int main(int argc, char const *argv[]) {
  unsigned int N = 1;
  std::string param;

  while (true) {

    getline(std::cin, param);
    std::istringstream iss(param);
    iss >> N;

    if (N < 1 || N > 100) {
      std::cout << "Error: 1 <= N <= 100" << std::endl;
    } else {
      break;
    }
  }
  unsigned int A[N];

  while (true) {
    bool isValid = true;

    getline(std::cin, param);
    std::istringstream iss(param);
    for (size_t i = 0; i < N; i++) {
      iss >> A[i];
      if (A[i] > 100) {
        std::cout << "Error: 1 <= A <= 100" << std::endl;
        isValid = false;
        break;
      }
    }
    if (isValid == true) {
      break;
    }
  }

  unsigned int count = bubbleSort(A, N);

  printArray(A, N);
  std::cout << count << std::endl;
  
  return 0;
}

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

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

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

  bool ok = true;
  if (N % 2 == 1 && A[0] != 1) ok = false;
  for (int i = 1; i < N; i++) {
    if (N % 2 == 0 && i % 2 == 1 && A[i] != 2) ok = false;
    if (N % 2 == 1 && i % 2 == 0 && A[i] != 2) ok = false;
  }
  if (!ok) {
    cout << 0 << '\n';
    return 0;
  }

  ll ans = 1;
  ll MOD = 1e9 + 7;
  for (int i = 0; i < N / 2; i++) {
    ans = (ans * 2) % MOD;
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    char alpha;
    cin >> alpha;
    if (alpha >= 'a' && alpha <= 'z') cout << "a" << endl;
    else if (alpha >= 'A' && alpha <= 'Z') cout << "A" << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int p[N];
  int i = 0;
  while (i < N) {
    cin >> p[i++];
  } 
  sort(p, p+N);
  cout << accumulate(p, p+K, 0) << endl;;
  return 0;
}


Measured memory_bytes: 3572
N = int(input())
A = [int(i) for i in input().split(" ")]
B = [int(i) for i in input().split(" ")]
C = [int(i) for i in input().split(" ")]

A.append(-1)
manzoku = 0
for i in range(N):
    num_dish = A[i] - 1
    manzoku += B[num_dish]
    if A[i+1] == A[i] + 1:
        manzoku += C[num_dish]

print(manzoku)        

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define pb push_back
#define pf push_front
#define Mid ((l+r)/2)
#define pi pair<int,int>
#define pii pair<pi,int>
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll g(ll x){
    return x*x*x*x*x;
}
int main()
{
    go;
    ll X;
    cin>>X;
    for(ll A=-2000;A<=2000;A++)
    {
        for(ll B=-2000;B<=2000;B++)
        {
            if(g(A)-g(B)==X)
                return cout<<A<<" "<<B,0;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
using System;using static System.Console;class P{static void Main(){for(var s=ReadLine();s!="-";s=ReadLine()){var h=0;for(int i=0,m=int.Parse(ReadLine());i<m;i++)h+=int.Parse(ReadLine());WriteLine((s+s).Substring(h%s.Length,s.Length));}}}


Measured memory_bytes: 15960
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl

int main() {
    int n;
    while (cin >> n) {
        vector<int> a(n);
        for (int& p : a) cin >> p;
        vector<int> b(n, -1), c(n, n);
        unordered_map<int, int> mp;
        for (int i = 0; i < n; ++i)
            mp[a[i]] = i;
        int mx = 1;
        int cr = -1;
        int ct = 0;
        for (int i = 1; i <= n; ++i) {
            int j = mp[i];
            if (cr < j) {
                cr = j;
                ++ct;
            } else {
                cr = j;
                ct = 1;
            }
            mx = max(mx, ct);
        }
        cout << n - mx << endl;
    }
    return 0;
}


Measured memory_bytes: 11124
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;
  

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    string res;
    if (a + b + c >= 22) res = "bust";
    else res = "win";

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


Measured memory_bytes: 256
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};



int main(){
    IOS;
    make2(ll,n,x);
    makevec(ll,a,n);
    ll ans=0;
    for(ll i=1;i<n;i++){
        ans+=min(x,a[i]-a[i-1]);
    }
    cout<<ans+x<<endl;



    return 0;
}


Measured memory_bytes: 4708
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(void) {
  int n;
  int a[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  sort(a, a + n, greater<int>());
  int alice, bob;
  alice = bob = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      alice += a[i];
    } else {
      bob += a[i];
    }
  }
  cout << alice - bob << endl;
  return EXIT_SUCCESS;
}



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

int main(){
  ll n,k;
  cin >> n >> k;
  ll a = n/k;
  ll b = n - (k*a);
  ll c = -(n - (k*(a+1)));
  ll ans = min(b,c);
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define end "\n"
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod =1e9+7;
const int N = (int)2e5 + 5;


void solve(){
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[0]+a[1];


}
int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long int 
using namespace std;


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	double a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<(ceil(c/b)<=ceil(a/d)?"Yes":"No");
	
	return 0; 
}

Measured memory_bytes: 3688
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static int dishCount;

	static int oneSushiDishCount;
	static int twoSushiDishCount;
	static int threeSushiDishCount;

	// 確率を保持
	static double[][][] dp;

	static Set<DishSituation> firstSet = new HashSet<>();

	static Set<DishSituation> secondSet = new HashSet<>();

	static double result;

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		dishCount = scan.nextInt();

		for (int i = 0; i < dishCount; i++) {

			int sushiType = scan.nextInt();

			if (sushiType == 1) {

				oneSushiDishCount++;

			} else if (sushiType == 2) {

				twoSushiDishCount++;

			} else if (sushiType == 3) {

				threeSushiDishCount++;
			}
		}

		dp = new double[dishCount + 1][dishCount + 1][dishCount + 1];

		dp[oneSushiDishCount][twoSushiDishCount][threeSushiDishCount] = 1;

		firstSet.add(new DishSituation(oneSushiDishCount, twoSushiDishCount, threeSushiDishCount));

		while (firstSet.size() != 0) {

			for (DishSituation target : firstSet) {

				dpMethod(target.oneSushiDish, target.twoSushiDish, target.threeSushiDish);
			}

			firstSet.clear();
			firstSet.addAll(secondSet);
			secondSet.clear();
		}

		println(result);

	}

	public static void dpMethod(int one, int two, int three) {

		double dpValue = dp[one][two][three];
		int total = one + two + three;
		double parameter = total / dpValue;

		if (total != 0) {

			if (0 < three) {

				dp[one][two + 1][three - 1] += (double) three / parameter;

				secondSet.add(new DishSituation(one, two + 1, three - 1));
			}

			if (0 < two) {

				dp[one + 1][two - 1][three] += (double) two / parameter;

				secondSet.add(new DishSituation(one + 1, two - 1, three));
			}

			if (0 < one) {

				dp[one - 1][two][three] += (double) one / parameter;

				secondSet.add(new DishSituation(one - 1, two, three));
			}

			result += (double) dishCount / parameter;
		}
	}

	public static void println(Object target) {
		System.out.println(target);
	}

	public static class DishSituation {

		public int oneSushiDish = 0;
		public int twoSushiDish = 0;
		public int threeSushiDish = 0;

		public DishSituation(int oneSushiDish, int twoSushiDish, int threeSushiDish) {

			this.oneSushiDish = oneSushiDish;
			this.twoSushiDish = twoSushiDish;
			this.threeSushiDish = threeSushiDish;
		}

		@Override
		public boolean equals(Object obj) {

			DishSituation target = (DishSituation) obj;

			return this.oneSushiDish == target.oneSushiDish
					&& this.twoSushiDish == target.twoSushiDish
					&& this.threeSushiDish == target.threeSushiDish;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + oneSushiDish;
			result = prime * result + twoSushiDish;
			result = prime * result + threeSushiDish;
			return result;
		}
	}
}


Measured memory_bytes: 527232
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;

namespace ARC65_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var c = Console.ReadLine().ToCharArray();
            Array.Reverse(c);
            string s = new String(c);
            while (s.Length != 0)
            {
                string x = s.Substring(0, 5);
                if (x == "maerd") s = s.Substring(5);
                else if (x == "esare") s = s.Substring(5);
                else if (x + s[5] == "resare") s = s.Substring(6);
                else if (x + s[5] + s[6] == "remaerd") s = s.Substring(7);
                else break;
            }

            Console.WriteLine(s.Length == 0 ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 29444
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int ans=0;
    if(c*2<=a+b){
        int c_num=min(x,y)*2;
        ans+=c*c_num;
        int x_num=x-min(x,y);
        int y_num=y-min(x,y);
        ans+=a*x_num+b*y_num;
        ans=min(ans,c*max(x,y)*2);
    }else{
        ans+=x*a+y*b;
    }
    cout << ans << endl;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int N, M;
vector<int> Edge[MAX_N];
int inCnt[MAX_N];

bool leaf[MAX_N];
int level[MAX_N];
bool used[MAX_N];

void solve(int pos, int l)
{
  level[pos] = max(level[pos], l);
  l = max(l, level[pos]);

  if(Edge[pos].size() == 0) {
    leaf[pos] = true;
    return;
  }

  for(int next : Edge[pos]) {
    if(inCnt[next]==1) {
      solve(next, l+1);
    } else {
      inCnt[next]--;
      level[next] = max(level[next], l+1);
    }
  }
}

vector<int> newEdge[MAX_N];
int ansList[MAX_N];

void solve2(int pos)
{
  used[pos] = true;
  for(int next : Edge[pos]) {
    if(level[pos]+1 == level[next]) {
      newEdge[pos].push_back(next);
      ansList[next] = pos+1;
    }
    if(!used[next])
      solve2(next);
  }
}

signed main()
{
  memset(level,-1,sizeof(level));

  cin >> N >> M;
  REP(n,N+M-1) {
    int a,b; cin >> a >> b; a--; b--;
    Edge[a].push_back(b);
    inCnt[b]++;
  }

  int root = -1;
  REP(n,N) {
    if(inCnt[n] == 0) {
      root = n;
      break;
    }
  }

  solve(root, 0);
  solve2(root);

  // REP(n,N) {
  //   cerr << n+1 << " " << level[n] << endl;
  // }

  REP(n,N) {
    if(n == root) {
      cout << 0 << endl;
    } else {
      cout << ansList[n] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 20480
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int x = Integer.parseInt(br.readLine());
		System.out.println(x*x*x);
	}

}



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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 5e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

int n, Q;
string s;
bitset<26> t[4*MAX_N];

void build(int v, int l, int r) {
    if (l == r) {
        int x = s[l] - 'a';
        t[v][x] = true;
        return;
    }
    int mid = (l+r) / 2;
    build(2*v, l, mid);
    build(2*v+1, mid+1, r);

    t[v] = t[2*v] | t[2*v+1];
}

void update(int v, int l, int r, int pos, int x) {
    if (l == pos && r == pos) {
        t[v].reset();
        t[v][x] = true;
        return;
    }
    if (l > pos || r < pos) return;
    int mid = (l+r) / 2;
    update(2*v, l, mid, pos, x);
    update(2*v+1, mid+1, r, pos, x);

    t[v] = t[2*v] | t[2*v+1];
}

bitset<26> query(int v, int l, int r, int qL, int qR) {
    if (qL <= l && r <= qR) {
        return t[v];
    }
    if (l > qR || r < qL) {
        bitset<26> b;
        b.reset();
        return b;
    }
    int mid = (l+r) / 2;
    bitset<26> leftSub = query(2*v, l, mid, qL, qR);
    bitset<26> rightSub = query(2*v+1, mid+1, r, qL, qR);

    return (leftSub | rightSub);
}


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

    cin >> n >> s >> Q;
    n++;
    s = '#' + s;
    build(1, 1, n);

    for (int i = 0; i < Q; i++) {
        int type; cin >> type;
        if (type == 1) {
            int pos;
            char c;
            cin >> pos >> c;
            int which = c-'a';
            update(1, 1, n, pos, which);
        } else {
            int l, r;
            cin >> l >> r;
            cout << query(1, 1, n, l, r).count() << "\n";
        }
    }










    return 0;
}


Measured memory_bytes: 11184
#include<stdio.h>

int main()
{
    int n,i,n1[100];
    float ans=0;

    scanf("%d",&n);

    for(i=0;i<n;i++)
    {
        scanf("%d",&n1[i]);
    }

        for(i=0;i<n;i++)
    {
        ans=ans+(float)1/n1[i];
    }

    ans=(float)1/ans;

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

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
int d[100010];
int ans;
signed main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&d[i]),d[i]-=m;
	ans=abs(d[1]);
	for(int i=2;i<=n;i++) ans=__gcd(ans,abs(d[i]));
	printf("%lld",ans);
	return 0;
	
}

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  int k,s; cin >> k >> s;
  int ans=0;
  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;
    }
  }
  cout << ans << '\n';

  return;
}

signed main() {
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3644
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int i = saori.saori_hayami();
		System.out.println(n-i+1);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	string s;
	cin >> s;

	vector<int> v[10];
	rep(i, n){
		int x = s[i] - '0';
		v[x].push_back(i);
	}

	int lef[n];
	set<int> st;
	rep(i, n){
		st.insert(s[i] - '0');
		lef[i] = st.size();
	}

	st.erase(st.begin(), st.end());

	int rig[n];
	rep(i, n){
		st.insert(s[n - i - 1] - '0');
		rig[n - i - 1] = st.size();
	}

	ll ans = 0;
	for(int i = 1; i <= n - 2; i++){
		int x = s[i] - '0';

		auto itr = lower_bound(v[x].begin(), v[x].end(), i);
		if(itr == v[x].begin()){
			ans += (ll) lef[i-1] * rig[i+1];
		}else{
			itr--;
			if(*itr > 0){
				ans += (ll) (lef[i-1] - lef[*itr-1]) * rig[i+1];
			}else{
				ans += (ll) lef[i-1] * rig[i+1];
			}

		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 768
//
//  main.cpp
//  619
//
//  Created by 8595198919 on 14/06/16.
//  Copyright (c) 2014年 8595198919. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;

int dist[105];
queue<int> que;
vector<int> G[105];
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        dist[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    que.push(1);
    dist[1]=0;
    while(!que.empty()){
        int now = que.front();
        que.pop();
        int d = dist[now];
        rep(i,G[now].size()){
            if(dist[G[now][i]]==-1){
                dist[G[now][i]]=d+1;
                que.push(G[now][i]);
            }
        }
    }
    for(int i = 1;i <= n;i++) {
        cout <<i <<" " << dist[i]<<endl;
    }
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000 //1e16
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int n,m,t,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U; 
    // int a,b;
    cin>>n>>k;
    while(n)
    {
        n/=k;
        count++;
    }
    cout<<count;
}
 

signed main()
{

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3612
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse4,sse4.2,popcnt,abm,mmx,avx")
#endif
#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

const int MOD = round(1e9 + 7);

int power(int base, int p) {
  if (p == 0) return 1;
  int res = power(base, p / 2);
  res = 1LL * res * res % MOD;
  if (p & 1) {
    res = 1LL * res * base % MOD;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n;
  cin >> n;
  int res = power(10, n);
  res = (res - power(9, n) + MOD) % MOD;
  res = (res - power(9, n) + MOD) % MOD;
  res = (res + power(8, n)) % MOD;
  res = (res % MOD + MOD) % MOD;
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3624
import sys
from collections import deque


def main():
    n, m = map(int, sys.stdin.readline().split())

    out_list = [[] for _ in range(n + 1)]
    in_cnt = [0] * (n + 1)
    in_cnt[0] = -1
    for _ in range(n - 1 + m):
        a, b = map(int, sys.stdin.readline().split())
        out_list[a].append(b)
        in_cnt[b] = in_cnt[b] + 1
    root = in_cnt.index(0)
    ans = [0] * (n + 1)
    que = deque([root])

    while que:
        p = que.popleft()
        for i in out_list[p]:
            in_cnt[i] = in_cnt[i] - 1
            if in_cnt[i] == 0:
                que.append(i)
                ans[i] = p

    for i in ans[1:]:
        print(i)


if __name__ == "__main__":
    main()

Measured memory_bytes: 21564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
#define db1(a) cerr<<(a)<<endl;
#define db2(a,b) cerr<<(a)<<" "<<(b)<<endl;
#define db3(a,b,c) cerr<<(a)<<" "<<(b)<<" "<<(c)<<endl;
#define db4(a,b,c,d) cerr<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl;
#define db5(a,b,c,d,e) cerr<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl;

vector<vector<int>> v(100010);
ll mod;

vector<ll> dp(100010);
vector<vector<ll>> prf(100010);

void dfs(int p,int pre){
    dp[p] = 1;
    for(auto i:v[p]){
        if(i!=pre){
            dfs(i,p);
            dp[p] = (dp[p] * (dp[i]+1)) % mod;
        }
    }
}

ll ans[100010];

void solve(int p,int pre,ll d){
    ans[p] = (d+1)%mod;
    ans[p] *= dp[p];
    ans[p] %= mod;
    int m = v[p].size();
    ll c1[m+1]={}, c2[m+1]={};
    c1[0]=d+1;
    c2[m]=1;
    for(int i=0;i<m;i++){
        if(v[p][i] == pre){
            c1[i+1] = c1[i];
        }
        else{
            c1[i+1] = c1[i] * (dp[v[p][i]]+1) % mod;
        }
        if(v[p][m-1-i] == pre){
            c2[m-1-i] = c2[m-i];
        }
        else{
            c2[m-i-1] = c2[m-i] * (dp[v[p][m-i-1]]+1) % mod;
        }
    }
    for(int i=0;i<m;i++){
        if(v[p][i] == pre) continue;
       // db4(p,v[p][i],c1[i],c2[i+1]);
        ll ret = c1[i] * c2[i+1];
        ret %= mod;
        solve(v[p][i],p,ret);
    }
}

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

    int n;
    cin>>n>>mod;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(0,n);
    solve(0,n,0);
    for(int i=0;i<n;i++) cout << ans[i] << "\n";


}

Measured memory_bytes: 23168
n = int(input())
A = list(map(int, input().split()))
count = 0


def merge(A, l, m, r):
    L = A[l:m] + [10 ** 9 + 1]
    R = A[m:r] + [10 ** 9 + 1]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global count
    count += r - l


def mergeSort(A, l, r):
    if r - l > 1:
        m = (l + r) // 2
        mergeSort(A, l, m)
        mergeSort(A, m, r)
        merge(A, l, m, r)


mergeSort(A, 0, n)
print(" ".join(list(map(str, A))))
print(count)



Measured memory_bytes: 66772
n=int(input())
i=0

if(n==0):
    print(0)
elif(n>0):
    tmp=1
    mainasu=0
    i=1
    while(tmp < n):
        tmp+=4**i
        mainasu-=2*4**(i-1)
        i+=1
    x=bin(n-mainasu)
    for i in range(2,len(x)):
        if(i%2==1):
            if(x[i]=="1"):
                print("0",end="")
            else:
                print("1",end="")
        else:
            print("{}".format(x[i]),end="")
    print()
else:
    tmp=-2
    mainasu=1
    i=1
    while(n < tmp):
        tmp-=2*4**i
        mainasu+=4**i
        i+=1
    x=bin(mainasu-n)
    for i in range(2,len(x)):
        if(i%2==1):
            if(x[i]=="1"):
                print("0",end="")
            else:
                print("1",end="")
        else:
            print("{}".format(x[i]),end="")
    print()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;

#define endl "\n"

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	ll r,d,x;
	cin>>r>>d>>x;
	int t=10;
	while(t--){
		x=r*x-d;
		cout<<x<<endl;
	}
	return 0;
}

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

#define int long long int
#define fi first
#define so second
#define pii pair<int,int>
#define ps push_back
#define TT int tt;cin>>tt;for(int cc=1;cc<=tt;cc++)

int ans,k,n,m;

signed main()
{
    int n,i,j,k;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    for(i=0;i<n/2;i++) swap(a[i],a[n-i-1]);
    int sum=a[0];
    k=0;
    j=1;
    for(i=2;i<n;i++)
    {
        
        sum+=a[j];
        k++;
        if(k==2) {k=0;j++;}
    }
    cout<<sum;
}


Measured memory_bytes: 5208
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <functional>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, m, h, w, a, b, sum = 0, ans = 0;
  scanf("%lld%lld", &n, &m);
  printf("%.12f", (double)n / m);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")`  

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    if (s[1] == 'B') s[1] = 'R';
    else s[1] = 'B';
    cout << s;
}
/*

*/  


Measured memory_bytes: 3640
/*****include*****/
#include <iostream>
#include <fstream>
#include <string>
/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	string order;
	int baseman[4];
	int point;
	int out_count;
	/*****処理部*****/
	int n;
	cin >> n;
	for(int loop = 0;loop<n;loop++){
		point = 0;
		out_count=0;
		for(int i=0;i<4;i++){
			baseman[i] = 0;
		}
		while(out_count != 3){
			baseman[0] = 1;
			cin >> order;
			if(order == "HIT"){
				if(baseman[3] == 1)	point++;
				for(int i=3;i>0;i--){
					baseman[i] = baseman[i-1];
				}
			}else if(order == "OUT"){
				out_count++;
			}else if(order == "HOMERUN"){
				for(int i=0;i<4;i++){
					if(baseman[i] == 1)	point++;
					baseman[i] = 0;
				}
			}
		}
		cout << point << endl;
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

// nのk乗をmで割った余り(n^k(mod m))を求める
ll pow_mod(ll n, ll k, ll m){
    if(k == 0){
        return 1;
    }
    else if(k % 2 == 1){
        return pow_mod(n, k-1, m) * n % m;
    }
    else{
        ll t = pow_mod(n, k/2, m);
        return t * t % m;
    }
}

int main(void)
{
    long long n, a, b, i, ans, x=1, y=1;

    cin >> n >> a >> b;

    ans = pow_mod(2,n,div1)-1;

    for(i=n-a+1; i<=n; i++){
        x *= i;
        x %= div1;
    }
    for(i=1; i<=a; i++){
        y *= i;
        y %= div1;
    }
    y = pow_mod(y,div1-2,div1);

    a = x*y%div1;

    x = 1; y = 1;

    for(i=n-b+1; i<=n; i++){
        x *= i;
        x %= div1;
    }
    for(i=1; i<=b; i++){
        y *= i;
        y %= div1;
    }
    y = pow_mod(y,div1-2,div1);

    b = x*y%div1;

    ans = ans-a-b;
    ans %= div1;
    if(ans<0) ans+=div1;

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256