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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
const double PI=3.1415926535897932;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

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


const ll SIZE = (1e5+10)*2;
string s;
string mem,ans;
ll cou[30];
char to;

int main(){
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        ++cou[s[i]-'a'];
    }

    ll ma = 0, pos = 0;
    for(int i = 0; i < 29; i++){
        if(ma < cou[i]){
            ma = cou[i];
            pos = i;
        }
    }

    if(ma == s.length()){
        cout << "0\n";
        return 0;
    }
    to = 'a'+pos;
    mem = s;
    ans = "";
    ll fl = 0, coun = 0;
    ll memcoun = LL_INF;

    for(int j = 0; j <= 'z'-'a'; j++){
        if(cou[j] == 0) continue;
    to = 'a'+j;
    mem = s;
    ans = "";
    fl = 0;
    coun = 0;
    while(fl == 0){
        ++coun;
        for(int i = 0; i < mem.length()-1; i++){
            if(mem[i] == 'a'+j || mem[i+1] == 'a'+j){
                ans += 'a'+j;
            }
            else{
                ans += mem[i];
            }
        }

        fl = 1;
        for(int i = 0; i < ans.length(); i++){
            if(ans[i] != 'a'+j){
                fl = 0;
                break;
            }
        }
        mem = ans;
        ans = "";
    }
    memcoun = min(memcoun,coun);
    }
    cout << memcoun << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
#include <stdio.h>
using namespace std;

typedef long long int ll;
ll S[100001];
ll T[50001];
int n,q;

int bin_search(ll *X,ll a,int s,int e){

  if(e-s==1){
    if(X[s]==a) return 1;
    else return 0;
  }

  int mid = (s+e)/2;
  if(a<X[mid]) bin_search(X, a, s, mid);
  else bin_search(X, a, mid, e);
		 
  


}


int main(){

  /*  cin>>n;
  for(int i=0;i<n;i++) cin>>S[i];
  cin>>q;
  for(int i=0;i<q;i++) cin>>T[i];

  int cnt = 0;
  for(int i=0;i<q;i++){
    cnt += bin_search(S,T[i],0,n);
  }
  cout<<cnt<<endl;
  */

  ios_base::sync_with_stdio(false);
  map<string,int> mp;
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    string op,str;
    cin>>op>>str;
    if(op=="insert"){
      mp[str]=1;
    }
    if(op=="find"){
      if(mp[str]) cout<<"yes\n";
      else cout<<"no\n";
    }
  }
  return 0;
}

Measured memory_bytes: 47468
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(x);
  Vb expo(x+1);
  expo[1] = true;
  FOR(i,2,x+1){
    int v = i * i;
    while(v <= x){
      expo[v] = true;
      v *= i;
    }
  }
  for(int i = x; i >= 1; i--){
    if(expo[i]) {OUT(i);return 0;}
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int q,t,f,n,i,b=0;
  char c;
  string s,sf="",st="";
  cin >> s;
  cin >> q;
  for(i=0;i<q;i++){
    cin >> t;
    if(t==1){
      b=(b+1)%2;
    }else{
      cin >> f >> c;
      if(f+b==2)
        st.push_back(c);
      else
        sf.push_back(c);
    }
  }
  if(b==0){
    for(i=sf.size()-1;i>=0;i--)
      cout << sf[i];
    cout << s << st << endl;
  }else{
    for(i=st.size()-1;i>=0;i--)
      cout << st[i];
    for(i=s.size()-1;i>=0;i--)
      cout << s[i];
    cout << sf << endl;
  }
  return 0;
}

Measured memory_bytes: 1088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

long double a, b, x;

void input() {
    cin >> a >> b >> x;
}

long double f(long double a, long double b, long double theta) {
    if(theta > PI / 2.0 - EPS) {
        return 0.0;
    }
    long double ret;
    if(a * tan(theta) <= b) {
        ret = a * a * b - a * a * a * tan(theta) / 2.0;
    } else {
        ret = b * b / tan(theta) * a / 2.0;
    }
    return ret;
}

void solve() {
    input();
    long double ok = PI / 2.0;
    long double ng = 0.0;
    for(int _ = 1; _ <= 100000; _++) {
        long double mid = (ok + ng) / 2.0;
        if(f(a, b, mid) < x) ok = mid;
        else ng = mid;
    }
    cout << fixed << setprecision(10) << ok / PI * 180 << endl;
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
g = [[] for _ in range(n)]
e = []
for _ in range(n - 1):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    e.append(b - 1)

stack = deque([0])
stack.append(0)
ans = [0 for _ in range(n)]
while stack:
    v = stack.popleft()
    c = 1
    for nv in g[v]:
        if ans[v] == c:
            c += 1
        ans[nv] = c
        c += 1
        stack.append(nv)

print(max(ans))
for i in e:
    print(ans[i])


Measured memory_bytes: 26392
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	vector<pii> x;
	rep(i,N) {
		int pos; cin >> pos;
		x.emplace_back(--pos,i);
	}

	int M = N*N;
	set<int> dic;
	rep(i,M) dic.emplace(i);
	vector<int> ans(M,-1);
	rep(i,N) {
		ans[x[i].first] = i;
		dic.erase(x[i].first);
	}
	sort(all(x));
	rep(i,N) {
		int pos,num;
		tie(pos,num) = x[i];
		rep(j,num) {
			if (*dic.begin() > pos) {
				cout << "No" << ln;
				return 0;
			}
			ans[*dic.begin()] = num;
			dic.erase(*dic.begin());
		}
	}
	reverse(all(x));
	rep(i,N) {
		int pos,num;
		tie(pos,num) = x[i];
		rep(j,N-1-num) {
			if (*dic.rbegin() < pos) {
				cout << "No" << ln;
				return 0;
			}
			ans[*dic.rbegin()] = num;
			dic.erase(*dic.rbegin());
		}
	}

	cout << "Yes" << ln;
	for (auto i : ans) cout << i+1 << " ";
	cout << ln;
}


Measured memory_bytes: 13952
#include <iostream>
#include <string>
using namespace std;
int main(){
   string s;
   cin>>s;
   if(s[0]!=s[1]&&s[2]!=s[3]){
       cout<<"No"<<endl;
   }else if(s[1]!=s[2]){
       cout<<"No"<<endl;
       }else{
       cout<<"Yes"<<endl;
   }
        return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處
namespace Number {
    typedef long long int LL;
    // 求取 a, b 的最大公因數
    LL gcd(LL a, LL b) {
        if (a % b == 0) {
            return b;
        }
        return gcd(b, a % b);
    }
    // 求取 a, b 的最大公因數 gcd
    // 以及 x, y 使得 a*x + b*y = gcd
    LL gcd_extend(LL a, LL b, LL *x, LL *y) { 
        if (a == 0) { 
            *x = 0, *y = 1; 
            return b; 
        } 
    
        LL x1, y1; // To store results of recursive call 
        LL gcd = gcd_extend(b%a, a, &x1, &y1); 
    
        *x = y1 - (b/a) * x1; 
        *y = x1; 
    
        return gcd; 
    }
    // 求 a_inv 使得 (a * a_inv) % m = gcd(a, m)
    // 若 a, m 互質，即求 a 在 mod m 群的反元素 a_inv 
    LL mod_inv(LL a, LL m) { 
        LL x, y; 
        LL g = gcd_extend(a, m, &x, &y); 
        // 處理 x 爲負的情形 
        LL a_inv = (x%m + m) % m; 
        return a_inv;
    }
    // 求 x^n % m
    LL mod_pow(LL x, LL n, LL m) {
        if (n == 0) {
            return 1;
        } else if (n & 1) {
            LL half = mod_pow(x, n/2, m);
            return (half * half % m) * x % m;
        } else {
            LL half = mod_pow(x, n/2, m);
            return half * half % m;
        }
    }
    // 連乘
    LL mul(LL from, LL to, LL m) {
        LL ret = 1;
        for (LL i = from; i <= to; i++) {
            ret *= i;
            ret %= m;
        }
        return ret;
    }
    // 求 (C n 取 k) % m
    LL mod_comb(LL n, LL k, LL m) {
        LL mi = k < n-k ? k : n-k;
        LL up = mul(n - mi + 1, n, m);
        LL down = mul(1, mi, m);
        return (up * mod_inv(down, m)) % m;
    }
}
  

LL pos[200005];

LL MOD = 1e9 + 7;

LL fact[200005];

LL comb(LL n, LL k) {
    if (n < k) {
        return 0;
    }
    LL ret = fact[n] * Number::mod_inv(fact[k], MOD);
    ret %= MOD;
    ret *= Number::mod_inv(fact[n - k], MOD);
    ret %= MOD;
    return ret;
}

int main() {
    LL n;
    cin >> n;
    fact[0] = 1;
    for (LL i = 1; i <= n + 1; i++) {
        fact[i] = fact[i - 1] * i % MOD;
    }
    LL l, r;
    for (LL i = 1; i <= n + 1; i++) {
        LL a;
        cin >> a;
        if (pos[a] > 0) {
            r = i;
            l = pos[a];
        } else {
            pos[a] = i;
        }
    }
    for (LL i = 1; i <= n + 1; i++) {
        LL ans = comb(n + 1, i);
        ans -= comb(l - 1 + n + 1 - r, i - 1);
        ans += MOD;
        ans %= MOD;
        cout << ans << endl;
    }
}


Measured memory_bytes: 5060
N,Q = map(int,input().split())
S = input()
LR = []
for _ in range(Q):
  LR.append([int(i) for i in input().split()])

AC_point = []
for n in range(N-1):
  if S[n] == "A" and S[n+1] == "C":
    AC_point.append(n+1)
import bisect
for lr in LR:
  a = bisect.bisect_left(AC_point,lr[0])
  b = bisect.bisect_left(AC_point,lr[1])
  print(b-a)


Measured memory_bytes: 25916
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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


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

    vector<int> ABC;
    int tmp;
    for(int i = 0; i < 3; i++){
        cin >> tmp;
        ABC.push_back(tmp);
    }

    sort(ABC.rbegin(),ABC.rend());

    cout << ABC[0] * 10 + ABC[1] + ABC[2] << endl;

    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  vector<int> bucket(200001, 0);
  for (int i = 0; i < n; i++) {
    bucket.at(a.at(i))++;
  }

  if (bucket.size() <= k) {
    cout << 0 << endl;
    return 0;
  } else {
    sort(bucket.begin(), bucket.end());
    int ball = bucket.size() - k;
    int count = 0;
    for (int i = 0; i < ball; i++) {
      count += bucket.at(i);
    }
    cout << count << endl;
    return 0;
  }
}

Measured memory_bytes: 1792
N, K = list(map(int, input().split()))
td = sorted([list(map(int, input().split())) for _ in range(N)],key=lambda x:-x[1])
q = []
ans = 0
s = set()
for i in range(K):
    ans += td[i][1]
    if td[i][0] in s:
        q.append(td[i][1])
    s.add(td[i][0])
ans += len(s)**2
k1 = K
ans1 = ans
while k1 < N and q:
    if td[k1][0] not in s:
        ans1 += td[k1][1] - q.pop() - len(s)**2 + (len(s)+1)**2
        ans = max(ans,ans1)
        s.add(td[k1][0])
    k1 += 1
print(ans)

Measured memory_bytes: 33024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#define rep(i,n) for(int i = 0;i<(n);i++);
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;

int main() {
	ll M1, M2, M3, M4;
	cin >> M1 >> M2 >> M3 >> M4;
	if (M1 == M3) cout << "0" << endl;
	else cout << "1" << endl;
}

Measured memory_bytes: 256
def main():
  s = input()
  K = int(input())
  a = set()
  for i in range(len(s)):
    for j in range(1, 6):
      a.add(s[i:i+j])
  print(sorted(list(a))[K-1])
  return

if __name__ == '__main__':
  main()

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

int main() {
  int a,b,c,d,res;

  cin >> a >> b >> c >> d;
  res = 0;
  
  for (int i = a; i < b+1; i++){
    if (c <= i && i <= d) res++;
  }
  
  if (res >= 1) res--;
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;

#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2);

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl

/*
合計N個のボール
K個の青い、N-K個の赤いボール
*/

vector<ll> fac(MAX);

void COMinit()
{
  fac[0]=1;
  for (ll i=1;i<=MAX;i++)
  {
    fac[i]=(fac[i-1]*i) % MOD; 
  }
}

ll fast(ll a, ll n)
{
  ll ret=1;
  while (n>0)
  {
    if (n & 1)
    {
      ret = (ret * a) % MOD;
    }
    n = (n>>1);
    a = a * a % MOD;
  }
  return (ret);
}

ll comb(ll n, ll r)
{
  ll top=1;
  ll bot=1;
  ll ans;

  if (n<r || n<0 || r<0) return (0);

  top = fac[n];
  bot = fac[r]*fac[n-r] % MOD;
  ans = top * fast(bot,MOD-2) % MOD;
  return (ans);
}

int main()
{
  ll N,K;cin>>N>>K;
  ll red = N-K;
  ll blue = K;
  
  COMinit();
  
  for (int i=1;i<=K;i++)
  {
    ll ans = comb(red+1,i) % MOD;
    ans *= comb(blue-1,i-1);
    ans %= MOD;
    cout<<ans<<endl;
  }
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    priority_queue<int, vector<int>, greater<int>> red, green;
    vector<int> r(a), g(b);
    for(int i = 0; i < a; ++i) {
        cin >> r[i];

    }
    for(int i = 0; i < b; ++i) {
        cin >> g[i];

    }
    sort(all(r), greater<>());
    sort(all(g), greater<>());

    for(int i = 0; i < x; ++i) {
        red.push(r[i]);

    }
    for(int i = 0; i < y; ++i) {
        green.push(g[i]);

    }

    vector<int> t(c);
    for(int i = 0; i < c; ++i) {
        cin >> t[i];

    }
    sort(all(t));

    for(int i = 0; i < c; ++i) {
        bool rf, gf;
        rf = gf = false;
        rf = red.top() < t[i];
        gf = green.top() < t[i];
        if(rf && gf) {
            if(red.top() < green.top()) {
                red.pop();
                red.push(t[i]);

            } else {
                green.pop();
                green.push(t[i]);

            }
        } else if(rf) {
            red.pop();
            red.push(t[i]);

        } else if(gf) {
            green.pop();
            green.push(t[i]);

        }
    }

    LL sum = 0;
    while(!red.empty()) {
        sum += red.top();
        red.pop();

    }
    while(!green.empty()) {
        sum += green.top();
        green.pop();

    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 2296
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  string S;
  cin >> S;
  int N = S.size();
  int cnt0=0;
  int cnt1=0;
  for(int i=0;i<N;i++){
    if(S[i]=='0') cnt0++;
    if(S[i]=='1') cnt1++;
  }
  cout << 2*min(cnt0,cnt1) << endl;
  return 0;
}

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

typedef long long ll;

int main()
{
	ll x, y;
	scanf("%lld%lld", &x, &y);
	ll g = __gcd(x, y);
	if(x % y == 0)
		puts("-1");
	else
		printf("%lld\n", x);
	return 0;
}

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

int main(){
    int N;
    string S;
    cin >> N >> S;
    vector<bool> responce;
    for(int i = 0; i < N; i++){
        responce.push_back(S[i] == 'o');
    }
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 2; j++){
            bool animals[N];
            animals[0] = i;
            animals[1] = j;
            for(int k = 2; k < N; k++){
                animals[k] = (responce[k - 1] ^ animals[k - 1] ^ animals[k - 2]);
            }
            if(!(animals[N - 2] ^ animals[N - 1] ^ animals[0] ^ responce[N - 1])){
                if(!(animals[N - 1] ^ animals[0] ^ animals[1] ^ responce[0])){
                    for(int k = 0; k < N; k++){
                        if(animals[k]){
                        cout << "S";
                        }else{
                            cout << "W";
                        }
                    }
                    return 0;
                }
            }
        }
    }
    cout << -1 << endl;
}

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


// mod1000000007の時の型 mint
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


//２のｎ乗
mint f(int n){
  if(n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if(n%2 == 1) x *= 2;
  return x;
}


mint comb(int n, int r){
  mint x = 1, y = 1;
  rep(i,r){
  	x *= i+1;
  	y *= n-i;
  }
  return y/x;
}


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

  mint ans = f(n);
  ans -= 1; 
  ans -= comb(n,a);
  ans -= comb(n,b);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    N, W = map(int, input().split())
    v = [[] for i in range(4)]

    for i in range(N):
        wi, vi = map(int, input().split())

        if i == 0:
            base = wi
            v[0].append(vi)
        else:
            v[wi - base].append(vi)

    for i in range(4):
        v[i].sort(reverse=True)

    ans = 0

    for i in range(len(v[0]) + 1):
        for j in range(len(v[1]) + 1):
            for k in range(len(v[2]) + 1):
                w = base*i + (base + 1)*j + (base + 2)*k

                if w > W:
                    continue

                l = (W - w) // (base + 3)

                kakaku = sum(v[0][:i]) + sum(v[1][:j]) + sum(v[2][:k]) + sum(v[3][:l])

                ans = max(ans, kakaku)

    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3188
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>

using namespace std;

typedef complex<double> P;

int main(){

	P p;
	double c_r = 90;
	double x,r; char c;
	while(cin>>x>>c>>r,(x||r)){
		P add = P(x,0) * P(cos(c_r * M_PI / 180),sin(c_r* M_PI / 180));
		p += add;
		c_r -= r;
	}

	cout << (int)p.real() << endl << (int)p.imag() << endl;

	return 0;
}

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

int main(void)
{
  std::string num;
  std::cin >> num;

  int end = num.size()-1;
  int endnum = num[end] - '0';

  if (endnum == 3) {
    std::cout << "bon\n";
  }
  else if (endnum == 0 || endnum == 1 | endnum == 6 | endnum == 8) {
    std::cout << "pon\n";
  }
  else {
    std::cout << "hon\n";
  }
}

Measured memory_bytes: 3600
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int x;
  scanf("%d", &x);
  puts(x < 1200 ? "ABC" : "ARC");
  return 0;
}

Measured memory_bytes: 128
input()
ks = list(map(int, input().split()))

def splitList(ks):
  temp = []
  for k in ks:
    if k == 0:
      if temp:
        yield temp
        temp = []
    else:
      temp.append(k)
  if temp:
    yield temp

def f(ks):
  if not ks:
    return 0
  n = min(ks)
  ks_ = [k-n for k in ks]
  kss = list(splitList(ks_))
  return n + sum(map(f, kss))

print(f(ks))


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

int main()
{
    int n,m,X,Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n), y(m);
    REP(i,n)    cin >> x[i];
    REP(i,m)    cin >> y[i];

    sort(x.begin(), x.end(), greater<int>() );
    sort(y.begin(), y.end());

    bool flag = false;

    FOR(i,X+1,Y+1){
        if(x[0]<i and i<=y[0]){
            flag = true;
        }
    }

    if(flag){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;


int n;
int p[30];


int main(){

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

    int ans = 0;

    for(int i = 0; i < n-2; i++){
        if(p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2]){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

const int maxn = 1e5;

int n, size[maxn];
vector< pair<int, int> > g[maxn];
long long ans;

void Dfs1(int u, int p) {
  size[u] = 1;
  for (pair<int, int> e : g[u]) {
    int v = e.first, len = e.second;
    if (v == p) continue;
    Dfs1(v, u);
    size[u] += size[v];
    ans += (long long)len * (size[v] << 1 == n ? n - 1 : min(size[v], n - size[v]) << 1);
  }
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, len;
    scanf("%d%d%d", &u, &v, &len);
    --u; --v;
    g[u].push_back({v, len});
    g[v].push_back({u, len});
  }
  Dfs1(0, -1);
  int best = n, id = -1;
  for (int i = 0; i < n; ++i) {
    int t = n - size[i];
    for (pair<int, int> e : g[i]) {
      if (size[e.first] < size[i]) {
        t = max(t, size[e.first]);
      }
    }
    if (t < best) {
      best = t;
      id = i;
    }
  }
  if (best << 1 != n) {
    int minv = 1e9;
    for (pair<int, int> e : g[id]) {
      minv = min(minv, e.second);
    }
    ans -= minv;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 12800
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
int main() {
	double n;
	cin >> n;
	int x[100];
	double sum = 0;
	double Sum = 0;
	double d = 0;
	rep(i, n) {
		cin >> x[i];
		sum += x[i];
		Sum += x[i] * x[i];
	    d = min(n*floor(sum / n)*floor(sum / n) + Sum - 2 * floor(sum / n)*sum, n*ceil(sum / n)*ceil(sum / n) + Sum - 2 * ceil(sum / n)*sum);
	}
	int k = d;
	cout << d << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    int inputNumber;

    int check = 0;

    //入力部分
    scanf("%d",&inputNumber);

    //計算部分
    while(inputNumber != 0){
        if(inputNumber % 10 == 7){
            printf("Yes\n");
            check = 1;
            break;
        }
        inputNumber = (inputNumber-(inputNumber%10))/10;
    }
    
    if(check == 0)printf("No\n");

    //出力部分
}

Measured memory_bytes: 1644
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;

public class Main {
  Scanner sc;
  static final int INF = 1 << 28;

  class Point {
    int x_, y_;

    Point(int x, int y) {
      x_ = x;
      y_ = y;
    }

    int[][] ofs = new int[][] { { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 } };

    Point(Point p, int d) {
      x_ = p.gx() + ofs[ d ][ 0 ];
      y_ = p.gy() + ofs[ d ][ 1 ];
    }

    int gx() {
      return x_;
    };

    int gy() {
      return y_;
    };
  }

  void run() {
    for ( ;; ) {
      int N = ni();

      if ( N == 0 )
        break;

      HashMap<Integer, Point> map = new HashMap<Integer, Point>();
      map.put( 0, new Point( 0, 0 ) );
      for ( int i = 1; i <= N - 1; ++i ) {
        int n = ni();
        int d = ni();

        Point p = map.get( n );
        map.put( i, new Point( p, d ) );
      }

      int minx = INF, maxx = -INF;
      int miny = INF, maxy = -INF;

      for ( Iterator<Integer> ite = map.keySet().iterator(); ite.hasNext(); ) {
        Point p = map.get( ite.next() );
        minx = Math.min( minx, p.gx() );
        maxx = Math.max( maxx, p.gx() );
        miny = Math.min( miny, p.gy() );
        maxy = Math.max( maxy, p.gy() );
      }

      System.out.println( ( maxx - minx + 1 ) + " " + ( maxy - miny + 1 ) );
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

  String ns() {
    return sc.next();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

Measured memory_bytes: 35508
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class BinaryIndexedTree
{
private:
    int n;
    vector<int> data;
public:
    BinaryIndexedTree(int n){ // コンストラクタ
        this->n = n;
        data.assign(n+1, 0);
    }
    void add(int k, int x){ // k番目の要素にxを加算する
        ++ k;
        while(k <= n){
            data[k] += x;
            k += k & -k;
        }
    }
    int sum(int k){ // 区間[0,k]の総和を返す
        ++ k;
        int ret = 0;
        while(k > 0){
            ret += data[k];
            k -= k & -k;
        }
        return ret;
    }
    int sum(int a, int b){ // 区間[a,b]の総和を返す
        return sum(b) - sum(a-1);
    }
};

long long inversionNumber(const vector<int>& v)
{
    int n = v.size();
    vector<pair<int, int> > p(n);
    for(int i=0; i<n; ++i)
        p[i] = make_pair(v[i], i);
    sort(p.rbegin(), p.rend());

    BinaryIndexedTree bit(n);
    long long ans = 0;
    for(int i=0; i<n; ++i){
        ans += bit.sum(p[i].second);
        bit.add(p[i].second, 1);
    }
    return ans;
}

int solve(const vector<int>& a)
{
    int n = a.size();
    int left = *min_element(a.begin(), a.end());
    int right = *max_element(a.begin(), a.end()) + 1;
    while(right - left > 1){
        int mid = (left + right) / 2;
        vector<int> b(n+1, 0);
        for(int i=0; i<n; ++i){
            b[i+1] = b[i];
            if(mid <= a[i])
                ++ b[i+1];
            else
                -- b[i+1];
        }

        if(inversionNumber(b) > n * (n + 1LL) / 4)
            right = mid;
        else
            left = mid;
    }
    return left;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    cout << solve(a) << endl;

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    int ans = 0;
    rep(i, n - 1) {
        for (int j = i + 1; j < n; j++) {
            ans = max(ans, abs(a[i] - a[j]));
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String s=reader.readLine();
			String[] t;
			t=s.split(" ");
			int n,m;
			n=Integer.parseInt(t[0]);
			m=Integer.parseInt(t[1]);
			if(n==0 &&m==0){
				System.exit(0);
			}
			int ansta=0;
			int ansha=0;
			int[] Sta=new int[n];
			int[] Sha=new int[m];
			for(int i=0;i<n;i++){
				Sta[i]=Integer.parseInt(reader.readLine());
			}
			for(int j=0;j<m;j++){
				Sha[j]=Integer.parseInt(reader.readLine());
			}
			int Sumsta=0;
			int Sumsha=0;
			for(int k=0;k<n;k++){
				Sumsta+=Sta[k];
			}
			for(int l=0;l<m;l++){
				Sumsha+=Sha[l];
			}
			int dif;
			if(Sumsha<Sumsta){
				dif=Sumsta-Sumsha;
			}else{
				dif=Sumsha-Sumsta;
			}
			label:
			for(int p=0;p<n;p++){
				for(int q=0;q<m;q++){
					if(Sumsha==Sumsta){
						if(Sta[p]==Sha[q]){
							ansta=Sta[p];
							ansha=Sha[q];
							break label;
						}
					}
					if(Sumsha<Sumsta){
						if(Sha[q]<Sta[p]){
							if((Sta[p]-Sha[q])*2==dif){
								ansta=Sta[p];
								ansha=Sha[q];
								break label;
							}
						}
					}else{
						if(Sha[q]>Sta[p]){
							if((Sha[q]-Sta[p])*2==dif){
								ansta=Sta[p];
								ansha=Sha[q];
								break label;
							}
						}
					}
				}
			}
			if(ansta==0 &&ansha==0){
				System.out.println("-1");
			}else{
				System.out.println(ansta+" "+ansha);
			}
		}
	}
}	

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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int n;
  cin >>n;
  VI A(n);
  rep(i,n) cin >> A[i];

  ll odd = 0, even = 0;
  rep(i,n){
    if(A[i] % 2) odd++;
    else even++;
  }
  if((odd) %2 == 0){
    cout << "YES" << endl;
    return 0;
  }
  puts("NO");
  return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    string s;
    cin >> s;
    if (s[s.size() - 1] == 's')
        s += "es";
    else
        s += "s";
    cout << s << endl;
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int d, t, s;
    cin>> d>> t>> s;

    cout << ( d > (t*s) ? "No\n"  : "Yes\n");


    return 0;
}




Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
long long n,a[30],res,maxres,i1;
string s;
int main()
{
    //freopen("input.txt","r",stdin);
    cin>>n>>s;
    maxres=-107;
    for(int x=0;x<n;x++){
     res=0;
     for(int i=0;i<x;i++)
      for(int j=x;j<n;j++)if(s[i]==s[j])a[s[i]-'a'+1]=1;
      for(int i=1;i<=26;i++){
            res+=a[i];
            a[i]=0;
      }
      if(res>maxres){
       maxres=res;
       i1=x;
      }
    }
    cout<<maxres<<endl;
}


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

int main(){
  int n;
  cin >> n;
  
  int x = n / 1.08;
  int r = x * 1.08;
  int rp = (x+1) * 1.08;
  
  if(r == n){
    cout << x << endl;
  }
  else if(rp == n){
      cout << x+1;
  }
  else{
    cout << ":(";
  }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<((ll)n);i++)
#define rep1(i,n) for(ll i=1;i<=((ll)n);i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define meow(a) cout<<a<<" meow\n";
typedef pair<long long,long long> pii;
const ll maxn=200005;
const ll MOD=998244353;
ll n,k;
ll a[maxn];
int main()
{
    //IOS;
    while(cin>>n>>k)
    {
        string s;
        cin>>s;
        s[k-1]=tolower(s[k-1]);
        cout<<s<<"\n";
    }
    return 0;
}


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

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

    if(a>=400 && a<=599){
        cout << 8 <<endl;
    }else if(a>=600 && a<=799){
        cout << 7 << endl;
    }else if(a>=800 && a<=999){
        cout << 6 << endl;
    }else if(a>=1000 && a<=1199){
        cout << 5 << endl;
    }else if(a>=1200 && a<=1399){
        cout << 4 << endl;
    }else if(a>=1400 && a<=1599){
        cout << 3 << endl;
    }else if(a>=1600 && a<=1799){
        cout << 2 << endl;
    }else if(a>=1800 && a<=1999)        cout << 1 << endl;
    

    return 0;
}

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

int main(){
    int a, b;

    cin >> a >> b;
    //total = (b-1);
    int connecter_num = 0;
    if(b > 1){
        while(1){
            if(b-(a*connecter_num-connecter_num+1)<=0){
                break;
            }
            connecter_num++;
        }
    }
    cout << connecter_num << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int r, c;
   
    scanf("%d %d", &r, &c);

    int a[r + 1][c + 1];
    int i, j;

    for (i = 0; i < r; ++i) {
        for (j = 0; j < c; ++j) {
            scanf("%d", &a[i][j]);
        }
    }

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

    for (i = 0; i < r; ++i) {
        for (j = 0; j < c; ++j) {
            a[i][c] += a[i][j];
        }
    }

    for (i = 0; i < c; ++i) {
        for (j = 0; j < r; ++j) {
            a[r][i] += a[j][i];
        }
    }
    
    for (i = 0; i < r; ++i) {
        a[r][c] += a[i][c];
    }

    for (i = 0; i < r + 1; ++i) {
        for (j = 0; j < c + 1; ++j) {
            printf("%d", a[i][j]);
            if (j == c) printf("\n");
            else printf(" ");
        }
    }

    return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

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...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    vector<int> a(n);
    REP(i,n) cin >> a[i];

    int ans=0;
    REP(i,n-2){
        int mi = min(a[i],min(a[i+1],a[i+2]));
        int ma = max(a[i],max(a[i+1],a[i+2]));
        if(a[i+1]!=mi && a[i+1]!=ma) ans++;
    }

    pl(ans)

    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

const int max_n = 1, inf = 1011111111;

int n, x, ans;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    while (n--) {
        scanf("%d", &x);
        if (x % 2) {
            ++ans;
        }
    }
    if (ans % 2) {
        printf("NO\n");
    } else {
        printf("YES\n");
    }
    return 0;
}


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

int main(){
    int i, N;
    long long answer = 0;
    vector<string> s;
    unordered_map<string, int> hashedStr;

    cin >> N;
    for(i = 0; i < N; i++){
        string tmp;
        cin >> tmp;
        sort(tmp.begin(), tmp.end());
        if(hashedStr[tmp] != 0){
            answer += hashedStr[tmp];
        }
        hashedStr[tmp]++;
    }

    cout << answer << endl;

    return 0;
}

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

int main()
{
        int n;
        cin >> n;
        int arr[n];
        int ans = 0;
        for(int i = 0; i < n;i++)
        {
                cin >> arr[i];
        }
        for(int i = 0; i< n;i++)
        {
                for(int j= i+1; j< n; j++)
                {
                        ans += arr[i] * arr[j];
                }
        }
        cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>

#define INF 1<<29

using namespace std;

int main(void) {
	string s;
	cin >> s;
	bool f1 = false, f2 = false, f3 = true;
	int visit = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[0] == 'A') {
			f1 = true;
		}
		if (2<=i&&i<=s.size()-2&&s[i] == 'C') {
			f2 = true;
			visit++;
		}
		if (visit != 1) {
			f2 = false;
		}
		if (!islower(s[i])&&s[i]!='A'&&s[i]!='C') {
			f3 = false;
		}
	}
	if (f1&&f2&&f3) {
		cout << "AC";
	}
	else {
		cout << "WA";
	}
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
sys.setrecursionlimit(10000)

N = int(input())
a = list(map(int, input().split()))
dp = [[[-1 for i in range(N+1)] for j in range(N+1)] for k in range(N+1)]

def rec(i, j, k):
    if dp[i][j][k] >= 0:
        return dp[i][j][k]
    if i == 0 and j == 0 and k == 0:
        return 0.0
    res = 0.0
    if i > 0:
        res += rec(i-1, j, k) * i
    if j > 0:
        res += rec(i+1, j-1, k) * j
    if k > 0:
        res += rec(i, j+1, k-1) * k
    res += N
    res *= 1.0/(i+j+k)

    dp[i][j][k] = res
    return res

c = Counter(a)
one, two, three = c[1], c[2], c[3]
print(rec(one, two, three))

Measured memory_bytes: 412276
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int[] coin = { 500, 100, 50, 10, 5, 1 };
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			n = 1000 - n;
			int ans = 0;
			for (int c : coin) {
				if (n >= c) {
					int a = n / c;
					n -= a * c;
					ans += a;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 17184
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        String s = scanner.next();
        int[] l = new int[q];
        int[] r = new int[q];
        for (int i=0;i<q;i++){
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }
        int[] integer = new int[n];
        integer[0] = 0;
        for (int i=0;i<n-1;i++){
            if (s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
                integer[i+1]=integer[i]+1;
            }else {
                integer[i+1]=integer[i];
            }
        }

        for (int i=0;i<q;i++){
            System.out.println(integer[r[i]-1]-integer[l[i]-1]);
        }
    }

}

Measured memory_bytes: 86608
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let s:String = read();
    let s:Vec<&str> = s.split('/').collect();

    println!("{}",
        if s[0] == "2019" {
            if s[1] > "04" {
                "TBD"
            } else {
                "Heisei"
            }
        } else if s[0] > "2019" {
            "TBD"
        } else {
            "Heisei"
        }
    );

}


Measured memory_bytes: 4352