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

using namespace std;

int main(){
    const int MOD = 1e9+7;
    int n;
    cin >> n;
    vector<int> line;
    for(int i = 0; i<n;i++){
        int person;
        cin >> person;
        line.push_back(person);
    }
    bool check = true;
    sort(line.begin(),line.end());
    for(int i=0;i<line.size();i+=2){
        if(line.size()%2==1){
            if(i==0){
                if(line[i]!=0){check = false;}
            }
            else{
                if(line[i]!=line[i-1]){
                    check = false;
                }
            }
        }
        else{
            if(line[i]!=line[i+1]){
                check = false;
            }
        }
    }
    if(check == false){
        cout << 0;
    }
    else{
        long long ans = 1;
        n/=2;
        while (n--)
      ans = (ans * 2) % MOD;
  	cout << ans;
    }
}

Measured memory_bytes: 892
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

string dlStr(string s,char de){
  string result = "";
  for(int i = 0; i < s.size(); i++) {
    if(s[i] != de) result.pb(de);
  }
  return result;
}

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN(s);
  if(s <= "2019/04/30") OUT("Heisei");
  else OUT("TBD");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X,cost,count;
  cin >> N >> X;
  count = N;
  cost = X;
  vector<int> vec(N); 
  for(int i = 0; i < N; i++){
  	cin >> vec.at(i);
    cost = cost - vec.at(i);
  }
  
  int min = *std::min_element(vec.begin(),vec.end());
  while (cost >= 0){
  	cost = cost - min;
    N++;
  }
  N--;
  cout << N << endl;
}

Measured memory_bytes: 256
N = int(input())
lst = []
  
  
for i in range(N):
  lst.append(int(input()))
  
M = lst[1] - lst[0]
m = lst[0]
  
for j in range(1, N):
    M = max([M, lst[j] - m])
    m = min([m, lst[j]])
              
print(M)


Measured memory_bytes: 13588
N, M = map(int, input().split())
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB = sorted(AB, key=lambda x: x[0])

cnt = 0
ans = 0
for a, b in AB:
    if cnt + b >= M:
        ans += a * (M - cnt)
        break
    else:
        cnt += b
        ans += a * b
print(ans)


Measured memory_bytes: 18948
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }
 
int main() {
  //std::cout << std::fixed << std::setprecision(10);
  ull n;
  cin >> n;

  cout << pow(n, 3) << endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

vector<vector<Int>> graph;
map<Int, Int> point;
vector<Int> ans;
vector<bool> seen;

void dfs(Int v,Int p) {
	seen[v] = true;

	Int res = p;
	if (point[v])res += point[v];

	ans[v] += res;
	for (auto next_v : graph[v]) {
		if (seen[next_v])continue;
		dfs(next_v, res);
	}

}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, Q;
	cin >> N >> Q;

	graph.resize(N);
	Int a, b;
	for (Int i = 0; i < N-1; i++) {
		cin >> a >> b;
		graph[a - 1].push_back(b - 1);//0-indexed
		graph[b - 1].push_back(a - 1);
	}

	Int p, x;
	for (Int i = 0; i < Q; i++) {
		cin >> p >> x;
		point[p - 1] += x;//0-indexed
	}

	ans.resize(N,0);
	seen.resize(N,false);
	dfs(0,0);

	for (Int i = 0; i < N; i++) {
		printf("%lld ", ans[i]);
	}

}

Measured memory_bytes: 46208
from collections import deque
import sys

n, q = map(int, input().split())
Edges = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    Edges[a].append(b)
    Edges[b].append(a)

Q = [0]*n
for _ in range(q):
    p, x = map(int, input().split())
    Q[p-1] += x

Ans = [0]*n
q = deque([0])
Ans[0] = Q[0]
Visited = [False]*n
Visited[0] = True
while q:
    fr = q.pop()
    for to in Edges[fr]:
        if Visited[to]:
            continue
        Ans[to] = Ans[fr]+Q[to]
        Visited[to] = True
        q.append(to)

print(*Ans)


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

ll sum(ll a, ll b){
    return ((a+b)*(b - a + 1)/2)%mod;
}
int main(){
    ll n,k;
    cin >> n >> k;

    ll ans = 0;

    for(ll i = k;i <= n+1; i++){
        ll min = (i*(i-1)/2)%mod;
        ll max = (i*(2*n+1-i)/2)%mod;
        ans += (max-min+1)%mod;
        ans = ans%mod;

    }
    if(ans==0){
        ans++;
    }
    if(ans < 0){
        ans += mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3600
x, n = map(int, input().split())
num_list = list(map(int, input().split()))
dif = 100000
o_list = []

if len(num_list) == 0:
    print(x)
    exit()
#
# for i in range(1, max(num_list)):
#     if i not in num_list:
#         o_list.append(i)

for i in range(-1000, 1000):
    if i not in num_list:
        o_list.append(i)

o_list.sort(reverse=True)

for num in o_list:
    if abs(x - num) <= dif:
        # if x not in num_list:
        dif = abs(x -num)
        ans = num

print(ans)


Measured memory_bytes: 9216
#include<iostream>
using namespace std;
int main()
{
int h,w;
while(1)
{
cin>>h>>w;
if(h==0&&w==0)break;
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
if(i==0||i==h-1||j==0||j==w-1)cout<<"#";
else cout<<".";
}
cout<<endl;
}
cout<<endl;
}
return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <map>
#include <cassert>
using namespace std;

map<char,int> match;
bool ok = false;

pair<int,pair<char,bool> > literal(string &s,int p) {
    if(s[p] == '~') {
        return make_pair(p+2,make_pair(s[p+1],false));
    }
    return make_pair(p+1,make_pair(s[p],true));;
}

int clause(string &s,int p) {
    pair<int, pair<char,bool> > pp1 = literal(s,p);
    assert(s[pp1.first] == '&');
    pair<int, pair<char,bool> > pp2 = literal(s,pp1.first+1);
    assert(s[pp2.first] == '&');
    pair<int, pair<char,bool> > pp3 = literal(s,pp2.first+1);

    if(pp1.second.first == pp2.second.first && pp1.second.second != pp2.second.second) return pp3.first;
    if(pp1.second.first == pp3.second.first && pp1.second.second != pp3.second.second) return pp3.first;
    if(pp2.second.first == pp3.second.first && pp2.second.second != pp3.second.second) return pp3.first;

    ok = true;
    return pp3.first;
}

int parse(string &s,int p) {
    if(s[p] == '(') {
        int pp = clause(s,p+1);
        if(s[pp] == ')') {
            if(pp+1 < s.length() && s[pp+1] == '|') {
                parse(s,pp+2);
            }
        }
    }
}

int main() {
    string exp;
    while(cin>>exp) {
        if(exp == "#") break;

        for(int i=0; i<26; ++i) {
            match['A'+i] = 0;
            match['a'+i] = 0;
        }

        ok = false;
        parse(exp,0);
        if(ok) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}

Measured memory_bytes: 0
N = int(input())
a = list(map(int, input().split()))

b0, b1, b2 = 0,0,0

for i in a:
    if i % 2 != 0:
        b0 += 1
    else:
        if i % 4 != 0:
            b1 += 1
        else:
            b2 += 1

if b1 != 0:
    b0 +=1
    
if b2 + 1 >= b0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14228
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n;cin>>n;){
		string s; cin>>s;
		int res=0;
		rep(i,n){
			string t; cin>>t;
			for(int j=1;j*(s.size()-1)<t.size();j++){
				for(int k=0;k+j*(s.size()-1)<t.size();k++){
					bool ok=true;
					rep(l,s.size())
						ok&=t[k+l*j]==s[l];
					if(ok){
						res++;
						goto end;
					}
				}
			}
			end:;
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  if (X >= 30)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
int main(){
	int m,f,r;
	for(;;){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1&&f==-1&&r==-1){break;}
			if(m==-1||f==-1){printf("F");}
			else if(80<=m+f){printf("A");}
			else if(65<=m+f&&m+f<80){printf("B");}
			else if(50<=m+f&&m+f<65){printf("C");}
		else if(30<=m+f&&m+f<50){
				if(50<=r){printf("C");
				}else{printf("D");}
			}else{printf("F");}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
while True:
    m, f, r = map(int, input().split())
    if m == f == r == -1: break
    if m == -1 or f == -1:
        print("F")
    elif 80 <= (m + f):
        print("A")
    elif 65 <= (m + f) < 80:
        print("B")
    elif 50 <= (m + f) < 65:
        print("C")
    elif 30 <= (m + f) < 50:
        if 50 <= r:
            print("C")
        else:
            print("D")
    elif (m + f) < 30:
        print("F")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
 
using namespace std;
 
 
int main()
{
  
         string s,t;
         cin>>s>>t;
         t.erase(t.end()-1);
         if(s==t)
            cout<<"Yes";
            
         else
           cout<<"No";
   
    return 0;    
        
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

string s;
int a, b, c, d, x;

int main()
{
	cin >> s;

	int ans = 700;

	for (int i = 0;i < 3;i++) {
		if (s[i] == 'o') {
			ans+=100;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int solve(int k);

int main(){

int n; cin >> n;
printf("%d\n",solve(n));



	return 0;
}

int solve(int k){
	unsigned long long temp = 0;
	for(int i=1;i<1e7;i++){
		temp = temp*10 + 7;
		temp = temp % k;
		if(temp == 0)return i;
	}
	
	return -1;
}

Measured memory_bytes: 3744
#include<stdio.h>

int main(void) {

	int W, H, x, y, z;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &z);

	if (0 <= x-z && x + z<= W ) {
		if (0 <= y-z && y+ z <= H ) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
	else {
		printf("No\n");
	}




	return 0;
}


Measured memory_bytes: 2112
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, K, C;
  std::string S;
  std::cin >> N >> K >> C >> S;

  std::vector<i64> from_left;
  from_left.reserve(K);
  for (i64 i = 0; i < N;) {
    if (S[i] == 'o') {
      if (static_cast<i64>(from_left.size()) >= K) return 0;
      from_left.push_back(i);
      i += C + 1;
    } else {
      ++i;
    }
  }

  std::vector<i64> from_right;
  from_right.reserve(K);
  for (i64 i = N - 1; i >= 0;) {
    if (S[i] == 'o') {
      from_right.push_back(i);
      i -= C + 1;
    } else {
      --i;
    }
  }
  std::reverse(from_right.begin(), from_right.end());

  for (i64 i = 0; i < K; ++i) {
    if (from_left[i] == from_right[i]) {
      std::cout << from_left[i] + 1 << std::endl;
    }
  }
  return 0;
}

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

int N;
int A[210];

int main(){
	cin >> N;
  	for (int i = 0; i < N; ++i) cin >> A[i];
  
  	int res = 0;
  
  	while (true){
    	bool exist_odd = false;
      	for (int i = 0; i < N; ++i){
        	if (A[i] % 2 != 0) exist_odd = true;
        }
      	if (exist_odd) break;
      
      	for (int i = 0; i < N; ++i){
        	A[i] /= 2;
        }
      	++res;
    }
  	
  	cout << res <<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n, m, days;
    cin >> n >> m;
    days = 0;
    for (int i = 0; i < m; i++){
        int c;
        cin >> c;
        days += c;
    }
    if (n-days >= 0){
        cout << n-days << "\n";
    }
    else {
        cout << -1 << "\n";
    }
}

Measured memory_bytes: 3568
//  .:::.   .:::.
// :::::::.:::::::
// :::::::::::::::
// ':::::::::::::'
//   ':::::::::'
//     ':::::'
//       ':'
#include <bits/stdc++.h>
#define rep(i,a,b) for (i=a;i<b;i++)
#define rep2(i,a,b) for (i=a;i>=b;i--)
#define mod 1000000007
#define mod2 998244353
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF  1e9+5
#define f first
#define s second
#define endl '\n'
#define ll long long
#define ii pair <int,int>
#define pll pair <ll,ll>
#define vi vector <int>
#define vl vector <ll>
#define vvi vector < vi >
#define vii vector < ii >
#define vpl vector < pll >
#define vvii vector < vii >
#define vll vector < ll >
#define vb  vector <bool>
#define pb push_back
#define mk make_pair
#define pg priority_queue<ll, vector<ll>, greater<ll>>
#define pq priority_queue<ll>
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define cset(a) __builtin_popcountll(a)
#define FILL(a, b, T) fill_n((T *)a, sizeof(a) / sizeof(T), b)
using namespace std;
ll n, m;
unordered_map<ll,vll> e;
vll indeg(100001);
vll outdeg(100001);
vll maxpath(100001);
vll vis(100001);
void dfs(ll x)
{
	vis[x] = 1;
    for(auto p1: e[x])
    {
        indeg[p1]--;
        maxpath[p1] = max(maxpath[p1],maxpath[x] + 1);
        if( indeg[p1] == 0)
        {
            dfs(p1);
        }
    }
}
int main()
{
    FIO;
    ll t, q, maxx, k, i, j, k1, k2, k3, x, flag, ans, sum, cnt, prev, y;
    cin>>n>>m;
    rep(i,0,m)
    {
        cin>>x>>y;
        e[x].pb(y);
        indeg[y]++;
        outdeg[x]++;
    }
    ans = 0;
    rep(i,1,n+1)
    {
        if( indeg[i] == 0 and vis[i] == 0)
        {
            dfs(i);
        }
    }
    rep(i,1,n+1)
    {
        ans = max(ans, maxpath[i]);
    }
    cout<<ans<<endl;
    return 0;    
}
/*
axyb
abyxb
*/

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

int main (void)
{
	string s;
	cin >> s;
	if (s == "MON") cout << 6 << "\n";
	if (s == "TUE") cout << 5 << "\n";
	if (s == "WED") cout << 4 << "\n";
	if (s == "THU") cout << 3 << "\n";
	if (s == "FRI") cout << 2 << "\n";
	if (s == "SAT") cout << 1 << "\n";
	if (s == "SUN") cout << 7 << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << (x) << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    int a, b;
    char op;

    cin >> a >> op >> b;

    OUT(op == '+' ? a + b : a - b);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

bool isMid(double W, double H, double x, double y){
  return (abs(x - W / 2.0) <= 1e-9 && abs(H / 2.0 - y) <= 1e-9);
}

int main(){
  double W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << fixed << setprecision(10) << (double)(W*H / 2.0);
  cout << " " << (isMid(W, H, x, y) ? 1 : 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int i,j,seito[31];
	
	for(i=0;i<31;i++){
		seito[i]=0;
	}
	for(i=0;i<28;i++){
		scanf("%d",&j);
		seito[j]=1;
	}
	for(i=1;i<31;i++){
		if(seito[i]==0){
			printf("%d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rep1(i,n) for(int i=1; (i)<(n); ++(i))
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; }
const long long llINF = 1LL<<60;
const int INF = 1e9;
int main(){
    int n, k, ans=0;  cin >> n >> k;
    vector<int> h(n); 
    rep(i,n){
      cin>> h[i];
      if(h[i]>=k) ans++;
      }
    
    cout << ans;

    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <time.h>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define reps(x, c) for (auto x : c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a)
#define mp(a, b) make_pair((a), (b))
#define pl pair<ll, ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cerr << #x "=" << (x) << "\n"
#define dbgv(x) \
    cerr << #x << "\n"; \
    reps(y, x) { cerr << y << " "; } \
    cerr << "\n"
int main() {
    ll n;
    cin >> n;
    vector<ll> a(5);
    rep(i, 5) { cin >> a[i]; }
    sort(all(a));
    cout << (n + a[0] - 1) / a[0] + 4 << endl;
    return 0;
}

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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;

int main(int argc, char *argv[]) {
    ll n, y;
    cin >> n >> y;

    for (ll i_10 = 0; i_10 <= n; ++i_10) {
        for (ll i_5 = 0; i_5 <= n; ++i_5) {
            ll i_1 = n - i_10 - i_5;
            if (i_1 < 0) continue;

            if (i_10*10000 + i_5*5000 + i_1*1000 == y) {
                cout << i_10 << " " << i_5 << " " << i_1 << endl;
                exit(EXIT_SUCCESS);
            }
            
        }
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}


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

int main() {
    int n;
    int s = 1;
    cin >> n;
    vi a(n, 0);
    for(int i=n-1; i>=0; i-=2) {
        a[i] = 2;
        if(i!=0) s = (s*2)%MOD;
    }
    if(n%2==1) a[0] = 1;
    for (int i=0; i<n; ++i) {
        int t;
        cin >> t;
        a[t]--;
        if(a[t]<0) {
            P(0);
            return 0;
        }
    }
    P(s);
}


Measured memory_bytes: 640
/**
 * Created by hiramekun at 18:23 on 2019-08-26.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}


template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    vl a(n);
    cin >> a;

    multiset<ll> s;
    rep(i, n) {
        if (s.empty()) {
            s.insert(a[i]);
            continue;
        }

        auto itr = s.lower_bound(a[i]);
        if (itr == s.begin()) {
            s.insert(a[i]);
        } else {
            itr--;
            s.erase(itr);
            s.insert(a[i]);
        }
    }
    cout << s.size() << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}



Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int n;
        cin>>n;
        int a[105]={};
        for(int j=0;j<n;j++){
            cin>>a[j];
        }
        int mx1=0;
        for(int j=0;j<n-1;j++){
            mx1=max(mx1,a[j]-a[j+1]);
        }
        int mx2=0;
        for(int j=1;j<n;j++){
            mx2=max(mx2,a[j]-a[j-1]);
        }
        cout<<mx2<<" "<<mx1<<endl;
    }
    return 0;
}



Measured memory_bytes: 3016
n, m = map(int,input().split())
A = list(map(int,input().split()))

total = sum(A)

th = total/(4*m)
A = sorted(A,reverse=True)

ans = 'Yes'
for i in range(m):
  if A[i] >= th:
    continue
  else:
    ans = 'No'
  

print(ans)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    long[] h = new long[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextLong();
    }
    Arrays.sort(h);
    long ans = 0;
    if(n > k) {
      for(int i = 0; i < (n - k); i++) {
        ans += h[i];
      }
    }
    System.out.println(ans);
  }
}

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

int main()
{
    long int n;
    cin>>n;
    long long int a[n],pref[n];
    for(long int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i)
        pref[i]=a[i]+pref[i-1];
        else
        pref[i]=a[i];
    }
    long long int ans=0, m=1e9+7;
    for(long int i=0;i<n;i++)
    {
        ans=(ans + (a[i]*((pref[n-1]-pref[i])%m))%m)%m;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6760
import java.util.Scanner;
public class Main {

  public static void myPrint(String[] ary, int a, int b) {
    StringBuilder s = new StringBuilder();
    for (int i = a; i <= b; i++) {
      s.append(ary[i]);
    }
    System.out.println(s);
  }

  public static void myReverse(String[] ary, int a, int b) {
    while (a < b) {
      String temp = ary[a];
      ary[a] = ary[b];
      ary[b] = temp;
      a++;
      b--;
    }
  }

  public static void myReplace(String[] ary, int a, int b, String p) {
    String[] pAry = p.split("");
    int j = 0;
    for (int i = a; i <= b; i++) {
      ary[i] = pAry[j];
      j++;
    }
  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    String str = s.nextLine();
    String[] strAry = str.split("");
    int n = s.nextInt();
    int a;
    int b;
    String p;
    for (int i = 0; i < n; i++) {
      String cmd = s.next();
      switch(cmd) {
        case "print":
          a = s.nextInt();
          b = s.nextInt();
          myPrint(strAry, a, b);
          break;
        case "reverse":
          a = s.nextInt();
          b = s.nextInt();
          myReverse(strAry, a, b);
          break;
        case "replace":
          a = s.nextInt();
          b = s.nextInt();
          p = s.next();
          myReplace(strAry, a, b, p);
          break;
      }
    }
    s.close();
  }
}



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

using namespace std;

int main(void) {
	int n, m;
	cin >> n >> m;
	vector<int>a(n), b(n);
	for (int i = 0; i < n; i++)cin >> a[i] >> b[i];
	vector<int>c(m), d(m);
	for (int i = 0; i < m; i++)cin >> c[i] >> d[i];
	for (int i = 0; i < n; i++) {
		int v = 1e9, p = 0;
		for (int j = 0; j < m; j++) {
			if (v > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				p = j;
				v = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			}
		}
		cout << p + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	long long n, i, j, k, best, c;
	cin >> n;
	vector<int> a(n);
	for (i = 0; i < n; i++) cin >> a[i];
	best = 1LL << 61;
	for (i = -100; i <= 100; i++) {
		c = 0;
		for (auto p : a) c += (p - i) * (p - i);
		best = min(best, c);
	}
	cout << best << "\n";

	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

int main()
{
    int r, g, b;
    cin >> r >> g >> b;

    int val = r * 100 + g * 10 + b;
    if(val % 4 == 0)
    	cout << "YES" << endl;
    else
    	cout << "NO" << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

//////////////////////////////////////
#include <iostream>
using namespace std;
#define dp(arg) do { cout << #arg << ":"; dprint(arg); } while(0)

template <typename T> void dprint(T arg) { cout << arg << "\n"; }
template <typename T> void dprint(const vector<T>& arg) { for_each(begin(arg), end(arg), [](T value){ cout << value << " "; }   ); cout << "\n";  }
template <typename T> void dprint(const vector<vector<T>>& arg) { for_each(begin(arg), end(arg), [=](vector<T> arg2){ dprint(arg2); cout << "\n";} );  }

// #define dprint(arg) ;
//////////////////////////////////////

lint subfunc(lint n, std::vector<long long> a, bool isPlus){
    // isPlus: 今，和はプラスであるべきか，マイナスであるべきか

    lint b[n]; // 結果を示す(デバッグ用)
    lint total = 0LL; // ここまでのa[i]の和
    lint resCount = 0LL; // 置き換えた数 = 結果となるコスト

    REP(i, n){
        // まず，一旦，a[i]のまま値を設定　+ 和を取る
        total += a[i];
        b[i] = a[i];
        if (isPlus && total < 1) { // 和はplusであるべきなのに，和がマイナスか0なら
            resCount += (-total) + 1; // 和を+1にするまでインクリメント
            b[i] += (-total) + 1;
            total = 1; // 和を+1にする
        }
        else if(!isPlus && total > -1){ // 和は-であるべきなのに，和が+か0なら
            resCount += (total) + 1; // 和を-1にするまでデクリメント
            b[i] -= (total) + 1;
            total = -1; // 和を-1にする
        }
        isPlus = !isPlus; // 次の和は記号反転
    }
    // 以下のコメントアウト外すとこのパターンでのコストと数列が出る
    //cout << "res:"; REP(i, n) cout << " " << b[i]; cout << "\n";
    //cout << "cost:" <<resCount << "\n";
    return resCount;
}

int main(){

    long long n;
    lint res1, res2;
    scanf("%lld",&n);
    std::vector<long long> a(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&a[i]);
    }

    // [注意] 以下の渡し方はaのcopyが走るので本当はうれしくない
    res1 = subfunc(n, a, true);  // パターン1: プラス始まり (+ - + -)
    res2 = subfunc(n, a, false); // パターン2: マイナス始まり (- + - +)
    cout << min(res1, res2) << "\n"; // で，コストが小さいほうを表示
    return 0;
}



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

using namespace std;

int main()
{
	int X, A;
	cin >> X >> A;

	if (X < A) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}

}






Measured memory_bytes: 3584
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let a:i64 = read();
    let b:i64 = read();
    let c:i64 = read::<i64>()*2 as i64;
    let x:i64 = read();
    let y:i64 = read();

    let mut ans:i64 = 0;
    if c <= a + b {
        ans += min(x,y)*c;
        //debug!(ans);
        ans += min(c*(x-y).abs(),max((x-y)*a, (y-x)*b));
    }
    else {
        ans += x*a + y*b;
    }

    println!("{}", ans);

}


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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace

#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    ll n;
    cin >> n;
    while (true)
    {
        bool prime = true;
        for (ll i = 2; i * i <= n; i++)
        {
            if (n % i == 0) prime = false;
        }
        if (prime)
        {
            cout << n << '\n';
            return 0;
        }
        n++;
    }
        
}



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

#define ll long long
#define ld long double
#define HS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f3f3f3f3f
#define point complex <double>
#define all(a) a.begin(), a.end()
#define pi acos(-1)
#define mod 1000000007


using namespace std;

int main() {

    HS;
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    int arr[10005];
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    int grid[105][105];
    int i = 1, j = 1;
    bool rev = 0;
    for (int _ = 1; _ <= n; _++) {
        while (arr[_]) {
            if (!rev)
                for (j; j <= w && arr[_]; j++) {
                    grid[i][j] = _;
                    arr[_]--;
                }
            if (j == w + 1)
                rev = 1, i++, j = w;
            if (rev)
                for (j; j >= 1 && arr[_]; j--) {
                    grid[i][j] = _;
                    arr[_]--;
                }
            if (j == 0)
                rev = 0, j = 1, i++;


        }
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cout << grid[i][j] << " ";
        }
        cout << endl;
    }


    return 0;

}

Measured memory_bytes: 3700
import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n-1,1,-1):
  for j in range(i-1,0,-1):
    ans+=j-bisect.bisect_left(l,l[i]-l[j]+1,hi=j)
print(ans)

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

int main(){
    string s;
    cin >> s;
    int a = 0, b = 0, c = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] == 'a') a++;
        else if(s[i] == 'b')    b++;
        else c++; 
    }
    int m = min(a, b);
    m = min(m, c);
    a -= m;
    b -= m;
    c -= m;
    if(a <= 1 && b <= 1 && c <= 1)  cout << "YES";
    else    cout << "NO" << endl;
}

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

int main()
{
  string buf;

  int cnt[ 26 ] = { 0 };
  int idx = 0;

  while( cin >> buf ) {
    for( int i = 0; i < buf.size(); i++ ) {
      char ch = buf[ i ];

      if( ch >= 65 and ch <= 90 ) {
        idx = ch - 65;
        cnt[ idx ] += 1;
      }
      if( ch >= 97 and ch <= 122 ) {
        idx = ch - 97;
        cnt[ idx ] += 1;
      }
    }
  }

  for( int i = 0; i < 26; i++ ) {
    cout << (char)( i + 97 ) << " : " << cnt[ i ] << endl;
  }
  return 0;
}

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

using namespace std;
using LL = long long;

constexpr int N = 1e6 + 5;
constexpr int INF = 1e9;


int n, m, k;
set< int> X[N], Y[N];
vector < string> s;
vector< vector< int>> ans;

void bfs(int x, int y) {
    if (s[x][y] == '@') return;

    ans[x][y] = 0;
    X[x].erase(y);
    Y[y].erase(x);
    queue< pair< int, int>> Q;
    Q.emplace(x, y);

    while (!Q.empty()) {
        x = Q.front().first, y = Q.front().second;
        Q.pop();

        while (true) {
            auto it = Y[y].upper_bound(x);
            if (it == Y[y].end()) break;
            int nx = *it;
            if (abs(nx - x) > k) break;
            if (s[nx][y] == '@') break;

            Y[y].erase(nx);
            X[nx].erase(y);

            ans[nx][y] = ans[x][y] + 1;
            Q.emplace(nx, y);
        }

        while (true) {
            auto it = Y[y].lower_bound(x);
            if (it == Y[y].begin()) break;
            it--;

            int nx = *it;
            if (abs(x - nx) > k) break;
            if (s[nx][y] == '@') break;

            Y[y].erase(nx);
            X[nx].erase(y);
            ans[nx][y] = ans[x][y] + 1;
            Q.emplace(nx, y);
        }

        while (true) {
            auto it = X[x].upper_bound(y);
            if (it == X[x].end()) break;

            int ny = *it;
            if (ny - y > k) break;
            if (s[x][ny] == '@') break;

            X[x].erase(it);
            Y[ny].erase(x);

            ans[x][ny] = ans[x][y] + 1;
            Q.emplace(x, ny);
        }

        while (true) {
            auto it = X[x].lower_bound(y);
            if (it == X[x].begin()) break;
            it--;

            int ny = *it;
            if (y - ny > k) break;
            if (s[x][ny] == '@') break;

            X[x].erase(it);
            Y[ny].erase(x);

            ans[x][ny] = ans[x][y] + 1;
            Q.emplace(x, ny);
        }
    }
}

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

    cin >> n >> m >> k;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    x1--; y1--;
    x2--; y2--;

    ans.assign(n, vector< int>(m, INF));


    for (int i = 0; i < n; i++) {
        string x;
        cin >> x;
        s.push_back(x);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            X[i].insert(j);
            Y[j].insert(i);
        }
    }

    bfs(x1, y1);

    if (ans[x2][y2] == INF) cout << -1 << "\n";
    else cout << ans[x2][y2] << endl;
}

Measured memory_bytes: 196056
/*input
abracadabra
avadakedavra
*/
#include <bits/stdc++.h>

using namespace std;

const int maxn = (int) 3e3 + 10;
char a[maxn], b[maxn];
vector<vector<int>> dp(maxn, vector<int>(maxn, -1));

int lcs(int n, int m) {
	if (dp[n][m] != -1) {
		return dp[n][m];
	}
	if (n == 0 || m == 0) {
		return 0;
	}
	if (a[n - 1] == b[m - 1]) {
		return dp[n][m] = lcs(n - 1, m - 1) + 1;
	} else {
		return dp[n][m] = max(lcs(n - 1, m), lcs(n, m - 1));
	}
}

int main() {
	scanf("%s", a);
	scanf("%s", b);
	int i = strlen(a), j = strlen(b);
	lcs(i, j);
	string ans = "";
	while (i > 0 && j > 0) {
		if (a[i - 1] == b[j - 1]) {
			ans = a[i - 1] + ans;
			i--, j--;
		} else {
			if (dp[i - 1][j] > dp[i][j - 1]) {
				i--;
			} else {
				j--;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 35968
import sys
buf = sys.stdin.buffer

n, m = map(int, buf.readline().split())
AB = map(int, buf.read().split())

reachable_from_start = set()
reachable_to_goal = set()
for a, b in zip(AB,AB):
    if a == 1:
        reachable_from_start.add(b)
    if b == n:
        reachable_to_goal.add(a)

possible = reachable_from_start & reachable_to_goal
if possible or n in reachable_from_start:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 44752
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
	int K;
	VI num;
	scanf("%d", &K);
	for (int i = 0; i < K; i++) {
		int a;
		scanf("%d", &a);
		num.PB(a);
	}
	reverse(ALL(num));
	ll l = 2, r = 2;
	for (int a : num) {
		ll nl, nr;
		nl = l / a * a;
		if (nl < l)
			nl += a;
		nr = r / a * a;
		nr += a - 1;
		l = nl;
		r = nr;
		if (nl > nr)
			break;
		debug("%lld %lld -- %d -- %lld %lld\n", l, r, a, nl, nr);
	}
	if (l > r)
		puts("-1");
	else
		printf("%lld %lld\n", l, r);
	return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
using namespace std;

int main()
{
	long long n;
	cin >> n;
	cout << fixed << setprecision(0) << pow(floor(pow(n, 0.5)),2) << endl;//setprecisionをつけないと指数表記(defaultfloat)をしてしまう。(fixedも必要。)
}

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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 50)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
template <typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

int dist[300][300], a[300][300];
int V;

void Warshall_Floyd() {
    for(int k = 0; k < V; ++k) for(int i = 0; i < V; ++i) for(int j = 0; j < V; ++j) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
}

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

    cin >> V;
    rep(i, V) rep(j, V) {
        dist[i][j] = (i == j) ? 0 : INF;
    }
    rep(i, V) rep(j, V) {
        cin >> a[i][j];
        dist[i][j] = a[i][j];
    }
    Warshall_Floyd();
    rep(i, V) rep(j, V) {
        if(dist[i][j] != a[i][j]) {
            cout << -1 << endl;
            return 0;
        }
    }
    int res = 0;
    rep(i, V - 1) FOR(j, i + 1, V) {
        bool flag = true;
        rep(k, V) {
            if(i != k && j != k && dist[i][j] == dist[i][k] + dist[k][j])
                    flag = false;
        }
        if(flag) res += dist[i][j];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<string> S(N);
    map<vector<int>,ll> mp;
    ll out = 0;
    for(int i=0;i<N;i++){
        cin >> S[i];
        vector<int> a(26);
        for(int j=0;j<10;j++){
            a[S[i][j]-'a']++;
        }
        mp[a]++;
    }
    for(auto m:mp){
        ll t = m.second;
        if(t==1) continue;
        out += (t-1)*t/2;
    }

    cout << out << endl;
    return 0;
}


Measured memory_bytes: 24984