akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define For(i,n) for(ll i=0; i<n; ++i)
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define deb(x) cout<<"For debug : "<<x<<endl;
typedef long long ll;
#define ld long double

void solve()
{
    int n;
    cin>>n;
    cout<<(n+n*n+n*n*n)<<endl;
}

int main(){
    optimize();
    ll T=1;
    //cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m;

int main() {
	cin >> n >> m;
	cout << n * m - n - m + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
using vi = vector<ll>;
#define rep(i,a,n) for(int i = (a);i < (n);i++)
#define pb push_back

int main(){
  ll a,b,c,n,t,ans = 0;
  vi vec;
  cin >> n >> t;
  ans += t;
  rep(i,0,n){
    cin >> c;
    vec.pb(c);
  }
  sort(vec.begin(),vec.end());
  rep(i,1,n){
    if(vec[i]-vec[i-1] < t)ans += vec[i]-vec[i-1];
    else ans += t;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
'use strict';
(function(stdin) {
  var inputs  = stdin.toString().split('\n')[0].split(' ').map(Number);
  (function(a,b) {
    var d = Math.floor(a / b);
    var r = Math.floor(a % b);
    var f = (a / b).toFixed(5);

    console.log('%d %d %d',d,r,f);

}(inputs[0],inputs[1]
  )); 
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15928
import sys

def f(b, n):
    if b < 2:
        return -1    

    if b > n:
        return n

    return f(b, n//b) + n % b


def main():
    input = sys.stdin.readline
    n = int(input())
    s = int(input())

    if s > n:
        return -1

    if s == n:
        return n+1

    for i in range(2, int(n**0.5)):
        if f(i, n) == s:
            return i

    for p in range(int(n**0.5) + 1, 0, -1):
        if (n - s) % p != 0:
            continue

        b = (n - s) // p + 1
        if f(b, n) == s:
            return b

    return -1


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


Measured memory_bytes: 3064
def check_lots(n, m, t, d, hls)
  x = m
  for y in (0...d)
    if x > 0 && hls[y][x - 1] == 1
      x -= 1
    elsif x < n - 1 && hls[y][x] == 1
      x += 1
    end
  end
  x == t
end

### main

while true
  n = gets.chomp.to_i
  break if n == 0

  m = gets.chomp.to_i - 1
  t = gets.chomp.to_i - 1
  d = gets.chomp.to_i

  hls = []

  d.times do
    hls.push gets.chomp.split("").map{|s| s.to_i}
  end

  if check_lots(n, m, t, d, hls)
    puts 0
    next
  end

  found = false

  for y in (0...d)
    for x in (0...(n - 1))
      next if hls[y][x] == 1 ||
              (x > 0 && hls[y][x - 1] == 1) ||
              (x < n - 1 && hls[y][x + 1] == 1)

      hls[y][x] = 1

      if check_lots(n, m, t, d, hls)
        puts "#{y + 1} #{x + 1}"
        found = true
        break
      end

      hls[y][x] = 0
    end

    break if found
  end

  if ! found
    puts 1
  end
end

Measured memory_bytes: 6148
#include<bits/stdc++.h>
//#define int long long
#define endl '\n'
#define mod 1000000007
#define inf 1e18
#define PI 3.14159265358979323846264338327950L
#define w(x) int x; cin>>x; while(x--)
using namespace std;
bool sieve[2000006];
void sieve_make() 
{
	memset(sieve,true,sizeof(sieve));
	sieve[0]=sieve[1]=false;
	for(int i=2;i*i<2000006;i++)
	{
		if(sieve[i])
		{
			for(int j=i*i;j<2000006;j+=i)
				sieve[j]=false;
		}
	}
}

int max(int a,int b)
{
	if(a>b)
		return a;
	return b;
}
int min(int a,int b)
{
	if(a<b)
		return a;
	return b;
}
int modexp(int a,int b,int c)
{
	if(a==0) return 0;
	if(b==0) return 1;

	int ans;
	if(b%2==0)
	{
		int small=modexp(a,b/2,c);
		ans=(small*small)%c;
	}
	else
	{
		int small=modexp(a,b-1,c);
		ans=(a%c);
		ans=(small*ans)%c;
	}
	return (ans+c)%c;
}
bool sign(int x)
{
	if(x>0)
		return true;
	return false;
}
int kadane(int* a,int n)
{
	int loc=a[0],glo=a[0];
	for(int i=1;i<n;i++)
	{
		loc=max(a[i],loc+a[i]);
		glo=max(glo,loc);
	}
	return glo;
}

int dp[100001];

int solve(vector<int>& a,int i)
{
	if(i==a.size()-1)
		return 0;

	if(dp[i]!=-1) return dp[i];
	if(i<a.size()-2)
		return dp[i]=min(abs(a[i]-a[i+2])+solve(a,i+2),abs(a[i]-a[i+1])+solve(a,i+1));
	return dp[i]=abs(a[i]-a[i+1])+solve(a,i+1);
}
int32_t main()
{
	ios::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
	
	
	
	
	memset(dp,-1,sizeof dp);
	int n;
	cin>>n;
	vector<int>a(n);

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


	cout<<solve(a,0)<<endl;
}



Measured memory_bytes: 11904
S = list(input())
K = int(input())
l = len(S)

if len(set(S)) == 1:
    print(l*K//2)
    exit()
else:
    ans = 0
    tmp = ""
    count = [1]
    for i in range(l-1):
        if S[i] == S[i+1]:
            count[-1] += 1
        else:
            count.append(1)
    
    for i in count:
        ans += i//2*K

    if S[0] == S[-1] and count[0]%2 == count[-1]%2:
        ans += K-1

    print(ans)

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

int main(void) {
    int x, y;
    cin >> x >> y;

    int x_g = 0;
    if(x == 2) x_g = 2;
    else if(x == 4 || x == 6 || x == 9 || x == 11) x_g = 1;

    int y_g = 0;
    if(y == 2) y_g = 2;
    else if(y == 4 || y == 6 || y == 9 || y == 11) y_g = 1;

    if(x_g == y_g) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second

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

int main(){
	ll z;
	scanf("%lld", &z);
	int ans = 0;
	if(z == 1LL) return !printf("0");
	for(ll i = 2; i * i <= z; i++){
		int po = 0;
		while(z % i == 0){
			z /= i;
			po++;
		}
		int ad = 1;
		//printf("%d", po);
		for(int i = 2; ad <= po; i++){
			ans ++;
			ad += i;
		}
	}
	if(z != 1LL) ans++;
	printf("%d", ans);


}

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

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

  sort(a.begin(), a.end()), a.push_back(0);

  int x = 0, x_n = 0, ans = 0;
  for (int i = 0; i <= N; i++) {
    if (a[i] == x) x_n++; else {
      if (x_n > x) ans += x_n - x;
      if (x_n < x) ans += x_n;
      x = a[i], x_n = 1;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<iostream>

int n;
int cnt[6];

int main()
{
	std::cin >> n;
	for( int i = 0; i != n; ++i )
	{
		double t;
		std::cin >> t;

		int cls;
		for( cls = 0; cls != 6; ++cls )
		{
			if( !cls && t < 165.0 )
				break;
			else if( t == 5 && t >= 185.0 )
				break;
			else if( t >= 165.0 + ( cls - 1 ) * 5.0 && t < 170.0 + ( cls - 1 ) * 5.0 )
				break;
		}
		++cnt[cls];
	}

	for( int i = 0; i != 6; ++i )
	{
		std::cout << i + 1 << ':';
		for( int j = 0; j != cnt[i]; ++j )
			std::cout << '*';

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

	return 0;
}

Measured memory_bytes: 1232
from itertools import islice
def solve(A):
    memo = [0]*(10**6+1)

    for a in A:
        memo[a] += 1
    if memo[1] > 0:
        return 1 if memo[1] == 1 else 0

    res = 0
    for i,v in enumerate(islice(memo,2,None),start=2):
        if v > 0:
            res += 1 if v == 1 else 0
            j = i
            while j <= 10**6:
                memo[j] = 0
                j += i
    return res

if __name__ == '__main__':
    N = int(input())
    A = list(map(int,input().split()))
    print(solve(A))


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

int main(){
    int N;
    cin >> N;
    map<string, ll> M;
    rep(i, N){
        string S;
        cin >> S;
        sort(all(S));
        M[S]++;
    }

    ll sum = 0;
    for(auto i : M){
        sum += i.second * (i.second - 1) / 2;
    }

    cout << sum << endl;
}

Measured memory_bytes: 11136
//created by pyoxiao on 2020/05/03
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
int n, m, k;
int deg[105];
void solve() {
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= k; i ++) {
        int d;
        scanf("%d", &d);
        while(d --) {
            int x;
            scanf("%d", &x);
            deg[x] ++;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i ++) {
        if(deg[i] == 0) {
            ans ++;
        }
    }
    printf("%d\n", ans);
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 3824
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	int N;
	scanf("%d",&N);
	int arr[200000];
	for (int i=0; i<N; i++){
		scanf("%d",&arr[i]);
	}

	sort(arr, arr+N);

	int pre = arr[0];

	for (int i=1; i<N; i++){
		if (pre == arr[i]){
			printf("NO\n");
			return 0;
		}
		pre = arr[i];
	}
	printf("YES\n");
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
#define c2i(c) ((int)c-'0')
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int char2int(char c) {
  return int(c-'0');
}
int main() {
    ll n, p;
    string s;
    cin >> n >> p >> s;
    if(p==2||p==5){
        ll ans = 0;
        rrep(i,n) 
            if (c2i(s[i])%p == 0) ans += i+1;
        cout << ans << endl;
        return 0;
    } 
    map<ll,ll> U;
    ll rem = 0;
    ll pow = 1;
    ll ans = 0;
    U[rem]++;
    rrep(i,n){
        rem = (rem + c2i(s[i])*pow)%p;
        ans += U[rem];
        U[rem]++;
        pow = pow*10%p;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main()
{
    int i, j, values[3], temp, valueDiffs[3];
    for(i=0; i<3; i++){
        scanf("%d", &values[i]);
    }

    valueDiffs[0] = abs(values[0]-values[1]);
    valueDiffs[1] = abs(values[0]-values[2]);
    valueDiffs[2] = abs(values[1]-values[2]);

    for(int k=0; k<2;k++){
        for(i=2; i>k;i--){
            if(valueDiffs[i]<valueDiffs[i-1]){
                temp = valueDiffs[i-1];
                valueDiffs[i-1]=valueDiffs[i];
                valueDiffs[i]=temp;
            }
        }
    }

    printf("%d\n", valueDiffs[0]+valueDiffs[1]);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <string.h>
#include <bitset>
#include <array>

using namespace std;

const string s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	char c;
	cin >> c;
	for(int i=0; i<26; i++){
		if(c==s[i]){
			cout << "A\n";
			return 0;
		}
	}
	cout << "a\n";
	return 0;
}

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

using namespace std;

long long dp[200005];
long long h[200005];
deque<int> dq;

double slope(int j, int k){
    return 1.0*(dp[j]-dp[k]+h[j]*h[j]-h[k]*h[k])/(h[j]-h[k]);
}

int main(){
    int N;
    long long C;
    cin >> N >> C;
    dq.push_back(1);
    cin >> h[1];
    for(int i = 2; i<=N; i++){
        cin >> h[i];
        while(dq.size() > 1){
            int idx = dq.front();
            dq.pop_front();
            if(slope(dq.front(), idx) > 2*h[i]){
                dq.push_front(idx);
                break;
            }
        }
        dp[i] = dp[dq.front()] + (h[i] - h[dq.front()])*(h[i]-h[dq.front()]) + C;
        while(dq.size() > 1){
            int idx = dq.back();
            dq.pop_back();
            if(slope(idx, dq.back()) < slope(i, idx)){
                dq.push_back(idx);
                break;
            }
        }
        dq.push_back(i);
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 3840
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	as := make([]int, m)
	bs := make([]int, m)
	for i := range as {
		fmt.Scan(&as[i])
		fmt.Scan(&bs[i])
	}
	counter := make(map[int]int)
	for _, v := range as {
		counter[v]++
	}
	for _, v := range bs {
		counter[v]++
	}
	for i := 1; i <= n; i++ {
		fmt.Println(counter[i])
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
using namespace std;
int A,B,C,D,E,F,tot,sug;
double mx=0;
int main()
{
	scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
	for(int i=0;i<=F;i+=A*100)
		for(int j=0;i+j<=F;j+=B*100)
			if(i!=0||j!=0)
				for(int k=0;i+j+k<=F&&k<=(i+j)*E/100;k+=C)
					for(int l=0;i+j+k+l<=F&&k+l<=(i+j)*E/100;l+=D)
						if(double(k+l)/double(i+j+k+l)>mx) 
						{
							mx=double(k+l)/double(i+j+k+l);
							tot=i+j+k+l;
							sug=k+l;
						}
	if(mx==0) printf("%d 0",A*100);
	else printf("%d %d",tot,sug);
	return 0;					
}

Measured memory_bytes: 256
N = int(input())
ans = 0

L = [0]*(int((N-1)**(1/2))+1)

for i in range(1,int((N-1)**(1/2))+1):
    if (N-1)%i == 0:
        ans += 2
        L[i] = 1
        ###
        #print(i,(N-1)//i)
        ###
    if i**2 == N-1:
        ans -= 1

for i in range(1,int(N**(1/2))+1):
    if i < int((N-1)**(1/2))+1 and L[i] == 1:
        continue
    if N%i == 0:
        NN = N
        while NN % i == 0:
            NN //= i
        if NN % i == 1:
            ans += 1
            #print(i)
        if i**2 == N:
            continue
        NN = N
        j = N//i
        while NN % j == 0:
            NN //= j
        if NN % j == 1:
            ans += 1
            #print(j)

print(ans)
###1が前半部分で数えられるので, 引く必要があるが, ここで1を数えたことで
###後半でN自身がカウントされていないので+-0

Measured memory_bytes: 47852
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
  int n,k;cin>>n>>k;
  
  vector<int> vec(n);
  
  rep(i,n) cin>>vec[i];
  
  vector<ll> dp(n+k+10);
  rep(i,n+k)dp[i]=100000000000;
  dp[0]=0;dp[1]=abs(vec[1]-vec[0]);
  
  for (int i=0;i<n-1;i++) {
    
    for (int j=1;j<=k;j++) {
      dp[i+j]=min(dp[i+j],dp[i]+abs(vec[i+j]-vec[i]));
    }
    
  }
  
  cout<<dp[n-1]<<endl;
  
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

int main()
{
	fastIO;
	ll a, b, c, d; cin >> a >> b >> c >> d;
	ll ans;

	ans = b*d > a*c? b*d : a*c;
	ans = ans > b*c? ans : b*c;
	ans = ans > a*d? ans : a*d;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n,m;
	cin>>n>>m;
	n = n*(n-1)/2;
	m = m*(m-1)/2;
	cout<<(n+m)<<endl;
	
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}


int main()
{
	int n;
	cin >> n;
	deque<ll>plus, minus;
	vector<pair<ll, ll>>menu(n - 1);
	int i = 0;

	rep(i, n) {
		int x; cin >> x;
		if (x >= 0) {
			plus.push_back(x);
		}
		else {
			minus.push_back(x);
		}
	}
	bool flag = true;
	if (plus.size() > 0 && minus.size() > 0) {

	}
	else if (plus.size() == 0) {
		sort(all(minus));
		int Min = minus.front();
		int Max = minus.back();
		minus.pop_front();
		minus.pop_back();
		if (minus.size() == 0) {
			cout << Max - Min << endl;
			cout << Max << " " << Min << endl;
			flag = false;
		}
		menu[i].first = Max;
		menu[i].second = Min;
		i++;
		plus.push_back(Max - Min);
	}
	else if (minus.size() == 0) {
		sort(all(plus));
		int Min = plus.front();
		int Max = plus.back();
		plus.pop_front();
		plus.pop_back();
		if (plus.size() == 0) {
			cout << Max - Min << endl;
			cout << Max << " " << Min << endl;
			flag = false;
		}
		menu[i].first = Min;
		menu[i].second = Max;
		i++;
		minus.push_back(Min - Max);
	}
	if (flag) {
		sort(all(plus));
		sort(all(minus));
		while (minus.size() != 1) {
			menu[i].F = plus[0];
			plus[0] -= minus.front();
			menu[i].S = minus.front();
			i++;
			minus.pop_front();
		}
		while (plus.size() != 1) {
			menu[i].F = minus[0];
			minus[0] -= plus.front();
			menu[i].S = plus.front();
			i++;
			plus.pop_front();
		}
		cout << plus.front() - minus.front() << endl;
		if (i < n - 1) {
			menu[i].first = plus.front();
			menu[i].second = minus.front();
		}
		rep(i, n - 1) {
			cout << menu[i].first << " " << menu[i].second << endl;
		}
	}
}


Measured memory_bytes: 4224
import sys

H, W = map(int, sys.stdin.readline().split())
N = int(sys.stdin.readline())
A =  list(map(int, sys.stdin.readline().split()))

grid = [[0 for _ in range(W)] for _ in range(H)]
point = A[0]
color = 0
for i in range(H):
    for j in range(W):
        # 色iが接するように、左 -> 右 -> 下の列を右から、と染めていく
        if i % 2 == 0:
            x = j
        else:
            x = W - j - 1
        if point == 0:
            color += 1
            point = A[color]

        grid[i][x] = color + 1
        point -= 1

for i in range(H):
    print(*grid[i])

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

int main(void)
{
    int h, w;
    cin >> h >> w;
    vector<string> v(h);
    rep(i, h) cin >> v[i];
    vector<bool> tate(h, true), yoko(w, true);
    rep(i, h) rep(j, w) if (v[i][j] == '#') tate[i] = false, yoko[j] = false;
    vector<string> ans;
    rep(i, h)
    {
        string s;
        rep(j, w) if (!tate[i] && !yoko[j]) s.push_back(v[i][j]);
        if (s.size() != 0)
            ans.push_back(s);
    }
    for (auto i : ans)
        cout << i << endl;
}


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

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

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M;
	cin >> N >> M;
	VI A(M), B(M);
	REP(i, M) {
		cin >> A[i] >> B[i];
	
	}
	rSORT(A);
	SORT(B);
	cout << max(B[0] - A[0] + 1,0LL) << endl;

	return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 505
using namespace std;
int n,cnt[N],x[N],a[N*N],c[N],vis[N];
int S1[N*N],T1,S2[N*N],T2,S3[N*N],T3;
bool cmp(int p,int q){ return x[p]<x[q];}
void GG(){ printf("No"); exit(0);}
int main()
{
	int i,j,p=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&x[i]),a[x[i]]=c[i]=i,cnt[i]=i-1;
	sort(c+1,c+n+1,cmp);
	for(i=1;i<=n;i++)
		for(j=1;j<i;j++) S1[++T1]=i;
	for(i=1;i<=n*n;i++){
		while(T1&&vis[S1[T1]]) T1--;
		if(i==x[c[p]]){
			vis[c[p]]=1;
			while(cnt[c[p]]){
				while(T2&&vis[a[S2[T2]]]) T2--;
				if(!T2) GG();
				S1[++T1]=a[S2[T2]],cnt[S1[T1]]++;
				a[S2[T2]]=c[p],cnt[c[p]]--;
			  }
			for(j=1;j<=n-c[p];j++) S3[++T3]=c[p];
			p++;
		  }
		else{
			if(T1) S2[++T2]=i,cnt[S1[T1]]--,a[i]=S1[T1--];
			else{ if(!T3) GG(); a[i]=S3[T3--];}
		  }
	  }
	printf("Yes\n");
	for(i=1;i<=n*n;i++)
		printf("%d ",a[i]);
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int n = (N - 1) / (K - 1);
	if ((N - 1) % (K - 1)) n++;

	cout << n << endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
using namespace std;
typedef long long LL;

LL n,m,k;

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m >> k;
	n = max(n,m);
	cout << (k - 1) / n + 1 << endl;
	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int a = sc.nextInt();
        int b = sc.nextInt();
        int h = sc.nextInt();
        int m = sc.nextInt();

        double angH = 30 * h + 0.5 * m;
        double angM = 6 * m;
        double disAng = Math.abs(angH - angM);

        if (disAng == 0) {
            System.out.println(Math.abs(a - b));
            return;
        }

        double angC = disAng;
        if (disAng > 180)
            angC = 360 - disAng;
        double cosC = Math.cos(Math.toRadians(angC));
        double c = a * a + b * b - 2 * a * b * cosC;

        System.out.println(Math.sqrt(c));
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 33076
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define pb push_back
#define F first 
#define S second 
#define f(i,n) for(int i=0;i<n;i++) 

using namespace std;

void test(){
	ll n;
	cin>>n;
	string s[4]={"AC","WA","TLE","RE"};
	int c[4]={0};
	f(i,n){
		string x;
		cin>>x;
		f(j,4)if(s[j]==x)c[j]++;
	}
	f(i,4)cout<<s[i]<<" x "<<c[i]<<"\n";	
}

int main(){
	int tests=1;
//	cin>>tests;
	while(tests--){
		test();
	}
}

Measured memory_bytes: 3624
#include<iostream>
#include<queue>
using namespace std;
char a[1005][1005];
int mem[1005][1005];
bool flag[1005][1005];
int ci,cj,di,dj;
int h,w;
int dx[]={0,1,0,-1,1,-1,1,-1,0,2,0,-2,1,2,1,-2,2,-1,-2,-1,2,-2,2,-2};
int dy[]={1,0,-1,0,1,-1,-1,1,2,0,-2,0,2,1,-2,1,-1,2,-1,-2,2,-2,-2,2};
int ans=1e9;
struct node{
	int x,y,val;
	node(int A,int B,int C)
	{
		x=A;y=B;val=C;
	} 
	friend bool operator<(node s1,node s2)
	{
		return s1.val>s2.val;
	}
	node(){}
}; 
void bfs()
{
	priority_queue<node> q;
	q.push(node(ci,cj,0));
	while(!q.empty())
	{
		node now=q.top();
		q.pop();
		int ni=now.x;
		int nj=now.y;
		int nc=now.val;
		if(mem[ni][nj]!=-1)
			continue;
		mem[ni][nj]=nc;
		if(ni==di&&nj==dj)
		{
			ans=nc;
			break;
		}
		for(int i=0;i<24;i++)
		{
			int ti=ni+dx[i];
			int tj=nj+dy[i];
			if(ti<1||tj<1||ti>h||tj>w)
				continue;
			if(a[ti][tj]=='#')
				continue;
			if(i<4)
				q.push(node(ti,tj,nc));
			if(i>=4)
				q.push(node(ti,tj,nc+1)); 
		}
	}
}
int main()
{
	cin>>h>>w;
	cin>>ci>>cj;
	cin>>di>>dj;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
		{
			cin>>a[i][j];
			mem[i][j]=-1;
		}
	bfs();
	if(ans==(int)1e9)
		ans=-1;
	cout<<ans;
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	double x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
	cout<<fixed<<setprecision(8)<<pow(pow(abs(x1-x2),2)+pow(abs(y1-y2),2),0.5)<<"\n"s;
}


Measured memory_bytes: 3408
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    int even = 0, odd = 0;
    REP(i,n) {
        int a; cin >> a;
        if (a % 2 == 0) even++;
        else odd++;
    }

    int ans = pow(3,n) - pow(2,even);

    cout << ans << '\n';

    return 0;
}

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

namespace AtCoder.Contests.ABC159
{
    /// <summary>
    /// 
    /// </summary>
    static class A
    {
        static void Main(string[] args)
        {
            var n = NextInt();
            var m = NextInt();

            Console.WriteLine(n * (n - 1) / 2 + m * (m - 1) / 2);
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 13140
N = int(input())
C = input()

flag_left = 0
flag_right = N-1
counter = 0

ok = max(C.count("W"),C.count("R"))
if ok ==N:
    print(0)
    exit()

while flag_left<flag_right:
    while C[flag_left]=="R":
        flag_left += 1
        if flag_left>N-1:
            break
    while C[flag_right]=="W":
        flag_right -= 1
        if flag_left<0:
            break
        
    if flag_left<flag_right:
        counter += 1
    flag_left += 1
    flag_right -= 1
print(counter)

Measured memory_bytes: 9420
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N,K,S; cin >> N >> K >> S;
	int T = (S == TEN(9) ? 1 : TEN(9));
	rep(i,K) cout << S << " ";
	rep(i,N-K) cout << T << " ";
	cout << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;

int main() {
	LL n, a, b;
	cin >> n >> a >> b;
	if ((a & 1) ^ (b & 1)) {
		LL ans = a + (b - a - 1) / 2;
		a = n - a + 1;
		b = n - b + 1;
		swap(a, b);
		ans = min(ans, a + (b - a - 1) / 2);
		cout << ans << '\n';

	} else {
		cout << (b - a) / 2 << '\n';
	}
	return 0;
}


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

#define int long long
#define pb push_back
#define ff first
#define ss second

int di[(int)(1e7+1)];
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   
    int n;
    cin>>n;
    
   
    for (int i = 1; i <= n; i++) 
    { 
      for (int j = 1; j * i <= n; j++) 
            di[i * j]++; 
    }
    
    int ans=0;
    for(int i=1;i<=n;i++)
        ans=ans+i*di[i];
    cout<<ans;
}

Measured memory_bytes: 81744
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#define ll long long

using namespace std;

int main(void) {
    int n, count = 0;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++) {
        cin >> l[i];
    }

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

    for(int i = 2; i < n; i++) {
        for(int j = 1; j < i; j++) {
            for(int k = 0; k < j; k++) {
                if(l[i] < l[j] + l[k]) count++;
            }
        }
    }

    cout << count << endl;
}


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

int main()
{
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    
    double rad = abs(h * 30.0 - m * 5.5);
    rad = rad > 180.0 ? (360 - rad) * M_PI / 180.0 : rad * M_PI / 180.0;
    cout << fixed << setprecision(20) << sqrt(pow(a, 2.0) + pow(b, 2.0) - 2.0 * a * b * cos(rad)) << endl;
    return 0;
}

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

int main()
{
	int n, k;
	string s;
	cin >> n >> s >> k;
	string str = "";
	char c = s[k-1];
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != c) str += '*';
		else str += s[i];
	}
	cout << str << endl;
	return 0;
}

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

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


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int main() {
	var(int, n, k);
	vec(int, h, n);
	sort(all(h));
	int ans = 1e9;
	rep(i, 0, n - k + 1) {
		chmin(ans, h[i + k - 1] - h[i]);
	}
	print(ans);
	return 0;
}


Measured memory_bytes: 640
n,k,*a=map(int,open(0).read().split())
l=[]
for i in range(n):
    t=0
    for j in range(i,n):
        t+=a[j]
        l.append(t)
for i in range(40,-1,-1):
    j=2**i
    t=[]
    for x in l:
        if x&j:
            t.append(x)
    if len(t)>=k:
        l=t
a,*b=l
for t in b:
    a&=t
print(a)

Measured memory_bytes: 28824
#include<cstdio>
#include<algorithm>
#define MN 101
using namespace std;
int n,m,ma[2],afr[2],mi[2],ifr[2],x[200001],y[200001];
bool cmp(int a,int b){return a>b;}
inline long long _min(long long x,long long y){
	if (x<0) return y;
	if (y<0) return x;
	if (x<y) return x;
	return y;
}
inline long long work(){
	int L,R,i,j;
	int MA,MI;MA=ma[0];MI=mi[1];
	for (i=1;i<=n;i++)
	if (MA==x[i]) break;
	for (j=1;j<=n;j++)
	if (MI==y[j]) break;
	L=y[i]<x[j]?y[i]:x[j];
	R=y[i]>x[j]?y[i]:x[j];
	int LL=L,RR=R;
	for (i=n;i;i--) if ((x[i]>=L&&x[i]<=R)||(y[i]>=L&&y[i]<=R)) continue;else
	if (y[i]>R&&x[i]>R) R=x[i]<y[i]?x[i]:y[i];else if (y[i]<L&&x[i]<L) L=x[i]>y[i]?x[i]:y[i];else if (x[i]-R>L-y[i]) L=y[i];else R=x[i];
	
	for (i=1;i<=n;i++) if ((x[i]>=LL&&x[i]<=RR)||(y[i]>=LL&&y[i]<=RR)) continue;else
	if (y[i]>RR&&x[i]>RR) RR=x[i]<y[i]?x[i]:y[i];else if (y[i]<LL&&x[i]<LL) LL=x[i]>y[i]?x[i]:y[i];else if (x[i]-RR>LL-y[i]) LL=y[i];else RR=x[i];
	return 1LL*(MA-MI)*(R-L<RR-LL?R-L:RR-LL);
}
int main(){
	register int i;
	scanf("%d",&n);
	if (n==1) return puts("0"),0;
	ma[0]=ma[1]=0;
	mi[0]=mi[1]=1e9;
	for (i=1;i<=n;i++){
		scanf("%d%d",&x[i],&y[i]);
		if (x[i]<y[i]) swap(x[i],y[i]);
		if (ma[0]<x[i]) ma[0]=x[i];if (ma[1]<y[i]) ma[1]=y[i];
		if (mi[0]>x[i]) mi[0]=x[i];if (mi[1]>y[i]) mi[1]=y[i];
	}
	printf("%lld\n",_min(work(),1LL*(ma[0]-mi[0])*(ma[1]-mi[1])));
}

Measured memory_bytes: 1664
#! /usr/bin/env python
# -*- coding : utf-8 -*-
input()
seq = [int(x) for x in input().split()]
for i in range(0, len(seq)):
    key = seq[i]
    j = i - 1
    assert isinstance(i, int)
    while j >= 0 and seq[j] > key:
        seq[j + 1] = seq[j]
        j -= 1
    seq[j + 1] = key
    print(' '.join(map(str,seq)))

Measured memory_bytes: 7692
#include<iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <cmath>
#include <math.h>
#include <iomanip>
using namespace std;



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

    int num=1,ans=0;
    for(int i=0;i<n;i++){
        if(a[i]==num){
            num++;
            ans++;
        }
    }
    if(ans==0){
        cout << -1;
    }else{
        cout << (n-ans);
    }
    

}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    ll a, b;
    cin >> a >> b;
    if(a + b == 15)cout << "+" << endl;
    else if(a * b == 15)cout << "*" << endl;
    else cout << "x" << endl;

    return 0;
}

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

namespace ABC088B_CardGameForTwo
{
    public class MainClass
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] inp = Console.ReadLine().Split(' ');
            int[] cards = new int[n];
            for (int i = 0; i < n; i++)
            {
                cards[i] = int.Parse(inp[i]);
            }
            cards = cards.OrderByDescending(e => e).ToArray();

            int aliceTotal = 0;
            int bobTotal = 0;
            for (int i = 0; i < n; i++)
            {
                if (i%2 == 0)
                {
                    aliceTotal += cards[i];
                }
                else
                {
                    bobTotal += cards[i];
                }
            }
            Console.WriteLine(aliceTotal - bobTotal);
        }
    }
}


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

typedef unsigned long ul;
typedef long long int ll;
typedef pair<ll, ll> P;
#define pb push_back
#define mp make_pair
#define REP(i,n) REPN(i,0,n)
#define REPN(i,m,n) for(int i=m; i<(n); i++)
#define ALL(a) (a).begin(),(a).end()
#define dump(x) cout << #x << " = " << (x) << endl

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

    int n;
    cin >> n;
    int l[n];
    REP(i, n) {
        cin >> l[i];
    }

    int max = l[0];
    int sum = 0;

    REP(i, n) {
        if (max < l[i]) {
            max = l[i];
        }
        sum += l[i];
    }

    if (max < (sum - max)) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n,m,q; cin >> n >> m >> q;
  vvl table(q,vl(4));
  
  queue<vl> qu;
  
  rep(i,q){
    ll a,b,c,d; cin >> a >> b >> c >> d;
    table[i][0] = a;
    table[i][1] = b;
    table[i][2] = c;
    table[i][3] = d;
  }
  
  for(ll i=1; i <= m; i++){
    vector<ll> array = {i};
    qu.push(array);
  }
  
  bool flag = true;
  while(flag){
    auto vec = qu.front();
    if(vec.size() == n){
      flag = false;
      break;
    }
    
    qu.pop();
    
    ll a = vec[vec.size()-1];
    
    for(ll i=a; i <= m; i++){
      auto vecd = vec;
      vecd.push_back(i);
      qu.push(vecd);
    }
  }
  
  ll ans = 0;
  while(!qu.empty()){
    auto vec = qu.front(); ll sum = 0;
    qu.pop();
    
    rep(i,q){
      if(vec[table[i][1]-1] - vec[table[i][0]-1] == table[i][2]){
        sum += table[i][3];
      }
    }
    
    ans = max(ans,sum);
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 17688
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1e9;
const long double EPS = 1e-10;

bool check(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}

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

  FOR(i, x, INF) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }




  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
int f[2010][2010];
int sum0[4010][2010],sum1[4010][2010],pos[2][4010];
char s[5010];
int read()
{
	int x=0,flag=1;char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-') flag=-1;
		c=getchar();
	}
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
	return flag*x;
}
int main()
{
//	freopen("magolor.in","r",stdin);
//	freopen("magolor.out","w",stdout);
	int n=read();
	for(int i=1;i<=2*n;i++)
	{
		scanf("%s",s+1);
		int ind=read();
		if(s[1]=='W') pos[0][ind]=i,sum0[i][ind]++;
		else pos[1][ind]=i,sum1[i][ind]++;
	}
	for(int i=1;i<=2*n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			sum0[i][j]+=sum0[i-1][j];
			sum1[i][j]+=sum1[i-1][j];
		}
	}
	for(int i=1;i<=2*n;i++)
	{
		for(int j=n;j>=1;j--)
		{
			sum0[i][j]+=sum0[i][j+1];
			sum1[i][j]+=sum1[i][j+1];
		}
	}
	memset(f,0x3f,sizeof(f));
	f[0][0]=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i==n&&j==n) break;
			if(i<n) 
			{
				int tmp=pos[0][i+1];
				int cost=sum0[tmp][i+2]+sum1[tmp][j+1];
				f[i+1][j]=min(f[i+1][j],f[i][j]+cost);
			}
			if(j<n)
			{
				int tmp=pos[1][j+1];
				int cost=sum0[tmp][i+1]+sum1[tmp][j+2];
				f[i][j+1]=min(f[i][j+1],f[i][j]+cost);
			}
		}
	}
//	cout<<sum0[4][1]<<endl;
//	cout<<f[1][1]<<endl;
	cout<<f[n][n];
	return 0;
}


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

using namespace std;

const int N = 1003;
typedef long long ll;
typedef pair<int, int> ii;
int x, y, z, k, f[N][N];
ll a[N], b[N], c[N];

struct CompareII {
	bool operator()(const ii& u, const ii& v) {
		int x1 = u.first, y1 = u.second;
		int x2 = v.first, y2 = v.second;
		return b[x1] + c[y1] + a[f[x1][y1]] < b[x2] + c[y2] + a[f[x2][y2]];
	}
};

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> x >> y >> z >> k;
	for (int i = 1; i <= x; ++i) cin >> a[i];
	for (int i = 1; i <= y; ++i) cin >> b[i];
	for (int i = 1; i <= z; ++i) cin >> c[i];
	priority_queue<ii, vector<ii>, CompareII > heap;
	sort(a + 1, a + 1 + x, greater<ll>());
	sort(b + 1, b + 1 + y, greater<ll>());
	sort(c + 1, c + 1 + z, greater<ll>());
	for (int i = 1; i <= y; ++i)
		for (int j = 1; j <= z; ++j) {
			f[i][j] = 1;
			heap.push(ii(i, j));
		}
	while (k--) {
		ii t = heap.top(); heap.pop();
		int x1 = t.first, y1 = t.second;
		cout << b[x1] + c[y1] + a[f[x1][y1]] << '\n';
		if (f[x1][y1] < x) {
			f[x1][y1]++;
			heap.push(ii(x1, y1));
		}			
	}
	cerr << 1.0 * clock() / CLOCKS_PER_SEC;
	return 0;
}


Measured memory_bytes: 12652
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define f first
#define s second
#define inf 999999999999
#define N  500009
#define M  (L+R)/2
#define ll long long
#define pb push_back
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;

ll n,ans,A,B,AB;
string s[N];
int main()
{
	ios::sync_with_stdio(0);
	
	cin>>n;
	
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	
	for(int i=1;i<=n;i++){
		int k=s[i].size();
		k--;
		for(int j=0;j<k;j++){
			if(s[i][j]=='A' && s[i][j+1]=='B')ans++;
		}
		if(s[i][0]=='B' && s[i][k]=='A')AB++;
		else
		if(s[i][0]=='B')B++;
		else
		if(s[i][k]=='A')A++;
	}
	
	if(AB>0){
	ans+=AB-1;
	if(A>0 || B>0)ans++;
	}
	ans+=min(A,B);
	cout<<ans<<endl;
	
return 0;
}








Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

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

using namespace std;

int main() {
    int h;
    int w;
    int n;

    cin >> h;
    cin >> w;
    cin >> n;

    int ans = 0;

    if (h > w)
    {
        if (n % h == 0){
            ans = n / h;
        }
        else
        {
            ans = n / h + 1;
        }
        
    }
    
    if (h <= w)
    {
        if (n % w == 0){
            ans = n / w;
        }
        else
        {
            ans = n / w + 1;
        }
        
    }

    cout << ans << endl; 
}


Measured memory_bytes: 888