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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


i64 A, B, C, D;

i64 gcd(i64 x, i64 y) {
  return y == 0 ? x : gcd(y, x % y);
}

i64 lcm(i64 x, i64 y) {
  return x * y / gcd(x, y);
}

i64 num_divisible(i64 x, i64 a, i64 b) {
  return x / a + x / b - x / lcm(a, b);
}

int main() {
  cin >> A >> B >> C >> D;

  i64 cnt = (B - num_divisible(B, C, D)) - (A - 1 - num_divisible(A - 1, C, D));
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n;
	cin>>n;
	map<string,LL> mp;
	FOR(i,0,n){
		string t;
		cin>>t;
		sort(t.begin(),t.end());
		mp[t]++;
	}
	LL ans=0;
	for(const auto& pr:mp){
		if(pr.ND>=2){
			ans+=1LL*(pr.ND-1)*pr.ND/2;
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 11136
a, b, c, d = map(int,input().split())
flag = True
while a > 0 and c > 0:
    c -= b
    if c <= 0:
        flag = True
        break
    a -= d
    if a <= 0:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 8920
import sys
from collections import deque

N,Q=map(int, sys.stdin.readline().split())

 
al=[ [] for i in range(N+1) ]
 
for _ in range(N-1):
	a,b=map(int, sys.stdin.readline().split())
	al[a].append(b)
	al[b].append(a)

Visit=[ None for i in range(N+1) ] 
score=[ 0 for i in range(N+1) ] 

for _ in range(Q):
	p,x=map(int, sys.stdin.readline().split())
	score[p]+=x


q=deque()
q.append(1)

while q:
	fro=q.popleft()
	Visit[fro]=1
	for to in al[fro]:
		if Visit[to] is None:
			score[to]+=score[fro]
			q.append(to)


for i,ans in enumerate(score):
	if i==0:	continue
	print ans,

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

t=[]
x=[]
y=[]

for i in range(n):
    a,b,c = map(int,input().split())
    t.append(a)
    x.append(b)
    y.append(c)


ans = True
move=(x[0]+y[0])
time = t[0] - 0
if move > time:ans = False
if (time - move)%2 ==1:ans = False

for i in range(1,n):
    move =x[i] + y[i] - x[i-1] - y[i-1]
    time =t[i] - t[i-1]
    if move > time:ans = False
    if (time - move)%2 ==1:ans = False

if ans:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 11736
#メモ化再帰以外は実装が厳しい

n,k = map(int, input().split( ))
memo = [-1]*(k+1)
mod = 10**9+7
def rec(x):
    if memo[x]>=0:
        return memo[x]
    mult = 0
    for i in range(x*2,k+1,x):
        mult += rec(i)
    res = memo[x] = pow(k//x,n,mod) - mult
    return res
ans = 0
rec(1)
for i in range(1,k+1):
    ans += i*memo[i]
print(ans%mod)
  


Measured memory_bytes: 77764
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for (int i = 0; i < N; i++) cin >> S[i];
    sort(S.begin(), S.end());
    for (auto s : S) cout << s;
    cout << endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  if(a[n-1] <= 0) {
    int ans = a[n-1];
    rep(i,n-1) ans -= a[i];
    cout << ans << endl;
    rep(i,n-1) {
      cout << a[n-1] << " " << a[i] << endl;
      a[n-1] -= a[i]; 
    }
  } else if(a[0] >= 0) {
    int ans = a[0];
    for(int i = 1; i < n-1; i++) ans -= a[i];
    ans = a[n-1] - ans;
    cout << ans << endl;
    for(int i = 1; i < n-1; i++) {
      cout << a[0] << " " << a[i] << endl;
      a[0] -= a[i];
    }
    cout << a[n-1] << " " << a[0] << endl;
  } else {
    int ans = 0;
    rep(i,n) ans += abs(a[i]);
    cout << ans << endl;
    int p = 0;
    while(a[p] < 0) {p++;}
    for(int i = p; i < n-1; i++) {
      cout << a[0] << " " << a[i] << endl;
      a[0] -= a[i];
    }
    rep(i,p) {
      cout << a[n-1] << " " << a[i] << endl;
      a[n-1] -= a[i];
    }
  }
  return 0;
}

Measured memory_bytes: 2304
x = list(map(int,input().split()))
a = x[0]
b = x[1]
k = x[2]
if b - a + 1 < k * 2:
    for i in range(b - a + 1):
        print(a + i)
else:
    for i in range(k):
        print(a + i)
    for i in range(k):
        print(b - k + 1 + i)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
	int H, W, i, j;
	while (scanf("%d %d", &H, &W) != EOF) {
		if(H == 0 && W == 0) {
			break;
		}
		for(i = 1; i <= H; i++) {
    			for(j = 1; j <= W; j++) {
    				if(i > 1 && i < H && j < W && j > 1)
    					printf(".");
    				else 
    					printf("#");
    				}
    			printf("\n");
    		}
	printf("\n");
     
       }
	return 0;
}


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

int main() {
    string s, t; cin >> s >> t;
    int slen = s.size();
    int tlen = t.size();

    for (int i = slen; i >= tlen; --i) {
        string flagment = s.substr(i - tlen, tlen);
        bool matched = true;
        for (int j = 0; j < (int)flagment.size(); ++j) {
            char c = flagment[j];
            matched &= c == '?' || c == t[j];
        }

        if (matched) {
            for (int j = 0; j < slen; ++j) {
                if (i - tlen <= j && j < i) {
                    s[j] = t[j - i + tlen];
                } else if (s[j] == '?'){
                    s[j] = 'a';
                }
            }
            cout << s << endl;
            return 0;
        }
    }

    cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
inputs = readlines

input=[]
for i in 1..inputs.size do
    input.push(inputs[i-1].split)
end

n = input[0][0].to_i
k = input[0][1].to_i
s = input[1][0].split("")

stack = []
if s[0] == "0"
    stack.push(0)
end

sum = 0
max = 0

count = 0
tar = s[0]

for i in 1..n do 
    if tar != s[i-1] 
        tar = s[i-1]
        stack.push(count)
        sum += count
        count = 1
        if stack.size > 2*k +1
            sum -= stack.shift
        end
        if tar == "0" and sum > max 
            max = sum
        end
    else
        count += 1
    end
end

stack.push(count)
sum += count
if s[n-1] == "0"
    stack.push(0)
    sum -= stack.shift
end

if stack.size > 2*k +1
    sum -= stack.shift
elsif stack.size == 1
    sum = n
end

if sum > max 
    max = sum
end

p max

Measured memory_bytes: 10108
from bisect import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA = [0] * (N + 1)
SB = [0] * (M + 1)
for i in range(N):
    SA[i+1] = SA[i] + A[i]
for i in range(M):
    SB[i+1] = SB[i] + B[i]
result = 0
for x in range(N+1):
    if SA[x] > K:
        break
    y = bisect(SB, K - SA[x]) - 1
    result = max(result, x + y)
print(result)

Measured memory_bytes: 47348
/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
typedef queue<int> qii;
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;

void solve(){
    ll a,b;
    cin>>a>>b;
    ll x=gcd(a,b);
    cout<<(a*b)/x;
}
    
int main(){
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    // fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int MAX=1e5+5;
vector<int> llist[MAX],ansA,ansB;
int n,m,color[MAX];
bool flag;
void dfsA(int u)
{
	color[u]=1;
	ansA.push_back(u);
	for(int i=0;i<llist[u].size();++i)
	{
		int t=llist[u][i];
		if(flag) break;
		if(color[t]==1) continue;
		dfsA(t);
	}
	flag=true;
}
void dfsB(int u)
{
	color[u]=1;
	if(u!=1) ansB.push_back(u);
	for(int i=0;i<llist[u].size();++i)
	{
		int t=llist[u][i];
		if(flag) break;
		if(color[t]==1) continue;
		dfsB(t);
	}
	flag=true;
}
int main()
{
	int a,b;
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		cin>>a>>b;
		llist[a].push_back(b);
		llist[b].push_back(a);
	}
	flag=false;
	dfsA(1);
	flag=false;
	dfsB(1);
	cout<<ansA.size()+ansB.size()<<endl;
	for(int i=ansA.size()-1;i>=0;--i){
		cout<<ansA[i]<<" ";
	}
	for(int i=0;i<ansB.size();++i){
		cout<<ansB[i]<<" ";
	}
	return 0;
}

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

int main(){
    int N, ans = 0;
    cin >> N;
    vector<int> d(N);
    for(int i = 0;i < N;i++){
        cin >> d.at(i);
    }
    sort(d.begin(), d.end());
    for(int i = 0;i < N;i++){
        if(i >= 1 && d.at(i) == d.at(i - 1)) continue;
        else ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);
const double PI = acos(-1);

struct Area{
	public:
	int l;
	int r;
	Area(int _l, int _r){
		l = _l;
		r = _r;
	}

	bool operator<( const Area& a ) const {
		if(l != a.l)return l < a.l;
		else return r > a.r;
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	set<Area> S;
	int n,m;
	cin >> n >> m;
	REP(i,m){
		int a,b;
		cin >> a >> b;
		S.insert(Area(a,b));
	}
	int rr = -1;
	int ans = 0;
	for(auto a:S){
		if(a.l >= rr){
			ans++;
			rr = a.r;
		}else{
			rr = min(rr,a.r);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
# xの逆元は、x*y = 1 mod pとなるようなy
N, K = map(int, input().split())
mod = 10**9 + 7
a = N - K + 1
print(a)
for i in range(K-1):
    a = a * (N - K - i) * (K - (i + 1)) // ((i+2) * (i+1))
    print(a % mod)



Measured memory_bytes: 3316
S = [int(c) for c in input()]
black_started = [0 ^ (i % 2) for i in range(len(S))]
white_started = [1 ^ (i % 2) for i in range(len(S))]
black_diff = 0
white_diff = 0
for i in range(len(S)):
    if black_started[i] != S[i]:
        black_diff += 1
    if white_started[i] != S[i]:
        white_diff += 1
print(min(black_diff, white_diff))


Measured memory_bytes: 5532
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright  : @Huki_Hara
# Created    : 2015-03-05

while True:
    try:
        a=list(map(int, input().split()))
        b=list(map(int, input().split()))
    except:
        break;

    hit=0
    blow=0
    for i in range(4):
        if a[i] == b[i]: 
            hit += 1
    for i in range(4):
        for j in range(4):
            if i != j and a[i] == b[j]: blow += 1

    print(str(hit) + " " + str(blow))

Measured memory_bytes: 6720
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  string s;
  cin >> s;

  ll ans = 0, r = 0, b = 0;
  REP(i, s.size()){
    if(s[i] == '0') r++;
    else b++;
  }
  ans = 2 * min(r, b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> p(n);
    REP(i, n){
        cin >> p[i];
    }
    lint ans = 0;
    for (int i=1; i<n-1; ++i){
        if(p[i-1] < p[i] && p[i] < p[i+1]){
            ans++;
        }
        else if(p[i+1] < p[i] && p[i] < p[i-1]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  bool flag = true;
  if(n % 2 != 0) flag = false;
  else rep(i, n/2) {
    if(s.at(i) != s.at((n/2) + i)) flag = false;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

#define MODULO 1000000007

int main()
{
	long long n;
	cin >> n;
	vector<int> c(n, 0);
	for (int i = 0; i < n; i++)
	{
		long long a;
		cin >> a;
		c[(n - 1 - a)/2]++;
		c[(n - 1 + a)/2]++;
	}
	bool valid = true;
	for (auto&& ci : c)
		if (ci != 2)
		{
			valid = false;
			break;
		}
	if (valid)
	{
		pair<long long, long long> dp[17];
		dp[0] = {1ll, 2ll};
		for (int i = 0; i < 16; i++)
		{
			dp[i+1] = {dp[i].first * 2, (dp[i].second * dp[i].second) % MODULO};
		}
		long long result = 1;
		long long x = n / 2;
		while (x > 0)
		{
			int i = 0;
			while (dp[i].first <= x) i++;	 
			result = (result * dp[i-1].second) % MODULO;
			x -= dp[i-1].first;
		}
		cout << result << endl;
	}
	else
		cout << 0 << endl;

	return 0;
}


Measured memory_bytes: 640
n = int(input())
a = [int(input()) for i in range(n)]

count = 1
now = 0

for i in range(n):
  if a[now] == 2:
    break
  else:
    now = a[now]-1
    count += 1
#    print("now:",a[now])

if a[now] == 2:
  print(count)
else:
  print(-1)

Measured memory_bytes: 7084
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] list = new int[N-1];
        for (int i = 0 ; i < N-1 ; i++) {
        	list[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int sum = list[0] + list[N-2];
        for(int i = 0 ; i < N-2 ; i++) {
        	sum += Math.min(list[i], list[i+1]);
        }

		System.out.println(sum);


    }
}

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

int main(){
	int n;
	int odd_count = 0;
	int multi4_count = 0;
	int even_not_multi4_count = 0;
	cin >> n;
	for(int i=0; i<n; i++) {
		int tmp;
		cin >> tmp;
		if(tmp%2) {
			odd_count++;
		} else if(tmp%4){
			even_not_multi4_count++;
		} else {
			multi4_count++;
		}
	}
	if(even_not_multi4_count) {
		if(odd_count<=multi4_count){
			cout << "Yes";
		} else {
			cout << "No";
		}
	} else {
		if(odd_count<=multi4_count + 1){
			cout << "Yes";
		} else {
			cout << "No";
		}
	}
}



Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

const int FACT_MAX = 200005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

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

llint n;
llint x[205], y[205];
vector<llint> vec;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i] >> y[i];
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(i >= j) continue;
			llint cnt = 0, dx = x[j]-x[i], dy = y[j]-y[i];
			for(int k = 1; k <= n; k++){
				llint dx2 = x[k]-x[i], dy2 = y[k]-y[i];
				if(dx*dy2 - dx2*dy == 0) cnt++;
			}
			vec.push_back(cnt);
		}
	}
	
	llint ans = 0;
	for(int i = 0; i < vec.size(); i++){
		if(vec[i] < 2) continue;
		llint tmp = modpow(2, vec[i]);
		tmp += mod - (vec[i]+1), tmp %= mod;
		ans += tmp * modpow(vec[i]*(vec[i]-1)/2, mod-2) % mod, ans %= mod;
	}
	ans += n+1, ans %= mod;
	
	ans = modpow(2, n) - ans + mod, ans %= mod;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
import math
import sys

a, b, C = [int(x) for x in sys.stdin.readline().split()]
C = math.radians(C)
l = a + b + math.sqrt(a * a + b * b - 2 * a * b * math.cos(C))
h = b * math.sin(C)
s = a * h / 2
print(s)
print(l)
print(h)

Measured memory_bytes: 7912
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val ps = (0 until n).map {
        val (x, y) = readLine()!!.split(' ').map { it.toDouble() }
        x to y
    }

    fun dfs(indices: List<Int>): Double {
        if (indices.size == n) {
            var d = 0.0
            for (i in 1 until n) {
                val p1 = ps[indices[i - 1]]
                val p2 = ps[indices[i]]
                d += Math.sqrt(Math.pow(p1.first - p2.first, 2.0) + Math.pow(p1.second - p2.second, 2.0))
            }
            return d
        }

        var d = 0.0

        for (i in 0 until n) {
            if (indices.contains(i)) continue
            d +=  dfs(indices + i)
        }

        return d
    }

    fun fact(n: Int): Int {
        if (n == 1) return 1
        return n * fact(n - 1)
    }

    println(dfs(emptyList()) / fact(n))
}


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

using namespace std;

#define int long long
#define For(i, a, b) for(int i = a; i <= b; ++ i)
#define fi first
#define se second

typedef pair < int, int > ii;

int r, c, n;
int ans[10];
map < ii, int > ma;

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> r >> c >> n;
	For(k, 1, n){
		int x, y; cin >> x >> y;
		For(i, - 2, 0) For(j, -2, 0)
			if(1 <= x + i && x + i <= r - 2 && 1 <= y + j && y + j <= c - 2) ma[ii(x + i, y + j )] ++;
	}
	for(auto i : ma) ans[i.se] ++;
	ans[0] = (r - 2) * (c - 2);
	For(i, 1, 9)  ans[0] -= ans[i];
	For(i, 0, 9) cout << ans[i] << "\n";
}
/*
10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9
*/

Measured memory_bytes: 56576
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


using namespace std;
int main() {
	int a, b;
	cin >> a >> b;

	cout << 2 * b - a << endl;

	return 0;
}

Measured memory_bytes: 256
A, B, C, D=(int(x) for x in input().split(" "))
import fractions

def eks(x,a):
    return a//x

def wai(x):
    return eks(x,B)-eks(x,A-1)

def lcm(a,b):
    return a*b//fractions.gcd(a,b)

zet=B-A+1-(wai(C)+wai(D)-wai(lcm(C,D)))
print (zet)

Measured memory_bytes: 5076
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	S := nextLine()
	ans := 0
	for i, j := 0, len(S)-1; i < j; i, j = i+1, j-1 {
		if S[i] != S[j] {
			ans++
		}
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}

func paindrome(s string) bool {
	return s == Reverse(s)
}

func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
  int first_temperature=0;
  int last_temperature=0;
  int c=0;//凍った肉を 1 ℃温めるのにかかる時間
  int d=0;//凍った肉を解凍するのにかかる時間
  int e=0;//凍っていない肉を 1 ℃温めるのにかかる時間

  scanf("%d",&first_temperature);
  scanf("%d",&last_temperature);
  scanf("%d",&c);
  scanf("%d",&d);
  scanf("%d",&e);

  int sec=0;
  int flozen=0;
  int t=first_temperature;
  if(t<0) flozen=-1;
  while(t<last_temperature){
    if(flozen==-1){//凍っている
      if(t==0){ sec+=d; flozen++; }//t=0
      else{ sec+=c; t++; }//t<0
    }
    else{ sec+=e; t++; }//t>0
  }
  printf("%d\n",sec);
  return 0;
}



Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n,d;
	cin>>n>>d;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		ll x,y;
		cin>>x>>y;
		if(d*d>=x*x+y*y)
		ans++;
	}
	cout<<ans<<endl;
}

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

int main () 
{
	long n, m;
	cin >> n >> m;
	if(n == 1  || m == 1)
    {
		if(n == 1 && m == 1)
        {
			cout << 1;
		}
        else
        {
			cout << max(0,(int)(n + m - 3)) << endl;
		}
	}
    else if(n == 2 || m == 2)
    {
		cout << 0;
	}
    else
    {
		long tmp = 0;
		tmp = (n-2) * (m-2);
		cout << tmp;
	}
}


Measured memory_bytes: 256
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
ll n,x;
ll a,b,ans;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),x=read();
	ans=n;
	a=x,b=n-x;
	while(true)
	{
		if(a<b)swap(a,b);
		ans+=((a/b)*2)*b;if(a%b==0){ans-=b;break;}
		a=a%b;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3756
import java.util.Scanner;
public class Main{
    int high;
    int low;
    int sa;
    
    public void solve(){
       Scanner sc = new Scanner(System.in);
	   for(int i=0;i<7;i++){
        high=sc.nextInt();
		low=sc.nextInt();
		sa=high-low;
		System.out.println(sa);
	   }
    }
    public static void main(String[]args){
        Main obj = new Main();
        obj.solve();
    }
}

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

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;



struct  Combination{
  vector<ll> con;
  vector<ll> coni;
  ll n;
  ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x;
        x = x*x;
        n = n >> 1;
    }
    return ans;
  }

  Combination(ll input){
    n=input;
    con.push_back(1);
    coni.push_back(1);
    rep(i,n){
      con.push_back(con[i]*(i+1));
      coni.push_back(coni[i] * mpow(i+1,MOD-2));
    }
  }
  
  ll comb(ll N, ll k){
    if(N == 0 && k == 1)return 1;
    if(N < k || k < 0)return 0;
    ll tmp=con[N]*coni[k];
    return tmp*coni[N-k];
  }
};

//
void solve(std::string A){
  ll cnt=0;
  ll t=0;
  //Combination C(A.size());
  rep(i,26){
    rep(j,A.size()){
      if(A[j]-'a'==i){
        t++;
      }
    }
    
    cnt+=t*(t-1)/2;
    t=0;
  }
  op(A.size()*(A.size()-1)/2-cnt+1);
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string A;
    std::cin >> A;
    solve(A);
    return 0;
}


Measured memory_bytes: 772
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int 
#define ar array
#define pb push_back
#define fi(a,b) for(ll i=a;i<(b);i++)
#define fj(a,b) for(ll j=a;j<(b);j++)
#define fk(a,b) for(ll k=a;k<(b);k++)


int main()
{
	FAST;
	//#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	//#endif
	//int tt;
	//cin>>tt;
	//while(tt--)
	{
		string s;
		cin>>s;
		if(s.back()=='s')
		{
			//s.pop_back();
			s+="es";
		}
		else
		{
			s+='s';
		}
		cout<<s;
		
		
		
	}		
}


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

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();
    long[][] s = new long[4][N];
    for (int i = 0; i < N; i++) {
      long x = scanner.nextLong();
      long y = scanner.nextLong();
      long z = scanner.nextLong();
      s[0][i] =  x + y + z;
      s[1][i] = -x + y + z;
      s[2][i] =  x - y + z;
      s[3][i] =  x + y - z;
    }

    for (int i = 0; i < 4; i++) {
      Arrays.sort(s[i]);
    }

    long max = 0;
    for (int i = 0; i < 4; i++) {
      long a = 0;
      for (int j = 0; j < M; j++) {
        a += s[i][j];
      }
      if (a > max) max = a;
      if (-a > max) max = -a;

      a = 0;
      for (int j = 0; j < M; j++) {
        a += s[i][N - j - 1];
      }
      if (a > max) max = a;
      if (-a > max) max = -a;
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 26352
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

ll _find(int d,int n){
    return n<100 ? pow(100,d)*n : 101*pow(100,d);
}

void solve(){
    
    
    ll n;
    cin>>n;
    
    vll M(n+1);
    for(ll i=0;i<=n;i++){
        cin>>M[i];
    }
    
    vll H(n);
    for(ll i=0;i<n;i++){
        cin>>H[i];
    }
    
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(H[i]<=M[i]){
            ans+=H[i];
            M[i]-=H[i];
            H[i]=0;
        }
        else{
            ans+=M[i];
            H[i]-=M[i];
            M[i]=0;
            if(H[i]<=M[i+1]){
                ans+=H[i];
                M[i+1]-=H[i];
                H[i]=0;
            }
            else{
                ans+=M[i+1];
                H[i]-=M[i+1];
                M[i+1]=0;
            }
        }
    }
    cout<<ans<<endl;
}

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

Measured memory_bytes: 4768
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
  int A, B, K;
  cin >> A >> B >> K;
  int ans = __gcd(A,B);
  while (true) {
    if (A % ans == 0 && B % ans == 0) {
      K--;
      if (K == 0) break;
    }
    ans--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, m) = readInputLine().split(" ").map{it.toInt()}
    
    var l = 1
    var r = n
    
    for (i in 1..m) {
        val (li, ri) = readInputLine().split(" ").map{it.toInt()}
        
        if (l < li) {
            l = li
        }
        if (ri < r) {
            r = ri
        }
    }
    
    if (r < l) {
        println(0)
    } else {
        println(r - l + 1)
    }
}

fun readInputLine(): String {
    return readLine()!!
}


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

typedef long long 		ll;
typedef vector<ll> 		vll;
typedef pair<ll,ll> 	pll;
typedef vector<pll> 	vpll;
typedef vector<int> 	vi;
typedef pair<int,int> 	pii;
typedef vector<pii> 	vpii;

#define fi				first
#define se 				second
#define pb 				push_back
#define mp 				make_pair
#define all(v)			v.begin(),v.end()
#define sz(v)			s.size()
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define per(i,a,b) 		for(int i=a;i>=b;i--)
#define fill(a,v)		memset(a,v,sizeof(a))
#define tc				int T;cin>>T;while(T--)
#define nl				printf("\n")
#define aya				cerr<<"yaha aya"<<"\n"
#define debug(x,y)		printf("%d %d\n",x,y)
#define fast_io			ios_base::sync_with_stdio(false);cin.tie(NULL);
#define grt				greater<int>()

const int mod = 1e9+7;
const int mod2= 1e9+9;

inline int pow_(ll a, int n, int p=mod){
	int r=1;while(n){if(n&1)r=r*a%p;n>>=1;a=a*a%p;}return r;
}

int main(void)
{
	int n, m;
	cin >> n >> m;
	int a[m];
	int s = 0;
	rep(i, 0, m-1){
		cin >> a[i];
		s += a[i];
	}
	if(s > n){
		cout << "-1\n";
	}else{
		cout << n-s << "\n";
	}
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(void){
  int h,w;
  int i,j;
  
  while(1){
    scanf("%d",&h);
    scanf("%d",&w);

    if(h==0 && w==0){
      break;
    }
    
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        if(i!=0 && j!=0 && i!=h-1 && j!=w-1){
          printf(".");
        }else{
          printf("#");
        }
      }
      putchar('\n');
    }
    putchar('\n');
  }
  
  return 0;
}

Measured memory_bytes: 576
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, H, W;
    cin >> N >> H >> W;
    vector<pair<int, int>> A(N);
    cin >> A;

    int ans = 0;
    REP(i, N) {
        if (A[i].first >= H && A[i].second >= W) ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define DEBUG
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
#define F first
#define S second 
#define pb push_back
#define endl "\n"

#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }

#ifdef DEBUG
    #define dbg(s) {s;}
#endif

#ifndef DEBUG
    #define dbg(s)
#endif

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) { // from [0, n-1]
    return uniform_int_distribution<int>(0, x - 1)(rng);
}

#define int ll
#define i32 int32_t

#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 

#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;

int getInt () {
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}


ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 

const ll mod = 1e9 + 7;

ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}

const int maxn = 1e6 + 7;

const ll inf = 1e9 + 7;

vector < pair<int, pii> > v;
int dsu[maxn];
int vert[maxn];
int ed[maxn];

void _union(int x, int y) {
    dsu[x] = y;
    ed[y] += ed[x];
    vert[y] += vert[x];
}

int _find(int x) {
    if (dsu[x] < 0) return x;
    return (dsu[x] = _find(dsu[x]));
}

i32 main() {
    //freopen("<file>.in", "r", stdin);
    //freopen("<file>.out", "w", stdout);

    IOS;

    int n, h, w; cin >> n >> h >> w;
    for (int i = 1; i <= n; i++) {
        int r, c, a; cin >> r >> c >> a;
        v.pb({a, {r, c + h}});
    }

    sort(v.begin(), v.end()); reverse(all(v));

    fill(dsu, dsu + maxn, -1); fill(vert, vert + maxn, 1);
    fill(ed, ed + maxn, 0);

    int ans = 0;

    for (auto z : v) {
        int w = z.F, x = z.S.F, y = z.S.S;
    
        //cout << w << " : " << x << " -- " << y << endl;

        int a = _find(x), b = _find(y);
        //cout << "? : " << a << " -- " << b << endl;
        if (a == b) {
            if (ed[a] < vert[a]) { ans += w; ed[a]++; }
        } else if (ed[a] + ed[b] + 1 <= vert[a] + vert[b]) {
            _union(a, b); ed[_find(a)]++; ans += w; 
        }
    }

    cout << ans << endl; 
}




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

int main(void)
{
	int N;
	cin >> N;
	int *A = new int[N];

	int cnt = 1;
	int flg = 0; // 0:無, 1:↑, 2:↓
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		if (i == 0) {
			continue;
		} else {
			if (flg == 0 && A[i - 1] < A[i]) {
				flg = 1;
			}
			else if (flg == 0 && A[i - 1] > A[i]) {
				flg = 2;
			}
			else if (flg == 1 && A[i - 1] < A[i]) {

			}
			else if (flg == 1 && A[i - 1] > A[i]) {
				flg = 0;
				++cnt;
			}
			else if (flg == 2 && A[i - 1] < A[i]) {
				flg = 0;
				++cnt;
			}
			else if (flg == 2 && A[i - 1] > A[i]) {
				
			}
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define re register
int gcd(re int a,re int b)
{
	if(!b)return a;
	return gcd(b,a%b);
}
void exgcd(re int a,re int b,re int&x,re int &y)
{
	if(!b){x=1;y=0;return;}
	exgcd(b,a%b,y,x);
	y-=a/b*x;
}
int a,b,c,d,x,y,x1,yk1,x2,y2,c1,d1,c2,d2,rd;
long long sol()
{
	re int l=0,r=(yk1-y2)/d2-1,xx,yy,xx1,yy1;
	for(re int mid=(l+r+1)/2;l<r;mid=(l+r+1)/2)
	{
		yy=yk1-mid*d2,xx=1ll*rd*yy%c;
		if(xx==0&&yy==0)xx=c;
		if(1ll*x*yy>=1ll*xx*y)l=mid;
		else r=mid-1;
	}
	yy=yk1-l*d2;xx=1ll*rd*yy%c;yy1=yy-d2;xx1=1ll*rd*yy1%c;
	if(xx==0&&yy==0)xx=c;if(xx1==0&&yy1==0)xx1=c;
	re long long xl1=xx-xx1,yl1=yy-yy1,xxl,yyl;
	l=0,r=1e9;
	for(re int mid=(l+r+1)/2;l<r;mid=(l+r+1)/2)
	{
		xxl=x+1ll*mid*xl1,yyl=y+1ll*mid*yl1;
		if((long double)xxl*yy>=(long double)xx*yyl)l=mid;
		else r=mid-1;
	}
	xxl=x+l*xl1,yyl=y+l*yl1;//printf("****%lld %lld %d %d %d %d %d\n",xxl,yyl,xx,yy,xx1,yy1,l);
	re long long ans=std::min(xx?xxl/xx:(1ll<<60),yy?yyl/yy:(1ll<<60));
	xxl+=xl1;yyl+=yl1;
	if(xxl>=0&&yyl>=0)ans=std::max(ans,std::min(xx?xxl/xx:(1ll<<60),yy?yyl/yy:(1ll<<60)));
	return ans;
}
int main()
{
	re int T;
	scanf("%d",&T);
	for(;T--;)
	{
		scanf("%d%d%d%d%d",&a,&x,&b,&y,&c);
		re int g=gcd(a,b);a/=g,b/=g,c/=gcd(c,g);
		g=gcd(a,c);a/=g;c/=g;y/=g;
		g=gcd(b,c);b/=g;c/=g;x/=g;
		exgcd(b,c,x1,yk1);
		if(c==1){printf("%d\n",x+y);continue;}
		d=1ll*a*(x1+c)%c;//printf("**%d %d %d\n",a,b,c);
		exgcd(d,c,x1,yk1);
		rd=(c-x1)%c;
		c1=c,d1=d;
		while(c1!=0)
		{
			x1=1ll*rd*c1%c;yk1=c1;
			c2=c1,d2=d1;
			if(d1)c1%=d1;
			else c1=0;
			if(c1)d1%=c1;
			else d1=0;
			if(d1==0)d1=c1;
			re int x2=1ll*rd*c1%c,y2=c1;
			if(x2==0&&y2==0)x2=c;
		//printf("****%d %d %d %d %d %d\n",x1,yk1,x2,y2,d,d2);
			if(1ll*x*yk1>=1ll*x1*y&&1ll*x2*y>=1ll*x*y2)
			{
				printf("%lld\n",sol());break;
			}
		}
	}
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define endl '\n'
    ll M = 1e9 + 7;
    ll fp(ll b, ll p)
    {
    	ll ans = 1;
    	while (p)
    	{
    		if (p & 1)
    			ans = ans * b % M;
    		p /= 2;
    		b = b * b % M;
    	}
    	return ans % M;
    }
    ll inv(ll x)
    {
    	return fp(x, M - 2);
    }
    void solve()
    {
    	ll n, k;
    	cin >> n >> k;
    	k = k % M;
    	std::vector<int> v(n);
    	for (auto &i : v)
    		cin >> i;
    	ll ans = 0;
    	for (int i = 0; i < n; i++)
    	{
    		ll l = 0, r = 0;
    		for (int j = 0; j < n; j++)
    		{
    			if (v[j] < v[i])
    			{
    				if (j < i)
    					l++;
    				else
    					r++;
    			}
     
    		}
    		l %= M;
    		r %= M;
    		ans += (l * k % M * (k - 1) % M * inv(2)) % M;
    		ans %= M;
    		ans += (r * k % M * (k + 1) % M * inv(2)) % M;
    		ans %= M;
    		// cout << v[i] << ' ' << l << r << endl;
     
    	}
    	cout << (ans % M);
     
     
    }
    int main()
    {
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
    	cout.tie(NULL);
     
     
     
    	int t;
    	// cin >> t;
    	t = 1;
    	while (t--) solve();
     
     
    	return 0;
    }

Measured memory_bytes: 256