akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>

using namespace std;

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

const ll mod = 1000000007;

struct unionfind {
  vector<int> group;

  unionfind(int n) {
    group = vector<int>(n);
    for (int i = 0; i < n; i++) group[i] = i;
  }

  int root(int x) {
    if (group[x] == x) return x;
    return group[x] = root(group[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    group[rx] = ry;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

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

  int n, m;
  cin >> n >> m;
  vector<Pii> ab(m);
  for (auto &x: ab) cin >> x.first >> x.second;

  unionfind uf(n);
  for (int i = 0; i < m; i++) {
    uf.unite(ab[i].first-1, ab[i].second-1);
  }

  unordered_map<int, int> rootCount;
  for (int i = 0; i < n; i++) {
    rootCount[uf.root(i)]++;
  }

  int maximum = 0;
  for (auto &x: rootCount) {
    if (x.second > maximum) maximum = x.second;
  }

  cout << maximum << endl;

  return 0;
}


Measured memory_bytes: 12036
#include<bits/stdc++.h>
using namespace std;
  
int a[8]={},b[8]={},c[15]={},d[15]={},ans[8][8]={};
void print(void);
void dfs(int);
  
int main(){
  int n,r,c1;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>r>>c1;
    ans[r][c1]=1;
  }
  dfs(0);
  return 0;
}
void dfs(int x){
  if(x==8){
  for(int i=0;i<8;i++)
    for(int j=0;j<8;j++)
      if(ans[i][j]==1)
    if(a[i]!=j)return;
  
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++)
      if(a[i] == j)cout<<'Q';
      else cout<<'.';
    cout<<endl;
  }
    return;
  }
  
  for(int i=0;i<8;i++){
    if(b[i]==1||c[x+i]==1||d[x-i+7]==1)continue;
    a[x]=i;
    b[i]=c[x+i]=d[x-i+7]=1;
    dfs(x+1);
    a[x]=b[i]=c[x+i]=d[x-i+7]=0;
  }
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;

vector<int> remain(2020,0);

int main(){
    string s;
    cin>>s;
    int ans = 0,n = s.size();
    ll num = 0,x=1;
    remain[0] = 1;
    for(int i=n-1;i>=0;i--){
        num += (s.at(i) - '0')*x;
        num = num%2019;
        ans += remain[num];
        remain[num]++;
        x = x*10%2019;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3748
#include <iostream>

int main() {
  int k, n = 7;
  std::cin >> k;
  for (int i = 0; i<k; ++i) {
    if (n%k==0) {
      std::cout << i+1;
      return 0;
    }
    else {
      n = (n*10 + 7)%k;
    }
  }
  std::cout << -1;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N;
    cin >> N;

    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }

    unordered_map<ll, ll> factors;
    for (ll i = 2; i <= N; i++) {
        ll y = i;
        for (ll x = 2; x * x <= N; x++) {
            while (y % x == 0) {
                ++factors[x];
                y /= x;
            }
        }
        if (y > 1) {
            ++factors[y];
        }
    }

    vector<Pll> fv;
    for (const auto& p : factors) {
        fv.emplace_back(p);
    }
    ll nf = (ll)fv.size();

    ll ans = 0;

    // 75
    for (ll i = 0; i < nf; i++) {
        if (fv[i].second >= 74) {
            ++ans;
        }
    }

    // 3 * 25
    // 5 * 15
    for (ll i = 0; i < nf; i++) {
        for (ll j = 0; j < nf; j++) {
            if (i == j) continue;
            if (fv[i].second >= 2 && fv[j].second >= 24) {
                ++ans;
            }
            if (fv[i].second >= 4 && fv[j].second >= 14) {
                ++ans;
            }
        }
    }

    // 3 * 5 * 5
    for (ll i = 0; i < nf; i++) {
        for (ll j = 0; j < nf; j++) {
            if (i == j) continue;
            for (ll k = j + 1; k < nf; k++) {
                if (i == k) continue;
                if (fv[i].second >= 2 && fv[j].second >= 4 && fv[k].second >= 4) {
                    ++ans;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1


ll n;
vector<P> G[100100];
int c[100100];

void solve(ll now,ll col){
    c[now] = col;
    rep(i,G[now].size()){
        P p = G[now][i];
        // cout << c[p.first] << p.first << endl;
        if(c[p.first] != -1)continue;
        solve(p.first,(col+p.second)%2);
    }
}

int main(){
    cin >> n;
    fill(c,c+100100,-1);
    rep(i,n-1){
        ll u,v,w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back(P(v,w%2));
        G[v].push_back(P(u,w%2));
    }
    solve(0,0);
    rep(i,n)cout << c[i] << endl;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i, k) for (auto &i : k)
#define all(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    vector<ll> dp(n,INF);
    REP(i,n){
        cin >> a[i];
        if(i!=0){
            if(i<=k){
                for(int j=0;j!=i;j++){
                    dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
                }
            }
            else{
                for(int j=i-1;j>=i-k;j--){
                    dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
                }
            }
        }
        else{
            dp[0]=0;
        }
    }
    cout << dp[n-1] << endl;
}


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

using namespace std;

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

    int lm = 1, rm = n;
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        lm = max(lm, l);
        rm = min(rm, r);
    }

    cout << (lm <= rm ? rm - lm + 1 : 0) << endl;

    return 0;
}


Measured memory_bytes: 256
a,b,c = map(int, input().split())
if (a==b or a==c) and (b!=c):
    print('Yes')
elif (b==a or b==c) and (a!=c):
    print('Yes')
elif (c==a or c==b) and (a!=b):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# なんこか入力
n,q = map(int, input().split())

# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
s = list(input())

# n行の複数列ある数値を二次元配列へ。x[n][?]
x = [[int(i) for i in input().split()] for i in range(q)] 
c = [0]
# n番目までに何個ACがあるか


count = 0
for i in range(1,n):
    if s[i-1] == "A" and s[i] == "C":
        count += 1
    c.append(count)
    
#print(c)

for i in range(q):
    if x[i][0] == 1:
        print(c[x[i][1]-1])
    else:
        print(c[x[i][1]-1]-c[x[i][0]-1])





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

#define MAXN 100010
#define ll long long
#define mod 1000000007

using namespace std;

ll n, m, k;
int ans, tot;

int a[MAXN];

string s;

int main(){
	int t;
	scanf("%lld%lld", &n, &k);
	cout << min(n % k, k - n % k);

	return 0;
}


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

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define Sort(vec) sort(all(vec))
#define Rev(vec) reverse(all(vec))

using Graph = vector<vector<int>>;

namespace Input
{
                
    void input(){return;}
    template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}
    
    void inputVec(){return;}
    template<typename First,typename... Rest> void inputVec(vector<First> &first,Rest&... rest){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i];
        }
        inputVec(rest...);
    }
    
    void inputVecParallel(int index){return;}
    template<typename First,typename... Rest> void inputVecParallel(int ____i,vector<First> &first,Rest&... rest){
        cin >> first[____i];
        inputVecParallel(____i,rest...);
        return;
    }

    template<typename First,typename... Rest> void inputVecParallel(vector<First> &first,Rest&... rest)
    {
        int ____size = first.size();
        for(int ____i = 0;____i < ____size;++____i)
        {
            cin >> first[____i];
            inputVecParallel(____i,rest...);
        }
        return;
    }

    void inputGraph(Graph &g,int path_num,bool isdirected){
        for(int i = 0;i < path_num;i++){
            int a,b;
            cin >> a >> b;
            a--;b--;
            if(isdirected){
                g[a].push_back(b);
            }
            else{
                g[a].push_back(b);
                g[b].push_back(a);
            }
        }
    }
}


void calculate(){
    string s,t;
    Input::input(s,t);
    bool flag = true;
    if(s.size() + 1 != t.size()) flag = false;
    for(int i = 0;i < (int)s.size();++i){
        if(s[i] != t[i]) flag = false;
    }
    cout << (flag ? "Yes\n" : "No\n");
}

int main(int,char**){
    calculate();    
}





Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int A, B; cin >> A >> B;

    int total = 0;
    for (int i = 0; i < 2; i++) {
        if (A < B) {
            total += B;
            B--;
        } else {
            total += A;
            A--;
        }
    }

    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline LL Scan() {
    LL x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
const int N=100005;
//Code begin....

int num[3];
char s[N];

int main ()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    FOR(i,1,len) ++num[s[i]-'a'];
    if (max(max(num[0],num[1]),num[2])-min(min(num[0],num[1]),num[2])<=1) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define mod 1000000007
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int t;
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int flag=1;
        int res=0;
        while(1){
          if(flag){
            c-=b;
          }
          else a-=d;
          flag=(flag^1);
          if(a<=0||c<=0)break;
        }
        if(a>0)cout<<"Yes";
        else cout<<"No";
        return 0;
}


Measured memory_bytes: 3652
N, A, B, C = map(int, input().split())
mod = 10 ** 9 + 7

W = [1] * (2 * N)
for i in range(2 * N - 1):
	W[i + 1] = ((i + 1) * W[i]) % mod

def rev(a):
	return pow(a, mod - 2, mod)

def comb(a, b):
	return (W[a] * rev(W[b]) * rev(W[a - b])) % mod

def f(a, b):
	res = 0
	for i in range(N):
		res += ((i + N) * com[i] * pow(b, i, mod)) % mod
		res %= mod
	return (pow(a, N, mod) * res) % mod

a = A * rev(A + B)
b = B * rev(A + B)
c = C * rev(100)
com = [comb(i + N - 1, i) for i in range(N)]

w_a = f(a, b)
w_b = f(b, a)
ans = ((w_a + w_b) * rev(1 - c)) % mod
print(ans)

Measured memory_bytes: 15284
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

int L;
vector<pair<int, int> > R;

double sp;

void sternBrocot(int x=0, int y=1, int z=1, int w=0){
    if ( w > 0 && y > 0&& !(1.0*x/y < sp && sp < 1.0*z/w) ) return;
    int num = x+z;
    int den = y+w;
    if ( num > L || den > L) return;
    sternBrocot(x, y, num, den);
    R.push_back(make_pair(num, den));
    sternBrocot(num, den, z, w);
}

main(){
    int p, n;
    while( cin >> p >> n && p && n ){
	L = n;
	R.clear();
	sp = sqrt(p);
	sternBrocot();
	pair<int, int> r1, r2;
	for ( int i = 0; i < R.size()-1; i++ ){
	    r1 = R[i];
	    r2 = R[i+1];
	    if ( 1.0*r1.first/r1.second < sp &&
		 sp < 1.0*r2.first/r2.second ){
		cout << r2.first << "/" << r2.second << " ";
		cout << r1.first << "/" << r1.second << endl;
	    }
	}
    }
}

Measured memory_bytes: 1736
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    int N;
    cin >> N;
    P f=make_pair(0ll, 0ll), s=make_pair(0ll, 0ll);
    REP(i, N){
        int A;
        cin >> A;
        if(f.fi<=A){
            s = f;
            f.fi = A;
            f.se = i;
        }else if(s.fi<A){
            s.fi = A;
            s.se = i;
        }
    }
    REP(i, N){
        if(f.se == i){
            cout << s.fi << el;
        }else{
            cout << f.fi << el;
        }
    }
}



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

int main() {
  string n;
  cin >> n;
  if ((n[1]==n[2])&&((n[0]==n[1])||(n[1]==n[3]))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3524
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_F&lang=jp

"""
import sys
from sys import stdin
from collections import namedtuple
input = stdin.readline


def solve(items, W, max_v):
    # ??¨???????????????????????????????????????
    n = len(items)
    dp = [[float('inf')]*(n*max_v + 1) for _ in range(n+1)] #  ?¨??????? ??§????????? ????¨????
    dp[0][0] = 0

    for i, item in enumerate(items):
        for j in range(n * max_v+1):
            if j < item.v:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = min(dp[i][j], dp[i][j-item.v]+item.w)

    for j in range(n * max_v + 1):
        if dp[n][j] <= W:
            result = j
    return result


item = namedtuple('item', ['v', 'w'])
def main(args):
    N, W = map(int, input().split())
    items = []
    for _ in range(N):
        v, w = map(int, input().split())
        items.append(item(v, w))
    items.sort()
    max_v = items[-1].v

    result = solve(items, W, max_v)
    print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 19844
from itertools import product
A,B,C,D = list(input().strip())
for x in product(("+","-"),repeat=3):
    a1,a2,a3 = x
    if eval(A+a1+B+a2+C+a3+D)==7:
        print(A+a1+B+a2+C+a3+D+"=7")
        break

Measured memory_bytes: 38384
if __name__ == '__main__':
    N = int(input())
    ans = 0
    for n in range(1, N+1, 2):
        cnt = 0
        for p in range(1, n+1):
            if n%p==0:
                cnt += 1
        if cnt==8:
            ans += 1
    print(ans)

Measured memory_bytes: 9012
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
void Set(); void Solve(); void Clean();
int main(){Set(); Solve(); Clean(); return 0;}

int N;
char *S;

void Solve()
{
	int ans = 1;
	for (int i = 1; i < N; ++i){
		if (S[i - 1] != S[i]) ++ans;
	}
	cout << ans << endl;
}

void Set()
{
#if DEBUG_MODE
	N = 10;
	S = new char[N + 1];
	strcpy(S, "aabbbbaaca");
#else
	cin >> N;
	S = new char[N];
	cin >> S;
#endif
}

void Clean()
{
	delete[] S;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[50];
int s;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a + n);
    reverse(a, a + n);
    for (int i = 0; i < k; ++i)
        s += a[i];
    cout << s;
}


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

int main() {
  int n;
  cin >> n;
  int N = 3 * n;
  vector<long long> a(N);
  
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  
  long long sum = 0;
  for (int i = N-2; i >= n; i-=2) {
    sum += a.at(i);
  }
  
  cout << sum << endl;
  
}



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

int main(){
	string s;
	int a,b=0;
	cin>>s;
	a=s.size();
	for(int i=0; i<(a+1)/2; i++){
		if(s[i]!=s[a-i-1])b++;
	}
	cout<<b<<endl;
}


Measured memory_bytes: 256
from collections import deque
from bisect import bisect_left

n = int(input())
a = [int(input()) for _ in range(n)]

dq = deque()
for e in a:
    idx = bisect_left(dq, e)
    if idx == 0:
        dq.appendleft(e)
    else:
        dq[idx-1] = e

ans = len(dq)
print(ans)


Measured memory_bytes: 8060
def gcd(n, m)
	if n < m
		a = m
		b = n
	else
		a = n
		b = m
	end

	return (a % b == 0 ? b : gcd(b, a % b))
end



n = gets().to_i
an = gets().split(' ').map(&:to_i)
an.sort!

g_all = gcd(an[0], an[1])
g_tmp = [an[0], an[1]]

(2 ... n).each {|i|
	g_tmp.map!{|gt|
		gcd(gt, an[i])
	}

	if an[i] % g_all != 0
		g_tmp.push(g_all)
		g_all = gcd(g_all, an[i])
	end
}

puts (g_tmp + [g_all]).max


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


main(){
   ll x,y,ans=0;
   cin >> x >> y;
   if(x==1){
      ans+=300000;
   }else if(x==2){
      ans+=200000;
   }else if(x==3){
      ans+=100000;
   }
   if(y==1){
      ans+=300000;
   }else if(y==2){
      ans+=200000;
   }else if(y==3){
      ans+=100000;
   }
   if(ans==600000) ans+=400000;
   cout << ans << endl;

   
}   

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

int main() {
    int N, D, i, j, c = 0;
    double distance, square;
    cin >> N >> D;
    int A[N][D];
    
    for(int a = 0; a < N; a++) {
        for (int b = 0; b < D; b++)
            cin >> A[a][b]; //A[a][b] = A a+1 b+1
            }
    
    for(i = 1; i < N; i++) {
        for(j = i + 1; j <= N; j++) {
            square = 0;
            for(int k = 0; k < D; k++)
                square += (A[j - 1][k] - A[i - 1][k]) * (A[j - 1][k] - A[i - 1][k]);
            distance = sqrt(square);
            if (distance - (int)distance == 0)
                c++;
                }
    }
    cout << c;
    return 0;
}


Measured memory_bytes: 256
while True:
    oddline = ''
    evenline = ''
    h, w = map(int, raw_input().split())
    if h+w==0:
        break
    for y in xrange(w):
        if y%2==0:
            oddline += '#'
            evenline += '.'
        else:
            oddline += '.'
            evenline += '#'
    for x in xrange(h):
        if x%2==0:
            print oddline
        else:
            print evenline
    print ''

Measured memory_bytes: 6444
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c<<endl;
}

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

using vi = vector<int>;
using vvi = vector<vi>;

void dfs(vvi& g, vi& parent, int k)
{
    for(auto& x : g[k]) if(!parent[x])
    {
        parent[x] = k;
        dfs(g, parent, x);
    }
}

void count(vvi& g, vi& cnt, vi& col, int k)
{
    for(auto& x : g[k]) if(!col[x])
    {
        cnt[col[k] - 1]++;
        col[x] = col[k];

        count(g, cnt, col, x);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);

    int n; cin >> n;

    vvi g(n + 1);

    for(int i = 0; i < n; i++)
    {
        int a, b; cin >> a >> b;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    vi col(n + 1);

    col[1] = 1;
    col[n] = 2;

    vvi parent(2, vi(n + 1));

    parent[1][1] = 1;
    parent[0][n] = n;

    dfs(g, parent[1], 1);
    dfs(g, parent[0], n);

    int move = 0;
    vi cur_node = {1, n};

    while(!col[ parent[move][cur_node[move]] ])
    {
        col[ parent[move][cur_node[move]] ] = 1 + move;
        cur_node[move] = parent[move][cur_node[move]];
        move = !move;
    }

    vi cnt(2);

    for(int i = 1; i <= n; i++)
        if(col[i]) count(g, cnt, col, i);

    vector<string> names = {"Fennec", "Snuke"};

    if(cnt[move] > cnt[!move]) cout << names[move] << endl;
    else cout << names[!move] << endl;

    return 0;
}

Measured memory_bytes: 11640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[401][401];
bool v[401][401];
ll minMerge(ll i,ll j,ll* arr)
{
    if(i==j)
        return 0;
    if(v[i][j])
        return dp[i][j];
    v[i][j]=1;
    ll& x=dp[i][j];
    x=LONG_MAX;
    ll tot=0;
    for(int k=i; k<=j; k++)
        tot+=arr[k];
    for(int k=i+1; k<=j; k++)
    {
        x=min(x,tot+minMerge(i,k-1,arr)+minMerge(k,j,arr));
    }
    return x;
}
int main()
{
    ll n;
    cin>>n;
    ll arr[n+10];
    for(int i=0; i<n; i++) cin>>arr[i];
    cout<<minMerge(0,n-1,arr);
}


Measured memory_bytes: 1664
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn main() {
    input! { n, m, a: [[usize1; m]; n] };
    let mut ans = n;
    let mut x = std::collections::HashSet::new();
    let mut cho = vec![0; n];
    while x.len() < m {
        let mut cnt = vec![0; m];
        for i in 0..n {
            let j = cho[i];
            if j < m {
                cnt[a[i][j]] += 1;
            }
        }
        let mx = *cnt.iter().max().unwrap();
        ans = std::cmp::min(ans, mx);
        for i in 0..m {
            if cnt[i] == mx {
                x.insert(i);
            }
        }
        for i in 0..n {
            while cho[i] < m && x.contains(&a[i][cho[i]]) {
                cho[i] += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import sys
input = sys.stdin.readline
N,K=map(int,input().split())
L=[int(i) for i in input().split()]
Pos = [x for x in L if x > 0]
Zero = [x for x in L if x == 0]
Neg = [x for x in L if x < 0]
Pos.sort()
Neg.sort(reverse=True)

Po = len(Pos)
Ne = len(Neg)
Ze= len(Zero)

ZeN = Ze*(Ze-1)//2 + Ze*(Po+Ne)
NeN = Po*Ne

if NeN<K<=NeN+ZeN:
    print(0)

else:
    def f(x):
        cnt = 0
        if x < 0:
            j = Po - 1
            for i in range(Ne):
                j=min(Po-1,j+1)
                while j >=0:
                    if Neg[i] * Pos[j] <= x:
                        j = j - 1
                    else:
                        break
                cnt = cnt + Po - j - 1
        else:
            j = 0
            for i in range(Po)[::-1]:
                j=max(0,j-1)
                while j < i:
                    if Pos[i]*Pos[j] <= x:
                        j = j+1
                    else:
                        break
                cnt = cnt+j

            j = 0
            for i in range(Ne)[::-1]:
                j = max(0, j - 1)
                while j < i:
                    if Neg[i]*Neg[j] <= x:
                        j = j+1
                    else:
                        break
                cnt = cnt+j

            cnt = cnt + ZeN + NeN
        return(cnt)

    Hi = 10**18
    Lo = -10**18

    while Hi-Lo > 1:
        Mid = (Hi + Lo) // 2
        if f(Mid) >= K:
            Hi = Mid
        else:
            Lo = Mid
    print(Hi)

Measured memory_bytes: 89940
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)N;i++)
#define p(s) cout<<(s)<<endl
#define ck(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
bool visit[810][810];
int main(){
	int H,W,K;
	cin>>H>>W>>K;
	char A[810][810];
	int sx,sy;
	REP(i,0,H) REP(j,0,W) {
		cin>>A[i][j];
		if(A[i][j]=='S'){
			sx=j;
			sy=i;
		}
	}
	queue<pair<int,pair<int,int>>> q;
	q.push({0,{sx,sy}});
	visit[sx][sy]=true;
	int mn=inf;
	while(!q.empty()){
		auto now=q.front();q.pop();
		REP(i,0,4){
			int nx=now.S.F+dx[i],ny=now.S.S+dy[i];
			int cost=now.F+1;
			if(!ck(ny,0,H)||!ck(nx,0,W)) continue;
			if(A[ny][nx]=='#'||visit[ny][nx]) continue;
			visit[ny][nx]=true;
			mn=min(mn,min(abs(nx-0),abs(W-1-nx)));
			mn=min(mn,min(abs(ny-0),abs(H-1-ny)));
			if(cost<K) q.push({cost,{nx,ny}});
		}
	}
	if(mn==inf) {
		mn=min(abs(sx-0),abs(W-1-sx));
		mn=min(mn,min(abs(sy-0),abs(H-1-sy)));
	}
	int ans=1;
	while(mn>0){
		ans++;
		mn-=K;
	}
	p(ans);
	return 0;
}


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

int main(){

    long long n, m; cin >> n >> m;
    if(n == 1 && m == 1) cout << 1 << endl;
    else if(n == 1) cout << m - 2 << endl;
    else if(m == 1) cout << n - 2 << endl;
    else cout << (n - 2) * (m - 2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, H, N;
    cin >> W >> H >> N;
    int Hmax = H;
    int Hmin = 0;
    int Wmax = W;
    int Wmin = 0;
    while(N--) {
        int x, y, a;
        cin >> x >> y >> a;
        if(a == 1) chmax(Wmin, x);
        if(a == 2) chmin(Wmax, x);
        if(a == 3) chmax(Hmin, y);
        if(a == 4) chmin(Hmax, y);
    }
    cout << max(0, Hmax - Hmin) * max(0, Wmax - Wmin) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<pair<int, int>> ans;
  if(N%2 == 0){
    REP(i, N) FOR(j, i+1, N){
      if(i == j) continue;
      if(j == N-i-1) continue;
      ans.emplace_back(make_pair(i+1, j+1));
    }
  }else{
    REP(i, N-1) FOR(j, i+1, N-1){
      if(i == j) continue;
      if(j == N-i-2) continue;
      ans.emplace_back(make_pair(i+1, j+1));
    }
    REP(i, N-1) ans.emplace_back(make_pair(i+1, N));
  }

  cout << ans.size() << endl;
  for(auto p : ans){
    cout << p.first << " " << p.second << endl;
  }

  return 0;
}

Measured memory_bytes: 512
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n,k,l = map(int,input().split())
    pq = [list(map(int,input().split())) for i in range(k)]
    rs = [list(map(int,input().split())) for i in range(l)]
    un1 = UnionFind(n)
    un2 = UnionFind(n)
    for i in range(k):
        un1.union(pq[i][0]-1,pq[i][1]-1)
    for i in range(l):
        un2.union(rs[i][0]-1,rs[i][1]-1)
    d = defaultdict(int)
    anslist = []
    for i in range(n):
        d[un1.findroot(i),un2.findroot(i)] += 1
    for i in range(n):
        anslist.append(d[un1.findroot(i),un2.findroot(i)])
    print(*anslist,sep = " ")
if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 103012
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let s = Array(readLine()!)
    let t = Array(readLine()!)
    
    var ans = 0
    for i in 0..<3 {
        if s[i] == t[i] {
            ans += 1
        }
    }
    
    print(ans)
}

main()


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

int main() {
  static const double pi = 3.141592653589793;
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  
  double ar = (h * 60 + m) * 2 * pi / 720;
  double br = m * 2 * pi / 60;
  
  double ans = 0;
  
  if (ar < br){
    ans = sqrt(a * a + b * b - 2 * a * b * cos(br - ar));
   
    cout << fixed << setprecision(12);
    cout << ans << endl;
  }
  else if (ar == br){
    if (a < b){
      cout << b - a << endl;
    }
    else if (a == b){
      cout << 0 << endl;
    }
    else{
      cout << a - b << endl;
    }
  }
  else{
    ans = sqrt(a * a + b * b - 2 * a * b * cos(ar - br));
   
    cout << fixed << setprecision(12);
    cout << ans << endl;
  }
}

Measured memory_bytes: 4228
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	int a, b, x;
	cin >> a >> b >> x;
	if (a <= x && x <= a + b) {
		cout << "YES";
	}
	else cout << "NO";
}


Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

n_m = bisect_left(a, 0)  # a[i] < 0 の数
n_0 = bisect_right(a, 0) - n_m  # a[i] = 0 の数
n_p = n - n_m - n_0  # a[i] > 0 の数

nn_m = n_m * n_p  # 積が負になるペア数
nn_0 = n_0 * (n - n_0) + n_0 * (n_0 - 1) // 2  # 積が0になるペア数
nn_p = n * (n - 1) // 2 - nn_m - nn_0  # 積が正になるペア数

if k <= nn_m:
    # k番目の値は負

    def check_minus(x):
        # k番目の値がx(<0)以下

        # a[i] * a[j] <= x

        # a[i]   * a[j] <= x  : a[j] >= abs(x) / abs(a[i])
        # a[i+1] * a[j] <= x  : a[j] >= abs(x) / abs(a[i+1])
        #     a[i]  <=     a[i+1] < 0
        # abs(a[i]) >= abs(a[i+1])
        # a: [-------00000+++++++]
        #     i             jjjjj
        #      i             jjjj
        #       i              jj

        # a[i] * a[j] <= -7
        # n_m = 4
        # n_0 = 3
        # a = [-5, -3, -2, -1, 0, 0, 0, 1, 2, 3, 4, 5]
        #       i                          j (j  j  j)
        #           i                         j (j  j)
        #               i                        j
        #                   i                          j
        # a[i] * a[j] = -5
        #  -2  *   4  = -6

        cnt = 0
        j = n_m + n_0
        for i in range(n_m):
            while j < n and a[i] * a[j] > x:
                j += 1
            # a[i] * a[j] <= x
            # [j, n)
            cnt += n - j

        return cnt >= k

    # a[i] * a[j] <= x
    lb = -10**18  # False
    ub = -1  # True
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if check_minus(mid):
            ub = mid
        else:
            lb = mid
    ans = ub
elif k <= nn_m + nn_0:
    # k番目の値は0
    ans = 0
else:
    # k番目の値は正
    a_p = a[n_m + n_0:]
    a_m = [-a[i] for i in reversed(range(n_m))]

    def check_plus(x):
        # k番目の値がx(>=0)以下
        def func(b):
            # b [++++++++++++++]
            #    ijjjjjjjjjjj
            #     ijjjjjjjj
            #      ijjjj
            #       ij

            # b[i] * b[j] <= x
            # b[i]   * b[j] <= x : b[j]  <= x / b[i]
            # b[i+1] * b[j] <= x : b[j]  <= x / b[i+1]

            c = 0
            j = len(b) - 1
            for i in range(len(b)):
                if i >= j:
                    break
                # i < j
                while i < j and b[i] * b[j] > x:
                    j -= 1
                # b[i] * b[j] <= x
                # (i, j]
                c += j - i
            return c

        cnt = nn_m + nn_0
        cnt += func(a_p)
        cnt += func(a_m)
        return cnt >= k

    # a[i] * a[j] <= x
    lb = 0  # False
    ub = 10**18 + 1  # True
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if check_plus(mid):
            ub = mid
        else:
            lb = mid
    ans = ub
print(ans)


Measured memory_bytes: 95188
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
using namespace std;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>

int main() {
	int H, W;
	cin >> H >> W;	

	for (int i = 0; i < W + 2; i++) {
		cout << '#';	
	}
	cout << endl;

	for (int i = 0; i < H; i++)	{
		string S;
		cin >> S;
		cout << '#' << S << '#' << endl;
	}

	for (int i = 0; i < W + 2; i++) {
		cout << '#';
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

void print() { cout << endl; }
template <typename Head, typename... Tail>
void print(Head head, Tail... tail) {
    int size = sizeof...(Tail);
    cout << head;
    if (size > 0) {
        cout << " ";
    }
    print(tail...);
}

void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
    cout << head;
    print0(tail...);
}

class iunionfind {
   public:
    // 連続するuintにのみ使える。vectorであるため定数時間がとれる。
    // 基本的にこれだけあればよい。任意の構造体を扱うときは、IDと構造体のマッピングをとるvectorを別途用意する。
    // libs-test.cppの iuf_map あたりを検索。
    vector<ull> partition;
    vector<ull> rank;

    iunionfind(ull n) {
        partition.resize(n);
        rank.resize(n);
        for (ull x = 0; x < n; x++) {
            partition[x] = x;
            rank[x] = 0;
        }
    }
    ull find(ull x) {
        if (partition[x] == x) {
            return x;
        } else {
            partition[x] = find(partition[x]);
            return partition[x];
        }
    }
    void unite(ull x, ull y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return;
        }
        if (rank[x] < rank[y]) {
            partition[x] = y;
        } else {
            partition[y] = x;
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
    }
    bool same(ull x, ull y) {
        return find(x) == find(y);
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> H(N);
    auto uf = iunionfind(N);

    for (ll i = 0; i < N; i++) {
        cin >> H[i];
    }
    vector<vector<ll>> near(N);
    for (ll i = 0; i < M; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        near[a].push_back(b);
        near[b].push_back(a);
    }
    ll result = 0;
    for (ll i = 0; i < N; i++) {
        ll h = H[i];
        bool highest = true;
        for (auto ne : near[i]) {
            ll hne = H[ne];
            if (hne >= h) {
                highest = false;
            }
        }
        if (highest) {
            result++;
        }
    }
    print(result);
    // map<ll, pair<ll, ll>> topcnt;
    // for (ll i = 0; i < N; i++) {
    //     ll un = uf.find(i);
    //     ll h = H[i];
    //     if (topcnt.count(un)) {
    //         ll hcur = topcnt[un].first;
    //         if (h > hcur) {
    //             topcnt[un] = make_pair(h, 1);
    //         } else if (h == hcur) {
    //             topcnt[un].second++;
    //         }
    //     } else {
    //         topcnt[un] = make_pair(h, 1);
    //     }
    // }

    // ll result = 0;
    // for (auto t : topcnt) {
    //     if (t.second.second == 1) {
    //         result++;
    //     }
    // }
    // print(result);
}


Measured memory_bytes: 11392
using System;

class Program
{
    static void Main(string[] args)
    {
        var nm = Console.ReadLine().Split();
        var n = int.Parse(nm[0]);
        var m = int.Parse(nm[1]);

        var d = new int[n + 1];
        for (int i = 0; i < m; i++)
        {
            var lr = Console.ReadLine().Split();
            var l = int.Parse(lr[0]) - 1;
            var r = int.Parse(lr[1]);
            d[l]++;
            d[r]--;
        }

        for (int i = 0; i < n; i++)
        {
            d[i + 1] += d[i];
        }

        var ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (d[i] == m) ans++;
        }

        Console.WriteLine(ans);
    }
}


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

map<int,int> mp;
int main(){
    int n,x;
    ll ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        cin>>x;
        ans+=(ll)mp[i-x];
        mp[x+i]++;
    }
    printf("%lld",ans);
}


Measured memory_bytes: 20880
S = input()
n = len(S)+1

lr = []
num = []
a = S[0]
cnt = 0
for s in S:
    if s == a:
        cnt += 1
    else:
        num.append(cnt)
        if a == '<':
            lr.append(1)
        else:
            lr.append(0)
        a = s
        cnt = 1
num.append(cnt)
if a == '<':
    lr.append(1)
else:
    lr.append(0)

ans = 0
if (len(lr) == 1 and lr[0] == 0) or (len(lr) > 1 and lr[0] == 0):
    ans += (num[0]*(num[0]+1))//2
    lr, num = lr[1:], num[1:]
if (len(lr) == 1 and lr[0] == 1) or (len(lr) > 1 and lr[-1] == 1):
    ans += (num[-1]*(num[-1]+1))//2
    lr.pop()
    num.pop()

if not lr:
    print(ans)
    exit()

for i in range(0, len(lr), 2):
    if num[i] == num[i+1]:
        b = num[i]
        c = num[i]
    elif num[i] < num[i+1]:
        b = num[i+1]
        c = num[i]
    else:
        b = num[i]
        c = num[i+1]
    ans += (b*(b+1))//2 + ((c-1)*c)//2
print(ans)

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
typedef struct E{
  ll to,cost;
}edge;
const int MAX_V=100100;
const ll Inf=1e18;
vector<vector<edge> >E(MAX_V);
vector<vector<edge> >EE(MAX_V);
ll d[MAX_V];
ll dd[MAX_V];
void dijkstra(int s){
  priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >que;
  fill_n(d,MAX_V,Inf);
  d[s] = 0;
  que.push(pair<ll,ll>(0,s));
  while(!que.empty()){
    pair<ll,ll> p=que.top();que.pop();
    int v = p.second;
    if(d[v]<p.first)continue;
    for(int j=0;j<E[v].size();j++){
      edge t = E[v][j];
      if(d[t.to]>d[v]+t.cost){
	d[t.to]=d[v]+t.cost;
	que.push(pair<ll,ll>(d[t.to],t.to));
      }
    }
  }
}
void ddijkstra(int s){
  priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >que;
  fill_n(dd,MAX_V,Inf);
  dd[s] = 0;
  que.push(pair<ll,ll>(0,s));
  while(!que.empty()){
    pair<ll,ll> p=que.top();que.pop();
    int v = p.second;
    if(dd[v]<p.first)continue;
    for(int j=0;j<EE[v].size();j++){
      edge t = EE[v][j];
      if(dd[t.to]>dd[v]+t.cost){
	dd[t.to]=dd[v]+t.cost;
	que.push(pair<ll,ll>(dd[t.to],t.to));
      }
    }
  }
}
int main(){
  int n,m,ss,tt;cin>>n>>m>>ss>>tt;
  ss--;tt--;
  for(int i=0;i<m;i++){
    ll a,b,c,ddd;cin>>a>>b>>c>>ddd;
    edge e;e.to=--b;e.cost=c;
    E[--a].pb(e);
    e.cost=ddd;
    EE[a].pb(e);
    e.to=a;
    EE[b].pb(e);
    e.cost=c;
    E[b].pb(e);
  }
  dijkstra(ss);
  ddijkstra(tt);
  priority_queue<pair<ll,ll>,vector<pair<ll,ll > >,greater<pair<ll,ll> > >que;
  for(int i=0;i<n;i++){
    //  cout<<d[i]<<" "<<dd[i]<<endl;
    que.push(mp(d[i]+dd[i],i));
  }
  int cnt=0;
  while(cnt!=n){
    if(que.top().S>=cnt){
      cout<<(ll)1e15-(ll)que.top().F<<endl;
      cnt++;
    }else{
      que.pop();
    }
  }
  return 0;
}


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

using namespace std ;

const int MAX = 2010 ;

int dp[MAX][MAX][2] , arr[MAX];
int n , x , y ;

int solve(int idx , int idx2 , int turn)
{
	int now ;
	if(idx2 == 0)
	{
		if(turn == 0)
			now = y ;
		else
			now = x ;
	}
	else
		now = arr[idx2] ;
	if(idx == n)
		return (abs(arr[idx] - now)) ;
	int &ret = dp[idx][idx2][turn] ;
	if(ret != -1)
		return ret ;
	if(turn == 0)
	{
		ret = solve(idx+1 , idx2 , turn) ;
		ret = max(ret , solve(idx+1 , idx , !turn)) ;
	}
	else
	{
		ret = solve(idx+1 , idx2 , turn) ;
		ret = min(ret , solve(idx+1 , idx , !turn)) ;
	}
	return ret ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>x>>y ;
	for(int i = 1 ; i <= n ; ++i)
		cin>>arr[i] ;
	memset(dp , -1 , sizeof(dp)) ;
	return cout<<solve(1 , 0 , 0)<<"\n" , 0 ;
}

Measured memory_bytes: 31872
import java.util.Scanner;

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

			for(;;) {

				int H = sc.nextInt();
				int W = sc.nextInt();

				if(H == 0 && W == 0) {
					break;
				}

				for(int j = 0; j < H; j++) {

					if((j == 0) || (j == H - 1)) {

						for(int k = 0; k < W; k++) {
							System.out.print("#");
						}

					} else {

						System.out.print("#");
						for(int k = 1; k < W - 1; k++) {
							System.out.print(".");
						}
						System.out.print("#");

					}
					System.out.print('\n');
				}
				System.out.println();
			}
	}
}

Measured memory_bytes: 32500