akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion


int32_t main() {
    make(int, n);
    VI c(n);
    for(auto& val : c){
        cin >> val;
        val--;
    }
    VVI g(n);
    for(int i = 1; i < n; ++i){
        make(int, v, u);
        v--, u--;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    VI sz(n);
    function<void(int, int)> dfs = [&](int v, int p){
        sz[v] = 1;
        for(int u : g[v]){
            if (u != p){
                dfs(u, v);
                sz[v] += sz[u];
            }
        }
    };
    dfs(0, -1);
    VI ans(n);
    VVI calc(n, VI(1, n));
    function<void(int, int)> dfs2 = [&](int v, int p){
        if (p != -1){
            calc[c[p]].push_back(sz[v]);
        }
        for(int u : g[v]){
            if (u != p){
                dfs2(u, v);
            }
        }
        calc[c[v]].back()--;
        if (p != -1){
            ans[c[p]] += calc[c[p]].back() * (calc[c[p]].back() + 1) / 2;
            calc[c[p]].pop_back();
            calc[c[p]].back() -= sz[v];
        }
    };
    dfs2(0, -1);
    for(int i = 0; i < calc.size(); ++i){
        ans[i] += calc[i][0] * (calc[i][0] + 1) / 2;
    }
    for(auto& val : ans){
        cout << n * (n + 1) / 2 - val << '\n';
    }


    return 0;
}

Measured memory_bytes: 53872
#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>
#include <stack>
#include <functional>

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

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int MOD = 1000000007;

// + - * / ^
int mod(int a)
{
    int res = a % MOD;
    if(res < 0) {
        return res + MOD;
    }
    return res;
}
int mul_mod(int a, int b)
{
    ll res = ((ll)a * (ll)b) % MOD;
    return mod((int)res);
}
int pow_mod(int a, int b)
{
    ll res = 1;
    while (b > 0) {
        if(b & 1) {
            res = res * (ll)a % (ll)MOD;
        }
        a = mul_mod(a, a);
        b >>= 1;
    }
    return (int)res;
}
int inv_mod(int a)
{
    return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
    return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 3000001;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < FAC_MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll com_mod(int a, int b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}


int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    com_init();
    ll n, m; cin >> n >> m;
    ll ans = 0;
    if (n > m) {
        cout << 0 << "\n";
        return 0;
    }
    ll xx = div_mod(fac[m], fac[m - n]);
    // n--; m--;
    ll multiplier = div_mod(1, fac[m - n]);
    rep (i, n + 1) {
        ll k = (i % 2 ? -1 : 1);
        k = mul_mod(k, mul_mod(fac[m - i], com_mod(n, i)));
        ans = mod(ans + k);
        // eprintf("%d ", mul_mod(ans, multiplier));
    }
    ans = mul_mod(ans, multiplier);
    eprintf("%lld ", ans);
    ans = mul_mod(ans, xx);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 73960
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n;
  scanf("%d",&n);
  vector<int> vc(n);
  for(int i = 0 ; i < n ; i++ ) scanf("%d",&vc[i]);
  int ans = 0,q,a;
  scanf("%d",&q);
  sort(vc.begin(),vc.end());
  while(q--){
    cin >> a;
    if(binary_search(vc.begin(),vc.end(),a)) ans++;
  }
  printf("%d\n",ans);
}


Measured memory_bytes: 3428
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  double A,B,X;
  cin>>A>>B>>X;
  if(X>=A*A*B/2){
    double k = 2*(B-(X/(A*A)));
    cout << setprecision(10) << atan(k/A)*180/3.141592653589793238462643383279 << endl;
  }
  else{
    double k = 2*(X/(A*B));
    cout << setprecision(10) << 90-atan(k/B)*180/3.141592653589793238462643383279 << endl;
  }
  return 0;
}

Measured memory_bytes: 512
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	map<string, ll> po;
	po[""] = 0;
	ll N;
	cin >> N;
	rep(i, N) {
		string s; cin >> s;
		++po[s];
	}
	cin >> N;
	rep(i, N) {
		string s; cin >> s;
		--po[s];
	}
	cout << max_element(all(po), [](pair<string, ll>x, pair<string, ll>y) {return x.second < y.second; })->second << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  int n, a;
  cin >> n >> a;
  cout << n * n - a << endl;
  return 0;
}

Measured memory_bytes: 3600
n = int(input())
a = list(map(int, input().split()))
s = 0
ans = 0
for i in range(len(a)):
  s += a[i]
for i in range(len(a)-1):
  s -= a[i]
  ans += s*a[i]
  ans %= 1000000007
print(ans)

Measured memory_bytes: 31424
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define N 100005
int seg[4*N];
int mul(int a, int b)
{
    return a*b%mod;
}
int mypower(int a, int b)
{
    int ans = 1;
    while(b)
    {
        if(b%2)
            ans = mul(ans, a);
        b=b/2;
        a=mul(a,a);
    }
    return ans;
}
void update(int st, int l, int r, int idx, int arr[], int val)
{
    if(l == r)
    {
        seg[st] = arr[l] = val;
        return;
    }
    int mid = (l+r)/2;
    if(idx <= mid)
        update(2*st+1, l, mid, idx, arr, val);
    else
        update(2*st+2,mid+1, r, idx, arr,val);
    seg[st] = min(seg[2*st+1],seg[2*st+2]);    
}
int query(int st, int l, int r, int ql, int qr)
{
    if(l > qr || r < ql)
    {
        return 0;
    }
    if(l >= ql && r <= qr)
        return seg[st];
    int mid = (l+r)/2;
    return min(query(2*st+1, l, mid, ql, qr), query(2*st+2, mid+1, r, ql, qr));
}

signed main() {
    int n, k;
    cin >> n >> k;
    int arr[n], i;
    for(i=0;i<n;i++)
        cin >> arr[i];
    sort(arr, arr+n);
    int sum = 0;
    for(i=0;i<k;i++)
        sum+=arr[i];
    cout << sum;    
    
}

Measured memory_bytes: 3632
H, W = map(int, input().split())
list = [[c for c in input()] for i in range(H)]

dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, -1, -1, -1, 0, 1 ,1 ,1]

for i in range(H):
    for j in range(W):
        if list[i][j] == "#":
            continue
        num = 0
        for k in range(8):
            x = i + dx[k]
            y = j + dy[k]
            if x < 0 or x >= H:
                continue
            if y < 0 or y >= W:
                continue
            if list[x][y] == "#":
                num += 1
        list[i][j] = num
        
for l in list:
    print(''.join([str(c) for c in l]))
                



Measured memory_bytes: 3064
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())

ANS=[0]*10

ANS[0]=b-a
ANS[1]=c-a
ANS[2]=d-a
ANS[3]=e-a
ANS[4]=c-b
ANS[5]=d-b
ANS[6]=e-b
ANS[7]=d-c
ANS[8]=e-c
ANS[9]=e-d

flag=0

for i in range(0,10):
    if ANS[i]>k:
        flag+=1
        
if flag==0:
    print('Yay!')
else :
    print(':(')

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using     ll=long long;
using    vll=vector<   ll>;
using   vvll=vector<  vll>;
using  vvvll=vector< vvll>;
using vvvvll=vector<vvvll>;
constexpr ll INF = 1LL << 60;
struct Fast{ //cin,cout高速化のおまじない＋桁数指定
	Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(std::numeric_limits<double>::max_digits10); }
} fast;
#define REPS(i, S, E) for (ll i = (S); i <= (E); i++)
#define REP(i, N) REPS(i, 0, (N)-1)
#define DEPS(i, S, E) for (ll i = (E); i >= (S); i--)
#define DEP(i, N) DEPS(i, 0, (N)-1)
#define EACH(e, v) for (auto&& e : v)
#define rep(i, S, E)  for (ll i = (S); i <= (E); i++)
#define dep(i, E, S)  for (ll i = (E); i >= (S); i--)
#define each(e, v) for (auto&& e : v)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
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; }
template<class T> inline T MaxE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; }
template<class T> inline T MinE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; }
template<class T> inline T MaxE(vector<T> &v) { return MaxE(v,0,(ll)v.size()-1); }
template<class T> inline T MinE(vector<T> &v) { return MinE(v,0,(ll)v.size()-1); }
template<class T> inline T Sum(vector<T> &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; }
template<class T> inline T Sum(vector<T> &v) { return Sum(v,0,v.size()-1); }
template<class T> inline ll sz(T &v){ return (ll)v.size(); }
template<class T> inline T POW(T a, ll n){ T r=1; for (; n>0; n>>=1, a*=a){ if (n&1)r*=a; } return r; }
inline ll POW(int a, ll n){ return POW((ll)a, n); }
inline ll CEIL(ll a, ll b){ return (a+b-1)/b; }



void solve()
{
	ll h,w;  cin >> h >> w;
	if (h==1 or w==1){
		cout << 1 << '\n'; return;
	}

	cout << CEIL(h*w,2) << '\n';
}


int main(){
#if 1
	solve();
#else
	ll t;  cin >> t;
	rep(i, 0, t-1){
		solve();
	}
#endif
	return 0;
}


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

using namespace std;

const int maxn = 1e5 + 10;
int h[maxn];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++) scanf("%d", &h[i]);
    h[1] --;
    bool flag = true;
    for(int i = 2; i <= n; i ++)
    {
        if(h[i] - 1 >= h[i - 1]) h[i] --;
        if(h[i] < h[i - 1]) flag = false;
    }
    printf("%s\n", flag ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 640
n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))

for i in range(1,n+1):
    A[i] += A[i-1]

for i in range(1,m+1):
    B[i] += B[i-1]

ans=0
for a_cnt in range(n+1):
    if A[a_cnt]>k:
        continue
    start=0
    goal=m+1
    while start!=goal:
        b_cnt=(start+goal)//2
        if A[a_cnt]+B[b_cnt]>k:
            goal=b_cnt
        else:
            start=b_cnt+1
            ans=max(ans,a_cnt+b_cnt)
print(ans)


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ac(n), pena(n);
  rep(i,m){
    int p;
    string s;
    cin >> p >> s;
    --p;
    if(ac[p])continue;
    if(s =="AC"){
      ac[p] = 1;
    } else {
      pena[p]++;
    }
  }
  int AC = 0, PENA = 0;
  rep(i,n){
    AC += ac[i];
    if(ac[i]) PENA += pena[i];
  }
  cout << AC << " " << PENA << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
	int h,w;
    int x=0;
  	cin >> h >> w;
	string kari[h];
  	int a[h+2][w+2];
  	fr(i,h+2){
      fr(j,w+2){
        a[i][j]=10000;
      }
    }
    bool flag = true;
    fr(i,h){
		cin >> kari[i];
    }
  	fr(i,h){
      fr(j,w){
        if(kari[i].substr(j, 1) == "#")a[i+1][j+1] = 0;
        if(kari[i].substr(j, 1) == ".")a[i+1][j+1] = 10000;
      }
    }
  	for(x=0;x<w+h;x++){
      flag = true;
      fr(i,h){
        fr(j,w){
          if(a[i+1][j+1]>a[i][j+1]+1){
            a[i+1][j+1]=a[i][j+1]+1;
            flag = false;
          }
          if(a[i+1][j+1]>a[i+2][j+1]+1){
            a[i+1][j+1]=a[i+2][j+1]+1;
            flag = false;
          }
          if(a[i+1][j+1]>a[i+1][j]+1){
            a[i+1][j+1]=a[i+1][j]+1;
            flag = false;
          }
          if(a[i+1][j+1]>a[i+1][j+2]+1){
            a[i+1][j+1]=a[i+1][j+2]+1;
            flag = false;
          }
        }
      }
      if(flag == true)break;
      ifr(i,h){
        ifr(j,w){
          if(a[i+1][j+1]>a[i][j+1]+1){
            a[i+1][j+1]=a[i][j+1]+1;
            flag = false;
          }
          if(a[i+1][j+1]>a[i+2][j+1]+1){
            a[i+1][j+1]=a[i+2][j+1]+1;
            flag = false;
          }
          if(a[i+1][j+1]>a[i+1][j]+1){
            a[i+1][j+1]=a[i+1][j]+1;
            flag = false;
          }
          if(a[i+1][j+1]>a[i+1][j+2]+1){
            a[i+1][j+1]=a[i+1][j+2]+1;
            flag = false;
          }
        }
      }
      if(flag == true)break;
    }
   int max = 0;
    fr(i,h){
      fr(j,w){
        if(a[i+1][j+1]>max)max=a[i+1][j+1];
      }
    }
    cout << max << endl;
}

Measured memory_bytes: 5248
#include <stdio.h>

int main(void)
{
	int H, W, x, y, i;
	
	for(i = 0; i < 300; i++){
		scanf("%d%d", &H, &W);
		if((H == 0) && (W == 0)) break;
		for(y = 1; y <= H; y++){
			for(x = 1; x <= W; x++){
				if((((y % 2) == 1) && ((x % 2) == 1)) || (((y % 2) == 0) && ((x % 2) == 0))){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return(0);
}



Measured memory_bytes: 1792
#include<stdio.h>
#define SIZE 100000
int main()
{
  int s[SIZE],t;
  int i,j,k,n,q,ans=0;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&s[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&t);
      j=0;
      k=n-1;
      while(j<k)
	{
	  if(t==s[(j+k)/2])
	    {
	      ans++;
	      break;
	    }
	  else if(t>s[(j+k)/2]) j=(j+k)/2;
	  else if(t<s[(j+k)/2]) k=(j+k)/2;
	  if(k-j<=1)
	    {
	      if((t==s[j])||(t==s[k])) ans++;
	      break;
	    }
	}
    }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 980
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Sun Mar 25 21:02:59 2018
//
package main

import (
	"fmt"
)

var N int
var D, X int

func main() {
	fmt.Scan(&N)
	fmt.Scan(&D, &X)

	days := make([]int, N)
	for i := range days {
		fmt.Scan(&days[i])
	}

	count := 0
	for i := range days {
		count += (D-1)/days[i] + 1
	}

	fmt.Println(count + X)
}


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

int main() {
  int N; cin >> N;
  cout << 0 << endl;
  string zero; cin >> zero;
  if (zero == "Vacant") return 0;
  string s;
  int left = 0, right = N;
  while (left < right) {
    int mid = (left + right) / 2;
    cout << mid << endl;
    cin >> s;
    if (s == "Vacant") return 0;
    if (mid % 2 == 0) {
      if (s == zero) left = mid;
      else right = mid;
    }
    else {
      if (s == zero) right = mid;
      else left = mid;
    }
  }
  return 0;
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  vector<string> w={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  for(int d=0;d<7;d++)
    if(s==w.at(d))
      cout<<7-d<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    int mi = INF;
    int res = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (mi >= a[i]) {
            res++;
        }
        chmin(mi, a[i]);
    }
    cout << res << endl;
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

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*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n,m;cin >> n >> m;
    vector<pair<int,int>> ab;
    rep(i,m){
        int a,b;cin >> a >> b;
        ab.push_back(make_pair(a,b));
    }
    sort(ALL(ab),[](pair<int,int> a,pair<int,int> b){
        return a.second < b.second;
    });
    int delim = 0;
    int ans = 0;
    for(int i=0;i<m;i++){
        if(ab[i].first>delim){
            delim = ab[i].second-1;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#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;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;

}

signed main() {
	vector<ll> v(3, 0);

	cin >> v[0] >> v[1] >> v[2];

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

	cout << v[0] + v[1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int i,j,k,n,m,x,y,t,a[100010];
int main(){
	scanf("%d",&n);for (i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n,greater<int>());
	while (a[t]>=t)t++;t--;
	if ((a[t]-t)%2==0){
		j=0;
		for (;a[t+j]>=t;j++);
		if (j%2==1)printf("Second\n");
		else printf("First\n");
	}
	else printf("First\n");
	return 0;
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
typedef vector<int> vi;typedef vector<vi> vvi;typedef pair<int,int> pii;typedef vector<pii> vpii;
typedef long long ll;

void Main() {
  int N;
  scanf("%d", &N);
  vi A(N);
  rep(i, N) scanf("%d", &A[i]);

  int sum = accumulate(ALL(A), 0);

  int mid = sum / N;

  int ans = 1e9;
  rep(i, 3) {
    int t = mid + i - 1;
    int cand = 0;
    forr(a, A) {
      cand += abs(a - t) * abs(a - t);
    }
    ans = min(ans, cand);
  }
  _p("%d\n", ans);
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int n;
	cin >> n;
	println((n-2)*180);
	return 0;
}


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

int main()
{
    int n,c1=0,c2=0,c3=0,c4=0,total;
    char a[100];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        if(a[i] == 'P'){
            c1 = 1;
        }else if(a[i] == 'W'){
            c2 = 1;
        }else if(a[i] == 'G'){
            c3 = 1;
        }else if(a[i] == 'Y'){
            c4 = 1;
        }
        total = c1+c2+c3+c4;
        if(total == 4){
            cout << "Four" << endl;
            return  0;
        }
    }
    cout << "Three" << endl;
    return 0;
}


Measured memory_bytes: 256
from heapq import heappop, heappush
import sys

N = int(input())
hq = []
for i in range(N):
    heappush(hq, tuple(reversed(list(map(int, input().split())))))
cnt = 0
for i in range(N):
    b, a = heappop(hq)
    cnt += a
    if cnt > b:
        print("No")
        sys.exit()
print("Yes")


Measured memory_bytes: 82392
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
    static int n;
    static int m;
    static long[][] xyz;
    static long max = 0;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		n = sc.nextInt();
		m = sc.nextInt();
		xyz = new long[n][3];
		for(int i = 0; i < n; i++){
		    xyz[i][0] = sc.nextLong();
		    xyz[i][1] = sc.nextLong();
		    xyz[i][2] = sc.nextLong();
		}
		
		// 計算
		long result = 0;
		for(int i = 0; i < 8; i++){
		    int[] sgn = new int[3];
		    for(int j = 0; j < 3; j++){
		        if((i>>j & 1) == 1){
		            sgn[j] = -1;
		        }else{
		            sgn[j] = 1;
		        }
		    }
		    Arrays.sort(xyz, (s, t) -> {
		        return Long.signum(s[0]*sgn[0] + s[1]*sgn[1] + s[2]*sgn[2] - t[0]*sgn[0] - t[1]*sgn[1] - t[2]*sgn[2]);
		    });
		    long[] sum = new long[3];
		    for(int k = 0; k < m; k++){
		        sum[0] += xyz[n-1-k][0];
		        sum[1] += xyz[n-1-k][1];
		        sum[2] += xyz[n-1-k][2];
		    }
		    max = max(max, abs(sum[0]) + abs(sum[1]) + abs(sum[2]));
		}
		result = max;
		
		// 出力
		System.out.println(result);
	}
}


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

int main(){
    char s1, s2, s3;
    scanf("%c%c%c",&s1, &s2, &s3);
    int count = 0;
    if(s1 == '1') count += 1;
    if(s2 == '1') count += 1;
    if(s3 == '1') count += 1;

    cout << count << endl;
    return 0;

}


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

int main(){
 int s;
  cin>>s;
  
 int count=1;
  while(s>4 || s==3){
   if(s%2==0){s/=2;}
   else{s=3*s+1;}
    count++;
  }
cout<<count+3<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,k; cin >> n >> k;
    OUT((n+k-3)/(k-1));

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	string s;cin>>s;
	for(int i= 2; i<s.size(); i += 2){
		string t = s.substr(0, s.size()-i);
		bool ok = true;
		rep(j,t.size()/2-1){
			if(t[j] == t[j + t.size()/2])continue;
			ok = false;
			break;
		}
		if(ok){
			cout<<s.size()-i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int a,b,ans;
scanf("%d%d",&a,&b);
	if(b>0){
	ans = a+b > a*b ? a+b : a*b;
	}else{
	ans = a-b > a*b ? a-b : a*b;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){

string x;
cin>>x;
for(int i=0;i<5;i++){
	cout<<x[i];
}
cout<<" ";
for(int i=6;i<13;i++){
	cout<<x[i];
}
cout<<" ";
for(int i=14;i<19;i++){
	cout<<x[i];
}
return 0;
}

Measured memory_bytes: 256
while True:
    try:
        w = int(raw_input())
        n = int(raw_input())
        ans = [j for j in range(1,w+1)]
        for k in range(n):
            a,b = map(int,(raw_input().split(",")))
            ans[a-1],ans[b-1] = ans[b-1],ans[a-1]
        for item in ans:
            print item
    except EOFError:
        break

Measured memory_bytes: 4220
# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;
const int N = 3010, P = 1e9 + 7;
int n;
char st[N];
int f[N][N], pre[N][N], bak[N][N];
int main(){
	read(n);
	scanf("\n%s", st + 2);
	f[1][1] = pre[1][1] = bak[1][1] = 1;
	for (int i = 2; i <= n; i++){
		if (st[i] == '<')
			for (int j = 1; j <= i; j++) f[i][j] = pre[i - 1][j - 1];
			else for (int j = 1; j <= i; j++) f[i][j] = bak[i - 1][j];
		for (int j = 1; j <= i; j++)
			pre[i][j] = (pre[i][j - 1] + f[i][j]) % P;
		for (int j = i; j >= 1; j--)
			bak[i][j] = (bak[i][j + 1] + f[i][j]) % P;
	} 
	printf("%d\n", pre[n][n]);
	return 0;
}



Measured memory_bytes: 105088
import sys

for e in sys.stdin:
    cnt = 0
    max, sum = map(int,e.split())

    if max == 0 and sum == 0:
        break    
    for i in range(1,max+1):
        for j in range(1,max+1):
            for k in range(1,max+1):
                if i+j+k == sum and i < j and j < k:
                    cnt += 1
    print(str(cnt))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N;
	cin >> N;
	string S;
	cin >> S;
	int cnt = 0;
	rep(i,0,N-2){
		if (S.substr(i, 3) == "ABC"){
			cnt++;
		}
	}
	cout << cnt << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n,k;cin >> n >> k;
	vector<int> x(n);
	rep(i,n)cin >> x[i];
	
	int ans = INT_MAX;
	rep(i,n-k+1)
	{
		if((1LL)*x[i]*x[i+k-1]>0)
		{
			//cout<<' '<<0<<endl;
			//cout<<max(abs(x[i]),abs(x[i+k-1] ) )<<endl;
			ans = min (ans, max(abs(x[i]),abs(x[i+k-1] ) ) );
			continue;
		}
		//cout<<' '<<1<<endl;
		//cout<<abs(x[i]-x[i+k-1])+min( abs(x[i]),abs(x[i+k-1]  ) )<<endl;
		ans = min( ans,abs(x[i]-x[i+k-1])+min( abs(x[i]),abs(x[i+k-1] )  ) );

	}
	cout<<ans<<endl;
	

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;
using Pos = std::pair<int, int>;
//cout<<fixed<<std:cout<<fixed<<setprecision(2)<<Max<<endl;
constexpr int mod = 1e9 + 7;

int N;
string str;
vector<bool> a;//sheep->0, wolf->1

bool check(){
    //fill
    if(str[0]=='x'){
        a[1]=a[0]?a[N-1]:!a[N-1];
    }else{
        a[1]=a[0]?!a[N-1]:a[N-1];
    }
    for(int i=2;i<N-1;++i){
        if(str[i-1]=='x'){
            a[i]=a[i-1]?a[i-2]:!a[i-2];
        }else{
            a[i]=a[i-1]?!a[i-2]:a[i-2];
        }
    }

    //check
    if(a[N-2]){
        if(str[N-2]=='x'){
            if(a[N-1]!=a[N-3])return false;
        }else{
            if(a[N-1]==a[N-3])return false;
        }
    }else{
        if(str[N-2]=='x'){
            if(a[N-1]==a[N-3])return false;
        }else{
            if(a[N-1]!=a[N-3])return false;
        }
    }

    if(a[N-1]){
        if(str[N-1]=='x'){
            if(a[0]!=a[N-2])return false;
        }else{
            if(a[0]==a[N-2])return false;
        }
    }else{
        if(str[N-1]=='x'){
            if(a[0]==a[N-2])return false;
        }else{
            if(a[0]!=a[N-2])return false;
        }
    }
    return true;
}

int main() {
    cin>>N>>str;
    a.resize(N);

    a[0]=0;
    a[N-1]=0;
    if(check()){
        for(const auto& val:a){
            if(val)cout<<'W';
            else cout<<'S';
        }
        cout<<endl;
        return 0;
    }
    a[0]=0;
    a[N-1]=1;
    if(check()){
        for(const auto& val:a){
            if(val)cout<<'W';
            else cout<<'S';
        }
        cout<<endl;
        return 0;
    }
    a[0]=1;
    a[N-1]=0;
    if(check()){
        for(const auto& val:a){
            if(val)cout<<'W';
            else cout<<'S';
        }
        cout<<endl;
        return 0;
    }
    a[0]=1;
    a[N-1]=1;
    if(check()){
        for(const auto& val:a){
            if(val)cout<<'W';
            else cout<<'S';
        }
        cout<<endl;
        return 0;
    }
    cout<<-1<<endl;

    return 0;
}

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

int res=0;
int n,a[300];
int main()
{
	cin>>n;
	for(int i=1;i<=2*n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+2*n+1);
	for(int i=1;i<=2*n;i+=2)
		res+=a[i];
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

quickSortVec l u arr
  | l >= u    = return ()
  | otherwise = do
      VM.unsafeSwap arr l ((u+l)`div`2)
      t <- VM.unsafeRead arr l
      let i = l
          j = u + 1
      nj <- loopVec t u i j arr
      VM.unsafeSwap arr l nj
      quickSortVec l (nj-1) arr
      quickSortVec (nj+1) u arr

loopVec !t !u !i !j arr = do
  ni <- doWhile i (+1)         (< t)
  nj <- doWhile j (subtract 1) (> t)
  if ni > nj
    then return nj
    else do VM.unsafeSwap arr ni nj
            loopVec t u ni nj arr
              where
                {-# INLINE doWhile #-}
                doWhile k op p
                  | nk > u    = return nk
                  | otherwise = do
                      x <- VM.unsafeRead arr nk
                      if p x then
                        doWhile nk op p
                        else
                        return nk
                        where
                          nk = op k

main = do
  n <- getInt
  t <- getIntList

  let t' = V.fromList (0:t)
  ds' <- V.thaw t'
  quickSortVec 0 n ds'

  ds <- V.freeze ds'

  let fmin i res | i > n = res
                 | otherwise = let d = ds V.! i - ds V.! (i-2)
                                   in fmin (i+2) (min res d)

      min0 = fmin 2 inf
      min1 = fmin 3 (ds V.! 1)
      min' = let d = ds V.! n + ds V.! (n-1)
             in min d (24 - d)

      ans = min min0 (min min1 min')

  print ans

Measured memory_bytes: 508
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k % 2)
		cout << b - a << endl;
	else
		cout << a - b << endl;
	return 0;
}


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

using namespace std;

int n,k;
vector<int> books[11];

int dp[11][2001];

int dfs(int pos,int sold){
    if(pos==10)return 0;
    if(dp[pos][sold]!=-1)return dp[pos][sold];
    int res=0;
    int sum=0;
    // ツ個サツ催敖づ個ジツδδδ督δ仰づ個本ツづーツ債つつ「ツ渉氾板づ可板づゥ
    for(int i=0;i<books[pos].size();i++){
        sum+=books[pos][i];
        if(sold-i-1>=0)res=max(res,dfs(pos+1,sold-(i+1))+sum+(i)*(i+1));
    }
    res=max(res,dfs(pos+1,sold));
    return dp[pos][sold]=res;
}

int main(){
    memset(dp,-1,sizeof(dp));
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        b--;
        books[b].push_back(a);
    }
    for(int i=0;i<10;i++)sort(books[i].begin(),books[i].end(),greater<int>());
    int res=dfs(0,k);
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define pi acos(-1)
#define P complex<double>

using namespace std;

int main()
{
    int a, b, x, mx;
    cin >> a >> b >> x;
    mx = a*a*b;
    if(x*2 <= mx) cout << fixed << setprecision(8) << 90.0 - abs(atan((1.0 * x / (0.5 * a * b)) / (1.0 * b))) / pi * 180;
    else
    {
        x = mx - x;
        cout << fixed << setprecision(8) << 90.0 - abs(atan((1.0 * a) / (1.0 * x / (0.5 * a * a)))) / pi * 180;
    }
}


Measured memory_bytes: 512
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	std::string s;
	std::cin >> s;
	int x = 0;
	if(s=="SUN") x=0;
	else if(s=="MON") x=1;
	else if(s=="TUE") x=2;
	else if(s=="WED") x=3;
	else if(s=="THU") x=4;
	else if(s=="FRI") x=5;
	else if(s=="SAT") x=6;
	print(7-x);
	return 0;
}


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

def main():
    n = int(input())
    h_list = list(map(int, input().split()))
    h_len = len(h_list)

    c = 0
    c_max = 0
    flag = 0
    for i, h in enumerate(h_list):
        if i < h_len - 1:
            if flag == 0 and h >= h_list[i + 1]:
                c = 1
                flag = 1
            elif h >= h_list[i + 1]:
                c += 1
                if c > c_max:
                    c_max = c
            elif flag == 1:
                flag = 0

    print(c_max)





if __name__ == '__main__':
    main()


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

int main() {
  int n, y;
  int a=-1, b=-1, c=-1;
  bool canPay=false;
  cin >> n >> y;
  for(int i=0; i<=n; i++) {
    for(int j=0; j<=n-i; j++) {
      if(i*10000+j*5000+(n-(i+j))*1000==y) {
        a=i;
        b=j;
        c=n-(i+j);
        canPay=true;
      }
    }
    if(canPay) break;
  }
  cout << a << " " << b << " " << c << endl;
}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  set<int> st;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin >> A;
    st.insert(A);
  }
  int k = st.size();
  if (k % 2 != 0)
    cout << k << endl;
  else
    cout << k - 1 << endl;
  return 0;
}

// 基本的には1枚しかないカードを取り除かれないカードに余っているカードを取り除かれるカードに選ぶことが出来るので操作は「2枚のカードを選んで取り除く」として構わない．
// カードの山にk種類のカードがあったとしてkが奇数なら余っているカードは偶数枚あるので答えはkとなり，偶数ならばどこかで必ず1枚しかないカードを取り除く必要があるので答えはk-1となる．


Measured memory_bytes: 4992
function main(input) {
  var length = input.length;
  var count01 = 0;
  var count10 = 0;
  // console.log(input.length);
  for(var i=0; i<length; i++){
    var target = input.charAt(i);
    // 奇数番目
    if(i%2 === 0){
      // 0101010101...
      if(target === "1"){
        // 0101との比較で奇数番目が1だったら変更
        count01++;
      }
      // 1010101010...
      if(target === "0"){
        count10++;
      }
    }
    // 偶数番目
    if(i%2 === 1){
      // 0101010101...
      if(target === "0"){
        // 0101との比較で奇数番目が0だったら変更
        count01++;
      }
      // 1010101010...
      if(target === "1"){
        count10++;
      }
    }
  }
  console.log(Math.min(count01, count10));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

string s;

int main(void)
{
	int i, paper = 0, rock = 0, ans = 0;

	cin >> s;

	for (i = 0; i < s.size(); i++)
	{
		char me;

		if (paper == rock)
			me = 'g', ++rock;
		else
			me = 'p', ++paper;

		if (me == 'p' && s[i] == 'g')
			++ans;
		else if (me == 'g' && s[i] == 'p')
			--ans;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 512
/**
 * @author Video Vocabulary
 * @date 2020-07-11 18:00:43
 */
#include <bits/stdc++.h>

using namespace std;

void solve() {

}

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

    int n, sum;
    cin >> n;
    map<int, int> mm;
    for (int x=1; x<=100; x++) {
        for (int y=1; y<=100; y++) {
            for (int z=1; z<=100; z++) {
                sum = x*x + y*y + z*z + x*y + y*z + z*x;
                if (sum<=n) {
                    mm[sum]++;
                }
            }
        }
    }
    for (int i=1; i<=n; i++) {
        cout << (mm.count(i)?mm[i]:0) << "\n";
    }
}


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

int N;
ll arr[100005][3];
ll dp[100005][3];

void read() {
	cin >> N;

	for (int i = 1; i <= N; ++i)
		for (int j = 0; j < 3; ++j)
			cin >> arr[i][j];
}

template <class A, class B>
void maxi(A &a, B b) {
	a = max(a, b);
}

int f(int i, int day) {
	if (i > N) return 0;
	if (dp[i][day] != -1) return dp[i][day];

	ll ans = INT_MIN;
	if (day == 0) {
		maxi(ans, arr[i][0]);
		maxi(ans, arr[i][2]);
	} else if (day == 1) {
		maxi(ans, arr[i][2]);
	} else if (day == 2) {
	}

	return dp[i][day] = ans;
}

void solve2() {
	memset(dp, -1, sizeof(dp));
	cout << f(1, 0) << endl;
}

void solve() {
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;

	for (int i = 1; i <= N; ++i) {
		dp[i][0] = INT_MIN;
		dp[i][1] = INT_MIN;
		dp[i][2] = INT_MIN;
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 3; ++k) {
				if (k != j) maxi(dp[i][j], arr[i][j] + dp[i-1][k]);
			}
		}
	}

	cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	read();
	solve();
	return 0;
}



Measured memory_bytes: 4992
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, M, X = list(map(int,_in[0].split(' ')))  # type:list(int)
    C_A_arr = []
    for i in range(N):
        _ = list(map(int,_in[i+1].split(' ')))  # type:list(int)
        C_A_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    condition = [0]*M
    cnt = float('inf')
    for bit in range(1<<N):
        condition = [0]*M
        _cnt = 0
        for i in range(N):
            if bit&(1<<i):
                for j in range(M):
                    condition[j] += C_A_arr[i][j+1]
                _cnt += C_A_arr[i][0]
        if min(condition) >= X:
            cnt = min(cnt,_cnt)
    if cnt == float('inf'):
        cnt = -1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 87176
import collections

n = int(input())

s = [input() for _ in range(n)]

c = collections.Counter(s).most_common()
mx = c[0][1]

out = list()
for e in c:
        if e[1] == mx:
                out += [e[0]]
        else:
                break
out.sort()
print(*out, sep='\n')

Measured memory_bytes: 45120