akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

int main() {
    int R, C, N;
    cin >> R >> C >> N;

    auto f = [&](int x, int y) {
        return 0 == x or x == C or y == 0 or y == R;
    };

    vector<pair<P, int>> p;

    rep(i, N) {
        int x1, y1, x2, y2;
        cin >> y1 >> x1 >> y2 >> x2;

        if (f(x1, y1) and f(x2, y2)) {
            p.emplace_back(make_pair(x1, y1), i);
            p.emplace_back(make_pair(x2, y2), i);
        }
    }

    sort(p.begin(), p.end(), [&](const pair<P, int> & a, const pair<P, int> & b) {

        P ta = a.first, tb = b.first;

        if (ta.first == tb.first and ta.second == tb.second) {
            return a.second < b.second;
        }

        if (ta.second == 0 and tb.second == 0) {
            return ta.first < tb.first;
        }
        if (ta.second == 0) return true;
        else if (tb.second == 0) return false;

        if (ta.first == C and tb.first == C) {
            return ta.second < tb.second;
        }
        if (ta.first == C) return true;
        else if (tb.first == C) return false;

        if (ta.second == R and tb.second == R) {
            return ta.first > tb.first;
        }
        if (ta.second == R) return true;
        else if (tb.second == R) return false;

        if (ta.first == 0 and tb.first == 0) {
            return ta.second > tb.second;
        }
        if (ta.first == 0) return true;
        else if (tb.first == 0) return false;
    });

    stack<int> st;
    for (auto tmp : p) {
        if (st.empty()) st.push(tmp.second);
        else {
            int t = st.top();
            if (t == tmp.second) st.pop();
            else st.push(tmp.second);
        }
    }

    cout << (st.size() ? "NO" : "YES") << endl;
}


Measured memory_bytes: 4852
#define _USE_MATH_DEFINES
#include <math.h>
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    if(n <= k)
    {
        cout << n * x << "\n";
    }
    else
    {
        cout << k * x + (n - k) * y << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
int main(){
    queue<int> q;
    int n,k,sum=0,m,A[200003];
    double ans;
    cin>>n>>k;
    REP(i,n){
        cin>>A[i];
        if(i<k){
            sum+=A[i];
            m=sum;
        }
        else{
            sum-=A[i-k];
            sum+=A[i];
            m=max(m,sum);
        }
    }
    ans=(m+k)/2.0;
    cout<<fixed << setprecision(10)<<ans<<endl;//setprecision(n)で小数点以下を指定できる。
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n, a[102];

void solve()
{
    cin >> n;
    for (int i=1; i<=n; i++) cin >> a[i];
    int pref[102]; pref[0]= 0;
    for (int i=1; i<=n; i++) pref[i] = pref[i-1] + a[i];

    int ans = INT_MAX;
    for (int i=1; i<n; i++) {
        ans = min(ans, abs(pref[i]-(pref[n]-pref[i])));
    }nout(ans);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3620
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx,avx2")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e15;

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

    int n;
    cin >> n;
    int ans = 0;
    vector<int> a(n + 1);
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
        ans += a[i];
    }
    if (n == 0 || a[0] >= 1) {
        if (ans == 1) {
            cout << "1\n";
        } else {
            cout << "-1\n";
        }
        return 0;
    }
    vector<int> r(n + 1);
    for (int i = 0; i <= n; i++) {
        if (i == 0) {
            r[i] = 1;
        } else {
            r[i] = 2 * r[i - 1] - a[i];
            if (r[i] > inf) r[i] = inf;
            if (r[i] < 0) {
                cout <<  -1 << "\n";
                return 0;
            }
        }
    }
    int k = a[n];
    for (int i = n - 1; i >= 0; i--) {
        k = min(r[i], k);
        ans += k;
        k += a[i];
    }
    cout << ans << "\n";

    return 0;
}


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

using namespace std;

int main(){
  int N;
  long long K;
  cin >> N >> K;
  
  vector<int> A(N), place(200001, -1), next(N, -1);
  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(place[A[i]] >= 0){
      next[place[A[i]]] = i + 1;
    }
    place[A[i]] = i;
  }
  
  for(int i = 0; i < N; i++){
    if(next[place[A[i]]] == -1){
      next[place[A[i]]] = N + i + 1;
    }
  }
  
  long long turn = next[0];
  for(int i = next[0] % N; i != 0; i = next[i] % N){
    turn += next[i] - i;
  }
  
  turn *= K / (turn / N);
  
  for(int i = 0; turn + next[i] - i < K * N; i = next[i] % N){
    turn += next[i] - i;
  }
  
  for(int i = turn % N; i < N;){
    if(next[i] <= N) i = next[i];
    else{
      cout << A[i] << ' ';
      ++i;
    }
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair

using namespace std;


void run(){
	ll n,d,a;
	cin>>n>>d>>a;
	vector <pair<ll,ll> > v;
	for(ll i=0;i<n;i++){
		ll x,h;
		cin>>x>>h;
		v.PB(MP(x,h));
	}
	sort(v.begin(),v.end());
	ll cur=0;
	queue <pair<ll,ll> > del;
	ll count=0;
	for(auto j:v){
	
		ll x=j.ff;
		
		while(1){
		if(del.empty())break;
		auto z=del.front();
		if(z.ff<=x){cur-=z.ss;del.pop();}
		else break;
		}
		
		ll am=j.ss-cur;
		if(am<0)am=0;
		
		ll delo=am/a+1;
		if(am%a==0)delo--;
		count+=delo;
		cur+=a*delo;
		del.push(MP(x+1ll+2ll*d,a*delo));
	}
	cout<<count;
	
}
int main() {
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)run();
	// your code goes here
	return 0;
}

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

int main()
{
	int a[100000+1],b[100000+1],s[100000+1];
	
	a[0]=0;a[1]=0;
	b[0]=0;b[1]=0;
	s[0]=0;
	for(int i=2;i<=100000;i++){
		a[i]=1;
		b[i]=0;
	}
	for(int i=2;i<=sqrt(100000);i++){
		if (a[i]==1){
			for(int j=2*i;j<=100000;j+=i) a[j]=0;
		}
	}
	for(int i=1;i<=100000;i++){
		if (i%2==1 && a[i]==1 && a[(i+1)/2]==1) b[i]=1;
		s[i]=s[i-1]+b[i];
	}
	int q,l,r,t;
	cin>>q;
	for(int i=1;i<=q;i++){
		cin>>l>>r;
		t=s[r]-s[l-1];
		cout<<t<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void){

int a, b, c;
scanf("%d %d %d", &a, &b, &c);
	
	if(a<b&&b<c){
		printf("Yes\n");
	}
	
	else{
		printf("No\n");
	}
	
	
return 0;
}


Measured memory_bytes: 2076
#include<stdio.h>
#define SWAP(type,x,y)do{type temp=x;x=y;y=temp;}while(0)
main(){
  int i,j,a[5],b[5],c,d;
  while(1){
    for(i=0;i<5;i++){
      scanf("%d %d",&c,&d);
      if(d==0&&c==0)return 0;
      a[i]=d+c;
      b[i]=i;
    }
    for(i=0;i<4;i++){
      for(j=4;j>i;j--){
	if(a[j]>a[j-1]){
	  SWAP(int,a[j],a[j-1]);
	  SWAP(int,b[j],b[j-1]);
      }
    }
    }
    printf("%c %d\n",b[0]+'A',a[0]);
  }
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(void)
{
	int n, a, b, sa, sb;
	int i;
	
	while (1) {
		scanf("%d", &n);
		if (n == 0)
			break;
		sa = 0; sb = 0;
		for (i = 0; i < n; i++) {
			scanf("%d%d", &a, &b);
			if (a > b)
				sa += a + b;
			else if (b > a)
				sb += a + b;
			else {
				sa += a; sb += b;
			}
		}
		printf("%d %d\n", sa, sb);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
 
    vector<vector<int>> G(N);    // 隣接リスト表現によるグラフ
    vector<pair<int, int>> E_in; // 辺の入力の順番を保持する
 
    for (int i = 1; i < N; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        pair<int, int> p = make_pair(a, b);
        E_in.emplace_back(p);
    }
 
    queue<int> que;
    vector<int> used(N, 0);
    vector<int> parent(N, 0); // 親との間にある辺の数値
    int max_color = 0;
    map<pair<int, int>, int> E_num; // 辺への割り振った番号を保持する
    que.emplace(0); // 最初のものは何でも良いので0からにする
    used[0] = 1;
    while (que.size() != 0) {
        int state = que.front(); // 現在の状態
 
        que.pop();
        int color_num = 0;
        for (auto next : G[state]) {
            if (used[next] != 1) {
                color_num++;
                used[next] = 1;
                if (color_num == parent[state]) {
                    // 親との間にある辺と番号が被らないようにする
                    color_num++;
                }
                pair<int, int> p = make_pair(state, next);
                E_num[p] = color_num; //辺彩色
                parent[next] = color_num;
                que.push(next); //次の状態をqueueへ格納
            }
        }
        max_color = max(max_color, color_num);
    }
 
    cout << max_color << "\n";
    for (auto i : E_in) {
        cout << E_num[i] << "\n";
    }
 
    return 0;
}

Measured memory_bytes: 16520
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
void solve(int n){
    int64 sum = 0;
    for(int i = 1; i <= n; i++){
        if(i % 3 == 0 || i % 5 == 0) continue;
        sum += i;
    }
    cout << sum << endl;
}
int main(){
    int n; cin >> n;
    solve(n);
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>


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

  int n,m;
  cin>>n>>m;
  map<int,int> mp;
  int ans=0;
  vi a(n);
  rep(i,n){
    cin>>a[i];
    if(i){
      a[i]+=a[i-1];
    }
  }
  rep(i,n){
    a[i]%=m;
    mp[a[i]]++;
  }

  mp[0]++;
  for(P m:mp){
    ans+=(m.S-1)*m.S/2;
  }

  cout<<ans<<endl;


}

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


#define ll                  long long
#define scl(n)              cin>>n;
#define scc(c)	            cin>>c;
#define fr(i,n)             for (ll i=0;i<n;i++)
#define fr1(i,n)            for(ll i=1;i<=n;i++)
int main()
{
  ll m,n , i, j;
  cin>>n;
  ll ans=0;
  
  ans=1000*(n/500);
  ll baki=n%500;
  ans+=5*(baki/5);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>  // min, max
#include <fstream>  // ifstream
#include <iomanip>  // setprecision
using namespace std;
typedef long long ll;

int main(void)
{
#ifdef FILE_DEBUG
    ifstream inputFile("data/input.txt");
    cin.rdbuf(inputFile.rdbuf());
#endif
    // これより下にコードを書く

    string S;
    cin >> S;

    if (S > "2019/04/30")
        cout << "TBD" << endl;
    else
        cout << "Heisei" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 2000000
bool isP[MAX];
int main(){
  for(int i=2;i<MAX;i++)isP[i]=true;
  for(int i=2;i*i<MAX;i++)
    if(isP[i])for(int j=i*i;j<MAX;j+=i)isP[j]=false;
  while(1){
    int a,b,n,cnt=0;
    cin>>a>>b>>n;
    if(a==0&&b==0&&n==0)break;
    while(cnt<n){
      cnt+=isP[a];
      a+=b;
    }
    cout<<a-b<<endl;
  }
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
struct MinCostFlow {
    vector<vector<pair<int, int>>> G;
    vector<vector<int>> cap;
    MinCostFlow(int n) {
        G.resize(n);
        cap.resize(n, vector<int>(n));
    }
    void add_edge(int i, int j, int c, int a) {
        G[i].emplace_back(j, a);
        G[j].emplace_back(i, -a);
        cap[i][j] = c;
    }
    Int min_cost_flow(int s, int t) {
        Int ans = 0;
        vector<Int> dist(G.size()), prv(G.size());
        for (;;) {
            fill(begin(dist), end(dist), 1e18);
            fill(begin(prv), end(prv), -1);
            dist[s] = 0;
            for (int i = 0; i < G.size() - 1; i++) {
                for (int j = 0; j < G.size(); j++) {
                    for (auto [n, a] : G[j]) {
                        if (cap[j][n] > 0 && dist[n] > dist[j] + a) {
                            prv[n] = j;
                            dist[n] = dist[j] + a;
                        }
                    }
                }
            }
            if (dist[t] > 9e17) break;
            ans += dist[t];
            for (int a = t; prv[a] != -1; a = prv[a]) {
                cap[prv[a]][a]--;
                cap[a][prv[a]]++;
            }
        }
        return ans;
    }
};
int main() {
    int N, K; cin >> N >> K;
    vector<vector<int>> A(N, vector<int>(N));
    for (auto &row : A) for (auto &a : row) cin >> a;
    MinCostFlow mcf(N * 2 + 2);
    int start = N * 2, goal = N * 2 + 1;
    for (int i = 0; i < N; i++) {
        mcf.add_edge(start, i, K, 0);
        mcf.add_edge(i, goal, K, 0);
        mcf.add_edge(N + i, goal, K, 0);
        for (int j = 0; j < N; j++) {
            mcf.add_edge(i, N + j, 1, -A[i][j]);
        }
    }
    cout << -mcf.min_cost_flow(start, goal) << '\n';
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (mcf.cap[N + j][i] == 1) {
                cout << 'X';
            } else {
                cout << '.';
            }
        }
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 3692
#include <iostream>
#include <cstring>

int n;

bool visited[50];
bool hasEdge[50][50];

int dfs(int x) {
	visited[x] = true;

	int ret = 1;
	for (int i = 0; i < n; ++i)
		if (hasEdge[x][i] && !visited[i])
			ret += dfs(i);

	return ret;
}

int main() {
	int m;
	std::cin >> n >> m;

	for (int i = 0; i < m; ++i) {
		int a, b;
		std::cin >> a >> b;
		--a, --b;

		hasEdge[a][b] = hasEdge[b][a] = true;
	}

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (hasEdge[i][j]) {
				std::memset(visited, 0, sizeof(visited));

				hasEdge[i][j] = hasEdge[j][i] = false;
				if (dfs(0) != n)
					++ans;

				hasEdge[i][j] = hasEdge[j][i] = true;
			}
		}
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  int64_t zoro = 0;
  bool result = false;
  for (int64_t i = 0; i < N; ++i) {
    int64_t a, b;
    cin >> a >> b;
    if(a==b) {
      ++zoro;
      if(zoro >=3) {
        result = true;
      }
    } else {
      zoro = 0;
    }
  }
  if(result){
  cout << "Yes" << endl;
  } else {
  cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
ll p;
int main(){
  ll n;
  cin>>n;
  vll a(n),b(n);
  rep(i,n) {
    cin>>a[i];
  }
  rep(i,n){
    cin>>b[i];
  }
  ll k=0;
  ll t=0;
  repR(i,n-1){
    if(b[i]>a[i]){
      k+=(b[i]-a[i])/2;
    }
    if(a[i]>b[i]){
      t+=a[i]-b[i];
    }
  }
  if(k>=t){
  COUT("Yes");
  }
  else COUT("No");

}


Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,x,y;
    cin>>n>>x>>y;
    x --;y --;
    vector<int> d(0);
    int dist;
    rep(i,n-1)REP(j,i+1,n){
        dist=j-i;
        dist=min(dist,abs(x-i)+1+abs(y-j));
        d.emplace_back(dist);
    }
    map<int,int> a;
    rep(i,d.size()) a[d[i]] ++;
    REP(i,1,n) cout<<a[i]<<endl;
}

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

const int Maxn = 100005;

int n;
int a[Maxn];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if (a[i - 1] > a[i]) { printf("No\n"); return 0; }
        else if (a[i - 1] < a[i]) a[i]--;
    }
    printf("Yes\n");
    return 0;
}


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

using namespace std;

int main()
{
    int A, B;   cin >> A >> B;
    
    int Ans = 0;
    
    if(A >= 6)  Ans += B / 2;
    if(A >= 13) Ans += B / 2;
    
    cout << Ans << endl;
}


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

int main(){
  int k;
  cin >> k;
  vector<int> vec={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,
                   2,2,1,15,2,2,5,4,1,4,1,51};
  cout << vec.at(k-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

int main(void){
	lld a,b,c,d,t;
	cin >> a >> b >> c >> d >> t;
	if(a==c){
		printf("YES");
	}else{
		if(b<=d) printf("NO");
		else{
			lld tt = (abs(a-c)/(b-d));
			if((abs(a-c)%(b-d))) tt++;
			if(t>=tt) printf("YES");
			else printf("NO");
		}
	}
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
 
using namespace std;
 
int main()
{
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  set<int> s(d.begin(), d.end());
 
  cout<< s.size() <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<string> c;
int n;
void dfs(long x);
int main(){
    cin>>n;
    dfs(0);
    int ans=0;
    for(int i=0;i<c.size();i++){
        bool f1=false,f2=false,f3=false;
        for(int j=0;j<c[i].size();j++){
            if(c[i][j]=='7')f1=true;
            if(c[i][j]=='5')f2=true;
            if(c[i][j]=='3')f3=true;
        }
        if(f1&&f2&&f3){
            //cout<<c[i]<<endl;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}
void dfs(long x){
    if(x<=n){
        c.push_back(to_string(x));
    }
    else return;
    dfs(x*10+3);
    dfs(x*10+5);
    dfs(x*10+7);
}


Measured memory_bytes: 1916
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
signed main(){
	int n;
	cin>>n;
	vector<vector<int>> a(3,vector<int>(n));
	rep(i,3) rep(j,n) cin>>a[i][j];
	rep(i,3) sort(All(a[i]));
	vector<int> dp(n,0);
	rep(i,n){
		if(i>0) dp[i]=dp[i-1];
		int ka=lower_bound(All(a[0]),a[1][i])-a[0].begin();
		int kc=a[2].end()-upper_bound(All(a[2]),a[1][i]);
		dp[i]+=ka*kc;
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 3440
import sys
from collections import Counter

n, m = list(map(int, input().split()))
aaa = list(map(int, input().split()))
cards = list(Counter(aaa).items())
for line in sys.stdin:
    b, c = map(int, line.split())
    cards.append((c, b))
ans = 0
cnt = 0
for c, b in sorted(cards, reverse=True):
    if cnt + b >= n:
        ans += c * (n - cnt)
        break
    ans += c * b
    cnt += b
print(ans)


Measured memory_bytes: 30364
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin>>n;
  if(n%2==1){
    cout<<0;
    return 0;
  }else{
    long long kotae=0;
    long long a=5;
    long long hanbun=n/2;
    while(a<=hanbun){
      kotae+=hanbun/a;
      a*=5;
    }
    cout<<kotae<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll n;
    cin >> n;
    vector<long double> x(n), y(n);
    loop(i, n) cin >> x[i] >> y[i];
    vector<pair<long double, ll>> angles(n);
    loop(i, n)
    {
        long double angle;
        angle = atan2(y[i], x[i]);
        if (angle <= 0.0)
            angle = 2.0 * acos(-1.0) + angle;
        angles[i] = make_pair(angle, i);
    }
    sort(all(angles));
    long double ans = 0.0;
    loop(i, n)
    {
        Loop(j, i, 2 * n)
        {
            long double X = 0.0, Y = 0.0;
            ll count = 0;
            for (ll k = i; k <= j; k++)
            {
                X += x[angles[k % n].second];
                Y += y[angles[k % n].second];
                count++;
            }
            if (count <= n)
                ans = max(ans, sqrt(X * X + Y * Y));
        }
    }
    putout(ans);
    return 0;
}


Measured memory_bytes: 3888
let arr_of_str s = Array.init (String.length s) (fun i -> i, s.[i])
let () = Printf.printf "%c\n" @@
  Scanf.scanf "%s %d" @@ fun s k ->
  let s = arr_of_str s in
  let li, c = Array.fold_left (fun (j, z) (i, c) ->
    if z <> '1' then (j, z) else if c <> '1' then (i, c) else (j, z)) (Array.length s, '1') s
  in
  if k-1 <= li then snd s.(k-1) else c

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

int main()
{
    int a,b,c,x,y;

    while(cin>>a>>b>>c>>x>>y)
    {
        int small=min(x,y);
        int result;
        if(a+b<2*c)
            result=a*x+b*y;
        else
        {
            if(x>y)
            {
                if(a>2*c)
                    result=x*2*c;
                else
                    result=small*2*c+(x-small)*a;
            }
            else
            {
                if(b>2*c)
                    result=y*2*c;
                else
                    result=small*2*c+(y-small)*b;
            }
        }
        cout<<result<<endl;
    }
    return 0;
}


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

int A[100010], B[100010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N + 1; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ans += min(B[i], A[i]);
		B[i] = max(B[i] - A[i], 0);
		ans += min(B[i], A[i + 1]);
		A[i + 1] = max(0, A[i + 1] - B[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    string s1,s2;
    int t=0,h=0;
    for(i=0;i<n;i++)
    {
        cin>> s1>> s2;
        if(s1.compare(s2)==0)
        {
            t++;h++;
        }
        else if(s1.compare(s2)>0)
            t+=3;
        else h+=3;
    }
    cout<< t<<" "<<h<<endl;
   
}



Measured memory_bytes: 3200
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  long long X, K, D;
  cin >> X >> K >> D;

  long long d = abs(X / D);
  long long r = K - d;

  if (r <= 0) {
    cout << abs(X) - D * K << endl;
  } else {
    if (r % 2 == 0) {
      cout << abs(X) - d * D << endl;
    } else {
      cout << abs(abs(X) - (d + 1) * D) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void){

  int a,b;
  scanf("%d %d", &a, &b);
	char s[a+b+2];
	scanf("%s", s);
	int flag = 1;
	for (int i = 0; i < a+b+1; i++) {
		if (i == a) {
			if (s[i] != '-') {
				flag = 0;
				break;
			}
		} else {
			if (s[i] < '0' || s[i] > '9') {
				flag = 0;
				break;
			}
		}
	}
	if (flag == 1) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

  return 0;
}

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

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

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int main()
{
    int n,k;
    cin >> n >> k;
    ll v[n];
    rep(i,n) cin >> v[i];
    ll ans = 0;
    rep(i,k){
        for(int r = 0; r <= k; r++){
            for(int l = 0; l + r <= k; l++){
                vector<ll> vec;
                int e = k - r - l;
                if(l + r > n){
                    rep(j,n) vec.push_back(v[j]);
                }else{
                    rep(j,r) vec.push_back(v[j]);
                    rep(j,l) vec.push_back(v[n-1-j]);
                }
                sort(vec.begin(),vec.end());

                ll sum = 0,sub = 0;
                rep(id,vec.size()) sum += vec[id];
                rep(id,e){
                    if(id < vec.size() && vec[id] < 0) sub += vec[id];
                }
                ans = max(ans,sum-sub);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
int n;
const int N=1e5+10;
int A[N];
int B[N],C[N];
int sum1=0,sum2=0;
int main()
{
	init(n);
	for(int i=1;i<=n;++i) {
		init(A[i]);
		if(A[i]>=0) B[++B[0]]=A[i],sum1+=A[i];
		else        C[++C[0]]=A[i],sum2+=A[i];
	}
	sort(B+1,B+1+B[0]),sort(C+1,C+1+C[0]);
	reverse(B+1,B+1+B[0]);
	if(!B[0]) {
		printf("%d\n",-sum2+C[C[0]]*2);
		int x=C[C[0]];
		for(int i=C[0]-1;i;--i) {printf("%d %d\n",x,C[i]);x=x-C[i];}
	}else if(!C[0]) {
		printf("%d\n",sum1-2*B[B[0]]);
		if(B[0]==2) printf("%d %d\n",B[1],B[2]);
		else{
			printf("%d %d\n",B[B[0]],B[1]);
			int x=B[B[0]]-B[1];
			for(int i=2;i<B[0]-1;++i) {printf("%d %d\n",x,B[i]);x=x-B[i];}
			printf("%d %d\n",B[B[0]-1],x);
		}
	}else{
		printf("%d\n",abs(sum1)+abs(sum2));
		int x=B[1];
		for(int i=1;i<C[0];++i) {
			printf("%d %d\n",x,C[i]);
			x=x-C[i];
		}
		int y=C[C[0]];
		for(int i=2;i<=B[0];++i) {
			printf("%d %d\n",y,B[i]);
			y=y-B[i];
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}


Measured memory_bytes: 2688
#include <stdio.h>

int main(){
  int n, i, j;
  int prime[10001];
  for(i = 2; i <= 10000; i++) {
    prime[i] = 1;
  }
  for(i = 2; i*i <= 10000; i++) {
    if(prime[i]) {
      for(j = 2 * i; j <= 10000; j += i) {
        prime[j] = 0;
      }
    }
  }
  while(1){
    scanf("%d", &n);
    if(n == 0) break;
    for(i=n ; i >= 5 ; i--){
      if(prime[i] && prime[i-2]) break;
    }
    printf("%d %d\n", i - 2, i);
  }
  return 0;
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef pair<int, int> P;

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {  // TODO
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  int ans = 0;
  rep(is, 1 << h) rep(js, 1 << w) {
    int cnt = 0;
    rep(i, h) rep(j, w) {
      if (is >> i & 1) continue;
      if (js >> j & 1) continue;
      if (s[i][j] == '#') cnt++;
    }
    if (cnt == k) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){

int N,k,i;
ll X=0,x=0,z,ans=1000000000000000000LL;

cin >> N;

std::vector<ll> a(N);

for(k=0;k<N;k++){
  cin >> a[k];
  X+=a[k];
}

for(i=0;i<N;i++){
  x+=a[i];

  z=abs(X-2*x);

  if(i+1<N)ans=min(ans,z);

}

cout << ans << endl;


}


Measured memory_bytes: 4824
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int count;

    struct Connection {
        public List<int> list;
        public Connection(int index)
        {
            list = new List<int>();
        }
    }

    static void Main()
    {
        var nm = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = nm[0];
        var M = nm[1];
        var connection = new Connection[N];
        for (int j = 0; j < N; ++j) connection[j] = new Connection(j);
        for (int i = 0; i < M; ++i)
        {
            var ab = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
            var a= ab[0];
            var b = ab[1];
            connection[ab[0] - 1].list.Add(ab[1]-1);
            connection[ab[1] - 1].list.Add(ab[0] - 1);
        }
        var stack = new Stack<int>();
        stack.Push(0);
        Dfs(stack,N,connection);
        Console.WriteLine(count);
    }

    static void Dfs(Stack<int>stack,int N,Connection[] connection)
    {
        if (N <= stack.Count)
        {
            count++;
            return;
        }
        var visit = stack.Peek();
        var length = connection[visit].list.Count();
        for (int i=0;i<length;++i)
        {
            if (!stack.Contains(connection[visit].list[i]))
            {
                stack.Push(connection[visit].list[i]);
                Dfs(stack,N,connection);
                stack.Pop();
            }
        }
    }
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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


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

    int N; cin >> N;
    vi a(N); REP(i, N) cin >> a[i];
    int ans = INF;
    for(int i = -100; i <= 100; i++)
    {
        int cost = 0;
        REP(j, N)
        {
            cost += (a[j] - i) * (a[j] - i);
        }
        chmin(ans, cost);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define lg2 std::__lg
#define EB emplace_back

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

int n;
std::vector <pr> E;
inline void link(int x, int y) {E.EB(std::minmax(x, y));}
int main() {
	int i, u, v;
	scanf("%d", &n);
	if (n & (n - 1)) puts("Yes");
	else return puts("No"), 0;
	link(n + 1, n + 2);
	for (i = 2; i < n; i += 2) link(1, i), link(1, i + 1), link(i, i + n + 1), link(i + 1, i + n);
	if (!(n & 1)) u = 1 << lg2(n + 1), v = (n + 1) & ~u, link(u, 2 * n), link(v, n);
	std::sort(E.begin(), E.end());
	for (const pr &e : E) printf("%d %d\n", e.first, e.second);
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N+1);
  vector<int> B(N);
  
  for (int i=0; i<N+1; i++) {
    cin >> A[i];
  }
  for (int i=0; i<N; i++) {
    cin >> B[i];
  }
  
  int64_t ans = 0;
  for (int i=0; i<N; i++) {
    if (A[i] >= B[i]) {
      A[i] -= B[i];
      ans += B[i];
    }
    
    else {
      ans += min(B[i], A[i] + A[i+1]);
      A[i+1] -= min(B[i] - A[i], A[i+1]);
      A[i] = 0;
    }
  }
  
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin>>n>>k;
	ll ans=0;
	FOR(i, 1, n+1){
		if(-2*i%k!=0){
			continue;
		}
		int m1=i/k+1;
		int m2=(i+n)/k;
		ll tmp=m2-m1+1;
		ans+=tmp+tmp*(tmp-1);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  int sum=0;
  REP(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  double mean=sum/double(n);
  int mu=int(mean);
  if(mu>=0 && mu!=int(mean+0.5)) mu++;
  if(mu<0 && mu!=int(mean-0.5)) mu--;
  int ans=0;
  REP(i,n) ans+=int(pow(mu-a[i],2));
  cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		// TODO ?????????????????????????????????????????????
		int n,q,i,j,ans=0,left,right,mid,key;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int s[]=new int[n];
		for(i=0;i<n;i++){
			s[i]=sc.nextInt();
		}
		q=sc.nextInt();
		int t[]=new int[q];
		for(j=0;j<q;j++){
			t[j]=sc.nextInt();
		}

		for(j=0;j<q;j++){
			key=t[j];
			left=0;
		    right=n;
		    while(left<right){
		    	mid=(left+right)/2;

			    if(s[mid]==key){
			    	left=right+1;
			        ans++;
			    }else if(key<s[mid]){
			    	right=mid;
			    }else{
			    	left=mid+1;
			    }
			}


		}
		System.out.println(ans);



	}

}

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

int main() {
  int a;
  cin >> a;
  int aa = a*a;
  int aaa = a*a*a;
  cout << a + aa + aaa << endl;
}

Measured memory_bytes: 3628
def pow_r(x, n,s):
    """
    O(log n)
    """
    x=x%s
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        x%=s
        K%=s
        n //= 2

    return K * x%s
n,a,b=map(int,input().split())
s=10**9+7
ma=1
for i in range(a):
    ma*=(n-i)
    ma%=s
ama=ma
for i in range(a,b,1):
    ma*=(n-i)
    ma%=s
bma=ma

mi=1
for i in range(a):
    mi*=(i+1)
    mi%=s
ami=mi
for i in range(a,b,1):
    mi*=(i+1)
    mi%=s
bmi=mi

if n==2:
    print(0)
else:
    print((pow_r(2,n,s)%s-(ama*pow_r(ami,s-2,s)%s+bma*pow_r(bmi,s-2,s)%s)-1)%s)

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

using namespace std;

template<class T>
void copy(vector<T> from, vector<T> to) {
  copy(from.begin(), from.end(), back_inserter(to));
}

template<class T>
void sort(vector<T> a) {
  sort(a.begin(), a.end());
}

template<class T>
void input_to(vector<T> a) {
  T a_i;
  cin >> a_i;
  a.push_back(a_i);
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if (b - a == c - b) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

int main()
{
	int N;
	long long K;
	cin >> N >> K;
	vector<long long> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	long long gcd = A[0];
	long long ma = A[0];
	for( int i = 1; i < N; i++ ) {
		gcd = __gcd( gcd, A[i] );
		if( A[i] > ma ) ma = A[i];
	}
	string ans = "POSSIBLE";
	if( K > ma || K % gcd ) {
		ans = "IMPOSSIBLE";
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
<?php

[$A, $B, $C] = fscanf(STDIN, "%d%d%d");
[$X] = fscanf(STDIN, "%d");

for ($i = 0; $i < $X; $i++) {
    if($A>=$B){
        $B *= 2;
    }else if($B>=$C){
        $C *= 2;
    }else{
        echo 'Yes';
        return;
    }
}

if($A<$B and $B<$C){
    echo 'Yes';
}else{
    echo 'No';
}

?>

Measured memory_bytes: 16148
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W  = sc.nextInt();
		int a  = sc.nextInt();
		int b  = sc.nextInt();
		
		if(a + W < b) {
			System.out.println(b - a - W);
		} else if(a <= b && b <= a + W) {
			System.out.println(0);
		} else if(b <= a && a <= b + W) {
			System.out.println(0);
		} else {
			System.out.println(a - b - W);
		}
		
	}
}


Measured memory_bytes: 21844
N=int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

total =	sum(B)

for ii in range(N-1):
    if A[ii]-A[ii+1] ==	-1:
        total += C[A[ii]-1]

print(total)



Measured memory_bytes: 3060
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,X,Y = imn()

ans = [0 for _ in range(N)]
for i in range(1,N+1):
    for j in range(i+1, N+1):
        index = min(j-i, abs(X-i)+1+abs(Y-j))
        ans[index] += 1
for i in range(1,N):
    print(ans[i])

Measured memory_bytes: 5680
#include<stdio.h>
#include<stdlib.h>

struct DATA{
	int n;
	int d;
}d1[1001],d2[1001],*p;

int cmp(const void *a,const void *b){
	struct DATA q = *(struct DATA *)a;
	struct DATA w = *(struct DATA *)b;
	return q.n-w.n;
}

struct ANS{
	int n;
	int c;
}a[1000];
int main(){
	int i,j,k,l,n,m;
	int q,w,e,r,t,y;
	char prev;
	char c;

	i = 0;
	p = d1;
	q = 0;
	prev = 0;
	y = 0;
	while(scanf("%c",&c) != EOF){y++;
		if(c == '\n' && prev == '\n'){
			p = d2;
			w = i;//d1 length
			i = 0;
			continue;
		}
		prev = c;
		if(c == ','){
			p[i].n = q;
			q = 0;
		}else if(c == '\n'){
			p[i].d = q;
			q = 0;
			i++;
		}else{
			q *= 10;
			q += (c-'0');
		}
	}

	qsort(d1,w,sizeof(struct DATA),cmp);
	qsort(d2,e = i,sizeof(struct DATA),cmp);

/*
	puts("");
	for(i = 0;i < w;i++){
			printf("%d %d\n",d1[i].n,d1[i].d);
		}
	puts("");
		for(j = 0;j < e;j++){
			printf("%d %d\n",d2[j].n,d2[j].d);
		}
	puts("");
*/

	k = 0;
	for(i = 0;i < w;i++){
		for(j = 0;j < e;j++){
			if(d1[i].n == d2[j].n){
				//printf("%d %d\n",i,j);
				a[k].n = d1[i].n;
				a[k].c += 2;
				for(l = i+1;;l++){
					if(l >= w){
						i = l-1;
						break;
					}
					if(d1[i].n == d1[l].n)a[k].c++;
					else{
						i = l-1;
						break;
					}
				}
				for(l = j+1;;l++){
					if(l >= e){
						j = l-1;
						break;
					}
					if(d2[j].n == d2[l].n)a[k].c++;
					else{
						j = l-1;
						break;
					}
				}
				k++;
			}
		}
	}
//printf("%d\n",k);
	for(i=0;i<k;i++) printf("%d %d\n",a[i].n,a[i].c);
	return 0;
}

Measured memory_bytes: 560
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long int gcd(long long int a,long long int b)
{
    while(a % b != 0)
    {
        int r = a % b;
        a = b;
        b = r;
    }
    return b;
}
int main()
{
    long long int n,m;
    string s,t;
    cin >> n >> m >> s >> t;
    long long int g = gcd(m,n);
    long long int l = n * m / g;
    n /= g;
    m /= g;
    bool flag = true;
    for(int i = 0;i < g;i++)
    {
        if(s[i * n] != t[i * m])
        {
            flag = false;
            break;
        }
    }
    if(flag)
    {
        cout << l << "\n";
    }
    else
    {
        cout << "-1\n";
    }

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void){
  int A,B,K;
  int i;
    scanf("%d",&K);
    scanf("%d %d",&A,&B);

     for(i=A;i<=B;i++){
        if (i%K==0){
           printf("OK\n");
           return 0;
        }
     }
     printf("NG\n");
     return 0;
}
     

Measured memory_bytes: 1624
using System;

class Program
{
    static void Main(string[] args)
    {
        int A = int.Parse(Console.ReadLine());
        int B = int.Parse(Console.ReadLine());
        int C = int.Parse(Console.ReadLine());
        int X = int.Parse(Console.ReadLine());
        int ans = 0;
       
        if (A * 500 + B * 100 + C * 50 < X) { ans = 0; }
        else
        {
            for (int i = 0; i < A+1; i++)
            {
                for(int j = 0; j < B+1; j++)
                {
                    for(int k = 0; k < C+1; k++)
                    {
                        if(i * 500 + j * 100 + k * 50 == X) { ans++; }
                    }
                }
            }
        }
        Console.WriteLine(ans);
      
    }
}

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

using namespace std;

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
    if (!item.empty()) {
            elems.push_back(item);
        }
    }
    return elems;
}

int main() {
    string s;
    vector<string> v;
    cin >> s;
    v = split(s, '/');

    int y = std::stoi(v[0]);
    int m = std::stoi(v[1]);
    int d = std::stoi(v[2]);

    bool ok = false;

    if(y < 2019) {
        ok = true; 
    } else if (y == 2019) {
        if(m < 4) {
            ok = true;
        } else if(m == 4) {
            if (d <= 30) {
                ok = true;
            }
        }
    }

    if(ok) {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256