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

long long int cal_max(long long int N_M, long long int K_M){

  return K_M*(2*N_M-K_M+1)/2;
  /*long long int first_M=N_M*(N_M+1)/2;
  long long int second_M=(N_M-K_M+1)*(N_M-K_M+2)/2;

  return first_M-second_M;*/
}

long long int cal_min(long long int K_m){
  return (K_m-1)*K_m/2;
}

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

  if(n<k){
    cout << "1" << endl;
    return 0;
  }
  
  long long int M,m;
  long long int sum=0;
  for(long long int i=k;i<=n+1;++i){
    M=cal_max(n,i);
    m=cal_min(i);
    sum+=M-m+1;
  }
  sum %= 1000000007;
  cout << sum << endl;
  
  return 0; 
}


Measured memory_bytes: 3592
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


# N = 10
# M = 9
# K = 3
# ARR = [
#     [10, 1],
#     [6, 7],
#     [8, 2],
#     [2, 5],
#     [8, 4],
#     [7, 3],
#     [10, 9],
#     [6, 4],
#     [5, 8],
# ]
#
# BRR = [
#     [2, 6],
#     [7, 5],
#     [3, 1],
# ]
#
# fl = [[] for i in range(N)]
# bl = [[] for i in range(N)]

N,M,K = list(map(int,input().split()))

ARR = []

for i in range(M):
    ARR.append(list(map(int,input().split())))

BRR = []
for i in range(K):
    BRR.append(list(map(int,input().split())))

unionFind = UnionFind(N)

fl = [[] for i in range(N)]
bl = [[] for i in range(N)]
for ar in ARR:
    fromNode = ar[0] - 1
    toNode = ar[1] - 1
    unionFind.union(fromNode, toNode)
    fl[fromNode].append(toNode)
    fl[toNode].append(fromNode)

for br in BRR:
    fromNode = br[0] - 1
    toNode = br[1] - 1
    bl[fromNode].append(toNode)
    bl[toNode].append(fromNode)

result = []
for i in range(N):
    size = unionFind.size(i) - 1


    for f in fl[i]:
        if unionFind.same(i,f):
            size = size - 1
    for b in bl[i]:
        if unionFind.same(i,b):
            size = size - 1

    result.append(str(size))

print(" ".join(result))


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N;
    cin>>N;
    vl A(N), B(N), C(N);
    map<long, long> Ai, Aj;
    REP(i, 0, N) cin >> A[i];
    B.assign(A.begin(), A.end());
    C.assign(A.begin(), A.end());
    REP(i, 0, N){
        B[i] += i;
        Ai[B[i]]++;
        C[i] -= i;
        C[i] *= -1;
        Aj[C[i]]++;
    }
    long ans = 0;
    for(auto& [key, value] : Ai){
       // cout << key << " " << value << " " <<  Aj[key] << endl;
        ans += value * Aj[key];
    }
    cout << ans << endl;
}

Measured memory_bytes: 42196
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<map>
#include<set>
#define ll long long
#define dou(s) atof(s.c_str())
#define lon(s) atoll(s.c_str())
#define str(n) to_string(n)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define fion(n) fixed<<setprecision(n)
#define endl "\n"
#define OR ||
#define AND &&
#define NOT !
#define line(s) getline(cin,s)
#define fdarst(a,n) (a[a.size()-1]>=n&&a[lower_bound(ALL(a),n)-a.begin()]==n?lower_bound(ALL(a),n)-a.begin():-1)
#define fist(s,t) ((int)s.find(t))
#define START int main(){cin.tie(0);ios::sync_with_stdio(false);
#define END }
using namespace std;
ll n,k;
vector<ll> w;
ll value(ll key){
  ll t,i=0;
  rep(o,0,k){
    t=0;
    while(t+w[i]<=key){
      t+=w[i];
      i++;
      if(i==n)return 2*n;
    }
  }
  return -1;
}
ll mini(ll lkey,ll rkey/*ここも調べる*/,ll joken){
  ll mkey;
  while(lkey!=rkey){
    mkey=(lkey+rkey)/2;
    if(value(mkey)>=joken)rkey=mkey;
    else lkey=mkey+1;
  }
  return rkey;
}
START
cin>>n>>k;
ll ww;
rep(i,0,n){cin>>ww;w.push_back(ww);}
cout<<mini(-1000000000,1000000000,n)<<endl;
END


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

using namespace std;

#define MAXN 100

int a[MAXN+5], vis[MAXN+5];

int main()
{
    int n;
    scanf("%d", &n);
    int mn, mx, fb, sb, c;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    if (n == 2) {
        if (a[0] == a[1]) goto possible;
        else goto impossible;
    }
    sort(a,a+n);
    mn = a[0], mx = a[n-1];
    if (mx > 2*mn) goto impossible;
    if (mx < 2*mn-1) goto impossible;
    if (a[n-1] != a[n-2]) goto impossible;

    vis[0] = 1; vis[n-2] = 1; vis[n-1] = 1;
    fb = mn, sb = mx-mn;
    c = 1;
    for (int i = 1; c < sb && i < n-2; ++i) {
        if (vis[i]) continue;
        if (a[i] == fb+c) {
            vis[i] = 1;
            ++c;
        }
    }
    if (c != sb) goto impossible;
    c = 1;
    for (int i = 1; c < fb && i < n-2; ++i) {
        if (vis[i]) continue;
        if (a[i] == sb+c) {
            vis[i] = 1;
            ++c;
        }
    }
    if (c != fb) goto impossible;
    for (int i = 1; i < n-2; ++i) {
        if (vis[i]) continue;
        if (a[i] < fb+1) goto impossible;
        vis[i] = 1;
    }
    for (int i = 0; i < n; ++i) {
        if (!vis[i]) goto impossible;
    }

possible:
    puts("Possible");
    return 0;

impossible:
    puts("Impossible");
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
  int N;
  cin >> N;
 
  int ans = 99999999;
 
  for(int i=0;i<=N;i++){
    int count = 0;
    int t = i;
    while(t > 0){
      count += t % 6;
      t /= 6;
    }
    t = N - i;
    while(t > 0){
      count += t % 9;
      t /= 9;
    }
 
    if(ans > count)
      ans = count;
  }
 
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

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

	cin >> N >> M;
	vector<pair<int, int>>v(N);
	for (auto &i : v)cin >> i.first >> i.second;
	sort(v.begin(), v.end());
	vector<pair<int, int>>box(M);
	for (auto &i : box)cin >> i.first >> i.second;
	vector<int>node(N + 1);
	sort(v.begin(), v.end());
	for (int i = 0; i < N; i++) {
		node[i] ^= v[i].second;
		node[i + 1] ^= v[i].second;
	}
	vector<int>ans;
	map<pair<int, int>, int>edgemp;
	for (int i = 0; i < M; i++) {
		auto a = lower_bound(v.begin(), v.end(), make_pair(box[i].first, 0)) - v.begin();
		auto b = lower_bound(v.begin(), v.end(), make_pair(box[i].second, 2)) - v.begin() - 1;
		if (a > b)continue;
		edgemp[{a, b + 1}] = i + 1;
	}
	vector<vector<int>>edge(N + 1);
	for (auto i : edgemp) {
		edge[i.first.first].push_back(i.first.second);
		edge[i.first.second].push_back(i.first.first);
	}
	vector<int>depth(N + 1, MOD);
	for (int i = 0; i <= N; i++) {
		if (depth[i] != MOD)continue;
		depth[i] = 0;
		queue<int>Q;
		Q.push(i);
		vector<int>rev;
		while (!Q.empty()) {
			int cn = Q.front();
			Q.pop();
			for (auto j : edge[cn]) {
				if (depth[j] > depth[cn] + 1) {
					depth[j] = depth[cn] + 1;
					Q.push(j);
					rev.push_back(j);
				}
			}
		}
		reverse(rev.begin(), rev.end());
		for (auto j : rev) {
			if (node[j]) {
				node[j] = 0;
				for (auto k : edge[j]) {
					if (depth[k] < depth[j]) {
						node[k] ^= 1;
						ans.push_back(edgemp[{min(j, k), max(j, k)}]);
						break;
					}
				}
			}
		}
	}
	if (accumulate(node.begin(), node.end(), 0)) {
		cout << -1 << endl;
		return 0;
	}
	sort(ans.begin(), ans.end());
	cout << ans.size() << endl;
	for (auto i : ans)cout << i << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 19924
#include <iostream>

using namespace std;

int main(){
  int s_h[3],s_m[3],s_s[3];
  int e_h[3],e_m[3],e_s[3];
  int t_h[3],t_m[3],t_s[3];
  int diff[3];
  int temp;
  
  for(int i=0;i<3;i++){
    cin>>s_h[i]>>s_m[i]>>s_s[i]>>e_h[i]>>e_m[i]>>e_s[i];
    diff[i]=(e_h[i]*3600+e_m[i]*60+e_s[i])-(s_h[i]*3600+s_m[i]*60+s_s[i]);
    t_h[i]=diff[i]/3600;
    temp=diff[i]%3600;
    t_m[i]=temp/60;
    t_s[i]=temp%60;
  }

  for(int i=0;i<3;i++){
    cout<<t_h[i]<<" "<<t_m[i]<<" "<<t_s[i]<<endl;
  }
}



Measured memory_bytes: 3088
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include<math.h>
typedef long long int ll;
int main()
{
  ll n,i;
  cin>>n;
  vector<pair<ll,ll> > vec;
  ll a[n];
  for(i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(i=0;i<n;i++)
  {
      vec.push_back(make_pair(a[i],i+1));
  }
  sort(vec.begin(),vec.end());
  for(i=0;i<vec.size();i++)
    cout<<vec[i].second<<" ";

}


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

int main(){
	int N,T,c,t,ans=1001;
	cin>>N>>T;
  	for(int i=0;i<N;++i){
    	cin>>c;
    	cin>>t;
      	if(t<=T)ans=min(ans,c);
    }if(ans!=1001)cout<<ans<<endl;
  	else cout<<"TLE"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(ll i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll> 
#define inf 100000000000000
#define mod 1000000007

const ll max_n = 1e5 + 9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int main()
{
    ll n , m;
    cin >> n >> m;

    ll height[n];
    ll max_height[n];

    for(ll i = 0 ; i < n ; i++){
        cin >> height[i];
        max_height[i] = 0;
    }

    for(ll i = 0 ; i < m ; i++){
        ll x , y;
        cin >> x >> y;
        max_height[x-1] = max(max_height[x-1] , height[y-1]);
        max_height[y-1] = max(max_height[y-1] , height[x-1]);
    }

    ll cnt = 0;
    for(ll i = 0 ; i < n ; i++){
        if(max_height[i] < height[i]){
            // debug(i);
            // debug(max_height[i]);
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 5196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005],d[100005];
bool cmp(ll x,ll y){
    return x>y;
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        d[i]=-1;
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        *upper_bound(d+1,d+1+n,a[i],cmp)=a[i];
    }
    cout<<lower_bound(d+1,d+1+n,-1,cmp)-d-1<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ef emplace_front
#define sz(V) ((int)(V).size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ld, ld> pdd;
ld operator * (const pdd &a, const pdd &b) { return a.first*b.second - b.first*a.second; }
ld ccw(const pdd &a, const pdd &b, const pdd &c) { return a*b + b*c + c*a; }

deque<pdd> CH;

ld DX, DY;
ll L;
int N;

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> L;
	CH.ef(0, 0);
	for(ld v, t; N--;) {
		cin >> t >> v;
		DX += v; DY += v*t;
		for(; 1 < sz(CH) && CH[sz(CH)-2].first + DX > L; CH.pop_back());
		if(1 < sz(CH) && CH.back().first + DX > L) {
			ld sx, sy, ex, ey;
			tie(sx, sy) = CH[sz(CH)-2];
			tie(ex, ey) = CH.back();
			CH.back().first = L - DX;
			CH.back().second = sy + (ey-sy)/(ex-sx)*(L-sx-DX);
		}
		for(; 1 < sz(CH) && ccw({-DX, -DY}, CH[0], CH[1]) >= 0; CH.pop_front());
		CH.ef(-DX, -DY);
		printf("%.20Lf\n", (CH.back().second + DY) / L);
	}
	return 0;
}

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

const int MAX_N = 110000;

int dp[MAX_N];
int main() {
	int n;
	cin >> n;

	for (int i = 0; i < MAX_N; i++) dp[i] = n;
	dp[0] = 0;

	for (int i = 1; i <= n; i++) {
		for (int pow_six = 1; pow_six <= i; pow_six *= 6) {
			dp[i] = min(dp[i], dp[i - pow_six] + 1);
		}
		for (int pow_nine = 1; pow_nine <= i; pow_nine *= 9) {
			dp[i] = min(dp[i], dp[i - pow_nine] + 1);
		}
	}

	cout << dp[n] << endl;
	return 0;
}

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

int main(){
    ll n;
    string s;   cin >> n >> s;
    vector<ll> rc(s.size()+1), gc(s.size()+1), bc(s.size()+1);
    
    rc.at(n)=0, bc.at(n)=0, gc.at(n)=0;
    for(ll i=n-1; 0<i; i--){ 
        if(s[i]=='R'){
            rc.at(i) = rc.at(i+1)+1;
            gc.at(i) = gc.at(i+1);
            bc.at(i) = bc.at(i+1);
        }else if(s[i]=='G'){
            rc.at(i) = rc.at(i+1);
            gc.at(i) = gc.at(i+1)+1;
            bc.at(i) = bc.at(i+1);
        }else{
            rc.at(i) = rc.at(i+1);
            gc.at(i) = gc.at(i+1);
            bc.at(i) = bc.at(i+1)+1;
        } 
    }
    ll cnt=0;
    for(ll i=0; i<n-2; i++){
        for(ll j=i+1; j<n-1; j++){
            if(s[i] == s[j]) continue;
            ll k=j+1;
            
            if((s[i]=='R' && s[j]=='G')||(s[i]=='G'&&s[j]=='R')){
                if(k-j<=j-i && 2*j-i<n)
                    if(s[2*j-i]=='B') cnt -= 1LL;
                cnt += bc.at(k);
            }else if((s[i]=='R' && s[j]=='B')||(s[i]=='B'&&s[j]=='R')){ 
                if(k-j<=j-i && 2*j-i<n)
                    if(s[2*j-i]=='G') cnt -= 1LL;
                cnt += gc.at(k);
            }else{
                if(k-j<=j-i && 2*j-i<n)
                    if(s[2*j-i]=='R') cnt -= 1LL;
                cnt += rc.at(k);
            }
                  
        }
    }
    cout << cnt << endl;
}

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

static const long MAX = 1000;
static const long VMAX = 10000;

long n, A[MAX], s;
long B[MAX], T[VMAX + 1];

long solve(){
	long ans = 0;
	bool V[MAX];
	for (long i = 0; i < n; i++){ // ?????????
		B[i] = A[i];
		V[i] = false;
	}
	sort(B, B + n);
	for (long i = 0; i < n; i++) T[B[i]] = i; // ??????????????????
	for (long i = 0; i < n; i++){
		if (V[i]) continue; // True?????¨??????????£???°???
		long cur = i, S = 0, m = VMAX, an = 0;
		while (1){
			V[cur] = true; // ???????????????????????\??£?????????
			an++; // ?????????????????¨??????1?????°???
			long v = A[cur]; // ???????????????????´?
			m = min(m, v); // ???????????????????°????????¨????
			S += v; // ?????????????????°?????????????¨????
			cur = T[v]; // ??????index??????????????¢??????
			if (V[cur]) break; // ?????£??????????????????
		}
		ans += min(S + (an - 2) * m, m + S + (an + 1) * s); // ?°???????????????????
	}
	return ans;
}

int main(){
	cin >> n;
	s = VMAX;
	for (long i = 0; i < n; i++){
		cin >> A[i];
		s = min(s, A[i]);
	}
	long ans = solve();
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
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; }
using namespace std;

//ABC137
signed main(void){

    int n, m; cin >> n >> m;
    vector<vector<int>> job(m + 1);
    rep(i, n){
        int a, b; cin >> a >> b;
        if(a <= m){
            job[m - a].push_back(b);
        }
    }

    priority_queue<int> que;
    int ans = 0;
    for(int day = m; day >= 0; day--){
        for(int i : job[day])que.push(i);
        if(!que.empty()){
            ans += que.top();
            que.pop();
        }  
    }
    cout << ans << endl;

}

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

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];

    long long ans = 0;
    int m = v[0];
    for (int i = 1; i < n; i++) {
        if (v[i] < m) {
            ans += m - v[i];
            v[i] = m;
        }
        m = v[i];
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4020
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]

    flag = True
    count = 0
    index = 0
    while flag :
        flag = False
        for i in reversed(range(index+1, n)) :
            if nums[i-1] > nums[i] :
                nums[i-1], nums[i] = nums[i], nums[i-1]
                count += 1
                flag = True
        index += 1

    nums_str = [str(i) for i in nums]
    print(" ".join(nums_str))
    print(count)

if __name__ == '__main__' :
    main()

Measured memory_bytes: 7804
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
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; }

ul N,M,ans;

inline void solve(){
  IN2(N,M);
  if(2*N<=M){
    M-=2*N;
    ans+=N;
    ans+=M/4;
  }else{
    ans=M/2;
  }
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n;
	cin>>n;
	vector<int>arr;
	while(n>0){
		arr.push_back(n%26);
		n/=26;
	}
	stack<char>ch;
	for(int i=0; i<arr.size(); i++){
		if(arr[i]>0){
			ch.push((char)(arr[i]+'a'-1));
		}
		else{
			if(i!=arr.size()-1){
				arr[i+1]--;
				arr[i]+=26;
				ch.push((char)(arr[i]+'a'-1));
			}
		}
	}
	while(ch.size()){
		cout<<ch.top();
		ch.pop();
	}
}

Measured memory_bytes: 3112
#include <stdio.h>

int main(void)
{
	int W,H,x,y,r;
	
	scanf("%d %d %d %d %d ",&W,&H,&x,&y,&r);
	
	if(x+r>W||r>x)
	{
	printf("No\n");
	}
	
	else if(y+r>H||r>y)
	{
	printf("No\n");
	}
	else
	{
	printf("Yes\n");
	}
	
	return 0;
}


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

int main(void) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int l[n];
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(l, l + n);

    ll ans = 0;
    rep(i, 0, n) rep(j, i + 1, n) rep(k, j + 1, n) {
        if (l[k] < l[i] + l[j]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

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

    int N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> AB;
    int tmp_A, tmp_B;
    for (int i = 0; i < N; i++) {
        cin >> tmp_A >> tmp_B;
        AB.push_back(make_pair(tmp_A, tmp_B));
    }
    sort(AB.begin(), AB.end());
    reverse(AB.begin(), AB.end());

    ll ans = 0;
    while (M > 0) {
        if (M - AB[N - 1].second >= 0) {
            ans = ans + (AB[N - 1].first * AB[N - 1].second);
            M -= AB[N - 1].second;
            AB.pop_back();
            N--;
        } else {
            ans += (AB[N - 1].first * M);
            M = 0;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 2420
#include<stdio.h>
int main()
{
    int h, w;
    scanf("%d %d", &h, &w);
    char a[10][10];
    int i, j;
    for (i = 0; i < h; i++)
        scanf("%s", a[i]);
    int x, y;
    x = y = 0;
    while (x < h && y < w)
    {
        if (x == h - 1 && y == w - 1)
        {
            if (a[x - 1][y] == '#' && a[x][y - 1] == '#')
            {
                printf("Impossible\n");
                return 0;
            }
            else
                break;
        }
        if (x == h - 1)
        {
            if (a[x][y + 1] == '#')
            {
                if (y > 0)
                {
                    if (a[x][y - 1] == '#' && a[x - 1][y] == '#')
                    {
                        printf("Impossible\n");
                        return 0;
                    }
                }
                y++;
                continue;
            }
            else
            {
                printf("Impossible\n");
                return 0;
            }
        }
        if (y == w - 1)
        {
            if (a[x + 1][y] == '#')
            {
                if (x > 0)
                {
                    if (a[x - 1][y] == '#' && a[x][y - 1] == '#')
                    {
                        printf("Impossible\n");
                        return 0;
                    }
                }
                x++;
                continue;
            }
            else
            {
                printf("Impossible\n");
                return 0;
            }
        }
        if (a[x][y + 1] == '#' && a[x + 1][y] == '#')
        {
            printf("Impossible\n");
            return 0;
        }
        if (a[x][y + 1] == '#')
        {
            y++;
            continue;
        }
        if (a[x + 1][y] == '#')
        {
            x++;
            continue;
        }
    }
    printf("Possible\n");
    return 0;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  if((A+B)%2==0){
    cout << (A+B)/2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<deque>
using namespace std;

int main() {

    int v, d;
    while(cin >> v >> d && (v || d)) {
        deque<int> fib (v);
        fib[0] = 2;
        fib[1] = 3;
        for(int i = 2; i < v; i++) {
            fib[i] = (fib[i-1] + fib[i-2]) % 1001;
        }
        sort(fib.begin(), fib.end());

        int sets = 1;
        int now = fib.front();
        fib.pop_front();
        while(!fib.empty()) {
            if(fib.front() - now >= d) {
                sets += 1;
            }
            now = fib.front();
            fib.pop_front();
        }

        cout << sets << endl;

    }
     
    return 0;
}

Measured memory_bytes: 0
using System;
using System.Linq;

namespace abc113_b
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int ret = 0; double min = double.MaxValue;
			for (int i = 0; i < n; i++)
			{
				double now = x[0] - a[i] * 0.006;
				now = Math.Abs(x[1] - now);
				if (min > now)
				{
					ret = i + 1; min = now;
				}
			}
			Console.WriteLine(ret);
		}
	}
}

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

using namespace std;

int main(){
    int w,h;
    while(true){
        cin >> w >> h;
        if(w==0 && h==0){
            break;
        }
        for(int i=0;i<w;i++){
            for(int y=0;y<h;y++){
                if(i==0||y==0||y==h-1||i==w-1){cout << "#";}
                else{ cout << "."; }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define popb pop_back
#define all(A) A.begin(),A.end()
#define dic unordered_map //Diccionario
#define bpc __builtin_popcountll //numero de bits para long long
#define bclz __builtin_clzll //leading zeros
 
using namespace std;
 
//Funtions here
int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> dp(n,INT_MAX);
	for(int i=0;i<n;i++) cin>>a[i];
	dp[0]=0;
	for(int i=0;i<n;i++){
		if(i+1<n) dp[i+1]=min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
		if(i+2<n) dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 3872
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int lli;
int main()
{
  ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
  lli a[5],i;
  for(i=0;i<5;i++)
  {
      cin>>a[i];
      if(a[i]==0)
      {
          cout<<i+1<<"\n";
          break;
      }
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define inf 2000000000
#define INF 1e18
typedef long long ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll a[15];
int main()
{
    fastread;
     ll i,j,k,n,m,x,y,t;
     for(i=1;i<=5;i++)
     cin>>a[i];
    for(i=1;i<=5;i++){
        if(a[i]==0){
        cout<<i<<endl;
        break;
        }
        
    }
 
   return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll t;
    cin >> t;
    REP(_, t){
        ll n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << floor_sum(n, m, a, b) << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b){
	return b ? gcd(b, a % b) : a;
}
int main(){
	int T;
	scanf("%d", &T);
	for(int i = 0; i < T; i += 1){
		long long A, B, C, D;
		scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
		if(A < B){
			printf("No\n");
			continue;
		}
		long long sD = gcd(B, D);
		A = A % B;
		A +=  (B - A) / sD * sD;
		if(A == B) A -= sD;
		if(A > C){
			printf("No\n");
			continue;
		}
		A = (A + sD) % B;
//		printf("%lld %lld %lld %lld %lld\n", A, B, C, D, sD);
		if(A + D < B) printf("No\n");
		else printf("Yes\n");
	}
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<char, char> PC;

int n, m, num;
int co[110];
vector<P> vp;

bool flag(P a, P b){
	if (a.first == b.first)return a.second < b.second;
	return a.first > b.first;
}

int main(){
	while (cin >> n >> m&&n + m){
		REP(i, n){
			REP(j, m){
				cin >> num;
				co[j] += num;
			}
		}
		REP(i, m)vp.push_back(P(co[i], i+1));
		sort(ALL(vp), flag);
		REP(i, m){
			if (i == m - 1){
				cout << vp[i].second << endl;
			}
			else{
				cout << vp[i].second << " ";
			}
			co[i] = 0;
		}
		vp.clear();
	}
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
using namespace std;
using lli = long long int;
const int limit = 100010;

using edge = struct{int to; lli cost;};
vector<edge> tree[limit];//edge型を格納するvectorを配列で宣言
lli depth[limit];

void dfs(int v,int p,lli d){//今いる頂点、今いる頂点の親、今いる頂点から求めたい頂点までの距離。
	depth[v] = d;
	for(auto &e : tree[v]){
		if(e.to == p)continue;//親に行かないようにする
		dfs(e.to,v,d + e.cost);//子、今いる頂点を親とする、今いる頂点までの距離＋今いる頂点から子までの距離
	}
}

int main(){
	int n;
	cin >> n;
	
	for(int i=0;i<n-1;i++){
		int a,b,c;
		cin >> a >> b >> c;
		a--,b--;
		tree[a].push_back({b,c});
		tree[b].push_back({a,c});
	}
	
	int q,k;
	cin >> q >> k;
	k--;
	
	dfs(k,-1,0);
	for(int i=0;i<q;i++){
		int x,y;
		cin >> x >> y;
		x--,y--;
		cout << depth[x] + depth[y] << endl;
	}
	return 0;
}


Measured memory_bytes: 14336
use proconio::input;
use rand::Rng;
use std::collections::BTreeSet;

const N: i64 = 1000000;

fn main() {
   input! {
      dn: usize,
      c: [i64; 26],
      s: [[i64;26]; dn],
   }

   let mut t = vec![];
   let mut last = vec![BTreeSet::new(); 26];
   for i in 0..26 {
      last[i].insert(0);
      last[i].insert(dn + 1);
   }
   for d in 0..dn {
      let mut mx = std::i64::MIN;
      let mut tn = 0;
      for t in 0..26 {
         let mut score = 0i64;
         score += s[d][t];
         for j in 0..26 {
            if j != t {
               score -= c[j] * (d + 1 - last[j].range(..=d).rev().next().unwrap()) as i64;
            }
         }
         if score > mx {
            mx = score;
            tn = t;
         }
      }
      last[tn].insert(d + 1);
      t.push(tn);
   }

   let mut rng = rand::thread_rng();
   for i in 0..N {
      let d = rng.gen_range(0, dn);
      let q = rng.gen_range(0, 26);
      if t[d] == q {
         continue;
      }
      let p = t[d];
      let mut score = 0;
      score -= s[d][p];
      score += s[d][q];
      let f1 = last[p].range(..=d).rev().next().unwrap();
      let b1 = last[p].range(d + 2..).next().unwrap();
      let f2 = last[q].range(..=d).rev().next().unwrap();
      let b2 = last[q].range(d + 2..).next().unwrap();
      score -= c[p] * (d + 1 - f1) as i64 * (b1 - (d + 1)) as i64;
      score += c[q] * (d + 1 - f2) as i64 * (b2 - (d + 1)) as i64;
      let temp: f64 = 1000.0 / ((i + 1) as f64);
      if score > 0 || rng.gen_range(0.0, 1.00) <= (score as f64 / temp).exp() {
         t[d] = q;
         last[p].remove(&(d + 1));
         last[q].insert(d + 1);
      }
   }
   for &t in t.iter() {
      println!("{}", t + 1);
   }
}


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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int n;cin>>n;
  int a[n]; rep(i, n){ cin>>a[i]; }

  int cnt = 0;
  int kuri = 0;
  rep(i, n){
    if (a[i]>0 and kuri){
      cnt += 1;
      cnt += (a[i]-1)/2;
      kuri = (a[i]-1)%2;
    }
    else if (a[i]>0){
      cnt += (a[i]+kuri)/2;
      kuri = (a[i]+kuri)%2;
    }
    else if (a[i]==0){
      kuri = 0;
    }
  }
  cout << cnt << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 1024
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
    int n;cin>>n;
  	int k;cin>>k;
  int count=1;
  	for(int i=k;i<n;i++){
    	count ++;
    }
  cout<<count<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Mon Jul  1 11:43:19 2019

@author: Yamazaki Kenichi
"""
from collections import deque

N, M = map(int,input().split())
uv = [list(map(int,input().split())) for i in range(M)]
S, T = map(int,input().split())

Ta = [[] for i in range(3*N+1)]
for c in uv:
    Ta[c[0]].append(c[1]+N)
    Ta[c[0]+N].append(c[1]+2*N)
    Ta[c[0]+2*N].append(c[1])

check = [0 for i in range(3*N+1)]

q = deque([S])
check[S] = 1
counta = 0
flg = False
while len(q) > 0:
    for i in range(len(q)):
        nexts = Ta[q.popleft()]
        for next_ in nexts:
            if check[next_] != 1:
                q.append(next_)
                check[next_] = 1
    counta += 1
    if check[T] == 1:
        flg = True
        break
if flg:
    print(counta//3)
else:
    print(-1)

Measured memory_bytes: 119524
import java.util.*;

public class Main {
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		String s=scan.next();
		if (s.contains("7")) {
			System.out.print("Yes");
		}else {
			System.out.print("No");
		}
	
}
}
//end

Measured memory_bytes: 35716
#include <bits/stdc++.h>
#define ll     long long int 
#define pb     push_back
#define umap   unordered_map
#define mod    1000000007
#define all(x) (x).begin(), (x).end()
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes 
//__builtin_ctz(x)      to count the number of trailing zeroes 
//__gcd(a,b)
using namespace std;
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 ll n,D;
 cin>>n>>D;
 ll val=D*D;
 ll x,y;
 int num=0;
 for(int i=1;i<=n;i++)
 {
   cin>>x>>y;
   if((x*x+y*y)<=val)
     num++;
 }
 cout<<num;
}

Measured memory_bytes: 3640
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
using namespace std;
int num(int a, int b, int c) {
	return abs(b - a) + abs(c - b);
}
signed main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	typedef pair<int, int> p;
	p v[100005];
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		v[i] = p(a, b);
	}
	sort(v, v + m);
	int now = v[0].second-1;
	int cnt = 0;
	for (int i = 1; i < m; i++) {
		if (v[i].second-1 < now)now = v[i].second-1;
		if (v[i].first > now) {
			cnt += 1;
			now = v[i].second-1;
		}
	}
	cnt += 1;
	cout << cnt;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;

int a, n;

int solve(int curr, double rest, int a2, int n2)
{
    if(a2 > a || n2 > n)
        return 0;
    if(rest < -EPS)
        return 0;
    if(rest < EPS)
        return 1;
    if(rest - (1.0 / curr) * (n - n2) > EPS)
        return 0;
    if(a2 * curr > a)
        return 0;

    int ret = solve(curr, rest - (1.0 / curr), a2 * curr, n2 + 1);
    ret += solve(curr + 1, rest, a2, n2);

    return ret;
}

int main()
{
    for(;;){
        int p, q;
        cin >> p >> q >> a >> n;
        if(q == 0)
            return 0;
        cout << solve(1, (double)p/q, 1, 0) << endl;
    }
}

Measured memory_bytes: 864
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1000100;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
ll ans;
int n,a[N],l[N],r[N],i;
int main(){
	//freopen("1.out","w",stdout);
	n=read();
	for(i=1;i<=n;i++)a[i]=read();
	for(i=1;i<=n;i++)
	for(l[i]=i-1;a[l[i]]>a[i];l[i]=l[l[i]]);
	for(i=n;i;i--)
	for(r[i]=i+1;a[r[i]]>a[i];r[i]=r[r[i]]);
	for(i=1;i<=n;i++)
		ans+=1ll*a[i]*(i-l[i])*(r[i]-i);
	write(ans);puts("");
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> vec(100001, 0);
  vector<int> primeFlag(100001, 0);
  vec[1] = 0; primeFlag[1] = 0; vec[3] = 1; primeFlag[3] = 1;
  for(int i=5; i<=100000; i+=2){
    bool isPrime = true;
    for(int j=2; j*j<=i; j++){
      if(i % j == 0) isPrime = false;
    }
    if(isPrime) primeFlag[i] = 1;
    if(isPrime && primeFlag[(i+1)/2] == 1){
      vec[i] = vec[i-2]+1;
    }else{
      vec[i] = vec[i-2];
    }
  }
  rep(i, n){
    int l, r;
    cin >> l >> r;
    cout << vec[r]-vec[l-2] << endl;
  }
  return 0;
}
    
      
      

Measured memory_bytes: 1408
from collections import deque

s=deque(list(input()))
q=int(input())

right=True
rev=False
for i in range(q):
    t=input().split()
    if t[0]=="1":
        right=not right
    if t[0]=="2":
        f=int(t[1])
        c=t[2]
        if f==1:rev=True
        else:rev=False

        if right^rev:
            s.append(c)
        else:
            s.appendleft(c)

if not right:
    s.reverse()
ans="".join(list(s))
print(ans)

Measured memory_bytes: 8420
def main():
    n,m = map(int, input().split())

    array = []
    for i in range(n):
        if i == 0:
            array = set(list(map(int,input().split()))[1:])
        else:
            A = list(map(int,input().split()))
            k = A[0]
            A = set(A[1:])
            array = array & A
    print(len(array))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n';
#define optimize( ) ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    optimize();
    int a,b;
    cin>>a>>b;
    string s1,s2,s3,s4;
    s3=to_string(a);
    s4=to_string(b);
    for(int i=0;i<b;i++){
        s1+=s3;
    }
    for(int i=0;i<a;i++){
        s2+=s4;
    }
    if(s1<s2){
        cout<<s1<<endl;
    }
    else{
        cout<<s2<<endl;
    }
    return 0;
}



Measured memory_bytes: 3692
#include <iostream>

using namespace std;

int main()
{
	int a, b, x;
	
	cin >> a >> b >> x;
	
	if (a > x || a + b < x) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	
	return (0);
}

Measured memory_bytes: 256
//Ring
#include<iostream>
#include<cstring>
using namespace std;

int main()
{
	char s[101],p[101],ss[201];
	
	cin >> s >> p;
	strcat(ss,s);
	strcat(ss,s);

	if(strstr(ss, p) != NULL)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3068
import math

K = int(input())
count = 0

A = [[0 for _ in range(K+1)] for _ in range(K+1)]
for j in range(K+1):
    for i in range(K+1):
        A[j][i] = math.gcd(j,i)

for k in range(1, K+1):
    for j in range(1, K+1):
        temp = A[k][j]
        for i in range(1, K+1):
            count += A[temp][i]
print(count)

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

int main() {
    int n, m, cnt = 0;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int a;
        cin >> a;
        if(a > m) cnt++;
    }
    cout << cnt << endl;
    return 0;
}



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

int n,q;
string tit[111],date[111],name[111];

bool ok1(string a,string b){
  if(b=="*")return 1;
  r(i,a.size()){
    if(i+(int)b.size()>a.size())return 0;
    int f=0;
    r(j,b.size()){
      if(a[i+j]!=b[j])f=1;
    }
    if(!f)return 1;
  }
  return 0;
}

bool ok3(string a,string b,string c){
  if(b=="*"&&c=="*")return 1;
  else if(b=="*"){
    return a<=c;
  }
  else if(c=="*"){
    return b<=a;
  }
  else{
    return b<=a && a<=c;
  }
}

int main(){
  cin>>n;
  r(i,n){
    cin>>tit[i];
    cin>>name[i];
    cin>>date[i];
  }
  cin>>q;
  r(jj,q){
    string a,b,c,d;
    cin>>a>>b>>c>>d;
    r(i,n){
      if(!ok1(tit[i],a))continue;
      if(!ok1(name[i],b))continue;
      if(!ok3(date[i],c,d))continue;
      cout<<tit[i]<<endl;
    }
    if(jj!=q-1)cout<<endl;
  }
}



Measured memory_bytes: 3240
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)


#define MAX_V 100000
vector<int> G[MAX_V];   //???
vector<int> rG[MAX_V];  //??????
vector<string> str;

void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
}

void dfs(int v, bool used[MAX_V], vector<int> &vs){     //????????????????????????????????????????????????????????????????????????vs?????\????????????
    used[v] = true;
    rep(i,G[v].size()){
        if(!used[G[v][i]])dfs(G[v][i],used,vs);
    }
    vs.push_back(v);
}

void rdfs(int v,int k,vector<int> &sccs, vector<int> &cmp, bool used[MAX_V]){   //??????????????£???????????????????????????????????????DFS
    used[v] = true;
    sccs.push_back(v);
    cmp[v] = k;
    rep(i,rG[v].size()){
        if(!used[rG[v][i]])rdfs(rG[v][i],k,sccs,cmp,used);
    }
}

int scc(int V, vector< vector<int> > &each_scc, vector<int> &cmp){
    vector<int> vs;
    bool used[MAX_V];
    rep(i,MAX_V)used[i] = false;
    vs.clear();
    rep(v,V){
        if(!used[v]) dfs(v, used, vs);
    }
    
    rep(i,MAX_V) used[i] = false;
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
        vector<int> sccs;
        if(!used[vs[i]]){
            rdfs(vs[i], k++, sccs, cmp, used);
            each_scc.push_back(sccs);
        }
    }
    return k;
}
/*
 add_edge(hoge,fuga);
 vector<vector<int>> each_scc;  //????????????????????£?????????????????????
 vector<int> cmp(MAX_V);        //???????????????????±??????????????????£??????????????????( ??????each_scc????????????????????? )
 int k = scc(v,each_scc,cmp);   //?????£?????????????????°
 */


int main(){
    int v,e;
    cin>>v>>e;
    rep(i,e){
        int s,t;
        cin>>s>>t;
        add_edge(s,t);
    }
    vector<vector<int>> each_scc;  //????????????????????£?????????????????????
    vector<int> cmp(MAX_V);        //???????????????????±??????????????????£??????????????????( ??????each_scc????????????????????? )
    int k = scc(v,each_scc,cmp);   //?????£?????????????????°

    int q;
    cin>>q;
    rep(i,q){
        int u,v;
        cin>>u>>v;
        cout<<(cmp[u]==cmp[v])<<endl;
    }
}

Measured memory_bytes: 9388
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int sum[212345];
    string X;
    cin >> X;

    int res = X.size();

    int cnt = 0;

    REP(i, X.size())
    {
        if (X[i] == 'S')
        {
            cnt++;
        }
        else
        {
            if (cnt > 0)
            {
                cnt--;
                res -= 2;
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 720
#include<iostream>

using namespace std;

int main()
{
	int N;
	int cnt = 0;
	cin >> N;

	for(int i=0;i<N;i++)
	{
		int a;
		cin >> a;

		if(a%2 == 1)cnt++;
	}

	if(cnt%2==0)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

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

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

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};

signed main(){
    int r;
    cin >> r;
    PRINT(3 * r * r);
    return 0;
}

Measured memory_bytes: 256