akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int digits(LL num){
	LL cnt = 1;
	int c = 0;
	while(true){
		if (num/cnt>=1){
			cnt *= 10;
			c++;
		}
		else
			break;
	}
	return c;
}

int main(int argc, char const *argv[])
{
	LL num;
	cin >> num;
	int dig =10000;
	for(LL a=1; a*a <= num; a++){
		if(num % a == 0){
			dig = min(dig,max(digits(a),digits(num/a)));
		}
	}
	cout<<dig<<endl;
}

Measured memory_bytes: 256
// ABC082B - Two Anagrams

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

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

	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());

	if (s < t) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	char s[100000];
	scanf("%s", s);
	int i;
	int count = 0;
	for (i = 0; s[i] != '\0'; i++) {
		if (s[i] == '0' && s[i+1] == '0') {
			s[i+1] = '1';
			count++;
		} else if (s[i] == '1' && s[i+1] == '1'){
			s[i+1] = '0';
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi vector <int>
#define vp vector <pair<int,int>>
#define f(x,y,z) for(x=y;x<z;x++)
#define pb push_back
#define mp make_pair
#define ld long double
#define fb(x,y,z) for(x=y;x>z;x--)
#define pqf priority_queue <int,vector <int>> 
#define pqb priority_queue <int,vector <int>,greater<int>> 
#define ps(x,y) fixed << setprecision(y) << x
#define PI 3.1415926535
#define mod 1000000007 
#define mods 998244353 
#define setbits(x) __builtin_popcountll(x)
#define all(x) (x).begin(), (x).end()
#define fill(a,b) memset(a,b,sizeof(a))


// AUTHOR ALOK KUMAR
int lcm(int a,int b)
{
    return (a*b)/(__gcd(a,b));
}
int power(int a,int b)
{
    int c=1;
    while(b)
    {
        if(b&1)
        c*=a;
        a*=a;
        b>>=1;
    }
    return c;
}
void solve()
{
    int n,m;
    cin>>n>>m;
    vi v[n+1];
    int i,j,k,k1,k2;
    f(i,0,m)
    {
        cin>>k1>>k2;
        v[k1].pb(k2);
        v[k2].pb(k1);
    }
    int vis[n+1]={0};
    int insertq[n+1]={0};
    queue <int> q;
    int count=0;
    f(i,1,n+1)
    {
        if(vis[i]==0)
        {
            count++;
            insertq[i]==1;
            q.push(i);
            while(!q.empty())
            {
                j=q.front();
                q.pop();
                vis[j]=1;
                f(k,0,v[j].size())
                {
                    if(vis[v[j][k]]==0&&insertq[v[j][k]]==0)
                    {
                        q.push(v[j][k]);
                        insertq[v[j][k]]=1;
                    }
                }
            }
            
        }
    }
    cout<<count-1<<"\n";
    
    
    
}



int32_t main()
{
    IOS
    int t=1;
   // cin>>t;
    while(t--)
    solve();
    return 0;
}



































Measured memory_bytes: 11208
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    static boolean[] ok;
    static int n;
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	int[] num = new int[10];
	ok = new boolean[10];
	String line;
	int index;
	while (scan.hasNext()) {
	    Arrays.fill(num, 0);
	    Arrays.fill(ok, false);
	    line = scan.nextLine();
	    for (int i = 0; i < 13; i++) {
		index = Integer.parseInt(line.substring(i, i + 1));
		num[index]++;
	    }
	    for (int i = 1; i < 10; i++) {
		n = i;
		if (num[i] >= 4) {
		    continue;
		}
		num[i] += 1;
		for (int j = 1; j < 10; j++) {
		    if (num[j] >= 2) {
			num[j] -= 2;
			isPuzzle(num);
			num[j] += 2;
		    }
		}
		num[i] -= 1;
	    }
	    StringBuilder sb = new StringBuilder();
	    boolean empty = true;
	    for (int i = 1; i < 10; i++) {
		if (ok[i] == true) {
		    sb.append(i + " ");
		    empty = false;
		}
	    }
	    if (empty == true) {
		System.out.print(0);
	    }
	    System.out.println(sb.toString().trim());
	}
    }
    public static void isPuzzle (int[] num) {
	if (isAllZero(num)) {
	    ok[n] = true;
	    return;
        }
	for (int i = 1; i < 10; i++) {
	    if (num[i] >= 3) {
		num[i] -= 3;
		isPuzzle(num);
		num[i] += 3;
	    }
	}
	for (int i = 1; i < 8; i++) {
	    if (num[i] > 0 && num[i + 1] > 0 && num[i + 2] > 0) {
		num[i] -= 1;
		num[i + 1] -= 1;
		num[i + 2] -= 1;
		isPuzzle(num);
		num[i] += 1;
		num[i + 1] += 1;
		num[i + 2] += 1;
	    }
	}
    }

    public static boolean isAllZero (int[] num) {
	for (int i = 1; i < 10; i++) {
	    if (num[i] > 0) {
		return false;
	    }
	}
	return true;
    }
}

Measured memory_bytes: 26804
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    cout << (a <= x && x <= a + b ? "YES" : "NO") << endl;
 
    return 0;
}

Measured memory_bytes: 256
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
# MOD = 10 ** 9 + 7
MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def fast_pow(num, kata, mod):
        if kata == 0:
            return 1

        res = 1
        while kata > 0:
            if kata & 1 == 1:
                res = res * num % mod
            num = num * num % mod

            kata >>= 1
        return res

    def prepare(n, MOD):
        f = 1
        factorials = [1]
        for m in range(1, n + 1):
            f *= m
            f %= MOD
            factorials.append(f)
        inv = pow(f, MOD - 2, MOD)
        invs = [1] * (n + 1)
        invs[n] = inv
        for m in range(n, 1, -1):
            inv *= m
            inv %= MOD
            invs[m - 1] = inv
        return factorials, invs

    n, m, k = ns()

    p, i = prepare(n, MOD)

    result = 0

    for ki in range(k + 1):
        ans = 1
        ans *= m % MOD
        ans *= fast_pow(m - 1, n - 1 - ki, MOD)
        ans %= MOD
        ans *= p[n - 1] * i[ki] * i[n - 1 - ki]
        ans %= MOD

        result += ans
        result %= MOD

    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42972
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1 for _ in range(n)]  # 各要素の親 自分が根の場合は -1 * (木の要素数)

    def root(self, x):  # xが属する木の根を返す
        if self.parents[x] < 0:  # 自分が根の場合
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def merge(self, x, y):  # xが属する木とyが属する木を合体する
        x_root = self.root(x)  # xの根
        y_root = self.root(y)  # yの根

        if x_root == y_root:  # 同じ木に属する
            return

        if self.parents[x_root] > self.parents[y_root]:  # x_rootの要素数 > y_rootの要素数 にしたい
            x_root, y_root = y_root, x_root

        self.parents[x_root] += self.parents[y_root] # x_rootにy_rootを合体
        self.parents[y_root] = x_root


def main():
    h, w = map(int, input().split())
    grid = [list(input()) for _ in range(h)]
    black_list = []
    uf = UnionFind(h * w)

    for r in range(h):
        for c in range(w):
            if grid[r][c] == "#":
                black_list.append([r, c])
            for dr, dc in [[0, 1], [1, 0]]:
                nr = r + dr
                nc = c + dc
                if not (0 <= nr < h and 0 <= nc < w):
                    continue
                if grid[r][c] != grid[nr][nc]:
                    # 0 to h*w-1 に変換
                    uf.merge(r * w + c, nr * w + nc)

    ans = 0
    black_dict = dict()
    for r, c in black_list:  # それぞれの黒マスに対して
        z = uf.root(r * w + c)  # 根を求める
        if z in black_dict:  # それぞれの木に何個黒マスがあるか
            black_dict[z] += 1
        else:
            black_dict[z] = 1

    for index, size in enumerate(uf.parents):
        if size < 0:  # それぞれの木に対して
            if index not in black_dict:  # 黒マス0コは無視
                continue
            ans += black_dict[index] * (- size - black_dict[index])  # 黒マス x 白マス

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 108692
#include<bits/stdc++.h>
using namespace std;
int MIN=9999;
string S;
long long int MOD = 1000000007;
const int MAX = 1000001;
long long int fac[MAX],finv[MAX], inv[MAX];

void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i=2;i<MAX;i++){
        fac[i] = fac[i-1]* i % MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long COM(int n,int k){
    if(n < k)return 0;
    if(n < 0 || k< 0)return 0;
    return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
}

int main(){
    long long int X,Y,A[100002];
    cin >> X >> Y;
    COMinit();
    long long int n1=0;
    for(int i=0;i<=max(X,Y);i++){
        long long int n2 = i;
        long long int n1 = X-2*i;
        if(n1 < 0)
            continue;
        if(n1*2+n2 == Y){
            cout << COM(n1+n2,n2) << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    
  return 0;
}

Measured memory_bytes: 23680
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;
        static void Main(string[] args)
        {
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var Aij = new long[N, N];
            var Aijnum = new long[N];
            for (var i = 0; i < N; ++i)
            {
                var t = Sarray();
                for (var j = 0; j < N; ++j)
                    Aij[i, j] = t[j];
            }
            
            var beki = new long[N, N];
            var ans = new long[N, N];
            for (var i = 0; i < N; ++i)
                ans[i, i] = 1;

            for (; 0 < K; K >>= 1)
            {
                if (0 != (K & 1))
                    ans = calcMat(ans, Aij);
                Aij = calcMat(Aij, Aij);
            }
            var sum = 0L;
            for (var i = 0; i < N; ++i)
                for (var j = 0; j < N; ++j)
                    sum = (sum + ans[i, j]) % Mod;
            WriteLine(sum);
        }
        static long[,] calcMat(long[,] L, long[,]R)
        {
            if (L.GetLength(1) != R.GetLength(0))
                throw new RankException();
            var I= L.GetLength(0);
            var J = L.GetLength(1);
            var K = R.GetLength(1);
            var clc = new long[I, K];
            for (var i = 0; i < I; ++i)
                for (var k = 0; k < K; ++k)
                    for (var j = 0; j < J; ++j)
                        clc[i, k] = (clc[i, k] + L[i, j] * R[j, k]) % Mod;
            return clc;
            
        }

    }
}

Measured memory_bytes: 14944
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 200005, INF = 0x3f3f3f3f;
typedef long long i64;

int N, A[MAX_N], B[MAX_N];

i64 work1() {
  int Rmin = INF, Rmax = -INF, Bmin = INF, Bmax = -INF;
  for (int i = 1; i <= N; ++i) {
    Rmin = min(Rmin, A[i]), Rmax = max(Rmax, A[i]);
    Bmin = min(Bmin, B[i]), Bmax = max(Bmax, B[i]);
  }
  return 1LL * (Rmax - Rmin) * (Bmax - Bmin);
}

bool cmp(int x, int y) {
  return B[x] < B[y];
}

i64 work2() {
  int maxA = -INF, idA = 0;
  int minB = INF, idB = 0;

  for (int i = 1; i <= N; ++i) {
    if (maxA <= A[i]) maxA = A[i], idA = i;
    if (minB >= B[i]) minB = B[i], idB = i;
  }
  
  if (idA == idB) return 1LL * INF * INF;

  int temp = maxA - minB;
  int Bmin = INF, Bmax = -INF, lim = INF;
  
  static int id[MAX_N], tot;
  
  for (int i = 1; i <= N; ++i)
    if (i != idA && i != idB) {
      Bmax = max(Bmax, B[i]), lim = min(lim, A[i]);
      Bmin = min(Bmin, B[i]);
      id[++tot] = i;
    }
  
  Bmax = max(Bmax, max(B[idA], A[idB]));
  Bmin = min(Bmin, min(B[idA], A[idB]));
  i64 now = 1LL * temp * (Bmax - Bmin);
  
  sort(id + 1, id + tot + 1, cmp);

  for (int i = 2; i <= tot; ++i) {
    int x = B[id[i]], val = min(x, lim);
    Bmax = max(A[id[i - 1]], Bmax), Bmin = val;
    
    Bmin = min(Bmin, min(B[idA], A[idB]));

    now = min(now, 1LL * temp * (Bmax - Bmin));
    if (x >= lim) break;
  }

  return now;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d%d", &A[i], &B[i]);
    if (A[i] < B[i]) swap(A[i], B[i]);
  }

  i64 res = min(work1(), work2());

  printf("%lld\n", res);
  
  return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;

  vector<vector<char>> bild(h+2, vector<char>(w+2));
  for(int i=0;i<w+2;i++) {
    bild[0][i] = '.';
    bild[h+1][i] = '.';
  }
  for(int i=1;i<h+1;i++) {
    for(int j=1;j<w+1;j++) {
      bild[i][0] = '.';
      cin >> bild[i][j];
      bild[i][w+1]='.';
    }
  }

  bool yes = true;

  for(int i=1;i<=h;i++) {
    for(int j=1;j<=w;j++) {
      if(bild[i][j] == '#') {
        if(bild[i][j-1] == '#') {
          continue;
        }
        if(bild[i][j+1] == '#') {
          continue;
        }
        if(bild[i-1][j] == '#') {
          continue;
        }
        if(bild[i+1][j] == '#') {
          continue;
        }
        yes = false;
        break;
      }
    }
    if(!yes) {
      break;
    }
  }

  if(yes) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<tuple>
#include<vector>
#include<algorithm>
#include<cmath>

using std::begin;
using std::end;

int gcd(int n, int m) {
  if(n < m) return gcd(m, n);
  if(m == 0) return n;

  return gcd(m, n % m);
}

void print_kouyakusu(int n) {
  std::vector<int> v;
  for(int i{1}; i <= std::sqrt(n); ++i) {
    if(n % i == 0) {
      v.push_back(i);
      if(i * i != n) {
        v.push_back(n / i);
      }
    }
  }
  std::sort(begin(v), end(v));
  for(int e: v) {
    std::cout << e << std::endl;
  }
}

int main(int, char**) {
  int n;
  std::cin >> n;
  if(n == 2) {
    int a, b;
    std::cin >> a >> b;

    int d{gcd(a, b)};

    print_kouyakusu(d);
  } else {
    int a, b, c;
    std::cin >> a >> b >> c;

    int d{gcd(a, b)};
    int d2{gcd(c, d)};

    print_kouyakusu(d2);
  }

  return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int ans = 0;
long long int N;
void dfs(long long int x,int a,int b,int c){
	if(x > N) return;
	if(a & b & c) ans++;
	dfs(10*x+3, 1, b, c);
	dfs(10*x+5, a, 1, c);
	dfs(10*x+7, a, b, 1);
}

int main() {
	cin >> N;
	dfs(0, 0, 0, 0);
	cout << ans << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
stu=[list(map(int,input().split()))for i in range(n)]
po=[list(map(int,input().split()))for i in range(m)]
for i in stu:
    tmp=10**12
    for j in po:
        ab=abs(i[0]-j[0])+abs(i[1]-j[1])
        if ab<tmp:
            tmp=ab
            ans=po.index(j)
    print(ans+1)

Measured memory_bytes: 3064
import math
import os
import random
import re
import sys

def solve(n, v, c):
	x = 0
	if n < 1:
		return 0
	for i in range(n):
		if v[i] > c[i]: x += v[i] - c[i]

	return x

if __name__ == '__main__':
    # a, b = map(int, input().split())
    # c, d = map(int, input().split())
    # print(2 + abs(c-a) + abs(d-b) - 1)
    # a, b, t =  map(int, input().split())
    n = int(input())
    v = list(map(int, input().split()))
    c = list(map(int, input().split()))
    print(solve(n,v,c))

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, x[100005];
    for (int i = 0; i < 100005; i++) {
        x[i] = 0;
    }

    cin >> N;
    int a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (a > 0)
            x[a - 1]++;
        x[a]++;
        x[a + 1]++;
    }
    int ans = 0;
    for (int i = 0; i < 100005; i++) {
        ans = max(ans, x[i]);
    }
    cout << ans;
}

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

int main()
{
	int a, b;
	cin >> a >> b;
	if (a==b||a==b==1)
		cout << "Draw";
	else if ((a > b)&&(b!=1) ||( a == 1&& b>a))
		cout << "Alice";
	else
	/*else if ((a < b) ||( b == 1&&a>b))*/
		cout << "Bob";

}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  
#include <numeric>
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
using ll = long long;
 
const int precision = 3;
const int modulo =  1000000007; // 10^9 + 7
const ll lmodulo =  1000000007; // 10^9 + 7
 
const double EPS = 1e-9;
const ll inf = 1e18;

void solve () {
	int n; cin >> n;
	vector<vector<int>> days(n, vector<int>(3));
	for (auto &it : days) {
		cin >> it[0] >> it[1] >> it[2];
	}

	vector<vector<int>> dp(n, vector<int>(3));
	dp[0] = days[0];

	for (auto i = 1; i < n; ++i) {
		dp[i][0] = days[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = days[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = days[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
	}

	int ret = max(dp[n - 1][0], dp[n - 1][1]);
	ret = max(ret, dp[n - 1][2]);
	cout << ret << endl;
}

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



Measured memory_bytes: 11264
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

class bipartite_matching {
 public:
  int n;
  std::vector<std::vector<int>> g;
  std::vector<int> match;

  bipartite_matching(int n_) : n(n_), g(n_), match(n_), used(n_) {}

  void add_edge(int u, int v) {
    g[u].push_back(v);
    g[v].push_back(u);
  }

  int maximum_matching(void) {
    int res = 0;
    fill(begin(match), end(match), -1);
    for (int v = 0; v < n; ++v) {
      if (match[v] == -1) {
        fill(begin(used), end(used), false);
        if (dfs(v))
          res++;
      }
    }
    return res;
  }

 private:
  std::vector<int> used;
  bool dfs(int v) {
    used[v] = true;
    for (int u : g[v]) {
      int w = match[u];
      if (w == -1 || (!used[w] && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }
};

int main() {
  int N;
  get(N);
  vector<Pi> R(N), B(N);
  FOR(i, N) { cin >> R[i].first >> R[i].second; }
  FOR(i, N) { cin >> B[i].first >> B[i].second; }
  bipartite_matching bm(2 * N);
  FOR(i, N) {
    FOR(j, N) {
      if (R[i].first < B[j].first && R[i].second < B[j].second)
        bm.add_edge(i, N + j);
    }
  }
  print(bm.maximum_matching());
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

  std::string S;  std::cin >> S;
  for (int i = 0; i < 3; ++i)
    if (S[i] == '7') {
      std::cout << "Yes\n";
      return 0;
    }

  std::cout << "No\n";

  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#define ULL unsigned long long
#define INF 0x3f3f3f3f
using namespace std;
int f(int x){
    int sum=0;
    while(x>0){
        x/=10;
        sum++;
    }
    return sum;
}
int main() {
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(f(i)%2==1){
            ans++;
        }
    }
    printf("%d",ans);
    return 0;
}


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

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int M, D;
   cin >> M >> D;
   int cnt = 0;
   for (int m = 1; m <= M; m++) {
      for (int d = 20; d <= D; d++) {
         if (d % 10 < 2) continue;
         if (m == (d % 10) * (d / 10)) cnt++;
      }
   }
   cout << cnt << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for (size_t i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (size_t i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define INF 1e7

int N, K;
bool like[10];

bool check(int n)
{
  bool r = true;
  while (1) {
    r &= like[n%10];
    n /= 10;
    if (n == 0) break;
  }
  return r;
}

int main()
{
  REP(i,10) like[i] = true;
  cin>>N>>K;
  REP(i,K) {
    int D;
    cin>>D;
    like[D] = false;
  }

  FOR(i,N,INF) {
    if (check(i)) {
      cout<<i<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int 
signed main() {
int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a+b>=k){cout<<min(a,k);}
    else{cout<<(a)-(k-a-b);}
    
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=59,mod=1e9+7;
	inline int add(int x,int y){return x+y>=mod?x-mod+y:x+y;}
	inline void addto(int &x,int y){x=x+y>=mod?x-mod+y:x+y;}
	inline int sub(int x,int y){return x>=y?x-y:x+mod-y;}
	inline int qpow(int x,int y){
		int ret=1;
		while(y){
			if(y&1) ret=1LL*x*ret%mod;
			x=1LL*x*x%mod,y>>=1;
		}
		return ret;
	}

	int C[N][N],n,f[N][N];
	int main(){
		n=read<int>();
		C[0][0]=1;
		for(int i=1;i<=n;i++){
			C[i][0]=1;
			for(int j=1;j<=i;j++)
				C[i][j]=add(C[i-1][j],C[i-1][j-1]);
		}

		f[1][0]=f[1][1]=n;
		for(int i=1;i<n;i++)
			for(int j=0;j<=i;j++)
				for(int k=max(j,1);k<=n-i;k++) if(~(k-j)&1){
					int d=(k-j)/2;
					for(int x=0;x<=k;x++)
						addto(f[i+k][abs(x-d)],1LL*f[i][j]*C[n-i][k]%mod*C[k][x]%mod);
				}
		printf("%d\n",f[n][0]);
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

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

int main() {
  int n; cin >> n;
  long long ans = 0;
  for(int i = 1; i <= n; i++) {
    if(i%15==0 || i % 3 == 0 || i % 5 == 0) continue;
    ans += i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
const int M = 2e5 ;
int n , k;
int a[M];
double ans[M];
int main()
{

    cin >> n >> k ;
    for (int i =0 ; i < n ;i++)
        cin >> a[i];
    for (int i =0 ; i < n ;i++)
    {
        double cur = 0 ;
        for (int j = 1;  j <= a[i] ;j++)
        {
            cur += j * (1.0/a[i]);
        }
        ans[i] = cur ;
    }
    double mx = 0;
    double cur =0 ;
    for (int i = 0; i < k-1 ;i++)
        cur += ans[i];
    for (int i =0,j=k-1;j<n;j++,i++)
    {
        cur += ans[j];
        mx = max (cur , mx);
        cur -=ans[i];
    }
    printf ("%.10f\n", mx );


}


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

int main(){
	int a,b,k ;
	cin >> a >> b >> k ;
	int th = 0 ;
	for(int i=100;i>0;i--){
		if(a%i==0&&b%i==0){
			th++ ;
			if(th==k){
				cout << i << endl ;
				return 0 ;
			}
		}
	}
}

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

long long getDiff(long long H,long long W){
  long long smax,smin,sdiff;
  sdiff = 1 << 30;
  for(long long h=0;h<H;h++){
    smax=smin=h*W;
    long long h1=(H-h)/2+(H-h)%2;
    long long h2=(H-h)/2;
    smax=max(smax,(long long)h1*W);
    smax=max(smax,(long long)h2*W);
    smin=min(smin,(long long)h1*W);
    smin=min(smin,(long long)h2*W);
    sdiff = min(sdiff, smax - smin);

    smax=smin=h*W;
    long long w1=W/2+W%2;
    long long w2=W/2;

    smax=max(smax,(long long)(H-h)*w1);
    smax=max(smax,(long long)(H-h)*w2);
    smin=min(smin,(long long)(H-h)*w1);
    smin=min(smin,(long long)(H-h)*w2);

    sdiff = min(sdiff, smax - smin);
  }

  return sdiff;
}



int main(){

  long long H,W;
  cin>>H>>W;

  long long minDiff = getDiff(H,W);
  minDiff = min(minDiff, getDiff(W,H));

  cout<<minDiff<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100005
#define NIL -1

typedef struct {int p, l, r;} Node;

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if( T[u].p == NIL ) printf("root, ");
  else if( T[u].l == NIL ) printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i=0, c=T[u].l; c != NIL; i++, c=T[c].r) {
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

void rec(int u, int p) {
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r,p);
  if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(void) {
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i=0;i<n;i++) {
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++) {
      scanf("%d",&c);
      if(j==0) T[v].l=c;
      else T[l].r =c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0;i<n;i++) {
    if(T[i].p == NIL) r = i;
  }
  
  rec(r,0);
  
  for(i=0;i<n;i++) print(i);
  
  return 0;
}


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

int main(void) {

	long long A, B, C, A_temp, B_temp, C_temp;
	cin >> A >> B >> C;
	int answer = 0;


	while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0){
		A_temp = A;
		B_temp = B;
		C_temp = C;

		if (A % 2 == 0){
			B_temp += A / 2;
			C_temp += A / 2;
			A_temp -= A;
		}

		if (B % 2 == 0) {
			A_temp += B / 2;
			C_temp += B / 2;
			B_temp -= B;
		}
		
		if (C % 2 == 0) {
			A_temp += C / 2;
			B_temp += C / 2;
			C_temp -= C;
		}

		A = A_temp;
		B = B_temp;
		C = C_temp;

		answer++;

		if (answer > 1000000) {
			answer = -1;
			break;
		}
	}

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        int[] seats = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0};
        int[] groupMembers = new int[] {2, 5, 2, 2, 2};
        int[] eatTimes = new int[] {19, 39, 25, 36, 22, 42};

        int headGroup = -1;
        int pastMinutes = 0;
        int customerCount = 0;
        List<Integer> waitTime = new ArrayList<Integer>(100);

        while (customerCount < 100) {
            // たべおわる
            for (int i = 0; i < seats.length; i++) {
                seats[i] = seats[i] == 0 ? 0 : seats[i] - 1;
            }

            // 来店
            if (headGroup == -1 && pastMinutes % 5 == 0) {
                headGroup = pastMinutes / 5;
            }

            // ちゃくせき
            while (headGroup != -1) {
                int needsSequencialSeats = groupMembers[headGroup % 5];
                int sequencialSeats = 0;
                int startIndex = -1;
                for (int i = 0; i < seats.length; i++) {
                    sequencialSeats = seats[i] == 0 ? sequencialSeats + 1 : 0;

                    if (sequencialSeats == needsSequencialSeats) {
                        startIndex = i - (needsSequencialSeats - 1);
                        break;
                    }
                }

                if (startIndex != -1) {
                    // すわれたみたい
                    waitTime.add(headGroup, pastMinutes - (headGroup * 5));
                    for (int i = startIndex; i < (startIndex + needsSequencialSeats); i++) {
                        seats[i] = eatTimes[headGroup % 6];
                    }

                    headGroup = (((headGroup + 1) * 5) <= pastMinutes) ? headGroup + 1
                            : -1;
                    customerCount++;
                } else {
                    // すわれなかったみたい
                    break;
                }

            }

            pastMinutes++;

        }

        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            System.out.println(waitTime.get(sc.nextInt()));
        }

    }
}

Measured memory_bytes: 17180
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const ll MAX = 200001;
const ll MOD = 998244353;
// source by drken start
long long fac[MAX], finv[MAX], inv[MAX];

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

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

int main() {
  ll n,m,k;
  cin >> n >> m >> k;
  vector<ll> mm1pw(n);
  mm1pw[0]=1;
  for(int i=0;i<n-1;i++){
    mm1pw[i+1]=(mm1pw[i]*(m-1))%MOD;
  }
  COMinit();
  ll ans=0;
  for(int i=0;i<=k;i++){
    ans += (((COM(n-1,i)*m)%MOD)*mm1pw[n-1-i])%MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 9592
fun main() {
    val (n, d) = readInts().map { it.toLong() }
    val sqDis = d * d
    var numOfPoints = 0
    repeat(n.toInt()) {
        val (x, y) = readInts().map { it.toLong() }
        numOfPoints += if (x * x + y * y <= sqDis) 1 else 0
    }
    println(numOfPoints)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }


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

int DP[1010][1010];

int main(){
	int n;	cin>>n;
	for(int qi=0; qi<n; qi++){
		string s,t;		cin>>s>>t;
		int S=s.length(), T=t.length();
		s=" "+s;	t=" "+t;

		for(int i=0; i<=max(S,T); i++){
			DP[0][i]=DP[i][0]=0;
		}

		for(int i=1; i<=S; i++){
			for(int j=1; j<=T; j++){
				if(s[i]==t[j]){
					DP[i][j]=DP[i-1][j-1]+1;
				}else{
					DP[i][j]=max(DP[i-1][j],DP[i][j-1]);
				}
			}
		}
		cout<<DP[S][T]<<endl;
	}

	return 0;
}



Measured memory_bytes: 7128
#include<bits/stdc++.h>
#define ll long long
#define ljc 1000000007
#define inv2 500000004
using namespace std;
#define gc getchar
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
inline ll fast_pow(ll a,ll b,ll p){
	ll t=1;
	if (b==-1) return 0;
	while (b){
		if (b&1ll) t=t*a%p;
		b>>=1ll;a=a*a%p;
	}
	return t;
}
int h[201010],n;
namespace ST{
	int f[201010][20],id[201010][20];
	inline pair<int,int> query(int l,int r){
		if (l>r) return make_pair(1e9+1,1e9+1);
		int k=log2(r-l+1);
		if (f[l][k]<=f[r-(1<<k)+1][k]){
			return make_pair(f[l][k],id[l][k]);
		}else{
			return make_pair(f[r-(1<<k)+1][k],id[r-(1<<k)+1][k]);
		}
	}
	inline void init(){
		for (int i=1;i<=n;i++) f[i][0]=h[i],id[i][0]=i;
		for (int j=1;j<=19;j++){
			for (int i=1;i+(1<<j)-1<=n;i++){
				int l=i,r=i+(1<<(j-1));
				if (f[l][j-1]<=f[r][j-1]){
					id[l][j]=id[l][j-1];
					f[l][j]=f[l][j-1];
				}else{
					id[l][j]=id[r][j-1];
					f[l][j]=f[r][j-1];
				}
			}
		}
		return;
	}
}
struct node{
	ll x,y;
};
inline node init(ll xx,ll yy){
	node x;x.x=xx,x.y=yy;return x;
}
inline node dp(int l,int r,int H){
	if (l>r) return init(0,0);
//	if (l>r) return init(0,0,0);
//	if (l==r) return init(0,fast_pow(2,h[l]-H-1,ljc),fast_pow(2,h[l]-H-1,ljc));
//	ll resr=0,resb=0,res1=0;
//	int id=ST::query(l,r).second;
//	node ls=dp(l,id-1,h[id]),rs=dp(id+1,r,h[id]);
//	if (id==l){
//		res1=rs.x*2ll%ljc;
//		resb=rs.R;
//		resr=rs.B;
//	}else if (id==r){
//		res1=ls.x*2ll%ljc;
//		resb=ls.B;
//		resr=ls.R;
//	}else{
//		if ((id-l)%2==0){
//			ll tmp=ls.R*rs.B%ljc+ls.B*rs.R%ljc;
//			if (h[id]==H) resb=resr=tmp;
//			else resr=resb=tmp*fast_pow(2ll,h[id]-H-1,ljc)%ljc;
//		}else{
//			ll tmp=ls.B*rs.B%ljc+ls.R*rs.R%ljc;
//			if (h[id]==H) resb=resr=tmp;
//			else resr=resb=tmp*fast_pow(2ll,h[id]-H-1,ljc)%ljc;
//		}
////	}
//	return init(res1,resr,resb);
	vector<int> now;now.clear();
	pair<ll,ll> tmp=ST::query(l,r);
	ll xxx=tmp.first;
	for (int id=tmp.second;id<=r&&h[id]==xxx;id=ST::query(id+1,r).second) 
		now.push_back(id);
	ll resx=2,resy=0;
	/*if (tmp.second==l) resx=2,resy=0;
	else */if (tmp.second!=l){
		node son=dp(l,tmp.second-1,xxx);
		resx=son.x*2%ljc;
		resy=son.y;
		resy=(resy*2%ljc+resx)%ljc;
	}
	for (int i=1;i<(int)now.size();i++){
		int L=now[i-1],R=now[i];
		if (R-L>1){
			node son=dp(L+1,R-1,xxx);
		resy=(resx*(son.x+son.y)%ljc+resy*(2*son.x%ljc+son.y%ljc)%ljc)%ljc;
		resx=resx*son.x%ljc;
		}
		resy=(resy*2%ljc+resx)%ljc;
	}
	if (r-now.back()>=1){
		node son=dp(now.back()+1,r,xxx);
		resy=(resx*(son.x+son.y)%ljc+resy*(2*son.x%ljc+son.y%ljc)%ljc)%ljc;
		resx=resx*son.x%ljc;
	} 
	return init(resx*fast_pow(2,xxx-H-1,ljc)%ljc,resy);
}
/*
4
2 3 5 4

3
1 3 2
*/
signed main(){
	n=read();
	for (int i=1;i<=n;i++) h[i]=read();
	ST::init();
	node tmp=dp(1,n,0);
	printf("%lld\n",(tmp.x+tmp.y)%ljc);
	return 0;
}



Measured memory_bytes: 3860
while True:
  m, f, r = map(int, input().split())
  if m == -1 and f == -1 and r == -1:
    break
  if m == -1 or f == -1:
    print("F")
  elif m+f >= 80:
    print("A")
  elif 65 <= m+f < 80:
    print("B")
  elif 50 <= m+f < 65:
      print("C")
  elif m+f >= 30:
      if r >= 50:
        print("C")
      else:
        print("D")
  else:
    print("F")


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

int main() {
  int N;
  cin >>N ;
  vector<int> a(110);
  for(int i=0;i<N;i++)cin>>a.at(i);
  vector<int> b(110);

  for(int k=0;k<N;k++){
  for(int i=0;i<N;i++){
      bool flag=true;
    for(int j=0;j<N;j++){
      if(a.at(i)<a.at(j)){flag=false;}
    }
    if(flag){
      b.at(k)=a.at(i);
      a.at(i)=0;
      break;
    }
  }
  }
  int score=0;
  for(int i=0;i<N;i++){
    if(i%2==0)score+=b.at(i);
    if(i%2==1)score-=b.at(i);
  }
  cout<<score<<endl;

}


Measured memory_bytes: 256
x = input().split()
a = sorted(list(map(int, input().split())), reverse=True)
n = int(x[0])
m = int(x[1])
goukei = 0
count = 0
for i in a:
  goukei += i
for i in a:
  if goukei/(4*m) <= i:
    count += 1
if count >= m:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9132
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,N,a,b,ans=0;
  cin>>N;
  vec ch(N),p(N),q(N);
  rep(i,N){
    cin>>p[i];
    ch[i]=i+1;
  }
  rep(i,N)cin>>q[i];
  do{
    ans++;
    rep(i,N){
      if(p[i]!=ch[i])break;
    }
    if(i==N)a=ans;
    rep(i,N){
      if(q[i]!=ch[i])break;
    }
    if(i==N)b=ans;
  }while(next_permutation(all(ch)));
  print(abs(a-b));
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;
using Graph = vector<vector<int>>;

struct UnionFind {
  vector<int> d;
  //UnionFind(int n=0): d(n,-1) {}
  UnionFind(int n){
    d.resize(n,-1);
  }
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

set<int> st;

int main(){
  int N, M, A, B;
  cin >> N >> M;
  UnionFind uf(N);
  for(int i = 0; i < M; i++){
    cin >> A >> B;
    A--;
    B--;
    uf.unite(A,B);
  }
  for ( int i = 0; i < N; i++){
    int p;
    p = uf.find(i);
    st.insert(p);
  }

  int ans = 0;
  int s = st.size();
  if (s >=2) ans = s -1;
  
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 7436
n = int(input())
a = []
 
for i in range(n):
    s, p = input().split()
    a.append([s,int(p),i+1])
 
b = sorted(a,key=lambda x: x[1], reverse=True)
c = sorted(b,key=lambda x: x[0])
 
for i in c:
    print(i[2])

Measured memory_bytes: 3060
#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>	
#include<unordered_map>
#include<unordered_set>
using namespace std;


typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdoutn

int main()
{
	IO;
	int x{};
	cin>>x;
	if(x>=30)cout<<"Yes\n";
	else cout<<"No\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	vector<ll> prefix_sum(n+1, 0);
	rep(i,n){
        prefix_sum[i+1] = prefix_sum[i] + a[i];
	}
	unordered_map<ll, ll> counter;
	for(auto h : prefix_sum){
        counter[h]++;
	}
	ll ans = 0;
	for(auto p : counter){
        if(p.second > 1)
            ans += p.second * (p.second-1)/2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 11592
#include <math.h>
#include <iostream>
#include <vector>
 
using namespace std;
 
int main() {
  int H;
  int W;
  cin >> H >> W;
  vector<string> a(H);
  vector<vector<int>> cnt(H, vector<int>(W, 0));
  for (int i = 0; i < H; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < H; ++i) {
    if (a[i][0] == '.')
      cnt[i][0] = 1;
    else
      break;
  }
  for (int i = 0; i < W; ++i) {
    if (a[0][i] == '.')
      cnt[0][i] = 1;
    else
      break;
  }
  int mod = pow(10, 9) + 7;
  for (int i = 1; i < H; ++i) {
    for (int j = 1; j < W; ++j) {
      if (a[i][j] == '.') {
        cnt[i][j] = (cnt[i - 1][j] + cnt[i][j - 1]) % mod;
      }
    }
  }
  cout << cnt[H - 1][W - 1];
}

Measured memory_bytes: 5248
#include <iostream> 

using namespace std;

int main() {
	string S;
	cin >> S ;
	int f=0;
	for(int i = 0 ;i<3;i++){
		if(S[i]== S[i+1])f++;	
	}
	if(f==0)	cout <<"Good";
	else cout <<"Bad";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	int n;
	cin >> n;
	lli a[10][10] = {};
	for(int i=1; i<=n; i++){
		int first=i%10;
		int j=i;
		while(j/10 != 0){
			j /= 10;
		}
		int last=j;
		a[first][last]++;
	}
	lli ans = 0;
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			ans += a[i][j]*a[j][i];
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 200000;

int main(){
    int N;
    char c[MAX];

    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> c[i];
    }

    int l = 0;
    int r = N - 1;
    int ans = 0;

    while(true){
        while(l < N && c[l] != 'W')l++;
        while(r >= 0 && c[r] != 'R')r--;
        if(l >= r)break;
        swap(c[l],c[r]);
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3336