akhauriyash/Code-Regression huggingface dataset:
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
signed main()
{
  std::vector<int> v;
  string xyz ="";
int x=0,y=0,z=0,w=0,i=0,j=0,n=0;
rep(i,999999){
  if(IsPrime(i))v.push_back(i);
}
while(std::cin >> x){
  rep(i,v.size()){
    if(v[i]<=x){
      y++;
    }
  }
std::cout << y << '\n';
y=0;
}
}



Measured memory_bytes: 3752
#include<bits/stdc++.h>
// use gp_hash_table<int,int,custom_hash> m;
// in place of map
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
// This custom_hash is for unordered_map 
// use map<int, int, custom_hash> mp;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.txt", "r", stdin);
 //    	freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	vi v(n);
	rep(i,n)cin>>v[i];
	int cur = 1;
	int ans = 0;
	rep(i,n){
		if(v[i]!=cur){
			ans++;
		}
		else{
			cur++;
		}
	}
	if(ans == n)ans = -1;	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back


int cnt, h, w, xy[110][110]={-1};
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
pair<int,int> p;
char c[110][110];
queue<pair<int,int> > q;
 
int bfs(int x,int y){
  // チェック済みかどうかの配列
	for(int i =0; i < h; i++){
		for(int j =0; j < w; j++){
			xy[i][j]=-1;
		}
	}
	q.push(pair<int,int>(x, y));
	xy[x][y]=0;
	while(q.size()){
		p=q.front(); //先頭の要素をqに入れる
		q.pop(); // 先頭の要素を取り出す
		for(int i = 0; i < 4; i ++){ // 1ノードで辿れるものを順番に見ていくことにより幅優先
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if(0 <= nx && nx <h  && 0 <= ny && ny < w && c[nx][ny] != '#' && xy[nx][ny]==-1){
				q.push(pair<int, int>(nx, ny));
				xy[nx][ny] = xy[p.first][p.second]+1;
			}
		}
	}
	return xy[p.first][p.second];
}

int main() {
  
  cin>>h>>w;
  int masu=0;
	for(int i =0; i<h; i++){
    for(int j =0; j<w; j++){
      cin>>c[i][j];
      if(c[i][j]=='.') masu++;
    }
  }
		
  bfs(0, 0);
      
  if(xy[h-1][w-1] == -1){
    print(-1);
  } else {
    print(masu - xy[h-1][w-1] - 1);
  }
	return 0;

}


Measured memory_bytes: 256
///                ..:: In The Name Of God ::..
#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define endl    '\n' 
#define INF 2e9
#define int ll
#define vi          vector<int>
#define vii         vector<pii>
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

typedef long long ll;

using namespace std;

signed main(){

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    string X;
    ll flag = 0;
    cin >> X ;
    for (int i = 0; i < 4; i++){
        if(X[i] != X[i+1]){
            flag += 0;
        }
        else if (X[i] == X[i+1]){
            flag += 1;
        }
    }

    if (flag == 0){
        cout << "Good" << endl;
    }
    else
        cout << "Bad" << endl;
}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

vector<char> v{'y','u','i','o','p','h','j','k','l','n','m'};

int main()
{
    string s;
    while(cin>>s, s!="#") {
        int f = -1;
        int cnt = 0;
        rep(i,s.size()) {
            auto it = find(ALL(v), s[i]);
            if(it==v.end()) {
                if(f==-1) f = 0;
                else if(f==1) {
                    f = 0;
                    cnt++;
                }
            }
            else {
                if(f==-1) f = 1;
                else if(f==0) {
                    f = 1;
                    cnt++;
                }
            }
        }
        P(cnt);
    }
    return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int MM=3013;
int dp[MM][MM];
char let[MM][MM];
void Wypisz(int i, int j)
{
    if(i==0||j==0)
        return;
    if(let[i][j]!='0')  Wypisz(i-1,j-1);
    else if(dp[i-1][j]>dp[i][j-1])
        Wypisz(i-1,j);
    else
        Wypisz(i,j-1);
    if(let[i][j]!='0')
        cout<<let[i][j];
}
int main()
{
    ios_base::sync_with_stdio(0);
    string A,B;
    cin>>A>>B;
    for(int i=0; i<A.size(); i++)
    {
        for(int j=0; j<B.size(); j++)
        {
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
            let[i+1][j+1]='0';
            if(A[i]==B[j])
            {
                if(dp[i+1][j+1]<dp[i][j]+1)
                {
                    dp[i+1][j+1]=dp[i][j]+1;
                    let[i+1][j+1]=A[i];
                }
            }
        }
    }
    Wypisz(A.size(),B.size());
    return 0;
}


Measured memory_bytes: 44672
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N, X, T;
    cin >> N >> X >> T;
    cout << (int)ceil((double)N / X) * T << endl;

    return 0;
}

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

from math import tan, degrees, pi

def main():
  a, b, x = map(int, input().strip().split())
  x /= a
  def bs(ltheta, rtheta):
    middle = (rtheta + ltheta) / 2
    if b - a * tan(middle) >= 0:
      v = a * (b - 0.5 * a * tan(middle))
    else:
      v = 0.5 * b * b / tan(middle)
      
    if abs(rtheta - ltheta) < 10**(-9) or v == x :
      return middle  
    if v > x:
      return bs(middle, rtheta)
    else:
      return bs(ltheta, middle)
  print(degrees(bs(0, pi/2)))

if __name__=='__main__':
  main()



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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
long long x ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>x ;
	long long cur = 100 ;
	long long cnt = 0 ;
	while(cur < x)
	{
		cnt++ ;
		cur += cur / 100ll ;
	}
	return cout<<cnt<<"\n" , 0 ;
}		

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second

const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

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

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

//約数の列挙O(√n)
vector<ll> divisor(ll n){
    vector<ll> res(0);
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


int main(){
  ll N;
  cin >> N;
  vector<ll> div = divisor(N);
  ll d = div.size();
  ll cnt[d];
  rep(i, d){
    cnt[i] = N / div[i];
  }
  revrep(i, d){
    rep(j, i){
      if(div[i] % div[j] == 0){
        cnt[j] -= cnt[i];
      }
    }
  }
  ll ans = 0;
  rep(i, d){
    if(i == 0) continue;
    ans += cnt[i];
  }
  cout << N - ans << endl;
}



Measured memory_bytes: 3144
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 5;
ll a[N];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    int ans = 0;
    int mini = INT_MAX;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(mini >= x)
            ans++;
        mini = min(mini, x);
    }
    cout << ans;
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(), n = sc.nextInt();
        boolean[] p = new boolean[102];
        for(int i=0;i<n;i++){
            p[sc.nextInt()] = true;
        }
        for(int i=0;i<100;i++){
            if(!p[x - i]){
                System.out.println(x-i);
                break;
            }else if(!p[x + i]){
                System.out.println(x+i);
                break;
            }
        }
    }
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < c&&c < b ) {
		cout << "Yes" << endl;
	}
	else if(b < c&&c < a) {
	cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}

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

int main(){
  int cnt[11];
  int a,b,c;
  
  std::cin>>a>>b>>c;
  for(int i=0;i<=10;i++){
      cnt[i] = 0;
  }
  cnt[a]++; cnt[b]++; cnt[c]++;

  if(cnt[5]==2 && cnt[7]==1){
      printf("YES");
  }else printf("NO");
  return 0;  
}

Measured memory_bytes: 256
stdin.ReadLine() |> ignore

let ary =
    stdin.ReadLine().Split() |> Array.map int

let q = stdin.ReadLine() |> int

let counts =
    let countAsTuples = ary |> Array.countBy (id)

    let cnt = Array.zeroCreate 100001

    for (key, num) in countAsTuples do
        cnt.[key] <- num

    cnt

let initSum =
    [| for i in 1 .. 100000 -> int64 i * int64 counts.[i] |]
    |> Array.sum

let rec replace i sum =
    if i <= 0 then
        ()
    else
        let b, c =
            stdin.ReadLine().Split()
            |> Array.map int
            |> fun ary -> ary.[0], ary.[1]

        let sum =
            sum + (int64 c - int64 b) * int64 counts.[b]

        counts.[c] <- counts.[b] + counts.[c]
        counts.[b] <- 0

        printfn "%d" sum

        replace (i - 1) sum

replace q initSum


Measured memory_bytes: 60052
#include <stdio.h>

int main(void)
{
    int n,a,b,c;
    scanf("%d %d %d",&n,&a,&b);
    c=n*a;
    if(c>b){
       printf("%d\n",b);
    }   
    else{
    printf("%d\n",c);
    }   
    return 0;
    }   




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

int main(){
	int n=0,m=0;
	scanf("%d",&n);
	int na[n];
	for (int temp=1;temp<=n;++temp){
		scanf("%d",&na[temp]);
	}
	scanf("%d",&m);
	for(int temp=0;temp<m;++temp){
		int temp1=0,temp2=0,sum=0;
		scanf("%d",&temp1);
		scanf("%d",&temp2);
		for (int t=1;t<=n;++t){
			if (t==temp1){
				sum=sum+temp2;
			}
			else{
			sum=sum+na[t];
			}
		}
		printf("%d\n",sum);
	}

}

Measured memory_bytes: 256
n=gets.to_i
v=gets.split.map &:to_i
k=Hash.new(0)
g=Hash.new(0)
(0...n).map{|i|i%2==1?k[v[i]]+=1:g[v[i]]+=1}
k=k.sort{|a,b|b[1]<=>a[1]}
g=g.sort{|a,b|b[1]<=>a[1]}
k<<[0,0]
g<<[0,0]
p n-((k[0][0]!=g[0][0])?k[0][1]+g[0][1]:[k[1][1]+g[0][1],k[0][1]+g[1][1]].max)

Measured memory_bytes: 20268
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	int maxValue = 0;
	int total = 0;
	for (int i = 0; i < N; i++) {
		int p;
		cin >> p;
		maxValue = max(maxValue, p);
		total += p;
	}

	cout << total - maxValue / 2 << endl;


	
}


Measured memory_bytes: 3592
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

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

	ll A=in(),B=in(),C=in(),K=in();
	ll S = min(A,K);
	K -= A;
	if(K<=0){
		out(S);
		return 0;
	}
	K -= B;
	if(K<=0){
		out(S);
		return 0;
	}
	S -= K;
	out(S);
	return 0;
}


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

int main() {
  int n,x,ans;
  while(true){
    cin >> n >> x;
    if(n==0&&x==0)break;
    ans=0;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        for(int k=j+1;k<=n;k++){
          if(i!=j&&i!=k&&j!=k && i+j+k==x)ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		if(a<=8 && b<=8) System.out.println("Yay!");
		else System.out.println(":(");

	}

}


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

using namespace std;

long long inf=1000000007;

int main(){
	int n;
	cin>>n;
	long long aoki=0;
	vector<long long> meal(n);

	for(int i=0;i<n;i++){
		long long a,b;
		cin>>a>>b;

		aoki-=b;

		meal.at(i)=a+b;
	}

	sort(meal.begin(),meal.end());
	reverse(meal.begin(),meal.end());

	for(int i=0;i<n;i+=2){
		aoki+=meal.at(i);
	}

	cout<<aoki<<endl;

	return 0;
}


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

int main() {
    ll n, k;
    cin >> n >> k;
    if (k == 1) {
        cout << 0 << endl;
        return 0;
    }
    vector<ll> s(n + 1);
    s[0] = 0;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        s[i + 1] = s[i] + a;
    }
    ll ans = 0;
    map<ll, ll> mp;
    for (int j = 1; j <= n; j++) {
        if (j - k >= 0 && mp[(s[j - k] - (j - k)) % k] > 0) mp[(s[j - k] - (j - k)) % k]--;
        mp[(s[j - 1] - (j - 1)) % k]++;
        ans += mp[(s[j] - j) % k];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14336
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= (int)b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
const int maxn = 200010;
int n, m, pos[maxn], remain[maxn], l[maxn];
struct Data {
    int num, l, r;
    Data() {}
    Data(int a, int b, int c) { num = a, l = b, r = c; }
    bool operator < (const Data & a) const {
        return r > a.r;
    }
} a[maxn];
bool flag[maxn];
priority_queue < Data > pq;
bool cmp(Data a, Data b) {
    return (a.l == b.l && a.r < b.r) || a.l < b.l;
}
int main()
{
    read(n), read(m);
    rep(i, 1, n) read(a[i].l), read(a[i].r);
    sort(a + 1, a + 1 + n, cmp);
    int cur = 1, ans = 0;
    flag[m + 1] = 1;
    rep(i, 1, n) a[i].num = i;
    rep(i, 1, n) {
        if(cur <= a[i].l && cur <= m) pos[i] = cur, flag[cur ++] = 1, pq.push(a[i]), ans ++;
        else if(!pq.empty()) {
            Data tmp = pq.top();
            if(tmp.r < a[i].r) {
                //cout << i << " takes place of " << tmp.num << endl;
                pq.pop();
                pq.push(a[i]);
                pos[i] = pos[tmp.num];
                pos[tmp.num] = 0;
            }
        }
    }
    int cnt = 0, cnt2 = 0;
    rep(i, 1, m)
        if(!flag[i]) remain[++ cnt] = m - i + 1;
    sort(remain + 1, remain + 1 + cnt);    
    //rep(i, 1, m) cout << remain[i] << " "; puts("");
    rep(i, 1, n) if(!pos[i]) {
        int x = m - a[i].r + 1;
        l[++ cnt2] = upper_bound(remain + 1, remain + 1 + cnt, x) - remain - 1;
    }
    //rep(i, 1, n) cout << l[i] << " "; puts("");
    sort(l + 1, l + 1 + cnt2);
    memset(flag, 0, sizeof(flag));
    flag[cnt + 1] = 1;
    cur = 1;
    rep(i, 1, cnt2)
        if(cur <= l[i] && cur <= cnt) cur ++, ans ++;
    printf("%d\n", n - ans);
    return 0;
}

Measured memory_bytes: 9588
N = int(input())

def make_divisors(n: int):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

ans = 0
for i in range(1, N+1, 2):
    if len(make_divisors(i)) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 62276
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll ,int>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5+5;
const ll mod=998244353;
int a,b,c,d,e;
string s;
int main(){
    ios::sync_with_stdio(false);
    cin>>s;
    a=s.size();
    for(int i=0;i<a;i++){
        if(s[i]=='?')s[i]='D';
    }
    cout<<s;
    return 0;
}


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

using namespace std;

const int MX = 100;

vector<int> G[MX];
int mx[MX];

int dfs(int v, int p = -1, int d = 0) {
	int cnt = 0, dep = 1;
	for (int u : G[v]) {
		if (u == p) continue;
		
		dep = max(dfs(u, v, d + 1) + 1, dep);
		cnt++;
	}
	
	mx[d] = max(mx[d], cnt);
	
	return dep;
}

int dfs2(int u, int v) {
	return max(dfs(u, v), dfs(v, u));
}

int main() {
	int n;
	ignore = scanf("%d", &n);
	
	if (n == 2) {
		printf("1 2\n");
		return 0;
	}
	
	for (int i = 1, u, v; i < n; i++) {
		ignore = scanf("%d %d", &u, &v);
		u--; v--;
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	
	auto ans = make_pair(n + 1, 1LL << 60);
	for (int v = 0; v < n; v++) {
		fill(mx, mx + n, 0);
		int dep = dfs(v);
		
		long long leaves = 1;
		for (int i = 0; i < dep - 1; i++) leaves *= mx[i];
		
		ans = min(make_pair(dep, leaves), ans);
	
		for (int u : G[v]) {
			fill(mx, mx + n, 0);
			int dep = dfs2(u, v);
			
			long long leaves = 2;
			for (int i = 0; i < dep - 1; i++) leaves *= mx[i];
			
			ans = min(make_pair(dep, leaves), ans);
		}
	}
	
	printf("%d %lld\n", ans.first, ans.second);
	
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(input().split())
MAP = list(sorted([int(X[i]) for i in range(M)]))

if M <= N:
    print(0)
else:
    MAP_diff = list(sorted([MAP[i+1] - MAP[i] for i in range(M-1)]))
    print(sum(MAP_diff[:M-N]))

Measured memory_bytes: 15584
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<ll,ll>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
////////////////////////////////

// c++17での名前衝突を避けるためdefine
#define gcd nyagcd
#define lcm nyalcm
ll nyagcd(ll x, ll y){
  ll z;
  if(x > y) swap(x,y);
  while(x){
    x = y % (z = x); y = z;
  }    
  return y;
}
ll nyalcm(ll x,ll y){
  return 1LL * x / gcd(x,y) * y;
}

void solve(){
  /*
  inl(N , M);
  vl a(N); in(a);
  ll nya = 1;
  rep(i , N){
    nya = lcm(nya , a[i] / 2);
    if(nya > M) die(0);
  }
  rep(i , N){
    if(nya % a[i] == 0) die(0);
  }
  if(nya == M) die(1);
  M -= nya;
  nya *= 2;
  out(M / nya + 1);
  */
  inl(K , X);
  out((K * 500 >= X) ? "Yes" :"No");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (200000)
#define MOD (1000000007)

char s[MAXN+1];
int main(void)
{

    scanf("%s", s);
    int len = strlen(s);
    int ans = 0;
    int state = 1;// 0: 2個ブロック前半 1: 2個ブロック後半 2: 1個ブロック
    for(int i=0;i<len;i++)
    {
        switch(state)
        {
            case 0:
                state = 1;
                ans++;
                break;

            case 1:
                ans++;
                state = 2;
                break;

            case 2:
                if(s[i-1]==s[i])
                {
                    state = 0;
                }else
                {
                    state = 2;
                    ans++;
                }
                break;
        }
    }

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







Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut ab: Vec<(i64, i64, i64)> = Vec::new();
    let mut sum = 0;

    for _ in 0..n {
        let a: i64 = read();
        let b: i64 = read();
        ab.push((a + b, a, b));
        sum += a;
    }

    ab.sort_by(|a, b| b.0.partial_cmp(&a.0).unwrap());

    //println!("{:?}",ab);
    for i in 0..n {
        if i % 2 == 1 {
            sum -= ab[i].0;
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 5260
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		ll x=0;
		REP(i, N)x^=A[i];
		cout<<YN(x==0)<<endl;
	}
	
	return 0;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int a, b, c;
    cin >> a >> b >> c;
    if (c - a - b < 0) {
        dump("No");
    } else {
        dump(((Int)4 * a * b < (c - a - b) * (c - a - b)) ? "Yes" : "No");
    }
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

char in[2002][2002];
int sum[2002][2002];
int main() {
	int H,W;
	scanf("%d%d",&H,&W);
	for(int i=0;i<H;i++){
		scanf("%s",in[i]);
	}
	int ret=max(W,H);

	for(int i=1;i<H;i++){
		for(int j=1;j<W;j++){
			int c=0;
			for(int p=i-1;p<=i;p++){
				for(int q=j-1;q<=j;q++){
					if(in[p][q]=='#'){
						c++;
					}
				}
			}
			if(c%2==0){
				sum[i][j]++;
			}
			//cerr << sum[i][j] << endl;
		}
	}
	for(int i=1;i<H;i++){
		stack<P> st;
		st.push(P(0,0));
		for(int j=1;j<=W;j++){
			if(sum[i][j]){
				sum[i][j]+=sum[i-1][j];
			}
			int k=j;
			while(st.top().second>sum[i][j]){
				k=st.top().first;
				ret=max(ret,(j-st.top().first+1)*(st.top().second+1));
				st.pop();
			}
			if(st.top().second<sum[i][j]){
				st.push(P(k,sum[i][j]));
			}
		}
	}
	printf("%d\n",ret);


	return 0;
}



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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int A, B, C, X, Y, price = 0;
	
	cin >> A >> B >> C >> X >> Y;
	
	if(2 * C <= A + B){
		while(X > 0 && Y > 0){
			X -= 1;
			Y -= 1;
			price += C * 2;
		}
		if(2 * C <= A && X > 0){
			price += X * 2 * C;
			cout << price;
			return 0;
		}else if(2 * C <= B && Y > 0){
			price += Y * 2 * C;
			cout << price;
			return 0;
		}
		if(X == 0){
			price += Y * B;
			cout << price;
			return 0;
		}
		if(Y == 0){
			price += X * A;
			cout << price;
			return 0;
		}
	}else{
		cout << A * X + B * Y;
		return 0;
	}
}//not yet

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

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

int main(void){
    ll A, B;
    cin>>A>>B;
    ll g;
    g=gcd(A, B);
    cout<<A*B/g<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
x = 0
y = 0
t = 0
for i in range(n):
 t_new, x_new, y_new = map(int, input().split())
 l = abs(x_new - x) + abs(y_new - y)
 dt = t_new - t
 if (l <= dt) and (l % 2 == dt % 2 ):
  x = x_new
  y = y_new
  t = t_new
 else:
  #print(t, x, y) 
  print('No')
  exit()
print('Yes')


Measured memory_bytes: 3060
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

V< V<int> > calc(string &s) {
    int n = s.size();
    V< V<int> > ret(n + 1, V<int>(26, n));
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) ret[i][j] = ret[i + 1][j];
        ret[i][s[i] - 'a'] = i;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    V< V<int> > nextidx = calc(s);
    // dp[i]: i 文字目を使わずに構築できる最小文字数
    V<int> dp(n + 1, INF);
    V<char> recon(n + 1, 'a');
    dp[n] = 1;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            // 次の文字がない時
            if (nextidx[i][j] == n) {
                if (dp[i] != 1) {
                    dp[i] = 1;
                    recon[i] = 'a' + j;
                }
            } else {  // i 以降でまた同じ文字が出てくる時
                if (chmin(dp[i], dp[nextidx[i][j] + 1] + 1)) recon[i] = 'a' + j;
            }
        }
    }
    
    // 復元
    string ans = "";
    int idx = 0;
    while (idx <= n) {
        ans.push_back(recon[idx]);
        idx = nextidx[idx][recon[idx] - 'a'] + 1;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 31064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(abs(a-b)<=k && abs(a-c)<=k && abs(a-d)<=k && abs(a-e)<=k && abs(b-c)<=k && abs(b-d)<=k && abs(b-e)<=k && abs(c-d)<=k && abs(c-e)<=k && abs(d-e)<=k){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 500;
const int mod = 1e8 + 7;
const double pi = acos(-1);
const int inf = 1e9;
const double eps = 1e-7;
int n,k;
ll a[N],cha[N];
ll sum;
int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//    ios::sync_with_stdio(false);
//    cin.tie(NULL);
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%lld", a + i), sum += a[i];
    if (sum % ((ll)n * (n + 1) / 2))
    {
        puts("NO");
        return 0;
    }
    sum /= ((ll)n * (n + 1) / 2);
    for (int i = 1; i < n; ++i)
        cha[i] = a[i + 1] - a[i];
    cha[n] = a[1] - a[n];
    int f = 1;
    for (int i = 1; i <= n; ++i)
        if (cha[i] > sum || (cha[i] - sum) % n)
            f = 0;
    if (f)
        puts("YES");
    else
        puts("NO");
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int a[4];
string ans;

void dfs(string s, int n, int sum) {
  if (n == 4) {
    if (sum == 7) {
      ans = s + "=7";
      return;
    }
  } else if (n < 4) {
    dfs(s + "+" + to_string(a[n]), n + 1, sum + a[n]);
    dfs(s + "-" + to_string(a[n]), n + 1, sum - a[n]);
  }

  return;
}

int main() {
  // 入力
  string s;
  cin >> s;

  for (int i = 0; i < 4; i++) a[i] = s[i] - '0';

  // 深さ優先探索
  dfs(to_string(a[0]), 1, a[0]);

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N, K = mis()
    A = [a-1 for a in mis()]
    B = [None]*N
    now = 0
    B[now] = 0
    for i in range(1, K+1):
        now = A[now]
        K -= 1
        if B[now] is not None:
            K %= (i - B[now])
            break
        B[now] = i
    for _ in range(K):
        now = A[now]
    print(now+1)

main()



Measured memory_bytes: 34016
using System;
using System.IO;
namespace aoj{
    class program{
     
    static void Main() {
		dice d = new dice(Console.ReadLine());
		string direction = Console.ReadLine();
		foreach(char dir in direction)
			d.Rotate(dir);
		d.ShowTop();
	    
    }
}
class dice{
	string top;
	string bottom;
	string north;
	string east;
	string south;
	string west;
	public dice(string rl){
		string[] tmp = rl.Split(' ');
		top=tmp[0];
		south=tmp[1];
		east=tmp[2];
		west=tmp[3];
		north=tmp[4];
		bottom=tmp[5];
	}
	void swap(ref string s1, ref string s2){

	}
	void RotateNorth(){
		string tmp=north;
		north=top;
		top=south;
		south=bottom;
		bottom=tmp;
	}
	void RotateSouth(){
		string tmp=south;
		south=top;
		top=north;
		north=bottom;
		bottom=tmp;
	}
	void RotateEast(){
		string tmp=east;
		east=top;
		top=west;
		west=bottom;
		bottom=tmp;
	}
	void RotateWest(){
		string tmp=west;
		west=top;
		top=east;
		east=bottom;
		bottom=tmp;
	}
	
	public void Rotate(char dir){
		switch(dir){
			case 'N':
				RotateNorth();
				break;
			case 'W':
				RotateWest();
				break;
			case 'S':
				RotateSouth();
				break;
			case 'E':
				RotateEast();
				break;
		}
	}
	public void ShowTop(){
		Console.WriteLine(top);
	}
}
		
}

Measured memory_bytes: 5264
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

	int d;
	vector<bool> vec(N);
	for (int i = 0; i < N; i++) {
		vec.at(i) = false;
	}
	for (int i = 0; i < K; i++) {
		cin >> d;
		vector<int> A(d);
		for (int ii = 0; ii < d; ii++) {
			cin >> A.at(ii);
			vec.at(A.at(ii) - 1) = true;
		}
	}

	int count = 0;
	for (int i = 0; i < N; i++) {
		if (!vec.at(i)) {
			count++;
		}
	}

	cout << count << endl;

	return 0;
}

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

int main() {
  int n,m,count=0;
  cin >> n >> m;
  count=(n-1)*n/2+(m-1)*m/2;
  cout<<count<<endl;
}

Measured memory_bytes: 256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
//#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"


/** stolen from tourist, Problem D, https://codeforces.com/contest/1208/standings/page/1 */
template <typename T>
struct fenwick {
    vector<T> fenw;
    int n;

    fenwick(int _n) : n(_n) {
        fenw.resize(n);
    }

    /* update add */
    void update(int x, T v) {
        while (x < n) {
            fenw[x] += v;
            x |= (x + 1);
        }
    }

    /* get sum of range (0,x), including x */
    T query(int x) {
        T v{};
        while (x >= 0) {
            v += fenw[x];
            x = (x & (x + 1)) - 1;
        }
        return v;
    }
};

void solve() {
    cini(n);
    cini(q);
    
    fenwick<ll> fen(n);
    for(int i=0; i<n; i++) {
        cini(a);
        fen.update(i,a);
    }

    for(int i=0; i<q; i++) {
        cini(t);
        if(t==0) {
            ll p,x;
            cin>>p>>x;
            fen.update(p,x);
        } else {
            ll l,r;
            cin>>l>>r;
            cout<<fen.query(r-1)-fen.query(l-1)<<endl;
        }
    }
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


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

int main(){
  int n,d; cin >> n >> d;
  vector<vector<int>> x(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> x[i][j];
    }
   }int ans =0;
        
    for(int i=0;i<n-1;i++){
      for(int m=i+1; m<n;m++){
      int a=0;
      for(int j=0;j<d;j++){
        int k = abs(x[i][j]-x[m][j]);
        a += k*k;
      }
        double b = sqrt(a);
        if(floor(b) == b){
          ans++;
        }
    }
}
  cout << ans << endl;
}   

Measured memory_bytes: 256
n, m, l = map(int, input().split())
a = []
b = []
c = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    a.append(list(map(int, input().split())))

for j in range(m):
    b.append(list(map(int, input().split())))

for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j] += a[i][k] * b[k][j]

for i in range(n):
    print(" ".join(map(str, c[i])))



Measured memory_bytes: 6888
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>

using namespace std;

typedef long long ll;

bool enough(vector<ll> h, ll a, ll b, ll t){
  ll dif = a - b;
  ll need = 0;
  for(ll i = 0;i < h.size(); i++){
    ll tmp = max(ll(0), h[i] - b * t);
    need += (ll)(tmp + dif - 1) / dif;
  }
  if(t >= need){
    return true;
  }else{
    return false;
  }
}

int solve() {
  ll n, a, b;
  cin >> n >> a >> b;
  vector<ll> h(n);
  ll mx = 0;
  for(ll i = 0;i < n;i++){
    cin >> h[i];
    mx = max(mx, h[i]);
  }

  ll mn = 0;
  ll mid = -1;
  while(1) {
    if(mx - mn == 1){
      break;
    }
    mid = mn + (mx - mn) / 2;
    if(enough(h, a, b, mid)){
      mx = mid;
    } else {
      mn = mid;
    }
  }
  cout << mx << endl;

  return 0;
}

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


Measured memory_bytes: 1792