akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    int N;
    cin >> N;
    vector<pair<int, pair<int, int>>> data(N);
    rep(i, N) {
        int x, y, h;
        cin >> x >> y >> h;
        data[i] = make_pair(h, make_pair(x, y));
    }
    sort(data.begin(), data.end(), greater<pair<int, pair<int, int>>>());
    rep(Cx, 101) {
        rep(Cy, 101) {
            int H_keep = -1;
            bool is_ok = true;
            rep(i, N) {
                int H = data[i].first + abs(data[i].second.first - Cx) + abs(data[i].second.second - Cy);
                if (data[i].first > 0) {
                    if (H_keep == -1) {
                        H_keep = H;
                    }
                    else {
                        if (H_keep != H) {
                            is_ok = false;
                        }
                    }
                }
                else {
                    if (H_keep - abs(data[i].second.first - Cx) - abs(data[i].second.second - Cy) > 0) {
                        is_ok = false;
                    }
                }
            }
            if (is_ok == true) {
                cout << Cx << " " << Cy << " " << H_keep << endl;
                return 0 ;
            }
        }
    }
    return 0;
}

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

if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()


ans = H*W
# 高さを変えて調べる
for h in range(1, H+1):
    a = h*W
    #残りを高さで割る場合
    b = ((H-h)//2) * W
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))


    #残りを幅で割る場合
    b = (H-h) * (W//2)
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))



# 幅を変えて調べる
for w in range(1, W+1):
    a = H*w
    #残りを高さで割る場合
    b = (W-w) * (H//2)
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))


    #残りを幅で割る場合
    b = ((W-w)//2) * H
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))

print(ans)

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

using namespace std;

const int N = 2008, MOD = 1e9 + 7;

namespace Numarare {
    int logpow (int b, int e) {
        int ans(1);
        while (e) {
            if (e&1)
                ans = 1LL * ans * b % MOD;
            b = 1LL * b * b % MOD;
            e>>=1;
        }
        return ans;
    }
    int f[N], invf[N];
    void activate() {
        f[0] = 1;
        for (int i = 1; i < N; ++i)
            f[i] = 1LL * f[i - 1] * i % MOD;
        invf[N - 1] = logpow(f[N - 1], MOD - 2);
        for (int i = N - 2; i >= 0; --i)
            invf[i] = 1LL * invf[i + 1] * (i + 1) % MOD;
    }

    int combinari(int n, int k) {
        return 1LL * f[n] * invf[k] % MOD * invf[n - k] % MOD;
    }

    int stars_and_bars(int ns, int nb) {///nb numere cu suma ns
        if (ns < 0 || nb < 0)
            return 0;
        return combinari(ns + nb - 1, nb - 1);
    }
}

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    Numarare::activate();
    for (int i = 1; i <= k; ++i)
        cout << 1LL * Numarare::stars_and_bars(n - k - i + 1, i + 1) * Numarare::stars_and_bars(k - i, i) % MOD << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main(){
  bool judge;
  char tmp[7],tmp2[7];
  int sta,sta2;
  char num[7],num2[7];
  cin >> sta;
  sta2 = sta;
  while(1){
    sprintf(num,"%d",sta);
    sprintf(num2,"%d",sta2);
    if(strlen(num) == 1) break;
    strcpy(tmp,num);
    strcpy(tmp2,num2);
    for(int i=0,j=strlen(tmp)-1;i<=j;i++,j--) swap(tmp[i],tmp[j]);
    for(int i=0,j=strlen(tmp2)-1;i<=j;i++,j--) swap(tmp2[i],tmp2[j]);
    if(strcmp(tmp2,num2) == 0){
      judge = false;
      break;
    }
    if(strcmp(tmp,num) == 0){
      judge = true;
      break;
    }
    sta = atoi(num);
    sta2 = atoi(num2);
    sta++;
    sta2--;
  }
  if(judge) cout << num << endl;
  else cout << num2 << endl;
}

Measured memory_bytes: 1212
n=int(input())
s=input()

R=s.count("R")
G=s.count("G")
B=s.count("B")
ans=R*G*B

for i in range(n-2):
    for j in range(i+1,n-1):
        k=2*j-i
        if k<n:
            if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                ans-=1

print(ans)
        



Measured memory_bytes: 9192
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

class Graph{
	private:
	int V;
	vvp List;
	void bfs(int v,int sv,int num,int cost,vb& used,Graph& gra){
		queue<P> que;
		que.push(P(v,num));
		used[v]=1;
		while(!que.empty()){
			P p=que.front();
			que.pop();
			if(!p.second) continue;
			for(auto i=List[p.first].begin();i!=List[p.first].end();i++){
				if(!used[(*i).first]){
					used[(*i).first]=1;
					gra.List[sv].push_back(P((*i).first,cost));
					que.push(P((*i).first,p.second-1));
				}
			}
		}
	}
	int DIJ(int s,int t){
		priority_queue<P> que;
		vi d(V,inf);
		d[s]=0;
		que.push(P(0,s));
		while(!que.empty()){
			P p=que.top();
			que.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(auto i=List[v].begin();i!=List[v].end();i++){
				int F=(*i).first,S=(*i).second;
				if(d[F]>d[v]+S){
					d[F]=d[v]+S;
					que.push(P(-d[F],F));
				}
			}
		}
		return d[t];
	}
	public:
	Graph(int v){
		V=v;
		List=vvp(v);
	}
	void add_edge(int s,int t){
		List[s].push_back(P(t,1));
		List[t].push_back(P(s,1));
	}
	int solve(vp a){
		Graph gra(V);
		for(auto i=a.begin();i!=a.end();i++){
			vb used(V);
			bfs(i-a.begin(),i-a.begin(),(*i).second,(*i).first,used,gra);
		}
		return gra.DIJ(0,V-1);
	}
};

int n,k;
vp a;

int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	Graph g(n);
	a=vp(n);
	for(auto i=a.begin();i!=a.end();i++){
		cin>>(*i).first>>(*i).second;
	}
	for(int i=0;i<k;i++){
		int s,t;
		cin>>s>>t;
		g.add_edge(s-1,t-1);
	}
	cout<<g.solve(a)<<endl;
}

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

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

const ll INF = 1LL << 62;
#define atcoder(int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int main() {

	int h, w;
	char a[110][110];
	cin >> h >> w;
	
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a[i][j];
		}
	}

	for (int i = 0; i <= h+1; i++) {
		for (int j = 0; j <= w+1; j++) {
			if (i == 0 || j == 0 || i == h + 1 || j == w + 1)cout << '#';
			else cout << a[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 103;
const int MAXW = 1e5 + 4;
long long dp[MAXN][MAXW * 2];
int w[MAXW];
int v[MAXN];
int main(){
    long long n, p, maxim = 0; cin >> n >> p;
    for(int i = 1; i <= n; ++i) cin >> w[i] >> v[i];
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < p; ++j){
            if(i != 0) dp[i][j] = max(dp[i - 1][j], dp[i][j]);
            if(j + w[i + 1] <= p) dp[i + 1][j + w[i + 1]] = dp[i][j] + v[i + 1];
        }
    }
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= p; ++j){
            maxim = max(maxim, dp[i][j]);
        }
    }
    cout << maxim ;
    return 0;
}


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


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

  int counter = 0;
  if (S[0] == T[0]) ++counter;
  if (S[1] == T[1]) ++counter;
  if (S[2] == T[2]) ++counter;


  cout << counter << endl;
}


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

ll gcd(ll x,ll y){
  if(x%y==0) return y;
  else gcd(y,x%y);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, m;
  string s, t;
  cin >> n >> m >> s >> t;
  ll G = gcd(n,m);
  ll L = (n*m)/G;
  
  bool can;
  if(s[0]!=t[0])can = false;
  else if(G==1) can = true;
  else{
    ll N = n/G;
    ll M = m/G;
    bool ok = true;
    for(ll i=1;i<G;i++){
      if(s[N*i]!=t[M*i]) ok = false;
    }    
    if(ok) can = true;
    else can = false;
  }
  if(can) cout << L <<endl;
  else cout << -1 << endl;
  return 0; 
}


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

typedef long long ll;

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

    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a >= k)
        cout << k;
    else if (a + b >= k)
        cout << a;
    else
    {
        ll n = k - a - b;
        cout << a - n;
    }

    return 0;
}

Measured memory_bytes: 3608
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const int INF2 = 1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

struct edge{int to,cap,rev; };

int ls = 2;
vector<edge> G[20000];
int level[20000],iter[20000];


void add_edge(int from,int to,int cap){
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size() - 1});
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty()){
		int v = que.front();que.pop();
		for(int i = 0;i < G[v].size();i++){
			edge &e = G[v][i];
			if(e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v,int t,int f){
	if(v == t) return f;
	for(int &i = iter[v];i < G[v].size();i++){
		edge &e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to]){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(){
	int flow = 0;
	while(1){
		bfs(ls);
		if(level[1] < 0) return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f = dfs(ls,1,INF)) > 0) flow += f;
	}
}

signed main(){
	int h,w,sx,sy,tx,ty;
	string field[300];
	int num[300][300];
	cin >> h >> w;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++) num[i][j] = -1;
	}
	for(int i = 0;i < h;i++) {
		cin >> field[i];
		for(int j = 0;j < w;j++){
			if(field[i][j] == 'S'){
				sx = i;
				sy = j;
				num[i][j] = 0;
			}else if(field[i][j] == 'T'){
				tx = i;
				ty = j;
				num[i][j] = 1;
			}
			else if(field[i][j] == 'o') num[i][j] = ls++;
		}
	}
	if(sx == tx || sy == ty){
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			if(num[i][j] != -1){
				for(int k = 0;k < h;k++){
					if(num[k][j] != -1 && k != i) add_edge(num[i][j] + ls,num[k][j],5000);
				}
				for(int k = 0;k < w;k++){
					if(num[i][k] != -1 && k != j) add_edge(num[i][j] + ls,num[i][k],5000);
				}
				if(num[i][j] >= 2) add_edge(num[i][j],num[i][j] + ls,1);
			}
		}
	}
	cout << max_flow() << endl;
	return 0;
}

Measured memory_bytes: 124928
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;
 int main(){
    string s; cin >> s;
    int a=10*(s[0]-'0')+s[1]-'0';
    int b=10*(s[2]-'0')+s[3]-'0';
   if(1<=a&&a<=12){
     if(1<=b&&b<=12) cout << "AMBIGUOUS" <<endl;
     else cout << "MMYY" <<endl;
   }else{
     if(1<=b&&b<=12) cout << "YYMM" <<endl;
     else cout <<"NA"<<endl;
   }
 }

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int array[]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    int K;
    scanf("%d",&K);
    printf("%d\n",array[K-1]);
    return 0;
    }

Measured memory_bytes: 128
n,m=map(int,input().split())
t=[0]*n
ans=0
temp=0
for i in range(n):
  at,bt=map(int,input().split())
  t[i]=[at,bt]
t.sort()
i=0
while True:
  if temp+t[i][1]>=m:
    ans=ans+t[i][0]*(m-temp)
    break
  else:
    ans=ans+t[i][0]*t[i][1]
    temp=temp+t[i][1]
    i=i+1
print(ans)

Measured memory_bytes: 20056
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

const long long int mod = 998244353;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
const long long int pl=1000000;

long long int a;

int main(){

    cout << fixed << setprecision(18);
    cin>>a;
    cout<<a*a*a+a*a+a<<endl;
}



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

int D, N;

int main() {
    cin >> D >> N;

    if (N == 100) N++;
    if (D == 0) {
        cout << N << endl;
        return 0;
    } else if(D == 1) {
        cout << 100 * N << endl;
    } else {
        // int zero_count = D * 2;
        // string zero_str(zero_count, '0');
        // printf("%d%s\n", N, zero_str.c_str());
        cout << 10000 * N << endl;
    }

    // int zero_count = D * 2;
    // if (N == 100) {
    //     D -= 2;
    // } else if (N % 10 == 0) {
    //     // 0は1つ
    //     D -= 1;
    // }
    // string zero_str(zero_count, '0');

    // printf("%d%s\n", N, zero_str.c_str());
}

Measured memory_bytes: 256
from fractions import gcd

n,x = map(int,input().split())
x_l =[int(i) for i in input().split()]
x_l.append(x)
x_l.sort()

diff=[]    
for i in range(n):
    diff.append(x_l[i+1]-x_l[i])

ans=0
for x_d in diff:
       ans = gcd(ans,x_d)
print(ans)


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

int main() {
  int n;
  cin >> n;
  for(int i=-1; i<n; i++) {
    string s;
    getline(cin,s);
    if(i==-1) continue;
    bool ck=false;
    for(int a=1; a<26; a++) {
      if(26%a!=0 || a==1) {
	for(int b=0; b<26; b++) {
	  char c[26];
	  for(int i=0; i<26; i++){
	    c[(i*a+b)%26]=i+'a';
	  }
	  string t=s;
	  for(int i=0; i<t.size(); i++){
	    if(t[i]!=' ') t[i]=c[t[i]-'a'];
	  }
	  if(t.find("that")!=-1 || t.find("this")!=-1) {
	    s=t;
	    ck=true;
	    break;
	  }
	}
      }
      if(ck) break;
    }
    
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 1220
#include <iostream>
using namespace std;
int main() {
    int h, w;
    cin >> h >> w;
    string s;
    int grid[h+2][w+2] = {};
    for (int i=0; i<h; i++) {
        cin >> s;
        for (int j=0; j<w; j++) {
            if (s[j] == '#') grid[i+1][j+1]++;
        }
    }
    int sum;
    for (int i=1; i<h+1; i++) {
        for (int j=1; j<w+1; j++) {
            if (grid[i][j] == 1) {
                sum = grid[i-1][j] + grid[i+1][j] + grid[i][j-1] + grid[i][j+1];
                if (sum == 0) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int X;
    cin >> X;
    int ans = 0;
    for (int b = 1; b <= X; ++b)
    {
        for (int p = 2; ; ++p)
        {
            const int a = pow(b, p);
            if (a > X) break;
            chmax(ans, a);
            if (b == 1) break;
        }
    }
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;

int main()
{
  int N, K; cin >> N >> K;
  cout << ((N+1)/2 >= K ? "YES" : "NO") << endl;
}

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


using namespace std;
//using namespace __gnu_cxx;

//const int MAXN = (int)1e5 + 5;


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int> arr(n);
    for (int &x : arr)
        cin >> x;
    sort(arr.rbegin(), arr.rend());
    long long ans = 0;
    for (int i = k; i < n; ++i) {
        ans += arr[i];
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3940
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

bool compare_string(string s, string t)
{
    for (size_t i = 0; i < s.size(); i++) {
        if (s[i] != '?' && s[i] != t[i]) {
            return false;
        }
    }
    return true;
}

int main()
{
    string s, t;
    cin >> s >> t;
    if (s.size() < t.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    vector<string> vs;
    for (int i = 0; i <= s.size() - t.size(); i++) {
        string ssub = s.substr(i, t.size());
        if (compare_string(ssub,t)) {

            string ans(s.size(), 'a');
            for (int j = 0; j < ans.size(); j++) {
                if (j >= i && j < i + t.size()) {
                    ans[j] = t[j - i];
                } else {
                    if (s[j] != '?') {
                        ans[j] = s[j];
                    }
                }
            }
            vs.push_back(ans);
        }
    }

    if (vs.empty()) {
        cout << "UNRESTORABLE" << endl;
    } else {
        sort(vs.begin(), vs.end());
        cout << vs.front() << endl;
    }
    return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())
f = 0
for i in range(k+1):
    if a < b * (2 ** i) and b * (2 ** i) < c * (2 ** (k-i)):
        f = 1

if f:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9176
//................ DON'T WISH IT WERE EASIER, WISH YOU WERE BETTER........................
//............ WHEN LIFE PUTS YOU IN TOUGH SITUATIONS, DONT SAY "WHY ME" SAY "TRY ME".......
 
#include <bits/stdc++.h>
#define fast  ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define pb emplace_back
#define endl "\n"
#define f first
#define mp make_pair
#define s second
#define delrep  v.erase(unique(v.begin(),v.end()),v.end());
#define all(a)  (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define sz(x)   (int)x.size()
#define lll __int64
const int N=1e6+10;
const int mod=998244353;
using namespace std;
typedef long long ll;
int get_second( pair<int, int> i ){ return i.second; } 
ll power(ll x,ll y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int trail_zero(int n){while (n % 10 == 0) n /= 10 ; return n;}
map<ll,ll> m1;
set<ll>set1; set<ll>st;
multiset<ll>s1;
map<pair<ll,ll>,ll> mx;
//vector<ll>a(N);
vector<pair<ll,ll>>vx;
vector<pair<pair<ll,ll>,ll>>vz;
vector<ll>val;
vector<pair<ll,ll>>val2;
map<char,int>m2;
char s111[N];
ll p2[N],p3[N];
bool vis[N]; string s[N];
ll h,k,g,x,ans=1,q,t,cnt=0,d=0,ansx=1e18,n,m;
stack<int>sx; queue<int>qx;
inline bool in (int x , int y) { return 1 <= x && x <n+1 && 1<= y && y <m+1; }
inline bool in2 (int x , int y) { return 0 <= x && x <n && 0<= y && y <m; }
bool check(int i,int j) { if(s[i][j]=='.') return true; else return false;   }
ll count_divisor(ll a)
{
  ll cnt=0;
  for(ll i=1;i*i<=a;i++)
  {
    if(a%i==0) { if(a/i!=i) cnt+=2; else cnt+=1; }
 
  }
  return cnt;
}
void primeFactors(ll n)
{
    while (n%2 == 0) { st.insert(2); n = n/2; }
    for (ll i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)  { st.insert(i);  n = n/i; }
    }
    if(n>2)  st.insert(n);
}
int pref[N],suff[N];
vector<vector<ll>>alp(26);
int a[2][505][505];
int main() 
{
   fast; string s,t; cin>>s>>t; for(int i=0;i<s.size();i++) alp[s[i]-'a'].pb(i+1);
   ll index=0,ans=0;
   for(ll i=0;i<t.size();i++)
     {      // tle if i generate seprate vector
       if(alp[t[i]-'a'].size()==0) return cout<<"-1",0;
       ll temp=upper_bound(alp[t[i]-'a'].begin(),alp[t[i]-'a'].end(),index)-alp[t[i]-'a'].begin();
       if(temp==alp[t[i]-'a'].size())  temp=0;
       ll y=alp[t[i]-'a'][temp];
       if(index<y) ans+=(y-index);  else { ans+=y; ans+=(s.size()-index); }
       index=y;
     }
     cout<<ans;
}
  

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

int n, l;
int a[200];
int s;
int as = 1e9;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> l;
    for(int i=0;i<n;i++)
    {
        a[i] = i + l;
        s += a[i];
    }
    for(int j=0;j<n;j++)
    {
        int s1 = 0;
        for(int i=0;i<n;i++)
        {
            if(i != j) s1 += a[i];
        }
        if(abs(s-as) > abs(s-s1)) as = s1;
    }
    cout << as;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define BIG 1000000000

using namespace std;

bool okay(int p, int k, vector<int> weights){
  int i;
  int sum = 0;
  int num_of_tracks = 1;
  int len = weights.size();
  for (i = 0; i < len; ++i){
    if(sum + weights.at(i) < p){
      sum += weights.at(i);
    }else{
      num_of_tracks++;
      if(weights.at(i) < p){
        sum = weights.at(i);
      }else{
        return false;
      }
    }
  }
  if(num_of_tracks <= k){
    return true;
  }
  return false;
}

int main(){
  int n, k, i;
  cin >> n >> k;
  vector<int> weights;
  for (i = 0; i < n; ++i){
    int w;
    cin >> w;
    weights.push_back(w);
  }
  int l = 0, h = BIG;
  while(l+1 < h){
    int m = (l+h)/2;
    if(okay(m, k, weights)) h = m; else l = m;
  }
  cout << l << endl;
}

Measured memory_bytes: 1932
def main():
    N = int(input())
    array = list(map(int, input().split()))
    set_array = list(set(array))
    if N != len(array):
        return "No"
    if N < 3:
        return "No"
    if len(set_array) == 1 and set_array[0] == 0:
        return "Yes"
    if len(set_array) == 3:
        for i in range(2):
            if array.count(set_array[i]) != array.count(set_array[i+1]):
                return "No"
        x = set_array[0]
        y = set_array[1]
        z = set_array[2]
        if x ^ y == z and y ^ z == x and x ^ z == y:
            return "Yes" 
    if len(set_array) == 2:
        x = min(set_array)
        y = max(set_array)
        if array.count(x)*2 == array.count(y):
            if x == 0 and y^y == 0 and 0^y == y:
                return "Yes"
    return "No"

print(main())

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll n, a;
  cin >> n;
  int ans = 100000;
  for(int i = 0; i < n; ++i)
  {
    cin >> a;
    int num = 0;
    while((a & 1) == 0)
    {
      a /= 2;
      num++;
    }
    ans = min(ans, num);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{ 
  int n,ans;
  cin>>n;
  ans=0;
  if(n>=105)ans++;
  if(n>=165)ans++;
  if(n>=195)ans++;
  if(n>=135){ans++;}
  if(n>=189){ans++;}
  cout<<ans;
  
}

Measured memory_bytes: 3540
def read_input():
    a, b, c = map(int, input().split())
    k = int(input())
    return a, b, c, k


def submit():
    a, b, c, k = read_input()

    target = max(a, b, c)
    rest = a + b + c - target

    for i in range(1, k+1):
        target *= 2

    print(rest + target)


if __name__ == '__main__':
    submit()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll m;std::cin >> m;
  std::cout << 48-m << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>

using namespace std;

typedef unsigned uint;
typedef long long Int;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }

int main()
{
	int n, m;
	while (cin >> n >> m, n && m){
		int field[1500], dice;
		for (int i = 1; i <= n; i++){
			cin >> field[i];
		}
		// goal = n
		int now = 1, ret = 0;
		bool f = false;
		for (int i = 0; i < m; i++){
			cin >> dice;
			if (!f) ret++;
			if (!f) now += dice;
			if (n <= now) f = 1;
			if (!f) now += field[now];
			if (n <= now) f = 1;
			if (now < 1) now = 1;
		}
		cout << ret << endl;
	}

    return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 100005;

struct CL
{
	ll b,l,r,ans;
	
	bool operator < (const CL &p)const
	{
		return ans > p.ans;
	}
}c[MAXN];

int n;

ll X,ans;

ll getans(ll v)
{
	ll sum = 0,MAX = 0;
	for (int i = 1;i <= v / X;i++)
		sum += c[i].ans;
	for (int i = 1;i <= n;i++)
	{
		ll val = 0;
		if (v % X >= c[i].b)
			val = c[i].l * c[i].b + c[i].r * (v % X - c[i].b);
		else
			val = c[i].l * (v % X);
		if (i <= v / X)
			MAX = max(MAX,val + sum - c[i].ans + c[v / X + 1].ans);
		else
			MAX = max(MAX,val + sum);
	}
	return MAX;
}

int main()
{
	scanf("%d%lld",&n,&X);
	for (int i = 1;i <= n;i++)
	{
		scanf("%lld%lld%lld",&c[i].b,&c[i].l,&c[i].r);
		ans -= c[i].l * c[i].b;
		c[i].ans = c[i].l * c[i].b + c[i].r * (X - c[i].b);
	}
	sort(c + 1,c + n + 1);
	ll low = 0,high = n * X;
	while (low < high)
	{
		ll mid = low + high >> 1;
		if (getans(mid) + ans >= 0)
			high = mid;
		else
			low = mid + 1;
	}
	printf("%lld\n",low);
	return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstring>
using namespace std;
const int w=20003;
char s[10005];
int x,y,_x,len,p,sum,q,now=1;
bool ws[2][2][40009];
int main(void)
{
	register int i;
	scanf("%s%d%d",s+1,&x,&y),len=strlen(s+1),x+=w,y+=w;
	while(now<=len&&s[now]=='F')++now,++_x;
	ws[0][0][w+_x]=1,ws[1][0][w]=1;
	while(now<=len)
	{
		++now,sum=0,p^=1,q^=p;
		while(now<=len&&s[now]=='F')++sum,++now;
		for(int i=w-len; i<=w+len; ++i)
			ws[p][q][i]=ws[p][q^1][i+sum]|ws[p][q^1][i-sum];
	}
	if(p==1&&ws[0][q^1][x]&&ws[1][q][y]||p==0&&ws[0][q][x]&&ws[1][q][y])puts("Yes");
	else puts("No");
	return 0;
}

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

using namespace std;


int main(){
	int n,k;
	vector<bool> bad(10,false);
	cin>>n>>k;
	for(int i=0;i<k;++i){
		int d;
		cin>>d;
		bad[d]=true;
	}
	
	vector<bool> good(100009,true);
	for(int i=1;i<=100000;++i){
		int n=i;
		while(n){
			int d=n%10;
			n/=10;
			if(bad[d])
				good[i]=false;
		}
	}
	for(int i=n;i<=100000;++i)
		if(good[i]){
			cout<<i<<"\n";
			break;
		}

	return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main() {
    
    vector<pair<int,int>> d(100000);
    int n,m;
    ll ans=0;
    
    cin >> n>>m;
    rep(i,0,n){
        cin >> d[i].first>>d[i].second;
    }
    
    sort(all(d));
    
    int i=0;
    while(m>0){
        ans+=(ll)d[i].first*min(d[i].second,m);
        m=m-d[i].second;
        i++;
    }
    
    cout << ans<<endl;
    
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod=1e9+7;

int main(){
  int h,w;cin>>h>>w;
  int maze[h][w]={};
  rep(i,h){
    string s;cin>>s;
    rep(j,w){
      if(s[j]=='.')maze[i][j]=1;
    }
  }
  ll dp[h][w]={};
  dp[0][0]=1;
  rep(i,h) rep(j,w){
    if(maze[i][j]==0)continue;
    if(i+1<h){
      if(maze[i+1][j]){
        dp[i+1][j]+=dp[i][j]%mod;
        dp[i+1][j]%=mod;
      }
    }
    if(j+1<w){
      if(maze[i][j+1]){
        dp[i][j+1]+=dp[i][j]%mod;
        dp[i][j+1]%=mod;
      }
    }
  }
  cout<<dp[h-1][w-1]<<endl;
}


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

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

  int X;
  cin >> X;

  int ans = 8 - ((X - 400) / 200);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3612
N=int(input())
Q=sorted([int(input()) for i in range(N)])
S=sum(Q)
mods=S%10
if mods!=0:
    ans=S
else:
    for n,i in enumerate(Q):
        if i%10!=0:
            ans=S-i
            break
        if n==N-1:
            ans=0
            break
print(ans)

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void dfs(string s, ll max, ll n){
	if(s.size()==n){
		cout<<s<<en;
		return;
	}
	s+="a";
	REP(i,max+1){
		dfs(s,max,n);
		s[s.size()-1]++;
	}
	dfs(s,max+1,n);
}

void solve(){
	ll n;
	cin>>n;
	string s="a";
	vector<string> ans;
	dfs(s,0,n);
	for(auto i:ans) cout<<i<<en;
}

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

    solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 1536
from itertools import permutations


def main():
    towns, roads, visit = map(int, input().split())
    visit_order = [int(x) - 1 for x in input().split()]
    dist = [[float("inf") for _ in range(towns)] for _ in range(towns)]
    for _ in range(roads):
        a, b, d = map(int, input().split())
        a -= 1
        b -= 1
        dist[a][b] = d
        dist[b][a] = d
    for k in range(towns):
        for i in range(towns):
            for j in range(towns):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    answer = float("inf")
    for p in permutations(visit_order):
        now = 0
        for i in range(visit - 1):
            now += dist[p[i]][p[i + 1]]
        answer = min(answer, now)
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 61272
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll ans=0;
    ll x=1;
    while(x<m)
    {
        x+=n-1;
        ans++;
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000009
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<ll> a,b;
	for(int i=0;i<n+1;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		b.pb(x);
	}
	ll ans = 0;
	for(int i=n-1;i>=0;i--){
		ans += min(a[i+1],b[i]);
		b[i] = max((ll)0,b[i]-a[i+1]);
		ans += min(a[i],b[i]);
		a[i] = max((ll)0,a[i]-b[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2548
#include<stdio.h>
#include<string.h>

int main(void){
  int K;
  char S[101];  
  
  
  scanf("%d", &K);
  scanf("%s", S);
  int LengthS = strlen(S);
  
  if (K >= LengthS) {
    printf("%s",S);
  }
  else if (K < LengthS){
    for (int i=0; i<K; i++ ){
    printf("%c",S[i]);
    }  
    printf("...");
  }  

return 0;
}

Measured memory_bytes: 1684
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#ifdef LOCAL
	#define debug(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define debug(...) 42
#endif

#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define mem(x,val) memset(x,val,sizeof x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

inline string getString(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string getLine(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
typedef long long ll;

const int S=100100;
int main()
{
	int n;
	while(~sf("%d",&n))
	{
		ll ara[n+5];
		for(int i=0;i<n;i++)sf("%lld",&ara[i]);

		ll ans=0;
		for(int i=1;i<n;i++)
		{
			if(ara[i]<ara[i-1])
			{
				ans+=ara[i-1]-ara[i];
				ara[i]=ara[i-1];
			}
		}
		pf("%lld\n",ans);
	}	
    return 0;
}



































Measured memory_bytes: 5252
import math
N, M = list(map(int,input().split()))
arr = []
arr_inv = []
M_new = int(math.sqrt(M))+1
for i in range(1,M_new):
    if M % i == 0:
        if i == M // i:
            arr.append(i)
        else:
            arr.append(i)
            arr_inv.append(M // i)
arr_inv.reverse()
arr = arr + arr_inv
for i in range(len(arr)):
    if arr[i] >= N:
        print(M // arr[i])
        break


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var grid = new int[3, 3];
            for(var i = 0; i < 3; i++)
            {
                var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                for (var j = 0; j < 3; j++)
                {
                    grid[i, j] = input[j];
                }
            }

            for(var i = 100; i >= -100; i--)
            {
                var suc = true;
                var A = new int[3];
                var B = new int[3];
                A[0] = i;
                B[0] = grid[0, 0] - A[0];
                
                for(var j = 1; j <= 2; j++)
                {
                    B[j] = grid[0, j] - A[0];
                }

                A[1] = grid[1, 0] - B[0];
                A[2] = grid[2, 0] - B[0];

                for (var j = 1; j <= 2; j++)
                {
                    if (grid[1, j] - B[j] != A[1]) suc = false;
                }

                for (var j = 1; j <= 2; j++)
                {
                    if (grid[2, j] - B[j] != A[2]) suc = false;
                }

                if (suc)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13268
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,a,ans;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);
	for(int i=1;i<=n;i++){
		in(a);
		if(i%2==1&&a%2==1)ans++;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
bool prime[1000001];
bool prime1(ll a)
{
  if(a<=1000000)
  {
    if(prime[a]==0)
      return true;
    return false;
  }
  else
  {
    for(ll i=2;i*i<=a;i++)
      if(a%i==0)
        return false;
    return true;
  }
}
int main()
{
  for(int i=2;i*i<=1000000;i++)
    if(prime[i]==0)
      for(int j=i*i;j<=1000000;j+=i)
        prime[j]=1;
  ll n,m;
  cin>>n>>m;
  ll g=__gcd(n,m);
  ll count=0;
  for(ll i=1;i*i<=g;i++)
  {
    if(g%i==0)
    {
      if(i*i==g){
      if(prime[i]==0)
        count++;}
      else
      {
        if(prime[i]==0)
        count++;
        if(prime1(g/i))
          count++;
      }
      
    }
  }
  cout<<count<<"\n";
}
  
        

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int main(){

    int n,m,l; cin >> n >> m >> l;
    vector<vector<int>> A(n,vector<int>(m));
    vector<vector<int>> B(m,vector<int>(l));
    rep(i,n)rep(j,m) cin >> A.at(i).at(j);
    rep(i,m)rep(j,l) cin >> B.at(i).at(j);

    rep(i,n){
        rep(j,l){
            ll sum = 0;
            rep(k,m) sum+= A.at(i).at(k)* B.at(k).at(j);
            cout << sum;
            if(j != l-1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int lot[31];
    int w,n;
    
    for(int i=1;i<=30;i++){
        lot[i]=i;
    }

    cin>>w>>n;
    for(int i=0;i<n;i++){
        int a,b;
        (cin>>a).ignore()>>b;
        swap(lot[a],lot[b]);
    }
    for(int i=1;i<=w;i++){
        cout<<lot[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace atcoder;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) {
            os << ',';
        }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    int N, Q;
    cin >> N >> Q;
    fenwick_tree<ll> fw(N);
    for(int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        fw.add(i, a);
    }
    while(Q--) {
        int t;
        cin >> t;
        if(t == 0) {
            int p;
            ll x;
            cin >> p >> x;
            fw.add(p, x);
        } else {
            int l, r;
            cin >> l >> r;
            cout << fw.sum(l, r) << "\n";
        }
    }
}

Measured memory_bytes: 8224