akhauriyash/Code-Regression huggingface dataset:
s = input()
q = int(input())
t = 0
f = []
b = []
for _ in range(q):
    a = input().split()
    if len(a) == 1:
        t += 1
    else:
        m, n = int(a[1]), a[2]
        if t % 2 == 0:
            if m == 1:
                f.append(n)
            else:
                b.append(n)
        else:
            if m == 1:
                b.append(n)
            else:
                f.append(n)
if t % 2 == 0:
    x = ''
    for i in f:
        x = i + x
    x = x + s
    for i in b:
        x = x + i
    print(x)
else:
    x = ''
    for i in b:
        x = i + x
    x = x + s[::-1]
    for i in f:
        x = x + i
    print(x)

Measured memory_bytes: 5740
import numpy as np

def main():
    N = int(input())

    INF = 10**6 + 100

    x = np.arange(1,INF,dtype=np.int64)
    div = x[N % x == 0]
    #print(div)
    #print(N // div)
    
    ans = (div + N//div).min() - 2
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 29028
#include <iostream>
#include <string>

bool isShiritori()
{
  std::string a, b, c;
  std::cin >> a;
  std::cin >> b;
  std::cin >> c;

  char a_back = a.back();
  char b_front = b.front();
  char c_front = c.front();
  char b_back = b.back();

  if (a_back != b_front) {
    return false;
  }
  if (b_back != c_front) {
    return false;
  }
  return true;
}

int main()
{
  if (isShiritori()) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var points = new Point[n];
            var index = 0;
            for (var i = 0; i < points.Length; i++)
            {
                var xyh = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
                points[i] = new Point { X = xyh[0], Y = xyh[1], H = xyh[2] };
                if (xyh[2] > 0) index = i;
            }

            for (var cx = 0; cx <= 100; cx++)
            {
                for (var cy = 0; cy <= 100; cy++)
                {
                    var h = Math.Abs(points[index].X - cx) + Math.Abs(points[index].Y - cy) + points[index].H;
                    var isValid = true;
                    for (var i = 0; i < points.Length; i++)
                    {
                        var tmpH = Math.Max(h - Math.Abs(points[i].X - cx) - Math.Abs(points[i].Y - cy), 0L);
                        if (points[i].H != tmpH)
                        {
                            isValid = false;
                            break;
                        }
                    }
                    if (isValid)
                    {
                        Console.WriteLine($"{cx} {cy} {h}");
                        return;
                    }
                }
            }
        }

        public struct Point
        {
            public long X { get; set; }
            public long Y { get; set; }
            public long H { get; set; }
        }
    }
}


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

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int,int>
#define mii map<int,int>
#define mci map<char,int>
#define fir first
#define sec second
#define eline "\n"

int main() {

	ios::sync_with_stdio(false);
	cin.tie(0);

	ll n, ans = 0;
	cin >> n;
	string s;
	unordered_map<string,int> m;
	for(int i = 0; i < n; ++i) {
		cin >> s;
		m[s]++;
		if(m[s] == 1) ++ ans;
	}
	cout << ans << eline; 
	
	return 0;
}


Measured memory_bytes: 17604
/* به نام یزدان */
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 4000 + 5, MOD = 998244353;
int n, cnt[2][MAX_N], dp[MAX_N][MAX_N];

void read_input() {
	string s;
	cin >> s;
	n = s.size();
	for (int i = 0; i < n; i++)
		if (s[i] == '0')
			cnt[0][i + 1] += 2;
		else if (s[i] == '1')
			cnt[0][i + 1]++, cnt[1][i + 1]++;
		else
			cnt[1][i + 1] += 2;
	for (int j = 0; j < 2; j++)
		for (int i = 1; i <= 2 * n; i++)
			cnt[j][i] += cnt[j][i - 1];
}

void solve() {
	dp[0][0] = 1;
	for (int i = 1; i <= 2 * n; i++)
		for (int j = 0; j <= i; j++)
			if (cnt[0][i] >= j && cnt[1][i] >= i - j) {
				if (j)
					dp[i][j] = dp[i - 1][j - 1];
				if (i - j)
					(dp[i][j] += dp[i - 1][j]) %= MOD;
			}
}

void print_output() {
	int ans = 0;
	for (int i = 0; i <= 2 * n; i++)
		ans += dp[2 * n][i];
	cout << ans;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	read_input();
	solve();
	print_output();
}


Measured memory_bytes: 60544
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int N,h,m,s;
    scanf("%d",&N);

    h = N/3600;

    m = N % 3600/60;

    s = N % 60;

    printf("%d:%d:%d\n",h,m,s);

    return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#define INF 1000000
using namespace std;
int t[INF+100],tt[INF+100];

void DP(int *a, int x){
	for(int i = x;i <= INF;i++){
		a[i] = min(a[i],a[i-x]+1);
	}
}

int main(){
	int n;
	for(int i = 1;i <= INF;i++){
		t[i] = tt[i] = INF;
	}
	t[0] = tt[0] = 0;
	for(int i = 1;;i++){
		int a = (i*(i+1)*(i+2))/6;
		if(a > INF)break;
		DP(t,a);
		if(a%2 == 1){
			DP(tt,a);
		}
	}

	while(1){
		cin >> n;
		if(n == 0)break;
		cout << t[n] << " " << tt[n] <<endl;
	}
	return 0;
}

Measured memory_bytes: 8972
H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input()+'.')
s.append("."*(W+1))
# print(s)

flug = True
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            if not (s[i+1][j] == '#' 
                    or s[i-1][j] == '#' 
                    or s[i][j+1] == '#' 
                    or s[i][j-1] == '#'):
                flug = False
if flug:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 65368
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<int, int>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)
using namespace std;
ll n, w[111], v[111], Dp[111][100100], W;

ll Solve(int i, int wieght)
{
    if (i == n) return 0;

    ll &ret = Dp[i][wieght];
    if (ret != -1) return ret;

    ll C1 = 0, C2 = 0;
    if (wieght + w[i] <= W) C1 = Solve(i+1, wieght + w[i]) + v[i];
    C2 = Solve(i+1, wieght);

    return ret = max(C1, C2);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> W;
    for (int i=0; i<n; i++) cin >> w[i] >> v[i];

    memset(Dp, -1, sizeof Dp);
    ll Answer = Solve(0, 0);

    cout << Answer << '\n';
    return 0;
}


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

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

    int n;
    while(cin >> n){
        if(n == 0) break;
        vector<int> A(n);
        int total = 0;
        for(int i = 0; i < n; i++){
            cin >> A[i];
            total += A[i];
        }
        sort(A.begin(), A.end());
        int average = total / n;
        int cnt = 0;
        for(int i = 0; i < n; i++){
            if(A[i] <= average) cnt++;
            else break;
        }
        cout << cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    int diff = 0;
    for(int i=1; i<N; i++) {
        if(S[i] != S[i-1]) {
            diff++;
        }
    }
    int happy = N-1-diff;
    if(2 * K < diff) {
        cout << happy + 2 * K << endl;
    } else {
        cout << N - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int n, r;
    cin >> n >> r;

    cout << r + 100 * MAX(10 - n, 0) << "\n";

    return 0;
}



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

int main() {
  int m[50], f[50], r[50], cnt = 0;
  string res[50];
  while (true) {
    cin >> m[cnt] >> f[cnt] >> r[cnt];
    if (m[cnt] == -1 && f[cnt] == -1 && r[cnt] == -1) {
      break;
    } else {
      if (m[cnt] == -1 || f[cnt] == -1)
        res[cnt] = "F";
      else if (m[cnt] + f[cnt] >= 80)
        res[cnt] = "A";
      else if (m[cnt] + f[cnt] >= 65)
        res[cnt] = "B";
      else if (m[cnt] + f[cnt] >= 50)
        res[cnt] = "C";
      else if (m[cnt] + f[cnt] >= 30) {
        res[cnt] = "D";
        if (r[cnt] >= 50)
          res[cnt] = "C";
      }
      else
        res[cnt] = "F";
      cnt++;
    }
  }

  for (int i=0;i<cnt;i++)
    cout << res[i] << endl;
}



Measured memory_bytes: 3112
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int chmin(int tri1, int tri2, int tri3, int ans){
  return min(ans, max(tri1, max(tri2, tri3)) - min(tri1, min(tri2, tri3)));
}

//解説AC
ll H,W;
const int INF = 1e9;

ll solve(ll height, ll width){
  ll res = INF;
  ll smax, smin;
  ll sa, sb, sc;
  FOR(h, 1, height){
    sa = h*width;
    ll w = width/2;
    sb = w * (height - h);
    sc = (width - w) * (height - h);    
    smax = max(sa, max(sb, sc));
    smin = min(sa, min(sb, sc));
    res = min(smax-smin, res);

    sb = ((height-h)/2) * width;
    sc = height * width - sa - sb;
    smax = max(sa, max(sb, sc));
    smin = min(sa, min(sb, sc));
    res = min(smax-smin, res);    
  }
  return res;
}

int
main(void){  
  ios_base::sync_with_stdio(false);
  ll ans = 0LL;
  cin >> H >> W;
  if(H%3 == 0 || W%3 == 0){cout << 0 << endl; return 0;}
  ans = min(solve(H,W), solve(W,H));
  cout << ans << endl;
  
  return 0;
}


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

int main() {
    int a,b;
    cin >> a >> b;
    if (a>9 || b>9)
        cout << -1;
    else
        cout << a*b;

    return 0;
}


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

const int MAXN = 10;

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


int n;
int sx, sy;
int spx[12], spy[12];

bool dfs(int cx, int cy, int con) {
    //cout << cx << ", " << cy << " (" << con << ")" << endl;
    if (con == n) return true;
    for (int dir = 0; dir < 4; ++dir) {
        for (int bi = -1; bi <= 1; ++bi) {
            int nx = cx + dx[dir]*2 + bx[dir]*bi;
            int ny = cy + dy[dir]*2 + by[dir]*bi;
            if (nx < 0 || nx >= MAXN || ny < 0 || ny >= MAXN) continue;
            if (max( abs(nx-spx[con]), abs(ny-spy[con]) ) > 1 ) continue;
            if ( dfs(nx, ny, con+1) ) return true;
        }
    }
    return false;
}

int main() {
    while (cin >> sx >> sy >> n) {
        if (sx == 0 && sy == 0) break;
        for (int i = 0; i < n; ++i) cin >> spx[i] >> spy[i];
        if (dfs(sx, sy, 0)) puts("OK");
        else puts("NA");
    }
}


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


int main()
{
    ll n;
    cin>>n;
    string s;
    map<string,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        m[s]++;
    }
    ll cnt=0;
    for(auto it=m.begin(); it!= m.end();it++)
    {
        if(it -> second > 0)
            cnt++;
    }
    
    cout<<cnt<<"\n";
    
    return 0;
    
}

Measured memory_bytes: 19256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 300005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

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

	ll n;
	cin>>n;
	if(n>=30){
		cout<<"Yes";
	}
	else cout<<"No";

	return 0;	
}

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

#define forn(l, r) for(int i = l; i < (r); ++i)
#define forj(l, r) for(int j = l; j < (r); ++j)
#define TAM 1000100
#define SYNC ios::sync_with_stdio(0);
#define $ << ' ' <<
#define F first
#define S second
#define endl '\n'


using namespace std;

using ll = long long int;
using ii = pair<int, int>;
using vii = vector<ii>;
using vi = vector<int>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const int MAXN = 112345;
const ll mod = 1000000007;



int main()
{
    SYNC
    vector<string> vec;
    string s;
    int n, l;
    cin >> n >> l;
    while (n--) {
        cin >> s;
        vec.push_back(s);
    }
    sort(vec.begin(), vec.end());
    for (int i = 0; i < (int) vec.size(); ++i) {
        cout << vec[i];
    }
    cout << endl;


    return 0;
}


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

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())

// code
// ------------------------------------------------
int main() {

  string s;
  cin >> s;

  cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
int a,b;
while(true){
scanf("%d %d",&a,&b);
if(a==0) break;
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){

if((i+j)%2)printf(".");
else printf("#");

}
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 1000
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

const long long MaxN = int(3e5 + 5), inf = (1LL << 62);

long long n, m, a[MaxN], p[MaxN];

int main()
{
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	long long all = 0;
	for (int i = 1; i < n; i++)
	{
		long long l = a[i], r = a[i + 1];
		if (l > r)
			r += m;
		all += r - l;
		if (r - l > 1)
		{
			p[l + 1] += 1;
			p[r] -= (r - l + 1) - 1;
			p[r + 1] += (r - l + 1) - 2;
		}
	}
	for (int i = 2; i <= 2 * m; i++)
		p[i] += p[i - 1];
	for (int i = 2; i <= 2 * m; i++)
		p[i] += p[i - 1];
	long long ans = inf;
	for (int i = 1; i <= m; i++)
		ans = min(ans, all - p[i] - p[i + m]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3840
#include<stdio.h>
int main()
{
   char s[5];
   int i,c=0,j;
   gets(s);
    for(i=0;i<4;i++){
     for(j=0;j<4;j++){
        if(s[i]==s[j+1]){
            c++;
        }
        j++;
     }
 
     }
    if(c==4)
        printf("Yes\n");
        else
            printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
	int a,b,c;
	int x;
	cin>> a>>b>>c;
	if(a>b){
		x=a; 
		a=b; 
		b=x;
	}
	if(b>c){
		x=b;
		b=c;
		c=x;
	}
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}

Measured memory_bytes: 1164
fun main(args : Array<String>) { 
  var c = 0
  val state:MutableList<Int> = mutableListOf(0)
  readLine()
  readLine()!!.toList().map { x ->
    when(x) { 
      'D' -> c--
      'I' -> c++
    }
    state.add(c)
  }
  println(state.max())
}


Measured memory_bytes: 33560
from collections import defaultdict, deque
import sys
import heapq
import math

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def main():
    # N = int(input())
    N, M = [int(a) for a in input().split()]
    AB = [
        [int(a) for a in input().split()]
        for _ in range(N)
    ]

    # AB = sorted(AB, key=lambda it: it[1])

    ARR = [[] for _ in range(M + 1)]
    for a, b in AB:
        if a > M:
            continue
        ARR[a].append(b)
    # print("ARR", ARR)

    res = 0
    q = []
    for i in range(1, M + 1):
        current = ARR[i]
        for a in current:
            heapq.heappush(q, -a)
        if len(q) != 0:
            res -= heapq.heappop(q)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33648
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

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 N;
    cin >> N;
    vl a(N);
    ll res = 0;
    rep(i, 0, N) {
        ll a;
        cin >> a;
        if (a % 2 != 0) res++;
    }
    if (res % 2 != 0) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
int f[200005]={0};
int sz[200005]={0};
int n,m;
int ans=1;
int get(int x)
{
	if(x==f[x])return x;
	return f[x]=get(f[x]);
}
void merge(int x,int y)
{
	int xx=get(x);
	int yy=get(y);
	if(xx!=yy){
		f[xx]=yy;
		sz[yy]+=sz[xx];
		ans=max(ans,sz[yy]);
	}
	
}
void init()
{
	for(int i=1;i<=n;i++){
		f[i]=i;
		sz[i]=1;
	}
}
int main(){
    cin>>n>>m;
    init();
    while(m--){
    	int x,y;
    	cin>>x>>y;
    	merge(x,y);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5164
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a < b){
            System.out.println("a < b");
        }else if(a > b){
            System.out.println("a > b");
        }else if(a == b){
            System.out.println("a == b");
        }
    }
}


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

using namespace std;

const int MOD = 1e9 + 7;
const int LOG = 61;

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int n;
   cin >> n;
   vector<long long> a(n + 1 , 0LL);
   vector<vector<int> > dp(n + 1 , vector<int>(LOG , 0));
   for (int i = 1; i <= n; i++) {
      cin >> a[i];
      for (int j = 0; j < LOG; j++) {
         long long st = 1LL << j;
         bool bit = a[i] & st;
         if (bit)
            dp[i][j]++;
      }
   }
   for (int i = n - 1; i >= 1; i--) {
      for (int j = 0; j < LOG; j++) {
         dp[i][j] += dp[i + 1][j];
      }
   }
   long long ans = 0LL;
   for (int i = 1; i < n; i++) {
      for (int j = 0; j < LOG; j++) {
         long long st = (1LL << j);
         bool bit = a[i] & st;
         if (bit) {
            long long p = (1LL * ((n - i) - dp[i + 1][j]) * (st % MOD)) % MOD;
            ans += p % MOD;
            ans %= MOD;
         }
         if (!bit) {
            long long p = (1LL * dp[i + 1][j] * (st % MOD)) % MOD;
            ans += p % MOD;
            ans %= MOD;
         }
      }
   }
   cout << ans % MOD << '\n';
   return 0;
}


Measured memory_bytes: 84608
X, N = list(map(int, input().split()))
if N == 0:
  print(X)
  exit()
p = list(map(int, input().split()))
absp = []
for i in p:
  absp.append(i-X)
if not 0 in absp:
  print(X)
  exit()
for check in range(1,101):
  if not check*(-1) in absp:
    print(X-check)
    exit()
  if not check in absp:
    print(X+check)
    exit()

Measured memory_bytes: 9140
module.exports=function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,i){i(1)(i(3).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(t,e,i){var n=i(2);t.exports=function(t){for(var e=t[0].split(" "),i=Number(e[0]),r=Number(e[1]),s=[],o=0,u=new n(1),d=0;d<i;d++){for(var f=t[d+1].split(""),l=0;l<r;l++)"#"==f[l]?u.enq({x:l,y:d,dist:0}):o+=1;s.push(f)}for(;u.size>0;){var c=u.deq();if("."==s[c.y][c.x]||0==c.dist){if("."==s[c.y][c.x]&&(s[c.y][c.x]="#",o-=1),o<=0)return void console.log(c.dist);c.x+1<r&&"#"!=s[c.y][c.x+1]&&u.enq({x:c.x+1,y:c.y,dist:c.dist+1}),c.x-1>=0&&"#"!=s[c.y][c.x-1]&&u.enq({x:c.x-1,y:c.y,dist:c.dist+1}),c.y+1<i&&"#"!=s[c.y+1][c.x]&&u.enq({x:c.x,y:c.y+1,dist:c.dist+1}),c.y-1>=0&&"#"!=s[c.y-1][c.x]&&u.enq({x:c.x,y:c.y-1,dist:c.dist+1})}}}},function(t,e,i){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e4;this.size=0,this.items=[],this.ind=0,this.maxGap=t}enq(t){this.size+=1,this.items.push(t),this.items.size-this.ind>this.maxGap&&(this.items=this.items.slice(this.ind))}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}}},function(t,e){t.exports=require("fs")}]);

Measured memory_bytes: 200640
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = input()
    if S == "ABC":
        print("ARC")
    else:
        print("ABC")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9036
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long N,min=INT64_MAX,sum=0;
    cin >> N;
    vector<int>X(N);
    for(int i=0;i<N;i++){
        cin >> X[i];
    }
    sort(X.begin(),X.end());
    for(int i=1;i<X[N-1]+1;i++){
        for(int j=0;j<N;j++){
            sum += (X[j]-i)*(X[j]-i);
        }
        if(min == -1){
            min = sum;
        }else{
            if(min > sum){
                min = sum;
            }
        }
        sum=0;
    }
    cout << min;
}

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

using Graph = vector<vector<int>>;

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> p(N);
	for(int i=0; i<N; ++i) cin >> p[i];
	sort(p.begin(), p.end());
	int sum = 0;
	for(int i=0; i<K; ++i) sum += p[i];
	cout << sum << endl;
}

Measured memory_bytes: 3632
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]

for i in range(n):
    t = l[i][0]
    x = l[i][1]
    y = l[i][2]
    d = x + y
    if d <= t and (d - t) % 2 == 0:
        continue
    else:
        print('No')
        quit()
print('Yes')


Measured memory_bytes: 27300
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define For(i,x,y) for(int i = x; i <= y; ++i)
#define FOR For
#define rev_For(i,x,y) for(int i = x; i >= y; --i)
#define REV_FOR rev_For
#define ll long long
#define Size(v) ((int)v.size())
#define _section "\n--------------------\n"
#define fi first
#define se second
#define pb push_back
using namespace std;
// using namespace __gnu_pbds;


int n;

void input() {
	cin >> n;
}

void solve() {
	while (n) {
		int now = n % 10;
		if (now == 7) {
			cout << "Yes";
			return;
		}
		n /= 10;
	}

	cout << "No";
}

signed main() {
#ifdef _DEBUG
	// freopen("INPUT.inp", "r", stdin);
	//freopen("OUTPUT.out", "w", stdout);
	clock_t start, end;
	start = clock();
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//------------------------------------------------------------------------------------
//----------------------------------MAIN PROGRAM--------------------------------------
	int t = 1;
	while (t--) {
		input();
		solve();
	}
//--------------------------------------END-------------------------------------------
//------------------------------------------------------------------------------------
#ifdef _DEBUG
	end = clock();
	cerr << "\n----------\nTime Elapsed: " << fixed << double(end - start) / double(CLOCKS_PER_SEC) << setprecision(6) << '\n';
#endif
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>

int main(void) {
  int n;
  int count_AB = 0, count_xxxA = 0, count_Bxxx = 0, count_BxxA = 0;
  std::cin >> n;
  while (n-- > 0) {
    std::string s;
    std::cin >> s;
    if (s.front() == 'B' && s.back() == 'A') ++count_BxxA;
    else if (s.front() == 'B') ++count_Bxxx;
    else if (s.back() == 'A') ++count_xxxA;
    for (int i = 0; i < s.length() - 1; i++) {
      if (s[i] == 'A' && s[i+1] == 'B') ++count_AB;
    }
  }
  if (count_BxxA > 0) {
    if (count_xxxA > 0 || count_Bxxx > 0) {
      count_AB += count_BxxA;
    } else {
      count_AB += count_BxxA - 1;
    }
  }
  count_AB += std::min(count_xxxA, count_Bxxx);
  std::cout << count_AB;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }


class UnionFind{
private:
	vector<int> parent;
	vector<int> mem;
	vector<set<int>> mp;
	int compo;
	int N;
public:
	UnionFind(int n_){
		Initialize(n_);
	}
	
	void Initialize(int n_){
		N=n_;
		parent.resize(N);
		mem.resize(N);
		mp.resize(N);
		for(int i=0;i<N;i++){
			parent[i]=i;
			mem[i]=1;
			//mp[i].insert(i);
		}
		compo = N;
	}
	
	void SetMap(vector<int> v){
		for(int i=0;i<N;i++){
			mp[i].insert(v[i]);
		}
	}
	
	int Parent(int a){
		if(parent[a] == a)return a;
		return parent[a] = Parent(parent[a]);
	}
	
	bool IsUnited(int a, int b){
		return Parent(a) == Parent(b);
	}
	
	void Unite(int a, int b){
		a = Parent(a); b = Parent(b);
		if(a == b) return;
		if(mp[a].size() < mp[b].size()){
			parent[a] = b;
			mem[b] += mem[a];
			for(auto v : mp[a]) mp[b].insert(v);
		} else {
			parent[b] = a;
			mem[a] += mem[b];
			for(auto v : mp[b]) mp[a].insert(v);
		}
		compo -= 1;
	}
	
	bool IsRoot(int x){
		return x == parent[x];
	}
	int MemCnt(int x){
		return mem[Parent(x)];
	}
	
	int Compo(){
		return compo;
	}
	
	bool Find(int n, int trgt){
		return mp[Parent(n)].find(trgt) != mp[Parent(n)].end();
	}
	
};





int main(){
	
	int N,M;
	cin >> N >> M;
	vector<int> P(N);
	for(int i=0;i<N;i++){cin >> P[i]; P[i]--;}
	vector<int> X(M),Y(M);
	for(int i=0;i<M;i++){ cin >> X[i] >> Y[i]; X[i]--; Y[i]--;}
	
	UnionFind UF(N);
	UF.SetMap(P);
	for(int i=0;i<M;i++) UF.Unite(X[i], Y[i]);
	
	int cnt = 0;
	for(int i=0;i<N;i++) if(UF.Find(i, i)) cnt++;
	
	cout << cnt << endl;
	
    return 0;
}

Measured memory_bytes: 39544
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S_prime=readline().strip()
    T=readline().strip()

    U=list(S_prime)
    for i in range(len(U)):
        if U[i]=="?":
            U[i]="a"

    words=[]
    for i in range(len(S_prime)-len(T)+1):
        V=U[:]
        for j in range(i,i+len(T)):
            if S_prime[j]!=T[j-i]:
                if S_prime[j]!="?":
                    break
            V[j]=T[j-i]
        else:
            words.append("".join(V))

    words.sort()
    if len(words)>=1:
        print(words[0])
    else:
        print("UNRESTORABLE")

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
#define debug(V) rep(i, V.size()) cout << V[i] << " ";
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, m, n, t, r, k, w, l, ans, i, j;
string S, T;
vl A, B;
void solve() {
    a = 1e18;
    t = 1;
    rep(i, n) {
        if(A[i] <= a / t) {
            t *= A[i];
        } else {
            cout << -1 << endl;
            return;
        }
        if(t == 0) {
            cout << 0 << endl;
            return;
        }
    }
    cout << t << endl;
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) {
        cin >> x;
        A.pb(x);
    }
    sort(all(A));
    solve();
}

Measured memory_bytes: 4272
N,K = map(int,input().split())
S = list(str(input()))

info = [1]
cur = S[0]

for i in range(1,N):
    if S[i] == cur:
        info[-1] += 1
    else:
        info.append(1)
        cur = S[i]

if K * 2 + 1 >= len(info):
    print(N-1)
else:
    print(sum(info) - (len(info)-(2 * K + 1)) - 1)

Measured memory_bytes: 4648
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,x,b[N],l[N],r[N],id[N];
ll val[N],sum[N],tot=0;

bool cmp(int u,int v) {
	return val[u]>val[v];
}

bool check(ll mid) {
	int full=mid/x,rem=mid%x;
	for(int j=1,i;i=id[j],j<=n;j++) {
		ll tmp=tot;
		int y=l[i];
		if(rem>b[i]) y=r[i];
		tmp-=1ll*y*rem-1ll*(y-l[i])*b[i];
		if(j<=full) tmp-=sum[full+1]-val[i];
		else tmp-=sum[full];
		if(tmp<=0) return 1;
	}
	return 0;
}

int main() {
	cin>>n>>x;
	for(int i=1;i<=n;i++) b[i]=gi(),l[i]=gi(),r[i]=gi(),id[i]=i,val[i]=1ll*r[i]*x-1ll*(r[i]-l[i])*b[i],tot+=1ll*l[i]*b[i];
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+val[id[i]];
	ll l=0,r=1ll*x*n;
	while(l<r) {
		ll mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	cout<<l;
	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
#define fo(i,s,e_ex) for(i=s;i<e_ex;i++)
#define Fo(i,k,n) for(i=k;k<n?i<=n:i>=n;k<n?i+=1:i-=1)
#define endl '\n'
#define MOD 1000000007//998244353
#define pbb push_back
#define mpp make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define mset(arr,val) memset(arr,val,sizeof(arr))
ll arr[405],prefs[405];
ll dp[405][405];
ll suminrange(ll l,ll r){
    if(l==0) return prefs[r];
    return prefs[r]-prefs[l-1];
}
ll findAns(ll l,ll r){
    if(l==r) return 0;
    if(dp[l][r]>=0) return dp[l][r];
    ll i,ans=LLONG_MAX;
    for(i=l;i<r;i++){
        ll myans = suminrange(l,i) + suminrange(i+1,r) + findAns(l,i) + findAns(i+1,r);
        ans = min(ans,myans);
    }
    return dp[l][r]=ans;
}
void solve(ll caseno){
	ll i,j,n,ans;
    cin>>n;
    mset(dp,-1);
    for(i=0;i<n;i++) cin>>arr[i];
    prefs[0]=arr[0];
    for(i=1;i<n;i++) prefs[i]=arr[i]+prefs[i-1];
    ans = findAns(0,n-1);
    cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		solve(i);
	}
	return 0;
}


Measured memory_bytes: 4872
n = int(input())
a = list(map(int, input().split()))

def func(x):
	global a

	s = 0
	k = 0

	for i in a:
		s += i
		if s*x <= 0:
			k += abs(x-s)
			s = x
		x *= -1

	return k


print(min(func(1), func(-1)))

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int a, b; scanf("%d%d", &a, &b);
	int ans = -1;
	if(1 <= a && a <= 9 && 1 <= b && b <= 9) ans = a*b;
	printf("%d\n", ans);
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < (int) n; i++)
#define forin(i, a, b) for(int i = a; i < (int) b; i++) 
#define rofin(i, a, b) for(int i = a; i > b; i--)
#define v vector
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define debug(i) cout << #i << ": " << i << endl
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

int main() {
    crap;
    int n;
    cin >> n;
    ll sum = 0;
    forin(i, 1, n + 1) {
        if(i % 3 != 0 && i % 5 != 0) {
            sum += (ll)i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define d double
using namespace std;
int main(){
  int n;
  cin>>n;
  double a[n],b[n];
  double v,ans=0;
  for(int i=0;i<n;i++){
    cin>>v;
    a[i]=1/v;
  }
  for(int i=0;i<n;i++){
    ans+=a[i];}
  ans=1/ans;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>
 
struct task {
    intmax_t A;
    intmax_t B;
};
 
int compareB (const void *a, const void *b)
{
    if(((struct task *)a)->B <= ((struct task *)b)->B)
        return -1;
    if(((struct task *)a)->B > ((struct task *)b)->B)
        return 1;
}
 
int main (int argc, char const *argv[])
{
    intmax_t N;
    struct task task[(int)2e5];
    intmax_t time = 0, ans = 0;
 
    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd%jd", &task[i].A, &task[i].B);
    }
 
    qsort(task, N, sizeof(struct task), compareB);
 
    for (intmax_t i = 0; i < N; i++) {
        time += task[i].A;
        if (time > task[i].B) {
            puts("No");
            return 0;
        }
    }
 
    puts("Yes");
 
    return 0;
}

Measured memory_bytes: 6524
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/11/20 19:53:47
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  vector<int> A(n); for (auto& a:A) cin>>a;
  int ans = 0;
  for (int i = 0; i < n; i+=2) {
    if (A[i] % 2 == 1)
      ans++;
  }
  cout << ans << endl;

  return 0;
}


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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int n, k;
    cin >> n >> k;
    vector <int> a(k);
    for (int i = 0; i < k; i++) {
        cin >> a[i];
    }

    for (int i = n; i >= 0; i++) {
        int tmp = i;
        bool ok = true;
        while (tmp) {
            int x = tmp % 10;
            for (int j = 0; j < k; j++) {
                if (a[j] == x) ok = false;
            }
            tmp /= 10;
        }
        if (ok) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int main(){
  int n;
  cin>>n;
  vector<int> ps;
  {
    int tmp = n;
    for(int x=2;x*x<=tmp;x++)if(tmp%x==0){
      ps.push_back(x);
      while(tmp%x==0)tmp/=x;
    }
    if(tmp>1)ps.push_back(tmp);
  }

  // ans = all - #{1 <= x <= n | OR_i (x % a[i] == 0)}
  int m = ps.size();
  int cnt = 0;
  FOR(msk,1,1<<m){
    int lcm = 1;
    REP(i,msk)if((msk>>i)&1)lcm*=ps[i];
    int mul = __builtin_popcount(msk)%2==1 ? 1 : -1;
    cnt += mul * (n / lcm);
  }
  printf("%d\n", n-cnt);
  return 0;
}



Measured memory_bytes: 3300
#include <stdio.h>

int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  int ans=a+b;
  if(ans%2!=0)
  {  
  if(a<=(ans/2+1) && b<=(ans/2+1))
      printf("Yay!");
  
  else
      printf(":(");
  }
  
  else
  { if(a<=(ans/2) && b<=(ans/2))
      printf("Yay!");
  
  else
      printf(":(");
  }
}

Measured memory_bytes: 128
N = int(input())
if N <10:
  print(N)
elif N >=10 and N<100:
  print(9)
elif N>=100 and N<1000:
  print(9+(N-99))
elif N >= 1000 and N<10000:
  print(9+900)
elif N >= 10000 and N<100000:
  print(9+900+(N-9999))
else:
  print(9+900+90000)



Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

constexpr int m = 2019;

int main() {
	int ans = 0, d = 1, t = 0;
	string s;
	vector<int>dp(2020, 0);
	dp[0]++;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		t += d * (s[s.size() - 1 - i] - '0');
		t %= m;
		dp[t]++;
		d *= 10;
		d %= m;
	}
	for (int i = 0; i < 2019; i++) {
		ans += (dp[i] - 1) * dp[i] / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3772
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int y = scn.nextInt();
		boolean flg = false;
		//		int cnt1=0;
		//		int cnt5=0;
		//		int cnt10=0;
		if (y % 1000 == 0) {
			for (int i = 0; i <= n && flg==false; i++) {
				for (int j = 0; j <= n - i; j++) {
					if (i * 10 + j * 5 + (n - i - j) == y / 1000) {
						flg = true;
						System.out.println(i + " " + j + " " + (n - i - j));
						break;
					}
				}
			}
		}
		if (flg == false) {
			System.out.println("-1 -1 -1");
		}
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//BEGIN CUT HERE
struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
//END CUT HERE

signed main(){
  int n,m;
  int d;
  cin>>n>>m;
  vector<int> p(n);
  rep(i,n){
  //  cin>>d;
   // p.at(i) = d-1;
    cin>>p.at(i); p.at(i)--;
   
  }


  UnionFind uf(n);
  rep(i,m){
    int x,y;
    cin>>x>>y;
    uf.unite(x-1,y-1);
  }
  int c=0;
  rep(i,n){
    if(uf.same(i,p.at(i))) c++;
  }
  cout << c << endl;

}




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


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

struct edge {int to; ll cost; };

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

ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b){
  if(a<b) swap(a,b);
  return a*b/gcd(a,b);
}
 
int main(){
  ll a, b;
  cin >> a >> b;
  ll ans = lcm(a, b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#define int long long
using namespace std;

int gcm(int a, int b) {
  int aa = a, bb = b;
	if(a<b){
    int x;
    x = a;
    a = b;
    b = x;
  }
  int y = a % b;
  while(y!=0){
    a = b;
    b = y;
    y = a % b;
  }
  return bb * (aa / b);
}

signed main(){
  int T;
  int N;
  cin >> N;
  int score=1;
  for(int i=0;i<N;i++){
    cin >> T;
    score = gcm(score,T);
  }
  cout << score << endl;
}

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

int main() {
	//int Ans=0;
	int R,G,B;
	int K;
	cin>>R>>G>>B>>K;

	while (G<=R) {
		K--;
		G*=2;
		if (K<0){
			cout<<"No"<<'\n';
			return 0;
		}
	}
	while (B<=G) {
		K--;
		B*=2;
		if (K<0){
			cout<<"No"<<'\n';
			return 0;
		}
	}
	cout << "Yes" << '\n';
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>

int main(){
	std::string hats;
	int N;
	int redCnt = 0,BlueCnt = 0;

	std::cin>>N;
	std::cin>>hats;

	for(int i=0;i<N;++i){
		if(hats[i] == 'R'){
			redCnt++;
		}else if(hats[i] == 'B'){
			BlueCnt++;
		}
	}
	if(redCnt > BlueCnt){
		std::cout<<"Yes"<<std::endl;
	}else{
		std::cout<<"No"<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#define int long long
using namespace std;
 
const int INF = 1e12;
const int MAX_V = 1000000;
 
int V;
vector <pair<int,int> >  G[MAX_V];
int d[MAX_V];
 
void dijkstra(int s) {
    typedef pair<int,int> pii;
    priority_queue<pii, vector<pii>, greater<pii> > que;
    for (int i = 0; i < V; i++) {
        d[i] = INF;
         
    }
    d[s] = 0;
    que.push(pii(0, s));
    while (!que.empty()) {
        pii p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)continue;
        for (int i = 0; i < G[v].size(); i++) {
            pair<int, int> e = G[v][i];
             
            if (d[e.first] > d[v] + e.second) {
                d[e.first] = d[v] + e.second;
                que.push(pii(d[e.first], e.first));
                 
            }
        }
    }
}
signed main() {
    int E, r;
    cin >> V >> E >> r;
    int s, t, a;
    for (int i = 0; i < E; i++) {
        cin >> s >> t >> a;
        G[s].push_back( make_pair(t, a));
    }
    dijkstra(r);
    for (int i = 0; i < V; i++) {
        if (d[i] >= INF) {
            cout << "INF" << endl;
        }
        else {
            cout << d[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 40504
#include<stdio.h>
#include<stdlib.h>

int main(){

	int A;
	int B;
	int ans;

	scanf("%d %d", &A, &B);

	ans = A-2*B;
	
	if ( ans >= 0 ){
		printf("%d", ans);
	}else{
		printf("0");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    
    int count=0;
    while(A>=B){
        B*=2;
        
        count++;
    }
 
    while(B>=C){
        C*=2;
        count++;
    }
    
  
    if(count<=K)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

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

int main(void){
    ll N, Q, sum = 0;
    string S;
    cin >> N >> Q >> S;
    vector<ll> count_ac(N);
    for(int i=0; i<N-1; i++){
        if(S.at(i)=='A' && S.at(i+1)=='C'){
            sum++;
        }
        count_ac[i+1] += sum;
    }
    for(int i=0; i<Q; i++){
        ll l, r;
        cin >> l >> r;
        cout << count_ac[r-1] - count_ac[l-1] << endl;
    }
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
	int ans=0,A, B, C, D;
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;
	if (A > B){
		ans += B;
	}
	else{
		ans += A;
	}
	if (C > D){
		ans += D;
	}
	else{
		ans += C;
	}
	cout << ans<<endl;
}

Measured memory_bytes: 256