akhauriyash/Code-Regression huggingface dataset:
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    ans="AC"
    if s[1]!='A'
        ans="WA"
    else
        index=0
        for i in 3:length(s)-1
            if s[i]=='C'
                if index==0
                    index=i
                else
                    ans="WA"
                end
            end
        end
        if index==0
            ans="WA"
        end
        for i in 2:length(s)
            if i!=index && 'A'<=s[i]<='Z'
                ans="WA"
            end
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 163820
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        if (n%(2*d+1)==0) {
            System.out.println(n/(2*d+1));
        } else {
            System.out.println(n/(2*d+1)+1);
        }
    }
}

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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;

int main() {
	int n, k; rd(n, k);
	vector<int> a(n);
	for (int& i : a) rd(i);

	vector<int> memo(n);
	
	for (int i = n-2; i >= 0; i--) {
		memo[i] = INF;
		for (int j = 1; j <= k; j++) if (i+j < n)
			memo[i] = min(memo[i], memo[i+j] + abs(a[i] - a[i+j]));
	}

	printf("%d\n", memo[0]);


}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; 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  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
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; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n, k;
double ans;

int main() {
	cin >> n >> k;
	
	inc1(i, n) {
		int v = i, c = 1;
		while(v < k) { v *= 2; c *= 2; }
		ans += 1.0 / c / n;
	}
	
	printf("%.12f\n", ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int d;
    cin >> d;
    const int n = 26;
    vector<int> c(n,0);
    rep(i,n)cin >> c[i];
    vector<vector<int>> s(365,vector<int>(n,0));
    rep(i,d)rep(j,n)cin >> s[i][j];
    vector<int> recent(n,0);

    rep(i,d){
        priority_queue<tuple<int,int,int>> que;
        rep(j,n){
            que.push(make_tuple(s[i][j],recent[i] - i,j));
        }
        int a,b,c;
        tie(a,b,c) = que.top();
        cout << c+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3684
#include <stdio.h>

main(){

int a,b,c,x,y,z;

scanf("%d%d%d",&a,&b,&c);

if(a> b){

x=a;

a=b;

b=x;

}

if(b > c){

y=b;

b=c;

c=y;

}

if(a > b){

z=a;

a=b;

b=z;

}

printf("%d %d %d\n",a,b,c);

return 0;

}

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

typedef long long LL;
typedef unsigned long long ULL;

const int PI = 3.141592653589793;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;

void solve() {
        int n; cin >> n;
        int P[N];
        memset(P, 0, sizeof P);
        for (int i = 0; i + 1 < n; i++) {
                int x; cin >> x;
                P[x]++;
        }
        for (int i = 1; i <= n; i++) {
                cout << P[i] << "\n";
        }
}

int main(){

        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);

        solve();
        return 0;
}



Measured memory_bytes: 4476
#include <iostream>
using namespace std;
int main() {
    int n = 0;  //あられの個数
    int ans = 0;
    char c; //あられの種類判定用の文字
    bool pflag = false; //桃色
    bool wflag = false; //白色
    bool gflag = false; //緑色
    bool yflag = false; //黄色

    scanf("%d",&n);

    for (int i = 0; i <2*n; ++i) {
        scanf("%c",&c);
        if (c =='P'){
            pflag = true;
        }
        if (c =='W'){
            wflag = true;
        }
        if (c =='G'){
            gflag = true;
        }
        if (c =='Y'){
            yflag = true;
        }
    }

    if (pflag == true)ans++;
    if (wflag == true)ans++;
    if (gflag == true)ans++;
    if (yflag == true)ans++;

    if (ans == 3) puts("Three");
    if (ans == 4) puts("Four");
    return 0;
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val s = readLine()!!
    val m = mutableMapOf<Char, Int>(Pair('E', 0), Pair('W', 0), Pair('S', 0), Pair('N', 0))
    s.forEach { var d = m[it] ?: 0; m[it] = ++d }
    val we = (m['E']!! > 0 && m['W']!! > 0) || (m['E']!! == 0 && m['W']!! == 0)
    val ns = (m['N']!! > 0 && m['S']!! > 0) || (m['N']!! == 0 && m['S']!! == 0)
    println(if (we && ns) "Yes" else "No")
}

Measured memory_bytes: 33920
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << max(A * B, C * D) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 1e6 + 7;

int cnt[N];
vector<int> divs[N];

void init() {
	for (int i = 2; i < N; i++) {
		if (divs[i].empty()) {
			for (int j = i; j < N; j += i) {
				divs[j].push_back(i);
			}
		}
	}
}

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

	init();
	int g = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		g = gcd(g, x);
		for (auto dv : divs[x]) {
			cnt[dv]++;
		}
	}
	int any = 0;
	for (int i = 0; i < N; i++) {
		any |= (cnt[i] > 1);
	}
	if (!any) {
		cout << "pairwise coprime\n";
	} else if (g == 1) {
		cout << "setwise coprime\n";
	} else {
		cout << "not coprime\n";
	}
}

Measured memory_bytes: 62348
from collections import deque
def BFS(N,M,List):
    Graph = [[] for T in range(N+1)]
    for NodeM in range(0,M):
        Graph[List[NodeM][0]].append(List[NodeM][1])
        Graph[List[NodeM][1]].append(List[NodeM][0])

    Distance = [-1]*(N+1)
    Distance[0] = 0
    Distance[1] = 0
    From = [0]*(N+1)

    Deque = deque()
    Deque.append(1)
    while Deque:
        V = Deque.popleft()
        for NodeV in Graph[V]:
            if Distance[NodeV]==-1:
                Distance[NodeV] = Distance[V]+1
                Deque.append(NodeV)
                From[NodeV] = V

    return Distance[1:],From[1:]
  
N,M = (int(X) for X in input().split())
List = [[] for T in range(0,M)]
for T in range(0,M):
    List[T] = [int(X) for X in input().split()]
Distance,From = BFS(N,M,List)
if Distance[-1]==2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

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

int main(){
  ll n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  for(int i=1; i<n;  ++i){
    if(a[i] >= a[i-1]) continue;
    ll step = abs(a[i] - a[i-1]);
    ans += step;
    a[i] = a[i-1];
    // cout << ans << " " << step << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3956
def readinput():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    return n,m,a

def main(n,m,a):
    days=sum(a)
    if days>n:
        return -1
    else:
        return n-days

if __name__=='__main__':
    n,m,a=readinput()
    ans=main(n,m,a)
    print(ans)


Measured memory_bytes: 9984
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		String S[]=new String[3];
		int s[]=new int[3];
		for(int i=0;i<3;i++){S[i]=next();s[i]=S[i].length();}
		int now=0;
		while(true){
			if(s[now]==0){
				switch(now){
				case 0:System.out.println("A");break;
				case 1:System.out.println("B");break;
				case 2:System.out.println("C");break;
				}
				System.exit(0);
			}
			s[now]--;
			char a=S[now].charAt(0);
			S[now]=S[now].substring(1,S[now].length());
			switch(a){
			case 'a':now=0;break;
			case 'b':now=1;break;
			case 'c':now=2;break;
			}
		}
	}
	static boolean isOK(int index,String key,String[]a){
		if (a[index].compareTo(key)>=0) return true;
	    else return false;
	}
	static int binary_search(String key,String[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}



Measured memory_bytes: 32620
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) begin(x)+(a), begin(x)+(n)
#define ADD(a, b) ((((a)%MOD+MOD)%MOD+((b)%MOD+MOD)%MOD)%MOD)
#define SUB(a, b) ((((a)%MOD+MOD)%MOD-((b)%MOD+MOD)%MOD+MOD)%MOD)
#define MUL(a, b) (((((a)%MOD+MOD)%MOD)*(((b)%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }


int N, K;
int A[100010];


int extGCD(int a, int b, int &x, int &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    int d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}


namespace Factorial {
    VI fact, finv;
    void init(int n){
        fact.resize(n+1);
        finv.resize(n+1);
        fact[0] = 1;
        repe(i, 1, n) fact[i] = MUL(i, fact[i-1]);
        extGCD(fact[n], MOD, finv[n], finv[0]);
        finv[0] = 1;
        repr(i, n, 1) finv[i] = MUL(i+1, finv[i+1]);
    }
    int comb(int n, int k){
        if(n < k) return 0;
        if(n < 0 or k < 0) return 0;
        return MUL(fact[n], MUL(finv[k], finv[n-k]));
    }
    int perm(int n, int k){
        if(n < k) return 0;
        if(n < 0 or k < 0) return 0;
        return MUL(fact[n], finv[n-k]);
    }
}


signed main(){
    cin >> N >> K;
    rep(i, 0, N) cin >> A[i];

    Factorial::init(N);
    sort(RNG(A, 0, N));

    int m = 0, M = 0;
    repe(i, 0, N-K) CHADD(m, MUL(A[i], Factorial::comb(N-(i+1), K-1)));

    sort(RNG(A, 0, N), greater<int>());
    repe(i, 0, N-K) CHADD(M, MUL(A[i], Factorial::comb(N-(i+1), K-1)));

    cout << SUB(M, m) << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	string a,b;
	string ANS="No";
	double c;
	cin >> a >> b;
	c=stoi(a+b);
	for(int i=0;i<=sqrt(c);i++){
		if(c==i*i)ANS="Yes";
	}
	cout << ANS << endl;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int> V(N);
  for (int i = 0; i < N; i++) {
    V.at(i) = S.at(i) - '0';
  }
  long long int ans = 0;
  for (int bit = 0; bit < (1 << (N - 1)); bit++) {
    long long int A = 0;
    long long int K = V.at(0);
    for (int i = 0; i < N - 1; i++) {
      if (bit & (1 << i)) {
        K = K * 10 + V.at(i + 1);
      }
      else {
        A += K;
        K = V.at(i + 1);
      }
    }
    A += K;
    ans += A;
  }
  cout << ans << endl;
}

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

divisor_num = [0] * 201

def get_divisor_num(a):
  count = 0
  for i in range(1,(a+1)//2):
    if a%i == 0:
      count+=1
  return count+1
    
for i in range(1,200):
  divisor_num[i] = get_divisor_num(i)
  
ans = 0
for i in range(n+1):
  if divisor_num[i] == 8 and i % 2 == 1:
    ans += 1
    
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val Array(_, k) = sc.nextLine.split(" ").map(_.toInt)
    val letters = sc.next
    println(letters.zipWithIndex.map {
      item =>
        if (item._2 == k - 1) item._1.toLower
        else item._1
    }.mkString)
  }
}


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

state = [[-1] * N for i in range(N)]
for index in range(N):
    Ai = int(input())
    for naka in range(Ai):
        x, y = map(int, input().split()) 
        state[index][x - 1] = y
        # state[index][naka] = [x, y]


# print(state)


maxx = 0
for index in range(1, 2 ** N):
    # print(index)
    person = index
    tempM = 0
    Ai = 0
    ok = 1
    while person > 0:
        if ok == 0:
            break
        if person % 2 == 1:
            tempM += 1
            for i in range(N):
                if state[Ai][i] != -1:
                    # print(str(Ai) + " " + str(i))
                    # print(str(state[Ai][i]) + " " + str((index // (2 ** i)) % 2))
                    # print()
                    if state[Ai][i] != (index // (2 ** i)) % 2:
                        ok = 0
                        break
                
        
        person //= 2
        Ai += 1
    
    if ok == 1:
        maxx = max(maxx, tempM)

print(maxx)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n;
string s; 
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n>>s;
	int p1=0,p2=0;
	fo(i,0,n) if(s[i]=='W')p1++;
	fo(i,n-p1,n) if(s[i]=='W')p2++;
	cout<<p1-p2<<endl; 
	return 0;
}


Measured memory_bytes: 3680
#!/usr/bin/env python
import bisect
from collections import defaultdict

def main():
    N, M = map(int, input().split())
    switches = defaultdict(list)
    for i in range(M):
        ks = list(map(int, input().split()))
        for s in ks[1:]:
            switches[s].append(i)
    p_list = list(map(int, input().split()))

    cnt = 0
    for i in range(2 ** N):
        on_nums = defaultdict(int)
        bits = bin(i)[2::][::-1]
        for k, b in enumerate(bits):
            if b == '1':
                for s in switches[k+1]:
                    on_nums[s] += 1

        if all([on_nums[s] % 2 == p_list[s] for s in range(M)]):
            cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()


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

using namespace std;
mt19937_64 rng(58);

int rep[200001];
int rnk[200001];

int ds_find(int x) {
    if (rep[x] != x) {
        rep[x] = ds_find(rep[x]);
    }
    return rep[x];
}

void ds_union(int x, int y) {
    int xp = ds_find(x);
    int yp = ds_find(y);
    if (xp == yp) return;
    if (rnk[xp] < rnk[yp]) {
        rep[xp] = yp;
        rnk[yp] += rnk[xp];
    } else {
        rep[yp] = xp;
        rnk[xp] += rnk[yp];
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    for (int i=0; i<n; i++) rep[i] = i, rnk[i] = 1;
    for (int j=0; j<m; j++) {
        int a, b;
        cin >> a >> b;
        ds_union(a-1, b-1);
    }
    int ans = 1;
    map<int, int> count;
    for (int i=0; i<n; i++) {
        ans = max(ans, rnk[ds_find(i)]);
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

//1-indexであることに注意
template <typename T>
struct BIT {
    int n;
    vector<T> data;
    int n_msb;

    BIT(int n) : n(n), data(n + 1, 0) {
        n_msb = 1;
        while (n_msb <= n) n_msb <<= 1;
        n_msb >>= 1;
    }

    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, T x) {
        while (i <= n) {
            data[i] += x;
            i += i & -i;
        }
    }

    // sum(i) >= val となる最小のiを返す
    // ただし、sum(i)は広義単調増加すると仮定
    int lower_bound(T val) {
        if (val <= 0) return 0;

        int res = 0;
        for (int k = n_msb; k > 0; k >>= 1) {
            if (res + k <= n && data[res + k] < val) {
                val -= data[res + k];
                res += k;
            }
        }
        return res + 1;
    }
};

vector<int> calc(int n, int K, const vector<int>& p) {
    vector<int> res(n - K + 1, 0);

    BIT<int> b(n);
    for (int i = 0; i < K; i++) {
        b.add(p[i], 1);
    }

    res[0] = K;
    for (int i = 0; i < K; i++) {
        if (b.sum(p[i]) != i + 1) {
            res[0] = i;
            break;
        }
    }

    for (int i = 1; i <= n - K; i++) {
        b.add(p[i - 1], -1);
        b.add(p[i + K - 1], 1);
        int idx = b.sum(p[i + K - 1]) - 1 + i;
        if (res[i - 1] == i - 1) {
            res[i] = i + K;
            for (int j = i; j < i + K; j++) {
                if (b.sum(p[j]) != j - i + 1) {
                    res[i] = j;
                    break;
                }
            }
        } else {
            if (idx == i + K - 1 && res[i - 1] == idx) {
                res[i] = i + K;
                continue;
            }

            res[i] = min(res[i - 1], idx);
        }
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]++;
    }

    vector<int> L = calc(n, K, p);
    reverse(p.begin(), p.end());
    for (int& x : p) {
        x = n + 1 - x;
    }

    vector<int> R = calc(n, K, p);
    for (int& x : R) {
        //cerr << x << endl;
        x = n - 1 - x;
    }
    reverse(R.begin(), R.end());

    using P = pair<int, int>;
    set<P> s;
    bool f = false;
    for (int i = 0; i <= n - K; i++) {
        //cerr << L[i] << " " << R[i] << endl;
        if (L[i] > R[i]) {
            f = true;
            continue;
        }
        s.emplace(L[i], R[i]);
    }
    int ans = s.size() + f;
    cout << ans << "\n";
    return 0;
}

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

const int maxn = 1e5+5;
int n, k;
int R, S, P;
string t;
char play[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> k;
    cin >> R >> S >> P;
    cin >> t;
    ll ans = 0;
    for (int i = 0; i < k; i++) {
        string r;
        for (int j = i; j < n; j += k) {
            r += t[j];
        }
        bool good = true;
        for (int j = 0; j < r.size(); j++) {
            if (!good) {
                good = true;
            }
            else {
                if (r[j] == 'r') ans += P;
                else if (r[j] == 's') ans += R;
                else if (r[j] == 'p') ans += S;
                if (j < r.size()-1 && r[j] == r[j+1]) {
                    good = false;
                }
            }
        }
        //cout << ans << endl;
    }
    cout << ans << '\n';
}



Measured memory_bytes: 640
N = int(input())
import math
#ユークリッド互除法の関数の定義
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
x = list(map(int,input().split()))

if N==1:
    print(x[0])
else:
    element = gcd(x[0], x[1])
    if N==2:print(element)
    else:
        for i in range(2,N):
            element=gcd(element,x[i])
        print(element)

# print(gcd_list(numbers))


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

public class Main{

    final static int maxn = (int) 1e5 + 7;

    static int[] a = new int[maxn];

    static int[] tree = new int[maxn << 2];

    static int n;

    static void build(int l, int r, int node) {
        if(l == r) {
            tree[node] = a[l];
            return;
        }
        int mid = (l + r) >> 1;
        build(l, mid, node<<1);
        build(mid + 1, r, node << 1 | 1);
        tree[node] = Math.max(tree[node<<1], tree[node<<1|1]);
    }

    static int query(int l, int r, int node, int ql, int qr) {
        if(ql <= l && qr >= r) return tree[node];
        int mid = (l + r) >> 1;
        int res = 0;
        if(ql <= mid) res = Math.max(res, query(l, mid, node<<1, ql, qr));
        if(qr > mid)  res = Math.max(res, query(mid+1, r, node<<1|1, ql, qr));
        return res;
    }

    static long get_left(int k, int l, int r) {
        long ans = -1;
        while(l <= r){
            int mid = (l + r) >> 1;
            if(query(1, n, 1, mid, r) > a[k]) {
                ans = mid;
                l = mid + 1;
            }
            else r = mid - 1;
        }
        return ans;
    }

    static long get_right(int k, int l, int r) {
        long ans = -1;
        while(l <= r){
            int mid = (l + r) >> 1;
            if(query(1, n, 1, l, mid) > a[k]) {
                ans = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        return ans;
    }

    public static void main(String[] args){
        Scanner cin = new Scanner(System.in);
        while(cin.hasNext()) {
            n = cin.nextInt();
            for(int i=1; i<=n; i++) a[i] = cin.nextInt();
            build(1, n, 1);
            long ans = 0;
            for(int i=1; i<=n; i++) {
                long pl1 = get_left(i, 1, i-1);
                long pl2 = pl1 == -1 ? -1 : get_left(i, 1, (int)pl1 - 1);
                long pr1 = get_right(i, i+1, n);
                long pr2 = pr1 == -1 ? -1 : get_right(i, (int)pr1 + 1, n);
                if(pl1 != -1 && pl2 != -1 && pr1 != -1 && pr2 != -1) ans += a[i] * ((pl1 - pl2) * (pr1 - i) + (i - pl1) * (pr2 - pr1));
                if(pl1 != -1 && pl2 != -1 && pr1 != -1 && pr2 == -1) ans += a[i] * ((pl1 - pl2) * (pr1 - i) + (i - pl1) * (n - pr1 + 1));
                if(pl1 != -1 && pl2 != -1 && pr1 == -1 && pr2 == -1) ans += a[i] * ((pl1 - pl2) * (n - i + 1));

                if(pl1 != -1 && pl2 == -1 && pr1 != -1 && pr2 != -1)  ans += a[i] * (pl1 * (pr1 - i) + (i - pl1) * (pr2 - pr1));
                if(pl1 != -1 && pl2 == -1 && pr1 != -1 && pr2 == -1) ans += a[i] * (pl1 * (pr1 - i) + (i - pl1) * (n - pr1 + 1));
                if(pl1 != -1 && pl2 == -1 && pr1 == -1 && pr2 == -1) ans += a[i] * (pl1 * (n - i + 1));

                if(pl1 == -1 && pl2 == -1 && pr1 != -1 && pr2 != -1) ans += a[i] * (i * (pr2 - pr1));
                if(pl1 == -1 && pl2 == -1 && pr1 != -1 && pr2 == -1) ans += a[i] * (i * (n - pr1 + 1));
            }
            System.out.println(ans);
        }
    }

}



















Measured memory_bytes: 61984
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef pair<int, int> pii;
typedef pair<string, int> P;
typedef long long ll;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[ry]>rank[rx]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
vector<ll> fac(1e6),inv(1e6),finv(1e6);
void initcom(){
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(int i=2;i<1e6;++i){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll com(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
int compress(vector<int> &x,int w){
    vector<int> sx;
    for(int i=0;i<(int)x.size();++i){
        for(int d=-2;d<=2;++d){
            int t=x[i]+d;
            if(t>=0&&t<w) sx.push_back(t);
        }
    }
    sort(sx.begin(),sx.end());
    sx.erase(unique(sx.begin(),sx.end()),sx.end());
    for(int i=0;i<(int)x.size();++i){
        x[i]=lower_bound(x.begin(),x.end(),x[i])-x.begin();
    }
    return (int)sx.size();
}
int main(){
    int n;cin>>n;
    vector<ll> a(3*n);
    for(int i=0;i<3*n;++i) cin>>a[i];
    priority_queue<ll,vector<ll>,greater<ll> > que1;
    priority_queue<ll> que2;
    ll sum1=0,sum2=0;
    for(int i=0;i<n;++i){
        sum1+=a[i];
        que1.push(a[i]);
    }
    for(int i=2*n;i<3*n;++i){
        sum2+=a[i];
        que2.push(a[i]);
    }
    vector<ll> t1(n+1),t2(n+1);
    t1[0]=sum1;t2[n]=sum2;
    for(int i=n;i<2*n;++i){
        que1.push(a[i]);
        sum1+=a[i];
        ll p=que1.top();que1.pop();
        sum1-=p;
        t1[i-n+1]=sum1;
    }
    for(int i=2*n-1;i>=n;--i){
        que2.push(a[i]);
        sum2+=a[i];
        ll p=que2.top();que2.pop();
        sum2-=p;
        t2[i-n]=sum2;
    }
    ll ans=-INF;
    for(int i=0;i<=n;++i){
        ans=max(ans,t1[i]-t2[i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main() {
    int n;cin>>n;
    bool ok = 1;
    int ct=0, cx=0, cy=0;
    while(n--) {
        int t, x, y;
        cin>>t>>x>>y;
        int d = abs(x-cx) + abs(y-cy);
        int dt = t-ct;
        if(d > (t-ct) || ((t-ct)-d)%2==1) {
            ok = 0;
        }
        ct = t;
        cx = x;
        cy = y;
    }
    if(ok) cout<<"Yes\n";
    else cout<<"No\n";
}

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

long long int nC2(long long int n) {
  return n * (n-1) / 2;
}

int main() {
  int n;cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;++i) {
    cin>>s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s.begin(), s.end());
  long long int ans = 0;
  int tmp = 1;
  for(int i=1;i<n;++i) {
    if(s[i]==s[i-1]) ++tmp;
    else {
      ans += nC2(tmp);
      tmp=1;
    }
  }
  ans += nC2(tmp);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=-1000000000;
typedef long long ll;
int N,M,C,W;
ll s[100005],t[100005],c[100005];
string T;
ll F[31][100005]={},ans=0,as=0;
int main(){
	cin>>N>>C;
	for(int i=0;i<N;++i){
		cin>>s[i]>>t[i]>>c[i];
		F[c[i]][s[i]]++;
		F[c[i]][t[i]+1]--;
	}
	for(int i=0;i<100005;++i){
		as=0;
		for(int j=1;j<=C;++j){
			F[j][i]+=F[j][i-1];
			if(F[j][i])++as;
		}
		ans=max(ans,as);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 25984
N = gets.to_i
a = gets.split.map(&:to_i)
pl = []
mi = []
a.each do |v|
  if v > 0
    pl << v
  else
    mi << v
  end
end
opr = []
if pl.length > 0 && mi.length > 0
  mi.sort!
  if mi.length > 1
    (mi.length-1).times do |i|
      opr << [pl[0],mi[i+1]]
      pl[0] -= mi[i+1]
    end
  end
  if pl.length > 1
    (pl.length-1).times do |i|
      opr << [mi[0],pl[i+1]]
      mi[0] -= pl[i+1]
    end
  end
  opr << [pl[0],mi[0]]
  ans = pl[0]-mi[0]
elsif pl.length == 0
  mi.sort!
  (mi.length-1).times do |i|
    opr << [mi[-1],mi[i]]
    mi[-1] -= mi[i]
  end
  ans = mi[-1]
elsif pl.length >= 3
  pl.sort!
  (pl.length-2).times do |i|
    opr << [pl[0],pl[i+1]]
    pl[0] -= pl[i+1]
  end
  opr << [pl[-1],pl[0]]
  ans = pl[-1] - pl[0]
else
  pl.sort!
  opr << [pl[1],pl[0]]
  ans = pl[1]-pl[0]
end
puts ans
opr.each do |x,y|
  puts "#{x} #{y}"
end

Measured memory_bytes: 20956
#include<stdio.h>
int main()
{
	int x, y;
	
	while (1)
	{
		scanf("%d", &x);
		scanf("%d", &y);
		if (x == 0 && y == 0)break;
	if (x <= y)
		printf("%d %d\n", x, y);
	if (x>y)
		printf("%d %d\n", y, x);
	}
}


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


void solve(){

	string s ;
	cin>>s ;

	int n =s.length() ;

	if(s[0]!=s[n-1]){
		if(n%2==1)
			cout<<"First" ;
		else
			cout<<"Second" ;
	}
	else{

		if(n%2==0){
			cout<<"First" ;
		}
		else{
			cout<<"Second" ;
		}


	}


	


}


int main(){

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin) ;
		freopen("output.txt","w",stdout) ;
    #endif 

		int y ;

		y=1 ;
		//cin>>y ;

		while(y--){
 
			solve() ;

		}

}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
int main(){
	ll x=readll(),y=readll();
	int num=0;
	while(x<=y) x*=2,num++;
	printf("%d\n",num);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<vector>

using namespace std;

int main(){
    int N, K, X, Y;
    cin >> N;
    cin >> K;
    cin >> X;
    cin >> Y;
  
  	int sum = 0;
    if (N <= K){
      sum = X*N;
    }
  	else{
      sum = X*K+Y*(N-K);
    }
  
    cout << sum << endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Scanner
{
    private readonly char Separator = ' ';
    private int Index = 0;
    private string[] Line = new string[0];
    public string Next()
    {
        if (Index >= Line.Length)
        {
            Line = Console.ReadLine().Split(Separator);
            Index = 0;
        }
        var ret = Line[Index];
        Index++;
        return ret;
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public string[] StringArray()
    {
        Line = Console.ReadLine().Split(Separator);
        Index = Line.Length;
        return Line;
    }

    public int[] IntArray()
    {
        var l = StringArray();
        var res = new int[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = int.Parse(l[i]);
        }
        return res;
    }

    public long[] LongArray()
    {
        var l = StringArray();
        var res = new long[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = long.Parse(l[i]);
        }
        return res;
    }
}

class Program
{
    private int N;
    private bool[][] F;
    private int[][] P;

    private void Scan()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        F = new bool[N][];
        for (int i = 0; i < N; i++)
        {
            F[i] = sc.StringArray().Select(s => s == "1").ToArray();
        }
        P = new int[N][];
        for (int i = 0; i < N; i++)
        {
            P[i] = sc.IntArray();
        }
    }

    public void Solve()
    {
        Scan();
        int l = 1 << 10;
        int ans = int.MinValue;
        for (int i = 1; i < l; i++)
        {
            int[] cnt = new int[N];
            bool[] array = new bool[10];
            int cp = i;
            for (int j = 0; j < 10; j++)
            {
                array[j] = (cp % 2) == 1;
                cp /= 2;
            }
            for (int j = 0; j < N; j++)
            {
                for (int k = 0; k < 10; k++)
                {
                    if(F[j][k]&&array[k])
                    {
                        cnt[j]++;
                    }
                }
            }
            var c = 0;
            for (int j = 0; j < N; j++)
            {
                c += P[j][cnt[j]];
            }
            ans = Math.Max(ans, c);
        }
        Console.WriteLine(ans);
    }



    static void Main(string[] args)
    {
        new Program().Solve();
    }
}

Measured memory_bytes: 13396
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map>
#include<stdio.h>
#include<queue>
#include<tuple>

#define ALL(a)  (a).begin(),(a).end()
const long long MOD = 1e9+7;

//いろんなstlの使い方　https://qiita.com/tukejonny/items/f4013547df761a0b3523
//http://y-mazun.hatenablog.com/entry/20111202/1322840281



using namespace std;


long long gcd(long long a, long long b) {
    if (a > b) {
        return gcd(b, a);
    }
    return a == 0 ? b : gcd(b % a, a);
}

int lcm(int m, int n) {
    // 引数に０がある場合は０を返す
    if ((0 == m) || (0 == n))
        return 0;

    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm


int moji(char in) {
    int ans = (int) in - (int) 'a';
    if ((ans < 0) || (ans > 25)) {
        ans = 26;
    }
    return ans;
}


int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int *) a - *(int *) b;
}



template<class T>
void chmin(T &a, T b) {
    if (a > b) {
        a = b;
    }
}

//formerは前方のindex(自分自身を含んで良い)
template<class T>
int former(const vector<T> &v, T x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}

//latterは後方のindex(自分自身を含んで良い)
template<class T>
int latter(const vector<T> &v, T x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}



//indexを用いてvectorから要素削除
template<typename T>
void remove(std::vector<T> &vector, unsigned int index) {
    vector.erase(vector.begin() + index);
}





int main() {
    int N;
    string S;
    cin>>N>>S;
    int migi=0;
    int hidari=0;
    for(int i=0;i<N;i++) {
        if (S[i] == '(') {
            hidari++;
        } else {
            if (hidari > 0) {
                hidari--;
            } else {
                migi++;
            }
        }
    }
    for (int i=0;i<migi;i++){
        S="("+S;
    }
    for(int i=0;i<hidari;i++){
        S=S+")";
    }
    cout<<S<<endl;




}














Measured memory_bytes: 256
from heapq import heappush, heappop
import sys

if __name__ == '__main__':
	pq = []
	while True:
		cmd = sys.stdin.readline()
		if cmd.strip() == 'end': break
		elif cmd.startswith('insert'):
			_, val = cmd.split()
			heappush(pq, -int(val))
		else:
			print -(heappop(pq))

Measured memory_bytes: 36056
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  int M;
  int X;
  
  cin >> N >> M >> X;
  
  vector<int> A(M);
  
  for(int i = 0;i < M;++i){
    cin >> A[i];
  }
  
  int num = 0;
  int num2 = 0;
  int num3;
  
  for(int i = 0;i < M;++i){
    if(A[i] < X){
      num++;
    }
    else if(A[i] > X){
      num2++;
    }
    
   num3 = min(num,num2);
  }
  
  cout << num3 << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long L;
using namespace std;
  
#define N 100005
#define U [N]={}
map<L,L> path[N];
L par U,dep U,siz U,hev U,cst U,add U,pos U,hl_par U,bit U,
k,n,q,a,b,c,i,p,r;
char s[5];
void dfs(L a){
    siz[a]=1;
    for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){
        L d=I->first;
        if(d==par[a]) continue;
        par[d]=a;
        dep[d]=dep[a]+1;
        cst[d]=I->second;
        dfs(d);
        siz[a]+=siz[d];
        if(!hev[a] || siz[hev[a]]<siz[d])
            hev[a]=d;
    }
}
    
L edgecost(L a){
    L ret=add[a]+add[par[a]]+cst[a];
    return ret%k ? ret : 0;
}
    
L sum(L i){
    L ret=0;
    while(i){
        ret+=bit[i];
        i-=i&-i;
    }
    return ret;
}
void S(L i, L x){
    x=edgecost(x)-sum(i+1)+sum(i);
    i++;
    while(i<N){
        bit[i]+=x;
        i+=i&-i;
    }
}
  
main(){
    for(cin>>n>>k;i<n-1;i++)
        cin>>a>>b>>c,
        path[a][b]=path[b][a]=c;
    dfs(0);
    
    for(c=i=0;i<n;i++)
        if(!i|hev[par[i]]-i)
        for(a=i;!c|a;a=hev[a])
            pos[a]=c++,
            hl_par[a]=i,
            S(pos[a],hev[a]);
    
    for(cin>>a;cin>>s>>a>>b;){
        if(*s&2){
            for(c=0;p=hl_par[a],r=hl_par[b],p-r;a=par[p])
                dep[p]<dep[r]?swap(p,r),swap(a,b),0:0,
                c+=sum(pos[a])-sum(pos[p])+edgecost(p);
            cout<<c+abs(sum(pos[a])-sum(pos[b]))<<endl;
        }else{
            add[a]+=b;
            S(pos[a],hev[a]);
            if(a)S(pos[a]-1,a);
        }
    }
}

Measured memory_bytes: 32008
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
#include <iomanip>
using namespace std;

vector<vector<int>> li(1111);
int twice = 0; //2回出てきたやつ
int in_heiro[1111]; //閉路に含まれれば１
int nextnode[1111]; //閉路上で次にくる点
int used[1111];
vector<int> heiro_node;

void dfs(int now) {
	if (used[now]) {
		twice = now;
	}
	else {
		used[now]++;
		for (auto &e : li[now]) {
			dfs(e);
			if (twice > 0) {
				in_heiro[now]=1;
				nextnode[now] = e;
				if (twice == now)
					twice = -1;
				break;
			}
			else if (twice < 0)
				break;
		}
		used[now]--;
	}
}

int main() {
	int n, m, a, b;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		in_heiro[i] = 0;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		li[a].push_back(b);
	}
	for (int i = 1; i <= n && twice==0; i++)
		dfs(i);
	while (1) {
		int p = 0, q = 0; //閉路をpからqへショートカットできる
		for (int i = 1; i <= n; i++) {
			if (in_heiro[i] == 1) {
				for (auto &e : li[i]) {
					if (in_heiro[e] == 1 && nextnode[i] != e) {
						p = i;
						q = e;
						break;
					}
				}
				if (p != 0)
					break;
			}
		}
		if (p == 0)
			break;
		else {
			//閉路上でpとqの間にある点を除外
			int now = nextnode[p];
			while (now != q) {
				in_heiro[now] = 0;
				now = nextnode[now];
			}
			nextnode[p] = q;
		}
	}
	int k = 0;
	for (int i = 1; i <= n; i++)
		if (in_heiro[i] == 1)
			k++;
	if (k > 0)
		cout << k << endl;
	else
		cout << "-1" << endl;
	for (int i = 1; i <= n; i++)
		if (in_heiro[i] == 1)
			cout << i << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
vector<int> edges[100005];int n,m;
void dfs(int start,int visited[])
{
    visited[start]=1;
    for(int i=0;i<edges[start].size();i++)
    {
        int ne=edges[start][i];
        if(visited[ne]==0)
        {
            dfs(ne,visited);
        }
    }
}
int solve()
{
    int visited[100005]={0};
    int count=0;
    for(int i=0;i<n;i++)
    {
        if(visited[i]==0)
        {
            count++;
            dfs(i,visited);
        }
    }
    return count-1;
}
int32_t main()
{
   cin>>n>>m;
    int a,b;
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);

    }
    int ans =solve();
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 11048
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

// const (
// 	initialBufSize = bufio.MaxScanTokenSize //65536
// 	maxBufSize     = 100000
// )
func main() {
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, initialBufSize)
	// scanner.Buffer(buf, maxBufSize)

	n := nextInt()
	a1 := make([]int, n)
	a2 := make([]int, n)
	for i := range a1 {
		a1[i] = nextInt()
	}
	for i := range a2 {
		a2[i] = nextInt()
	}

	max := 0
	for i := 0; i < n; i++ {
		sum := 0
		for j := 0; j <= i; j++ {
			sum += a1[j]
		}
		for k := i; k < n; k++ {
			sum += a2[k]
		}
		if sum > max {
			max = sum
		}
	}
	fmt.Println(max)
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}
func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
ll mod=1e9+7;
ll qpow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return res%mod;
}
int main(){
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>

#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++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


struct city
{
  int num;
  int x;
  int y;
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  int n;
  cin>>n;
  vector<city> xy(n);
  rep(i,n)
  {
    int a,b;
    cin>>a>>b;
    city t;
    t.num=i+1;
    t.x=a;
    t.y=b;
    xy[i]=t;
  }
  sort(all(xy),[](city a,city b){return a.x<b.x;});
  vector<vector<pair<int,int>>> edge(n+1);
  rep(i,n-1)
  {
    edge[xy[i+1].num].push_back({xy[i+1].x-xy[i].x,xy[i].num});
    edge[xy[i].num].push_back({xy[i+1].x-xy[i].x,xy[i+1].num});
  }
  sort(all(xy),[](city a,city b){return a.y<b.y;});
  rep(i,n-1)
  {
    edge[xy[i+1].num].push_back({xy[i+1].y-xy[i].y,xy[i].num});
    edge[xy[i].num].push_back({xy[i+1].y-xy[i].y,xy[i+1].num});
  }
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
  vector<int>visited(n+1,0);
  q.push({0,1});
  int res=0;
  while(!q.empty())
  {
    pair<int,int> tp=q.top();q.pop();
    if(visited[tp.second])continue;
    visited[tp.second]=1;
    res+=tp.first;
    //cout<<res<<endl;
    for(auto nn :edge[tp.second])
    {
      if(visited[nn.second])continue;
      q.push({nn.first,nn.second});
    }
  }
  cout<<res<<endl;



  return 0;

}


Measured memory_bytes: 10876