akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

//変数
ll R, C, N;
vector<vector<ll>> xy;


ld calc_rad(const ll& x, const ll& y) {
	return atan2(x - R / 2.0, y - C / 2.0);
}

struct Point {
	Point(int id_, ll x_, ll y_) :id(id_), x(x_), y(y_) {}
	int id;
	ll x, y;
	bool operator < (const Point& r)const {
		return calc_rad(this->x, this->y) < calc_rad(r.x, r.y);
	}
};





//サブ関数
//入力
void input()
{
	cin >> R >> C >> N;
	ll a, b, c, d;
	REP(i, N) {
		cin >> a >> b >> c >> d;
		xy.push_back({ a,b,c,d });
	}
}

bool isEdgep(pair<ll, ll> p) {
	if (p.first == 0 || p.first == R)return true;
	if (p.second == 0 || p.second == C)return true;
	return false;
}

bool isEdge(vector<ll> p) {
	return isEdgep({ p[0],p[1] }) && isEdgep({ p[2],p[3] });
}


//計算
void calc()
{
	vector<vector<ll>> edge;
	for (auto p : xy) if (isEdge(p)) {
		edge.push_back(p);
	}

	vector<Point> ps;
	REP(i,edge.size()){
		auto p = edge[i];
		ps.push_back(Point(i, p[0], p[1] ));
		ps.push_back(Point(i, p[2], p[3] ));
	}
	sort(ps.begin(), ps.end());


	bool res = true;
	set<int> se;
	stack<Point> st;
	for (auto p : ps) {
		if (st.empty())st.push(p);
		else if (se.find(p.id) == se.end()) {
			st.push(p);
			se.insert(p.id);
		}
		else if (st.top().id == p.id) {
			st.pop();
		}
		else {
			res = false;
			break;
		}
	}
	cout << (res ? "YES" : "NO") << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 25516
/*
  Id: ak260901
  Task: a
  Lang: C++
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define foru(i, l, r) for(register int i = l; i <= r; i++)
#define ford(i, r, l) for(register int i = r; i >= l; i--)

typedef long long ll;

ll read() {
  ll res = 0; char c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)) res = res * 10 + c - '0', c = getchar();
  return res;
}

const ll maxn = 2e3 + 3;
const ll mod = 1e9 + 7;
ll n, m, a[maxn], b[maxn];
ll dp[maxn][maxn];

int main() {
    n = read(); m = read(); dp[0][0] = 1;
  for(ll i = 0; i <= n; i++) dp[i][0] = 1;
  for(ll i = 0; i <= m; i++) dp[0][i] = 1;
  for(ll i = 1; i <= n; i++) a[i] = read();
  for(ll i = 1; i <= m; i++) b[i] = read();
  for(ll i = 1; i <= n; i++) {
    for(ll j = 1; j <= m; j++) {
      if(a[i] == b[j]) (dp[i][j] += dp[i - 1][j - 1]) %= mod;
      (dp[i][j] += dp[i][j - 1]) %= mod;
      (dp[i][j] += dp[i - 1][j]) %= mod;
      dp[i][j] = (dp[i][j] - dp[i - 1][j - 1] + mod) % mod;
    }
  } printf("%lld\n", dp[n][m]);
  return 0;
}


Measured memory_bytes: 31616
#include <cstdio>
#include <queue>

using namespace std;

#define N 100
#define INF -1

int n,d[N],m[N][N];

void bfs(int s){
	for(int i=0;i<n;i++){
		d[i] = INF;
	}
	int u,v;
	queue<int> q;
	q.push(s);
	d[s] = 0;
	while( !q.empty() ){
		u = q.front();
		q.pop();
		for(v=0;v<n;v++){
			if(d[v] != INF || m[u][v] != 1)continue;
			d[v] = d[u] + 1;
			q.push(v);
		}
	}
	for(int i=0;i<n;i++){
		printf("%d %d\n",i+1,d[i]);
	}
}

int main(void){
	int u,k,v;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			m[i][j] = 0;
		}
	}
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		u--;
		for(int j=0;j<k;j++){
			scanf("%d",&v);
			v--;
			m[u][v] = 1;	
		}
	}
	bfs(0);
	return 0;
}


Measured memory_bytes: 2752
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <algorithm>

int main()
{
    std::stack<int> stk;

    std::string str;
    while (std::cin >> str) {
        if (str == "+") {
            int a = stk.top();
            stk.pop();
            int b = stk.top();
            stk.pop();
            stk.push(b + a);
        } else if (str == "-") {
            int a = stk.top();
            stk.pop();
            int b = stk.top();
            stk.pop();
            stk.push(b - a);
        } else if (str == "*") {
            int a = stk.top();
            stk.pop();
            int b = stk.top();
            stk.pop();
            stk.push(b * a);
        } else {
            stk.push(std::stoi(str));
        }
    }

    std::cout << stk.top() << std::endl;

    return 0;
}


Measured memory_bytes: 3156
n,k,q=map(int,input().split())
lista=[]
ans1=0
for i in range(q):
    a=int(input())
    lista.append(a)

listb=[k-q]*n
for i in range(q):
    listb[lista[i]-1]=listb[lista[i]-1]+1
#print(listb)

for i in range(n):
    if listb[i]>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 56152
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define REP(i,a) for(int i=0;i<(a);i++)
#define REPR(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

mint dp[101][4][4][4];

int main() {
  int N;
  dp[0][3][3][3] = 1;
  cin >> N;
  for (size_t i = 0; i < N; i++) {
    for (size_t j = 0; j < 4; j++) {
      for (size_t k = 0; k < 4; k++) {
        for (size_t l = 0; l < 4; l++) {
          for (size_t m = 0; m < 4; m++) {
            if (k==0&&l==1&&m==2) continue;
            if (k==1&&l==0&&m==2) continue;
            if (k==0&&l==2&&m==1) continue;
            if (j==0&&k==1&&m==2) continue;
            if (j==0&&l==1&&m==2) continue;
            dp[i+1][k][l][m] += dp[i][j][k][l];
          }
        }
      }
    }
  }
  mint ans = 0;
  REP(j,4) REP(k,4) REP(l,4) ans += dp[N][j][k][l];
  cout << ans.n << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from itertools import accumulate
from bisect import bisect, bisect_left
def inpl(): return map(int, input().split())
N, K  = inpl()

bucket = [0]*(10**5 + 1)
for _ in range(N):
    a, b = inpl()
    bucket[a] += b

S = list(accumulate(bucket))
print(bisect_left(S, K))

Measured memory_bytes: 10624
#include <cstdio>
#include <vector>
#define R second.second
#define Z(i,a,b,c)v.insert(v.begin()+i,make_pair(a,make_pair(b,c)))
using namespace std;
main(){
	int W,Q,d,w,i;
	char s[2];
	for(;scanf("%d%d",&W,&Q),W;puts("END")){ //some case Q==0
		vector<pair<int,pair<int,int> > >v;
		for(Z(0,-2,0,0),Z(1,-1,W,0);Q;Q--){
			if(scanf("%s",s),*s-'w'){
				for(scanf("%d%d",&d,&w),i=0;~v[i].first;i++)if(v[i+1].second.first-v[i].R>=w){Z(i+1,d,v[i].R,v[i].R+w);printf("%d\n",v[i].R);break;}
				if(v[i].first==-1)puts("impossible");
			}else for(scanf("%d",&d),i=0;i<v.size();i++)if(v[i].first==d){v.erase(v.begin()+i);break;}
		}
	}
}

Measured memory_bytes: 1044
using System;
using System.Linq;

namespace soundhound2018_summer_qual_c
{
	class Program
	{
		static void Main(string[] args)
		{
			double[] x = Console.ReadLine().Split().Select(double.Parse).ToArray();
			if (x[2] == 0)
			{
				Console.WriteLine((x[1] - 1) / x[0]);
			}
			else
			{
				Console.WriteLine(2 * (x[0] - x[2]) / (x[0] * x[0]) * (x[1] - 1));
			}
		}
	}
}

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

const ll mod = 1000000000 + 7;

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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    ll n, a, b; cin >> n >> a >> b;
    ll ans = 1;

    ans = modpow(2, n, mod);
    ans--;
    //cout << ans << endl;

    ll aans = 1;
    if(a*2>n) a = n-a;
    for (int i = 0; i < a; i++){
        aans = aans * (n-i) % mod;
        aans = aans * modinv(i+1, mod) % mod;
    }
    ans -= aans;
    if(ans<0) ans += mod;
    
    ll bans = 1;
    if(b*2>n) b = n-b;
    for (int i = 0; i < b; i++){
        bans = bans * (n-i) % mod;
        bans = bans * modinv(i+1, mod) % mod;
    }
    ans -= bans;
    if(ans<0) ans += mod;

    cout << ans << endl;   
}



Measured memory_bytes: 384
n,m=map(int,input().split())
d=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))
kk=[]
hantei=0
ans=0
ans2=0
for i in range(2**n):
  z=[]
  ans=0
  for j in range(n):
    if (i>>j&1):
      z.append(1)
    else:
      z.append(0)
  for k in range(len(d)):
    hantei=0
    for l in range(len(d[k])-1):
      hantei+=z[d[k][l+1]-1]
    if hantei%2==p[k]:
      ans+=1
  if ans==m:
    ans2+=1
print(ans2)

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

int gcd(int a,int b){
    return b>0 ? gcd(b,a%b):a;
}
int main(){
    long long n, a, b, c, ans=0;
    cin>>n;
    for(a=1; a<=n; a++)
    {
        for(b=1; b<=n; b++)
        {
            for(c=1; c<=n; c++)
            {
                ans+= gcd( a, gcd(b,c) );
            }
        }
    }

    cout<<ans;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

ll h,w;

int main(){
	cin>>h>>w;
	if(h==1&&w==1) cout<<1<<endl;
	else if(h==1) cout<<w-2<<endl;
	else if(w==1) cout<<h-2<<endl;
	else cout<<(h-2)*(w-2)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int N, M;
vector<queue<int>> A;

bool solve(int x) {
    vector<bool> visited(M, false);
    vector<queue<int>> B(A);
    bool ok = true;
    while (true) {
        for (int i = 0; i < N; i++) {
            while (!B[i].empty() && visited[B[i].front()]) B[i].pop();
            if (B[i].empty()) {
                ok = false;
                break;
            }
        }
        if (!ok) break;
        vector<int> cnt(M, 0);
        int cnt_max = 0, max_s = -1;
        for (int i = 0; i < N; i++) cnt[B[i].front()]++;
        for (int i = 0; i < M; i++)
            if (cnt_max < cnt[i]) {
                cnt_max = cnt[i];
                max_s = i;
            }
        if (cnt_max <= x)
            return true;
        else
            visited[max_s] = true;
    }
    return false;
}

int binary_search(int ok, int ng) {
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (solve(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}

int main() {
    cin >> N >> M;
    A.resize(N);
    for (int i = 0; i < N; i++)
        for (int j = 0; j < M; j++) {
            int a;
            cin >> a;
            a--;
            A[i].push(a);
        }
    cout << binary_search(N + 1, 0) << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

const int maxn = 1e5+5;
int n, m, b, i, x, y, k;
int frn[maxn], ans[maxn];
int hm[maxn], comp[maxn];

vector <int> fs[maxn];

void dfs(int now, int k) {
    comp[now] = k;
    hm[comp[now]] ++;
    for(auto u : fs[now]) {
        if(comp[u] == 0) {
            dfs(u, k);
        }
    }
}

int main()
{
    //freopen("f.in", "r", stdin);
    //freopen("f.out", "w", stdout);

    cin >> n >> m >> b;
    for(i = 1; i <= m; i ++) {
        cin >> x >> y;
        fs[x].push_back(y);
        fs[y].push_back(x);
        frn[x] ++; frn[y] ++;
    }
    for(i = 1; i <= n; i ++) {
        if(comp[i] == 0) {
            ++ k;
            dfs(i, k);
        }
    }
    /*for(i = 1; i <= n; i ++) {
        cout << comp[i] << '\n';
    }*/

    for(i = 1; i <= n; i ++) {
        ans[i] += hm[comp[i]] - 1;
        ans[i] -= frn[i];
    }
    for(i = 1; i <= b; i ++) {
        cin >> x >> y;
        if(comp[x] == comp[y]) {
            ans[x] --; ans[y] --;
        }
    }
    for(i = 1; i <= n; i ++) {
        cout << ans[i] << ' ';
    }

    return 0;
}


Measured memory_bytes: 7936
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int ans = Math.min(B,D)-Math.max(A,C);
        if(ans<0)ans=0;
        System.out.println(ans);
    }
}

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

int main()
{
	int n;
	cin >> n;
	auto a = vector<int>(n);
	for(auto&& b : a) cin >> b;
	int ans = 0;
	for(auto b : a){
		ans += (b - 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N, K = [int(a) for a in input().split()]

ans = 0
NUM = 1000000007
for k in range(K, N+2):
    s_min = k * (k - 1) / 2
    s_max = k * (2 * N - k + 1) / 2
    c = (s_max - s_min) + 1
    ans += c
    ans %= NUM
print(int(ans))


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

using namespace std;
using ll = long long;



int main()
{
    int a,b,m;
    cin >> a >> b >> m;
    vector<ll> x(a), y(b);
    for(int i = 0; i < a; i++)cin >> x[i];
    for(int j = 0; j < b; j++)cin >> y[j];
    ll nin = 1e12;

    for(int i = 0; i < m; i++){
        ll t, k, c;
        cin >> t >> k >> c;
        t--; k--;
        ll cur = x[t] + y[k] - c;
        nin = min(nin, cur);
    }
    cout << min(nin, *min_element(x.begin(), x.end()) + *min_element(y.begin(), y.end())) << endl;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		String[] s=new String[10];
		int[] n=new int[10];
		try{
				for(int i=0;i<10;i++){
					s[i]=reader.readLine();
					n[i]=Integer.parseInt(s[i]);
				}
				Arrays.sort(n);
				System.out.println(n[9]);
				System.out.println(n[8]);
				System.out.println(n[7]);
		}catch(IOException e){
			System.exit(0);
		}
	}
}

Measured memory_bytes: 16932
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var W = ReadLine().Split().Select(int.Parse).ToArray();
        var ans = int.MaxValue;

        for (int i = 1; i < W.Length; i++)
        {
            var S2 = W.Skip(i).Sum();
            var S1 = W.Sum() - S2;
            ans = Min(ans, Abs(S2 - S1));
        }
        WriteLine(ans);
    }
}

Measured memory_bytes: 13396
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

X, N = read_ints()
if N == 0:
    print(X)
    exit()

P = read_ints()
for i in range(101):
    b = X + i
    a = X - i
    if a not in P:
        print(a)
        exit()
    if b not in P:
        print(b)
        exit()


Measured memory_bytes: 65420
#include <iostream>
#include <cstring>	// require memset
//#include <fstream>	// require freopen

using namespace std;
int memo[1001],a[7],b[7];

void comb (int c, int s, int m)
{

	if (s > 1000 ){
		return;
	} // end if
	if (c == m ){
		memo[s]++; return;
	} // end if
	
	for (int i = 0; i <= b[c]; ++i ){
		comb (c+1, s+a[c]*i, m );
	} // end for
}	

int main()
{
//	cut here before submit 
//	freopen ("testcase.sum_of_card", "r", stdin );
	int m;

	while (cin >> m && m ){
		for (int i = 0; i < m; ++i ){
			cin >> a[i] >> b[i];
		} // end for
		memset (memo, 0, sizeof(memo ) );
		comb (0, 0, m);
		int g;
		cin >> g;
		for (int i = 0; i < g; ++i ){
			int ng;
			cin >> ng;
			int res = memo[ng];
			cout << res << endl;
		} // end for
	} // end loop
		
	return 0;
}

Measured memory_bytes: 872
def main():
  A,B,C,X,Y = list(map(int, input().split()))

  min_cost = 2 * (10 ** 5) * max(A, B, C)

  for i in range(max(X, Y) + 1):
    num_c = 2 * (max(X, Y) - i)
    num_b = max(0, min(Y - num_c // 2, i))
    num_a = max(0, min(X - num_c // 2, i))
    total = A * num_a + B * num_b + C * num_c
    min_cost = min(total, min_cost)

  print(min_cost)

if __name__ == "__main__":
    main()

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

using namespace std;

int main()
{
int a,b;
cin>>a>>b;
int f=a;
if(a==1)cout<<b;
else
{int i=1;
while(a--,a!=0)
{
    cout<<b-a<<" ";
 
}
cout<<b<<" ";
while(f--)
{
    if(f!=0){
    cout<<b+i<<" ";
 i++;}
}}
return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

//const ll INF=(ll)1e19;
const int INF=(1<<30);


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

  vector<pair<int,int>> r(N), b(N);

  REP(i,N){
    int a, b;
    cin >> a >> b;
    r[i] = make_pair(a,b);
  }
  sort(ALL(r));

  REP(i,N){
    int c, d;
    cin >> c >> d;
    b[i] = make_pair(c,d);
  }
  sort(ALL(b));

  int ri = 0;
  int bi = 0;;

  vector<bool> visited(N,false);

  int ans=0;

  REP(bi, N){
    int max_i=-1;
    int max_y=-1;
    REP(ri, N){
      if(visited[ri])continue;

      if(r[ri].first >= b[bi].first)break;
      
      if(r[ri].second < b[bi].second){
        if(r[ri].second > max_y){
          max_y = r[ri].second;
          max_i = ri;
        }
      }

    }
    if(max_i != -1){
      visited[max_i]=true;
//      cout << bi << " " << max_i << endl;
      ans++;
    }
  }
  cout << ans << endl;

}



Measured memory_bytes: 256
//先辗转相除找gcd再通过gcd求lcm
#include <bits/stdc++.h>

using namespace std;

long long a,b;

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

int main()
{
	while(scanf("%lld%lld",&a,&b)!=EOF)
	{
		long long yin=gcd(a,b);
		long long ax=a/yin,bx=b/yin;
		printf("%lld %lld\n",yin,ax*bx*yin);
	}
	return 0;
} 


Measured memory_bytes: 3152
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 55556
#define MOD 1000000007

typedef long long int lli;

//　素数判定
int isPrime(int x) {
	if ( x <= 1 ) return 0;
	int ok = 1;
	for ( int i = 2; i < x; i++ ) {
		if ( x % i ) continue;
		ok = 0; break;
	}
	return ok;
}

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

	int ans[56];
	int cnt = 0;
	for (int i = 1; i < MAX; i += 5) {
		if( isPrime(i) ) ans[cnt++] = i;
		if (cnt == n) break;
	}

	rep(i, 0, n) printf("%d ", ans[i]);
  return 0;
}


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

using namespace std;

int main(void){
    int D;
    cin>>D;
    if(D==25) cout<<"Christmas"<<endl;
    if(D==24) cout<<"Christmas Eve"<<endl;
    if(D==23) cout<<"Christmas Eve Eve"<<endl;
    if(D==22) cout<<"Christmas Eve Eve Eve"<<endl;

    return 0;
}



Measured memory_bytes: 256
#coding:utf-8

n = int(input())
T = [list(map(int, input().split())) for i in range(n)]
A = [False for i in range(n)]

class binaryTree:
    def __init__(self, node, x=-1):
        self.node = node
        self.p = x
    
    def partialTree(self,tree,left, right):
        node = tree.node
        if left != -1:
            if A[left]:
                A[left].p = tree
                tree.l = A[left]
            else:
                tree.l = binaryTree(left, node)
                A[left] = tree.l
                tree.l.p = tree
        else:
            tree.l = binaryTree(left, node)
            tree.l.node = -1
            
        if right != -1:
            if A[right]:
                A[right].p = tree
                tree.r = A[right]
            else:
                tree.r = binaryTree(right, node)
                A[right] = tree.r
                tree.r.p = tree
        else:
            tree.r = binaryTree(right, node)
            tree.r.node = -1
            
def searchParent():
    p_tree = A[0]
    while p_tree.p != -1:
        p_tree = p_tree.p
    return p_tree

     
def setHeight(tree):
    h1 = h2 = 0
    if tree.l.node != -1:
        h1 = setHeight(tree.l) + 1
    if tree.r.node != -1:
        h2 = setHeight(tree.r) + 1
    if tree.l.node == -1 and tree.r.node == -1:
        tree.hei = 0
        return 0
    tree.hei = max(h1,h2)
    return max(h1, h2)

def setDepth(tree,depth):
    tree.dep = depth
    depth += 1
    if tree.l.node != -1:
        setDepth(tree.l,depth)

    if tree.r.node != -1:
        setDepth(tree.r,depth)

def getSibling(tree):
    if tree.p == -1:
        return -1
    if tree.p.l.node != -1 and tree.p.l.node != tree.node:
        return tree.p.l.node
    if tree.p.r.node != -1 and tree.p.r.node != tree.node:
        return tree.p.r.node
    return -1

        
def makeTree():
    for i in range(n):
        t = T[i]
        node = t[0]
        left = t[1]
        right = t[2]
        if A[node]:
            tree = A[node]
        else:
            tree = binaryTree(node)
            A[node] = tree
        binaryTree.partialTree(binaryTree, tree,left,right)

makeTree()
p_tree = searchParent()
setHeight(p_tree)
depth = 0
setDepth(p_tree,depth)


for i in range(n):
    tree = A[i]
    tree.sib = getSibling(tree)
    deg = 0
    if tree.r.node != -1:
        deg += 1

    if tree.l.node != -1:
        deg += 1

    if tree.p == -1:
        kind = "root"
    else:
        if deg == 0:
            kind = "leaf"
        else:
            kind = "internal node"

    ID = i
    if tree.p == -1:
        parent = -1
    else:
        parent = tree.p.node
    sibling = tree.sib
    degree = deg
    depth = tree.dep
    height = tree.hei

    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}"\
          .format(ID, parent, sibling, degree, depth, height, kind))


Measured memory_bytes: 5632
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

const int INF = 2147483647;
//const ll LINF = ll();今度書く

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	int k, x;
	scanf("%d%d", &k, &x);
	rep(i, k * 2 - 1) {
		if(x + (i - k + 1) >= -1000000 && x + (i - k + 1) <= 1000000)printf("%d ", x + (i - k + 1));
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
l = [int(x) for x in input().split()]

num_youso = l[0]
hidari = l[1]
migi = l[2]

lis = [0]*(num_youso -1)

for x in range(1,num_youso + 1):
  for y in range(x +1,num_youso + 1 ):
    saitan = y - x
    hidari_kyori = abs(x - hidari)
    migi_kyori = abs(y - migi)
    if hidari_kyori + migi_kyori + 1 < saitan:
      saitan = hidari_kyori + migi_kyori + 1
    lis[saitan -1] += 1
    
    

for i in range(num_youso -1):
  print(lis[i])
    
    
    


Measured memory_bytes: 3444
#include <stdio.h>

int main(void){
    
    int a,b,c,i=1;
    long int max=10000000;
    
    scanf( "%d %d %d",&a,&b,&c );
    
    for( i = 1; i <= max; i++){
        if( i * a % b == c){
            printf("YES");
            return 0;
        }
    }
    printf("NO");

       return 0;
}

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

int main(void){
  int A[3], ans;
  for(int i = 0; i < 3; i++)
    cin >> A[i];
  sort(begin(A),end(A));
  ans = A[2] - A[0];
  cout << ans << "\n";
  return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	ll m = 60;
	vl cnt(m);
	FOR(i,0,n) {
		ll x; cin >> x;
		FOR(j,0,m) if (x & (1LL << j)) cnt[j]++;
	}
	
	ll res = 0;
	FOR(j,0,m) {
		ll a = (1LL << j) % MOD;
		ll b = cnt[j] * (n-cnt[j]) % MOD;
		res = (res + a*b) % MOD;
	}
	cout << res << endl;
}



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


int main(){
  string s;
  cin>>s;
  vector<int>vec(3,0);
  for(int i=0;i<3;i++){
    if(s.at(i)=='R'){
      vec[i]=1;
    }
  }
  for(int i=1;i<3;i++){
    if(vec[i]==1){
      vec[i]+=vec[i-1];
    }
  }
  int ans =0;
  for(int i=0;i<3;i++){
    ans=max(vec[i],ans);
  }
  cout<<ans<<endl;
  
  
  return 0;
}


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

int main() {
  int W,H,x,y,r;
  cin >>W>>H>>x>>y>>r;
  bool hantei=true;
  if(x-r<0){
      hantei=false;
  }
  if(x+r>W){
      hantei=false;
  }
  if(y-r<0){
      hantei=false;
  }
  if(y+r>H){
      hantei=false;
  }
  if(hantei){
      cout <<"Yes"<<endl;
  }else{
      cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int count = 0;

    for (int i=0; i < N-2; i++) {
        if (S.substr(i, 3) == "ABC") {
            count += 1;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    a,b,c = I2()
    print(min(a+b,b+c,a+c))

Measured memory_bytes: 9068
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s[]=new String[n];
		int cnt[]=new int[n];
		String scheck[]=new String[n];
		for(int i=0;i<n;i++) {
			s[i]=scan.next();
			cnt[i]=0;
			scheck[i]="";
		}
		scan.close();
		Arrays.sort(s);
		int suffix=0;
		int max=0;
		for(int i=0;i<n;i++) {
			if(i!=0&&s[i].equals(s[i-1])==false) {
				scheck[suffix]=s[i-1];
				suffix+=1;
			}if(i==n-1)scheck[suffix]=s[i];

			if(i==n-1 && s[i].equals(s[i-1])==false)scheck[suffix]=s[i];
			cnt[suffix]+=1;
			if(max<cnt[suffix])max=cnt[suffix];
		}
		for(int i=0;i<=suffix;i++) {
			if(cnt[i]==max)System.out.println(scheck[i]);
		}
	}
}

Measured memory_bytes: 75692
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		int nTests = sc.nextInt();
		HashSet<String> h = new HashSet<>();
		for (int i = 0; i < nTests; i++) {
			String c = sc.next();
			if (!h.contains(c))
				h.add(c);
		}

		System.out.println((h.size() == 3) ? "Three" : "Four");
	}
}

Measured memory_bytes: 20948
n=int(input())
a=list(map(int,input().split()))
yon=0
so=0
flag=False
for i in range(len(a)):
  if a[i]%4==0:
    yon+=1
  elif a[i]%2==0:
    flag=True
  else:
    so+=1
if flag:
  so+=1
if so-1<=yon:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 15020
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def inp():
    return int(input())
def inps():
    return input().rstrip()
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10

# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque 

# ---------------------------------------

mod = 2019
S = inps()
dp = [0] * len(S)
mp = {}
ten = 1
for i in range(len(S)-1, -1, -1):
    n = int(S[i])
    if i == len(S) - 1:
        dp[i] = n % mod
    else:
        ten = (ten * 10) % mod
        dp[i] = (dp[i + 1] + n * ten) % mod
    if dp[i] in mp:
        mp[dp[i]] += 1
    else:
        mp[dp[i]] = 1

ans = 0
for k, v in mp.items():
    if k == 0:
        ans += v
    ans += v * (v - 1) // 2
print(ans)
    


Measured memory_bytes: 75568
#include <iostream>
#include <vector>
#include <string>
#include <cfenv>
#include <cmath>
#include <list>

using namespace std;

#include <iostream>
#include <vector>
using namespace std;

/* 配列 a の [left, right) をソートします */
void MergeSort(vector<int> &a, int left, int right) {
    if (right - left == 1) return;
    int mid = left + (right - left) / 2;

    // 左半分 [left, mid) をソート
    MergeSort(a, left, mid);

    // 右半分 [mid, right) をソート
    MergeSort(a, mid, right);

    // 一旦「左」と「右」のソート結果をコピーしておく (右側は左右反転)
    vector<int> buf;
    for (int i = left; i < mid; ++i) buf.push_back(a[i]);
    for (int i = right-1; i >= mid; --i) buf.push_back(a[i]);

    // マージする
    int iterator_left = 0;                    // 左側のイテレータ
    int iterator_right = (int)buf.size() - 1; // 右側のイテレータ
    for (int i = left; i < right; ++i) {
        // 左側採用
        if (buf[iterator_left] <= buf[iterator_right]) {
            a[i] = buf[iterator_left++];
        }
        // 右側採用
        else {
            a[i] = buf[iterator_right--];
        }
    }
}

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

  vector<int> H(N);

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

  MergeSort(H, 0, N);
  long long x = 0;
  for(int i=0; i<N-K; i++){
    x += H[i];
  }

  cout << x << endl;

  return 0;
}


Measured memory_bytes: 2580
#include <iostream>
#include <map>
#include <utility>

using namespace std;

const long long MOD = 1000000007;

long long euclid_gcd(long long a, long long b){
	if (a < b){
		return euclid_gcd(b, a);
	}
	if(b == 0){
		return a;
	}
	long long r;
	while((r = a % b)){
		a = b;
		b = r;
	}
	return b;
}

// c^n
long long modpow(long long c, long long n){
	long long ret = 1;
	while(n != 0){
		if(n&1){
			ret = ret * c % MOD;
		}
		c = c * c % MOD;
		n /= 2;
	}
	return ret;
}

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

	long long zero_zero = 0, l_zero = 0, r_zero = 0;
	map<pair<long long, long long>, long long> M;
	for (int i = 0; i < N; i++){
		long long A, B;
		cin >> A >> B;

		if(A == 0 && B == 0){
			zero_zero++;
		} else if (A == 0){
			l_zero++;
		} else if (B == 0){
			r_zero++;
		} else {
			if (B == 0){
				M[make_pair(1, 0)]++;
			} else if (B > 0){
				long long gcd = euclid_gcd(abs(A), abs(B));
				A /= gcd;
				B /= gcd;
				M[make_pair(A, B)]++;
			} else {
				long long gcd = euclid_gcd(abs(A), abs(B));
				A /= -gcd;
				B /= -gcd;
				M[make_pair(A, B)]++;
			}
		}
	}

	long long ans = 1;
	if(l_zero != 0 || r_zero != 0){
		ans *= (modpow(2, l_zero) + modpow(2, r_zero) - 1 + MOD) % MOD;
	}
	for (auto m : M){
		long long n = M[m.first];
		if(n==0){
			continue;
		}

		auto counterpart = make_pair(m.first.second, m.first.first);
		if(counterpart.second < 0){
			counterpart.second *= -1;
		} else {
			counterpart.first *= -1;
		}

		long long n_counterpart = M[counterpart];
		M[counterpart] = 0;
		if(n_counterpart != 0){
			ans *= ((modpow(2, n) + modpow(2, n_counterpart)) % MOD - 1 + MOD) % MOD;
			ans %= MOD;
		} else {
			ans *= modpow(2, n);
			ans %= MOD;
		}
	}

	cout << (ans + zero_zero - 1 + MOD) % MOD << endl;
	return 0;
}


Measured memory_bytes: 28424
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int A,B;
  cin>>A>>B;
  cout<<max(0, A-2*B)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int k, a, b;
    cin >> k >> a >> b;
    int i = a/k;
    int j=b/k;
    if((a%k==0)||(b%k==0)||(j-i>0)){
        cout << "OK" << endl;

    }else{
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


a = ns()

if a >= "A" and a <= "Z":
    print("A")
else:
    print("a")

Measured memory_bytes: 61728
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








int main(){
    int N; std::cin >> N;
    std::vector<int> cnt(100'001, 0);
    long long sum(0);
    {
        int A;
        for(int i(0); i < N; ++i){
            std::cin >> A;
            sum += A;
            ++cnt[A];
        }
    }
    int Q; std::cin >> Q;
    {
        int B, C;
        for(int i(0); i < Q; ++i){
            std::cin >> B >> C;
            int c(cnt[B]);
            sum += c * ((long long)C - B);
            cnt[B] -= c;
            cnt[C] += c;
            std::cout << sum << std::endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3756
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <map> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)





int main() {

	int n;
	cin >> n;
	double x = n / 1.08;
	int y = (int)(x+0.9);
	int z = (int)(y * 1.08);
	if (z == n) {
		cout << y;
	}
	else cout<<":(";
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <math.h>

using namespace std;


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

	int n, m;
	cin >> n >> m;
	vector<int> l;
	vector<int> r;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		l.emplace_back(a);
		r.emplace_back(b);
	}
	sort(l.begin(), l.end());
	sort(r.begin(), r.end());
	int ans = r[0] - l[l.size() - 1] + 1;
	if (ans < 0) ans = 0;
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 1276
#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<int> ans(N, -1);
  bool ok = true;
  rep(i, M) {
    int dig;
    int num;
    cin >> dig >> num;
    if (ans[dig-1] <= 0) {
      ans[dig-1] = num;
    } else {
      if (ans[dig-1] != num) {
        ok = false;
      }
    }
  }
  if (N == 3 && ans[0] == 0) {
    ok = false;
  }
  if (N == 2 && ans[0] == 0) {
    ok = false;
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  int ans_num = 0;
  for (int i = N-1; i >= 0;i--) {
    if (ans[i] == -1) {
      if (N == 2) {
        if (i==0) {
          ans[i] = 1;
        } else {
          ans[i] = 0;
        }
      }
      if (N == 3) {
        if (i == 0)
        {
          ans[i] = 1;
        }
        else {
          ans[i] = 0;
        }
      }
      if(N == 1) {
        ans[i] = 0;
      }
    }
    ans_num += pow(10, N-i-1) * ans[i];
  }
  cout << ans_num << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int stat=0;
		int henko=0;
		if(a.charAt(0)=='B') {
			stat=0;
		}
		else {
			stat=1;
		}

		for(int i=1; i<a.length(); i++) {
			if(a.charAt(i)=='B' && stat==0) {
				//
			}
			else if(a.charAt(i)=='B' && stat==1) {
				henko++;
				stat=0;
			}
			else if(a.charAt(i)=='W' && stat==1) {
				//
			}
			else if(a.charAt(i)=='W' && stat==0) {
				henko++;
				stat=1;
			}
		}
		System.out.println(henko);
	}
}

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

int main()
{
    int R;
    cin >> R;
    if (R < 1200)
        cout << "ABC" << endl;
    else if (R < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
import itertools


N = int(input())

Town = []

for _ in range(N):
    x, y = map(int,input().split())
    Town.append((x,y))

all_dist = []

for perm in list(itertools.permutations(range(N))):
    (pre_x, pre_y) = Town[perm[0]]
    dist = 0
    for i in perm[1:]:
        (x, y) = Town[i]
        dist += ((pre_x - x)**2+(pre_y - y)**2)**(1/2)
    all_dist.append(dist)

mean = sum(all_dist)/len(all_dist)
print(mean)

Measured memory_bytes: 48876
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int main(int argc, char const* argv[])
{
  int64_t A, B, K;
  scanf("%ld %ld %ld", &A, &B, &K);
  for (int64_t i = min(A, B); i > 0; i--) {
    if ((A % i == 0) && (B % i == 0)) {
      K--;
    }
    if (K == 0) {
      printf("%ld\n", i);
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
using namespace std;

int main(){
    int h,w; cin >> h >> w;
    vector<vector<char>> s(h+2,vector<char>(w+2,'.'));
    for ( int i = 1 ; i < h+1 ; i++ ){
        for ( int j = 1 ; j < w+1 ; j++ ) cin >> s[i][j];
    }
    vector<vector<int>> num(h+2,vector<int>(w+2));
    for ( int i = 1 ; i <= h ; i++ ){
        for ( int j = 1 ; j <= w ; j++ ){
            int cnt = 0;
            for ( int k = -1 ; k <= 1 ; k++ ){
                for ( int l = -1 ; l <= 1 ; l++ ){
                    if ( s[i+k][j+l] == '#' ) cnt++;
                }
            }
            if ( s[i][j] == '#') cnt--;
            num[i][j] = cnt;
            if ( s[i][j] == '#') cout << s[i][j];
            else cout << num[i][j];
            if ( j == w ) cout << endl;
        }
    }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
c = A[0]
S = 0
count = 0
for i in range(len(A)):
  if A[i] < c :
    count = count + c
    S = S + A[i]
  else:
    count = count + A[i]
    c = A[i]
    S = S + A[i]

print(count - S)

Measured memory_bytes: 32232
N = int(input())
W = [input() for _ in range(N)]

if N == len(set(W)):
    s = W[0]
    c = True
    for wi in W[1:]:
        if s[-1] != wi[0]:
            c = False
            break
        s = wi
    if c:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

int n = 5;
int a[5];

int dfs(int c, int num, int bit){
    if(c == n){
        return num;
    }

    int ans = INT_MAX;
    for(int i = 0;i < 5;i++){
        if((bit & (1 << i)) == 0){
            int next;
            if(num % 10 == 0){
                next = num;
            }else{
                next = num+10-(num%10);
            }
            ans = min(ans, dfs(c+1, next+a[i], bit | (1<<i)));
        }
    }

    return ans;
}

int main(){
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }

    cout << dfs(0, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int l;
  cin >> l;

  double len = (double) l / 3.0;

  double ans = len * len * len;

  cout << setprecision(16) << ans << endl;

  return 0;
}


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

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

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}


int main(){
  ll N,K;
  cin >> N >> K;
  ll ans = K*zyou(K-1,N-1);
  cout << ans << endl;
 }

Measured memory_bytes: 256