akhauriyash/Code-Regression huggingface dataset:
N,M = map(int,input().split())

li=[0]*M
for i in range(M):
    li[int(i)]=input().split()
#print(li)

count=[0]*N#ペナルティを数える
flg=[0]*N #初期状態０⇒ACを出したら１
for i in range(M):
    if li[int(i)][1] == "AC":#ACを出したら
        flg[int(li[int(i)][0])-1]=1#flg[]に１を格納
    if flg[int(li[int(i)][0])-1] == 0:#まだACを出していないなら
        count[int(li[int(i)][0])-1]+=1#ペナルティ数を１追加

for i in range(N):
    if flg[int(i)] == 0:#１度も正解していないとき
        count[int(i)]=0#ペナルティ数を0にする

print(sum(flg), sum(count))

Measured memory_bytes: 93852
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7 ;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}





int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    int a,b;
    cin>>a>>b;
    if(b<=1){cout<<0<<endl;return 0;}
    int ans=a;
    int cnt=1;
    while(ans<b){
        ans+=(a-1);
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
    }


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

using namespace std;

#define int long long
#define ff first
#define ss second
#define pb emplace_back

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    n *= 2;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < n; i += 2)
        ans += a[i];
    cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#include<regex>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl; }
const LL MOD = 1e9 + 7;
const LL LLINF = 1LL << 60;
const int INF = 1 << 30;


int main(void) {
	LL N;
	cin >> N;

	vector<LL> B(N - 1);
	rep(i, N - 1) cin >> B[i];

	vector<LL> A(N);
	A[0] = B[0];
	A[1] = B[0];

	for (LL i = 1; i < N - 1; i++) {
		A[i + 1] = B[i];
		if (A[i] > B[i]) A[i] = B[i];
	}
	cout << accumulate(ALL(A), 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a, b, c, k;
  int result = 0;
  scanf("%d%d%d%d", &a, &b, &c, &k);
  if(a >= k){
    result = k;
  }else if((a+b) >= k){
    result = a;
  }else{
    result = a - (k - (a+b));
  }
  printf("%d\n", result);
  return 0;
}


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

int main(){
	int d;	cin >> d;
	switch(d){
		case 25:
			cout << "Christmas" << endl;
			break;
		case 24:
			cout << "Christmas Eve" << endl;
			break;
		case 23:
			cout << "Christmas Eve Eve" << endl;
			break;
		case 22:
			cout << "Christmas Eve Eve Eve" << endl;
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		
		int ans = 0;
		
		for(int a = 1; a < N; a ++) {
			for(int b = 1; b < N; b ++) {
				if(a * b < N) {
					ans ++;
				}else {
					break;
				}
			}
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 36296
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string w;
    getline(cin,w);
    int len=w.size();
    int a[26]={0};
    int T=0;
    for(int i=0;i<len;i++)
        a[w[i]-97]++;
    for(int i=0;i<25;i++)
        if(a[i]%2!=0){
           T=1;
         break;
        }
    if(T==0)
        printf("Yes\n");
    else
        printf("No\n");

}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] a = new long[N + 1];
        for (int i = 0; i < N + 1; i++) {
            a[i] = scanner.nextLong();
        }
        long[] b = new long[N];
        for (int i = 0; i < N; i++) {
            b[i] = scanner.nextLong();
        }

        long result = 0;
        long defeated;
        for (int i=0; i < N; i++) {
            defeated = Math.min(a[i], b[i]);
            result += defeated;
            defeated = Math.min(a[i+1], b[i]-defeated);
            a[i+1] -= defeated;
            result += defeated;
        }
        System.out.println(result);
    }
}

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

int main() {
    int n;
    cin>>n;
    vector<int> h(n+1,0), minCost(n+1,0);
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    h[0]=INT_MAX;
    minCost[1]=0;
    for(int i=2;i<=n;i++){
        minCost[i]=min(minCost[i-1]+abs(h[i]-h[i-1]),minCost[i-2]+abs(h[i]-h[i-2]));
    }
    
    // for(int i=0;i<=n;i++) cout<<minCost[i]<<" ";
    // cout<<endl;
    cout<<minCost[n];
	return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

string s,ans="";

void f(ll i){
    if(ans[i]=='S'){
        if(s[i]=='o'){
            ans[i+1]=ans[i-1];
        }
        else{
            if(ans[i-1]=='S'){
                ans[i+1]='W';
            }
            else{
                ans[i+1]='S';
            }
        }
    }
    else if(ans[i]=='W'){
        if(s[i]=='x'){
            ans[i+1]=ans[i-1];
        }
        else{
            if(ans[i-1]=='S'){
                ans[i+1]='W';
            }
            else{
                ans[i+1]='S';
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n>>s;
    int count=1;

    for(int i=0;i<=n;i++){
        ans+=" ";
    }
    ans[0]='S';
    ans[1]='S';
    for(int i=1;i<=n-1;i++){
        f(i);
    }
    if(s[0]=='o'){
        if(ans[n-1]=='W')
            count=0;
    }
    else if(s[0]=='x'){
        if(ans[n-1]=='S')
            count=0;
    }
    if(ans[n]!=ans[0]){
        count=0;
    }

    if(count==0){
        count=1;
        for(int i=0;i<=n;i++){
            ans[i]=' ';
        }
        ans[0]='S';
        ans[1]='W';
        for(int i=1;i<=n-1;i++){
            f(i);
        }
        if(s[0]=='o'){
            if(ans[n-1]=='S')
                count=0;
        }
        else if(s[0]=='x'){
            if(ans[n-1]=='W')
                count=0;
        }
        if(ans[n]!=ans[0]){
            count=0;
        }
    }

    if(count==0){
        count=1;
        for(int i=0;i<=n;i++){
            ans[i]=' ';
        }
        ans[0]='W';
        ans[1]='W';
        for(int i=1;i<=n-1;i++){
            f(i);
        }
        if(s[0]=='o'){
            if(ans[n-1]=='W')
                count=0;
        }
        else if(s[0]=='x'){
            if(ans[n-1]=='S')
                count=0;
        }
        if(ans[n]!=ans[0]){
            count=0;
        }
    }

    if(count==0){
        count=1;
        for(int i=0;i<=n;i++){
            ans[i]=' ';
        }
        ans[0]='W';
        ans[1]='S';
        for(int i=1;i<=n-1;i++){
            f(i);
        }
        if(s[0]=='o'){
            if(ans[n-1]=='S')
                count=0;
        }
        else if(s[0]=='x'){
            if(ans[n-1]=='W')
                count=0;
        }
        if(ans[n]!=ans[0]){
            count=0;
        }
    }
    if(count==0)
        cout<<-1<<endl;
    else{
        ans=ans.substr(0,n);
        cout<<ans<<endl;
    }
    return 0;
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;

using namespace std;

inline bool prime(int n){
	if(n < 2) return false;
	if(n == 2) return true;
	for(int i = 2 ; i * i <= n ; ++i){
		if(n % i == 0) return false;
	}
	return true;
}

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

	int n;
	cin >> n;
	
	vi p;
	repi(i , 55555){
		if(prime(i) && to_string(i).back() == '3') p.pb(i);
	}
	
	rep(i , n) cout << p[i] << " ";

	return 0;
}

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


def main():
    n, m, x, y = map(int, input().split())
    xs = list(map(int, input().split())) + [x]
    ys = list(map(int, input().split())) + [y]

    x_max = max(xs)
    y_min = min(ys)

    if x_max < y_min:
        print('No War')
    else:
        print('War')


if __name__ == '__main__':
    main()


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

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
  int n,k;
  cin>>n>>k;
  mint a=1;
  mint b=1;
  rep(i,k){
    a = a*(n-k+1-i)/(i+1);
    if(i) b = b*(k-1-i+1)/i;
    mint ans = a*b;
    cout << ans.x << endl;
  }
}



Measured memory_bytes: 256
//あらためて見るとこの問題全然わからない

//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int a[2][200000], b[2][200000];
	int kazuA[29] = {}, kazuB[29] = {};
	rep(i, N) {
		a[0][i] = getint(); 
		rep(j, 28) kazuA[j] += a[0][i] >> j & 1;
	}
	rep(i, N) {
		b[0][i] = getint();
		rep(j, 28) kazuB[j] += b[0][i] >> j & 1;
	}
	int kotae = 0;
	rep(i, 28) {
		int p = i & 1;

		int kazu[2];
		kazu[0] = 0;
		kazu[1] = N - kazuA[i];
		rep(j, N) a[!p][kazu[a[p][j] >> i & 1]++] = a[p][j];
		kazu[0] = 0;
		kazu[1] = N - kazuB[i];
		rep(j, N) b[!p][kazu[b[p][j] >> i & 1]++] = b[p][j];

		int kari = 0;
		int d = (1 << i) - 1;
		int d2 = 1 << i;
		int k1 = kazu[0];
		int k2 = N;
		rep(j, N - kazuA[i]) {
			while (k1 > 0 && (a[!p][j] & d) + (b[!p][k1 - 1] & d) >= d2) k1--;
			while (k2 > kazu[0] && (a[!p][j] & d) + (b[!p][k2 - 1] & d) >= d2) k2--;
			kari ^= k1 ^ k2;
		}
		k1 = kazu[0];
		k2 = N;
		for (int j = N - kazuA[i]; j < N; j++) {
			while (k1 > 0 && (a[!p][j] & d) + (b[!p][k1 - 1] & d) >= d2) k1--;
			while (k2 > kazu[0] && (a[!p][j] & d) + (b[!p][k2 - 1] & d) >= d2) k2--;
			kari ^= N ^ k1 ^ k2;
		}

		kotae += (kari & 1) << i;
	}

	int d2 = 1 << 28;
	int k = N;
	int kari = N;
	rep(j, N) {
		while (k > 0 && a[0][j] + b[0][k - 1] >= d2) k--;
		kari ^= k;
	}
	kotae += (kari & 1) << 28;

	printf("%d", kotae);

	Would you please return 0;
}

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

int main()
{
int a;
int b;
cin>> a;
double p[a];
int m[a];

for(int i=0;i<a;i++)
{
    cin>>p[i];}
 double mm=0;
 for(int i=0;i<a;i++)
 {
     mm=mm+(1/p[i]);
 }
 cout<<1/mm<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b;
    int area;
	int inner_primeter;
	
	
	
	
	scanf("%d %d", &a ,&b);
	while(1){
	if(1<=a && 100>=b){
		area=a*b;
		inner_primeter=a*2+b*2;
		break;
	}else{
		scanf("%d %d", &a ,&b);
	    continue;
	}
	}
	printf("%d %d\n", area ,inner_primeter);
		
	return 0;
}

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

int cnt[128];

int main() {
    int u, v;
    while (scanf("%d%d", &u, &v) != EOF) {
        u--, v--;
        rep (i, 128) cnt[i] = 0;
        cnt[u]++, cnt[v]++;
        for (;;) {
            scanf("%d%d", &u, &v);
            if (u == 0 && v == 0) break;
            u--, v--;
            cnt[u]++, cnt[v]++;
        }
        bool f = true;
        rep (i, 128) if (cnt[i]%2 != (i<2)) f = false;
        puts(f ? "OK" : "NG");
    }
    return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int K = scan.nextInt();
        int T = scan.nextInt();
        int[] a = new int[T];
        for (int i = 0; i < T; i++) {
            a[i] = scan.nextInt();
        }
        Arrays.sort(a);
        int max = T-1;
        for (int i = 0; i < T-1; i++) {
            if (a[i] == 0) {
                continue;
            }
            while (0 < a[i]) {
                if (a[i] < a[max]) {
                    a[max] -= a[i];
                    a[i] = 0;
                    continue;
                }
                a[i] -= a[max];
                a[max] = 0;
                max -= 1;
            }
        }
        System.out.println(Math.max(0, a[max]-1));
    }
}


Measured memory_bytes: 23252
def ok(target, S):
    for t in target:
        if t in S:
            S = S[S.index(t)+1:]
        else:
            return False
    return True


N = int(input())
S = input()
ans = 0

for i in range(0, 999+1):
    target = str(i).zfill(3)
    ans += ok(target, S)

print(ans)


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

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

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    ll h,w;
    cin >> h >> w;
    ll x = h*w;
    if(h==1||w==1){
        cout << 1 << endl;
        return 0;
    }
    if(x%2==0){
        cout << x/2 << endl;
    }else{
        cout << (x/2)+1 << endl;
    }
}

Measured memory_bytes: 256
public class Main{
    public static void main(String []args) {
        {
      int a, b, c, d;
 
     a = 1;
     b = 9;
     for (c = a; c <= b; c++) {
      
      for (d = 1; d < 10; d++) {
         System.out.println(c+"x"+d+"="+(c*d));
      }
    }
     }
      
    }
} 

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

#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second

using namespace std;

vector <int> g[112345];
int v[112345];
ll M = 1e9 + 7;

int main()
{
	int n,k;
	cin>>n>>k;
	for(int i = 0; i <(n-1); i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}

	int root = 0;
	for(int node = 1; node <=n; node++)
	{
		if(g[node].size() > k-1)
		{
			root = node;
            break;
		}
	}

	if (!root) root = 1; 

	ll ans = k;

	v[root] = 1;

	queue <int> q;

	for(int i = 0; i < g[root].size(); i++)
	{
		 q.push(g[root][i]);
		 ans = (ans * (k-i-1)) % M;
	}

	while(!q.empty())
	{
		int node = q.front();
		q.pop();
		v[node] = 1;
		int c = 2;
		for(int i = 0; i < g[node].size(); i++)
		{
			if (v[g[node][i]]) continue;

			q.push(g[node][i]);
			ans = (ans * (ll)(k-c)) % M; 
			c++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S;
	bool ans = true;
	
	cin >> S;

	if (S.length() % 2 == 0) {
		for (int i = 0; i < S.length(); i += 2) {
			if (S.substr(i, 2) != "hi") ans = false;
		}
	}
	else ans = false;

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#coding: utf-8
import math

class UnionFind():
    def __init__(self,r):
        self.size = [1] * (r+1)
        self.rank = [0] * (r+1)
        # self.root_pointer = [i for i in range(r+1)]
        self.table = [-1 for _ in range(r+1)]

    # xが属す集合の根を求める
    def find(self,x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def union(self,x,y):
        root_x = self.find(x)
        root_y = self.find(y)
        if root_x != root_y:
            # グラフの高さが異なる場合
            if self.table[root_x] != self.table[root_y]:
                if self.table[root_x] < self.table[root_y]:
                    self.table[root_y] = root_x
                else:
                    self.table[root_x] = root_y
            # グラフの高さが同じ場合
            else:
                self.table[root_x] += -1
                self.table[root_y] = root_x
        return

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

if __name__ == "__main__":
    N,M = map(int,input().split(" "))
    uf = UnionFind(N)
    P = map(int, input().split(" "))
    for _ in range(M):
        x,y = map(int, input().split(" "))
        # unionfindを作成
        uf.union(x,y)
    
    result = 0
    for i,o in enumerate(P):
        if uf.issame_root(o,i+1):
            result += 1
    
    print(result)

Measured memory_bytes: 13872
#include<stdio.h>
int main(void)
{
 	int w,a,b,x;
	scanf("%d %d %d",&w,&a,&b);
	if(a<b){
		x=(w+a)-b;
		if(w+a>=b){
			x=0;
		}
		else{
			if(x<0){
				x=x*-1;
			}
		}
		printf("%d\n",x);
	}
	else{
		x=(w+b)-a;
		if(w+b>=a){
			x=0;
		}
		else{
			if(x<0){
				x=x*-1;
			}
		}
		printf("%d\n",x);
	}
	return 0;
}


Measured memory_bytes: 128
def solve():
    BTC = 380000
    N = int(input())
    
    ans = 0
    for _ in range(N):
        x, u = map(str, input().split())
        x = float(x)
        if u == 'JPY':
            ans += x
        else:
            ans += x * BTC
    print(ans)


if __name__ == '__main__':
    solve()


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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m);
	set<int> dic;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		dic.insert(a[i]);
	}
	vector<int> an, o = a;
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		if (dic.count(b[i])) an.push_back(b[i]);
		o.push_back(b[i]);
	}
	sort(an.begin(), an.end());
	sort(o.begin(), o.end());
	o.erase(unique(o.begin(), o.end()), o.end());
	printf("%d %d\n", (int)an.size(), (int)o.size());
	for (auto val : an) {
		printf("%d\n", val);
	}
	for (auto val : o) {
		printf("%d\n", val);
	}
	return 0;
}



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

#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fst first
#define snd second

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

vector<vector<pair<int, int>>> g;
vector<set<int>> s;
vector<int> ans;

void dfs(int u, int p, int p_clr)
{
    int cur = 1;
    for (auto x : g[u])
    {
        int v, id;
        tie(v, id) = x;
        if (v == p)
            continue;
        if (p_clr == cur)
            cur++;
        ans[id] = cur;
        dfs(v, u, cur);
        cur++;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    g.resize(n);
    ans.resize(n - 1);
    for (int i = 0; i < n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].EB(v, i);
        g[v].EB(u, i);
    }
    dfs(0, 0, 0);
    cout << *max_element(ALL(ans)) << "\n";
    for (auto x : ans)
    {
        cout << x << "\n";
    }
    return 0;
}

Measured memory_bytes: 8320
#include<cstdio>
#include<algorithm>
#include<cstring>
typedef long long ll;
using namespace std;
int n,m,i,a[18];
ll F[1<<17],inv[1<<17],f[1<<17],ans;
const int mod=1e9+7;
int C(int a,int b){return a<b?0:F[a]*inv[b]%mod*inv[a-b]%mod;}
void dec(ll &a,int b){(a-=b)<0?a+=mod:0;}
void inc(ll &a,int b){(a+=b)>=mod?a-=mod:0;}
int main(){
	scanf("%d%d",&n,&m);F[0]=F[1]=inv[0]=inv[1]=1;
	for(i=2;i<=(1<<n);i++)F[i]=F[i-1]*i%mod,inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(i=2;i<=(1<<n);i++)inv[i]=inv[i]*inv[i-1]%mod;
	for(i=1;i<=m;i++)scanf("%d",&a[i]);
	for(f[0]=1<<n,i=m;i;i--)for(int j=(1<<n)-1;j;j--)for(int k=0;k<n;k++)if(j&(1<<k))dec(f[j],f[j^(1<<k)]*C((1<<n)-a[i]-(j^(1<<k)),(1<<k)-1)%mod*F[1<<k]%mod);
	for(i=0;i<(1<<n);i++)inc(ans,f[i]*F[(1<<n)-i-1]%mod);
	printf("%lld\n",ans);
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j) for(int i=0;i<j;i++)
#define print(a) cout<<a<<endl
typedef long long ll;
typedef string str;
typedef unsigned long long ul;
#define vint vector<int>

int main() {
	int n,k;cin>>n>>k;
	long double dn=n,dk=k,sum=0;
	rep(i,n){
		long double di=i+1,d=ceil(log2(dk/di));
		if(dk<=di){
			d=0;
		}
		sum+=(1/dn)*pow(0.5,d);
	}
	cout<<setprecision(16)<<sum<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int a,b,c,d,a2,b2,c2;
  a = n / 1000;
  a2 = n % 1000;
  b = a2 / 100;
  b2 = a2 % 100;
  c = b2 / 10;
  c2 = b2 % 10;
  d = c2;
  
  if (a == b && b == c) {
    cout << "Yes" << endl;
  } else if (b == c && c == d){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll x[100010],y[100010];
char d[100010];

ll t[100],tcnt;
ll f[4][3];


int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld%lld %c",y+i,x+i,d+i);
	
	{
		//右端を調べる
		//右方向、左方向、上下方向に移動する最も右側にいるものを調べる
		ll f1=-INF,f2=-INF,f3=-INF;
		rep(i,0,n){
			if(d[i]=='R')f1=max(f1,y[i]);
			else if(d[i]=='L')f2=max(f2,y[i]);
			else f3=max(f3,y[i]);
		}
		//左に動くものが右端にいる時間[0,t1)を求める
		if(f2==-INF)t[tcnt]=0;
		else t[tcnt]=max(0,min((f2-f1+1)/2,f2-f3));
		tcnt++;
		//上下に動くものが右端にいる時間[t1,t2)を求める
		if(f3==-INF)t[tcnt]=t[tcnt-1];
		else t[tcnt]=max(t[tcnt-1],max(f3-f1,f2-f3));
		tcnt++;
		f[0][0]=f1;
		f[0][1]=f2;
		f[0][2]=f3;
	}
	
	{
		//右端を調べる
		//右方向、左方向、上下方向に移動する最も右側にいるものを調べる
		ll f1=-INF,f2=-INF,f3=-INF;
		rep(i,0,n){
			if(d[i]=='L')f1=max(f1,-y[i]);
			else if(d[i]=='R')f2=max(f2,-y[i]);
			else f3=max(f3,-y[i]);
		}
		//左に動くものが右端にいる時間[0,t1)を求める
		if(f2==-INF)t[tcnt]=0;
		else t[tcnt]=max(0,min((f2-f1+1)/2,f2-f3));
		tcnt++;
		//上下に動くものが右端にいる時間[t1,t2)を求める
		if(f3==-INF)t[tcnt]=t[tcnt-1];
		else t[tcnt]=max(t[tcnt-1],max(f3-f1,f2-f3));
		tcnt++;
		f[1][0]=f1;
		f[1][1]=f2;
		f[1][2]=f3;
	}
	
	{
		//右端を調べる
		//右方向、左方向、上下方向に移動する最も右側にいるものを調べる
		ll f1=-INF,f2=-INF,f3=-INF;
		rep(i,0,n){
			if(d[i]=='U')f1=max(f1,x[i]);
			else if(d[i]=='D')f2=max(f2,x[i]);
			else f3=max(f3,x[i]);
		}
		//左に動くものが右端にいる時間[0,t1)を求める
		if(f2==-INF)t[tcnt]=0;
		else t[tcnt]=max(0,min((f2-f1+1)/2,f2-f3));
		tcnt++;
		//上下に動くものが右端にいる時間[t1,t2)を求める
		if(f3==-INF)t[tcnt]=t[tcnt-1];
		else t[tcnt]=max(t[tcnt-1],max(f3-f1,f2-f3));
		tcnt++;
		f[2][0]=f1;
		f[2][1]=f2;
		f[2][2]=f3;
	}
	
	{
		//右端を調べる
		//右方向、左方向、上下方向に移動する最も右側にいるものを調べる
		ll f1=-INF,f2=-INF,f3=-INF;
		rep(i,0,n){
			if(d[i]=='D')f1=max(f1,-x[i]);
			else if(d[i]=='U')f2=max(f2,-x[i]);
			else f3=max(f3,-x[i]);
		}
		//左に動くものが右端にいる時間[0,t1)を求める
		if(f2==-INF)t[tcnt]=0;
		else t[tcnt]=max(0,min((f2-f1+1)/2,f2-f3));
		tcnt++;
		//上下に動くものが右端にいる時間[t1,t2)を求める
		if(f3==-INF)t[tcnt]=t[tcnt-1];
		else t[tcnt]=max(t[tcnt-1],max(f3-f1,f2-f3));
		tcnt++;
		f[3][0]=f1;
		f[3][1]=f2;
		f[3][2]=f3;
	}
	
	double ans=INF;
	rep(i,0,tcnt)rep(j,-6,7){
		double time=t[i]+j/2.0;
		if(time<0||time>=1e10)continue;
		double a[4];
		rep(k,0,4)a[k]=max(f[k][0]+time,max(f[k][1]-time,f[k][2]));
//		printf("%lld %lld\n",time,(a[0]+a[1])*(a[2]+a[3]));
		ans=min(ans,(a[0]+a[1])*(a[2]+a[3]));
	}
	printf("%.9f",ans);	
}

Measured memory_bytes: 1792
from collections import deque

INF = 10 ** 9

H, W = map(int, input().split())
si, sj = map(int, input().split())
gi, gj = map(int, input().split())

si += 1
sj += 1
gi += 1
gj += 1

sentinel = [-1] * (W + 4)
MAP = [sentinel, sentinel]
for _ in range(H):
    MAP.append([-1, -1] + [-1 if c == '#' else INF for c in input()] + [-1, -1])
MAP.append(sentinel)
MAP.append(sentinel)

#detected = [[False] * (W+4) for _ in range(H+4)]
#arrived = [[False] * (W+4) for _ in range(H+4)]
MAP[si][sj] = 0
q = deque([(si, sj)])
while q:
    i, j = q.popleft()
    if i == gi and j == gj:
        break
    for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        if MAP[i+di][j+dj] > MAP[i][j]:
            MAP[i+di][j+dj] = MAP[i][j]
            q.appendleft((i+di, j+dj))

    for di in range(-2, 3):
        for dj in range(-2, 3):
            if MAP[i+di][j+dj] > MAP[i][j] + 1:
                MAP[i+di][j+dj] = MAP[i][j] + 1
                q.append((i+di, j+dj))

# print(*MAP, sep = '\n')

ans = MAP[gi][gj]
if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 85788
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<string>
#define mem(a, b) memset((a), (b), sizeof (a));
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+10;
template<class T>inline T read(T&x){char c;while((c = getchar()) <= 32);bool flag = false;if(c == '-')flag = true, c = getchar();for(x = 0; c > 32; c = getchar())x = x*10+c-'0';if(flag)x = -x;return x;}
template<class T>inline T write(T x){if(x < 0)putchar('-'), x = -x;if(x < 10)putchar(x+'0');else write(x/10),putchar(x%10+'0');}
//------------------- Main ------------------------
bool cmp(int a, int b)
{
    return a>b;
}
int main()
{
    int n;
    int a, b[maxn], c[maxn];
    while(cin >> n)
    {
        int ma = 0, mb = 0, mma, mmb;
        memset(b, 0, sizeof b);
        memset(c, 0, sizeof c);
        for(int i = 1; i <= n; ++i)
        {
            read(a);
            if(i&1)
            {
                b[a]++;
                if(b[a] > ma)ma = b[a], mma = a;
            }
            else
            {
                c[a]++;
                if(c[a] > mb)mb = c[a], mmb = a;
            }
        }
        sort(b, b+maxn, cmp);
        sort(c, c+maxn, cmp);
        //cout << b[0] << ' ' << c[0] << endl;
        //cout << b[1] << ' ' << c[1] << endl;
        int ans;
        if(mma == mmb)
        {
            if(b[0] == c[0])
            {
                if(b[1]>c[1])ans = n-b[0]-b[1];
                else ans = n-b[0]-c[1];
            }
            else if(b[0] > c[0])ans = n-b[0]-c[1];
            else ans = n-c[0]-b[1];
        }
        else ans = n-b[0]-c[0];
        write(ans);
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef  long long   ll;
ll inf=1000000000000000000,mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        ll n,k;cin>>n>>k;
         map<ll,ll> mp;ll num,num1;
         for(ll i=0;i<k;i++){
             cin>>num;
             for(ll j=0;j<num;j++){
                 cin>>num1;mp[num1]++;
             }
         }
         ll sum=0;
         for(ll i=1;i<=n;i++)if(mp[i]==0)sum++;
         cout<<sum;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (auto& e : l) cin >> e;
  sort(l.begin(), l.end());
  ll r = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int b = lower_bound(l.begin() + (j + 1), l.end(), l[i] + l[j]) - l.begin() - 1;
      if (b < n) r += b - j;
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
	int N;
	cin >> N;
	vector<llong> A(N);
	for(int i=0; i<N; ++i) cin >> A[i];
	sort(A.rbegin(), A.rend());
	int q = N/2;
	int r = N%2;
	llong ans = 0;
	for(int i=0; i<q; ++i){
		ans += 2 * A[i];
	}
	ans -= A[0];
	if(r==1) ans += A[q];
	cout << ans << endl;
}

Measured memory_bytes: 4808
#include <bits/stdc++.h>
using namespace std;
int main () {
int ans = 0;
int n,k;
int a[100000];
cin >> n >> k;
for(int i =0;i<n;i++){
cin >> a[i];
}
int min = 100000;
int argmin = 0;
for(int i=0;i < n;i++){
if(a[i] < min){
min = a[i];
argmin = i;
}
}
int l = argmin;
int r = n - argmin;
//while(l > 0){
//l -= k-1;
//ans++;
//}
//while(r > 0){
//r -= k-1;
//ans++;
//}
ans += l / (k-1);
ans += r / (k-1);
//if(l % (k-1) != 0) ans++;
//if(r % (k-1) != 0) ans++;

if(k-1 > r || k-1 > l){
ans = n / k;
if(n%k!=0)ans++;
}
if(k==2){ans--;}
if(n==k)ans = 1;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 640
/*
* @Author: Samson
* @Date:   2018-05-03 15:59:43
* @Last Modified by:   Samson
* @Last Modified time: 2018-05-03 16:04:26
*/
//   @URL : http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C
#include<bits/stdc++.h>
#include<algorithm>
#include <cstdlib>
#include<map>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e5+10;

map<string,bool> m;

int main(void)
{
	ios::sync_with_stdio(false); 
	//cin.tie(0);
	string a,b;
	int T;
	cin>>T;
	while(T--)
	{
		cin>>a>>b;
		if(a == "insert")
			m[b] = true;
		else
		{
			if(m[b])
				cout<<"yes\n";
			else
				cout<<"no\n";
		}
	}

	return 0;
}


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

int main(void) {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int n = k;
    if (a >= n) {
        cout << n;
        return 0;
    } else {
        n -= a;
    }
    if (b >= n) {
        cout << a;
        return 0;
    } else {
        n -= b;
    }
    cout << a - n;

}

Measured memory_bytes: 3592
def test
    n = gets.to_i
    vs = gets.split(" ").map(&:to_i)
    cs = gets.split(" ").map(&:to_i)
    ans = 0
    n.times do |i|
        tmp = vs[i] - cs[i]
        ans += tmp if tmp >= 0
    end
    ans
end

puts test

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


// 1白
// 2黒

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int co[100002]={};
	vector<P> tree[n];
	FOR(i,0,n-1){
		int a,b,w;
		cin >> a >> b >> w;
		a--;b--;
		tree[a].push_back({b,w&1});
		tree[b].push_back({a,w&1});
	}
	queue<int> q;
	q.push(0);
	co[0] = 1;
	while(!q.empty()){
		int now = q.front();
		q.pop();
		for(auto to:tree[now]){
			if(co[to.first]==0){
				if(to.second){
					co[to.first] = 3 - co[now];
				}else{
					co[to.first] = co[now];
				}
				q.push(to.first);
			}
		}
	}
	FOR(i,0,n){
		cout << co[i]-1 << endl;
	}
}


Measured memory_bytes: 8320
import math
n,k = input().split()
n = int(n)
k = int(k)
ans = 0

for i in range(1,n+1) :
	count = math.ceil(math.log(k/i, 2))
	if count <= 0: count = 0
	ans+= ((1/2)**count)*(1/n)

print (ans)


Measured memory_bytes: 3060
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// 998244353;// ;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<LL>>g, rev;
vector<edge>edges;
vector<LL>v;
map<LL, LL>ma;
set<LL>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans,a[510000], b[510000], dp[50000];
string str, ss;
bool f;
char c;
struct QuickFind {
	vector<int> gi; //親
	vector<vector<int>> vg; //併合した後削除する
	vector<vector<int>> tg; //併合した後削除しない
	int n;

	QuickFind(int size) : n(size) {
		gi.resize(n);
		vg.resize(n);
		tg.resize(n);
		for (int i = 0; i < n; i++) {
			gi[i] = i;
			vg[i].push_back(i);
			tg[i].push_back(i);
		}
	}
	bool same_group(int a, int b) {
		return gi[a] == gi[b];
	}
	void merge(int a, int b) {
		int ga = gi[a];
		int gb = gi[b];
		if (ga == gb) return;
		if (vg[ga].size() < vg[gb].size()) swap(ga, gb);
		for (int j : vg[gb]) gi[j] = ga;
		vg[ga].insert(vg[ga].end(), vg[gb].begin(), vg[gb].end());
		vg[gb].clear();
		tg[ga].insert(tg[ga].end(), tg[gb].begin(), tg[gb].end());
	}
};
QuickFind qf(200000);
int main() {
	cin >> n >> m >> k;
	rep(i, m) {
		LL x, y;
		cin >> x >> y;
		x--, y--;
		a[x]++, a[y]++;
		qf.merge(x, y);
	}
	rep(i, k) {
		LL x, y;
		cin >> x >> y;
		x--, y--;
		if (qf.same_group(x, y))a[x]++, a[y]++;
	}
	rep(i, n) {
		if (i)cout << " ";
		cout<<qf.vg[qf.gi[i]].size() - a[i]-1;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 26096
def main():
    import sys
    input = sys.stdin.readline #文字列をsplit()しない場合s=s[:-2]が必要

    n=int(input())
    D=[int(_) for _ in input().split()]
    D.sort()
    print(D[n//2]-D[n//2-1])

if __name__=='__main__':
    main()

Measured memory_bytes: 52764
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<String> listS = new ArrayList<String>();
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			listS.add(s);
			s = null;
		}
		List<String> listSsec = new ArrayList<String>(new LinkedHashSet<>(listS));
		System.out.println(listSsec.size());
	}
}

Measured memory_bytes: 78636
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <bitset>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000'000'007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    rep(i,ty-sy) cout << "U";
    rep(i,tx-sx) cout << "R";
    rep(i,ty-sy) cout << "D";
    rep(i,tx-sx) cout << "L";
    cout << "L";
    rep(i,ty-sy+1) cout << "U";
    rep(i,tx-sx+1) cout << "R";
    cout << "D";
    cout << "R";
    rep(i,ty-sy+1) cout << "D";
    rep(i,tx-sx+1) cout << "L";
    cout << "U" << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

from sys import stdin
from collections import defaultdict


def main():
    N = int(stdin.readline())
    A = list(map(int, stdin.readline().split()))

    B = defaultdict(lambda: 0)
    for a in A:
        B[a] += 1

    for n in range(1, N + 1):
        print(B[n])


if __name__ == "__main__":
    main()


Measured memory_bytes: 37340
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

const int N=200005;

int n,t,ans;
int f[N],a[N];
map<int,int> cnt;

int main(){
	int i,j,k;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]),cnt[a[i]]++;
	sort(a+1,a+1+n);
	for (i=n;i>=1;i--){
		if (!cnt[a[i]]) continue;
		cnt[a[i]]--;
		for (j=1;1ll*j*2<=1ll*(a[i]+a[i]);j=j*2);
		if (cnt[j-a[i]]){
			ans++;
			cnt[j-a[i]]--;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 19712
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math


INF = 10 ** 20

def main():
    n = getN()
    if n == 1:
        print(1)
        print(1)
        return
    if n == 2:
        print(2)
        print(0)
        print("11")
        return

    print(n-1)
    print("11")
    for i in range(1, n-1):
        print("1" + "0" * i + "1")

    return
if __name__ == "__main__":
    main()


Measured memory_bytes: 6048
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <vector>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>


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

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll nmax=50;

bool visited[nmax+1][nmax+1];
ll field[nmax+1][nmax+1];

ll h,w;

ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,1,-1};


int main() {
    string s,str;
    ll ans;
    cin>>s;
    ans=inf;
    ll len=s.length();
    for(ll i=0;i+3<=len;i++){
//        cout<<s<<" "<<stoll(s.substr(i,3))<<endl;

        ans=min(ans,abs(753-stoll(s.substr(i,3))));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from __future__ import division, print_function

oo = 10**9 + 5
N = 10**5 + 5

def main():
    n, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    
    dp = [oo] * n
    dp[0] = 0
    for i in range(n):
        for j in range(i + 1, i + k + 1):
            if j < n:
                dp[j] = min(dp[j], dp[i] + fabs(a[i] - a[j]))
                
    print(int(dp[n - 1]))


# PyPy 2 Fast IO Template. Made by Pajenegod & C1729
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Importing Modules
import math
import collections

from collections import Counter
from math import fabs

if __name__ == "__main__":
    main()

Measured memory_bytes: 43116
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[6];
		a[0]=100;
		a[1]=101;
		a[2]=102;
		a[3]=103;
		a[4]=104;
		a[5]=105;
		int b[]=new int[n+1];
		b[0]=1;
		for(int j=1;j<=n;j++)
		{one:for(int i=0;i<6;i++)
		{if(j>=a[i])
		    {b[j]=b[j-a[i]];
		    if(b[j]==1)
		    {break one;}
		}}}
		if(b[n]==0)
		System.out.println("0");
		else
		System.out.println("1");}
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <string.h>
int main(){
    int N = 0;
    scanf("%d", &N);
    double x;
    char s[3]; 
    double sum = 0;
    for(int i = 0; i < N; i++){
        scanf("%lf %s", &x, s);
        if(s[0] == 'J'){
            sum += x;
            }
        else{
            sum += (x * 380000);
            }
    }
    printf("%lf\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }

int main() {
	
	int x, n; cin >> x >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int ans;
	int val = 10000000;
	for (int i = -1; i <= 300; i++) {
		int tmp;
		bool skip = false;
		for (int j = 0; j < n; j++) {
			if (i == p[j]) {
				skip = true;
			}
		}
		if (skip) continue;
		tmp = abs(i - x);
		if (chmin(val, tmp)) {
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
using namespace std;
//scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

//printf("Yes\n");
int main() {
  int a;
  int b;
  char x;
  int c;
  while(1){
  scanf("%d %c %d",&a,&x,&b);
   if(x=='+'){
     c=a+b;
     printf("%d\n",c);
   }
   if(x=='-'){
     c=a-b;
     printf("%d\n",c);
   }
   if(x=='*'){
     c=a*b;
     printf("%d\n",c);
   }
   if(x=='/'){
     c=a/b;
     printf("%d\n",c);
   }
   if(x=='?') break;
  }

}


Measured memory_bytes: 2708