akhauriyash/Code-Regression huggingface dataset:
/********************    I am only one, but still I am one.    **************************************/
/**************    I cannot do everything, but still I can do something.    *************************/
/***   And because I cannot do everything I will not refuse to do the something that I can do.    ***/
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

struct box{
	int v,d,c;
};
const int maxn = 1e5+5;
vector<int>g[maxn],lst(maxn),clr(maxn);
vector<box>q(maxn);
int n,m,t;
void dfs(int u,int d,int c){
	if(!clr[u]){
		clr[u] = c;
	}
	if( lst[u] >= d )return; // O( 10 * (n+m) )
	lst[u]=d;
	
	if( d == 0 ) return;
	for(auto v:g[u]){
		dfs(v,d-1,c);
	}
}
int32_t main(){
	IOS
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	cin>>t;
	for(int i=1;i<=t;i++){
		cin>>q[i].v>>q[i].d>>q[i].c;
	}
	reverse(q.begin()+1,q.begin()+t+1);
	for(int i=1;i<=t;i++){
		dfs(q[i].v,q[i].d,q[i].c);
	}
	for(int i=1;i<=n;i++){
		cout << clr[i] << endl;
	}
	
	
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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




int main(){
  for(int t=0;t<6;t++){

  
  int mx,a[20]={};
  cin>>mx;
  if(mx==0){break;}
  for(int i=0;i<9;i++){
    cin>>a[i];
    mx-=a[i];
  }
  cout<<mx<<endl;

  }
  
    
  return 0;
}



Measured memory_bytes: 3080
#include <iostream>
 
using namespace std;
 
int main()
{
  char str[10000], ch;
  int key;
  cin >> key;
  cin >> str;
 
  for(int j = 0; str[j] != '\0'; ++j){
      ch = str[j];
      ch = ch + key;
      if(ch > 'Z'){
        ch = ch - 'Z' + 'A' - 1;
      }
      str[j] = ch;
  }
 
  cout << str;
 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  int n;
  string s;
  cin>>n>>s;
  rep(i,s.size()){
    cout<<(char)((s[i]-'A'+n)%26+'A');
  }
  cout<<endl;
  return(0);
}


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

using namespace std;
typedef long long ll;

const int N = 1e3 + 7;
int t, res, n, m, sum;
int a[N][N], dp[N][N][2];
bool check[N][N][2];

int go(int i, int j, int typ)
{
    if(check[i][j][typ]) return dp[i][j][typ];
    check[i][j][typ] = true;
    if(i == n) return dp[i][j][typ] = 0;
    if(j == m) return dp[i][j][typ] = a[i + 1][m] + go(i + 1, j, 1 - typ);
    if(typ == 0) return dp[i][j][0] = max(go(i, j + 1, 1), a[i + 1][j] + go(i + 1, j, 1));
    return dp[i][j][1] = min(go(i, j + 1, 0), a[i + 1][j] + go(i + 1, j, 0));
}

main()
{
#define file "r"
//    freopen(file".inp", "r", stdin);
//  freopen(file".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin >> m >> n;
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
        {
            cin >> a[i][j];
            sum += a[i][j]; a[i][j] += a[i][j - 1];
        }
    cout << abs(sum - 2*go(0, 0, 1)) << "\n";
//    for(int i = 0; i <= n; i ++)
//    {
//        for(int j = 0; j <= m; j ++) cout << dp[i][j][0] << " "; cout << "\n";
//        for(int j = 0; j <= m; j ++) cout << dp[i][j][1] << " "; cout << "\n\n";
//    }
//    cout << sum << "\n";
    return 0;
}



Measured memory_bytes: 17004
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
    int n, m, x, a[128], ans;
    scanf("%d%d%d", &n, &m, &x);
    for(int i = 0; i < m; i++)
        scanf("%d", &a[i]);
    for(int i = 0; i < m; i++){
        if(a[i] > x){
            ans = min(i, m-i); 
            break;
        }
        else if(i == m-1)
            ans = 0;
    }

    printf("%d", ans);
    return 0;
}

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

int main() {
	char W[100][11];
	int N, i, ok = 1, len, j;
	
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%s", &W[i]);
	}

	for (i = 1; i < N && ok; i++) {
		len = strlen(&W[i - 1]);
		ok = (W[i][0] == W[i - 1][len - 1]);
	}

	for (i = 0; i < N && ok; i++) {
		for (j = i + 1; j < N && ok; j++) {
			if (strcmp(&W[i], &W[j]) == 0) {
				ok = 0;
			}
		}
	}

	if (ok == 0) {
		printf("No");
	}
	else {
		printf("Yes");
	}

	return 0;

}

Measured memory_bytes: 128
n = int(input())
c = {}
for i in range(n):
    s = input().split()
    if s[0] not in c:
        c[s[0]] = list()
    c[s[0]].append((int(s[1]), i))
s = sorted(c.keys())
for i in s:
    for r in sorted(c[i], key = lambda p : p[0])[-1::-1]:
        print(r[1] + 1)

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

// Loops
#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 _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

void solve(long long R) {
  if(R<1200) cout << "ABC" << endl;
  else if(R<2800)cout << "ARC" << endl;
  else cout << "AGC" << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long R;
  std::cin >> R;
  solve(R);
  return 0;
}


Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

using Graph = vector<vector<int> >;

// トポロジカルソートする
void rec(int v, const Graph &G, vector<bool> &seen, vector<int> &order) {
    seen[v] = true;
    for (auto next : G[v]) {
        if (seen[next]) continue; // 既に訪問済みなら探索しない
        rec(next, G, seen, order);
    }
    order.push_back(v);
}

int main() {
    int N, M;
    cin >> N >> M;
    Graph G(N+M-1);
    Graph R(N+M-1);    
    for (int i = 0; i < N+M-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        R[b].push_back(a);
    }

    // トポロジカルソート
    vector<bool> seen(N, 0);
    vector<int> order;
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue;
        rec(v, G, seen, order);
    }

    //orderには葉から順に並んでいる
    vector<int> dummy(N);
    for (int ii = 0; ii < N; ++ii){
    	dummy[order[ii]] = ii;
    }

	vector <int> parent(N, -1);
	for (int ii = 0; ii < order.size(); ++ii){
		int v = order[ii];
	    //nvの中でorderが最小のものを求める
	    int minV = 100100100;
	    for (auto nv : R[v]) {
	    	minV = min(minV, dummy[nv]);
	    }
	    if (minV != 100100100){
	    	parent[v] = order[minV];
	    }
	}

	for (int ii = 0; ii < N; ++ii){
		cout << parent[ii] + 1 << endl;
	}

}


Measured memory_bytes: 14844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()

const string YES = "Yes";
const string NO = "No";

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    const ll n1 = (c + b - 1) / b;
    const ll n2 = (a + d - 1) / d;
    if(n1 <= n2){
        cout << YES << endl;
    }else{
        cout << NO << endl;
    }
    return 0;
}


Measured memory_bytes: 3596
def solve
  a,b,h,w=gets.split.map &:to_i

  return puts "No" if (a%h).zero? && (b%w).zero?

  puts "Yes"

  swap = (b%w).zero?
  a,b,h,w = b,a,w,h if swap

  s = Array.new
  s[b] = 1
  b.step(1+w, -w) do |i|
    s[i-w] = s[i] + 1
  end
  b.times do |i|
    next if s[i]
    s[i] = 0
    i.step(b-w, w) do |j|
      s[j+w] = s[j] - 1
    end
  end

  t = Array.new
  b.times do |i|
    t << s[i+1] - s[i]
  end
  t = a.times.map{t}

  t = t.transpose if swap
  puts t.map{|i| i*" "}
end

solve


Measured memory_bytes: 7932
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(v) (v).begin(),(v).end()
const ll MOD = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	string t = "";
	int pos = 0;
	while (pos < s.size()) {
		if (s[pos] == 'A') {
			t.push_back('A');
			pos++;
		}
		else if (pos + 2 <= s.size() && s[pos] == 'B' && s[pos + 1] == 'C') {
			t.push_back('D');
			pos += 2;
		}
		else {
			t.push_back(s[pos]);
			pos++;
		}
	}
	ll ans = 0;
	int a = 0;
	for (int i = 0; i < t.size(); i++) {
		if (t[i] == 'D') ans += a;
		else if (t[i] == 'A') a++;
		else a = 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 776
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

c1 = Counter(D)
c2 = Counter(T)

for t in c2.keys():
    if c2[t] > c1[t]:
        print("NO")
        exit()
print("YES")

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s[0]==s[1] && s[1]==s[2])
    cout<<"Yes";
    else if(s[1]==s[2] && s[2]==s[3])
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

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

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


Measured memory_bytes: 3628
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;

int main() {
	int n, x, y, t, px = 0, py = 0, pt = 0, ok = 1;
	scanf("%d", &n);
	for (int i = 0; i < n && ok; i++) {
		scanf("%d %d %d", &t, &x, &y);
		int dis = abs(x-px) + abs(y-py);
		int tme = t-pt;
		if (dis > tme or dis%2 != tme%2) ok = 0;
		px = x;
		py = y;
		pt = t;
	}
	printf(ok ? "Yes\n" : "No\n");
	return 0;
}

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

using namespace std;
using VI = vector<int>;
using VPI = vector<pair<int, int>>;
using LL = long long;

#define FOR(a,n) for(int i=a;i<n;i++)
#define rFOR(a,n) for(int i=n-1;i>=a;i--)
#define IN(n,a) for(int i=0;i<n;i++) cin>>a[i]
#define pIN(n,t) for(int i=0;i<n;i++){int a,b; cin>>a>>b; t.emplace_back(a,b);}
#define SORT(a) sort(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()

int main()
{
	int k, n;
	cin >> k >> n;
	VI a(n);
	IN(n, a);

	int ans = 0;

	FOR(0, n - 1)
	{
		if (a[i + 1] - a[i] > ans) ans = a[i + 1] - a[i];
	}
	if ((a[0] + k) - a[n - 1] > ans) ans = (a[0] + k) - a[n - 1];

	cout << k - ans;

}

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

int main(void){
    int n,k;
    cin >> n >> k;

    int ans = 0;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        if(a>=k) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N, x; cin >> N >> x;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    long long ans = 0;
    for (int i = 1; i < N; i++) {
        if (a[i-1] + a[i] > x) {
            ans += a[i-1] + a[i] - x;
            a[i] = max(0, x - a[i-1]);
        }
    } 

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
	
	#define pb push_back
	#define ppb pop_back
	#define mp make_pair
	#define all(x) (x).begin(),(x).end()
	#define sz(x) (int)(x).size()
	#define ll long long
	#define bit __builtin_popcountll
	#define sqr(x) (x) * (x)
	#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
	#define debug(x) cout << #x <<" = " << x << endl
	#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
	#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
	#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;
	
	using namespace std;
	
	typedef pair<int, int> pii;
	
	const double eps = 1e-9;
	const double pi = acos(-1.0);
	const int INF = 1000000000;
	
	const int dx[4] = {0,  0, 1, -1};
	const int dy[4] = {1, -1, 0,  0};
	
	const int N = 100000;
	int main() {
		ios_base::sync_with_stdio(0);
		char ch;
		cin >> ch;
		if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
			cout << "vowel";
		else
			cout << "consonant";
	  	return 0;
	}


Measured memory_bytes: 256
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    s = ni()
    d = {}
    d[s] = 1
    ans = 1
    while True:
        ans += 1
        if s % 2 == 0:
            s = s // 2
        else:
            s = 3 * s + 1
        if s in d:
            print(ans)
            return
        else:
            d[s] = 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 9148
#include<stdio.h>
#include<iostream>
#include<set>
#include<string>

using namespace std;

int main(){
    int N;
    cin>>N;
    set<string> dict;
    for(int i=0; i<N; i++){
        string command, str;
        cin>>command>>str;
        if(command=="insert"){
            dict.insert(str);
        }
        else if(command=="find"){
            if(dict.find(str)!=dict.end())
                cout<<"yes"<<endl;
            else
                cout<<"no"<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 32148
def main():
    n = input()
    A = [int(i) for i in input().split()]
    if 0 in A:
        print("0")
        return
    ans = 1
    max_num = pow(10, 18)
    for a in A:
        ans *= a
        if ans > max_num:
            print("-1")
            return
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21556
def clear_maze(sx, sy, maze):

    INF=-10**9
    global cnt
    cnt=0


    distance = [[INF for i in range(w+1)] for j in range(h+1)]
    #    distance = [[None]*field_x_length]*field_y_length



    def bfs():
        global cnt
        queue = []

        queue.insert(0, (sx, sy))

        distance[sx][sy] = 0

        while len(queue):
            x, y = queue.pop()



            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]


                if (0 <= nx and  0 <= ny  and maze[nx][ny] != '#' and distance[nx][ny] == INF):
                    queue.insert(0, (nx, ny))

                    distance[nx][ny] = distance[x][y] + 1
                    if cnt<=distance[nx][ny]:
                        cnt=distance[nx][ny]





        return cnt

    cnt=0
    distance = [[INF for i in range(w + 1)] for j in range(h + 1)]




    return bfs()

h,w = map(int, input().split())
maze=[list(input()) for i in range(h)]
t=[[0]*w for i in range(h)]
for i in range(h):
    maze[i]=['#']+maze[i]+['#']

maze=[['#' for i in range(w+2)]]+maze+[['#' for i in range(w+2)]]




ans=0

for i in range(1,h+1):
    for j in range(1,w+1):
        if maze[i][j]=='#':
            continue
        v=(clear_maze(i, j, maze))

        if ans<=v:
            ans=v
print(ans)


Measured memory_bytes: 44524
#!/usr/bin/env python3
import sys
import heapq

def solve(N: int, A: "List[int]"):
    max_A = max(A)
    next_max_A = heapq.nlargest(2, A)[-1]
    for i in range(N):
        if A[i] == max_A:
            print(next_max_A)
        else:
            print(max_A)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12544
N = int(input())
A = list(map(int,input().split()))

su = sum(A) % (10**9+7)
ans = 0

for i in range(N):
    ans += ((su - A[i]) * A[i]) % (10**9+7)
    su -= A[i]

print(ans % (10**9+7))

Measured memory_bytes: 31612
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数
//if(cin.eof()) break; 入力数が決まってないとき
//ifstream  while(ifs>>data)

// 浮動小数点
// cout << fixed; 以下と組み合わせで小数点以下n桁
// cout << setprecision(n) << 値; n桁表記
// defaultfloat
int main (){
    string ans = "APPROVED";
    int n; cin >>n;
    vei a(n);
    REP(i,n){
        cin >> a[i];
    }
    REP(i,n){
        if(a[i]%2 == 0){
        if(a[i]%3 == 0 || a[i]%5 == 0) {
            ans = "APPROVED";
        }
        else {
            ans = "DENIED";
            break;
        }
        }
    }
    cout << ans;
}

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

int main() {
  int n, f = 0;
  cin >> n;

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    f += a[i] - 1;
  }

  cout << f << endl;
}

Measured memory_bytes: 256
n = int(input())
a = sorted(list(map(int,input().split())))
ans1 = a[-1]
ans2 = a[0]
for i in range(1,n-1):
    if abs(ans2-ans1/2)>abs(a[i]-ans1/2):
        ans2 = a[i]
print(ans1,ans2)

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n,k;
  cin>>n>>k;
  
  
  
  if(k<=n/2+n%2)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;


    
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n=int(input())
H=list(map(int,input().split()))
count=0
while True:
    start,end=0,0
    for i in range(n):
        if H[i]!=0:
            H[i]-=1
            start=1
            if end:
                count+=1
                end=0
        else:
            if start:
                end=1
    if not start:
        break
    count+=1
print(count)
    


Measured memory_bytes: 3188
#include <stdio.h>

int main(void)
{
	int hen1, hen2, tai;
	int c_t, c_h;
	
	c_t = 0;
	c_h = 0;
	
	while (scanf("%d,%d,%d", &hen1, &hen2, &tai) != EOF){
	
		if (hen1 * hen1 + hen2 * hen2 == tai * tai){
			c_t++;
		}
		else if (hen1 == hen2){
			c_h++;
		}
	}
	
	printf("%d\n", c_t);
	printf("%d\n", c_h);
	
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<ll> C(N);
    
    for(int i=0;i<N;i++) cin>>C[i];
    
    sort(all(C));
    
    ll sum=0;
    ll cnt=rui(2,N-1),plus=cnt*rui(2,mod-2)%mod;
    
    for(int i=N-1;i>=0;i--){
        sum+=C[i]*cnt;
        sum%=mod;
        
        cnt+=plus;
        cnt%=mod;
    }
    
    sum*=rui(2,N);
    sum%=mod;
    
    cout<<sum<<endl;
}



Measured memory_bytes: 1792
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}


ll A[200002] = {0};
int main()
{
	ll K = 0, N = 0, i = 0, ans = 2000000, temp = 0;
	scanf("%lld %lld", &K, &N);
	for (i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
	}
	temp = K - A[N-1] + A[0];
	for (i = 0; i < N; i++) {
		ll index = 0, len1 = 0, add = 0;
		if (i == 0) {
			index = N - 1;
			add = 0;
			len1 = A[index] - A[i];
		} else {
			index = i - 1;
			add = temp;
			len1 = K - (A[i] - A[index]);
		}
		//printf("1 e=%lld s=%lld len1=%lld add=%lld\n", index, i, len1, add);
		ans = MIN(ans, len1);
	}
	for (i = 0; i < N; i++) {
		ll index = 0, len1 = 0, add = 0;
		if (i == (N - 1)) {
			add = 0;
			len1 = A[i] - A[0];
		} else {
			index = i + 1;
			add = temp;
			len1 = K - (A[index] - A[i]);
		}
		//printf("2 e=%lld s=%lld len1=%lld add=%lld\n", index, i, len1, add);
		ans = MIN(ans, len1);
	}
	printf("%lld\n", ans);
    return 0;
}


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

int main() {
  int N, AC=0, WA=0, TLE=0, RE=0;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  for (int i = 0; i < N; i++) {
    if(S.at(i)=="AC"){
      AC++;
    }
    else if(S.at(i)=="WA"){
      WA++;
    }
    else if(S.at(i)=="TLE"){
      TLE++;
    }
    else if(S.at(i)=="RE"){
      RE++;
    }
  }
    cout << "AC" << " " << "x" << " " << AC << endl;
    cout << "WA" << " " << "x" << " " << WA << endl;
    cout << "TLE" << " " << "x" << " " << TLE << endl;
    cout << "RE" << " " << "x" << " " << RE << endl;
}

Measured memory_bytes: 6264
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=2001 ;
int main()
{
   fast ;
   ll n ;
   cin>>n ;
   set<string>s ;
   for(ll i=0;i<n;i++)
   {
       string r ;
       cin>>r ;
       s.insert(r) ;
   }
   cout<<s.size() ;



}



Measured memory_bytes: 19248
#include <bits/stdc++.h>
#define REP(i, n)     for(int i = 0;i < n;i++)
#define REPR(i, n)    for(int i = n;i >= 0;i--)
#define FOR(i, m, n)  for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(),greater<long long>());
#define ALL(X) (X).begin(),(X).end()
#define INF 99999999
#define M_PI 3.14159265358979323846
#define MOD 1000000007

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) os << "[" << el.first << " " << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) os << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<double> P;

void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N;
    for (int i = 0; i < N; i++)
    {
      double p;
      cin >> p;
      P.push_back(p);
    }
    
}

int solve(){
  vector<vector<double>> dp(N+1,vector<double>(N+1,0));
  dp[0][0] = 1;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j <= i+1; j++)
    {
      if(j==0) dp[i+1][j] += dp[i][j]*(1-P[i]);
      else dp[i+1][j] += dp[i][j]*(1-P[i]) + dp[i][j-1]*P[i];
    }
    
  }
  double ans=0;
  for (int k = N/2+1; k <= N; k++)
  {
    ans += dp[N][k];
  }
  cout << fixed << setprecision(10) << ans << endl; 
  return 0;
}

int main()
{
    input();
    solve();
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int count=0;
    for(int i=1;i<=N;i++){
        int sub;
        cin >> sub;
        if(sub%2==1&&i%2==1)count++;
        
    }
    
    cout << count << endl;
}


Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map> 
using namespace std;
map<int,int> stk;
struct node
{
	int l,sum;
	friend bool operator <(node t1,node t2)
	{
		return t1.l>t2.l;
	}
}s[100005];
int n,i,j,k,a[100005],top;
long long ans=1,tot;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++) 
	{	scanf("%d",&a[i]);
 		if(!stk[a[i]]) stk[a[i]]=++top,s[stk[a[i]]].l=a[i];
 		s[stk[a[i]]].sum++;
	}
	sort(s+1,s+1+top);
	for(i=1;i<=n;i++) 
	{   
		if(s[i].sum>=2)
		{
			ans*=(long long)s[i].l;
			tot++;
			if(s[i].sum>=4 && tot<2) tot++,ans*=(long long)s[i].l;
		}
		if(tot==2) break;
	}
	if(tot!=2) ans=0;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6144
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int x;
    scanf("%d",&x);
    int a[x];
    for(int c = 0 ; x > c ; c++){
        scanf("%d",&a[c]);
    }
    for(int b = x ; b != 0 ; b--){
        printf("%d",a[b-1]);
        if(b!=1){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}
 


Measured memory_bytes: 2044
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

class Add_Segment_Tree {
	vector<long long int>v;
	vector<int>l;
	vector<int>r;
	long long int ret;
	int num;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = Update(place * 2) + Update(place * 2 + 1);
		return v[place];
	}
	void Sum(int a, int b, int place) {
		if (l[place] >= a && r[place] <= b) {
			ret += v[place];
			return;
		}
		if (l[place] > b || r[place] < a) return;
		Sum(a, b, place * 2);
		Sum(a, b, place * 2 + 1);
		return;
	}
public:
	void Left(int place) {
		if (place >= v.size() / 2) {
			l[place] = place - v.size() / 2;
			return;
		}
		Left(place * 2);
		Left(place * 2 + 1);
		l[place] = l[place * 2];
		return;
	}
	void Right(int place) {
		if (place >= v.size() / 2) {
			r[place] = place - v.size() / 2;
			return;
		}
		Right(place * 2);
		Right(place * 2 + 1);
		r[place] = r[place * 2 + 1];
		return;
	}
	Add_Segment_Tree(int n) {
		n++;
		num = 1;
		while (num < n * 2)num *= 2;
		l.resize(num);
		r.resize(num);
		v.resize(num, 0);
		Left(1);
		Right(1);
	}
	void Add(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] += num;
		if (!update)return;
		place /= 2;
		while (place) {
			v[place] = v[place * 2] + v[place * 2 + 1];
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int Sum(int a, int b) {
		ret = 0;
		Sum(a, b, 1);
		return ret;
	}
};

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

	cin >> N;
	Add_Segment_Tree one(N * 2 + 3);
	for (int i = 0; i <= 2; i++) {
		one.Add(i, 1, true);
	}
	for (int i = 3; i <= N * 2; i++) {
		long long int box = one.Sum(i - 1, i - 1);
		box += one.Sum(max(0, i - (int)N - 1), min((int)N - 2, i - 3));
		box %= MOD;
		one.Add(i, box, true);
	}
	long long int ans = 0;
	long long int by = N - 1;
	by *= N - 1;
	by %= MOD;
	for (int i = 0; i <= N - 2; i++) {
		ans += one.Sum(i, i)*by;
		ans %= MOD;
	}
	ans += one.Sum(N - 1, N - 1)*N;
	ans %= MOD;
	ans += one.Sum(2 * N, 2 * N);
	ans %= MOD;
	ans += MOD;
	ans -= one.Sum(N - 1, N - 1);
	ans %= MOD;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main (){

	int kazu;
	bool n[4][14] = {false};
	int k[52];
	string p[52];
	cin >> kazu;
	for(int i = 1;i <= kazu;i++){
	cin >> p[i - 1] >>k[i - 1];
	if(p[i - 1] == "S"){
		n[0][k[i - 1]] = 1;
	}else if(p[i -1] == "H"){ 
		n[1][k[i-1]] = 1;
	}else if(p[i-1] == "C"){
		n[2][k[i-1]] = 1;
	}else{
		n[3][k[i-1]] = 1;
	}
	}
	for(int j = 0;j <= 3;j++){
		for(int y = 1;y <= 13;y++){
			if(n[j][y] == 0){
				switch(j){
				case 0:
					cout << "S " << y<<endl;
					break;
				case 1:
					cout << "H " << y<<endl;
					break;
				case 2:
					cout << "C " << y<<endl;
					break;
				case 3:
					cout << "D " <<y<<endl;
					break;
				}
			}
		}
	}
	

	return 0;
}

Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
ll fact[200005]={1},inv[200005]={1};
ll modpow(ll a,ll b){
  ll r=1;
  while(b>0){
    if(b%2==1)(r*=a)%=mod;
    (a*=a)%=mod;
    b/=2;
  }
  return r;
}
ll chose(ll a,ll b){
  return fact[a]*inv[b]%mod*inv[a-b]%mod;
}
int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    rep(i,n){
      fact[i+1]=fact[i]*(i+1)%mod;
      inv[i+1]=modpow(fact[i+1],mod-2);
    }
    ll ans=0;
    
    arep(i,n-k-1,n){
      (ans+=modpow(m-1,i)*m%mod*chose(n-1,i))%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6696
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

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

    int n, k;
    cin >> n >> k;
	vector<int> v(n);
	for (int& x : v) {
		cin >> x;
	}
	int ans = 0;
	for (int i = 1; i <= min(n, k); i++) {
		for (int j = 1; j <= i; j++) {
			vector<int> t(i);
			auto p = [](int x) {return x < 0;};
			auto it = copy_if(begin(v), begin(v) + j, begin(t), p);
			it = copy_if(end(v) - i + j, end(v), it, p);
			sort(begin(t), it);
			int s = accumulate(begin(v), begin(v) + j, 0);
			s += accumulate(end(v) - i + j, end(v), 0);
			s -= accumulate(begin(t), begin(t) + min<int>(it - begin(t), k - i), 0);
			ans = max(ans, s);
		}
	}

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
 
res = 0;
dp = [[0]*(N+1) for _ in range(N+1)]
 
for i in range(N-1, -1, -1):
  for j in range(N-1, i, -1):
    if S[i] == S[j]:
      dp[i][j] = max(dp[i][j], dp[i+1][j+1]+1);
    res = max(res, min(dp[i][j], j-i));
print(res)

Measured memory_bytes: 231816
import numpy as np

def main():
	N = int(input())
	h = list(map(int, input().split(" ")))
	# print(N)
	# print(h)

	cost = np.zeros(N, dtype=int)

	for i in range(N-1):
		if i == 0:
			cost[i+1] = abs(h[i+1] - h[i])
		else:
			cost[i+1] = min(cost[i] + abs(h[i+1] - h[i]), cost[i-1] + abs(h[i+1] - h[i-1]))

	print(cost[N-1])

if __name__ == '__main__':
	main()

Measured memory_bytes: 22716
#include <bits/stdc++.h>
 
#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(int i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
//#define ff fi.fi
//#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cerr << ">>>>>> " << #x << " -> " << x << endl
#define nani(x) cerr <<  "Line " << __LINE__ << ": " << #x << " is " << x << endl
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
#define endl '\n'
const int MAX = 2e5+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll MOD2 = 1000005329;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 2000;

ll cnt[MAX],id,ans,tmp;
stack<int> buk;
stack<piii> tup;
string sss;

int main(){
//	cout<<fixed<<setprecision(10);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>sss;
    buk.push(0), tup.push({0,{0,0}});
    for(auto i:sss){
    	++id;
    	if(i=='(')buk.push(id);
		else if(i==')'){
			if(buk.top()==0){
				tup.push({id,{-1,cnt[0]}});
				cnt[0] = 0;
			}
			else {
				tmp = buk.top();
				buk.pop();
				tup.push({id,{buk.top(),tmp}});
				++cnt[buk.top()];
				ans+=cnt[buk.top()];
			}
		}
		else {
			if(buk.top()>tup.top().fi)buk.pop();
			else {
				if(tup.top().sf==-1){
					cnt[0] = tup.top().ss;
					tup.pop();
				}
				else {
					ans-=cnt[tup.top().sf];
					cnt[tup.top().sf]--;
					buk.push(tup.top().ss);
					tup.pop();
				}
			}
		}
		assert(ans>=0);
		cout<<ans<<endl;
	}
    return 0;
}



Measured memory_bytes: 6352
#include<cstdio>
#define neko 5010
#define seko 1000010
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~(i)))
#define rf(i,a,b) for(register int i=(a);i>=(b);i=~(-(i)))
int n,a[seko],b[seko];
typedef long long ll;
ll dp[neko][neko],fac[seko],invfac[seko],ans,mod=1e9+7;
ll slowpow(ll m,ll n)
{
	ll b=1;
	for(;n;n>>=1,m=m*m%mod)if(n&1)b=b*m%mod;
	return b;
}
ll C(ll m,ll n)
{if(n>m)return 0;return fac[m]*invfac[n]%mod*invfac[m-n]%mod;}
ll ADD(ll x,ll y){return (x+=y)>=mod?x-mod:x;}
int main()
{
	scanf("%d",&n);
	f(i,1,n)scanf("%d%d",&a[i],&b[i]),++dp[-a[i]+2000][-b[i]+2000];
	fac[0]=invfac[0]=1;
	f(i,1,10000)fac[i]=fac[i-1]*i%mod;
	invfac[10000]=slowpow(fac[10000],mod-2);
	rf(i,9999,1)invfac[i]=invfac[i+1]*(i+1)%mod;
	f(i,0,4000)
	 f(j,0,4000)
	 {
		if(i)dp[i][j]=ADD(dp[i][j],dp[i-1][j]);
		if(j)dp[i][j]=ADD(dp[i][j],dp[i][j-1]);
	 }
	f(i,1,n)ans=(ans+dp[a[i]+2000][b[i]+2000])%mod;
	f(i,1,n)ans=(ans+mod-C(2*(a[i]+b[i]),2*a[i]))%mod;
	printf("%lld\n",(ans*slowpow(2,mod-2)%mod+mod)%mod);
}

Measured memory_bytes: 166144
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p = new int[n];
        for(int i=0; i<n; i++) {
            p[i] = sc.nextInt();
        }

        Arrays.sort(p);
        int ans = 0;
        for(int i=0; i<k; i++) {
            ans += p[i];
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 38848
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
#define mod 1000000007
#define G() Cr=getchar()
int Xr;char Cr;
inline int rd(){   //读入优化
    Xr=0,G();
    while(Cr<'0'||Cr>'9')G();
    while(Cr>='0'&&Cr<='9')Xr=(Xr<<3)+(Xr<<1)+Cr-'0',G();
    return Xr;
}
int n,x,y;
int va[2005];
int ans[2005];
int main(){
	n=rd(),x=rd(),y=rd();
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			if(j<=x)ans[j-i]++;
			else if(i<=x&&j>=y){
				ans[j-i-y+x+1]++;
			}
			else if(i<=x&&j<y){
				ans[min(j-i,x-i+1+y-j)]++;
			}
			else if(i>x&&i<y){
				if(j<=y){
					ans[min(j-i,i-x+1+y-j)]++;
				}
				else{
					ans[min(j-i,i-x+1+j-y)]++;
				}
			}
			else{
				ans[j-i]++;
			}
		} 
	}
	for(int i=1;i<n;i++)printf("%d\n",ans[i]);
}


Measured memory_bytes: 256
from math import gcd

MOD = 10**9+7
n = int(input())
d = {}
zero = 0
for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero += 1
        continue
    flip = 0
    while not (a >= 0 and b > 0):
        a, b = -b, a
        flip ^= 1
    g = gcd(a, b)
    a //= g
    b //= g
    if not (a, b) in d:
        d[(a, b)] = [0, 0]
    d[(a, b)][flip] += 1
ans = 1
for (v1, v2) in d.values():
    ans *= pow(2, v1, MOD) + pow(2, v2, MOD) - 1 # -1 is because need to remove the case that choose nothing
    ans %= MOD
ans -= 1
ans += zero
ans %= MOD
print(ans)


Measured memory_bytes: 134032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N, K;
int dp[105000][2];
int R, S, P;
string T;
int ans = 0;

int f(char a) {
    if(a == 'r') return P;
    if(a == 's') return R;
    if(a == 'p') return S;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    for(int i = 0; i < K; i++) {
        int score = 0;
        bool same = false;
        for(int j = 0; ; j++) {
            int now = j * K + i;
            if(now >= N) {
                ans += score;
                break;
            }
                if(j == 0) {
                    score += f(T[now]);
                    same = false;
                } else {
                    if(T[now] == T[now - K]) {
                        if(same) score += f(T[now]);
                        same ^= true;
                    } else {
                        same = false;
                        score += f(T[now]);
                    }
                }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

int main() {
	int a, b, c;
  	std::string res;
  
  std::cin >> a >> b >> c;
  
  if ( a == (b+c) || b == (c+a) || c == (a + b)) {
  	res = "Yes";
  } else {
  	res = "No";
  }
  
  std::cout << res << std::endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define maxn 320
int n, k, m;
long long int tree[maxn][maxn], suf[maxn][maxn];	
long long int C[maxn][maxn];
long long int tmp[maxn];
#define mod m
#define dp tree
long long int ans[maxn];
int main(){
	cin>>n>>k>>m;	
	for (int i=0; i<maxn; i++) C[i][0]=1;
	for (int i=1; i<maxn; i++){
		for (int j=1; j<maxn; j++) C[i][j]= (C[i-1][j]+C[i-1][j-1])%m;
	}	
	for (int i=1; i<=k; i++) {
		dp[1][i]= 1;
	}
	for (int i=k; i>=1; i--) {
		suf[1][i]= (suf[1][i+1]+dp[1][i])%mod;
	}
	for (int i=2; i<=n; i++){
		for (int j=k; j>=1; j--){
			long long int ad= 0;	
			for (int t=1; t<i; t++){
				ad=0;
				ad = suf[t][j+1]%mod;
				ad= ad*C[i-2][t-1]%m;
				ad= ad*dp[i-t][j]%mod;
				dp[i][j]= (dp[i][j]+ad)%mod;	
			}	
			suf[i][j]= (suf[i][j+1]+dp[i][j])%mod;
		}
	
	}
	if (dp[n][k]<0) dp[n][k]+=mod;
	ans[1]= k;
	ans[0]= 1;

	for (int i=2; i<=n; i++){
		for (int j=1; j<=i; j++){
			long long int ad=0;
			for (int t=1; t<=k; t++) ad=(ad+dp[j][t])%m;
			ad= C[i-1][j-1]*ad%mod;
			ad= ad*ans[i-j]%mod;
			ans[i]= (ans[i]+ad)%mod;	
		}
	}
	if (ans[n]<0) ans[n]+=mod;
	ans[n]%=mod;
	cout<<ans[n]<<endl;
}

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

int main()
{
  char c;
  cin >> c;
  c++;
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 3616
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();
        var q = int.Parse(input.ReadLine());

        var builH = new StringBuilder();
        var builT = new StringBuilder();

        var rev = false;

        for(int i=0; i<q; i++) {
            var spl   = input.ReadLine().Split(' ');
            var a     = int.Parse(spl[0]);

            if(a == 1) {
                rev = !rev;
            } else {
                var f = int.Parse(spl[1]);
                var c = spl[2][0];

                if(f == 1) {
                    if (!rev) builH.Append(c);
                    else builT.Append(c);
                } else {
                    if (!rev) builT.Append(c);
                    else builH.Append(c);
                }
            }
        }

        var buil = new StringBuilder(s.Length + builH.Length + builT.Length);

        if (!rev) {
            for(int i=0; i<builH.Length; i++) {
                buil.Append(builH[builH.Length - i - 1]);
            }
            for(int i=0; i<s.Length; i++) {
                buil.Append(s[i]);
            }
            buil.Append(builT);
        }
        else {
            for(int i=0; i<builT.Length; i++) {
                buil.Append(builT[builT.Length - i - 1]);
            }
            for(int i=0; i<s.Length; i++) {
                buil.Append(s[s.Length - i -1]);
            }
            buil.Append(builH);
        }

        return buil;
    }
}

Measured memory_bytes: 17972
#include <cstdio>
#include <algorithm>
using namespace std;
#define INF 1e9

int main(){
    int N,A,B;
    scanf("%d",&N);
    int l[N];
    for(int i=0;i<N;i++){
        scanf("%d",&l[i]);
        l[i]-=(i+1);
    }
    sort(l,l+N);
    long long int S=0;
    for(int i=0;i<N;i++){
        S+=abs(l[i]-l[N/2]);
    }
    printf("%lld\n",S);
    return 0;
}


Measured memory_bytes: 896