akhauriyash/Code-Regression huggingface dataset:
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define ll long long
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}


ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1,};
//vector<int> dx = {1,-1,0,0};
//vector<int> dy = {0, 1, 1, 1, 0, -1, -1, -1, 0};
//vector<int> dx = {0, 1, 0, -1, -1, -1, 0, 1, 1};

ll N;
vector<int> edge[100010 * 2];
bool visited[100010 * 2];
ll x, y;

void dfs(ll now){
  if(visited[now]) return;
  visited[now] = 1;
  if(now < 100010) x++;
  else y++;
  for(int next : edge[now]) dfs(next);
}

int main(){
  cin >> N;
  rep(i, N){
    ll x, y;
    cin >> x >> y;
    y += 100010;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }

  ll sum = 0;
  rep(i, 100010 * 2){
    if(visited[i]) continue;
    x = 0, y = 0;
    dfs(i);
    sum += x * y;
  }
  cout << sum - N << endl;

}


Measured memory_bytes: 10240
n,k,q = map(int, input().split())
correct_answers = [int(input()) for i in range(q)]
points = [k-q for i in range(n)]
for i in range(q):
    points[correct_answers[i]-1] += 1

for point in points:
    if point < 1:
        print("No")
    else:
        print("Yes")

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


Measured memory_bytes: 5596
def solve():
    N, M = map(int, input().split())
    FROM_1 = set()
    TO_N = set()
    for i in range(M):
        a, b = map(int, input().split())
        if a == 1:
            FROM_1.add(b)
        elif a == N:
            TO_N.add(b)
        if b == 1:
            FROM_1.add(a)
        elif b == N:
            TO_N.add(a)
    ans = FROM_1 & TO_N
    print('POSSIBLE') if ans else print('IMPOSSIBLE')

if __name__ == '__main__':
    solve()


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

typedef unsigned long long ll;

ll get_upper(ll lower, ll a, ll b) { 
  ll upper = a*b/lower;
  if (upper*lower == a*b) --upper;
  return upper;
}
// index が条件を満たすかどうか
bool isOK(ll lower, ll a, ll b) {
  ll upper = get_upper(lower, a, b);
  return lower <= upper;
}

int binary_search(ll a, ll b) {
    ll left = a;
    ll right = b-1;

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid, a, b)) left = mid;
        else right = mid;
    }

    /* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
    return left;
}

void solve(ll a, ll b)  { 
  if (a > b) swap(a, b);
  ll ans = 2*(a-1); // (a未満, bより大)の数
  ll lower = binary_search(a, b);
  ll upper = get_upper(lower, a, b);
  if (lower < a || upper >= b) {}
  else if (lower == a) { 
    if (lower < upper && upper < b) ++ans;
  }
  else {
    ++ans; // (a, b-1)
    if (lower == upper) ans += (lower-a-1)*2+1;
    else ans += (lower-a)*2;
  }
  // cout << a << " " << b << " " << lower << " " << upper << " " << ans << endl;
  cout << ans << endl;
}

int main() {
  ll q;
  cin >> q;
  for (ll i = 0; i < q; ++i) {
    ll a, b;
    cin >> a >> b;
    if (a == 1 && b == 1) { cout << 0 << endl; }
    else { solve(a, b); }
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
int a[N];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int res=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
				if(a[i]==a[j]||a[i]==a[k]||a[j]==a[k])
					continue;
				if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[k]+a[j]>a[i])
					res++;
			}
		}
	}
	printf("%d\n",res); 
}

Measured memory_bytes: 3708
import sys
from collections import deque
n = int(sys.stdin.readline())
lines = sys.stdin.readlines()
 
Q = deque()
for i in range(n):
    command = lines[i].split()
    if command[0] == "insert":
        Q.appendleft(command[1])
    elif command[0] == "deleteFirst":
        Q.popleft()
    elif command[0] == "deleteLast":
        Q.pop()
    elif command[0] == "delete":
        try:
            Q.remove(command[1])
        except:
            pass
print(" ".join(Q))

Measured memory_bytes: 214236
#include <iostream>
using namespace std;
int main()
{
 long long n,ans=0,cur=0;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  int x;
  cin>>x;
  if(x==0)ans+=cur/2,cur=0;
  else cur+=x;
 }
 ans+=cur/2;
 cout<<ans<<endl;
 return 0;
}

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


int main()
{
    int N;
    cin >> N;
    vector<long long> A(N);
    for( int i = 0; i < N; ++i ) cin >> A[i];


    sort(A.begin(), A.end(), greater<long long>() );
    vector<long long> sum(A);
    for( int i = 1; i < N; ++i ) sum[i] += sum[i-1];

    long long M = 0;
    int idx = 0;
    // 正になる数を探索
    for( int i = 0; i < N-1; ++i ){
        if( M < 2*sum[i]-sum[N-1] ){
            idx = i;
            M = 2*sum[i]-sum[N-1];
        }
    }
    cout << M << endl;

    int count = 0;
    while( count < N ){
        if( count < idx ){
            cout << A[idx+1] << " " << A[count] << endl;
            A[idx+1] -= A[count++];
        }else if( count == idx ){
            cout << A[idx] << " " << A[idx+1] << endl;
            A[idx] -= A[idx+1];
            count += 2;
        }else{
            cout << A[idx] << " " << A[count] << endl;
            A[idx] -= A[count++];
        }
    }

    return 0;
}

Measured memory_bytes: 3456
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int data[5];
    int deff[5];
    pint pdata[5];
    for (int i = 0; i < 5; i++)
    {
        cin >> data[i];
        deff[i] = data[i] - data[i] / 10 * 10;
        if (deff[i] != 0)
        {
            deff[i] = 10 - deff[i];
        }
        pdata[i] = make_pair(deff[i], data[i]);
    }

    int ans = 0;
    sort(pdata, pdata + 5);
    bool add_none_zero = false;
    ans += pdata[4].second;
    for (int i = 0; i < 4; i++)
    {
        if (pdata[i].second % 10 == 0)
        {
            ans += pdata[i].second;
        }
        else
        {
            ans += pdata[i].second / 10 * 10 + 10;
        }
    }
    cout << ans << endl;
}

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

int mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<vector<int>> dp(n + 1, vector<int>(3, 0));
    vector<int> t(n, 0);
    int x, y, z;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 3; j++) dp[i + 1][j] = dp[i][j];
        for (int j = 0; j < 3; j++){
            if (a[i] == dp[i][j]) {
                dp[i + 1][j] = a[i] + 1;
                break;
            }
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 3; j++){
            if (a[i] == dp[i][j]) t[i]++;
        }
    }
    long long ans = 1;
    for (int i = 0; i < n; i++) ans *= t[i], ans %= mod;
    cout << ans << endl;
}

Measured memory_bytes: 6528
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            int N = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

            long ans = 0;
            for(var i = 0; i < N; i++)
            {
                while (a[i] % 2 == 0)
                {
                    ans++;
                    a[i] /= 2;
                }
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();
            
        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}



Measured memory_bytes: 12128
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    int a, b;
    cin >> a >> b;
    int ans = a*b;
    cout << ans << endl; 
    return 0;
}

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

int main() {

	int i, N;

	cin >> N;

	if (N>81){
	    cout << "No" << endl;

	    return 0;

	}

	for (i=1;i<10;i++){
            if(N%i == 0 && N/i <=9){
                cout << "Yes" << endl;

                return 0;
            }

	}

	cout << "No" << endl;


	return 0;


}

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

int main(){
    string a,b;
    cin>>a>>b;

    int ans;
    if(a.size()>b.size())ans = 1;
    else if(a.size()<b.size())ans = 2;
    else ans = 0;

    if(ans == 0){
        for(int i=0;i<a.size();++i){
            if(a[i]>b[i]){
                ans = 1;
                break;
            }
            else if(a[i]<b[i]){
                ans = 2;
                break;
            }
        }
    }

    switch(ans){
        case 0:cout<<"EQUAL";break;
        case 1:cout<<"GREATER";break;
        case 2:cout<<"LESS";break;
    }
}
//1=GREATER 2=LESS 0=EQUAL

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<int> b(n-1);
  rep(i,n-1) cin >> b[i];
  vector<int> ans(n+1);
  ans[0] = b[0];
  ans[n] = b[n-2];
  rep(i,n-2) {
    ans[i+1] = min(b[i], b[i+1]);
  }
  int res = 0;
  for(int i: ans) res += i;
  cout << res << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3580
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[m];
        int[] b = new int[m];
        for(int i = 0; i < m; i++) {
            a[i] = sc.nextInt()-1;
            b[i] = sc.nextInt()-1;
        }
        long[] answer = new long[m];
        answer[m - 1] = (long)n * (n-1) / 2;
        UnionFind uf = new UnionFind(n);
        for(int i = m - 1; i >= 1; i--) {
            answer[i - 1] = answer[i];
            if(uf.root(a[i]) != uf.root(b[i])) {
                answer[i - 1] -=(long)uf.size(a[i]) * uf.size(b[i]);
                uf.connect(a[i], b[i]);
            }
        }
        for(int i = 0; i < m; i++) {
            System.out.println(answer[i]);
        }
    }
}

class UnionFind {
    private int[] parents;

    UnionFind(int n) {
        parents = new int[n];
        Arrays.fill(parents, -1);
    }

    int size(int node) {
        return -parents[root(node)];
    }

    int root(int node) {
        if(parents[node] < 0) return node;
        else return parents[node] = root(parents[node]);
    }

    boolean connect(int node1, int node2) {
        int root1 = root(node1);
        int root2 = root(node2);
        if(root1 == root2) return false;
        else {
            if(root1 < root2) {
                int temp = root1;
                root1 = root2;
                root2 = temp;
            }
            parents[root1] += parents[root2];
            parents[root2] = root1;
            return true;
        }
    }
}



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

int main() {
    int s, w;
    cin >> s >> w;
    if (s <= w) {
        cout << "unsafe" << endl;
    }
    else {
        cout << "safe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
#define int long long
#define MAXN 200106
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
int n , m , q;

int fa[MAXN];
int find( int x ) {
	return x == fa[x] ? x : fa[x] = find( fa[x] );
}
struct dl{
	int u , v;
} d[MAXN] ;
int cnt , c;

signed main( ) {
	cin >> n >> m >> q;
	for( int i = 1 ; i <= n ; ++ i ) fa[i] = i;
	for( int i = 1 , u , v , c ; i <= q ; ++ i ) {
		scanf("%lld%lld%lld",&u,&v,&c);
		++ u , ++ v;
		if( !c ) {
			fa[find( u )] = find( v );
		} else {
			d[++ cnt] = (dl) { u , v };
		}
	}
	for( int i = 1 , u , v ; i <= cnt ; ++ i ) {
		if( find( d[i].u ) == find( d[i].v ) )
			return puts("No") , 0;
	}
	for( int i = 1 ; i <= n ; ++ i ) if( fa[i] == i )
		++ c;
	int ed = m - n + c;
	if( !cnt ) return puts( ( ed >= c - 1 && ed <= c * ( c - 1 ) / 2 ) ? "Yes" : "No" ) , 0;
	else return puts( ( ed >= max( c , 3ll ) && ed <= c * ( c - 1 ) / 2 ) ? "Yes" : "No" ) , 0;
}

Measured memory_bytes: 3840
n,k=map(int,input().split())
x=[int(i) for i in input().split()]
ans=10**9
 
for i in range(n-k+1):
    temp=0
    temp+=(min(abs(x[i]),abs(x[i+k-1]))+abs(x[i]-x[i+k-1]))
    ans=min(ans,temp)
print(ans)

Measured memory_bytes: 19840
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define nrep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;


int main(){
	int n;scanf("%d",&n);
	vi inp;
	rep(i,n){
		int x;scanf("%d",&x);
		inp.push_back(x);
	}
	sort(inp.begin(),inp.end());
	int m;scanf("%d",&m);
	bool ret=true;
	rep(i,m){
		int x;scanf("%d",&x);
		vi::iterator it=lower_bound(inp.begin(),inp.end(),x);
		if(*it==x)inp.erase(it);
		else ret=false;
	}
	string rstr=ret?"YES\n":"NO\n";
	cout<<rstr;
	return 0;
}



Measured memory_bytes: 1400
n = int(input())
p = list(map(int, input().split()))[:n]

# 前後の数値と比較して、真ん中が２番目（＝中位）ならカウントアップ
count = 0
for i in range(1, len(p)-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
        count += 1

print(count)

Measured memory_bytes: 3060
# include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
 ll n,x,t;
	cin>>n>>x>>t;
	ll time=n/x;
	if(n%x!=0)time++;

	ll ans=time*t;
	cout<<ans<<endl;
    return 0;
 }


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i< (n); ++i)
const long long INF = 1LL<<58;

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){ if(a>b) a = b; }
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

// 最大公約数を求める GCD
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


// 素因数分解 pair
vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            ++num;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 210000;
const int MOD = 1000000007;

//  二項係数の計算nCk セット
//  https://drken1215.hatenablog.com/entry/2018/06/08/210000
//  使い方としては、最初に一度前処理として COMinit() をしておけば、あとは COM(n, k) 関数を呼べばよい
//  前処理 COMinit(): O(n)
//　クエリ処理 COM(n, k): O(1)
ll 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() {

    ll X;
    cin >> X;

    ll price = 100;
    ll ans = 0;
    for (ll i = 1; i <= INF; ++i) {
        ll add = (ll)price / 100;
        price += add;
        if (price >= X) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


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


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	map<int, int>cnt;
	rep(i, n)cnt[a[i]]++;
	int ans = 0;
	for (auto itr = cnt.begin(); itr != cnt.end(); itr++) {
		int tmp = itr->first;
		if (itr->second < tmp) {
			ans += itr->second;
		}
		else {
			ans += itr->second - tmp;
		}
	}
	cout << ans << endl;
	return 0;
}


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


int main() {

	int N, M;
	cin >> N >> M;

	vector<vector<int>> c(M, vector<int>(2));
    rep (i, M) {
        cin >> c.at(i).at(0) >> c.at(i).at(1);
    }


    int a[N + 1] = {0};

    for (int i = 0; i < M; ++i) {
        ++a[c.at(i).at(0)];
        ++a[c.at(i).at(1)];
    }

    for (int i = 1; i <= N; ++i) {
        cout << a[i] << endl;
    }

}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using graph = vector<vector<int>>;

vector<int> topological_sort(const graph& G) {
	int n = G.size();
	vector<int> used(n), idx; idx.reserve(n);
	function<void(int)> dfs = [&](int v) {
		used[v] = true;
		for (int w : G[v]) if (!used[w]) dfs(w);
		idx.push_back(v);
	};
	for (int i = n - 1; i >= 0; i--) {
		if (!used[i]) dfs(i);
	}
	reverse(idx.begin(), idx.end());
	return idx;
}

int main()
{
	int N, M;
	cin >> N >> M;
	graph G(N);
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y; --x, --y;
		G[x].push_back(y);
	}
	auto id = topological_sort(G);
	vector<int> dp(N);
	for (int i = 0; i < N; i++) {
		int v = id[i];
		for (auto to : G[v]) {
			dp[to] = max(dp[to], dp[v] + 1);
		}
	}
	cout << *max_element(dp.begin(), dp.end()) << endl;
	return 0;
}


Measured memory_bytes: 7936
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222




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


  cin >> n;
  ok = false;
  rep(i, n) {
    cin >> tmp;
    if (tmp % 2) ok = true;
  }
  if (ok) cout << "first" << endl;
  else cout << "second" << 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++)
using ll = long long;
using P = pair<int,string>;

int main() {
 int n;
 cin >> n;
 set<int> a;

 rep(i,n){
   int x;
   cin >> x;
   a.insert(x);
 }
 cout << a.size() << endl;
 }


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = Integer.parseInt(sc.next().replaceAll("/", ""));
		if(s > 20190430) System.out.println("TBD");
		else System.out.println("Heisei");
	}
}


Measured memory_bytes: 21588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int result = 0;

		for (int i = 0; i <= n; i ++) {
			result += i;
		}
		System.out.println(result);
	}

}


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

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

Measured memory_bytes: 256
class UnionFind():
    # コンストラクタ
    def __init__(self, n):
        # 要素数
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n

    # 要素xが属するグループの根を返す
    # 経路圧縮
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]

    # 要素x,yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を返す
    def group_count(self):
        return len(self.roots())

    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = map(int,input().split())
AB = [[int(i) for i in input().split()] for _ in range(M)]

uf = UnionFind(N)

from collections import deque

answer = deque([N*(N-1)//2])
for A,B in AB[::-1]:
    A -= 1
    B -= 1
    if uf.same(A,B):
        answer.appendleft(answer[0])
    else:
        answer.appendleft(answer[0] - uf.size(A) * uf.size(B))
        uf.union(A,B)

for i in range(1,M+1):
    print(answer[i])

Measured memory_bytes: 29112
n,a,b=gets.chomp.split(' ').map{|n| n.to_i}

# n log n
def sum_of_digits num
	n = 0
	num_ = num
	while(num_ != 0)
		n += num_ % 10
		num_ = num_ / 10
	end
	return n
end
arr = Array.new(n+1){|idx| idx}
puts arr.select{|i| a <= sum_of_digits(i) && sum_of_digits(i) <= b}.inject{|sum, i| sum + i}

# 2

Measured memory_bytes: 1916
#include<stdio.h>
#include<math.h>
int main(){

  int i,n;
  scanf("%d", &n );

  int x[1001],y[1001];
  double z[1001];
  
  for ( i = 0 ; i < n ; i++ ){
    scanf("%d", &x[i] );
  }
  
  for ( i = 0 ; i < n ; i++ ){
    scanf("%d", &y[i] );
  }

  for ( i = 0 ; i < n ; i++ ){
    z[i] = fabs( 1.0 * x[i] - y[i] );
  }

  double sum,man,euc,tri,che;

  sum = 0;
  for ( i = 0 ; i < n ; i++ ){
    sum = sum + z[i];
  }
  man = sum;

  sum = 0;
  for ( i = 0 ; i < n ; i++ ){
    sum = sum + z[i] * z[i];
  }
  euc = sqrt( sum );

  sum = 0;
  for ( i = 0 ; i < n ; i++ ){
    sum = sum + z[i] * z[i] * z[i];
  }
  tri = cbrt( sum );

  int max;
  max = 0;

  for ( i = 0 ; i < n ; i++ ){
    if ( z[i] > max ) max = z[i];
  }

  che = 1.0 * max;

  printf("%.8lf\n%.8lf\n%.8lf\n%.8lf\n", man, euc, tri, che );
  
  return 0;

}

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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

#define pb push_back

vector<int> p;

int n, m, c;

bool isp(int a) {
    rep(i, p.size()) {
        if(a==p[i])return true;
        if(a%p[i]==0)return false;
    }
    return true;
}

int main(){
	cin.tie(0);
	
	for_(i, 2, 10000) {
	    if(isp(i))p.pb(i);
	}
	
	cin>>n;
	rep(i, n) {
		cin>>m;
		if(isp(m))c++;
	}
	
	cout<<c<<endl;
	
	return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

// 二つの値の最小値を求める関数
Int Min(const Int a, const Int b) {
    if (a <= b) {
        return a;
    } else {
        return b;
    }
}
// 二つの値の最大値を求める関数
Int Max(const Int a, const Int b) {
    if (a >= b) {
        return a;
    } else {
        return b;
    }
}

int main(void) {
    Int w, h, x, y;
    cin >> w >> h >> x >> y;
    double half = (double)(w * h) / 2.0;
    if (w / 2 == x && w % 2 == 0 && h / 2 == y && h % 2 == 0) {
        cout << half << " " << 1 << endl;
    } else {
        cout << half << " " << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1e9+7
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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;
    string s;
    cin >> n >> s;
    ll r=0,g=0,b=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else b++;
    }
    ll sum=r*g*b;
    for(int i=0;i<n-2;i++){
        for(int j=i+2;j<n;j++){
            if((i+j)%2!=0) continue;
            if(s[i]!=s[(i+j)/2] && s[i]!=s[j] && s[j]!=s[(i+j)/2]) sum--;
        }
    }
    cout << sum << endl;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  map<char, char> ms, mt;

  rep(i, S.size()) {
    char s = S[i], t = T[i];
    if (ms.count(s) == 0)
      ms[s] = t;
    else if (ms[s] != t) {
      cout << "No" << endl;
      return 0;
    }

    if (mt.count(t) == 0)
      mt[t] = s;
    else if (mt[t] != s) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}

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

int main() {
    int freq[100];
    for(int i = 0; i < 3; i++) {
        int x;
        cin >> x;
        freq[x]++;
    }
    if (freq[5] == 2 && freq[7] == 1)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
        
    return 0;
    
}


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

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int n,a,b,c,d;
string s;
void bye()
{
    cout<<"No"<<endl;
    exit(0);
}
bool chk(int x,int y)
{
    f(i,x,y-1)
    {
        if(s[i]=='#' && s[i+1]=='#')return false;
    }
    return true;
}
bool chk2(int x,int y)
{
    f(i,x,y-2)
    {
        if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.')return true;
    }
    return false;
}
 main()

{
    fast
    cin>>n>>a>>b>>c>>d;
    cin>>s;
    s="#"+s;
    if(c==d)bye();
    if(!chk(a,c))bye();
    if(!chk(b,d))bye();
    if(c<d)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    if(chk2(b-1,d+1))
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;

}





































Measured memory_bytes: 3792
A=abs
_,*p=[list(map(int,t.split()))for t in open(0)]
for t in p:
 if t[2]:x,y,h=t
r=range(101)
for i in r:
 for j in r:H=h+A(x-j)+A(y-i);print(*(j,i,H)*all(u==max(H-A(s-j)-A(t-i),0)for s,t,u in p))

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

int main(){
    int n; cin >> n;
    vector<int> h;
    int tmp;
    rep(i,n){
        cin >> tmp;
        h.emplace_back(tmp);
    }

    int MIN;
    int mi = 0;
    rep(i,n){
        if(i==0){
            mi = h[i];
            MIN = mi;
        }else{
            if(h[i]<h[i-1]){
                if(h[i] < MIN){
                    MIN = h[i];
                }
            }else{
                mi += (h[i] - h[i-1]);
            }
        }
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<set>
using namespace std;
int main(){
  int n;
  string before;
  string after;
  set<string>st;
  bool success=true;

  cin>>n;
  cin>>before;
  st.insert(before);
  for(int i=1;i<n&&success;i++){
    cin>>after;
    if(after[0]!=before[before.size()-1]){
      success=false;
    }
    if(st.find(after)!=st.end()){
      success=false;
    }
    st.insert(after);
    before=after;
  }
  
  if(success){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return(0);
}


Measured memory_bytes: 256
def gcd(a,b):
  a,b = min(a,b),max(a,b)
  if a != 0:
    return gcd(b%a,a)
  else:
    return b

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=1)
g = a[0]
c = a[0]
mi = a[0]//2
for i in a[1:]:
  while mi <= m:
    if (mi-i//2) % i == 0:
      break
    else:
      mi += c
  if mi > m:
    print(0)
    exit()
  g = gcd(i,c)
  c *= i
  c = c // g
print((m-mi)//c+1)

Measured memory_bytes: 14292
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;

typedef long long ll;


int main() {
	int n; cin >> n;
	vector<int> a(n + 2);
	for (int i = 0; i < n; i++) cin >> a[i];
	int ans = 0;
	for (int i = 1; i < n; i++) {
		if (a[i] == a[i - 1]) {
			ans++;
			a[i] = -1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 764
# https://atcoder.jp/contests/abc063/tasks/arc075_b
import sys
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop
import math
sys.setrecursionlimit(12345678)


def can_delete(ml, t, a, b):
    for i in range(len(ml)):
        ml[i] -= (b * t)

    count = 0
    for m in ml:
        if m > 0:
            count += math.ceil(m/(a-b))

    return t >= count


def main():
    n, a, b = map(int, input().split())
    monsters = []
    for _ in range(n):
        monsters.append(int(input()))

    l = 0
    r = 10**9
    while l < r:
        m = (l + r) // 2
        if can_delete(monsters.copy(), m, a, b):
            r = m
        else:
            l = m + 1

    print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11396
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    int ansp,ansd=0;
    rep(i,n){
      int p,d1,d2;
      cin>>p>>d1>>d2;
      if(ansd<d1+d2){
        ansp=p;
        ansd=d1+d2;
      }
    }
    cout<<ansp<<" "<<ansd<<endl;
  }
}

Measured memory_bytes: 3076
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define Rep(i,x) for(int i=head[x];i+1;i=nxt[i])
#define rep2(i,a,b) for(int i=(a);i<(b);i++)
#define ff first
#define ss second
using namespace std;
const int N=20010;
const int M=10000005;
const int inf=100007;
typedef long long ll;
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}}
//------------------------------------------head---------------------------------------------------//
namespace Flow
{
	int cap[M],to[M],nxt[M],e;
	int head[N],q[N],lev[N];
	int s,t;
	inline void ins(int x,int y,int c)
	{
		cap[e]=c;
		to[e]=y;
		nxt[e]=head[x];
		head[x]=e++;
	}
	inline void add_edge(int x,int y,int c)
	{
		ins(x,y,c);
		ins(y,x,0);
	}
	inline void init(int x,int y)
	{
		memset(head,-1,sizeof(head));
		e=0;s=x;t=y;
	}
	int bfs()
	{
		memset(lev,-1,sizeof(lev));
		int rear,h;
		rear=h=0;
		lev[s]=0;
		q[rear++]=s;
		while(h<rear)
		{
			int x=q[h++];
			Rep(i,x)
			{
				int j=to[i];
				if(cap[i] && lev[j]==-1)
				{
					lev[j]=lev[x]+1;
					if(j==t) return 1;
					q[rear++]=j;
				}
			}
		}
		return 0;
	}
	int dfs(int x,int y)
	{
		if(x==t || !y) return y;
		int fl=0;
		Rep(i,x) if(cap[i] && lev[to[i]]==lev[x]+1)
		{
			int j=dfs(to[i],min(y,cap[i]));
			cap[i]-=j;cap[i^1]+=j;fl+=j;y-=j;
			if(!y) break;
		}
		return fl;
	}
	inline int dinic()
	{
		int ans=0,T=1;
		while(bfs()) while(T=dfs(s,inf)) ans+=T;
		return ans;
	}
};
char s[N][N];
vector<int>pos[N],pos2[N];
int n,m;
inline int gg(int x,int y){return (x-1)*m+y;}
int main()
{
	read(n);read(m);int sp,st;
	rep(i,1,n)scanf("%s",s[i]+1);
	rep(i,1,n)
	{
		rep(j,1,m)
		{
			if(s[i][j]=='o' || s[i][j]=='S' || s[i][j]=='T')
			{
				pos[i].push_back(gg(i,j));
				pos2[j].push_back(gg(i,j));
			}
			if(s[i][j]=='S') sp=gg(i,j); if(s[i][j]=='T')st=gg(i,j);
		}
	}Flow::init(sp,st+n*m);
	rep(i,1,n)rep(j,1,m)
	{
		if(s[i][j]=='o')Flow::add_edge(gg(i,j),gg(i,j)+n*m,1);
		if(s[i][j]=='T' || s[i][j]=='S') Flow::add_edge(gg(i,j),gg(i,j)+n*m,inf);
	}
	rep(i,1,n)
	{
		if(pos[i].size()>1)
		for(int j=0;j<pos[i].size();j++) for(int k=0;k<pos[i].size();k++) if(j!=k) Flow::add_edge(pos[i][j]+n*m,pos[i][k],inf);
	}
	rep(i,1,m)
	{
		if(pos2[i].size()>1)
		for(int j=0;j<pos2[i].size();j++) for(int k=0;k<pos2[i].size();k++) if(j!=k)Flow::add_edge(pos2[i][j]+n*m,pos2[i][k],inf);
	}
	int ans=Flow::dinic();
	if(ans>=100000)puts("-1");
	else printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 58880
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int H,W;
  cin >> H;
  cin >> W;
  
  for(int i=0;i<W+2;i++){
    cout << "#" ;
  }
  cout << endl; //一行目
  
  vector<char> vec(H*W);
  
  for(int i=0 ; i<H*W ; i++){
    cin >> vec.at(i);
  }
  
  for(int j=0 ; j<H ; j++){
    cout << "#";
    for(int i=0 ; i<W ; i++){
      cout << vec.at(j*W+i);
    }
     cout << "#"<<endl;
  }
  
  for(int i=0;i<W+2;i++){
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
    string s, p;
    cin >> s >> p;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != p[0]) continue;
        bool check = true;
        int coordinate = i;
        for (int j = 0; j < p.length(); j++) {
            if (s[coordinate] != p[j]) {
                check = false;
                break;
            }
            ++coordinate;
            if (coordinate == s.length()) coordinate = 0;
        }
        if (check) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}



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

void chmin(int& a, int b){
  if (a > b) a = b;
}
int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  
  int ans = 1000000000;
  // ABピザを固定
  if (X >= Y) {
    // ABピザでAピザBピザ i枚分買った
    for (int i = 0; i <= X; i++) {
      int price = C * 2 * i + A * (X-i) + B * max(Y-i, 0);
      
      chmin(ans, price);

    }
  } else {
    for (int i = 0; i <= Y; i++) {
      int price = C * 2 * i + A * max(X-i, 0) + B * (Y-i);
      
      chmin(ans, price);
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 3636
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#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;

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

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

	int N;
	cin >> N;
	string S1, S2;
	cin >> S1 >> S2;

	LL MOD = 1e9 + 7;
	LL ret = 1;
	bool p = true;
	REP(i, N){
		if(S1[i] == S2[i]){
			if(p){
				if(i == 0) ret = 3;
				else ret *= 1;
			}
			else{
				ret *= 2;
			}
			p = false;
		}
		else{
			if(p){
				if(i == 0) ret = 6;
				else ret *= 3;
			}
			else{
				ret *= 2;
			}
			p = true;
			i++;
		}
		ret %= MOD;
		cerr << ret << endl;
	}

	cout << ret << endl;


	return 0;
}


Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            if "#" == s[y + 1][x]:
                continue
            if "#" == s[y][x + 1]:
                continue
            if "#" == s[y - 1][x]:
                continue
            if "#" == s[y][x - 1]:
                continue

            print("No")
            return
    print("Yes")
    return


main()


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

int main() {
    int n;
    cin >> n;
    if(n == 111){
        cout << 999;
    } else if(n == 119){
        cout << 991;
    } else if(n == 191){
        cout << 919;
    } else if(n == 199){
        cout << 911;
    } else if(n == 911){
        cout << 199;
    } else if(n == 919){
        cout << 191;
    } else if(n == 991){
        cout << 119;
    } else {
        cout << 111;
    }
}

Measured memory_bytes: 256
s=input()

a=[1]
if s[0]!="<":a=[0,1]
for i in range(len(s)-1):
  if s[i]!=s[i+1]:a.append(1)
  else:a[-1]+=1
if s[-1]!=">":a.append(0)

b=0
for i in range(len(a)//2):
  ma,mi=max(a[i*2],a[i*2+1]),min(a[i*2],a[i*2+1])
  b+=ma*(ma+1)//2
  b+=mi*(mi-1)//2
print(b)


Measured memory_bytes: 6300
from collections import deque

H, W = map(int, input().split())

maze = "#" * (W+2)
for _ in range(H):
  maze += "#" + input() + "#"
maze += "#" * (W+2)

dist = [-1] * (W+2) * (H+2)
q = deque()

dist[(W+2) * 1 + 1] = 0
q.append((W+2) * 1 + 1)

while len(q) != 0:
  v = q.popleft()
  
  udlr = (-W-2, W+2, -1, 1)
  for move in udlr:
    nv = v + move
    if maze[nv] == "#":
      continue
    if dist[nv] != -1:
      continue
    dist[nv] = dist[v] + 1
    q.append(nv)
if dist[(W+2) * H + W] == -1:
  print(-1)
else:
  print(W * H - maze.count("#") + 2 * (W + H + 2) - dist[(W+2) * H + W] -1)

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

using namespace std;

const int MAX_N = 2e3 + 5;
const int MAX_L = 20;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;



void solve() {
    int n; cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        cnt += (x != i);
    }
    if (cnt != 2 && cnt != 0) cout << "NO";
    else cout << "YES";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int tc; tc = 1;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }
}


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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  while(b <= a && k > 0){
    b *= 2;
    k--;
  }
  while(c <= b && k > 0){
    c *= 2;
    k--;
  }
  if(a < b && b < c){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

using namespace std;

int n;
string s[100010];

int main(){
    scanf("%d", &n);

    cin >> ws;
    for(int i = 0; i < n; i++) getline(cin, s[i]), sort(s[i].begin(), s[i].end());

    sort(s, s + n);

    long long ans = 0;
    int ct = 1;
    for(int i = 1; i < n; i++){
        if(s[i] == s[i - 1]) ct++;
        else {
            ans += (long long) ct * (ct - 1) / 2;
            ct = 1;
        }
    }

    ans += (long long) ct * (ct - 1) / 2;

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

Measured memory_bytes: 7296
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))



function main()
  X,N = readint()
  p = readint()

  d = Dict{int,int}()
  for i in 1:N
    d[p[i]] = 1
  end

  if get(d,X,0) == 0
    println(X)
    return
  end

  for i in 1:100
    if get(d,X-i,0)==0
      println(X-i)
      return
    end

    if get(d,X+i,0)==0
      println(X+i)
      return 
    end
  end
end

main()

Measured memory_bytes: 165768
N = int(input())
P = [0] + list(map(int, input().split()))

res = 0
for i in range(1, len(P)):
    if i == P[i]:
        if i == N:
            P[i], P[i - 1] = P[i - 1], P[i]
        else:
            P[i], P[i + 1] = P[i + 1], P[i]
        res += 1

print(res)


Measured memory_bytes: 14008