akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

#define R register
#define ll long long
const int MAXN=3e3+10;
const int mod=1e9+7;

inline int qpow(int x,int p)
{
	int res=1;
	while(p)
	{
		if(p&1) res=(ll)res*x%mod;
		x=(ll)x*x%mod;
		p>>=1;
	}
	return res;
}

int n,q;
int a[MAXN];
int f[MAXN][MAXN];

int main()
{
	scanf("%d%d",&n,&q);
	for(R int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(R int i=1;i<=n;i++)
		for(R int j=1;j<=n;j++)
			f[i][j]=a[i]<a[j]?1:0;
	int inv=qpow(2,mod-2);
	for(R int i=1;i<=q;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		f[x][y]=f[y][x]=(ll)(f[x][y]+f[y][x])*inv%mod;
		for(R int j=1;j<=n;j++)
		{
			if(j==x||j==y) continue;
			f[j][x]=f[j][y]=(ll)(f[j][x]+f[j][y])*inv%mod;
			f[x][j]=f[y][j]=(ll)(f[x][j]+f[y][j])*inv%mod;
		}
	}
	int ans=0;
	for(R int i=1;i<=n;i++)
		for(R int j=1;j<i;j++)
			ans=(ans+f[i][j])>mod?ans+f[i][j]-mod:ans+f[i][j];
	printf("%lld\n",(ll)ans*qpow(2,q)%mod);
	return 0;
}

Measured memory_bytes: 35456
N = int(input())

# Nが奇数の時は2が1つもないので0
if N % 2 == 1:
    print(0)
# Nが偶数の時は5の数を数える
# N以下の2の倍数のうち
# 5の倍数の数 + 25の倍数の数 + ...
else:
    ans = 0
    for i in range(1, 50):
        ans += (N // 5 ** i) // 2

    print(ans)


Measured memory_bytes: 2940
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]
ab.sort(key=lambda x:x[1])
ans = 0
endplace = 0
for ai, bi in ab:
    if endplace <= ai:
        endplace = bi
        ans += 1
print(ans)


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> A(n),B(n);
  for(int i=0;i<n;i++){
    cin >> A.at(i);
  }
  
  for(int i=0;i<n;i++){
    B.at(i)=A.at(i);
  }
  
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  for(int i=0;i<n;i++){
    
    for(int j=0;j<n-1;j++){
      
      if(A.at(i)!=B.at(j)){
        cout << B.at(j) << endl;
        break;
      }
      if(A.at(j)==B.at(j)){
        cout << B.at(j+1) << endl;
        break;
      }
    }
  }
}


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

using namespace std;

#define forn for (ll i = 0; i < n; i++)
#define form for (ll j = 0; j < m; j++)
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (ll i = a; i < b; i++)

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

ll gcd(ll a, ll b){
    ll r;
    while (b != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}


ll *calc_z(string s){
    ll n = s.size();
    ll *z = new ll[n] {0};
    ll l = 0, r = 0;
    for (ll i = 1; i < n; i++){
        if (r >= i) z[i] = min(z[i-l], r-i+1);
        while (z[i]+i < n && s[z[i]] == s[z[i]+i]) z[i]++;
        if (i + z[i] - 1 > r){
            l = i;
            r = i+z[i]-1;
        }
    }
    return z;
}

ll find_lower(ll *a, ll n, ll v){
    ll l = -1, r = n;

    while (r>l+1){
        ll m = (l+r)/2;

        if (a[m] >= v) r = m;
        else l = m;
    }
    if (r == n) return n-1;
    if (a[r] == v) return r;
    return r == 0 ? 0 : r-1;
}

void init(){
}

void solve(){
    int x, y;
    cin >> x >> y;
    int s1 = 4*x-y;
    int s2 = y-2*x;
    if ((s1 >= 0 && s1 % 2 == 0) && (s2 >= 0 && s2 % 2 == 0)) cout << "Yes\n";
    else cout << "No\n";
}


int main(){
    //init();

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

    //ll t; cin >> t; while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
const int INF = 1001001001;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define re0 return 0
#include<string.h>
int npr(int n , int r){//nPr
    r = n - r;
    int sum = 1;
    int i;
    for (i=n;i>=r+1;i--)sum*=i;
    return sum;
}
int gcd(int a, int b) {//最大公約数
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {//最小公倍数
    return a * b / gcd(a, b);
}
int digsum(int n) {//桁和
    int res = 0;
    while(n > 0) {
        //res += n%10;
        //　↑をres++;にすれば桁数
         res++;
        n /= 10;
    }
    return res;
}
bool isPrime(int x){//素数判定
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
/*bit全探索
for (int bit = 0; bit < (1<<N); ++bit) {
}
if (bit & (1 << i)) {
}
*/


signed main(){
    int a;
    cin >> a;
    cout << a + (a*a) + (a*a*a) <<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;

int main() {
    // input, ready
    int N;
    ll K;
    cin >> N >> K;
    vector<int> town(N+1);
    for (int i=1; i<=N; i++) {
        cin >> town[i];
    }

    // resolve
    map<int,int> teleport;
    map<int,int> teleport_rev;
    int cnt =-1;
    int now=1;
    vector<bool> gone(N+1,false);
    while(!gone[now]) {
        cnt++;
        teleport[now] = cnt;
        gone[now] = true;
        teleport_rev[cnt] = now;
        now = town[now];
    }

    // output
    ll ans = 0;
    if (K <= teleport[now]) cout << teleport_rev[K] << endl;
    else {
        ll ans = teleport[now] + (K-teleport[now]) % (ll)(cnt - teleport[now]+1);
        cout << teleport_rev[ans] << endl;
    }

    // cout << fixed << setprecision(10) << middle << endl;

    return 0;
}


Measured memory_bytes: 22348
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  int n,k,r,s,p;
  cin >> n >> k;
  cin >> r >> s >> p;
  string t;
  cin >> t;

  vector<char> a(t.size());

  int ret = 0;

  REP(i,t.size()){
    int add = 0;
    if(t[i] == 'r'){
      a[i] = 'r';
      add = p;
    }
    else if(t[i] == 's'){
      a[i] = 's';
      add = r;
    }
    else if(t[i] == 'p'){
      a[i] = 'p';
      add = s;
    }
    if(i >= k){
      if(a[i] == a[i - k]){
        add = 0;
        a[i] = 'n';
      }
    }
    // debug(add);
    ret += add;
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
int main (void) {
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,k; cin >> n >> k;
    ll r = n%k;
    cout << min(r,k-r) << '\n';
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int x[20][20];
signed main(){
    int n,d,ans=0;
    cin>>n>>d;
    rep(i,n){
        rep(j,d)cin>>x[i][j];
    }
    rep(i,n-1){
        for(int j=i+1;j<n;j++){
            int sum=0;
            rep(k,d){
                sum+=abs(x[i][k]-x[j][k])*abs(x[i][k]-x[j][k]);
            }
            int q=sqrt(sum);
            if(q*q==sum)ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;

int main(){
 	string added_symbol[] = {"dream","dreamer","erase","eraser" };
  	string s;
   	cin >> s;
  	
	reverse(s.begin(), s.end());
  	for(int i=0; i<4; i++) reverse(added_symbol[i].begin(), added_symbol[i].end());
  	bool judge;
  	for(int i=0; i<s.length();){
      	judge = false;
  		for(int j=0; j<4; j++){
          string temp = added_symbol[j];
          s.substr(i, temp.size());
          if(s.substr(i, temp.size()) ==  temp ){
            i+=added_symbol[j].length();
            judge = true;
          }
        }
      
      	if(judge == false) break;
    }
  
  	if(judge){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second

inline bool cmp (pair<pair<ll, ll>, ll> p1, pair<pair<ll, ll>, ll> p2) {
	if(p1.F.F == p2.F.F)
		return p1.S < p2.S;
	return p1.F.F < p2.F.F;
}

string convert(ll n) {
	int r;
	string ans, ansr;
	while(n > 0) {
		r = n%10;
		ansr.push_back((char)(r + 48));
		n /= 10;
	}
	int len = (int)ansr.size();
	for(int i = 0; i < 6-len; i++) {
		ans.push_back('0');
	}
	for (string::reverse_iterator rit=ansr.rbegin(); rit!=ansr.rend(); ++rit) {
		ans.push_back(*rit);
	}
	return ans;
}

int main() {
	ll n, m;
	vector<pair<pair<ll, ll>, ll> > v;
	map<ll, string> id;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int p, y;
		cin >> p >> y;
		v.push_back(make_pair(make_pair(p, i+1), y));
	}
	sort(v.begin(), v.end(), cmp);
	string first, last;
	int num1, num2 = 1;
	for (int i = 0; i < m; i++) {
		//cout << v[i].F.S << " " << v[i].F.F << " " << v[i].S << endl;
 		num1 = v[i].F.F;
		if (i != 0 && v[i].F.F == v[i-1].F.F)
			num2++;
		else
			num2 = 1;
		first = convert(num1);
		last = convert(num2);
		id[v[i].F.S] = first + last;
	}
	for (int i = 1; i <= m; i++) {
		cout << id[i] << endl;
	}
}

Measured memory_bytes: 17008
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	string s;
	cin >> s;
	int n = s.size();
	string ans;
	for(int i=0;i<n;i+=2){
		ans = ans + s[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main() {
  int N, verdict[4] = {0}; // AC, WA, TLE, RE
  scanf("%d", &N);

  for(int i = 0; i < N; i++) {
    char str[5];
    scanf("%s", str);
    
    switch(str[0]) {
      case 'A':
        verdict[0]++;
        break;
      case 'W':
        verdict[1]++;
        break;
      case 'T':
        verdict[2]++;
        break;
      case 'R':
        verdict[3]++;
        break;
    }
  }

  printf("AC x %d\n", verdict[0]);
  printf("WA x %d\n", verdict[1]);
  printf("TLE x %d\n", verdict[2]);
  printf("RE x %d\n", verdict[3]);

  return 0;
}

Measured memory_bytes: 1712
#template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
A = inputlist()
c = Counter(A)
key = c.keys()
count = 0
for i in key:
    count += c[i]-1
l = len(set(A))
if count % 2 == 1:
    l-=1
print(l)

Measured memory_bytes: 21084
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			long K = scan.nextLong();

			long s = 7%K;
			long count =1;

			if(s==0) {
				System.out.println(count);
				return;
			}

			//ここからは奇数のみ。
			while(true) {
				s = ((10*s)%K+7)%K;
				count++;
				if(s==0)break;
				if(count==1000500) {
					count = -1;
					break;
				}
			}

			System.out.println(count);

		}
	}
}


Measured memory_bytes: 35856
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define pop(v) (v).back(); (v).pop_back()
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

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

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

    lint n, a[200], ans = 0;
    cin>>n;
    rep(i, n)cin>>a[i];
    while(1){
        rep(i, n){
            if(a[i]%2)goto L_break1;
            else a[i] /= 2;
        }
        ans++;
    }
L_break1:
    co(ans);
}

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

using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
template<typename T> using id_setp = tree<pair<T,T>,null_type,less<pair<T,T>>,rb_tree_tag,tree_order_statistics_node_update> ;

#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+1;
 
typedef long long ll;
typedef long double ld;
 
int main()
{
   IOS();
   ll n,m,i,j;
   cin>>n>>m;
   vector<pair<ll,ll>> v(n+1);
   f(i,0,n+1)
   {
      v[i].F=0;v[i].S=0;
   }
   ll c[n+1]={0};
   f(i,0,m)
   {
      string s;
      ll x;
      cin>>x>>s;
      if(v[x].S==0 && s=="WA")
      {
         v[x].F++;
      }
      else if(s=="AC")
      {
         v[x].S=1;
         c[x]=1;
      }
   }
   ll p=0,ca=0;
   f(i,1,n+1)
   {
      if(c[i])
         ca++;
      if(v[i].S==1)
         p+=v[i].F;
   }
   cout<<ca<<' '<<p<<'\n';

   return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

typedef struct UnionFindTree{
  vector<int> par;
  vector<int> treerank;
  
  UnionFindTree(int n){
    par.resize(n); treerank.resize(n);
    rep(i, n) par[i] = i, treerank[i] = 0;
  }
  
  int find(int x){
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  
  void unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return;
    if(treerank[x] < treerank[y]) swap(x, y);
    if(treerank[x] == treerank[y]) treerank[x]++;
    par[y] = x;
    return;
  }
  
  bool same(int x, int y){
    return find(x) == find(y);
  }
}UF;
 
template<class T> struct edge{
    int from, to; T cost;
    edge(int f, int t, T c){
        from = f; to = t; cost = c;
    }
};
 
template<class T> struct Graph{
    vector<vector<edge<T>>> G;
    int n;
    
    Graph(int n_){
        n = n_;
        G.resize(n);
    }
    
    void add_edge(int f, int t, T c){
        G[f].emplace_back(f, t, c);
    }
    
    vector<T> dijkstra(int s){
        using P = pair<T, int>;
        priority_queue<P, vector<P>, greater<P>> que;
        vector<T> d(n, numeric_limits<T>::max());
        d[s] = 0;
        que.push(P((T)0, s));
        while(!que.empty()){
            P p = que.top(); que.pop();
            int v = p.second;
            if(d[v] < p.first) continue;
            for(edge<T> &e : G[v]){
                if(d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
        return d;
    }
    
    T kruskal(){
        vector<edge<T>> E;
        rep(i, n)for(edge<T> &e: G[i]) E.push_back(e);
        sort(E.begin(), E.end(), [](const edge<T> &e1, const edge<T> &e2){return e1.cost < e2.cost;});
        UF uf(n);
        T res = 0;
        for(edge<T> &e: E){
            if(!uf.same(e.from, e.to)){
                uf.unite(e.from, e.to);
                res += e.cost;
            }
        }
        return res;
    }
    
    vector<int> toposo(){
        vector<int> ret(n), in(n, 0);
        rep(i, n)for(edge<T> &e: G[i]) ++in[e.to];
        int cur = 0;
        stack<int> st;
        rep(i, n)if(!in[i]) st.push(i);
        while(!st.empty()){
            int v = st.top(); st.pop();
            ret[cur++] = v;
            for(edge<T> &e: G[v]){
                --in[e.to];
                if(!in[e.to]) st.push(e.to);
            }
        }
        return ret;
    }
};

int main(){
    int v, e;
    scanf("%d%d", &v, &e);
    Graph<int> g(v);
    rep(i, e){
        int s, t;
        scanf("%d%d", &s, &t);
        g.add_edge(s, t, 0);
    }
    vector<int> ans = g.toposo();
    rep(i, v) printf("%d\n", ans[i]);
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	string t; cin>>t;
	string ans;
	int n=s.size();
	int m=t.size();
	rep(i,0,m){
		ans.push_back(s[i]);
		ans.push_back(t[i]);
	}
	if(n-m) ans.push_back(s[n-1]);
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int r;
    cin >>r;
    if(r < 1200)
        cout << "ABC";
    if(r >= 1200 && r < 2800)
        cout << "ARC";
    if(r >= 2800)
        cout << "AGC";
    return 0;

}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int max(int ,int );

int main(void){
  int min,x=0;
  int e;
  cin >> e;
 
  while(e!=0){
    min=e;
    for(int z=0;z*z*z<=e;z++){
      for(int y=0;y*y <= e - z*z*z ;y++){
	x = e - z*z*z - y*y;
	if(x+y+z<min) min = x+y+z;
      }
    }
      
    cout << min << endl;
    cin >> e;
  }
  return 0;
}

  

Measured memory_bytes: 3072
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n, k;
  cin >> n >> k;
  int p;
  rep(i, n) {
    int a;
    cin >> a;
    if (a == 1) p = i;
  }
  /*int l = p, r = n-p-1;
  cout << l/(k-1) + (r+k-2)/(k-1) << endl;*/
  cout << (n-1+k-2)/(k-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(void){
    double r;
    
    cin >> r;
    
    cout << fixed << setprecision(5);
    cout << M_PI*r*r << " " << M_PI*2*r << endl;
    
    return 0;
}



Measured memory_bytes: 3228
import sys

sys.setrecursionlimit(10 ** 5)


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n
        self.taken = [0] * n

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

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            new_root = r1
        else:
            d1 = self.table[r1]
            d2 = self.table[r2]
            if d1 <= d2:
                self.table[r2] = r1
                self.table[r1] += d2
                self.taken[r1] += self.taken[r2]
                new_root = r1
            else:
                self.table[r1] = r2
                self.table[r2] += d1
                self.taken[r2] += self.taken[r1]
                new_root = r2

        cells = -self.table[new_root]
        taken = self.taken[new_root]
        if cells > taken:
            self.taken[new_root] += 1
            return True
        return False


n, h, w = map(int, input().split())
hw = h + w
cards = []
for line in sys.stdin:
    r, c, a = map(int, line.split())
    cards.append((a, r - 1, h + c - 1))
cards.sort(reverse=True)

uft = UnionFind(hw)
ans = 0

for a, r, c in cards:
    if uft.union(r, c):
        ans += a
print(ans)


Measured memory_bytes: 23912
n,k,q=map(int,input().split())
l=[]
for i in range(n):
    l.append(k)

for j in range(n):
    l[j]=l[j]-q
#print(l)
    
for b in range(q):    
    a=int(input())
    l[a-1]+=1

for c in range(n):
    if l[c]>0:
        print('Yes')
    else:
        print('No')


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

int main(){
    long long int a,b,c,k;
    cin>>a>>b>>c>>k;

    if(k>a){
        k=k-a;
        //a=k;
        if(k>b){
            k=k-b;
            a=a-k;
        }
        
    }else {
        a=k;
    }
    cout<<a<<endl;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==5&&b==5&&c==7){
    cout<<"YES";
  }
  else if(a==5&&b==7&&c==5){
    cout<<"YES";
  }
  else if(a==7&&b==5&&c==5){
    cout<<"YES";
  }
  else{
    cout<<"NO";
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int tmpmin=1e9;
int main(int argc,char const* argv[])
{
  int ans=INF;
  int n,T;
  cin >> n >> T;
  for(int i=0;i<n;i++)
    {
      int c,t;
      cin >> c >> t;
      if(t<=T)
	{
	  ans=min(ans,c);
	}
    }
  if(ans==INF)
    {
      cout << "TLE" << endl;
    }
  else
    {
      cout << ans << endl;
    }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long 
const int maxn = 1e5+10;
int n;
ll a[maxn];
ll sum[maxn];
int ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	ans=1;
	for(int i=n-1;i;i--)
	{
		if(sum[i]*2>=a[i+1]) ans++;
		else break;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1792
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B = LI()

    if A % 2 == B % 2 == 1:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10048
N,Q = map(int,input().split(" "))
s=list(input())
ju = []
for i in range(Q):
    ju.append(input().split(" "))

def isdeadleft(xp):
    oxp = xp
    for i in range(Q):
        com = ju[i]
        if s[xp] == com[0]:
            if com[1] == "L":
                xp -= 1
            else:
                xp += 1
        if xp < 0:
            return True
        if xp > N-1:
            xp = N-1
    return False

def isdeadright(xp):
    oxp = xp
    for i in range(Q):
        com = ju[i]
        if s[xp] == com[0]:
            if com[1] == "L":
                xp -= 1
            else:
                xp += 1
        if xp < 0:
            xp = 0
        if xp > N-1:
            return True
    return False

def mid(x1,x2):
    return int((x1+x2)/2)

if isdeadleft(N-1) or isdeadright(0):
    print(0)
    exit()

#left
p1 = 0
p3 = N-1
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdeadleft(p2):
        p1,p2 = p2,mid(p2,p3)
    else:
        p2,p3 = mid(p1,p2),p2
if isdeadleft(p1):
    p = p3
else:
    p = p1
#right
p1 = 0
p3 = N-1
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdeadright(p2):
        p2,p3 = mid(p1,p2),p2
    else:
        p1,p2 = p2,mid(p2,p3)
if isdeadright(p3):
    q = p1
else:
    q = p3

if p > q:
    print(0)
else:
    print(q-p+1)


Measured memory_bytes: 98632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;
#define ll long long
#define repX(i,j,n) for (ll i = j; i < n; i++)
#define rep(i, n) repX(i,0,n)


int main()
{
    int r,d,x;
    
    cin >> r >> d >> x;
    
    for(int i=2000+1;i<2010+1;i++)
    {
        x = r*x-d;
        cout << x  << endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>

using namespace std;


double zahyou[8][2];




double getdis(int i, int j) {
	double sum = 0;

	double dx, dy;

	dx = zahyou[i][0] - zahyou[j][0];
	dy = zahyou[i][1] - zahyou[j][1];

	return sqrt(dx * dx + dy * dy);
}




int main()
{
	int n;

	cin >> n;

	double wkx, wky;

	for (int i = 0; i < n; i++) {
		cin >> wkx;
		cin >> wky;

		zahyou[i][0] = wkx;
		zahyou[i][1] = wky;

	}

	double sum = 0;

	for (int i = 1; i < n; i++) {
		for (int j = 0; j < i; j++) {
			sum += getdis(i, j);
		}

	}

	sum *= 2;
	sum /= (double)n;

	printf("%.7lf\n", sum);





	return 0;

}



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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  string S;
  cin >> S;
  bool flg1,flg2,flg3;

  flg1 = (S[0] == 'A');

  // flg2
  string S2 = S.substr(2, S.size()-1-2);
  int cnt = 0;
  int index;
  for(int i = 0; i < S2.size(); i++){
    if(S2[i] == 'C'){
      cnt++;
      index = i + 2;
    }
  }
  if(cnt == 1){
    flg2 = true;
  } else { 
    flg2 = false;
  }

  // flg3;
  flg3 = true;
  for(int i = 0; i < S.size(); i++){
    char c = S[i];

    if(i != 0 && i != index){
      if(c - 'a' >= 0  && 'z' - c >= 0){
        continue;
      } else { 
        flg3 = false;
        break;
      }
    }
  }
  cout << (flg1&&flg2&&flg3 ? "AC" : "WA") << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int d = scan.nextInt();
		int x = scan.nextInt();
		
		for (int i =0; i<10; i++) {
			int a = r*x-d;
			System.out.println(r*x-d);
			x=a;
			
		}

	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, s1 = 0, s2 = 0, tmp;
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++){
		scanf("%d", &tmp);
		if(tmp % 4 == 0) s1 ++;
		else if(tmp % 2 == 0) s2 ++;
	}
	
	if(s1 * 2 + s2 >= n || (s2 == 0 && s1 * 2 + 1 >= n)) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int n, m;
string s;
int a[100001];

int main() {
    cin >> n >> m >> s;
    a[0] = 1;
    for (int i = 1, j; i <= n; ++i) {
        if (s[i] == '1')
            continue;
        for (j = max(i - m, 0); j < i; ++j) {
            if (a[j] > 0)
                break;
        }
        a[i] = i - j;
    }
    // for (int i = 0; i <= n; ++i) {
    //     cout << a[i] << " ";
    // }
    // cout << endl;
    int suf = n;
    vector<int> ans;
    while (suf > 0) {
        int d = a[suf];
        if (d == 0) {
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(d);
        suf -= d;
    }
    reverse(ans.begin(), ans.end());
    cout << ans[0];
    for (int i = 1, size = ans.size(); i < size; ++i) {
        cout << " " << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1528
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long a[100005];
long long power(long long a, int b) {
	long long res = 1;
	for (int i = 1; i <= b; i++) {
		res *= a % 998244353;
		res %= 998244353;
	}
	return res;
}
int main() {
	int n;
	cin >> n;
	long long dis = 1;
	int max1 = 0;
	for (int i = 1; i <= n; i++) {
		int m;
		cin >> m;
		if (i == 1 && m != 0) {
			cout << 0;
			return 0;
		}
		else if (i != 1 && m == 0) {
			cout << 0;
			return 0;
		}
		a[m]++;
		max1=max(max1, m);
	}
	for (int i = 1; i <= max1; i++) {
		if (a[i] == 0) {
			cout << 0;
			return 0;
		}
		dis *= power(a[i - 1], a[i])% 998244353;
		dis %= 998244353;
	}
	cout << dis % 998244353;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;




int main()
{
	int a, b; cin >> a >> b;
	if (a*b % 2 == 0)
	{
		cout << "Even" << endl;
	}
	else
	{
		cout << "Odd" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

ll t[501];
int main(){
	ll k;
	scanf("%lld",&k);
	t[0]=1;
	fup(i,1,500,1)t[i]=t[i-1]*(i+7)/i;
	fdn(i,500,0,1)
	{
		fup(j,1,k/t[i],1)putchar('F');
		printf("ESTIVAL");
		k%=t[i];
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int long long int
#define ff first
#define ss second
#define loop(i,k,n) for(int i=k;i<n;++i)
#define rloop(i,n,k) for(int i=n;i>=k;i--)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define all(v) v.begin(),v.end()
#define mset(a,i) memset(a,i,sizeof(a))
#define mii map<int,int>  
#define pii pair<int,int>
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define mp make_pair
#define pb push_back
#define mod 1000000007  
#define endl "\n"
#define inf 1e18

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> pbds1;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { if(0) return; cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args){   
    if(0) return; 
    const char* comma = strchr (names + 1, ',');
    cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
void get_it_done(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
int gcd(int a,int b){
    if(b==0) return a;
    if(a<b) return gcd(b,a);
    return gcd(b,a%b);
}
const int N = 3e5+5;
int dp[3005][3005][2];

void solve(){
    int n,sum = 0;
    cin>>n;
    vi a(n);
    loop(i,0,n){
        cin>>a[i];
        sum += a[i];
    }
    mset(dp,0);
    loop(i,0,n){
        dp[i][i][0] = a[i];
        dp[i][i][1] = 0;
    }
    for(int rminusl=1;rminusl<n;rminusl++){
        for(int l=0;l<n;l++){
            int r = l+rminusl;
            if(r>=n){
                break;
            }
            dp[l][r][0] = max(a[l]+dp[l+1][r][1],a[r]+dp[l][r-1][1]);
            dp[l][r][1] = min(dp[l+1][r][0],dp[l][r-1][0]);
        }
    }
    int x = dp[0][n-1][0];
    int ans = 2*x-sum;
    cout<<ans<<endl;
}

int32_t main(){
    get_it_done(); 
    int tc=1;
    // cin >> tc;
    while (tc--){
        solve();        
    }
}


Measured memory_bytes: 144728
#include<bits/stdc++.h>
#define rep(i,n) for(long long i=0;i<(n);i++)
#define ll long long
using namespace std;
int main(){
    ll L,N,T;
    cin >> N >> L >> T;
    vector<ll> X(N);
    vector<int> W(N);
    rep(i,N) cin >> X[i] >> W[i];
    vector<ll> tmp(N); ll count = 0;
    rep(i,N){
        ll d = (W[i] == 1) ? (X[i] + T) : (X[i] - T)%L + L;
        d %= L; 
        tmp[i] = d;
    }
    /*
    rep(i,N){
        ll d = (W[i] == 1) ? (X[i] + T) : (X[i] - T);
        if(W[i] == 1){
            count += d/L; 
        } else {
            if(d < 0) count += -1 + d/L ;
        } 
    }
    count = (count % N + N)%N;

    sort(tmp.begin(),tmp.end());
    rep(i,N){
        int p = (i + count)%N;
        if(p < 0) p = N + p;
        cout << tmp[p] << endl;
    }
    */
    sort(tmp.begin(), tmp.end());
    for (int i = 0; i < N; ++i) {
        if (W[i] == 1) count -= (T - (L - X[i]) + L) / L;
        else count += (T - (X[i] + 1) + L) / L;
    }
    count = (count % N + N) % N;
    vector<long long> res(N);
    for (int i = 0; i < N; ++i) res[(i+count)%N] = tmp[i];
    for (int i = 0; i < N; ++i) cout << res[i] << endl;

    return 0;
}

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

using namespace std;

int main() {
	string s;
	char C;
	vector<vector<char>> a(2,vector<char>());
	int front=0,Q,T,F;

	cin >> s;
	cin >> Q;

	for(int i = 0;i < Q;i++){
		cin >> T;
		if(T == 1) front= (front+1)%2;
		else{
			cin >> F >> C;
			a[(front + F - 1)%2].push_back(C);
		}
	}

	if(front == 1) reverse(s.begin(),s.end());
	reverse(a[front].begin(),a[front].end());
	
	for(char c:a[front])
		cout << c;
	cout << s;
	for(char c:a[(front+1)%2])
		cout << c;
	cout << endl;

	return 0;
}

Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<utility>
#include<cstdlib>
#include<iterator>
#include<queue>
#include<stack>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
typedef unsigned int uint;
#define int long long
const int INF = 9223372036854775806;


namespace G {
}

int rate[] = { 399,799,1199,1599,2399,2799,3199 };
int map[9]{ 0 };

int solve(int n) {
	if (n <= 399) return 0;
	else if (n <= 799) return 1;
	else if (n <= 1199)return 2;
	else if (n <= 1599) return 3;
	else if (n <= 1999) return 4;
	else if (n <= 2399)return 5;
	else if (n <= 2799) return 6;
	else if (n <= 3199) return 7;
	else return 8;
}

signed main() {
	int ans = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int ngo;
		int index;
		cin >> ngo;
		index = solve(ngo);
		if ((map[index] == 0) && (index != 8)) {
			ans += 1;
			map[index] = 1;
		}
		else if (index == 8) {
			ans += 1;
			map[index] += 1;
		}
	}
	
	
	if (ans - map[8] == 0) cout << 1 << " " << ans << endl;
	else cout << ans - map[8] << " " << ans << endl;

	return 0;
}

Measured memory_bytes: 256
extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut, SubAssign, Range};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet, HashMap};
use std::fmt::Display;

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}

macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
fn count_step(a: i32, b: i32) -> i32 {
    if b == 0 {
        0
    }else if a >= b {
        1 + count_step(b, a % b)
    }else {
        count_step(b, a)
    }
}
fn gcd(a: i32, b: i32) -> i32 {
    if b == 0 {
        a
    }else {
        gcd(b, a % b)
    }
}
fn main() {
    loop {
        let_all!(a: i32, b: i32);
        if a == 0 && b == 0 {
            return
        }
        println!("{} {}", gcd(a, b), count_step(a, b));
    }
}



Measured memory_bytes: 5052
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;
typedef pair< int, pair<int, int> > edge;

llint N;
llint x[100005], y[100005];
vector< pair<int, int> > vecx, vecy;
vector<edge> edges;

int parent[100005];

void init()
{
	for(int i = 0; i < N; i++) parent[i] = i;
}

int root(int i)
{
	if(parent[i] == i) return i;
	return parent[i] = root(parent[i]);
}

bool same(int i, int j)
{
	return root(i) == root(j);
}

void unite(int i, int j)
{
	int root_i = root(i);
	int root_j = root(j);
	if(root_i == root_j) return;
	parent[root_i] = root_j;
}

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> x[i] >> y[i];
	}
	init();
	
	for(int i = 0; i < N; i++){
		vecx.push_back( make_pair(x[i], i) );
		vecy.push_back( make_pair(y[i], i) );
	}
	sort(vecx.begin(), vecx.end());
	sort(vecy.begin(), vecy.end());
	
	for(int i = 0; i < N-1; i++){
		edges.push_back( make_pair( vecx[i+1].first - vecx[i].first, make_pair(vecx[i].second, vecx[i+1].second) ));
		edges.push_back( make_pair( vecy[i+1].first - vecy[i].first, make_pair(vecy[i].second, vecy[i+1].second) ));
	}
	sort(edges.begin(), edges.end());
	
	int ans = 0;
	for(int i = 0; i < edges.size(); i++){
		if(same(edges[i].second.first, edges[i].second.second)) continue;
		unite(edges[i].second.first, edges[i].second.second);
		ans += edges[i].first;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

struct Point {
    double x;
    double y;
    Point(){}
    Point(int x, int y) {
        this->x = x;
        this->y = y;
    }
};

long long factorial(int n){
    if (n == 1)
        return 1;
    else
        return n*factorial(n-1);
}

bool operator<(const Point& ls, const Point& rs) {
    if(ls.x < rs.x)
        return true;
    if(ls.x == rs.x)
        return ls.y < rs.y;
    return false;
}

int main() {
    int n; cin >> n;
    vector<Point> v;
    for(int i=0; i < n; i++) {
        int x,y;
        cin >> x >> y;
        v.push_back(Point(x,y));
    }
    sort(v.begin(), v.end());
    double sum = 0;
    do {
        for(int i = 0; i < n-1; i++) {
            double xdiff = v[i].x - v[i+1].x;
            double ydiff = v[i].y - v[i+1].y;
            sum += sqrt(xdiff*xdiff + ydiff*ydiff);
        }
    } while(next_permutation(v.begin(), v.end()));
    printf("%.7f\n", sum/factorial(n));
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld eps = 1e-12;
constexpr int inf = numeric_limits<int>::max() / 2;
constexpr ll mod = 1e9 + 7;
mt19937_64 rnd{random_device()()};

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int st = 60 * h1 + m1, gt = 60 * h2 + m2;
  cout << max(0, gt - st - k) << endl;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

string s;
int dp[100010][4];

void solve() {
	cin >> s;
	
	dp[0][0] = 1;
	for(int j = 1; j < 4; j++) dp[0][j] = 0;
	
	for(int i = 1; i <= s.length(); i++) {
		for(int j = 0; j < 4; j++) dp[i][j] += dp[i - 1][j];
		for(int j = 0; j < 4; j++) dp[i][j] %= P;
		if(s[i - 1] == 'A') {
			dp[i][1] += dp[i - 1][0];
		} else if(s[i - 1] == 'B') {
			dp[i][2] += dp[i - 1][1];
		} else if(s[i - 1] == 'C') {
			dp[i][3] += dp[i - 1][2];
		} else {
			for(int j = 1; j < 4; j++) dp[i][j] += dp[i - 1][j - 1];
			for(int j = 0; j < 4; j++) dp[i][j] %= P;
			dp[i][0] += (dp[i - 1][0] * 2) % P;
			dp[i][1] += (dp[i - 1][1] * 2) % P;
			dp[i][2] += (dp[i - 1][2] * 2) % P;
			dp[i][3] += (dp[i - 1][3] * 2) % P;
		}
		
		for(int j = 0; j < 4; j++) dp[i][j] %= P;
	}	
	
	cout << dp[s.length()][3] << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 5348
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    int n,l;
    cin>>n>>l;
    string s[n];
    rep(i,n){
        cin>>s[i];
    }
    sort(s,s+n);
    rep(i,n){
        cout<<s[i];
    }cout<<endl;

    return 0;
}


Measured memory_bytes: 256
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
set<LL> aa;
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	return !b ? a : gcd(b, a % b);
}
LL LCM(LL a, LL b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		//printf("%d ", 2);
		aa.insert(2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			//printf("%d ", i);
			aa.insert(i);
			n /= i;
		}
	}
	if (n > 2){
		//printf("%d ", n);
		aa.insert(n);
	};
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	string s;
	cin >> s;
	set<char>set;
	while (true) {
		for (int i = 0; i < s.length(); i++)
			set.insert(s[i]);
		if ((int)set.size() == 1)return cout << s << endl, 0;
		else {
			int v= stoi(s, NULL, 10);
			v++;
			s = "";
			s = to_string(v);
			set.clear();
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e3+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll x,ans=0;cin>>x;
    ans = 2*(x/11);
    x%=11;
    if(x>0){
        if(x<=6)ans+=1;
        else ans+=2;
    }
    cout<<ans;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
c = 1
ans = 0
if K == 0:
    print(N*N)
else:
    for i in range(K+1, N+1):
        ans += c*(N // i)
        ans += max(N % i - K + 1, 0)
        c += 1
    print(ans)

Measured memory_bytes: 64788