akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> H >> N;
	vector< int > A(N), B(N);
	rep(i, N) cin >> A[i] >> B[i];
	vector< int > dp(H + 1e5, LINF);
	dp[0] = 0;
	rep(i, N) {
		rep(j, dp.size()) {
			if (j + A[i] < dp.size()) {
				chmin(dp[j + A[i]], dp[j] + B[i]);
			}
		}
	}
	int ans = LINF;
	for (int j = H; j < dp.size(); j++) {
		chmin(ans, dp[j]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1660
n = int(input())

t_votes = a_votes = 1
for i in range(n):
    t_rate, a_rate = (int(x) for x in input().split())
    count = max(-(-t_votes // t_rate), -(-a_votes // a_rate))
    t_votes = t_rate*count
    a_votes = a_rate*count

print(t_votes+a_votes)


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

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

const int mid = 80 * 160;
int m, n;
bool f[81][81][mid * 2];
int a[81][81], b[81][81];

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> m >> n;
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++)
            cin >> b[i][j];
    f[1][1][mid - abs(a[1][1] - b[1][1])] = true;
    f[1][1][mid + abs(a[1][1] - b[1][1])] = true;
    for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++){
        if (i == 1 && j == 1) continue;
        int tmp = abs(a[i][j] - b[i][j]);
        if (i > 1){
            for (int t = tmp; t < mid * 2 - tmp; t++){
                f[i][j][t] |= f[i - 1][j][t - tmp];
                f[i][j][t] |= f[i - 1][j][t + tmp];
            }
        }
        if (j > 1){
            for (int t = tmp; t < mid * 2 - tmp; t++){
                f[i][j][t] |= f[i][j - 1][t - tmp];
                f[i][j][t] |= f[i][j - 1][t + tmp];
            }
        }
    }
    int res = mid;
    for (int t = 0; t < mid * 2; t++)
        if (f[m][n][t]) res = min(res, abs(t - mid));
    cout << res;
    return 0;
}


Measured memory_bytes: 162304
k=int(input())
run=[[str(i) for i in range(1,10)],[],[],[],[],[],[],[],[],[]]
#print(run)
i=0
while i<=8:
    for num in run[i]:
        c=int(num[-1])
        if 1<=c<=8:
            run[i+1].append(num+str(c-1))
            run[i+1].append(num+str(c))
            run[i+1].append(num+str(c+1))
        if c==0:
            run[i+1].append(num+"0")
            run[i+1].append(num+"1")
        if c==9:
            run[i+1].append(num+"8")
            run[i+1].append(num+"9")
    #print(len(run[i+1]))
    i=i+1
total=[]
for r in run:
    for s in r:
        total.append(s)
#print(total)
print(total[k-1])
#print(run)

Measured memory_bytes: 18780
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;
    int[] as;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }
        solve();
    }

    void solve() {
        if (as[0] > 0) {
            System.out.println(-1);
            return;
        }
        long[] dp = new long[n];
        dp[n - 1] = as[n - 1];
        for (int i = n - 2; i >= 0; i--) {
            if (as[i] >= as[i + 1]) {
                dp[i] = dp[i + 1] + as[i];
            } else if (as[i] == as[i + 1] - 1) {
                dp[i] = dp[i + 1];
            } else {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(dp[0]);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 45404
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int left = Integer.parseInt(in.next());
        int right = Integer.parseInt(in.next());
        in.close();
        int leftdiv = left / 2019;
        int rightdiv = right / 2019;
        int leftMod = left % 2019;
        int rightMod = right % 2019;
        int ans = -1;
        if (leftdiv == rightdiv) {
            lp:
            for (int i = leftMod; i < rightMod; i++) {
                for (int j = i + 1; j <= rightMod; j++) {
                    if (i * j % 2019 < ans || ans == -1) {
                        ans = i * j % 2019;
                    }
                    if (ans == 0) break lp;
                }
            }
        } else {
            ans = 0;
        }
        System.out.println(ans);
    }
}


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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
#define linf 1e14
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll n,w,a,b;
vector<ll>wei(101),val(101);
vector<vector<ll> >dp(101,vector<ll>(100001,inf));

ll solve(ll i,ll j){
    if(j<0)
        return linf;
    if(!i&&j==val[0])
        return wei[0];
    if(!i&&!j)
        return 0;
    if(!i)
        return linf;
    if(dp[i][j] != inf)
        return dp[i][j];
    dp[i][j]=min(solve(i-1,j),wei[i]+solve(i-1,j-val[i]));
    return dp[i][j];
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin>>n>>w;
    for(int i=0;i<n;i++){
        cin>>wei[i]>>val[i];
    }
    ll ans=0;
    //solve(n-1,100000);

    //for(int i=0;i<101;i++){
   // cout<<ans<<endl;
        for(ll j=0;j<100001;j++){
           // cout<<j<<endl;
            if(solve(n-1,j)<=w){
                ans=max(ans,j);
            }
            //cout<<j<<endl;
        }
    //}
    cout<<ans;
    return 0;
}


Measured memory_bytes: 80256
#include<cstdio>
using namespace std;

const int N = 1e5;
int fa[N+2];
long long fv[N+2];
int n,q;

int find_fa(int u)
{
	int i = u; long long t = 0ll;
	while(u!=fa[u]) {t += fv[u]; u = fa[u];}
	long long k = fv[i];
	fv[i] = t;
	while(i!=u)
	{
		t -= k;
		int j = fa[i];
		fa[i] = u;
		i = j;
		k = fv[i];
		fv[i] = t;
	}
	return u;
}

int main()
{
	scanf("%d%d",&n,&q); bool ans = true;
	for(int i=1; i<=n; i++) {fa[i] = i; fv[i] = 0ll;}
	for(int i=1; i<=q; i++)
	{
		int x,y; long long z; scanf("%d%d%lld",&x,&y,&z);
		int p = find_fa(x),q = find_fa(y);
		if(p!=q)
		{
			fa[q] = p; fv[q] = fv[x]+z-fv[y];
		}
		else
		{
			if(z!=fv[y]-fv[x]) {ans = false; break;}
		}
	}
	if(ans==true) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
int main()
{
    int ara[5],i;
    for(i=0;i<5;i++){
        scanf("%d",&ara[i]);
    }
    for(i=0;i<5;i++){
        if(ara[i]==0)
        printf("%d\n",i+1);
    }
    return 0;
}


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

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

  double div = N;
  if (N % 2 == 0)
    div /= 2;
  else
    div = (div + 1) / 2;

  cout << fixed << setprecision(6);
  cout << div / N << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int power(int x) {
	return x * x;
}
int main()
{
	int N, X[110];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	int ans = mod;
	for (int i = 0; i <= 100; i++) {
		int sum = 0;
		for (int j = 0; j < N; j++) {
			sum += power(X[j] - i);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
}


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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main(){ _
	
	int x; cin >> x;
	if(x < 600) cout << 8 << endl;
	else if(x < 800) cout << 7 << endl;
	else if(x < 1000) cout << 6 << endl;
	else if(x < 1200) cout << 5 << endl;
	else if(x < 1400) cout << 4 << endl;
	else if(x < 1600) cout << 3 << endl;
	else if(x < 1800) cout << 2 << endl;
	else cout << 1 << endl;

	return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
int main(void){
 
  int n,m,i,sum=0,judge;
  int a[10000];
  
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d",&a[i]);
   	sum+=a[i];
  }
  
  judge=n-sum;
  
  if(judge<0)
    printf("-1");
  else
    printf("%d", judge);
  
  return 0;
  
  
 
 
}

Measured memory_bytes: 1756
import sys
from scipy.sparse.csgraph import floyd_warshall
N, M, L = map(int, input().split())
INF = 10 ** 9 + 1
G = [[float('inf')] * N for i in range(N)]
for i in range(M):
    a, b, c = map(int, sys.stdin.readline().split())
    a, b = a - 1, b - 1
    G[a][b] = c
    G[b][a] = c


# 全点間最短距離を計算
G = floyd_warshall(G)


# コストL以下で移動可能な頂点間にコスト１の辺を張る
E = [[float('inf')] * N for i in range(N)]
for i in range(N):
    for j in range(N):
        if G[i][j] <= L:
            E[i][j] = 1


# そのグラフの全点間最短距離を求める
E = floyd_warshall(E)


# クエリに答えていく
Q = int(input())
for i in range(Q):
    s, t = map(int, sys.stdin.readline().split())
    s, t = s - 1, t - 1
    print(int(E[s][t] - 1) if E[s][t] != float('inf') else - 1)


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

typedef long long ll;

using namespace std;

int main(){
    int n,m,p[10000],box[500][2];
    int dp[10001],ans=0;
    
    for(int i=1;i<=10000;i++)
        dp[i]=1000000000;
        
    scanf("%d%d",&m,&n);
    
    for(int i=0;i<m;i++)
        scanf("%d",&p[i]);
    
    for(int i=0;i<n;i++)
        scanf("%d%d",&box[i][0],&box[i][1]);
    
    sort(p,p+m);
    
    for(int i=m-2;i>=0;i--)
        p[i]+=p[i+1];
    
    dp[0]=0;
    
    for(int i=0;i<n;i++)
        for(int j=10000;j>=0;j--){
            if(box[i][0]+j<=10000)
                dp[j+box[i][0]]=min(dp[j+box[i][0]],dp[j]+box[i][1]);
            else
                dp[10000]=min(dp[10000],dp[j]+box[i][1]);
        }
    
    for(int i=9999;i>=0;i--)
        dp[i]=min(dp[i],dp[i+1]);
    
    for(int i=1;i<=m;i++)
        ans=max(ans,p[m-i]-dp[i]);
    
    printf("%d\n",ans);
    
    return 0;
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 2e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int n, a[N], k;
bool ok(int x){
	int cnt = 0;
	for(int i=0; i<n; i++){
		if (a[i] <= x) continue;
		cnt += (a[i]-1) / x;
	}
	return cnt <= k;
}
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n >> k;
	for(int i=0; i<n; i++) cin >> a[i];
	int l = 1, r = 1e9;
	while(l <= r){
		int m = (l+r) / 2;
		if (ok(m)) r = m-1;
		else l = m+1;
	}
	int ans = r + 1;
	cout << ans << endl;
	return 0;
}


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



int main(void)
{
    int a,b,c;
    cin >> a >> b >> c;
    if (b/a >= c) {
        cout << c << endl;
    }
    else {
        cout << b / a << endl;
    }
    return 0;
}

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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;

int N, A[3], L[8];

int main() {
  cin >> N;
  for(int i = 0; i < 3; i++) cin >> A[i];
  for(int i = 0; i < N; i++) cin >> L[i];
  vector< int > dp(1 << N, INF);
  dp[0] = 0;
  for(int i = 0; i < 3; i++) {
    vector< int > dp2(1 << N, INF);
    for(int j = 0; j < 1 << N; j++) {
      for(int k = 1; k < 1 << N; k++) {
        if(j & k) continue;
        int cost = (__builtin_popcount(k) - 1) * 10;
        int sum = 0;
        for(int l = 0; l < N; l++) {
          if((k >> l) & 1) sum += L[l];
        }
        cost += abs(A[i] - sum);
        dp2[j | k] = min(dp2[j | k], dp[j] + cost);
      }
    }
    dp.swap(dp2);
  }
  cout << *min_element(begin(dp), end(dp)) << endl;
}


Measured memory_bytes: 256
class Ship:
  def __init__(self, land_from, land_to):
    self.land_from = land_from - 1
    self.land_to = land_to - 1

N, M = map(int, input().split())

mid_from = set()
mid_to = set()

ships = []
for _ in range(M):
  f, t = map(int, input().split())
  ship = Ship(f, t)
  if ship.land_from == 0:
    mid_from.add(ship.land_to)
  if ship.land_to == N - 1:
    mid_to.add(ship.land_from)

# 最後の島が到達可能であるかを判定
if mid_from & mid_to:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')


Measured memory_bytes: 18944
// 🐋💭
import Foundation

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

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}
///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    print(readInt() >= 30 ? "Yes": "No")
}
main()


Measured memory_bytes: 12996
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  while(1) {
    int h,w;
    cin>>h>>w;
    if(!h)break;
    vector<string> t(h);
    REP(i,h)cin>>t[i];
    vector<string> alls;
    REP(i,h)REP(j,w) {
      int di[]={1,1,1,0,-1,-1,-1,0};
      int dj[]={1,0,-1,-1,-1,0,1,1};
      REP(k,8) {
        string str;
        REP(l,h*w) {
          int ni=(i+di[k]*l+h*w)%h;
          int nj=(j+dj[k]*l+h*w)%w;
          if(l&&ni==i&&nj==j) break;
          str += t[ni][nj];
          alls.push_back(str);
        }
      }
    }
    sort(begin(alls),end(alls),[](const string& lhs, const string& rhs){
      if (lhs.size() > rhs.size()) return true;
      if (lhs.size() == rhs.size() && lhs < rhs) return true;
      return false;
    });
    int n=alls.size();
    string ans="0";
    REP(i,n-1) {
      if (alls[i].size() == 1) break;
      if(alls[i] == alls[i+1]) {
        ans = alls[i];
        break;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 29248
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}



signed main(){
	int N;
	cin>>N;
	string s;
	cin>>s;
	int cnt = 0, ans = 1;
	REP(i,2*N){
		if(s[i]=='B'&&cnt % 2 == 0){
			cnt++;
		}else if(s[i]=='W'&&cnt % 2){
			cnt++;
		}else{
			ans *= cnt;
			cnt--;
		}
		ans %= MOD;
	}
	if(cnt != 0){
		cout << 0 << endl;
		return 0;
	}
	REP(i,N){
		ans *= i + 1;
		ans %= MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)
#define F(i,x,n) for(int i = x; i < n ; ++i)

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

inline bool pn(long int x){
    if(x <= 1)return false;
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i <= (3 + int(sqrt(x)))/2; ++i){
        if((x != i && x % i == 0) || (x != (3 + int(sqrt(x)) - i) && x % (3 + int(sqrt(x)) - i) == 0))
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
//#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

long int jjjjj(long int n){
    long int x = 1;
    for(int i = 1; i <= n; ++i){
        x *=i;
    }
    return x;
}

int main(){
    int a,b;
    cin >> a >> b;
    int c;
    if(b >= 100) c = a * 1000 + b;
    else if(b >= 10) c = a * 100 + b;
    else c = a * 10 + b;

    if(sqrt(c) == int(sqrt(c)))cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  int n, k;
  cin >> k >> n;
  bool d[10];
  fill(d, d+10, false);
  rep(i, n){
    int tmp;
    cin >> tmp;
    d[tmp] = true;
  }
  for(int i = k; 1 ; i++){
    int tmp = i;
    bool flag = true;
    while(tmp){
      if(d[tmp%10]){
        flag = false;
        break;
      }
      tmp /= 10;
    }
    if(flag){
      cout << i <<endl;
      return 0;
    }
  }
      
}

Measured memory_bytes: 256
N=int(input())
rang=[]
for _ in range(N):
  x,l=map(int,input().split())
  rang.append((x-l, x+l))
rang=sorted(rang, key=lambda x: x[1])
lastright=rang[0][1]
cnt=1
for i in range(1,N):
  left=rang[i][0]
  right=rang[i][1]
  if left>=lastright:
    cnt+=1
    lastright=right
print(cnt)

Measured memory_bytes: 19016
import java.text.*;
import java.math.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int kaisu = 3;
		String[] num= new String[kaisu];
		while(true) {

			for(int i = 0; i < kaisu; i++) {
				num[i] = scan.next();
			}

			int a = Integer.parseInt(num[0]);
			String op = num[1];
			int b = Integer.parseInt(num[2]);

			if(op.equals("?")) {
				break;
			}
			if(op.equals("/")) {
				int c = a / b;
				System.out.println(c);
			}
			if(op.equals("+")) {
				int c = a + b;
				System.out.println(c);
			}
			if(op.equals("-")) {
				int c = a - b;
				System.out.println(c);
			}
			if(op.equals("*")) {
				int c = a * b;
				System.out.println(c);
			}
		}
	}
}

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

int M;
int N;
int Q;
vector<vector<long long>>Data;

long long score(const vector<int> &A){
    long long res=0;
    rep(i,Q){
        if((A.at(Data[i][1])-A.at(Data[i][0]))==Data[i][2]){
            res=res+Data[i][3];
        }
    }
    return res;
}

long long dfs(vector<int> &A){
    if(A.size()==N){
        return score(A);
    }//数列のサイズがNになったら終わる
    int last=1;
    long long res=0;
    if(!A.empty()){
        last=A.at(A.size()-1);
    }
    for(int i=last;i<=M;i++){
        A.push_back(i);
        res=max(res,dfs(A));
        A.pop_back();
    }//0からMまで入れていく
    return res;
}//M^N通りの数列を作ることができる

int main(){
    cin>>N>>M>>Q;
    Data.resize(Q);
    rep(i,Q){
        int a,b,c,d;cin>>a>>b>>c>>d;
        a--;b--;
        Data[i].push_back(a);
        Data[i].push_back(b);
        Data[i].push_back(c);
        Data[i].push_back(d);
    }
    vector<int>A;
    cout<<dfs(A)<<endl;
}

Measured memory_bytes: 3636
d, g = map(int, input().split())
P = []
C = []
All = []
for i in range(d):
  p, c = map(int, input().split())
  P.append(p)
  C.append(c)
  All.append((i+1) * p * 100 + c)
#print(All)

import itertools
import math
cand = 100000000000000
for pat in itertools.product([0, 1], repeat=d):
  bonus_point = sum([a * p for a, p in zip(All, pat)])
  bonus_n = sum([num * p for num, p in zip(P, pat)])
  total_n = 0
#  print(bonus_point, bonus_n)
  if bonus_point >= g:
    total_n = bonus_n
  else:
    total_n = bonus_n
    rest = g - bonus_point
    for i in range(d, 0, -1):
      if pat[i-1] == 0:
        if (P[i-1] - 1) * i * 100 >= rest:
          total_n += math.ceil(rest / (i * 100))
          break
        else:
          rest -= (P[i-1] - 1) * i * 100
          total_n += P[i-1]
#  print(bonus_n, total_n)
  cand = min(cand, total_n)
print(cand)

Measured memory_bytes: 43100
local function check(x, vec)
  local w = {}
  for i = 1, #vec do
    w[i] = vec[i]
  end
  local isok = true
  for i = 1, 62 do
    local rmpos = 0
    for j = #w, 1, -1 do
      if w[j] % 2 == 1 then
        rmpos = j
        break
      end
    end
    if rmpos == 0 then
      if x % 2 == 1 then
        isok = false
        break
      end
    else
      local v = w[rmpos]
      table.remove(w, rmpos)
      if x % 2 == 1 then
        x = v ~ x
      end
      for j = 1, #w do
        if w[j] % 2 == 1 then
          w[j] = v ~ w[j]
        end
      end
    end
    x = x // 2
    for j = 1, #w do
      w[j] = w[j] // 2
    end
  end
  return isok
end
local q = io.read("*n")
for iq = 1, q do
  local n = io.read("*n", "*l")
  local as = io.read()
  local a = {}
  for ac in as:gmatch("%d+") do
    table.insert(a, tonumber(ac))
  end
  local s = io.read()
  local t = {}
  local valid = true
  for i = n, 1, -1 do
    if s:sub(i, i) == "0" then
      table.insert(t, a[i])
    else
      if not check(a[i], t) then
        valid = false break
      end
    end
  end
  print(valid and 0 or 1)
end

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

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

    int h[n];
    for(int i=0; i<n; i++){
        cin>>h[i];
    }
    
    int max = h[0];
    for(int i=0; i<n-1; i++){
        int delta = h[i] - h[i+1];
        if(delta > 1){
            cout<<"No"<<endl;
            exit(0);
        }
        else if(delta == 1){
            if(max - h[i+1] > 1){
                cout<<"No"<<endl;
                exit(0);
            }
        }
        else if(max <= h[i+1]){
            max = h[i+1];
        }
    }

    cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/


int main(){
int N,X,Y;
map<int,int> dist_map;
cin>>N>>X>>Y;
rep3(i,N-1){
    rep4(j,i+1,N){
        int dist;
        dist = min(j-i,abs(j-Y)+abs(i-X)+1);
        dist_map[dist]++;

    }
}
rep3(i,N-1){
    cout<<dist_map[i]<<endl;
}
return 0;
}

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
long long n,k,a,b;

void _case()
{
    cin>>n>>k>>a>>b;
    cout<<(n-a)*(k-b)<<'\n';
}

main()
{
    fastio();
    _case();

}



Measured memory_bytes: 3628
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;


int abc104_c(){
    //入力
    int a,b,k;
    cin >> a >> b >> k;
    //処理
    if(b-a<2*k) REP(i,0,b-a+1) cout << a+i << ENT;
    else{
    //出力
    REP(i,0,k){
        cout << a+i << ENT;
    }
    for(int i=k; i>0; --i){
        cout << b-i+1 << ENT;
    }
    }
    return 0;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i<b; i++)
#define dep(i,a,b) for(int i = a-1; i>=b; i--)
#define makeUnique(vec) sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin())
#define LOG_vec(vec, sep) for (int fl = 0; fl < vec.size(); fl++) { cout << vec[fl]<< sep; } cout << "\n";
#define LOG_ints(vec, sep) for (int fl = 0; fl < MAXSIZE; fl++) { cout << vec[fl]<< sep; } cout << "\n"
#define all(x) (x).begin(), (x).end()
#define ll long long
#define LSB(i) ((i) & -(i))
#define vvi vector<vector<int>>
#define vi vector<int>
#define MAXSIZE 100000000
using namespace std;

int main(){
	string s;
	cin >> s;
	bool ok = true;
	rep(i, 0, s.length()/2) {
		if (s[i] == s[s.length() - 1 - i] && s[i] == s[s.length() / 2 - 1 - i] && s[i]== s[s.length() / 2 + 1 + i]) {

		}
		else {
			ok = false;
		}
	}
	cout << (ok == true ? "Yes" : "No");
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int X, Y;
    cin >> X >> Y;
    cout << X + Y/2 << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (__typeof(n) i = 0; i < n; i++)
#define repo(i, n) for (__typeof(n) i = 1; i <= n; i++)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
#define a(a)         \
    for (auto i : a) \
        cout << i << " ";
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main()
{
    string s;
    cin >> s;
    if (s == "Sunny")
        c("Cloudy") else if (s == "Cloudy") c("Rainy") else c("Sunny")
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>


int main(void){

	char s[101];
	char a[51];
	char b[51];
	int n;
	int m;
	int f;
	scanf("%d",&n);
	scanf("%s",s);

	m = n/2;

	strncpy( a, s, m );
	a[m] = '\0';
	strncpy( b, s+m, m );
	b[m] = '\0';

//	printf("a : %s\n",a);
//	printf("b : %s\n",b);

	f = strcmp(a,b);
	if(n % 2 == 0){
		if(f == 0){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main
{

  final static int[] WEIGHT =
  { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };

  public static void main(String[] args) throws NumberFormatException, IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    while (input.ready())
    {
      final int num = Integer.parseInt(input.readLine());

      System.out.println(solver(num));
    }

  }

  private static String solver(int num)
  {
    final char[] bitFlag = Integer.toBinaryString(num).toCharArray();
    StringBuilder ret = new StringBuilder();

    int count = 0;
    for (int i = bitFlag.length - 1; i >= 0; i--)
    {
      if (bitFlag[i] == '1')
      {
        ret.append(WEIGHT[count]);
        ret.append(" ");
      }
      count++;
    }
    return ret.toString().trim();
  }

  private static String solver2(int num)
  {
    final char[] bitFlag = Integer.toBinaryString(num).toCharArray();
    List<String> stringList = new ArrayList<>();

    int count = 0;
    for (int i = bitFlag.length - 1; i >= 0; i--)
    {
      if (bitFlag[i] == '1')
      {
        stringList.add(String.valueOf(WEIGHT[count]));
      }
      count++;
    }
    return String.join(" ", stringList);
  }
}

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

using namespace std;

int n,z,w;
int a[2001];
int dp[2001][2];


int rec(int i, int k, int z, int w) {
  if(dp[i][k] >= 0) return dp[i][k];
  if(i == n) return abs(w-z);
  int ret;
  if(!k) {
    ret = 0;
    for(int j = i; j < n; j++) {
      ret = max(ret,rec(j+1,1,a[j],w));
    }
  }

  else {
    ret = 1e9;
    for(int j = i; j < n; j++) {
      ret = min(ret,rec(j+1,0,z,a[j]));
    }
  }
  return dp[i][k] = ret;
}

int main() {
  cin >> n >> z >> w;

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

  for(int i = 0; i <= n; i++) fill(dp[i],dp[i]+2,-1);

  cout << rec(0,0,z,w) << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  rep (i, N) cin >> A[i];
  rep (i, N) cin >> B[i];

  vector<ll> foo(N);
  vector<ll> bar(N);

  rep (i, N) foo[i] = A[i] ^ A[(i+1)%N];
  rep (i, N) bar[i] = B[i] ^ B[(i+1)%N];

/*
  rep (i, N) cerr << foo[i] << " ";
  cerr << endl;

  rep (i, N) cerr << bar[i] << " ";
  cerr << endl;
*/

  ll shuuki_foo = N;
  ll shuuki_bar = N;

  rep (i, N) {
    if (i == 0) continue;
    if (N % i) continue;
    bool flag = true;
    rep (j, N) {
      if (foo[j] != foo[(j + i) % N]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      shuuki_foo = i;
      break;
    }
  }

  rep (i, N) {
    if (i == 0) continue;
    if (N % i) continue;
    bool flag = true;
    rep (j, N) {
      if (bar[j] != bar[(j + i) % N]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      shuuki_bar = i;
      break;
    }
  }

  // cerr << shuuki_foo << ", " << shuuki_bar << endl;

  if (shuuki_foo != shuuki_bar) return;

  ll aaa = -1;
  rep (i, shuuki_foo) {
    bool flag = true;
    rep (j, shuuki_foo) {
      if (bar[j] != foo[(j + i) % N]) {
        flag = false;
        break;
      }
    }
    if (flag) aaa = i;
  }

  if (aaa == -1) return;

  for (ll k = aaa; k < N; k += shuuki_foo) {
    ll x = A[k] ^ B[0];
    cout << k << " " << x << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 9728
#include <stdio.h>

int main(void){
  
  char S[5];
  int num = 0;
  
  fgets(S,5,stdin);
  
  for(int i = 0;i < 4;++i){
    if(S[i] == '+'){
      ++num;
    }
    else{
      --num;
    }
  }
  printf("%d",num);
  return 0;
}


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

using namespace std;

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

  int n;
  cin >> n;
  vector<vector<long long>> dp(n + 1, vector<long long>(3));
  for (int i = 1; i <= n; ++i) {
    int a[3];
    for (int j = 0; j < 3; ++j) {
      cin >> a[j];
    }
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (k == j) {
          continue;
        }
        dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[j]);
      }
    }
  }
  cout << max({dp[n][0], dp[n][1], dp[n][2]});

  return 0;
}

Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
#define LL long long int

int main()
{
    LL A, B, C, D;
    scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
    printf("%lld\n", min(A, B) + min(C, D));
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;


typedef std::pair<int,int> P;

const int INF = 1000000;

int diagram(P p){
    return p.first * p.first + p.second * p.second;
}

int compare(P a, P b){
    if(diagram(a) > diagram(b))
        return -1;
    if(diagram(a) < diagram(b))
        return 1;
    //diagram(a) == diagram(b)
    if(a.first > b.first)
        return -1;
    if(a.first < b.first)
        return 1;
    return 0;
}

int main() {
    int h, w;
    while(cin >> h >> w, h) {
        P s = make_pair(h,w);
        P ans = make_pair(150,150);
        int ww = 200, hh = 200;
        int dd = INF;
        for(int i = 1; i <= 150; i++) {
            for(int j = 1; j <= 150; j++) {
                P p = make_pair(j,i);
                if(p.first < p.second && compare(s,p)>0 && compare(p,ans)>0){
                    ans = p;
                }
            }
        }

        cout << ans.first << ' ' << ans.second << endl;
    }
}

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

int main(){
    long N,M;cin>>N>>M;
    long H[N];
    for(int i=0;i<N;i++)cin>>H[i];
    vector<vector<int>> road(N,vector<int>(0));
    vector<int> num(N,0);

    for(int i=0;i<M;i++){
        long a,b;cin>>a>>b;
        num.at(a-1)++;
        num.at(b-1)++;
        if(H[a-1]>H[b-1])road.at(a-1).push_back(1);
      else if(H[a-1]<H[b-1]) road.at(b-1).push_back(1);
    }

    int ans=0;
    for(int i=0;i<N;i++){
        if(num.at(i)==road.at(i).size())ans++;
    }
  /*for(int i=0;i<N;i++){
    cout<<num.at(i)<<":"<<road.at(i).size()<<endl;
  }*/
    cout<<ans<<endl;
}

Measured memory_bytes: 8568
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  int N; cin >> N;
  
  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i]; P[i]--;
  }

  bool ans = true;
  bool swap = false;
  for (int i = 0; i < N; i++) {
    if (P[i] != i) {
      if (swap) {
	ans = false;
	break;
      }
      int index = P[i];
      if (P[index] != i) {
	ans = false;
      } else {
	P[index] = index;
	P[i] = i;
	swap = true;
      }
    }
  }

  cout << (ans ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll,ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int n,k; cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    rep(j,k){
        bool check=true;
        vector<int> ans(n,0);
        rep(i,n){
            int l=max(0,i-a[i]);
            int r=min(n-1,i+a[i]);
            ans[l]++;
            if(r<n-1) ans[r+1]--;
        }
        rep(i,n-1) ans[i+1]+=ans[i];
        rep(i,n){
            if(ans[i]!=n){
                check=false;
                break;
            }
        }
        a=ans;
        if(check) break;
    }
    rep(i,n) cout << a[i] << ' ';
    cout << endl;
return 0;
}



Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define int long long
#define INF 2e10+10

int n,k,x;
int a[MAXN];
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>k>>n;

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

    }

    int resp=INF;
    resp=min(resp,a[n]-a[1]);
    //horário
    for(int i=2;i<=n;i++){
        int temp=a[i-1]-a[i];
        if(temp<=0)temp+=k;
        //cout<<i<<" "<<temp<<"\n";
        resp=min(resp,temp);
    }


    for(int i=n-1;i>=1;i--){

        int temp=k-a[i+1]+a[i];
            //cout<<i<<" "<<temp<<"\n";
            resp=min(resp,temp);


    }
    cout<<resp;



    return 0;
}

Measured memory_bytes: 1792
n,m=map(int,input().split())
s=input()
ans=[]
now=n
while now>0:
    for i in range(m,0,-1):
        if now-i<0:
            continue
        if s[now-i]=='0':
            ans.append(str(i))
            now-=i
            break
    else:
        print(-1)
        exit()
print(' '.join(ans[::-1]))

Measured memory_bytes: 47856
n = int(input())
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append([b, a])

ab = sorted(ab)
total = 0

for i in range(n):
    b, a = ab[i]
    total += a
    if total>b:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 37272
N = gets.to_i
A = gets.split.map(&:to_i).sort!

def divisors(n)
  d = []
  1.upto(Math.sqrt(n).to_i) do |i|
    if n % i == 0
      d << i
      d << n / i
    end
  end
  d
end

divs = (divisors(A[0]) | divisors(A[1])).sort_by! { |a| -a }
counts = Array.new(divs.size, 0)

A.each do |a|
  divs.each_with_index do |div, idx|
    counts[idx] += 1 if a % div == 0
  end
end

counts.each.with_index do |count, idx|
  if count >= N - 1
    puts divs[idx]
    break
  end
end

Measured memory_bytes: 11136
from bisect import bisect_left
N = int ( input() )
t_list = list ( map ( int, input().split() ) )
t_list.sort()
ans = 0

for i in range ( N - 2 ):
  a = t_list[i]
  for j in range ( i + 1, N - 1 ):
    b = t_list[j]
    c = bisect_left ( t_list , a + b)
    ans += c - j - 1
    
print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll fac[4000005],ifac[4000005],inv[4000005],p=1e9+7;
void ycl(int n){
	fac[1]=fac[0]=ifac[0]=ifac[1]=inv[0]=inv[1]=1;
	for (int i=2;i<=n;i++){
		inv[i]=(p-p/i)*inv[p%i]%p;
		fac[i]=fac[i-1]*i%p;
		ifac[i]=ifac[i-1]*inv[i]%p;
	}
}
ll C(int n,int m){
	if (n<m) return 0;
	return ((fac[n]*ifac[m])%p*ifac[n-m])%p;
}
ll f[2005][2005];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	if (k<=1){printf("1\n"); return 0;}
	ycl(n*k);
	f[0][0]=1;
	for (int i=1;i<=n;i++){
		for (int j=n;j>=0;j--){
			if (j<=i) f[i][j]=(f[i][j]+f[i-1][j-1]*C(i*k-j-1,k-2))%p;
			f[i][j]=(f[i][j]+f[i][j+1])%p;
		}
	}
	ll ans=f[n][0];
	ans=ans*fac[n]%p;
	printf("%lld\n",ans);
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/03  Problem: code-festival-2016-ex-final_b / Link: https://cf16-exhibition-final.contest.atcoder.jp/tasks/cf16_exhibition_final_b?lang=en  ----- */
/* ------問題------

すぬけ君は、誕生日プレゼントに三角形をもらいました。 三頂点の座標は (x1,y1), (x2,y2), (x3,y3) でした。
すぬけ君は、三角形の内部に半径の等しい二つの円を、重ならないように描きたいです (二円が点で接していてもいいです)。 円の半径の最大値を求めてください。

-----問題ここまで----- */
/* -----解説等-----

S = 1/2 * abs(ay(bx-cx) + by(cx-ax) + cy(ax -bx)) = 1/2 * R * (a + b + c)
内心円の中心からなる円を２つ書くとこれらはある辺に対して平行
相似から、求めるものをXとすると
X = {edge() * R} / (2r + edge())
edge()は当然3つあるので全部やる

----解説ここまで---- */

LL N;

double ans = 0LL;

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

	double ax, ay, bx, by, cx, cy;
	cin >> ax >> ay >> bx >> by >> cx >> cy;
	double a = hypot(ax - bx, ay - by);
	double b = hypot(bx - cx, by - cy);
	double c = hypot(cx - ax, cy - ay);
	double R = abs(ay*(bx - cx) + by*(cx - ax) + cy*(ax - bx)) / (a + b + c);
	ans = max({ a,b,c }) * R / (2 * R + max({ a,b,c }));
	cout << fixed << setprecision(10) << ans << "\n";

	return 0;
}


Measured memory_bytes: 256