akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int a[100001],l,m,n;
  int mx;
  while(cin>>n>>m&&n+m){
    memset(a,0,sizeof(a));
    for(i=0;i<m;i++){
      cin>>l;
      a[l]=1;
    }
    mx=1;
    if(a[0]){
      for(i=1;i<n+1;i=j){
	for(;i<n+1&&a[i]==0;i++);
	for(j=i;j<n+1&&a[j];j++);
	if(j<n+1&&a[j+1]){
	  for(k=j+1;k<n+1&&a[k];k++);
	  if(k-i>mx)
	    mx=k-i;
	}else{
	  if(j-i>mx)
	    mx=j-i;
	}
      }
    }else{
      for(i=1;i<n+1;i=j){
	for(;i<n+1&&a[i]==0;i++);
	for(j=i;j<n+1&&a[j];j++);
	if(j-i>mx)
	  mx=j-i;
      }
    }
    cout<<mx<<endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    n,p = map(int,input().split(" "))
    if n == 0 and p == 0:
        break
    P = [0 for i in range(n)]
    i = 0
    wan = p
    while P[i] != p:
        if wan == 0:
            wan = P[i]
            P[i] = 0
        else:
            P[i] += 1
            wan -= 1
        i = (i+1)%n
    print(i%n)

Measured memory_bytes: 6720
#include <bits/stdc++.h>
using namespace std;
int main (){
int x1,x2,x3,x4,x5;
    cin >>x1>>x2>>x3>>x4>>x5;
    
    if (x1==0){cout <<"1"<<endl;}
    else if (x2==0){cout <<"2"<<endl;}
    else if (x3==0){cout <<"3"<<endl;}
    else if (x4==0){cout <<"4"<<endl;}
    else if (x5==0){cout <<"5"<<endl;}
    
   }

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

int main()
{
  string s, t;
  cin >> s >> t;
  if(strncmp(s.c_str(), t.c_str(), s.size()) == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<ll>A(N);
    map<ll, ll>mp;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        mp[A[i]] += 2;
    }

    sort(A.begin(), A.end(), greater<ll>());
    ll ans = 0;
    N--;
    mp[A[0]]--;
    int i = 0;
    while (true) {
        if (N > mp[A[i]]) {
            ans += A[i] * mp[A[i]];
            N -= mp[A[i]];
            mp[A[i]] = 0;
            i++;
        } else {
            ans += A[i] * N;
            break;
        }
        if (N == 0) {
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 17180
#include <bits/stdc++.h>
#define For(i, a, b) for(register int (i) = (a); (i) <= (b); ++(i))
#define ForDown(i, a, b) for(register int (i) = (a); (i) >= (b); (i)--)
using namespace std;
int F() {
	register int x = 0, ch = getchar(), f = 0;
	while(!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}
string s;
int n;
int main() {
	cin >> n >> s;
	For(i, 0, s.length()) s[i] = (s[i] - 'A' + n) % 26 + 'A';
	cout << s;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
dp = [-1]*(n+1)
for i in range(m):
    dp[int(input())] = 0
dp[0] = 1
if dp[1] != 0:
    dp[1] = 1
for i in range(2,n+1):
    if dp[i] != 0:
        dp[i] = (dp[i-1]+dp[i-2])%1000000007
print(dp[n])

Measured memory_bytes: 6900
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;
// constexpr int mod = 998244353;

int sum[505][505];

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

    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 0; i < m; ++i){
        int l, r;
        cin >> l >> r;
        ++sum[l][r];
    }
    for(int i = 1; i <= n + 1; ++i){
        for(int j = 1; j <= n + 1; ++j){
            sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
        }
    }
    for(int i = 0; i < q; ++i){
        int l, r;
        cin >> l >> r;
        --l;
        int ans = sum[r][r] - sum[l][r] - sum[r][l] + sum[l][l];
        cout << ans << endl;
    }
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR(i,k,n) for(ll i=(k);(k)<(n)?i<(n):i>(n);(k)<(n)?i+=1:i-=1)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int INF = 1<<29;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< ll > vi;
typedef vector< vi > vvi;
typedef pair< ll,ll > ii;
#define F first
#define S second
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define sz(a) ll((a).size())
#define all(o) (o).begin(), (o).end()
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define TR(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
template<class T> T** arr2D(int n,int m,T init){
    T** mat=new T*[n];
    FOR(i,0,n){
        mat[i]=new T[m];
        FOR(j,0,m){
            mat[i][j]=init;
        }
    }
    return mat;
}
template<class T> void initialise(T** mat,T init,int n,int m){
    FOR(i,0,n){
        FOR(j,0,m){
            mat[i][j]=init;
        }
    }
}
template<class T> void destroy(T** mat,int n,int m){
    FOR(i,0,n){
        delete[] mat[i];
    }delete[] mat;
}
const int MOD = 1000000007;
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }

/////////////////////////////////////////////////////////////////////
void solve(){
    int N;
    cin>>N;
    vector<vector<int>> mat(N,vector<int>(3,0));
    FOR(i,0,N){
        FOR(j,0,3){
            cin>>mat[i][j];
        }
    }
    vector<vector<ll>> happiness(N,vector<ll>(3,0));
    FOR(i,0,3)happiness[0][i]=mat[0][i];
    FOR(i,1,N){
        FOR(j,0,3){
            FOR(k,1,3){
                chmax(happiness[i][j], happiness[i-1][(j+k)%3]+mat[i][j]);
            }
        }
    }
    ll ans=0;
    FOR(i,0,3){
        chmax(ans,happiness[N-1][i]);
    }
    cout<<ans<<'\n';
}
int main()
{
    fastio
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    ull t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 14224
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>

using namespace std;


int main()
{
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u)
    {
        cout << a - 1 << " " << b << '\n';
    }
    else
    {
        cout << a << " " << b - 1 << '\n';
    }
    
    return 0;
}

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

void resources(vector<int> numbers){
  int min = numbers[0];
  int max = numbers[1] - numbers[0];

  for(int i = 1;i < numbers.size();i++){
    if(max < (numbers[i] - min))max = (numbers[i] - min);
    if(min > numbers[i])min = numbers[i];
  }
  cout << max << endl;
}

int main(){
  int n;
  vector<int> num;

  cin >> n;
  for(int i = 0;i < n;i++){
    int input;
    cin >> input;
    num.push_back(input);
  }

  resources(num);
}



Measured memory_bytes: 4700
#include<bits/stdc++.h>
#define M 5005
#define N 55
#define X 4
using namespace std;
typedef pair<int,int> P;
int x,y,z,v[X],n,e,a;
double memo[N][M];
P d[N];

double dfs(int u,int sum){
  int nu=u,nsum=sum;
  if(d[u].first==1)nu=min(y,u+d[u].second);
  if(d[u].first==2)nsum+=d[u].second;
  if(d[u].first==3)nsum=max(0,nsum-d[u].second);
  if(nu==y)return nsum;
  if(memo[nu][nsum]!=-1)return memo[nu][nsum];
  double res=0;
  for(int i=0;i<x;i++){
    int nnu=min(y,nu+v[i]);
    res+=dfs(nnu,nsum);
  }
  return memo[nu][nsum]=res/x;
}

int main(){
  while(1){
    cin>>x>>y>>z;
    if(!x&&!y&&!z)break;
    for(int i=0;i<N;i++)
      for(int j=0;j<M;j++)memo[i][j]=-1;
    for(int i=0;i<N;i++)d[i]=P(0,0);
    for(int i=0;i<x;i++)cin>>v[i];
    for(int i=0;i<z;i++){
      cin>>n>>e>>a;
      d[n]=P(e,a);
    }
    cout<<(int)dfs(0,0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3312
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	string s, t, u;
	ll a, b;
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if (s == u)
		a--;
	else if (t == u)
		b--;
	cout << a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] tmp = br.readLine().split(" ");
        int a = Integer.parseInt(tmp[0]);
        int b = Integer.parseInt(tmp[1]);

        int ans = 0;
        for(int i = 0; i < 2; i++) {
            if(a > b) {
                ans += a;
                a--;
            }else {
                ans += b;
                b--;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 20948
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n, minp=INF, cnt = 0;
    cin>>n;
    vi p(n);
    rep(i,n){
        cin >> p[i];
    }
    rep(i,n){
        if(minp>p[i]){
            minp = p[i];
            cnt++;
        }
    }
    out(cnt);
}

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

int main() {
    int x, y;
    cin >> x >> y;
    
    rep(i,x+1) {
        int leg = 4*i + 2*(x-i);
        if(leg == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(){
	int h,w,i,j,x;
	char c[200][200];
	scanf("%d %d",&h,&w);
	for(i=1;i<=h;i++)
		for(j=1;j<=w;j++)
			scanf(" %c",&c[i][j]);
	for(i=1;i<=2*h;i++){
		for(j=1;j<=w;j++){
			x=(i+1)/2;
			printf("%c",c[x][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
if b-a>=673:
    print(0)
else:
    x=[]
    for i in range(a, b):
        for j in range(i+1, b+1):
            x.append((i*j)%2019)
    print(min(x))

Measured memory_bytes: 6804
var stdin = require("fs").readFileSync("/dev/stdin", "utf8");
stdin = stdin.trim().split("\n");
var stdout = [];
function print(x){stdout.push(x)};


var menu = stdin.map(n=>parseInt(n));
var d = [];
var ans = 0
for (i=0; i < 5; i++){
    d.push((menu[i]-1) % 10)
    ans += parseInt((menu[i]+9)/10) * 10
}

d.sort()
print(ans - 10 + d[0] + 1);


stdout = stdout.join("\n");
console.log(stdout);

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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second
#define pii pair<int, int>



void solve() {
    int n;
    cin >> n;

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int l = 1, r = (n - (n % i)) / i;
        if (!(n % i))
            r--;
        ans += r - l + 1;
    }
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int M, N;
double dp[17][17][1 << 16];
double p[17][17];

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

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> M >> N;
    for(int i = 0; i < M; i++) {
        for(int j = 0; j < N; j++) {
            cin >> p[i][j];
        }
    }
    for(int i = 1; i < (1 << M); i++) {
        for(int j = 0; j < M; j++) {
            if((1 << j) & i) {
                //cerr << N << " " << j << " " << i << " " << 1 << endl;
                dp[N][j][i] = 1;
            }
        }
    }
    for(int i = N - 1; i >= 0; i--) {
        for(int j = 0; j < (1 << M); j++) {
            for(int k = 0; k < M; k++) {
                if(!(j & (1 << k))) continue;
                double now = p[k][i] * dp[i+1][k][j];
                double losemax = 0;
                int subbits = (j & (~(1 << k)));
                //cerr << subbits << endl;
                for(int l = 0; l < M; l++) {
                    if(!(subbits & (1 << l))) continue;
                    chmax(losemax, dp[i][l][subbits]);
                }
                now += (1 - p[k][i]) * losemax;
                chmax(dp[i][k][j], now);
                //cerr << i << " " << k << " " << j << " " << now << " " << losemax << endl;
            }
        }
    }
    double ans = 0;
    for(int i = 0; i < M; i++) {
        chmax(ans, dp[0][i][(1 << M) - 1]);
    }
    cout << fixed << setprecision(30) << ans << endl;
    return 0;
}


Measured memory_bytes: 120816
n,*s=map(int,open(0).read().split());s,t,f,g=[s[i-n:i]for i in range(n,4*n+1,n)];a=[n*[0]for _ in range(n)]
for b in range(64):
  e=1<<b;u=[k&e for k in f];v=[k&e for k in g];l=[0]*n;m=l[:]
  for i in range(n):
    for j in range(n):
      if(u[i]&v[j])|((s[i]^1)*u[i])|((t[j]^1)*v[j]):a[i][j]|=e;l[i]+=1;m[j]+=1
  for i in range(n):
    if s[i]*u[i]*(l[i]==0):
      for j in range(n):
        if(t[j]^1)*(n-m[j]>1):a[i][j]|=e;m[j]+=1;break
  for j in range(n):
    if t[j]*v[j]*(m[j]==0):
      for i in range(n):
        if(s[i]^1)*(n-l[i]>1):a[i][j]|=e;l[i]+=1;break
h=a[0][:];w=[i[0]for i in a]
for i in range(n):
  for j in range(n):w[i]=(w[i]|a[i][j]if s[i]else w[i]&a[i][j]);h[j]=(h[j]|a[i][j]if t[j]else h[j]&a[i][j])
if(g!=h)|(f!=w):print(-1);exit() 
for i in a:print(*i)

Measured memory_bytes: 100224
#include<bits/stdc++.h>
#define reg register
#define maxn 200001
using namespace std;
int nt[maxn << 1], fi[maxn], go[maxn], d[maxn], rt;
int dp[maxn], n, sum, sumx, siz[maxn], ans, cnt;
char s[maxn];
vector<int> Q[maxn];
inline int  read() {
    reg int s = 0, t = 0; reg char ch = getchar();
    while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
    while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}
void add(int u, int v){
	nt[++cnt] = fi[u]; fi[u] = cnt; go[cnt] = v;
}
void dfs(int u, int fa){
	siz[u] = (s[u] == 'W'); 
	for(int i = fi[u]; i; i = nt[i]){
		int v = go[i]; if(v == fa) continue;
		dfs(v, u); siz[u] += siz[v];
		if(siz[v] != ans && siz[v] != 0){
			Q[u].push_back(v); Q[v].push_back(u);
		}
	}
}
void find(int x, int fa){
	sum += 2;  d[x] = 0;
	if(s[x] == 'W' && Q[x].size() % 2 == 0) sum += 1, d[x] = 2;
	if(s[x] == 'B' && Q[x].size() % 2 == 1) sum += 1, d[x] = 2;
	for(int i = 0; i < Q[x].size(); i++){
		int v = Q[x][i]; if(v == fa) continue;
		find(v, x);
	}
}
void solve(int x, int fa){
	dp[x] = d[x]; int maxx = 0, cmaxx = 0;
	for(int i = 0; i < Q[x].size(); i++){
		int v = Q[x][i]; if(v == fa) continue;
		solve(v, x); 
		if(dp[v] > maxx) cmaxx = maxx, maxx = dp[v];
		else if(dp[v] > cmaxx) cmaxx = dp[v];
		
	}
	sumx = max(sumx, maxx + cmaxx + d[x]);
	dp[x] += maxx;
}
int main()
{
	n = read();
	for(int i = 1; i < n; i++){
		int x = read(), y = read();
		add(x, y); add(y, x);
	}
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++) {
		ans += ((s[i] == 'W') ? 1 : 0);
		if(s[i] == 'W') rt = i;
	}
	if(ans == 0) {puts("0\n"); return 0;}
	if(ans == 1) {printf("1\n"); return 0;}
	dfs(1, 0);  find(rt, 0);
	sum = sum - 2; 	solve(rt, 0);
	cout << sum - sumx << endl;
	return 0;
}


Measured memory_bytes: 21376
import networkx as nx
import itertools

N, M = map(int, input().split())
G = nx.Graph()
G.add_nodes_from(range(1, N + 1))
G.add_weighted_edges_from([map(int, input().split()) for _ in range(M)])
S = nx.floyd_warshall(G)

ans = M
for i, j, d in G.edges(data=True):
    for s, t in itertools.combinations(G.nodes(), 2):
        if S[s][i] + d['weight'] + S[j][t] == S[s][t]:
            ans -= 1
            break
print(ans)


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

int main(){
    unsigned long long a, b, k;
    cin >> a >> b >> k;
    if(a == 0 && b == 0){
        cout << a << endl << b << endl;
        return 0;
    }
    else if(a > k){
        cout << a-k << endl << b << endl;
        return 0;
    }
    else if(b + a > k){
        cout << 0 << endl << b-k+a << endl;
        return 0;
    }
    else{
        cout << 0 << endl << 0 << endl;
        return 0;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i, n) ans += (i+1) * (n-i);
    rep(i, n-1) {
        ll u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);
        ans -= u * (n-v+1);
    }
    cout << ans << endl;
}

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

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll money = 1000;
    ll stock = 0;
    for(int i = 1; i < n; i++){
        if(a[i] > a[i-1]){
            stock = money / a[i-1];
            money += (a[i] - a[i-1]) * stock;
        }
    }
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
using Pl=pair<ll,ll>;
using PPl=pair<ll,Pl>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,m;
    cin>>n>>m;
    vi vec(n);
    ll ans=0;
    REP(i,n){
        cin>>vec[i];
        vec[i]%=m;
    }
    map<int,ll> ma;
    int sum=0;
    ma[0]++;
    REP(i,n){
        sum+=vec[i];
        sum%=m;
        ans+=ma[sum];
        ma[sum]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define MAXN 105
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m;
char str[MAXN][MAXN];
int dp[MAXN][MAXN];
void upd(int &a,int b) {a=min(a,b);}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) scanf("%s",str[i]);
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            dp[i][j]=INF;
    if(str[0][0]=='#') dp[0][0]=1; else dp[0][0]=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        {
            if(i==0&&j==0) continue;
            if(i>0)
            {
                if(str[i][j]=='.'||str[i-1][j]=='#') upd(dp[i][j],dp[i-1][j]);
                else upd(dp[i][j],dp[i-1][j]+1);
            }
            if(j>0)
            {
                if(str[i][j]=='.'||str[i][j-1]=='#') upd(dp[i][j],dp[i][j-1]);
                else upd(dp[i][j],dp[i][j-1]+1);
            }
        }
    printf("%d\n",dp[n-1][m-1]);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<math.h>
    #include<string>
    #include<algorithm>
    using namespace std;
     
     
    int ans[60];
    int found;
     
    int main(){
    	
    	for(int i=6;found<=60;i+=5){
    		bool b=true;
    		for(int j=2;j<=sqrt(i);j++){
    			if(i%j==0)b=false;
    		}
    		if(b){
    			ans[found]=i;
    			found++;
    		}
    	}
    	
    	int n;cin>>n;
    	for(int i=0;i<n;i++)cout<<ans[i]<<" ";
    	
    	return 0;
    }

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
int rd() {
	int a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, c>9&c!=253);
	for(a=(b = c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
const int N=1e6+1, M=1.5e6;
int head[N], to[M*2], next[M*2], deg[N], vis[M], handle[N/2];
int add(int u, int v) {
	static int e=0;
	vis[e/2]=-1;
	++deg[u], ++deg[v];
	to[e]=v, next[e]=head[u], head[u]=e++;
	to[e]=u, next[e]=head[v], head[v]=e++;
	return e/2-1;
}
void dfs(int u) {
	for(int &i=head[u]; i!=-1; i=next[i])
		if(vis[i/2]==-1) {
			vis[i/2]=i%2;
			dfs(to[i]);
		}
}
int main() {
	int n;
	n=rd();
	memset(head, -1, (2*n+1)*sizeof(int));
	for(int i=0; i<n; ++i) {
		int pa=rd();
		add(i*2+1, pa!=-1?pa*2-1:0);
	}
	for(int i=0; i<n; ++i) {
		int pa=rd();
		add(i*2+2, pa!=-1?pa*2:0);
	}
	for(int i=0; i<n; ++i) {
		if(deg[i*2+1]%2!=deg[i*2+2]%2) {
			puts("IMPOSSIBLE");
			return 0;
		}
		handle[i] = deg[i*2+1]%2==1?add(i*2+1, i*2+2):-1;
	}
	puts("POSSIBLE");
	dfs(1);
	for(int i=0; i<n; ++i) printf("%d ", handle[i]==-1?0:vis[handle[i]]==0?1:-1);
	puts("");
	return 0;
}


Measured memory_bytes: 22016
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int s,a=0,cnt=1;
  vector<int> lis;
  bool f=false;
  cin >> s;
  lis.push_back(s);
  while(f==false){
    cnt++;
    if(s%2==0) a=s/2;
    else a = 3*s + 1;
    for(int i=0;i<lis.size();i++){
      if(a==lis[i]){
        f=true;
        break;
      }
    }
    lis.push_back(a);
    s = a;
  }
  cout << cnt<<endl;




}


Measured memory_bytes: 256
N=int(input())
S=input()
str="ABC"
c=0
i=2
while i<=N-1:
    if S[i] == "C":
        if S[i-1]=="B":
            if S[i-2]=="A":
                c+=1
                i+=3
            else:
                i+=3
        else:
            i+=3
    else:
        i+=1
print(c)

Measured memory_bytes: 9140
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}



///////////////////////////


int main() {
	
	ll H;
	cin >> H;
	ll log=0;

	while (H > 0) {
		H /= 2;
		log++;
	}

	ll ans = 1;

	repn(i, log) { ans *= 2; }
	ans -= 1;
	cout << ans;


	
	
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

using ull = unsigned long long;

int main(int argc, char** argv)
{
    ull A;
    std::string Bstr;
    cin >> A;
    cin >> Bstr;
    auto point = Bstr.find('.');
    Bstr.erase(Bstr.begin() + point);
    ull B100 = atoi(Bstr.c_str());

    ull ret100 = A * B100;
    cout << (ret100 / 100) << endl;

    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Linq;

class C
{
	static void Main()
	{
		var A = 1000000;
		Console.ReadLine();
		var a = new int[A + 1];
		foreach (var x in Console.ReadLine().Split().Select(int.Parse)) a[x]++;

		var c = new long[A + 1];
		for (var d = 1; d <= A; d++) c[d] = MInv(d);
		for (var d = 1; d <= A / 2; d++)
			for (var m = 2 * d; m <= A; m += d) c[m] = MSub(c[m], c[d]);

		var h = MInv(2);
		long s = 0;
		for (var d = 1; d <= A; d++)
		{
			long si = 0, si2 = 0;
			for (var m = d; m <= A; m += d)
			{
				if (a[m] == 0) continue;
				si = MAdd(si, MMul(a[m], m));
				si2 = MAdd(si2, MMul(a[m], MMul(m, m)));
			}
			s = MAdd(s, MMul(MMul(MSub(MMul(si, si), si2), h), c[d]));
		}
		Console.WriteLine(s);
	}

	const int M = 998244353;
	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
	static long MInv(long x) => MPow(x, M - 2);
	static long MInt(long x) => (x %= M) < 0 ? x + M : x;
	static long MAdd(long x, long y) => (x + y) % M;
	static long MSub(long x, long y) => MInt(x - y);
	static long MMul(long x, long y) => x * y % M;
	static long MDiv(long x, long y) => x * MInv(y) % M;
}


Measured memory_bytes: 37184
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;
int main()
{
	long long n,a[55],i,sum,num,key,k;
	while(scanf("%lld",&n)!=EOF)
	{
		for(i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		key=1;sum=0;
		while(key)
		{
			k=1;key=0;
			for(i=2;i<=n;i++)
			{
				if(a[i]>a[k])
				{
					k=i;
				}
			}
			if(a[k]>=n)
			key=1;
			if(key)
			{
				num=a[k]/n;
				sum+=num;
				a[k]=a[k]%n;
				for(i=1;i<=n;i++)
				{
					if(i!=k)
					a[i]+=num;
				}
			}
		}
		printf("%lld\n",sum);
	}
	return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    print(chr(ord(s)+1))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include<string>
#define pii pair<int,int>
#define fr(j,n) for(int j=0;j<n;j++)
#define f(n) for(int i=0;i<n;i++)
#define rt return 0;
#define sc second
#define fi first
#define i(n) int n;cin>>n;
#define pb(i) push_back(i);
#define rt return 0;
#define sz(a) a.size()
#define all(v) v.begin(),v.end()
#define ff(i,in,fi) for(int i=in;i<fi;i++)
//#define df int n;cin>>n;int a[n];fr(n){cin>>a[i];}5 8 7 14 55 19 9 2
using namespace std;
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define invect(data,n,commands) for(int xxx = 0;xxx<n;xxx++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define ll long long int
#define p(s) cout<<#s<<":"<<s<<'\n';
#define here(n) cout<<"here"<<n<<endl;
#define ios         ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
map<int,int> ma;
std::vector<int> v;

void solve()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n-1];
	f(n)
	cin>>a[i];
	f(n)
	cin>>b[i];
	f(n-1)
	cin>>c[i];
	int sum=0;
	f(n)
	{
		if(i==0)
		{
			sum+=b[a[i]-1];
			continue;
		}
		if(a[i-1]+1==a[i])
		{
			sum+=b[a[i]-1]+c[a[i]-2];
		}
		else
		{
			sum+=b[a[i]-1];
		}
	}
	cout<<sum;
}
signed main(){
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}


Measured memory_bytes: 256
N,M=map(x->parse(Int,x),split(readline()))
if N==1
	println(M)
	exit()
end
ans=1
i=2
while i*i<=M
	if M%i==0
		if div(M,i)>=N
			ans=max(ans,i)
		end
		if div(M,div(M,i))>=N
			ans=max(ans,div(M,i))
		end
	end
	i+=1
end
println(ans)


Measured memory_bytes: 111800
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
//using namespace atcoder;

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	map<int, int> ANum, BNum;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		ANum[A[i]]++;
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
		BNum[B[i]]++;
	}
	for (int i = 0; i <= N; i++) {
		if (ANum.find(i) == ANum.end() || BNum.find(i) == BNum.end()) continue;
		if (ANum[i] + BNum[i] > N) {
			cout << "No" << endl;
			return 0;
		}
	}
	reverse(B.begin(), B.end());
	int j1 = N - 1, j2= 0;
	for (int i = 0; i < N; i++) {
		if (A[i] == B[i]) {
			while ((A[i] == B[j1] || B[i] == A[j1]) && (A[i] ==B[j2] || A[j2] == B[i])) {
				j1--;
				j2++;
				if (j1 < 0) j1 = N - 1;
				if (j2 >= N) j2 = 0;
			}
			if (A[i] != B[j1] && B[i] != A[j1]) swap(B[i], B[j1]);
			else swap(B[i], B[j2]);
		}
	}
	cout << "Yes" << endl;
	for (int b : B) cout << b << " ";
	cout << endl;
}


Measured memory_bytes: 23404
while(True):
    a,op,b = input().split()
    if(op == '?'):
        break
    if(op == '+'):
        r = int(a) + int(b)
    if(op == '-'):
        r = int(a) - int(b)
    if(op == '*'):
        r = int(a) * int(b)
    if(op == '/'):
        r = int(a) / int(b)
    print(int(r))

Measured memory_bytes: 7660
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++14

int dp[MAX];
int rec(int n){
    if(n==0)return 0;
    if(dp[n]!=-1)return dp[n];

    int res=n;
    for(int pow6=1;pow6<=n;pow6*=6)res=min(res,rec(n-pow6)+1);
    for(int pow9=1;pow9<=n;pow9*=9)res=min(res,rec(n-pow9)+1);
    return dp[n]=res;
}
int main(){
    ll n;cin>>n;
    memset(dp,-1,sizeof(dp));
    cout<<rec(n)<<endl;
}

Measured memory_bytes: 7004
import math

n = int(input())
ans=2

def go(n,k):
	aux=1
	while(n%k==0):
		n/=k
	if n%k==1:
		return True
	return False

for i in range(2,n):
	if(i*i>n): 
		break
	if n%i==0:
		if(go(n,i)): 
			ans+=1
		if(i!=n/i and go(n,n/i)):
			ans+=1
n-=1

for i in range(2,n):
	if(i*i>n): 
		break
	if n%i==0: 
		ans+=1
		if(i!=n/i):
			ans+=1
if n==1:
	print("1")
else:
	print(ans)

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

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

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main(){
    string S,T;
    cin>>S>>T;
    int N = S.size(),M = T.size();
    bool can = false;
    int p=0;
    for(int i = N-M;i>=0;i--){
        bool ok = true;
        rep(j,M){
            if(S[i+j]!=T[j]&&S[i+j]!='?'){
                ok = false;
            }
        }
        if(ok){
            p=i;
          	can = true;
            break;
        }
    }
    if(!can) cout<<"UNRESTORABLE"<<endl;
    else{
        rep(i,N){
            if(i<p||i>=p+M){
                if(S[i]!='?') cout<<S[i];
                else cout<<'a';
            }
            else {
                cout<<T[i-p];
            }
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3560
import java.util.Scanner;
class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        while(true){
        	String T=sc.nextLine();
            if(T.equals("0")) break;
        	int sum=0;
            for(int i=0;i<T.length();i++){                
                sum+=Character.getNumericValue(T.charAt(i));
            }
            System.out.println(sum);
        }
        sc.close();
    }
}


Measured memory_bytes: 26604
#include <bits/stdc++.h>
using namespace std;
int main(){
    int k,x;
    while(cin >> k >> x){
    	int s = 0;
    	if(x - k + 1 < 0)
 			 s = -(x - k + 1);
        int a[200] = {0};
		for(int i = x - k + 1 + s; i <= k + s; i++)
  		 		a[i]=1;
	    for(int i = k+1+ s; i < k + x+s; i++)
    	    a[i]=1;    
		for(int i = x - k + 1+s; i < k + x+s; i++){
	    if(a[i]==1)
 	   	 	cout << i-s;
		if(i == k+x-1+s)
  	        cout << endl;
		else cout << " ";
	    }
    }
    return 0;
}


Measured memory_bytes: 256
// 2020-08-24 20:31:42
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const int inf = 1e9;
void answer() {
  int n, ma, mb;
  cin >> n >> ma >> mb;
  vector<int> a(n), b(n), c(n);
  rep(i, n) cin >> a[i] >> b[i] >> c[i];
  vector<vector<int> > dp(410, vector<int>(410, inf));
  dp[0][0] = 0;
  rep(i, n) {
    vector<vector<int> > p = dp;
    int mx = 10 * (i+1);
    REPC(aj, 1, mx) REPC(bj, 1, mx) {
      if(aj - a[i] >= 0 && bj - b[i] >= 0) {
        chmin(dp[aj][bj], p[aj - a[i]][bj - b[i]] + c[i]);
      }
    }
  }
  int ans = inf;
  REPC(aj, 1, 400) {
    if(aj % ma == 0) {
      int bj = aj / ma * mb;
      if(1 <= bj && bj <= 400) {
        chmin(ans, dp[aj][bj]);
      }
    }
  }
  if(ans == inf) ans = -1;
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 4624
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
struct node{
	int a,b;
}s[maxn];
bool cmp(node a,node b)
{
	return a.a<b.a;
}
int main()
{
	int n,m;
	int ant=0;
	ll ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&s[i].a,&s[i].b);
	}
	priority_queue<int>q;
	sort(s,s+n,cmp);
	for(int i=1;i<=m;i++)
	{
		while(s[ant].a<=i&&ant<n)
		{
			q.push(s[ant].b);
			ant++;
		}
		if(!q.empty())
		{
			ans+=q.top();
			q.pop();
		}
	}
	printf("%lld\n",ans); 
	return 0;
 } 

Measured memory_bytes: 1660
#include <cstdio>

bool is_sorted(int p[], int n) {
	for(int i = 0; i < n - 1; i++) {
		if(p[i] > p[i + 1]) {
			return false;
		}
	}
	return true;
}

void swap(int* a, int* b) {
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int n;
	int p[50];
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}

	int result = 0;
	for(int i = 0; i < n - 1; i++) {
		for(int j = i; j < n; j++) {
			swap(&p[i], &p[j]);
			result += is_sorted(p, n) ? 1 : 0;
			swap(&p[i], &p[j]);
		}
	}

	puts(result > 0 ? "YES" : "NO");

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int isprime(int x)
{
  if(x < 2) return 0;
  if(x == 2) return 1;
  else if(x % 2 == 0) return 0;
  for(int i = 3; i <= sqrt(x); i+=2){
    if(x % i == 0) return 0;
  }
  return 1;
}

int main()
{
  int A,B,cnt = 0;
  scanf("%d",&B);
  for(int i = 0; i < B; i++){
    scanf("%d",&A);
    if(isprime(A) == 1)
     cnt++;
  }
  printf("%d\n",cnt);
  return 0;
}





Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

int go(int a, int b) {
    int res = 1;
    for (int i = 0; i < b; i++) {
        res *= a;
    }
    return res;
}

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

    int n;
    cin >> n;
    string s = "";
    int len = 0;
    int tot = 0;
    while (n > tot) {
        tot += go(26, ++len);
    }
    for (int i = len - 1; i >= 1; i--) {
        n -= go(26, i);
    }
    n--;
    while (n > 0) {
        int k = n % 26;
        s = (char)('a' + k) + s;
        n /= 26;
    }
    while (s.size() < len) {
        s = 'a' + s;
    }
    cout << s << '\n';

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 3656
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i := 1; i < n; i++ {
		d[i] = d[i-1] + a[i-1]
	}
	var result int

	for i := 1; i < n; i++ {
		result += d[i] * a[i]
	}
	fmt.Println(result)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  if(s[0] == s[1] && s[1] == s[2]) {
    cout << "Yes" << endl;
    return 0;
  }
  if(s[1] == s[2] && s[2] == s[3]) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String O = sc.next();
        String E = sc.next();

        for(int i=0; i<O.length(); i++){
        	System.out.print(O.charAt(i));
        	if (i < E.length()){
        		System.out.print(E.charAt(i));
        	}
        }
    }
}

Measured memory_bytes: 20820
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N;
vector<int> even, odd;

int main(){
  ios_base::sync_with_stdio(false); 
  cin >> N;
  for(int i=0; i<N; ++i){
    int x; cin >> x;
    if((i+1)&1)
      odd.push_back(x);
    else
      even.push_back(x);
  }
  if(N&1){
    for(int i=(int)odd.size()-1; i>=0; --i)
      cout << odd[i] << " ";
    for(int i=0; i<(int)even.size(); ++i)
      cout << even[i] << " ";
  }
  else{ 
    for(int i=(int)even.size()-1; i>=0; --i)
      cout << even[i] << " ";
    for(int i=0; i<(int)odd.size(); ++i)
      cout << odd[i] << " ";
  }
  cout << "\n";
  return 0;
}

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    if(n*a<b){
        cout << n*a << endl;
    }else{
        cout << b << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

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

int main()
{
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  std::vector<long long> num(N+1, 0);
  for(auto& val: A)
    std::cin >> val;
  for(const auto& val: A)
    num[val]++;
  std::vector<bool> memo(N+1, false);
  long long P = ((num[A[0]]-1)*(num[A[0]]-2))/2;
  memo[A[0]] = true;
  for(size_t i = 1; i < A.size(); ++i)
  {
    auto val = A[i];
    if(!memo[val])
    {
      P += (num[val]*(num[val]-1))/2;
      memo[val] = true;
    }
  }
  std::vector<long long> ans(N, 0);
  ans[0] = P;
  for(size_t i = 1; i < A.size(); ++i)
  {
    auto prev = num[A[i-1]];
    auto cur = num[A[i]];
    ans[i] = ans[i-1] - ((prev-1)*(prev-2))/2 + (prev*(prev-1))/2 - (cur*(cur-1))/2 + ((cur-1)*(cur-2))/2;
  }
  for(auto& val: ans)
    std::cout << val << "\n";
  return 0;
}



Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    
    cout << A*B-A-B+1 << endl;
    
return 0;
}



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

typedef long long ll;

#define sz(v) (int)v.size()

void PLAY() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(10);
}



int main() {
	PLAY();
	
	int dist;
	int time;
	int vel;
	cin >> dist >> time >> vel;

	double x = 1.0 * dist / time;
	if (x <= vel)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 3532
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
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; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll dx[] = { 1, 0 , -1,  0 }, dy[] = { 0, 1, 0, -1 };
ll cb(ll a, ll b);

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

	ll l = 0, r = 0;

	rep(i, n) {
		if (l == 0 && s[i] == ')') r++;
		if (l > 0 && s[i] == ')') {
			l--;
		}
		if (s[i] == '(') l++;
	}

	rep(i, r) cout << '(';
	cout << s;
	rep(i, l) cout << ')';

	return 0;
}

ll cb(ll a, ll b) {
	ll ans = 1;
	rep(i, b) ans *= (a - i);
	rep(i, b) ans /= (b - i);

	return ans;
}


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

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define FIO ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
vector<int>adj[100];
int visited[100];
void bfs(int s,int n)
{
    for(int i=0; i<n; i++)
    {
        visited[i]=0;
        queue<int>Q;
        Q.push(s);
        visited[s]=1;
        while(!Q.empty())
        {
            int u=Q.front();
            Q.pop();
            for(int i=0; i<adj[u].size(); i++)
            {
                if(visited[adj[u][i]]==0)
                {
                    int v=adj[u][i];
                    visited[v]=1;
                    Q.push(v);
                }
            }
        }
    }
}
int gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    return (a*b)/gcd(a,b);
}

bool prime(int n)
{
    if(n<=1)
    {
        return 0;
    }
    for(int i=2; i*i<sqrt(n); i++)
    {
        if(n%i==0)
        {
            return 0;
        }
        return 1;
    }
}
long convert(int n)
{
    long binary = 0;
    int i = 1;
    //converting decimal to binary
    while (n!=0)
    {
        int rem = n%2;
        n /= 2;
        binary += rem*i;
        i *= 10;
    }
    return binary;
}
int binarySearch(int arr[], int lo, int hi, int x)
{
    if (hi >= lo)
    {
        int mid = lo + (hi - lo) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, lo, mid - 1, x);
        return binarySearch(arr, mid + 1, hi, x);
    }
    return -1;
}


int main()

   {
      int a,b,c;
      cin>>a>>b>>c;
      set<int>s;
      s.insert(a);
      s.insert(b);
      s.insert(c);
      (s.size()==2)?cout<<"Yes"<<endl:cout<<"No"<<endl;
   }


Measured memory_bytes: 256