akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

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

    map<string, long long> m;
    for(int i=1; i<=N; i++){
        string s=to_string(i);
        string top = {s[0]};
        string bottom {s[(int)s.size()-1]};
        m[top+bottom]++;
    }

    long long ans=0;
    for(auto c:m){
        if(c.first[1]=='0')continue;

        string tmp = "  ";
        copy(c.first.begin(), c.first.end(), tmp.begin());
        reverse(tmp.begin(), tmp.end());
        if(m.count(tmp)==0)continue;

        long long val1 = c.second;
        long long val2 = m[tmp];
        ans+=val1*val2;
        //cout << c.first << ' ' << c.second << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,a[36],a1[36],a2[36];
char c[36],c1[36],c2[36];

void BubbleSort(){
  for(int i=0;i<n;i++)
    for(int j=n-1;j>=i+1;j--){
      if(a1[j]<a1[j-1]){
	int t=a1[j];
	a1[j]=a1[j-1];
	a1[j-1]=t;
	char t2=c1[j];
	c1[j]=c1[j-1];
	c1[j-1]=t2;
      }
    }
}

void SelectionSort(){
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(a2[j]<a2[minj]){
	minj=j;
      }
    }
    int t=a2[i];
    a2[i]=a2[minj];
    a2[minj]=t;
    char t2=c2[i];
    c2[i]=c2[minj];
    c2[minj]=t2;
  }
}

bool isStable(char *x,int *y){
  for(int i=1;i<=9;i++){
    int start=0;
    for(int j=0;j<n;j++){
      if(i!=a[j])continue;
      for(int k=start;k<n;k++){
	if(i!=y[k])continue;
	if(c[j]!=x[k])return false;
	start=k+1;
	break;
      }
    }
  }
  return true;
}

void output(char *x,int *y){
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<x[i]<<y[i];
  }
  cout<<endl;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>c[i]>>a[i];
    c1[i]=c2[i]=c[i];
    a1[i]=a2[i]=a[i];
  }
  BubbleSort();
  output(c1,a1);
  if(isStable(c1,a1))cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  SelectionSort();
  output(c2,a2);
  if(isStable(c2,a2))cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  return 0;
}


Measured memory_bytes: 3108
N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")

all_case = r*g*b

excluded_case = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]: continue
        k = j*2-i
        if k>= N or S[k] == S[i] or S[k] == S[j]: continue
        excluded_case += 1

print(all_case-excluded_case)


Measured memory_bytes: 9196
#include "bits/stdc++.h"

using namespace std;

int main() {
	int N, A;
	int H[999];
	double T;
	cin >> N >> T >> A;
	double b = 10000000;
	int ans;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
		if (b > abs(A - (T - H[i] * 0.006))) {
			b = abs(A - (T - H[i] * 0.006));
			ans = i + 1;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools
def calc_num(S,S_len):
    result = 0;
    l = [3,5,7];
    i = 3;
    while i <= S_len:
      for v in itertools.product(l,repeat=i):
        if int("".join(map(str, v))) <= S and list(set(v) & set(l)) == l: 
          result = result + 1;
      i = i + 1;
    return result
  
S = list(map(int,input()))
S_len = len(S);
S = int("".join(map(str, S)));
result = calc_num(S,S_len);
print(result)

Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
#include <vector>

const int MAX_W = 1e5;

std::vector<long long> maxV(1 + MAX_W, 0);

int main() {
  int n, W;
  scanf("%d%d", &n, &W);
  maxV[0] = 0;
  for (int i = 0; i < n; i++) {
    int w, v;
    scanf("%d%d", &w, &v);
    for (int w0 = W - w; w0 >= 0; w0--)
      maxV[w0 + w] = std::max(maxV[w0 + w], maxV[w0] + v);
  }
  long long answer = 0;
  for (int w = 0; w <= W; w++)
    answer = std::max(answer, maxV[w]);
  printf("%lld\n", answer);
  return 0;
}


Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<char>>();
    let t = read::<String>().chars().collect::<Vec<char>>();
    let mut ans = 0;
    for i in 0..3 {
        if s[i] == t[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll inf  = 1e7+5;

void dfs(int n, int m, int dist);
bool visited [inf];
int dist[inf];
int main() {
  int a,b,c; cin >> a >> b >> c;
  cout << c << " " << a << " " << b;
}



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

using namespace std;
typedef long long ll;
ll n,m,v,p,a[200001];
bool ok(int poz)
{
    ll nr=a[poz]+m;
    ll nrop=m*(v-1);
    ll nrmari=0;
    for(int i=1;i<=n;i++)
        if(a[i]>nr&&i!=poz)
        {
            nrop-=m;
            nrmari++;
        }
    for(int i=1;i<=n;i++)
        if(a[i]<=nr&&i!=poz)
        {
            ll dif=nr-a[i];
            nrop-=min(dif,m);
        }
    for(int i=n;i>=1&&nrmari<p-1;i--)
    {
        if(i!=poz)
        {
            ll dif=nr-a[i];
            if(dif<=m&&dif>=0)
            {
                nrop-=(m-dif);
                nrmari++;
            }
        }
    }
    if(nrmari<=p-1&&nrop<=0)
        return 1;
    return 0;
}
int main()
{
    cin>>n>>m>>v>>p;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    int st=1;
    int dr=n;
    int pozmin=n+1;
    //cout<<ok(3)<<'\n';
    while(st<=dr)
    {
        int mij=(st+dr)/2;
        if(ok(mij))
        {
            if(mij<pozmin)
                pozmin=mij;
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    cout<<n-pozmin+1;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9 + 7
int main(){
    int n;
    cin>>n;
    vector<int>h(n);
    for(int i =0;i<n;i++){
        cin>>h[i];
    }
    vector<int> dp (n, INF);
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(auto j:{i+1,i+2}){
            if(j<n){
                dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i, n)cin >> w.at(i);
    ll ans = inf, num[n];
    num[0] = w[0];
    REP(i, n-1){
        num[i] = num[i-1]+w[i];
        ans = min(ans, abs(accumulate(all(w), 0LL)-num[i]-num[i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
// #define fi first
// #define se second
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};

/*--------------------------------------------------------------------------------

--------------------------------------------------------------------------------*/

// 1 <= k <= n <= 10^7　程度

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();

    ll n; cin >> n;
    ll ans = 0;
    Rep(i, 1, n/3){
        ans += COM(n-2*i-1, i-1);
        ans %= MOD;
    }
    cout << ans << endl;
}

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

#define INF int(100100)

int main(){
    while(1){
        int n,m;
        cin >> n >> m;
        
        if(n==0&&m==0)  break;          //終了の判断

        int time[m][m],cost[m][m];

        for(int i=0;i<m;i++){           //配列の初期化
            for(int j=0;j<m;j++){
                if(i==j)
                    time[i][j] = cost[i][j] = 0;
                else
                    time[i][j] = cost[i][j] = INF;
            }
        }

        for(int i=0;i<n;i++){           //配列の設定
            int a,b,c,t;
            cin >> a >> b >> c >> t;
            time[a-1][b-1] = time[b-1][a-1] = t;
            cost[a-1][b-1] = cost[b-1][a-1] = c;
        }

        for(int k=0;k<m;k++){           //最短距離に書き換え
            for(int i=0;i<m;i++){
                for(int j=0;j<m;j++){
                    if(time[i][j]>(time[i][k]+time[k][j]))
                        time[i][j] = time[i][k]+time[k][j];
                    if(cost[i][j]>(cost[i][k]+cost[k][j]))
                        cost[i][j] = cost[i][k]+cost[k][j];
                }
            }
        }

        int k;  cin >> k;       
        for(int i=0;i<k;i++){           //表示
            int p,q,r;
            cin >> p >> q >> r;

            if(r==1){
                cout << time[p-1][q-1] << endl;
            }else{
                cout << cost[p-1][q-1] << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3164
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n < 0)
            return 0;

        vector<char> c(n);
        vector<int> ly(n), lx(n);
        for(int i=0; i<n; ++i)
            cin >> c[i] >> lx[i] >> ly[i];

        int y = 1;
        int x = 3;
        int d = 0;
        for(;;){
            y += dy[d];
            x += dx[d];

            bool isMirror = false;
            for(int i=0; i<n; ++i){
                if(c[i] == 'x'){
                    if(y == 4*ly[i] && 4*lx[i] <= x && x <= 4*(lx[i]+1)){
                        d ^= 3;
                        isMirror = true;
                    }
                }else{
                    if(x == 4*lx[i] && 4*ly[i] <= y && y <= 4*(ly[i]+1)){
                        d ^= 1;
                        isMirror = true;
                    }
                }
            }

            if(!isMirror && ((y == 1 && x == 3) || y == 0 || y == 32 || x == 0 || x == 32)){
                y *= 25;
                x *= 25;
                cout << x << ' ' << y << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 1204
n=int(input())
a=0
b=0
ab=0
num=0
for i in range(n):
    s=input()
    if s[0]=="B" and s[-1]=="A":
        ab+=1
    elif s[0]=="B":
        b+=1
    elif s[-1]=="A":
        a+=1
    for j in range(len(s)-1):
        if s[j]=="A" and s[j+1]=="B":
            num+=1
if a!=0 and b!=0:
    num+=ab+1
    a-=1
    b-=1
    num+=min(a,b)
elif a!=0:
    num+=ab
elif b!=0:
    num+=ab
else:
    num+=max(0,ab-1)
print(num)


Measured memory_bytes: 9172
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <tuple>

using namespace std;

using int64 = long long;

const int64 INF = (1LL<<60);

int main() {
    string S;
    cin >> S;

    bool ok = true;

    for (int i = 0; i < S.size(); i++) {
        if ((i & 1) && S[i] != 'i')
            ok = false;
        if (!(i & 1) && S[i] != 'h')
            ok = false;
    }

    if (S.size() & 1)
        ok = false;

    cout << (ok ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
H = H + 2
W = W + 2
grid = '#' * W
for i in range(H-2):
    grid += '#' + input() + '#'
grid += '#' * W

def bfs(start):
    INF = 10**9
    dist = [INF] * (H*W)
    dist[start] = 0
    q = deque([start])
    while q:
        v = q.popleft()
        dv = dist[v]
        for move in (-1, 1, W, -W):
            w = v + move
            if grid[w] == '#':
                continue
            dw = dv + 1
            if dw >= dist[w]:
                continue
            dist[w] = dw
            q.append(w)

    return max(x for x in dist if x < INF)

answer = max(bfs(v) for v in range(H*W) if grid[v]!='#')
print(answer)



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

N,K = map(int, input().split())
A = list(map(int, input().split()))

def num_cut(L):
  result = 0
  for a in A:
    result += a//L
    if a%L == 0:
      result -= 1
  return result

m = 0
M = 10**9

while M-m>1:
  X = (m+M)//2
  if num_cut(X)>K:
    m = X
  else:
    M = X

print(M)

Measured memory_bytes: 30908
#include <iostream>
#include <cstring>
using namespace std;
int  nr_s, nr_t, i, j, nr, mini=1001, cont;
char s[1001], t[1001];

int main()
{
    cin.getline(s+1, 1001);
    nr_s=strlen(s+1);
    cin.getline(t+1, 1001);
    nr_t=strlen(t+1);

    for(i=1; i<=(nr_s-nr_t+1); i++)
    {
        cont=0;
        nr=1;
        for(j=i; j<=(i+nr_t-1); j++, nr++)
            if(s[j]!=t[nr]) cont++ ;

        if(cont<mini) mini=cont;

    }
    cout<<mini;

    return 0;
}


Measured memory_bytes: 3568
require 'rational'

A, B, C, D = gets.split.map(&:to_i)

range = B - A + 1
sum_val = 0
[C, D].each do |val|
  sum_val += range / val
  sum_val += 1 if (A - 1) / val < B / val - range / val
end

val = C.lcm(D)
sum_val -= range / val
sum_val -= 1 if (A - 1) / val < B / val - range / val

puts range - sum_val

Measured memory_bytes: 1788
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

cmdPrint s a b = putStrLn . drop a . take (b+1) $ s
cmdReverse s a b = take a s ++ (reverse .drop a . take (b+1) $ s) ++ drop (b+1) s
cmdReplace s a b p = take a s ++ p ++ drop (b+1) s

exec :: String -> [[String]] -> IO ()
exec s [] = return ()
exec s (["print", a, b]:cs) = cmdPrint s (read a) (read b) >> exec s cs
exec s (["reverse", a, b]:cs) = exec (cmdReverse s (read a) (read b)) cs
exec s (["replace", a, b, p]:cs) = exec (cmdReplace s (read a) (read b) p) cs

main = do
    s <- getLine
    q <- readLn
    cs <- map words <$> replicateM q getLine
    exec s cs

Measured memory_bytes: 5680
def pow(x, n):
    ans = 1
    while n:
        if n % 2:
            ans = ans * x % 1000000007
        x *= x % 1000000007
        n >>= 1
    return ans % 1000000007

s = input()
n, a, b = s.split()
n, a, b =  int(n), int(a), int(b)


a0 = 1
a1 = 1 
for i in range(1, a+1):
  a0 = a0 * (n - i + 1) % 1000000007
  a1 = a1 * i % 1000000007

b0 = 1
b1 = 1 
for i in range(1, b+1):
  b0 = b0 * (n - i + 1) % 1000000007
  b1 = b1 * i % 1000000007

A = (pow(2, n) - 1 - a0 * pow(a1, 1000000005) - b0 * pow(b1, 1000000005)) % 1000000007

print(A)


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

int main(){
	 int a, b, c;
     cin>>a>>b>>c;
     int temp;
     temp = a;
     a = b;
     b = temp;
     temp = a;
     a = c;
     c = temp;
     cout<<a<<" "<<b<<" "<<c;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

A,B,E = map(int,sys.stdin.readlines())

S = 3 * E
H = S-B-E
I = S-A-E
C = S-A-B
G = S-C-E
D = S-A-G
F = S-C-I

print(A,B,C)
print(D,E,F)
print(G,H,I)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
long long x,a,b,c,ans=0,sum=0;
int main()
{
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++)
    {
        for(int j=0;j<=b;j++)
        {
            for(int k=0;k<=c;k++)
            {
                sum=500*i+100*j+50*k;
                if(sum==x)
                    ans++;
            }
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
ll a,b,c,d;
cin>>a>>b>>c>>d;

cout<<max(a*c,max(a*d,max(b*c,b*d)));

return 0;
}






ll gcd(ll a, ll b){

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

}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long int
#define fi first
#define se second
#define opti ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const ll N = 1e5+6;
ll t,i,j,k,n,m,q;

int main()
{
    opti
    cin>>n;
    ll c[n+1],s[n+1],f[n+1];
    for(i=1;i<n;i++)
    {
        cin>>c[i];
        cin>>s[i];
        cin>>f[i];
    }
    ll ans[n+1];
    memset(ans,0,sizeof(ans));
    for(i=1;i<=n-1;i++)
    {
        ll tim = 0;
        for(j=i;j<=n-1;j++)
        {
            if(tim <=  s[j])
            {
                tim += (c[j]+s[j] - tim);
            }
            else
            {
                ll curr = s[j];
                while(curr<tim)
                {
                    if(curr + f[j]>=tim)
                    {
                        tim += (curr + f[j] - tim);
                        break;
                    }
                    curr += f[j];
                }
                tim += c[j];
            }
        }
        ans[i] = tim;
    }
    for(i=1;i<=n;i++)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define CF {std::cout<<"First\n";return 0;}
#define CS {std::cout<<"Second\n";return 0;}
std::string s;
int main(){
    std::cin>>s;int l=s.size();
    if(s[0]==s[l-1])if(l%2)CS else CF
    else if(l%2)CF else CS
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

ll N, M;
vector<int> to[100010];
int idx[100010];
int edge[100010];
int node[100010];
int oe[100010];
int judge[100010];
int es[200010];
ll ans = 0;

void dfs(int v, int id, int type){
    idx[v] = id;
    node[id]++;
    oe[v] = type;
    for(auto u : to[v]){
        if(idx[u] != 0){
            if(oe[u] == type) judge[id] = true;
        }else{
            dfs(u, id, (type + 1) & 1);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M;
    ans = N * N;

    for(int i = 0; i < M; i++){
        int u, v;
        cin >> u >> v;
        es[i] = u;
        to[u].emplace_back(v);
        to[v].emplace_back(u);
    }

    int id = 1;
    for(int i = 1; i <= N; i++){
        if(idx[i] == 0) dfs(i, id++, 0);
    }
    for(int i = 0; i < M; i++){
        edge[idx[es[i]]]++;
    }
    ll nsum = 0, graph = 0, oc = 0;
    for(int i = 1; i < id; i++){
        if(node[i] == 1) continue;
        nsum += node[i];
        graph++;
        if(!judge[i]) oc++;
    }
    cout << ans - (nsum * nsum) + (graph * graph) + (oc * oc) << endl;
    return 0;
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
int n,l[201],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;++i)scanf("%d",&l[i]);
	sort(l+1,l+n+n+1);
	for(int i=1;i<=n+n;i+=2)ans+=l[i];
	printf("%d\n",ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();
		int x = 0;
		int flg = 0;
		for(int i = 1;i <= num;i++)
		{
			x = i;
			if(x % 3 == 0)
			{
				System.out.print(" " + i);
			}else{
				flg = 0;
				while(x > 0 && flg == 0)
				{
					if(x % 10 == 3)
					{
						System.out.print(" " + i);
						flg = 1;
					}
					x /= 10;
				}
			}
			
		}
		System.out.println("");
	}
}

Measured memory_bytes: 24284
N,M,X=map(int, input().split())

import numpy as np

A=[]
B=[]

for i in range(N):
  A.append(list(map(int,input().split())))


C=[]
temp=[0 for i in range(N)]

for i in range(2**N):
  for j in range(N):
    if (i >> j) & 1:
      temp[j]=1
    else:
      temp[j]=0
  tempE=[0 for i in range(M+1)]
  for k in range(N):
    x = np.array(tempE)
    y = np.array([A[k][j]*temp[k] for j in range(M+1)])
    tempE=x+y
  C.append(tempE)


tempC=float('inf')
for i in range(2**N):
  tempD=min(C[i][1:M+1])
  if tempD>=X:
    tempC=min([tempC,C[i][0]])

if tempC==float('inf'):
  tempC=-1

print(tempC)

Measured memory_bytes: 28068
#include <stdio.h>
#define max 100

inline int summax(int a[], int x, int n) {
    int rez = 0;
    for (int i = 1; i <= n; i++) {
        rez += (x - a[i]) * (x - a[i]);
    }
    return rez;
}

int a[max+1];

int main() {
    int n, minn;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    minn = summax(a, -100, n);
    for (int i = -99; i <= 100; i++) {
        int sum = summax(a, i, n);
        if (sum <= minn) minn = sum;
    }
    printf("%d", minn);
    return 0;
}


Measured memory_bytes: 128
# include <iostream>
# include <cstdio>
# include <cstring>
using namespace std;
const int N = 5e2 + 12;
long long d[N][N],f[4][N],ans = 1e18;int c[N][N];
int n,C,que[5];
void dfs(int tot)
{
	if(!tot)
	{
		long long tmp = 0;
		for(int i = 0;i < 3;i++)
		tmp += f[i][que[i]];
		ans = min(ans,tmp);
		return;
	}
	for(int i = 1;i <= C;i++)
	{
		bool f = true;
	 for(int j = 2;j >= tot;j--)
	 if(que[j] == i)f = false;
	 if(f)que[tot - 1] = i,dfs(tot - 1);
    }
}
int main()
{
	scanf("%d %d",&n,&C);
	for(int i = 1;i <= C;i++)
	 for(int j = 1;j <= C;j++)
	 scanf("%lld",&d[i][j]);
	 for(int i = 1;i <= n;i++)
	  for(int j = 1;j <= n;j++)
	  scanf("%d",&c[i][j]);
	 for(int k = 1;k <= C;k++)
	  for(int l = 0;l < 3;l++)
	  for(int i = 1;i <= n;i++)
	   for(int j = 1;j <= n;j++)
	   if((i + j) % 3 == l)
	   f[l][k] += d[c[i][j]][k];
	 dfs(3);
	 printf("%lld\n",ans);
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 10005

using namespace std;

int main()
{
    string str1,str2;

    cin>>str1>>str2;

    ll len1=str1.length();
    ll len2=str2.length();

    if(len1==len2)
    {
        if(str1>str2)
            printf("GREATER\n");

        else if(str2>str1)
            printf("LESS\n");

        else
            printf("EQUAL\n");
    }

    else if(len1>len2)
        printf("GREATER\n");

    else
        printf("LESS\n");

    return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,y;
int main(){
	cin>>n>>y;
	for(int i=0;i<=n;i++){
	    for(int j=0;j<=n;j++){
			    int z=n-i-j;
				if(z>=0){
					if(i*10000 + j*5000 + z*1000 == y){
						cout<<i<<' '<<j<<' '<<z;
						return 0;
					}
				}
			}
	}
	cout<<-1<<' '<<-1<<' '<<-1;
	return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a<=c)&&(c<=b)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <vector>

using namespace std;
int main(){
  string S;
  cin >> S;
  if (S.length() == 1){
    cout << 0 << endl;
    return 0;
  }
  int counter = 0;
  for (int i = 1; i < S.length(); i++){
    if (S[i] != S[i-1]){
      counter++;
    }
  }
  cout << counter << endl;
  return 0;
}


Measured memory_bytes: 512
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	// 入力
	int N;
	string S;
	cin >> N >> S;

	int ans = 0;
	REP(i, 1000) {
		int keta[3];
		keta[2] = i % 10;
		keta[0] = i / 100;
		keta[1] = (i - keta[0] * 100 - keta[2]) / 10;

		int ketaCnt = 0;
		REP(j, N) {
			if (keta[ketaCnt] == S[j] - '0') {
				ketaCnt++;
				if (ketaCnt == 3) {
					ans++;
					break;
				}
			}
		}
	}

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


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

#define pb push_back
#define F first
#define S second
#define fo(i,a,b)  for(int i = a; i < b; i++)

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ReadFile            freopen("input.in","r",stdin)
#define WriteFile           freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f;
const ld EPS = 1e-7;
double Pi=acos(-1);
const ld rad=Pi/180.0;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll nCr (ll n,ll m)
{
        return(m == 0)?1:n*nCr(n-1,m-1)/m;
}
/*****************************************************/


int main()
{
    int n;
    cin >> n;
    vector <int> vec(n);
    vector <int> vec2(n);
    vector <int> vec3(n);
    for(int i = 0; i < n; ++i)
        cin >> vec[i];
    vec2 = vec;

    sort(vec2.begin() , vec2.end());

    for(int i = 0; i < n; ++i)
        vec3[i] = abs(vec2[i] - vec[i]);

    for(int i = 0; i < n; ++i){
        if(vec3[i] > 1){
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 1408
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

//つねに10億7などの剰余をとる構造体
//参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858
//参考: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
int mod  = MODA;
struct modint {
	ll x;
	modint (ll x):x(x%mod){}
	modint& operator+=(const modint a){
		(x += a.x ) %= mod;
		return *this;
	}
	modint& operator-=(const modint a){
		(x -= a.x ) %= mod;
		if (x < 0) x += mod;
		return *this;
	}
	modint& operator*=(const modint a){
		(x *= a.x ) %= mod;
		return *this;
	}
	modint& operator/=(modint a){ //除算のみO(log mod)なので注意。割る数が小さいならnCrのinvを使うこと
		ll exp = mod - 2;
		while(exp > 0){ 
			if(exp & 1) *this *= a.x;
			a *= a.x;
			exp >>= 1;
		}
		return *this;
	}
	modint operator+(const modint a) const{
		modint res(*this);
		return res+=a;
	}
	modint operator-(const modint a) const{
		modint res(*this);
		return res-=a;
	}
	modint operator*(const modint a) const{
		modint res(*this);
		return res*=a;
	}
	modint operator/(const modint a) const{
		modint res(*this);
		return res/=a;
	}
};
modint modpow(modint x, ll n){
	modint res=1;
	while(n > 0){
		if(n & 1) res = res * x.x;
		x = x * x;
		n >>= 1;
	}
	return res;
}

int main() {
	modint ans = 1;
	int tmp;
	int n;
	cin >> n;
	vector<int> t(n+2);
	REP1(i, n) cin >> t[i];
	t[0] = 0; t[n+1] = 0;
	vector<int> a(n+2);
	REP1(i, n) cin >> a[i];
	a[0] = 0; a[n+1] = 0;
	int tma[n+1] = {}, tmi[n+1] = {}, ama[n+1] = {}, ami[n+1] = {};
	REP1(i, n){
		tma[i] = t[i];
		if(t[i] != t[i-1]) tmi[i] = t[i];
		else tmi[i] = 1;
	}
	for(int i = n; i >= 1; i--){
		ama[i] = a[i];
		if(a[i] != a[i+1]) ami[i] = a[i];
		else ami[i] = 1;
	}
	REP1(i, n) {
		if(min(tma[i], ama[i]) - max(tmi[i], ami[i]) + 1 <= 0) ans = 0;
		else ans *= (ll)(min(tma[i], ama[i]) - max(tmi[i], ami[i]) + 1);
	}
	cout << ans.x << endl;
}

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

using namespace std;

#define rep(i, a, n) for(int i = a; i < (n); ++i)

vector<int> a(9);
vector<bool> reach(9);

bool check(int A, int B, int C)
{
    return reach[A] == true && reach[B] == true && reach[C] == true;
}

bool check(int Num){
    rep(i, 0, 9)    
    {
        if (a[i] == Num)
        {
            reach[i] = true;
            break;
        }
    }
    int res = check(0, 1, 2);
    if (res == true) return true;

    res = check(3, 4, 5);
    if (res == true) return true;

    res = check(6, 7, 8);
    if (res == true) return true;

    res = check(0, 4, 8);
    if (res == true) return true;

    res = check(2, 4, 6);
    if (res == true) return true;

    res = check(0, 3, 6);
    if (res == true) return true;

    res = check(2, 5, 8);
    if (res == true) return true;

    res = check(1, 4, 7);
    if (res == true) return true;

    return false;
};

int main(){
    rep(i, 0, 9)
    {
        cin >> a[i];
        reach[i] = false;
    }

    int n;
    cin >> n;

    int b = 0;
    bool res = false;
    rep(i, 0, n)
    {
        cin >> b;
        if (check(b) == true)
        {
            res = true;
        }
    }
    if (res == true)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

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

using namespace std;

typedef long long ll;

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
//#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795


ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll N=2e5+1;

vl fac(N);

ll c(ll n,ll r,ll m)
{
  ll y=1;
 // ll y=powM(fac[n-r],m-2,m);
  for(int i=1;i<=r;i++)
  {
    y=y*(n-i+1)%m;
  }
  ll z=powM(fac[r],m-2,m);
  return y*z%m;
}



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

ll n,a,b;
cin>>n>>a>>b;
ll m=(ll)1e9+7;

//invf[0]=1;
fac[0]=1;
  for(int i=1;i<=N;i++)
  {
    fac[i]=fac[i-1]*i%m;
    ///nvf[i]=powM(fac[i],m-2,m);
  }

  ll ans=powM(2,n,m)-c(n,a,m)-c(n,b,m)-1;

  ans=(ans+3*m)%m;

  cout<<ans<<"\n";

}

Measured memory_bytes: 1792
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int n;
	bool ans = true;
	cin >>n ;
	for(int i = 0, a; i < n; i++) {
		cin >> a;
		if(a&1^1 && (a%3!=0 && a%5!=0)) ans = false;
	}
	cout << (ans?"APPROVED":"DENIED");

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;
#define LL long long

int N,A[222222];

int main() {
	cin>>N;
	for(int i=2;i<=N;i++){
		int x;
		cin>>x;
		A[x]++;
	}
	for(int i=1;i<=N;i++)cout<<A[i]<<endl;
	return 0;
}



Measured memory_bytes: 4396
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

A,B=input().split()
A=int(A)
if not "." in B:
    print(A*int(B))
else:

    if B[-2]==".":
        Z=""
        for b in B:
            if not b==".":
                Z+=b
        B=int(Z)
        C=A*int(B)
        C//=10
        print(C)
    elif B[-3]==".":
        Z=""
        for b in B:
            if not b==".":
                Z+=b
        B=int(Z)
        C=A*int(B)
        C//=100
        print(C)


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

const int N = 55;
typedef long long ll;

int n, a[N], b[N];
bool var[N], vis[N];
ll cost;
queue <int> q;

bool Bfs(int s, int t) {
	memset(vis, 0, sizeof(vis));
	vis[s] = 1;
	while(!q.empty()) q.pop();
	q.push(s);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(int i = u; i > 0; i--) 
			if(!vis[u%i] && var[i]) {
				vis[u%i] = 1;
				q.push(u%i);
			}
	}
	return vis[t];
}

bool check() {
	for(int i = 1; i <= n; i++) 
		if(!Bfs(a[i], b[i])) return false;
	return true;
}

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) 
		cin>>a[i];
	for(int i = 1; i <= n; i++) 
		cin>>b[i];
	memset(var, 1, sizeof(var));
	for(int i = 50; i >= 1; i--) {
		if(!check()) {
			cout<<-1<<endl;
			return 0;
		}
	    var[i] = 0;
	    if(!check()) var[i] = 1;
	}
	for(int i = 1; i <= 50; i++)
		if(var[i]) cost |= 1ll<<i;
	cout<<cost<<endl;
	return 0;
}

Measured memory_bytes: 256
m, d = map(int , input().split())
count = 0
for month in range(1,m+1):
    for i in range(2, 10):
        if month % i == 0:
            div = month // i
            if 1< div < 10 :
                if i*10+div <= d:
                    count += 1
print(count)

Measured memory_bytes: 38384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>

#define size 100005

int main()
{
    int n, i, arr[size], sum=0, max;
    scanf("%d", &n);
    max=0;

    for(i=1; i<=n; i++)
    {
        scanf("%d", &arr[i]);
        sum = sum + arr[i];
        if(arr[i]>max)
            max = arr[i];
    }

    if((sum-max)>max)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 1656
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

class mycmp{
public:
	bool operator()(const P p1, const P p2){
		return p1.second > p2.second;
	}
};

int main(){
	char buf[64];
	int win,lose,draw;	
	int n;
	bool isnl = false;
	while(~scanf("%d",&n)){
		if(n==0) break;
		if(isnl){
			cout << endl;
		}
		vector<P> data;
		for(int i=0,j=0;i<n;i++){
			scanf("%s %d %d %d",buf,&win,&lose,&draw);
			data.push_back(P(buf,win*3+draw*1));
		}
		
		sort(data.begin(),data.end(),mycmp());

		for(int i=0;i<data.size();i++){
			printf("%s,%d\n",data[i].first.c_str(),data[i].second);
		}
		isnl=true;
	}
}

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

const int MAX_N = 100000;

int main(){
    int n;
    cin >> n;
    int input;
    set<int> s;
    for(int i=0;i<n;i++){
        cin >> input;
        if(s.find(input) == s.end())s.insert(input);
        else s.erase(input);
    }
    
    cout << s.size() << endl;
    
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;

int main() {
    long long N , D, tmp, X, Y, ans;
    cin >> N >> D;
    tmp = D * D;
    ans = 0;
    for (long long i = 0; i < N; ++i)
    {
        cin >> X >> Y;
        if (X * X + Y * Y <= tmp)
            ans++;
    }
    cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3148
class PrintTestCases
	def show_cases(number)
		number.each.with_index(1) do |val,index|
			puts "Case #{index}: #{val}"
		end
	end
end

input = Array.new
while line = gets
	break if line.to_i == 0
	input.push(line.to_i)
end

PrintTestCases.new.show_cases(input)

Measured memory_bytes: 6184
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    cout << N << ":";
    int M = N;
    vector<int> A;
    for (int i = 2; i*i <= N; i++) {
        while(M % i == 0) {
            A.emplace_back(i);
            M /= i;
        }
    }
    if (M != 1) A.emplace_back(M);
    for (auto i:A) cout << " " << i;
    cout << endl;
}


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

using namespace std;

struct UnionFind
{
    vector<int> par;
    
    UnionFind(int N) : par(N)
    {
        for (int i = 0; i < N; i++) par[i] = -1;
	}
    
    int root(int x)
    {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    
    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        
        if (par[rx] > par[ry]) std::swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
    }
    
    int size(int x)
    {
        return -par[root(x)];
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a,b);
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans = max(ans, uf.size(i));
    }
    
    cout << ans << endl;

    return 0;
}

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

int main() {
	vector<int> vec(210);
  	int N;
  	cin >> N;
  
  	bool exist_odd = false;
  	int sum = 0;
  
  	for(int i = 0; i < N; i++){
    	cin >> vec[i];
    }
  
  	while (true) {
   	for (int i = 0; i < N; i++){
    	if(vec[i] % 2 == 1) {
        	exist_odd = true;
        }
     }
      
      	if (exist_odd) break;
      
      	for(int i = 0; i < N; i++) {
        	vec[i] /= 2;
          	}
      sum++;
    }
      
      
    cout << sum << endl;
}


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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)

int main(){
  int n;
  cin >> n;
  int m;
  cin >> m;
  --m;
  REP(i, n - 1){
    int d;
    cin >> d;
    if(m > d){
      cout << "No" << endl;
      return 0;
    }else if(m == d){
      m = d;
    }else{
      m = d - 1;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main() {
	long N, M;
	cin >> N >> M;
	if (2 == N || 2 == M) cout << 0;
	else if (1 == N) {
		if (1 == M) cout << 1;
		else cout << M - 2;
	}
	else if (1 == M) cout << N - 2;
	else cout << (N - 2) * (M - 2);
}

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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
ll modpow(ll a,ll n, ll m=mo){
    ll ret = 1ll;
    while(n!= 0){
        if(n&1)(ret *= a)%= m;
        (a *= a)%=m;
        n>>=1;
    }
    return ret;
}
inline long long Mod(long long a, long long m) {
    return (a % m + m) % m;
}

inline long long mul(long long a, long long b, long long m) {
    a = Mod(a, m); b = Mod(b, m);
    if (b == 0) return 0;
    long long res = mul(Mod(a + a, m), b>>1, m);
    if (b & 1) res = Mod(res + a, m);
    return res;
}

long long pow(long long a, long long n, long long m) {
    if (n == 0) return 1 % m;
    long long t = pow(a, n/2, m);
    t = mul(t, t, m);
    if (n & 1) t = mul(t, a, m);
    return t;
}
ll lcm(ll a,ll b){
    ll g = __gcd(a,b);
    return 1ll*a/g*b;
}
ll phi(ll n){
    ll ret = n;
    for(int i=2;i*i<=n;++i)if(n%i==0){
        ret = ret/i*(i-1);
        while(n%i==0)n/=i;
    }
    if(n != 1) ret = ret/n*(n-1);
    return ret;
}
ll solve(int a,int m){
    if(m==1)return 30;
    if(a==0)return m;
    if(a==1)return 1;
    
    ll pm = phi(m);
    ll nextx = solve(a,pm);
    ll lc = lcm(pm,m);
    ll ret = pow(a,nextx,lc);
    while(ret < 30)ret += lc;
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int q;
    cin>>q;
    for(int i=0;i<q;++i){
        int a,m;
        cin>>a>>m;
        ll ret = solve(a,m);
        cout << ret << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC target("sse2")
 
    #include <bits/stdc++.h>
    #include <vector> 
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace std;
 
    #define int         long long
    #define ll          long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
    #define mi          map<int,int>
    #define mii         map<pii,int>
    #define mp          make_pair
    #define all(a)      (a).begin(),(a).end()
    #define FF           first
    #define SS           second
    #define sz(x)       (int)x.size()
    #define endl        '\n'
    #define rep(i,a,b)  for(int i=a;i<b;i++)
     ll hell=1000000007;



   
  
    int solve(){  
       
        int n;
         cin>>n;
        bool bl[n]={false};
        
        rep(i,0,n)
        {
            int x,y;
            cin>>x>>y;
            bl[i]=(x==y);
        }

        rep(i,0,n-2)
        if(bl[i]&&bl[i+1]&&bl[i+2])return cout<<"Yes",0;
        cout<<"No";


     return 0;
        
        }


    signed main()
    {       


 
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0); 
 
    int t=1,k=1;                                                                                                                  
    //cin>>t;
   
    while(t--)
    {
     
     // cout<<"Case #"<<k++<<": ";
     solve();
     //cout<<endl;
    }
    return 0;
    } 

Measured memory_bytes: 3604
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();
        String s = in.next();
        s = s.replace("B", "");

        out.println(s.length() > n - s.length() ? "Yes" : "No");
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 21204