akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main(){
  int n,flag,i,j,min;
  char a[37][3],b[37][3],kari[3];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",a[i]);
    strcpy(b[i],a[i]);
  }

  flag=1; /* 1==安定(バブルソートは常に安定) */
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if( (int)(a[j][1]-a[j-1][1])<0){ 
	strcpy(kari,a[j]);
	strcpy(a[j],a[j-1]);
	strcpy(a[j-1],kari);
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%s",a[i]);
    if(i!=n-1) printf(" ");
  }
  if(flag) printf("\nStable\n");
  else printf("\nNot stable\n");

  /* 選択ソート */
  flag=1;
  for(i=0;i<n-1;i++){
    min=i;
    for(j=i+1;j<n;j++){
      if( (int)b[min][1]>(int)b[j][1]) min=j;
    }

    strcpy(kari,b[i]);
    strcpy(b[i],b[min]);
    strcpy(b[min],kari);
  }

  /* 安定かのチェック+出力 */
  for(i=0;i<n;i++){
    printf("%s",b[i]);
    if(i!=n-1) printf(" ");
    
    if(strcmp(a[i],b[i]) ) flag=0;
	
  }

  if(flag) printf("\nStable\n");
  else printf("\nNot stable\n");
      
  return 0;
}
  



Measured memory_bytes: 2052
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, con = 0;
	string s;
	
	cin>>N>>s;
	
	for(int i = 2; i < s.size(); i++){
		// string z = s[i-2] + s[i-1] + s[i];
		
		if(s[i-2] == 'A' && s[i-1] == 'B' && s[i] == 'C') con++;
	}
	
	cout<<con<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{

    int a, b, t, ans = 0, i = 0,j = 1;
    cin >> a >> b >> t;
    for(;;){
        i += a;
        if(i >= t + 1) break;
        ans += b;
    }

    cout << ans;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define Mod 998244353
#define ha "YES"
#define na "NO"
#define sp " "
typedef long long ll;

void IO()
{
#ifndef ONLINE_JUDGE
	freopen("pracin.txt", "r", stdin);
	freopen("pracout.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
	fast;
}
vector<bool> used;
vector<vector<int>> adj;
vector<int> dir[200005];
vector<int> a, b;
//bipartite graph or not using bfs

void bfs(int i)
{
	queue<int> q;
	q.push(i);
	used[i] = 1;
	a.push_back(i);
	while (!q.empty())
	{	i = q.front();
		q.pop();
		for (auto vertex : adj[i])
		{
			if (used[vertex] == -1)
			{
				used[vertex] = used[i] ^ 1;
				if (used[vertex] == 1) a.push_back(vertex);
				else b.push_back(vertex);
				q.push(vertex);
			}
			if (used[vertex] == used[i]) {
				cout << -1;
				exit(0);
			}

		}


	}
}
// binnary exponention (logn)
ll binary_exponention(ll a, ll b) {
	if (b == 0)
		return 1;
	ll res = binary_exponention(a, b / 2);
	if (b % 2)
		return res * res * a % Mod;

	return res * res % Mod;

}

// remember the question's fine details
// BE CAREFUL OF EDGE CASES....
// always check for edges cases
//  n == 1, n = size - 1, n is prime ,we



int dfs(vector<int> adj[], int n, vector<int> &dp, int i)
{
	if (dp[i] != -1 ) return dp[i];
	if (adj[i].size() == 0 ) return dp[i] = 0;
	int ans = 1;

	for (int j : adj[i])
	{
		
		
		ans = max(dfs(adj, n, dp, j)+1, ans);

	}

	return dp[i] = ans ;


}
void solve()
{


	int n, m; cin >> n >> m;
	vector<int> adj[n];
	while (m--)
	{
		int a, b; cin >> a >> b;
		adj[--a].push_back(--b);
	}


	vector<int> dp(n, -1);
	for (int i = 0; i < n; i++)
		dfs(adj, n, dp, i);

	cout << *max_element(all(dp));


}



int main()
{
	IO();

	// int t; cin >> t; while (t--)
	solve();
}

Measured memory_bytes: 17036
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
   if p[i] < p[i+1] and p[i+1] < p[i+2]:
      cnt += 1
   elif p[i] > p[i+1] and p[i+1] > p[i+2]:
      cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr front()
#define tp top()
typedef long long int ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <pii, int> ppi;
typedef pair <int, pii> pip;
#define iofast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define iofile freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
const ll LLINF = 9e18;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1);
const int SIZE = 200005;

int main (){
	
	int a, b, c;
	
	scanf("%d %d", &a, &b);
	if(a%2==0 || b%2==0) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
def exchg(a, b, c):
	count = 0
	if (a == b == c) and ((a & 1) == 0 and (b & 1) == 0 and (c & 1) == 0):
		return -1
	while((a & 1) == 0 and (b & 1) == 0 and (c & 1) == 0):
		a, b, c = (a+b)//2, (b+c)//2, (c+a)//2
		# print(a, b, c)
		count += 1
	return count
a, b, c = map(int, input().split())
print(exchg(a, b, c))

Measured memory_bytes: 9152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int a, b;
    cin >> a >> b;
    if (a < 9 && b < 9) out("Yay!");
    else out(":(");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

const int MAXN = 10100;

int n, k;

int N,SA[MAXN];
char S[MAXN], str[MAXN];

void SuffixArray()
{
    int i,j,k;
    int m = 26; // 처음 알파벳 개수
    vector <int> cnt(max(N,m)+1,0),x(N+1,0),y(N+1,0);
    for (i=1;i<=N;i++) cnt[x[i] = S[i]-'a'+1]++;
    for (i=1;i<=m;i++) cnt[i] += cnt[i-1];
    for (i=N;i;i--) SA[cnt[x[i]]--] = i;
    for (int len=1,p=1;p<N;len<<=1,m=p){
        for (p=0,i=N-len;++i<=N;) y[++p] = i;
        for (i=1;i<=N;i++) if (SA[i] > len) y[++p] = SA[i]-len;
        for (i=0;i<=m;i++) cnt[i] = 0;
        for (i=1;i<=N;i++) cnt[x[y[i]]]++;
        for (i=1;i<=m;i++) cnt[i] += cnt[i-1];
        for (i=N;i;i--) SA[cnt[x[y[i]]]--] = y[i];
        swap(x,y); p = 1; x[SA[1]] = 1;
        for (i=1;i<N;i++)
            x[SA[i+1]] = SA[i]+len <= N && SA[i+1]+len <= N && y[SA[i]] == y[SA[i+1]] && y[SA[i]+len] == y[SA[i+1]+len] ? p : ++p;
    }
}

int main() {
    scanf("%d%d",&n,&k);
    scanf("%s",str);
    N = 2*n;
    for (int i=0;i<k;i++) {
        for (int j=1;j<=n;j++) S[j] = str[j-1];
        for (int j=n+1;j<=2*n;j++) S[j] = str[2*n-j];
        SuffixArray();
        int tmp = -1;
        for (int j=1;j<=2*n;j++) {
            if (SA[j]<=n) {
                tmp = SA[j];
                break;
            }
        }
        for (int j=tmp;j<tmp+n;j++) str[j-tmp] = S[j];
        int fl = 1;
        for (int j=0;j<n;j++) if (str[j]!=str[0]) fl = 0;
        if (i==k-1||fl) break;
        reverse(str,str+n);
    }
    printf("%s\n",str);

    return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int>a(m);
    vector<int>f(n + 1);
    for(int i = 0;i < m;i++){
        cin >> a[i];
        f[a[i]]++;
    }
    for(int i = 1;i <= n;i++){
        f[i] += f[i - 1];
    }
    cout << min(f[x],f[n] - f[x]) << endl;
}


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





int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  if (a<c){
    if (b<c){
      cout<<0<<endl;
    }
    else if (d<b){
      cout<<d-c<<endl;
    }
    else{
      cout<<b-c<<endl;
    }
    
  }
  
  if (a>=c){
    if (a>d){
      cout<<0<<endl;
    }
    
    else if (b<d){
      cout<<b-a<<endl;
    }
    
    else {
      cout<<d-a<<endl;
    }
  }
    
}
  













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

int main(){
    int n;
    cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    rep(i,n){
        cin >> x[i] >> u[i];
    }
    double b = 0;
    int j = 0;
    rep(i,n){
        if(u[i]  == "BTC") b += x[i];
        else if(u[i] == "JPY") j += x[i];
    }
    double sum = b*380000 + j;
    cout << fixed << setprecision(5) << sum <<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner()
	A := sc.NextIntArray()

	sort.Ints(A)

	fmt.Println(A[2]*10 + A[1] + A[0])

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
    	Scanner s = new Scanner(System.in);
    	int n = s.nextInt();
    	int cnt = 0;
    	boolean flag = false;
    	while(n-->0) {
    		int a = s.nextInt(), b = s.nextInt();
    		if (a == b) {
    			cnt++;
    		}else {
    			cnt = 0;
    		}
    		if (cnt >= 3) {
    			flag = true;
    		}
    	}
    	if (flag) {
    		System.out.println("Yes");
    	}else {
    		System.out.println("No");
    	}
    }
}


Measured memory_bytes: 36020
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
lli a[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0;lli x=(lli)(1e18);
    cin>>n;
    for(int i=0;i<n;++i)
    {
    	cin>>a[i];
    	if(a[i]==0)
    	{
    		cout<<"0";
    		return 0;
    	}
    }
    for(int i=0;i<n;++i)
    {
    	x/=a[i];
    	if(x==0)
    	{
    		cout<<"-1";
    		return 0;
    	}
    }
    lli ans=1ll;
    for(int i=0;i<n;++i)
    	ans*=1ll*a[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 4436
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
#define INF 10000000000
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    int n;
    cin>>n;
    lli ans=1000000000000;
    vector<lli> a,b;
    rep(i,n){
        lli l;
        cin>>l;
        if(i>0) l+=a.at(i-1);
        a.push_back(l);
    }
    
    rep(i,n-1){
        lli k=abs(a.at(n-1)-2*a.at(i));
        ans=min(ans,k);
    }
    out(ans);
}

Measured memory_bytes: 2420
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
int a,b;
cin>>a>>b;
int d,r;
double f;
d = a/b;
r = a%b;
f = (double) a / b;

printf("%d %d %.6f",d,r,f);

return 0;
}


Measured memory_bytes: 3224
n = gets.to_i
x = gets.split.map(&:to_f)
y = gets.split.map(&:to_f)

(1..3).each do |p|
    d = 0.0
    n.times do |i|
        d += ((x[i] - y[i]).abs)**p
    end

    puts d**(1.0/p)
end

chebyshev = []
n.times do |i|
    chebyshev.push (x[i] - y[i]).abs
end


puts chebyshev.max

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

int h,w;
vi a,b,c;

int main(){
	cin>>h>>w;
	a=b=c=vi(h+1,w);
	for(int i=0;i<h;i++) for(int j=0;j<w;j++){
		char C;
		cin>>C;
		if(C=='W') a[i+1]--;
		else if(C=='B') b[i+1]--;
		else c[i+1]--;
	}
	a[0]=b[0]=c[0]=0;
	for(int i=1;i<=h;i++){
		a[i]+=a[i-1];
		b[i]+=b[i-1];
		c[i]+=c[i-1];
	}
	int ans=inf;
	for(int i=0;i<h-2;i++) for(int j=i+1;j<h-1;j++){
		ans=min(ans,a[i+1]+b[j+1]-b[i+1]+c[h]-c[j+1]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int a;
    cin >> a;
    cout << (a + a*a + a*a*a)<<endl;

    return 0;
}
/*
5
1 0 1
20 1 0
300 0 1
4000 0 0
50000 1 0
1 2
2 3
2 4
1 5
*/


Measured memory_bytes: 3632
fn main() {
    let n: usize = read();
    let mut a = vec![vec![0;n];n];

    let mut stack = vec![(0,n,1)];
    while let Some((l,r,lv)) = stack.pop() {
        if l < r - 1 {
            let m = (l+r) / 2;
            for i in l..m {
                for j in m..r {
                    a[i][j] = lv;
                }
            }
            stack.push((l,m,lv+1));
            stack.push((m,r,lv+1));
        }
    }

    for i in 0..n-1 {
        for j in i+1..n {
            print!("{} ",a[i][j]);
        }
        print!("\n");
    }
}
fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}

fn read<T: std::str::FromStr>() -> T{
    get_line().parse().ok().unwrap()
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int ans=1000000,cnt=0;
    string s,t;
    cin >> s >> t;
    for(int i=0; i<=s.size()-t.size(); i++){
        cnt=0;
        for(int j=0; j<t.size(); j++){
            if(s.at(i+j)!=t.at(j)) cnt++;
        }
        ans=min(ans,cnt);
    }
    cout << ans;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  vector<ll> x(n);
  ll sum = 0;
  REP(i, n) {
    cin >> x[i];
    sum += x[i];
  }
  vector<ll> a(2);
  a[0] = sum / n;
  a[1] = a[0] + 1;
  ll ans = 1e18;
  REP(i, 2) {
    ll t = 0;
    REP(j, n) {
      ll u = x[j] - a[i];
      t += u * u;
    }
    ans = min(ans, t);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define INF 1000000000
typedef struct LIST{
	int to;
	struct LIST *next;
}Edge;
Edge** init(int v){
	Edge **edge=(Edge**)calloc(v,sizeof(Edge*));
	return edge;
}
void add_edge(Edge **edge,int s,int t){
	Edge *tmp=(Edge*)malloc(sizeof(Edge));
	tmp->to=t;
	tmp->next=edge[s];
	edge[s]=tmp;
	return;
}
void delete_edge(Edge **edge,int v){
	int i;
	Edge *e,*tmp;
	FOR(i,0,v){
		e=edge[i];
		while(e!=NULL){
			tmp=e->next;
			free(e);
			e=tmp;
		}
	}
	return;
}
Edge **edge;
int color[100000];
int num[100000];
void dfs(int v,int d,int c){
	Edge *e;
	num[v]=d;
	if(color[v]==0) color[v]=c;
	for(e=edge[v];e!=NULL;e=e->next){
		if(num[e->to]<d-1)dfs(e->to,d-1,c);
	}
	return;
}
int v[100000],d[100000],c[100000];
int main(void)
{
	int n,m,q,a,b,i;
	scanf("%d%d",&n,&m);
	edge=init(n);
	FOR(i,0,m){
		scanf("%d%d",&a,&b);
		add_edge(edge,--a,--b);
		add_edge(edge,b,a);
	}
	scanf("%d",&q);
	FOR(i,0,q){
		scanf("%d%d%d",&v[i],&d[i],&c[i]);
		v[i]--;
	}
	FOR(i,0,n) num[i]=-1;
	for(i=q-1;i>=0;i--) dfs(v[i],d[i],c[i]);
	FOR(i,0,n) printf("%d\n",color[i]);
	delete_edge(edge,n);
	return 0;
}
    


Measured memory_bytes: 9600
#include <iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int x = a*b;
	int y = c*d;
	if (x>y){
		cout << x << endl; 
	}else if (x<y){
		cout << y << endl;
	}else{
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m,n){
		int a[11]={0};
		for(int i=0;i<n;i++){
			int b,c;
			cin>>b>>c;
			a[c]+=b;
		}
		int ans=0;
		for(int i=10;i>=0;i--){
			if(m-a[i]>=0) m-=a[i];
			else{
				ans+=i*(a[i]-m);
				m=0;
			}
		}
		cout<<ans<<endl;
	}
}

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

int main(){
    int r;
    cin >> r;
    if (r < 1200){
        cout << "ABC" << endl;
    }else if (r < 2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }
}

Measured memory_bytes: 256
n, m , q = map(int, input().split())
 
l = []
for i in range(q):
  a,b,c,d = map(int, input().split())
  l.append((a,b,c,d))
max_score = 0
comb = [[1]]
while len(comb) > 0:
  seed = comb.pop()
  if len(seed) == n:
    score = 0
    for j in l:
      if seed[j[1]-1]-seed[j[0]-1]==j[2]:
      
        score += j[3]
    if score > max_score:
      max_score = score
  else:
    for k in range(seed[-1], m+1):
      s = seed[:]
      s.append(k)
      comb.append(s)
print(max_score)


Measured memory_bytes: 68536
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k,x; cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=k;i<n;i++){
    cout<<(a[i-k]<a[i]?"Yes":"No")<<endl;
  }
}

Measured memory_bytes: 4416
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>
using namespace std;

int main(void){
	while(1){
		int n;
		int ans=0;
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n/4;i++){
			int a;
			cin >> a;
			ans+=a;
		}
		cout << ans << endl;

	}
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll                 long long
#define ff                 first
#define ss                 second
#define mp                 make_pair
#define pb                 push_back
#define io                 ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pie                acos(-1)
#define loop(i,a,n)        for(ll i=a;i<n;i++)
#define vi                 vector<int>
#define vl                 vector<ll>
#define vvi                vector<vector<int>>
#define pll                pair<ll,ll>
#define pii                pair<int,int>
#define vpi                vector<pii>
#define vpl                vector<pll>
#define endl               "\n"
#define se(x)              cout<<#x<<" " <<x<<endl;
#define see(x,y)           cout<<#x<<" " <<x<<" "<<#y<<" "<<y<<endl;
#define seee(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(v)             v.begin(),v.end()
#define scan(a,n)          loop(i,0,n)cin>>a[i];
#define sig                exit(0);  
#define flush              fflush(stdout);
#define present(a,b)       a.find(b)!=a.end()        
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
const int e = 100005;
const ll INF = 9e18+5;
const ll M = 1e9+7;
vector<ll>fact;
vector<ll>invfact;
template<typename T>void show(T &a , int n)
{
    loop(i,0,n)
        cout<<a[i]<<" ";
    cout<<endl;
}
template<typename T>void mod(T& a , T b)
{
    a = (a%b+b)%b;
}
template<typename T> T mpow(T a , T b)
{
    T ans = 1;
    while(b)
    {
        if(b&1)
        ans = ans*a;
        mod(ans,(T)M);
        a = a*a;
        mod(a,(T)M);
        b>>=1;
    }
    mod(ans,(T)M);
    return ans;
}
template<typename T> T modinv(T a)
{
    return mpow(a,(T)M-2);
}
void factorial()
{
    fact.resize(e);
    invfact.resize(e);
    fact[0] = 1;
    invfact[0] = 1;
    loop(i,1,e)
    {
        fact[i] = fact[i-1]*i;
        mod(fact[i],M);
    }
    loop(i,1,e)
    {
        invfact[i] = modinv(fact[i]);
        mod(invfact[i],M);
    }
}
ll ncr(ll n , ll r)
{
    ll ans ;
    ans = fact[n]*invfact[n-r];
    mod(ans,M);
    ans = ans*invfact[r];
    mod(ans,M);
    return ans;
}
void solve();
void pre();
int main() {
	// your code goes here
	io;
	int t  =1;;
	//cin>>t;
	while(t--)
    solve();
	return 0;
}
void pre()
{
    //initialize properly before each testcase
    // change value of e always as per the constraints
    // overflow
}

//Solution starts here;
void solve()
{
    pre();
    int x,y;
    cin>>x>>y;
    if(4*x>=y && y>=2*x && (4*x-y)%2==0 && (y-2*x)%2==0)
    cout<<"Yes";
    else
    cout<<"No";
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N;
    while(scanf("%lld",&N),N){
        map<int,int>cnt;
        rep(i,N){
            int a;
            scanf("%lld",&a);
            cnt[a]++;
        }

        int ans=LLONG_MAX;
        for(auto& p:cnt){
            if(p.second*2>N)ans=p.first;
        }
        if(ans!=LLONG_MAX)printf("%lld\n",ans);
        else puts("NO COLOR");
    }
    return 0;
}

Measured memory_bytes: 5260
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll sum[200010];
vector<ll>g[200010];
bool visit[200010];

int main(void){
    ll a,b,q;
    cin>>a>>b>>q;
    vector<ll>s(a+2),t(b+2);
    s[0]=-(ll)INF,s[a+1]=(ll)INF;
    t[0]=-(ll)INF,t[b+1]=(ll)INF;
    for(ll i=1;i<=a;i++)cin>>s[i];
    for(ll i=1;i<=b;i++)cin>>t[i];
    for(ll i=0;i<q;i++){
        ll x;
        cin>>x;
        ll ans = (ll)INF;
        auto itr1 = lower_bound(t.begin(),t.end(),x);
        auto itr2 = lower_bound(s.begin(),s.end(),x);
        ll rt = (*itr1);
        ll rs = (*itr2);
        itr1--;itr2--;
        ll lt = (*itr1);
        ll ls = (*itr2);
        ans = min(ans,max(rt,rs)-x);
        ans = min(ans,x-min(lt,ls));
        ans = min(ans,min(2*rs-x-lt,x+rs-2*lt));
        ans = min(ans,min(2*rt-x-ls,x+rt-2*ls));
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 8832
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
using ulong = unsigned long;
using ll = long long;
const int M = 1e9 + 7;
#pragma unused(M)

struct Node{
    vector<Node*> nodes;
    int mini = -M, maxi = M;
    bool even;
    void propagate(Node* from = nullptr){
        if(mini == -M && !from){ return; }
        auto size = maxi - mini;
        if(mini == -M){
            even = !from -> even;
            mini = from -> mini - 1;
            maxi = from -> maxi + 1;
        }else if(from){
            mini = max(mini, from -> mini - 1);
            maxi = min(maxi, from -> maxi + 1);
            if(even == from -> even || mini > maxi){
                cout << "No" <<endl;
                exit(0);
            }
        }

        if(from && size == maxi - mini){ return; }
        for(Node* n : nodes){
            n -> propagate(this);
        }
    }
    void set(int num){
        mini = maxi = num;
        even = !(num % 2);
    }
    void print(){
        cout << mini << endl;
    }
};

int main(){
	int n, k;
	cin >> n;
    vector<Node> nodes(n);
    for(int i=0;i<n-1;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        nodes[a].nodes.push_back(&nodes[b]);
        nodes[b].nodes.push_back(&nodes[a]);
    }
    cin >> k;
    for(int i=0;i<k;i++){
        int v, p;
        cin >> v >> p;
        v--;
        // nodes[v].cands.insert(p);
        nodes[v].set(p);
    }

    for(int i=0;i<n;i++){
        nodes[i].propagate();
    }

    cout << "Yes" <<endl;
    for(int i=0;i<n;i++){
        nodes[i].print();
    }

	return 0;
}



Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=210000;
int n,a[N];
vector<PII> dp[N];
int main() {
	scanf("%d",&n);
	rep(i,1,n+1) {
		scanf("%d",a+i);
	}
	n+=1;
	dp[0].pb(PII(0,0));
	rep(i,1,n+1) {
		int d=a[i]-a[i-1];
		vector<PII> z;
		for (auto q:dp[i-1]) {
			z.pb(mp(0,q.se+2));
			z.pb(mp(max(q.fi+min(d,0),0),q.se+1));
			if (q.fi+max(d,0)<=a[i]) z.pb(mp(q.fi+max(d,0),q.se));
		}
		sort(all(z));
		int mz=1<<30;
		for (auto p:z) {
			if (p.se<mz) {
				mz=p.se;
				dp[i].pb(p);
			}
		}
	}
	printf("%d\n",dp[n][0].se);
}

Measured memory_bytes: 15360
#include <iostream>

using namespace std;

int main()
{
    int n, ans = 1;
    char buf = '$';
    string s;
    cin >> n;
    cin >> s;

    for(int i = 1; i < n; ++i)
        if(s[i] != s[i - 1]) ++ans;
    
    cout << ans;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する
ll mod = 1000000007;


int main() {
    string s;
    cin >> s >> s;
    int i = 0;
    ll ans = 1;
    int patarn;
    if( i + 1 < s.size() && s[i] == s[i+1]){
        ans = 6;
        i += 2;
        patarn = 2;
    }else{
        ans = 3;
        patarn = 1;
        i++;
    }
    while(i < s.size()){
        if( i + 1 < s.size() && s[i] == s[i+1]){
            if(patarn == 1){
                ans = (ans * 2) % mod;
            }else{
                ans = (ans * 3) % mod;
            }
            patarn = 2;
            i+=2;
        }else{
            if(patarn == 1){
                ans = (ans * 2) % mod;
            }else{
                ans = (ans * 1) % mod;
            }
            patarn = 1;
            i++;
        }
    }

    cout << ans << endl;


    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N, K;
	cin >> N >> K;
	vector<ll> R(N+1);
	R[0] = 0;
	for (ll i = 1; i < N+1; i++)
		R[i] = R[i-1] + i;
	ll ans = 0;
	for (int i = K; i <= N+1; i++)
	{
		ll mn = R[i-1];
		int idx = max(0, N-i);
		ll mx = R[N] - R[idx];
		ans = (ans + (mx - mn + 1)) % 1000000007;
	}
	cout << ans << endl;
}



Measured memory_bytes: 4844
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int w = parseInt(sc.next());
		int h = parseInt(sc.next());
		int n = parseInt(sc.next());
		int[] x = new int[n]; 
		int[] y = new int[n]; 
		int[] a = new int[n];
		int xl=0;
		int xr=w;
		int yb=0;
		int yt=h;
		for (i = 0; i < n; i++) {
			x[i] = parseInt(sc.next());
			y[i] = parseInt(sc.next());
			a[i] = parseInt(sc.next());
			switch(a[i]) {
			case 1:
				if(xl < x[i]) {
					xl = x[i];
				}
				break;
			case 2:
				if(xr > x[i]) {
					xr = x[i];
				}
				break;
			case 3:
				if(yb < y[i]) {
					yb = y[i];
				}
				break;
			case 4:
				if(yt > y[i]) {
					yt = y[i];
				}
				break;
			}
		}
		sc.close();
		int xx =xr - xl;  
		int yy =yt - yb;
		if(xx<0)xx=0;
		if(yy<0)yy=0;
		out.println(xx*yy);
	}
}


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

using namespace std;
#define ll long long
#define pb push_back

int main()
{	
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll ans1 = a*c;
	ll ans2 = a*d;
	ll ans3 = b*c;
	ll ans4 = b*d;
	cout << max(ans1, max(ans2, max(ans3, ans4))) << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int b[n];
    for (int i = 0; i < n; i++) {
        b[i] = a[i] - i;
    }
    nth_element(b, b+n/2, b+n);

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += abs(a[i] - i - b[n/2]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val d = sc.nextInt()

    def abs(x: Int): Int = Math.abs(x)
    val ans = if ((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d) {
      "Yes"
    } else {
      "No"
    }
    println(ans)
  }
}

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

int N, A, B, C, D;
string S;

bool solve() {
	for (int i = A; i <= B - 1; i++) {
		if (S[i] == '#' && S[i + 1] == '#') return false;
	}
	for (int i = C; i <= D - 1; i++) {
		if (S[i] == '#' && S[i + 1] == '#') return false;
	}

	if (A < B && C < D) return true;

	// A < B && D < C
	for (int i = B - 1; i <= D - 1; i++) {
		if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') return true;
	}
	return false;
}

int main() {
	cin >> N >> A >> B >> C >> D >> S; A--; B--; C--; D--;
	bool I = solve();
	if (I == true) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

template<class T,uint mod>
struct RollingHash_{
	vector< uint > hashed, power;

	inline uint mul(uint a, uint b){
		return a*(unsigned long long)b%mod;
	}
	RollingHash_(){}
	RollingHash_(T s, uint base = 10007) {
		int sz = (int) s.size();
		hashed.assign(sz + 1, 0);
		power.assign(sz + 1, 0);
		power[0] = 1;
		for(int i = 0; i < sz; i++) {
			power[i + 1] = mul(power[i], base);
			hashed[i + 1] = mul(hashed[i], base) + s[i];
			if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
		}
	}

	uint get(int l, int r){
		uint ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
		if(ret >= mod) ret -= mod;
		return ret;
	}
};

typedef pair<uint,uint>Hash;

template<class T>
struct RollingHash{
	RollingHash_<T,998244353>RH1;
	RollingHash_<T,1000000007>RH2;

	RollingHash(){}
	
	RollingHash(T s){
		RH1=RollingHash_<T,998244353>(s);
		RH2=RollingHash_<T,1000000007>(s);
	}

	Hash get(int l,int r){
		return make_pair(RH1.get(l,r),RH2.get(l,r));
	}
};

int n;string s;
RollingHash<string>hs;

bool C(int t){
	rep(i,s.size()){
		for(int j=i+t;j+t<=s.size();j++){
			if(hs.get(i,i+t)==hs.get(j,j+t))return true;
		}
	}
	return false;
}

int main(){
	cin>>n>>s;
	hs=RollingHash<string>(s);
	int ok=0,ng=n+1;
	while(ng-ok>1){
		int t=(ok+ng)/2;
		if(C(t))ok=t;
		else ng=t;
	}
	cout<<ok<<endl;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	N := nextInt()
	curH := nextInt()
	cur := 0
	ans := 0
	for i := 1; i < N; i++ {
		H := nextInt()
		if H <= curH {
			cur++
			if cur >= ans {
				ans = cur
			}
		} else {
			cur = 0
		}
		curH = H
	}
	fmt.Fprintln(out, ans)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 2304
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

struct UF{
    int N;
    vector<int>rank;
    vector<int>parent;
    vector<ll>sz;
    void init(int n){
        N = n;
        rank = std::vector<int>(N, 0);
        sz = std::vector<ll>(N, 1);
        parent = std::vector<int>(N);
        for(int i = 0; i < N; i++)parent[i] = i;
    }
    UF(int n = 0){
        if(n)init(n);
    }
    int find(int x){
        if(parent[x] == x)return x;
        return parent[x] = find(parent[x]);
    }
    ll unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y)return 0;
        
        ll tmp = sz[x] * sz[y];
        ll tmp2 = sz[x] + sz[y];
        sz[x] = tmp2;
        sz[y] = tmp2;
        if(rank[x] < rank[y]){
            parent[x] = y;
        }
        else{
            parent[y] = x;
            if(rank[x] == rank[y])rank[x]++;
        }
        return tmp;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int N, M;
    vector<int>A;
    vector<int>B;

    cin >> N >> M;
    UF uf(N);
    ll ans = 0;
    for(ll i = N; i >= 1; i--)ans += (i - 1);
    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        A.push_back(a-1);
        B.push_back(b-1);
    }
    vector<ll>tmp;
    for(int i = M - 1; i >= 0; i--){
        tmp.push_back(ans);
        if(uf.same(A[i], B[i])){
            continue;
        }
        ll t = uf.unite(A[i], B[i]);
        ans -=t;

    }
    for(int i = M - 1; i >= 0; i--)cout<<tmp[i]<<endl;

    
    return 0;
}

Measured memory_bytes: 4592
s = input()
ind_A = 1
ind_Z = len(s)
for i in range(len(s)):
  if s[i]=='A':
    break
  ind_A +=1
  
for i in range(len(s)):
  if s[len(s)-i-1] == 'Z':
    break
  ind_Z -=1
  
print(ind_Z-ind_A+1)

Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; i++) {
    cin >> W[i];
  }
  int ans = 99999999;
  for (int i = 0; i < N; i++) {
    int sone = 0;
    int stwo = 0;
    for (int j = 0; j < i; j++) {
      sone += W[j];
    }
    for (int j = i; j < N; j++) {
      stwo += W[j];
    }
    ans = min(ans, abs(sone - stwo));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque

def main():
    process_num, max_q_time = map(int, input().split())
    r_schedule_lst = deque([])
    for i in range(0, process_num):
        r_schedule_lst.append(list(input().split()))
    
    current_process = []
    elapsed_time = 0
    res = []
    while r_schedule_lst:
        cur_process = list(r_schedule_lst.popleft())
        cur_process_name = cur_process[0]
        cur_process_time = int(cur_process[1])
        
        remaining_time = cur_process_time - max_q_time
        if remaining_time > 0:
            elapsed_time += max_q_time
            r_schedule_lst.append([cur_process_name, remaining_time])
        else:
            elapsed_time += cur_process_time
            res.append([cur_process_name, elapsed_time])
        
    for n, t in res:
        print(n, t)
            
if __name__ == '__main__':
    main()
    


Measured memory_bytes: 15096
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        Map<Integer, int[]> map = new TreeMap<>();
        for (int i = 0; i < m; i++) {
            int a = Integer.parseInt(sc.next());
            int[] ary = new int[2];
            ary[0] = a;
            ary[1] = i;
            int b = Integer.parseInt(sc.next());
            map.put(b, ary);
        }
        String[] ans = new String[m];
        int[] pary = new int[n];
        for (int[] num : map.values()) {
            pary[num[0] - 1]++;
            ans[num[1]] = String.format("%06d%06d", num[0], pary[num[0] - 1]);
        }
        for (String s: ans) {
            System.out.println(s);
        }
    }
}

Measured memory_bytes: 117512
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

n,m = map(int,input().split())
Bridge = [list(map(int,input().split())) for i in range(m)]

uf = UnionFind(n)

Inconvenience = [n*(n-1)//2]

for b in reversed(Bridge):
  if not uf.same(b[0]-1,b[1]-1):
    Inconvenience += [Inconvenience[-1]-uf.size(b[0]-1)*uf.size(b[1]-1)]
    uf.union(b[0]-1,b[1]-1)
  else:
    Inconvenience += [Inconvenience[-1]]
    
Inconvenience.pop()
for i in reversed(Inconvenience):
  print(i)

Measured memory_bytes: 111960
import java.io.*;
import java.util.*;
class Main{
public static void main(String args[]){
	Scanner in = new Scanner(System.in);
	char[] a = in.next().toCharArray();
  	char[] b = in.next().toCharArray();
  	char[] c = in.next().toCharArray();
  	int i1=0,i2=0,i3=0;
  	char next='a';
  	char winner;
  	while(true){
      	if(next=='a'){
          	if(i1==a.length){
            	System.out.println("A");
              	break;
            }
        	next = a[i1++];
        }
      	else if(next=='b'){
        	if(i2==b.length){
            	System.out.println("B");
              	break;
            }	
          	next = b[i2++];
        }
      	else{
          	if(i3==c.length){
            	System.out.println("C");
              	break;
            }
        	next = c[i3++];
        }
    }
  	
}
}

Measured memory_bytes: 21972
#include <stdio.h>
int main(void){
	int p,q,r;
	scanf("%d %d %d", &p, &q, &r);
	int a=p+q,b=q+r,c=p+r;
	if(a<=b && a<=c)printf("%d\n", a);
	else if(b<=a && b<=c)printf("%d\n", b);
	else if(c<=b && c<=a)printf("%d\n", c);
	return 0;


}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <ctime>
#include <map>
#include <set>

using namespace std;

#define endl "\n"
#define X first
#define Y second
#define Z third
#define mp make_pair
#define mt make_triple

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.141592653589793;
const ld E = 2.71828182845904523;
const ll LLINF = 4000000009000000099;
const ll INF = 1009000099;
const ll MOD7 = 1000000007;
const ll MOD9 = 1000000009;

template<class A, class B, class C> struct triple { A first; B second; C third; triple(A, B, C); triple(); };
template<class A, class B, class C> triple<A, B, C>::triple(A a, B b, C c) { first = a; second = b; third = c; }
template<class A, class B, class C> triple<A, B, C>::triple() { }
template<class A, class B, class C> triple<A, B, C> make_triple(A a, B b, C c) { triple<A, B, C> t(a, b, c); return t; }
template<class A, class B, class C> bool operator<(triple<A, B, C> a, triple<A, B, C> b) { if (a.first != b.first) return a.first < b.first; if (a.second != b.second) return a.second < b.second; if (a.third != b.third) return a.third < b.third; }
template<class T> T inline sqr(T a) { return a * a; }

ll bpow(ll a, ll d, ll mod) { if (d == 0) return 1; ll t = bpow(a, d / 2, mod); t = (t * t) % mod; if (d & 1) t = (t * a) % mod; return t; }
ll bpow(ll a, ll d) { if (d == 0) return 1; ll t = bpow(a, d / 2); t = (t * t); if (d & 1) t = (t * a); return t; }
ll gcd(ll a, ll b) { while (a && b) if (a > b) a %= b; else b %= a; return a + b; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll C(ll n, ll k) { ll res = 1; for (int i = 1; i <= k; ++i) res = res * (n - k + i) / i; return res; }
ll C(ll n, ll k, ll mod) { ll u = 1, d = 1; for (int i = 2; i <= n; ++i) u = (u * i) % mod; int x = max(k, n - k), z = min(k, n - k); for (int i = 2; i <= x; ++i) { d = (d * i) % mod; if (i <= z) d = (d * i) % mod; } d = bpow(d, mod - 2, mod); ll res = (u * d) % mod; return res; }

void solve()
{
	int n; cin >> n;
	vector<vector<int>> g(n, vector<int>(n));
	ll ans = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
		{
			cin >> g[i][j];
			ans += g[i][j];
		}

	auto check = g;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			for (int k = 0; k < n; ++k)
				check[i][j] = min(check[i][j], check[i][k] + check[k][j]);

	if (check != g)
	{
		cout << -1;
		return;
	}


	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
		{
			int d = 1;
			for (int k = 0; k < n && d; ++k)
				if (k != i && k != j)
					if (g[i][k] + g[k][j] == g[i][j])
						ans -= g[i][j], d = 0;
		}
	cout << ans / 2;
}


int main() {
	ios::sync_with_stdio(0);
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
#else
#endif
	solve();
	return 0;
}

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

typedef long long ll;
typedef unsigned long long int llu;
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define mem(a, v) memset(a, v, sizeof(a))
#define PI acos(-1)
#define S(a) scanf("%d",&a)
#define SL(a) scanf("%lld",&a)
#define S2(a, b) scanf("%d%d",&a,&b)
#define nl printf("\n")
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x, y) cout<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<" | "<<#z<<" : "<<z<<endl;
#define debv(x) {cout<<#x<<" : "<<endl; for(int ii =0; ii < x.size(); ii++) cout<<x[ii]<<" "; cout<<endl; }
#define debarr(x, xs) {cout<<#x<<" : "<<endl; for(int ii =0; ii < xs; ii++) cout<<x[ii]<<" "; cout<<endl; }
//auto T=clock(); 
//cout<<double(clock()-T)/CLOCKS_PER_SEC<<'\n';
//cout << fixed << setprecision(10) << f(0, 0, 0) << "\n";
const ll mod = 1000000007LL;
const int lmt = 1000005;

int main(){
    int r, g, b;
    cin >> r>> g >> b;
    int num = (r*100) + (g*10) + b;
    if(num%4 == 0)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

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

using namespace std;

bool mark[28];

int main (){
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        int x = s[i] - 'a';
        mark[x] = true;
    }
    for (int i = 0; i < 26; i++){
        if (mark[i] == false){
            char a = i + 'a';
            return cout << a, 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512