akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, n, sr, sc;
	cin >> H >> W >> n >> sr >> sc;
	string s, t;
	cin >> s >> t;
	bool ans = true;
	for(char c : "LRUD"){
		if(c == 'L'){
			int c1 = 0, c2 = 0;
			for(int i = 0; i < n; i++){
				c1 += (s[i] == c);
				if(sc + c2 - c1 <= 0){
					ans = false;
					break;
				}
				if(t[i] == 'R' && sc + c2 + 1 - c1 <= W) c2++;
			}
		}
		else if(c == 'R'){
			int c1 = 0, c2 = 0;
			for(int i = 0; i < n; i++){
				c1 += (s[i] == c);
				if(sc + c1 - c2 > W){
					ans = false;
					break;
				}
				if(t[i] == 'L' && sc + c1 - c2 - 1 > 0) c2++;
			}
		}
		else if(c == 'U'){
			int c1 = 0, c2 = 0;
			for(int i = 0; i < n; i++){
				c1 += (s[i] == c);
				if(sr + c2 - c1 <= 0){
					ans = false;
					break;
				}
				if(t[i] == 'D' && sr + c2 + 1 - c1 <= H) c2++;
			}
		}
		else{
			int c1 = 0, c2 = 0;
			for(int i = 0; i < n; i++){
				c1 += (s[i] == c);
				if(sr + c1 - c2 > H){
					ans = false;
					break;
				}
				if(t[i] == 'U' && sr + c1 - c2 - 1 > 0) c2++;
			}
		}
	}
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int x; cin >> x;
  int M = 1000000;

  for(int i = x;i<M;++i){
    bool prime = true;
    for(int j = 2;j<i;++j){
      if(i%j==0){
	prime = false;
	break;
      }
    }
    if(prime){
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3640
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
string s; 
int main(){
	cin>>s;
	if(s=="SUN")
		cout<<7;
	if(s=="MON")
		cout<<6;
	if(s=="TUE")
		cout<<5;
	if(s=="WED")
		cout<<4;
	if(s=="THU")
		cout<<3;
	if(s=="FRI")
		cout<<2;
	if(s=="SAT")
		cout<<1; 
	return 0;
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

struct UnionFindWeighted {
    vector<int> p;
    vector<ll> w;

    UnionFindWeighted(int n) : p(n, -1), w(n, 0) {
    }

    // w[v] - w[u] = weight
    bool UnionSet(int u, int v, ll weight) {
        int ru = root(u);
        int rv = root(v);
        if (ru == rv) return w[u] - w[v] == weight;

        w[ru] = weight - w[u] + w[v];
        p[rv] += p[ru];
        p[ru] = rv;
        return true;
    }

    pair<ll, int> find(int u, int v) {
        int ru = root(u);
        int rv = root(v);
        if (ru != rv) return {0, -1};
        return {w[u] - w[v], 0};
    }

    bool isSame(int u, int v) {
        return root(u) == root(v);
    }

    int size(int x) {
        return -p[root(x)];
    }
    int root(int x) {
        if (p[x] < 0) {
            return x;
        } else {
            int r = root(p[x]);
            w[x] += w[p[x]];
            p[x] = r;
            return r;
        }
    }

};


void solve() {
    int N, M;
    cin >> N >> M;
    UnionFindWeighted uf(N);
    for (int i = 0; i < M; i++) {
        int l, r; ll d;
        cin >> l >> r >> d;
        l--, r--;
        if (!uf.UnionSet(l, r, d)) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;

}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
long long ans;

int main(){
  long long n,m; cin >> n >> m;
  if(m < n*2){
    cout << m/2 << endl;
    return 0;
  }
  ans += n;
  m = m - n*2;
  ans += m/4;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
void solve(){
	ll n,m; cin >> n >> m;
	vector<ll> a(n);
	FOR(n) cin >> a[i];
	sort(all(a));
	map<ll,ll> mp;
	FOR(m){
		ll b,c; cin >> b >> c;
		mp[c] += b;
	}
	FOR(n){
		if(mp.empty()) break;
		auto itr = mp.end();
		--itr;
		ll ne = (*itr).first;
		ll o = a[i];
		if(ne <= o) break;
		else{
			a[i] = ne;
			if((*itr).second == 1){
				mp.erase(itr);
			} else{
				--mp[ne];
			}
		}
	}
	
	ll ans = 0;
	for (ll ii : a) ans += ii;
	cout << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 10324
(defun moge (n i)
  (if (= n 0)
      i
      (multiple-value-bind (a b)
          (floor n 10)
        (moge a (+ b i)))))


(defun hoge ()
  (let* ((n (read))
         (a (moge n 0)))
    (multiple-value-bind
        (i j)
        (floor n a)
      (if (= j 0)
          (format t "Yes~%")
          (format t "No~%")))))

(hoge)


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

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int sum1 = a+b;
    int sum2 = c+d;
    if(sum1>sum2) cout << "Left" << endl;
    else if( sum1<sum2) cout << "Right" << endl;
    else cout << "Balanced" << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;


class Program
{
    static long big = 1000000007;
    static void Main(string[] args)
    {
        long n = crI();
        if (n == 1)
        {
            Console.WriteLine(0);
            return;
        }
        long ans = (modKakeru(10,n) - modKakeru(9,n) - modKakeru(9,n) + modKakeru(8,n)) % big;
        ans = (ans + big) % big;
        Console.WriteLine(ans);


    }

    static long modKakeru(long a , long n)
    {
        long ans = 1;
        for(long i = 0; i < n; i++)
        {
            ans = ans * a % big;
        }
        return ans;
    }

    
    





    //入力受け取り用
    static string crS() { return Console.ReadLine(); }
    static int crI() { return int.Parse(Console.ReadLine()); }
    static long crL() { return long.Parse(Console.ReadLine()); }
    static int[] arrInt() { return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray(); }
    static long[] arrLong() { return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); }
    static string[] arrStr() { return Console.ReadLine().Split(' ').ToArray(); }
    static List<int[]> mapInt(int h)
    {
        List<int[]> mapInt = new List<int[]>();
        for (int i = 0; i < h; i++)
        {
            mapInt.Add(arrInt());
        }
        return mapInt;
    }

    static List<long[]> mapLong(long h)
    {
        List<long[]> mapLong = new List<long[]>();
        for (int i = 0; i < h; i++)
        {
            mapLong.Add(arrLong());
        }
        return mapLong;
    }


    static List<string[]> mapStr(int h)
    {
        List<string[]> mapStr = new List<string[]>();
        for (int i = 0; i < h; i++)
        {
            mapStr.Add(arrStr());
        }
        return mapStr;
    }

    static List<char[]> mapChar(int h)
    {
        List<char[]> mapChar = new List<char[]>();
        for (int i = 0; i < h; i++)
        {
            string s = crS();
            mapChar.Add(s.ToCharArray());
        }
        return mapChar;
    }

    static List<char[]> mapCharCopy(List<char[]> map)
    {
        List<char[]> copyMap = new List<char[]>();
        foreach (var arr in map)
        {
            List<char> list = new List<char>();
            foreach (var ele in arr)
            {
                list.Add(ele);
            }
            copyMap.Add(list.ToArray());
        }
        return copyMap;
    }

    //二次元配列出力用
    static void output2DArray(int h , int w , int[,] map)
    {
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (j == w - 1) Console.WriteLine(map[i, j]);
                else Console.Write(map[i, j] + " ");
            }
        }
    }
}

Measured memory_bytes: 27468
N = int(input())
A = list(map(int, input().split()))

if A.count(0) == N:
    print('Yes')
    exit()

if N % 3 != 0:
    print('No')
    exit()

if len(set(A)) == 3:
    F = list(set(A))
    x, y, z = F
    if not (((x ^ y) == z) or ((y ^ z) == x) or ((z ^ x) == y)):
        print('No')
        exit()

    if (A.count(x) == N // 3) and (A.count(y) == N // 3) and (A.count(z) == N // 3):
        print('Yes')
    else:
        print('No')
    exit()

if len(set(A)) == 2:
    if A.count(0) == N // 3:
        print('Yes')
    else:
        print('No')
    exit()

print('No')


Measured memory_bytes: 14116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int n;
  cin >> n;
  ll ans = 1;
  rep1(i,n) ans = (ans*i)%1000000007;
  cout << ans << endl;
}

Measured memory_bytes: 256
long M=998244353,a,b,k,F[3<<17]={1,1},I[3<<17]={1,1},R[3<<17]={1,1},i,j=1,s;main(n){for(scanf("%d%d%d%ld",&n,&a,&b,&k);j++<n;R[j]=(I[j]=(M-M/j)*I[M%j]%M)*R[j-1]%M)F[j]=j*F[j-1]%M;for(;i<=n;i+=j<0|j>n|a*i+b*j-k||(s=(s+F[n]*R[n-i]%M*R[i]%M*F[n]%M*R[n-j]%M*R[j])%M))j=(k-a*i)/b;printf("%d",s);}

Measured memory_bytes: 7296
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    from collections import deque

    h, w = input_int_list()
    grid = []
    visited = []
    grid.append(["@"] * (w + 2))
    visited.append([True] * (w + 2))
    for _ in range(h):
        grid.append(["@"] + list(input()) + ["@"])
        visited.append([True] + [False] * w + [True])
    grid.append(["@"] * (w + 2))
    visited.append([True] * (w + 2))

    # 幅優先探索で すべてを"#"に変える。
    # かかった手数分が答え
    direction = ((0, 1), (1, 0), (-1, 0), (0, -1))
    dq = deque()
    # すべての"#"をdequeに入れる
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if grid[i][j] == "#":
                dq.append((i, j, 0))
                visited[i][j] = True
    ans = 0
    # 幅優先探索
    while dq:
        i, j, d = dq.popleft()
        for di, dj in direction:
            if grid[i + di][j + dj] == "." and not visited[i + di][j + dj]:
                dq.append((i + di, j + dj, d + 1))
                visited[i + di][j + dj] = True
                ans = max(ans, d + 1)

    print(ans)
    return


if __name__ == "__main__":
    main()


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int K;
  cin >> K;
  for (int i = 0; i < K; i++) {
    if (A >= B) {
      B *= 2;
    } else if (B >= C) {
      C *= 2;
    }
  }
  
  if (A < B && B < C) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3588
import sys

def gcd(a, b): return gcd(b, a % b) if b else abs(a)
def lcm(a, b): return abs(a // gcd(a, b) * b)

n, *t = map(int, sys.stdin.read().split())

def main():
    res = 1
    for x in t:
        res = lcm(res, x)
    print(res)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3188
import math

A,B,H,M=map(int,input().split())

h=(360/12)*H+(360/12)*(M/60)
m=(360/60)*M

Hx=A*math.sin(math.radians(h))
Hy=A*math.cos(math.radians(h))

Mx=B*math.sin(math.radians(m))
My=B*math.cos(math.radians(m))

print(((Hx-Mx)**2+(Hy-My)**2)**(1/2))

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

using namespace std;

template <class T>inline T updmax(T &a, T b) { return a = max(a, b); }
template <class T>inline T updmin(T &a, T b) { return a = min(a, b); }

template <unsigned long long mod> class modint {
public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod-this->v); }
	modint &operator+=(const modint rhs) {
		v += rhs.v;
		if (v >= mod)v -= mod;
		return *this;
	}
	modint &operator-=(const modint rhs) {
		if (v < rhs.v)v += mod;
		v -= rhs.v;
		return *this;
	}
	modint &operator*=(const modint rhs) {
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a) {
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp) {
			if (exp % 2) {
				ret *= a;
			}
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint &operator/=(modint rhs) {
		(*this) *= inverse(rhs);
		return *this;
	}
		friend ostream &operator<<(ostream &os, modint &u) {
		os << u.v;
    	return (os);
	}
};

const int MOD = 1000000007;
using mint = modint<MOD>;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin >> s;
	int n = s.length();
	vector<vector<mint>> dp(n+1, vector<mint>(13, 0));
	dp[0][0] = 1;
	for(int i=0; i < n; i++){
		if(s[i] == '?'){
			for(int j=0; j < 13; j++){
				for(int k=0; k < 10; k++){
					dp[i+1][(j*10+k)%13] += dp[i][j];
				}
			}
		}else{
			for(int j=0; j < 13; j++)dp[i+1][(j*10+s[i]-'0')%13] += dp[i][j];
		}
	}
	cout << dp[n][5] << "\n";
	return 0;
}

Measured memory_bytes: 13648
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int n;
  cin >> n;
  for (int i = 0; i <= 9; i++){
    for (int r = 0; r <= 9; r++){
      if (i * r == n){
        cout << "Yes\n";
        return 0; 
      }
    } 
  }
  cout << "No\n";
  return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void call(int n)
{
    int i = 1;
    do
    {
        int x = i;
        if (x % 3 == 0)
        {
            cout << " " << i;
            continue;
        }
        do
        {
            if (x % 10 == 3)
            {
                cout << " " << i;
                break;
            }
            x /= 10;
        } while (x);
    } while (++i <= n);
    cout << endl;
}
int main()
{
    int n;
    cin>>n;
    call(n);
    return 0;
}



Measured memory_bytes: 3088
#include <unordered_set>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <functional>
#include <set>

int N;
long long H;
long long a[100010];
long long b[100010];
long long c[100010];

void run() {
	std::cin >> N;
	std::cin >> H;
	for (int i = 0; i < N; ++i) {
		std::cin >> a[i] >> b[i];
		c[i] = std::max(a[i], b[i]) << 32 | a[i];
	}
	std::sort(c, c + N);
	long long d = 0;
	long long ans = 1LL << 60;
	for (int i = N - 1; i >= 0; --i) {
		H -= c[i] >> 32;
		d = std::max((long long)(int)c[i], d);
		ans = std::min(ans, N - i + (H > 0 ? (H + d - 1) / d : 0));
	}
	std::cout << ans << std::endl;
}
int main() {
	run();
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    string s[H];
    rep(i, H) cin >> s[i];
    int ans = 0;
    rep(i, 1<<H){
        rep(j, 1<<W){
            int cnt = 0;
            rep(x, H){
                rep(y, W){
                    if(s[x][y] == '#' && (i&(1<<x) && (j&(1<<y)))) cnt++;
                }
            }
            if(cnt == K) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

int main(){
  string line;
  while(getline(cin, line)){
    if(line == "0") break;
    int q1,b,c1,c2,q2;
    stringstream ss(line);
    ss>>q1>>b>>c1>>c2>>q2;
    int ans1 = 0;
    int ans2 = 0;
    for(int jidori = q2; jidori >= 0; jidori--){
      if(jidori == 0){
        cout<<"NA"<<endl;
        break;
      }
      int money = b - jidori*c1;
      if(money < 0) continue;
      int tori = money / c2;
      if(tori + jidori >= q1){
        printf("%d %d\n",jidori,tori);
        break;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
 
 int main(){
    int a[4],b[4],hit,blow,i,j;
    while(std::cin>>a[0]){
    for(i=1;i<4;i++){
    std::cin>>a[i];
    }for(i=0;i<4;i++){
    std::cin>>b[i];
    }
    hit=0;
    blow=0;
    for(i=0;i<4;i++){
        for(j=0;j<4;j++){
            if(i==j&&a[i]==b[j]){
            hit++;
            }if(i!=j&&a[i]==b[j]){
            blow++;
            }
        }
    }
    std::cout<<hit<<" "<<blow<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0)
    return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1; // 分母
  ll numerator = 1;   // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
private:
  vector<ll> parents;

public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) {
    return root(x) == root(y);
  }

  bool merge(ll x, ll y) {
    if (issame(x, y))
      return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry])
      swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) {
    return -parents[root(x)];
  }

private:
  ll root(ll x) {
    if (parents[x] < 0)
      return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

bool lessThan(const string &a, const string &b) {
  if (a == "") {
    return true;
  } else if (a.size() == b.size()) {
    return a < b;
  } else {
    return a.size() < b.size();
  }
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M);
  for (ll i = 0; i < M; i++) {
    cin >> A[i];
  }

  vector<string> dp(N + 1, "-");
  ll matches[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};

  dp[0] = "";
  for (ll i = 0; i < N; i++) {
    if (dp[i] == "-") {
      continue;
    }

    for (auto a : A) {
      if (i + matches[a - 1] > N) {
        continue;
      }

      if (lessThan(dp[i + matches[a - 1]], dp[i] + (char)('0' + a))) {
        dp[i + matches[a - 1]] = dp[i] + (char)('0' + a);
      }
    }
  }

  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 43264
#include<bits/stdc++.h>
using namespace std;
int main()
{

    char s[5];
    cin>>s;
    cin.ignore();
    if(s[0]==s[1]&&s[1]==s[2] ||s[1]==s[2]&&s[2]==s[3]) cout<<"Yes"<<endl;
    else                        cout<<"No"<<endl;
    return 0;

}


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

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

	set<string> fruit;

	for (int i = 0; i < item; i++) {
		string tmp;
		cin >> tmp;
		fruit.insert(tmp);
	}
	cout << fruit.size() << endl;

//	system("pause");
	return 0;
}

Measured memory_bytes: 19236
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> v(m);
    REP(i,m){
        cin>>v[i];
    }
    sort(ALL(v));
    vector<ll> d;
    REP(i,m-1){
        d.push_back(v[i+1]-v[i]);
    }
    sort(ALL(d));
    ll sum=0;
    REP(i,m-n){
        sum+=d[i];
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 4892
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	int n,m,x;
	int c[14],a[14][14];
	int now[14];
	cin>>n>>m>>x;
	rep(i,n)
	{
		cin>>c[i];
		rep(j,m)
			cin>>a[i][j];
	}
	int ans=1e9+7;
	rep(i,(1<<n))
	{
		int cost=0;
		memset(now,0,sizeof(now));
		rep(j,n)if((i>>j)&1)
		{
			cost+=c[j];
			rep(k,m)now[k]+=a[j][k];
		}
		bool f=0;
		rep(j,m)
		{
			if(now[j]<x)f=1;
		}
		if(!f)ans=min(ans,cost);
	}
	if(ans==1e9+7)ans=-1;
	cout<<ans<<endl;
	return 0;
}



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

int main(){
  string S;
  cin >> S;
  ll K;
  cin >> K;
  ll cnt=0;
  ll s=S.size();
  bool q=false;
  bool w=true;
  for(int i=0;i<s-1;i++){
    if(S[i]!=S[i+1]){w=false;}
  }
  if(w){
    cout << (s*K)/2 << endl;
    return 0;
  }
  for(int i=0;i<s;i++){
    if(i==s-1){
      if(S[i]==S[0]){q=true;}
    }
    else{
      if(S[i]==S[i+1]){cnt++; i++;}
    }
  }
  cnt=cnt*K;
  if(q){cnt+=K-1;}
  
  ll cn=0;
  q=false;
  reverse(S.begin(),S.end());
  for(int i=0;i<s;i++){
    if(i==s-1){
      if(S[i]==S[0]){q=true;}
    }
    else{
      if(S[i]==S[i+1]){cn++; i++;}
    }
  }
  cn=cn*K;
  if(q){cn+=K-1;}
  cout << min(cn,cnt) << endl;
}

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

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    long long n,a,b;
    cin >> n >> a >> b;
    long long count,rem;
    count = n/(a+b);
    if(n - (a+b)*count >= a) {
        rem = a;
    }else {
        rem = n - (a+b)*count;
    }
    long long ball;
    ball = a*count + rem;
    cout << ball;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n, m, c;
  	cin >> n >> m >> c;
  	int b[m];
  	for(int i=0;i<m;i++) cin >> b[i];
  	int a;
  	int cnt =0;
  	for(int i=0;i<n;i++){
      int ans = 0;
      for(int j=0;j<m;j++) {
        cin >> a;
        ans += a * b[j];
      }
      if (ans + c > 0) cnt++;
    }
  	cout << cnt << endl;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  int ans=0;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    if(a>=K){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool data[50];
int main(void){
  string s;
  string t;
  cin>>s;
  cin>>t;
  int length=s.length();
  int length_t=t.length();
  for(int i=0;i<length;i++){
    data[i]=false;
  }
  for(int i=0;i<length_t;i++){
    for(int j=0;j<length;j++){
      if(s[j]==t[i] || s[j]=='?'){
        if(i==0){
          if(i!=0)continue;
          data[j]=true;
        }else{
          if(j==0)continue;
          if(data[j-1]){
            data[j]=true;
          }
        }
      }
    }
  }
  cout<<endl;
  int count=0;
  int point=-1;
  int ans_count=0;
  string pre;
  string ans;
  for(int i=0;i<length;i++){
    if(data[i]){
      if(count==0)point=i;
      count++;
    }else{
      point=-1;
      count=0;
    }
    if(count==length_t){
      pre=s;
      for(int j=0;j<length_t;j++){
        if(s[point+j]==t[j] || s[point+j]=='?'){
          s[point+j]=t[j];
        }else{
          goto GO;
        }
      }
      for(int j=0;j<length;j++){
        if(s[j]=='?')s[j]='a';
      }
      if(ans_count==0){
        ans=s;
        ans_count++;
      }else{
        if(ans > s){
          ans=s;
        }
      }
      GO:
      count=0;
      s=pre;
      i=point;
    }
  }
  if(ans_count==0){
    cout<<"UNRESTORABLE"<<endl;
  }else{
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

double f1(double a,double b,double alpha,double x){
	return a*pow(b,2)*tan(M_PI/2-alpha)-2*x;
}

double f2(double a,double alpha,double x){
	return pow(a,3)*tan(alpha)-2*x;
}

int main()
{
	double a,b,x;
	cin>>a>>b>>x;

	if(2*x<=a*a*b){
		// cout<<"lower case"<<endl;
		double low=0,high=M_PI/2;
		while(abs(f1(a,b,high,x))>1e-8){
			double mid=(low+high)/2;
			if(f1(a,b,mid,x)<0)high=mid;
			else low=mid;
		}
		cout<<setprecision(12)<<high*180/M_PI<<endl;
	}else{
		double low=0,high=M_PI/2;
		x=a*a*b-x;
		while(abs(f2(a,low,x))>1e-8){
			double mid=(low+high)/2;
			if(f2(a,mid,x)<0)low=mid;
			else high=mid;
		}
		cout<<setprecision(12)<<low*180/M_PI<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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



int N;
string s;

int main () {
  cin >> N;
  cin >> s;
  int l = s.size();

  Rep(i, l) {
    char tmp = ((s[i] - 'A') + N) % 26 + 'A';
    cout << tmp;
  }

  cout << "\n";

}

Measured memory_bytes: 256
public class Main {
	static int n;
	static long z;
	static long w;
	static long[] a;
	private static void solve() {
		int n = ni();
		long z = nl();
		long w = nl();
		long[] a = nal(n);
 
		if (n == 1) {
			System.out.println(Math.abs(a[n - 1] - w));
		} else {
			long ret = Math.max(Math.abs(a[n - 1] - w), Math.abs(a[n - 2] - a[n - 1]));
	
			System.out.println(ret);
		}
	}
	


	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			@Override
			public void run() {
				long start = System.currentTimeMillis();
				String debug = args.length > 0 ? args[0] : null;
				if (debug != null) {
					try {
						is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
					} catch (Exception e) {
						throw new RuntimeException(e);
					}
				}
				reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
				solve();
				out.flush();
				tr((System.currentTimeMillis() - start) + "ms");
			}
		}, "", 64000000).start();
	}

	private static java.io.InputStream is = System.in;
	private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
	private static java.util.StringTokenizer tokenizer = null;
	private static java.io.BufferedReader reader;

	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new java.util.StringTokenizer(reader.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	private static double nd() {
		return Double.parseDouble(next());
	}

	private static long nl() {
		return Long.parseLong(next());
	}

	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private static char[] ns() {
		return next().toCharArray();
	}

	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}

	private static int[][] ntable(int n, int m) {
		int[][] table = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[i][j] = ni();
			}
		}
		return table;
	}

	private static int[][] nlist(int n, int m) {
		int[][] table = new int[m][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[j][i] = ni();
			}
		}
		return table;
	}

	private static int ni() {
		return Integer.parseInt(next());
	}

	private static void tr(Object... o) {
		if (is != System.in)
			System.out.println(java.util.Arrays.deepToString(o));
	}
}


Measured memory_bytes: 23124
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

template <typename F>
class
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
    [[nodiscard]]
#elif defined(__GNUC__) && __GNUC_PREREQ(3, 4)
    __attribute__((warn_unused_result))
#endif  // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
    FixPoint : F {
      public :
          explicit constexpr FixPoint(F&& f) noexcept : F(std::forward<F>(f)) {}

      template <typename... Args>
      constexpr decltype(auto)
      operator()(Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
}
}
;  // class FixPoint

template <typename F>
static inline constexpr decltype(auto)
makeFixPoint(F&& f) noexcept {
  return FixPoint<F>{std::forward<F>(f)};
}

ll dp[310][310][310];

int main() {
  int N, M;
  while (cin >> N >> M) {
    vector<vector<pair<int, int>>> conditions(N);
    for (int i = 0; i < M; i++) {
      int s, t, x;
      cin >> s >> t >> x;
      --s;
      --t;
      conditions[t].emplace_back(s, x);
    }
    memset(dp, -1, sizeof(dp));
    auto solve = makeFixPoint([&](auto f, int r, int g, int b) -> ll {
      ll& res = dp[r + 1][g + 1][b + 1];
      if (res != -1) {
        return res;
      }
      int k = max({r, g, b});
      if (k >= 0) {
        for (auto cond : conditions[k]) {
          int s = cond.first, x = cond.second;
          int y = (s <= r) + (s <= g) + (s <= b);
          if (y != x) {
            return res = 0;
          }
        }
      }
      if (k >= N - 1) {
        return res = 1;
      }
      res = 0;
      res = (res + f(k + 1, g, b)) % MOD;
      res = (res + f(r, k + 1, b)) % MOD;
      res = (res + f(r, g, k + 1)) % MOD;
      return res;
    });
    cout << solve(-1, -1, -1) << endl;
  }
  return 0;
}


Measured memory_bytes: 233088
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int a, b, c; cin >> a >> b >> c;
  cout << max({10 * a + b + c, a + 10 * b + c, a + b + 10 * c}) << '\n';
}

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

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

  vector<pair<string, int>> restraunt;
  vector<pair<string, int>> check;

  for(int i = 0; i < N; i++){
    string s;
    int p;
    cin >> s >> p;
  
    restraunt.push_back(make_pair(s, p));
  }
  check = restraunt;
  sort(restraunt.begin(), restraunt.end());
  
  for(int i = 0; i < N; i++){
    for(int j = i + 1; j < N; j++){
      if(restraunt.at(i).first == restraunt.at(j).first && 
         restraunt.at(i).second < restraunt.at(j).second){
        int before;
        int after;
        tie(ignore, before) = restraunt.at(i);
        tie(ignore, after) = restraunt.at(j);
        get<1>(restraunt.at(i)) = after;
        get<1>(restraunt.at(j)) = before; 
      }
         
    }
    
  }
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(restraunt.at(i) == check.at(j)){
        cout << j + 1 << endl;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define LL long long
using namespace std;
LL n;
int main()
{
	scanf("%lld",&n);LL x=n/1000000000+1,y=n%1000000000;
	if(n==1000000000000000000) return puts("0 0 0 1000000000 1000000000 0"),0;
	return printf("0 0 %lld %lld 1 1000000000",x,1000000000-y),0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

template <typename T, typename U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

int main() {
    int N, P;
    cin >> N >> P;
    bool odd = false;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        if (A & 1) odd = true;
    }
    cout << (odd ? ipow(2LL, N - 1) : (P ? 0 : ipow(2LL, N))) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

int n, m, f[MAXN], siz[MAXN];

inline int Find(int x)
{
	while (x ^ f[x])
		x = f[x] = f[f[x]];
	return x;
}

inline void Merge(int x, int y)
{
	x = Find(x), y = Find(y);
	if (x == y)
		return ;
	siz[x] += siz[y], f[y] = x;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), m = Read();
	for (int i = 1; i <= n; i ++)
		f[i] = i, siz[i] = 1;
	for (int i = 1; i <= m; i ++)
		Merge(Read(), Read());
	for (int i = 1; i <= n; i ++)
		if (Find(i) == i && (Find(i) ^ Find(1)) && (Find(i) ^ Find(2)))
			if (siz[Find(1)] >= siz[Find(2)])
				siz[Find(1)] += siz[i];
			else
				siz[Find(2)] += siz[i];
	LL ret = 1LL * siz[Find(1)] * (siz[Find(1)] - 1) / 2 + 1LL * siz[Find(2)] * (siz[Find(2)] - 1) / 2;
	return printf("%lld\n", ret - m), 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	int D;
	cin >> D;
	if (D == 25)cout << "Christmas" << endl;
	else if (D == 24)cout << "Christmas Eve" << endl;
	else if (D == 23)cout << "Christmas Eve Eve" << endl;
	else cout << "Christmas Eve Eve Eve" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

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

  bool flag1=true, flag2=true;

  for(int i=0; i<s.length(); i+=2){
    if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
      continue;
    else
      flag1 = false;
  }
  for(int i=1; i<s.length(); i+=2){
    if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
      continue;
    else
      flag2 = false;
  }

  if (flag1 && flag2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize("Os")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}
int main()
{
    vok();
    ll n,s;
    IN n>>s;
    vll v(n);
    loop(i,0,n)
    {
        IN v[i];
    }
    vll dp(s+1,0LL);
    dp[0]=1LL;
    ll div_2=P(2,M-2LL,M)%M;
    loop(i,0,n)
    {
        rloop(j,s,v[i])
        {
            dp[j]+=((dp[j-v[i]]*div_2)%M);
            dp[j]%=M;
        }
    }
    ll ans=P(2LL,n,M);
    ans%=M;
    ans*=dp[s];
    ans%=M;
    OUT ans<<endl
    return 0;
}

Measured memory_bytes: 3672
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let acc = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    acc.(i + 1) <- (as_.(i) + acc.(i) + k - 1) mod k;
  done;
  let map = Array.make (n + 2) IntMap.empty in
  for i = 0 to n do
    map.(i + 1) <-
      IntMap.add acc.(i)
        (1 +
          try IntMap.find acc.(i) map.(i)
          with Not_found -> 0) map.(i)
  done;
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 @@
  Array.init (n + 1) @@ fun i ->
    ( try IntMap.find acc.(i) map.(i)
      with Not_found -> 0 ) -
    ( try IntMap.find acc.(i) map.(max 0 (i - k + 1))
      with Not_found -> 0 )

Measured memory_bytes: 187828
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

bool judge(string S){
  cerr << S << endl;
  bool ret = true;
  for (int i=0; i<S.size(); i++){
    if (S[i] != S[S.size() - i - 1]){
      ret = false;
      break;
    }
  }
  
  return ret;
}

#include <iostream>
#include <string>

using namespace std;

int main(){
  string S;
  cin >> S;
  bool f = judge(S) & judge(S.substr(0, (S.size() - 1) / 2)) & judge(S.substr((S.size() + 3) / 2 -1, S.size() - ((S.size() + 3) / 2-1)));
  cout << (f ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int n;
	string cmd,str;
	set<string> s;

	cin >> n;
	rep(i,n){
	cin >> cmd >> str;

	if(cmd == "insert"){
	s.insert(str);
	}
	else{
		if(s.find(str) != s.end()){
		cout << "yes" << endl;
		}
		else{
		cout << "no" << endl;
		}
	}
	}

	return 0;
}



Measured memory_bytes: 32608
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in cs(in a, in b){
  return (a-b)*(a-b);
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  VI mar;
  cin>>n;
  mar.resize(n);
  forn(i,n)
    cin>>mar[i];
  in bst=1e9;
  for(in g=-100;g<=100;++g){
    in sm=0;
    forn(i,n)
      sm+=cs(mar[i],g);
    bst=min(bst,sm);
  }
  cout<<bst<<endl;
  return 0;
}

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

int main() {
    while (true) {
        int b, r, g, c, s, t;
        cin >> b >> r >> g >> c >> s >> t;
        
        if (b==0 && r==0 && g==0 && c==0 && s==0 && t==0) {
            break;
        }
        
        int free_game = s;
        int bonus_game = 5*b+3*r;
        int normal_game = t-free_game-bonus_game;
        
        int sub = 2*bonus_game+3*normal_game;
        int add = 15*(bonus_game+b+r)+7*g+2*c;
        
        cout << 100-sub+add << endl;
    }
}


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

using namespace std;
using nagai = long long;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	c = min(c, a + b + 1);
	cout << b + c << '\n';
	return 0;
}



Measured memory_bytes: 896
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
typedef long int li;


int fact_ord(int b,int n){
  int ret=0;
  while(n){
    n/=b;
    ret+=n;
  }
  return ret;
}

int main(){
  int n; cin >>n;
  int primes[]=  {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47} ;
  int thresh[5]= {74,24,14,4,2} ;
  int array[5]=  {0,0,0,0,0};
  for(int x:primes){
    int a=fact_ord(x,n);
    rep(i,5){
      if(a>=thresh[i]) array[i]++;
    }
  }
  if(df) {
    for(int x:array) cout << x << " ";
    cout << "\n";
  }
  int ans=0;
  ans+=array[0];
  ans+=array[1]*(array[4]-1);
  ans+=array[2]*(array[3]-1);
  ans+=array[3]*(array[3]-1)/2*(array[4]-2);
  printf("%d\n",ans);
}


Measured memory_bytes: 256