akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
long double pi=3.14159265358979323846L;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll x;cin>>x;
    ll sum=0;
    rep(i,0,1000000){
        sum+=i;
        if(sum>=x){
            cout<<i<<endl;
            return 0;
        }
    }
}


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;
typedef priority_queue<int> PQ;
#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;
	cin >> N;
	VI A(N+1),B(N);
	REP(i, N + 1) {
		cin >> A[i];
	}
	REP(i, N) {
		cin >> B[i];
	}
	int ans = 0;



	for (int i = N; i > 0; i--) {
		int tmp= min(A[i], B[i - 1]);
		ans += tmp;
		B[i - 1] -= tmp;
		if (B[i - 1] > 0) {
			tmp = min(A[i - 1], B[i - 1]);
			A[i - 1] -= tmp;
			ans += tmp;
		}
	}
	cout << ans << endl;
	return 0;
}



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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

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

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

constexpr ll INF = TEN(18);

int main() {
    int N, K;
    cin >> N >> K;
    V<int> P(N), C(N);
    rep(i, N) cin >> P[i], --P[i];
    rep(i, N) cin >> C[i];

    ll ans = -INF;

    rep(i, N) {
        int v = i;
        ll cycle_sum = 0;
        int cycle_cnt = 0;

        while (true) {
            cycle_cnt++;
            cycle_sum += C[v];
            v = P[v];
            if (v == i) break;
        }

        ll path = 0;
        int cnt = 0;

        while (true) {
            cnt++;
            path += C[v];

            if (cnt > K) break;

            int num = (K - cnt) / cycle_cnt;
            ll score = path + max(0ll, cycle_sum) * num;
            chmax(ans, score);

            v = P[v];
            if (v == i) break;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int sum2 = 0;
    int sum4 = 0;
    for(int i = 0; i < n; i++){
        int ai;
        cin >> ai;
       if(ai % 4 == 0){
		    sum4 += 1;
       }else if(ai % 2 == 0){
           sum2 += 1;
       }

    }
    int a = 0;
    if(sum4 > 0){
        a = 1;
    }
    string frag = "No";
    if(sum2 == 0){
        if(sum4*2 + 1 >= n){
            frag = "Yes";
        }
    }else if(sum2 > 0){
        if(sum4*2 + sum2 >= n){
            frag = "Yes";
        }
    }
    cout << frag << endl;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.PriorityQueue;
import java.math.BigInteger;
    
public class Main{

static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE/2;
static final long LINF=Long.MAX_VALUE/2;
    
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int m=ir.nextInt();
int n=ir.nextInt();
int[] manju=ir.toIntArray(m);
int[] boxlen=new int[n];
int[] boxcost=new int[n];
for(int i=0;i<n;i++){
boxlen[i]=ir.nextInt();
boxcost[i]=ir.nextInt();
}
sort(manju);
int[][] dp=new int[m+1][n+1];
for(int i=m-1;i>=0;i--){
for(int j=n-1;j>=0;j--){
int len=i+boxlen[j]>=m?m:i+boxlen[j];
int cnt=0;
for(int k=i;k<len;k++) cnt+=manju[m-1-k];
dp[i][j]=Math.max(dp[i][j],dp[len][j+1]+cnt-boxcost[j]);
dp[i][j]=Math.max(dp[i][j],dp[i][j+1]);
}
}
out.println(dp[0][0]);
out.flush();
}

public static void sort(int[] a){
for(int i=a.length-1;i>=1;i--){
int t=(int)Math.random()*i;
int temp=a[i]; a[i]=a[t]; a[t]=temp;
}
Arrays.sort(a);
}

static class InputReader {
private InputStream in;
private byte[] buffer=new byte[1024];
private int curbuf;
private int lenbuf;

public InputReader(InputStream in) {this.in=in;}
  
public int readByte() {
if(lenbuf==-1) throw new InputMismatchException();
if(curbuf>=lenbuf){
curbuf= 0;
try{
lenbuf=in.read(buffer);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(lenbuf<=0)
return -1;
}
return buffer[curbuf++];
}

public boolean isSpaceChar(int c){return !(c>=33&&c<=126);}

private int skip() {int b; while((b = readByte())!=-1&&isSpaceChar(b)); return b;}

public String next() {
int b=skip();
StringBuilder sb=new StringBuilder();
while(!isSpaceChar(b)){
sb.appendCodePoint(b);
b=readByte();
}
return sb.toString();
}
 
public int nextInt() {
int c=readByte();
while (isSpaceChar(c)) c=readByte();
boolean minus=false;
if (c=='-') {
minus=true;
c=readByte();
}
int res=0;
do{
if(c<'0'||c>'9') throw new InputMismatchException();
res=res*10+c-'0';
c=readByte();
}while(!isSpaceChar(c));
return (minus)?-res:res;
}

public long nextLong() {
int c=readByte();
while (isSpaceChar(c)) c=readByte();
boolean minus=false;
if (c=='-') {
minus=true;
c=readByte();
}
long res = 0;
do{
if(c<'0'||c>'9') throw new InputMismatchException();
res=res*10+c-'0';
c=readByte();
}while(!isSpaceChar(c));
return (minus)?-res:res;
}

public int[] toIntArray(int n){
int[] a=new int[n];
for(int i=0;i<n;i++) a[i]=nextInt();
return a;
}
}
}

Measured memory_bytes: 43364
n = int(input());
a = 1;
list = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

while True:
    b = 26*(26 ** a - 1) // 25;
    if b >= n:
        c = a;
        d = b-n;
        break;
    a += 1;

sol = [None]*c;
e = 26 **c -d-1;

for i in range(0,c):
    f = e % (26);
    sol[i] = list[f]
    e = ((e - f)//26);
    
con = ''

for v in range(c):
    con = con + sol[c-1-v];
    
print(con);

Measured memory_bytes: 9236
#include <stdio.h>

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

Measured memory_bytes: 128
function main(input) {
  var N = input[0];
  var base = 753;
  var ans = 753;
  for(var i=0;i<N.length-2;i++){
    ans = Math.min(ans, Math.abs(base - (Number(N.substr(i,3)) ) ));
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = (ll)1e6 + 3;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

ll pref[MOD + 5];

ll solve() {
	ll x, d, n;
	scanf("%lld%lld%lld", &x, &d, &n);
	if (n == 0) return 1;
	if (x == 0) return 0;
	if (d == 0) return bin_pow(x, n);
	x = mult(x, rev(d));
	if (x + n - 1 >= MOD) return 0;
	ll res = mult(pref[x + n - 1], rev(pref[x - 1]));
	res = mult(res, bin_pow(d, n));
	return res;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	pref[0] = 1;
	for (int i = 1; i < MOD; i++)
		pref[i] = mult(pref[i - 1], i);

	int q;
	scanf("%d", &q);
	while(q--) printf("%lld\n", solve());

	return 0;
}


Measured memory_bytes: 8704
# coding: utf-8

def is_harshad_number(n):
    sumed = sum(map(int, str(n)))
    return n % sumed == 0

def main():
    n = int(raw_input())
    print "Yes" if is_harshad_number(n) else "No"

if __name__ == "__main__":
    main()


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define  ENDL  '\n'
#define N 10000007
using namespace std;
typedef unsigned long  long int ulli;
bool prime[N];
ulli cantdiv[N];
void primos();
int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  ulli resp=1;
  cin>>n;
  primos();
  for(int i=2; i<=n;  ++i)
  {
    resp+=(cantdiv[i])*i;
  }
  cout<<resp;
  return 0;
}

void primos()
{
  for(int i=1; i<=N; ++i)
  {
    for(int j=i; j<N; j+=i)
    {
      cantdiv[j]++;
    }
  }
  cantdiv[1]=1;
  return;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n, m;
    cin >> n >> m;
    char a[n][n], b[m][m];

    rep(i, n) rep(j, n) cin >> a[i][j];
    rep(i, m) rep(j, m) cin >> b[i][j];

    
    rep(t, n - m + 1)
    {
        rep(s, n - m + 1)
        {
            bool flag = 0;
            rep(i, m)
            {
                rep(j, m)
                {
                    if (a[t + i][s + j] != b[i][j])
                        flag = 1;
                }
            }
            if (flag == 0)
            {
                OP("Yes");
                return 0;
            }
        }
    }

    OP("No");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long m = scanner.nextLong();
        System.out.println((Math.min(n,m/2))+((m-2*Math.min(n,m/2))/4));
    }
}


Measured memory_bytes: 21716
#include <iostream>
using namespace std;
int main(){
	int N;
	cin>>N;
	int a[N],count=0;
	for(int i=0;i<N;i++){
		cin>>a[i];
		while(a[i]%2==0){
			count++;
			a[i]/=2;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <bitset>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

long long pow_mod(long long x, long long n, long long mod_num) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) { res = (res * x) % mod_num; }
        x = (x * x) % mod_num;
        n = (n >> 1);
    }
    return res;
}

const int MOD = 1000000007;
const int MAX_N = 100050;
int N;
std::string L;

int main(int argc, char **argv) {
    std::cin >> L;

    long long other = 0;
    long long tmp = 1;
    for (int i = 0; i < L.size(); i++) {
        if (L[i] == '0') {
            other += (((tmp * 2) % MOD) * pow_mod(3, L.size() - 1 - i, MOD)) % MOD;
            //other += (tmp * ((2 * (L.size() - 1 - i)) % MOD)) % MOD;
            other %= MOD;
        } else {
            tmp = (tmp * 2) % MOD;
        }
    }

    long long ret = (pow_mod(3, L.size(), MOD) - other + MOD) % MOD;

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

    return 0;
}

Measured memory_bytes: 512
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    l.insert(0, 0)

    num = 0
    sum = 0
    for e in l:
        if sum + e <= x:
            num += 1
            sum += e
        else:
            break

    print(num)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
main(){
	string str;
	getline(cin,str);
	for(int i=0;i<str.size();++i){
		if(str[i]>='a' && str[i]<='z'){
			str[i]=str[i]-'a'+'A';
		}
		//cout<<str[i]<<endl;
	}
	cout<<str<<endl;
}

Measured memory_bytes: 1172
#include <stdio.h>
int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    if( (a+b)%3==0 || a%3==0 || b%3==0 )
    {
        printf("Possible");
    }
    else
    {
        printf("Impossible");
    }
    return 0;
}

Measured memory_bytes: 2128
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
b = set()
cur = 1
b.add(cur)
for i in range(n):
  cur = a[cur-1]
  if cur == 2:
    print(i+1)
    exit()
  elif cur in b:
    break
  else:
    b.add(cur)
print(-1)

Measured memory_bytes: 13220
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main(){
int n;
double a;
string aa[7];
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lf",&a);
if(a<165) aa[1].pb('*');
else if(a<170) aa[2].pb('*');
else if(a<175) aa[3].pb('*');
else if(a<180) aa[4].pb('*');
else if(a<185) aa[5].pb('*');
else aa[6].pb('*');
}
for(int i=0;i<6;i++){
cout << i+1 << ':' << aa[i+1]<< endl;
}
}

Measured memory_bytes: 1252
import sys
input = sys.stdin.readline


def read():
    S = input().strip()
    return S,

def cumsum(a):
    for i in range(1, len(a)):
        a[i] += a[i-1]
    return a

def solve(S):
    S = S + '.'
    N = len(S)
    pairs = []
    i = 0
    while S[i] != '.':
        n_close = 0
        n_open = 0
        while S[i] == '>':
            i += 1
            n_close += 1
        while S[i] == '<':
            i += 1
            n_open += 1
        pairs.append((n_close, n_open))
    
    T = cumsum([i for i in range(N)])
    
    ans = 0
    for n_close, n_open in pairs:
        ans += T[n_close] + T[n_open]
    for i in range(1, len(pairs)):
        ans -= min(pairs[i-1][1], pairs[i][0])
    return ans

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Measured memory_bytes: 37020
<?php
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);
$n = strlen($s);
$m = strlen($t);
// s, tの文字列をそれぞれ辞書順のs:昇順、t:降順にする
$s_arr = str_split($s);
sort($s_arr);
$asc_s = implode($s_arr);
$t_arr = str_split($t);
rsort($t_arr);
$desc_t = implode($t_arr);

$ret = true;
//var_dump($s_arr, $t_arr);
//var_dump($asc_s, $desc_t);

echo (strcmp($asc_s,$desc_t) < 0) ? "Yes\n" : "No\n";

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

using namespace std;

typedef pair<int,string> P;

int main(){
  int N, M[31];

  while(cin >> N, N){
    string name[N];
    int cnt[31] = {0};
    int d[N][31];

    for(int i = 0 ; i < N ; i++){
      cin >> name[i] >> M[i];
      for(int j = 0 ; j < M[i] ; j++){
        cin >> d[i][j];
        cnt[d[i][j]]++;
      }
    }
   
    vector<P> vec;
    for(int i = 0 ; i < N ; i++){
      int sum = 0;
      for(int j = 0 ; j < M[i] ; j++){
        sum += N-cnt[d[i][j]]+1;
      }
      vec.push_back(P(sum,name[i]));
    }
    sort(vec.begin(), vec.end());
    cout << vec[0].first << " " << vec[0].second << endl;
  }

  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n,k;
int ans = 1e9 + 1;

int main(){
    cin >> n >> k;
    vector<int> h(n);
    for(int i =0;i<n;i++){
        cin >> h[i];
    }
    sort(h.begin(),h.end(),greater<int>());

    for(int i=0;i+k-1<n;i++){
        ans = min(h[i] - h[i+k-1],ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=len(s);
    map<char,int> cnt;
    rep(i,n) cnt[s[i]]++;
    int ans=1e5;
    for(auto itr:cnt){
      char c=itr.fi;
      int now=0;
      string t=s;
      while(count(begin(t),end(t),c)!=len(t)){
        now++;
        string t1;
        rep(i,len(t)-1) t1.push_back(c);
        rep(i,len(t)-1){
          if(t1[i]!=t[i]&&t1[i]!=t[i+1]){
            t1[i]=t[i];
          }
        }
        t=t1;
      }
      ans=min(ans,now);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		int n = Integer.parseInt(reader.readLine());
		Deque<Integer> deque = new ArrayDeque<Integer>();
		for (int i = 0; i < n; i++) {
			String line = reader.readLine();
			if(line.charAt(0) == 'i')
				deque.push(Integer.parseInt(line.substring(7)));
			else if(line.charAt(6)=='F')
				deque.removeFirst();
			else if(line.charAt(6)=='L')
				deque.removeLast();
			else
				deque.remove(Integer.parseInt(line.substring(7)));
			/*System.out.println(deque.stream().map(String::valueOf)
					.collect(Collectors.joining(", ", "[", "]")));*/
		}
		builder.append(deque.poll());
		for(int num2 : deque)
			builder.append(" ").append(num2);
		System.out.println(builder);
	}
}

Measured memory_bytes: 117920
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int main(int argc, const char * argv[]) {
    int k;
    scanf("%d",&k);
    if(k%2==0||k%5==0){
        printf("-1");
        return 0;
    }
    long long i=7,cnt=1;
    while(1){
        i%=k;
        if(i==0){
            printf("%lld",cnt);
            return 0;
        }
        cnt++;
        i*=10;
        i+=7;
        
    }
    
    
    return 0;
}


Measured memory_bytes: 1708
#include <iostream>

using namespace std;

int main()
{
	int n;
	int w[100];

	cin >> n;

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

	int s1 = 0;
	int sa = 1000000;

	for (int i = 0; i < n; i++)
	{
		s1 += w[i];
		s2 = s2 - w[i];

		int sa1 = abs(s1 - s2);

		if (sa > sa1)
		{
			sa = sa1;
		}
	}

	cout << sa << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;



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

  
  int n,k;
  cin>>n>>k;
  vector<int>a(n),f(n);

  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>f[i];
  sort(a.begin(),a.end());
  sort(f.rbegin(),f.rend());

 

  int s=0,e=(int)1e12;
  int mid ,ans;

  while(s<=e)
  {
     mid=(s+e)/2;

     int x=0;
     for(int i=0;i<n;i++)
     {
        x+=max(0ll,a[i]-mid/f[i]);
     }
     if(x<=k)
     {
        ans=mid; e=mid-1;
     }
     else
     {
        s=mid+1;
     }
  }

  cout<<ans<<"\n";
   
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

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

    rep(i,0,n)
    {
        h -= a[i];
    }

    if (h<=0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 1024
N,X,D = map(int,input().split())
if D==0:
    print(1 if X==0 else N+1)
    exit()
if D < 0:
    D *= -1
    X -= D*(N-1)

from collections import defaultdict
arrs = defaultdict(lambda: defaultdict(lambda: 0))
mni = mxi = 0
for k in range(N+1):
    d,m = divmod(k*X + D*mni, D)
    l = mxi - mni + 1
    arrs[m][d] += 1
    arrs[m][d+l] -= 1
    mni += k
    mxi += N-k-1

ans = 0
for arr in arrs.values():
    p = None
    c = 0
    for x,v in sorted(arr.items()):
        if c > 0:
            ans += x-p
        c += v
        p = x
print(ans)

Measured memory_bytes: 125436
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include <climits>
using namespace std;

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

  int pattern_A = 0;
  int pattern_B = 0;

  for(int i=0; i<S.length(); ++i){
    if(i%2 == 0 && S[i] != '0'){
      pattern_A++;
    }
    if(i%2 == 1 && S[i] != '1'){
      pattern_A++;
    }
    if(i%2 == 1 && S[i] != '0'){
      pattern_B++;
    }
    if(i%2 == 0 && S[i] != '1'){
      pattern_B++;
    }
  }

  if(pattern_A > pattern_B){
    cout << pattern_B << endl;
  }else{
    cout << pattern_A << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	uint64_t N, A, B;
	if (scanf("%" SCNu64 "%" SCNu64 "%" SCNu64, &N, &A, &B) != 3) return 1;
	if (A > B) { uint64_t t = A; A = B; B = t; }
	if ((B - A) % 2 == 0) {
		printf("%" PRIu64 "\n", (B - A) / 2);
	} else {
		uint64_t c1, c2;
		c1 = (A - 1) + 1 + ((B - 1) - A) / 2;
		c2 = (N - B) + 1 + (B - (A + 1)) / 2;
		printf("%" PRIu64 "\n", c1 < c2 ? c1 : c2);
	}
	return 0;
}


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

typedef long long ll;
struct edge{int to;ll cost;};

vector<edge> tree[100010];
ll dist[100010];

void dfs(int v, int p, ll d){
  dist[v]=d;
  for (auto  &e:tree[v]){
    if(e.to==p) continue;
    dfs(e.to, v, d+e.cost);
  }
}

int main(){
  int N;cin>>N;
  for (int i=0;i<N-1;++i){
    int a, b;ll c;cin>> a>>b >> c; a--,b--;
    tree[a].push_back({b,c});tree[b].push_back({a,c});
  }

  int Q, K;cin>>Q>>K;K--;
  dfs(K, -1, 0);

  for (int i=0;i<Q;++i){
    int x, y;cin>>x>>y;x--,y--;
    cout << dist[x]+dist[y] << endl;
  }

  return 0;
}

Measured memory_bytes: 14336
fn main() {
    let mode = "b";

    if mode == "a" {
        a::answer();
    } else if mode == "b" {
        b::answer();
    }
}
mod b {
    use std::io::*;

    pub fn answer() {
        let mut buf = String::new();

        stdin().read_to_string(&mut buf).unwrap();
        let mut ite = buf.split_whitespace();

        // 1行目読み捨て
        ite.next();

        let seq = ite.map(|x| x.parse::<i32>().unwrap()).collect::<Vec<_>>();

        let res = calc(&seq);

        println!("{}", res);
    }
    fn calc(a: &Vec<i32>) -> f64 {
        let mut bunbo_neta = 1f64;
        for i in 0..a.len() {
            bunbo_neta *= a[i] as f64;
        }
        let mut bunbo = 0f64;
        for i in 0..a.len() {
            bunbo += bunbo_neta / (a[i] as f64);
        }

        let bunshi: f64 = bunbo_neta;

        bunshi / bunbo
    }

    #[cfg(test)]
    mod tests {
        use super::*;
        #[test]
        fn test1() {
            assert_eq!(calc(&vec![10, 30]), 7.5);
        }
        #[test]
        fn test2() {
            let res = calc(&vec![200, 200, 200]);
            assert!(res > 66.6666 && res < 66.67);
        }
        #[test]
        fn test_b_3() {
            let res = calc(&vec![1000]);
            assert!(res == 1000.0);
        }
    }
}
mod a {
    use std::io::*;

    pub fn answer() {
        let mut buf = String::new();

        stdin().read_to_string(&mut buf).unwrap();

        let mut iter = buf.split_whitespace();

        let a = iter.next().unwrap().parse::<i32>().unwrap();
        let s = iter.next().unwrap();

        let res = calc(a, s);
        println!("{}", res);
    }

    fn calc(a: i32, s: &str) -> &str {
        if a >= 3200 {
            return s;
        }
        "red"
    }

    #[cfg(test)]
    mod tests {
        use super::*;
        #[test]
        fn test1() {
            assert_eq!("pink", calc(3200, "pink"));
        }

        #[test]
        fn test2() {
            assert_eq!("red", calc(3199, "pink"));
        }

        #[test]
        fn test3() {
            assert_eq!("red", calc(4049, "red"));
        }

    }
}


Measured memory_bytes: 4352
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long p = sc.nextLong();
		if(n==1) {
			System.out.println(p);
			return;
		}
		Map<Long,Long> sosuMap = new HashMap<Long,Long>();
		for(long i =2;i <= Math.sqrt(p);) {
			if(p % i == 0) {
				long sosuCount = 0;
				while(p % i == 0) {
					sosuCount++;
					p /= i;
				}
				sosuMap.put((long) i, sosuCount);
			}
			if(i ==2) {
				i++;
			}else {
				i+=2;
			}
		}

		long answer = 1;
		for(Map.Entry<Long, Long> entry:sosuMap.entrySet()) {
			if(entry.getValue() >= n) {
				answer *=Math.pow((double)entry.getKey(),(double)(entry.getValue() / n));

			}

		}

		System.out.println(answer);
	}

}

Measured memory_bytes: 23252
/**
 *      ///----- My Info -----///
 *      Code by: Unk
 *      Codeforces User: Ernest0_0Abreu
 *      Country: Cuba
 *      E-mail: ernestoabreup@gmail.com
 *      CopyRight
**/
#include <bits/stdc++.h>
#ifdef Ernest0_0Abreu 
#include <debug/to_string.h>
#endif
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
    	///----- My Template -----///
///===================================================================================================================================
/// Debug
#define _end cout << "\n"
#ifndef Ernest0_0Abreu
#define db(x) ;
#define dbrange(x,begin,end) ;
#define dbname(x) ;
#define dbnamerange(x,begin,end) ;
#define dbmat(x,begin_n,end_n,begin_m,end_m) ;
#define dbST(x,end) ;
#define db_end ;
#endif
///Function
#define pi (acos(-1))
#define lg2(x) 31-__builtin_clz(x)
#define lgx(x,b) log(b)/log(x)
/// Macros
#define fst first
#define scd second
#define left (node<<1)
#define right ((node<<1)+1)
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
/// Typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// Constant
const ll MAXN = 1e6+7;
const int MOD = 1e9+7;
const ull BASE = 311;
const ld EPS = 1e-9;
const int INF = ((1<<30)-1);
const ll INFLL = ((1ll<<62ll)-1ll);
const ll oo = 2e18;
/// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027;
/// Module Prime Numbers: 3,1000033, 998244353, 1000000007, 1000000009, 1000000021;
///===================================================================================================================================
#define int long long
		///----- My code -----///



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

	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	ans = min(a , k);
	k-= min(a , k);
	k-=min(b , k);
	ans-=min(c , k);

	cout << ans;
	
	return 0;
}


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

int main (){

    string S;
    cin >> S;
    map<char,int>m;
    for(int i = 0; i < 3; i++) {
        m[S[i]]++;
    }

    if(m['a'] == 1 && m['b'] == 1 && m['c'] == 1) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int INF=1001001001001001001ll;

struct segtree{
    static const int SEG=1<<18;
    vector<pint> dat;
    segtree():dat(SEG*2,pint(INF,INF)){}
    void update(int k,pint p){
        k+=SEG-1;
        dat[k]=p;
        while(k){
            k=(k-1)/2;
            dat[k]=min(dat[k*2+1],dat[k*2+2]);
        }
    }
    pint query(int a,int b,int k=0,int l=0,int r=SEG){
        if(r<=a||b<=l)return pint(INF,INF);
        if(a<=l&&r<=b)return dat[k];
        return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
};

int N;
int P[222222];

segtree odd,even;

typedef tuple<pint,pint,pint>T;

T calc(int l,int r){
    int ll,rr;
    if(l&1){
        ll=odd.query(l,r).se;
        rr=even.query(ll,r).se;

    }
    else{
        ll=even.query(l,r).se;
        rr=odd.query(ll,r).se;
    }


    return T({P[ll],P[rr]},{ll,rr},{l,r});
}

signed main(){
    cin>>N;
    rep(i,N){
        cin>>P[i];
        if(i&1)odd.update(i,pint(P[i],i));
        else even.update(i,pint(P[i],i));
    }

    priority_queue<T,vector<T>,greater<T>>que;
    que.push(calc(0,N));

    vint ans;
    while(que.size()){
        pint a,b,c;
        tie(a,b,c)=que.top();
        que.pop();

        ans.pb(a.fi);
        ans.pb(a.se);

        int l,r,ll,rr;
        tie(l,r)=c;
        tie(ll,rr)=b;

        if(l!=ll)que.push(calc(l,ll));
        if(ll+1!=rr)que.push(calc(ll+1,rr));
        if(rr+1!=r)que.push(calc(rr+1,r));
    }

    rep(i,ans.size()){
        if(i)cout<<" ";
        cout<<ans[i];
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 26160
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define Rep(i,x) for(int i=head[x];i+1;i=nxt[i])
#define rep2(i,a,b) for(int i=(a);i<(b);i++)
#define ff first
#define ss second
using namespace std;
const int N=300005;
const int inf=1e9+7;
typedef long long ll;
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}}
//------------------------------------------head---------------------------------------------------//
priority_queue<int> pq;
ll pv[N],sf[N];
int a[N];
ll sum;
int main()
{
	ll ans=-1e18;
	int n;read(n);rep(i,1,n*3)read(a[i]);
	rep(i,1,n)sum+=a[i];
	pv[n]=sum;rep(i,1,n)pq.push(-a[i]);
	rep(i,n+1,n*3)
	{
		pq.push(-a[i]);sum+=a[i];
		int xt=pq.top();sum+=xt;pq.pop();
		pv[i]=sum;
	}sum=0;while(!pq.empty())pq.pop();
	rep(i,n*2+1,n*3){pq.push(a[i]);sum+=a[i];}sf[n*2+1]=sum;
	per(i,n*2,1)
	{
		pq.push(a[i]);sum+=a[i];
		int xt=pq.top();sum-=xt;pq.pop();
		sf[i]=sum;
	}
	rep(i,n,n*2)ans=max(ans,pv[i]-sf[i+1]);
	//-rep(i,1,n*3)printf("%lld ",sf[i]);puts("");
	printf("%lld\n",ans);
	return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N;
	cin >> N;
	vec(H)
	fx(N) {
		vecp(H)
	}
	int ans = 0;
	fx(N) {
		int i = x;
		while(x+1<N&&H.at(x)>=H.at(x+1)) {
			x++;
		}
		ans = max(x - i, ans);
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int ans=-1;
    for(int i=10*b ;i<10*b+10;i++){
        if((i*8)/100==a){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,M;
  cin>>N>>M;
  priority_queue<long> P;
  
  
  for(int i=0;i<N;i++) {
    int aa;
    cin>>aa;
    P.push(aa);
  }
  
  for(int i=0;i<M;i++){
    long a=P.top();
    P.pop();
    P.push(a/2);
  }
  long S=0; 
  for(int i=0;i<N;i++){
    S+=P.top();
    P.pop();
  }
  cout<<S<<endl;
}
            

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

//const ll mod = 1e9 + 7;
const ll M = 18;
ll mod;
struct Mat
{
    ll m[3][3];
    Mat(ll v)
    {
        memset(m, 0, sizeof m);
        for(ll i = 0; i < 3; i++)
            m[i][i] = v;
    }

    Mat operator* (const Mat &a) const
    {
        Mat r(0);
        for(ll i = 0; i < 3; i++)
        {
            for(ll j = 0; j < 3; j++)
            {
                for(ll k = 0; k < 3; k++)
                {
                    r.m[i][j] = (r.m[i][j] + m[i][k] * 1ll * a.m[k][j]) % mod;
                }
            }
        }
        return r;
    }
};

ll modexp(Mat a, ll b, ll s)
{
    Mat r(1);
    while(b)
    {
        if(b & 1) r = r * a;
        a = a * a;
        b >>= 1;
    }
    return (s * 1ll * r.m[0][1] + r.m[0][2]) % mod;
}

ll modexp(ll a, ll b)
{
    ll r = 1;
    while(b)
    {
        if(b & 1) r = (r * 1ll * a) % mod;
        a = (a * 1ll * a) % mod;
        b >>= 1;
    }
    return r;
}

ll t[M+1];

ll BS(ll n, ll a, ll b, ll lmt)
{
    ll l = -1, r = n;

    while(l != r)
    {
        ll mid = (l + r + 1) >> 1;
        if(a + mid * b < lmt) l = mid;
        else r = mid - 1;
    }
    return l;
}
int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    ll l, a, b, t1 = 1;
    ll ans = 0;
    cin >> l >> a >> b >> mod;
    t[0] = -1;
    for(ll i = 1; i <= M; i++)
    {
        t1 *= 10;
        t[i] = BS(l - 1, a, b, t1);
        ll A = a + (t[i - 1] + 1) * b;
        ll n = t[i] - t[i - 1];

        if(n)
        {
            Mat a(1);
            a.m[0][0] = t1 % mod;
            a.m[0][1] = 1;
            a.m[1][2] = b % mod;

            ll r = modexp(a, n, A % mod);
            ll x = modexp(t1 % mod, n);
            ans = (ans * 1ll * x + r) % mod;
        }
    }
    cout << ans << endl;

    //double end_time = clock();
    //prllf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);

    return 0;
}


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

int main(){

  int N;

  cin>>N;

  vector<int> card(N);

  int alice=0,bob=0;

  for(int i=0; i<N; i++){
    cin>> card.at(i);
  }

  sort(card.begin(),card.end());
  reverse(card.begin(),card.end());

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

    if( i % 2 == 0) alice += card.at(i);

    if(i % 2 !=0) bob += card.at(i);

  }

  cout<<alice - bob<<endl;

  return 0;
}

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

int main(){
  int h, w; cin >> h >> w;
  vector<vector<char>> map(h, vector<char>(w));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> map.at(i).at(j);
    }
  }
  vector<int> dx = {-1, 0, 1, 0};
  vector<int> dy = {0, -1, 0, 1};
  bool ok;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(map[i][j] == '#'){
        ok = false;
      	for(int k = 0; k < 4; k++){
       	 if(i + dx[k] >= 0 && i + dx[k] < h && j + dy[k] >= 0 && j + dy[k] < w){
           if(map[i+dx[k]][j+dy[k]] == '#') ok = true;
         }
        }
      }
      if(!ok) break;
    }
    if(!ok) break;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a, b, c, s = 0;
cin >> a >> b >> c;
int f = a;
while (a < c+0.5){
    if (a > c+0.5){
        break;
    }
    s += b;
    a += f;
}
cout << s;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

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

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll N, X, Y;
	std::cin >> N >> X >> Y;
	vll ans(N + 1, 0);
	vector<queue<ll>> vq(N + 1);

	rep(i, 1, N) {
		vq[i].push(i + 1);
		vq[i + 1].push(i);
	}
	vq[X].push(Y);
	vq[Y].push(X);

	vector<vll> t(N + 1, vll(N + 1, 9999));
	repeq(i, 1, N) {
		ll cnt = 0;
		queue<ll> q;
		q.emplace(i);
		vector<bool> t(N + 1, false);
		t[i] = true;
		
		while (!q.empty()) {
			cnt++;
			queue<ll> r;
			while (!q.empty()) {
				auto s = vq[q.front()];
				while (!s.empty()) {
					if (!t[s.front()]) {
						t[s.front()] = true;
						r.push(s.front());
						ans[cnt]++;
					}
					s.pop();
				}
				q.pop();
			}
			q = r;
		}
	}

	rep(i, 1, N) {
		std::cout << ans[i]/2 << endl;
	}
	return 0;
}


Measured memory_bytes: 33664
'''
Let g(x) = 序列內數字唯一，且最多 x 個位置不同。
Let f(x) = 序列內數字唯一，且給定 x 個位置時，使這些位置不同的方法數。

題目所求是 C(N, N) f(N)。

其中 g(x) 代表有至少 N - x 個位置是相同。可以分三個部份填數字，注意順序會影響，所以要乘上全排列：
(1) N - x 個位置（數字必需相同）：C(M, N - x) * (N - x)! = P(M, N - x)
(2) 序列 A 其餘位置（可以隨便填，但不能用到 (1) 的數字）：C(M - (N - x), x) * x! = P(M - (N - x), x)
(3) 序列 B 其餘位置（可以隨便填，但不能用到 (1) 的數字）：C(M - (N - x), x) * x! = P(M - (N - x), x)
g(x) = (1) * (2) * (3)

g(x) 是「選定 0 個位置，使這些位置不同的方法數」、「選定 1 個位置，使這些位置不同的方法數」、…、「選定 x 個位置，使這些位置不同的方法數」，即
g(x) = C(x, 0) f(0) + C(x, 1) f(1) + ... + C(x, x) f(x)
     = sum( C(x, i) * f(i) for i in [0, x] )
根據二項式反演，得到
f(x) = sum( (-1) ** (x - i) * C(x, i) * g(i) for i in [0, x] )
'''

class CombMod:
    def __init__(self, V, p):
        self.fact = [1] * V
        self.finv = [1] * V
        for i in range(1, V):
            self.fact[i] = self.fact[i - 1] * i % p
        self.finv[-1] = pow(self.fact[-1], p - 2, p)
        for i in range(V - 2, 0, -1):
            self.finv[i] = self.finv[i + 1] * (i + 1) % p
        self.p = p
        
    def fact(self, a):
        return self.fact[a]
    
    def finv(self, a):
        return self.finv[a]

    def comb(self, a, b):
        return self.fact[a] * self.finv[b] % self.p * self.finv[a - b] % self.p
        
    def perm(self, a, b):
        return self.fact[a] * self.finv[a - b] % self.p
    
    def hcomb(self, a, b):
        return self.comb(a + b - 1, b)


N, M = map(int, input().split())
mod = 10**9 + 7
tool = CombMod(max(N, M) + 10, mod)

f_N = 0
for i in range(0, N + 1):
    p1 = tool.perm(M, N - i)
    p2 = tool.perm(M - (N - i), i)
    g_i = p1 * p2 % mod * p2 % mod
    val = (-1)**((N - i) % 2) * tool.comb(N, i) % mod * g_i % mod
    f_N = (f_N + val) % mod
ans = tool.comb(N, N) * f_N % mod
print(ans)


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n; cin>>n;
  vector<string> s(n); REP(i,n)cin>>s[i];
  int m; cin>>m;
  vector<string> t(m); REP(i,m)cin>>t[i];
  map<string,int> M;
  REP(i,n)M[s[i]]++;
  REP(i,m)M[t[i]]--;
  int ans = 0;
  for(auto P : M){
    CHMAX(ans,P.second);
  }
  cout<<ans<<endl;
  return 0;
}


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

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


    long long i = 0;

    vector<long long> ans(s.size(), 0);

    while(i < s.size()){
        long long start_r = i;
        long long count_even = 0, count_odd = 0;
        while(i < s.size() and s[i] == 'R'){
            if(i % 2 == 0){
                count_even++;
            }
            else{
                count_odd++;
            }
            i++;
        }
        long long end_r = i-1;
        long long start_l = i;

        while(i < s.size() and s[i] == 'L'){
            if(i % 2 == 0){
                count_even++;
            }
            else{
                count_odd++;
            }
            i++;
        }
        long long end_l = i-1;

        if(end_r % 2 == 0){
            ans[end_r] = count_even;
            ans[start_l] = count_odd;
        }
        else{
            ans[end_r] = count_odd;
            ans[start_l] = count_even;
        }

    }

    for(long long j = 0; j < ans.size(); j++){
        printf("%lld ", ans[j]);
    }

    printf("\n");

    return 0;

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

int main(){
    int n;  cin >> n;
    vector<ll> a(n);
    ll sum=0;
    REP(i, n){
        cin >> a.at(i);
        sum += a.at(i);
    }
    sort(ALL(a));
    REP(i, n){
        ll tmp=sum;
        FOR(j, i, n){
            if(tmp%10!=0){
                cout << tmp << endl;
                return 0;
            }
            tmp = sum-a[j]; 
        }
        sum -= a[i];    
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 256
lst_1 = input().split()

A = int(lst_1[0])
B = int(lst_1[1])
C = int(lst_1[2])

ans = 0

while 1:

    if (A > B) or (C == 0):
        break
    B -= A
    ans += 1
    C -= 1

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N, D, M, T;
	map<int, int> ma;

	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d", &D);
		ma[D]++;
	}
	scanf("%d", &M);
	bool def = true;
	for(int i = 0; i < M; i++){
		scanf("%d", &T);
		ma[T]--;
		if(ma[T] < 0) def = false;
	}
	printf(def ? "YES\n" : "NO\n");
	return 0;
}


Measured memory_bytes: 9600