akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env perl

use strict;
use warnings;
use bigint;

my $x = <>;
chomp $x;

sub c {
  my ($m, $n) = @_;
  $x - $n <= 5 * ($m + $n);
}

sub bsearch {
  my $plus = shift;
  my $l = 0;
  my $r = 1000000000000000;
  while ($l + 1 < $r) {
    my $n = int(($l + $r) / 2);
    if ($n + $plus >= 0 && &c($n + $plus, $n)) {
      $r = $n;
    } else {
      $l = $n;
    }
  }
  2 * $r + $plus;
}

my $xx = &bsearch(-1);
my $yy = &bsearch(0);
my $zz = &bsearch(1);

my @array = sort { $a <=> $b } ($xx, $yy, $zz);
print $array[0];


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

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

    for(int64_t A=-1000; A<=1000; A++) {
        for(int64_t B=-1000; B<=1000; B++) {
            if(A*A*A*A*A - B*B*B*B*B == X) {
                cout << A << ' ' << B << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3644
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    string S; cin >> S;
    Int res = 0;
    rep(i, 1, S.size()) {
        if (S[i-1] != S[i]) ++res;
    }

    cout << res << endl;
}


Measured memory_bytes: 512
// abc134c: Exception Handling
#include <stdio.h>

#define upto(i,s,e,d) for(int i=(s);i<=(e);i+=(d))
#define downto(i,s,e,d) for(int i=(s);i>=(e);i-=(d))
#define in(n) scanf("%d",n)
#define out(d) printf("%d\n",d)

int search(int k, int *a, int n){
  int l=0,r=n,m;
  while(l<r){ m=(l+r)/2; if(a[m]<k) r=m; else l=m+1; }
  return l;
}

int main(){
  int n;in(&n);
  int m = 1, gn = 1;
  int g[n]; in(g);
  upto(i,1,n-1,1){
    int a; in(&a);
    int j = search(a,g,gn);
    if(g[j]>=a) j++;
    g[ j<gn? j: gn++ ] = a;
  }
  out(gn);
  return 0;
}

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

int main() {
    
    int t;
    cin >> t;
    int arr[t], sum=0;
    for(int i=0; i<t; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    
    sort(arr, arr+t);
    
    sum = sum - arr[t-1];
    if(arr[t-1]>=sum) cout << "No" << endl;
    else cout << "Yes" << endl;
    

    
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  int n = s.size();
  ll ans=0;
  rep(i,1<<(n-1)){
    vector<int> index;
    rep(j,n-1){
      if(i>>j&1) index.push_back(j);
    }
    vector<string> p;
    if(index.empty()) ans+=stoll(s);
    else{
      int tmp=0;
      for(int i=0; i<index.size(); i++){
        p.push_back(s.substr(tmp,index[i]-tmp+1)); tmp=index[i]+1;
        if(i==index.size()-1) p.push_back(s.substr(tmp,n-tmp));
      }
      for(auto x : p) ans+=stoi(x);
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define F first
#define S second


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n, q;
	cin >> n;
	VI a(n); rep(i, n)cin >> a[i];
	cin >> q;
	rep(i, q) {
		int b, m, e;
		cin >> b >> m >> e;
		rotate(a.begin() + b, a.begin() + m, a.begin() + e);
	}
	rep(i, sz(a)) {
		cout << a[i];
		printf(i == sz(a) - 1 ? "\n" : " ");
	}
}


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

int n,a[205],ans=0;

bool cmp(int x,int y){return x<y;
}

int main(){
	cin>>n;
	for(int i=1;i<=2*n;i++)cin>>a[i];
	sort(a+1,a+1+2*n,cmp);
	for(int i=1;i<=2*n;i+=2)ans+=(min(a[i],a[i+1]));
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <limits>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <numeric>
#include <tuple>

constexpr long long mod = static_cast<long long>(1e9 + 7);

int main() {
  int A, B;
  std::cin >> A >> B;
  --A;
  --B;
  std::cout << 100 << ' ' << 100 << '\n';
  for(int i = 0; i < 50; ++i)
  {
    for(int j = 0; j < 100; ++j)
    {
      if (B > 0 && i % 2 == 0 && j % 2 == 0)
      {
        --B;
        std::cout << '#';
      }
      else
        std::cout << '.';
    }
    std::cout << '\n';
  }

  for(int i = 0; i < 50; ++i)
  {
    for(int j = 0; j < 100; ++j)
    {
      if (A > 0 && i % 2 == 1 && j % 2 == 0)
      {
        --A;
        std::cout << '.';
      }
      else
        std::cout << '#';
    }
    std::cout << '\n';
  }
  std::cout << std::flush;
  return 0;
}


Measured memory_bytes: 256
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    n = int(input())
    a = list(map(int, input().split()))

    #output
    answer = 0
    for i in range(1, n):
        if a[i] < a[i-1]:
            answer += a[i-1]-a[i]
            a[i] = a[i-1]

    print(answer)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Measured memory_bytes: 104696
#include <iostream>
#include <set>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int N,L;
    cin>>N>>L;
    vector <string> lexo;
    string s;
    for(int i=0;i<N;i++){
        cin>>s;
        lexo.push_back(s);
    }
    sort(lexo.begin(),lexo.end());
    auto it=lexo.begin();
    
    for(;it!=lexo.end();it++){
        cout<<*it;
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX_E 2010 // max M
#define MAX_V 1010 // max N
// #define INF 9223372036854775800
#define INF (1LL << 59)

struct edge {
  int from;
  int to;
  long long cost;
};

edge es[MAX_E];
long long d[MAX_V];
bool negative[MAX_V];
int V, E;

int main() {
  cin >> V >> E;
  for (int i = 1; i < MAX_V; i++) d[i] = INF;
  for (int i = 1; i < MAX_V; i++) negative[i] = false;

  for (int i = 1; i <= E; i++) {
    int a, b;
    long long c;
    cin >> a >> b >> c;
    es[i].from = a;
    es[i].to = b;
    es[i].cost = c * -1;
  }

  d[1] = 0;
  for (int i = 0; i < V - 1; i++) {
    for (int j = 1; j <= E; j++) {
      edge e = es[j];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
      }
    }
  }
  long long ans = d[V] * -1;

  for (int i = 0; i < V; i++) {
    for (int j = 1; j <= E; j++) {
      edge e = es[j];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        negative[e.to] = true;
      }
      if (negative[e.from]) {
        negative[e.to] = true;
      }
    }
  }

  if (negative[V]) {
    cout << "inf" << endl;
  } else {
    cout << ans << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>

std::pair<int,int> query[200010];
long long int sum1[200010],sum2[200010];

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=b;i++)
	{
		int c,d;
		scanf("%d%d",&c,&d);
		query[i] = std::make_pair(c,d);
		if(c==1) sum1[d]++;
		else sum2[d]++;
	}
	
	for(int i=1;i<=a;i++) sum1[i] += sum1[i-1];
	for(int i=1;i<=a;i++) sum2[i] += sum2[i-1];
	
	int H = a-1, W = a-1;
	long long int ans = a-2;
	ans *= (a-2);
	
	for(int i=1;i<=b;i++)
	{
		if(query[i].first==1)
		{
			if(2<=query[i].second&&query[i].second<=W)
			{
				ans -= (sum1[W]-sum1[query[i].second-1])*(H-1);
				W = query[i].second-1;
			}
		}
		else
		{
			if(2<=query[i].second&&query[i].second<=H)
			{
				ans -= (sum2[H]-sum2[query[i].second-1])*(W-1);
				H = query[i].second-1;
			}
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 6416
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>

using namespace std;

int main(){

	int A;
	int B;

	cin >> A >> B;

	if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0){
		cout << "Possible";
	}else{
		cout << "Impossible";
	}





	return 0;

}


Measured memory_bytes: 256
from math import pi, cos, sin, sqrt

A, B, H, M = map(int, input().split())

A_th = ((H / 12) + (M / 60) / 12) * 2 * pi
B_th = (M / 60) * 2 * pi
A_x, A_y = A * cos(A_th), A * sin(A_th)
B_x, B_y = B * cos(B_th), B * sin(B_th)

print(sqrt(((A_x - B_x) ** 2 + (A_y - B_y) ** 2)))

Measured memory_bytes: 9404
#include <iostream>
#include <vector>
using namespace std;
struct edge{int to,cost;};
vector<edge> G[100010];
int a[100010] = {};
bool used[100010],flag = true;
void dfs(int s, int p){
    used[s] = true;
    for(auto e:G[s]){
        if(e.to==p) continue;
        if(used[e.to] && a[e.to]!=a[s] + e.cost){
            flag = false;
            return;
        }else if(!used[e.to]){
            a[e.to] = a[s] + e.cost;
            dfs(e.to,s);
        }
    }
}

int main(){
    int i,n,m;
    cin >> n >> m;
    for(i=0;i<m;i++){
        int l,r,d;
        cin >> l >> r >> d;
        l--; r--;
        G[l].push_back({r,d});
        G[r].push_back({l,-d});
    }
    for(i=0;i<n;i++){
        used[i] = false;
    }
    for(i=0;i<n;i++){
        if(!used[i]){
            dfs(i,-1);
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 12032
H,W,A,B = map(int,input().split())
MOD = (10**9)+7
D = [0,2, 9, 11, 14, 15, 17, 19, 20, 23, 24, 25, 27, 28, 29]

def inv(a):
    ans = 1
    hoge = a
    for count in range(31):
        if (count) in D:
            ans *= hoge
            ans %= MOD
        hoge *= hoge
        hoge %= MOD
    return ans

g = [1]*(H+W)
for i in range(1,H+W):
    g[i] = (g[i-1]*i%MOD)
ans = 0
for i in range(H-A):
    L = g[B-1+i]*inv(g[B-1])*inv(g[i])
    R = g[(W-B-1)+(H-1-i)]*inv(g[(W-B-1)])*inv(g[H-1-i])
    ans += L*R%MOD
print(ans%MOD)

Measured memory_bytes: 44008
N, M = map(int, input().split())
datalist = [list(map(int, input().split())) for _ in range(N)]
tmp = 0

ans1 = []
ans2 = []
ans3 = []
ans4 = []
ans5 = []
ans6 = []
ans7 = []
ans8 = []

for i in range(N):
    tmp = (datalist[i][0] + datalist[i][1] + datalist[i][2])
    ans1.append(tmp)
    tmp = 0
ans1.sort(reverse=True)
ans1 = sum(ans1[:M])
for i in range(N):
    tmp = (datalist[i][0] + datalist[i][1] - datalist[i][2])
    ans2.append(tmp)
    tmp = 0
ans2.sort(reverse=True)
ans2 = sum(ans2[:M])
for i in range(N):
    tmp = (datalist[i][0] - datalist[i][1] + datalist[i][2])
    ans3.append(tmp)
    tmp = 0
ans3.sort(reverse=True)
ans3 = sum(ans3[:M])
for i in range(N):
    tmp = (datalist[i][0] - datalist[i][1] - datalist[i][2])
    ans4.append(tmp)
    tmp = 0
ans4.sort(reverse=True)
ans4 = sum(ans4[:M])
for i in range(N):
    tmp = (-datalist[i][0] + datalist[i][1] + datalist[i][2])
    ans5.append(tmp)
    tmp = 0
ans5.sort(reverse=True)
ans5 = sum(ans5[:M])
for i in range(N):
    tmp = (-datalist[i][0] + datalist[i][1] - datalist[i][2])
    ans6.append(tmp)
    tmp = 0
ans6.sort(reverse=True)
ans6 = sum(ans6[:M])
for i in range(N):
    tmp = (-datalist[i][0] - datalist[i][1] + datalist[i][2])
    ans7.append(tmp)
    tmp = 0
ans7.sort(reverse=True)
ans7 = sum(ans7[:M])
for i in range(N):
    tmp = (-datalist[i][0] - datalist[i][1] - datalist[i][2])
    ans8.append(tmp)
    tmp = 0
ans8.sort(reverse=True)
ans8 = sum(ans8[:M])

ans = max(ans1,ans2,ans3,ans4,ans5,ans6,ans7,ans8)
print(ans)



Measured memory_bytes: 3316
import sys

while True:
	data = map(int, raw_input().split())
	H = data[0]
	W = data[1]
	
	if H == 0 and W == 0:
		break
	else:
		for i in range(H):
			for j in range(W):
				if (i + j) % 2 == 0:
					sys.stdout.write("#")
				else:
					sys.stdout.write(".")
			print("")
		print("")

Measured memory_bytes: 6452
#include <stdio.h>
#include <math.h>
 
#define PI (3.14159265358979323846)
 
int main(void)
{
    double x = 0.0, y = 0.0;
    int now = 90;
    int spin;
    int add_m;
     
    while (1){
        scanf("%d%*c%d", &add_m, &spin);
         
        if (add_m == 0 && spin == 0) break;
         
        y += (double)add_m * sin((double)now / 180.0 * PI);
        x += (double)add_m * cos((double)now / 180.0 * PI);
         
        now -= spin;
        if (now < 0) now += 360;
        else if (now > 360) now -= 360;
    }
     
    printf("%d\n%d\n", (int)x, (int)y);
     
    return (0);
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define mx 100005
using namespace std;

int a[5], b, c;
bool t = true;
int main(){
  for(int i = 0; i < 3; i++){
    scanf("%d%d", &b, &c);
    a[b]++, a[c]++;
  }
  for(int i = 1; i < 5; i++){
    if(a[i]==3) t = false;
  }
  cout << (t ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main(){
    int n,x,ans=0;cin>>n;
    vector<int>b;
    for(int i=0;i<n-1;i++){
        cin>>x;
        b.pb(x);
    }
    ans+=b[0]+b[n-2];
    for(int i=0;i<n-2;i++){
        ans+=min(b[i],b[i+1]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <tuple>

static int R, C, K;
typedef std::pair<int, int> KEY;
typedef std::map<KEY, int> MAP;
static MAP value_map;

static std::vector<int64_t> memo;

static int64_t search(int r, int c, int k)
{
	if (r > R || c > C) {
		return 0;
	}

	const size_t memo_i = (C * (r - 1) + (c - 1)) + R*C*k;
	const int64_t memo_v = memo[memo_i];
	if (memo_v >= 0) {
		return memo_v;
	}

	int64_t v = search(r + 1, c, 0);
	v = std::max(v, search(r, c + 1, k));
	if (k < 3) {
		auto itr = value_map.find(KEY(r, c));
		if (itr != value_map.end()) {
			v = std::max(v, itr->second + search(r + 1, c, 0));
			v = std::max(v, itr->second + search(r, c + 1, k + 1));
		}
	}

	memo[memo_i] = v;

	return v;
}

int main()
{
	std::cin >> R >> C >> K;
	memo.resize(R*C * 4, -1);
	for (int i = 0; i < K; ++i) {
		int r, c, v;
		std::cin >> r >> c >> v;
		value_map.insert(MAP::value_type(KEY(r, c), v));
	}
	std::cout << search(1, 1, 0) << std::endl;
	return 0;
}

Measured memory_bytes: 297336
#include <bits/stdc++.h>
using namespace std; 
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define ld long double
#define endl "\n"
#define rep(i,a,b) for(int i=a;i<b;i++)
#define reprev(i,a,b) for(int i=b-1;i>=a;i--)
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vin(a,n) vi a(n); rep(i,0,n) cin>>a[i];
#define vout(a) rep(i,0,sz(a)) cout<<a[i]<<" "; cout<<endl;
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define inf LLONG_MAX
#define pi 3.1415926535897932384626
#define tr(container, it) \
for(auto it = container.begin(); it != container.end(); it++)

int power(int x, unsigned int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}

signed main()
{
    IOS
    char ch;
    cin>>ch;
    if(ch<'a') cout<<'A'<<endl;
    else cout<<'a'<<endl;
    return 0;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n,q;
  cin >>n>>q;
  string s;
  cin>>s;
  vector<int>l(q),r(q);
  rep(i,q)cin>>l[i]>>r[i];
  int kazu[n+1];
  rep(i,q){
    l[i]--;
    r[i]--;
  }
  rep(i,n+1)kazu[i]=0; 
  int sum=0;
  rep(i,n-1){
    if(s[i]=='A'&&s[i+1]=='C')sum++;
    kazu[i+1]=sum;
  }          
  rep(i,q){
    int kotae=kazu[r[i]]-kazu[l[i]];
    cout<<kotae<<endl;
  }
  return 0;
}

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

int N;
int const INF = INT_MAX;

struct SegmentTree {
private:
    int n;
    vector<int> node;

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

    void update(int x, int val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }

    int getmin(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return node[k];

        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int main() {
    cin>>N;
    SegmentTree seg( vector<int>(N, INF) );
    vector<long>P(N);
    for(int i=0;i<N;i++){
      cin>>P[i];
      seg.update(i,P[i]);
    }
    long ans=1;
    for(int i=N-1;i>0;i--) {
      if(P[i]<seg.getmin(0,i)){
        ans++;
      }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3824
#include <stdio.h>

long long dibisor(long long n)
{
    long long i;long long ret;
    for (i = 1; i * i <= n; i++)
    {
        if(n % i == 0)
        {
            ret = i;
        }
    }
    return ret;
}

int main()
{
    long long n;
    scanf("%lld",&n);
    long long ans = dibisor(n) - 1;
    ans += (n / dibisor(n)) - 1;

    printf("%lld",ans);
}

Measured memory_bytes: 128
N = int(input())
a = (N-1)//26
b = N%26
ans = ''
while a!=0:
  if b==0:
    b = 26
  ans = chr(b+96) + ans
  b = a%26
  a = (a-1)//26

if b==0:
  b=26
ans = chr(b+96) + ans
print(ans)

Measured memory_bytes: 61760
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

bool check(string s) {
	int c3 = 0, c5 = 0, c7 = 0;
	REP(i, SZ(s)) {
		if (s[i] == '3')c3++;
		else if (s[i] == '5')c5++;
		else if (s[i] == '7')c7++;
	}
	return (c3 != 0 && c5 != 0 && c7 != 0);
}

vector<int> n357;

void dfs(string s) {
	if (check(s))n357.PB(stoi(s));
	if (SZ(s) != 9) {
		dfs(s + "3");
		dfs(s + "5");
		dfs(s + "7");
	}
}

int main() {
	int n; cin >> n;
	string s;
	dfs(s);
	int ans = 0;
	for (auto i : n357) {
		if (i <= n)ans++;
	}
	cout << ans << endl;
}

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


int main() {
    ll H;
    cin >> H;
    ll ans = 0;
    ll i = 1;
    while (H > 0) {
        H /= 2;
        ans += i;
        i *= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    # define ll long long
    # define int long long  //comment it out when MLE
    //# define endl "\n"
    #define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //# define m 163577857
    # define mo 1000000007
    # define pi acos(-1)
    # define fi first
    # define se second
    #define REP(i,n) for (int i = 1; i <= n; i++)
    const ll mod = 1000000007;
    //const int K = 2;
    //typedef vector<vector<int> > matrix;
/*
    int add(int a, int b,int mod) {
        a%=mod;
        b%=mod;
        a += b;
        if (a >= mod) a -= mod;
        if(a<0)
        {
            a += mod;
            a %= mod;
        }
        return a;
    }

    int mul(ll a, int b,int mod) {
        a%=mod;
        b%=mod;
        a *= b;
        a += mod;
        return a % mod;
    }
    int po(int a,int b,int mod)
    {
        if(b==0)
            return 1;
        if(b%2==0)
            return po(mul(a,a,mod),b/2,mod);
        return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
    }


    ll fact[1000003];
    ll inv[1000003];

    void fact0()
    {
        int i,j;
        fact[0]=1;
        for(i=1;i<=600000;i++)
        {
            fact[i]=i*fact[i-1]%mod;
        }
        inv[0]=1;
        inv[1]=1;
        ll p=mod;
        for (i=2; i<=600000; i++)
            inv[i] = (p - (p/i) * inv[p%i] % p) % p;

        for(i=2;i<=600000;i++)
        {
            inv[i]*=inv[i-1];
            inv[i]%=mod;
        }
    }
    int help(int a,int b)
    {
       // cout<<a<<" "<<b<<endl;
        int an = fact[a];
        //cout<<an<<endl;
        an *= inv[b];
        an %= mod;
        an *= inv[a-b];
        an %= mod;
        return an;
    }*/



signed main(){
       gok

     int n;
     cin>>n;
     int a[n];
     int p=1;
     bool ch1=false;
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
         if(a[i]==0)
            ch1=true;
     }
     int ma=1000000000000000000*1.00;
     bool ch=false;
     for(int i=0;i<n;i++)
     {
         if((ma/(a[i])) < p)
         {
             ch=true;
             break;
         }
         p*=a[i];
     }
     if(ch1)
        cout<<0;
     else if(ch)
        cout<<-1;
     else
    cout<<p;
















        return 0;
    }


Measured memory_bytes: 4424
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	ArrayList<ArrayList<Integer>> g = new ArrayList<>();
	int dist[];
	boolean used[];
	int INF = 1001001001;
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		for(int i=0; i<n; i++) {
			g.add(new ArrayList<>());
		}
		dist = new int[n];
		for(int i=0; i<n; i++) {
			dist[i]=INF;
		}
		used = new boolean[n];
		for(int i=0; i<m; i++) {
			int a=sc.nextInt();
			int b=sc.nextInt();
			a--;
			b--;
			g.get(a).add(b);
			g.get(b).add(a);
		}
		bfs(0,0);
		if(dist[n-1]<=2) {
			System.out.println("POSSIBLE");
		}else {
			System.out.println("IMPOSSIBLE");
		}
		sc.close();
	}


	public void bfs(int p, int d) {
		ArrayDeque<Integer> q = new ArrayDeque<>();
		q.add(p);
		dist[p]=0;
		used[p]=true;
		while(!q.isEmpty()) {
			int s = q.poll();
			for(int i=0; i<g.get(s).size(); i++) {
				int t = g.get(s).get(i);
				if(used[t]) continue;
				used[t]=true;
				dist[t]=dist[s]+1;
				q.add(t);
			}
		}
	}


}


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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i=0;i<n;i++) cin >> d[i];
  //vectorのsort
  sort(d.begin(), d.end());
  int ans=d[n/2]-d[n/2-1];
  cout << ans << endl;
}
  

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

using namespace std;

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

    vector<int> v;
    int limit = min(a, b);
    for (int i = 1; i <= limit; ++i) {
        if (a % i == 0 && b % i == 0)
            v.push_back(i);
    }

    int divisor_count = v.size();
    cout << v[divisor_count - k] << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int visit[100009], n, m, ans;
vector<int >v[100009];
int dp[100009];
int dfs(int x)
{
    visit[x] = 1;
    int ma = 1;
    for(int i = 0; i < v[x].size(); i++)
    {
        if(!visit[v[x][i]])
        {
            ma = max(ma, 1 + dfs(v[x][i]));
        }
        else
        {
            ma = max(ma, 1 + dp[v[x][i]]);
        }
    }
    ans = max(ans, ma);
    return dp[x] = ma;
}

main()
{
    cin>>n>>m;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin>>a>>b;
        v[a].push_back(b);
    }
    for(int i = 1; i <= n; i++)
    {
        if(!visit[i])
            dfs(i);
    }
    //for(int i = 1; i <= n; i++)
      //  cout<<dp[i]<<" ";
    cout<<ans - 1;
}


Measured memory_bytes: 8576
from collections import defaultdict
n=int(input())
arr=list(map(int,input().split()))
d=defaultdict(int)
for i in arr:
	d[i]+=1
total=sum(arr)
ans=""
for i in range(int(input())):
	b,c=map(int,input().split())
	total=total-d[b]*b
	total=total+d[b]*c
	d[c]+=d[b]
	d[b]=0
	ans+=str(total)+"\n"

print(ans)

Measured memory_bytes: 24112
#include <stdio.h>

int main(void)
{
    int N;
    float p;

    scanf("%d", &N);

    p = N/2.0;

    if(p > N/2) {
        printf("%d\n", (N/2)+1);
    } else {
        printf("%d\n", N/2);
    }

    
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define ll long long
#define sz(a) int((a).size())
#define fr(i,n) for(int i=0;i<n;i++) 
#define rf(i,n) for(int i=1;i<=n;i++) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define MAX INT_MAX 
using namespace std;
#define M 1000000007
int main()
{
    int t,n;
    cin>>t>>n;
    for(int i=0;i<max(t,n);i++)
        cout<<min(t,n);
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;

int n,m,C;
string s;
int L[maxn], R[maxn];

struct ST{
  int l, r, val;
}st[maxn * 4];
void build(int id, int l,int r){
  st[id].l=l, st[id].r=r, st[id].val = 0;
  if(l==r)return;
  int m=(l+r)>>1;
  build(id<<1,l,m);
  build(id<<1|1,m+1,r);
}

void add(int id, int l,int r, int val){
  if(st[id].l==l&&st[id].r==r){
    st[id].val = max(st[id].val, val);
    return;
  }
  int m = (st[id].l+st[id].r)>>1;
  if(r<=m)add(id<<1,l,r,val);
  else if(l>m)add(id<<1|1,l,r,val);
  else add(id<<1,l,m,val),add(id<<1|1,m+1,r,val);
}

int query(int id, int pos){
  if(st[id].l==st[id].r){
    return st[id].val;
  }
  int m = (st[id].l+st[id].r)>>1;
  if(pos<=m)return max(st[id].val, query(id<<1,pos));
  else return max(st[id].val, query(id<<1|1,pos));
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin>>n>>m>>C>>s;
  for(int i=1;i<=n;i++){
    L[i] = L[i-1];
    if(s[i-1]=='o'){
      L[i]=max(L[i], (i-C-1>=1?L[i-C-1]:0)+1);
    }
  }
  for(int i=n;i>=1;i--){
    R[i] = R[i+1];
    if(s[i-1]=='o'){
      R[i] = max(R[i], (i+C+1<=n?R[i+C+1]:0)+1);
    }
  }
  vector<int>ret;
  if(C<=1){
    for(int i=0;i<n;i++){
      if(s[i]=='x')continue;
      if(L[i] + R[i+2]<m)ret.push_back(i+1);
    }
  } else {
    build(1,1,n);
    for(int i=1;i<=n;i++){
      int l = i - C + 1;
      l = max(l,1);
      int cur = L[l-1] + R[i+1];
      add(1,l,i,cur);
    }
    for(int i=1;i<=n;i++){
      int r = i+C-1;
      r = min(r, n);
      int cur = L[i-1]+R[r+1];
      add(1,i,r,cur);
    }
    for(int i=0;i<n;i++){
      if(s[i]=='o'&&query(1,i+1)<m)ret.push_back(i+1);
    }
  }
  for(int i=0;i<ret.size();i++)cout<<ret[i]<<endl;
  return 0;
}

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

#define INF 1e5 

int prise[100006],f[100006];
bool isprise[100006];

void os(int r)
{
	int tot=0;
	memset(isprise,1,sizeof(isprise));
	isprise[1]=isprise[0]=0;
	for(int i=2;i<=r;i++)
	{
		if(isprise[i])
			prise[tot++]=i;
		for(int j=0;i*prise[j]<=r;j++)
		{
			isprise[i*prise[j]]=0;
			if(i%prise[j]==0)
				break;
		}
	}
}

void Prefix_and()
{
	for(int i=2;i<=100005;i++)
	{
		f[i]=f[i-1];
		if(i%2==1&&isprise[i]&&isprise[(i+1)/2])
			f[i]++;
	}
}

int main()
{
	int n,x,y;
	os(100005);
	Prefix_and();
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		cout<<f[y]-f[x-1]<<endl;
	}
	return 0;
}

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

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


Measured memory_bytes: 256
/* ex 9_2
   riverstone */

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

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}


int main(void){
    //最初のノードの指す先
    node *first = NULL;
    char cube;
    int ret = 0;

    //1文字ずつ標準入力を受け取る。
    while(scanf("%c", &cube) != EOF && cube != '\n'){
        //スタックにノードを追加
        push(&first, cube);
        
        if((first->next != NULL) && (first->elem != first->next->elem)){
            //スタックから2つのデータを取り出す。
            pop(&first);
            pop(&first);
            //2つキューブを取り除いたのでカウントする
            ret += 2;
        }
    }
    printf("%d\n", ret);
    return 0;
}

Measured memory_bytes: 4716
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a=nxtl(),b=nxtl(),k=nxtl();
    ll t=min(a,k);
    a-=t;
    k-=t;
    t=min(b,k);
    k-=t;
    b-=t;
    cout<<a<<" "<<b<<endl;
    

    return 0;   
}


 
 


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
    int N;
    int oturi;

    scanf("%d",&N);

    if (N%1000 ==0) {
        oturi = 0;
    } else {
        oturi = 1000 - N%1000;
    }

    printf("%d\n", oturi);

    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

class Graph{
public:
    ////////////グラフサイズを渡して作成する
    ////////////infの値は必要に応じて調整すること
    Graph(long long int n):g_size(n),edges(n,vector<long long int>(n,inf)){
        REP(i,n){
            edges[i][i] = 0;
        }


    }
    
    //////////// 枝のvector<>をわたして作成
    //////////// infの値は必要に応じて調整すること
    Graph(long long int n,vector<pair<long long int,long long int>> v):g_size(n),edges(n,vector<long long int>(n,inf)){
        REP(i,g_size){
            edges[i][i] = 0;
        }
        REP(i,v.size()){
            add_edge(v[i].first, v[i].second);
        }        
    }

    ///////////初期状態では有向
    ///////////無向にするときは
    /*  edges[b][a] = cost;  */
    //を追加
    void add_edge(long long int a,long long int b,long long int cost=1){
        edges[a][b] = cost;
        edges[b][a] = cost;
    }
      llint solve(){
        llint result = 0;
        result += search(0,1<<0);
        return result;
    }
    llint search(llint n,llint bit){
        if(bit==(1<<g_size)-1){
            return 1;
        }
        llint result = 0;
        REP(i,g_size){
            if(edges[n][i]!=1||((1<<i)&bit)){
                continue;
            }else if(((bit | (1 << i)))==(1<<g_size)-1){
                    return 1;
            }else{
                result += search(i, (bit | (1 << i)));
            }
        }
        return result;
    }
  

  
private:
    long long int g_size;
    vector<vector<long long int>> edges;
  
};

int main(){
    llint n, m;
    cin >> n >> m;
    vector<pair<long long int, long long int>> v(m);
 
    REP(i,m){
        cin >> v[i].first >> v[i].second;
        v[i].first--;
        v[i].second--;
    }
    Graph graph(n,v);
    cout << graph.solve() << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
SP = {}
ALL = {}
for i in range(N):
    [Stmp, Ptmp] = list(input().split())
    if Stmp not in SP:
        SP[Stmp] = [int(Ptmp)]
    else:
        SP[Stmp].append(int(Ptmp))
    ALL[Stmp+str(Ptmp)] = i+1

A = list(SP.keys())
A.sort()
M = len(A)
for i in range(M):
    L = SP[A[i]]
    L.sort(reverse=True)
    for j in range(len(L)):
        print(ALL[A[i]+str(L[j])])


Measured memory_bytes: 38256
import java.util.Scanner;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
        int H,W;
 
        H = sc.nextInt();
        W = sc.nextInt();
 
        int table[][] = new int[H+1][W+1];
 
        for(int row = 0; row < H; row++){
            for(int col = 0; col < W; col++){
                table[row][col] = sc.nextInt();
            }
        }
 
        for(int row = 0; row < H; row++){
            table[row][W] = 0;
            for(int col = 0; col < W; col++){
                table[row][W] += table[row][col];
            }
        }
 
        for(int col = 0; col <= W; col++){
            table[H][col] = 0;
            for(int row = 0; row < H; row++){
                table[H][col] += table[row][col];
            }
        }
 
        for(int row = 0; row <= H; row++){
            System.out.printf("%d", table[row][0]);
            for(int col = 1; col <= W; col++){
                System.out.printf(" %d", table[row][col]);
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 60716
N = int(input())
As = list(map(int, input().split()))
dic = {}
for A in As:
    if A in dic.keys():
        dic[A] += 1
    else:
        dic[A] = 1
total = 0
for A in dic.keys():
    a = dic[A]
    if a > 1:
        temp = a*(a-1)/2
        total += temp
for i in range(N):
    Ai = As[i]
    if dic[Ai] == 2:
        print(int(total-1))
    elif dic[Ai] > 2:
        a = dic[Ai]
        diff = (a*(a-1) - (a-1)*(a-2))/2
        print(int(total - diff)) 
    else:
        print(int(total))

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

int main() {
  int W, H, x, y;
  scanf("%d%d%d%d", &W, &H, &x, &y);
  // 長方形の中心を通る直線を引けば、分割後の面積が最大となる
  // 与えられた(x. y)が中心である場合、直線は無数に存在する
  printf("%lf %d", (double)W * (double)H / 2, 2 * x == W && 2 * y == H);
  return 0;
}

Measured memory_bytes: 256
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   987654319
#define eps                   0.000000000000001
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())≠
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define endl                 '\n'
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[300010];
vector<int> val(300010),dis(200010),vis(300010,0);
int myrandom (int i) { return std::rand()%i;}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int n;
    cin>>n;
    vector<int> v(n);
    f(i,n)
    {
        cin>>v[i];
    }
    sort(all(v));
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<i;j++)
        {
            int num=v[i]+v[j];
            int lo=-1,hi=n;
            while(hi-lo>1)
            {
                int mid=(lo+hi)/2;
                if(v[mid]<num)
                {
                    lo=mid;
                }
                else
                {
                    hi=mid;
                }
            }
            int t=lo;
            lo=-1,hi=n;
            while(hi-lo>1)
            {
                int mid=(lo+hi)/2;
                if(v[mid]<=v[i]-v[j])
                {
                    lo=mid;
                }
                else
                {
                    hi=mid;
                }
            }
            num=t-hi+1;
            if(i>=hi&&i<=t)
                num--;
            if(j>=hi&&j<=t)
                num--;
            ans=ans+num;
        }
    }
    cout<<ans/3<<endl;
}
// t4xxnve1
// 11906472
// YHUHA8ZBJH
// Preeyadarshee Dev Team 808db2e1




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

int main(){
    int a,b;
    cin>>a>>b;
    int N;
    cin>>N;
    int s[N];
    int f[N];
    for(int i=0;i<N;i++){
        cin>>s[i]>>f[i];
    }
    int i=0;
    int check=0;
    while(i<N){
        if(a<f[i]&&b>s[i]){
            check=1;
        }
        i++;
    }
    cout<<check<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;

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

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n, y; cin >> n >> y;

    for (int i = 0; i < n + 1; i++) {
        for (int j = 0; j < n + 1; j++) {
            int k = n - i - j;
            if (k < 0) break;
            int cand = 10000 * i + 5000 * j + 1000 * k;
            if (cand == y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            } else if (cand > y) break;
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  cin >> n;
  set<string> s;
  char back_c;
  REP(i,n){
    string str;
    cin >> str;
    if(s.count(str)==0){
      s.insert(str);
    }else{
      cout << "No" << endl;
      return 0;
    }
    if(i>0 && back_c != str.front()){
      cout << "No" << endl;
      return 0;
    }
    back_c = str.back();
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
const int maxn=2e5+10;
int F1[maxn],F2[maxn];
int findset1(int x)
{
    if(F1[x]==x) return x;
    return F1[x]=findset1(F1[x]);
}
int findset2(int x)
{
    if(F2[x]==x) return x;
    return F2[x]=findset2(F2[x]);
}
int main()
{
    int n,k,l;
    scanf("%d%d%d",&n,&k,&l);
    for(int i=1;i<=n;i++)
    {
        F1[i]=i;
        F2[i]=i;
    }
    for(int i=1;i<=k;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        int fx=findset1(x);
        int fy=findset1(y);
        if(fx!=fy)
            F1[fx]=fy;
    }
    for(int i=1;i<=l;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        int fx=findset2(x);
        int fy=findset2(y);
        if(fx!=fy)
            F2[fx]=fy;
    }
    for(int i=1;i<=n;i++)
    {
        findset1(i);findset2(i);
    }
    map<pair<int ,int >,int >mp;
    for(int i=1;i<=n;i++)
    {
        mp[make_pair(F1[i],F2[i])]++;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<mp[make_pair(F1[i],F2[i])]<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 13568
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
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 long long INF = 1LL << 60;

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

    if(n[0] == '7' || n[1] == '7' || n[2] == '7'){
        cout << "Yes" << endl;
    }

    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int a,arr[100],cnt=0;
    cin>>a;
    for(int i=1;i<=a;++i){
        cin>>arr[i];
        if(arr[i]!=i)cnt++;}
    if(cnt==0||cnt==2)cout<<"YES"<<endl;
    else cout<<"NO";
    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b/a, c) << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	string s, t;
	cin >> s >> t;
	int a=0;
	char x;
	for (int i = 0;i < t.size()+1;i++) {
		x = s[0];
		s = s.substr(1, t.size() - 1) + x;
		if (s == t) a = 1;
	}
	if (a==1) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	XOR = [0]
	S = [0]
	for i in range(N):
		XOR.append(XOR[-1] ^ A[i])
		S.append(S[-1] + A[i])
	# print(XOR)
	# print(S)
	i = 0
	j = 1
	ans = 0
	while j < N + 1:
		if S[j] - S[i] == XOR[j] ^ XOR[i]:
			ans += j - i
			j += 1
		else:
			i += 1
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 30880
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }
    
    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var aa = ToIntArray(input.ReadLine(), n);
        var bb = ToIntArray(input.ReadLine(), n);

        var aaa = new List<work>(n);

        for (int i=0; i<n; i++) {
            aaa.Add(new work() { a = aa[i], b = bb[i] });
        }

        aa.Sort();
        bb.Sort();

        for(int i=0; i<n; i++) {
            if (aa[i] > bb[i]) return "No";
        }

        aaa.Sort((x,y)=> { return x.b - y.b; });
        for (int i = 0; i < n; i++) aaa[i].idx = i;
        aaa.Sort((x, y) => { return x.a - y.a; });

        int count = 0;
        int idx = 0;
        while (true) {
            count++;
            var w = aaa[idx];
            if (w.idx == 0) break;
            idx = w.idx;
        }
        if (count < n) return "Yes";

        for(int i=0; i<n-1; i++) {
            if (aa[i + 1] <= bb[i]) return "Yes";
        }
        return "No";
    }

    class work
    {
        public int idx;
        public int a;
        public int b;
    }

    static List<int> ToIntArray(string strs, int n) {
        var ret = new List<int>(n);
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret.Add(int.Parse(spl[i]));
        return ret;
    }
}


Measured memory_bytes: 35548