akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rept(i,k,n) for(ll i = (k); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;
typedef tuple<int,int,int> Tii;

ll mod=1e9+7;

long long powm(long long a, long long b, long long mod=1000000007){
    if(b<0) b+=mod-1;
    if(b>0){
        if(b%2==1) return a*powm(a*a%mod,b/2)%mod;
        else return powm(a*a%mod,b/2)%mod;
    }else{
        return 1;
    }
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}


int main(){
    ll k,l;
    string s;
    cin>>k>>s;
    l=s.size();
    vector<ll> x25(l+k+1,1),x26(l+k+1,1),con(l+k+1,1);
    rept(i,1,l+k+1){
        x25[i]=x25[i-1]*25%mod;
        x26[i]=x26[i-1]*26%mod;
    }
    rept(i,l-1,l+k){
        con[i+1]=((con[i]*(i+1))%mod)*modinv(i+2-l,mod)%mod;
    }
    ll sum=0;
    rept(i,l,l+k+1){
        sum+=con[i-1]*x25[i-l]%mod*x26[l+k-i]%mod;
        sum%=mod;
    }
    cout<<sum<<endl;
   // cout<<x25<<x26<<con<<endl;
    return 0;
}



Measured memory_bytes: 51172
#include <stdio.h>
#include <math.h>

int main()
{
    int dice[7]={},cpy[7]={},i;
  
    for(i=1;i<=7;i++)
        scanf("%d",&dice[i]);
       
    
        char str[1000];
        scanf("%s",str);
        int n;
        n=strlen(str);
        int cnt=0;
    
    
   
    
    while(cnt<n){
        char a;
        for(i=1;i<=7;i++)
            cpy[i]=dice[i];
        
        if(str[cnt]=='E')
        {
            dice[1]=cpy[4];
            dice[2]=cpy[2];
            dice[3]=cpy[1];
            dice[4]=cpy[6];
            dice[5]=cpy[5];
            dice[6]=cpy[3];
        }
        if(str[cnt]=='W')
        {
            dice[1]=cpy[3];
            dice[2]=cpy[2];
            dice[3]=cpy[6];
            dice[4]=cpy[1];
            dice[5]=cpy[5];
            dice[6]=cpy[4];
        }if(str[cnt]=='S')
        {
            dice[1]=cpy[5];
            dice[2]=cpy[1];
            dice[3]=cpy[3];
            dice[4]=cpy[4];
            dice[5]=cpy[6];
            dice[6]=cpy[2];
        }if(str[cnt]=='N')
        {
            dice[1]=cpy[2];
            dice[2]=cpy[6];
            dice[3]=cpy[3];
            dice[4]=cpy[4];
            dice[5]=cpy[1];
            dice[6]=cpy[5];
        }
        cnt++;
    }
    
    printf("%d\n",dice[1]);
}


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

int main()
{
    int n;
    cin >> n;
    int d1[n], d2[n];
    for (int i = 0; i < n; i++)
    {
        cin >> d1[i];
        cin >> d2[i];
    }
    int count = 0, flag = 0;
    for (int i = 0; i < n; i++)
    {
        if (d1[i] == d2[i])
        {
            count++;
        }
        else
        {
            count = 0;
        }
        if (count == 3)
        {
            flag = 1;
            cout << "Yes";
            break;
        }
    }
    if (flag == 0)
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 3572
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    S = input()
    c = Counter(S)
    n, w, s, e = c["N"], c["W"], c["S"], c["E"]
    if n == s or (n != 0 and s != 0):
        if w == e or (w != 0 and e != 0):
            print("Yes")
            return
    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n,q; cin >> n >> q;
    string s; cin >> s;
    int l[n] = {0};
    int r[n] = {0};
    for(int i=0; i<q; i++){
        cin >> l[i] >> r[i];
    }
    int p[n] = {0};
    for(int i=0; i<n-1; i++){
        p[i+1] = p[i] + (s[i]=='A'&&s[i+1]=='C'?1:0);
    }
    for(int i=0; i<q; i++){
        cout << p[r[i]-1] - p[l[i]-1] << "\n";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2176
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

public class Program {
    public static void Main() {
        var n = ReadLib.ReadAsInt();
        var moths = new Queue<int>(ReadLib.ReadAsIntArray().OrderByDescending(i => i));

        var score = 0;
        while (moths.Count >= 2) {
            moths.Dequeue();
            score += moths.Dequeue();
        }

        Console.WriteLine(score);
    }
}

static class ReadLib {
    public static long ReadAsLong() {
        return long.Parse(Console.ReadLine());
    }

    public static int ReadAsInt() {
        return int.Parse(Console.ReadLine());
    }

    public static int[] ReadAsIntArray() {
        return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9,MOD = 1e9+7,ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,v[ohara],dp[55][55];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

ll comb(ll nn,ll k){
    if(nn<k)return 0;
    if(dp[nn][k]!=0)return dp[nn][k];
    if(k==0)return dp[nn][k]=1;
    if(nn==k)return dp[nn][k]=1;
    return dp[nn][k]=comb(nn-1,k-1)+comb(nn-1,k);
}

int main(void){
    cin>>n>>a>>b;
    map<ll,ll> kosuu;
    rep(i,n)cin>>v[i],kosuu[v[i]]++;
    set<ll> st;
    sort(v,v+n);
    reverse(v,v+n);
    rep(i,a){
        st.insert(v[i]);
        ans+=v[i];
        cmp=v[i];
    }
    printf("%.15f\n",(double)ans/a);
    if(Size(st)==1){
        ans=0;
        ans+=comb(kosuu[v[0]],a);
        rrep(i,a,b){
            st.insert(v[i]);
            if(Size(st)>=2)break;
            ans+=comb(kosuu[v[0]],i+1);
        }
        Cout(ans);
    }
    else{
        ll need=a;
        rep(i,a){
            if(cmp!=v[i])need--;
        }
        Cout(comb(kosuu[cmp],need));
    }
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {

    val bingo = Array(3) { readLine()!!.split(" ").map(String::toInt) }
    val input = Array(readLine()!!.toInt()) {
        readLine()!!.toInt()
    }

    var flg = false
    for (h in 0..2) {
        flg = flg || bingo[h].all { input.contains(it) }
    }

    for (w in 0..2) {
        flg = flg || intArrayOf(bingo[0][w], bingo[1][w], bingo[2][w]).all { input.contains(it) }
    }

    flg = flg || intArrayOf(bingo[0][0], bingo[1][1], bingo[2][2]).all { input.contains(it) }
    flg = flg || intArrayOf(bingo[2][0], bingo[1][1], bingo[0][2]).all { input.contains(it) }
    if (flg) {
        println("Yes")
    } else {
        println("No")
    }
}





Measured memory_bytes: 37900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 100;
ll a[maxn];
vector<ll>v;
int main(){
	ll n;
	cin >> n;
	if (n == 2) cout << 1 << endl, exit(0);
	ll x = n - 1;
	int cnt = 1;
	for (int i = 2; i <= sqrt(x); i++){
		if (x%i == 0&&(x/i)>sqrt(n)) cnt++;
	}
	for (int i = 2; i <= sqrt(n); i++){
		x = n;
		while (x%i == 0) x /= i;
		if (x%i == 1) cnt++;
	}
	cout << cnt+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return;
		int dp[(1 << 16)];
		REP(i, (1 << 16)) {
			dp[i] = 1e9;
		}
		dp[0] = 0;
		int costs[17][17] = {};
		REP(i, n) {
			REP(q, n + 1) {
				cin >> costs[i][q];
			}
		}
		REP(i, (1 << n)) {
			REP(q, n) {
				if (i & (1 << q)) continue;
				int now_cost = costs[q][0];
				REP(j, n) {
					if (i & (1 << j)) {
						now_cost = min(now_cost, costs[q][j + 1]);
					}
				}
				dp[i + (1 << q)] = min(dp[i + (1 << q)], dp[i] + now_cost);
			}
		}
		cout << dp[(1 << n) - 1] << endl;
	}
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3576
#include <stdio.h>

int main(int argc, char const *argv[]) {
    int N;
    //入力
    scanf("%d", &N);
    //出力
    if ( (N/1000) == 0 ) {
        printf("ABC\n");
    } else if ( (N/1000) == 1 ) {
        printf("ABD\n");
    } else {
        printf("ABE\n");
    }
    return 0;
}


Measured memory_bytes: 128
n = gets.strip.to_i
s=gets.strip

max_l = n
min_l = 0

until min_l +1 == max_l
#p [min_l, max_l]
  l = (max_l+min_l+1)/2
  memo = {}
  ok = false
  (s.length-l+1).times do |i|
    k = s[i..i+l-1]
    if !memo[k].nil?
      if memo[k]+l-1 < i
        ok=true
        break
      end
    else
      memo[k]=i
    end
  end

  if ok
    min_l = l
  else
    max_l = l
  end

end

p min_l

Measured memory_bytes: 20220
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

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

  unordered_map<int, vector<int>> path;
  unordered_map<int, bool> last;
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    path[a].push_back(b);
    if (b == N) last[a] = true;
  }

  if (path.find(1) != path.end()) {
    for (const auto mid: path[1]) {
      if (last.find(mid) != last.end()) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 13504
// AOJ 2920: Tea Party
// 2019.2.17 bal4u

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int N, a, sum, min;

	scanf("%d", &N);
	sum = 0, min = 101;
	while (N--) {
		scanf("%d", &a);
		sum += a;
		if ((a & 1) && a < min) min = a;
	}
	if (sum & 1) sum -= min;
	printf("%d\n", sum / 2);
	return 0;
}



Measured memory_bytes: 2056
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long LL;

string s,t;
LL n,K,ans = 0;
LL dp[305][305][305];

int main(){
	cin >> s; n = s.length();
	t = s; reverse(t.begin(),t.end());
	s = ' ' + s; t = ' ' + t;
	cin >> K;
	
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= n;j ++){
			for(LL k = 0;k <= K;k ++){
				dp[i][j][k] = max(dp[i - 1][j][k],dp[i][j - 1][k]);
				if(k) dp[i][j][k] = max(dp[i][j][k],dp[i - 1][j - 1][k - 1] + 1);
				if(s[i] == t[j]) dp[i][j][k] = max(dp[i][j][k],dp[i - 1][j - 1][k] + 1);
//				cout << i << ' ' << j << ' ' << k << ' ' << dp[i][j][k] << '\n';
			}
		}
	}
	for(LL i = 1;i <= n;i ++){
		ans = max(ans,dp[i][n - i][K] << 1);
		ans = max(ans,(dp[i][n - i - 1][K] << 1) + 1);
//		cout << dp[i][n - i][K] << ' ' << dp[i][n - i - 1][K] << endl;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 219188
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll cntt1 = c / b, cntt2 = c % b;
    ll cnta1 = a / d, cnta2 = a % d;
    if (cntt2 > 0) {
        cntt1++;
    }
    if (cnta2 > 0) {
        cnta1++;
    }
    if (cntt1 <= cnta1) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
import math
from collections import Counter
n, p = [int(_) for _ in input().split()]

def isprime_alpha(n):
    if n == 1:
        return True
    elif n == 2:
        return True
    elif n == 3:
        return True
    elif n % 2 == 0 or n % 3 == 0:
        return False
    else:
        for j in range(5, math.ceil(n ** (1/2))+1):
            if n % j == 0:
                return False
        return True

def factor(n, fac_list):
    if isprime_alpha(n):
        fac_list.append(n)
        return fac_list
    else:
        for i in range(2, math.ceil(n ** (1/2))+1):
            if n % i == 0:
                fac_list.append(i)
                return factor(n // i, fac_list)

list = []
list_result = factor(p, list)
counter_dict = Counter(list_result)

result = 1
for key, value in counter_dict.items():
    if value % n != 0:
        value -= value % n
    for j in range(value // n):
        result *= key

print(result)

Measured memory_bytes: 3316
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

long long modpow(long long x, long long n, long long mod) {
    if (n == 0) return 1;
    long long res = modpow(x * x % mod, n / 2, mod);
    if (n & 1) res = res * x % mod;
    return res; 
}

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

void solve() {
    int N; string X;
    cin >> N >> X;

    int popcount = 0;
    for (int i = 0; i < N; i++) {
        if (X[i] == '1') popcount++;
    }

    int popcount_plus = popcount + 1;
    int popcount_minus = popcount - 1;

    int mod_plus = 0;
    int mod_minus = 0;

    for (int i = 0; i < N; i++) {
        if (popcount_minus <= 0) break;
        if (X[i] == '1') {
            mod_plus += modpow(2, N-i-1, popcount_plus);
            mod_plus %= popcount_plus;
            mod_minus += modpow(2, N-i-1, popcount_minus);
            mod_minus %= popcount_minus;
        }
    }

    for (int i = 0; i < N; i++) {
        int x = 0;
        int fx = 0;
        if (X[i] == '1') { 
            if (popcount_minus > 0) {
                x = mod_minus - modpow(2, N-i-1, popcount_minus);
                if (x < 0) x += popcount_minus;
                fx++;
            }
        }
        else {
            x = mod_plus + modpow(2, N-i-1, popcount_plus);
            x %= popcount_plus;
            fx++;
        }
        while (x != 0) {
            int popcount_tmp = __builtin_popcount(x);
            x %= popcount_tmp;
            fx++;
        }
        cout << fx << '\n';
    }
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3696
n,c=map(int,input().split())
can=list(map(int,input().split()))

res=[0]*(n-c+1)

for i in range(n-c+1):
	s=can[i]
	e=can[i+c-1]
	if s>=0 and e>=0:
		res[i]=e
	else:
		if s<=0 and e<=0:
			res[i]=-s
		else:
			if s<=0 and e>=0:
				if abs(s)>=e:
					res[i]+=-s+e*2
				else:
					res[i]+=-s*2+e
print(min(res))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define _GLIBCXX_DEBUG
static const int MAX = 100000;

int n, q, l, r, A[MAX];
string s;

main(){
  cin >> n >> q >> s;

  int count = 0;
  rep2(i, 1, n){
     if(s[i-1] == 'A' && s[i] == 'C') count++;
     A[i] = count;
  }
  
  rep(i, q){
    cin >> l >> r;
    cout << A[r-1] - A[l-1] << endl;
  }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 2147483647;  // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll ngcd(vector<ll> a) {
    ll res;
    res = a[0];
    for (ll i = 1; i < (ll)a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}

//ミョ(-ω- ?)
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    //前処理
    vector<ll> Sieve(1e6 + 5, -1);
    Sieve[0] = 0;
    Sieve[1] = 1;
    repp(i, 2, 1e6 + 5) {
        if (Sieve[i] != -1) continue;
        ll m = 0;
        while (i * m <= 1e6+5) {
            ++m;
            ll multi = i * m;
            if (multi > 1000000) break;
            if (Sieve[m * i] != -1) continue;
            Sieve[i * m] = i;
        }
    }
    //ここまで共通の処理


    ll n;
    cin >> n;
    vector<ll> a(n, 0);
    rep(i, n) cin >> a[i];

    vector<ll> cnt(1e6 + 5, 0);
    ll v_gcd = ngcd(a);

    rep(i, n) {
        ll before = 0;
        while (a[i] > 1) {
            cnt[Sieve[a[i]]]++;
            before = Sieve[a[i]];
            while (a[i] >= Sieve[a[i]] && Sieve[a[i]] == before &&  a[i] % Sieve[a[i]] == 0 )
                a[i] /= Sieve[a[i]];
        }
    }
    bool pairwise = true;
    repp(i, 1, 1e6 + 1) {
        if (cnt[i] > 1) {
            pairwise = false;
            break;
        }
    }
    if (pairwise)
        cout << "pairwise coprime\n";
    else if (v_gcd == 1)
        cout << "setwise coprime\n";
    else
        cout << "not coprime\n";
    return 0;
}

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

int main() {
#ifdef LOCAL_EXEC
//    freopen("sample.in", "r", stdin);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#endif

  int a[200005];
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < k; i++) {
    int cum[200005] = {};
    for (int j = 1; j <= n; j++) {
      cum[max(1, j - a[j])]++;
      cum[min(n + 1, j + a[j] + 1)]--;
    }
    int cur = 0;
    bool alln = true;
    for (int j = 1; j <= n; j++) {
      cur += cum[j];
      a[j] = cur;
      if (cur != n) alln = false;
    }
    if (alln) break;
  }

  for (int i = 1; i <= n; i++) {
    cout << a[i] << ' ';
  }
  cout << '\n';


	return 0;
}

Measured memory_bytes: 5180
#include<bits/stdc++.h>
using namespace std;
#define LOCAL 0
#define lli long long int
const lli mod=1e9+7;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;ans%=mod;}b/=2;a*=a;a%=mod;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
#define S second
const int INF=0x3f3f3f3f;
#define Pa pair<int,int>
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define ld long double
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
int a[105];

int main()
{
    int n;
    si(n);
    
    for(int i=0;i<n;i++) si(a[i]);
    
    sort(a,a+n);
    
    reverse(a,a+n);
    
    int sum=0;    
    for(int i=0;i<n;i+=2) sum+=a[i];
    
    for(int i=1;i<n;i+=2) sum-=a[i];
    
    cout<<sum<<endl;
	return 0;
}


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

int main(){
  int A, B;
  
  cin >> A >> B;
  
  for(int i=10; i<10100; i++){
    if(i*8/100 == A && i*10/100 == B){
      cout << i << endl;
      return 0;
    }
  }
  
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
ts = list(map(int, input().split()))
vs = list(map(int, input().split()))
ws = list(map(int, input().split()))


def place(i):
    x = (ts[0] * vs[0] + ts[1] * vs[1]) * (i // 2)
    if i % 2 == 1:
        x += ts[0] * vs[0]

    y = (ts[0] * ws[0] + ts[1] * ws[1]) * (i // 2)
    if i % 2 == 1:
        y += ts[0] * ws[0]

    return x, y


x0, y0 = place(2)
if x0 == y0:
    print("infinity")
    exit()


def changed(i):
    x1, y1 = place(i)
    x2, y2 = place(i + 1)
    return x1 != y1 and (x2 == y2 or (x1 < y1) != (x2 < y2))


ok = 0
ng = 10 ** 20

while ng - ok > 1:
    mid = (ok + ng) // 2
    if changed(mid):
        ok = mid
    else:
        ng = mid

print(ok)


Measured memory_bytes: 3192
H, N = map(int, input().split())
AB = []
for _ in range(N):
    A, B = map(int, input().split())
    AB.append([A, B])
dp = [10**9] * (H + 1)
dp[0] = 0
for i in range(H):
    for a, b in AB:
        if i + a <= H:
            dp[i + a] = min(dp[i + a], dp[i] + b)
        else:
            dp[H] = min(dp[H], dp[i] + b)
print(dp[H])


Measured memory_bytes: 74192
#include <bits/stdc++.h> 
using namespace std; 
  
#define rep(i,n) for (i = 0; i < n; ++i) 
#define REP(i,k,n) for (i = k; i <= n; ++i) 
#define REPR(i,k,n) for (i = k; i >= n; --i)
#define ll long long 
// int check()
#include <string.h>
 
 
int main()
{
    double h1,s1,h2,s2;
    cin>>h1>>s1>>h2>>s2;
    double q=h2/s1;//1.1
    double w=h1/s2;//1
    // ll w1=h1%s2;
    if(  ceil(q)>ceil(w) )
    cout<<"No";
    else cout<<"Yes";
 
    return 0;
}
 
 

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second



int main() {
	ll n, ans = 0;
	string s[610] = {}, t[610] = {};
	cin >> n;
	for (int i = 0;i < n;i++)cin >> s[i];
	for (int i = 0;i < n;i++)s[i] += s[i];
	for (int i = n;i < 2 * n;i++)s[i] = s[i - n];
	for (int i = 0;i < 2 * n;i++) {
		for (int j = 0;j < 2 * n;j++) {
			t[j] += s[i][j];
		}
	}

	for (int k = 0;k < n;k++) {
			bool fl = true;
			for (int i = 0;i < n;i++) {
				for (int j = 0;j < n;j++) {
					if (s[i][j + k] != s[j][i + k]) {
						fl = false;
						break;
					}
				}
			}
			if (fl) ans += n;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<map>

using namespace std;

int main(void){
    map<char, char> p;
    p['A'] = 'T';
    p['T'] = 'A';
    p['C'] = 'G';
    p['G'] = 'C';
    string S;
    cin >> S;
    int ans = 0;
    for(int i = 0; i < S.length(); i++){
        for(int j = i + 1; j <= S.length(); j++){
            int k;
            for(k = i; k < j; k++){
                if(p[S[k]] == 0) break;
            }
            if(k >= j) ans = max(ans, j - i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
x = int(input())

if x >= 1800:
    ans = 1
elif x >= 1600:
    ans = 2
elif x >= 1400:
    ans = 3
elif x >= 1200:
    ans = 4
elif x >= 1000:
    ans = 5
elif x >= 800:
    ans = 6
elif x >= 600:
    ans = 7
else:
    ans = 8

print(str(int(ans)))

Measured memory_bytes: 9180
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

int ds[10];

int main(void) {
  REP(i, 3) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    ds[a]++;
    ds[b]++;
  }
  bool ok = true;
  REP(i, 4) {
    if(ds[i] >= 3) {
      ok = false;
    }
  }
  puts(ok ? "YES" : "NO");
  return 0;
}


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

int N,M,v;
pair <int,int> vote_area[110];
int main(){
  while (cin >> N >> M && N >0) {
     for (int l=0; l<M; ++l){
    vote_area[l].first = 0;
    vote_area[l].second = -(l+1);
	}
    for (int i=0; i<N; ++i) {
	  for (int j=0; j<M; ++j) {
	    cin >> v;
		//i人目の人が場所jに行きたいかどうか
		vote_area[j].first += v;
		  }
	    }
		//ここで計算して出力する
	  sort(vote_area, vote_area+M);
	  reverse(vote_area, vote_area+M);
	  for (int t=0; t<M; ++t){
	     vote_area[t].second = (-1)*vote_area[t].second;
		}
	  for (int k=0; k<M-1; ++k){
	    std::cout << vote_area[k].second << " " <<  std::flush;
	  }
	  cout << vote_area[M-1].second << endl;
      }
	}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
  char a, b ;
  cin >> a >> b;
  if (a > b) cout << '>' << endl;
  else if (a < b) cout << '<' << endl;
  else cout << '=' << endl;
  return 0;
}

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

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << std::min(a, b) + std::min(c, d) << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int d=sc.nextInt();
    while(a>=0 || c>=0)
    {
      c-=b;
      if(c<=0)
       {
         System.out.println("Yes");
         break;
       } 
      a-=d;
      if(a<=0)
      {
        System.out.println("No");
        break;
      }
    }  
  }
}  


Measured memory_bytes: 35736
n, m = map(int, input().split())

a = []
b = []
ans = []
dis = []

for i in range(n):
    p, q = map(int, input().split())
    a.append(p)
    b.append(q)
    ans.append(-1)
    dis.append(100000000000)

for i in range(m):
    x, y = map(int, input().split())
    
    for j in range(n):
        calc_dis = abs(a[j]-x) + abs(b[j]-y)

        if dis[j] > calc_dis:
            ans[j] = i+1
            dis[j] = calc_dis

for i in range(n):
    print(ans[i])


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x=0,w=0,cnt=1;
		
		int n = sc.nextInt();
		
		int [][] jun = new int [2][n+1];
		
		int [][] kumi = new int [n*(n-1)/2][4];
		
		for(int i = 0; i < n*(n-1)/2; i++){
			for(int j = 0; j < 4; j++){
				kumi[i][j] = sc.nextInt();
			}
		}
		for(int i = 0; i <= n; i++){
			jun[0][i] = x;
			x++;
			jun[1][i] = 0;
		}
		for(int j = 0; j < n*(n-1)/2; j++){
			w=0;
			if(kumi[j][2]>kumi[j][3]){
				w=2;
			}else if(kumi[j][2]<kumi[j][3]){
				w=3;
			}else if(kumi[j][2]==kumi[j][3]){
				w=0;
			}
			if(w==2){
				jun[1][kumi[j][0]] += 3;
			}
			if(w==3){
				jun[1][kumi[j][1]] += 3;
			}
			if(w==0){
				jun[1][kumi[j][0]] += 1;
				jun[1][kumi[j][1]] += 1;
			}
		}
		for(int m = 1; m < n+1; m++){
			cnt = 1;
			for(int k = 1; k < n+1; k++){
				if(jun[1][m]<jun[1][k]){
					cnt++;
				}
			}
			System.out.println(cnt);
		}
		// TODO Auto-generated method stub

	}

}

Measured memory_bytes: 44132
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;
use std::collections::HashMap;

fn main() {
    let (n, m): (usize, usize);
    let mut map = HashMap::new();
    input!(n, m);
    let v = input_vector::<usize>();
    let mut sum = 0;
    map.insert(sum, 1);
    for z in v {
        sum += z;
        sum %= m;
        let po = map.entry(sum).or_insert(0);
        *po += 1;
    }
    let mut ans = 0_usize;
    for (_, x) in map.iter() {
        ans += (*x * (*x - 1)) / 2;
    }
    p(ans);
}

Measured memory_bytes: 12540
#include<stdio.h>

void swap(int *x,int *y){
  int tmp;

  tmp = *x;
  *x = *y;
  *y = tmp;
}

void selectionSort(int a[], int n){

  int i,j,k,minj;

  k=0;
  for(i=0; i<n; i++){
    minj = i;
    for(j=i; j<n; j++){
      if(a[j]<a[minj]){
        minj=j;
      }
    }
    if(a[i]!=a[minj]){
      swap(&a[i],&a[minj]);
      //printf("%d %d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4],a[5]);
      k++;
    }
  }
  for(i=0; i<n-1; i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[n-1]);
  printf("%d\n",k);
}

int main(void){
  int i,n;

  scanf("%d",&n);

  int z[n];

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

  selectionSort(z,n);

  return 0;
}



Measured memory_bytes: 2036
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
char a;
int main()
{
	int maxn=0;
	int sum=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a=='I')
		sum++;
		else
		sum--;
		maxn=max(maxn,sum);
	 } 
	 cout<<maxn<<endl;
	 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair<ll,ll> 
#define mll map<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ing(m,ad) rep(i,m){ int u,v; cin>>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);}
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1000000007
const int MAXN=100005;
int spf[MAXN];
ll fac1[MAXN],fac2[MAXN],inv[MAXN];
ll gcd(ll x, ll y){ return y?gcd(y,x%y):x; }

void sieve(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

void pre(){
    fac1[0]=fac2[0]=inv[1]=1;
    for(int i=1;i<MAXN;i++){
        fac1[i]=(fac1[i-1]*i)%mod;
        if(i>1) inv[i]=( mod - ((ll)(mod/i)*inv[mod%i])%mod ) %mod;
    }
    for(int i=1;i<MAXN;i++) fac2[i]=(fac2[i-1]*inv[i])%mod;
}
ll C(int n,int k){
    if(n<k) return 0;
    return ((fac1[n]*fac2[n-k]%mod)*fac2[k]%mod);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int t=1;
    // cin>>t;
    while(t--){
        string s;
        cin>>s;
        if(s=="SSS") cout<<"0\n";
        else if(s[1]=='S' || s=="SRS") cout<<"1\n";
        else if(s=="RRR") cout<<"3\n"; else cout<<"2\n";
    }
    return 0;
}

Measured memory_bytes: 3104
n, m = map(int, input().split())
hs = list(map(int, input().split()))

peaks = [True] * n

for i in range(m):
  a, b = map(int, input().split())
  if hs[a - 1] > hs[b - 1]:
    peaks[b - 1] = False
  elif hs[a - 1] < hs[b - 1]:
    peaks[a - 1] = False
  else:
    peaks[a - 1] = False
    peaks[b - 1] = False

print(peaks.count(True))

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) V vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define cont const auto
#define fi first
#define se second
#define Vec vector
#define P pair
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
typedef tuple<ll,ll,ll> T;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N,Q;
  cin>>N>>Q;
  vector<T> event;
  rep(i,N){
    int s,t,x;
    cin>>s>>t>>x;
    event.emplace_back(s-x,1,x);
    event.emplace_back(t-x,2,x);
  }
  rep(i,Q){
    int d;
    cin>>d;
    event.emplace_back(d,3,0);
  }

  SORT(event);
  multiset<ll> stop;
  for(cont&now:event){
    int a,flag,x;
    tie(a,flag,x)=now;
    //cout<<"stop ";call(stop);
    if(flag==1){
      stop.insert(x);
    }
    else if(flag==2){
      auto itr=stop.find(x);
      if(itr!=stop.end())stop.erase(itr);
    }
    else if(flag==3){
      if(stop.empty())out(-1);
      else out(*stop.begin());
    }
  }
  
  
  
  
  return 0;
}



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

using namespace std;

const long double PI = 3.1415926535897932384626433827950;
const double rad = PI / 180;


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

	int a, b, h, m;
	cin >> a >> b >> h >> m;

	long double sd;

	sd = PI * 2 * ((long double)h / 12.0 + ((long double)m / 60 / 12.0) - ((long double)m / 60));

	long double ans;

	ans = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(sd);

	ans = sqrtl(ans);

	cout << fixed << setprecision(20) << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

int f(int x) {
  int ret = 0;

  for (int i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      ret++;
      if (x / i != i) ret++;
    }
  }
  return ret;
}

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

  int ans = 0;
  for (int i = 1; i <= N; i += 2) {
    if (f(i) == 8) ans++;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
import scala.io.{StdIn => in}
import annotation.tailrec

object Main extends App {

  val Array(a, b, c, x , y) = in.readLine.split(" ").map(_.toInt).toArray
  val ans = Array(
    a * x + b * y,
    math.max(x, y) * c * 2,
    math.min(x, y) * c * 2 + (x - y).abs * (if(x > y) a else b)
  ).min

  println(ans)
}

Measured memory_bytes: 25660
# include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c;
    int z;
    cin >> a >> b >> c;
    if(a>b){
        z=b;
        b=a;
        a=z;
    }
    if(b>c){
        z=c;
        c=b;
        b=z;
    }
    if(a>b){
        z=b;
        b=a;
        a=z;
    }
    cout << a << " " << b << " " << c << endl;
}


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

using namespace std;

int main(){
  int N, max, next;
  cin >> N;
  int A[N], B[N];
  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++) B[i] = A[i];
  sort(B, B+N);
  max = B[N-1]; next = B[N-2];
  for(int i=0; i<N; i++){
    if(A[i] == max) cout << next << endl;
    else cout << max << endl;
  }

  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> b(n);
    int i;
    for(i = 0; i < n+1; i++){
        cin >> a.at(i);
    }
    for(i = 0; i < n; i++){
        cin >> b.at(i);
    }
    int64_t ans = 0;
    for(int x : a){
        ans += x;
    }
    for(i = 0; i < n; i++){
        if(a.at(i) <= b.at(i)){
            a.at(i+1) -= b.at(i) - a.at(i);
            if(a.at(i+1) < 0){
                a.at(i+1) = 0;
            }
            a.at(i) = 0;
        }
        else{
            a.at(i) -= b.at(i);
        }
    }
    for(int x : a){
        ans -= x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int ch(int x){
  if(x < 0){x *= (-1);}
  return x;
}

int main()
{
    // 入力
    int n, m;
    cin >> n >> m;

    vector<vector<int>> v(n,vector<int>(0));
    for(int i = 0; i < m; i++){
      int a, b;
      cin >> a >> b;
      v[a-1].push_back(b);
      v[b-1].push_back(a);
    }

    // 初期順列
    vector<int> order(n);
    for (int i = 0; i < n; ++i) order[i] = i+1;


    // 探索
    
    int cnt = 0;
    do {
      if(order[0] != 1){continue;}
      else{
        int res = 0;
        for(int i = 0; i < n-1; i++){
          if(v[order[i]-1].size() == 0){break;}
          else{
          for(int j = 0; j < v[order[i]-1].size(); j++){
            if(v[order[i]-1][j] == order[i+1]){res++; break;}
          }          
        }
        if(res == n-1){cnt++;}
        }
      }
    } while (next_permutation(order.begin(), order.end()));

    // 答えを出力
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n;
	int room[10][3][4];
	int i,j,k;
	int a,b,c,d;
	for(i=0;i<10;i++) for(j=0;j<3;j++) for(k=0;k<4;k++) room[i][j][k]=0;
	scanf("%d\n",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&a,&b,&c,&d);
		room[c-1][b-1][a-1]+=d;
	}
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				printf(" ");
				printf("%d",room[k][j][i]);
			}
			puts("");
		}
		if(i==3) break;
		for(j=0;j<20;j++) printf("#");
		puts("");
	}
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

bool is_runrun(ll N){
  ll tmp = N%10;
  while(N>0){
    N/=10;
    if(N==0) return true;
    if(abs(N%10-tmp)>1) return false;
    tmp = N%10;
  }
  return true;
}

ll next(ll N){
  ll p = 1;
  ll c = 0;
  if(is_runrun(N+p)) return N+p;
  while(true){
    p *= 10;
    c += 1;
    ll N_tmp = N+p;
    REP(i,c) N_tmp /= 10;
    ll v = N_tmp%10;
    REP(i,c){
      N_tmp *= 10;
      N_tmp += max((ll)0,v-1);
      v--;
    }
    if(is_runrun(N_tmp)) return N_tmp;
  }
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll K;
  IN(K);

  ll val=1;
  REP(i,K-1) val = next(val);
  OUT(val);

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)

using namespace std;

typedef long long ll;
const int N = 200010;

int n, tot, tmp;
pair <int, int> p[N];
vector <int> a[26];
ll ans, h[N];
char s[N];

ll find(int x) {ll ans = 0; for(; x; x -= x & -x) ans += h[x]; return ans;}
void change(int x, int y) {for(; x <= n + 5; x += x & -x) h[x] += y;}

int main()
{
    scanf("%s", s + 1);
    n = strlen(s + 1);
    FOR(i, 1, n) a[s[i] - 'a'].push_back(i);
    FOR(x, 0, 25) if (a[x].size())
        for(int i = 0, j = a[x].size() - 1; i <= j; ++i, --j)
            p[++tot] = make_pair(a[x][i], a[x][j]);
    sort(p + 1, p + tot + 1);
    FOR(i, 1, tot) if (p[i].first == p[i].second)
    {
        ++tmp; if (tmp > 1) {puts("-1"); return 0;}
        ans += find(p[i].first + 1);
        change(p[i].second + 1, 1);
    }
    else
    {
        ans += find(p[i].first + 1) + find(p[i].second + 1);
        change(p[i].second + 1, 2);
    }
    printf("%lld\n", ans / 2);
    return 0;
}


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

int W,H;
char C[111][111];

string maxst(const string a,const string b){
  int l = a.size();
  int r = b.size();
  if( l > r ) return a;
  else if ( l < r ) return b;
  for(int i=0;i<l;i++){
    if( a[i] > b[i] ) return a;
    else if( a[i] < b[i] ) return b;
  }
  return a;
}

string ctos(char c){
  string s = " ";
  s[0] = c;
  return s;
}

string dp[111][111][80];

string solve(int x,int y,int d){
  if( dp[x][y][d] != "-1" ) return dp[x][y][d];
  string ret = "";
  if( isdigit( C[x+1][y] ) ){
    ret =  maxst( ret , ctos( C[x+1][y] ) + solve(x+1,y, d+1) );
  }
  if( isdigit( C[x][y+1] ) ){
    ret =  maxst( ret , ctos( C[x][y+1] ) + solve(x,y+1, d+1) );
  }
  //  cout << x << "  "<<y << " " <<ret << endl;
  return dp[x][y][d] = ret;
}


int main(){
  while(  cin >> W >> H && W && H ){
    memset(C,0,sizeof(C));
    for(int i=0;i<H;i++)
      for(int j=0;j<W;j++)
	cin >> C[j][i];
    string res="";
    for(int i=0;i<H;i++)
      for(int j=0;j<W;j++)
	for(int k=0;k<77;k++) dp[j][i][k] = "-1";
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if( isdigit(C[j][i]) && C[j][i] != '0' ){
	  //cout << C[j][i] << " in " << endl;
	  res = dp[j][i][0] = maxst( res, ctos(C[j][i])+solve(j,i,1) );
	}
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 16728
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    int n, x = 0;
    int i, max = 0;
    string s;
    
    cin >> n >> s;
    
    for(i = 0; i < n; i++) {
        if(s[i] == 'I') {
            x++;
        } else if(s[i] == 'D') {
            x--;
        }
        
        if(max < x) {
            max = x;
        }
    }
    
    cout << max << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 100010
vector<ll> g[N];
ll dep[N];
void dfs1(ll x,ll d){
	dep[x]=d;
	for(auto y:g[x]){
		dfs1(y,d+1);
	}
}
bool used[N];
void dfs2(ll x){
	if(used[x])return;
	used[x]=1;
	for(auto y:g[x]){
		dfs2(y);
	}
}
ll n,k,p[N];
int main(){
	cin>>n>>k;
	k=min(k,n);
	rep(i,n){
		cin>>p[i]; p[i]--;
		if(i!=0)g[p[i]].push_back(i);
	}
	ll ans=(p[0]!=0);
	p[0]=0;
	dfs1(0,0);
	vector<P> v;
	rep(i,n){
		v.push_back(make_pair(dep[i],i));
	}
	sort(all(v),greater<P>());
	rep(i,n)used[i]=0;
	for(auto e:v){
		ll x=e.second;
		if(used[x])continue;
		rep(i,k-1)x=p[x];
		ans+=(p[x]!=0);
		dfs2(x);
	}
	cout<<ans<<endl;
}





Measured memory_bytes: 12532
s = input()

n = len(s)

s_l = s[:int((n-1)/2)]
s_r = s[int((n-1)/2)+1:]

c = 0

if ''.join(reversed(s_l)) == s_l:
    c += 1
if ''.join(reversed(s_r)) == s_r:
    c += 1
if s_l == ''.join(reversed(s_r)):
    c += 1

if c== 3:
    print('Yes')

else:
    print('No')
        

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
void solve(){
    ll n,i=0,j,k,temp,ans=0;
    cin>>n;
    vt<ll> a,b,c,medium(n+3),largest(n+3);
    read(a,n);
    read(b,n);
    read(c,n);
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    f(j,0,n,1){
        temp=0;
        while(b[j]>a[i] && i<n){
            temp++;
            i++;
        }
        if (i>=n)
            i=n;
        medium[j]=((j-1)>=0?medium[j-1]:0)+temp;
    }
    j=0;
    f(k,0,n,1){
        temp=0;
        while(c[k]>b[j] && j<n){
            temp+=medium[j];
            j++;
        }
        if (j>=n)
            j=n;
        largest[k]=((k-1)>=0?largest[k-1]:0)+temp;
    }
    f(i,0,n,1)
        ans+=largest[i];
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 7896