akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int N=6010, M=3010;

ll n, m, k, u, v, x, y, t, a, b, ans, mod;
ll I[N];
ll dp[N][N+M];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>mod;
	I[1]=1;
	for (int i=2; i<N; i++) I[i]=-(mod/i)*I[mod%i]%mod;
	dp[0][M]=1;
	for (int i=1; i<=3*n; i++) for (int j=1; j+1<N+M; j++){
		if (i>=1) dp[i][j]+=dp[i-1][j-1];
		if (i>=2) dp[i][j]+=dp[i-2][j+1];
		if (i>=3) dp[i][j]+=dp[i-3][j];
		dp[i][j]%=mod;
		dp[i][j]=dp[i][j]*I[i]%mod;
	}
	for (int j=M; j<N+M; j++) ans+=dp[3*n][j];
	ans%=mod;
	for (int i=1; i<=3*n; i++) ans=ans*i%mod;
	if (ans<0) ans+=mod;
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 423168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int sa = b - a;
		if(sa % 2 == 0) {
			System.out.println("Alice");
		} else {
			System.out.println("Borys");
		}
	}
}


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

int main() {
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    vector<ll> capacities = {A, B, C, D, E};

    ll min_idx = -1;
    ll min_cap = (ll)1e15 + 1;
    for (int i = 0; i < capacities.size(); i++) {
        ll capacity = capacities.at(i);
        if (capacity < min_cap) {
            min_cap = capacity;
            min_idx = i;
        }
    }
    ll num_transportations = N / min_cap + (ll)(N % min_cap != 0);
    // cout << num_transportations << '\n';
    ll time = num_transportations + 4;
    cout << time << '\n';
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES  // M_PI等のフラグ

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <list>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;


void solve(){
    int S, W;
    cin >> S >> W;
    if (S<=W) {
        cout << "unsafe\n";
    }
    else {
        cout << "safe\n";
    }
}

int main(int argc, char const *argv[]){
    solve();
    return 0;
}

Measured memory_bytes: 3584
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


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


def main():
    X = int(input())
    M = 120
    A = [i**5 for i in range(M)]

    for i in range(M):
        for j in range(i, M):
            if A[j] - A[i] == X:
                print(j, i)
                break
            elif A[j] + A[i] == X:
                print(j, -i)
                break

    return


if __name__ == '__main__':
    main()


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

const int N = 1010, M = 64;

int Q[N * (N + 1) / 2], tmp[M];

int32_t main() {
        vector <int> v;

        int n, k; cin >> n >> k;

        for(int i = 1; i <= n; i++) {
                cin >> Q[i]; Q[i] += Q[i - 1];
                for(int j = 1; j <= i; j++) {
                        v.push_back(Q[i] - Q[j - 1]);
                }
        }

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



        int MAX = 0;

        for(int i = 50; i >= 0; i--) {
                int cnt = 0;
                for(int x: v) {
                       // cout <<x << " ";
                        cnt += ((x & (1LL << i)) > 0);
                }
               // cout << endl;
                //getchar();
                vector <int> tmp;

                if(cnt >= k) {
                       for(int x: v) {
                            if((x & (1LL << i)) > 0) tmp.push_back(x);
                       }
                       v.clear();
                       for(int x: tmp) v.push_back(x);
                       MAX += (1LL << i);
                }
        }

        cout << MAX << endl;


}


Measured memory_bytes: 6384
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    Vvec<ll> a(N, vector<ll>(N));
    for(auto& v: a){
        for(auto& x: v) cin >> x;
    }

    vector<ll> dp(1<<N);
    for(int i=0; i<(1<<N); i++){
        for(int j=0; j<N; j++){
            for(int k=j+1; k<N; k++){
                if((i>>j)&(i>>k)&1) dp[i] += a[j][k];
            }
        }
    }

    for(int i=0; i<(1<<N); i++){
        for(int j=i; j>0; j=(j-1)&i){
            dp[i] = max(dp[i], dp[j] + dp[i^j]);
        }
    }

    cout << dp[(1<<N)-1] << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

bool isPostNumber(int a,int b,string s){
    if (s.length() != a + b + 1) return false;
    for (int i=0;i<s.length();i++){
        if (i == a && s[i] != '-')
            return false;
        else if (i != a && ('0' > s[i] || '9' < s[i]))
            return false;
    }
    return true;
}
int main() {
    int a,b;
    string s;
    cin >> a >> b >> s;

    cout << (isPostNumber(a,b,s) ? "Yes" : "No" ) << endl;
  return 0;
}

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

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int H = ni();
        int W = ni();
        int[][] dp = new int[H][W + 1];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                int x = ni();
                dp[i][j] = x ^ 1;
            }
        }

        for (int i = 1; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (dp[i][j] == 1) {
                    dp[i][j] = dp[i - 1][j] + 1;
                }
            }
        }

        int ans = 0;

        for (int i = 0; i < H; i++) {
            ArrayDeque<Pair> stack = new ArrayDeque<>();
            for (int j = 0; j <= W; j++) {
                int h = dp[i][j];
                if (stack.isEmpty() || stack.peek().x < h) {
                    stack.push(new Pair(h, j));
                } else if (stack.peek().x > h) {
                    int b = 0;
                    while (!stack.isEmpty() && stack.peek().x >= h) {
                        Pair p = stack.poll();
                        ans = Math.max(ans, p.x * (j - p.y));
                        b = p.y;
                    }
                    stack.push(new Pair(h, b));
                }
            }
        }

        out.println(ans);
    }

    public class Pair implements Comparable<Pair> {
        int x, y;

        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public int compareTo(Pair p) {
            return x == p.x ? y - p.y : x - p.x;
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 92468
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/










int N, A[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    rep(i, 0, 4) cin >> A[i];
    sort(A, A + 4);
    if (A[0] == 1 and A[1] == 4 and A[2] == 7 and A[3] == 9) printf("YES\n");
    else printf("NO\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main(){
  int even, odd;
  cin >> even >> odd;

  int sum;
  sum = even * (even - 1) + odd * (odd - 1);

  cout << sum / 2 << endl;

  return 0;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI p(n), df(n);
	rep(i, n) cin >>p[i];
	
	rep(i, n) if(i+1 == p[i]) df[i] = 1;
	//for(auto x :df) cerr<<x<<" "; dbg("");
	int ans = 0;
	rep(i, n){
		if(i+1<n && df[i] == df[i+1] && df[i]==1){
			ans++; df[i] = df[i+1] = 0;
		}else if(df[i] == 1){ ans++; df[i]=0;}
	}
	cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
s = [input() for _ in range(N)]

cnt = {}
for i, si in enumerate(s):
    cnt_tmp = {}
    for j, sij in enumerate(si):
        key = str(sij)
        cnt_tmp.setdefault(key, 0)
        cnt_tmp[sij] += 1
    #
    key_si = ''
    for key, val in sorted(cnt_tmp.items()):
        key_si += '{0}_{1}/'.format(key, val)
    #
    cnt.setdefault(key_si, 0)
    cnt[key_si] += 1

ans = 0
for key, val in cnt.items():
    ans += val * (val - 1) // 2

print(ans)

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

typedef long long ll;

using namespace std;

set<ll> s;
ll maxnr = 400000000;

void bst(ll x) {
	
	if (s.find(x) != s.end()) return;
	s.insert(x);
	if (x >= maxnr) return;
	if( x == 0 ) {
		for(int i = 1; i <= 9; i++) {
			bst(i);
		}
	} else {
		int lst = x % 10;
		if (lst > 0 ) bst(x*10 + lst-1);
		bst(x*10 + lst);
		if (lst < 9) bst(x*10 + lst + 1);
	}
	
}

int main() {
	int k; cin >> k;
	bst(0);
	set<ll>::iterator i = s.begin();
	advance(i, k);
	cout << *i;
}





Measured memory_bytes: 5504
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
#define ll long long

int d = 365;
//int k = 0;
vector<vector<int>> s(d, vector<int>(26, 0));
vector<ll> c(26);

void init() {
    cin >> d;
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    return;
}

ll calc(vector<int> out) {
    ll score = 0;
    vector<ll> last(26, 0);
    for(int i = 0; i < out.size(); i++) {
        last[out[i]] = i+1; // タイプ番号
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i+1)-last[j]);
        }
        score += s[i][out[i]];
        //cout << "score : " << score << endl;
    }

    //int p = min(int(out.size()+k), int(d));
    //cout << p << endl;
    //if(out.size() >= d) return score;
    //cout << k << endl;
    //cout << out.size() << " " << d << endl;
    //int p = min(int(out.size()+k), d);
    int k = 13;
    //int p = min(int(out.size()+k), d);
    int p = out.size()+k;
    for(int i = out.size(); i < p; i++) {
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i+1)-last[j]);
        }
    }
        
    return score;
}

/*
vector<int> proc(int k) {
    vector<int> out;
    ll ans = 0;
    //ll tmp = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
    //cout << "k: " << k << endl;
    //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    return out;
}
*/

int main() {
    init();
    
    vector<int> out;
    ll ans = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
        //cout << "k: " << k << endl;
        //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            //for(int k = 0; k < 26; k++) {
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            //}
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    
    for(int i = 0; i < d; i++) {
        cout << out[i]+1 << endl;
    }
    //cout << max_v << endl;
    return 0;
}

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


int main(){
  int N, H;
  cin >> N >> H;
  vector<int> a(N), b(N);
  for(int i=0; i<N; i++){
    cin >> a[i] >> b[i];
  }

  int max_a = *max_element(a.begin(), a.end());
  sort(b.begin(),b.end());

  int count = 0;
  int dec = 1;
  while(H>0){
    if(dec <= N){
      if(b[N-dec] > max_a){
        H -= b[N-dec];
        count++;
        dec++;
      }
      else{
        count += ceil(H*1.0/max_a);
        H = 0;
      }
    }
    else{
      count += ceil(H*1.0/max_a);
      H = 0;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#define Max 100

int main(){
  int A[Max];
  int i,j,n,x;
  int temp,min,time=0;

  scanf("%d",&n);
  for(i=0 ; i<n ; i++) scanf("%d",&A[i]);

  for(i=0 ; i<n ; i++){
    min = A[i];
    for(j=i ; j<n ; j++){
      if(A[j] < min){
        min = A[j];
        x = j;
      }
    }
    if(A[i] != min){
    temp = A[i];
    A[i] = min;
    A[x] = temp;
    time++;
    }
  }

  for(i=0 ; i<n-1 ; i++) printf("%d ",A[i]);
  printf("%d\n",A[n-1]);
  printf("%d\n",time);

  return 0;
}

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

using namespace std;

int n;
int arr[200005];

int main()
{
	cin >> n;
	long long a=0,b=0;
	for(int i=0;i<n;i++)
	{
		cin >> arr[i];
		a+=arr[i];
	}
	long long ans=a;
	for(int i=0;i<n;i++)
	{
		a-=arr[i]; b+=arr[i];
		ans=min(ans,llabs(a-b));
	}
	cout << ans << endl;
}

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

int main() {

	ll x; cin >> x;
	ll ans = 0;
	ll quo = x / 11;
	ll mod = x % 11;
	if (mod == 0) {
		ans = quo * 2;
	}
	else if (1 <= mod && mod <= 6) {
		ans = quo * 2 + 1;
	}
	else { // 6 < mod <= 11
		ans = quo * 2 + 2;
	}

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

Measured memory_bytes: 384
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx-sx;
    int dy = ty-sy;
    
    string ret;
    rep(i, dy) {
        ret += "U";
    }
    rep(i, dx) {
        ret += "R";
    }
    rep(i, dy) {
        ret += "D";
    }
    rep(i, dx+1) {
        ret += "L";
    }
    rep(i, dy+1) {
        ret += "U";
    }
    rep(i, dx+1) {
        ret += "R";
    }
    ret+= "D";
    ret+= "R";
    rep(i, dy+1) {
        ret += "D";
    }
    rep(i, dx+1) {
        ret += "L";
    }
    ret += "U";

    cout << ret << endl;


    return 0;
}



Measured memory_bytes: 3100
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
static inline void fast_io()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
using namespace std;
using ll = long long;
using ld = long double;

int main()
{
    fast_io();

    int l, r, d;
    cin >> l >> r >> d;
    int cnt = 0;
    for (int i = d; i <= r; i += d) {
        if (i >= l) {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
//rep(i, v.size()) v[i]=i;
//#define int long long
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>

using namespace std;

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

  int ans = 0;
  rep(i, N){
    if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())
N, K = map(int, input().split())
H = list(map(int, input().split()))

H.sort()

sum = 0
for i in range(N-K) :
  sum += H[i]
print (sum)



Measured memory_bytes: 26812
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int[] h = new int[n + 1];

		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(sc.next());
		}

		int max = 0;
		int now = 0;
		for (int i = 1; i < n; i++) {

			if (h[i] <= h[i - 1]) {
				now++;
				max = Math.max(max, now);
			} else {
				max = Math.max(max, now);
				now = 0;
			}
			//			System.out.println(i + " " + max + " " + now);
		}

		System.out.println(max);

		sc.close();
	}
}

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

int main(void) {
  string s; long long k;
  cin >> s >> k;
  int n = s.length();

  if (n == 1) {
    cout << k/2 << "\n";
    return 0;
  }


  if (s == string(n, s[0])) {
    cout << (s.length() * k) / 2 << "\n";
    return 0;
  }

  long long d = 0;
  for (long long i = 1; i < s.length(); i++) {
    int p = 1;
    while (s[i] == s[i-1]) {
      p++;
      i++;
      if (i == s.length()) break;
    }
    d += p/2;
  }

  long long change = d * k;


  if (s[0] == s[n-1]) {
    int i = n-1;
    int p = 1;

    while (i >= 1 && s[i] == s[i-1]) {
      p++;
      i--;
    }

    int j = 1;
    while (j < i && s[j] == s[j-1]) {
      p++;
      j++;
    }

    if (p % 2 == 1) change += k-1;
  }
  cout << change << "\n";
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)

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

  return 0;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
#define int ll
#define el '\n'
template<class T> bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll; typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

string s; cin>>s;
int n=sz(s),m=13;
vv<vv<ll>> dp(n+1,vv<ll>(m,0));
dp[0][0]=1;
D(n);
for(int i=0;i<n;++i){
	if(s[i]!='?'){
		for(int d=0;d<m;++d){
			ll& t=dp[i+1][(10*d+s[i]-'0')%m];
			t=(t+dp[i][d])%MOD;
		}
	} else {
		for(int b=0;b<m;++b){
			for(int l=0;l<=9;++l){
				ll& t=dp[i+1][(10*b+l)%13];
				t=(t+dp[i][b])%MOD;
			}
		}
	}
}
cout<<dp[n][5]<<el;

return 0;
}


Measured memory_bytes: 13648
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String[] w = new String[n];
        Arrays.setAll(w, i -> sc.next());

        // 主処理
        boolean judge = true;
        Set<String> set = new HashSet<>(Arrays.asList(w));

        if (w.length == set.size()) {
            char lastChar = w[0].charAt(w[0].length() - 1);
            for (int i = 1; i < w.length; i++) {
                char c = w[i].charAt(0);
                if (lastChar != c) {
                    judge = false;
                    break;
                }
                lastChar = w[i].charAt(w[i].length() - 1);
            }

        } else {
            judge = false;
        }

        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 26448
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int D[105][55],i,j,t,x,dp[105][55];
char d[305],*p;
int max(int a,int b){return a>b?a:b;}
int main()
{
	memset(D,-1,sizeof(D));
	memset(dp,-1,sizeof(dp));
	for(t=0;gets(d);t++)
	{
		d[strlen(d)]=',';
		j=0;
		p=strtok(d,",");
		do{D[t][j++]=atoi(p);}while(p=strtok(NULL,","));
		memset(d,0,sizeof(d));
	}
	dp[0][0]=D[0][0];
	for(i=0;i<t;i++)
		for(j=0;D[i][j]!=-1;j++)
		{
			if(D[i+1][j]!=-1)dp[i+1][j]=max(dp[i+1][j],dp[i][j]+D[i+1][j]);
			if(i<(t/2)&&D[i+1][j+1]!=-1)dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+D[i+1][j+1]);
			if(i>=(t/2)&&j>0)dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]+D[i+1][j-1]);
		}
	printf("%d\n",dp[t-1][0]);
	return 0;
}

Measured memory_bytes: 576
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    const int n = 9;
    const int time = 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2;
    int t;
    int a[n], b[n];

    cin >> t;
    while (t--) {
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            sum += a[i];
        }
        for (int i = 0; i < n; ++i) {
            cin >> b[i];
            sum += b[i];
        }

        sum = (sum + 1) / 2;
        sort(b, b + n);
        int win = 0;
        do {
            int a_s = 0;
            for (int i = 0; i < n; ++i) {
                if (a[i] > b[i])
                    a_s += a[i] + b[i];
                if (a_s >= sum)
                    break;
            }
            if (a_s >= sum)
                ++win;
        } while (next_permutation(b, b + n));

        printf("%.5lf %.5lf\n", (double)win / time, (double)(time - win) / time);
    }

    return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(12);
    
    double l;cin>>l;
    cout<<(l/3.0)*(l/3.0)*(l/3.0)<<endl;
    return 0;
}


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

using namespace std; 

const int MAXN = 100000+100, MAXM = 200000+100; 

struct edges{
    int num, to, next; 
}edge[MAXM]; 

int cnt, vis[MAXN], dis[MAXN], head[MAXM], st = 1; 

void addedge(int u, int v, int w){
    edge[++cnt].to = v; 
    edge[cnt].num = w; 
    edge[cnt].next = head[u]; 
    head[u] = cnt; 
}

struct node{
    int dis, num; 
    bool operator <(const node& jbc)const{
        return jbc.dis < dis; 
    }
}; 

void dijkstra(){
    dis[st] = 0; 
    priority_queue<node>heap; 
    heap.push((node){0, st}); 
    while(!heap.empty()){
        node now = heap.top(); 
        heap.pop(); 
        int x = now.num, d = now.dis; 
        if(vis[x])
            continue; 
        vis[x] = 1; 
        if(dis[x] != d)
            continue; 
        for(int i = head[x]; i; i = edge[i].next){
            int y = edge[i].to; 
            if(dis[y] > dis[x] + edge[i].num){
                dis[y] = dis[x] + edge[i].num; 
                if(!vis[y]){
                    heap.push((node){dis[y], y}); 
                }
            }
        }
    }
}

int k; 

int main(){
    cin >> k;
    for(int i = 0; i <= k; ++i)
    	dis[i] = 0x7fffffff;
    for(int i = 0; i < k; ++i) {
		addedge(i, (i + 1) % k, 1);
		addedge(i, (i * 10) % k, 0);
    }
    dijkstra();
    cout << dis[0] + 1 << endl;
    return 0; 
}


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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int dp[100];
signed main(void)
{
  string s;
  cin >> s;

  REP(i, 1LL<<3) {
    int now = s[0]-'0';
    REP(j, 3) {
      if(i&1<<j) {
        now += s[j+1]-'0';
      } else {
        now -= s[j+1]-'0';
      }
    }
    if(now == 7) {
      cout << s[0];
      REP(j, 3) {
        if(i&1<<j) cout << "+";
        else cout << "-";
        cout << s[j+1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }

  return 0;
}


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

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;

  bool ans = true;

  for (int i = 0; i < A; i++) {
    if ((S[i] - '0') < 0 || (S[i] - '0') > 9) {
      ans = false;
      break;
    }
  }

  if (S[A] != '-') ans = false;

  for (int i = A + 1; i < S.size(); i++) {
    if ((S[i] - '0') < 0 || (S[i] - '0') > 9) {
      ans = false;
    }
  }

  cout << (ans ? "Yes" : "No") << endl;
}

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

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

  ll times10=1;
  rep(i,n){
    times10 = 10*times10;
    times10 = times10 % mod;
  }
  ll times9=1;
  rep(i,n){
    times9 = 9*times9;
    times9 = times9 % mod;
  }
  ll times8=1;
  rep(i,n){
    times8 = 8*times8;
    times8 = times8 % mod;
  }

  ll ans;
  ans = times10 - times9*2 + times8;
  ans%=mod;
  if(ans < 0) ans = mod + ans;
  ans = ans % mod;
  cout << ans << endl;
}


Measured memory_bytes: 3620
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i32 = read();
    let s: String = read();
    let vec: Vec<char> = s.chars().collect();
    let mut wcount_vec: Vec<i32> = Vec::new();
    let mut ecount_vec: Vec<i32> = Vec::new();

    for (i, &c) in vec.iter().enumerate() {
        if i == 0 {
            if c == 'W' {
                wcount_vec.push(1);
                ecount_vec.push(0);
            } else {
                wcount_vec.push(0);
                ecount_vec.push(1);
            }
        } else {
            if c == 'W' {
                let w = wcount_vec[i-1].clone()+1;
                let e = ecount_vec[i-1].clone();
                wcount_vec.push(w);
                ecount_vec.push(e);
            } else {
                let w = wcount_vec[i-1].clone();
                let e = ecount_vec[i-1].clone()+1;
                wcount_vec.push(w);
                ecount_vec.push(e);
            }
        }
    }
    let mut min = n;
    for i in 0..n {
        let mut each_min= n;
        if i == 0 {
            each_min = ecount_vec[(n-1) as usize] - ecount_vec[0];
        } else {
            each_min = wcount_vec[(i-1) as usize] + (ecount_vec[(n-1) as usize] - ecount_vec[i as usize]);
        }
        min = cmp::min(min, each_min);
    }

    println!("{}", min);
}

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 gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 13296
n = int(input())
b = list(map(int, input().split()))
a = [0] * n
a[0] = b[0]

if n==2:
    print(b[0]*2)
    exit()

for i in range(1, n-1):
    a[i] = min(b[i], b[i-1])
    a[i+1] = b[i]

print(sum(a))

Measured memory_bytes: 3064
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


N, K = map(int, input().split())

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


temp = 0
A =[int(x) for x in input().split()]
sums =[]
for x in sorted(A):
    temp += int(x)
    sums.append(temp)

ans = 0
for l in range(K-2, N-1):
    c = cmb(l, K-2, mod)
    ans += (((sums[N-1]-sums[l] - sums[N-l-2] ) % mod) * c) %mod
print(ans % mod)

Measured memory_bytes: 26644
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<set>

using namespace std;
#define LL long long

int main() {
	while (true) {
		LL n, j[65002];
		LL psum = 0, ans;

		cin >> n;
		if (!n) break;

		for (int i = 0; i < n; i++) {
			int p;  cin >> p;  psum += p;
		}
		ans = psum * n;
		for (int i = 0; i < n - 1; i++) cin >> j[i];
		sort(j, j + n - 1);
		reverse(j, j + n - 1);

		for (int i = 0; i < n - 1; i++) {
			psum += j[i];
			ans = max(ans, psum*(n - i - 1));
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3664
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, X, M = MI()
    def f(x): return x % M
    # N += 2

    ans = 0
    r = [0] * (M+1)
    p = 1
    q = 0
    pre = X
    # S = [0] * (N+1)
    # S[0] = X
    S = [X]
    for i in range(1, N):
        tmp = f(pre ** 2) % M
        # print(tmp)
        if r[tmp]:
            # print('aa', i, r[tmp])
            left = N - r[tmp]
            loop = i - r[tmp]
            # print(left, loop)
            p, q = left // loop, left % loop
            # print(p, q, S[i-1] - S[r[tmp]-1], i-1, r[tmp]-1)
            # print(S)
            ans = S[r[tmp]-1]
            ans += p * (S[i-1] - S[r[tmp]-1])
            if q > 0:
                ans += (S[r[tmp]+q-1] - S[r[tmp]-1])
            print(ans)
            # ans += S[]
            return 
        pre = tmp
        r[tmp] = i
        # S[i] = tmp + S[i-1]
        S.append(tmp + S[i-1])
    else:
        # print(S)
        print(S[N-1])



if __name__ == '__main__':
    solve()



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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

constexpr int MOD = 998244353;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};
mint operator "" _m(unsigned long long n) { return n; }

void chmin(int &x, int y) {
  x = min(x, y);
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N; cin >> N;
  string S; cin >> S;
  int r = 0, g = 0, b = 0;
  mint ans = 1;
  int cnt = 0;
  rep(i, S.size()) {
    int d = r + g + b - max({r, g, b}) - min({r, g, b});
    if (S[i] == 'R') r++;
    if (S[i] == 'G') g++;
    if (S[i] == 'B') b++;
    if (r > 0 && g > 0 && b > 0) {
      if (d == 0) {
        ans *= mint(r) * g * b;
      } else {
        ans *= d;
      }
      r--;
      g--;
      b--;
    }
    int e = r + g + b - max({r, g, b}) - min({r, g, b});
    cnt += e;
    if (d < e) {
      if (S[i] == 'R') ans *= max(g, b) - d;
      if (S[i] == 'G') ans *= max(r, b) - d;
      if (S[i] == 'B') ans *= max(r, g) - d;
    }
  }
  rep(i, N) ans *= i + 1;
  cout << ans << endl;
  /*
  vector<int> dp(1 << 3 * N, 1e9);
  dp[0] = 0;
  rep(i, 1 << 3*N) {
    rep(x, 3*N) rep(y, x) rep(z, y) {
      if (i >> x & 1) continue;
      if (i >> y & 1) continue;
      if (i >> z & 1) continue;
      if (!(S[x] == 'R' || S[y] == 'R' || S[z] == 'R')) continue;
      if (!(S[x] == 'G' || S[y] == 'G' || S[z] == 'G')) continue;
      if (!(S[x] == 'B' || S[y] == 'B' || S[z] == 'B')) continue;
      chmin(dp[i | 1 << x | 1 << y | 1 << z], dp[i] + x - z);
    }
  }
  cout << dp[(1 << 3*N) - 1] << endl;
  cout << cnt << endl;
  */
}

Measured memory_bytes: 720
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

if N%2 == 0:
    print(sum(A[:int(N/2)])*2 - A[0])
else:
    print(sum(A[:N//2+1])*2 - A[0] - A[N//2])



Measured memory_bytes: 31428
if True:
    n,m=map(int,input().split())
    s=[(0,0) for i in range(n)]
    for i in range(n):
        s[i]=list(map(int,input().split()))
    #print(s)
else:
    n,m=2,5
    s=[(4,9),(2,4)]
s=sorted(s,key=lambda x: x[0])
#print(s)
d=0
ans=0
for i in range(n):
    pr=s[i][0]
    b=s[i][1]
    if d+b<m:
        ans+=pr*b
        d+=b
    else:
        ans+=(m-d)*pr
        break
print(ans)


Measured memory_bytes: 60320
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <utility>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

const int N = 200007;
const long long MOD = 998244353;
vector<long long> fct(N);

long long powerf(long long a, long long b, long long c) {
    long long res = 1;
    while(b > 0) {
        if(b%2 == 1) {
            res = (res * a) % c;
        }
        b/=2;
        a=(a*a)%c; 
    }
    return res;
}

void init()
{
    fct[0] = 1;
    for(int i=1; i<N; i++)
    {
        fct[i] = (fct[i-1] * i) % MOD; 
    }
}

long long ncr(long long n, long long r)
{
    if(n < r)
        return 0;
    long long num = fct[n];
    long long den = (fct[n-r] * fct[r]) % MOD;
    return (num * powerf(den, MOD-2, MOD)) % MOD;
}

int main() {
    init();
    long long n, m, k;
    cin >> n >> m >> k;
    long long ans = 0;
    for(long long kk=0; kk<=k; kk++)
    {
        long long rem = n - kk;
        long long cur = ((ncr(n-1, kk) * m) % MOD * powerf(m-1, rem-1, MOD)) % MOD;
        ans = (ans + cur) % MOD;
    }    
    cout << ans << "\n";
}

Measured memory_bytes: 4704
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();

        if (a < b) {
            System.out.println("a < b");
        } else if (a == b) {
            System.out.println("a == b");
        } else {
            System.out.println("a > b");
        }
    }
}


Measured memory_bytes: 26348
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    int n;
    cin >> n;
    deque<int> a(n);
    int cnt5 = 0, cnt0 = 0;
    int sum = 0;

    rep(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }
    if (sum % 10 == 0)
    {
        sort(a.begin(), a.end());
        rep(i, n)
        {
            if (a[i] % 10 != 0)
            {
                sum -= a[i];
                break;
            }
        }
        if (sum % 10 == 0)
        {
            sum = 0;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stack>
#include <cstdio>
using namespace std;
  int main(){
    int k,n,i,j,x[10];
    scanf("%d",&n);
for(k=0;k<n;k++){
    for(i=0;i<10;i++){
       scanf("%d",&x[i]);
}
stack<int> B;
stack<int> C;
B.push(x[0]);
for(i=1;i<=9;i++){
if(x[i-1]>x[i]){
C.push(x[i]);
goto ccc;
}else{
	B.push(x[i]);
	goto bbb;
}
bbb:;
}
ccc:
for(j=i;j<9;j++){
if(B.top()<x[j+1]){
B.push(x[j+1]);
}else if(C.top()<x[j+1]){
	C.push(x[j+1]);
}else{
	printf("NO\n");
	goto aaa;
}
}
printf("YES\n");
aaa:;
}
return 0;
  }

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

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define eb emplace_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int n;
    cin >> n;
    ull ans = 0;
    if ( n%2 ){
        ans = (ull)((n+1)/2)*n - n;
    }else{
        ans = (ull)(n/2)*(n+1) - n;
    }

    cout << ans << "\n";

    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}




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

int main(){
  int64_t n;cin>>n;
  int64_t i,j,mn=n;
  i = sqrt(n)+1;
  while(--i){
      if(n%i!=0)continue;
      j = n/i;
      mn = min(mn,i+j-2);
      if(mn!=(i+j-2))break;
  }
  cout << mn;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

long long A;
string B;

long long solve() {
    long long v = B[0] - '0';
    long long d = (B[2]-'0') * 10 + (B[3]-'0');
    return A * v + A * d / 100;
}

int main() {
    while (cin >> A >> B) cout << solve() << endl;
}

















Measured memory_bytes: 3636
import heapq
from collections import defaultdict, deque
from math import ceil, factorial
from fractions import gcd
import sys
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10**9+7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))


N, M = mii()
A = lmii()

sm = sum(A)

polular = [a for a in A if a >= sm/(4*M)]

if len(polular) >= M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 5564
#include <iostream>
#include<map>
using namespace std;
const int maxn = 2e6 + 10;
typedef pair<int, int> P;
int fa[maxn], ma[maxn];
void init(int n)
{
	for (int i = 0; i <= n; ++i)
	{
		fa[i] = i;
		ma[i] = i;
	}
}
int find(int* fa, int x)//找到根节点
{
	if (fa[x] == x)
	{	
		return fa[x];
	}
	return fa[x] = find(fa, fa[x]);
}
void unin(int a, int b, int* fa)
{
	a = find(fa, a);//找到a根节点
	b = find(fa, b);//找到b跟节点
	fa[a] = b;//a为b的父节点
}
map<P, int>ans;
int main()
{
	int n, k, l;
	while (scanf("%d%d%d", &n, &k, &l) != EOF)
	{
		init(n);
		ans.clear();
		for (int i = 0; i < k; ++i)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			unin(a, b, ma);
		}
		for (int i = 0; i < l; ++i)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			{
				unin(a, b, fa);
			}
		}
		for (int i = 1; i <= n; ++i)
		{
			ans[make_pair(find(ma, i), find(fa, i))]++;
		}
		for (int i = 1; i <= n; ++i)
		{
			i == n ? printf("%d\n", ans[make_pair(find(ma, i), find(fa, i))]) : printf("%d ", ans[make_pair(find(ma, i), find(fa, i))]);
		}
	}
	return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vll a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    while (k && sz(a)) {
        a.pop_back();
        k--;
    }
    ll ans = 0;
    for (int i = 0; i < sz(a); i++) {
        ans += a[i];
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1792