akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll res = 0;
    rep(i, 0, n){
        res += a[i];
    }
    if(res == x){
        cout << n << endl;
        return 0;
    }
    int ans = 0;
    ll sum = 0;
    rep(i, 0, n-1){
        sum += a[i];
        if(sum > x) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3560
/*
Hey there stalker....

█▀▀▄░░░░░░░░░░░▄▀▀█
░█░░░▀▄░▄▄▄▄▄░▄▀░░░█
░░▀▄░░░▀░░░░░▀░░░▄▀
░░░░▌░▄▄░░░▄▄░▐▀▀
░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█
░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█
▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█
█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀
░▀▄░░▀░░▀▀▀░░▀░░░▄█▀
░░░█░░░░░░░░░░░▄▀▄░▀▄
░░░█░░░░░░░░░▄▀█░░█░░█
░░░█░░░░░░░░░░░█▄█░░▄▀
░░░█░░░░░░░░░░░████▀
░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀

Like what you see?
*/
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pii         pair<ll ,ll>
#define vi          vector<ll>
#define present(container, element) (container.find(element) != container.end()) /* For set n maps */
#define cpresent(container, element) (find(all(container),element) != container.end()) /* For vectors */
#define all(a)      (a).begin(),(a).end()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define F           first
#define S           second
#define I           insert
#define sz(x)       (ll)x.size()
#define rep(i,a,b)    for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define trav(a, x) 	for(auto& a : x)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lcase(a) (char)tolower(a)
#define ll long long int
#define lld long double
#define endl "\n"
#define PI 3.14159265358979323844
#define MOD 1000000007
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define mod 1e9 + 7
const int N = 1e5 + 5;
/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

int32_t main()
{
   IOS

    int TESTS=1;
    //cin >> TESTS;
    while (TESTS--)
    {
    	ll k,n;
    	cin>> n >> k;
    	vi v(n);
    	rep(i,0,n)
    	{
    		cin>> v[i];
    	}
    	sort(v.begin(),v.end());

    	if(k>=n)
		{
			cout<< "0"<< endl;
			continue;
		}
		ll ans=0;

    	for(int i=0;i<n-k;i++)
    	{
    		ans+=v[i];
    	}
    	cout<< ans << endl;




    }
    return 0;
}


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

long long extgcd(long long a, long long b, long long &x, long long &y) {
    long long d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

long long mod_inverse(long long a, long long m) {
    long long x, y;
    extgcd(a, m, x, y);
    return (x % m + m) % m;
}

pair<long long, long long> linear_congruence(const vector<long long> &A, const vector<long long> &B, const vector<long long> &M) {
    long long x = 0, m = 1;

    for(unsigned i = 0; i < A.size(); ++i) {
        if(B[i] == -1) continue;

        long long a = A[i] * m, b = B[i] - A[i] * x, d = __gcd(M[i], a);
        if(b % d != 0) return make_pair(0, -1);
        long long t = b / d * mod_inverse(a / d, M[i] / d) % (M[i] / d);
        x = x + m * t;
        m *= M[i] / d;
    }

    return make_pair(x % m, m);
}

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

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

    vector<long long> M(m);
    for(auto &e : M) cin >> e;

    vector<long long> A(m, 1);

    for(int i = 0; i < d; ++i) {
        vector<long long> B(m);
        for(auto &e : B) cin >> e;

        long long b, mod;
        tie(b, mod) = linear_congruence(A, B, M);

        n = n - (n - b + mod) % mod;

        if(mod == -1 || n < 0) {
            n = -1;
            break;
        }
    }

    cout << n << endl;

    return EXIT_SUCCESS;
}

Measured memory_bytes: 1212
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>


//マクロ
/*動かない・・・
#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 _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e12
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
int a, b, c;
int cnt;

//使用する関数
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;
}

ll calc(ll a) {
	if (a == 1)return 1;
	return calc(a / 2) * 2 + 1;
}

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

	cin >> a >> b >> c;

	if (a == b)cnt++;
	if (b == c)cnt++;
	if (a == c)cnt++;
	if (cnt == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC";
    else cout<<"ABC";
    
    
    return 0;
}

Measured memory_bytes: 3640
p=2019
s,a,d,z=input()[::-1],0,0,[0]*p
for i,j in enumerate(s):
	d=(d+(int(j)*pow(10,i,p)))%p
	z[d]+=1
r=z[0]
for i in range(p):
	r+=z[i]*(z[i]-1)//2
print(r)

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

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

int main () {
    int N, cnt = 0;
    cin >> N;
    for(int i = 1; i < 1000000; i++) {
        for(int j = 1; j < 1000000; j++) {
            if(i*j < N) cnt++;
            else break;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n, r;
    cin >> n >> r;
    if (n >= 10)
    {
        cout << r << endl;
    }
    else
    {
        cout << r + 100 * (10 - n) << endl;
    }
}

Measured memory_bytes: 256
x, n = map(int, input().split())
if n != 0:
  p = list(map(int, input().split()))

f = range(102)
f = list(f)
for i in range(n):
  f.remove(p[i])

ans=0
dif=1000
for i in reversed(f):
  if abs(x-i) <= dif:
    ans = i
    dif = abs(x-i)
  
print(ans)

Measured memory_bytes: 9204
import java.util.*;
public class Main{

  public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int c = sc.nextInt();
      Map<Integer, ArrayList<int[]>> channels = new HashMap<>();
      for(int i = 1;  i <= c; i++) {
          channels.put(i, new ArrayList<>());
      }
      for(int i = 0; i < n; i++) {
          int[] itv = new int[]{sc.nextInt(), sc.nextInt()};
          channels.get(sc.nextInt()).add(itv);
      }

      ArrayList<int[]> allItvs = new ArrayList<>();
      for(int i = 1;  i <= c; i++) {
          ArrayList<int[]> itvs = channels.get(i);
          if(itvs.size() == 0) continue;
          Collections.sort(itvs, (itv1, itv2) -> itv1[0] - itv2[0]);
          int start = itvs.get(0)[0];
          int end = itvs.get(0)[1];
          for(int j = 1; j < itvs.size(); j++) {
            int[] itv = itvs.get(j);
            if(itv[0] == end) {
              end = itv[1];
            } else {
              allItvs.add(new int[] { start - 1, end});
              start = itv[0];
              end = itv[1];
            }
          }
          allItvs.add(new int[] { start - 1, end});
      }

      Collections.sort(allItvs, (itv1, itv2) -> itv1[0] == itv2[0] ? itv1[1] - itv2[1] : itv1[0] - itv2[0]);
      PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> a[1] == b[1] ? a[0] - b[0] : a[1] - b[1]);

      int min = 0;
      for(int[] itv : allItvs) {
          while(!pq.isEmpty() && itv[0] >= pq.peek()[1])
            pq.poll();
          pq.offer(itv);
          min = Math.max(min, pq.size());
      }
      System.out.println(min);
  }
}



Measured memory_bytes: 95632
#include<cmath>
#include<iostream>
#include<cstdio>
#include <string>
using namespace std;

int main()
{
	string a;
	cin >> a;
	if (a == "a" || a == "i" || a == "u" || a == "e" || a == "o") {
		cout << "vowel";
	}
	else {
		cout << "consonant";
	}

	return 0;


}

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

using namespace std;

typedef pair<int,int> pii;

const int INF=1000000000;
int n,m;
map<string,int> indice;
vector<pii> points;
vector<int> G[1001];
// node,どちらから来たか
pii d[1001][4];
int src,dst;

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

int dijkstra(){
  for(int i=0;i<1001;i++)
    for(int j=0;j<4;j++)
      d[i][j].first=d[i][j].second=INF;
  priority_queue<pair<pii,pii> > pq;
  for(int i=0;i<4;i++){
    d[src][i].first=0;
    d[src][i].second=0;
    pq.push(make_pair(pii(0,0),pii(src,i)));
  }
  while(pq.size()){
    pair<pii,pii> p=pq.top();pq.pop();
    int cost=p.first.first;
    int cross=p.first.second;
    int node=p.second.first;
    int curAng=p.second.second;
    if(d[node][curAng]<p.first)continue;
    // まっすぐ進む
    for(int i=0;i<G[node].size();i++){
      int to=G[node][i];
      int movey=points[to].first-points[node].first;
      int movex=points[to].second-points[node].second;
      if((movey>0&&dy[curAng]>0)
	 ||(movey<0&&dy[curAng]<0)
	 ||(movex<0&&dx[curAng]<0)
	 ||(movex>0&&dx[curAng]>0)){
	if(d[to][curAng]>pii(cost+abs(movey)+abs(movex),cross+1)){
	  d[to][curAng]=pii(cost+abs(movey)+abs(movex),cross+1);	  
	  pq.push(make_pair(d[to][curAng],pii(to,curAng)));
	}
      }
    }
    // 左に曲がる
    for(int i=0;i<G[node].size();i++){
      int to=G[node][i];
      int movey=points[to].first-points[node].first;
      int movex=points[to].second-points[node].second;
      int nxtAng=(curAng+1)%4;
      if((movey>0&&dy[nxtAng]>0)
	 ||(movey<0&&dy[nxtAng]<0)
	 ||(movex<0&&dx[nxtAng]<0)
	 ||(movex>0&&dx[nxtAng]>0)){
	if(d[to][nxtAng]>pii(cost+abs(movey)+abs(movex),cross+1)){
	  d[to][nxtAng]=pii(cost+abs(movey)+abs(movex),cross+1);	  
	  pq.push(make_pair(d[to][nxtAng],pii(to,nxtAng)));
	}
      }
    }
  }
  int minDist=INF;
  int res=INF;
  for(int i=0;i<4;i++){
    if(minDist>d[dst][i].first){
      minDist=d[dst][i].first;
      res=d[dst][i].second;
    }
    else if(minDist==d[dst][i].first)
      res=min(res,d[dst][i].second);
  }
  return res;
}

int main(){

  while(cin>>n>>m&&(n|m)){
    indice.clear();points.clear();
    for(int i=0;i<1001;i++)G[i].clear();
    for(int i=0;i<n;i++){
      string name;
      int x,y;
      cin>>name>>x>>y;
      indice[name]=i;
      points.push_back(pii(y,x));
    }
    for(int i=0;i<m;i++){
      string p,q;
      cin>>p>>q;
      int a=indice[p];
      int b=indice[q];
      G[a].push_back(b);G[b].push_back(a);
    }
    string a,b;
    cin>>a>>b;
    src=indice[a];dst=indice[b];
    int res=dijkstra();
    if(res==INF)cout<<"impossible"<<endl;
    else cout<<res+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1128
N, M = map(int, input().split())
Q = [tuple(map(int, input().split())) for _ in range(M)]

# 右側が小さい順にソート、制約a<bなのでそのまま使ってよい
Q = sorted(Q, key=lambda x: x[1])
# 境界、右側の区間の始まり
border = []

for a, b in Q:
    flag = True
    for x in border:
        # 既存の境界で分けられるか
        if a < x and x <= b:
            flag = False
            break
    if flag:
        border.append(b)

ans = len(border)
print(ans)

Measured memory_bytes: 24676
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve() 
{
  int N, M; cin >> N >> M;

  priority_queue<LL> A;
  LL ans = 0;

  REP0(i, N)
  {
    LL tmp; cin >> tmp;
    A.push(tmp);
    ans += tmp;
  }

  REP0(i, M) 
  {
    LL top = A.top();
    A.pop();
    LL rem = top%2;
    top /= 2ll;
    A.push(top);
    ans -= (top + rem);
  }

  cout << ans << endl;
}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout<<std::fixed<<std::setprecision(10);
  solve();
  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>
#include<cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i,n) FOR(i,0,n)

struct edge{int to,cost;};

void dump_line(int *b,int n){
	for(int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	cout << "\n";
}

ll mypow(ll x,ll n){
	if(n==0) return 1;
	ll res=mypow(x*x,n/2);
	if(n&1) res=res*x;
	return res;
}

ll mod_pow(ll x,ll n,ll mod){
	if(n==0) return 1;
	ll res=mod_pow(x*x%mod,n/2,mod);
	if(n&1) res=res*x%mod;
	return res;
}

ll a[51],p[51];

ll dfs(ll n,ll x){
//	cout << "n:" << n << " x:" << x << "\n";
	if(n==0 && x<=0) return 0;
	if(n==0 && x>=1) return 1;
	if(a[n]/2 >= x){
//		cout << "	2\n2";
		return dfs(n-1,x-1);
	}
	else{
//		cout << "	3\n";
		return p[n-1]+1+dfs(n-1,x-a[n-1]-2);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n,x;
	cin >> n >> x;

	a[0] = p[0]=1;
	rep(i,n){
		a[i+1]=a[i]*2+3;
		p[i+1]=p[i]*2+1;
	}

	cout << dfs(n,x) << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int k;
    bool chk = false;
    for (k = 2; k * (k - 1) / 2 <= n; k++) {
        if (k * (k - 1) / 2 == n) {
            chk = true;
            break;
        }
    }
    if (!chk) {
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n" << k << "\n";
    vector<int> graph[k];
    int tmp = 1;
    rep (i, k) {
        repp (j, i + 1, k) {
            graph[i].push_back(tmp);
            graph[j].push_back(tmp);
            tmp++;
        }
    }
    rep (i, k) {
        cout << k - 1 << " ";
        for (int j : graph[i]) cout << j << " ";
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <stdio.h>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a;
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputDoubleArray(a,N) double a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//自作ソート関数→return trueの時、前にソートされる。
bool sort_by_pandy(pair<int,pair<int, long>> p, pair<int,pair<int, long>> q){
  if(p.second.first != q.second.first){
    return p.second.first < q.second.first;
  }else{
    return p.second.second < q.second.second;  
  }
}

bool sort_by_order(pair<int,pair<int, long>> p, pair<int,pair<int, long>> q){
  return p.first < q.first;
}

int main(){
  //input
  inputInt2(N,M);
  vector<pair<int,pair<int,long>>> v(M);
  fN(i,M) {
    v[i].first = i;
    cin >> v[i].second.first >> v[i].second.second;
  }
  
  //main
  sort(v.begin(), v.end(), sort_by_pandy);
  
  for(int i=0; i<M; ++i){
    if(i==0){
      v[i].second.second = 1;
    }else{
      if(v[i-1].second.first != v[i].second.first){//属する県が違う
        v[i].second.second = 1;
      }else{
        v[i].second.second = v[i-1].second.second + 1;
      }
    }
  }
  
  sort(v.begin(), v.end(), sort_by_order);
  
  //output
  for(int i=0; i<M; ++i){
    cout << setfill('0') << right << setw(6) << v[i].second.first;
    cout << setfill('0') << right << setw(6) << v[i].second.second << endl;;
  }
  
  return 0;
}

Measured memory_bytes: 3840
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));
		int i=0;
		int num = 1;
		while(true){
			String str = br.readLine();
			num = Integer.parseInt(str);

				if(num == 0){
					break;
				}
				else if(num != 0){
					i++;
					System.out.println("Case " + i + ": " + num);
				}
		}
	}
}

Measured memory_bytes: 27172
s=str(input())
ans=False
n=len(s)

tmp1 = s[:int((n-1)/2)]
tmp2 = s[int((n+3)/2)-1:]

if tmp1 !="".join(list(reversed(tmp1))):
    print("No")
elif tmp2 !="".join(list(reversed(tmp2))):
    print("No")
elif s !="".join(list(reversed(s))):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  N--;
  string ans;
  while (N > -1) {
    ans.push_back('a' + N % 26);
    N = N / 26 - 1;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
N = gets.to_i
ts = []
(N-1).times {
  c,s,f = gets.split.map(&:to_i)
  ts << 0
  (0...ts.size).each{ |i|
    t = ts[i]
    t = [t,s].max
    t += t % f == 0 ? 0 : (f - t % f)
    t += c
    ts[i] = t
  }
}
puts ts, 0

Measured memory_bytes: 1788
#include <iostream>
#define endl '\n'
using namespace std;
const int num=2e3+1;
int s,dp[num],mod=1e9+7;
int solve(int n){
    int ret=0;
    if(dp[n]!=1)return dp[n];
    for(int i=3;i<=n-3;++i)ret=(ret+solve(i))%mod;
    dp[n]=(ret+dp[n])%mod;
    return dp[n];
}

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

    cin>>s;
    fill(dp,dp+s+1,1);
    for(int i=0;i<3;++i)dp[i]=0;
    cout<<solve(s)%mod<<endl;;
    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = s.nextInt();
		}
		int min = a[0];
		int max = a[0];
		for (int i = 0; i < N; i++) {
			min = Math.min(min, a[i]);
			max = Math.max(max, a[i]);
		}

		long result=2147483647L;
		
		for(int i=min;i<=max;i++){
			int sum=0;
			for(int j=0;j<N;j++){
				sum+=(i-a[j])*(i-a[j]);
			}
			result=Math.min(sum, result);
		}
		System.out.println(result);
	}
}

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

int main() {
  int i, j, n, count=0;
  bool flag = false;
  cin >> n;
  vector<int> data(n, 0);
  for (i=0; i<n; i++) {
    cin >> data.at(i);
    data.at(i)--;
  }
  j = 0;
  while(count<n) {
    if (j == 1) {
      flag = true;
      break;
    }
    count++;
    j = data.at(j);
  }
  if (flag) {
    cout << count << endl;
  }
  else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 768
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def main():
    n,k = inpl()
    xary = []; yary = []
    a = []
    x_append = xary.append
    y_append = yary.append
    a_append = a.append
    for i in range(n):
        x,y = inpl()
        xary += [x]
        yary += [y]
        a += [[x,y]]
    xary.sort(); yary.sort()
    res = INF
    for xi in range(n-1):
        for xj in range(xi+1,n):
            for yi in range(n-1):
                for yj in range(yi+1,n):
                    cnt = 0
                    l = xary[xi]; r = xary[xj]
                    d = yary[yi]; u = yary[yj]
                    # print(l,r,d,u)
                    for i in range(n):
                        x,y = a[i]
                        if l<=x<=r and d<=y<=u:
                            cnt += 1
                    if cnt >= k:
                        res = min(res, (r-l)*(u-d))
    print(res)
if __name__ == "__main__":
    main()

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

bool check(int64_t n, int64_t s, int64_t b) {
    if (b == 1) {
        return false;
    }

    int64_t ss = 0;

    while (n > 0) {
        ss += n % b;
        n /= b;
    }

    return s == ss;
}

int main() {
    int64_t n, s;
    cin >> n >> s;

    if (s > n) {
        cout << -1 << endl;
        return 0;
    }

    for (auto b : irange(2L, (int64_t)(sqrt(n)) + 1)) {
        if (check(n, s, b)) {
            cout << b << endl;
            return 0;
        }
    }

    // xb + y = n
    // x + y = s
    // => x*(b-1) = n - s
    auto m = n - s;
    int64_t b = -1L;
    for (auto k = 2L; k * k <= m; ++k) {
        if (m % k == 0) {
            if (check(n, s, k + 1)) {
                cout << k + 1 << endl;
                return 0;
            }
            if (check(n, s, m / k + 1)) {
                b = m / k + 1;
            }
        }
    }

    if (b > 0) {
        cout << b << endl;
        return 0;
    }

    if (check(n, s, m + 1)) {
        cout << m + 1 << endl;
        return 0;
    }

    if (s == n) {
        cout << n + 1 << endl;
        return 0;
    }

    cout << -1 << endl;
}

Measured memory_bytes: 256
num=1
while True:
    maxw=input()
    if maxw==0:break
    print "Case %d:"%num
    dp,w,v=[0]*1001,[0]*1001,[0]*1001
    n=input()
    for i in xrange(n):
        v[i],w[i]=map(int,raw_input().strip().split(","))
    for i in xrange(n):
        for j in xrange(maxw,-1,-1):
            if j+w[i]<=maxw:
                dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i])
    print max(dp)
    print dp.index(max(dp))
    num+=1

Measured memory_bytes: 4320
#include <cmath>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int N;
int d[100][100][2];
int hoge[100][100];

int main() {
  cin >> N;
  // cout << N << endl;
  vector< int > x(N);
  vector< int > y(N);

  REP(i, N) {
    cin >> x[i] >> y[i];
    // cout << x[i] << y[i];
  }
  int cost = N;
  REP(i, N) {
    FOR(j, i + 1, N) {
      d[i][j][0] = x[i] - x[j];
      d[i][j][1] = y[i] - y[j];
      d[j][i][0] = -x[i] + x[j];
      d[j][i][1] = -y[i] + y[j];
    }
  }

  REP(i, N) {
    REP(j, N) {
      int res = N;
      REP(k, N) {
        REP(l, N) {
          if (i == j || k == l)
            continue;
          res -=
              ((d[i][j][0] == d[k][l][0] && d[i][j][1] == d[k][l][1]) ? 1 : 0);
        }
      }
      cost = min(cost, res);
    }
  }
  cout << cost << endl;
}

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

typedef long long ll;

const int maxn = 3010;
string s, t;
int len1, len2, dp[maxn][maxn];

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

    cin >> s >> t;
    len1 = s.length(), len2 = t.length();
    for (int i = 0; i <= len1; i++) {
        for (int j = 0; j <= len2; j++) {
            if (i == 0 || j == 0) {
                continue;
            }
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = 1 + dp[i - 1][j - 1];
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    string answer;
    while (len1 > 0 && len2 > 0) {
        if (s[len1 - 1] == t[len2 - 1]) {
            answer += s[len1 - 1];
            len1--;
            len2--;
        } else if (dp[len1 - 1][len2] > dp[len1][len2 - 1]) {
            len1--;
        } else {
            len2--;
        }
    }
    reverse(answer.begin(), answer.end());
    cout << answer;

    return 0;
}

Measured memory_bytes: 38928
require 'matrix'

(n, m, c) = gets.chomp.split(' ').map(&:to_i)
b = Vector.elements(gets.chomp.split(' ').map(&:to_i))

s = 0
n.times do
  a = Vector.elements(gets.chomp.split(' ').map(&:to_i))
  if a.inner_product(b) + c > 0 then
    s += 1
  end
end
puts s.to_s

Measured memory_bytes: 2684
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner c = new Scanner(System.in);
        int target = c.nextInt();
        String t = target+"";
        int first = Integer.parseInt(t.substring(t.length()-1));
        if(first == 3){
            System.out.println("bon");
        }else if(first == 0 || first == 1 || first == 6 || first == 8){
            System.out.println("pon");
        }else{
            System.out.println("hon");
        }
    }
}

Measured memory_bytes: 38548
#解説参照
import sys
n,*a,=map(int, sys.stdin.read().split())
if a[0]:
    print(-1)
    exit()

ans=0
for i in range(n-1):
    if a[i+1]>a[i]+1:
        print(-1)
        exit()
    if a[i+1]-a[i]==1:
        ans+=1
    else:####
        ans+=a[i+1]

print(ans)

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int x = N * A;
  
  if (x > B) {
    cout << B << endl;
  }
  
  else if (x < B) {
    cout << x << endl;
  }

  else {
    cout << B << endl;
  }
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc104/tasks/abc104_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

bool check(string &s)
{
  if (count(ALL(s), 'A') != 1 || count(ALL(s), 'C') != 1)
    return false;

  int cp, ap;
  int l = s.length();
  FOR(i, 0, l)
  {
    if (s[i] != tolower(s[i]))
    {
      if (s[i] == 'A')
        ap = i;
      else if (s[i] == 'C')
        cp = i;
      else
        return false;
    }
  }

  return ap == 0 && 1 < cp && cp < l - 1;
}

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  string s;

  cin >> s;

  string r = check(s) ? "AC" : "WA";

  cout << r << '\n';

  return 0;
}


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

using namespace std;

bool primes[100001];
bool primes_like_2017[100001];
int range_sum[100001];

int Q;
int l[100001], r[100001];

int main(int argc, char* argv[]) {
  cin >> Q;
  for (int i = 0; i < Q; i++)
    cin >> l[i] >> r[i];

  primes[0] = primes[1] = false;
  primes_like_2017[0] = false;
  primes_like_2017[1] = false;
  primes_like_2017[2] = false;
  for (int i = 2; i <= 100000; i++)
    primes[i] = true;

  for (int i = 2; i * i <= 100000; i++) {
    if (!primes[i])
      continue;

    for (int j = 2; i * j <= 100000; j++)
      primes[i * j] = false;
  }

  for (int i = 3; i <= 100000; i++)
    primes_like_2017[i] = i % 2 == 1 && primes[i] && primes[(i + 1) / 2];

  range_sum[0] = 0;
  for (int i = 1; i <= 100000; i++)
    range_sum[i] = range_sum[i - 1] + (primes_like_2017[i] ? 1 : 0);

  for (int i = 0; i < Q; i++)
    cout << range_sum[r[i]] - range_sum[l[i] - 1] << endl;

  return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

pii par[MAXN][2];
int cycled[MAXN][2];

pair<int, pii> ee[MAXN];

pii get_par(int v, int ind) {
	return mp(v, ind) == par[v][ind] ? par[v][ind] : par[v][ind] = get_par(par[v][ind]._1, par[v][ind]._2);
}

void solve(){
	int n, h, w;
	scanf("%d%d%d", &n, &h, &w);
	REP(i, 0, n) {
		scanf("%d%d%d", &ee[i]._2._1, &ee[i]._2._2, &ee[i]._1);
	}
	sort(ee, ee + n);
	reverse(ee, ee + n);
	REPN(i, 1, h) {
		par[i][0] = mp(i, 0);
	}
	REPN(i, 1, w) {
		par[i][1] = mp(i, 1);
	}
	ll ans = 0ll;
	REP(i, 0, n) {
		int a = ee[i]._2._1, b = ee[i]._2._2;
		pii pa = get_par(a, 0);
		pii pb = get_par(b, 1);
		if (pa == pb) {
			if (cycled[pa._1][pa._2]) {
				continue;
			}
			ans += ee[i]._1;
			cycled[pa._1][pa._2] = 1;
		} else {
			if (cycled[pa._1][pa._2] && cycled[pb._1][pb._2]) {
				continue;
			}
			ans += ee[i]._1;
			cycled[pa._1][pa._2] |= cycled[pb._1][pb._2];
			par[pb._1][pb._2] = pa;
		}
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 6144
#include<iostream>
using namespace std;
int main()
#define int long long
{
	int t;
	t=1;
  	//cin>>t;
	while(t--){
      int n,ans=0,k;
		cin>>n;
          
          for(int i=0;i<n;i++){
            
            cin>>k;
            if(i%2==0 && k%2==1)
              ans++;
          }
      cout<<ans;
		
 
	}
	return 0;
 
}

Measured memory_bytes: 3160
#![allow(unused_imports)]

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        mut t: Chars,
    }
    let mut ans = 0u64;
    for i in 0..t.len() {
        if t[i] == '?' {
            t[i] = 'D';
        }
    }

    for i in 0..t.len() {
        print!("{}", t[i]);
    }

    println!();
}


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

using namespace std;

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int n;
   cin >> n;
   vector<int> a(n + 1 , 0);
   int tot = -1;
   for (int i = 1; i <= n; i++) {
      cin >> a[i];
      if (tot == -1) {
         tot = a[i];
      } else {
         tot = __gcd(tot , a[i]);
      }
   }
   vector<int> pref(n + 1 , 0);
   for (int i = 1; i <= n; i++) {
      pref[i] = a[i];
      if (i > 1) {
         pref[i] = __gcd(pref[i] , pref[i - 1]);
      }
   }
   vector<int> suf(n + 1 , 0);
   for (int i = n; i >= 1; i--) {
      suf[i] = a[i];
      if (i < n) {
         suf[i] = __gcd(suf[i] , suf[i + 1]);
      }
   }
   for (int i = 1; i <= n; i++) {
      int cur = 0;
      if (i == 1) {
         cur = suf[i + 1];
      } else if (i == n) {
         cur = pref[i - 1];
      } else {
         cur = __gcd(pref[i - 1] , suf[i + 1]);
      }
      tot = max(tot , cur);
   }
   cout << tot << '\n';
   return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <bitset>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REP1(i, n) for(int i = 1; i <= (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define ZERO(a) memset(a, 0, sizeof(a))

#define RAD(d) (PI * (d) / 180)
#define DEG(r) (180.0 * (r) / PI)

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

template<class T> void dump(const vector<T> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

template<class T> void dump(int w, int h, const vector<T> &v)
{
	REP(j, h){
		REP(i, w-1){ cout << v[j * w + i] << " "; }
		cout << v[j * w + w-1] << endl;
	}
}

template<class T> T accumulate(const vector<T> &v)
{
	T sum = 0;
	REP(i, SZ(v)){ sum += v[i]; }
	return sum;
}

template<class T> struct Matrix
{
	T w, h;
	vector<T> A;
	Matrix(T w_, T h_) : w(w_), h(h_), A(w * h) {}
	T get(T x, T y) const { return A[y * w + x]; }
};

template<class T> void input(Matrix<T> &m)
{
	REP(j, m.h){
		REP(i, m.w){
			cin >> m.A[j * m.w + i];
		}
	}
}

template<class T> Matrix<T> prod(const Matrix<T> &a, const Matrix<T> &b)
{
	Matrix<T> m(b.w, a.h);

	REP(j, m.h){
		REP(i, m.w){
			ll c = 0;
			REP(k, a.w){
				c += a.A[j * a.w + k] * b.A[k * b.w + i];
			}
			m.A[j * m.w + i] = c;
		}
	}

	return m;
}

void dump(const Matrix<ll> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%lld ", m.A[j * m.w + i]); }
		printf("%lld\n", m.A[j * m.w + m.w-1]);
	}
}

void dump(const Matrix<double> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%f ", m.A[j * m.w + i]); }
		printf("%f\n", m.A[j * m.w + m.w-1]);
	}
}

string &to_upper(string &s)
{
	REP(i, s.length()){
		if('a' <= s[i] && s[i] <= 'z'){
			s[i] -= 32;
		}
	}

	return s;
}

string &to_lower(string &s)
{
	REP(i, s.length()){
		if('A' <= s[i] && s[i] <= 'Z'){
			s[i] += 32;
		}
	}

	return s;
}

// すべての約数を列挙する
template <class T> vector<T> get_divisors(T n)
{
	vector<T> ret;
	for(T i = 1; i * i <= n; i++){
		if(n % i == 0){
			ret.push_back(i);
			if(i * i != n)
				ret.push_back(n / i);
		}
	}
	sort(ALL(ret));
	return ret;
}

// 1-sqrt(N)までの約数を列挙する
template <class T> vector<T> get_divisors2(T n)
{
	vector<T> ret;
	for(T i = 1; i * i <= n; i++){
		if(n % i == 0){
			ret.push_back(i);
		}
	}
	return ret;
}

int F(ll A, ll B)
{
	return LEN(to_string(max(A, B)));
}

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

	REP(i, M){
		int a;
		cin >> a;
		N -= a;
	}

	if(N < 0){
		cout << "-1" << endl;
	}
	else{
	cout << N << endl;
	}

	return 0;
}


Measured memory_bytes: 3640
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String[][] array = new String[8][8];
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		String s = sc.next();
		List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		for(int i=0;list.size()>i;i++) {
			//System.out.println(i);
			if(i%2==0) {
				if(list.get(i).equals("R")||list.get(i).equals("U")||list.get(i).equals("D")){
					continue;
				}
				System.out.println("No");
				System.exit(0);
			}
			else {
				if(list.get(i).equals("L")||list.get(i).equals("U")||list.get(i).equals("D")){
					continue;
				}
				System.out.println("No");
				System.exit(0);
			}
		}

		System.out.println("Yes");

	}

}

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

int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];

    int max=A[0];
    ll ans=0;
    rep(i, N){
        if(A[i]<=max){
            ans+=max-A[i];
        }else max=A[i];
    }

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

Measured memory_bytes: 4412
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %lld\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%lld", name[i][j]); \
    }\
    printf("\n");\
  }\

using namespace std;

typedef long long ll;

struct UnionFind {
  vector<int> par;
  vector<int> rank;

  UnionFind(int n) : par(n), rank(n) { 
    for(int i = 0; i < n; i++) {par[i] = i; rank[i] = 1;}
  }

  int find(int x) {if (par[x]==x) return x; else return par[x] = find(par[x]);}
  void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x==y) return;

    if (rank[x]>rank[y]) {par[y] = x; rank[x] += rank[y];}
    else {par[x] = y; rank[y] += rank[x];}
  }
  bool same(int x, int y) {return find(x)==find(y);}
  int get_rank(int x) {return rank[find(x)];}
};


UnionFind u(100005);
ll N, M;
int A[100005], B[100005];
vector<ll> v;

int main(void) {
    scanf("%lld %lld", &N, &M);
    rep(i, 0, M) {
      int a, b; 
      scanf("%d %d", &a, &b);
      A[i] = a-1; B[i] = b-1;
    }

    ll x = (N*(N-1))/2;
    v.pb(x);

    per(i, 0, M) {

      //2-5-6
      //1-3-4
      /*
      rep(i, 0, N) {
        if (i>0) printf(" ");
        printf("%d", u.rank[i]);
      }
      printf("\n");
      */
      if (u.same(A[i], B[i])) {v.pb(x); continue;}
      
      ll arank = (ll)u.get_rank(A[i]);
      ll brank = (ll)u.get_rank(B[i]);
      u.unite(A[i], B[i]);
      ll abrank = (ll)u.get_rank(A[i]);


      x += (arank*(arank-1))/2;
      x += (brank*(brank-1))/2;
      x -= (abrank*(abrank-1))/2;
      v.pb(x);
    }
    per(i, 0, M) {
      printf("%lld\n", v[i]);
    }

	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

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

constexpr int inf = (int)1e9;
constexpr double INF = 1e12, EPS = 1e-9;
constexpr int MX = 2010;
constexpr int mod = inf + 7;

int n, m, q, a[MX];
int L[MX][MX], R[MX][MX];
int memo[MX][MX];

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  int sum{0};

  rep(i, N + 1) {
    int total{0};
    int t{i};

    while (t > 0) {
      total += t % 10;
      t /= 10;
    }

    if (A <= total && total <= B) sum += i;
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

class Edge{
    public:
    int from,to,cost;
    void print(){
        cout << from << " " << to << " " << cost << "\n";
        return;
    }
};

int main(){
    ll n; cin >> n;
    int node_max = 0;
    while(pow(2,node_max) <= n)++node_max;
    node_max--;

    // cout << node_max << endl;
    vector<Edge> ans;
    rep(i,node_max){
        Edge temp1 = {i+1, i+2, 0};
        Edge temp2 = {i+1, i+2, (int)pow(2,i)};
        ans.push_back(temp1);
        ans.push_back(temp2);
    }
    // vector<int> node(node_max);
    for(int i = node_max-1;0 <= i; i--){
        if(n-pow(2,i) >= pow(2,node_max)){
            Edge temp = {i+1,node_max+1,(int)(n-pow(2,i))};
            ans.push_back(temp);
            n -= pow(2,i);
        }
    }
    cout << node_max + 1 << " " << ans.size() << endl;
    for(auto i : ans)i.print();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=3005,mod=1e9+7;
int dp[N][N],n,ans;
char s[N];
int main()
{
	scanf("%d%s",&n,s+1);
	dp[1][1]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
			dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
		for(int j=1;j<=i;j++)
		{
			if(s[i]=='<')
				dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod;
			else
			{
				dp[i+1][0]=(dp[i+1][0]+dp[i][j])%mod;
				dp[i+1][j+1]=(dp[i+1][j+1]-dp[i][j]+mod)%mod;
			}
		}
	}
	for(int i=1;i<=n;i++)
		ans=(ans+dp[n][i])%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 34176
def main():
    N, M, X, Y = (int(i) for i in input().split())
    x = sorted([int(i) for i in input().split()])
    y = sorted([int(i) for i in input().split()])
    if (x[-1] > y[0]):
        return 'War'
    else:
        for i in range(x[-1] + 1, y[0] + 1, 1):
            if i > X and i <= Y:
                return 'No War'
        return 'War'


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
// ABC178D.cpp :

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


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

const int mod = 1000000000 + 7;
int main()
{
    int s;
    cin >> s;
    ll dp[2020];
    dp[0] = 1;
    ll x = 0;
    for (int i = 1; i <= s; i++) {
        if (i - 3 >= 0) x += dp[i - 3];
            x %= mod;
            dp[i] = x;
    }
    cout << dp[s] << endl;
}


Measured memory_bytes: 3160
import math as mt
x = input().split()

ab = ''.join(x)
ab = int(ab)
abr = mt.sqrt(ab)
for i in range(0,int(abr) + 1):
  for j in range(0,int(abr) + 1):
    if(i*j == ab and i == j):
      print("Yes")
      #print(i,j)
      exit()
print("No")
                 

Measured memory_bytes: 38768
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/04/04.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC129
//
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__


char M[2020][2020];
int HC[2020][2020];
int WC[2020][2020];

int LW, RW, UH, LH;

queue<pair<int,int>> Q;

int H,W;
int mx,my;

void drawC(int H, int W){
  REP(y,H+2){
    REP(x,W+2){
      cout << setw(3) << HC[y][x] << " ";
    }
    cout << endl;
  }
  cout << endl;
  REP(y,H+2){
    REP(x,W+2){
      cout << setw(3) << WC[y][x] << " ";
    }
    cout << endl;
  }
  return;
}

void draw(int H, int W){
  REP(y,H+2){
    REP(x,W+2){
      cout << M[y][x] << " ";
    }
    cout << endl;
  }
  return;
}

void initC(void){
  REP(i,2020){
    REP(j,2020){
      HC[i][j]=-1;
      WC[i][j]=-1;
    }
  }
}

void checkW(int y, int x){
  LW=x-1;
  RW=x+1;
  int count=1;
  while(M[y][LW]=='.'){
    count++;
    LW--;
  }
  while(M[y][RW]=='.'){
    count++;
    RW++;
  }
  for(int i=LW+1; i<RW; i++){
    WC[y][i]=count;
  }
}

void checkH(int y, int x){
  UH=y-1;
  LH=y+1;
  int count=1;
  while(M[UH][x]=='.'){
    count++;
    UH--;
  }
  while(M[LH][x]=='.'){
    count++;
    LH++;
  }
  for(int i=UH+1; i<LH; i++){
    HC[i][x]=count;
  }
}

void solve(void){
  
  cin >> H >> W;
  
  REP(y,H+2){
    if(y==0||y==H+1){
      REP(x,W+2){
        M[y][x]='#';
      }
      continue;
    }
    string S;
    cin >> S;
    S='#'+S+'#';
    REP(x,S.size()){
      M[y][x]=S[x];
    }
  }
  
  initC();
  
//  draw(H+2,W+2);
  
  REP(y,H+2){
    REP(x,W+2){
      if(M[y][x]=='#'){continue;}
      if(HC[y][x]>0 && WC[y][x]>0){continue;}
      checkW(y,x);
      checkH(y,x);
    }
  }
  
//  drawC(H+2,W+2);
  
  int maxp=0;
  REP(y,H+2){
    REP(x,W+2){
      chmax(maxp, HC[y][x]+WC[y][x]-1);
    }
  }

  cout << maxp << endl;
  
  return;
   
}

#define TESTCASES 1

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}



Measured memory_bytes: 36096