akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int M, N;
int d[256][256];
int op[256];

int main(){
  while(scanf("%d", &M) && M){
    scanf("%d", &N);
    memset(d, 0, sizeof(d));
    memset(op, 0, sizeof(op));
    REP(i, 1, N+1) scanf("%d", op+i);

    rep(i, N+1) REP(j, 1, M+1){
      int next = i + j;
      if(op[next] == 0){
	d[i][next] = 1;
      }else{
	d[i][max(0, min(N+1, next+op[next]))] = 1;
      }
    }

    rep(k, N+2) rep(i, N+2) rep(j, N+2){
      if(d[i][k] && d[k][j]) d[i][j] = 1;
    }

    /*    rep(i, N+2){
      rep(j, N+2) printf("%d ", d[i][j]); puts("");
      }*/

    int p;
    for(p = 0; p < N+1; p++) if(d[0][p] && !d[p][N+1]){ puts("NG"); break;}
    if(p == N+1) puts("OK");
  }
  return 0;
}

Measured memory_bytes: 1432
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
	long long n,i,j,k,count=0,ans=0,l,r,x,y,sum=0,mx=0,m;
	cin>>n;
	long long a[n-1],b[n+1]={0};
	for(i=0;i<n-1;i++)
	{
	    cin>>a[i];
	    b[a[i]]++;
	}
     for(i=1;i<=n;i++)
     cout<<b[i]<<endl;
	return 0;
}

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

    #define int long long
    #define ci(m)     for(int i=0;i<m;i++)
    #define cj(m)     for(int j=0;j<m;j++)
    #define ck(m)     for(int k=0;k<m;k++)
    #define gcd            __gcd
    #define endl           "\n"
    #define pb             emplace_back
    #define setbits(x)     __builtin_popcountll(x)
    #define zrobits(x)     __builtin_ctzll(x)
    #define mod            1000000007
    #define mod2           998244353
    #define maxe           *max_element
    #define mine           *min_element
    #define inf            1e18
    #define deci(x, y)      fixed<<setprecision(y)<<x
    #define w(t)           int t; cin>>t; while(t--)
    #define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
    #define PI             3.141592653589793238
    using namespace std;
    vector<int>v[100000];
    int col[100000];
    int dp[100000][11];
    int n,m;
    int32_t main() {
        nitin;
        cin>>n>>m;
        while(m--)
        {
            int a,b;
            cin>>a>>b;
            --a;
            --b;
            v[a].push_back(b);
            v[b].push_back(a);
        }
        int t;
        cin>>t;
        vector<vector<int>>queries;
        for(int i=0;i<t;i++)
        {
            int a,b,c;
            cin>>a>>b>>c;
            queries.push_back({a,b,c});
        }
        while(t--)
        {
            int node,dist,color;
            node=queries[t][0];
            dist=queries[t][1];
            color=queries[t][2];
            node--;
            queue<int>q;
            q.push(node);
            unordered_map<int,bool>m;
            m[node]=true;
            if(col[node]==0)
            col[node]=color;
            dp[node][dist]=1;
            while(dist--)
            {
                queue<int>nq;
                while(!q.empty())
                {
                    int vert=q.front();
                    q.pop();
                    for(auto c:v[vert])
                    {
                        if(!m[c] && !dp[c][dist])
                        {
                            nq.push(c);
                            if(col[c]==0)
                            col[c]=color;
                            dp[c][dist]=1;
                            m[c]=true;
                        }
                    }
                }
                q=nq;
                if(q.empty())
                    break;
            }

        }
        for(int i=0;i<n;i++)
            cout<<col[i]<<" ";
        cout<<endl;
        return 0;
    }

Measured memory_bytes: 29968
#include <cstdio>

using namespace std;

int main() {
  char s[9];
  scanf("%s", s);
  for (int i = 0; i < 3; ++i) {
    if (s[i] == s[i + 1]) {
      puts("Bad");
      return 0;
    }
  }
  puts("Good");
}


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

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

    ll arr[n];
    for(ll i=0;i<n-1;i++)
        cin>>arr[i];

    if(n==2){
        cout<<2*arr[0];
        return 0;
    }
    ll ans[n];
    for(ll i=n-2;i>0;i--){
        ans[i] = min(arr[i],arr[i-1]);
    }
    ans[0] =max(arr[0] , ans[1]);
    ans[n-1]=max(arr[n-2],ans[n-2]);
    ll sum = 0;
    for(ll i=0;i<n;i++){
        sum+=ans[i];
        //cout<<ans[i]<<" ";
    }
    //cout<<endl;
    cout<<sum;

}



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

int main() {
    int H, N;
    cin >> H >> N;
    vector<int>A(N);
    vector<int>B(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i] >> B[i];
    }
    vector<ll>dp(H+1, 1e18);
    dp[0] = 0;
    for (int i = 1; i <= H; ++i) {
        for (int j = 0; j < N; ++j) {
            int k = i - A[j];
            k = max(k, 0);
            dp[i] = min(dp[i], dp[k] + B[j]);
        }
    }
    cout << dp[H] << "\n";
    return 0;
}

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

using int64 = long long;
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int cnt[2][202020];

int main() {
   int n, m;
   cin >> n >> m;
   string s;
   cin >> s;
   int a[n];
   rep (i, n) {
      a[i] = (s[i]=='A');
   }
   vec<int> v[n];
   rep (i, m) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      v[x].push_back(y);
      v[y].push_back(x);
      cnt[a[x]][y]++;
      cnt[a[y]][x]++;
   }
   bool ok[n];
   queue<int> q;
   rep (i, n) {
      ok[i] = (cnt[1][i] > 0 && cnt[0][i] > 0);
      if (!ok[i]) q.push(i);
   }
   while (q.size()) {
      int x = q.front(); q.pop();
      for (auto &u : v[x]) {
         if (!ok[u]) continue;
         if (--cnt[a[x]][u] == 0) {
            ok[u] = false;
            q.push(u);
         }
      }
   }

   rep (i, n) {
      if (ok[i]) {
         cout << "Yes"<< endl;
         return 0;
      }
   }
   puts("No");

   return 0;
}

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

typedef long long int64;

struct Solution {
    int64 N, X;

    int64 F(int64 a, int64 b) {
        if (b % a == 0) return 2 * a * (b / a) - a;
        return 2 * a * (b / a) + F(b % a, a);
    }

    void Solve() {
        scanf("%lld%lld", &N, &X);
        printf("%lld\n", N + F(N - X, X));
    }
};

int main() {
    Solution().Solve();
    return 0;
}


Measured memory_bytes: 128
def isPalindrome(List):
    for i in range(len(List) // 2):
        if List[i] == List[len(List) - i - 1]:
            continue
        else:
            return False
    return True


List = [i for i in input()]
if (isPalindrome(List)):
    if (isPalindrome(List[:len(List) // 2])):
        if (isPalindrome(List[len(List) // 2 + 1:len(List)])):
            print("Yes")
            exit()
print("No")



Measured memory_bytes: 3060
#include <bits/stdc++.h>    
#define pb push_back
typedef long long ll;
const int inf = 2e9;
using namespace std;
ll MOD = 1000000007;
typedef pair<int,int> ii;
typedef struct {int a,b,c;}iii;
 
int n;
int L[33];
vector<int> v;
char S[100005];
 
int main()
{   
	ll ans = 1;
	scanf("%d%s",&n,S);
	for(int i=0; i<n; i++) L[(S[i]-'a')]++;
	for(int i=0; i<28; i++) if(L[i]>0) v.pb(L[i]);
	n = v.size();
 
	for(int i=0; i<n; i++) 
		ans = (ans*(v[i]+1))%MOD;
 
 
	printf("%lld\n",ans-1);
}

Measured memory_bytes: 384
a=input()
x,y,z,b=int(a[0]),int(a[1]),int(a[2]),int(a[3])
if x+y+z+b==7:
    print("{}+{}+{}+{}=7".format(x,y,z,b))
elif x-y-z-b==7:
    print("{}-{}-{}-{}=7".format(x,y,z,b))
elif x+y+z-b==7:
    print("{}+{}+{}-{}=7".format(x,y,z,b))
elif x+y-z+b==7:
    print("{}+{}-{}+{}=7".format(x,y,z,b))
elif x-y+z+b==7:
    print("{}-{}+{}+{}=7".format(x,y,z,b))
elif x+y-z-b==7:
    print("{}+{}-{}-{}=7".format(x,y,z,b))
elif x-y-z+b==7:
    print("{}-{}-{}+{}=7".format(x,y,z,b))
else:
    print("{}-{}+{}-{}=7".format(x,y,z,b))


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

long gcd(long a,long b)
{
  if(a>b){
    long buf=a;
    a=b;
    b=buf;
  }
  if(a==0)
    return b;
  gcd(a,b%a);
}
long gcm(long a,long b)
{
  long g=gcd(a,b);
  return a/g*b;
}

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

  a--;
  long x,y;
  x=a-a/c-a/d+a/gcm(c,d);
  y=b-b/c-b/d+b/gcm(c,d);

  cout << y-x << endl;
  return 0;

}

Measured memory_bytes: 256
H,W=map(int,input().split())

c=[None]*10

for i in range(10):
    c[i]=list(map(int,input().split()))

A=[]

for i in range(H):
    A+=list(map(int,input().split()))

minc=[None]*10

for i in range(10):
    minc[i]=c[i]

#mincを求める.

for k in range(10):
    for i in range(10):
        for j in range(10):
            if minc[i][j]>c[i][k]+c[k][j]:
                minc[i][j]=c[i][k]+c[k][j]



NUM=[0]*10

for i in range(H*W):
    if A[i]!=-1:
        NUM[A[i]]+=1

ANS=0
for i in range(10):
    ANS+=NUM[i]*minc[i][1]

print(ANS)


Measured memory_bytes: 3540
use proconio::{input, fastout};

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

#[fastout]
fn main() {
    input!{
        n: usize,
        mut p: [usize;n],
    }

    p.sort();
    let mut ans = 0;
    for i in 0..n {
        if i==n-1 {
            ans += p[i]/2;
        } else {
            ans += p[i];
        }
    }

    println!("{}", ans);

}


Measured memory_bytes: 2208
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int i,l=s.length(),j;
    j=0;
    for(i=0;i<l;i++){
        if(s[i]=='B'){
            s[i]='.';
            j--;
            if(j>=0){
                s[j]='.';
            }
        }
        else{
            j=i+1;
        }
    }
    for(i=0;i<l;i++){
        if(s[i]!='.'){
            cout<<s[i];
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 200005
#define MOD 1000000007
#define INF 10000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

void solve(){

    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if(n > 0){
        ans += (n*(n-1))/2;
    }
    if(m > 0){
        ans += (m*(m-1))/2;
    }
    cout << ans ;

}

int main()
{
    fast();
    int t= 1;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
import math

X = int(input())

# 500, 100, 50, 10, 5, 1
def main():
    def main0(x, acc):
        if x >= 500:
            acc += math.floor(x / 500) * 1000
            return main0(x % 500, acc) 
        # elif x >= 100:
        #     return main0(x % 100, acc) 
        # elif x >= 50:
        #     return main0(x % 50, acc) 
        # elif x >= 10:
        #     return main0(x % 10, acc) 
        elif x >= 5:
            acc += math.floor(x / 5) * 5
            return main0(x % 5, acc) 
        else:
            return acc

    return main0(X, 0)

print(main())


Measured memory_bytes: 38384
#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int
main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int &aa: a)
  {
    cin >> aa;
  }
  vector<int> b(N);
  int count = 0;
  for (int i = N; 0 < i; i--)
  {
    int sum = 0;
    for (int n = i + i; n <= N; n += i)
    {
      sum += b[n - 1];
    }
    if ((a[i - 1] + sum) % 2)
    {
      b[i - 1] = 1;
      count++;
    }
  }
  cout << count << endl;
  bool first = true;
  for (int i = 0; i < N; i++)
  {
    if (b[i])
    {
      if (first)
      {
        first = false;
      }
      else
      {
        cout << ' ';
      }
      cout << i + 1;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2432
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N;
    cin >> N;
    ll ans = 1;
    for(ll i = 0; i < 3; i++) ans *= N;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int N,K,R,hasil;
		scanf("%d",&N);
			getchar();	
	scanf("%d",&R);
			getchar();
	
	if(N <=10)
	{
	hasil =	100 * (10-N);
	K = R + hasil;	
		
	}
	else
	{
	K = R;
	
	}
	printf("%d",K);
	
	
	return 0;
}

Measured memory_bytes: 1712
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
print(S[:4] + ' ' +S[4:])


Measured memory_bytes: 4212
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<unordered_map>
#include<math.h>

using namespace std;
typedef unsigned long long ll;

#define INF 1e+15 + 7

int main(){
	ll City[6];
	ll N;
	cin>>N;
	ll m = INF;
	for(int i = 0; i < 5; i++){
		cin>>City[i];
		
		m = min(m, City[i]);
	}
	ll mm = (ll)(N * 10 / (m));
	mm += 9;
	mm /= 10;
	if(mm == 0)mm = 1;
	cout<<mm + 4<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;

int n;
ll k, a[N], b[N];

bool valid(ll lim){
    ll cnt = 0;
    for(int i = 0 ; i < n ; ++i)
        cnt += max(0LL, a[i] - (lim / b[i]));
    bool ok = true;
    // for(int i = 0 ; i < n ; ++i){
    //     ll m3lsh = max(0LL, a[i] - (lim / b[i]));
    //     if(m3lsh * b[i] == lim)ok = true;
    // }
    // cout << endl << "Cnt = " << cnt << endl;
    return cnt <= k && ok;
}

ll bs(){
    ll l = 0, r = 1e12, mid, ans = -1;
    while(l <= r){
        mid = (l + r) / 2LL;
        if(valid(mid)){
            ans = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    // assert(ans != -1);
    return ans;
}

int main(){
    scanf("%d%lld", &n, &k);
    for(int i = 0 ; i < n ; ++i)scanf("%lld", a + i);
    for(int i = 0 ; i < n ; ++i)scanf("%lld", b + i);
    sort(a, a + n);
    sort(b, b + n);
    reverse(b, b + n);
    // for(int i = 0 ; i < n ; ++i)cout << a[i] << " "; cout << endl;
    // for(int i = 0 ; i < n ; ++i)cout << b[i] << " "; cout << endl;
    printf("%lld\n", bs());
    // for(int j = 1 ; j <= 15 ; ++j){
    // k = j;    
    // for(int i = 9 ; i <= 25 ; ++i)cout << valid(i) << " ";cout << endl;
    // }
    // cout << valid(10) << endl;
    // cout << valid(11) << endl;
    // cout << valid(12) << endl;
    // cout << valid(13) << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define s(x) (x).begin(),(x).end();
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
int main(){
  int N;
  cin >>N;
  vi num(N);
  rep(i,N)cin>>num[i];
  bool  f = true;
  rep(i,N){
    int a = num[i];
    if(a%2==0){
      if(a%5!=0&&a%3!=0)f=false;
    }
  }
  if(f)cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
 
int main(){
  int A , B , C ;
  cin >> A >> B >> C ;
  long long D[15];
  D[0] = (long long) C ;
  rep(i,10) {
    D[i+1] = A*D[i] - B ;
    cout << D[i+1] << endl;
  }
}

Measured memory_bytes: 256
import bisect
N, Q = map(int, input().split())
S = input()
arr = []
for i in range(N-1):
  if S[i:i+2] == "AC":
    arr.append(i)
#print(arr)
for i in range(Q):
  l, r = map(int, input().split())
  print(bisect.bisect_right(arr, r-2) - bisect.bisect_left(arr, l-1))
               

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

int main() {
    std::string S;
    std::cin >> S;

    int cur = 0;
    for (size_t i = 0; i < S.size(); ++i) {
        if (S[i] == '+') {
            ++cur;
        } else {
            --cur;
     
        }
    }

    std::printf("%d\n", cur);

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int v[100], w[100];
int dp[101][10'001];

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

    rep(i, n)
    {
        cin >> v[i] >> w[i];
    }

    irep(i, n) irep(j, wmax)
    {
        if (i == 0) {
            dp[i][j] = j == 0 ? 0 : -1;
        } else {
            dp[i][j] = dp[i - 1][j];
            if (j - w[i - 1] >= 0) {
                dp[i][j] = max(dp[i][j], dp[i][j - w[i - 1]] + v[i - 1]);
            }
        }
    }

    int result = -1;
    irep(i, wmax)
    {
        result = max(result, dp[n][i]);
    }
    cout << result << endl;

    return 0;
}


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

const int INFTY = (1 << 30);
const int MAX = 500000;
int cnt;

void merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1+1], R[n2+1];

  for (int i = 0; i < n1; i++) L[i] = A[left + i];
  for (int i = 0; i < n2; i++) R[i] = A[mid + i];

  L[n1] = R[n2] = INFTY;
  int l_i {0}, r_i {0};
  for (int i = left; i < right; i++) {
    cnt++;
    if (L[l_i] < R[r_i]) {
      A[i] = L[l_i];
      l_i++;
    } else {
      A[i] = R[r_i];
      r_i++;
    }
  }
}


void mergeSort(int A[], int left, int right) {
  int mid = (right + left) / 2;
  if (left + 1 < right) {
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int n, A[MAX];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i];
  mergeSort(A, 0, n);
  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl << cnt << endl;
}



Measured memory_bytes: 6936
#include <bits/stdc++.h>
#define yabs(x) ((x<0)?(-(x)):(x))

using namespace std;
typedef long long LL;

const int N=1e5+10;

struct Edge{ int to,next;} way[N<<1];

int n,m,tot,num[N],col[N],d[N],X,Y,k[N],sum[N];
LL ans;

void Build(int a,int b) { way[++tot]=(Edge){b,num[a]}; num[a]=tot; }

void Init()
{
	scanf("%d%d",&n,&m);
	int a,b; tot=1;
	for (int i=1;i<=m;++i)
	{
		scanf("%d%d",&a,&b);
		Build(a,b); Build(b,a); 
		d[a]++; d[b]++;
	}
}

bool vis[N],fl,use[N];
int Dfs(int x,int fa,int c)
{
	vis[x]=1; col[x]=c;
	int cnt=c;
	for (int i=num[x];i;i=way[i].next)
	{
		int v=way[i].to;
		if (v==fa) continue;
		if (vis[v])
		{
			X=x; Y=v;
			if (col[x]==col[v]) fl=1;
			else fl=0;
		}
		else use[i>>1]=1,cnt+=Dfs(v,x,-c);
	}
	ans+=yabs(cnt);
	return cnt;
}

void Dp(int x,int fa)
{
	sum[x]=col[x];
	for (int i=num[x];i;i=way[i].next)
	{
		int v=way[i].to;
		if (v==fa || !use[i>>1]) continue;
		Dp(v,x);
		sum[x]+=sum[v]; k[x]+=k[v];
	}
}

int P[N];
void Solve()
{
	if (n==2) { printf("1\n"); return ; }
	int root=1;
	if (m==n-1) 
	{ 
		ans=0;
		int sum=Dfs(root,0,1); 
		if (sum!=0) printf("-1\n");
		else printf("%lld\n",ans);
	}else 
	{
		int summ=Dfs(root,0,1);
		if (fl)
		{
			Dp(root,0); ans=0;
			if (sum[root]%2) printf("-1\n");
			else 
			{
				int summ=sum[root];
				col[X]-=sum[root]/2; col[Y]-=sum[root]/2;
				Dp(root,0);
				for (int i=1;i<=n;++i) ans+=yabs(sum[i]);
				printf("%lld\n",ans+yabs(summ)/2);
			}
		}else
		{
			ans=0;
			k[X]++; k[Y]--;
			Dp(root,0);
			if (sum[1]) { printf("-1\n"); return ;}
			int top=0;
			for (int i=1;i<=n;++i)
				if (k[i]==-1) P[++top]=sum[i];
				else if (k[i]==1) P[++top]=-sum[i];
				else ans+=yabs(sum[i]);
			P[++top]=0;
			sort(P+1,P+top+1);
			int chose=P[(top+1)/2];
			for (int i=1;i<=top;++i) ans+=yabs(chose-P[i]);
			printf("%lld\n",ans);
		}
	}
}

int main()
{   
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

struct card {
  char s;
  int v;
};

void bubbleSort(vector<card> &a, int n) {
  bool flag = true;
  while (flag) {
    flag = false;
    repr(i, n-2) {
      if (a[i].v > a[i+1].v) {
        swap(a[i], a[i+1]);
        flag = true;
      }
    }
  }

  rep(i, n) {
    if (i) cout << " ";
    cout << a[i].s << a[i].v;
  }
  cout << endl;
}

void selectionSort(vector<card> &a, int n) {
  int minj;
  rep(i, n) {
    minj = i;
    FOR(j, i, n) {
      if (a[j].v < a[minj].v) {
        minj = j;
      }
    }
    if (minj != i) {
      swap(a[i], a[minj]);
    }
  }

  rep(i, n) {
    if (i) cout << " ";
    cout << a[i].s << a[i].v;
  }
  cout << endl;
}

int main() {
  int n;
  bool flag = true;
  cin >> n;
  vector<card> a1(n), a2(n);
  rep(i, n) cin >> a1[i].s >> a1[i].v;
  a2 = a1;

  bubbleSort(a1, n);
  cout << "Stable" << endl;
  selectionSort(a2, n);
  rep(i, n) {
    if (a1[i].s != a2[i].s) {
      flag = false;
      break;
    }
  }
  if (flag) cout << "Stable" << endl;
  else cout << "Not stable" << endl;

  
  return 0;
}


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

int main(){
  int n; cin >> n;
  vector<int> arr(n);
  rep(i,n) cin >> arr[i];
  int cnt = 0;
  for(int i = 1; i < n - 1; i++){
    if(arr[i] != max({arr[i-1],arr[i],arr[i+1]}) && arr[i] != min({arr[i-1],arr[i],arr[i+1]})){
      cnt++;
    }
  }
  cout << cnt;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1005;
int gcd(int x,int y){
    int t;
    while(y){
        t=x%y;
        x=y;
        y=t;
    }
    return x;
}
ll t[N],a[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&t[i],&a[i]);
    ll x=1,y=1;
    for(int i=1;i<=n;i++){
        ll x1=x+(x%t[i]==0?0:t[i]-x%t[i]),y1=y+(y%a[i]==0?0:a[i]-y%a[i]);
        ll yy=x1/t[i]*a[i],xx=y1/a[i]*t[i];
        if(yy>=y&&(x1+yy<=xx+y1||xx<x)){
            x=x1;
            y=yy;
        }
        else{
            x=xx;
            y=y1;
        }
    }
    printf("%lld\n",x+y);
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int l=s.length(),i,j;
  for(i=l-2;i>0;i-=2){
    for(j=0;j<i/2;j++) if(s.at(j)!=s.at(i/2+j)) break;
    if(j==i/2) break;
  }
  cout<<i<<endl;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> v(3*n);
	for (int i=0; i<3*n; i++){
		cin >> v[i];
	}
	long long sum=0;
	sort(v.rbegin(), v.rend());
	for(int i = 1; i<2*n; i+=2){
		sum+=v[i];
	}
	cout << sum;
 }


Measured memory_bytes: 1408
double x[100],y[100],t,u,b,s;
n,i,j,k,c;
main(m){
	for(;m=scanf("%d",&n),j=i=n;printf("%d\n",m)){
		for(;j--;scanf("%lf,%lf",x+j,y+j));
		for(;j=--i;)
			for(;j--;)
				if(s=(u=acos(hypot(x[j]-x[i],y[j]-y[i])/2))<9)
					for(t=atan2(y[j]-y[i],x[j]-x[i]);c=0,s+3;s-=2)
						for(k=n;k--;)
							hypot(x[i]+cos(b)-x[k],y[i]+sin(b=t+s*u)-y[k])<1.1&&++c>m?m=c:0;
	}
}

Measured memory_bytes: 0
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
C = [[A+B, A, B] for A, B in AB]
C.sort(reverse=True)
ans = 0
for i, (c, a, b) in enumerate(C):
    if i % 2 == 0:
        ans += a
    else:
        ans -= b
print(ans)

Measured memory_bytes: 38168
INF = float("inf") #const

def main():
    s = input()
    n = len(s) - 1
    ans = 0

    for i in range(2**n):
        op = ["-"]*n
        for j in range(n):
            if (i>>j)&1:
                op[j] = "+"
        tmp = ""
        for a,b in zip(s,op+[""]):
            tmp += a + b
        if eval(tmp) == 7:
            print(tmp+"=7")
            return


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
n = gets.chomp.to_i
array = []
n.times { array << gets.to_i }
ordered_array = array.sort
n.times do |i|
  if ordered_array[n - 1] == array[i]
    puts ordered_array[n - 2]
  else
    puts ordered_array[n - 1]
  end
end

Measured memory_bytes: 8224
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

var (
	n, m int
	ns   [][]int
)

func dfs(xs []int) {
	if len(xs) == n {
		ns = append(ns, xs)
		return
	}

	for i := xs[len(xs)-1]; i <= m; i++ {
		dfs(append(xs, i))
	}
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	n, m = scanInt(), scanInt()
	q := scanInt()
	a := make([]int, q)
	b := make([]int, q)
	c := make([]int, q)
	d := make([]int, q)
	for i := 0; i < q; i++ {
		a[i], b[i], c[i], d[i] = scanInt(), scanInt(), scanInt(), scanInt()
	}

	ns = make([][]int, 0, 3628800)
	for i := 1; i <= m; i++ {
		dfs([]int{i})
	}

	ans := 0
	for _, vs := range ns {
		sum := 0
		for i := 0; i < q; i++ {
			if vs[b[i]-1]-vs[a[i]-1] == c[i] {
				sum += d[i]
			}
		}
		ans = max(ans, sum)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 13760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a , b , n;
  cin >> a >> b;
  n = a * b;
  
  if (n % 2 == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

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

static const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    unsigned n;
    cin >> n;
    vector<int> cc(n), ss(n), ff(n);
    for (int i = 0; i < n-1; ++i) {
        cin >> cc[i] >> ss[i] >> ff[i];
    }
    for (int i = 0; i < n; ++i) {
        int t = 0;
        for (int j = i; j < n-1; ++j) {
            t = (t + ff[j] - 1) / ff[j] * ff[j];
            if(t < ss[j]) t = ss[j];
            t += cc[j];
        }
        cout << t << "\n";
    }
    return 0;
}


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

class dice {
public:
	int getRightFace(int top, int front);
	void setFaceNumber(int *number);
private:
	int face[6];
};

void dice::setFaceNumber(int *number) {
	for(int i=0; i<6; ++i) {
		face[i]=number[i];
	}
}

int dice::getRightFace(int top, int front) {
	int pos_top, pos_front;
	string str;
	string target_str;
	for(int i=0; i<6; ++i) {
		if(face[i]==top) pos_top=i;
		if(face[i]==front) pos_front=i;
	}
	str = to_string(pos_top)+to_string(pos_front);
	target_str="01540";
	if((int)target_str.find(str)!=-1) {
		return face[2];
	}
	target_str="04510";
	if((int)target_str.find(str)!=-1) {
		return face[3];
	}
	target_str="02530";
	if((int)target_str.find(str)!=-1) {
		return face[4];
	}
	target_str="03520";
	if((int)target_str.find(str)!=-1) {
		return face[1];
	}
	target_str="12431";
	if((int)target_str.find(str)!=-1) {
		return face[0];
	}
	target_str="13421";
	if((int)target_str.find(str)!=-1) {
		return face[5];
	}
	return 0;
}

int main() {
	int num[6];
	int n,top,front;
	dice d;
	cin >> num[0] >> num[1] >> num[2] >> num[3] >> num[4] >> num[5];
	d.setFaceNumber(num);
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> top >> front;
		cout << d.getRightFace(top,front) << endl;
	}
	return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll x; cin >> x;
    ll n; cin >> n;
    vector <ll> ges;
    vector <ll> les;
    REP(i, n+1){
        ges.push_back(x+i);
        les.push_back(x-i);
    }
    set <ll> banned;
    REP(i, n){
        ll p; cin >> p;
        banned.insert(p);
    }
    REP(i, n+1){
        if (banned.find(les[i]) == banned.end()){
            cout << les[i] << endl;
            return 0;
        }
        if (banned.find(ges[i]) == banned.end()){
            cout << ges[i] << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3608
from collections import deque
from itertools import product


def bfs(x, y):
    dist = [[10 ** 9] * w for _ in range(h)]
    dist[y][x] = 0
    que = deque([(x, y)])
    near = list(product(range(-2, 3), repeat=2))

    while len(que) > 0:
        x, y = que.popleft()
        if (x, y) == (Dw - 1, Dh - 1):
            return dist[y][x]

        for dx, dy in near:
            cnt = (abs(dx) + abs(dy) >= 2)
            i, j = x + dx, y + dy
            if (0 <= i < w and 0 <= j < h and
                    dist[j][i] > dist[y][x] + cnt and s[j][i] == '.'):
                dist[j][i] = dist[y][x] + cnt
                if cnt == 0:
                    que.appendleft((i, j))
                elif cnt == 1:
                    que.append((i, j))
    else:
        return -1


h, w = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
s = [input() for _ in range(h)]

print(bfs(Cw - 1, Ch - 1))


Measured memory_bytes: 95300
A,B=map(int,input().split())
s=input()
S=[s[i] for i in range(len(s))]
N=A+B+1
c=0
num={str(i) for i in range(10)}
if S[A]=='-' and len(S)==N:
  c=1
  S.pop(A)
  for i in range(N-1):
    if 1-(S[i] in num):
      c=0
if c==1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9100
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,sum;
int a[20],len,b[20];
void init(int nn)
{
    sum=0;
    len=0;
    int tnt=1;
    while(nn)
    {
        a[++len]=nn%10;
        nn/=10;
    }
    for(int i=0;i<len;i++)
    {
        b[i]=tnt;
        tnt*=10;
    }
}
void dfs(int pos,int x,int y,int z,int w)
{
    if(pos==0)
    {

        if(x&&y&&z)
        {
            sum++;
            //printf("%d\n",w);
        }
        return ;
    }
    int tnt=0;
    if(!x) tnt++;
    if(!y) tnt++;
    if(!z) tnt++;
    if(tnt>pos) return ;
    if(n>=(w*10+3)*b[pos-1])
        dfs(pos-1,x+1,y,z,w*10+3);
    if(n>=(w*10+5)*b[pos-1])
        dfs(pos-1,x,y+1,z,w*10+5);
    if(n>=(w*10+7)*b[pos-1])
        dfs(pos-1,x,y,z+1,w*10+7);

}
int main()
{
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        init(n);
        /*for(int i=len;i>=1;i--)
            printf("%d",a[i]);
        printf("\n");*/
        for(int i=3;i<=len;i++)
        {
            if(n>=(3)*b[i-1])
                dfs(i-1,1,0,0,3);
            if(n>=(5)*b[i-1])
                dfs(i-1,0,1,0,5);
            if(n>=(7)*b[i-1])
                dfs(i-1,0,0,1,7);
        }
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = 998244353;
const int N = (int)2e5 + 5;

void solve(){
	string s;
	cin>>s;
	string str[3]={"Sunny", "Cloudy","Rainy"};
	if(s==str[0])cout<<str[1];
	else if(s==str[1])cout<<str[2];
	else if(s==str[2])cout<<str[0];

}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int n, c[50], v[50],m;
int mc[50], mv[50];
void tomar(int sumc, int sumv, int pos){
    if(pos == n){
        if(sumv - sumc > m){
            m = sumv - sumc;
        }
        return;
    }
    if(mc[pos] == 1 or mv[pos] == 1){
        return;
    }
    mc[pos] = 1;
    mv[pos] = 1;
    tomar(sumc+c[pos], sumv+v[pos], pos+1);
    tomar(sumc, sumv, pos+1);
    mc[pos] = 0;
    mv[pos] = 0;
}

int main(){
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%d", &v[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%d", &c[i]);
    }
    tomar(0,0,0);
    printf("%d", m);
    return 0;
}


Measured memory_bytes: 128
// i wanna find something i wanted all along
// somewhere i belong

#include <bits/stdc++.h>
#include <vector>

#define s second
#define f first
#define pb push_back
//#define int ll

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const long long MAX=3e2+85,INF=1e5+7,mod=998244353;

ll n,m,t[5];
//string s;
//set<int>st;
//bool mark[MAX];
//int dx[2]={0,1};
//int dy[2]={1,0};
//pii p[MAX];
//vector <int> v1,v2;
//multiset <int> st;
//queue <pii> q;
//map<pii,int> dp;
//map <pii,bool> mark;
//deque <int> dq;
double dp[MAX][MAX][MAX],ans;

void solve()
{
    cin >> n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        t[x]++;
    }
    for(int k=0;k<=n;k++)
    {
        for(int j=0;j<=n;j++)
        {
            for(int i=0;i<=n;i++)
            {
                if(!i&&!j&&!k) continue;
                if(i)
                {
                    dp[i][j][k]+=dp[i-1][j][k]*i;
                }
                if(j)
                {
                    dp[i][j][k]+=dp[i+1][j-1][k]*j;
                }
                if(k)
                {
                    dp[i][j][k]+=dp[i][j+1][k-1]*k;
                }
                dp[i][j][k]+=n;
                dp[i][j][k]/=(i+j+k);
            }
        }
    }
    cout << setprecision(15) << dp[t[1]][t[2]][t[3]];
}

main()
{
    ios_base::sync_with_stdio(0);
    solve();
    return -0;
}


Measured memory_bytes: 350208
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>
#include <set>
#include <functional>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    cout << min(b / a, c) << endl;
    return 0;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def main():
    X = int(input())
    x = make_divisors(X)
    for i in range(1, int(X**0.5)+1):
        for j in x:
            B = i-j
            if i**5-B**5==X:
                print(i,B)
                break
        else:
            continue
        break
main()    

Measured memory_bytes: 9460
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

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

using namespace std;

int main(){
    int a[5];
    int k;
    bool flag = true;

    rep(i, 5)   cin >> a[i];
    cin >> k;
    for (int i=0; i<4; i++){
        for (int j=i+1; j<5; j++){
            if (a[j] - a[i] > k){
                flag = false;
                break;
            }
        }
        if (!flag) break;
    }

    if (flag)   cout << "Yay!" << endl;
    else        cout << ":(" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int A[200100];
int W[200100];
int n;
int a;
 
long long int merge_and_count(int l, int r)
{
    if(l+1 >= r)
    {
        return 0;
    }
    if(l+2 == r)
    {
        if (A[l] <= A[l+1])
        {
            return 0;
        }
        swap(A[l], A[l+1]);
        return 1;
    }
     
    int m = (l+r)/2;
    long long int cl = merge_and_count(l, m);
    long long int cr = merge_and_count(m, r);
    long long int c = 0;
    int x=l, y=m;
    int k=l;
    while (x<m && y<r)
    {
        if(A[x] <= A[y])
        {
            W[k] = A[x];
            k = k + 1;
            x = x + 1;
        }
        else
        {
            W[k] = A[y];
            c = c + m - x;
            k = k + 1;
            y = y + 1;
        }
    }
     
    while (x<m)
    {
        W[k] = A[x];
        k = k + 1;
        x = x + 1;
    }
    while (y<r)
    {
        W[k] = A[y];
        k = k + 1;
        y = y + 1;
    }
    assert(k == r);
    copy(W+l, W+r, A+l);
    return cl + cr + c;
}
 
int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &a);
        A[i] = a;
    }
    cout << merge_and_count(0, n) << endl;
}

Measured memory_bytes: 4776
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int R, G, B, n;
    cin >> R >> G >> B >> n;
    ll ans = 0;
    for(int i = 0; i <= n / R; i++){
        for(int j = 0; j <= n / G; j++){
            int sum = i * R + j * G;
            if(n >= sum && (n - sum) % B == 0){
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

int main(){
    double p[2];
    int cnt[2][4];
    for(int i=0; i<2; ++i)
        for(int j=0; j<4; ++j) cnt[i][j] = 0;
    while(cin >> p[0] >> p[1]){
        for(int i=0; i<2; ++i){
            if(p[i] >= 1.1) ++cnt[i][0];
            else if(p[i] >= 0.6) ++cnt[i][1];
            else if(p[i] >= 0.2) ++cnt[i][2];
            else ++cnt[i][3];
        }
    }
    for(int j=0; j<4; ++j) cout << cnt[0][j] << " " << cnt[1][j] << endl;
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 long double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  101LL
#define tmod             998244353LL
using namespace std;

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

ll Powb(ll b,ll n,ll m);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
ll P[N+1];
void Sieve(int n=N);

int main()
{
fast;
ll q=1,t;
//cin >> q; t = q;
while(q--)
{
    ll i,j,n,m,k,l=0,r=0,a=1,b=0,c=0,d=0,e,g=1,p,u,v,w,x,y,flag=1;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
    cin >> n;
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            if(i*j==n) {cout << "Yes"; return 0;}
        }
    }
    cout << "No";
}

    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    //memset(P,true,sizeof(P));
    //P[0] = false;
    //P[1]= false;
    for(int i=1;i<=n;i++) P[i] = i;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i]==i)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                if(P[j]==j)
                    P[j]=i;
            }
        }
    }

}



Measured memory_bytes: 3640
#include <cstdio>

int main(){

  int t,i,m,e,x,y,sum;

  scanf("%d",&t);
  scanf("%d",&i);
  scanf("%d",&m);
  scanf("%d",&e);

  sum = t + i + m + e;

  x = sum / 60;
  y = sum % 60;

  printf("%d\n%d\n",x,y);

  return 0;

}

Measured memory_bytes: 1024
import java.util.*;
 
class Main {
  
    public static void main(String[] args) {
      
      
        Scanner sc = new Scanner(System.in);
         String A = sc.nextLine();
         char N = A.charAt(0);
      
      if(N=='A'){System.out.print('T');}
      else if(N=='T'){System.out.print('A');}
      else if(N=='G'){System.out.print('C');}
      else if(N=='C'){System.out.print('G');}
      
	
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int n; cin >> n;
	int ans = 0;

	for (int i = 1; i <= n; ++i)
		if ((i % 5) && (i % 3))
			ans += i;

	cout << ans;
	return 0;
}


Measured memory_bytes: 3656