akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

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

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

struct UnionFind {
    int n, cnt;
    vector<ll> par, rank, sz;

    UnionFind(ll n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) { iota(par.begin(), par.end(), 0); }

    ll find(ll x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

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

    ll size(ll x) { return sz[find(x)]; }

    void unite(ll x, ll y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        } else {
            par[y] = x;
            sz[x] += sz[y];
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
        cnt--;
    }
};

int main() {
    ll N, M; cin >> N >> M;
    UnionFind u=UnionFind(N+1);
    vector<ll> ans(M+1,0);
    ans[M]=N*(N-1)/2;
    vector<int> A(M), B(M);
    rep(i,M){
        cin >> A[i] >> B[i];
    }
    for(int i=M-1; i>0; i--){
        if(!u.same(A[i],B[i])){
            ans[i]=ans[i+1]-u.size(A[i])*u.size(B[i]);
            u.unite(A[i],B[i]);
        }else{
            ans[i]=ans[i+1];
        }
    }

    for(int i=1; i<=M; i++){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 5248
n = int(input())
record = []
for i in range(n):
    pl = list(input().split())
    record.append(pl)
x = input()

isSleep = False
ans = 0

for r in record:
    if isSleep:
        ans += int(r[1])
    if r[0] == x:
        isSleep = True

print(ans)

Measured memory_bytes: 3060
A,B=map(int,input().split())
UP=[["#"]*100 for _ in range(50)]
DN=[["."]*100 for _ in range(50)]
i,j=0,0
a=1
# 偶数行目の偶数番目を白く塗る
while a<A:
    UP[j][i]="."
    a+=1
    i+=2
    if i>=100:
        j+=2
        i=0
i,j=0,1
b=1
# 奇数行目の偶数番目を黒く塗る
while b<B:
    DN[j][i]="#"
    b+=1
    i+=2
    if i>=100:
        j+=2
        i=0
print("{} {}".format(100, 100))
print("\n".join("".join(i) for i in UP))
print("\n".join("".join(i) for i in DN))

Measured memory_bytes: 3188
from collections import deque
def main():
    N = int(input())
    S = input()
    c = [0] * N
    a = [deque() for _ in range(10)]
    b = [deque() for _ in range(10)]
    for i in range(N):
        a[int(S[i])].append(i)
        b[int(S[i])].append(i)
    for i in range(N):
        x = b[int(S[i])].popleft()
        cc = 0
        for j in range(10):
            if b[j]: cc += 1
        c[i] = cc
    output = 0
    visited = [0] * 10
    for i in range(N):
        a[int(S[i])].popleft()
        if visited[int(S[i])]: continue
        visited[int(S[i])] = 1
        for j in range(10):
            if a[j]:
                x = a[j][0]
                output += c[x]
    print(output)
    return

if __name__ == '__main__':
    main()


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

int main() {
  int N,A;
  cin >> N;
  vector< vector< pair<int,int> > > s(N);
  REP(i,N) {
    cin >> A;
    REP(j,A) {
      int x,y;
      cin >> x >> y;
      s[i].emplace_back( --x, y );
    }
  }

  int ans = 0;
  // 全探索
  REP(t,1 << N) {
    int ng = 0;
    REP(i,N) {
      if ( ((t >> i) & 1) == 1 ) {
        for ( auto x: s[i] )
          if ( ((t >> x.first) & 1) != x.second ) ng = 1;
      }
    }
    if ( ng == 0 ) {
      int cnt = 0;
      REP(i,N) if (((t >> i) & 1)==1) cnt++;
      ans = max(ans,cnt);
    }
  }
  cout << ans << endl;

  return 0;
}


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

char fie[30][30];
int R,C;

struct state{
  int x,y,m,d;
};

bool M[30][30][20][4];
int dx[]={1,0,-1,0};//0> 1v 2< 3^ 
int dy[]={0,1,0,-1};

bool next(int &x,int &y,int d){
  x+=dx[d];
  y+=dy[d];
  if( x == -1 ) x = C-1;
  else if( y == -1 ) y = R-1;
  else if( x == C+1 ) x = 0;
  else if( y == R+1 ) y = 0;
  return true;
}

bool calc(int x,int y,int &m,int &d){
  if( fie[x][y] == '<' ) d = 2;
  else if( fie[x][y] == '>' ) d = 0;
  else if( fie[x][y] == '^' ) d = 3;
  else if( fie[x][y] == 'v' ) d = 1;
  else if( fie[x][y] == '_' ){
    if( m == 0 ) d = 0;
    else d = 2;
  } else if( fie[x][y] == '|' ){
    if( m == 0 ) d = 1;
    else d = 3;
  } else if( fie[x][y] == '@' ) return true;
  else if( isdigit(fie[x][y] )  )m = fie[x][y] - '0';
  else if( fie[x][y] == '+' ) m = (m+1)%16;
  else if( fie[x][y] == '-' ) m = (m+15)%16;
  return false;
}

bool solve(){
  memset(M,0,sizeof(M));
  queue<state> q;
  q.push( (state){0,0,0,0} );
  M[0][0][0][0] = 1;
  while( !q.empty() ){
    state st = q.front(); q.pop();
    //cout << st.x << " " << st.y << " " << st.m << " "<< st.d << endl;
    if( fie[st.x][st.y] == '?' ){
      for(int i=0;i<4;i++){
        int nx = st.x, ny = st.y;
        next( nx, ny, i );
        if( M[nx][ny][st.m][i] ) continue;
        M[nx][ny][st.m][i] = 1;
        q.push( (state){nx,ny,st.m,i} );
      }
    } else {
      int nx = st.x, ny = st.y, nm = st.m, nd = st.d;
      if( calc( nx, ny, nm, nd ) ) return true;
      next( nx, ny, nd );
      if( M[nx][ny][nm][nd] ) continue;
      M[nx][ny][nm][nd] = 1;
      q.push( (state){nx,ny,nm,nd} );
    }
  }
  
  return false;
}

int main(){
  cin >> R >> C;
  for(int i=0;i<R;i++)
    for(int j=0;j<C;j++)
      cin >> fie[j][i];

  if( solve() ) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

ll N, A, B, C, D;
char s[202020];
ll dpA[202020];
ll dpB[202020];
ll flg = 0;

int main(){

    cin >> N >> A >> B >> C >> D;
    for(ll i = 1; i <= N; i++)cin >> s[i];
    dpA[A] = 1;
    for(ll i = 1; i <= N; i++){
        if(dpA[i]){
            if(s[i + 1] == '.')dpA[i + 1] = 1;
            if(s[i + 2] == '.')dpA[i + 2] = 1;
        }
    }
    dpB[B] = 1;
    for(ll i = 1; i <= N; i++){
        if(dpB[i]){
            if(s[i + 1] == '.')dpB[i + 1] = 1;
            if(s[i + 2] == '.')dpB[i + 2] = 1;
        }
    }
    if(C < D)flg = 1;
    else{
        for(ll b = B; b <= D; b++){
            if(s[b - 1] == '.' && s[b] == '.' && s[b + 1] == '.')flg = 1;
        }
    }
    if(flg && dpA[C] && dpB[D])cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 2944
import collections
n = int(input())
a = list(input().split())
b = collections.Counter(a)
num = list(b.values())
k = len(num)
an = 0

for i in range(k):
	an+=(num[i])*(num[i]-1)//2

for i in range(n):
	ans=an-b[a[i]]+1
	print(ans)


Measured memory_bytes: 26788
N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))

visited = set()
current = 0
answer = 0
count = 0
while current not in visited and count < K:
    visited.add(current)
    count += 1
    current = A[current]
    answer = current

if count == K:
    print(answer + 1)
    exit(0)

# print(count)
start = A[current]
ary = [start]
loop_size = 1
while start != current:
    loop_size += 1
    start = A[start]
    ary.append(start)

# print(ary)
# print('loop_size', loop_size)
print(ary[(K - count) % loop_size - 1] + 1)


Measured memory_bytes: 32412
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		if(N < 1000) {
			System.out.println("ABC");
		}else {
			System.out.println("ABD");
		}
	}

}

Measured memory_bytes: 21716
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a  =sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		if(b-a+1 <= 2*k) {
			for(int i = a; i <= b; i++) {
				System.out.println(i);
			}
		}
		else {
			for(int i = a; i < a+k; i++) {
				System.out.println(i);
			}
			for(int i = b-k+1; i <= b;i++) {
				System.out.println(i);
			}
		}
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#include<functional>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

int main()
{
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    int ans=0;
    bool change=false;

    rep(i,n-1)
    {
        if(i+1==a[i])
        {
            if(change)
            {
                change=false;
            }
            else
            {
                ans++;
                change=true;
            }  
        }
        else
        {
            change=false;
        }
        
    }
    if(a[n-1]==n && !change)
    {
        ans++;
    }
    cout<<ans;
    
    
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
    string a;
    while(cin>>a){
        int len=a.length();
//        cout<<len<<endl;
        int num=753,sum=0;
        for(int i=0;i<len-2;i++){
            sum=(a[i]-'0')*100+(a[i+1]-'0')*10+(a[i+2]-'0');
            if(abs(sum-753)<num){
                num=abs(sum-753);
            }
        }
        cout<<num<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String X = sc.next();
			String Y = sc.next();

			if(X.charAt(0) < Y.charAt(0)){
				System.out.println("<");
			} else if(X.charAt(0) > Y.charAt(0)){
				System.out.println(">");
			} else {
				System.out.println("=");
			}
		}
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

struct edge{ int from,to,cost; };

bool comp( const edge& left, const edge& right ) {
    return left.cost < right.cost;
}

int rnk[100],par[100];

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

int find(int x){
	if(par[x] == x) return x;
	return par[x] = find(par[x]);
}

void unite(int a,int b){
	a = find(a);
	b = find(b);
	if(a == b) return;
	if(rnk[a] > rnk[b]){
		par[b] = a;
	}else{
		par[a] = b;
		if(rnk[a] == rnk[b]) rnk[b]++;
	}
}

int main(){
	int n,m;
	while(cin >> n,n){
		cin >> m;
		vector<edge> v;
		init(n);
		for(int i = 0;i < m;i++){
			int a,b,c;
			scanf("%d,%d,%d",&a,&b,&c);
			v.push_back({a,b,c / 100 - 1});
		}
		sort(v.begin(),v.end(),comp);
		int res = 0;
		for(int i = 0;i < m;i++){
			edge e = v[i];
			if(find(e.to) == find(e.from)) continue;
			unite(e.to,e.from);
			res += e.cost;
		}
		cout << res << endl;
	}
	return 0;
}

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

int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = (N % 1000) / 100;
  c = (N % 100) / 10;
  d = N % 10;
  if (a == b && b == c) cout << "Yes" << endl;
  else if (d == c && c == b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N, M = list(map(int, input().rstrip().split()))

t = [0] * (N + 1)

for i in range(M):
    a, b = list(map(int, input().rstrip().split()))
    t[a] += 1
    t[b] += 1


for i in range(1, N + 1):
    print(t[i])


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

int calcdigit(int num)
{
	int digit = 1;

	while (true) {
		if (num / 10 == 0) {
			break;
		}
		else {
			num /= 10;
			digit++;
		}
	}

	return digit;
}

int main()
{
	int n;

	cin >> n;

	vector<int> vec(n);

	rep(i, n) {
		cin >> vec[i];
	}

	int ans = 0;

	while (true) {
		int digit = calcdigit(ans);
		bool flag = false;

		rep(i, n + 1 - digit) {
			int temp = 0;

			rep(j, digit) {
				temp *= 10;
				temp += vec[i + j];
			}

			if (temp == ans) {
				flag = true;
				break;
			}
		}

		if (flag == true) {
			ans++;
		}
		else {
			cout << ans << endl;
			break;
		}
	}

	return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, a[100009];
LL bv[100009], bp[100009], c;
LL an[100009], as[100009], ans[100009];


int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	LL ma = 0;
	bv[c] = 0;
	bp[c] = -1;
	c++;
	inc(i, n) {
		if(setmax(ma, a[i])) {
			bv[c] = a[i];
			bp[c] = i;
			c++;
		}
	}
	
	inc(i, n) {
		int L = 0;
		int R = c;
		while(R - L > 1) {
			int M = (L + R) / 2;
			(a[i] <= bv[M] ? R : L) = M;
		}
		an[R]++;
		as[R] += a[i] - bv[R - 1];
	}
	
	/*
	incID(i, 1, c) {
		cout << "[" << bv[i - 1] << ", " << bv[i] << "] " << an[i] << " " << as[i] << endl;
	}
	cout << endl;
	*/
	
	dec(i, c - 1) { an[i] += an[i + 1]; }
	incID(i, 1, c) { ans[ bp[i] ] = an[i + 1] * (bv[i] - bv[i - 1]) + as[i]; } 
	
	inc(i, n) {
		cout << ans[i] << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 5760
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = String.valueOf(sc.nextInt());
		String rn = "",rs = "";
		char n1 = n.charAt(0),n2 = n.charAt(1),n3 = n.charAt(2);
		if(n1 == n2 && n2 == n3) {
			System.out.println(Integer.valueOf(n));
			return;
		}else if(n1 == n2){
			if((int)n2 > (int)n3) {
				rs = String.valueOf(n1);
			}else {
				 rs = String.valueOf((char)((int)n1 + 1));
			}
		}else {
			if((int)n1 > (int)n2) {
				rs = String.valueOf(n1);
			}else {
				rs = String.valueOf((char)((int)n1 + 1));
			}
		}
		rn += rs+rs+rs;
		System.out.println(rn);
	}
}

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

#define print(x) cerr << #x << " is " << x << endl;
#define int long long int
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define all(v) (v).begin(), (v).end()   
#define pii pair<int, int>
#define pb push_back
#define PI 3.1415926535897932384626
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define out cout << fixed << setprecision(12) <<

const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const double lifeofpi = acos(-1);


int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int val = n % 10;
    if(val == 2 || val == 4 || val == 5 || val == 7 || val == 9){
        cout << "hon\n";
    }
    else if(val == 1 || val == 0 || val == 6 || val == 8){
        cout << "pon\n";
    }
    else{
        cout << "bon\n";
    }

    return 0;
}

Measured memory_bytes: 3652
#include<iostream>

using namespace std;

int main() {
	char a[3];
	int i,x=700;

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

	for (i = 0; i < 3; i++) {
		if(a[i]=='o'){
			x += 100;
		}
	}

	cout << x;
	return 0;
}

Measured memory_bytes: 256
x=[int(input()) for _ in range(5)]
a=0
b=0

for i in range(5):
    if x[i]%10!=0:
        a+=x[i]-(x[i]%10)+10
        
        if b <= 10-x[i]%10:
            b=10-x[i]%10
        
    else:
        a+=x[i]

print(a-b)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cassert>
using namespace std;
typedef long long ll;

int par[210],sz[210];
void init(int n){
	for(int i=0;i<n;i++){
		par[i] = i; sz[i] = 1;
	}
}

int find(int x){
	if(par[x]==x) return x;
	return par[x] = find(par[x]);
}

void unite(ll x, ll y){
	x = find(x); y = find(y);
	if(x==y) return;
	if(sz[x]<sz[y]) swap(x,y);
	par[y] = x; sz[x] += sz[y];
}

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

struct edge{ll u,v,cost,num;};
vector<edge> E;
bool comp1(const edge& e1, const edge& e2){
	if(e1.cost!=e2.cost) return e1.cost<e2.cost;
	else return e1.num<e2.num;
}

bool comp2(const edge& e1, const edge& e2){
	if(e1.cost!=e2.cost) return e1.cost<e2.cost;
	else return e1.num>e2.num;
}

pair<ll,ll> kruscal(int n,ll w,int x){
	int i; pair<ll,ll> p = {0,0};
	for(i=0;i<E.size();i++){
		if(E[i].num==1) E[i].cost += w;
	}
	if(x==0) sort(E.begin(),E.end(),comp1);
	if(x==1) sort(E.begin(),E.end(),comp2);
	init(n);
	for(i=0;i<E.size();i++){
		edge e = E[i];
		if(!same(e.u,e.v)){
			unite(e.u,e.v);
			p.first += e.cost;
			p.second += 1 - e.num;
		}
	}
	for(i=0;i<E.size();i++){
		if(E[i].num==1) E[i].cost -= w;
	}
	if(sz[find(0)]<n) p.second = -1;
	return p;
}

int main(){
	while(true){
		int i,n,m,k;
		cin >> n >> m >> k;
		if(n + m + k==0) break;
		E.clear();
		int cnt = 0;
		for(i=0;i<m;i++){
			ll u,v,w; char c;
			cin >> u >> v >> w >> c;
			u--; v--;
			ll l = 0 + (c=='B');
			E.push_back({u,v,w,l});
		}
		ll inf = 1000000000000;
		if(kruscal(n,inf,0).second<k || kruscal(n,-inf,0).second>k){
			cout << -1 << endl;
		}else{
			ll r = inf,l = -inf;
			while(r - l>1){
				ll mid = (l + r)/2;
				if(kruscal(n,mid,0).second<k) l = mid;
				else r = mid;
			}
			cout << kruscal(n,r,0).first - r*(n - k - 1) << endl;
			ll x = kruscal(n,r - 1,0).second,y = kruscal(n,r,1).second;
			assert(x==y);
		}
	}
}


Measured memory_bytes: 3176
#include <stdio.h>

int main(void)
{
	int n;
	int a, b;
	int ap, bp;
	int i;
	
	while (1) {
		scanf("%d", &n);
		if (n == 0) {
			break;
		}
		
		ap = bp = 0;
		for (i = 0; i < n; i++) {
			scanf("%d %d", &a, &b);
			if (a > b) {
				ap += a + b;
			}
			else if (a < b) {
				bp += a + b;
			}
			else {
				ap += a;
				bp += b;
			}
		}
		printf("%d %d\n", ap, bp);
	}
	
	return (0);
}

Measured memory_bytes: 600
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    long[] dp = new long[N+1];
    for (int i = 0; i < M; i++) {
      dp[sc.nextInt()] = -1;
    }
    dp[0] = 1;
    dp[1] = dp[1] == 0 ? 1 : 0;
    for (int i = 2; i < N+1; i++) {
      if (dp[i] == -1) {
        dp[i] = 0;
      } else {
        dp[i] = dp[i-1] + dp[i-2];
        dp[i] %= 1000000007;
      }
    }
    System.out.println(dp[N]);
  }
}

Measured memory_bytes: 48560
A, B, C, X, Y = map(int, input().split())

price1 = A * X + B * Y
price2 = min(X, Y) * 2 * C + abs(X - Y) * (A if X > Y else B)
price3 = max(X, Y) * 2 * C

print(min(price1, price2, price3))


Measured memory_bytes: 61844
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,i,j;
  cin>>n;
  long long int a[n],b=0;
  for(i=0;i<n;i++)
  {
    cin>>a[i];
  }
  sort(a,a+n);
  for(i=0;i<n-1;i++)
  {
    
      if(a[i]==a[i+1])
      {
        b=1;
        break;

      }
    
  }
  if(b==1)
  {

      cout<<"NO";

  }
  else{
    cout<<"YES";

  }
  return 0;
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c;
  cin >> a >> b >> c;
  cout << min(b / a, c) << endl;
  return 0;
}


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

int main() {
    int n; cin >> n;
    multiset<int> unused;
    for(int i = 0; i < 1 << n; ++i) {
        int a; cin >> a;
        unused.insert(a);
    }

    multiset<int> used;
    used.insert(*prev(unused.end()));
    unused.erase(prev(unused.end()));
    for(int i = 0; i < n; ++i) {
        multiset<int> nused;
        for(auto a : used) {
            auto it = unused.lower_bound(a);
            if(it == unused.begin()) {
                break;
            }
            it = prev(it);
            nused.insert(a);
            nused.insert(*it);
            unused.erase(it);
        }
        used = move(nused);
    }

    cout << (unused.empty() ? "Yes" : "No") << endl;
}


Measured memory_bytes: 18688
import math
a,b = map(int, input().split())
l = [list(map(int,input().split())) for i in range(a)]

cnt = 0
for i in range(a):
  for j in range(i+1,a):
    x = 0
    for k in range(b):
      x += (l[i][k]-l[j][k])**2
    if x**(1/2) - int(x**(1/2)) == 0:
      cnt += 1
print(cnt)

Measured memory_bytes: 3188
def main():
    n, k = map(int, input().split())
    H = [int(input()) for _ in range(n)]
    H.sort()
    ans = 10 ** 9 + 2
    for i in range(n - k + 1):
        ans = min(ans, H[i + k - 1] - H[i])
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13376
//I am so vegetable
//#define err
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define pb push_back
#define in insert
#define er erase
#define ct count
#define ep empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const double pi = acos(-1.0);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, ll MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll inv(ll x, ll MOD) { return qpow(x, MOD - 2) % MOD; }
ll m_m(ll a,ll MOD){ return (a%MOD+MOD)%MOD; }


signed main() {
	//ofstream cout("E:\\acm dream\\out.txt",ios::out);
	FIO;
    #ifdef err
	double be = clock();
    #endif
    int ans = 0;
    int l,r,d;cin>>l>>r>>d;
    _for(i,l,r+1){
        if(i%d==0)++ans;
    }
    cout<<ans;
    #ifdef err
	double en = clock();
    cout<<"time: "<<fixed<<setprecision(8)<<en-be;
    #endif
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);



int main(){
    FIN;
    string s;
    cin >> s;
    ll cur = 0;
    for(ll i=0;i<s.size();i++){
        ll x = s[i] - '0';
        cur += x;
        cur %= 9;
    }

    if(cur == 0) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 3652
module Main where

import Data.Functor

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  { loop 1
}

loop :: Int -> IO ()
loop i = do
  { [x] <- getInts
  ; if x == 0 then done
    else do
     { putStrLn ("Case " ++ show i ++ ": " ++ show x)
  ; loop (i+1)
     }
  }

done :: IO ()
done = return ()

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

string S;

int main() {
    cin >> S;

    if (S <= "2019/04/30") {
        printf("Heisei\n");
    } else {
        printf("TBD\n");
    }
}

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

int main() {
  string s; cin>>s; int n=s.size();
  bool ok=true;
  for(int i=0;i<=n-1;i++) {
    if (s[i] != s[n-1-i]) ok=false;
  }
  int u1=(n-1)/2-1;
  for(int i=0;i<=u1;i++) {
    if (s[i] != s[u1-i]) ok=false;
  }
  //cout<<u1<<endl;
  int u2=(n+3)/2;
  for(int i=u2;i<n;i++) {
    if (s[i] != s[n-1-i]) ok=false;
  }
  //cout<<u2<<endl;
  if (ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
L = [input() for _ in range(H)]

inf = 10**9
dp = [[inf] * W for _ in range(H)]

#[0][0]を埋める
if (L[0][0] == '.'):
    dp[0][0] = 0
else:
    dp[0][0] = 1

for i in range(H):
    for j in range(W):

        #[0][0]の時は無視
        if (i == 0 and j == 0):
            continue
        #→の場合。一個前のマス。
        a = dp[i][j - 1]
        #↓の場合。一個前のマス。
        b = dp[i - 1][j]

        #.から#に移動するときだけ操作が(1回)必要
        if (L[i][j - 1] == "." and L[i][j] == "#"):
            a += 1
        if (L[i - 1][j] == '.' and L[i][j] == '#'):
            b += 1

        # min(dp[i][j],a,b)でもいいが結局問題になるのはa,bの比較だけでは？
        dp[i][j] = min(a, b)

print(dp[-1][-1])


Measured memory_bytes: 9220
#include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n, a) for(int i = a; i < n; ++i)

int main(void) {
  int n, i, j, max = 0, now = 0;
  scanf("%d", &n);
  int r[n], d[n];
  d[0] = 0;
  rep(i, n) {
    scanf("%d", &r[i]);
    if(i) d[i] = r[i] - r[i - 1];
  }
  rep(i, n) {
    now += d[i];
    if(now < 0) now = 0;
    if(now > max) max = now;
  }
  if(!max) {
    max = -10e9 - 7;
    repi(i, n, 1) {
      if(max < d[i]) max = d[i];
    }
  }
  printf("%d\n", max);
  return 0;
}


Measured memory_bytes: 4232
#include <bits/stdc++.h>
using namespace std;
#define INF 1001001001
typedef pair<int,int> pp;
typedef pair<int, pp> P;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int H,W;

bool isIn(int i, int j) {
    return i>=0 && i<H && j>=0 && j<W;
}

int main() {
    cin >> H >> W;
    char s[50][50];
    int white = 0;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            cin >> s[i][j];
            if(s[i][j] == '.') ++white;
        }
    }

    int dist[50][50];
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            dist[i][j] = INF;
        }
    }
    queue<pp> q;
    dist[0][0] = 0;
    q.push(pp(0,0));
    while(!q.empty()) {
        pp cur = q.front(); q.pop();
        for(int i=0; i<4; ++i) {
            int nx = cur.first + dx[i];
            int ny = cur.second + dy[i];
            if(isIn(nx, ny) && s[nx][ny] == '.') {
                dist[nx][ny] = dist[cur.first][cur.second] + 1;
                s[nx][ny] = '#';
                q.push(pp(nx,ny));
            }
        }
    }
    
    if(dist[H-1][W-1] == INF) cout << -1 << endl;
    else cout << white - dist[H-1][W-1] - 1 << endl;
    return 0;
}

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

using namespace std;

int main(void){

  int i,j,k,t,tmp;
  string s;
  int a,b,c;
  cin>>a>>b>>c;
  cout<<(a+b)*c/2;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<ll, ll> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}


 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	const int maxn = 1e6 + 5;

	vector<int> divs(maxn);
	for(int i = 1; i < maxn; i++)
		for(int j = i; j < maxn; j += i)
			divs[j]++;

	int n;
	cin >> n;

	ll ans = 0;

	for(int c = 1; c <= n; c++){
		int x = n - c;
		ans += 1ll * divs[x];
	}

	cout << ans << endl;

	return 0;
}


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

#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define sz size()
#define endl "\n"
#define pb push_back
#define pp pop_back
#define mp make_pair
#define REP(I,n) for(int I = 0; I < n; I++)
#define REP_1(I,n) for(int I = 1; I <= n; I++)
#define w(t) int t; cin>>t; while(t--)

#define MOD 1000000007
#define INF 1e9 + 7

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

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef map<int,string> mis;
typedef set<int> si;
typedef set<string> ss;

typedef long long ll;

template<class T>
istream &operator>>(istream &in,vector<T> &arr) {
	for(auto &x : arr)
		in >> x ;
	return in;
}

template<class T>
ostream &operator<<(ostream &out,vector<T> &arr) {
	for(auto &x : arr)
		out << x << ' ';
	return out;
}
void solve() {
	string str;
	cin>>str;
	if(str=="ABC")
		cout<<"ARC";
	else
		cout<<"ABC";
}					
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	solve();
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    string str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    str+=str;
    int f=1;
    int sum=0;
    for(int i=0;i<s.size();i++){
        for(int j=f;j<str.size();j++){
            //cout<<str[j]<<endl;
            if(str[j]=='A') sum++;
            if(s[i]==str[j]){
                int tmp=-16;
                tmp+=s[i]-'0';
                f=tmp;
                //cout<<f<<endl;
                break;
            }
        }
        
    }
    cout<<sum<<endl;
    return 0;
}





Measured memory_bytes: 3212
s = input()
t = input()
l = []
cnt = 0
for i in s:
    l.append(i)
for j in range(len(s)):
    l.insert(0, l[len(s) - 1])
    
    #print(l[:len(s)])
    
    if "".join(l[:len(s)]) == t:
        cnt += 1
if cnt >= 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
setrecursionlimit(1000000)

# INF = float('inf')
INF = int(1e10)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    S = input()
    if S[2] == S[3] and S[4] == S[5]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
N,Q=map(int,input().split())
d=[[] for _ in range(N+1)]

ans=[0]*(N+1)
for i in range(1,N):
    a,b=map(int,input().split())
    d[a].append(b)
    d[b].append(a)

for i in range(Q):
    p,x=map(int,input().split())
    ans[p]+=x

from collections import deque
flag=[0]*(N+1)
q=deque([1])
while q:
    k=q.popleft()
    flag[k]=1
    for v in d[k]:
        if flag[v]==1:
            continue
        ans[v]+=ans[k]
        q.appendleft(v)

print(*ans[1:])

Measured memory_bytes: 56084
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define mod 1000000007
#define ll long long
#define N 310
using namespace std;
ll f[N][N][N];
int head[N],nxt[N<<1],x[N<<1],to[N<<1],cnt;
void add(int r,int l,int lim)
{
	nxt[++cnt]=head[r];
	to[cnt]=l;
	x[cnt]=lim;
	head[r]=cnt;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int l,r,x;
		scanf("%d%d%d",&l,&r,&x);
		add(r,l,x);
	}
	f[1][0][0]=1;
	for(int r=1;r<=n;r++)
	{
		for(int o=head[r];o;o=nxt[o])
		{
			int l=to[o];
			for(int i=0;i<r;i++)
				for(int j=0;j<=max(0,i-1);j++)
				{
 					if(x[o]==1 && l<=i) f[r][i][j]=0;
 					if(x[o]==2 && (i<l || l<=j)) f[r][i][j]=0;
					if(x[o]==3 && j<l) f[r][i][j]=0;
                }
		}
		for(int l=0;l<r;l++)
			for(int i=0;i<=max(0,l-1);i++)
			if(f[r][l][i])
			{
				f[r+1][l][i]=(f[r+1][l][i]+f[r][l][i])%mod;
				f[r+1][r][i]=(f[r+1][r][i]+f[r][l][i])%mod;
				f[r+1][r][l]=(f[r+1][r][l]+f[r][l][i])%mod;
			}
	}
	ll ans=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<=max(0,i-1);j++)
		ans=(ans+f[n][i][j])%mod;
    printf("%lld\n",ans*3%mod);
	return 0;
}


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

int main(){
        int n;
        long long int tot_t=1, tot_a=1;
        cin>>n;
        for(int i=0; i<n; i++){
                int ti, ai;
                cin>>ti>>ai;
                long long int mag_t, mag_a;
                if(tot_t%ti==0) mag_t=tot_t/ti;
                else mag_t=tot_t/ti+1;
                if(tot_a%ai==0) mag_a=tot_a/ai;
                else mag_a=tot_a/ai+1;
                long long int mag=max(mag_t, mag_a);
                tot_t=mag*ti;
                tot_a=mag*ai;
        }

        cout<<tot_t+tot_a<<endl;

        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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 dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    rep(i,4)cout << s[i];
    cout << " ";
    rep(i,s.size()-4)cout << s[i+4];
    cout << endl;
}

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

int main()
{

    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    ll n = min(s.size(), t.size());
    rep(i, n){
        ll s_n = '0' + s[i];
        ll t_n = '0' + t[i];
        if (s_n > t_n){
            puts("No");
            return 0;
        }else if (s_n < t_n){
            puts("Yes");
            return 0;
        }
    }

    if (s.size() < t.size()){
        puts("Yes");
    }else{
        puts("No");
    }

    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#define lmid l,m,rt<<1
#define rmid m+1,r,rt<<1|1
#define LL long long
#define rl r-l+1
using namespace std;
int main()
{
     int n,a;
     scanf("%d%d",&n,&a);
     cout<<n*n-a<<endl;
}


Measured memory_bytes: 256
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define endl '\n'


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int a, b;
        in >> a >> b;
        if (a == 1) a = 14;
        if (b == 1) b = 14;
        if (a < b) out << "Bob" << endl;
        else if (a > b) out << "Alice" << endl;
        else out << "Draw" << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("out.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define pDB pair<double,double>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
int knight[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}
//struct compare
//{
//  bool operator()(const int& l, const int& r)
//  {
//      return l>r;
//  }
//};

bool cmp(int a, int b)
{
    return a<b;
}
int on(int mask,int st)
{
    return mask|(1<<st);
}
int off(int mask,int st)
{
    return mask&(~(1<<st));
}
bool check(int mask,int st)
{
    return mask&(1<<st);
}
ll inf=1e18;
ll mod=1e9+7;
double dp[301][301][301];
int vis[301][301][301];
int n;
double total;
double fun(int one,int two,int three)
{
    if(one==0 && two==0 && three==0)
    {
        return 0.0;
    }
    double &ret=dp[one][two][three];
    if(vis[one][two][three]==1)
    {
        return ret;
    }
    vis[one][two][three]=1;
    double ans=1.0;
    double x;
    if(one)
    {
        x=one;
        ans+=((x/total)*fun(one-1,two,three));
    }
    if(two)
    {
        x=two;
        ans+=(x/total)*fun(one+1,two-1,three);
    }
    if(three)
    {
        x=three;
        ans+=((x/total)*fun(one,two+1,three-1));
    }
    x=one+two+three;
    ans*=total;
    ans/=(x);
    return ret=ans;

}
double countt[10];
int main()
{
//    READ;
    int n,x;
    sf(n);
    total=n;
    for(int i=0;i<n;i++)
    {
        sf(x);
        countt[x]++;
    }
    double ans=(fun(countt[1],countt[2],countt[3]));
    cout<<fixed<<setprecision(10)<<ans<<endl;

    return 0;
}


Measured memory_bytes: 319744
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        int n;
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
 
        if(a<b){
            n = a;
            a = b;
            b = n;
          }
        
          if(b<c){
            n = b;
            b = c;
            c = n;
          }
        
          if(a<b){
            n = a;
            a = b;
            b = n;
          }

          System.out.println(""+c+" "+b+" "+a);
    }
}


Measured memory_bytes: 26148
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
const int MOD = 1000000007;
ll dp[210][210];
int main(){
    int n;
    scanf("%d", &n);
    string s = "";
    rep(i, n){
        char c; cin >> c;
        if(c == '-') continue;
        s += c;
    }
    n = s.size();
    if(!n) goto one;
    memset(dp, 0, sizeof(dp));
    if(s[0] == 'D') goto fail;
    dp[0][1] = 1;
    REP(i, 1, n){
        rep(j, i + 2){
            if(s[i] == 'D'){
                dp[i][j] += (dp[i - 1][j] * j) % MOD;
                dp[i][j] += (dp[i - 1][j + 1] * (j + 1) * (j + 1)) % MOD;
            }else{
                dp[i][j] += dp[i - 1][j - 1];
                dp[i][j] += (dp[i - 1][j] * j) % MOD;
            }
            dp[i][j] %= MOD;
        }
    }
    printf("%d\n", dp[n - 1][0]);
    return 0;
  fail:
    puts("0");
    return 0;
  one:
    puts("1");
    return 0;
}

Measured memory_bytes: 1588
import java.util.*;
import java.math.*;

public class Main {

    static long MOD = 1000000007;



    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = i + l;
        }
        int sum = 0;
        for(int i = 0; i < n; i++) {
            sum += a[i];
        }
        int dif = 324092384;
        int ans = sum * 2;
        for(int i = 0; i < n; i++) {
            if(Math.abs(a[i]) < dif) {
                dif = Math.abs(a[i]);
                ans = sum - a[i];
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
using namespace std;
int a[1000000],n;
int binarysearch(int key)
{
  int left = 0;
  int right = n;
  while (left < right)
  {
    int mid = (left+right)/2;
    if(a[mid] == key)
      return 1;
    if(a[mid]<key) left = mid+1;
    else if(key<a[mid]) right = mid;
  }
   return 0 ;
}
int main (){
  int i,q,k,sum = 0;
  scanf("%d",&n);
  for(int i =0;i<n;i++)
    scanf("%d",&a[i]);
  scanf("%d",&q);
  for(int i = 0;i<q;i++)
  {
    scanf("%d",&k);
    if(binarysearch(k))
    sum++;
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N;cin>>N;
    int a,b;
    int ans=0;
    rep(i,N){
        cin>>a>>b;
        ans+=max(a,b)-min(a,b)+1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3576
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  list($m) = explode(" ", trim(fgets(STDIN)));

  $a = strlen($n);
  $ans=0;
  for ($i=0; $i<$a; $i++) {
    if($n[$i] != $m[$i]){
      $ans++;
    }
  }
  echo $ans;

Measured memory_bytes: 16704
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	string s,t;
 	cin>>s>>t;
 	cout<<t+s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	float s;
	int a, m;
	scanf("%f", &s);
	a=(int)(s/1.08);
	for(int i=-2;i<2;i++){
		m=(a+i)*1.08;
		if(m==(int)s){
			printf("%d", a+i);
			return 0;
		}
	}
	
	
	printf(":(");
	return 0;
}

Measured memory_bytes: 128
// D - Menagerie
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; string S; cin>>N>>S;
	vector<bool> a(N+2);
	for(int j=0; j<4; j++){
		a[0] = j/2; a[1] = j%2;
		for(int k=2; k<N+2; k++)
			a[k] = a[k-1] && S[(k-1)%N]=='o'
				|| !a[k-1] && S[(k-1)%N]=='x'? a[k-2]: !a[k-2];
		if(a[0]==a[N] && a[1]==a[N+1]) break;
	}
	if(a[0]!=a[N] || a[1]!=a[N+1]) cout<<"-1";
	else for(int i=0; i<N; i++) cout<<(a[i]?'S':'W');
	cout<<endl;
}

Measured memory_bytes: 512
import java.io.PrintWriter;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		long mod = (long) 1e9 + 7;
		int h = sc.nextInt(), w = sc.nextInt();
		char[][] a = new char[h][w];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.next().toCharArray();

		}
		long[][] dp = new long[h][w];
		dp[0][0] = 1;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i][j] == '#') {
					a[i][j] = 0;
				} else {
					if (i == 0 && j == 0) {
						continue;
					} else {
						if (i == 0) {
							dp[i][j] = dp[i][j - 1];

						} else if (j == 0) {
							dp[i][j] = dp[i - 1][j];

						} else {
							dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod;
						}
					}
				}
			}
		}
		pw.println(dp[h - 1][w - 1]);
		pw.flush();

	}

}


Measured memory_bytes: 55760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int card[100500];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        int l, r;
        cin >> l >> r;
        card[l]++;
        card[r+1]--;
    }
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        card[i] += card[i-1];
        if(card[i] == M) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640