akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
int h,w;
while(1)
{
cin>>h>>w;
if(h==0&&w==0)break;
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
cout<<"#";
}
cout<<endl;
}
cout<<endl;
}
return 0;
}

Measured memory_bytes: 3080
L,R = map(int,input().split())

ans = 2018

for i in range(L,min(R,L+2100)):
    for j in range(i+1,min(R+1,i+2100)):
        if (i*j) % 2019 <= ans:
            ans = (i*j) % 2019

print(ans)

Measured memory_bytes: 9080
a, b, c = list(map(int, input().split()))
# 7*n =5*k+1
# 2*n = 2*k+1
# 1*n = 100*k+97
for n in range(1, 100+1):
    if (a*n) % b == c:
        print("YES")
        exit()

print("NO")


Measured memory_bytes: 38384
r,g,b,n = map(int,input().split())
ans = 0
cnt = 0
for i in range(n//r+1):
    ans = 0
    for j in range((n-i*r)//g+1):
        ans = i*r+j*g
        a = (n-ans)/b
        if a % 1 == 0:
            cnt +=1
print(cnt)

Measured memory_bytes: 9200
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    string s;
    cin>>s;
    int ans=0;
    for(auto a:s){
        if(a=='+') ans++;
        else ans--;
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<int,ll> p;
typedef pair<pii,int> P;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
const ll MOD=1e9+7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n,0){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[rx]<rank[ry]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
struct edge{
    int u,v;
    ll cost;
};
vector<edge> G;
vector<P> C;
bool compx(P c1,P c2){
    if(c1.first.first==c2.first.first) return c1.first.second<c2.first.second;
    return c1.first.first<c2.first.first;
}
bool compy(P c1,P c2){
    if(c1.first.second==c2.first.second) return c1.first.first<c2.first.first;
    return c1.first.second<c2.first.second;
}
bool compedge(edge& e1,edge& e2){
    return e1.cost<e2.cost;
}
int n;
int main(){
    cin>>n;
    C=vector<P>(n);
    for(int i=0;i<n;++i){
        int x,y;cin>>x>>y;
        C[i]=P(pii(x,y),i);
    }
    sort(C.begin(),C.end(),compx);
    for(int i=0;i<n-1;++i){
        G.push_back(edge{C[i].second,C[i+1].second,C[i+1].first.first-C[i].first.first});
        G.push_back(edge{C[i].second,C[i+1].second,abs(C[i+1].first.second-C[i].first.second)});
    }
    sort(C.begin(),C.end(),compy);
    for(int i=0;i<n-1;++i){
        G.push_back(edge{C[i].second,C[i+1].second,abs(C[i+1].first.first-C[i].first.first)});
        G.push_back(edge{C[i].second,C[i+1].second,C[i+1].first.second-C[i].first.second});
    }
    sort(G.begin(),G.end(),compedge);
    int m=(int)G.size();
    UnionFind uf(n);
    ll ans=0;
    for(int i=0;i<m;++i){
        edge e=G[i];
        if(uf.same(e.u,e.v)) continue;
        uf.unite(e.u,e.v);
        ans+=e.cost;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12784
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
	int dx[] = {50, -50, -50, 50};
	int dy[] = {50, 50, -50, -50};

	int n;
	while( scanf("%d", &n), n >= 0 ){
		bool mx[9][9] = {};
		bool my[9][9] = {};
		
		char ch;
		int mi, mj;
		for(int i = 0; i < n; ++i){
			scanf(" %c%d%d", &ch, &mi, &mj);
			if( ch == 'x' ){
				mx[mi][mj] = true;
			}
			else{
				my[mi][mj] = true;
			}
		}
		
		int dir = 0;
		int x = 50;
		int y = 0;
		
		while(true){
			x += dx[dir];
			y += dy[dir];

			if( x % 100 == 0 ){
				if( my[x / 100][y / 100] ){
					if( dir % 2 == 0 ){ ++dir; }
					else{ --dir; }
				}
				else if( x == 0 || x == 800 ){
					break;
				}
			}
			else{
				if( mx[x / 100][y / 100] ){
					if( dir % 2 == 0 ){ --dir; }
					else{ ++dir; }
				}
				else if( y == 0 || y == 800 ){
					break;
				}
			}
			
			dir &= 3;
			
			if( x == 50 && y == 0 ){
				x = 75;
				y = 25;
				break;
			}
		}
		
		printf("%d %d\n", x, y);
	}
}

Measured memory_bytes: 1028
def main():
    x = int(input())
    money = 100
    count = 0

    if x <= money:
        print(count)
    else:
        while True:
            money_add = int(money * 0.01)
            money = money + money_add
            count += 1
            if x <= money:
                break
        print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
def resolve():
    o = input()
    e = input()

    length = len(o) + len(e)

    ans = str()
    oe = int()
    for i in range(1, length + 1):
        if i % 2 == 0:
            oe = int(i / 2) - 1
            ans += e[oe]
        if i % 2 == 1:
            oe = int((i-1) / 2)
            ans += o[oe]
    print(ans)
resolve()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
char d[10];
int n,k;
bool flag;
string to_string(int x){
	string s="";
	while(x>0){
		s+=x%10+'0';
		x/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<k;i++){
		char f;
		cin>>f;
		d[f-'0']=1;
	}
	for(int i=n;i<100000;i++){
		string s=to_string(i);
		flag=true;
		for(int j=0;j<s.size();j++){
			if(d[s[j]-'0']==1){
				flag=false;
				break;
			}
		} 
		if(flag){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int count;
	int i, j;
	int a, b, c;

	scanf("%d", &count);
	for(i = 0; i < count; i++){
		scanf("%d %d %d", &a, &b, &c);

		if(a*a == b*b + c*c ||
			b*b == c*c + a*a ||
			c*c == a*a + b*b) printf("YES\n");
		else printf("NO\n");
	}

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v;
  int sum = 0;
  int skip;
  for (int i = 1; i <= n + 1; i++) {
    v.push_back(i);
    sum += i;
    if (sum > n) {
      skip = sum - n;
      break;
    }
  }

  for (auto w : v) {
    if (w != skip) cout << w << '\n';
  }

  return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
int n,c;
char s[123456];
int main(){ 
    cin>>n;
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=1;i<n;i++){
        if(s[i]!=s[(i-1)])c++;
    }
    cout<<(c+1)<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
string a,b,c,d;
int i=0,j=0,k=0,l=0,x,y;
void reada(){
  if(i>=a.size()) return;
  c="";
  while(i<a.size()&&a[i]!='['){
    if(a[i]=='(') k++;
    if(a[i]==')') k--;
    c+=a[i];
    i++;
  }
  i++;x=0;
  if(i>=a.size()) return;
  while(a[i]!=']') x=x*10+a[i]-'0',i++;
  i++;
}
void readb(){
  if(j>=b.size()) return;
  d="";
  while(j<b.size()&&b[j]!='['){
    if(b[j]=='(') l++;
    if(b[j]==')') l--;     
    d+=b[j];
    j++;
  }
  j++;y=0;
  if(j>=b.size()) return;
  while(b[j]!=']') y=y*10+b[j]-'0',j++;
  j++;
}

int main(){
  cin>>a>>b;
  while(1){
    reada();
    if(i>=a.size()){
      cout << c << endl;
      break;
    }
    readb();
    if(j>=b.size()){
      cout << d << endl;
      break;
    }
    if(k>l){
      while(k>l) reada();
      if(i>=a.size()){
	cout << d << endl;
	break;
      }
      cout << d << "[" << x+y << "]";
    }else{
      while(k<l) readb();
      if(j>=b.size()){
	cout << c << endl;
	break;
      }
      cout << c << "[" << x+y << "]";
    }
  }
  return 0;
}

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

int mnis(int arr[], int n) 
{ 
    multiset<int> last; 
  
    for (int i = 0; i < n; i++) {   
        multiset<int>::iterator it = last.lower_bound(arr[i]);   
        if (it == last.begin()) 
            last.insert(arr[i]);   
        else { 
            it--; 
            last.erase(it);
            last.insert(arr[i]);
        } 
    } 
    return last.size();
} 


int main(){

	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);

   	int n;
   	cin>>n;

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

   	cout<<mnis(arr,n)<<endl;
}

Measured memory_bytes: 5376
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    val b = new ArrayBuffer[Long]
    var n = 0

    while( { n = readInt; n} != 0 ) {
      val line = { for(i<-1 to n) yield readInt }.toArray.sorted
      var ans = 0L
      var total = 0L
      for(i<- 0 until n) {
        ans += total
        total += line(i).toLong
      }
      b.append(ans)
    }

    print(b.mkString("\n")+"\n")
  }
}

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n, k, ans = 0;
    cin >> n >> k;
    while(n > 0)
    {
        n/= k;
        ans++;
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int i,a,b,c,w,n;
	int s[32]={0};
	
	scanf("%d",&w);
	for(i=1;i<=w;i++){
		s[i]=i;
		
	}
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d , %d",&a,&b);
		c= s[b];
		s[b]=s[a];
		s[a]=c;
	
}

for(i=1;i<=w;i++){
	printf("%d\n",s[i]);
}
return 0;
}

Measured memory_bytes: 596
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        String whiteLine = "";
        List<String> BW = new ArrayList<>();
        for (int i = 0; i < W; i++) {
            whiteLine += ".";
        }
        for (int i = 0; i < H; i++) {
            String S = sc.next();
            if (!S.equals(whiteLine)) {
                BW.add(S);
            }
        }
        boolean[] lostOrder = new boolean[W];
        for (int i = 0; i < W; i++) {
            boolean orderJudge = true;
            for (int j = 0; j < BW.size(); j++) {
                if (BW.get(j).charAt(i) == '#') {
                    orderJudge = false;
                }
            }
            if (orderJudge) {
                lostOrder[i] = true;
            }
        }
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < BW.size(); i++) {
            for (int j = 0; j < W; j++) {
                if (!lostOrder[j]) {
                    ans.append(BW.get(i).charAt(j));
                }
            }
            ans.append("\n");
        }
        System.out.println(ans);
    }
}

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

int main(){
    int d,n;
    cin >> d >> n;
    int w=pow(100,d);
    if(n!=100){
        if(d==0){
            cout << n << endl;
        }
        else if(d!=0){
            cout << n*w << endl;
        }
    }
    else if(n==100){
        cout << 101*w << endl;
    }

	return 0;
}

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

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

int main() {
	map<int,int> m;
	int n;
	cin >> n;
	int arr[n];
	for(int i = 0, a; i < n; i++) {
		cin >> a;
		arr[i] = a;
		m[a]++;
	}
	ll res = 0;
	for(pair<int,int> p : m) {
		int a = p.fs, cnt = p.sd;
		res += ((1LL*cnt)*(cnt - 1))/2;
	}
	for(int i = 0; i < n; i++) {
		ll cnt = m[arr[i]];
		ll temp = res;
		res -= (cnt*(cnt - 1))/2;
		--cnt;
		res += (cnt*(cnt - 1))/2;
		cout << res << '\n';
		res = temp;
	}
}

Measured memory_bytes: 8320
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll inf=1e13;
ll n,a[2005],m[2005],x,res=inf,tr;
int main()
{
    memset(m,0x3f,sizeof m);
    scanf("%lld%lld",&n,&x);
    for (int i=0;i<n;++i)
        scanf("%lld",&a[i]);
    for (ll i=0;i<n;++i) {
        tr=x*i;
        for (ll j=0;j<n;++j) {
            m[j]=min(m[j],a[(j-i+n)%n]);
            tr+=m[j];
        }
        res=min(res,tr);
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int time[3],p,q,r;
	cin>>p>>q>>r;
	time[0]=p;
	time[1]=q;
	time[2]=r;
	sort(time,time+3);
	cout<<time[0]+time[1]<<endl;
	return 0;
}


Measured memory_bytes: 3656
n = int(input())
[a,b] = [int(i) for i in input().split()]
p = [int (i) for i in input().split()]

s = []
t = []
u = []

for i in p:
    if i <= a:
        s.append(i)
    elif b+1 <= i:
        u.append(i)
    else:
        t.append(i)

print(min(len(s),len(t),len(u)))


Measured memory_bytes: 3060
#include <iostream>
#include <array>

int main(){
	using namespace std;
  	array<int, 52> hoge = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  	int n;
  	cin >> n;
  	cout << hoge.at(n - 1); 
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	int N;
	cin >> N;
    int mn = N+1, ans = 0;
    rep(i,N) {
        int p;
        cin >> p;
        if (p<mn) {
            ans++;
            mn = min(mn, p);
        }
    }
	cout << ans << endl;
	return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll x,y;
	cin>>x>>y;
	for(ll i = 0;i<=x;i++)
	{
		ll b = x-i;
		if(2*i + b*4 == y)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 3556
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <iostream>
#include <math.h>

int main () {
	long long number;
	std::cin >> number;
	int min = 9999999;
	while (number) {
		int a = number % 1000;
		number /= 10;
		if (fabs(a - 753) < min) {
			min = fabs(a - 753);
		}
	}
	std::cout << min << std::endl;
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  int A, B, C; cin >> A >> B >> C;
  if (A + B + C >= 22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
from itertools import product


N, M, X = map(int, input().split())
C = []
A = []
for _ in range(N):
    c, *a = map(int, input().split())
    C.append(c)
    A.append(a)

ans = float("inf")
for buys in product((0, 1), repeat=N):
    cost = 0
    achivements = [0] * M
    for i, buy in enumerate(buys):
        if not buy:
            continue
        cost += C[i]
        for j in range(M):
            achivements[j] += A[i][j]
    if all(a >= X for a in achivements):
        ans = min(ans, cost)
print(ans) if ans != float("inf") else print(-1)


Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    string s; cin >> s;
    int N = stoi(s);

    int ans = 0;
    for (int i = 3; i <= s.size(); i++) {
        for (int bit = 0; bit < pow(3, i); bit++) {
            int mp[3];
            mp[0] = mp[1] = mp[2] = 0;

            int tmp = 0, now = bit;
            for (int j = 0; j < i; j++) {
                int x = now % 3;
                mp[x]++;

                if (x == 0) tmp += 3;
                if (x == 1) tmp += 5;
                if (x == 2) tmp += 7;

                now /= 3;
                tmp *= 10;
            }

            tmp /= 10;

            if (tmp <= N && mp[0] != 0 && mp[1] != 0 && mp[2] != 0) ans++;
        }
    }

    cout << ans << endl;
    return 0;
}










Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

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

int dp[105][4][2];

int main() {
  string s;
  int K;
  cin >> s >> K;

  int n = s.size();
  dp[0][0][0] = 1;
  rep(i, n) {
    rep(j, 4) {
      rep(k, 2) {
        int nd = s[i] - '0';
        rep(d, 10) {
          int ni = i + 1, nj = j, nk = k;
          if (d != 0) ++nj;
          if (nj > K) continue;
          if (k == 0) {
            if (d > nd) continue;
            if (d < nd) nk = 1;
          }
          dp[ni][nj][nk] += dp[i][j][k];
        }
      }
    }
  }

  int ans = dp[n][K][0] + dp[n][K][1];
  cout << ans << endl;
  return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int maxn = 100000+10;
vi graph[maxn];
int N,M,memo[maxn];

int dp(int u){
	int &res = memo[u];
	if(res != -1)return res;
	res = 0;
	for(auto &v : graph[u]){
		res = max(res,1+dp(v));
	}
	return res;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> M;
	forn(i,0,N)memo[i] = -1;
	forn(i,0,M){
		int u,v; cin >> u >> v; u--; v--;
		graph[u].pb(v);
	}
	int res = 0;
	forn(i,0,N)res = max(res,dp(i));
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 7552
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/




#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    ll s; cin >> s;
    const int v = 1000000000;
    int x = (v - s % v) % v;
    int y = (s + x) / v;
    cout <<"0 0 1000000000 1 " << x << " " << y << endl;
}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int a,b;
    cin >> a >> b;
    if(a > 9  ||  b > 9)cout << "-1";
    else cout << a*b;
    return 0;
}


Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;
int dp[3333][3333][2],n,m;

void add(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int main()
{
	get2(n,m);
	for(int i=0;i<=n;i++)dp[0][i][i==0]=1;
	for(int i=0;i<m;i++)for(int j=0;j<=n;j++)for(int k=0;k<2;k++)
	{
		//RR
		if(j>0)add(dp[i+1][j-1][k|(j==1)],dp[i][j][k]);
		//RB
		if(j>0)add(dp[i+1][j][k|(j==1)],dp[i][j][k]);
		//BR
		if(j<n)add(dp[i+1][j][k|(j==0)],dp[i][j][k]);
		//BB
		if(j<n)add(dp[i+1][j+1][k|(j==0)],dp[i][j][k]);
	}
	int ans=0;
	for(int i=0;i<=n;i++)add(ans,dp[m][i][1]);
	printendl(ans);
	return 0;
}

Measured memory_bytes: 80128
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void p(vector<char> A){rep(i,A.size()){cout << A[i];}cout << endl;}

int main(){
    int n;
    cin >> n;
    vector<int> a1(n);
    vector<int> a2(n);
    rep(i,n) cin >> a1[i];
    rep(i,n) cin >> a2[i];
    int ans = 0;
    rep(i,n){
        int cnt = 0;
        for(int j = 0;j < n;j++){
            if (i == j){
                cnt += a1[i];
                cnt += a2[j];
            }
            else if (j < i){
                cnt += a1[j];
            }
            else{
                cnt += a2[j];
            }
        }
        ans = max(ans,cnt);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fori(i,a,n) for(i=a;i<=n;i++)
#define ford(i,n,a) for(i=n;i>=a;i--)
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
ll n,i,k,a[200000];
int main()
{
	cin>>n;
	fori(i,1,n)
	{
		scanf("%lld",&k);
		if (k%2==0)
		{
			if (k%3!=0&&k%5!=0)
			{
				puts("DENIED");
				return 0;
			}
		}
	}
	puts("APPROVED");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100002];
int n, k, v[102];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    for(int i = 1; i <= k; ++i)
    {
        for(int j = 1; j <= n; ++j)
            if(i - v[j] >= 0 && !dp[i - v[j]])
                dp[i] = 1;
    }
    if(dp[k])
        cout << "First";
    else
        cout << "Second";
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int cnt = 0;
    int minvalue = INT_MAX;
    for(int i = 0; i < n; ++i){
        minvalue = min(minvalue , a[i]);
        if(a[i] <= minvalue){
            ++cnt;
        }
    }

    cout << cnt << "\n";
return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a == 1) a = 14;
  if (b == 1) b = 14;
  if (a > b) cout << "Alice" << endl;
  else if (a < b) cout << "Bob" << endl;
  else cout << "Draw" << endl;
}

Measured memory_bytes: 256
# coding: utf-8
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=='?':
        break
    elif op=='+':
        print(a+b)
    elif op=='-':
        print(a-b)
    elif op=='*':
        print(a*b)
    elif op=='/':
        print(a//b)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
 
using namespace std;
 
 
//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)
 
#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
 
//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef map<int, int> mint;
typedef vector<int> vint;
typedef vector<char> vch;
typedef vector<long long> vll;
typedef vector<string> vstr;
 
 
int mod(int a, int b){return (a%b+b)%b;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b){ll ans=1; rep(i, b){ans=ans*a%MOD;} return ans;}
 
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
 
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};
 
 
 
 
template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}
 
 
vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}
 
 
 
 
int main(){
 
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll x;
    cin >> x;

    ll sum = 0;
    rep(i, x){
        if(sum < x and x <= sum+(i+1)){
            ppp(i+1);
            break;
        }
        sum += i+1;
    }


    return 0;
}

Measured memory_bytes: 256
n = int(input().strip())

li = list(map(int,input().strip().split()))

d = {}
res = []
for i in li:
    d[i] = d.get(i,0)+1
    if(d[i] == 2 or d[i]==4):
        res.append(i)

if(len(res)<2):print(0)
else:
    res = sorted(res,reverse=True)
    print(res[0]*res[1])
    


Measured memory_bytes: 17960
Alpha = ["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"]

N = int(input())

line = list(input())

for i in range(len(line)):
    line[i] = Alpha[(Alpha.index(line[i]) + N) % 26]
    
print("".join(line))

Measured memory_bytes: 3064
implicit none
integer :: n,x0
integer,allocatable :: x(:)
integer :: i,p,q,r,gcd

read *,n,x0
allocate(x(n))
read *,(x(i),i=1,n)

do i = 1, n
   x(i) = abs(x(i) - x0)
enddo

gcd = x(1)
do i = 2, n
   p = min(gcd,x(i))
   q = max(gcd,x(i))
   
   r = 1
   do while (r > 0)
      r = mod(q,p)
      q = p
      p = r
   enddo
   
   gcd = q
enddo

write(*,'(i0)') gcd
end

Measured memory_bytes: 1152
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vint A(N);
    rep(i, N) cin >> A[i];
    ll ans = 1;
    ll p = 1000000007;
    int smallest = 0;
    int start;
    sort(A.begin(), A.end());
    if (N % 2 == 0) {
        smallest = 1;
        if (A[0] != smallest || A[1] != smallest) {
            cout << 0 << endl;
            return 0;
        }
        ans = 2;
        start = 2;
    }
    else {
        if (A[0] != smallest) {
            cout << 0 << endl;
            return 0;
        }
        ans = 1;
        start = 1;
    }
    
    int j = smallest + 2;
 
    for(int i = start; i < N; i+=2) {
        if (A[i] != j || A[i + 1] != j) {
            cout << 0 << endl;
            return 0;
        }
        j += 2;
        ans *= 2;
        ans %= p;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

int main(void){
  float T,N;
  cin >>T >>N;
  float A;
  A=T/N;
  cout <<A<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
#include<stack>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int main(void){
  string buf;
  char com;
  while(cin>>buf>>com,com!='X'){
    string ans = "";
    switch(com){
    case 'L' :
      ans = tolower(buf[0]);
      loop(i,1,buf.size()){
	if(buf[i] == '_'){
	  ans += toupper(buf[++i]);
	}else{
	  ans += buf[i];
	}	
      }
      break;
    case 'U' :
      ans = toupper(buf[0]);
      loop(i,1,buf.size()){
	if(buf[i] == '_'){
	  ans += toupper(buf[++i]);
	}else{
	  ans += buf[i];
	}
      }
      break;
    case 'D' :
      ans = tolower(buf[0]);
      loop(i,1,buf.size()){
	if('A'<=buf[i] && buf[i]<='Z'){
	  ans += '_';
	  ans += tolower(buf[i]);
	}else{
	  ans += buf[i];
	}
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1200
#include <stdio.h>
#define Aa 1000
int main(){
  int A[Aa];
  int n=0,i=0,j=0,v=0,k=0;
  scanf("%d",&n);
  for(i = 0;i < n; i++){
    scanf("%d",&A[i]);
  }
  for(k = 0;k < (n-1); k++){
    printf("%d ",A[k]);
  }
  printf("%d\n",A[k]);
for(i = 1; i < n; i++){
  v = A[i];
  j = i - 1;
  while(j >= 0 && A[j] > v){
    A[j + 1] = A[j];
    j--;
    A[j + 1] = v;
  }
  for(k = 0;k < (n-1); k++){
    printf("%d ",A[k]);
  }
  printf("%d\n",A[k]);
 }
return 0;
}



Measured memory_bytes: 2124
#define _GLIBCXX_DEBUG
#include"bits/stdc++.h"

using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back

//pair
#define fir first
#define sec second

//types
#define ll long long
#define vec vector
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T>
T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()
template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T = int>
void print(vec<T> v){ for (T item: v) { cout << item << " "; } cout << endl; }

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"Yes":"N1010o"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, string before = "", int nest = 0) { cout << string("          ", nest) << before <<  ": "; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__
#define next next__
#define prev prev__

//constants
const ll INF = 1e18;
const int MOD = 10000007;

//variables
int n;
string s,str;
vec<int> nums;

void Main() {
    //code here
    n = gi;
    nums = gim(n);
    int count = 0;
    while (count_if(ALL(nums), [](auto i){return i % 2 != 0;}) == 0) {
        transform(ALL(nums), nums.begin(), [](auto i){return i/2;});
        count += 1;
    }
    print(count);
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}

Measured memory_bytes: 256
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		mut s: Chars,
		t: Chars,
	}

	for _i in 0..s.len() {
		let mut flag = true;
		for j in 0..s.len() {
			if s[j] != t[j] {
				flag = false;
				break;
			}
		}
		if flag {
			println!("Yes");
			return;
		}
		s.rotate_right(1);
	}
	println!("No");
}


Measured memory_bytes: 2192
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct linestruct{
  double a,b;
} line;

int cmpLine(const void *a,const void *b){
  double p=((line *)a)->a;
  double q=((line *)b)->a;
  return p-q>0?-1:1;
}

double *v=NULL;
int cmpV(const void *a,const void *b){
  int p=*(int *)a;
  int q=*(int *)b;
  return v[p]<v[q]?-1:1;
}

void init(int *bit){
  int n=bit[0];
  memset(bit+1,0,sizeof(int)*n);
}

int sum(int *bit,int index){
  int res=0;
  for(int i=index;i>0;i-=i&-i) res+=bit[i];
  return res;
}

void add(int *bit,int index){
  int n=bit[0];
  for(int i=index;i<=n;i+=i&-i) bit[i]++;
}

void run(void){
  int n;
  scanf("%d",&n);
  line *l=(line *)calloc(n,sizeof(line));
  int i;
  for(i=0;i<n;i++){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    l[i].a=-(double)a/b;
    l[i].b=(double)c/b;
  }
  qsort(l,n,sizeof(line),cmpLine);
  v=(double *)calloc(n,sizeof(double));
  int *index=(int *)calloc(n,sizeof(int));
  int *bit=(int *)calloc(n+1,sizeof(int));
  bit[0]=n;
  double ll=-200000000;
  double rr=200000000;
  for(int iter=0;iter<100;iter++){
    double m=(ll+rr)/2;
    for(i=0;i<n;i++){
      v[i]=l[i].a*m+l[i].b;
      index[i]=i;
    }
    qsort(index,n,sizeof(int),cmpV);
    init(bit);
    int inv=0;
    for(i=0;i<n;i++){
      int p=index[i];
      inv+=sum(bit,p+1-1);
      add(bit,p+1);
    }
    if(2*inv<=n*(n-1)/2){
      rr=m;
    } else {
      ll=m;
    }
  }
  double ansX=ll;
  for(i=0;i<n;i++){
    double a=l[i].a;
    double b=l[i].b;
    l[i]=(line){1/a,-b/a};
  }
  qsort(l,n,sizeof(line),cmpLine);
  ll=-200000000;
  rr=200000000;
  for(int iter=0;iter<100;iter++){
    double m=(ll+rr)/2;
    for(i=0;i<n;i++){
      v[i]=l[i].a*m+l[i].b;
      index[i]=i;
    }
    qsort(index,n,sizeof(int),cmpV);
    init(bit);
    int inv=0;
    for(i=0;i<n;i++){
      int p=index[i];
      inv+=sum(bit,p+1-1);
      add(bit,p+1);
    }
    if(2*inv<=n*(n-1)/2){
      rr=m;
    } else {
      ll=m;
    }
  }
  double ansY=ll;
  printf("%.9lf %.9lf\n",ansX,ansY);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 2056
from math import log
alphabet = ["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"]
N = int(input())
if N == 1: print("a")
elif N == 2: print("b")
else:
    N -= 1
    shou = N
    for i in range(N):
        if 26 * (26 ** i - 1) // 25 > N:
            shou -= 26 * (26 ** (i - 1) - 1) // 25
            break
    ans = ["a"] * i
    flag = 0
    #print(shou,ans)
    while shou > 0:
        ans[flag] = alphabet[shou % 26]
        shou //= 26
        flag += 1
        #print(ans,shou)
    ans.reverse()
    for i in ans: print(i,end = "")
    print()


Measured memory_bytes: 62216
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#define SIZE 12
#define MX 205

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll ans[SIZE][SIZE];
ll fib[SIZE];
bool use[MX];

void make()
{
	fib[0]=1;
	fib[1]=2;
	for(int i=2;i<SIZE;i++)
	{
		for(int j=0;j<i;j++)
		{
			use[fib[j]]=true;
			for(int k=j+1;k<i;k++) use[fib[j]+fib[k]]=true;
		}
		fib[i]=1;
		while(1)
		{
			bool up=!use[fib[i]];
			for(int j=0;j<i;j++) if(use[fib[j]+fib[i]]) up=false;
			if(up) break;
			fib[i]++;
		}
	}
	ll mul=1;
	ans[0][0]=0;
	for(int i=1;i<SIZE;i++)
	{
		ans[i][i]=0;
		for(int j=0;j<i;j++) ans[i][j]=ans[j][i]=fib[j]*mul;
		if(i==1) mul*=2LL;
		else
		{
			mul*=fib[i-1]+fib[i-2];
			mul++;
		}
	}
}
int main()
{
	make();
	int n;
	scanf("%d",&n);
	ll mx=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			printf("%lld ",ans[i][j]);
			mx=max(mx,ans[i][j]);
		}puts("");
	}
	/*
	vector <ll> vec;
	vector <int> ord;
	for(int i=0;i<n;i++) ord.push_back(i);
	do
	{
		ll sum=0;
		for(int i=0;i+1<n;i++) sum+=ans[ord[i]][ord[i+1]];
		vec.push_back(sum);
	}while(next_permutation(ord.begin(),ord.end()));
	sort(vec.begin(),vec.end());
	vector <ll> vx=vec;
	vx.erase(unique(vx.begin(),vx.end()),vx.end());
	printf("%d %d : %lld\n",vx.size(),vec.size(),vec[vec.size()-1]);
	//printf("%lld\n",mx);*/
	return 0;
}


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

int main(){
  string a, b;
  cin >> a >> b;
  int num = stoi(a+b);
  for(int i = 1; i <= 1000; i++){
    if(i*i==num){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,m;
int a[100005];
map<int,int>cnt;
int rem[100005],same[100005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		rem[a[i]%m]++;
		cnt[a[i]]++;
	}
	for(auto p:cnt){
		same[p.first%m]+=p.second/2;
	}
	int ans=0;
	if(m%2==0){
		ans+=rem[m/2]/2;
		rem[m/2]=0;
	}
	ans+=rem[0]/2;rem[0]=0;
	for(int i=1;i<=m/2;i++){
		int oppo=m-i;
		int add=min(rem[i],rem[m-i]);
		ans+=add;
//		cerr<<i<<" "<<oppo<<" "<<add<<endl;
		rem[i]-=add;
		rem[m-i]-=add;
	}
	for(int i=0;i<m;i++){
		int rest=min(rem[i]/2,same[i]);
		ans+=rest;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6144
using System;

namespace abc063A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            if (A + B >= 10)
                Console.WriteLine("error");
            else
                Console.WriteLine(A+B);
        }
    }
}


Measured memory_bytes: 11092
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);
parse_tuple!(A, B, C, D);
parse_tuple!(A, B, C, D, E);

// ===

fn main() {
    let (n, k): (usize, usize) = read();
    let mut a: Vec<i32> = readnc();
    let mut kinds = vec![];

    a.sort();
    let mut i = 0;
    while i < n {
        let mut j = i;
        while j < n && a[i] == a[j] {
            j += 1;
        }
        kinds.push(j-i);
        i = j;
    }


    kinds.sort();
    kinds.reverse();
    let mut keep = 0;
    for ki in 0..min(k, kinds.len()) {
        keep += kinds[ki];
    }
    println!("{}", n-keep);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;

int a[100002], b[100002];
int main(){
	int n, k, ans = inf;
	scanf("%d%d", &n, &k);
	for(int i = 1;i <= n;i++)scanf("%d", &a[i]);
	
	int l = 0, r = 0, sum = 0;
	while(r <= n){
		if(sum == k)ans = min(ans, r-l);
		if(sum < k){if(a[++r] <= k && b[a[r]]++ == 0)sum++;}
		else {if(a[++l] <= k && --b[a[l]] == 0)sum--;}
	}
	
	if(ans == inf)printf("0\n");
	else printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 4012
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define REP(i,n) for(int i=0;i<n;++i)
using namespace std;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a[100000];
  cin >> n;
  REP(i, n)
    cin >> a[i];

  sort(a, a + n);
  
  int num = a[0];
  int i = 0;
  while(i < n) {
    if(a[i] % num != 0) {
      num = a[i] % num;
      i = 0;
    } else {
      ++i;
    }
  }
  cout << num << endl;

  return 0;
}


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

int main() {
  
  int64_t N, M; cin >> N >> M;
  
  if (M <= N * 2) { cout << M / 2 << endl; return 0; }
  
  int64_t tmp = (M - N * 2) / 4;
  
  cout << N + tmp << endl;
  
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int n,m;
int main()
{
    //freopen("1.txt","r",stdin);
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        printf("%d\n",(1<<m)*(1900*m+(n-m)*100));
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
	int n,i,s,max=0,min=100;
	int hero[5];
	for(i=0;i<5;i++)
		scanf("%d",&hero[i]);
	scanf("%d",&s);
	for(i=0;i<5;i++)
	{
		if(hero[i]>max)
			max=hero[i];
	}
	for(i=0;i<5;i++)
	{
		if(hero[i]<min)
			min=hero[i];
	}
	if(max-min>s)
		printf(":(\n");
	else
		printf("Yay!\n");
	return 0;
}

Measured memory_bytes: 128
from math import sqrt
N, D = map(int, input().split())
X = []
for i in range(N):
    x = tuple(map(int, input().split()))
    X.append(x)

cnt = 0
for i in range(N-1):
    for j in range(i+1, N):
        distance = 0
        for d in range(D):
            distance += (X[i][d]-X[j][d])**2

        distance = sqrt(distance)
        if int(distance) - distance == 0:
                cnt += 1
print(cnt)


Measured memory_bytes: 3316