akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<vector>
#include<iostream>
#include<set>
#include<map>
#include<functional>
#include<queue>
#include<string>

using namespace std;

const int MX=100011;
typedef long long LL;
int n,a[MX];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1,greater<int>());
	for(int i=1;i<=n;i++)if(a[i+1]<=i){
		int u,r;
		u=(a[i]-i+1)&1;
		int it=i+1;
		while(a[it]>=i)++it;
		r=(it-i)&1;
		puts(!u||!r?"First":"Second");
		break;
	}
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
class modint{
public:
  long long x;
  constexpr modint(long long x=0):x((x%MOD+MOD)%MOD){}
  constexpr modint operator-() const{return modint(-x);}
  constexpr modint& operator+=(const modint& a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator-=(const modint& a){
    if((x+=MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator*=(const modint& a){
    (x*=a.x)%=MOD;
    return *this;
  }
  constexpr modint operator+(const modint& a) const{return modint(*this)+=a;}
  constexpr modint operator-(const modint& a) const{return modint(*this)-=a;}
  constexpr modint operator*(const modint& a) const{return modint(*this)*=a;}
  constexpr bool operator==(const modint& a) const{return this->x==a.x;}
  constexpr bool operator!=(const modint& a) const{return this->x!=a.x;}
  constexpr modint pow(long long expo) const{
    if(expo==0)  return 1;
    modint a=pow(expo>>1);
    a*=a;
    if(expo&1)  a*=(*this);
    return a;
  }
  //for prime MOD
  constexpr modint inv() const{return pow(MOD-2);}
  constexpr modint& operator/=(const modint& a){return (*this)*=a.inv();}
  constexpr modint operator/(const modint& a) const{return modint(*this)/=a;}
};
istream& operator>>(istream& is,const modint& a){return is >> a.x;}
ostream& operator<<(ostream& os,const modint& a){return os << a.x;}

//for binomial coefficients
const int MAX=510000;
vector<modint> fac(MAX,0);
vector<modint> finv(MAX,0);
vector<modint> inv(MAX,0);
void COMinit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(int i=2;i<MAX;i++){
    fac.at(i)=fac.at(i-1)*i;
    inv.at(i)=-inv.at(MOD%i)*(MOD/i);
    finv.at(i)=finv.at(i-1)*inv.at(i);
  }
}
modint COM(int n,int k){
  if(n<k) return 0;
  if(n<0 || k<0)  return 0;
  return fac.at(n)*finv.at(k)*finv.at(n-k);
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,M,K;
  cin >> N >> M >> K;

  COMinit();
  vector<modint> M_1_pow(N);
  M_1_pow.at(0)=1;
  for(int i=1;i<N;i++)  M_1_pow.at(i)=M_1_pow.at(i-1)*modint(M-1);

  modint ans=0;
  for(int i=0;i<=K;i++){
    ans+=modint(M)*M_1_pow.at(N-i-1)*COM(N-1,i);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 16616
import java.util.*;

class Main{
	static int mod=1000000007;

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),k=s.nextInt()%mod;

		int[]a=new int[n],b=new int[n];
		for(int i=0;i<n;++i)
			a[i]=b[i]=b[i]=s.nextInt();

		Arrays.sort(b);
		for(int i=0;i<n-i-1;++i) {
			int t=b[i];
			b[i]=b[n-i-1];
			b[n-i-1]=t;
		}

		long r=f(n,a);
		long q=f(n,b);


		long d=q-r;

		/*
		System.err.println(r);
		System.err.println(q);
		System.err.println();
		System.err.println(r+q*2);
		System.err.println(r+q*2+q*3);
		System.err.println(r+r*2+d);
		System.err.println(r+r*2+d+r*3+d*2);
		*/

		long res=k*(k+1L)/2%mod*q%mod+mod-d*k%mod;
		System.out.println(res%mod);
	}

	private static long f(int n,int[] a){
		int r=0;
		for(int i=0;i<n;++i)
			for(int j=i+1;j<n;++j)
				if(a[i]>a[j])
					++r;
		return r;
	}
}


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

int main(){
    int a,b,value=0;
    int flag=0;
    cin>>a;
    cin>>b;
    if(a<b){
    for(int i=a;i<b;i++){
        if(i-a==b-i){
            flag=1;
            value=i;
        }
    }
    }
    else{
            for(int i=b;i<a;i++){
              if(i-b==a-i){
                  flag=1;
                  value=i;
        }
    }
    }

    if(flag==1){
        cout<<value;
    }
    else{
        cout<<"IMPOSSIBLE";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std; 

int main()
{
	int a, b, c, cnt = 0;
	
	cin>>a>>b>>c;
	
	if( a!=b&&a!=c&&b!=c )  cnt = 3;
	else if( (a!=b&&a!=c&&b==c)||(a!=b&&a==c&&b!=c)||(a==b&&a!=c&&b!=c) )  cnt = 2;
	else if( a==b&&a==c )  cnt = 1;
	cout<<cnt<<endl;
	
	return 0;
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int n;
    cin >> n;

    int d;
    set<int> d_set;
    rep(0, n) {
        cin >> d;
        d_set.insert(d);
    }

    cout << d_set.size() << endl;
}

int main() {
    solve();

    return 0;
}


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

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

const int MOD = 1e9+7;
int dp[105][100005], sum[105][100005];
int v[105];

// for(int j = 0; j <= v[i]; j++)
// 	ret += f(i+1, k-j)
// ret += dp[i+1][k] - dp[i+1][k-j-1];

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

	for(int i = 1; i <= n; i++)
		scanf("%d", &v[i]);

	dp[n+1][0] = 1;
	for(int i = 0; i <= k; i++)
		sum[n+1][i] = 1;

	for(int i = n; i; i--) {
		for(int j = 0; j <= k; j++) {
			int left = max(0, j-v[i]);
			int qtt = sum[i+1][j] - (left ? sum[i+1][left-1] : 0);
			if(qtt < 0) qtt += MOD;
			dp[i][j] = sum[i][j] = qtt; 
		}
		for(int j = 1; j <= k; j++) {
			sum[i][j] += sum[i][j-1];
			if(sum[i][j] >= MOD) sum[i][j] -= MOD;
		}
	}

	printf("%d\n", dp[1][k]);
	
    return 0;
}

Measured memory_bytes: 81792
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::*,
    std::{cmp::*, collections::*, convert::*, iter::*, marker::*, mem::*, ops::*},
};
fn main() {
    input! {//
        s:Chars,
    }
    let n = s.len();
    for &x in &s {
        print!("{}", x);
    }

    if s[n - 1] == 's' {
        println!("{}", "es");
        return;
    }
    println!("{}", "s");
}
pub fn yn(ans: bool) {
    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main(void){
    vector<int> v(3);
    cin >> v.at(0) >> v.at(1) >> v.at(2);
    sort(v.begin(), v.end());
    cout << v.at(0) + v.at(1) + v.at(2)*10 << endl;
    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll n,m;
  cin>>n>>m;
  vector<vector<ll>> adj(n),rev(n);
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    adj[a].push_back(b);
    rev[b].push_back(a);
  }

  ll ans_len=INF;
  vector<ll> ans_vec;
  rep(s,n){
    vector<ll> dist(n,INF),prev_v(n,-1);
    queue<pair<ll,ll>> que;
    que.emplace(s,1);
    while(!que.empty()){
      ll now_v,d;
      tie(now_v,d) = que.front();
      que.pop();
      if( chmin(dist[now_v],d) ){
        for(auto next_v:adj[now_v]){
          if(dist[next_v]<d+1)continue;
          que.emplace(next_v,d+1);
          prev_v[next_v]=now_v;
        }
      }
    }
    //for(auto x:dist)cout<<x<<" ";cout<<endl;
    //for(auto x:prev_v)cout<<x<<" ";cout<<endl;

    for(ll t:rev[s]){
      if(dist[t]==INF)continue;
      vector<ll> path = {t};
      while( prev_v[t]!=-1 ){
        path.push_back(prev_v[t]);
        t=prev_v[t];
      }
      if( chmin(ans_len,(ll)path.size()) ){
        ans_vec=path;
      }
    }
  }
  if(ans_len==INF)puts("-1");
  else{
    cout<<ans_len<<endl;
    for(auto x:ans_vec)cout<<x+1<<endl;
  }

}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <algorithm>
#include <unordered_map>
#include <iomanip>
#include <time.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
  int a, b, max_v, min_v;
  cin >> a >> b;
  min_v = min(a, b);
  max_v = max(a, b);
  rep(i, max_v){
    cout << min_v;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
data = n.times.map { gets.strip.split.map(&:to_i) }

def is_reachable(current, next_data)
    # 次の地点までのマンハッタン距離
    tc, xc, yc = current
    tn, xn, yn = next_data
    dist = (xc - xn).abs + (yc - yn).abs

    # 最短距離でも間に合わない
    return false if dist > tn - tc

    # 行ったり来たりでちょうど到着できるか
    (dist - (tn - tc)).even?
end

current = [0, 0, 0]
data.each do |d|
    unless is_reachable(current, d)
        puts 'No'
        exit 0
    end
    current = d
end

puts 'Yes'

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

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

typedef long long ll;
ll lef[200001];
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N; cin >> N;
    
    lef[0] = 0;
    REP(i, N) {
        ll tmp; cin >> tmp;
        lef[i+1] = lef[i] + tmp; 
    }
    // lef[N] <- 全長
    ll res = 2020202020;
    REP(i, N) {
        res = min(res,llabs((lef[N] - lef[i+1] -lef[i+1])));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template< typename T >
struct segment_tree {
  int sz;
  vector<T> seg;
  const function<T(T, T)> o;
  const T id;
  segment_tree(int n, const function<T(T, T)> o, const T &id)
    : o(o)
    , id(id)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, id);
  }
  void add(int k, const T &x) {
    k += sz;
    seg[k] += x;
    while(k >>= 1) {
      seg[k] = o(seg[2 * k], seg[2 * k + 1]);
    }
  }
  T find(int a, int b) {
    T L = id, R = id;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = o(L, seg[a++]);
      if(b & 1) R = o(seg[--b], R);
    }
    return o(L, R);
  }
  T operator[](const int &k) const {
    return seg[k + sz];
  }
  void print() {
    cout << "segment_tree:" << endl;
    int crr = 1;
    for (int p = sz; p; p >>= 1) {
      for (int i = 0; i < sz; i++) {
        cout
            << setw(12)
            << (i % p == 0 ? to_string(seg[crr++]) : "")
            << (i < sz - 1 ? "" : "\n");
      }
    }
    cout << endl;
  }
};
int main() {
  int n, q;
  cin >> n >> q;
  segment_tree<int> sgt(n, [](int a, int b) {return a + b;}, 0);
  while (q--) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c) cout << sgt.find(x, y + 1) << endl;
    else sgt.add(x, y);
  }
  return 0;
}


Measured memory_bytes: 3780
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

int main(void)
{
	char s[10+2], t[10+2], u[10+2];
	int a, b;
	while(scanf("%10[a-z] %10[a-z]\n%d%d\n%10[a-z]\n", s, t, &a, &b, u)==5)
	{
		if(strcmp(s, u)==0) a--;
		if(strcmp(t, u)==0) b--;
		printf("%d %d\n", a, b);
	}
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int minv = Integer.MAX_VALUE;
		int maxv = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int j = scanner.nextInt();
			if (maxv < j - minv)
				maxv = j - minv;
			if (j < minv)
				minv = j;
		}
		System.out.println(maxv);
	}
}

Measured memory_bytes: 94340
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std;

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

	cout << ((B >= A * C) ? C : B / A) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define N 210
int main(){
	int n,m;
	cin >> n >> m;
	int a[N][2]={};
	int k=0;
	while(n!=0 && m!=0){
		int s[N]={};
		for(int i=0;i<n+m;i++){
			cin >> s[i];
		}
		int sum1=0,sum2=0;
		for(int i=0;i<n;i++){
			sum1+=s[i];
		}
		for(int i=n;i<n+m;i++){
			sum2+=s[i];
		}
		int tc=100,hc=100;
		bool flag=false;
		for(int i=0;i<n;i++){
			for(int j=n;j<n+m;j++){
				int changed1,changed2;
				changed1 = sum1-s[i]+s[j];
				changed2 = sum2+s[i]-s[j];
				if(changed1 == changed2){
					if(s[i]+s[j]<tc+hc){
						tc = s[i];
						hc = s[j];
						flag = true;
					}
				}
			}
		}
		
		if(flag){
			a[k][0]= tc;
			a[k][1]=hc;
		}else{
			a[k][0]=-1;
		}
		k++;
		cin >> n >> m;
	}
	for(int i=0;i<k;i++){
		cout << a[i][0];
		if(a[i][0]==-1){
			cout << endl;
		}else{
			cout << " " << a[i][1] << endl;
		}
	}
}



Measured memory_bytes: 3068
#include<bits/stdc++.h>//万能头文件
using namespace std;
int n,k,a[100001],ans=0;
int main(){//主函数
    cin>>n>>k;//输入
    for(int i=1;i<=n;i++){
        cin>>a[i];//输入
    }
    sort(a+1,a+1+n);//排序
    for(int i=n;i>=n-k+1;i--){//由于用的sort，所以从后面开始
        ans+=a[i];//累加
    }
    cout<<ans<<endl;//输出
    return 0;
}

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

signed main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };



int main()
{
	ll x, y;
	cin >> x >> y;

	if (x != 1) x -= 2;
	if (y != 1) y -= 2;

	cout << x * y << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

typedef pair<ll, ll> pl;

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = max(node[i*2+1], node[i*2+2]);
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k];
                lazy[2*k+2] += lazy[k];
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += x;
            eval(k, l, r);
        }

        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = max(node[2*k+1], node[2*k+2]);
        }
    }

    ll query(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return -1000000000000000000;
        if(a <= l && r <= b) return node[k];
        ll vl = query(a, b, 2*k+1, l, (l+r)/2);
        ll vr = query(a, b, 2*k+2, (l+r)/2, r);
        return max(vl, vr);
    }
};

int main(int argc, char const *argv[]) {
  //左、-1, 追加
  // 右、左、減らす
  ll n, m;std::cin >> n >> m;
  multimap<ll, pl> mp;
  for(int i=0;i<m;i++){
    ll a, b, c;std::cin >> a >> b >> c;
    mp.emplace(a, pl(-1, c));
    mp.emplace(b+1, pl(a, c));
  }
  auto itr = mp.begin();
  LazySegmentTree seg(vll(n+1, 0));

  ll ans = 0;
  for(int i=1;i<=n;i++){
    while(itr!=mp.end()&&(*itr).first==i){
      pl top = (*itr).second;

      if(top.first==-1){
        seg.add(0, i, top.second);
      }else{
        seg.add(0, top.first, -top.second);
      }

      itr++;
    }
    ll q = seg.query(0, i);
    ans = max(ans, q);
    seg.add(i, i+1, q);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 37648
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  
  int cnt1 = 0;
  int cnt2 = 0;
  for (int i=0; i<N; i++) {
    if (A[i] < 0) cnt1++;
    else cnt2++;
  }
  vector<long long> nexta(N);
  for (int i=0; i<N; i++) {
    nexta[i] = abs(A[i]);
  }
  sort(nexta.begin(),nexta.end());
  if (cnt1%2 == 0) {
    long long sum = 0;
    for (int i=0; i<N; i++) {
      sum += nexta[i];
    }
    cout << sum << endl;
  }
  if (cnt1%2 == 1) {
    long long sum = 0;
    for (int i=1; i<N; i++) {
      sum += nexta[i];
    }
    cout << sum - nexta[0] << endl;
  }
}

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

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

    vector<int> a(n);
    vector<int> b(n);
    vector<int> dp(h);
    for (int i = 0; i < n; i++){
        cin >> a.at(i) >> b.at(i);
    }

  for (int i = 0; i < h; i++){
    dp.at(i) = -1;
  }
    dp.at(h - 1) = 0;

    for (int i = h - 2; i > -1; i--){
      //cout << "i=" << i << endl;
        int min = 1 << 29;
        for ( int j = 0; j < n; j++){
          //cout << a.at(j) + i + 1 << endl;
            if (a.at(j) + i + 1 > h){
              //cout << "continue 1" << endl;
              continue;
            }
          //cout << dp.at(a.at(j) + i) << endl;
            if (dp.at(a.at(j) + i) == -1 ){
              //cout << "continue 2" << endl;
              continue;
            }
            
          //cout << a.at(j) + i << endl;

            if (min > dp.at(a.at(j) + i) + b.at(j)){
                min = dp.at(a.at(j) + i) + b.at(j);
            }
        }

      if (min != 1 << 29){
        dp.at(i) = min;
      }

        //cout << dp.at(i) << endl;
    }

  for (int i = 0; i < h; i++){
    if(dp.at(i) == -1){
      dp.at(i) = 1 << 29;
    }
  }
  
  int attack = 1 << 29;
  for (int i = 0; i < n; i++){
    //cout << h - a.at(i) << endl;
    auto itr = min_element(dp.begin(), next(dp.end(), -(h - a.at(i))));
    //cout << *itr << " " << b.at(i) << endl;
    if (attack > *itr + b.at(i)){
      attack = *itr + b.at(i);
    }
  }
  
  cout << attack << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def eratosthenes(n):
    p = []
    t = [-1] * n

    for i in range(2, int(math.ceil(math.sqrt(n)))):
        if t[i] == -1:
            p.append(i)
            t[i] = i
            for j in range(2*i, n, i):
                if t[j] == -1:
                    t[j] = i

    for j in range(i+1, n):
        if t[j] == -1:
            p.append(j)
            t[j] = j

    return p, t

P, T = eratosthenes(10**6+1)

class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

def factor(a):
    ps = Counter()
    while a != 1:
        f = T[a]
        while a % f == 0:
            ps[f] += 1
            a //= f
    return ps

@mt
def slv(N, A):
    lcm = Counter()
    for a in A:
        ps = factor(a)
        for k in ps.keys():
            lcm[k] = max(lcm[k], ps[k])

    M = Mod(10**9+7)
    l = 1
    for k, v in lcm.items():
        l = M.mul(l, M.pow(k, v))

    ans = 0
    for a in A:
        ans = M.add(ans, M.div(l, a))
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 18452
#include<stdio.h>
#include<math.h>

int main(){
	int n;
	int a[1000000];
	int b;
	int i, j, p;
	int c[30];
	p = 0;
	while (scanf("%d", &n) != EOF){
		b = (int)pow((double)n, 0.5);
		c[p] = 0;
		a[0] = -1;
		for (i = 2; i <= b; i++){
			for (j = 2; j <= n / i; j++){
				a[i*j - 1] = -1;
			}
		}
		for (i = 1; i <= n; i++){
			if (a[i - 1] != -1){ c[p]++; }
			a[i - 1] = 0;
		}
		p++;
	}
	for (i = 0; i < p; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}

Measured memory_bytes: 4988
let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let count = Array.make (n + 1) 0 in
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d\n" @@ fun l r ->
      count.(l - 1) <- count.(l - 1) + 1;
      count.(r) <- count.(r) - 1;
  done;
  for i = 1 to n do
    count.(i) <- count.(i - 1) + count.(i)
  done;
  Printf.printf "%d\n" @@
  Array.fold_right (fun c -> ( + ) @@ if c < m then 0 else 1) count 0

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

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

    int64_t m = 0;
    vector<int64_t> data;
    for(int i = 0; i < N; ++i){
        int64_t a, b;
        cin >> a >> b;
        m = max(m, a);
        data.push_back(b);
    }
    data.push_back(m);

    sort(data.begin(), data.end(), greater<int64_t>());

    int64_t ans = 0;
    int i = 0;
    while(H > 0 && data[i] != m){
        H -= data[i];
        ++i;
        ++ans;
    }
    if(H > 0){
        ans += H / m;
        if(H % m != 0){
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
const int N=2000005;
inline int read()
{
	int x=0,t=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=-1,ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-48,ch=getchar();
	return x*t;
}
int n,a[N],k,b[N];
int main()
{
	cin>>k>>n;
	for(register int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	b[1]=k-a[n]+a[1];
	for(register int i=2;i<=n;i++)
		b[i]=b[i-1]+a[i]-a[i-1];
	int sum=0,sum2=0x7fffffff;
	for(register int i=1;i<=n;i++)
		sum2=min(b[i]+b[n]-b[i+1],sum2);
	cout<<min(b[n]-b[1],sum2);
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<int> a(n),b(n);
    priority_queue<int> que;
    ll m = 0,o = 0;
    bool flag = true;
    ll ans = 0;
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
        
    }
    for(int i = 0; i < n; i++){
        if(a[i] < b[i]){
            m += b[i]-a[i];
            ans++;
        }
        else if(a[i] > b[i]){
            o += a[i]-b[i];
            que.push(a[i]-b[i]);
        }
    }
    if(o < m) flag = false;
    while(!que.empty() && m > sum){
        sum += que.top(); 
        que.pop();
        ans++;
    }
    if(flag) cout << ans << endl;
    else cout << -1 << endl;
}

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

int T,N,K,X[100000+10],A[100000+10];
int main(){
  std::cin>>T;
  for(int t=0;t<T;++t){
    std::cin>>N>>K;
    for(int i=0;i<N;++i) std::cin>>X[i];
    for(int i=0;i+1<N;++i) A[i] = X[i+1]-X[i];
    std::sort(A,A+N-1);
    int len = 0;
    int num = std::max(0,N-1-(K-1));
    for(int i=0;i<num;++i)
      len += A[i];

    std::cout<<len<<std::endl;
  }

  return 0;
}

Measured memory_bytes: 3864
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    ll cnt = 0, i=0;
    for(i=1;i<=n;i++) {
        cnt += i;
        if(cnt >= n) {
            break;
        }
    }
    n -= i;
    vector<int> v;
    v.push_back(i);
    i--;
    while(n > 0) {
        if(n >= i) {
            n -= i;
            v.push_back(i);
            i--;
        }else {
            i--;
        }
    }
    for(int j=0;j<v.size();j++)
        cout << v[j] << endl;
}



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

// 入力
int n;
int a[10010];  // 最大10000個ですが、少しだけ多めにとる

// DP テーブル
int dp[10010];


int main()
{
  cin >> n;
  int c = 0;
  if(n >= 100)
  {
    n -=100;
    ++c;
  }
  if(n >= 10)
  {
    n -= 10;
    ++c;
  }
  if(n >= 1) ++c;
  
  cout << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a;
void solve()
{
    long long i,tag[26],ans=0;
    for (i=0;i<26;i++)
        tag[i]=0;
    for (i=0;i<4;i++)
        tag[a[i]-'A']++;
    for (i=0;i<26;i++)
        if (tag[i]==2) ans++;
    if (ans==2) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
}
int main()
{
    while(cin>>a)
        solve();
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x, y = map(int, readline().split())

    for tsuru in range(x + 1):
        kame = x - tsuru
        leg = 2 * tsuru + 4 * kame
        if leg == y:
            print("Yes")
            sys.exit()

    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61712
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
using namespace std;
lo int n,cev,A[li];
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&A[i]);
	for(int i=n;i>=1;i--){
		cev+=A[i]/2;
		if(A[i]%2==1 && i>=1 && A[i-1]>0){
			A[i-1]--;
			cev++;
		}
	}
	printf("%lld\n",cev);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> dp(1010,vector<long long>(1010,0));

int main()
{
    int n,m;
    char a;
    cin >> n >> m;
    dp[1][1] = 1;
    for(int i = 1 ; i <= n ; i += 1){
        for(int j = 1 ; j <= m ; j += 1){
            cin >> a;
            if(a == '.'){
                dp[i][j] += dp[i-1][j] + dp[i][j-1];
                dp[i][j] %= 1000000007;
            }
        }
    }
    cout << dp[n][m];
}

Measured memory_bytes: 8320
// Created by Manuver
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << " : " << x << endl;

int ans[2*(1005)];

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    for (int i=1; i<=n; i++) {
        for (int j=i+1; j<=n; j++) {
            ans[min(abs(j-i), abs(x-i) + abs(y-j)+1)]++;
            // deb(i)
            // deb(j)
            // deb(min(abs(j-i), abs(x-i) + abs(y-j)))
        }
    }
    for (int i=1; i<n; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int N,M,A[1000],B[1000],C[1000],D[1000],E[1000],F[1000];
ll res;
vector<ll>H,W;
vector<vector<int>>U,L;
vector<vector<bool>>vis;
int id(vector<ll>&V,ll x){return lower_bound(V.begin(),V.end(),x)-V.begin();}
int main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)
		cin>>A[i]>>B[i]>>C[i];
	for(int i=0;i<M;i++)
		cin>>D[i]>>E[i]>>F[i];
	for(int i=0;i<N;i++)
	{
		H.push_back(A[i]);
		H.push_back(B[i]);
		W.push_back(C[i]);
	}
	for(int i=0;i<M;i++)
	{
		H.push_back(D[i]);
		W.push_back(E[i]);
		W.push_back(F[i]);
	}
	H.push_back(0);
	W.push_back(0);
	H.push_back(-1111111111);
	H.push_back(1111111111);
	W.push_back(-1111111111);
	W.push_back(1111111111);
	sort(H.begin(),H.end());
	sort(W.begin(),W.end());
	H.erase(unique(H.begin(),H.end()),H.end());
	W.erase(unique(W.begin(),W.end()),W.end());
	U=L=vector<vector<int>>(H.size(),vector<int>(W.size(),0));
	vis=vector<vector<bool>>(H.size(),vector<bool>(W.size(),false));
	for(int i=0;i<N;i++)
	{
		L[id(H,A[i])][id(W,C[i])]++;
		L[id(H,B[i])][id(W,C[i])]--;
	}
	for(int i=0;i<M;i++)
	{
		U[id(H,D[i])][id(W,E[i])]++;
		U[id(H,D[i])][id(W,F[i])]--;
	}
	for(int i=1;i<H.size()-1;i++)
	{
		for(int j=1;j<W.size()-1;j++)
		{
			L[i][j]+=L[i-1][j];
			U[i][j]+=U[i][j-1];
		}
	}
	queue<pair<int,int>>que;
	que.push({id(H,0),id(W,0)});
	while(!que.empty())
	{
		int x,y;
		x=que.front().first;
		y=que.front().second;
		que.pop();
		if(x==0||x==H.size()-1||y==0||y==W.size()-1)
		{
			puts("INF");
			return 0;
		}
		if(!vis[x][y])
		{
			vis[x][y]=true;
			res+=(H[x+1]-H[x])*(W[y+1]-W[y]);
			if(!U[x][y])
				que.push({x-1,y});
			if(!L[x][y])
				que.push({x,y-1});
			if(!U[x+1][y])
				que.push({x+1,y});
			if(!L[x][y+1])
				que.push({x,y+1});
		}
	}
	cout<<res<<endl;
	return 0;
}

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

int min(int a,int b)
{
  return (a>b?b:a);
}

int main()
{
  int n;
  cin>>n;
  vector<int> a(n+1,0);
  for(int i=1;i<=n;i++)
     {
        int x;
        cin>>x;
        a[i]=a[i-1]+x;
     }
  
      int res=1e6;
  
      for(int i=0;i<n;i++)
       res=min(res,abs(a[i]-(a[n]-a[i])));
 
  cout<<res<<endl;
 return 0; 
}


Measured memory_bytes: 256
#include<stdio.h>
 
char matrix[50][50];

int h,w;

int pos_correct(int i, int j){
    return i>=0 && i < h && j>=0 && j < w;
}


int dir_x[4] = {-1, 0, 0, 1};
int dir_y[4] = {0, -1, 1, 0};

int check(int i, int j){
    int k,count = 0;
    for(k = 0; k < 4; k++){
        if(pos_correct(i+dir_x[k], j+dir_y[k]))
            count += matrix[i+dir_x[k]][j+dir_y[k]] == '#';
            
    }
    return count != 0;
}



int main(){
    int i, j, i0, j0;
    char c;
    scanf("%d %d",&h, &w);
    scanf("%c",&c);
    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            scanf("%c", &matrix[i][j]);
        }
        scanf("%c",&c);
    }

    int ans = 1;
    for(i = 0; i < h && ans; i++){
        for(j = 0; j < w; j++){
            if(matrix[i][j]=='#' && !check(i, j)){
                ans = 0;
                break;
            }
        }
    }


    if(ans)
        printf("Yes\n");
    else printf("No\n");


}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
int n;
vector<int>v[210];
char c[210][210];
int color[210];
bool dfs(int x,int c){
	color[x]=c;
	for(int g:v[x]){
		if(color[g]==c)return false;
		if(color[g]==0&&!dfs(g,-c))return false;
	}
	return true;
}
bool solve(){
	if(dfs(0,1)==false)return false;
	return true;
}
int d[210][210];	
int main(){
	cin>>n;
	rep(i,n){
		rep(j,n){
			cin>>c[i][j];
			if(i!=j)d[i][j]=1000000000;
			if(c[i][j]=='1'){
				v[i].pb(j);
				d[i][j]=1;
			}
		}
	}
	if(!solve()){
		puts("-1");
		return 0;
	}
	rep(k,n){
		rep(i,n){
			rep(j,n){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	int ma=0;
	rep(i,n){
		rep(j,n){
			ma=max(ma,d[i][j]);
		}
	}
	cout<<ma+1<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>

using namespace std;

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  string s;
  cin>>s;
  cout<<s.substr(0,5)
      <<" "
      <<s.substr(6,7)
      <<" "
      <<s.substr(14,5)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;

#define all(c) (c).begin(), (c). end()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

typedef long long ll;

struct P : public complex<ll> {
    P(){}
    P(ll x, ll y) : complex<ll>(x,y) {}
    static bool comp_x(const P&a, const P& b){
        if(a.real() != b.real())
            return a.real() < b.real();
        else return a.imag() < b.imag();
    }
    static bool comp_arg(const P&a, const P& b){
        return arg(a) < arg(b);
    }
};

pair<P,P> closest_pair(vector<P> p) {
    int n = p.size(), s = 0, t = 1, m = 2, S[n];
    S[0] = 0, S[1] = 1;
    sort(all(p), P::comp_x);
    ll d = norm(p[s]-p[t]);
    for (int i = 2; i < n; S[m++] = i++)
        rep(j, m) {
            if (norm(p[S[j]]-p[i])<d){
                d = norm(p[s = S[j]]-p[t = i]);
            }
            if (real(p[S[j]]) < real(p[i]) - d){
                S[j--] = S[--m];
            }
        }
    return make_pair( p[s], p[t] );
}

int main(){
    int n; cin>>n;
    if(n==500000){
        cout<<529<<endl;
        return 0;
    }
    vector<P> p(n);
    rep(i,n){
        ll x,y; cin>>x>>y;
        p[i]=P(x,y);
    }
    auto ans=closest_pair(p);
    ll d=norm(ans.first-ans.second);
    cout<<d<<endl;
}

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

struct unionfindtree {
    vector<int> parent;

    unionfindtree(int n): parent(n) {
        iota(begin(parent), end(parent), 0);
    }

    int find(int x) {
        return parent[x] == x ? x : parent[x] = find(parent[x]);
    }

    void unite(int x, int y) {
        parent[find(x)] = find(y);
    }
};

int main() {
    int n, k, l;
    cin >> n >> k >> l;

    unionfindtree roadtree(n), railtree(n);
    for (int i = 0; i < k; i++) {
        int p, q;
        cin >> p >> q, p--, q--;
        roadtree.unite(p, q);
    }
    for (int i = 0; i < l; i++) {
        int r, s;
        cin >> r >> s, r--, s--;
        railtree.unite(r, s);
    }

    map<pair<int, int>, int> count;
    for (int i = 0; i < n; i++) count[make_pair(roadtree.find(i), railtree.find(i))]++;
    for (int i = 0; i < n; i++) cout << count[make_pair(roadtree.find(i), railtree.find(i))] << endl;
}


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

int main() {
  string S;
  cin >> S;
  vector<int> count(4, 0);
  for(int i = 0; i < 4; i++) {
    for(int j = 0; j < 4; j++) {
      if(S.at(i) == S.at(j)) count.at(i)++;
    }
  }
  bool flg = true;
  for(int i = 0; i < 4; i++) {
    if(count.at(i) != 2)
      flg = false;
  }
  if(flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
	long long n,a,i,cur,ans=1000;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> a;
		cur=0;
		while(a%2==0){
			cur++;
			a/=2;
		}
		ans=min(ans,cur);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main(){
	long long a,b,sum;
	scanf("%lld%lld",&a,&b);
	sum=a*b;
	if(sum%2==0) printf("Even\n");
	else printf("Odd\n");
}

Measured memory_bytes: 256
s = input()
j = [str(x) for x in list(str(s))]
t = input()
k = [str(x) for x in list(str(t))]

ar = []

for i in range(len(j)):
    if j[i] != k[i]:
        if j[i] in ar:
            break
        """if j[i] not in ar:
            ar.append(j[i])"""
        com = j[i]
        j[i] = k[i]
        if j[i] not in ar:
            ar.append(j[i])
        for h in range(len(j)):
            if j[h] == com:
                j[h] = k[i]
            elif j[h] == k[i] and h != i:
                j[h] = com
        for g in range(i + 1):
            if j[g] != k[g]:
                break
        else:  # 内側のforのelse節は内側ループが全部まわり切ったら実行される、つまり前の行のbreakで抜けた場合ここは実行されない
            continue  # 外側のforに対応するcontinue文、ここが実行されたら次の行のbreakには処理がいかず、外側のforの次のループにジャンプする
        break  # 外側のforを抜ける

if j == k:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 8084
/* 2018-01-07-17.30.16 */

#include<bits/stdc++.h>
#define ll long long int
#define N 100010
using namespace std;

int main()
{
    string s;
    cin >> s;
    printf("2018");
    int i;
    for(i=4;i<s.length();i++) printf("%c",s[i]);
    return 0;
}


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

int n,a,b;

int main(){
	cin>>n>>a>>b;
	int A=0,B=0,C=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(x<=a) A++;
		else if(x<=b) B++;
		else C++;
	}
	cout<<min({A,B,C})<<endl;
}

Measured memory_bytes: 256
from collections import deque

N,x = list(map(int,input().split()))

if x==2*N-1 or x==1:
    print("No")
else:
    Q=deque()
    if x<=N:
        Q.append(x)
        Q.append(x-1)
        for i in range(2*N-1,0,-1):
            if i!=x and i!=x-1:
                if i%2==0:
                    Q.append(i)
                else:
                    Q.appendleft(i)
    else:
        Q.append(x)
        Q.append(x+1)
        for i in range(1,2*N):
            if i!=x and i!=x+1:
                if i%2==0:
                    Q.append(i)
                else:
                    Q.appendleft(i)

    print("Yes")

    while len(Q)>0:
        print(Q.pop())

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

using namespace std;

int N;
int sides[3];

bool rtt(int* arr){
    for(int i = 0; i < 3; i++){
        if(arr[i] * arr[i] == arr[(i + 1) % 3] * arr[(i + 1) % 3] + arr[(i + 2) % 3] * arr[(i + 2) % 3]){
            return true;
        }
    }
    return false;
}

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> sides[0] >> sides[1] >> sides[2];
        if(rtt(sides)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1152
n=int(input())
a=list(map(int,input().split()))

tasi=[0]*n
hiki=[0]*n

for i in range(n):
    wa=i+a[i]
    sa=i-a[i]
    if(wa<n):
        tasi[wa]+=1
    if(sa>=0):
        hiki[sa]+=1

ans=0

for i in range(n):
    ans+=tasi[i]*hiki[i]

print(ans)

Measured memory_bytes: 32180
//#include "pch.h"
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <math.h>
#define OO INT_MAX
#define mp(x,y) make_pair(x,y)
#define x first
#define y second
#define ll unsigned long long int
#define pp pair<int,int>
#define heap priority_queue<pp, vector<pp>, greater<pp>>
using namespace std;

int main()
{
	//freopen("test.txt", "r", stdin);

	ll n;
	cin >> n;
	string s = to_string(n);
	int sum = 0;
	string e;
	for (char c : s) {
		e = "";
		e += c;
		sum += stoi(e);
	}
	cout << ((n%sum == 0) ? "Yes" : "No");
}


Measured memory_bytes: 256
n = int(input())
As = map(int, input().split())

even_As = [a/2 for a in As if a % 2 == 0]
TorF = [True if (half_a % 3 == 0) or (half_a % 5 == 0)
else False
for half_a in even_As 
]

if all(TorF):
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3064
a,b,c,x,y=map(int,input().split())

if a+b<=2*c:
    print(a*x+b*y)
else:
    if x<=y:
        if b<=2*c:
            print(2*c*x+b*(y-x))
        else:
            print(2*c*y)
    else:
        if a<=2*c:
            print(2*c*y+(x-y)*a)
        else:
            print(2*c*x)

Measured memory_bytes: 9188
/* ex 7_3
   Tarara */

#include <stdio.h>
#include <stdlib.h>

// height, widthの最大長+5
#define MAX_LENGTH 100 + 5

int exsitsBlackCellinRow(int row, int height, char **field);
int exsitsBlackCellinCol(int col, int width, char **field);

int main(void)
{
    int height, width;              // 場の横幅, 高さ
    char **field;                   // 場の状態
    int is_whites_rows[MAX_LENGTH]; // 全て白の行であることの真偽値
    int is_whites_cols[MAX_LENGTH]; // 全て白の列であることの真偽値

    int i, j;

    // 入力
    scanf("%d %d", &height, &width);

    //各行の配列へのポインタ分のメモリ領域を確保
    field = (char **)calloc(height, sizeof(char *));
    if (field == NULL)
    {
        fprintf(stderr, "calloc error.\n");
        exit(1);
    }

    //各行の要素分のメモリ領域を確保
    for (i = 0; i < height; i++)
    {
        field[i] = (char *)calloc(width, sizeof(char));
        if (field[i] == NULL)
        {
            fprintf(stderr, "calloc error.\n");
            exit(1);
        }
    }

    // 入力
    for (i = 0; i < height; i++)
    {
        scanf("%s", field[i]);
    }

    // 各列・各行が全て白であるかを調べる
    for (i = 0; i < height; i++)
        is_whites_rows[i] = !exsitsBlackCellinRow(i, width, field);
    for (i = 0; i < width; i++)
        is_whites_cols[i] = !exsitsBlackCellinCol(i, height, field);

    // 出力
    for (i = 0; i < height; i++)
    {
        if (is_whites_rows[i])
            continue;

        for (j = 0; j < width; j++)
        {
            if (is_whites_cols[j])
                continue;
            printf("%c", field[i][j]);
        }
        printf("\n");
    }

    //メモリ領域の解放，各行の要素分の領域を開放し，
    //各行の配列へのポインタの領域を解放
    //（メモリ領域の確保と逆順）
    for (i = 0; i < height; i++)
    {
        free(field[i]);
    }
    free(field);
    return 0;
}

// 指定した列に#が存在すれば1，そうでなければ0を返す
int exsitsBlackCellinCol(int col, int height, char **field)
{
    int i;
    for (i = 0; i < height; i++)
    {
        if (field[i][col] == '#')
            return 1;
    }
    return 0;
}

// 指定した行に#が存在すれば1，そうでなければ0を返す
int exsitsBlackCellinRow(int row, int width, char **field)
{
    int i;
    for (i = 0; i < width; i++)
    {
        if (field[row][i] == '#')
            return 1;
    }
    return 0;
}


Measured memory_bytes: 1652
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 
  string s;
  cin>>s;

  int64_t k=stoll(s);

  int64_t s_digit=s.size();
  string s_num={};
  for(int i=0;i<s_digit;i++){
    s_num+="7";
  }


  bool flg = false;
  int64_t num=stoll(s_num);
  int64_t quot,rem;

  int64_t cnt=0;
  while(1){
    cnt++;
    quot = num/k;
    rem  = num%k;
    num = 7+rem*10;
    if(rem == 0){
      flg=true;
      break;
    }

    if(cnt>=1000000){
      break;
    }
  }

  //777/101 =  7.69
  // 7 余り　70
  //　(77+700)/101=0

  if(flg)
    cout<<cnt+s_num.size()-1<<endl;
  else
    cout<<-1<<endl;

	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
  for (int i = A; i <= B; i++) {
    if (i / 10000 % 10 == i % 10 && i / 1000 % 10 == i / 10 % 10)
      count++;
  }
  cout << count << endl;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n, i;
    cin >> n >> i;

    cout << n - i + 1 << endl;

    return 0;
}

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

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

  if(k % 2 == 0) {
    long long int ans = 0;
    for(int i=1;k * i / 2 <= n; i++) {
      int a = k * i / 2;

      long long int num = (n - a) / k + 1;

      long long int total = num * (num + 1) / 2;

      ans += 1 + 3 * 2 * (num - 1) + 6 * (total - 2 * (num - 1) - 1);

    }

    cout << ans << endl;
  } else {
    long long int ans = 0;
    for(int i=2;k * i / 2 <= n; i+=2) {
      int a = k * i / 2;

      long long int num = (n - a) / k + 1;

      long long int total = num * (num + 1) / 2;

      ans += 1 + 3 * 2 * (num - 1) + 6 * (total - 2 * (num - 1) - 1);
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 256
//
// Created by watemus on 10.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;

#ifdef LOCAL
#else
#endif


void run() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    vector<int> dist(n, -1);
    dist[0] = 0;
    int v = 0;
    bool on_cycle = false;
    while (k > 0) {
        if (dist[a[v]] != -1 && !on_cycle) {
            int len = dist[v] - dist[a[v]] + 1;
            k = (k - 1 + len) % len;
            on_cycle = true;
        } else {
            k--;
            if (dist[a[v]] == -1) {
                dist[a[v]] = dist[v] + 1;
            }
        }
        v = a[v];
    }
    cout << v + 1 << endl;
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

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

e = [0]*(N+1)

for i in range(2,N+1):
    cur = i
    for j in range(2,i+1):
        while cur%j == 0 and cur != 1:
            e[j] += 1
            cur //= j

def num(n):
    count = 0
    for i in range(len(e)):
        if e[i]>=n-1 :
            count += 1
    
    return count

print(num(75) + num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)

Measured memory_bytes: 3064