akhauriyash/Code-Regression huggingface dataset:
import collections
import itertools
import operator


class UnionFind:
    def __init__(self, x):
        class KeyDict(dict):
            def __missing__(self, key):
                self[key] = key
                return key

        self.parent = KeyDict()
        self.rank = collections.defaultdict(int)
        self.size = collections.defaultdict(lambda: 1)

        if x is not None:
            for elem in range(x+1):
                _, _, _ = self.parent[elem], self.rank[elem],self.size[elem]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if not self.are_same(x,y):
            xx = self.size[x]
            yy = self.size[y]
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += xx
            else:
                self.parent[y] = x
                self.size[x] += yy
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

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

    def are_same(self, x, y):
        '''print(x,y,self.find(x),self.find(y),self.find(x) == self.find(y))'''
        return self.find(x) == self.find(y)

    def grouper(self):
        roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
        root = operator.itemgetter(1)
        for _, group in itertools.groupby(sorted(roots, key=root), root):
            yield [x for x, _ in group]


a,b = map(int,input().split())
c = []
uf = UnionFind(a)
for i in range(b):
    n,m = map(int,input().split())
    c.append([n,m])
co = a*(a-1)//2
ccc = []
ccc.append(co)
for i in range(b)[::-1]:
    z = uf.Size(c[i][0])
    zz = uf.Size(c[i][1])
    if not uf.are_same(c[i][0],c[i][1]):
        co -= z*zz
    if co < 0:
        co = 0
    uf.unite(c[i][0],c[i][1])
    ccc.append(co)
for i in range(b)[::-1]:
    print(ccc[i])


Measured memory_bytes: 47096
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(x, it) for(auto it = x.begin(); it != x.end(); it++)
#define pr(x) cout << #x << " = " << x << endl
#define fill(x,y) memset(x,y,sizeof(x))
#define endl "\n"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;
typedef vector< pll > vpll;
ld eps = 1e-7;
ll mod = 1000000007;
ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

const int mxn = 1e6 + 1;
int present[mxn];
bool cant[mxn];

void solve()
{
	int n, i, mx = -1, ans = 0, j;
	cin >> n;
	vi a(n + 1);
	a[0] = 0;
	rep(i, 1, n + 1)
	{
		cin >> a[i];
		present[a[i]]++;
		mx = max(mx, a[i]);
	}
	rep(i, 1, n + 1)
	{
		if(cant[a[i]] == 1)
			continue;
		for(j = a[i] * 2; j <= mx; j += a[i])
		{
			cant[j] = 1;
		}

	}
	rep(i, 1, n + 1)
	{
		if(cant[a[i]] == 0 && present[a[i]] == 1)
			ans++;
	}
	cout << ans << endl;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	//cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}

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

#define PI 3.14159265
  

int main() 
{
    int n;
    cin>>n;
    int a=n%10;
    if(a==2 || a==4 ||a==5 ||a==7 ||a==9)
    cout<<"hon";
    else if(a==3)
    cout<<"bon";
    else
    cout<<"pon";
}

/*1.000000000
2.414213562
127.321336469



*/

Measured memory_bytes: 3624
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int L = a + b;
    int R = c + d;
    if (L == R) {
        cout << "Balanced" << endl;
    }
    else if (L < R) {
        cout << "Right" << endl;
    }
    else {
        cout << "Left" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    S = input().rstrip()
    T = input().rstrip()

    ans = 0
    for s, t in zip(S, T):
        if s == t:
            ans += 1

    print(ans)


sol()

Measured memory_bytes: 3588
def main():
    from itertools import accumulate
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    A=list(accumulate(A))
    A=[[(A[i]-i-1)%K,i+1] for i in range(0,N)]
    A.append([0,0])
    A.sort()
    s=1
    start=0
    count=0
    for i in range(0,N):
        if A[i][0]==A[i+1][0]:
            s+=1
        else:
            X=[A[i][1] for i in range(start,start+s)]
            a=0
            b=0
            subcount=0
            while len(X)-1>=a and len(X)-1>=b:
                if K-1>=X[b]-X[a]:
                    b+=1
                else:
                    subcount+=len(X)-b
                    a+=1
            count+=len(X)*(len(X)-1)//2-subcount
            start+=s
            s=1
    X=[A[i][1] for i in range(start,start+s)]
    a=0
    b=0
    subcount=0
    while len(X)-1>=a and len(X)-1>=b:
        if K-1>=X[b]-X[a]:
            b+=1
        else:
            subcount+=len(X)-b
            a+=1
    count+=len(X)*(len(X)-1)//2-subcount
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 120024
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
using namespace std;

int main(void)
{
    int n;
    cin >> n;
    if(n < 1000){cout << "ABC" << endl;}
    else{cout << "ABD" << endl;}
    return 0;
}

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

using namespace std;

using ll = long long;
using vll = vector<ll>;

template <class T>
string to_string(vector<T> v) {
  string str = "";
  for (auto &x : v) {
    str += to_string(x);
    str.push_back(' ');
  }
  if (str.length() > 0) str.pop_back();

  return str;
}

void A() {
  int l, r, d;
  scanf("%d %d %d", &l, &r, &d);

  int lower = l / d + (l % d != 0);
  int upper = r / d + (r % d != 0);
  printf("%d\n", upper - lower + (r % d == 0));
}

int main() {
  A();
  return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

map<char, long long> alp_cnt(string s) {
    map<char, long long> ans;
    for (long long i = 0; i < s.size(); i++) {
        if (ans.count(s[i])) {
            ans[s[i]]++;
        } else {
            ans[s[i]] = 1;
        }
    }
    return ans;
}

template <class T> T up(T a, T div) { return (a + div - 1) / div; }

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

    string s;
    cin >> s;
    ll ans = INF64;

    auto che = [](string x) {
        FOR(i, 1, x.size()) {
            if (x[i] != x[i - 1])
                return false;
        }
        return true;
    };
    REP(alp, 27) {
        char now = alp + 'a';
        string x = s;
        bool f   = true;
        ll cnt   = 0;
        while (true) {
            f = che(x);
            if (f)
                break;
            REP(i, x.size() - 1) {
                if (x[i + 1] == now) {
                    x[i] = now;
                }
            }
            x.pop_back();
            cnt++;
        }
        chmin(ans, cnt);
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if(s < t)cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<stack>
#include<algorithm>
#include<queue>
#include<cmath>
#include<numeric>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<iomanip>
#include<functional>
#include<bitset>

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

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin>>n;
    if(n%10==2 || n%10==4||n%10==5||n%10==7||n%10==9){
        cout<<"hon"<<endl;
    }
    if(n%10==0||n%10==1||n%10==6||n%10==8){
        cout<<"pon"<<endl;
    }
    if(n%10==3){
        cout<<"bon"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3676
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)


# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

def DIVISORS(n):
    ret = []
    i = 1
    while i * i <= n:
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
        i += 1

    ret.sort()
    return ret


N = int(input())
divisors = DIVISORS(N)

ans = 0
for x in divisors:
    m = x - 1
    if m == 0:
        continue
    r = N % m
    if r == N // m:
        ans += m

print(ans)



Measured memory_bytes: 3704
A, B = list(map(int, input().split()))
i = 1
if A <= B:
  N = B
  while (N % A) != 0:
    i += 1
    N = B * i
else:
  N = A
  while (N % B) != 0:
    i += 1
    N = A * i
print(N)

Measured memory_bytes: 2940
use std::io;

fn main() {
    let mut N = String::new();
    let mut ACcount :usize = 0;
    let mut WAcount :usize = 0;
    let mut TLEcount :usize = 0;
    let mut REcount :usize = 0;
    io::stdin().read_line(&mut N);
    let n :usize = N.trim().parse().unwrap();
    for i in 0..n{
        let mut S = String::new();
        io::stdin().read_line(&mut S);
        if S.trim() == "AC"{
        ACcount += 1;
        }else if S.trim() == "WA"{
            WAcount += 1;
        }else if S.trim() == "TLE"{
            TLEcount += 1;
        }else if S.trim() == "RE"{
            REcount += 1;
        }
    }
    println!("AC x {}",ACcount);
    println!("WA x {}",WAcount);
    println!("TLE x {}",TLEcount);
    println!("RE x {}",REcount);
}

Measured memory_bytes: 2152
#include <iostream>

using namespace std;

int A[100000];
int cnt[100000];

int main(){
    int N;
    int K, Q;
    cin >> N >> K >> Q;
    for(int i = 0; i < Q; i++){
        cin >> A[i];
        A[i]--;
        cnt[A[i]]++;
    }
    for(int i = 0; i < N; i++){
        if(K-Q+cnt[i] > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    string s; cin >> s;
    int i = 0, j = n-1;
    int ans = 0;
    while (i < j) {
        while (i < j && s[i] == 'R') i++;
        while (i < j && s[j] == 'W') j--;
        if (i < j) ans++;
        i++; j--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3484
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define N 100

int m[N+1][N+1];
int Matrix_Chain_Order(int *, int);

int main(){

  int n, i;
  int p[N+1];
  
  scanf("%d", &n);
  
  for(i = 0;i < n;i++){
    scanf("%d%d", &p[i], &p[i+1]);
  }
  
  printf("%d\n", Matrix_Chain_Order(p, n));
  return 0;
}


int Matrix_Chain_Order(int *p, int n){
  int i, j, k, l, q;
  
  for(i = 1; i <= n; i++){
    m[i][i] = 0;
  }
  
  for(l = 2; l <= n;l++){
    for(i = 1; i <= n-l+1;i++){
      j = i + l - 1;

      m[i][j] = INT_MAX;

      for(k = i;k <= j - 1;k++){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	m[i][j] = ((m[i][j] <= q) ? m[i][j] : q);
      }

    }
  }

  return m[1][n];
}

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

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

ll N;
vector<P> v;

int main() {
    cin >> N;
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        P p = make_pair(b, a);
        v.push_back(p);
    }

    sort(v.begin(), v.end());

    ll sum = 0;
    string ans = "Yes";
    for (int i = 0 ; i < v.size(); i++) {
        // cout << v[i].first << " " << v[i].second << endl;
        sum += v[i].second;
        if (sum > v[i].first) {
            ans = "No";
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 6512
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        long[] xy = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        int res = 0;
        while (xy[0] <= xy[1])
        {
            xy[0] *= 2;
            res++;
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=INT_MAX;
const double PI=3.1415926;
int main()
{
    ll n,m,a,sum=0;
    cin>>n>>m;
    rep(i,m)
    {
        cin>>a;
        sum+=a;
    }
    cout<<max(-1LL,n-sum);
}


Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <iomanip>

double Pi = acos(-1);
using namespace std;
inline double add(double a, double b){
	return abs(a + b) <= 1e-8 ? 0 : a + b;
}
int main(){
	double a, b, C; cin >> a >> b >> C;
	double S = 0.5*a*b*sin(C*Pi/180);
	double h = 2 * S / a;
	double c = sqrt(add(a*a + b*b, - 2 * a*b*cos(C*Pi/180)));
	double L=a+b+c;
	cout << fixed << setprecision(8);
	cout << S << ' ' << L << ' ' << h << '\n';
}

Measured memory_bytes: 1284
#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>
using namespace std;
typedef pair<int,int> P;
#define MAX 10000
 
P add(P a,P b){
  return P(a.first+b.first,a.second+b.second);
}
 
P mul(P a,P b){
  return P(a.first*b.first-a.second*b.second,a.first*b.second+a.second*b.first);
}
 
int pos=0,len,flg;
string s;
P solve();
void printF(P p);
 
P getNum(){
  P res=P(0,0);
  bool f=false;
  if(s[pos]=='('){ pos++;return solve();  }
  if(s[pos]=='-'){f=true;pos++;}
  if(s[pos]=='i'){
    res.second=1;
    pos++;
  }else{
    while('0'<=s[pos]&&s[pos]<='9'){
      res.first*=10;
      res.first+=(s[pos]-'0');
      if(res.first>MAX)flg=true;// debug
      pos++;
    }
    if(s[pos]=='i'){
      swap(res.first,res.second);
      pos++;
    }
  }
 
  if(flg)return P(0,0); // debug
 
  if(f)res=mul(P(-1,0),res);
  return res;
}
 
P solve(){
  stack< P > st;
  st.push(getNum());
 
  while(1){
    if(abs(st.top().first)>MAX)flg=true;
    if(abs(st.top().second)>MAX)flg=true;
    char ch=s[pos];pos++;
    if(ch=='='||ch==')')break;
    P num=getNum();
    if(abs(num.first)>MAX)flg=true;
    if(abs(num.second)>MAX)flg=true;
    if(ch=='*'){
      P a=st.top();st.pop();
      st.push(mul(a,num));
    }else if(ch=='+'){
      st.push( num );
    }else {
      st.push( mul(P(-1,0),num) );
    }
 
  }
 
  vector<P> vec;
  P res=P(0,0);
  while(!st.empty()){
    vec.push_back(st.top());
    st.pop();
  }
  reverse(vec.begin(),vec.end());
  for(int i=0;i<(int)vec.size();i++){
    P a=vec[i];
    res=add(a,res);
    if(abs(res.first)>MAX)flg=true;
    if(abs(res.second)>MAX)flg=true;
  }
  return res;
}
 
void printF(P p){
  if(flg){cout<<"overflow"<<endl;return;}
  if(p.first!=0){
    cout<<p.first;
    if(p.second>1){
      cout<<"+"<<p.second<<"i"<<endl;
    }else if(p.second==1){
      cout<<"+1i"<<endl;
    }else if(p.second==0){
      cout<<endl;
    }else if(p.second==-1){
      cout<<"-1i"<<endl;
    }else if(p.second<-1){
      cout<<p.second<<"i"<<endl;
    }
  }else{
    if(p.second>1){
      cout<<p.second<<"i"<<endl;
    }else if(p.second==1){
      cout<<"1i"<<endl;
    }else if(p.second==0){
      cout<<"0"<<endl;
    }else if(p.second==-1){
      cout<<"-1i"<<endl;
    }else if(p.second<-1){
      cout<<p.second<<"i"<<endl;
    }
 
  }
}
 
int main(){
  while(cin>>s){
    s.push_back('=');
    pos=0;
    len=s.size();
    flg=false;
    P ans=solve();
    printF(ans);
  }
  return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  ll ans = 0;

  for(int i = 1; i <= n; ++i){
    if(i * i > n) break;

    ans = i * i;
  }

  cout << ans << endl;
}


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

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

using namespace std;

typedef pair<int,int> P;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<vector<P>> v(n);
    vector<vector<P>> w(8);
    int m;cin>>m;
    REP(i,m){
      double x,y;
      cin>>x>>y;
      w[0].emplace_back(x,y);
      w[1].emplace_back(y,-x);
      w[2].emplace_back(-x,-y);
      w[3].emplace_back(-y,x);
    }
    REP(i,4){
      w[i+4]=vector<P>(m);
      reverse_copy(begin(w[i]),end(w[i]),begin(w[i+4]));
    }
    REP(i,8){
      int m=w[i].size();
      REP(j,m){
        if(j==0)continue;
        w[i][j].first-=w[i][0].first;
        w[i][j].second-=w[i][0].second;
      }
      w[i][0]=P(0,0);
    }
    REP(i,n){
      int m;
      cin>>m;
      REP(j,m){
        double x,y;
        cin>>x>>y;
        v[i].emplace_back(x,y);
      }
      REP(j,m){
        if(j==0)continue;
        v[i][j].first-=v[i][0].first;
        v[i][j].second-=v[i][0].second;
      }
      v[i][0]=P(0,0);
      bool ok=false;
      REP(j,8){
        if(v[i]==w[j])
          ok=true;
      }
      if(ok)
        cout<<(i+1)<<endl;
    }
    cout<<"+++++"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1248
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var dic = new Dictionary<string, int>();
        var keys = new string[] { "A", "B", "C", "D", "E" };
        foreach(string key in keys)
        {
            dic[key] = int.Parse(Console.ReadLine());
        }
        int k = int.Parse(Console.ReadLine());
        string output = "Yay!";
        // 組み合わせ
        foreach(var key1 in dic.Keys)
        {
            foreach(var key2 in dic.Keys)
            {
                if(key1 == key2)
                {
                    continue;
                }

                var d1 = dic[key1];
                var d2 = dic[key2];
                var diff = Math.Abs(d1 - d2);
                if(diff > k)
                {
                    output = ":(";
                    break;
                }
            }
        }

        Console.WriteLine(output);

    }
}



Measured memory_bytes: 13152
(defun solver ()
  (let ((a (string (read)))
	(b (string (read)))
	(c (string (read))))
    (if (and (equal (char (reverse a) 0)
		    (char b 0))
	     (equal (char (reverse b) 0)
		    (char c 0)))
	(format t "YES~%")
	(format t "NO~%"))))

(solver)

Measured memory_bytes: 12896
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
CD = [list(map(int, input().split())) for _ in range(N)]

def sortx(xy):
  return xy[0]
def sorty(xy):
  return -xy[1]

AB.sort(key=sorty)
CD.sort(key=sortx)

count = 0

for cd in CD:
  for ab in AB:
    if ab[0] < cd[0] and ab[1] < cd[1]:
      count += 1
      AB.remove(ab)
      break

print(count)

Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 998244353;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

i64 pow(i64 x, i64 n, i64 mod) {
  i64 ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}

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

  int n;
  cin >> n;
  vt<int> d(n);
  rep(i, 0, n) cin >> d[i];

  vt<i64> cnt(n, 0);
  rep(i, 0, n) cnt[d[i]]++;
  if(cnt[0] != 1 || d[0] != 0) return cout << 0 << endl, 0;
  
  i64 ans = 1;
  rep(i, 1, n) {
    if(cnt[i] == 0) continue;
    if(cnt[i - 1] <= 0) return cout << 0 << endl, 0;
    ans *= pow(cnt[i - 1], cnt[i], mod);
    ans %= mod;
  }
  cout << ans << endl;
}

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

int main() {
 int N,D;
 cin>>N>>D;
 if(N<=2*D+1){
   cout<<"1"<<endl;
 }
 else if(N>2*D+1){
   if(N<=4*D+2){
     cout<<"2"<<endl;
   }
   else if(N>4*D+2){
     if(N<=6*D+3){
       cout<<"3"<<endl;
     }
     else if(N>6*D+3){
       if(N<=8*D+4){
         cout<<"4"<<endl;
       }
       else if(N>8*D+4){
         if(N<=10*D+5){
           cout<<"5"<<endl;
         }
         else if(N>10*D+5){
           if(N<=12*D+6){
             cout<<"6"<<endl;
           }
           else if(N>12*D+6){
             cout<<"7"<<endl;
           }
         }
       }
     }
   }
 }
}


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

struct Dice{
	int num[6];
};

int main(){
	struct Dice dice;
	string str;
	int store[6];

	for(int i=0;i<6;i++){
		cin>>dice.num[i];
	}
	cin>>str;

	for(int i=0;i<str.length();i++){
		for(int j=0;j<6;j++){
			store[j] = dice.num[j];
		}
		switch(str[i]){
		case 'N':
			dice.num[0] = store[1];
			dice.num[1] = store[5];
			dice.num[5] = store[4];
			dice.num[4] = store[0];
			break;
		case 'E':
			dice.num[0] = store[3];
			dice.num[3] = store[5];
			dice.num[5] = store[2];
			dice.num[2] = store[0];
			break;
		case 'S':
			dice.num[0] = store[4];
			dice.num[4] = store[5];
			dice.num[5] = store[1];
			dice.num[1] = store[0];
			break;
		case 'W':
			dice.num[0] = store[2];
			dice.num[2] = store[5];
			dice.num[5] = store[3];
			dice.num[3] = store[0];
			break;
		}
	}

	cout<<dice.num[0]<<endl;
	return 0;
}

Measured memory_bytes: 1204
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;

	writeln(N % 2 == 0 ? N : N * 2);
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define int ll
const ll mod =1e18;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 400000+10;
const int K = 31;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}

int32_t main()
{

   IOS
	int n;
    cin>>n;
    int a[n+1] = {0};
    for(int i =0;i<n-1;i++)
        {
            int x;
            cin>>x;
            a[x]++;
        }
    for(int i = 1;i<=n;i++){
        cout<<a[i]<<endl;
    }
    
   

}

Measured memory_bytes: 5216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n;
    bool flag=false;
    FOR(i,1,10000){
      if((1+8*n)==i*i && i%2==1){
        flag=true;
        k=(1+i)/2;
        break;
      }
    }
    if(!flag){
      cout<<"No"<<endl;
      return 0;
    }
    cout<<"Yes"<<endl;
    cout<<k<<endl;
    vector<vector<int>> s(k+1);
    int now=1;
    FOR(i,1,k+1){
      int st=now;
      rep(j,k-i){
        s[i].push_back(now++);
      }
      FOR(j,i+1,k+1){
        s[j].push_back(st++);
      }
    }
    FOR(i,1,k+1){
      cout<<k-1<<' ';
      rep(j,k-1) cout<<s[i][j]<<' ';
      cout<<endl;
    }
}

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define JD



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

    #ifndef JD
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif


    ll p[12];p[0]=1;
    ll ar[12]={};
    for(int i=1;i<12;++i)
    {
        p[i]=26*p[i-1];
        ar[i]+=(ar[i-1]+p[i]);
        //cout<<ar[i]<<" ";
    }

    string s = "abcdefghijklmnopqrstuvwxyz";
    vll v;
    ll n;
    cin>>n;
    ll d,ind;
    for(ll i=0;i<12;++i)
    {
        if(ar[i]>=n)
        {
            d = n-ar[i-1]-1;
            ind = i;
            break;
        }
    }

    string ans(ind,'a');
    while(d)
    {
        ll r = d%26;
        v.pb(r);
        d/=26;
    }
    //__print(v);
    int len = v.size();

    //reverse(all(v));
    for(int i=0;i<len;++i)
        ans[ind-1-i] = s[v[i]];
    cout<<ans;


    return 0;
}


Measured memory_bytes: 3624
#include<cstdio>

typedef struct{
	int rank;
	int point;
} information;

int main(void){
	int N, i;
	information a, b;
	scanf("%d", &N);
	scanf("%d %d", &a.rank, &a.point);
	for(i=0;i<N-1;i++){
		scanf("%d %d", &b.rank, &b.point);
		if(b.rank > a.rank)
			a = b;
	}
	printf("%d\n", a.rank + a.point);
	return 0;
}


Measured memory_bytes: 128
N = int(input())
A = [0]
A.extend(list(map(int, input().split())))
A.append(0)
sumA = 0
for i in range(len(A)-1):
    sumA += abs(A[i + 1] - A[i])

for i in range(1,N+1):
    print(sumA - abs((A[i] - A[i - 1])) - abs((A[i + 1] - A[i])) + abs((A[i + 1] - A[i - 1])))

Measured memory_bytes: 14048
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

typedef long long ll;

int main()
{
    int x,y,z;
    cin >> x >> y >> z;
    int cnt = 0;
    while(cnt * (y+z) + z <= x){
        cnt++;
    }
    cout << --cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline void goodbye(const T& val) { cout << val << endl; exit(0); }

void solve()
{
	ll n;
	cin >> n;

	ll even = n / 2;
	ll odd  = n - even;

	cout << fixed << setprecision(12) << (double)odd / (double)n << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


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

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s, t; cin >> s >> t;
	int n = s.size(), m = t.size();
	vector <int> a(n + 1, 0), b(m + 1, 0);
	for(int i = 1; i <= n; i++) {
		a[i] = a[i - 1] + (s[i - 1] - 'A');
	}
	for(int i = 1; i <= m; i++) {
		b[i] = b[i - 1] + (t[i - 1] - 'A');
	}
	int q; cin >> q;
	for(int i = 1; i <= q; i++) {
		int l1, r1, l2, r2; cin >> l1 >> r1 >> l2 >> r2;
		int xx = a[r1] - a[l1 - 1] - (r1 - l1 + 1 - (a[r1] - a[l1 - 1]));
		xx %= 3;
		xx = (xx + 3) % 3;
		int yy = b[r2] - b[l2 - 1] - (r2 - l2 + 1 - (b[r2] - b[l2 - 1]));
		yy %= 3;
		yy = (yy + 3) % 3;
		cout << ((xx ^ yy) ? "NO" : "YES") << endl;
	}
}

Measured memory_bytes: 4192
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();

    let n: usize = s.len();

    let mut ans: usize = 0;
    for i in 0..n {
      let j = n - i - 1;
      if s[i] != s[j] {
         ans += 1;
      }
    }

    println!("{}", ans / 2);
}


Measured memory_bytes: 4352
from collections import defaultdict
n, m = map(int, input().split())
cnt = defaultdict(int)
for _ in range(m):
    a, b = map(int, input().split())
    cnt[a] = (cnt[a]+1) % 2
    cnt[b] = (cnt[b]+1) % 2

if any(v for v in cnt.values()):
    print('NO')
else:
    print('YES')

Measured memory_bytes: 9448
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
string s, t;
int r1[26], r2[26];
signed main() {
	cin >> s >> t;
	int n = s.size();
	rep(i, 26) {
		r1[i] = -1, r2[i] = -1;
	}
	rep(i, n) {
		if (r1[s[i] - 'a'] < 0)r1[s[i] - 'a'] = (t[i] - 'a');
		else {
			if (r1[s[i] - 'a'] != t[i] - 'a') {
				puts("No");
				ggr
			}
		}
		if (r2[t[i] - 'a'] < 0)r2[t[i] - 'a'] = (s[i] - 'a');
		else {
			if (r2[t[i] - 'a'] != s[i] - 'a') {
				puts("No");
				ggr
			}
		}
	}
	puts("Yes");
	ggr
}


Measured memory_bytes: 776
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'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'};
vector<char>AL(26);
AL = {'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'};
*/



int main() {
	double W, H, X, Y;
	cin >> W >> H >> X >> Y;
	cout <<setprecision(30)<< W * H / 2 << ' ';
	if (W / 2 == X && H / 2 == Y) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  if (n < 1200)
    cout << "ABC";
  else if (n < 2800)
    cout << "ARC";
  else
    cout << "AGC";
  cout << endl;
  return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    int a[n],b[n],c[m],d[m];
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i < m; i++){
        cin >> c[i] >> d[i];
    }
    
    for(int i = 0; i < n; i++){
        int num = 0;
        int count = 1000000000;
        for(int j = 0; j < m; j++){
            int dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(count > dis){
                count = dis;
                num = j+1;
            }
        }
        cout << num << endl;
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    ll N, K;
    cin >> N >> K;

    ll ans = 0;
    if (N <= abs(N - K)) {
        ans = N;
    } else {
        ans = N % K;
        chmin(ans, abs((ans - K) % K));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import Data.List

hit [] [] = 0
hit (a0:as) (b0:bs) =
  let s = if a0 == b0
          then 1
          else 0
  in
    s + (hit as bs)

blow :: [Int] -> [Int] -> Int
blow x y =
  let b = sum $ map (\e -> if elem e y then 1 else 0) x
      h = hit x y
  in
    b-h

play :: [[Int]] -> [[Int]]
play [] = []
play (x:y:xs) =
  let h = hit  x y
      b = blow x y
      r = play xs
  in
    [h,b]:r

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = play i
  mapM_ putStrLn $ map unwords $ map (map show) o

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

int main(){
  int A;
  int B;
  int K;
  int n;
  int i;
  int result;
  cin >> A;
  cin >> B;
  cin >> K;
  
  for (i = 100 ; i>0 ; i=i-1){
    if (A%i==0 and B%i==0){
      n++;
    }
    if (n==K){
      result = i;
    }
    if (n==K) break;
  }
    cout << result <<"\n";
}

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

int N;
string S;
int result = 1;

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

    for(int i = 0; i < N - 1; i++)
    {
        if(S[i] != S[i+1]) result += 1;
    }
    cout<<result<<"\n";

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
using namespace std;
int main(){
	long long n;
	cin>>n;
	long long s=-(n/2)*(n/2+1)/2;
	for(int i=1;2*i<n+1;++i){
		long long p=n/i;
		long long c=p*(p+1)/2;
		s+=i*c;
	}
	s+=n*(n+1)/2;
	cout<<s<<endl;
	return 0;
}

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


def solve(N: int, A: "List[int]"):
    A = list(reversed(sorted(A)))
    c = 0
    q = []
    heapq.heappush(q,(-A[0],A[0],A[0]))
    for i in range(1,N):
        a = A[i]
        pt = heapq.heappop(q)
        heapq.heappush(q,(-a,a,pt[1]))
        heapq.heappush(q,(-a,pt[2],a))
        c += -pt[0]
    print(c)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 131276
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a, b, c;
    cin >> a >> b >> c ;
    
    //*
    if( b >= c ){
        cout << "delicious" << endl;
    } else if ( b < c && c <= a + b){
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
    //*/
    
    //cout << a.at(0) - 'a' + 'A' << b.at(0) - 'a' + 'A' << c.at(0) - 'a' + 'A' << endl;

    return 0; 
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define MAX 86400
#define inf 1e9
#define eps 1e-9
using namespace std;

int n;
int s[MAX];
double lim;

bool ok(double m){
  double c=lim;
  for(int i=0;i<MAX;i++){
    c-=s[i];
    c+=m;
    c=min(c,lim);
    if(c<0)return false;
  }
  double d=c;
  for(int i=0;i<MAX;i++){
    d-=s[i];
    d+=m;
    d=min(d,lim);
    if(d<0)return false;
  }
  return c-d<eps;
}

int main()
{
  while(1){
    cin>>n>>lim;
    if(n+lim==0)break;
    for(int i=0;i<MAX;i++)s[i]=0;
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>>a>>b>>c;
      for(int j=a;j<b;j++)s[j]=c;
    }

    double l=0,r=inf,m;
    for(int i=0;i<50;i++){
      m=(r+l)/2.0;
      if(ok(m))r=m;
      else l=m;
    }
    printf("%.10f",l);
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1612
#include <iostream>
#include <string>

int main(void)
{
    std::string S;
    std::cin >> S;

    std::string tail[2];
    for(int i = 0; i < S.size(); ++i)
    {
        tail[0] += (i % 2 ? "0" : "1");
        tail[1] += (i % 2 ? "1" : "0");
    }

    int cnt[2] = {0};
    for(int i = 0; i < S.size(); ++i)
    {
        for(int j = 0; j < 2; ++j)
        {
            cnt[j] += (S[i] != tail[j][i]);
        }
    }

    std::cout << (cnt[0] > cnt[1] ? cnt[1] : cnt[0]) << std::endl;
}

Measured memory_bytes: 768
package main
import (
  "fmt"
  "os"
)
func main() {
  var n,m int
  fmt.Scan(&n,&m)
  m /= 1000
  if n <= m && m <= 10*n {
    var x,y,z int
    var ubnd int = min((m-n)/4,(10*n-m)/5) + 1
    for y=0;y<ubnd;y++ {
      if (m-n-4*y)%9 == 0 && (10*n-m-5*y)%9 == 0 {
        x = (m-n-4*y)/9
        z = (10*n-m-5*y)/9
        fmt.Println(x,y,z)
        os.Exit(0)
      }
    }
  }
  fmt.Println(-1,-1,-1)
}
func min(i int,j int) int {
  if i < j {
    return i
  } else {
    return j
  }
}

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

int main()
{
        ll N;
        cin>>N;
        ll A[N]={},B[N]={},C[N]={};
        ll i,j,k;
      ll  bal[N][3]={};
        for(i=0;i<N;i++){
                        cin>>A[i]>>B[i]>>C[i];
                for(j=0;j<3;j++){
                                if(i==0){
                                        if(j==0)bal[i][0]=bal[i][0]+A[i];
                                        else if(j==1)bal[i][1]=bal[i][1]+B[i];
                                        else bal[i][2]=bal[i][2]+C[i];
                                }
                                else {
                                        for(k=0;k<3;k++){
                                                if(j==k)continue;
                                                else if(j==0){
                                                            bal[i][j]=max(bal[i][j],bal[i-1][k]+A[i]);
                                                                }
                                                else if(j==1){
                                                          bal[i][j]=max(bal[i][j],bal[i-1][k]+B[i]);
                                                }
                                                else{
                                                        bal[i][j]=max(bal[i][j],bal[i-1][k]+C[i]);
                                                }
                                        }
                                }
                }
        }
        ll xx=max(bal[N-1][0],bal[N-1][1]);      xx=max(xx,bal[N-1][2]);
        cout<<xx<<endl;
        return 0;
}


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

int main(){
	int x, h, m, s;
	cin>>x;
	h = x / 3600;
	m = (x / 60) % 60;
	s = x % 60;
	cout<<h<<":"<<m<<":"<<s<<endl;
	return 0;
}


Measured memory_bytes: 3104