akhauriyash/Code-Regression huggingface dataset:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(D, C, S, T, M, Q):
    def evaluate(i, t, satisfaction, last):
        satisfaction += S[i][t]
        last[t] = i
        for j, c in enumerate(C):
            satisfaction -= c * (i - last[j])
        return (satisfaction, last)

    satisfaction = 0
    last = [-1] * 26
    count = [BinaryIndexedTree(D) for _ in range(26)]
    for i, t in enumerate(T):
        satisfaction, last = evaluate(i, t, satisfaction, last)
        count[t].add(i, 1)

    for d, new in Q:
        old = T[d]
        satisfaction += S[d][new] - S[d][old]
        cnt_old = count[old].query(d)
        nxt_d_old = count[old].bisect(lambda x: x < cnt_old + 1)
        pre_d_old = count[old].bisect(lambda x: x < cnt_old - 1) if cnt_old > 1 else -1
        satisfaction -= C[old] * (nxt_d_old - d) * (d - pre_d_old)
        T[d] = new
        count[old].add(d, -1)
        count[new].add(d, 1)
        cnt_new = count[new].query(d)
        nxt_d_new = count[new].bisect(lambda x: x < cnt_new + 1)
        pre_d_new = count[new].bisect(lambda x: x < cnt_new - 1) if cnt_new > 1 else -1
        satisfaction += C[new] * (nxt_d_new - d) * (d - pre_d_new)
        print(satisfaction)

class BinaryIndexedTree:
    def __init__(self, n=None, f=lambda x, y: x + y, identity=0, initial_values=None):
        assert(n or initial_values)
        self.__f, self.__id, = f, identity
        self.__n = len(initial_values) if initial_values else n
        self.__d = [identity] * (self.__n + 1)
        if initial_values:
            for i, v in enumerate(initial_values): self.add(i, v)

    def add(self, i, v):
        n, f, d = self.__n, self.__f, self.__d
        i += 1
        while i <= n:
            d[i] = f(d[i], v)
            i += -i & i

    def query(self, r):
        res, f, d = self.__id, self.__f, self.__d
        r += 1
        while r:
            res = f(res, d[r])
            r -= -r & r
        return res

    def bisect(self, func):
        n, f, d, v = self.__n, self.__f, self.__d, self.__id
        x, i = 0, 1 << (n.bit_length() - 1)
        while i > 0:
            if x + i <= n and func(f(v, d[x + i])): v, x = f(v, d[x + i]), x + i
            i >>= 1
        return x

if __name__ == '__main__':
    input = sys.stdin.readline
    D = int(input())
    *C, = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(D)]
    T = [int(input()) - 1 for _ in range(D)]
    M = int(input())
    Q = [tuple(map(lambda x:int(x) - 1, input().split())) for _ in range(M)]
    main(D, C, S, T, M, Q)


Measured memory_bytes: 17468
//by Tipa_Top1
#include <bits/stdc++.h>                   

#define f first
#define s second
#define ll long long 
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, n) for (int i = 1; i <= n; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return
#define rep(i, a, b) for(int i = a; i <= b; i++) 

using namespace std;

const int mod = 1e9 + 7;
const int maxn = 1e6 + 111;

int n, a[maxn], sum;

main(){
	cin >> n;

	rep(i, 1, n){
		cin >> a[i];
		sum += a[i];
	}

	if (sum % (n * (n + 1) / 2) != 0){
		puts("NO");
		return 0;
	}

	int k = sum / (n * (n + 1) / 2), cur = 0;

	a[n + 1] = a[1];

	for (int i = 2; i <= n + 1; i++){
		if (a[i] - a[i - 1] - k > n || abs(a[i] - a[i - 1] - k) % n){
			puts("NO");
			return 0;
		}
		cur += abs(a[i] - a[i - 1] - k);
	}

	if (cur != k * n)
		puts("NO");
	else
		puts("YES");
}

Measured memory_bytes: 1152
dish = [int(input()) for i in range(5)]

cnt = 10
m = 0
for i in range(5):
    if dish[i] % 10 != 0 and dish[i] % 10 < cnt:
        cnt = dish[i] % 10
        m = i

ans = dish.pop(m)
for d in dish:
    if d % 10 == 0:
        ans += d
    else:
        ans += 10 * (d//10+1)

print(ans)


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

int main(){
    
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n)cin >> v[i];

    double ans = 0;

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

    ans = v[0];
    for(int i=1;i<n;i++){
        ans = (ans + v[i])/2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>
#include <set>
#include <vector>
using namespace std;

int main(){
    int n, k;
    cin>>n>>k;
    int tori = 0;
    int i;
    int tmp = 0;
    for(i=1; i<=n; i++){
        if(i==1){
            tori = k;
        }
        else{
            tori *= k-1;
        }
    }
    cout<<tori<<endl;
    return 0;
}

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

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int N;
    cin>>N;
    vector<int> A(N),B(N);
    REP(i,N){
      cin>>A[i]>>B[i];
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    if(N%2==0){
      cout<<(((B[N/2-1]+B[N/2])-(A[N/2-1]+A[N/2]))+1)<<endl;
    }else{
      cout<<B[N/2]-A[N/2]+1<<endl;
    }

    
}


Measured memory_bytes: 4768
a, b, c = map(int, input().split())
x = y = 0
for i in range(c):
    d, e, f = map(int, input().split())
    if f == 1:
        x = max(x, d)
    elif f == 2:
        a = min(a, d)
    elif f == 3:
        y = max(y, e)
    elif f == 4:
        b = min(b, e)
if x >= a or y >= b:
    print(0)
else:
    print(abs(a - x) * abs(b - y))

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int A, B;
	cin >> A >> B;
	cout << (A * B % 2 == 1 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=2e5+5,Mo=1e9+7,i2=Mo+1>>1;

int pwr(int x,int y) {
	int z=1;
	for(;y;y>>=1,x=(ll)x*x%Mo)
		if (y&1) z=(ll)z*x%Mo;
	return z;
}

int n,s,a[N],cnt[N],val[N],tr[N],Mx[N],pre[N];

void C() {fo(i,1,n) tr[i]=0;}
void I(int x,int y) {for(;x<=n;x+=x&-x) (tr[x]+=y)%=Mo;}
int Q(int x) {int r=0;for(;x;x-=x&-x) (r+=tr[x])%=Mo;return r;}

int calc(int l,int r) {
	if (Mx[l]==Mx[r]&&Mx[l]) return (ll)s*pre[r]%Mo*pwr(pre[l-1],Mo-2)%Mo;
	return 0;
}

int main() {
	n=read();
	fo(i,1,n) cnt[a[i]=read()]++;
	fd(i,n,1) cnt[i]+=cnt[i+1];
	int ans=0;s=1;
	fo(i,1,n) s=(ll)s*(cnt[i]-n+i)%Mo;
	if (!s) {puts("0");return 0;}
	fo(i,1,n) val[i]=(ll)(cnt[i]-n+i-1)*pwr(cnt[i]-n+i,Mo-2)%Mo;
	int la=n;
	fd(i,n,1) {
		if (!val[i]) {
			pre[i]=1;
			fo(j,i+1,la) pre[j]=(ll)pre[j-1]*val[j]%Mo;
			la=i-1;
		} else Mx[i]=la;
	}
	fd(i,n,1) {
		(ans+=(ll)s*Q(a[i]-1)%Mo)%=Mo;
		I(a[i],1);
	}
	C();
	fo(i,1,n) {
		if (val[a[i]+1]) {
			int ret=(Q(Mx[a[i]])-Q(a[i])+Mo)%Mo;
			(ans-=(ll)s*ret%Mo*pwr(pre[a[i]],Mo-2)%Mo*i2%Mo)%=Mo;
		}
		I(a[i],pre[a[i]]);
	}
	C();
	fd(i,n,1) {
		if (val[a[i]+1]) {
			int ret=(Q(Mx[a[i]])-Q(a[i])+Mo)%Mo;
			(ans+=(ll)s*ret%Mo*pwr(pre[a[i]],Mo-2)%Mo*i2%Mo)%=Mo;
		}
		I(a[i],pre[a[i]]);
	}
	fo(i,1,n) cnt[i]=0;
	fo(i,1,n) cnt[a[i]]++;
	fo(i,1,n) (ans+=(ll)s*cnt[i]%Mo*(cnt[i]-1)%Mo*i2%Mo*i2%Mo)%=Mo;
	printf("%d\n",(ans+Mo)%Mo);
	return 0;
}

Measured memory_bytes: 4864
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int a = 0, b = 0, c = 0;
    for(auto& ch : s){
        a += ch == 'a';
        b += ch == 'b';
        c += ch == 'c';
    }
    cout << (max({a, b, c}) - min({a, b, c}) <= 1 ? "YES" : "NO") << '\n';
}


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
//#define max(a,b) (a>b ? a : b)
//#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int INF = 100000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;

void show_2d(int h, int w, vector<vi> &v){
    rep(i, h)rep(j, w){cout << v[i][j];}cout <<endl;
}

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> S(h, vector<char>(w));
    rep(i,h)rep(j,w) cin >> S[i][j];
    
    vector<vi> dp(h, vi(w, INF));
    dp[0][0] = 0;
    
    rep(i,h)rep(j,w){
        if(i+1<h){
            if(S[i][j]!=S[i+1][j]) dp[i+1][j] = min(dp[i+1][j],dp[i][j]+1);
            else dp[i+1][j] = min(dp[i+1][j],dp[i][j]);    
        }
        if(j+1<w){
            if(S[i][j]!=S[i][j+1]) dp[i][j+1] = min(dp[i][j+1],dp[i][j]+1);
            else dp[i][j+1] = min(dp[i][j+1],dp[i][j]);    
        }
    }
    
    int ans = dp[h-1][w-1]/2;
    if(S[0][0]=='#') ans++;
    else if(S[h-1][w-1]=='#') ans++;
    cout << ans << endl;
}

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

char a[52][52];
bool visit[52][52];
int u, cnt;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

void dfs(int y, int x){
	++cnt;

	for(int i = 0; i < 4; ++i){
		int ny = y + dy[i], nx = x + dx[i];
		switch( a[ny][nx] ){
			case '.':
				if( !visit[ny][nx] ){
					visit[ny][nx] = true;
					dfs(ny, nx);
				}
				break;
			case 'B':
				u |= 1;
				break;
			case 'W':
				u |= 2;
				break;
		}
	}
}

int main(){
	int w, h;
	while(scanf("%d%d", &w, &h), w != 0){
		int ans[4] = {};

		memset(a, 0, sizeof a);
		memset(visit, 0, sizeof visit);

		for(int i = 1; i <= h; ++i){
			scanf(" %s", a[i] + 1);
		}

		for(int i = 1; i <= h; ++i)
		for(int j = 1; j <= w; ++j){
			if( !visit[i][j] && a[i][j] == '.' ){
				visit[i][j] = true;
				u = cnt = 0;
				dfs(i, j);
				ans[u] += cnt;
			}
		}
		
		printf("%d %d\n", ans[1], ans[2]);
	}
}

Measured memory_bytes: 1112
#include<stdio.h>
int main(void)
{
    int kyo[10],i,j,temp,sum;
    for(i=0;i<6;i++){
        scanf("%d",&kyo[i]);
    }
    for(i=0;i<4;i++){
      for(j=i;j<4;j++){
          if(kyo[i]<kyo[j]){
          temp=kyo[i];
          kyo[i]=kyo[j];
          kyo[j]=temp;
          }
      }  
    }
    sum=kyo[0]+kyo[1]+kyo[2];
    if(kyo[4]<kyo[5]){
        sum=sum+kyo[5];
    }
    else{
        sum=sum+kyo[4];
        }
    printf("%d\n",sum);
	return 0;
}



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

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

    string s;
    cin >> s;
    
    char base = (s[0] == '0')? '1' : '0';
    
    int ans = 0;
    
    rep(i, s.size()){
        if(base == s[i]){
            base = (s[i] == '0')? '1' : '0';
            ans++;
        }else{
            base = s[i];
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
N, M = map(int,input().split()) 
a = []
for i in range(M):
    l, r = map(int,input().split())
    a.append((r, l))
a.sort()
ans = 0
last = -1
for i in range(0, M):
    r, l = a[i]
    if last <= l:
        ans = ans + 1
        last = r
print (ans)


Measured memory_bytes: 17016
a,b,c,x,y=map(int,input().split())

def cal(cp):
    res=2*cp*c
    xx=x-cp
    yy=y-cp
    res+=a*max(0,xx)+b*max(0,yy)
    return res

ans=[cal(0),cal(x),cal(y),cal(x+y)]
print(min(ans))

Measured memory_bytes: 3064
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

template <typename T>
T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T>
T lcm(T m, T n) { return n * m / gcd(n, m); }

signed main(void)
{
  int n;
  cin >> n;
  string s;
  cin >> s;

  vector<int> c(n);
  c[0] = 1;

  for (int i = 1; i < n; ++i)
  {
    if (s[i - 1] != s[i])
      c[i] = 1;
  }

  cout << accumulate(c.begin(), c.end(), 0) << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */

int main() {
  string s; cin >> s;
  REP(i, s.size()-1){
    if(s[i] == s[i+1]){
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
}


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

int main()
{
	int n, i, i2;
	int prime[10000];
	for(int i=2; i<= 10000; i++){
		prime[i]=1;
		for(i2 = 2; i2<=sqrt(i); i2++)
		{
			if(i % i2 == 0)
			{
				prime[i] = 0;
				break;
			}
		}
	}
	while(1)
	{
		scanf ("%d",&n);
		if(n==0)
		{
			return 0;
		}
		for(i=n; 1; i--)
		{
			if(prime[i] && prime[i-2])
			{
				printf("%d %d\n",i-2 ,i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2700
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  string march = "MARCH";
  int n; scan(n);
  vector<string> s(n);
  scan(s);
  vll cnt(5, 0);
  rep (i, n) {
    rep (j, 5) {
      if (s[i][0] == march[j]) {
        cnt[j] += 1;
      }
    }
  }
  ll ans = 0;
  rep (i, (1 << 5)) {
    if (__builtin_popcount(i) != 3) { continue; }
    ll add = 1;
    rep (j, 5) {
      if ((i >> j) & 1) {
        add *= cnt[j];
      }
    }
    ans += add;
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
int main(){
    int N;
    cin >> N;
    vector<int> A;
    for(int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    sort(A.begin(), A.end(), greater<int>());
    int ans = 0;
    for(int i=0; i<N; i++){
        if(i%2 == 0) ans += A[i];
        else ans -= A[i];
    }
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

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

    long d = a / b;
    long r = a % b;
    double f = (double)a / (double)b;
    printf("%ld %ld %.5f\n", d, r, f);
}



Measured memory_bytes: 3156
#include <iostream>
#include<vector>
using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int>A(N-1);
	vector<int>c(N,0);
	for (int i = 0; i < N-1; i++) {
		cin >> A[i];
		c[A[i]-1] = c[A[i]-1] + 1;
	}
	for (int i = 0; i < N; i++)
		cout << c[i]<<endl;
	return 0;
}

Measured memory_bytes: 4772
<?php
fscanf(STDIN, '%d %d', $a, $b);
$ans = -1;
for ($i = 1; $i <= 2000; $i++) {
    $x = intval(floor($i * 0.08));
    $y = intval(floor($i * 0.10));
    if ($x === $a && $y === $b) {
        $ans = $i;
        break;
    }
}
echo $ans . PHP_EOL;

Measured memory_bytes: 4856
#include <stdio.h>
int main() {
	int n;
	int i = 0;
	scanf("%d", &n);
	int num[50];
	for (i = 0; i <= n - 1; i++) { scanf("%d", &num[i]); }
	int j, temp;
	for (i = 0; i < n - 1; i++) {
		for (j = i + 1; j <= n - 1; j++)
		{
			if (num[i] > num[j]) { temp = num[i]; num[i] = num[j]; num[j] = temp; }
		}
	}
		float ans = ((float)num[0] + (float)num[1]) / 2;
		for (i = 2; i <= n - 1; i++) {
			ans += (float)num[i];
			ans /= 2;
		}
		printf("%g", ans);
		return 0;
	}


Measured memory_bytes: 128
#include<iostream>
#include<functional>
#include<queue>
#include<deque>
#include<vector>
#include<algorithm>
using namespace std;

inline void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (true) {
		k = getchar_unlocked();
		if (k < '0') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
inline void writeln(int x) {
	int s = 0, p; char f[7];
	while (x) {
		p = x; x /= 10;
		f[s++] = p - (x << 1) - (x << 3);
	}
	if (!s) f[s++] = 0;
	while (s--) putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}
#pragma warning(disable:4996)
int n, m, q, a[200003], b[200003], c[200003], d[200003], e[100003], f[100003], g[100003];
int h1[100003], h2[100003], h3[100003], h4[100003], dist[100003], E[200003];
vector<pair<int, int> > z[100003]; vector<int> x[100003];
vector<int>D[100003];
int Q1[110000], Q1L, Q1R;
int main() {
	reader(&n); reader(&m); reader(&q);
	fill(d, d + m + 1, 1 << 30);
	for (int i = 1; i <= m; i++) { reader(&a[i]), reader(&b[i]); f[a[i]]++; f[b[i]]++; }
	for (int i = 1; i <= q; i++) reader(&c[i]), d[c[i]] = i;
	for (int i = 1; i <= n; i++) { x[i].resize(f[i]); }
	for (int i = 1; i <= m; i++) {
		x[a[i]][g[a[i]]] = b[i]; g[a[i]]++;
		x[b[i]][g[b[i]]] = a[i]; g[b[i]]++;
	}
	fill(dist, dist + n + 1, -1); dist[1] = 0;
	Q1[0] = 1; Q1R = 1;
	while (Q1R > Q1L) {
		int a1 = Q1[Q1L]; Q1L++;
		for (int i : x[a1]) {
			if (dist[i] == -1) {
				dist[i] = dist[a1] + 1;
				Q1[Q1R] = i; Q1R++;
			}
		}
	}
	for (int i = 1; i <= m; i++) {
		if (dist[a[i]] > dist[b[i]]) h1[a[i]]++;
		if (dist[b[i]] > dist[a[i]]) h1[b[i]]++;
	}
	for (int i = 1; i <= n; i++)z[i].resize(h1[i]);
	for (int i = 1; i <= m; i++) {
		if (dist[a[i]] > dist[b[i]]) { z[a[i]][h2[a[i]]] = make_pair(b[i], d[i]); h2[a[i]]++; }
		if (dist[b[i]] > dist[a[i]]) { z[b[i]][h2[b[i]]] = make_pair(a[i], d[i]); h2[b[i]]++; }
	}
	for (int i = 1; i <= n; i++) h3[dist[i]]++;
	for (int i = 0; i <= n; i++) D[i].resize(h3[i]);
	for (int i = 1; i <= n; i++) D[dist[i]][h4[dist[i]]] = i, h4[dist[i]]++;
	e[1] = (1 << 30);
	for (int i = 1; i <= n; i++) {
		for (int j : D[i]) {
			for (pair<int, int>k : z[j]) {
				e[j] = max(e[j], min(e[k.first], k.second));
			}
		}
	}
	for (int i = 2; i <= n; i++) {
		if (e[i] < 300000) E[e[i]]++;
	}
	for (int i = 1; i <= q; i++) {
		E[i] += E[i - 1];
		writeln(E[i]);
	}
	return 0;
}

Measured memory_bytes: 24972
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define endl "\n"

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

signed main() {
	crap;

	int n;
	cin >> n;

	vi arr(n);
	bool zero = false;

	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
		if (arr[i] == 0) {
			zero = true;
		}
	}

	if (zero) {
		cout << 0 << endl;
	} else {
		int prod = 1;
		for (int i = 0; i < n; ++i) {


			if (prod > (1000000000000000000 / arr[i])) {
				cout << -1 << endl;
				return 0;
			}
			prod = prod * arr[i];
		}

		cout << prod << endl;
	}



	return 0;
}

Measured memory_bytes: 3964
n = int(input())
aaa = list(map(int, input().split()))
ans = 0
for i in range(1, n):
    if aaa[i - 1] > aaa[i]:
        ans += aaa[i - 1] - aaa[i]
        aaa[i] = aaa[i - 1]
print(ans)


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

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, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n, m; std::cin >> n >> m;
    vector<set<int>> to(n);
    rep(i, m) {
        int a, b; std::cin >> a >> b;
        --a, --b;
        to[a].insert(b), to[b].insert(a);
    }
    bool ok = false;
    for (auto &v : to[0]) {
        if (to[v].find(n-1) != to[v].end()) ok = true;
    }
    std::cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << "\n";
}


Measured memory_bytes: 28416
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  int i, j, k, v, sum = 0, ar[101][101], b[101][101], r, c;
    while(cin>>r>>c>>v)
    {
        for(i = 0; i < r; i++)
        {
            for(j = 0; j < c; j++)
            {
                cin >> ar[i][j];
            }
        }
        for(i = 0; i < c; i++)
        {
            for(j = 0; j < v; j++)
            {
                cin >> b[i][j];
            }
        }
        for(i = 0; i < r; i++)
        {
            for(j = 0; j < v; j++)
            {
                for(k = 0; k < c; k++)
                {
                    sum = sum + ar[i][k] * b[k][j];
                }
                if(j == v - 1)
                {
                    cout << sum;
                }
                else
                {
                    cout << sum << " ";
                }
                sum = 0;
            }
            cout << endl;
        }
        sum = 0;
    }
}




Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
void cput(string &s, char c, int n) {
  rep(i,n) {
    s += c;
  }
}

int main () {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int dx = tx -sx;
  int dy = ty- sy;

  string ans;
  cput(ans, 'U', dy);
  cput(ans, 'R', dx);
  cput(ans, 'D', dy);
  cput(ans, 'L', dx);

  cput(ans, 'L', 1);
  cput(ans, 'U', dy+1);
  cput(ans, 'R', dx+1);
  cput(ans, 'D', 1);
  cput(ans, 'R', 1);
  cput(ans, 'D', dy+1);
  cput(ans, 'L', dx+1);
  cput(ans, 'U', 1);

  cout << ans << endl;
}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
#define MAX 100000

int parent(int i) 
{
	return i / 2;
}

int left(int i)
{
	return i * 2;
}

int right(int i)
{
	return i * 2 + 1;
}

int main(void)
{
	int H, i, A[MAX + 1];

	cin >> H;

	for (i = 1; i <= H; i++) {
		cin >> A[i];
	}

	for (i = 1; i <= H; i++) {
		cout << "node " << i << ": key = " << A[i] << ", ";
		if (parent(i) >= 1) {
			cout << "parent key = " << A[parent(i)] << ", ";
		}
		if (left(i) <= H) {
			cout << "left key = " << A[left(i)] << ", ";
		}
		if (right(i) <= H) {
			cout << "right key = " << A[right(i)] << ", ";
		}
		cout << endl;

	}


	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,x,n) for(int i=x;i<n;++i)

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

    int a = stoi(s.substr(0,2));
    int b = stoi(s.substr(2,2));
    bool a_may_month = (0<a && a<=12);
    bool b_may_month = (0<b && b<=12);

    if(a_may_month && b_may_month) cout << "AMBIGUOUS" << endl;
    else if(a_may_month) cout << "MMYY" << endl;
    else if(b_may_month) cout << "YYMM" << endl;
    else cout << "NA" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    ll n; cin >> n;
    vector<ll> v(n);
    for(int i=0;i<n;i++){
        cin >> v.at(i);
    }
    ll cnt =0;
    for(int i=0;i<n;i++){
        if(v.at(i)<0){
            cnt++;
            v.at(i) = 0-v.at(i);
        }
    }
    ll sum = 0;
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
        sum += v.at(i);
    }
    ll ans = 0;
    if(cnt%2==0){
        ans = sum;
    }else{
        ans = sum - v[0]*2; 
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = (ll)1e9 + 7;

int main() {
  string s;
  cin >> s;
  int mx = 0;
  int m = 0;
  bool rain = false;
  rep(i, s.size()) {
    if (s[i] == 'R')
      rain = true;
    else
      rain = false;
    if (rain) m++;
    mx = max(mx, m);
    if (!rain) m = 0;
  }
  cout << mx << endl;

  return 0;
}


Measured memory_bytes: 3628
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll L[100], R[100];

int main(){
  ll N; cin >> N;
  if (N == 0){
    cout << 0 << endl;
    return 0;
  }

  ll now = 1, ans_length = 0;
  for (int i = 1; i < 100; i++){
    L[i] = L[i - 1]; R[i] = R[i - 1];
    if (now > 0) R[i] += now;
    else L[i] += now;

    now *= -2;
    if (L[i] <= N && N <= R[i]) {
      ans_length = i; break;
    }
  }
  
  now/=-2;
  for (int i = ans_length - 1; i >= 0; i--){
    if (L[i] <= N && N <= R[i]){
      cout << 0;
    }else{
      cout << 1;
      N -= now;
    }
    now /= -2;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main() {
	string st;
	cin >> st;
	int ans(0);
	vector<char> vec;
	for(auto i : st) {
		if(i == 'S') {
			vec.push_back(i);
		}else {
			if(vec.size() >= 1 && vec.back() == 'S') {
				vec.pop_back();
			}else {
				vec.push_back(i);
			}
		}
	}
	cout << vec.size() << endl;
}


Measured memory_bytes: 772
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;



void run_case() {
    LL a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a*c, b*d), max(a*d, b*c));

}


int main() {
    //freopen("input", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(6);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3636
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, costs[25], vals[25];

int main() {
	scanf("%lld", &N);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &vals[i]);
	}
	for(int i = 0; i < N; i++) {
		scanf("%lld", &costs[i]);
	}
	ll ans = 0;
	for(int i = 0; i < 1 << N; i++) {
		ll curr = 0;
		for(int j = 0; j < N; j++) {
			if((1 << j) & i) {
				curr -= costs[j];
				curr += vals[j]; 
				// cout << j << " " <<i<< " "<< curr << " "<< " \n";
			}
		}
		ans =  max(ans, curr);
	}
	printf("%lld\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        int ans = (s+t).length();

        for(int i = 0;i < n;i++){
            String a = s.substring(i,n);
            String b = t.substring(0,n-i);
            if(a.equals(b)){
                ans -= a.length();
                break;
            }
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 21844
def solve():
    S = input()
    n = S.count('N')
    e = S.count('E')
    w = S.count('W')
    s = S.count('S')
    if (n and not s) or (not n and s) or (e and not w) or (not e and w):
        print('No')
    else:
        print('Yes')

if __name__ == "__main__":
    solve()

Measured memory_bytes: 61776
def inpl(): return list(map(int, input().split()))

S = list(input())
T = list(input())
S.sort()
T.sort(reverse=True)

for i in range(min(len(S), len(T))):
    if S[i] < T[i]:
        print("Yes")
        exit()
    elif S[i] == T[i]:
        continue
    else:
        print("No")
        exit()
if len(S) >= len(T):
    print("No")
else:
    print("Yes")

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

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }

    for (int i = K; i < N; i++){
        if(A[i] > A[i-K]){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4052
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: w,h,x,y,bunkatsu

    read*, w,h,x,y
    bunkatsu=0
    if (2*x==w .and. 2*y==h) bunkatsu=1
    print*, dble(w*h)/2d0, bunkatsu
end program name

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 10007;

signed main() {
	int N; cin >> N;
	string S; cin >> S;
	int dp[1010][8] = {};
	rep(i, 4, 8)dp[0][i] = 1;
	unordered_map<char, int> map;
	map['J'] = 2;
	map['O'] = 1;
	map['I'] = 0;
	rep(i, 0, S.size()) {
		//dumpc(dp[i]);
		rep(j, 0, 8) {
			rep(k, 0, 8) {
				if ((k&(1 << map[S[i]])) == 0)continue;
				if ((j&k) == 0)continue;
				//cerr << "dp[" << i + 1 << "][" << bitset<3>(j) << "]+=dp[" << i << "][" << bitset<3>(k) << "]" << endl;;
				dp[i + 1][j] += dp[i][k];
				if (i < S.size() - 5)dp[i + 1][j] %= MOD;
			}
		}
	}
	cout << (*max_element(dp[S.size()], dp[S.size()] + 8)) % MOD << endl;
	return 0;
}

Measured memory_bytes: 3220
fun main(args: Array<String>) {
    while (true) {
        val (m, f, r) = readLine()!!.split(" ").map(String::toInt)

        if ((m == -1) and (f == -1) and (r == -1)) {
            break
        }

        if ((m == -1) or (f == -1)) {
            when {
                50 <= r -> println("C")
                else -> println("F")
            }
        } else {
            val totalScore = m + f
            when {
                80 <= totalScore -> println("A")
                (65 <= totalScore) and (totalScore < 80) -> println("B")
                (50 <= totalScore) and (totalScore < 65) -> println("C")
                (30 <= totalScore) and (totalScore < 50) -> if (50 <= r) {println("C")} else {println("D")}
                else -> println("F")
            }
        }
    }
}



Measured memory_bytes: 31992
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N; 
  vector<int> L(2010);
  cin >> N;
  for (int i=0; i<N; i++) cin >> L[i];

  sort(L.begin(), L.begin()+N);

  int ans = 0;
  for (int i=0; i<N; i++){
    for (int j=i+1; j<N; j++){
      for (int k=j+1; k<N; k++){
        if(L[k] < L[i] + L[j])
          ans++;
        else
          break;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
a=list(map(int,input().split()))
a.sort()

if (max(a)-a[0])%2==0 and (max(a)-a[1])%2==0:
    print(int((max(a)*3-sum(a))/2))
elif (a[2]-a[0])%2==1 and (a[2]-a[1])%2==1:
    print(int((max(a)*3-sum(a))/2))
else:
    print(int((max(a)*3-sum(a))/2)+2)

Measured memory_bytes: 38256
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Long> list = new ArrayList<>();
    final List<Long> list2 = new ArrayList<>();
    int n = sc.nextInt();
    long d = sc.nextLong();
    int count = 0;
    long dis = 0;
    long d2 = d*d;

    for(int i = 0; i < n ; i++){
        list.add(sc.nextLong());
        list2.add(sc.nextLong());
    }

    for(int i = 0; i < n ; i++){
        dis = list.get(i) * list.get(i) + list2.get(i) * list2.get(i);
        if(dis <= d2){
            count++;
        }
        //System.out.println(dis + " " + d2);
    }

    System.out.println(count);

    
    






}
}

Measured memory_bytes: 73768
#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);
    int n;
    cin>>n;
    multiset<ll> cnt;
    rep(i,n){
      ll a;
      cin>>a;
      if(i==0){
        cnt.insert(a);
        continue;
      }
      auto itr=cnt.lower_bound(a);
      if(itr==begin(cnt)){
        cnt.insert(a);
        continue;
      }
      //cout<<' '<<*itr<<endl;
      itr--;
      if(*itr>=a) cnt.insert(a);
      else{
        cnt.erase(itr);
        cnt.insert(a);
      }
      /*
      for(auto itr:cnt) cout<<itr<<' ';
      cout<<endl;
      */
    }
    cout<<len(cnt)<<endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint,int> pi;
typedef long long lint;
map<int ,int> mp;
int query(int x)
{
	if(mp.find(x)!=mp.end())	return  mp[x];
	cout<<x<<endl;
	fflush(stdout);
	string s;
	cin>>s;
	if(s=="Vacant")	exit(0);
	return mp[x]=(s=="Male");
}
int main()
{
	int n;
	cin>>n;
	int s=0,e=n-1;
	while(e-s>=2)
	{
		int m=(s+e)/2;
		if((query(m)^(m%2))!=(query(s)^(s%2)))
		{
			e=m;
		}
		else	s=m;
	}
	for(int i=s;i<=e;i++)	query(i);
	return 0; 
}

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

int dp[105][4][2];

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int K;
  cin >> K;
  dp[0][0][0] = 1;
  rep(i,n)rep(j,4)rep(k,2){
    int nd = s[i] - '0';
    rep(d,10){
      int ni = i+1, nj = j, nk = k;
      if (d != 0) nj++;
      if (nj > K) continue;
      if (k == 0){
        if(d > nd) continue;
        if(d < nd) nk = 1;
      }
      dp[ni][nj][nk] += dp[i][j][k];
    }
  }
  int ans  = dp[n][K][0]+dp[n][K][1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
num = [-1]*N
err = False
for _ in range(M):
  s, c = map(int, input().split())
  if num[s-1] == -1:
    num[s-1] = c
  else:
    if num[s-1] != c:
      err = True
if err or (N > 1 and num[0] == 0):
  print(-1)
else:
  ans = 0
  i = 0
  n = 0
  while i < N:
    if num[i] < 0:
      n = 1 if i == 0 and N > 1 else 0
    else:
      n = num[i]
    ans = ans * 10 + n
    i += 1
  print(ans)

Measured memory_bytes: 38384
# 2019/08/16

n,x=map(int,input().split())
a=list(map(int,input().split()))


def solve():
    cnt=0
    for i in range(n-1):
        tmp=a[i]+a[i+1]-x
        if tmp>0:
            cnt+=tmp
            if tmp>a[i+1]:
                buf=tmp-a[i+1]
                a[i]-=buf
                tmp-=buf
            a[i+1]-=tmp
    return cnt

ans=solve()
print(ans)

Measured memory_bytes: 14544
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
	cin >> N;
	int s = 0;
	for (int i = 0; i < N;  i++) {
		int l, r;
		cin >> l >> r;
		for(int n = l-1; n < r; n++){
			s++;
		}
	}
	cout << s << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	cout << (a+b)%24 << endl;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    int m;
    cin >> m;
    vector<int> b(m);
    for(int i = 0; i < m; i++){
      cin >> b[i];
    }
    cout << lexicographical_compare(a.begin(), a.end(), b.begin(), b.end()) << endl;
}


Measured memory_bytes: 3176
// author:-*mdragneell*

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define pi  pair<int,int>
#define pl  pair<ll,ll>

int const N=500005;
ll min(ll x,ll y) { if(x<y) return x; else return y; }
ll max(ll x,ll y) { if(x>y) return x; else return y; }

ll cache[N],n,m;
vector<ll>gr[N],vis(N,0);

ll longestpath(ll node)
{
	//vis[node]=1;
	if(cache[node]) return cache[node];
	ll temp=0;

	for(int i=0;i<gr[node].size();i++)
	{
				temp=max(temp,longestpath(gr[node][i]))	;
	}
	return cache[node]=max(cache[node],1+temp);

}

int main()
{
	ll i,j;
	cin>>n>>m;
	memset(cache,0,sizeof(cache));

	for(i=0;i<m;i++)
	{
		ll x,y;  cin>>x>>y;
		gr[x].pb(y);
	}
	ll ans=0;

	for(i=1;i<=n;i++){
		ans=max(ans,longestpath(i)-1);
	}
	cout<<ans<<endl;





}


Measured memory_bytes: 24960
#include <iostream>
#include <stdlib.h>
#include <ctype.h>
#include <algorithm>
#include <string>

using namespace std;

const int MAX_S = 10;
char s1[MAX_S], s2[MAX_S], s3[MAX_S];

int main()
{
	//入力
	cin >> s1 >> s2 >> s3;
	char a = toupper(*s1);
	char b = toupper(*s2);
	char c = toupper(*s3);

	cout << a << b << c << endl;
    return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	vector<int> dp(10001, 0);
	dp[0] = 1;
	for(int i = 0; i < n; i++) {
		int a;
		cin >> a;
		for(int j = 10001 - a; j >= 0; j--) {
			if(dp[j]) {
				dp[j + a]++;
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < 10001; i++) {
		if(dp[i] && i % 10 != 0) {
			ans = max(i, ans);
		}
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, deque
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# H, K, = map(int, input().split())
N = int(input())
L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

for i in range(N):
    L[i] = (L[i], i)

L.sort()
print(*[v[1] + 1 for v in L])

Measured memory_bytes: 22692
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>

using namespace std;


int main()
{
	int N;
	cin >> N;
	
	vector<vector<pair<int, int> > > Edge(N);

	for (int i = 0; i < N - 1; ++i)
	{
		int u, v, w;
		cin >> u >> v >> w;
		--u;
		--v;
		w %= 2;
		Edge[u].emplace_back(v, w);
		Edge[v].emplace_back(u, w);
	}

	vector<int> used(N, -1);
	list<int> lst;
	used[0] = 0;
	lst.emplace_back(0);

	while(!lst.empty())
	{
		for (const auto & next : Edge[lst.front()])
		{
			if (used[next.first] != -1) { continue; }

			used[next.first] = (used[lst.front()] + next.second) % 2;
			lst.emplace_back(next.first);
		}

		lst.pop_front();
	}

	for (int i = 0; i < N; ++i)
	{
		cout << used[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 8448