akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
   
#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, k;
vector <int> g[N];

inline int mult (int a, int b) {
   return 1ll * a * b % mod;
}

int dfs (int v = 1, int pr = 0) {
   int can = k - 1 - (pr > 0);
   int res = 1;
   for (auto to : g[v]) {
      if (to == pr) continue;
      res = mult (res, can);
      can --;
   }
   for (auto to : g[v]) {
      if (to == pr) continue;
      res = mult (res, dfs (to, v));
   }
   return res;
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n >> k;
   for (int i = 1; i < n; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   cout << mult (k, dfs ());
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using p32 = pair<i32, i32>;

int main() {
    i32 n, t;
    cin >> n >> t;
    vector<p32> ab(n);
    for (auto& e : ab) cin >> e.first >> e.second;
    sort(begin(ab), end(ab));

    vector<i32> dp(t+1);
    for (auto& e : ab) {
        i32 a, b;
        tie(a, b) = e;
        for (i32 i = t-1; i >= 0; i--) {
            dp[min(t, i+a)] = max(dp[min(t, i+a)], dp[i] + b);
        }
    }

    cout << dp[t] << endl;
}


Measured memory_bytes: 384
a=input()
b=a.split()
N=int(b[0])
A=int(b[1])
B=int(b[2])
if A<B:
    if A+B<N:
        print(A,0)
    else:
        print(A,B-(N-A))
elif A>=B:
    if A+B<N:
        print(B,0)
    else:
        print(B,A-(N-B))



Measured memory_bytes: 3060
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
  S = input()
  if S == "AC":
   	AC += 1
  if S == "WA":
    WA+= 1
  if S == "TLE":
    TLE += 1
  if S == "RE":
    RE+= 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))

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

int getResult(const string &s, const string &t){
  const size_t sSize = s.size();
  const size_t tSize = t.size();
  int minDiff = tSize;

  for(int i = 0; (i + tSize) <= sSize; i++){
    int diff = 0;
    for(int j = 0; j < tSize; j++){
      if(s[i + j] != t[j]){
        diff++;
      }
    }
    if(diff < minDiff){
      minDiff = diff;
    }
  }

  return minDiff;
}

int main(){
  string S, T;
  cin >> S >> T;

  int result = getResult(S, T);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;
 
int parent[N];
 
int gcd(int a, int b) { 
    if (a == 0) 
        return b;  
    return gcd(b%a, a);  
} 
   
int lcm(int a, int b) {  
    return (a*b)/gcd(a,b);  
} 
 
ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}
 
int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}
 
void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}
 
ll nCr(ll n, ll r) {
    ll res = 1;
    for(ll i=1;i<=r;i++) {
        res = res * (n - r + i) / i;
        // is different from
        // res *= (n -r + i) / i;
    }
    return res;
}
 
int ask(int i, int j) {
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    int v;
    cin >> v;
    return v;
}

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> dp(n, vector<int>(3));
    int a, b, c;
    cin >> a >> b >> c;
    dp[0][0] = a, dp[0][1] = b, dp[0][2] = c;
    for(int i=1;i<n;i++) {
        cin >> a >> b >> c;
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a;
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b;
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c;
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
    return;
} 
 
int main()
{
    IOS
    //int t;
    //cin >> t;
    //while(t--) 
    solve();
    return 0; 
}

Measured memory_bytes: 8744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    bool flg = true;
    for(char c='a'; c<='z'; c++){
        int cnt = 0;
        for(int i=0; i<s.size(); i++){
            if(s[i] == c) cnt++;
        }
        if(cnt%2 == 1){
            flg = false;
            break;
        }
    }

    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()
ans = [''] * len(S)
cur = 0
for s in S:
    if s == 'B':
        cur -= 1
        ans[cur] = ''
        cur = max(0, cur)
    else:
        ans[cur] = s
        cur += 1

print("".join(ans))

Measured memory_bytes: 3572
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100;
ll N, F[MAX_N][10], P[MAX_N][11];

void solve() {
    const int n = 10;
    ll ans = -INF;
    REP(i, pow(2, n)) {
        if (i == 0) continue;
        ll sum = 0;
        REP(k, N) {
            int c_open = 0;
            REP(j, n) {
                if ((1 & i >> j) == 1 && F[k][j] == 1) {
                    c_open++;
                }
            }
            sum += P[k][c_open];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

int main() {
    cin >> N;
    REP(i, N) REP(j, 10) cin >> F[i][j];
    REP(i, N) REP(j, 11) cin >> P[i][j];
    solve();
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Text.Printf
import Debug.Trace

solve :: [Integer] -> Integer
solve [] = 0
solve [x] = x
solve (x:xs) = x*(2^((length xs) - 1)) + (solve xs) + (solve ((10*x+(xs!!0)):(tail xs)))

solve_sub :: Int->[Integer] -> Integer
solve_sub n [] = 0
solve_sub n [x] = x*2^n
solve_sub n (x:xs) = x*(2^n)*10^(length xs) + (1-5^(length xs))`div`(1-5)*x*2^(length xs - 1 + n) + (solve_sub (n+1) xs)
  
solve_ :: [Integer] -> Integer
solve_ l = solve_sub 0 l 

listize :: Integer->[Integer]
listize 0 = []
listize n = (listize $ n`div`10)++[(n`mod`10)]

main :: IO()
main = do
  n <- readLn
  -- O(2^N)
  --printf "%d\n" $ solve $ listize n
  -- O(N)
  printf "%d\n" $ solve $ listize n


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  ll ans = 0;
  for(int i = 0; i < n; ++i) {
    ll a; cin >> a;
    while(a % 2 == 0) {
      a /= 2;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

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

    cout << 180 * (n - 2) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
#include<limits.h>
using namespace std;

const int N=5e5+5;
int n=1,tot;

void failure(char s[],int fail[]){
	fail[1]=0;
	for(int i=2,j=0;i<=n;i++){
		while(j&&s[j+1]!=s[i]) j=fail[j];
		if(s[j+1]==s[i]) j++;
		fail[i]=j;
	}
}

char s[N],rs[N];
int f[N],rf[N];

int main(){
	scanf("%s",s);
	n=strlen(s);
	for(int i=1;i<=n;i++) rs[i]=s[n-i];
	rs[n+1]='\0';
	for(int i=n;i>=1;i--) s[i]=s[i-1];
	s[n+1]='\0';
	failure(s,f);
	failure(rs,rf);
	if(f[n]==n-1) printf("%d\n1\n",n);
	else if(f[n]==0||rf[n]==0||n%(n-f[n])!=0||n%(n-rf[n])!=0) puts("1\n1");
	else{
		for(int i=1;i<n;i++) if((i%(i-f[i])!=0||f[i]==0)&&(rf[n-i]==0||(n-i)%(n-i-rf[n-i])!=0)) tot++;
		printf("2\n%d\n",tot);
	}
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int cnt = 0;
  for(int i=0;i<s.length()/2;i++){
    if(s[i]!=s[s.length()-i-1]){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))

(defun f(x)
  (let* ((n500 (truncate (/ x 500)))
         (r500 (mod x 500))
         (n5 (truncate (/ r500 5)))
         )
    (+ (* 1000 n500) (* 5 n5))))

(let ((line (parse-integer (read-line nil nil))))
  (format t "~A~%" (f line)))


Measured memory_bytes: 16612
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

struct SCC{
  vector<vector<Int> > G,R,T,C;
  vector<Int> vs,used,blg;
  SCC(){}
  SCC(Int n):G(n),R(n),used(n),blg(n){}

  void add_edge(Int u,Int v){
    G[u].emplace_back(v);
    R[v].emplace_back(u);
  }

  void dfs(Int v){
    used[v]=1;
    for(Int u:G[v])
      if(!used[u]) dfs(u);
    vs.emplace_back(v);
  }

  void rdfs(Int v,Int k){
    used[v]=1;
    blg[v]=k;
    C[k].emplace_back(v);
    for(Int u:R[v])
      if(!used[u]) rdfs(u,k);
  }

  Int build(){
    Int n=G.size();
    for(Int v=0;v<n;v++)
      if(!used[v]) dfs(v);

    fill(used.begin(),used.end(),0);
    Int k=0;
    for(Int i=n-1;i>=0;i--){
      if(!used[vs[i]]){
        T.emplace_back();
        C.emplace_back();
        rdfs(vs[i],k++);
      }
    }
    for(Int v=0;v<n;v++)
      for(Int u:G[v])
        if(blg[v]!=blg[u])
          T[blg[v]].push_back(blg[u]);

    for(Int i=0;i<k;i++){
      sort(T[i].begin(),T[i].end());
      T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end());
    }
    return k;
  }
  Int operator[](Int k) const{return blg[k];};
};


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> xs(n),ys(n),zs(n);
  for(Int i=0;i<n;i++) cin>>xs[i]>>ys[i]>>zs[i];

  SCC scc(n);
  for(Int i=0;i<m;i++){
    Int u,v;
    cin>>u>>v;
    u--;v--;
    scc.add_edge(v,u);
  }
  Int k=scc.build();

  vector<Int> ans(n,0);
  for(Int bit=0;bit<8;bit++){

    vector<Int> vs(n,0);
    for(Int i=0;i<n;i++){
      vs[i]+=(bit&1)?xs[i]:-xs[i];
      vs[i]+=(bit&2)?ys[i]:-ys[i];
      vs[i]+=(bit&4)?zs[i]:-zs[i];
    }

    const Int INF = 1e18;
    vector<Int> dp(k,-INF);
    for(Int i=0;i<n;i++)
      chmax(dp[scc.blg[i]],vs[i]);

    for(Int v=0;v<k;v++)
      for(Int u:scc.T[v])
        chmax(dp[u],dp[v]);

    for(Int i=0;i<n;i++)
      chmax(ans[i],dp[scc.blg[i]]-vs[i]);
  }

  for(Int i=0;i<n;i++) cout<<ans[i]<<"\n";
  cout<<flush;
  return 0;
}



Measured memory_bytes: 62764
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int N, M;
	cin >> N >> M;

	vector<int> A(N);
	for(int i=0; i<N; i++) cin >> A[i];


	ll cur = 0;
	int cnt = 0;
	for(int i=1; i<N; i++){
		if(A[i-1] < A[i]){
			cur += A[i]-A[i-1];
		} else {
			cnt++;
			cur += A[i];
		}
	}

	vector<ll> c(M+1);
	for(int i=1; i<N; i++){
		c[A[i]] += (A[i]-A[i-1]+M)%M-1;
	}

	vector<int> b(M+1), d(M+1);
	for(int i=0; i<N-1; i++) b[A[i]]++;
	for(int i=1; i<N; i++) d[A[i]]++;

	ll ans = cur;
	debug(any{cur});
	for(int x=1; x<M; x++){
		cnt -= d[x];
		cur -= cnt;
		cur += c[x];
		ans = min(ans, cur);
		debug(any{x, cur, cnt, d[x], b[x], c[x]});
		cnt += b[x];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  int ans = 0;
  for (int i = 0; i < N - 1; i++)
  {
    if (S[i] == S[i + 1])
      ans++;
  }
  ans += 2 * K;
  ans = min(ans, N - 1);
  cout << ans;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>


using namespace std;

int main() {

    long N, M;
    cin >> N >> M;

    priority_queue<long> que;

    long a;
    for (int i = 0; i<N; i++) {
        cin >> a;
        que.push(a);
    }

    for (int i=0; i<M; i++) {
        long top = que.top();
        que.pop();
        que.push(top/2);
    }

    long res = 0;
    while (!que.empty()) {
        res += que.top();
        que.pop();
    }

    cout << res;
}




Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>

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

int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];

    vector<ll> AB;
    rep(i, X) rep(j, Y) AB.push_back(A[i] + B[j]);

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

    vector<ll> ABC;
    rep(i, min(K, (int)AB.size())) rep(j, Z) ABC.push_back(AB[i] + C[j]);

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

    rep(i, K) cout << ABC[i] << endl;
    
    return 0;
}

Measured memory_bytes: 43652
n = gets.to_i
s = gets

sum = s.count('R') * s.count('G') * s.count('B')

0.upto(n-1) do |i|
  (i+1).upto(n-1) do |j|
    k = j*2 - i
    next if (j >= k || n <= k || s[i] == s[j] || s[j] == s[k] || s[k] == s[i])
    
    sum -= 1
  end
end

puts sum

Measured memory_bytes: 14356
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: f64 = read();
    let mut a: f64 = 1.0;
    let mut ans: f64 = n - 1.0;

    while a <= n.sqrt(){
        let b = n / a;
        if n % a == 0.0 && a * b == n {
            if (a + b - 2.0) < ans {
                ans = a + b - 2.0;
            }
        }
        a += 1.0;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#define ll long long int
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    long long int total =0;
    for(int i=0;i<s.length();i++)
    {
        total+=(s[i]-'0');
    }
    if(total%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


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

using namespace std;
int main (void)
{
	ios::sync_with_stdio(false);
	 
	int x;
	cin >> x;
	
	if( x<1200 ) cout << "ABC" ;
	else cout << "ARC";
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  (n, m) = InputLine.to_ia
  
  if n == m then
    puts 'Yes'
  else
    puts 'No'
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>

int main () {
  int N, x;
  std::cin >> N >> x;
  std::vector<int> data(N);
  for (int i=0; i<N; i++) {
    std::cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  int count = 0;
  for (int i=0; i<N; i++) {
    if (x >= data.at(i)) {
      count++;
      x -= data.at(i);
      if (i == N-1 && x > 0) {
      count--;
      }
    }
    else {
      break;
    }
  }
  std::cout << count << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  char a[3];
  char b[3];
  int c;
  int i;
  cin>>a;
  cin>>b;
  for(i=0;i<3;i++){
    if(a[i] == b[i]){
      c++;
    }
  }
  cout<<c;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<set>

using namespace std;

int main(void){

    int n;
    cin >> n;
    map<string, int> str;
    int maxValue = 0;

    for(int i = 0;i < n;i++){
        string tmp; cin >> tmp;
        auto a = str.find(tmp);
        if(a != str.end()){
            a->second++;
        }else{
            str.insert(make_pair(tmp, 1));
        }
    }

    for(auto const& entry: str){
        maxValue = max(maxValue, entry.second);
    }
    for(auto const& entry: str){
        if(maxValue == entry.second){
            cout << entry.first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 3300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
using namespace std;
int lr[2002][2002], rr[2002][2002], uc[2002][2002], dc[2002][2002];

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

    int n, m;
    cin >> n >> m;


    vector<string> A(n);

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

    for(int i = 0; i < n; i++) {
        int last = -1;

        for(int j = 0; j < m; j++) {
            if(A[i][j] == '#') last = j;

            lr[i][j] = last;
        }

    }

    for(int i = 0; i < n; i++) {
        int last = m;
        for(int j = m - 1; j >= 0; j--) {
            if(A[i][j] == '#') last = j;
            rr[i][j] = last;
        }
    }
    for(int i = 0; i < m; i++) {
        int last = -1;
        for(int j = 0; j < n; j++) {
            if(A[j][i] == '#') last = j;
            uc[j][i] = last;
        }
    }
    for(int i = 0; i < m; i++) {
        int last = n;
        for(int j = n - 1; j >= 0; j--) {
            if(A[j][i] == '#') last = j;
           dc[j][i] = last;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(A[i][j] == '#') continue;
            int cur = 0;
            cur += j - lr[i][j];
            cur += rr[i][j] - j;
            cur += i - uc[i][j];
            cur += dc[i][j] - i;
   ans = max(ans, cur);
        }
    }
    cout << ans - 3 << endl;
}

Measured memory_bytes: 67200
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

long n, l;
typedef std::pair<long, long> P;
P schedule[86405];
long u[86405];

bool pos(double cap){
	double cont = l;
	for(int j = 0; j < 2; j++){
		cont += cap * schedule[0].first;
		if(j == 1 && cont >= l){
			//printf("  possible_ret_1 cont = %lf, cap = %.10lf\n", cont, cap);
			return true;
		}
		cont = std::min(cont, (double)l);
		for(int i = 0; i < n; i++){
			//use
			cont += (cap - u[i]) * (schedule[i].second - schedule[i].first);
			if(cont < 0){
				return false;
			}
			
			//non_use
			if(i < n-1){
				cont += cap * (schedule[i+1].first - schedule[i].second);
			}else{
				cont += cap * (86400 - schedule[i].second);
			}
			if(j == 1 && cont >= l){
				//printf("  possible_ret_2 cont = %lf, cap = %.10lf\n", cont, cap);
				return true;
			}
			cont = std::min(cont, (double)l);
		}
	}
	return false;
}

int main(){
	while(1){
		scanf("%ld%ld", &n, &l);
		if(n == 0){
			return 0;
		}
		for(int i = 0; i < n; i++){
			scanf("%ld%ld%ld", &schedule[i].first, &schedule[i].second, u+i);
		}
		double ok = 1000000;
		double ng = 0;
		while(std::abs(ok - ng) > 0.0000001){
			double mid = (ok + ng) / 2;
			//printf("cap = %lf\n", mid);
			if(pos(mid)){
				ok = mid;
			}else{
				ng = mid;
			}
		}
		printf("%.10lf\n", ok);
	}
}




Measured memory_bytes: 5168
A = list(input())
S = [-1,1]
res = ["-","+"]
for i in range(2):
    for j in range(2):
        for k in range(2):
            if int(A[0])+int(A[1])*S[i]+int(A[2])*S[j]+int(A[3])*S[k] == 7:
                print(A[0]+res[i]+A[1]+res[j]+A[2]+res[k]+A[3]+"=7")
                exit()

Measured memory_bytes: 38384
/*
https://t.me/unstoppabIesoIvemachinechannel
*/
#pragma ARCENIY_KIRILLOV_POVELITEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;















signed main(){
    int n;
    cin >> n;
    int d[n];
    int sum = 0;
    for (int i = 0; i < n; i++) cin >> d[i];
    for (int i = 0; i < n; i++){
            for (int j = i + 1; j < n; j++){
                sum += d[i] * d[j];
            }
    }
    cout << sum;




}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<queue>
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
typedef double lf;
typedef unsigned un;
typedef int in;
#define mian main
#define maxn 10000+10
#define maxm 10000+10
#define _(a) read(a)
#define non void
#define inf 2147483647
#define bre break
#define con continue
#define prq priority_queue
#define re register
#define bu bool
#define cz char
#define cst const
#define ope operator
#define inl inline
#define upp upper_bound
#define low lower_bound
#define next_per next_permutation
cz obuf[1<<23],*O=obuf,buf[100000],*L=buf,*R=buf;
inl cz gc(){return L==R&&(R=(L=buf)+fread(buf,1,100000,stdin),L==R)?EOF:*L++;}
template<typename T>inl T Max(T a,T b){return a>b?a:b;}
template<typename T>inl T Min(T a,T b){return a<b?a:b;}
template<typename T>inl T Abs(T a){return a<0?-a:a;}
template<typename T>inl non read(T &a){a=0;T k=1;char c=gc();while(c<'0'||c>'9')k=c=='-'?-1:k,c=gc();while(c>='0'&&c<='9')a=a*10+(c^48),c=gc();if(c!='.'){a*=k;return;}T t=0.1;while(c<'0'||c>'9')c=gc();while(c>='0'&&c<='9')a+=t*(c^48),c=gc(),t*=0.1;a*=k;}
template<typename T>non print(T x){if(x>9)print(x/10);*O++=x%10+'0';}
template<typename T>non out(T a,cz t='\n'){print(a);*O++=t;}
non fresh(){fwrite(obuf,O-obuf,1,stdout);}
in x;
ll f[50];
in main()
{
	read(x);
	f[0]=2;
	for(re in i=1;i<=x;++i)f[i]=(f[i-1]<<1)+2;
	out(f[x]);
	fresh();
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

  vector<P> v;
  rep(i, n) {
    int x, h;
    cin >> x >> h;
    v.push_back({x, h});
  }

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

  ll ans = 0;
  ll tot = 0;
  queue<P> q;

  rep(i, n) {
    int x = v[i].first;
    int h = v[i].second;

    while (!q.empty() && q.front().first < x) {
      P p = q.front();
      q.pop();
      tot -= p.second;
    }
    h -= tot;

    if (h > 0) {
      int s = (h + a - 1) / a;
      ans += s;
      ll damage = (ll)s * a;
      tot += damage;
      q.push({x + 2 * d, damage});
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2672
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    a, b, c, k = rl()
    if a >= k:
        print (k)
    elif a + b >= k:
        print (a)
    else:
        rem = k - a - b
        print (a - rem)






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 82380
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef queue<ll> ql;
typedef set<ll> sl;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll &b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll &b) {if(b > a) {a = b; return 1;} return 0;}
const ll inf = 1LL << 60;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const ll max = 500010;
ll num, L, M, N, ans=0, count=0;
int main() {
  cin >> L;
  N = L/3;
  if(L%3 == 0) cout << N*N*N << endl;
  if(L%3 == 1) {
    if(N%3 == 0) cout << N*N*N + N*N + N/3 << ".037037037037" << endl;
    if(N%3 == 1) cout << N*N*N + N*N + N/3 << ".370370370370" << endl;
    if(N%3 == 2) cout << N*N*N + N*N + N/3 << ".703703703703" << endl;
  }
  if(L%3 == 2) {
    if(N%3 == 0) cout << N*N*N + N*N*2 + N*4/3 << ".296296296296" << endl;
    if(N%3 == 1) cout << N*N*N + N*N*2 + N*4/3 + 1 << ".629629629629" << endl;
    if(N%3 == 2) cout << N*N*N + N*N*2 + N*4/3 + 2 << ".962962962962" << endl;
  }
}


Measured memory_bytes: 256
function main()
  
  n = parse(Int, readline())
  A = parse.(Int, split(readline()))
  
  A_sum = sum(A)
  A_sum %= 10^9+7
  
  ans = 0
  for i in 1:n
    A_sum -= A[i]
    if A_sum < 0
      A_sum += 10^9+7
    end
    ans += A[i]*A_sum
    ans %= 10^9+7
  end
  
  println(ans)
  
end

main()

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

using namespace std;

int n, m, ans;
pair<int, int> p[100005];
int ta;

int main() {
	scanf("%d%d", &m, &n);
	for (int i = 0; i < n; i++)
		scanf("%d%d", &p[i].second, &p[i].first);
	sort(p, p + n);
	ans = 1;
	ta = p[0].first;
	for (int i = 1; i < n; i++)
		if (p[i].second >= ta) {
			ans++;
			ta = p[i].first;
		}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

const int INF=1001001001;

int N,K;
int x[100002];

int main(){
    cin>>N>>K;
    repn(i,N) cin>>x[i];
    x[0]=-INF;
    x[N+1]=INF;

    int L,R;
    repn(i,N){
        if(0<=x[i]){
            L=i-1;
            R=i;
            break;
        }
    }

    int ans=1001001001;
    repn(i,N-K+1){
        ans=min(ans,min(abs(x[i])+abs(x[i+K-1]-x[i]),abs(x[i+K-1])+abs(x[i+K-1]-x[i])));
    }

    cout<<ans<<endl;
}

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

int main()
{
  int n;
  string s, t;
  cin >> n >> s >> t;
  vector<char> ans;
  for (int i = 0; i < n; i++)
  {
    ans.push_back(s[i]);
    ans.push_back(t[i]);
  }
  for (int i = 0; i < 2 * n; i++)
  {
    cout << ans[i];
  }
  cout << endl;
}


Measured memory_bytes: 3588
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (b / a > c)
            System.out.println(c);
        else
            System.out.println(b / a);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int l;
	cin>>l;
	double x=l/3.0;
	double p=pow(x,3);
	cout << fixed << setprecision(10) << p << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
import math
def is_prime(n):
  if n == 1: return False
  for k in range(2, int(math.sqrt(n)) + 1):
    if n % k == 0:
      return False
  return True
if is_prime(N):
  print(N-1)
else:
  a = math.floor(math.sqrt(N))
  while True:
    if N%a==0:
      break
    a=a-1
  print(int(a+N/a-2))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  vector<int> vec(3);
  for(int i=0;i<3;i++){
    cin>>vec[i];
  }
  sort(vec.begin(),vec.end(),greater<int>());
  cout<<(vec[0]*10+vec[1]+vec[2]);
}

Measured memory_bytes: 256
import sys
import math
a, b, c, d, e, f = [int(i) for i in sys.stdin.readline().split()]
max_sugar = 0
max_sum = min(a, b) * 100
max_noudo = 0
for _a in range(f // a):
    max_b = math.floor((f - _a * a * 100) / b) + 1
    for _b in range(max_b):
        water = (_a * a + _b * b) * 100
        max_c = math.floor(min(f - water, (_a * a + b * _b) * e) / c) + 1
        for _c in range(max_c):
            _d = max(0, min((f - water - _c * c) // d, ((_a * a + _b * b) * e - _c * c) // d))
            if _c + _d == 0:
                continue
            if (_a * a + _b * b) * 100 + _c * c + _d * d > f:
                continue
            noudo = (c * _c + d * _d) / ((_a*a + _b*b) * 100)
            if noudo > e / 100:
                continue
            elif noudo > max_noudo:
                max_sugar = _c * c + _d * d
                max_sum = (_a*a + _b*b) * 100 + max_sugar
                max_noudo = noudo
print(max_sum, max_sugar)

Measured memory_bytes: 41712
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
/*vector<Type> v;
vector<Type> v();
vector<Type> v(n);
vector<Type> v(n, d);
vector<vector<Type>> vv;
vector<vector<Type>> vv();
vector<vector<Type>> vv(n);
vector<vector<Type>> vv(n, vector<Type>(m));
vector<vector<Type>> vv(n, vector<Type>(m, d));*/

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i,n){
    cin>>l[i];
  }
  int count=0;
  sort(l.begin(), l.end(), greater<int>() );
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      for(int k=j;k<n;k++){
        if(l[j]+l[k]>l[i] && l[i]!=l[k] && l[i]!=l[j] && l[j]!=l[k] ){
          //cout<<i<<' '<<j<<' '<<k<<endl;
          count++;
        }
      }
    }
  }
  cout<<count;
  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int N = 2e5 + 10;




using namespace std;

int main()
{



  IOS;


  int k;
  cin >> k;
  string s;
  cin >> s;
  string a;

  int n = s.length();

  if (n <= k)
  {
    cout << s << endl;

    return 0;
  }

  else
  {
    for (int i = 0; i < k; i++)
    {

      cout << s[i];



    }

    cout << "...";


  }


}

Measured memory_bytes: 3652
abk=list(map(int,input().split()))
a=abk[0]
b=abk[1]
k=abk[2]
for i in range(k):
    if i%2 == 0:
        b = b + a//2
        a = a//2
    else:
        a = a + b//2
        b = b//2
print(a,b)


Measured memory_bytes: 2940
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }

    let ans = (b-1+(a-2))/(a-1);

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


Measured memory_bytes: 4352
def main():
    N, W = map(int, input().split())

    # dp[0..N][weight]
    dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

    for n in range(N):
        weight, value = map(int, input().split())

        for w in range(W + 1):
            if weight <= w:
                dp[n + 1][w] = max(dp[n][w - weight] + value, dp[n][w])
            else:
                dp[n + 1][w] = dp[n][w]

    print(dp[N][W])


main()


Measured memory_bytes: 171400
#include <iostream>
using namespace std;
int main()
{
int A,B;
cin>>A>>B;
A=(A+11)%13;
B=(B+11)%13;
if(A>B)cout<<"Alice"<<endl;
if(A<B)cout<<"Bob"<<endl;
if(A==B)cout<<"Draw"<<endl;
system ("pause");
return 0;
}

Measured memory_bytes: 504
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;


vi from[100001], to[100001];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
        --a[i];
    }
    
    ll ans = LLONG_MAX, d = 0, sm = 0;
    rep(i, n - 1) {
        bool mut = false;
        if (a[i] < a[i + 1]) {
            sm += min(a[i + 1] - a[i], 1+a[i + 1]);
            if (a[i] + 1 < a[i + 1])mut = true;
        }
        else {
            sm += min(m - a[i] + a[i+1], 1 + a[i + 1]);
            if (m - a[i] + a[i + 1] > 1) {
                mut = true;
                d--;
            }
        }
        if (mut) {
            from[a[i]].push_back(a[i + 1]);
            to[a[i + 1]].push_back(a[i]);
        }
    }

    rep(x, m) {
        if (x > 1 && sz(from[x - 2])) {
            d -= sz(from[x - 2]);
        }
        if (x > 0) {
            sm += d;
        }
        smin(ans, sm);
        each(fr, to[x]) {
            if (fr == m && x == 0) {

            }
            else {
                int dif = fr < x ? x - fr : m - fr + x;
                sm += dif - 1;
                d++;
            }
        }
    }
    cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  rep(i, n) cin >> a[i];
  vector<ll> sum1(n + 1, 0);
  rep(i,n){
    sum1[i + 1] = sum1[i] + a[i];
  }
  sum = sum1[n];
  ll ans = 1000000000000;
  for (int i = 1; i < n; i++){
    ans = min(ans, abs(sum1[i] - (sum - sum1[i])));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<string>
#include<numeric>
using namespace std;

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for (int i=0;i<n;i++) cin >> a[i];
  int m = gcd(a[0],a[1]);
  for (int i=2;i<n;i++){
    m = gcd(m,a[i]);
  }

  cout << m << endl;
  return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  vector<int> v;
  int n,a;
  a=0;
  cin>>n;
  fr(i,n){
    int m;
    cin>>m;
    v.push_back(m);
  }
  sort(v.begin(), v.end());
  fr(i,n-1){
    if(v[i]==v[i+1]) ++a;
  }
  int b = n - (a+1)/2*2;
  cout<<b;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin>>n;
  vector<int> v(n);
  for(int i=0; i<n; i++)
    cin>>v[i];
  reverse(v.begin(), v.end());
  for(int i=0; i<n; i++)
  {
    cout << v[i];
    i!=n-1? cout << " " : cout << "\n";
  }
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

void printVector(const vector<ll>& vec) {
    for (ll value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

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

ll COM(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    
   int a,b,t=0,s=0,N; cin>>N;
   rep(i,N){
   cin>>a>>b;
   if(a==b){++t;}
   else {t=0;}
   if(t==3){++s;}
   }
   if(s>0){cout<<"Yes"<<endl;}
   else{cout<<"No"<<endl;}

}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;

ull gcd(vector<ull>& v) {
	// 末尾の2要素で割り算する
	ull mod = *rbegin(v) % *(rbegin(v) + 1);
	if (mod == 0) {
		// 0ということは割り算の終了条件を満たしている。
		// 要素が二つであればおわり。
		if (v.size() == 2) {
			return *(rbegin(v) + 1);
		}
		// 終わらない場合、末尾を捨てて続行
		v.pop_back();
		return gcd(v);
		
	} else {
		*rbegin(v) = *(rbegin(v) + 1);
		*(rbegin(v) + 1) = mod;
	}
	return gcd(v);
}

int main() {
	ull N;
	cin >> N;
	
	vector<ull> vec(N);
	for (size_t i = 0; i < N; i++) {
		cin >> vec[i];
	}
	const ull ans = gcd(vec);

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 1024
def main():
    class UnionFind:
        def __init__(self, n=0):
            self.d = [-1]*n

        def root(self, x):
            if self.d[x] < 0:
                return x
            self.d[x] = self.root(self.d[x])
            return self.d[x]

        def unite(self, x, y):
            x, y = self.root(x), self.root(y)
            if x == y:
                return False
            if x > y:
                x, y = y, x
            self.d[x] += self.d[y]
            self.d[y] = x
            return True

        def same(self, x, y):
            return self.root(x) == self.root(y)

    raw = tuple(map(int, open(0).read().split()))
    n, m = raw[:2]
    uf = UnionFind(n)
    [uf.unite(a, b) for a, b in zip(*[iter(raw[2:2*m+2])]*2)]

    [print('yes' if uf.same(a, b) else 'no') for a, b in zip(*[iter(raw[2*m+3:])]*2)]

if __name__ == '__main__':
    main()



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

int main(){
    int N;
    string Ss[102];
    stack<string> checker;
    checker.push("$$");
    string ans = "YES";

    cin >> N;
    for(int i=0;i<N;i++) cin >> Ss[i];

    for(int i=0;i<N;i++){
        if(Ss[i] == "A"){
            checker.push("A");
        }
        else{
            string top = checker.top();
            if(top == "$$"){
                ans = "NO";
                break;
            }
            checker.pop();
        }
    }
    if(checker.top() != "$$") ans = "NO";
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3212