akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAX_N = 300030;
int par[MAX_N];
int rnk[MAX_N];
ll n;

void init(){
  for (int i=0; i<n; i++){
    par[i] = i;
    rnk[i] = 0;
  }
}

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 (rnk[x]<rnk[y]){
    par[x] = y;
  } else {
    par[y] = x;
    if (rnk[x]==rnk[y]) rnk[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}


int main(){
  ll m; cin >> n >> m;
  init();
  ll score = n*(n-1)/2;
  vector<pair<int, int>> node(m);
  for (int i=0; i<m; i++){
    cin >> node[i].first >> node[i].second;
  }
  vector<ll> Uni(n,1);
  stack<ll> ans;
  for (int i=m-1; i>-1; i--){
    ans.push(score);
    if (!same(node[i].first, node[i].second)){
      score -= Uni[find(node[i].first)]*Uni[find(node[i].second)];
      ll tmp = Uni[find(node[i].first)];
      Uni[find(node[i].first)] += Uni[find(node[i].second)];
      Uni[find(node[i].second)] += tmp;
      unite(node[i].first, node[i].second);
    }
  }
  for (int i=0; i<m; i++){
    cout << ans.top() << endl;
    ans.pop();
  }
}


Measured memory_bytes: 4252
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
#define rep(i,n) for (ll i = 0; i < (n); ++i)
typedef long long int ll;
using ipair = pair<int,int>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
const int MOD=1000000007;

int main(){  
    
    int n;cin>>n;
    vector<ll> a(n);
    ll mx = 0;
    rep(i,n){cin>>a[i];mx = max(mx,a[i]);}
    vector<ll> ans(n,0);
    rep(i,35){
        if(mx<pow(2,i))break;
        int cnt = 0;
        vector<int>ones,zeros;
        rep(j,n){
            if(a[j]&(1<<i)){
                cnt++;
                ones.push_back(j);
            }else zeros.push_back(j);
        }
        if(cnt%2==0){
            for(int v:ones){
                ans[v]+=pow(2,i);
            }
        }else{
            for(int v:zeros){
                ans[v]+=pow(2,i);
            }
        }
    }
    rep(i,n)printf("%ld ",ans[i]);
    return 0;
}

Measured memory_bytes: 8456
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <vector>

using namespace std;

// https://atcoder.jp/contests/abc075/tasks/abc075_c

class UnionFind {
public:
  UnionFind(int n) : _parent(n, -1) {
  }

  int root(int x) {
    if (_parent[x] < 0) return x;
    return _parent[x] = root(_parent[x]);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (size(x) < size(y)) swap(x, y);
    _parent[x] += _parent[y];
    _parent[y] = x;
  }

  int size(int x) {
    return -_parent[root(x)];
  }
  
  bool same(int x, int y) {
    return root(x) == root(y);
  }

  int groups() {
    int res = 0;
    for (auto &e : _parent) {
      if (e < 0) ++res;
    }
    return res;
  }

private:
  vector<int> _parent;
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> bridges;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    bridges.emplace_back(make_pair(a-1, b-1));
  }

  int answer = 0;
  for (int i = 0; i < m; ++i) {
    UnionFind uf(n);
    for (int j = 0; j < m; ++j) {
      if (i == j) continue;
      uf.unite(bridges[j].first, bridges[j].second);
    }
    if (uf.groups() > 1) ++answer;
  }

  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int n;
ll m;
l_l calc(int mid,vector<int> a,vector<ll> sum){
    ll total=0,num=0;
    for(int i=0; i<n; i++){
        int j=lower_bound(a.begin(),a.end(),mid-a[i])-a.begin();
        num+=n-j;
        total+=sum[n]-sum[j];
        total+=a[i]*ll(n-j);
    }
    return l_l(total,num);
}
int main(){
    cin >> n >> m;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    vector<ll> sum(n+1);
    sort(a.begin(),a.end());
    for(int i=0; i<n; i++) sum[i+1]=sum[i]+a[i];
    int l=0,r=200005;
    while(r-l>1){
        int mid=(r+l)/2;
        if(calc(mid,a,sum).second>=m) l=mid;
        else r=mid;
    }
    auto p=calc(l,a,sum);
    ll ans=p.first;
    ans-=(p.second-m)*l;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2576
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>

using namespace std;

int Sum(const vector<int>& Jwels, size_t a, size_t b, size_t suteru)
{
  int val = 0;
  
  list<int> Hands;
  while(a > 0)
  {
    const int temp = Jwels[a - 1];
    val += temp;
	Hands.emplace_back(temp);    
    -- a;
  }
  
  while(b > 0)
  {
    const int temp = Jwels[Jwels.size() - b];
    val += temp;
    Hands.emplace_back(temp);    
    -- b;
  }
  
  Hands.sort();
  for(auto Itr = Hands.cbegin(); suteru > 0 && Itr != Hands.cend(); -- suteru, ++ Itr)
  {
    if(*Itr > 0)
      break;
    
    val += -(*Itr);
  }
    
  return val;
}

int main()
{
  size_t n, k;
  cin >> n >> k;
  
  vector<int> Jwels(n, 0);
  for(size_t i = 0; i < n; ++ i)
    cin >> Jwels[i];
  
  const int min_pop = min(n, k);
  int max_val = 0;
  for(size_t a = 0; a <= min_pop; ++ a)
  {
    for(size_t b = 0; b <= min_pop - a; ++ b)
    {
      const int val = Sum(Jwels, a, b, k - (a+b));
      if(max_val < val)
        max_val = val;
    }
  }
  cout << max_val << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    int n, k, ans = 0;
    scanf("%d%d", &n, &k);
    vector<int> v(n);
    for (int i = 0; i < n; ++i) scanf("%d", &v.at(i));
    for (int l = 0; l <= min(n, k); ++l) for (int r = 0; r <= min(n, k) - l; ++r) {
        int sum = 0;
        vector<int> neg;
        for (auto lp = v.begin(); lp != v.begin() + l; ++lp) {
            if (*lp < 0) neg.push_back(*lp);
            else sum += *lp;
        }
        for (auto rp = v.end() - r; rp != v.end(); ++rp) {
            if (*rp < 0) neg.push_back(*rp);
            else sum += *rp;
        }
        sort(neg.begin(), neg.end());
        sum += accumulate(neg.begin() + min(int(neg.size()), k - (l + r)), neg.end(), 0);
        ans = max(ans, sum);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let x: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let y: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let z: i32 = read(&mut stdin_lock, &mut buf, b'\n');

    let ans = (x - z) / (y + z);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
  string s;
  cin >> s;
  vector<int> swaped;
  string prev;
  for (auto c : s)
  {
    switch (c)
    {
    case 'A':
    {
      if (prev.size() > 0)
      {
        prev = "";
        swaped.push_back(2);
      }
      swaped.push_back(0);
      break;
    }
    case 'B':
    {
      prev = prev + 'B';
      break;
    }
    case 'C':
    {
      if (prev.size() > 0 && prev[prev.size() - 1] == 'B')
      {
        if (prev.size() == 1)
        {
          swaped.push_back(1);
          prev = "";
        }
        else
        {
          swaped.push_back(2);
          swaped.push_back(1);
          prev = "";
        }
      }
      else
      {
        prev = prev + 'C';
      }
      break;
    }
    }
  }
  if (prev.size() > 0)
  {
    prev = "";
    swaped.push_back(2);
  }
  long long zero = 0;
  long long sum = 0;
  for (auto c : swaped)
  {
    if (c == 0)
    {
      zero++;
    }
    else if (c == 1)
    {
      sum += zero;
    }
    else if (c == 2)
    {
      zero = 0;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 1784
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
struct card{
	char suit;int n;
}BS[36],SS[36];
void s(int n,struct card A[]){
	for(int i=0;i<n;i++){
		printf("%c%d",A[i].suit,A[i].n);
		if (i==n-1) printf("\n");
		else printf(" ");
	}
}
void bs(int n){
	for (int i=0;i<n;i++){
		int flg=0;
		for (int j=n-1;j>i;j--){
			if (BS[j].n<BS[j-1].n){
				swap(BS[j],BS[j-1]);
				flg=1;
			}
		}
		if (!flg) break;
	}
	s(n,BS);
}
void ss(int n){
	for (int i=0;i<n;i++){
		int minj=i;
		for (int j=i;j<n;j++)
			if (SS[j].n<SS[minj].n) minj=j;
		if (minj!=i) swap(SS[i],SS[minj]);
	}
	s(n,SS);
}
void ck(int n){
	for (int i=0;i<n;i++)
		if(SS[i].suit!=BS[i].suit){
			printf("Not stable\n");return;
		}
	printf("Stable\n");return; 
}
int main(){
	int n;cin>>n;
	for (int i=0;i<n;i++){
		cin>>BS[i].suit>>BS[i].n;
		SS[i]=BS[i];
	}
	bs(n);printf("Stable\n");ss(n);ck(n);
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define l1 long long
int main(){ int x,n,min=0,p,y,l; cin>>x>>n; p=x;l=x;
  int arr[n]; for(int i=1;i<=n;i++)cin>>arr[i]; 
 if(n==0)cout<<x;
 else{ 
        for(int i=1;i<=n;i++){if(x==arr[i]){min++; break;}}
        if(min==0)cout<<x;
        else{
      while(1){min=0; 
	          p=p-1;
	        for(int i=1;i<=n;i++){if(p==arr[i]){++min; break;} }
      	        if(min==0){cout<<p;break;}
      	        l=l+1;min=0;
      	        for(int i=1;i<=n;i++){if(l==arr[i]){++min; break;} }
      	        if(min==0){cout<<l;break;}
              }
           }
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n,h;
  cin >> n >> h;
  vector<ll> a(n),b(n);
  ll maxa = 0;
  REP(i,n){
    cin >> a[i] >> b[i];
    maxa = max(a[i],maxa);
  }
  ll tmp = 0;
  ll cnt = 0;
  std::sort(ALL(b),greater<ll>());
  for (auto val : b){
    if (maxa > val) break;
    tmp += val;
    cnt++;
    if (tmp >= h) {
      break;
    }
  }
  while(tmp < h) {
    tmp+=maxa;
    cnt++;
  }
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 1792
s=gets.chomp
ws=['dream','dreamer','erase','eraser']
l=s.length
loop do
  a = ws.detect do |w|
    wl = w.length
    l >= wl && s[l-wl,wl] == w
  end
  break unless a
  l -= a.length
end
puts l == 0 ? 'YES' : 'NO'


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

int main(){
	ll N,K; cin>>N>>K;
	vector<ll> x(N+3,0);
	string s; cin>>s;
	ll p=0;
	if(s[0]=='0') x[p++]=0;
	char mem=s[0];
	ll len=1;
	for(int i=1;i<s.size();i++){
		//変わった
		if(mem!=s[i]){
			x[p++]=len;
			mem=s[i];
			len=1;
		}
		else{
			len++;
		}

		if(i==s.size()-1){
			x[p++]=len;
		}
	}
	if(s[s.size()-1]=='0') x[p]=0;
	else p--;
	//x:0~pに逆順・・逆
	if(p/2<=K) cout<<s.size();
	else{
		ll tmp=0;
		rep(i,2*K+1){
			tmp+=x[i];
		}
		ll ans=tmp;
		ll l=0,r=2*K;
		rep(b,(p-2*K)/2){
			tmp+=x[++r];
			tmp+=x[++r];
			tmp-=x[l++];
			tmp-=x[l++];
			//printf("tmp:%lld\n",tmp);
			if(ans<tmp) ans=tmp;
		}
		cout<<ans;
	}
	//rep(i,p+1) cout<<x[i]<<endl;
}

Measured memory_bytes: 1280
"""
解説を読んでから、バケットソートで書き直した。
単純にリストのリストをソートすると、O(NlogN)かかる。
Nの最大値N_max個のバケットを用意してからバケットソートすると、O(N_max+A_max)になる。
A_max<=N_maxだから、要するにO(N_max)になる。
"""
N_max = 10**5+1

N, K = map(int, input().split())

bucket_list = [0 for i in range(N_max)]
for i in range(N):
    a, b = map(int, input().split())
    bucket_list[a] += b
 
counter = 0
answer = None
for i in range(1, N_max):
    counter += bucket_list[i]
    if counter >= K:
        answer = i
        break
 
print(answer)


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

int main(void){
    // Your code here!
    long long N;
    cin>>N;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];        
    }
    sort(A.begin(),A.end());
    for(int i=0;i<N-1;i++){
        if(A[i]==A[i+1]){
            cout<<"NO"<<endl;
            return 0;
        } 
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

struct node{
	struct node *left;
	struct node *right;
	struct node *parent;
	int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){//kに一致するノードを探す
	if (u == NIL){return NIL;}//なかた
	if (u->key == k){ return u; }//あた
	else if (u->key > k){
		return treeSearch(u->left, k);
	}
	else{
		return treeSearch(u->right, k);
	}
}

void treeDelete(Node z){
	Node tmp;

	if (z->left == NIL && z->right == NIL){//子なし
		if (z->parent->left == z){//zが親の左側に属していたら
			z->parent->left = NIL;
		}
		else{
			z->parent->right = NIL;
		}
		free(z);
	}
	else if (z->left != NIL && z->right != NIL){//子2人
		tmp = z->right;//右側から最少を探す
		while (tmp->left != NIL){
			tmp = tmp->left;
		}
		z->key = tmp->key;
		treeDelete(tmp);		
	}
	else{//子1人
		if (z->left!=NIL){//左に子がいたら
			if (z->parent->left == z){//zが親の左側にいたら
				z->parent->left = z->left;
				z->left->parent = z->parent;
			}
			else{//zが親の右側にいたら
				z->parent->right = z->left;
				z->left->parent = z->parent;
			}
		}
		else{//右に子がいたら
			if (z->parent->left == z){//zが親の左側にいたら
				z->parent->left = z->right;
				z->right->parent = z->parent;
				
			}
			else{//zが親の右側にいたら
				z->parent->right = z->right;
				z->right->parent = z->parent;
			}
		}
		free(z);
	}
}

Node sss(int k, Node x){
	if (x == NIL){ return x; }//root
	if (k < x->key){
		if (x->left != NIL){
			return sss(k, x->left);
		}
		else{
			return x;
		}
	}
	else{
		if (x->right != NIL){
			return sss(k, x->right);
		}
		else{
			return x;
		}
	}
}

void insert(int k){
	Node y = sss(k,root);//入れるべき場所の親探し
	Node z;

	z = malloc(sizeof(struct node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	z->parent = y;

	if (y == NIL){ root=z; }
	else if (y->key < k){//kが親キーより大きい
		y->right = z;
	}
	else{
		y->left = z;
	}
}

void inorder(Node u){
	if (u->left != NIL)
		inorder(u->left);
	printf(" %d", u->key);
	if (u->right != NIL)
		inorder(u->right);	
}
void preorder(Node u){
	printf(" %d", u->key);
	if (u->left != NIL)
		preorder(u->left);
	if (u->right != NIL)
		preorder(u->right);
}

int main(){
	int n, i, x;
	char com[20];
	scanf("%d", &n);

	for (i = 0; i < n; i++){
		scanf("%s", com);
		if (com[0] == 'f'){
			scanf("%d", &x);
			Node t = treeSearch(root, x);
			if (t != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if (com[0] == 'i'){
			scanf("%d", &x);
			insert(x);
		}
		else if (com[0] == 'p'){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if (com[0] == 'd'){
			scanf("%d", &x);
			treeDelete(treeSearch(root, x));
		}
	}

	return 0;
}

Measured memory_bytes: 19364
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n;
ll dp[maxn];
ll a[maxn];
int main()
{
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i];
    }
    dp[1]=0;
    dp[0]=0;
    dp[2]=abs(a[2]-a[1]);
    repd(i,3,n)
    {
        dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));

    }
    cout<<dp[n];
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

Measured memory_bytes: 5120
def solve(H):
    total = 0
    while True:
        c = 0
        for i, h in enumerate(H):
            if c == 0:
                if h > 0:
                    H[i] -=1
                    c = 1
            elif 0 < h:
                H[i] -= 1
            elif h == 0:
                break
        if c == 0:
            return total
        total += 1
N = int(input())
H = [int(x) for x in input().split()]
print(solve(H))



Measured memory_bytes: 3064
def c170(x, n, plist):

    if n == 1:
        if x - n not in plist:
            return x - n
        else:
            return x + n

    for i in range(n):
        if x-i not in plist:
            return x-i
        elif x+i not in plist:
            return x+i

def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    plist = list(map(int, input().split()))
    print(c170(x, n, plist))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9092
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,ll> pii;
const int MOD=1e9+7;
int N;
double ans=0.0;
double dp[305][305][305];
int buc[3];
double bfs(int one,int two,int three)
{
  if(one==0 && two==0 && three==0)
    {
      return 0;
    }
  if(dp[one][two][three]>1e-9)
    {
      return dp[one][two][three];
    }
  double res=1.0;
  if(one) res+=bfs(one-1,two,three)*one/N;
  if(two) res+=bfs(one+1,two-1,three)*two/N;
  if(three) res+=bfs(one,two+1,three-1)*three/N;
  if(one+two+three!=N) res*=N/double(one+two+three);
  return dp[one][two][three]=res;
}
int main()
{
  cin >> N;
  for(int i=0;i<N;i++)
    {
      int a;
      cin >> a;
      a--;
      buc[a]++;
    }
  cout << fixed << setprecision(10) << bfs(buc[0],buc[1],buc[2]) << endl;
  return 0;
}


Measured memory_bytes: 219392
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var a, b int

	fmt.Scan(&a, &b)
	if a <= b {
		fmt.Println(strings.Repeat(strconv.Itoa(a), b))
	} else {
		fmt.Println(strings.Repeat(strconv.Itoa(b), a))
	}
}


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

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 vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int K,N; cin >> K >> N;
    VI A(N+1); REP(i,N) cin >> A[i];
    A[N] = A[0];
    int ans = INT_INF;
    REP(i,N-1) chmin(ans, K-A[i+1]+A[i]);
    int t = (K-A[N-1]) + A[0];
    chmin(ans, K-t);
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N,x = 0,max = 0;
    string S;
    cin>>N>>S;
    for (int i=0;i<N;i++){
        if(S.at(i)=='I'){
            ++x;
        }else if(S.at(i)=='D'){
            --x;
        }
        if(max<x){
            max = x;
        }
    }
    cout<<max<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];
  A.emplace_back(INF);

  int ans = 0;
  int cnt = 0;
  REP(i, N){
    if(A[i] >= A[i+1]) cnt++;
    else{
      chmax(ans, cnt);
      cnt = 0;
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
	    double l = sc.nextInt();

		double a = l/3.0;

		System.out.println(Math.pow(a,  3));

	}
}


Measured memory_bytes: 25172
import sys

# %%

n, m = list(map(int, sys.stdin.readline().split()))
ary = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
bry = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
mod = 10 ** 9 + 7

# %%

if len(set(ary)) != len(ary) or len(set(bry)) != len(bry):
    print(0)

else:
    ary.append(0)
    bry.append(0)

    cnt = 1
    i = 0
    j = 0
    for num in range(n * m, 0, -1):

        if (num == ary[i]) and (num == bry[j]):
            i += 1
            j += 1

        elif (num == ary[i]) or (num == bry[j]):
            if num == ary[i]:
                cnt *= len(bry[:j])
                i += 1
            else:
                cnt *= len(ary[:i])
                j += 1

        else:
            # na = len(ary[:i])
            # nb = len(bry[:j])
            cnt *= (i * j - (n * m - num))

        cnt = cnt % mod

    print(cnt)


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int calc(int s, int e, int ts, int te) {
    int x = min(e, te) - max(s, ts);
    if(x < 0) x = 0; return x;
}

map< int, map<int, int> > logs;
int ruiseki[1010];
signed main() {
    int N, M;
    while(cin >> N >> M) {
        if(N == 0 && M == 0) break;
        vector<pii> v[10010];
        logs.clear();
        int r, t, n, m, s; cin >> r;
        rep(i,0,r) {
            cin >> t >> n >> m >> s;
            t -= 540;
            m--;
            if(s == 0) v[m].pb(pii(logs[m][n], t));
            else logs[m][n] = t;
        }

        int q; cin >> q;
        rep(i,0,q) {
            int ts, te, mm; cin >> ts >> te >> mm;
            ts -= 540; te -= 540;
            mm--;

            memset(ruiseki, 0, sizeof(ruiseki));
            rep(j,0,v[mm].size()) {
                ruiseki[ v[mm][j].fr     ]++;
                ruiseki[ v[mm][j].sc + 1 ]--;
            }
            int ans = 0;
            rep(j,1,1000) {
                ruiseki[j] += ruiseki[j-1];
                if(ruiseki[j] && ruiseki[j-1] && ts < j && j <= te) ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3392
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,k;
    cin >> h >> w >> k;
    vvint dp(h+1,vint(w,0));
    dp[0][0]=1;
    for(int i=1;i<=h;i++){
        REP(j,w){
            int cnt = (1<<(w-1));
            REP(b,cnt){
                int now = b;
                vint br(w-1);
                REP(t,w-1){
                    br[t]=(now&1);
                    now>>=1;
                }
                bool f = false;
                REP(t,w-2){
                    if(br[t]==1&&br[t+1]==1){
                        f=true;
                        break;
                    }
                }
                if(f) continue;
                if(j>0&&br[j-1]==1){
                    dp[i][j-1]+=dp[i-1][j];
                    dp[i][j-1]%=mod;
                }else if(j<w-1&&br[j]==1){
                    dp[i][j+1]+=dp[i-1][j];
                    dp[i][j+1]%=mod;
                }else if(((j>0&&br[j-1]==0)||j==0)&&((j<w-1&&br[j]==0)||j==w-1)){
                    dp[i][j]+=dp[i-1][j];
                    dp[i][j]%=mod;
                }
            }
        }
    }
    cout << dp[h][k-1]%mod << endl;
    return 0;
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long InF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


vector<pair<int, int> > dia[100005];
int diadis[100005], ft;

void dfs(int a, int b = -1) {
	if (b == -1) { diadis[a] = 0, ft = a; }
	if (diadis[a] > diadis[ft]) { ft = a; }
	for (auto h : dia[a])
		if (h.first != b) {
			diadis[h.first] = diadis[a] + h.second;
			dfs(h.first, a);
		}
}



int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int s, t, w;
		cin >> s >> t >> w;
		dia[s].push_back({ t, w });
		dia[t].push_back({ s, w });
	}
	dfs(0);
	dfs(ft);
	cout << diadis[ft] << endl;
}



Measured memory_bytes: 13528
// Copyright (C) 2016 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>
#include <ctime>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <string>

#define x first
#define y second
#define MP std::make_pair
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

typedef long long LL;
typedef std::pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
std::string procStatus()
{
    std::ifstream t("/proc/self/status");
    return std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        if (ch == '-')
            f = -1;
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 3e3 + 5;
const int MOD = 1e9 + 7;

int N, M;
int ub[MAXN];
int sum[MAXN];

void input()
{
    read(N); read(M);
    static char inp[MAXN];
    scanf("%s", inp + 1);
    for (int i = 1; i <= N; ++i) {
        sum[i] = sum[i - 1] + (inp[i] == '1');
    }
    for (int i = 1; i <= M; ++i) {
        int l, r;
        read(l); read(r);
        chkmax(ub[l], r);
    }
    for (int i = 1; i <= N; ++i) {
        chkmax(ub[i], std::max(i, ub[i - 1]));
    }
}

void solve()
{
    static int dp[MAXN][MAXN];

    dp[0][0] = 1;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= N; ++j) {
            if (!dp[i][j])
                continue;
            int s = sum[ub[i + 1]] - sum[ub[i]];
            if (j <= ub[i] - i) (dp[i + 1][j + s] += dp[i][j]) %= MOD;
            if (j - 1 <= ub[i] - i && j >= 1) (dp[i + 1][j - 1 + s] += dp[i][j]) %= MOD;
        }
    }
    int ans = (dp[N][0] + dp[N][1]) % MOD;

    write(ans); putchar('\n');
}

int main()
{
#ifdef __DEBUG
    freopen("F.in", "r", stdin);
    freopen("F.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}


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

int main(){
  ll N;
  cin >>N;
  vector<ll> vec(N);
  vector<ll> vec1(N);
  for(int i=0;i<N;i++){
    cin >> vec[i];
    vec1[i]=vec[i];
  }
  sort(vec1.begin(),vec1.end());
  ll a=vec1[0];
  ll ans=0;
  map<ll,ll> m;
  for(ll i=0;i<N;i++){
    if(a==vec1[i]){
      m[vec1[i]]++;
      if(i==N-1){
        ans+=m[vec1[i]]*(m[vec1[i]]-1)/2;
      }
    }
    else{
      ans+=m[a]*(m[a]-1)/2;
      a=vec1[i];
      m[vec1[i]]++;
    }
  }
  ll d=ans;
  for(ll i=0;i<N;i++){
    ans+=(m[vec[i]]-1)*(m[vec[i]]-2)/2-m[vec[i]]*(m[vec[i]]-1)/2;
    cout << ans <<endl;
    ans=d;
  }
}
    

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

int main()
{

    int N;
    cin >> N;
    int c[501], s[501], f[501];
    int i;
    for (i = 0; i < N - 1; i++)
    {
        cin >> c[i] >> s[i] >> f[i];
    }
    int tr = s[0] + c[0];
    if (N == 1)
    {
        cout << s[0];
        return 0;
    }
    else if (N == 2)
    {
        cout << tr;
        return 0;
    }
    int tg,j;
    for (j = 0; j < N-1 ; j++)
    {
        tr=s[j]+c[j];
        for (i = j+1; i < N - 1; i++)
        {
            tg=s[i];
            //s[i] is i番目の駅を出発する時間
            while (tg < tr)
            {
                tg += f[i];
            }

            tr = tg + c[i];
        }
        cout << tr << "\n";
        
    }
    cout << 0;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> number(N);
  for(int i = 0; i < N; i++){
    cin >> number.at(i);
  }
  int count = 0;

  for(int i = 0; i < N; i++){
    if(number.at(i)  != i + 1){
      count++;
    }
  }
  if(count <= 2){
    cout << "YES" <<endl;
  }
  else{
    cout << "NO" <<endl;
  }
    
}


Measured memory_bytes: 256
n, a, b = gets.chomp.split(" ").map(&:to_i)
ans = 0
1.upto(n) do |i|
  x = i
  s = 0
  while true
    break if x == 0
    s += x % 10
    x /= 10
  end
  if a <= s && s <= b then
    ans += i
  end
end
puts ans

Measured memory_bytes: 1788
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 'No'
n = inp()
Hlist = inpl()
i = n-1
while i:
    if Hlist[i-1] >= Hlist[i]+2: 
        ans = 'No'
        break
    elif Hlist[i-1] == Hlist[i]+1:
        Hlist[i-1] = Hlist[i]
    i += -1

if i == 0: ans = 'Yes'

print(ans)

Measured memory_bytes: 23152
n=int(input())
h_list = list(map(int, input().split()))

ans = "Yes"
for i in range(n-1):
  if h_list[i]<h_list[i+1]:
    h_list[i+1]-=1
  elif h_list[i]==h_list[i+1]:
    pass
  elif h_list[i]>h_list[i+1]:
    ans = "No"

print(ans)

Measured memory_bytes: 63856
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// -fsanitize=undefinedでオーバーフロー検出,オーバーフローする入力を投げるとよい
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
bool is_prime(int n) {
    for (int i = 2; i*i <= n; ++i) {
        if (n % i == 0) return false;
    }
    if(n==1) return false;
    return true;
}

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
 
    ll a,b,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str,stra="CODEFESTIVAL2016";
    ll k;
    ll w,x,y;
    ll h;
    cin>>w>>h>>n;
    ll za[h][w];
    ll l=0;
    ll r=w;
    ll u=h;
    d=0;
    rep(_,n){
        cin>>x>>y>>b;
        if(b==1){
            l=max(l,x);
        }if(b==2){
            r=min(r,x);
        }if(b==3){
            d=max(d,y);
        }if(b==4){
            u=min(u,y);
        }
    }
    //cout<<r<<" "<<l<<" "<<u<<" "<<d<<endl;
    if(l>=r||d>=u) cout<<0<<endl;
    else cout<<(r-l)*(u-d)<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>


char ssss[1000];


int main(){

	int cnt;

	int i,j,m;

	long long n,q,w,e,r,t,y;

	
	long long s[17]={0,283,3638,42033,474028,5274023,

	58074018,634074013,6874074008,74074074003,794074073998,

	8474074073993,90074074073988,954074074073983,

	10074074074073978,106074074074073973,1114074074074073968};
	

	long long ss[16]={48,56,64,72,80,88,96,104,

					112,120,128,136,144,152,160,168};
	long long sss[16]={1,91,991,9991,99991,999991,9999991,
	99999991,999999991,9999999991,99999999991,
	999999999991,9999999999991,99999999999991,999999999999991,
	9999999999999991};



	scanf("%lld",&n);



	for(i = 0;i < 16;i++)if(s[i] > n)break;

	i--;


	q = n-s[i];

	w = (q+5)/ss[i];

	q = (q+5)%ss[i];
	if(!w)q -= 5;

	



	e = sss[i]+w*15;
//printf("e:%lld q:%lld w:%lld\n",e,q,w);
	sprintf(ssss,
	"%lld%lldFizz%lldBuzzFizz%lld%lldFizzBuzz%lldFizz%lld%lldFizzBuzz%lld%lldFizz%lldBuzzFizz%lld%lldFizzBuzz%lldFizz%lld%lldFizzBuzz",
	e,e+1,e+3,e+6,e+7,e+10,e+12,e+13,e+15,e+16,e+18,e+21,e+22,e+25,e+27,e+28);
//printf("%s\n\n",ssss);
//printf("e:%d q:%d w:%lld\n",e,q,w);
//printf("w:%lld\n",w);
	for(j = 0;j<20;j++)printf("%c",ssss[j+q-1]);
	puts("");
	
	return 0;
}

Measured memory_bytes: 616
N=int(input())
A= [int(i) for i in input().split()] 
import sys
count=0
while count<1000000:
    for i in range  (N):
        if A[i]%2==0:
            A[i]=A[i]/2
        else:
            print (count)
            sys.exit()
    count+=1

Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if sum(A) < sum(B):
    print(-1)
    exit()

diff = [A[i] - B[i] for i in range(N)]
diff = sorted(diff)
j = 0
k = N - 1
num = 0
tmp = 0
while diff[j] < 0:
    tmp += diff[j]
    j += 1
    num += 1
    while tmp < 0:
        tmp += diff[k]
        k -= 1
        num += 1

print(num)


Measured memory_bytes: 18524
n=int(input())
nums=[input().split() for i in range(n)]
for j in range(n):
    nums[j][1]=int(nums[j][1])
    nums[j].append(int(j))


def quick_sort(nums,p,r):
    if p<r:
        q=partition(nums,p,r)
        quick_sort(nums,p,q-1)
        quick_sort(nums,q+1,r)

def partition(nums,p,r):
    i=p-1
    x=nums[r][1]
    for j in range(p,r):
        if nums[j][1]<=x:
            i+=1
            nums[i],nums[j]=nums[j],nums[i]
    nums[r],nums[i+1]=nums[i+1],nums[r]
    return i+1

quick_sort(nums,0,n-1)

key=1

for i in range(n):
    if i!=n-1:
        if nums[i][1]==nums[i+1][1]:
            if nums[i][2]>nums[i+1][2]:
                key=0

if key:
    print("Stable")

else:
    print("Not stable")

for i in range(n):
    print(nums[i][0],nums[i][1])




Measured memory_bytes: 28184
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void) {
	int n, k;
	cin >> n >> k;
	int ans = 1;
	while (n >= k) {
		n /= k;
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
    ll n; cin >> n;
    ll ac = 0; ll wa = 0; ll tle = 0; ll re = 0;
    REP(i,n){
        string s; cin >> s;
        if (s=="AC") ac++;
        else if (s=="TLE") tle++;
        else if (s=="WA") wa++;
        else re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int>vec(N+1);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  vec[N] = 0;
  int ans =0;
  for(int i=1; i < N+1; i++){
    if(vec[i] < vec[i-1]){
      ans += vec[i-1] - vec[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;

int main() {

double W,H,x,y; cin >> W >> H >> x >> y;

double ans;
int pat;

if(W/2==x&&H/2==y) pat = 1;
else pat = 0;

ans=W/2*H;
  
cout << fixed << setprecision(18);

cout << ans << ' ' << pat << endl; 

return 0;

}

Measured memory_bytes: 256
let n, a, b = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let ts = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let _ = Array.fold_left (fun c t -> if a <= t && t < b then c else c + 1) 0 ts |> Printf.printf "%d\n"

Measured memory_bytes: 384
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
long long n;vector<long long> a,b;map<long long,long long> h;set<long long> f[100010]; 
map<long long,long long> vis;
int main()
{
	cin>>n;
	for(long long i=0;i<n+n-1-1;i++)
	{
		long long x,y;
		cin>>x>>y;h[x*n+y]++,h[y*n+x]++;
		f[x].insert(y),f[y].insert(x);
		if(h[x*n+y]==2) a.push_back(x),b.push_back(y);
	}
	long long kl=0;
	for(long long i=0;i<a.size();i++)
	{
		if(h[a[i]*n+b[i]]==2)
		{++kl;
			if(f[a[i]].size()<f[b[i]].size()) swap(a[i],b[i]);
			while(f[b[i]].size())
			{
				long long t=*f[b[i]].begin();
				h[a[i]*n+t]+=h[b[i]*n+t];
				h[t*n+a[i]]+=h[b[i]*n+t];
				h[b[i]*n+t]=h[t*n+b[i]]=0;
				f[a[i]].insert(t);f[t].erase(b[i]);
				f[t].insert(a[i]);f[b[i]].erase(t);
				if(h[a[i]*n+t]==2)a.push_back(a[i]),b.push_back(t);
			}
		}
	}
	if(kl==n-1) cout<<"YES";else cout<<"NO";return 0;
}

Measured memory_bytes: 57712
#include <stdio.h>

int main(void)
{
   int n, S[1000000], q, T[1000000], i, j;
   int wa = 0;

   scanf("%d", &n);
   for ( i = 0; i < n; i++ ) {
      scanf("%d", &S[ i ]);
   }
   scanf("%d", &q);
   for ( i = 0; i < q; i++ ) {
      scanf("%d", &T[ i ]);
   }

   for ( i = 0; i < q; i++ ) {
      for ( j = 0; j < n; j++ )
         if ( T[ i ] == S[ j ] ) {
            wa = wa + 1;
            break;
         }
   }

   printf("%d\n", wa);

   return 0;
}

Measured memory_bytes: 1860
//use proconio::input;
//use std::cmp::max;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};
    ($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};
    ($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};
    ($iter:expr, usize1) => {read_value!($iter, usize) - 1};
    ($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};
}

const M: u64 = 1000_000_007;

fn main() {
    input! {
        h: usize,
        w: usize,
        a: [chars; h],
    }
    let mut dp = vec![vec![0u64; w]; h];
    dp[0][0] = 1;
    for i in 1..h {
        if a[i][0] == '.' {
            dp[i][0] = dp[i - 1][0];
        }
    }
    for j in 1..w {
        if a[0][j] == '.' {
            dp[0][j] = dp[0][j - 1];
        }
    }
    for i in 1..h {
        for j in 1..w {
            if a[i][j] == '.' {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                if dp[i][j] > M {
                    dp[i][j] -= M;
                }
            }
        }
    }
    print!("{}", dp[h - 1][w - 1]);
}


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

typedef long long ll;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0);
//#define cerr if(false)cerr
#define PRINT(x) cerr<<"\n" << (#x) << " is " << (x) << endl;
//Erase duplicates in vector
#define REMOVE_DUP(x) x.erase(unique(x.begin(), x.end()), x.end());
#define UP toupper // lowercase to uppercase;
#define DOWN tolower
#define SZ(a) (int)a.size()
#define EB emplace_back
#define PB push_back
#define REP(i, a, b) for(int i=a; i<b; i++)
#define PER(i, a, b) for(int i=a; i>=b; i--)
ostream_iterator<int> output(cout, " ");
#define MOD 1e9+7
#define INF INT_MAX;
#define lim_size 200007

void solve(){
	int k, n;
	cin >> k >> n;
	vector<int> v(n);
	for(auto &i : v)cin >> i;
	int ans = k;
	for(int i=1; i<n; i++){
		ans = min(ans, k-(v[i] - v[i-1]));
	}
	ans = min(ans, k - (k - v[n-1] + v[0]));
	cout << ans << endl; 
}

int main(){
	FAST_IO;
	int t=1; //cin >> t;
	while(t--){
		solve();
		//solve1();
	}
}			


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

vector<vector<int>> g;

vector<int> topological_sort(vector<vector<int>> &g) {
    int V = g.size();
    vector<int> ans;

    vector<int> ind(V);
    for (int i = 0; i < V; ++i) for (int x: g[i]) ind[x]++;
    queue<int> Q;
    for (int i = 0; i < V; ++i) if (ind[i] == 0) Q.push(i);
    while (!Q.empty()) {
        int v = Q.front(); Q.pop(); 
        ans.push_back(v);
        for (int x: g[v]) if (--ind[x] == 0) Q.push(x);
    }
    return ans;
}

int main() {
    int v, e;
    cin >> v >> e;
    g.resize(v);
    for (int i = 0; i < e; i++) {
        int s, t;
        cin >> s >> t;
        g[s].push_back(t);
    }

    vector<int> ans = topological_sort(g);

    for (int i = 0; i < v; i++) cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 3736