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

int main(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int ans = 0;
    if(m2 < m1){
        ans = 60 * (h2 - h1) - (m1 - m2);
    }else {
        ans = 60 * (h2 - h1) + (m2 - m1);
    }
    ans -= k;
    if(ans < 0) ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 3636
/*
NOTE :
*min_element(.begin(),.end())
*max_element(.begin(),.end())
stack push pop top
queue push pop front
priority_queue<> pq
 push()  pop() size()  top()
map<>
 find() begin() end() insert(map<>::value_type())
pair<>
sort(.begin(), .end())
sort(arr, arr+N)
sort(a, a+N, greater<int>())
binary_search(vc.begin(), vc.end(), x)  //binary_search???true, false?????????
vector<int>::iterator lit = lower_bound(vc.begin(), vc.end(), x);
  lower_bound?????????????????????"??\???"????????????????????????????????????????????¬???????????????
vector<int>::iterator uit = upper_bound(vc.begin(), vc.end(), x);
  upper_bound????????????????????????"?¶???????"?????????????????????????????????????????¬???????????????
*/
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cassert>
#include <sstream>
#include <algorithm>
#include <valarray>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

#define MAX 100
#define INF 1<<20
#define LLINF 10e12 // 1<<31 // 2^31
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,a,n) for(int i=(a);i<(n);i++)
#define SET(a,c) memset(a,c,sizeof a)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique(ALL((o))), (o).end());
#define SQ(x) ((x)*(x))

using namespace std;
typedef long long ll;
typedef valarray<int> array_t;
/////

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // FROM HERE
  double v;
  while(cin >> v)
  {
    double h = 0.5 * v * v / 9.8;
    printf("%d\n",((int)(h*0.2)+1)+1);
  }
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;
const ll LINF = 1e18;

int main(){
  int n,k;
  cin >> n >> k;
  vector<ll> v(n);
  rep(i,n) cin >> v[i];
  sort(all(v));
  ll ans = INF;
  for(int i=0;(i+k-1)<n;i++){
    chmin(ans,abs(v[i+k-1] - v[i]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
using System;
class latte
{
    static void Main()
    {
        while (true)
        {
            string s = Console.ReadLine();
            if (s == null) break;
 
            string[] t = s.Split();
            int a = int.Parse(t[0]);
            int b = int.Parse(t[1]);
            int c = a + b;
            Console.WriteLine(c.ToString().Length);
        }
    }
}


Measured memory_bytes: 15864
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
int main(){
  int MATHI[10][10];
  int n,a,b,c,syo;
  while(1){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++) MATHI[i][j]=1000000;
      MATHI[i][i]=0;
    }
    syo=0;
    cin >> n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin >> a >> b >> c;
      MATHI[a][b]=MATHI[b][a]=c;
      syo=max(syo,max(a,b));
    }
    for(int i=0;i<=syo;i++){
      for(int j=0;j<=syo;j++){
	for(int k=0;k<=syo;k++){
	  MATHI[j][k]=min(MATHI[j][k],MATHI[j][i]+MATHI[i][k]);
	}
      }
    }
    int no,h=1000000;
    for(int i=0;i<=syo;i++){
      int sum=0;
      for(int j=0;j<=syo;j++){
	sum+=MATHI[i][j];
      }
      if(h>sum){
	h=sum;
	no=i;
      }
    }
    cout << no << " " << h << endl;
  }
}

Measured memory_bytes: 1160
///apigs property
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second
#define pb push_back
#define vll vector< ll >
#define vi vector< int >
#define pll pair< ll , ll >
#define pi pair< int , int >
#define all(s) s.begin() , s.end()
#define sz(s) s.size()
#define md (s + e) / 2
#define mid (l + r) / 2
#define msdp(dp) memset(dp , -1 , sizeof dp)
#define mscl(dp) memset(dp , 0 , sizeof dp)
using namespace std;
typedef long long ll;
ll q, k, l, m, n, o, p;
map < ll , ll > mp;
vll adj[555555];
const ll mod = 1e9+7;
double dp[305][305][305];
double mem(ll a , ll b , ll c){
	//cout << a << " " << b << " " << c << endl;
	if(a < 0 || b < 0 || c < 0 || (!a && !b && !c))return 0.0;
	double &r = dp[a][b][c];
	if(r != -1.0)return r;
	r = 0.0;
	r = n * 1.0 / (a + b + c) * 1.0;
	if(a)r += (a * 1.0 / (a + b + c)* 1.0) * mem(a - 1 , b , c);
	if(b)r += (b * 1.0 / (a + b + c)* 1.0) * mem(a + 1, b - 1, c);
	if(c)r += (c * 1.0 / (a + b + c)* 1.0) * mem(a , b + 1, c - 1);
	//cout << r << " ";
	return r;  
}
void solve(){
	for(ll i = 0; i <= 300 ; i++)for(ll j = 0 ; j <= 300 ; j++)for(ll ii = 0 ; ii <= 300 ; ii++)dp[i][j][ii] = -1.0;
	cin >> n;
	for(ll i = 0 ; i < n ; i++){
		cin >> k;
		if(k == 1)o++;
		else if(k == 2)p++;
		else l++;
	}
	cout << fixed << setprecision(11) << mem(o , p , l);
}
int main() {
    fast ;
	// cin >> q;
    q = 1;
    while(q--){
    	solve();
	}
}



Measured memory_bytes: 233832
S = input()
flag = True
count = 0
if not S[0] == "A":
  flag = False
for i in range(2,len(S)-1):
  if S[i] == "C":
    count += 1
  else:
    if not S[i].islower():
      flag = False
if not S[1].islower():
  flag = False
if not S[len(S)-1].islower():
  flag = False
if not count == 1:
  flag = False
if flag:
  print("AC")
else:
  print("WA")

Measured memory_bytes: 9044
#include <stdio.h>

int main(void) {
	int i, x, sum = 0;
	for(i = 0; i < 5; ++i) {
		scanf("%d", &x);
		if(x < 40) {
			sum += 40;
		} else {
			sum += x;
		}
	}
	printf("%d\n", sum / 5);
	return 0;
}


Measured memory_bytes: 2740
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,x,X=0;
  long long int ans=0,sum=0;
 long long int a[100];
  cin>>n>>x;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  sort(a,a+n);
  for(int i=0;i<n;i++){
     if(x-a[i]>0){
ans++;
x-=a[i];
}
     else if(x-a[i]==0){
ans++;
break;
}
else break;
if(i==n-1) ans--;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<ll, ll> i_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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
vector<l_l> pathes[100500];
l_l parent[100500];
vector<l_l> children[100500];
ll N, T, S, E;
ll times[100500];
bool cleared[100500];

void dfs(ll now) {
    for(ll i = 0; i < pathes[now].size(); i++) {
        ll to = pathes[now][i].second;
        if(to == parent[now].second) continue;
        children[now].push_back(pathes[now][i]);
        parent[to].second = now;
        parent[to].first = pathes[now][i].first;
        dfs(to);
    }
}

void g(int now) {
    if(now == -1) return;
    for(int i = 0; i < children[now].size(); i++) {
        int to = children[now][i].second;
        if(parent[to].second == now) {
            children[now].erase(children[now].begin() + i);
            break;
        }
    }
    g(parent[now].second);
}

bool ok = true;

void f(ll now) {
    //while(!children[now].empty() && cleared[children[now].back().second]) children[now].pop_back();
    if(children[now].empty()) {
        cleared[now] = true;
        if(parent[now].first == -1) return;
        ll to = parent[now].second;
        ll cost = times[to] + times[now];
        cost *= T;
        if(parent[now].first - cost <= 0) {
            ok = false;
            return;
        }
        times[to]++;
        f(to);
        return;
    }
    ll to = children[now].back().second;
    ll cost = times[to] + times[now];
    cost *= T;
    if(children[now].back().first - cost <= 0) {
        ok = false;
        return;
    }
    children[now].pop_back();
    times[to]++;
    f(to);
}

bool comp(l_l a, l_l b) {
    ll la = a.first - T * (ll)pathes[a.second].size();
    ll lb = b.first - T * (ll)pathes[b.second].size();
    return la > lb;
}

int main() {
    //cout.precision(10);
    cin >> N >> T >> S >> E;
    for(ll i = 1; i <= N - 1; i++) {
        ll a, b, w;
        cin >> a >> b >> w;
        pathes[a].push_back({w, b});
        pathes[b].push_back({w, a});
    }
    parent[E] = {-1, -1};
    dfs(E);
    g(parent[S].second);
    for(ll i = 1; i <= N; i++) {
        sort(children[i].begin(), children[i].end(), comp);
    }
    f(S);
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 23736
import re
s = input()

r1 = '^.*keyence$'
r2 = '^k.*eyence$'
r3 = '^ke.*yence$'
r4 = '^key.*ence$'
r5 = '^keye.*nce$'
r6 = '^keyen.*ce$'
r7 = '^keyenc.*e$'
r8 = '^keyence.*$'

if re.match(r1, s) or re.match(r2, s) or re.match(r3, s) or re.match(r4, s) or re.match(r5, s) or re.match(r6, s) or re.match(r7, s) or re.match(r8, s):
    print("YES")
else :
    print("NO")

Measured memory_bytes: 3316
while true
    n, m = gets.chomp.split.map(&:to_i)
    break if [n, m] == [0, 0]
    arr1 = []
    arr2 = []
    n.times{arr1 << gets.to_i}
    m.times{arr2 << gets.to_i}
    sum1 = arr1.sort!.inject(:+)
    sum2 = arr2.sort!.inject(:+)
    diff = sum1 - sum2
    min, card = nil, []
    if diff.even?
        arr1.each{|card1|
            arr2.each{|card2|
                if (card1 == card2 + diff/2.0) && (min.nil? || min > card1 + card2)
                    min = card1 + card2
                    card = [card1, card2]
                    break
                end
            }
        }
    end
    puts min.nil? ? -1 : card.join(" ")
end


Measured memory_bytes: 6872
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a[5];
	for(int i=0;i<5;i++){
		cin>>a[i];
	}
	sort(a,a+5);
	for(int i=4;i>=0;i--){
		cout<<a[i];
		if(i!=0){
			cout<<" ";
		}
	}
	cout<<endl;
}


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

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a%b);
}

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

    int g, a, m;
    cin >> g;
    m = g;
    
    for(int i = 1; i < n; i++){
        cin >> a;
        g = gcd(g, a);
        m = max(m, a);
    }

    if(m >= k && k%g == 0){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

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

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

    vector<long long int> p(m), y(m);
    vector<vector<long long int>> data(n);// (prefecture, year), be careful with the initialization...    
    for(int i=0; i<m; i++){
        cin >> p[i] >> y[i];
        data[p[i] - 1].push_back(y[i]);
    }

    for(int i=0; i<n; i++){
        sort(data[i].begin(),data[i].end());
    }
    for(int i=0; i<m; i++){
        cout << 
        setw(6) << setfill('0') << p[i] <<
        setw(6) << setfill('0') << lower_bound(data[p[i] - 1].begin(), data[p[i] - 1].end(), y[i]) - data[p[i] - 1].begin() + 1 <<
        endl;
    }
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <vector>

int main(){
    std::string s;
    std::cin >> s;

    int n = s.size();
    bool flg = true;
    std::string sRev = s;
    std::reverse(std::begin(sRev), std::end(sRev));
    for(int i = 0; i < n; ++i){
        flg = flg && s.at(i) == sRev.at(i);
    }

    std::string t = s.substr(0, (n - 1) / 2);
    std::string tRev = t;
    std::reverse(std::begin(tRev), std::end(tRev));
    for(int i = 0; i < t.size(); ++i){
        flg = flg && t.at(i) == tRev.at(i);
    }

    auto m = (n + 3) / 2 - 1;
    std::string u = s.substr(m, n - m + 1);
    std::string uRev = u;
    std::reverse(std::begin(uRev), std::end(uRev));
    for(int i = 0; i < u.size(); ++i){
        flg = flg && u.at(i) == uRev.at(i);
    }

    std::string ans = "No";
    if(flg){
        ans = "Yes";
    }

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

    return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int main(){
    fastcin();
    LL x;
    cin >> x;
    LL bd = 0;
    for(LL i=1; i*i*i*i*i<=x*1e9; i++) bd = i;
    for(LL i=0; i<=bd; i++){
        for(LL j=0; j<=bd; j++){
            LL a = i*i*i*i*i;
            LL b = j*j*j*j*j;
            if(a-b == x){
                cout << i << " " << j << endl;
                return 0;
            }else if(a+b == x){
                cout << i << " " << -j << endl;
                return 0;
            }
        }
    }
    return 1;
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,a,b,c,d,i,sum[3]={0},cnt=0;
cin>>n>>a>>b>>c>>d;
while(1){
	sum[1]=sum[1]+b;
	cnt=cnt+a;
	if(cnt>=n){
	break;
	}
}
cnt=0;
while(1){
	sum[2]=sum[2]+d;
	cnt=cnt+c;
	if(cnt>=n){
	break;
	}
}
if(sum[1]<=sum[2]){
printf("%d\n",sum[1]);
}
else{
printf("%d\n",sum[2]);
}
return 0;
}


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


int main() {
 ll N;
 cin >> N;
 string ans;
  if(N != 0){
 while(true){
   if(N%2 != 0){
     ans += '1';
     N = (N-1)/(-2);
   }
   else if(N%2 == 0){
     ans += '0';
     N = N/(-2);
   }
   if(N == 0)break;
 }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
  }
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
ll upperdiv(ll a, ll b){
    return (a+b-1)/b; //a/bの切り上げ
}
int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(a.begin(),a.end()); //昇順
    sort(f.begin(),f.end());
    reverse(f.begin(),f.end()); //降順
    ll mx=0;
    rep(i,n) mx+=a[i];
    if(mx<=k){
        cout << 0 << endl;
        return 0;
    }
    ll l = -1, r = (ll)1e12;
    while(l+1<r){
        ll x = (l+r)/2;
        bool ok = [&](ll c){
            ll tot=0;
            rep(i,n) tot+=max(ll(0),a[i]-(c/f[i]));
            //rep(i,n) cout << "i:" << i << ", " << max(ll(0),a[i]-c/f[i]) << " " << a[i] << endl;
            //cout << c << " " << tot << " " << k << endl;
            return tot<=k;
        }(x);
        if(ok) r=x; else l=x;
    }
    cout << r << endl;
    return 0;
}

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

using namespace std;

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

  int answer = 0;
  for (int countA = 0; countA <= A; countA++) {
    int a = countA * 500;

    if (a > X) {
      break;
    }
    if (a == X) {
      answer++;
      continue;
    }

    for (int countB = 0; countB <= B; countB++) {
      int b = countB * 100 + a;

      if (b > X) {
        break;
      }
      if (b == X) {
        answer++;
        continue;
      }

      for (int countC = 0; countC <= C; countC++) {
        int c = countC * 50 + b;

        if (c > X) {
          break;
        }
        if (c == X) {
          answer++;
          break;
        }
      }
    }
  }

  cout << answer << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
	final Scanner sc=new Scanner(System.in);
	int syakkin=100000;
	int n=sc.nextInt();
	for(int i=0;i<n;i++){
	    syakkin*=1.05;
	    if(syakkin%1000!=0){
		syakkin=((syakkin/1000)+1)*1000;
	    }
	}
	System.out.println(syakkin);
    }
}

Measured memory_bytes: 17156
from collections import deque
def dfs(graph, N, start, points):
    visited = [0] * N
    visited[start] = 1
    stack = deque([(start, points[start])])
    ret = [0] * N
    while stack:
        edge, point = stack.pop()
        ret[edge] = point
        for e in graph[edge]:
            if not visited[e]:
                visited[e] = 1
                stack.append((e, point + points[e]))
    return ret

N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(lambda n: int(n) - 1, input().split())
    graph[a].append(b)
    graph[b].append(a)
points = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    points[p - 1] += x
print(*dfs(graph, N, 0, points))

Measured memory_bytes: 67412
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int main(){
  vector<int> v(10);
  rep(i,10) cin>>v[i];
  sort(v.rbegin(),v.rend());
  rep(i,3) cout<<v[i]<<endl;
}

Measured memory_bytes: 0
using System;

namespace agc029a
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int N = S.Length;
            int bcount = 0;
            long count = 0;
            for(int i = 0; i<N;i++){
                if(S[i]=='B'){//Bの個数をひたすらカウント
                    bcount++;
                }else{
                    count += bcount;//Wであれば、これまでのBの個数がWの移動数
                }
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 13140
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

class Seg_sum():
    def __init__(self,x):
        #####単位元######
        self.ide_ele_min = 0
        self.func = lambda a,b : a+b

        self.n = len(x)

        #num_max:n以上の最小の2のべき乗
        self.num_max =2**(self.n-1).bit_length()
        self.x = [self.ide_ele_min]*2*self.num_max

        for i,num in enumerate(x, self.num_max):
            self.x[i] = num
        for i in range(self.num_max-1,0,-1):
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def update(self,i,x):
        i += self.num_max
        self.x[i] = x
        while(i>0):
            i = i//2
            self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1])

    def query(self,i,j):
        res = self.ide_ele_min
        if i>=j:
            return res
        i += self.num_max
        j += self.num_max -1
        while(i<=j):
            if(i==j):
                res = self.func(res,self.x[i])
                break
            if(i&1):
                res = self.func(res,self.x[i])
                i += 1
            if(not j&1):
                res = self.func(res,self.x[j])
                j -= 1
            i = i>>1
            j = j>>1
        return res

n = int(readline())
xy = [ list(map(int,i.split()))  for i in readlines()]
mod = 998244353

xy.sort()
ys = [i[1] for i in xy]
ys.sort()
y_rank = {}
for i,y in enumerate(ys):
    y_rank[y] = i


point = [[0,0] for _ in range(n)]
for i,(x,y) in enumerate(xy):
    point[i][0] = i
    point[i][1] = y_rank[y]

seg = Seg_sum([0] * (n+10))

cnt = [[0,0,0,0] for _ in range(n)]
for x,y in point:
    cnt[x][2] = seg.query(0,y)
    cnt[x][1] = seg.query(y,n)
    cnt[x][0] = n-y-1 - cnt[x][1]
    cnt[x][3] = y - cnt[x][2]
    seg.update(y,1)

ex2 = [1] * (n)
for i in range(1,n):
    ex2[i] = (ex2[i-1]*2)%mod

ans = (ex2[n-1] * n) % mod
for n1,n2,n3,n4 in cnt:
    ans += (ex2[n1]-1)*(ex2[n3]-1)*ex2[n2+n4]
    ans %= mod
    ans += (ex2[n2]-1)*(ex2[n4]-1)*ex2[n1+n3]
    ans %= mod
    ans -= (ex2[n1]-1)*(ex2[n2]-1)*(ex2[n3]-1)*(ex2[n4]-1)
    ans %= mod

print(ans)

Measured memory_bytes: 187772
#include <bits/stdc++.h>
using namespace std;
int a[30];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    int cnt=0;
    for(int i=2;i<n;i++){
        if((a[i]<a[i+1]&&a[i]>a[i-1])||(a[i]>a[i+1]&&a[i]<a[i-1])) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

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

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

#define MAX_N 100010

int N, x;
int a[MAX_N];
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> x;
    ll ans = 0;
    REP(i,N) cin >> a[i];
    REP(i,N-1) {
        if (a[i]+a[i+1]>x) {
            ans += min(a[i+1]+a[i]-x,a[i+1]);
            a[i+1] -= min(a[i+1]+a[i]-x,a[i+1]);
            
        }
        if (a[i]+a[i+1]>x) {
            ans+= a[i]-x;
            a[i] -= a[i]-x;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 640
loop do
	line = gets
	if !line then
		break
	end
	a = line.split.map{|v| v.to_i}
	b = gets.split.map{|v| v.to_i}

	hit = 0
	brow = 0

	4.times do |i|
		if a[i] == b[i]
			hit += 1
		elsif a.index(b[i])
			brow += 1
		end
	end

	puts "#{hit} #{brow}"
end

Measured memory_bytes: 6104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
 
int bignumber(int a, int b){
    if(a>b){
        return(a);
    } else {
        return(b);
    }
}
 
int main(void){
    int a1,a2,a3;
    scanf("%d%d%d",&a1,&a2,&a3);
    int b1=abs(a1-a2),b2=abs(a2-a3),b3=abs(a3-a1);
    int ans=b1+b2+b3-bignumber(bignumber(b1,b2),b3);
    printf("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
from heapq import heapify, heapreplace
n = int(input())
a = list(map(int, input().split()))
a1 = a[:n]
heapify(a1)
a2 = a[n:2*n]
a3 = [-i for i in a[2*n:]]
heapify(a3)
b1 = [sum(a1)]
b2 = [sum(a3)]
for i in range(n):
    b1.append(a2[i]-heapreplace(a1, a2[i]))
    b2.append(-heapreplace(a3, -a2[n-i-1])-a2[n-i-1])
for i in range(n):
    b1[i+1] += b1[i]
    b2[i+1] += b2[i]
accu = []
mx = b1[0]
for i in b1:
    mx = max(mx, i)
    accu.append(mx)
ans = -10**16
mx = b2[0]
for i in range(n+1):
    mx = max(mx, b2[i])
    ans = max(ans, mx+accu[n-i])
print(ans)

Measured memory_bytes: 42932
def solve(x, y, a, b, c, p, q, r):
    p = sorted(p)[::-1]
    q = sorted(q)[::-1]
    r = sorted(r)[::-1]
    v = sorted(p[:x] + q[:y])
    n = len(v)
    t = sum(v)
    i = 0
    for k in range(c):
        if (i < n) and (v[i] < r[k]):
            t += r[k] - v[i]
            i += 1
    return t

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
print(solve(x, y, a, b, c, p, q, r))

Measured memory_bytes: 23328
n,T=map(int,input().split())
c=[0]*n
t=[0]*n
ans=[]
for i in range(n):
    c[i],t[i]=map(int,input().split())
    if t[i]<=T:
        ans.append(c[i])
if len(ans)==0:
    print("TLE")
    exit()
print(min(ans))


Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n,l;cin>>n>>l;
    ll a[n];
    rep(i,n){cin>>a[i];}
    ll cur;
    rep(i,n-1){
        if(a[i]+a[i+1]>=l){
            cur=i+1;
            break;
        }
        if(i==n-2){
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
    for(int i=1;i<cur;i++){
        cout << i << endl;
    }
    for(int i=n-1;i>cur;i--){
        cout << i << endl;
    }
    cout << cur << endl;
    return 0;
}


Measured memory_bytes: 1664
import java.io.IOException;
import java.util.Scanner;
public class Main {

	static int W;
	static int H;
	static int x;
	static int y;
	static int r;

	static boolean judge = true;

	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		W = sc.nextInt();
		H = sc.nextInt();
		x = sc.nextInt();
		y = sc.nextInt();
		r = sc.nextInt();

		String ans;

		check1();
		check2();
		check3();

		if(judge) {
			ans = "Yes";
		}else {
			ans = "No";
		}

		System.out.println(ans);

		sc.close();
	}

	public static void check1() {
		if(x<0 || y<0) {
			judge = false;
		}
	}

	public static void check2() {
		if((x-r)<0 || (y-r)<0) {
			judge = false;
		}
	}

	public static void check3() {
		if((x+r)>W || (y+r)>H) {
			judge = false;
		}
	}
}


Measured memory_bytes: 26280
n, m = map(int, input().split())
x = (n + 1) // 2
cnt_l = -(-m // 2)
cnt_r = m // 2
ans = []
for i in range(cnt_l):
    ans.append((i+1, x-i))
for i in range(cnt_r):
    ans.append((x+1+i, 2*x-i-1))

for i in range(m):
    print(*ans[i])

Measured memory_bytes: 21164
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<queue>
#define int long long
using namespace std;
int test[123456], uiop[123456];
signed main() {
	int n, m, k, a, b = 100000000000, ans = 0; string s, t; cin >> n >> m;
	if (n >= m) {
		for (int h = 0; h < n; h++) {
			ans = ans * 10 + m;
		}
	}
	else {
		for (int h = 0; h < m; h++) {
			ans = ans * 10 + n;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(I,N) for(int I=0;I<N;I++)
using ll=long long int;
using namespace std;
int counter=0;
int black=0;
int ans=0;
int main(){
	int h,w,k;
	cin>>h>>w>>k;
	char c[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>c[i][j];
			if(c[i][j]=='#')black++;
		}
	}

	for(int N=0;N<(1<<h);N++){
		for(int NN=0;NN<(1<<w);NN++){
			for(int jj=0;jj<h;jj++){
				for(int jjj=0;jjj<w;jjj++){
					if( (((N>>jj)&1)||((NN>>jjj)&1))&&c[jj][jjj]=='#')counter++;
				}
			}
			if(k==black-counter)ans++;
			counter=0;
		}
	}
	cout<<ans;
}



Measured memory_bytes: 3636
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.root = [-1] * (n + 1)
		self.rank = [0] * (n + 1)

	def find(self, x):
		if self.root[x] < 0:
			return x
		else:
			self.root[x] = self.find(self.root[x])
			return self.root[x]

	def unite(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return 0
		elif self.rank[x] > self.rank[y]:
			self.root[x] += self.root[y]
			self.root[y] = x
		else:
			self.root[y] += self.root[x]
			self.root[x] = y
			if self.rank[x] == self.rank[y]:
				self.rank[y] += 1

	def isSame(self, x, y):
		return self.find(x) == self.find(y)

	def size(self, x):
		return -self.root[self.find(x)]

import sys
input=sys.stdin.buffer.readline

n,m,k=map(int,input().split())
friend=UnionFind(n)
f_cnt=[0]*n
for _ in range(m):
	a,b=map(int,input().split())
	a-=1
	b-=1
	friend.unite(a,b)
	f_cnt[a]+=1
	f_cnt[b]+=1
block=[[] for _ in range(n)]
for _ in range(k):
	c,d=map(int,input().split())
	block[c-1].append(d-1)
	block[d-1].append(c-1)
ans=[]
for i in range(n):
	ret=friend.size(i)-f_cnt[i]-1
	for j in block[i]:
		if friend.isSame(i,j):
			ret-=1
	ans.append(ret)
print(*ans)

Measured memory_bytes: 102116
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) ((x) * (x))
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas
#define fname "parray"
#define fin fname".in"
#define fout fname".out"
#define files freopen(fin, "r", stdin);freopen(fout, "w", stdout);
namespace IO {

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a);

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a);

    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


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

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int p = n - 1;
    int c = 0;
    rep(i, 0, n) {
        if (s[i] == 'R')continue;
        while (p >= 0 && s[p] == 'W') --p;
        if (p < i) continue;
        ++c;
        swap(s[p], s[i]);
    }
    put(c);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
//    files
    int q = 1;
//    cin >> q;
    while (q--) solve();
}



Measured memory_bytes: 3424
import java.util.Scanner;
  
public class Main {
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
   int n=sc.nextInt();
   int i = 1;      
    while(i <= n){
     if(i % 3 == 0){
      System.out.print(" " + i);
     }else{
      int Check=i;          
       while(Check > 0){
        if(Check % 10 == 3){
         System.out.print(" " + i);
         break;
        }
       Check = Check / 10;
       }
     }
      i++;
    }
     System.out.println();
 }
}

Measured memory_bytes: 24468
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

#define IMIN INT_MIN;
#define IMAX INT_MAX;

int maxelem(vector<int> src) {
	int dst = IMIN;
	rep(i, src.size()) {
		dst = (dst > src[i]) ? dst : src[i];
	}
	return dst;
}

int secondelem(vector<int> src) {
	int dst = IMIN;
	int dst2 = IMIN;
	rep(i, src.size()) {
		if (dst < src[i]) {
			dst2 = dst;
			dst = src[i];
		}
		else if (dst2 < src[i]) {
			dst2 = src[i];
		}
	}
	return dst2;
}

vector<int> count(vector<int> a) {
	int ma = maxelem(a);
	vector<int> count(ma+1, 0);
	rep(i, a.size()) {
		count[a[i]]++;
	}
	return count;
}

int find(vector<int> a, int b) {
	rep(i, a.size()) {
		if (a[i] == b) return i;
	}
	return -1;
}

int main(){
	int H, W;
	cin >> H >> W;
	int c[10][10];
	rep(i, 10) rep(j, 10) cin >> c[i][j];
	int A[H][W];
	rep(i, H) rep(j, W) cin >> A[i][j];
	int cnt;

	rep(k, 10) rep(i, 10) rep(j, 10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
	rep(i, H) rep(j, W) if (A[i][j] != -1) cnt += c[A[i][j]][1];
	cout << cnt;

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9+7;
const ll LLINF = 7e18;
using namespace std;


int main(){
	int n, a;
	cin >> n >> a;
	if (a >= n%500) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



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

int main()
{
    int n, t = 0;
    double m;
    int c = 0;
    cin >> n >> m;
    int votes[n];
    for (int i = 0; i < n; i++)
    {
        cin >> votes[i];
        t += votes[i];
    }
    double x = t * (1 / (4 * m));
    for (int i = 0; i < n; i++)
    {
        if (votes[i] >= x)
        {
            c++;
        }
        if (c >= m)
        {
            cout << "Yes" << "\n";
            return 0;
        }
    }
    cout << "No" << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b)
{
    return b==0?a:gcd(b,a%b);
}
bool Is_prime(long long n) {
    for(long long i=2;i*i<=n;i++)
        if(n%i==0) return false;
    return true;
}
#define maxn 1000000
bool vis[maxn];
long long prime[maxn], x;
void isprime(long long n) {
    for(long long i=2;i<=n;i++)
    {
        if(!vis[i]) prime[x++]=i;
        for(long long j=2;j*i<=n;j++)
        {
            vis[i*j]=true;
        }
    }
}
void oulasai(long long n) {
    for(long long i=2;i<=n;i++)
    {
        if(!vis[i]) prime[x++]=i;
        for(long long j=0;j<x;j++)
        {
            if(i*prime[j]>n) break;
            vis[i*prime[j]]=true;
            if(i%prime[j]==0) break;
        }
    }
}
int main()
{
    long long A, B;
    cin >> A >> B;
    long long Gcd = gcd(A, B);
    oulasai(sqrt(Gcd));
    long long ans = 0;
    for(long long i = 0; i < x; i++) {
        if(Gcd % prime[i] == 0) {
            ans ++;
            while(Gcd % prime[i] == 0)
                Gcd /= prime[i];
        }
    }
    if(Is_prime(Gcd) == true && Gcd != 1)
        ans++;
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define endl "\n"
#define loop(i,s,e) for(int i=s;i<e;i++)
#define int long long
#define mp make_pair
#define pii pair<int,int>
#define mset(a,f)  memset(a , f , sizeof(a))
#define pb push_back
const int N = 2e6 + 6;
const int inf = 1e18;
const int M = 1e9 + 7;
int A[N];
int n;

void solve()
{
 string s;
 cin >> s;
      loop(i,0,s.length())
      {
            if(s[i] == '7')
            {
                  cout << "Yes";
                  return;
            }
      }     

      cout << "No";
}
 
int32_t main()
{
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);

       int t = 1;
       // cin >> t;
       while(t--)solve();
  
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N,0);
  for(int i = 0;i<N;i++)
  {
    cin >> A.at(i);
  }
  vector<int> B(N,0);
  for(int i = 0;i<N;i++)
  {
    B.at(A.at(i) - 1) = i + 1;
  }
  
  for(int i = 0;i<N;i++)
  {
    cout << B.at(i) << " ";
  }
  cout << endl;  
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  char c[3];
  rep(i,3)cin>>c;
  int res=700;
  rep(i,3)res+=(c[i]=='o')*100;
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const ll INF = 1e18;

struct E {
    int to, w;
};

const int N = 52, S = N * N, V = N * S;
vector<E> g[V];
int c[N], d[N];
ll dt[V];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m, s;
    cin >> n >> m >> s;

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

        for (int j = a; j < S; j++) {
            g[x * S + j].push_back({y * S + j - a, b});
            g[y * S + j].push_back({x * S + j - a, b});
        }
    }

    for (int i = 0; i < n; i++) {
        cin >> c[i] >> d[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < S; j++) {
            g[i * S + j].push_back({i * S + min(j + c[i], S - 1), d[i]});
        }
    }

    priority_queue<pair<ll, int>, 
        vector<pair<ll, int>>, 
        greater<pair<ll, int>>> q;

    fill(dt, dt + V, INF);

    int start_vertex = min(S - 1, s);
    dt[start_vertex] = 0;

    q.push({0, start_vertex});

    while (!q.empty()) {
        int node = q.top().second;
        ll cd = q.top().first;
        q.pop();

        if (cd != dt[node])
            continue;

        for (const E &e : g[node]) {
            if (dt[e.to] > dt[node] + e.w) {
                dt[e.to] = dt[node] + e.w;
                q.push({dt[e.to], e.to});
            }
        }
    }

    for (int i = 1; i < n; i++) {
        ll ans = INF;
        for (int j = 0; j < S; j++)
            ans = min(ans, dt[i * S + j]);
        cout << ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 18724
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
  int a,b,c;
  cin >> a >> b >> c;
  int test[] = {a,b,c};
  sort(test,test+3);
  cout << test[0] <<" "<< test[1] <<" "<< test[2]<<endl;


  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    int a[n], b[n], c[n-1];
    forn(i, 0, n) {
        cin >> a[i];
    }
    forn(i, 0, n) {
        cin >> b[i];
    }
    forn(i, 0, n-1) {
        cin >> c[i];
    }
    int ans = 0;
    forn(i, 0, n) {
        ans += b[a[i]-1];
        if (i && a[i-1]+1 == a[i]) {
            ans += c[a[i-1]-1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3608
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
vector<int>g[205];
int m,n,ans,mat[205];
bool vis[205];
struct mzls
{
	int x,y;
}a[205],b;
inline bool dfs(int x)
{
	for(int i=0;i<g[x].size();i++)
	{
		int v=g[x][i];
		if(vis[v])
			continue;
		vis[v]=1;
		if(!mat[v]||dfs(mat[v]))
		{
			mat[v]=x;
			return 1;
		}
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)
		scanf("%d%d",&a[i].x,&a[i].y);
	for(int i=1;i<=n;i++)
		for(int j=n+1;j<=2*n;j++)
			if(a[i].x<a[j].x&&a[i].y<a[j].y)
			{
				g[i].push_back(j);
				g[j].push_back(i);
			}
	for(int i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		ans+=dfs(i);
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for(ll i=0;i<(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    V<ll>a(n);
    set<ll>b;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b.insert(a[i]);
    }
    for(auto it=b.begin();it!=b.end();it++)
    {
        if(it!=b.begin())cout<<" ";
        cout<<*it;


    

    }
    cout<<endl;
    

    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------













































Measured memory_bytes: 8296
#include <stdio.h>
#include <math.h>
int main()
{
  double x1, y1, x2, y2, d ;
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2) ;
  d = ( x1-x2 )*( x1-x2 ) + ( y1-y2 )*( y1-y2 ) ;

  printf("%10.8f\n", sqrt(d)) ;

  return 0 ;
}


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

int main(){
  int n; long long s = 1; scanf("%d", &n);
  vector<long long> v(n); rep(i, n) scanf("%lu", &v[i]);
  rep(i, n) s = __gcd(s, v[i]) * (v[i] / __gcd(s, v[i])) * (s / __gcd(s, v[i]));
  printf("%lu\n", s);
  return 0;
}


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

int main(){
    string s;
    while(1){
        getline(cin, s);
        if(s[0] == '.') break;
        stack<char> st;
        for(int i = 0; i < s.size(); i++){
            if(s[i] == '('){
                st.push('(');
            }else if(!st.empty() && st.top() == '(' && s[i] == ')'){
                st.pop();
            }else if(s[i] == '['){
                st.push('[');
            }else if(!st.empty() && st.top() == '[' && s[i] == ']'){
                st.pop();
            }else if(s[i] == ')' || s[i] == ']'){
                st.push(s[i]);
            }
        }
        cout << (st.empty() ? "yes" : "no") << endl;
    }
    return 0;
}



Measured memory_bytes: 3156
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
c = 0
aa = 0
for a in A:
	ans += B[a - 1]
	if a - 1 == aa:
		ans += c
	aa = a
	c = C[a - 1] if a < N else 0
print(ans)


Measured memory_bytes: 8996
#include <iostream>

void outputField(char** field, int row, int column) {
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < column; j++) {
            std::cout << field[i][j];
        }
        std::cout << std::endl;
    }   
}

int countMine(char** field, int rowIndex, int columnIndex) {
    char counter = 0;
    for (int i = rowIndex - 1; i <= rowIndex + 1; i++) {
        for (int j = columnIndex - 1; j <= columnIndex + 1; j++) {
            if(field[i][j] == '#') {
                counter++;
            }
        }
    }
    return counter;
}

int main() {
    int row = 0;
    int column = 0;
    
    // 入力からフィールドを作成
    std::cin >> row >> column;
    char** field = new char*[row];
    for (int i = 0; i < row; i++) {
        field[i] = new char[column];
    }
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < column; j++) {
            std::cin >> field[i][j];
        }
    }
    
    // フィールドからカウント用フィールドを作成
    char** countField = new char*[1 + row + 1];
    countField[0] = new char[1 + column + 1];
    countField[row + 1] = new char[1 + column + 1];
    for (int i = 0; i < 1 + column + 1; i++) {
        countField[0][i] = 0;
        countField[row + 1][i] = 0;
    }
    for (int i = 0; i < row; i++) {
        countField[i + 1] = new char[1 + column + 1];
        countField[i + 1][0] = 0;
        for (int j = 0; j < column; j++) {
            countField[i + 1][j + 1] = field[i][j] == '#' ? '#' : 0;
        }
        countField[i + 1][column + 1] = 0;
    }
    
    // カウントを行う
    for (int i = 1; i < row + 1; i++) {
        for (int j = 1; j < column + 1; j++) {
            if (countField[i][j] == 0) {
                countField[i][j] = countMine(countField, i , j) + '0';
            }
        }
    }
    
    // カウント用フィールドから出力用フィールドを作成
    char** outField = new char*[row];
    for (int i = 0; i < row; i++) {
        outField[i] = new char[column];
    }
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < column; j++) {
            outField[i][j] = countField[i + 1][j + 1];
        }
    }
    
    outputField(outField, row, column);
    
    for (int i = 0; i < row; i++) {
        delete[] field[i];
        delete[] outField[i];
    }
    delete[] field;
    delete[] outField;
    
    for (int i = 0; i < 1 + row + 1; i++) {
        delete[] countField[i];
    }
    delete[] countField;
}


Measured memory_bytes: 3628
n = int(input())
h = list(map(int,input().split()))
a,b = 0,0
C = [0]*n
for i in range(n-1):
  if h[i]>=h[i+1]:
    a+=1
  else:
    C[b]=a
    b+=1
    a=0
C[b]=a
print(max(C))

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

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

typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;

int main(){
	string s;
	cin>>s;

	int c1=0,c2=0;

	char rev='0';
	for (int i = 0; i < s.size(); ++i){
		if(s[i]!=rev)
			c1++;

		if(rev=='0'){
			rev='1';
		}else{
			rev='0';
		}

	}

	rev='1';
	for (int i = 0; i < s.size(); ++i){
		if(s[i]!=rev)
			c2++;

		if(rev=='0'){
			rev='1';
		}else{
			rev='0';
		}

	}

	cout<<min(c1,c2)<<endl;


}

Measured memory_bytes: 512
H, W, K = map(int, input().split())
P = 10**9 + 7
x = K + K*(K+1)//2 + K*(K+1)*(K-1)//3*H*W*pow((H+W)*(H+W-1),P-2,P)
for i in range(H+W, H+W-K, -1):
    x *= i
    x %= P
print(x)


Measured memory_bytes: 41744
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>

using namespace std;

int main(){
	string s;
	cin >> s;
	if(s[0] == s[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e7+5;
const long long inf=0x3f3f3f3f;
long long sum;
bitset<maxn>s;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	long long n;
	cin>>n;
	s[0]=1;
	for(long long i=1;i<=n;i++)
	{
		long long x;
		cin>>x;
		s|=s<<x;
		sum+=x;
	}
	for(long long i=(sum+1)>>1;;i++)
	{
		if(s[i])
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}




Measured memory_bytes: 3968