akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main() {
    string s; cin >> s;
    int N = s.size();
    ll K; cin >> K;
    if(s[0]!=s[N-1]) {
        s += '$';
        ll cnt = 1;
        ll ans = 0;
        REP(i,N) {
            if(s[i+1]==s[i]) cnt += 1;
            else{
                ans += cnt / 2;
                cnt = 1;
            }
        }
        ans *= K;
        cout << ans << endl;
    }
    else {
        char c = s[0];
        int i=0;
        ll cnt1=0;
        ll cnt2=0; 
        while(s[i]==c){
            cnt1++;
            i++;
        }
        int j=N-1;
        while(s[j]==c && j>=i){
            cnt2++;
            j--;
        }
        ll cnt = 1;
        ll ans = 0;
        FOR(k,i,j+1) {
            if(s[k+1]==s[k]) cnt ++;
            else {
                ans += cnt / 2;
                cnt = 1;
            }
        }
        ans *= K;
        ans += ((cnt1+cnt2)/2)*(K-1);
        ans += cnt1/2 + cnt2/2;
        cout << (cnt1+cnt2==N?N*K/2:ans) << endl;
    }
}

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

int D;
vector<int> c;
vector<vector<int>> s;
vector<int> solution;
vector<int> last(26);

unsigned int xor128() {
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t;
    t = x ^ (x << 11);
    x = y; y = z; z = w;
    return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
}

ll evaluate(vector<int>& sol) {
    ll score = 1e6;
    fill(ALL(last), 0);

    REP(d, D) {
        int j = sol[d] - 1;
        last[j] = d + 1;
        REP(i, 26) {
            score -= (d + 1 - last[i]) * c[i];
        }
        score += s[d][j];
    }

    return max(score, 0ll);
}

void simulated_annealing() {

    auto begin_time = chrono::steady_clock::now();
    auto cur_time = begin_time;
    ll time_elapsed = 0;
    const ll DURATION = 1900;

    double temperature = 1;

    vector<int> cur_state = solution;

    ll cur_score = evaluate(cur_state);
    ll best_score = cur_score;

    int iter = 0;

    while (true) {
        // check the time and update the temperature
        if (iter % 100 == 0) {
            cur_time = chrono::steady_clock::now();
            time_elapsed = chrono::duration_cast<chrono::milliseconds>(cur_time - begin_time).count();
            if (time_elapsed > DURATION) break;
            temperature = (double) (DURATION - time_elapsed) / DURATION;
        }

        // get the next state
        // pick a day and change it to other type
        int d = xor128() % D;
        int i = cur_state[d];
        int j = xor128() % 26 + 1;
        cur_state[d] = j;

        // calculate the score of the next state
        ll next_score = evaluate(cur_state);

        // if the score improved or force_next is true, set the neighbor as the current node
        const ll R = 10000;
        // const bool force_next = temperature > (double) (xor128() % R) / R;
        const bool force_next = false;

        if (next_score > cur_score || force_next) {
            cur_score = next_score;
        } else {
            // roll back the change
            cur_state[d] = i;
        }

        // save the best state
        if (cur_score > best_score) {
            solution = cur_state;
            best_score = cur_score;
        }

        iter++;
    }

    cerr << "Time elapsed: " << time_elapsed << endl;
    cerr << "Iterations: " << iter << endl;
}

void greedy() {
    fill(ALL(last), 0);

    for (int d = 0; d < D; d++) {
        int j = 0, score = 0;
        for (int i = 0; i < 26; i++) {
            int nscore = s[d][i] + (d - last[i]) * c[i] * 5;
            if (nscore > score) {
                j = i;
                score = nscore;
            }
        }
        last[j] = d + 1;
        solution[d] = j + 1;
    }
}

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

    cin >> D;
    c.resize(26);
    REP(i, 26) cin >> c[i];
    s.resize(D, vector<int>(26));
    REP(i, D) REP(j, 26) cin >> s[i][j];
    solution.resize(D);

    greedy();
    simulated_annealing();

    REP(d, D) cout << solution[d] << endl;
}


Measured memory_bytes: 3728
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
int vectPrint(const vector<ll>& A) {
    int size = A.size();
    for (int i = 0; i < size; i++) {
        cout << A[i] << " ";
    }
    cout << endl;
    return 0;
}
ll max2val(ll a, ll b) {
    if (a > b) {
        return a;
    }
    else {
        return b;
    }
}

int main(void) {
    // Your code here!
    ll N, M, K;
    ll ans, j;

    std::cin >> N;
    std::cin >> M;
    std::cin >> K;
    vector<ll> vecN(N, 0), vecM(M, 0);
    vector<ll> a(1), b(1);
    
    for (ll i = 0; i < N; i++) {
        cin >> vecN[i];
    }
    for (ll i = 0; i < M; i++) {
        cin >> vecM[i];
    }
    //単純増加列
    for (ll i = 0; i < N; i++) {
        a.push_back(a[i] + vecN[i]);
    }
    for (ll i = 0; i < M; i++) {
        b.push_back(b[i] + vecM[i]);
    }

    ans = 0;
    j = M;
    for (ll i = 0; i < N + 1; i++) {
        if (a[i] > K)break;
        while (b[j] > K - a[i]) {
            j -= 1;
        }
        ans = max2val(ans, i + j);
    }

    cout << ans;
    
    return 0;
}


Measured memory_bytes: 11120
#include <iostream>
#include <string.h>

using namespace std;

int main(){
  char a,b;
  scanf("%c %c",&a,&b);
  //cout << a << b << endl;

  if (a == b){
    cout << "H" << endl;
  }
  else{
    cout << "D" << endl;
  }
  return 0;

}


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

int main() {
    const int limit = 1e6 + 5;
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> v(limit), primes;
    fill(v.begin(), v.end(), 1);
    v[1] = 0;
    for (int i = 2; i <= limit; i++) {
        if (!v[i]) continue;
        primes.push_back(i);
        for (int j = 2 * i; j < n; j += i) {
            v[j] = 0;
        }
    }
    vector<int> mark(limit);
    bool pairwise = true;
    for (int x : a) {
        int t = x;
        for (int p : primes) {
            if (p * p > t) break;
            if (t % p == 0) {
                if (mark[p]) {
                    pairwise = false;
                    break;
                }
                mark[p] = 1;
                while (t % p == 0)
                    t /= p;
            }
        }
        if (v[t]) {
            if (mark[t])
                pairwise = false;
            mark[t] = 1;
        }
        if (!pairwise)
            break;
    }
    if (pairwise) {
        cout << "pairwise coprime\n";
        return 0;
    }
    int g = a[0];
    for (int x : a) {
        g = __gcd(g, x);
    }
    if (g == 1)
        cout << "setwise coprime\n";
    else
        cout << "not coprime\n";
}


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

int main(){
    string S;
    cin >> S;
    for(int s = 0; s < (1 << (S.size()-1)); s++){
        string now = "";
        now += S[0];
        for(int i = 0; i < S.size()-1; i++){
            if(s & (1<<i)) now += "+";
            else now += "-";
            now += S[i+1];
        }
        int sum = int(S[0]-'0');
        for(int i = 1; i < 6; i+=2){
            if(now[i] == '+') sum += int(now[i+1]-'0');
            else sum -= int(now[i+1]-'0');
        }
        if(sum == 7){
            now += "=7";
            cout << now << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	char s[15];
	scanf("%s",s);
	int j=0;
	int len=strlen(s);
	for(int i=0;i<(len/2);i++)
	{
		if((s[i]=='i'&&s[len-1-i]!='i')||(s[i]=='w'&&s[len-1-i]!='w')||(s[i]=='('&&s[len-1-i]!=')')||(s[i]==')'&&s[len-1-i]!='('))
		{
			j++;
		}	
	}
	if(len%2==1&&s[len/2]!='i'&&s[len/2]!='w')
	{
		j++;
	}	
	printf("%d\n",j);
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int s;
  cin >> s;

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

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    int N,M;
    cin>>N>>M;
    bool ans=true;
    vector<string> P(10,"-1");
    string S;
    rep(i,N){
        S.pb('n');
    }
    rep(i,M){
        int s;
        string c;
        cin>>s>>c;
        s--;
        if((s==0&&N!=1&&c=="0")||(P[s]!=c&&P[s]!="-1")){
            ans=false;
        }
        P[s]=c;
        S.erase(S.begin()+s);
        S.insert(S.begin()+s,c[0]);
    }
    if(S[0]=='n'&&N!=1){
        S[0]='1';
    }
    rep(i,N){
        if(S[i]=='n')S[i]='0';
    }
    if(!ans){
        cout<<-1<<endl;
        return 0;
    }
    cout<<S<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

void fprint() { std::cout << '\n'; }
template <class H, class... T> void fprint(H &&head, T &&... args) {
    std::cout << std::fixed << std::setprecision(10) << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    fprint(std::forward<T>(args)...);
}

template <class T> T factorial(T N) {
    // int 型だとたかだか N <= 12 まで
    // long long 型だと N <= 20 まで
    T ans = 1;
    for (int i = 0; i < N; i++) {
        ans *= (i + 1);
    }
    return ans;
}

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

    int N;
    scan(N);
    vector<pair<int, int>> v(N);
    rep(i, N) scan(v[i].first, v[i].second);
    sort_(v);

    ld ans = 0.0;

    do {
        for_(i, 1, N) {
            ans += sqrt(pow(v[i].first - v[i - 1].first, 2) +
                        pow(v[i].second - v[i - 1].second, 2));
        }
    } while (next_permutation(all(v)));
    int div = factorial(N);
    ans /= div;
    fprint(ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
long long H;
cin>>H;
long long ans=H;
long long num_monster=1;
while(H>1){
  if(H%2==1){
    ans-=num_monster;
  }
  H/=2;
  ans+=num_monster;
  num_monster*=2;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;

ll power(ll x , ll y){
    if(y == 0)
        return 1ll;
    else
    {
        ll a = power(x , y/2);
        if(y&1)
            return  (((a*a)%Mod)*x)%Mod;
        else
            return (a*a)%Mod;
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    string s; cin >> s;
    ll ans = 0 , cnt = 0 , n = s.size();

    for(int i = 0 ;i < n ; i++){
        if(s[i] == '1'){
            ans += (power(2 , cnt)*power(3 , n-1-i))%Mod;
            cnt++;
            ans %= Mod;
        }
    }
    ans += power(2 , cnt);
    cout << (ans%Mod) << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++){
    cin>>a[i];
    if(i==0){
      if(a[0]>0){
        cout<<-1<<endl;
        return 0;
      }
    }
    else{
      if(a[i]>i||a[i]-a[i-1]>1){
        cout<<-1<<endl;
        return 0;
      }
    }
  }
  ll ans=0;
  ll now=0;
  for(ll i=0;i<n;i++){
    if(a[i]==0)continue;
    if(a[i]==now+1){
      ans++;
      now++;
      continue;
    }
    ans+=a[i];
    now=a[i];
  }
  cout<<ans<<endl;
}
      
  

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int h,w;
    cin >> h >> w;
    vector<string>field(h);
    rep(i,h) {
        cin >> field[i];
    }
    vector<vector<int>>L(h,vector<int>(w));
    vector<vector<int>>R(h,vector<int>(w));
    vector<vector<int>>D(h,vector<int>(w));
    vector<vector<int>>U(h,vector<int>(w));
    rep(i,h) {
        int cur = 1;
        rep(j,w) {
            if(field[i][j]=='#') cur = 0;
            L[i][j] = cur;
            cur++;
        }
        // cout << endl;
    }
    rep(i,h) {
        int cur = 1;
        for(int j = w-1;j>=0;j--) {
            if(field[i][j]=='#') cur = 0;
            R[i][j] = cur;
            // cout << R[i][j] << " ";
            cur++;
        }
        // cout << endl;
    }
    rep(j,w) {
        int cur = 1;
        rep(i,h) {
            if(field[i][j]=='#') cur = 0;
            U[i][j] = cur;
            cur++;
        }
    }
    
    rep(j,w) {
        int cur = 1;
        for(int i = h-1;i>=0;i--) {
            if(field[i][j]=='#') cur = 0;
            D[i][j] = cur;
            cur++;
        }
    }
    int ans = 0;
    rep(i,h) rep(j,w) {
        if(field[i][j] == '#') continue;
        int res = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3;
        ans = max(ans,res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 73756
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

// 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();
}

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

//math
template <class T>
inline T sqr(T x) { return x * x; }

template <class T>
inline T nCr(T n, T r)
{
    T num = 1;
    for (int i = 1; i <= r; ++i)
    {
        num *= (n - i + 1) / i;
    }
    return num;
}
template <class T>
inline T nPr(T n, T r)
{
    r = n - r;
    T sum = 1;
    int i;
    for (i = n; i >= r + 1; --i)
        sum *= i;
    return sum;
}

template <class T>
inline T facctorial(T k)
{
    T sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

//numeric
template <class T>
inline T gcd(T a, T b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

template <class T>
inline T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

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

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main()
{
    LL n;
    cin >> n;
    if (n % 2 == 0)
    {
        cout << n / 2 * (n - 1) << endl;
    }
    else
    {
        cout << (n - 1) / 2 * n << endl;
    }
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

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")
}

fn main() {
    let n: u64 = read();
    let m: usize = read();
    let a: u64 = (0..m).fold(0, |b, _| b + read::<u64>());
    if n < a {
        println!("{}", -1);
    } else {
        println!("{}", n - a);
    }
}


Measured memory_bytes: 2108
#include<iostream>
#include<cmath>
using namespace std;
typedef double dbl;
dbl x[4], y[4], k[2];

int main() {
	while (cin >> x[0] >> y[0]) {
		int ans = 0;
		for (int i = 1; i <= 3; i++) cin >> x[i] >> y[i];
		k[0] = x[1] - x[0]; k[1] = x[3] - x[2];
		if (k[0] == 0) {
			if (y[3] == y[2]) ans++;
		}
		else if (k[1] == 0) {
			if (y[1] == y[0]) ans++;
		}
		else {
			k[0] = (y[1] - y[0]) / k[0]; k[1] = (y[3] - y[2]) / k[1];
			if (fabs(k[0] * k[1] + 1) < 1e-10) ans++;
		}
		if (ans) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll l_inf=0x3f3f3f3f3f3f3f3f;
const int maxn=1010;
inline int read(){
    int x=0,c=getchar(),f=0;
    for(;c>'9'||c<'0';f=c=='-',c=getchar());
    for(;c>='0'&&c<='9';c=getchar())
    x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline bool scan_lf(double &num)
{
        char in;double Dec=0.1;
        bool IsN=false,IsD=false;
        in=getchar();
        if(in==EOF) return false;
        while(in!='-'&&in!='.'&&(in<'0'||in>'9'))
                in=getchar();
        if(in=='-'){IsN=true;num=0;}
        else if(in=='.'){IsD=true;num=0;}
        else num=in-'0';
        if(!IsD){
                while(in=getchar(),in>='0'&&in<='9'){
                        num*=10;num+=in-'0';}
        }
        if(in!='.'){
                if(IsN) num=-num;
                return true;
        }else{
                while(in=getchar(),in>='0'&&in<='9'){
                        num+=Dec*(in-'0');Dec*=0.1;
                }
        }
        if(IsN) num=-num;
        return true;
}

int main()
{
	int n;
	int a[202];
	while (~scanf("%d", &n)){
		for (int i=0; i<n; i++)  a[i] = read();
		sort(a, a+n);
		reverse(a, a+n);
		
		int aa = 0 , bb = 0;
		int k = n / 2;
		for (int i=0; i<n; i++){
			if (i&1)  bb += a[i];
			else  aa += a[i];
		}
		cout << aa-bb << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long A, long long B, long long C, long long X, long long Y){
  ll nc = C*2 , x = A*X + B*Y , ans = x;
  ll nx = X , ny = Y;
  for (int i = 0; i < max(X,Y); i++) {
    x -= ((nx > 0 ? A : 0) + (ny > 0 ? B : 0));
    if(nx > 0)nx--;
    if(ny > 0)ny--;
    x += nc;
    ans = min(x,ans);
  }
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(A, B, C, X, Y);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace B_ABC148
{
    class MainClass
    {

        static int[] s;
        static string[] s2;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            s2 = ReadLine().Split().ToArray();
            for (int i = 0; i < s[0]; i++)
            {
                Write(s2[0][i]);
                Write(s2[1][i]);

            }
            WriteLine();
        }
    }
}


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

int main(){
  int N;
  int sum=0;
  cin>>N;
  for(int i=0;i<N;i++){
    int l,r;
    cin>>l>>r;
    sum+=r-l+1;
    }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>

int main()
{
	int a, b, c, d;
	std::cin >> a >> b >> c >> d;

	if(abs(c - a)  <= d)
		{
		std::cout << "Yes" << std::endl;
	}else if(abs(a - b ) <= d && abs(c - b) <= d){
		std::cout << "Yes" << std::endl;
	}else{
		std::cout << "No" << std::endl;
	}
}

Measured memory_bytes: 256
/*
    Problem 2
    https://atcoder.jp/contests/abc106/tasks/abc106_b
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
/* global variables */
/* function */
int cntDvisor(int x) {
    if (x <= 1) return 1;
    int cnt = 0;
    for (int i = 1; i*i <= x; i++) {
        if (x % i == 0) {
            cnt++;
            if (i * i != x) cnt++;
        }
    }
    return cnt;
}
/* main */
int main(){
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        if (cntDvisor(i) == 8) ans++;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,c,d;
int main()
{
	cin>>a>>b>>c>>d;
	if(a+b>c+d)
		cout<<"Left\n";
	else
	if(a+b<c+d)
		cout<<"Right\n";
	else
		cout<<"Balanced\n";
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <math.h>
#include <map>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <type_traits>
#include <queue>
#include <vector>


#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

// グリッド上の縦横移動
constexpr std::array<std::pair<int, int>, 4> dxdy = {
    std::pair<int, int>( 1,  0),
    std::pair<int, int>(-1,  0),
    std::pair<int, int>( 0,  1),
    std::pair<int, int>( 0, -1)
};

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

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

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

inline bool isIn(int x, int y, int H, int W){
    return 0 <= x and x < H and 0 <= y and y < W;
}
inline bool bitUP(int state, int k){ return (state >> k) & 1; }
inline bool bitUP(long long int state, int k){ return (state >> k) & 1;}

// z-algorithm
template <class T> std::vector<int> z_algorithm(const T &str) {
    const int n = str.size();
    std::vector<int> resOfCP(n); resOfCP[0] = n;
    int i = 1, j = 0;
    while (i < n) {
        while (i + j < n and str[j] == str[i + j]) ++j;
        resOfCP[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i + k < n and k + resOfCP[k] < j) resOfCP[i + k] = resOfCP[k], ++k;
        i += k; j -= k;
    }
    return resOfCP;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


int main(void){
    int a, b; scanf("%d%d", &a, &b);
    int c = a / b; if(c * b < a) c++;
    printf("%d\n", c);
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed<<setprecision(x)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

const ll mod = 1e9 + 7;
//const int scope = 100005;
char k[100005];

void add_store(int &a, int b)
{
    (a += b) %= mod;
    
}

int main()
{
    fast_io;
    
    int D;
    cin>>k>>D;
    int length = strlen(k);
    
    vector< vector<int>> dp (D, vector<int> (2));
    dp[0][0] = 1;
    
    for(int pos=0;pos<length;pos++)
    {
        vector< vector<int>> dp1(D, vector<int>(2));
        for(int sum=0;sum<D;sum++)
        {
            for( bool small : {false,true})
            {
                for(int dig=0;dig<=9;dig++)
                {
                    
                    if(dig > pos[k]-'0' && small == false)
                    break;
                    
                    add_store( dp1[(sum+dig)%D][small || dig < pos[k]-'0'], dp[sum][small]);
                }
            }
        }
        dp = dp1;
    }
    
    int ans = dp[0][true] + dp[0][false];
    int res = (ans%mod)-1;
    
    //res =0 ? cout<<res : cout<<0;
  res == -1 ? cout<<mod-1 : cout<<res;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c,n,i;
	scanf("%d %d %d",&n,&a,&b);
	if(n==2){
		for (i=1; i < a ;i++) {
			if(a%i+b%i==0){
				printf("%d\n",i);
			}
		}
	}else if(n==3){
		scanf("%d",&c);
		for (i=1; i < a ;i++) {
			if(a%i+b%i+c%i==0){
				printf("%d\n",i);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"

#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

int N, K;
int cost(int cl, int cr, vector<ll> V)
{
   int k = cl + cr;
   vector<ll> A(k);
   int n = 0;
   for (int i = 0; i < cl; i++)
   {
      A[n] = V[i];
      n++;
   }
   for (int i = 0; i < cr; i++)
   {
      A[n] = V[N - i - 1];
      n++;
   }
   sort(A.begin(), A.end());
   int64_t sum = 0;

   n = 0;
   while (A[n] < 0 && n < min(K - k, k))
      n++;
   while (n < k)
   {
      sum += A[n];
      n++;
   }
   return sum;
}

void Main()
{
   cin >> N >> K;
   vector<ll> V(N);
   FORV(v, V)
   cin >> v;
   int cl, cr;
   int64_t mm = 0;
   int64_t sum;
   for (int k = 1; k <= min(K, N); k++)
   {
      for (int cl = 0; cl <= k; cl++)
      {
         sum = cost(cl, k - cl, V);
         mm = max(mm, sum);
      }
   }
   cout << mm << endl;
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))

s = 0

for i in range(n):
  #print(s)
  s_ = (i+1) - l[i]
  if s_ == (i-s):
    s += 1

if s != 0:
  print(n-s)
else:
  print(-1)

Measured memory_bytes: 24744
using System;
using System.Collections.Generic;

namespace ALDS1_3_A {
    class Program {
        static void Main(string[] args) {
            string[] input = Console.ReadLine().Split(' ');
            Stack<int> stk = new Stack<int>();
            foreach (var s in input) {
                int num;
                if (int.TryParse(s, out num)) {
                    stk.Push(num);
                    continue;
                }

                int a = stk.Pop();
                int b = stk.Pop();
                switch (s) {
                    case "+":
                        stk.Push(b + a);
                        break;
                    case "-":
                        stk.Push(b - a);
                        break;
                    case "*":
                        stk.Push(b * a);
                        break;
                }
            }
            Console.WriteLine(stk.Peek());
        }
    }
}

Measured memory_bytes: 10080
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

typedef vector<long long int> vec;
typedef vector<vec> mat;

// A*B の計算
mat mul(mat &A, mat &B){
	mat C(A.size(), vec(B[0].size()));
	for(int i = 0; i < A.size(); i++){
		for(int k = 0; k < B.size(); k++){
			for(int j = 0; j < B[0].size(); j++){
				C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
			}
		}
	}
	return C;
}

// A^n の計算
mat pow(mat A, long long int n){
	mat B(A.size(), vec(A.size()));
	for(int i = 0; i < A.size(); i++){
		B[i][i] = 1;
	}
	while(n > 0){
		if(n & 1){
			B = mul(B, A);
		}
		A = mul(A, A);
		n /= 2;
	}
	return B;
}

int main(){
	
	long long int N, K;
	cin >> N >> K;
	
	mat A(N, vec(N));
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			cin >> A[i][j];
		}
	}
	
	mat ret = pow(A, K);
	
	long long int ans = 0;
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			ans += ret[i][j];
		}
	}
	
	cout << ans % MOD << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
#define se second
#define fi first
#define mod 1000000007
 
typedef pair<int,int> pii;
 
int N,M;
vector<pii> V[500];
int dp[310][310][310];
 
int P(int a,int b,int c)
{
    if(dp[a][b][c] != -1)return dp[a][b][c];
    long long res = 0;
    int A,B,C;
    A = max(a,max(b,c));
    C = min(a,min(b,c));
    B = a + b + c - A - C;
    //printf(" %d %d %d\n",a,b,c);
    for(int i = 0; i < V[A].size(); i++)
    {
        pii now = V[A][i];
        int cou = 1;
        if(B >= now.fi)cou++;
        if(C >= now.fi)cou++;
        if(cou != now.se)return dp[a][b][c] = 0;
    }
    if(A == N)return 1;
    res = P(A + 1,b,c);
    res += P(a,A + 1,c);
    res %= mod;
    res += P(a,b,A + 1);
    res %= mod;
    return dp[a][b][c] = res;
}
 
int main()
{
    scanf("%d%d",&N,&M);
    for(int i = 0; i <= N; i++)
    {
        for(int j = 0; j <= N; j++)
        {
            for(int k = 0; k <= N; k++)
            {
                dp[i][j][k] = -1;
            }
        }
    }
    for(int i = 0; i < M; i++)
    {
        int l,r,k;
        scanf("%d%d%d",&l,&r,&k);
        V[r].push_back(make_pair(l,k));
    }
    printf("%d\n",P(0,0,0));
    /*for(int i = 0; i <= N; i++)
    {
        for(int j = 0; j <= N; j++)
        {
            for(int k = 0; k <= N; k++)
            {
                printf(" %d %d %d   %d\n",i,j,k,P(i,j,k));
            }
        }
    }*/
    return 0;
}

Measured memory_bytes: 114944
#include "bits/stdc++.h"
using namespace std;

template <class T1> void write(T1 e)
{
    cout << e << endl;
}
template <class T1,class T2> void write(T1 e1,T2 e2)
{
    cout << e1 << " "<< e2 << endl;
}
template <class T1,class T2,class T3> void write(T1 e1,T2 e2,T3 e3)
{
    cout << e1 << " " << e2 << " " << e3 << endl;
}

#define oo          (1<<30)
#define SZ(a)       (int)a.size()
#define LL          long long int
#define ULL         unsigned long long
#define ISS         istringstream
#define OSS         ostringstream
#define VS          vector <string>
#define VI          vector <int>
#define VD          vector <double>
#define VLL         vector <long long>
#define SII         set<int>::iterator
#define SI          set<int>
#define mem(a,b)    memset(a,b,sizeof(a))
#define fs          first
#define sc          second
#define pii         pair < int , int >

#define EQ(a,b)     (fabs(a-b)<ERR)
#define all(a,b,c)  for(int I=0;I<b;I++)    a[I] = c
#define CROSS(a,b,c,d) ((b.x-a.x)*(d.y-c.y)-(d.x-c.x)*(b.y-a.y))
#define sqr(a)      ((a)*(a))
#define FORE(i,a)   for(typeof((a).begin())i=(a).begin();i!=(a).end();i++)
#define BE(a)       a.begin(),a.end()
#define RBE(a)      a.rbegin(),a.rend()
#define rev(a)      reverse(BE(a));
#define sorta(a)    sort(BE(a))
#define pb          push_back
#define popb        pop_back
#define Round(i,a)  i = ( a < 0 ) ? a - 0.5 : a + 0.5;

#define makeint(n,s)  istringstream(s)>>n
#define string_to_int(str) atoll(str.c_str());

#define LCM(A,B)    ((__gcd(A,B))/A)*B
#define GCD(A,B)     __gcd(A,B)

#define YES     write("YES")
#define Yes     write("Yes")
#define yes     write("yes")
#define NO      write("NO")
#define No      write("No")
#define no      write("no")

#define read()      freopen("test.txt","r",stdin)
#define write_file()     freopen("WA.txt", "w", stdout);
#define Faster      {ios_base::sync_with_stdio(false); cin.tie(0);}

#define PI          3.141592653589793
#define pi          2*acos(0)
#define gama        0.57721566490
#define ERR         1e-5
#define PRE         1e-8
#define MAX         1000009

#define Scan(A)         scanf("%lld", &A)
#define Scan2(A, B) 	scanf("%lld %lld",&A, &B)
#define Scan3(A, B, C) 	scanf("%lld %lld %lld",&A, &B, &C)
#define Scan4(A, B, C, D) 	scanf("%lld %lld %lld %lld",&A, &B, &C, &D)

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

bool isvowel(char ch)
{
    ch = tolower(ch);
    return ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u';
}

struct myStruct
{
    LL Sum;
    string name;
    string Party;
};

bool cmp(myStruct a, myStruct b)
{
    return a.Sum > b.Sum ? 0 : 1;
}

map <char, int> Mp;

void Method()
{
    int j = 0;
    for(char i = 'a'; i <= 'z'; i++)
    {
        char temp = (char) i;
        Mp[temp] = j;
        j++;
    }
}

int main()
{
    string A, B;
    while(cin >> A >> B)
    {
        string temp = A+B;
        LL N = string_to_int(temp);
        LL ans = (LL)sqrt(N);
        if(ans * ans == N)
            Yes;
        else
            No;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k;
  cin >> k;
  int sum = 0;
  for(int a = 1; a < k+1; a++){
    for(int b = 1; b < k+1; b++){
      for(int c = 1; c < k+1; c++){
        sum += gcd(a, gcd(b, c));
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3624
def examC():
    N = I()
    A = LI()
    negative = []; positive = []
    ans = 0; ansC = []
    for i in A:
        if i<0:
            negative.append(i)
        else:
            positive.append(i)
    if negative==[]:
        positive.sort()
        if N>2:
            cur = positive[0] - positive[1]
            ansC.append([positive[0], positive[1]])
            ans = sum(positive) - 2 * positive[0]
            for i in range(2, N - 1):
                ansC.append([cur, positive[i]])
                cur -= positive[i]
            ansC.append([positive[N - 1], cur])
        else:
            ansC.append([positive[1],positive[0]])
            ans = positive[1]-positive[0]

    elif positive==[]:
        negative.sort(reverse=True)
        cur = negative[0] - negative[1]
        ansC.append([negative[0],negative[1]])
        ans = -sum(negative)+2*negative[0]
        for i in range(2,N):
            ansC.append([cur,negative[i]])
            cur -=negative[i]
    else:
        positive.sort()
        negative.sort(reverse=True)
        ans = sum(positive) - sum(negative)
        curN = negative[0]
        curP = positive[0]
        for i in range(len(positive)-1):
            ansC.append([curN,positive[i+1]])
            curN -=positive[i+1]
        for i in range(len(negative)-1):
            ansC.append([curP,negative[i+1]])
            curP -=negative[i+1]
        ansC.append([curP,curN])

    print(ans)
    for v in ansC:
        print(" ".join(map(str,v)))

from string import digits
import sys,copy,bisect,itertools,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


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

int main(){
	int x, y;
	cin >> x >> y;
	
	if(x < y) cout << "a < b" << endl;
	else if(x > y) cout << "a > b" << endl;
	else if(x == y) cout << "a == b" << endl;
	return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &e: a) cin >> e;
    for (auto &e: a) e--;
    
    vector<int> cus(n+1);
    cus[0] = 0;
    for (int i = 0; i < n; i++) {
        cus[i+1] = (cus[i] + a[i]) % k;
    }
    
    ll ans = 0;
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        m[cus[i]]++;
        if (i >= k-1) m[cus[i-(k-1)]]--;
        ans += m[cus[i+1]];
    }
    cout << ans << endl;
    
    return 0;
}


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

int main() {
  int N,F[100][10],P[100][11];
  cin >>N;
  for (int j(0);j<N;j++){
    for (int i(0);i<10;i++){
       cin>>F[j][i];
    }
  }
  for (int j(0);j<N;j++){
    for (int i(0);i<11;i++){
       cin>>P[j][i];
    }
  }
  ll ans(-1000000000000);
  for (int bit = 1; bit < (1<<10); ++bit){
    ll benefit(0);
    ll kosuu[100]={0};
    for (int i = 0; i < 10; ++i) {
      if (bit & (1<<i)) { // i が bit に入るかどうか
        for (int n(0);n<N;n++){
          if (F[n][i]==1) kosuu[n]+=1;
        }
      }
    }
    for (int n(0);n<N;n++){
     // cout << kosuu[n]<<" "<<P[n][kosuu[n]]<<" ";
      benefit+=P[n][kosuu[n]];
    }
    // cout << endl;
    // cout << benefit << " ";
    ans=max(benefit,ans);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int floor(long A, long B){
    return A/B;
}

int main(){
    long A,B,N,max=0,i;
    cin >> A >> B >>N;
    if(N>B-1){
        i=B-1;
    }else{
        i=N;
    }
    max=floor(A*i,B)-A*floor(i,B);
    cout << max;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    vector<int> m = {a, b, c};
    for (int i = 0; i < k;i++){
        int &MAX = *max_element(m.begin(), m.end());
        MAX *= 2;
    }
    int sum=0;
    rep(i,3){
        sum += m[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main() {
    int a,b,C;
    double S,L,h,rad;
    double PI = acos(-1);
    scanf("%d%d%d",&a,&b,&C);
    rad=C*PI/180.0;
    S=a*b*sin(rad)/2.0;
    L=sqrt(a*a+b*b-2*a*b*cos(rad))+a+b;
    h=2*S/a;
    
    printf("%lf\n%lf\n%lf\n",S,L,h);
    return 0;
}





Measured memory_bytes: 3504
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define triplerep(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;

int H, W, canvas[59][59];
int dh[] = { -1, 0, 1, 0};
int dw[] = { 0, 1, 0, -1};

int main() {
    cin >> H >> W;
    mem( canvas, 0);
    
    char c;
    for ( int i = 1; i <= H; i++ ) {
        for ( int j = 1; j <= H; j++ ) {
            cin >> c;
            if (c == '#') canvas[i][j] = 1;
            else canvas[i][j] = 0;
        }
    }
    
    for ( int i = 1; i <= H; i++ ) {
        for ( int j = 1; j <= H; j++ ) {
            if (canvas[i][j] == 1) {
                bool f = false;
                rep(a,4) {
                    if ( canvas[i+dh[a]][j+dw[a]] == 1 ) {f=true; break;}
                }
                if ( !f ) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}


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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

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

    int n;
    cin >> n;
    vector<vi> a(n, vi(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }

    vector<ll> dp(1 << n, 0);
    for (int mask = 1; mask < (1 << n); ++mask) {
        for (int i = 0; i < n; ++i) {
            if ((mask & (1 << i)) == 0) continue;
            for (int j = i + 1; j < n; ++j) {
                if ((mask & (1 << j)) == 0) continue;

                dp[mask] += a[i][j];
            }
        }
    }

    for (int mask = 1; mask < 1 << n; ++mask) {
        for (int ss = mask; ss > 0; ss = (ss - 1) & mask) {
            dp[mask] = max(dp[mask], dp[ss] + dp[mask ^ ss]);
        }
    }

    cout << dp[(1 << n) - 1] << '\n';
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<i64> a(n);
    for (auto &e : a) std::cin >> e;

    i64 s = std::accumulate(a.begin(), a.end(), 0ll), t = 0;
    i64 ret = std::numeric_limits<i64>::max();
    for (int i = 0; i + 1 < n; i++) {
        t += a[i];
        ret = std::min(ret, std::abs(t - (s - t)));
    }

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

    return 0;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
from itertools import accumulate

def main():
    N,K = map(int,input().split())
    p = [int(i) for i in input().split()]

    for i in range(N):
        p[i] = (p[i] + 1) / 2

    p = [0] + list(accumulate(p))

    ans = 0
    for i in range(N-K+2):
        ans = max(ans, p[i+(K-1)] - p[i-1])

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 86348
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a,b;
	cin >> a >> b;
	int ans = 0;
	if(1 <= a && a <= 9) ans++;
	if(1 <= b && b <= 9) ans++;
	if(ans == 2) cout << a*b << endl;
	else cout << "-1" << endl;
}

Measured memory_bytes: 256