akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    char S[N];
    int Nr=0, Ng=0, Nb=0;
    int R[N], G[N], B[N];

    ll ans = 0;

    for(int i = 0; i < N; ++i){
        cin >> S[i];
        
        if(S[i] == 'R'){
            R[Nr] = i;
            Nr++;
        }
        else if(S[i] == 'G'){
            G[Ng] = i;
            Ng++;
        }
        else if(S[i] == 'B'){
            B[Nb] = i;
            Nb++;
        }
    }

    //int sm;
    int b;
    for(int r = 0; r < Nr; ++r){
        for(int g = 0; g < Ng; ++g){
            ans += Nb;
            //xBx
            b = (R[r] + G[g])/2;
            if( (R[r] + G[g])%2 == 0
             && 0 <= b && b < N && S[b] == 'B') ans--; 
            //xxB
            b = max(R[r],G[g])*2 - min(R[r],G[g]);
            if(0 <= b && b < N && S[b] == 'B') ans--; 
            //Bxx
            b = min(R[r],G[g])*2 - max(R[r],G[g]);
            if(0 <= b && b < N && S[b] == 'B') ans--; 
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int facctorialMethod(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}
int main() {
	int n;
	cin >> n;
	vector<string>a(n);
	vector<long long int>b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = 1;
		for (int j = 0; j < 10; j++) {
			if (a[i][j] == 'a') {
				b[i] *= 2;
			}
			else if (a[i][j] == 'b') {
				b[i] *= 3;
			}
			else if (a[i][j] == 'c') {
				b[i] *= 5;
			}
			else if (a[i][j] == 'd') {
				b[i] *= 7;
			}
			else if (a[i][j] == 'e') {
				b[i] *= 11;
			}
			else if (a[i][j] == 'f') {
				b[i] *= 13;
			}
			else if (a[i][j] == 'g') {
				b[i] *= 17;
			}
			else if (a[i][j] == 'h') {
				b[i] *= 19;
			}
			else if (a[i][j] == 'i') {
				b[i] *= 23;
			}
			else if (a[i][j] == 'j') {
				b[i] *= 29;
			}
			else if (a[i][j] == 'k') {
				b[i] *= 31;
			}
			else if (a[i][j] == 'l') {
				b[i] *= 37;
			}
			else if (a[i][j] == 'm') {
				b[i] *= 41;
			}
			else if (a[i][j] == 'n') {
				b[i] *= 43;
			}
			else if (a[i][j] == 'o') {
				b[i] *= 47;
			}
			else if (a[i][j] == 'p') {
				b[i] *= 53;
			}
			else if (a[i][j] == 'q') {
				b[i] *= 59;
			}
			else if (a[i][j] == 'r') {
				b[i] *= 61;
			}
			else if (a[i][j] == 's') {
				b[i] *= 67;
			}
			else if (a[i][j] == 't') {
				b[i] *= 71;
			}
			else if (a[i][j] == 'u') {
				b[i] *= 73;
			}
			else if (a[i][j] == 'v') {
				b[i] *= 79;
			}
			else if (a[i][j] == 'w') {
				b[i] *= 83;
			}
			else if (a[i][j] == 'x') {
				b[i] *= 89;
			}
			else if (a[i][j] == 'y') {
				b[i] *= 97;
			}
			else if (a[i][j] == 'z') {
				b[i] *= 101;
			}
		}
	}
	long long int ans = 0;
	int count=1;
	//sort(b.begin(), b.end());
	
	map <string, int> mp;
	for (int i = 0; i < n; i++) {
		sort(a[i].begin(), a[i].end());
		ans += mp[a[i]];
		mp[a[i]]++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef RUS_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef RUS_HOME
    freopen("input", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}




void smain() {

    int k,h1,m1,h2,m2;
    cin>>h1>>m1>>h2>>m2>>k;
    h1=h1*60+m1;
    h2=h2*60+m2;
    if(h2<h1){
        h2+=24*60;
    }
    int dif=h2-h1;
    cout<<max(0LL,dif-k);



}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define N 1005

int main()
{
    int n;

    cin>>n;

    string s[n+5];
    map<string,int> mp;
    for(int i=0;i<n;i++) {
        cin>>s[i];
        mp[s[i]]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}


Measured memory_bytes: 6756
#include<stdio.h>
int main(){
	int a;
	int b;
	scanf("%d%d", &a, &b);
	if(a < b){
		printf("a < b\n");
	}
	if(a > b){
		printf("a > b\n");
	}
	if(a == b){
		printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 2040
#!/usr/bin/env python
from bisect import *

n, m = map(int, input().split())
p = [0 for _ in range(m)]
y = [0 for _ in range(m)]
for i in range(m):
    p[i], y[i] = map(int, input().split())

d = [[] for _ in range(n)]
for i in range(m):
    d[p[i]-1].append(y[i])

for i in range(len(d)):
    d[i] = sorted(d[i])

ls = rs = ''
def complement(nstr):
    while len(nstr) != 6:
        nstr = '0' + nstr
    return nstr

for i in range(m):
    ls = complement(str(p[i]))
    r = bisect_right(d[p[i]-1], y[i])
    rs = complement(str(r))
    ans = ls+rs
    print(ans)


Measured memory_bytes: 27316
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int N, A, B;
    int p, ans;
    int one = 0;
    int two = 0;
    int three = 0;

    cin >> N;
    cin >> A >> B;

    for (int i = 0; i < N; i++) {
        cin >> p;
        if (p <= A) {
            one++;
        } else if (p >= A+1 && p <= B) {
            two++;
        } else {
            three++;
        }
    }

    ans = min({one, two, three});

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
struct UnionFind{
    vector<int> parent;
    vector<long long> edge;
    vector<long long> node;

    UnionFind(int N) : parent(N, -1), edge(N, 0), node(N, 0) {}

    void print(int x){
        printf("%d: parent:%d edge:%lld node:%lld\n", x, parent[x], edge[x], node[x]);
    }

    // (root_index, root_value - x_value)
    pair<int, long long> root(int x){
        if(parent[x] < 0){
            return make_pair(x, 0);
        }else{
            pair<int, long long> p = root(parent[x]);
            p.second += edge[x] + node[parent[x]];

            // update
            parent[x] = p.first;
            edge[x] = p.second - node[ parent[x] ]; // edge + node[parent] = p.second
            return p;
        }
    }

    void unite(int x, int y, int c){
        // y - x = c
        node[x] += c;
        node[y] += c;
        edge[x] -= c;
        edge[y] -= c;

        pair<int, long long> px = root(x);
        pair<int, long long> py = root(y);
        if(px.first == py.first) return;
        // assert -parent[py.first] >= -parent[px.first]
        if(parent[py.first] > parent[px.first]){
            swap(px, py);
            c = -c;
        }
        parent[py.first] += parent[px.first];
        parent[px.first] = py.first;
        edge[px.first] = py.second - px.second + c - node[py.first];

    }

    // return y - x
    long long compare(int x, int y){
        pair<int, long long> px = root(x);
        pair<int, long long> py = root(y);
        if(px.first != py.first) return LLONG_MIN;
        return -(py.second - px.second);
    }
};

int main(){
    int N, Q;
    while(cin >> N >> Q){
        UnionFind UF(N + 1);
        while(Q --> 0){
            string query;
            cin >> query;
            if(query == "COMPARE"){
                int x, y;
                cin >> x >> y;
                long long answer = UF.compare(x, y);
                cout << (answer > LLONG_MIN ? to_string(answer) : "WARNING") << endl;
            }else if(query == "IN"){
                int x, y, c;
                cin >> x >> y >> c;
                UF.unite(x, y, c);
            }
        }
    }
    return 0;
}

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

struct restaurant {
    int idx;
    string place;
    int i;

};
bool compareVec(restaurant r1, restaurant r2) 
{ 
    if (r1.place != r2.place) return r1.place < r2.place;
    return r1.idx > r2.idx;
} 


int main () {
    int N;
    cin >> N;
    vector<restaurant > vec (N);
    for (int i = 0; i < N; ++i) {
        cin >> vec[i].place >> vec[i].idx;
        vec[i].i = i + 1;
    }
    sort(vec.begin(), vec.end(), compareVec);

    for (auto a : vec) {
        cout << a.i << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val a = sc.nextInt()
    val b = sc.nextInt()
    val k = sc.nextInt()
    var count = 0
    for (i in 1000 downTo 1) {
        if (a % i == 0 && b % i == 0) {
            count++
            if (count == k) {
                println(i)
                return
            }
        }
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 34320
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		int ans = 0;

		String[] str = new String[100000];
		for (int i = 0; i < s.length(); i++) {
			if (i != 0 && s.substring(i, i + 1).equals(s.substring(i - 1, i))) {
				str[i - 1] += s.substring(i, i + 1);
			} else {
				str[i] = s.substring(i, i + 1);
				ans++;
			}
		}

		System.out.println(ans - 1);
	}
}

Measured memory_bytes: 46780
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100100];
vector<int> fours;
vector<int> twos;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]%4==0){
			fours.push_back(a[i]);
		}
		else if(a[i]%2==0){
			twos.push_back(a[i]);
		}
	}
	int a1=fours.size()*2;
	int a2=twos.size();
	int b1=fours.size()*2;
	if(b1!=0)
		b1++;
	if(b1>=n){
		cout<<"Yes"<<endl;
		return 0;
	}
	else if(a1+a2>=n){
		cout<<"Yes"<<endl;
		return 0;
	}
	else{
		cout<<"No"<<endl;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 1192
#include<bits/stdc++.h>
#define ll long long
using namespace std;
char s[1000005];
int a[1000005];
int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    int cnt=0;
    for(int i=len;i>=1;i--)
    {
        if(s[i]-'0'<4)cnt+=s[i]-'0';
        else if(s[i]-'0'==4)
        {
            if(a[i+1]&&s[i-1]-'0'>=5)
            {
                cnt+=9-(s[i]-'0');
                a[i]=1;
            }
            else cnt+=s[i]-'0';
        }
        else if(s[i]-'0'>5)
        {
            cnt+=11-(s[i]-'0');
            a[i]=1;
            if(a[i+1])cnt-=2;
        }
        else
        {
            if(a[i+1])
            {
                a[i]=1;
                cnt+=9-(s[i]-'0');
            }
            else
            {
                if(s[i-1]-'0'>=5)
                {
                    cnt+=11-(s[i]-'0');
                    a[i]=1;
                }
                else cnt+=s[i]-'0';
            }
        }
    }
    printf("%d\n",cnt);
}


Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<map>

void stupid(){
        int N;
    std::cin>>N;
    std::vector<long long>A(N);
    for(int i=0;i<N;++i){
        std::cin>>A[i];
    }
    long long ans=0;
    for(int i=1;i<N;++i){
        for(int j=0;(j+i)<N;++j){
            if(A[j]+A[i+j]==i){
                ans++;
            }
        }
    }
    std::cout<<ans<<std::endl;
}

void correct(){
    int N;
    std::cin>>N;
    std::vector<long long>A(N);
    long long maxA,minA;
    for(int i=0;i<N;++i){
        std::cin>>A[i];
        if(i==0){
            maxA=A[0];
            minA=A[0];
        }else if(maxA<A[i]){
            maxA=A[i];
        }else if(minA>A[i]){
            minA=A[i];
        }
    }
    std::map<long long,long long> L,R;
    for(int i=0;i<N;++i){
        L[i+1+A[i]]++;
        R[i+1-A[i]]++;
    }
    unsigned long long ans=0;
    for(int x=minA;x<=N-minA;++x){
        // std::cout<<"x"<<x<<"r"<<R[x]<<"l"<<L[x]<<std::endl;
        ans+=L[x]*R[x];
    }
    std::cout<<ans<<std::endl;
    return;
}

int main(){
    correct();
}

Measured memory_bytes: 47396
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long> a(n + 1);
    vector<long> b(n);
    for (int i = 0; i < n + 1; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    long answer = 0;
    for (int i = 0; i < n; ++i) {
        if (b[i] >= a[i]) {
            answer += a[i];
            b[i] -= a[i];
            if (b[i] < a[i + 1]) {
                answer += b[i];
                a[i + 1] -= b[i];
            } else {
                answer += a[i + 1];
                a[i + 1] = 0;
            }
        } else {
            answer += b[i];
        }
    }
    cout << answer << endl;
}


Measured memory_bytes: 1792
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [u128; n],
    }
    a.sort();

    let mut ans = if a.len() == 0 { 0 } else { 1 };

    for i in 0..n {
        ans *= a[i];
        if ans == 0 {
            break;
        }
        if 1_000_000_000_000_000_000 < ans {
            println!("-1");
            return;
        }
    }

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


Measured memory_bytes: 6140
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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

int main() {
	int a,b;
	cin >> a >> b;
	cout << max(0, a-2*b) << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    
    sum += r - l + 1;
  }
  
  cout << sum << endl;
}
    
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<pair<int, int>> v;
    int pre = 0;
    for(int i = 1; i < n; i++) {
        if(a[i - 1] >= a[i]) {
            v.emplace_back(pre, i - 1);
            pre = i;
        }
    }
    v.emplace_back(pre, n - 1);
    // for(auto i : v) {
    //     debug(i.first, i.second);
    // }
    ll m = 1000;
    for(auto i : v) {
        ll k = m / a[i.first];
        m -= (m / a[i.first]) * a[i.first];
        m += a[i.second] * k;
    }
    cout << m << endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m;
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a>c&&c>b||a<c&&c<b)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
from itertools import product

S = input()
nd,N = len(S),int(S)

if N<357:
  print(0)
  exit()

count = 0
for n_digit in range(3,nd+1):
  for p in product(['3','5','7'],repeat=n_digit):
    if set(p) == {'3','5','7'} and int(''.join(p))<=N:
      count += 1
print(count)
  

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));


void solve()
{
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long m=INT_MIN;
	m=max(a*d,a*c);
	//m=max(m,a*d);
	m=max(m,b*c);
	m=max(m,b*d);
	cout<<m;
		
}

int main()
{	
	fast;
	int t=1;
	//cin>>t;
	while(t--)
		solve();
}	


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

int main(){
	unsigned long long n;
	cin>>n;
	unsigned long long k;
	cin>>k;
	vector<unsigned long long> a(n);
	for(long long i=0;i<n;i++){
		cin>>a[i];
	}
	for(long long i=k;i<n;i++){
		if(a[i]>a[i-k]){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

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

string s;
int main(){
	cin>>s;
    int res = 0;
    if (s[0]=='1'){
        ++res;
    }
    if (s[1]=='1'){
        ++res;
    }
    if (s[2]=='1'){
        ++res;
    }
   
    cout<<res<<endl;
} 

Measured memory_bytes: 256
#include <stdio.h>

int a[100010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	printf("%d",a[0]);
	for(int i=1;i<n;i++)if(a[i-1]!=a[i])printf(" %d",a[i]);
	puts("");
}


Measured memory_bytes: 2176
#include<stdio.h>
#include<string.h>

int main(){
	
	//準備部分
	int n,i,tp=0,hp=0;//tp太郎ポイント,hp花子ポイント
	char tc[101],hc[101];//tc太郎カード,hc花子カード
	
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s",tc,hc);
		if(strcmp(tc,hc)==0)tp++,hp++;
		else if(strcmp(tc,hc)>0)tp+=3;
		else if(strcmp(tc,hc)<0)hp+=3;
	}
	printf("%d %d\n",tp,hp);
	
	return 0;
}



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

class TextEditor{
private:
  string buf;
  vector<string> text;
  int row,pos;

  void InputText();
  void MoveCursor(char com);
  void DeleteCharacter();
  void CutLine();
  void PasteBuffer();
  
public:
  TextEditor();

  void ProcessCommand(char com);
  void PrintText();
};




int main(){

  TextEditor editor;

  char command;

  while(cin >> command, command != '-'){
    editor.ProcessCommand(command);
  }
  
  editor.PrintText();
  
  return 0;
}




TextEditor::TextEditor(){
  buf = "";
  pos = row = 0;
  InputText();
}


void TextEditor::InputText(){
  string input;

  while(getline(cin,input), input!="END_OF_TEXT"){
    text.push_back( input );
  }
}


void TextEditor::MoveCursor(char com){
  switch(com){
  case 'a': //move cursor to the first character of line
    pos = 0;
    break;
    
  case 'e': // move the cursor to the end-of-line
    pos = text[row].size();
    break;
    
  case 'p': //move upper line
    if(row > 0)row--;
    pos = 0;
    break;

  case 'n': //move lower line
    if(row < text.size()-1 )row++;
    pos = 0;
    break;

  case 'f': //move cursor right
    if( pos != text[row].size() ) pos++;
    else if( row < text.size()-1 ){ pos = 0; row++; }
    break;

  case 'b': //move cursor left
    if( pos != 0 ) pos--;
    else if( row > 0 ){ pos = text[--row].size(); }
    break;
  }
}


void TextEditor::DeleteCharacter(){
  if(pos != text[row].size() ){
    text[row].erase( text[row].begin() + pos );
  }
  else if( row < text.size()-1 ){
    text[row] += text[row+1];
    text.erase( text.begin() + row + 1 );
  }
}


void TextEditor::CutLine(){
  if(pos == text[row].size()){
    DeleteCharacter();
    buf = "\n";
  }
  else{
    buf = text[row].substr(pos);
    text[row].erase( text[row].begin()+pos , text[row].end() );
    pos = text[row].size();
  }
}


void TextEditor::PasteBuffer(){
  if( buf == "\n" ){
    string newline = text[row].substr(pos);
    text[row].erase( text[row].begin()+pos , text[row].end() );
    text.insert( text.begin()+row+1 , newline );
    row++; pos = 0;
  }

  else{
    text[row].insert( pos, buf );
    pos += buf.size();
  }

}


void TextEditor::ProcessCommand(char com){


  switch(com){
  case 'd':
    DeleteCharacter();
    break;
    
  case 'k':
    CutLine();
    break;

  case 'y':
    PasteBuffer();
    break;

  default:
    MoveCursor(com);
  }
  
}


void TextEditor::PrintText(){
  for(auto line : text){
    cout << line << endl;
  }
}



Measured memory_bytes: 3128
from collections import defaultdict
from itertools import permutations

n, c = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(c)]
cmat = [list(map(int, input().split())) for _ in range(n)]

dcnt = [defaultdict(int) for _ in range(3)]
for i, ci in enumerate(cmat):
    for j, cij in enumerate(ci):
        mod = (i + j) % 3
        dcnt[mod][cij - 1] += 1

ans = 10 ** 9
for color in permutations(range(c), 3):
    tmp = 0
    for tgt, cnt in zip(color, dcnt):
        tmp += sum(d[k][tgt] * cnt[k] for k in cnt)
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 77384
#include<stdio.h>
 int main(void)
{
 int a,b,c,x,y,u,z;

  scanf("%d%d%d",&a,&b,&c);
  if(a<=c && b<=c)
       x=c,u=b,z=a;
  else if (a<=b && c<=b)
        x=b,u=c,z=a;
  else if (b<=a && c<=a)
        x=a,u=c,z=b;
  y=(x*10)+u+z;
  printf("%d\n",y);
  return 0;
}
                            

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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main(void){

  long long a, b;
  cin >> a >> b;
  
  long long gcd = GCD(a, b);
  int result = 0;
  for (long long i = 2; i * i <= gcd; ++i) {
    if (gcd % i != 0) continue;
    result++;
    // 割れる限り割り続ける
    while (gcd % i == 0) {
        gcd /= i;
    }
  }
  if (gcd != 1) result++;
  cout << result + 1 << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int n,i,a,b;
	long long k,data[100001]={0},c=0;
	scanf("%d%lld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d%d",&a,&b);
		data[a] += b;
	}
	for(i=0;c<k;i++){
		c+=data[i];
	}
	printf("%d",i-1);
	return 0;
}

Measured memory_bytes: 896
import java.util.*;

class Main{
	public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);
      	ArrayList<Num> list = new ArrayList<Num>();
      	int n;
      	n = sc.nextInt();
      	list.add(new Num(1,sc.nextInt()));
      	for(int i=1;i<n;i++){
        	int k = sc.nextInt();
          	int min = 0,max = list.size()-1,b=0;
         	while(min<=max){
            	int mid = (min+max)/2;
              	if(list.get(mid).t>k){
                  	max = mid-1;
                }else{
                  	min = mid+1;
                }
            }
          	list.add(min,new Num(i+1,k));
        }
      	for(int i=0;i<n;i++){
        	System.out.print(list.get(i).n);
          	if(i!=n-1){
            	System.out.print(" ");
            }
        }
      	System.out.println("");
    }
}

class Num{
	int n,t;
  	public Num(int a,int b){
    	n = a; t = b;
    }
}




Measured memory_bytes: 55636
A,B=map(int,input().split())
if (A+B)>=(A-B) and (A+B)>=(A*B):
  print(A+B)
elif (A-B)>=(A+B) and (A-B)>=(A*B):
  print(A-B)
elif (A*B)>=(A+B) and (A*B)>=(A-B):
  print(A*B)

Measured memory_bytes: 9172
#include <iostream>
#include <string>
#include <vector>
#define llint long long

using namespace std;

string s;
llint k;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s >> k;
	vector<llint> vec;
	
	llint cnt = 0; char pre = '^';
	for(int i = 0; i < s.size(); i++){
		if(s[i] == s[i-1]) cnt++;
		else{
			vec.push_back(cnt);
			cnt = 1;
		}
	}
	vec.push_back(cnt);
	vec.erase(vec.begin());
	
	if(vec.size() == 1){
		cout << vec[0] * k / 2 << endl;
		return 0;
	}
	
	llint sum = 0;
	for(int i = 1; i < (int)vec.size()-1; i++) sum += vec[i] / 2;
	llint ans = sum * k;
	ans += vec[0]/2 + vec.back()/2;
	if(s[0] == s[(int)s.size()-1]) ans += (k-1) * ((vec[0]+vec.back())/2);
	else ans += (vec[0]/2 + vec.back()/2) * (k-1);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
int n, W;
int v[1005], w[1005];
int dp[1005][10005];

int solve(int i, int j)
{
	if (i == n) return 0;
	if (dp[i][j] >= 0) return dp[i][j];
	int res;
	if (w[i] > j) res = solve(i + 1, j);
	else res = max(solve(i + 1, j), solve(i + 1, j - w[i]) + v[i]);
	return dp[i][j] = res;
}
int main()
{
	MS(dp, -1);
	cin >> n >> W;
	REP(i, n)
	{
		cin >> v[i] >> w[i];
	}
	cout << solve(0, W) << endl;
	return 0;
}

Measured memory_bytes: 40456
import java.io.IOException;
import java.util.Scanner;

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

		while (true) {
			long b = sc.nextLong();

			if (b == 0) {
				break;
			}

			long ans1 = b;
			long ans2 = 1;

			for (int i = 2;; i++) {
				long sum = i * (i + 1) / 2;

				if (b < sum)
					break;

				long n = b - sum;
				if (n % i == 0) {
					ans1 = n / i + 1;
					ans2 = i;
				}
			}
			System.out.println(ans1 + " " + ans2);
		}
	}
}


Measured memory_bytes: 30912
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define float long double
#define f(i,a,b) for(int i = a;i < b;i++)
#define ff(i,a,b)  for(int i = a-1;i>=b;i--)
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL)
const int mod = 1e9+7;
//int to string -> to_string()
//string to int -> stoi()

int32_t main()
{
   IOS;
   int n,m;
   cin>>n>>m;
   if(n==m)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,a[200010],x,c[200010],t,i,ans;
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		a[x]++;
	}
	for(i=1;i<=n;i++)
		if(a[i])c[++t]=a[i];
	sort(c+1,c+t+1);
	for(i=1;i<=t-m;i++)
		ans+=c[i];
	printf("%d\n",ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define MAX_H 200
#define MAX_W 100
#define rep(i, n) for(ll i=0; i<n; i++)
#define rer(i, a, b) for(ll i=a-1; i>=b; i--)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int h, w;
string img[MAX_H];

signed main(){
    cin >> h >> w;
    rep(i, h){
        cin >> img[2*i];
        img[2*i+1] = img[2*i];
    }
    rep(i, 2*h){
        cout << img[i] << endl;;
    }
    return 0;
}

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

using namespace std;

string rotate_left (string s) {
    return s.substr(1, s.size() - 1) + s.substr(0, 1);
}

string rotate_right (string s) {
    return s.substr(s.size() - 1, 1) + s.substr(0, s.size() - 1);
}

string swap_half (string s) {
    bool even = s.size() % 2 == 0;
    int h = s.size() /2;
    if (even) {
        return s.substr(h, h) + s.substr(0, h);
    } else {
        return s.substr(h + 1, h) + s.substr(h, 1) + s.substr(0, h);
    }
}

string rev(string s) {
    reverse(begin(s), end(s));
    return s;
}

string inc_dig (string s) {
    string ret = "";
    for (char c : s) {
        if(isdigit(c)) {
            ret += ((c - '0') + 1) % 10 + '0';
        } else {
            ret += c;
        }
    }
    return ret;
}

string dec_dig (string s) {
    string ret = "";
    for (char c : s) {
        if(isdigit(c)) {
            ret += ((c - '0') + 9) % 10 + '0';
        } else {
            ret += c;
        }
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        string opers, s;
        cin >> opers >> s;
        for (auto op = opers.rbegin(); op != opers.rend(); ++op) {
            if(*op == 'J') {
                s = rotate_right(s);
            } else if (*op == 'C') {
                s = rotate_left(s);
            } else if (*op == 'E') {
                s = swap_half(s);
            } else if (*op == 'A') {
                s = rev(s);
            } else if (*op == 'P') {
                s = dec_dig(s);
            } else if (*op == 'M') {
                s = inc_dig(s);
            }
        }
        cout << s << endl;
        
    }
    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    ll a, b; cin >> a >> b;

    ll bbt = b;
    int l = 1;
    while(bbt/2!=0){
        bbt /= 2;
        l++; 
    }

    ll ans = 0;
    ll ans2 = 0;
    for(int i=0; i<=l; i++){
        ll cnt = 0, cnt2 = 0;
        ll tmpa = a % (ll)pow(2, i+1);
        ll tmpb = (b+1) % (ll)pow(2, i+1);

        dump(ans);
        if(i==0){
            cnt = a/2;
            cnt %= 2;
            cnt2 = (b+1)/2;
            cnt2 %= 2;

            ans += (cnt^cnt2) * pow(2, i);
            continue;
        }

        if(tmpa<(ll)pow(2, i)){
            cnt = 0;
        }
        else{
            cnt = tmpa % 2;
        }

        if(tmpb<(ll)pow(2, i)){
            cnt2 = 0;
        }
        else{
            cnt2 = tmpb % 2;
        }

        ans += (cnt^cnt2) * pow(2, i);

    }

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


Measured memory_bytes: 512
from itertools import accumulate

n=int(input())
a=list(map(int,input().split()))

s=list(accumulate(a))

chg=0
sign=1
op1=0

for i in range(n):
    curs=s[i]+chg

    if sign*curs>0:
        sign*=-1
        continue

    chg+=sign-curs
    a[i]+=sign-curs
    op1+=abs(sign-curs)

    sign*=-1

chg=0
sign=-1
op2=0

for i in range(n):
    curs=s[i]+chg

    if sign*curs>0:
        sign*=-1
        continue

    chg+=sign-curs
    a[i]+=sign-curs
    op2+=abs(sign-curs)

    sign*=-1

print(min(op1,op2))

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

int N, A, B, C, ans = 1e9;
int l[8];

void calc(vector<int> v) {
  int a = 0, b = 0, c = 0, al = 0, bl = 0, cl = 0;
  for (int i = 0; i < v.size(); i ++) {
    if (v[i] == 0) a ++, al += l[i];
    else if (v[i] == 1) b ++, bl += l[i];
    else if (v[i] == 2) c ++, cl += l[i];
  }
  if (al == 0 || bl == 0 || cl == 0) return;
  a = max(0, a - 1), b = max(0, b - 1), c = max(0, c - 1);
  int sum = 10 * (a + b + c) + abs(A - al) + abs(B - bl) + abs(C - cl);
  ans = min(ans, sum);
  return;
}

void dfs(int depth, vector<int> v) {
  if (depth == N) {
    calc(v);
    return;
  }
  for (int i = 0; i < 4; i ++) {
    v[depth] = i;
    dfs(depth + 1, v);
  }
}

int main() {
  cin >> N >> A >> B >> C;
  for (int i = 0; i < N; i ++) cin >> l[i];

  vector<int> vec(N);
  dfs(0, vec);

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
constexpr long INF = 1L << 60;
constexpr int MOD = 998244353;


long N, L[2020];
// 0(N^2) で使う２編を決める
// 残り１編の条件
// L[k] < L[i]+L[j] 
// L[k] > L[i]-L[j] upper bound
// L[k] > L[j]-L[i] upper bound

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> N;
  REP(i,N) cin >> L[i];
  sort(L, L + N);
  
  long ans = 0;
  for(int i = 0; i < N; ++i) {
    for(int j = i+1; j < N; ++j) {
      long con1 = L[i] + L[j];
      long con2 = abs(L[j] - L[i]);
      ans += max(0L, lower_bound(L, L + N, con1) - upper_bound(L, L + N, con2)-(con2<L[i]&&L[i]<con1)-(con2<L[j]&&L[j]<con1));
    }
  }
  cout << ans / 3;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
1 100
)");
#define cin input
#endif

int main()
{
	int d, n;
	cin >> d >> n;

	if (d==0)
	{
		if(n!=100)
			cout << n << endl;
		else
			cout << n+1 << endl;
	}
		
	if (d==1)
	{
		if(n!=100)
			cout << 100*n << endl;
		else
			cout << 100*(n+1) << endl;
	}

	if (d==2)
	{
		if(n!=100)
			cout << 10000*n << endl;
		else
			cout << 10000*(n+1) << endl;
	}

}

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

int main() {
string s;
int res=0,count=0;
cin>>s;
for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
        count++;
    }
    if(s[i]=='B'){
        res++;
    }
}
if(count==s.size() || res==s.size()){
    cout<<"No"<<endl;
}
else
cout<<"Yes"<<endl;
return 0;
}

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

using namespace std;

#define ge getchar()
#define Re read()

inline int read() {
	int x = 0, t = 0, ch;
	while(!isdigit(ch = ge)) ;
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = ge;
	return t ? -x : x;
}

int main() {
	int m = Re, d = Re, res = 0;
	for(int i = 2; i <= 9; i++)
		for(int j = 2; j <= 9; j++)
			if(i * 10 + j <= d)
				if(i * j <= m)
					res++;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"Yes":"No")<<endl;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i=0; i<s.size(); ++i) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3920
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	int mv = 0;
	map<string,int> vote;
	vector<string> win;
	for(int a=0;a<n;a++){
		string name;
		cin>>name;
		if(vote.count(name)){
			vote[name] += 1;
		}
		else{
			vote[name] = 1;
		}
		int rar = vote[name];
		if(rar>mv){
			win.clear();
			mv = rar;
			win.push_back(name);
		}
		else if(rar == mv) win.push_back(name);
	}
	sort(win.begin(),win.end());
	int si = win.size();
	for(int a = 0;a<si;a++) cout<<win[a]<<"\n";
	return 0;
}

Measured memory_bytes: 25456
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main()
{
    int n;
    cin >> n;
    vector<int>x(n), y(n), r;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        r.push_back(i);
    }
    double a = 0;
    double p = 0;
    do{
        for (int i = 0; i < n - 1; i++) {
            double d = sqrt(pow((x[r[i]]-x[r[i+1]]), 2)+ pow((y[r[i]] - y[r[i + 1]]), 2));
            a += d;
            
        }
     //   a+= sqrt((x[0] - x[n-1])*(x[0] - x[n-1]) + (y[0] - y[n- 1])*(y[0] - y[n- 1]));
    //    cout << a << endl;
        p++;


    } while (next_permutation(r.begin(), r.end()));
//    cout << p;
    cout << setprecision(20);
    cout << a / p << endl;

    return 0;

}


Measured memory_bytes: 256
//waz
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
 
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;
 
#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))
 
int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}
 
const int N = 1e5 + 10;
 
int n, a[N], b[N], sum, ans;
 
int c[N], d[N];
 
int t[N << 1], m, fa[N];
 
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
 
void unit(int x, int y)
{
	if (find(x) != find(y))
		fa[find(x)] = find(y);
}
 
int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(a[i]), sum ^= a[i];
	a[n + 1] = sum, sum = 0;
	for (int i = 1; i <= n; ++i) gi(b[i]), sum ^= b[i];
	b[n + 1] = sum, sum = 0;
	++n;
	for (int i = 1; i <= n; ++i) c[i] = a[i], d[i] = b[i];
	sort(c + 1, c + n + 1);
	sort(d + 1, d + n + 1);
	for (int i = 1; i <= n; ++i)
		if (c[i] != d[i])
		{
			puts("-1");
			return 0;
		}
	for (int i = 1; i <= n; ++i)
	{
		if (a[i] != b[i] && i < n) ++ans;
		if (a[i] != b[i] || i == n) t[++m] = a[i], t[++m] = b[i];
	}
	if (!ans)
	{
		puts("0");
		return 0;
	}
	sort(t + 1, t + m + 1);
	m = unique(t + 1, t + m + 1) - t - 1;
	for (int i = 1; i <= m; ++i) fa[i] = i;
	for (int i = 1; i <= n; ++i)
		if (a[i] != b[i]) unit(lower_bound(t + 1, t + m + 1, a[i]) - t, lower_bound(t + 1, t + m + 1, b[i]) - t);
	for (int i = 1; i <= m; ++i)
		if (find(i) == i) ++ans;
	printf("%d\n", ans - 1);
	return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1e9+7
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    int ans = 1;
    while(ans * 2 <= n){
        ans *= 2;
    };
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
int n,i;
scanf("%d",&n);
int a[n],b[n];
for(i=0;i<n;i++){
    b[i]=0;
}
for(i=0;i<n-1;i++){
scanf("%d",&a[i]);
b[a[i]-1]++;
}
for(i=0;i<n;i++){
printf("%d\n",b[i]);
}
return 0;
}    

Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
const ll mod = 1e9 + 7;
void solve() {
	int n, k;
	cin >> n >> k;
	VI a(n);
	rep(i, 0, n)cin >> a[i];
	sort(all(a), [&](int a, int b) {return abs(a) < abs(b); });
	if (abs(a[n - k]) == 0) {
		cout << 0 << endl;
		return;
	}
	int neg = 0;
	ll ans = 1;
	int last_neg = -1, last_pos = -1;
	int first_neg = -1, first_pos = -1;
	for (int i = n - 1; i >= n - k; i--) {
		if (a[i] < 0) {
			neg++;
			last_neg = i;
		}
		if (a[i] > 0) {
			last_pos = i;
		}
		ans *= a[i];
		ans %= mod;
		if (ans < 0) {
			ans = (ans + mod) % mod;
		}
	}
	for (int i = n - k - 1; i >= 0; i--) {
		if (first_neg==-1&&a[i] < 0) {
			first_neg = i;
		}
		if (first_pos==-1&&a[i] >= 0) {
			first_pos = i;
		}
		if (first_pos != -1 && first_neg != -1) {
			break;
		}
	}

	if (neg % 2 == 0||n==k) {
		cout << ans << endl;
		return;
	}
	ll ans1 = 1;
	for (int i = n - 1; i >= n - k; i--) {
		if (i != last_pos&&i != last_neg) {
			ans1 *= a[i];
			ans1 %= mod;
			if (ans1 < 0) {
				ans1 = (ans1 + mod) % mod;
			}
		}
	}
	if (first_pos != -1 && first_neg != -1 && last_pos != -1 && last_neg != -1) {
		if (1LL * abs(a[first_neg])*abs(a[last_neg]) >= 1LL * abs(a[first_pos])*abs(a[last_pos])) {
			ans1 *= a[first_neg];
			ans1 %= mod;
			if (ans1 < 0) {
				ans1 = (ans1 + mod) % mod;
			}
			ans1 *= a[last_neg];
			ans1 %= mod;
			if (ans1 < 0) {
				ans1 = (ans1 + mod) % mod;
			}
		}
		else {
			ans1 *= a[last_pos];
			ans1 %= mod;
			ans1 *= a[first_pos];
			ans1 %= mod;
		}
		cout << ans1 << endl;
	}
	else if (last_pos == -1) {
		if (first_pos == -1) {
			ll ans2 = 1;
			for (int i = 0; i < k; i++) {
				ans2 *= a[i];
				ans2 %= mod;
				if (ans2 < 0) {
					ans2 = (ans2 + mod) % mod;
				}
			}
			cout << ans2 << endl;
			return;
		}
		else {
			ans1 *= a[first_pos];
			ans1 %= mod;
			cout << ans1 << endl;
			return;
		}
	}
	else {
		if (first_pos == -1) {
			ans1 *= a[first_neg];
			ans1 %= mod;
			if (ans1 < 0) {
				ans1 = (ans1 + mod) % mod;
			}
			ans1 *= a[last_neg];
			ans1 %= mod;
			if (ans1 < 0) {
				ans1 = (ans1 + mod) % mod;
			}
			cout << ans1 << endl;
			return;
		}
		if (first_neg == -1) {
			ans1 *= a[last_pos];
			ans1 %= mod;
			ans1 *= a[first_pos];
			ans1 %= mod;
			cout << ans1 << endl;
			return;
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 3936
import collections
import itertools as it
import math
import numpy as np

# A = input()
# A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()

N = int(input())
point = [tuple(map(int, input().split())) for i in range(N)]

total = 0
for keiro in list(it.permutations(point)):
  for i, town in enumerate(keiro[:-1]):
    x1, y1 = keiro[i]
    x2, y2 = keiro[i+1]
    total += math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
  
print(total/len(list(it.permutations(point))))

Measured memory_bytes: 27016
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
typedef unsigned long long ull ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define rrep(i , n) for ( int i = n-1; i >=0 ; i--)

#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

class UnionFind {
private:
	ull size_; 
	std::vector<ull> par, rank, count;

public:
	UnionFind() : size_(0), par(std::vector<ull>()), rank(std::vector<ull>()), count(std::vector<ull>()) {};
	UnionFind(ull size__) : size_(size__) {
		par.resize(size_); rank.resize(size_); count.resize(size__);
		for (ull i = 0; i < size_; i++) par[i] = i, rank[i] = 0, count[i] = 1;
	}
	ull size() { return size_; }
	// ull root(ull x) { return par[x] == x ? x : par[x] = root(par[x]); }
	
	ull root(ull x)
	{
		while(par[x] != x)
		{
			par[x] = par[par[x]];
			x = par[x];
		}
		return x;
	}
	
	bool same(ull x, ull y) { return root(x) == root(y); }

	void unite(ull x, ull y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y, count[y]+=count[x], count[x]=0;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++, count[x]+=count[y], count[y]=0;
		else par[y] = x, count[x] += count[y], count[y] = 0;
	}

	ull size__(ull x)
	{
		return count[root(x)];
	}

	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};
/*
maybe sth wrong 
got wa in one problem
*/
ll modpow(ll a, ll b)
{
	if (b == 0)
	{
		return 1;
	}

	if (b % 2)
	{
		return a * modpow(a, b-1) % MOD;
	}
	else
	{
		ll halfB = b / 2;
		ll half = modpow(a, halfB);
		return half * half % MOD;
	}
}

ll calcComb(ll n, ll m)
{
	if (m > n-m)
	{
		return calcComb(n, n-m);
	}

	ll ansMul = 1;
	ll ansDiv = 1;

	rep(i, m)
	{
		ansMul *= (n-i);
		ansDiv *= (i+1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}

	return ansMul * modpow(ansDiv, MOD - 2) % MOD;
}

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


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

	ll A[N];
	rep(i, N)
	{
		cin >> A[i];
	}

	ll dp[N+1][2];
	//ll dp[N+1];
	memset(dp, 0, sizeof(dp));
	//dp[0][0] = 0;
	//dp[0][1] = 0
	rep(i, N)
	{
		if (i == 1)
		{
			dp[i+1][0] = dp[i][0] + A[i];
		}
		else
		{
			dp[i+1][0] = max(dp[i][0] + A[i], dp[i][1]+A[i]);
		}
		
		
		if (i > 0)
		{
			if (i == 1)
			{
				dp[i+1][1] = dp[i][0] - 2*A[i-1]-A[i];
			}
			else
			{
				dp[i+1][1] = max(dp[i][0] - 2*A[i-1]-A[i], dp[i][1] + 2*A[i-1] -A[i]);
			}
		}
		/*
		dp[i+1] = ()
		*/
		//cout << i << ", "<< dp[i+1][0] << ", " << dp[i+1][1] << endl; 
	}
	
	cout << max(dp[N][0], dp[N][1]) << endl;

	
	return 0;
}


Measured memory_bytes: 2560
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
char a[11],b[11];
int c[10][2][10],lna,lnb;
int fn(int p,int q,int r){
  if(p==lna)
    return 0;
  if(c[p][q][r])
    return c[p][q][r];
  if(a[lna-p-1]-q<(lnb-p-1<0?'0':b[lnb-p-1]))
    return c[p][q][r]=a[lna-p-1]-'0'-q-(lnb-p-1<0?0:b[lnb-p-1]-'0')+10+max(fn(p+1,1,r),r?fn(p+1,0,r-1):0)*10;
  else
    return c[p][q][r]=a[lna-p-1]-'0'-q-(lnb-p-1<0?0:b[lnb-p-1]-'0')+fn(p+1,0,r)*10;
}
int main(){
  int n;
  scanf("%s%s%d",a,b,&n);
  lna=strlen(a);
  lnb=strlen(b);
  printf("%d\n",fn(0,0,n));
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>]
#include <map>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;

int main(){
ll a,b;cin>>a>>b;
cout<<(1900*b+(a-b)*100)*pow(2,b);
}

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

int main() {
  int n, a, b; cin >> n >> a >> b;

  auto f = [&](int x) {
    int res = 0;
    while (x) {
      res += x % 10;
      x /= 10;
    }
    return res;
  };

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int d = f(i);
    if (d >= a && d <= b) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256