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

const int M = 2e5 + 10;
int a[M];
int n, k;

int f() {
    a[0] = 0;
    int c[M] = {0};
    for (int i = 1; i <= n; i++) 
        c[max(1, i - a[i])]++, c[min(n + 1, i + a[i] + 1)]--;

    int t = 0;
    for (int i = 1; i <= n; i++) {
        t += c[i];
        a[i] = t;
    }

    int all_are_n = 1;
    for (int i = 1; i <= n; i++) all_are_n &= a[i] == n;
    return all_are_n;
}

int main () {
    while (scanf("%d %d", &n, &k) == 2) {
        for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
        while (k-- && !f());

        cerr << k << "\n";
        for (int i = 1; i <= n; i++) printf("%d ", a[i]);
        printf("\n");
    }
}



Measured memory_bytes: 5308
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            // Input
            int N = Integer.parseInt(sc.next());
            long[] a = new long[N];
            for (int i = 0; i < N; i++) {
                a[i] = Long.parseLong(sc.next());
                if (a[i] == 0) {
                    System.out.println(0);
                    return;
                }
            }

            // Calc
            long total = 1L;
            long LIMIT = 1000000000000000000L;
            for (int i = 0; i < N; i++) {
                long mul = total * a[i];
                if (mul / a[i] != total || mul > LIMIT)  {
                    total = -1;
                    break;
                }
                total = mul;
            }
            System.out.println(total);
        }
    }
}


Measured memory_bytes: 60160
#include <atcoder/all>
#include "bits/stdc++.h"
using namespace std;
using namespace atcoder;

int t,n,m,a,b;

int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d%d%d",&n,&m,&a,&b);
		printf("%lld\n",floor_sum(n,m,a,b));
	}
}

Measured memory_bytes: 3808
#include<iostream>
using namespace std;
int N;
bool r;
void rec(int n){
  if(n==0)r=true;
  if(n<=0)return;
  rec(n-4);
  rec(n-7);
}
int main(void){
  cin>>N;
  rec(N);
  cout<<(r?"Yes":"No")<<endl;
  return 0;
}


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

int main() {
  int n, k, ans = 0;
  cin >> n >> k;
  rep(i, n){
    int h;
    cin >> h;
    if(h >= k) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
ad=dict()
ans=0
for i in range(len(a)):
	if a[i] in ad:
		ad[a[i]]+=1
	else:
		ad[a[i]]=1
for i in range(min(ad),max(ad)+1):
	tmp=0
	if i in ad:
		tmp+=ad[i]
	if i-1 in ad:
		tmp+=ad[i-1]
	if i+1 in ad:
		tmp+=ad[i+1]
	if tmp>ans:
		ans=tmp
print(ans)
	

Measured memory_bytes: 14004
function Main(input) {
input = input.split("\n");
x = input[0].split(" ");

for (var i = 0; i < 5; i++) {
 if  (x[i] == 0) {
  var result = i + 1;
   break;
 } else {
 }
 };


console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29556
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;



signed main(){
	int N, X, T;
	cin >> N >> X >> T;
	int t = (N + X - 1) / X;
	out(t * T);
}

Measured memory_bytes: 3620
K = int(input())
A, B = map(int, input().split())
b = False
bai = K
counter = 1
while bai <= B:
    if A <= bai <= B:
        b = True
        break
    counter += 1
    bai = K*counter
if b:
    print("OK")
else:
    print("NG")

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

using namespace std;
typedef long long ll;
const int mxn = 1e5+5;

ll arr[mxn];
ll pre[mxn];
ll suf[mxn];

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

    for(int i = 1; i <= n; i++) cin >> arr[i];
    pre[1] = arr[1];
    suf[n] = arr[n];
    for(int i = 2; i <= n; i++) pre[i] = __gcd(pre[i-1], arr[i]);
    for(int i = n-1; i >= 1; i--) suf[i] = __gcd(suf[i+1], arr[i]);
    ll ans = -1;
    for(int i = 1; i <= n; i++) ans = max(ans, __gcd(pre[i-1], suf[i+1]));
    cout << ans << '\n';
    return 0;
}


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

int main()
{
	int n;
	cin>>n;
	vector<string> s(n);
	for(size_t i = 0; i<n; i++)
	{
		cin>>s[i];
	}
	sort(s.begin(),s.end());
	int a = 0;
	for(size_t i = 0; i<n-1; i++)
	{
		if(s[i]==s[i+1])
		{
			a++;
		}
	}
	cout<<n-a<<endl;
	return 0;
}

Measured memory_bytes: 9512
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n = 3;
    vi a(n); for(auto& e : a) cin >> e;
    int K; cin >> K;

    sort(_all(a));
    a.back() <<= K;

    cout << a[0] + a[1] + a[2] << endl;

    return 0;
}


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

using namespace std;

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

int dp[105][10005];

int main() {
  int n, W;
  cin >> n >> W;
  int v[n], w[n];
  rep(i, n) cin >> v[i] >> w[i];

  rep(i, n) rep(j, W + 1) {
    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
    if (j + w[i] <= W)
      dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
  }

  cout << dp[n][W] << endl;
  return 0;
}



Measured memory_bytes: 7044
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<class Tuple, unsigned Index>
void print_tuple(ostream& os, const Tuple& t) {}

template<class Tuple, unsigned Index, class Type, class... Types>
void print_tuple(ostream& os, const Tuple& t) {
	if(Index > 0) os << ", ";
	os << get<Index>(t);
	print_tuple<Tuple, Index + 1, Types...>(os, t);
}

template<class... Types>
ostream& operator<<(ostream& os, const tuple<Types...>& t) {
	os << '(';
	print_tuple<tuple<Types...>, 0, Types...>(os, t);
	return os << ')';
}

template<class Iterator>
ostream& dump_range(ostream&, Iterator, const Iterator&);

template<typename T>
ostream& operator<<(ostream& os, vector<T> c) {
	return dump_range(os, c.cbegin(), c.cend());
}

template<class Iterator>
ostream& dump_range(ostream& os, Iterator first, const Iterator& last) {
	os << '[';
	for(int i = 0; first != last; ++i, ++first) {
		if(i) os << ", ";
		os << *first;
	}
	return os << ']';
}

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

	for(int n, d; cin >> n >> d && n;) {
		int rest = 0;
		vector<int> power(n, 0);
		vector<vector<int>> missiles(n);
		for(int i = 0; i < n; ++i) {
			int m;
			cin >> m;
			rest += m;
			missiles[i].resize(m);
			for(int j = 0; j < m; ++j) {
				cin >> missiles[i][j];
				power[i] += missiles[i][j];
			}
		}

		while(rest) {
			bool update = false;
			for(int i = 0; i < n;) {
				if(missiles[i].size() == 0) {
					power.erase(power.begin() + i);
					missiles.erase(missiles.begin() + i);
					--n;
					continue;
				}

				const int next = power[i] - missiles[i].back();
				for(int j = 0; j < n; ++j) {
					if(i == j) continue;
					if(next + d < power[j]) goto ng;
				}

				--rest;
				missiles[i].pop_back();
				power[i] = next;
				update = true;

			ng:;
				++i;
			}

			if(!update) break;
		}

		cout << (rest ? "No" : "Yes") << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

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

    int d, t, s; cin >> d >> t >> s;
    cout << (t*s >= d ? "Yes" : "No") << endl;

    return 0;
}


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

const int mod=998244353;
const int maxn=105;
char ch[maxn];
map<pair<unsigned long long,unsigned long long>,int>F;

int f(string s){
	if(s.empty())return 1;
	if(int(s.size())==1)return s[0]-'0'+1;
	int len=int(s.size());
	unsigned long long m1=(len<64)?(1uLL<<len):0;
	unsigned long long m2=(len>=64)?(1uLL<<(len-64)):0;
	for(int i=0;i<int(s.size());i++)if(s[i]=='1'){
		if(i<64)m1|=(1uLL<<i);
		else m2|=(1uLL<<(i-64));
	}
	if(F.count(make_pair(m1,m2)))return F[make_pair(m1,m2)];
	int ans=1LL*(s[0]-'0'+1)*f(s.substr(1))%mod;
	for(int i=1;i<=len;i++){
		string t=s.substr(0,i);
		for(int j=2;j<=len/i;j++){
			for(int k=0;k<i;k++)if(t[k]=='1'&&s[(j-1)*i+k]=='0')
				t[k]='0';
			ans=(ans+1LL*f(t)*f(s.substr(j*i)))%mod;
		}
	}
	return F[make_pair(m1,m2)]=ans;
}

int main(){
	scanf("%s",ch);string s=ch;
	printf("%d\n",f(s));
	return 0;
}

Measured memory_bytes: 3072
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>

using std::max;
typedef long long ll;
const int N = 100010;
int _w;

int n, a[N], d[N];

namespace Tree {
	int head[N], nxt[N*2], to[N*2], eid;
	void init() {
		eid = 0;
		memset(head, -1, sizeof head);
	}
	void link( int u, int v ) {
		to[eid] = v, nxt[eid] = head[u], head[u] = eid++;
		to[eid] = u, nxt[eid] = head[v], head[v] = eid++;
	}
}

ll f[N];

void dfs( int u, int fa ) {
	using namespace Tree;
	if( d[u] == 1 ) {
		f[u] = a[u];
	} else {
		ll s = 0, mx = 0;
		for( int i = head[u]; ~i; i = nxt[i] ) {
			int v = to[i];
			if( v == fa ) continue;
			dfs(v, u);
			s += f[v];
			mx = max( mx, f[v] );
		}
		if( s < a[u] || s > a[u] + a[u] )
			puts("NO"), exit(0);
		ll t = s - a[u];
		f[u] = a[u] - t;
		t += t;
		if( mx > s-mx ) {
			ll t2 = s-mx;
			t2 += t2;
			if( t2 < t ) puts("NO"), exit(0);
		} else {
			ll t2 = s % 2 ? s-1 : s;
			if( t2 < t ) puts("NO"), exit(0);
		}
	}
}

int main() {
	_w = scanf( "%d", &n );
	for( int i = 1; i <= n; ++i )
		_w = scanf( "%d", a+i );
	Tree::init();
	for( int i = 0; i < n-1; ++i ) {
		int u, v;
		_w = scanf( "%d%d", &u, &v );
		Tree::link(u, v);
		++d[u], ++d[v];
	}
	if( n == 2 ) {
		puts( a[1] == a[2] ? "YES" : "NO" );
		return 0;
	}
	for( int i = 1; i <= n; ++i )
		if( d[i] > 1 ) {
			dfs(i, 0);
			puts( f[i] ? "NO" : "YES" );
			break;
		}
	return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int n; cin >> n;
	vector<int> v(n);
	map<int, int> o, e;
	rep(i, n) {
		int v; cin >> v;
		if (i % 2) e[v]++;
		else o[v]++;
	}

	vector<pair<int, int>> a, b;
	a.push_back(make_pair(0, 0));
	b.push_back(make_pair(0, 0));
	for (auto i : o) a.push_back(make_pair(i.second, i.first));
	for (auto i : e) b.push_back(make_pair(i.second, i.first));

	sort(all(a), greater<pair<int, int>>());
	sort(all(b), greater<pair<int, int>>());

	if (a[0].second == b[0].second)
		cout << n - max(a[0].first + b[1].first, a[1].first + b[0].first) << endl;
	else
		cout << n - a[0].first - b[0].first << endl;
}


Measured memory_bytes: 6520
def col_count(A,N,M):
    col = [[0,0,0] for _ in range(N+1)]
    for i in range(N):
        for j in range(3):
            col[i+1][j] = col[i][j]
        for j in range(3):
            if col[i][j] == A[i]:
                col[i+1][j] += 1
                break

    output = 1
    for i in range(N):
        cnt = 0
        for j in range(3):
            if col[i][j] == A[i]:
                cnt += 1

        output *= cnt
        output %= M
    return output

def main():
    N = int(input())
    A = list(map(int,input().split()))
    M = 10**9+7

    print(col_count(A,N,M))

if __name__ == "__main__":
    main()


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

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = int.Parse(_[0]);
            var k = int.Parse(_[1]);

            var h = new int[n];
            for(var i = 0; i < n; i++){
                h[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(h);

            var minVal = int.MaxValue;
            for(var i = 0; i < n - k + 1; i++){
                minVal = Math.Min(minVal, h[i + k - 1] - h[i]);
            }

            Console.WriteLine(minVal);
        }
    }
}


Measured memory_bytes: 15452
# include<iostream>
using namespace std;
int main ()
{
	long long  X;
	cin>>X;
	long long sum =0;
    if(X>0)
    {
         sum += X/500*1000;
		 X =X%500;	
	 }	
	 
	sum += X/5*5;
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i;
	int cup[4] = {1};
	char c[2];
	
	while (scanf("%c,%c", &c[0], &c[1]) != EOF){
		if (c[0] =='A' && c[1] =='B' || c[0] =='B' && c[1] =='A'){
			cup[3] = cup[0];
			cup[0] = cup[1];
			cup[1] = cup[3];
		}
		else if (c[0] =='A' && c[1] =='C' || c[0] =='C' && c[1] =='A'){
			cup[3] = cup[0];
			cup[0] = cup[2];
			cup[2] = cup[3];
		}
		else if (c[0] =='B' && c[1] =='C' || c[0] =='C' && c[1] =='B'){
			cup[3] = cup[1];
			cup[1] = cup[2];
			cup[2] = cup[3];
		}
	}
	
	for (i = 0; i < 3; i++){
		if (cup[i] == 1){
			switch (i){
			  case 0:
				printf("A\n");
				break;
				
			  case 1:
				printf("B\n");
				break;
				
			  case 2:
				printf("C\n");
				break;
			}
		}
	}
	
	return (0);
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;

int dp[200000];

int main(){
    int N; cin >> N;
    vi m;
    m.push_back(1);
    FOR(i, 1, 8) m.push_back(pow(6, i));
    FOR(i, 1, 8) m.push_back(pow(9, i));
    sort(m.begin(), m.end());

    REP(i, N+1) dp[i] = 1e9;
    dp[0] = 0;

    FOR(i, 1, N+1){
        int minres = 1e9;
        for(int j=m.size()-1; j>=0; j--){
            int n = m[j];
            if (i-n >= 0){
                minres = min(minres, dp[i-n]);
            }
        }
        dp[i] = minres+1;
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 640
<?php
fscanf(STDIN, '%d %d', $x, $y);

$arr = array();
for ($i = 0; $i < $x; $i++) {
    fscanf(STDIN, "%[^\r\n]", $row_arr);
    $row = str_split($row_arr);
    array_push($arr, $row);
}

$repeat_flag = true;
for ($i = 0; $i < $x; $i++) {
    for ($j = 0; $j < $y; $j++) {
        echo $arr[$i][$j];
    }
  
    echo PHP_EOL;
    
    if ($repeat_flag === true) {
        $i--;
        $repeat_flag = false;
    } else {
        $repeat_flag = true;
    }
}

Measured memory_bytes: 4728
#include <iostream>
using namespace std;
#define MOD 1000000007

int main()
{
	int N,f=0,b=0;
	long long int K,ans=0;
	cin >> N >>K;
	int A[N];
	long long int x=K*(K-1)/2%MOD,y=(K*(K-1)/2+K)%MOD;
	for(int i=0;i<N;i++) cin >> A[i];
	for(int i=0;i<N;i++)
	{
		b=0;
		f=0;
		for(int j=0;j<i;j++)
			if(A[j]<A[i]) f++;
		for(int j=i+1;j<N;j++)
			if(A[j]<A[i]) b++;
		ans+=f*x+b*y;
		ans%=MOD;
	}
	cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(void)
{
    int n,m;
    cin >> n >> m;
    cout << n * (n-1) / 2 + m * (m-1) / 2 << endl;
    return 0;
}

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

int main() {
	string s,t;
	cin >> s >> t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());
	string k = "No";
	if(s < t)
	{
		k = "Yes";
	}
    cout << k << endl;
}


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

const int N = 1000 + 10;

int main()
{
    char str[N];
    int num[N];
    while(~ scanf("%s", str))
    {
        memset(num, 0, sizeof num);
        bool flag = true;
        for(int i = 0; str[i]; i++)
        {
            if(++num[str[i]-'a'] > 1)
            {
                flag = false; break;
            }
        }
        puts(flag ? "yes" : "no");
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main(){
   
   string s,t;
   int k;
   
   int cnt=0;
   cin>>s>>k;
   int n=(int)s.size();
   if(s==string(n,s[0])){
       cout<<n*k/2<<"\n";
   }
   else{
       int ans1=0;
       for (int i = 0; i < n-1; i++)
       {
           if(s[i%n]==s[(i+1)%n]){
               ans1++;
               i++;
           }
       }
       int ans2=0;
       for (int i = 0; i+1 < 2*n; i++)
       {
           if(s[i%n]==s[(i+1)%n]){
               ++ans2;
               ++i;
           }
       }
       cerr<<ans1<<" "<<ans2<<endl;
       cout<<ans1+(ans2-ans1)*(k-1)<<"\n";
   }   
    return 0;
}

Measured memory_bytes: 256
s = input()
#print(s[0])
if s[0]==s[1]==s[2]=="R":
    print(3)
elif s[0]=="R" and s[1]=="R":
    print(2)
elif s[1]=="R" and s[2]=="R":
    print(2)
elif s[0]=="R":
    print(1)
elif s[1]=="R":
    print(1)
elif s[2]=="R":
    print(1)
else:
    print(0)

Measured memory_bytes: 9036
#include <cmath>
#include <queue>
#include <cstdio>
#include <algorithm>

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

using namespace std;

const double EPS=1e-8;
const double PI=acos(-1);

struct point{
	double x,y;
	point():x(0),y(0){}
	point(double x,double y):x(x),y(y){}
	point operator-(const point &a)const{ return point(x-a.x,y-a.y); }
};

double cross(const point &a,const point &b){ return a.x*b.y-a.y*b.x; }

double arg(const point &a){ double t=atan2(a.y,a.x); return t<0?t+2*PI:t; }

typedef vector<point> polygon;

bool is_ccw(const polygon &F){
	int n=F.size();
	double A=0;
	rep(i,n) A+=cross(F[i],F[(i+1)%n]);
	return A>-EPS;
}

// trace the frame of a polygon
vector<int> trace(const vector<int> *G,int u0,int i0){
	vector<int> F;
	int u=u0,i=i0;
	do{
		F.push_back(u);
		int v=G[u][i];
		int k=G[v].size();
		rep(j,k) if(G[v][j]==u) i=(j-1+k)%k;
		u=v;
	}while(u!=u0 || i!=i0);
	return F;
}

// normalize the list of vertices
vector<int> reg(vector<int> a){
	int k=min_element(a.begin(),a.end())-a.begin();
	rep(i,k){
		a.push_back(a[0]);
		a.erase(a.begin());
	}
	return a;
}

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		point P[100];
		rep(u,n) scanf("%lf%lf",&P[u].x,&P[u].y);

		vector<int> G[100];
		rep(i,m){
			int u,v; scanf("%d%d",&u,&v); u--; v--;
			G[u].push_back(v);
			G[v].push_back(u);
		}

		// angle sort
		rep(u,n){
			int k=G[u].size();
			pair<double,int> A[100];
			rep(i,k){
				int v=G[u][i];
				A[i]=make_pair(arg(P[v]-P[u]),v);
			}
			sort(A,A+k);
			rep(i,k) G[u][i]=A[i].second;
		}

		// decompose to polygons
		vector< vector<int> > F; // set of polygons
		rep(u,n) rep(i,G[u].size()) F.push_back(reg(trace(G,u,i)));
		sort(F.begin(),F.end());
		F.erase(unique(F.begin(),F.end()),F.end());

		// find the outside boundary
		int n2=F.size(),u0=-1;
		rep(u,n2){
			int k=F[u].size();
			polygon H(k);
			rep(i,k) H[i]=P[F[u][i]];
			if(!is_ccw(H)) u0=u;
		}

		// build the dual graph
		vector<int> G2[300];
		rep(u,n2) rep(v,u) {
			bool ok=false;
			int nu=F[u].size(),nv=F[v].size();
			rep(i,nu) rep(j,nv) if(F[u][i]==F[v][(j+1)%nv] && F[u][(i+1)%nu]==F[v][j]) ok=true;
			if(ok){
				G2[u].push_back(v);
				G2[v].push_back(u);
			}
		}

		// BFS
		int d[300];
		rep(u,n2) d[u]=(u==u0?0:-1);
		queue<int> Q;
		Q.push(u0);
		while(!Q.empty()){
			int u=Q.front(); Q.pop();
			rep(i,G2[u].size()){
				int v=G2[u][i];
				if(d[v]==-1) d[v]=d[u]+1, Q.push(v);
			}
		}

		printf("%d\n",*max_element(d,d+n2));
	}

	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, -1, 0, 1, 1, 1, -1, -1};

int H, W;
char grid[60][60];
int dist[60][60]; // 最短距離

void bfs(int y, int x) {
  dist[y][x] = 1;

  queue<P> next;
  P cur = P(y, x);
  next.push(cur);

  while (!next.empty()) {
    cur = next.front();
    next.pop();

    for (int i = 0; i < 4; i++) {
      int ny = cur.first + dy[i];
      int nx = cur.second + dx[i];

      if (grid[ny][nx] == '.' && dist[ny][nx] > dist[cur.first][cur.second] + 1) {
        next.push(P(ny, nx));
        dist[ny][nx] = dist[cur.first][cur.second] + 1;
      }
    }
  }
}

int main() {
  // 入力
  cin >> H >> W;
  fill(grid[0], grid[59], '#');
  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) {
      cin >> grid[i][j];
    }
  }

  // bfs
  fill(dist[0], dist[59], INF);
  bfs(1, 1);

  int ans = 0;
  if (dist[H][W] == INF) {
    ans = -1;
  } else {
    int cnt = 0;
    for (int i = 1; i < H + 1; i++) {
      for (int j = 1; j < W + 1; j++) {
        if (grid[i][j] == '#') cnt++;
      }
    }

    ans = H * W - dist[H][W] - cnt;
  }

  // 解答
  cout << ans << endl;

  return 0;
}


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

int main(){
  long long int a,b,c,ans1,ans2;
  cin>>a>>b>>c;
  ans1=b/c;
  ans2=a/c;
  
  if(a%c==0){
    cout<<ans1-ans2+1;
  }
  else{
    cout<<ans1-ans2;
  }
}


Measured memory_bytes: 256
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  lines.shift();
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    largest = left < n && arr[left] > arr[i] ? left : i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 140156
a, b = map(int, input().split())

if a * b < 0 and abs(a) == abs(b):
    print("Zero")
elif a >= 0 and b >= 0:
    print("Positive")
elif a < 0 and b >= 0:
    if a % 2 == 0:
        print("Positive")
    else:
        print("Negative")
elif a >= 0 and b < 0:
    if b % 2 == 0:
        print("Positive")
    else:
        print("Negative")
elif a < 0 and b < 0:
    if (abs((a - b)) + 1) % 2 == 0:
        print("Positive")
    else:
        print("Negative")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1e9+7;
int  a[100020];
int q[100020];
int n;
long long quick(long long a,long long b){
    long long ans ,t;
    ans = 1 % mod;
    t = a % mod;
    while(b){
        if(b&1) ans = ans*t%mod;
        t=t*t%mod;
        b>>=1;
    }
    return ans;
}

int main(){
    cin>>n;
    for(int i = 1;  i <= n ; i++){
        cin>>a[i];
        q[a[i]]++;
    }
    if(q[0]>=2){
        cout<<"0"<<endl;
    }
    else if(q[0]==1||q[0]==0){//奇数或者偶数
        int num = 0 ;
        for(int i = 0 ; i <= n-1 ; i++){
            if(q[i]==2) num++;
            else if(q[i]>2) {
                cout<<"0"<<endl;
                return 0;
            }
        }
        num%=mod;
        cout<<quick(2,num)%mod<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		ArrayList<Integer> arr = new ArrayList<>();

		for(int i = 0; i < 5; i++) {
			arr.add(sc.nextInt());
		}

		for(int i = 1; i <= 5; i++) {
			if(arr.get(i-1) == 0) {
				System.out.println(i);
				break;
			}
		}
	}

}


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

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

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

using namespace std;

#define endl '\n'
#define Opy ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef long long ll;

int main()
{
    //Opy;

/*-------------------------------------------------
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
-------------------------------------------------*/
    string A;

    cin>> A;

    if(A[0] == 'R' && A[1] == 'R' && A[2] == 'R') cout<< "3\n";
    
    else if((A[0] == 'R' && A[1] == 'R') || (A[1] == 'R' && A[2] == 'R'))
    {
        cout<< "2\n";
    }

    else if(A[0] == 'S' && A[1] == 'S' && A[2] == 'S') cout<< "0\n";

    else cout<< "1\n";

    return 0;
}


Measured memory_bytes: 3628
from collections import deque 

n, m = map(int, input().split())
to = [[] for _ in range(n+1)]

for _ in range(m):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

q = deque([1])
ans = [0]*(n+1)
while q:
    p = q.popleft()
    for i in to[p]:
        if ans[i]==0:
            ans[i]=p
            q.append(i)
print('Yes')
print(*ans[2:], sep='\n')



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

using namespace std;

int main()
{
   long long int n;
   cin>>n;
   long long int a[n];
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
   }
    sort(a,a+n);
    int sum=0;
    int d=0;
    int k=0;
    int mini=999999;
    for(int i=1;i<=100;i++)
    {
        d=i;
        sum=0;
        for(int j=0;j<n;j++)
        {
            //cout<<d<<" "<<k<<" "<<sum<<endl;
            k=a[j]-d;
            sum=sum+k*k;
        }
        if(sum<mini)
        {
            mini=sum;
        }
    }
    cout<<mini<<endl;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

//for(i=0; i<N; i++) cin >> a[i];


int main(void) {
  ll i, j, k;
  
  ll N;
  ll a[MAX*2], b[MAX*2];
  
  cin >> N;
  for(i=0; i<N; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a, a+N);
  sort(b, b+N);
  
  
  if(N&1) {
    pt(b[N/2]-a[N/2]+1);
  }else {
    ll A=a[N/2-1]+a[N/2];
    ll B=b[N/2-1]+b[N/2];
    pt(B-A+1);
  }
  
  
  
  
  
  
}
 
 




Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7, N = 2e5 + 5;
int dp[N], nxt[N], last[N];
int n;
int solve(int indx) {
	if (indx == n) return 1;
	int &ret = dp[indx];
	if (ret != -1) return ret;
	ret = 0;
	ret = (ret + solve(indx + 1)) % mod;
	if (nxt[indx] != -1) ret = (ret + solve(nxt[indx])) % mod;
	return ret;
}
int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (v.empty() || v.back() != x) v.push_back(x);
	}
	n = v.size();
	memset(dp, -1, sizeof dp);
	memset(last, -1, sizeof last);
	for (int i = n - 1; i >= 0; i--) {
		nxt[i] = last[v[i]];
		last[v[i]] = i;
	}
	cout << solve(0) << endl;
	return 0;
}


Measured memory_bytes: 9716
H,W = gets.chomp.split(" ").map(&:to_i)
a = Array.new(H){Array.new(W)}
H.times do |i|
  a[i] = gets.chomp.split("")
end
h = []
w = []
H.times do |i|
  if !a[i].all?(".")
    h << i
  end
end
W.times do |i|
  has = false
  h.each do |j|
    if a[j][i] == "#"
      has = true
    end
  end
  if has
    w << i
  end
end
h.each do |i|
  w.each do |j|
    print a[i][j]
  end
  puts ""
end

Measured memory_bytes: 14888
#include <bits/stdc++.h>
typedef long long ll;
 
using namespace std;
const int INF = 1e9 + 5;
int main(){
    vector<long long> v;
    long long x; cin >> x;
    for(int i = 130; i >= 0; i--) {
        for(int j = i; j >= 0; j--) {
            if(x == pow(i, 5) - pow(j, 5)) {
                cout << i << " " << j;
                return 0;
            }
            if(pow(i, 5) - pow(j, 5) > 1e9) {
                break;
            }
        }
    }
    for(int i = 0; i < 70; i++) {
        for(int j = 0; j < 70; j++) {
            if(x == pow(i, 5) + pow(j, 5)) {
                cout << i << " " << -j;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4100
int main(int argc, const char * argv[]) {
    int t,h,m,s;
    scanf("%d",&t);
    h=t/3600;
    m=(t-3600*h)/60;
    s=t-3600*h-60*m;
    if(0<=t&&t<86400){
        printf("%d:%d:%d\n",h,m,s);
    }

        
    
    return 0;
}

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

#define ll long long int

int main() {
    int n, m;
    cin >> n >> m;
    unordered_map<int, vector<int>> u;
    for(int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        u[a].push_back(b);
    }
    int ans = 0;
    priority_queue<int> pq;
    for(int i = 0; i <= m; i++) {
        for(int j = 0; j < u[i].size(); j++) {
            pq.push(u[i][j]);
        }
        if(!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8868
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <iomanip>
#include <iterator>
#include <utility>

typedef long long ll;
typedef unsigned long long ull;

int main() {
	int n, k;
	std::vector<int> x;
	std::cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		int a;
		std::cin >> a;
		x.push_back(a);
	}
	int ans = 1000000000;
	int temp = 0;
	for (int i = 0; i < n - k + 1; ++i) {
		if (std::abs(x[i + k - 1] - x[i] + std::abs(x[i])) < ans || std::abs(x[i + k - 1] - x[i] + std::abs(x[i + k - 1])) < ans) {
			ans = std::min(std::abs(x[i + k - 1] - x[i] + std::abs(x[i])), std::abs(x[i + k - 1] - x[i] + std::abs(x[i + k - 1])));
		}
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 3400
#include<iostream>
#include<vector>

typedef long long ll;

using namespace std;

int main(){
  ll A,B,C,X,Y; cin >> A >> B >> C >> X >> Y;
  
 ll min_sum = 1e11; 
  
  for(ll z = 0; z <= 2 * max( X,Y); z += 2){
    ll sum = 0;
    ll x = X - z / 2; if( x < 0){ x = 0;}
    ll y = Y - z / 2; if( y < 0){ y = 0;}
    sum = x * A + y * B + z * C ;
    
    min_sum = min( min_sum,sum);}
  
  cout << min_sum << endl; return 0;}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n, k, ans;
    sc(n) sc(k)
    vector<int> a(n);
    for (int i = 0; i < n; i++) sc(a[i])
    n -= 1; k -= 1;
    if (n % k == 0) ans = n / k;
    else ans = n / k + 1;
    cout << ans << endl;
    return 0;
}

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

int main() {
    const int INF = 1e9;
    int n;
    cin >> n;
    vector<int> h(n);
    REP(i, n) cin >> h[i];
    vector<int> dp(n, INF);
    dp[0] = 0;
    for(int i = 1; i < n; i++) {
        int cost1 = abs(h[i] - h[i - 1]);
        dp[i] = min(dp[i], dp[i - 1] + cost1);
        if(i > 1) {
            int cost2 = abs(h[i] - h[i - 2]);
            dp[i] = min(dp[i], dp[i - 2] + cost2);
        }
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
import heapq
n,m = map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    a[i] = -a[i]
a.sort()
heapq.heapify(a)
for i in range(m):    
    p=heapq.heappop(a)
    heapq.heappush(a,(p+1)//2)
print(sum(a)*(-1))

Measured memory_bytes: 14180
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x,a,b;
  cin >> x >> a >> b;

  if(abs(x-a) > abs(x-b)) puts("B");
  else puts("A");
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
typedef pair<long long,int> pii;

int main(){
  int w,h,rw,rh;
  priority_queue<pii,vector<pii>,greater<pii> > q;
  scanf("%d %d",&w,&h);
  rw = w+1;
  rh = h+1;
  for(int i=0;i<w;i++){
    long long cost;
    scanf("%lld",&cost);
    q.push(make_pair(cost,1));
  }
  for(int i=0;i<h;i++){
    long long cost;
    scanf("%lld",&cost);
    q.push(make_pair(cost,0));
  }
  long long int ans = 0;
  while(!q.empty()){
    long long c = q.top().first;
    int x = q.top().second;
    q.pop();
    if(x==1){
      ans+=c*rh;
      rw--;
    }else if(x==0){
      ans+=c*rw;
      rh--;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 4464
'use strict'

function main (input) {
  let x = Number(input[0])
  if (x < 1200) {
    console.log('ABC')
  } else {
    console.log('ARC')
  }
}

function doMain () {
  let input = ''
  process.stdin.resume()
  process.stdin.setEncoding('utf8')
  process.stdin.on('data', (chunk) => {
    input += chunk
  })
  process.stdin.on('end', () => {
    input = input.trim().split('\n')
    main(input)
  })
}

doMain()


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M);
  for (int i = 0; i < M; ++i) cin >> L.at(i) >> R.at(i);
  
  int L_max = 0, R_min = N+1;
  for (int i = 0; i < M; ++i) {
    L_max = max(L_max, L.at(i));
    R_min = min(R_min, R.at(i));
  }
  int ans = max(R_min - L_max + 1, 0);
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n , q;
	std::string buf;
	std::vector<std::stack<long> > stacks;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	std::getline(ifs, buf);
#else
	std::getline(std::cin, buf);
#endif
	{
		std::istringstream stream(buf);

		stream >> n >> q;
	}

	stacks.resize(n);
	for(int i = 0; i < q; i++){
#if INPUT_FROM_FILE
		std::getline(ifs, buf);
#else
		std::getline(std::cin, buf);
#endif
		std::istringstream stream(buf);
		long tmp, t, x;

		if(buf[0] == '0'){
			stream >> tmp >> t >> x;

			stacks[t].push(x);
		}
		else if(buf[0] == '1'){
			stream >> tmp >> t;

			if(!stacks[t].empty()){
				std::cout << stacks[t].top() << std::endl;
			}
		}
		else{
			stream >> tmp >> t;
			if(!stacks[t].empty()){
				stacks[t].pop();
			}
		}

	}

	return 0;
}



Measured memory_bytes: 5060
N = int(input())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)
Alice = []
Bob = []
for idx, v in enumerate(a_list):
    if idx % 2 == 0:
        Alice.append(v)
    else:
        Bob.append(v)
print(sum(Alice) - sum(Bob))


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

int main () {
    int n,x[1005],y[1005];
    double D=0;
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&x[i]);
    }
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&y[i]);
    }
    for (int p = 1; p < 4; p++)
    {
        for (int i = 0; i < n; i++)
        {
            D+=pow(abs(x[i]-y[i]),p);
        }
        D=pow(D,(double)1/(double)p);   
        printf("%.6lf\n",D);
        D=0;
    }
    double Max=0;
    for (int i = 0; i < n; i++)
    {
        if(abs(x[i]-y[i])>Max) Max=abs(x[i]-y[i]);
    }
    printf("%.6lf",Max);
    
    
}


Measured memory_bytes: 2112
n = int(input())
a = list(map(lambda x: int(x), input().split()))
count = 1
count_break = 0
for i in range(n):
    if a[i] == count:
        count+= 1
    else:
        count_break += 1

if count_break == n :
    print('-1')
else:
    print(count_break)


Measured memory_bytes: 24744
#include<stdio.h>

int main(){
  int i,zantei=0,max=0;
  char a[20];
  scanf("%s",a);
  for(i=0;i<10;i++){
    if(a[i]=='A'||a[i]=='C'||a[i]=='G'||a[i]=='T'){
      zantei++;
    }else{
      if(zantei>max){
        max=zantei;
        zantei=0;
      }
    }
  }
  if(zantei>max){
        max=zantei;
        zantei=0;
      }
  printf("%d",max);
  return 0;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> edge[1000], redge[1000];
    static int ic[1000], oc[1000];
    static bool erased[1000];
    int ec = 0;

    for(int i=0;i<m;++i){
        int a, b;
        cin >> a >> b;
        edge[a-1].push_back(b-1);
        redge[b-1].push_back(a-1);
        ++oc[a-1];
        ++ic[b-1];
    }
    queue<int> head, tail;
    for(int i=0;i<n;++i){
        if(ic[i] == 0) head.push(i);
        if(oc[i] == 0) tail.push(i);
    }
    while(!head.empty()){
        int t = head.front();
        head.pop();
        ++ec;
        erased[t] = true;
        for(auto to: edge[t]){
            --ic[to];
            if(ic[to] == 0) head.push(to);
        }
    }
    while(!tail.empty()){
        int t = tail.front();
        tail.pop();
        if(erased[t]) continue;
        ++ec;
        erased[t] = true;
        for(auto from: redge[t]){
            --oc[from];
            if(oc[from] == 0) tail.push(from);
        }
    }
    if(ec == n){
        cout << -1 << endl;
        return 0;
    }

    static bool checked[1000];
    int mk = n+1, ms;
    for(int i=0;i<n;++i){
        if(!erased[i]){
            queue<pair<int,int>> q;
            for(int j=0;j<n;++j) checked[j] = false;
            for(auto t: edge[i]){
                if(erased[t]) continue;
                q.emplace(t, 1);
                checked[t] = true;
            }
            while(!q.empty()){
                auto t = q.front();
                q.pop();
                if(t.first == i){
                    int len = t.second;
                    if(len < mk){
                        ms = i;
                        mk = len;
                    }
                    goto nx;
                }
                for(auto to: edge[t.first]){
                    if(erased[to] || checked[to]) continue;
                    q.emplace(to, t.second+1);
                    checked[to] = true;
                }
            }
        }nx:;
    }
    cout << mk << endl;
    queue<int> qq;
    int prev[1000];
    for(int i=0;i<n;++i) checked[i] = false;
    for(auto t: edge[ms]){
        if(erased[t]) continue;
        qq.emplace(t);
        prev[t] = ms;
        checked[t] = true;
    }
    while(!qq.empty()){
        int t = qq.front();
        qq.pop();
        if(t == ms){
            do{
                t = prev[t];
                cout << t+1 << endl;
            }while(t != ms);
            return 0;
        }
        for(auto to: edge[t]){
            if(erased[to] || checked[to]) continue;
            qq.push(to);
            prev[to] = t;
            checked[to] = true;
        }
    }
    return 0;
}

Measured memory_bytes: 512
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
typedef long long ll;
const int Imx=2147483647;
const int mod=1000000007;
const ll Lbig=2e18;
//My own input/output stream
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putsp()
#define putii(x,y) puti(x),putnum(y),putsp()
#define putiii(x,y,z) putii(x,y),putnum(z),putsp()
#define putsi(x) putnum(x),putendl()
#define putsii(x,y) puti(x),putnum(y),putendl()
#define putsiii(x,y,z) putii(x,y),putnum(z),putendl()
inline ll getnum()
{
	register ll r=0;register bool ng=0;register char c;c=getchar();
	while(c!='-'&&(c<'0'||c>'9'))c=getchar();
	if(c=='-')ng=1,c=getchar();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=getchar();
	if(ng)r=-r;return r;
}
template <class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline void putsp(){putchar(' ');}
inline void putendl(){putchar('\n');}
inline char mygetchar(){register char c=getchar();while(c==' '||c=='\n')c=getchar();return c;}
int cnt[400111],cnt1[1600111];
#define ls p<<1
#define rs p<<1|1
void add(int x,int d,int l,int r,int p)
{
	if(x==l&&x==r)
	{
		cnt[x]+=d;
		cnt1[p]=x-200000>0&&cnt[x]>0;
		return;
	}
	int m=l+r>>1;
	if(x<=m)add(x,d,l,m,ls);
	else add(x,d,m+1,r,rs);
	cnt1[p]=cnt1[ls]+cnt1[rs];
}
int n,m,a[400111],oa[400111];
int solve()
{
//	for(int i=1;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
/*	int it=n,ans=0;
	while(it>0)
	{
		int mn=it-a[it];
		while(it>0&&mn<it)
		{
			it--;
			ans++;
			mn=min(mn,it-a[it]);
		}
		while(it>0&&a[it]==0)it--;
	}*/
	return n-cnt1[1];
//	return n-ans;
}
int ocnt[400111];
int main()
{
	getii(n,m);
	for(int i=1;i<=n;i++)
	{
		int x;
		geti(x);
		oa[i]=x;
		a[x]++;
	}
	for(int i=1;i<=n;i++)
	{
		ocnt[200000+i-a[i]+1]++;
		ocnt[200000+i+1]--;
	}
	for(int i=1;i<=400000;i++)ocnt[i]+=ocnt[i-1];
	for(int i=1;i<=400000;i++)add(i,ocnt[i],0,400005,1);
//	cout<<"ok"<<endl;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		getii(x,y);
		add(200000+oa[x]-a[oa[x]]+1,-1,0,400005,1);
		a[oa[x]]--;
		add(200000+y-a[y],1,0,400005,1);
		a[y]++;
		oa[x]=y;
		int ans=solve();
		putsi(ans);
	}
	return 0;
}

Measured memory_bytes: 13952
//It is good to start with zero//
//    kyu @Aryabhatta//




#include<bits/stdc++.h> 
using namespace std;                          
#pragma GCC optimize("O3")
typedef long long ll;
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define vec(i, a)  for( auto i=a.begin();i != a.end(); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define mp make_pair
#define pb push_back
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define in  freopen("input.txt","r",stdin);
#define out freopen("output.txt","w",stdout);
#define sixfive in out 
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector<ll> vi;
const ll MOD = 1e9 + 7;
ll n_bits(ll n ) { ll x= __builtin_popcount(n) ;return x ;}
vector<int>adj[1000006];
bool vis[1000006];
int cnt=0;


void dfs(int node)
{
    vis[node]=1;
    for(auto x:adj[node])
    {
        if(!vis[x])
            dfs(x);
    }
}

int main()
{    
    #ifndef ONLINE_JUDGE
    sixfive
    #endif
    fast
    ll t=1;
    //cin>>t;
    while(t--)
    {    
        int n,m;
        cin>>n>>m;
        int x,y;
        int k=0;
        rep(i,m)
        {
            cin>>x>>y;
            if(!k)
            {
                k=x;
            }
            adj[x].pb(y);
            adj[y].pb(x);
        }
        dfs(k);
        for(int i=1;i<=n;i++)
        {
            if(!vis[i])
            {
                cnt++;
                dfs(i);
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

//            sometimes I do it for her...//

Measured memory_bytes: 30804