akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define ll long long

const int MOD = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    int x = 0;
    REP(i, s.length())
    {
        if(s[i] == 'A')
        {
            x = i;
            break;
        }
    }

    int y = 0;
    for(int i = s.length() - 1; i >=0; i--)
    {
        if(s[i] == 'Z')
        {
            y = i;
            break;
        }
    }
    cout << y - x + 1 << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(a,b) for (int (a) = 0; (a) < (b); (a)++)
signed main() {
    int n,m; cin >> n >> m;
    int a[n]; for (int i = 0; i< n; i++) {cin >> a[i];}
    int b[n]; b[0] = a[0]%m; for (int i = 1; i< n; i++) {b[i] = b[i-1] + a[i];b[i] %= m;}
    map<int,int> cnt;
    cnt[0]++;
    for (int i = 0; i < n; i++) {
        cnt[b[i]]++;
    }
    int ans = 0;
    for (auto&& A : cnt) {
        ans += A.second * (A.second - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	int t=1;
	while(t--){
		int n,m;
		cin>>n>>m;
		char a[n][m];
		int dp[n][m];
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++)
					cin>>a[i][j];
		}
		dp[0][0]=1;
		for(int i=1;i<m;i++){
			if(a[0][i]=='#' || dp[0][i-1]==-1)
				dp[0][i]=-1;
			else
				dp[0][i]=1;
		}
		for(int i=1;i<n;i++){
			if(a[i][0]=='#' || dp[i-1][0]==-1)
				dp[i][0]=-1;
			else
				dp[i][0]=1;
		}
		for(int i=1;i<n;i++){
			for(int j=1;j<m;j++){
				if(a[i][j]=='#'){
					dp[i][j]=-1;
				}
				else{
					if(dp[i-1][j]!=-1)
						dp[i][j]+=dp[i-1][j]%1000000007;
					if(dp[i][j-1]!=-1)
						dp[i][j]+=dp[i][j-1]%1000000007;
					if(dp[i-1][j]==-1&&(dp[i][j-1]==-1))
						dp[i][j]=-1;

				}
			}
		}
		// for(int i=0;i<n;i++){
		// 	for(int j=0;j<m;j++)
		// 		cout<<dp[i][j]<<" ";
		// 	cout<<endl;
		// }
		if(dp[n-1][m-1]==-1)
			cout<<0<<endl;
		else
			cout<<dp[n-1][m-1]%1000000007<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 5120
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
int main(){
    long long x,y,z,x1,y1,z1;
    long long temp = -1;
    scanf("%lld %lld %lld",&x,&y,&z);
    for(int i = 1;;i++){
            temp++;
			if(temp >= 10000){
                printf("-1");
                break;
            }
            else if(x % 2 == 1||y % 2 == 1||z % 2 == 1){
                	printf("%lld",temp);
                    break;
            }
            else{
            	 x1 = x/2;
            	 y1 = y/2;
            	 z1 = z/2;
                 x = y1 + z1;
                 y = x1 + z1;
                 z = x1 + y1;
            }
        }
    }


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

using namespace std;

typedef long long ll;

const int N = 1e8;
const int INF = 1e9;
const int MOD = 998244353;


int main() {
    int n;
    cin >> n;
    int a[n];
    double sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += 1.0 / a[i];
    }
    cout << setprecision(10) << 1 / sum;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
n = int(input())
a = list(map(int,input().split()))
ok = False
for i in range(n):
    if a[i]==1: ok = True
if ok==0: print(-1)
else:
    ans = 0
    num = 1
    for i in range(n):
        if a[i]==num:
            ans+=1
            num+=1
    print(n-ans)

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

using namespace std;

typedef long long ll;

ll N, M, P, Q, R, S, K, A, B, C, D, E, F, X, Y, Z;
ll arr[200005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> K >> N;
	for (int i = 0; i < N; ++i){
		cin >> arr[i];
	}
	for (int i = 0; i < N-1; ++i){
		X = max(X,arr[(i+1)%N]-arr[i]);
	}
	X = max(X,(arr[0]+K)-arr[N-1]);
	cout << K - X << '\n';
	return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        List<Integer> houses = new ArrayList<Integer>();
        while(sc.hasNextInt()) {
        	houses.add(sc.nextInt());
        }
        int max = Collections.max(houses);
        int min = Collections.min(houses);
        System.out.println(max-min);

	}

}


Measured memory_bytes: 23124
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>

using namespace std;


int main(){

	long int a, b;
	long int f;
	long int G, L, temp;

	while(cin >> a){
		cin >> b;
		f = a * b;
		if(a < b){
			temp = a;
			a = b;
			b = temp;
		}
		while(1){
			temp = a % b;
			if(temp==0) break;
			a = b;
			b = temp;
		}
		G = b;
		L = f/G;

		cout << G << ' ' << L << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ull unsigned long long int
#define ll long long
#define FOR(i,n) for(int i = 0;i<n ;i++)
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>
#define mii map<int,int>
#define uii unordered_map<int,int>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define MOD 1e9+7
#define INF 0x3f3f3f3f
#define print(x) cout<<x<<"\n";

//#include<boost/multiprecision/cpp_int.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//(Uncomment when needed and be sure it not give TLE bcoz it requires time)
//#pragma GCC optimize "trapv"//to check integer overflow and gives RE.
//typedef tree<pair<int,int>,null_type, 
//less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)\
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("O3")
//uncoment for large int requirement
//using boost::multiprecision::cpp_int;
//using namespace _gnu_pbds;

using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
//use it with unordered_map<T,T,custom_hash> safe_map

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

int main()
{fast_io

int t;
//cin>>t;
t = 1;
while(t--)
{
   ll n,d;
   cin>>n>>d;
   int ans = 0 ; 
   while(n--){
       ll x,y;
       cin>>x>>y;
       ll p = x*x + y*y;
       //p = int(sqrtl(p));
       if(p<=d*d)
       ans++;
   }
   cout<<ans<<endl;
}
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  string bw, wb;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2) {
      bw.push_back('0');
      wb.push_back('1');
    } else {
      bw.push_back('1');
      wb.push_back('0');
    }
  }
  ll wbc = 0, bwc = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != wb[i])
      wbc++;
    if (s[i] != bw[i])
      bwc++;
  }
  cout << min(bwc, wbc) << endl;
  return 0;
}


Measured memory_bytes: 720
def main():
    n, w= map(int, input().split())
    w_item = []
    v_item = []
    dp = [[0 for _ in range(w+1)] for _ in range(n+1)]
    for _ in range(n):
        tmp_w, tmp_v = map(int, input().split())
        w_item.append(tmp_w)
        v_item.append(tmp_v)

    for i in range(n):
        for j in range(w+1):
            if w_item[i] <= j:
                dp[i+1][j] = max(dp[i][j], dp[i][j-w_item[i]] + v_item[i])
            else:
                dp[i+1][j] = dp[i][j]
    print(dp[-1][-1])

if __name__ == '__main__':
    main()



Measured memory_bytes: 171528
iN=$stdin.gets.to_i
  h={}
  iN.times do
    *bfr,v=$stdin.gets.split.map(&:to_i)
    h[bfr]=0 unless h.has_key?(bfr)
    h[bfr]+=v
  end
  1.upto(4) do |b|
    1.upto(3) do |f|
      1.upto(10) do |r|
        print " "
        print h.has_key?([b,f,r]) ? h[[b,f,r]] : 0
      end
      print "\n"
    end
    print "#"*20 + "\n" if b<4
  end


Measured memory_bytes: 6896
#include <stdio.h>
#include<math.h>
#include<string.h>
int main()
{
 long int x,y,z,sum,i=0,k;
 char a[100000000]; 
 gets(a);
 printf("%c",a[0]);
 for(i=1;i<strlen(a);i++)
 {
     if(i%2==0)
     {
      printf("%c",a[i]);   
     }
     
 }
 

    return 0;
}


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

#define double long double

const double PI = 3.14159265358979323846;

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double angle1 = (PI / 2.0) - (6.0 * m * PI / 180.0);
    double angle2 = (PI / 2.0) - (30.0 * h * PI / 180.0) - ((6.0 * m * PI / 180.0) / 12.0);
    double y1 = a * cos(angle2);
    double x1 = a * sin(angle2);
    double y2 = b * cos(angle1);
    double x2 = b * sin(angle1);
    double dist = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
    cout << fixed << setprecision(15) << dist << endl;
	return 0;
}


Measured memory_bytes: 4148
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}



int main() {

  long n;
  cin >> n;

  vector<long> a(n);

  double ave = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ave += a[i];
  }
  ave = ave / n; //平均

  // sort(a.begin(), a.end());


  long ans = 0;
  double dif = 10000;
  for (int i = 0; i < n; ++i) {
    if (abs(a[i] - ave) < dif){
      ans = i;
      dif = abs(a[i] - ave);
    }
  }











  cout << ans << endl;
  // cout << "w:" << w << "  h:" << h << endl;


}




















Measured memory_bytes: 256
#include <iostream>
    using namespace std;
     
    int main(){
        int N;
        cin >> N;
        for(int i = 0; i < 1e5; i++){
            if(N < i * i){
                cout << (i - 1) * (i - 1) << endl;
                return 0;
            }
        }
    }

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

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

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

int n;
int a[3];

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

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

  int g = gcd(a[0], a[1]);
  if (n == 3) g = gcd(g, a[2]);

  vector<int> d;
  for (int i = 1; (ll)i * i <= g; i++) {
    if (g % i) continue;
    d.emplace_back(i);
    if (i != g / i) d.emplace_back(g / i);
  }
  sort(d.begin(), d.end());
  for (int i = 0; i < d.size(); i++) {
    cout << d[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <stdexcept>

using namespace std;

int main(){
  int n,m;
  map<string, int> ans_map;
  map<string, int> t_map;

  cin >> n;
  for(int i=0; i<n; i++){
    string temp;
    cin >> temp;

    try{
      ans_map[temp] += 1;
    }catch(out_of_range out){
      ans_map.insert( make_pair( temp, 1 ) );
    }
  }

  cin >> m;
  for(int i=0; i<m; i++){
    string temp;
    cin >> temp;
    try{
      ans_map[temp] -= 1;
    }catch(out_of_range out){
      ans_map.insert( make_pair(temp, -1) );
    }
  }

  int max = 0;
  for(auto i=ans_map.begin(); i!=ans_map.end(); i++){
    if(max < i->second){
      max = i->second;
    }
  }

  cout << max;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N,L = map(int,readline().split())
A = list(map(int,readline().split()))

# 2個でL以上の隣合うペアがどこかにあれば、そこを最後に残せば大丈夫
target = -1
for i in range(1,len(A)):
  if A[i] + A[i - 1] >= L:
    target = i
    break
if target == -1:
  print("Impossible")
  exit(0)

left = []
for i in range(1,target):
  left.append(i)
  
right = []
for i in range(len(A) - 1,target,-1):
  right.append(i)

print("Possible")
for l in left:
  print(l)
for r in right:
  print(r)
print(target)

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2003,INF=10000;

int main(){
    
    int N;cin>>N;
    vector<int> C(N),pre(200001,-1);
    vector<ll> sum(N+1);
    sum[0]=1;sum[1]=1;
    for(int i=0;i<N;i++){
        int a;cin>>a;
        C[i]=a;
        if(i){
            if(C[i]!=C[i-1]&&pre[a]!=-1) sum[i+1]=(sum[pre[a]+1]+sum[i])%mod;
            else sum[i+1]=sum[i];
        }
        pre[a]=i;
    }
    
    cout<<sum[N]<<endl;
    
}


Measured memory_bytes: 3456
#include<stdio.h>
#include<string.h>
int main(){
  int n,i,j,a[101][101],m,l;
  scanf("%d",&n);
  for(i=1;i<=n;i++) for(j=1;j<=n;j++) a[i][j]=0;
  for(i=1;i<=n;i++){
    scanf("%d %d",&j,&m);

    for(j=1;j<=m;j++){
      scanf("%d",&l);
      a[i][l]=1;
    }
  }
  for(i=1;i<=n;i++) for(j=1;j<=n;j++) {
      printf("%d",a[i][j]);
      if(j==n) printf("\n");
      else printf(" ");
    }
  
}



Measured memory_bytes: 2088
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
int N,R;
int main()
{
    cin >>N>>R;
    if(N<10){
        cout<<R+(100*(10-N))<<endl;
    }
    else{
        cout<<R<<endl;
    }
    return 0;
    
}
     
 

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N;
  int i;
  int ans=0;
  scanf("%d",&N);
  
  int V[N+1],C[N+1];
  for(i=0;i<N;i++){
    scanf("%d",&V[i]);
  }
  
  for(i=0;i<N;i++){
    scanf("%d",&C[i]);
    if(V[i]-C[i] >= 0) ans+=V[i]-C[i];
  }
  

  printf("%d\n",ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const double pi = acos(-1.0);

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

    if (n == 1){
        printf("%.16f\n", 1.0);
        return 0;
    }

    vector<double> x(n), y(n);
    REP(i,n) cin >> x[i] >> y[i];

    vector<double> ans(n);
    REP(i,n){
        vector<double> theta;
        REP(j,n){
            if (j == i) continue;
            theta.push_back(atan2(y[j] - y[i], x[j] - x[i]));
        }
        sort(ALL(theta));
        REP(j,n-1) theta.push_back(theta[j] + 2 * pi);

        double mi = 2 * pi;
        REP(j,n-1) mi = fmin(mi, theta[j+n-2] - theta[j]);

        // cout << mi << endl;

        if (mi < pi){
            ans[i] = (pi - mi) / 2 / pi;
        }
    }

    REP(i,n){
        printf("%.16f\n", ans[i]);
    }
    

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;

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

	string s;
	cin >> s;
	int x = 700;
	for (char c : s) {
		if (c == 'o') x += 100;
	}
	cout << x << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

    int count = 0 ;
    for(int i=0;i<=k;i++){
        if(i>s)break;
        for(int j=0;j<=k;j++){
            if(i+j>s)break;
            int l = s-i-j;
            if(0 <= l && l <= k){
                count++;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, n) cin >> v[i];
    sort(all(v));

    double ans = (v[0] + v[1]) / 2;

    for(int i=2; i<n; i++){
        ans = (ans + v[i]) / 2;
    }

    cout << fixed << setprecision(9) << ans << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
edges = [[]for _ in range(n)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append((c, b))
    edges[b].append((c, a))
INF = float('inf')


def bfs(init_v):
    dist = [INF]*n
    dist[init_v] = 0
    tasks = deque([(0, init_v)])
    while tasks:
        d, v = tasks.popleft()
        for d2, v2 in edges[v]:
            if dist[v2] <= dist[v]+d2:
                continue
            dist[v2] = dist[v]+d2
            tasks.append((dist[v2], v2))
    return dist


q, k = map(int, input().split())
dist = bfs(k-1)
for _ in range(q):
    x, y = map(lambda x: int(x)-1, input().split())
    print(dist[x]+dist[y])

Measured memory_bytes: 47012
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int Input;

            Double Result;
            

            Input = int.Parse(System.Console.ReadLine());


            if (1 <= Input || Input <= 100)
            {
                Result = Math.Pow(Input, 3);

                System.Console.WriteLine(Result);
            }

        }
    }
}

Measured memory_bytes: 9320
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll A, B;
  cin >> A >> B;
  string ans = "No";
  for (ll C = 1; C <= 3; C++) {
    if ((A * B * C) % 2 == 1) {
      ans = "Yes";
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N];
    for (int i=0; i<N; i++){
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    System.out.println(a[N-1]-a[0]);
  }
}

Measured memory_bytes: 21460
N = int(input())
s = list(input()for i in range(N))
ans = 0
A,B = 0,0
AB = 0
for i in s:
    for j in range(len(i)-1):
        if i[j:j+2] == "AB":
            ans += 1
    if i[0] == "B" and i[-1] == "A":
        AB += 1
    elif i[0] == "B":
        B += 1
    elif i[-1] == "A":
        A += 1
ans +=AB+min(A,B)
if A==0 and B==0 and AB > 0:
    ans -= 1
print(ans)

Measured memory_bytes: 3700
//#pragma warning disable

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

public class Test
{
    public static int[,] CreatePartialSumTable(byte[][] s, int H, int W)
    {
        var sum = new int[H + 1, W + 1];

        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                sum[i + 1, j + 1] = sum[i, j + 1] + sum[i + 1, j] - sum[i, j] + (int)s[i][j];
            }
        }

        return sum;
    }

    public static void Main()
    {
        var line1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = line1[0];
        var M = line1[1];
        var Q = line1[2];

        var s = new byte[N][];

        for (var i = 0; i < N; i++)
        {
            s[i] = new byte[M];
            var s0 = Console.ReadLine();

            for (int j = 0; j < M; j++)
            {
                s[i][j] = (byte)(s0[j] - '0');
            }
        }

        int[,] face = CreatePartialSumTable(s, N, M);

        int[,] edgeVert;  // 垂直方向の罫線
        {
            var temp = new byte[N][];

            for (int i = 0; i < N; i++)
            {
                temp[i] = new byte[M - 1];
                for (int j = 0; j < M - 1; j++)
                {
                    temp[i][j] = (byte)(s[i][j] * s[i][j + 1]);  // 両方青
                }
            }
            
            edgeVert = CreatePartialSumTable(temp, N, M - 1);
            temp = null;
        }
        

        int[,] edgeHori;  // 水平方向の罫線
        {
            var temp = new byte[N - 1][];

            for (int i = 0; i < N - 1; i++)
            {
                temp[i] = new byte[M];
                for (int j = 0; j < M; j++)
                {
                    temp[i][j] = (byte)(s[i][j] * s[i + 1][j]);  // 両方青
                }
            }

            s = null;

            edgeHori = CreatePartialSumTable(temp, N - 1, M);
            temp = null;
            GC.Collect();
        }
                

        for (int k = 0; k < Q; k++)
        {
            var line2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();  
            var x1 = line2[0];  // 縦方向の座標をxi、横方向の座標をyiで表すのはNG
            var y1 = line2[1];
            var x2 = line2[2];
            var y2 = line2[3];

            var f = face[x2, y2] - face[x2, y1 - 1] - face[x1 - 1, y2] + face[x1 - 1, y1 - 1];
            var v = edgeVert[x2, y2 - 1] - edgeVert[x2, y1 - 1] - edgeVert[x1 - 1, y2 - 1] + edgeVert[x1 - 1, y1 - 1];
            var h = edgeHori[x2 - 1, y2] - edgeHori[x2 - 1, y1 - 1] - edgeHori[x1 - 1, y2] + edgeHori[x1 - 1, y1 - 1];

            Console.WriteLine(f - v - h);

            if (k % 30000 == 0)
            {
                GC.Collect();
            }
        }
    }
}


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

int main() {
	int n;
	cin >> n;
	long long dp[n+1];
	dp[0] = 2;
	dp[1] = 1;
	for (int i=2; i<=n; i++)
		dp[i] = dp[i-1] + dp[i-2];

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

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from itertools import accumulate
import bisect
n,q = map(int,input().split())
if n%2:
  a = [0]+list(map(int,input().split()))
  n += 1
else:
  a = list(map(int,input().split()))
fs = [a[i] if i%2 else 0 for i in range(n)]
accss = [0]*n
accff = list(accumulate(a))
accfs = list(accumulate(fs))
xls = []
xpt = []
for i in range(n//2):
  xls.append((a[2*i+1]+a[i+n//2])/2)
  if i == 0:
    xpt.append(accff[n-1]-accff[n//2-1])
  else:
    xpt.append(accff[n-1]-accff[i+n//2-1]+accfs[2*i-1])
for _ in range(q):
  x = bisect.bisect_left(xls,int(input()))
  if x >= n//2:
    print(xpt[-1])
  else:
    print(xpt[x])

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

int main(){
	int a,b,c,d;
	int ans=0;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(((abs(a-b)<=d) && (abs(b-c)<=d)) || (abs(a-c)<=d))	ans=1;
	if(ans==1)	printf("Yes");
	else	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    //std::map<char, int> mp
    int cnta = 0 , cntb = 0;
    for (size_t i = 0; i < 3; i++) {
        if(s[i] == 'A'){
            cnta++;
        }
        else{
            cntb++;
        }
    }
    if(cnta == 0 || cntb == 0){
        cout<<"No\n";
    }
    else{
        cout<<"Yes\n";
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.IO;
using System.Linq;

namespace CompetitiveProgramming
{
  
  class Solve
  {
    const int INF = (int)(1e9) + 10;

    private void Main()
    {
      long[] HWN = Console.ReadLine().Split().Select(long.Parse).ToArray();
      long H = HWN[0], W = HWN[1], N = HWN[2];

      long[] count = new long[10];
      long sum = 0;
      Hashtable ht = new Hashtable();

      count[0] = (H - 2) * (W - 2) - sum;

      for (long i = 0; i < N; i++)
      {
        long[] ab = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long a = ab[0] - 1, b = ab[1] - 1;

        for (long j = -2; j <= 0; j++)
        {
          for (long k = -2; k <= 0; k++)
          {
            long t = a + j;
            long u = b + k;
            if (t >= 0 && t + 2 < H && u >= 0 && u + 2 < W)
            {
              if (ht[t * INF + u] == null)
              {
                ht[t * INF + u] = 0L;
              }
              ht[t * INF + u] = (long)ht[t * INF + u] + 1;
              long tmp = (long)ht[t * INF + u];
              count[tmp - 1]--;
              count[tmp]++;
            }
          }
        }
      }
      for (int i = 0; i < 10; i++)
      {
        Console.WriteLine(count[i]);
      }
    }

    public Solve()
    {
      Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
      Main();
      Console.Out.Flush();
    }
  }

  class Program
  {
    static void Main(string[] args)
    {
      new Solve();
    }
  }
}

Measured memory_bytes: 82488
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}


int main(void){
  ll N, A, B, W, H, C, D, Q;
  string s, t;
  cin >> N;
  ll x[N];
  vector<ll> x_vec, x_vec_origin;
  rep(i, N) {
    cin >> x[i];
    x_vec.push_back(x[i]);
    x_vec_origin.push_back(x[i]);
  }
  sort(ALL(x_vec));
  ll n_div2_upper = N/2;
  ll n_div2_lower = n_div2_upper-1;
  ll ave = (x_vec[n_div2_upper]+x_vec[n_div2_lower])/2;
  rep(i, N){
    if (x_vec_origin[i]<= ave) cout << x_vec[n_div2_upper] << endl;
    else cout << x_vec[n_div2_lower] << endl;
  }

}


Measured memory_bytes: 7140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 605;
vector<int>G[maxn];
int in[maxn]={0};
int top[maxn]={0};
double dp[maxn];
void gettop(int n){
    queue<int>qq;
    for(int i=1;i<=n;i++){
        if(in[i]==0)
            qq.push(i);
    }
    int ind=-1,u;
    while(!qq.empty()){
        top[++ind]=qq.front();
        u=qq.front();
        qq.pop();
        for(int i=0;i<G[u].size();i++){
            in[G[u][i]]--;
            if(in[G[u][i]]==0)
            qq.push(G[u][i]);
        }
    }
}

double gao(int n,int block){
    int u;
    dp[n]=0;
    for(int i=n-2;i>=0;i--){
        u=top[i];
        double maxnum = 0;
        double ans = 0;
        int num = G[u].size();
        for(int i=0;i<num;i++){
            ans+=dp[G[u][i]];
            maxnum=max(maxnum,dp[G[u][i]]);
        }
        if(u==block&&num>1){
            ans-=maxnum;
            num--;
        }
        dp[u]=ans/num+1;
    }
   //cout << dp[1] << endl;
    return dp[1];
}
int main()
{
    int n,m;
    int u,v;
    cin >> n >>m;
    for(int i=0;i<m;i++){
        cin >> u >> v;
        G[u].push_back(v);
        in[v]++;
    }
    gettop(n);
//    for(int i=0;i<n;i++)
//        printf("%d ",top[i]);
    dp[1]=0;
    double res = 1e18;
    for(int i=1;i<=n;i++)
        res=min(res,gao(n,i));
    printf("%.10f\n",res);
    return 0;
}


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

A.sort(reverse=True)

ans = 0
mod = 10**9+7

for i in range(n):
    ans = (ans+(i+2)*A[i])%mod
    # print(i,ans)

for i in range(n*2-2):
    ans = (ans*2) % mod

print(ans)

Measured memory_bytes: 27108
#include "bits/stdc++.h"
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();

    vv<int> dp = vvec(n + 1, m + 1, 0);
    rep(i, n) rep(j, m) {
        if (s[i] == t[j]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
    }

    string ans;
    for (int i = n - 1, j = m - 1; i >= 0 && j >= 0;) {
        for (; j >= 0;) {
            if (s[i] == t[j] && dp[i + 1][j + 1] == dp[i][j] + 1) {
                ans.push_back(s[i]);
                i--;
                j--;
            }
            else if (dp[i + 1][j + 1] == dp[i + 1][j]) {
                j--;
            }
            else i--;
        }
    }
    reverse(all(ans));
    write(ans);
}

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

void solve() {
	int N; cin >> N;
	vector<int> h(N);
	rep(i, N) scanf("%d", &h[i]);

	int res = 0;
	while (true) {
		if (*max_element(h.begin(), h.end()) == 0) break;

		int i = 0;
		while (i < N) {
			if (h[i] == 0) i++;
			else {
				res++;
				while (i < N && h[i] > 0) {
					h[i]--;
					i++;
				}
			}
		}
	}
	cout << res << endl;
}

int main(void) {
	solve();

	return 0;
}

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

// long long l[100];

int main() {
  int n;
  cin >> n;
  int ans =sqrt(n);
  cout << ans*ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


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())


def main():
    N, M = [int(x) for x in input().split()]
    AB = [[int(x) for x in input().split()] for _ in range(M)]

    u = UnionFind(N)
    ans = [N * (N - 1) // 2]
    for i, (a, b) in enumerate(AB[::-1]):
        x = 0
        y = 0
        if not u.same(a - 1, b - 1):
            x = u.size(a - 1)
            y = u.size(b - 1)
        ans.append(max(0, ans[i] - x * y))
        u.union(a - 1, b - 1)

    ans.pop()
    for a in ans[::-1]:
        print(a)


if __name__ == '__main__':
    main()


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

const ll MX = 1e18;

int main(){
    int n;
    cin >> n;
    ll ans = 1;
    bool ng = false;
    rep(i,n){
        ll a;
        cin >> a;
        if(a == 0){
            cout << 0 << endl;
            return 0;
        }
        if(ng || (MX + 1)/ans < a || ans*a > MX){
            ng = true;
        }
        ans *= a;
    }
    if(ng) cout << -1 << endl;
    else
    {
        cout << ans << endl;
    }
    return 0;
    
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <queue>
#include <unordered_set>
#include <complex>
#include <unordered_map>
#include <bitset>
#include <ctime>
#include <cassert>
#include <random>

#define sz(a) (int)((a).size())

using namespace std;

mt19937 rnd(239);

typedef long long ll;
typedef long double ld;

int solve()
{
    ios::sync_with_stdio(0);
    int n;
    if (!(cin >> n))
    {
        return 1;
    }
    vector<ll> a(n + 2, 0);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    ll ans = 0;
    n += 2;
    for (int i = 1; i < n; i++)
        ans += abs(a[i] - a[i - 1]);
    for (int i = 1; i + 1 < n; i++)
    {
        if (a[i] == a[i - 1] || a[i] == a[i + 1])
            cout << ans << '\n';
        else if ((a[i - 1] < a[i] && a[i] < a[i + 1]) || (a[i - 1] > a[i] && a[i] > a[i + 1]))
            cout << ans << '\n';
        else
            cout << ans - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) << '\n';
    }
    return 0;
}

int32_t main()
{
    #ifdef ONPC
        freopen("in.txt", "r", stdin);
    #endif
    int T = 100;
    //cin >> T;
    for (int i = 1; i <= T; i++)
    {
        #ifdef ONPC
            cerr << "Test #" << i << ":\n";
        #endif
        if (solve())
            break;
        #ifdef ONPC
            cerr << "_______________________________________________" << endl;
        #endif
    }
    #ifdef ONPC
        cerr << endl << "finished in " << clock() * 1000LL / CLOCKS_PER_SEC << " ms" << endl;
    #endif
    return 0;
}


Measured memory_bytes: 2048
#abc075 b
h,w=map(int,input().split())
maze=[]
for i in range(h):
    maze.append(list(input()))



move=[[1,0],[0,1],[-1,0],[0,-1],[-1,1],[-1,-1],[1,1],[1,-1]]
for i in range(h):
    for j in range(w):
        if maze[i][j]=="#":
            continue
        else:
            cnt=0
            for dy,dx in move:
                y=i+dy
                x=j+dx
                if (0<=y<h and 0<=x<w)==False:
                    continue
                else:
                    if maze[y][x]=="#":
                        cnt+=1
            maze[i][j]=str(cnt)
for i in range(h):
    ans=""
    for j in range(w):
        ans+=maze[i][j]
    print(ans)


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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
#define F first
#define S second
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  string s; cin >> s;
  s[1] ^= ('R' ^ 'B');
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3584
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[] a = new int[N];
		int[] b = new int[N];
		int[] c = new int[N];

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		for (int i = 0; i < N; i++) {
			b[i] = sc.nextInt();
		}
		Arrays.sort(b);

		for (int i = 0; i < N; i++) {
			c[i] = sc.nextInt();
		}
		Arrays.sort(c);

		long ans = 0;
		int i = 0;
		int k = 0;
		for(int j=0;j<N;j++) {
			while(i < N && a[i] < b[j]) {
				i++;
			}

			while(k < N && b[j] >= c[k]) {
				k++;
			}
			ans += (long)i * ((long)N - (long)k);
		}

		System.out.println(ans);
	}

	public static int binarysearch(int[] a,int x) {
		int left = 0;
		int right = a.length;
		while(left < right) {
			int mid = (left + right)/2;
			if(a[mid] == x) {
				return mid;
			}else if(x < a[mid]) {
				right = mid;
			}else {
				left = mid + 1;
			}
		}
		return right;
	}

}


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

int main() {
	int n, m;
	cin >> n >> m;
	if( m < 10 ) n = n*10 + m;
	else if( m < 100 ) n = n*100 + m;
	else n = n*1000 + m;

	m = int( sqrt(n) );

	m*m == n ? cout << "Yes\n" : cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <set>
using namespace std;
typedef pair<int, int> P;
int main(){
    int N, K;
    cin >> N >> K;
    int cnt = 0;
    if(K > (N - 1) * (N - 2) / 2){
        cout << -1 << endl;
        return 0;
    }
    set<P> s;
    for(int i = 1; i < N; i++){
        cnt++;
        s.insert(P(1, i + 1));
    }
    int cntp = (N - 1) * (N - 2) / 2;
    int flag = 0;
    for(int i = 2; i <= N; i++){
        if(flag == 1) break;
        for(int j = i + 1; j <= N; j++){
            if(cntp == K){
                flag = 1;
                break;
            }
            s.insert(P(i, j));
            cnt++;
            cntp--;
        }
    }
    cout << cnt << endl;
    for(auto p: s){
        cout << p.first << ' ' << p.second << endl;
    }
}

Measured memory_bytes: 3768
#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 double EPS = 1e-9;

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


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

	M = 15;
	for (int i = 0; i < 5; i++) {
		cin >> N;
		M -= N;
	}
	cout << M << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int a,b,x,y;
  scanf("%d%d%d%d", &a, &b, &x, &y);
  printf("%lf %d\n", double(a)*double(b) / 2, x + x == a&&y + y == b);
  
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        d: isize,
        xy: [(isize, isize); n],  // Vec<(i32, i32, i32)>
    }
    let mut count = 0;
    for (x, y) in xy {
        if x * x + y * y <= d * d {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 7884
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,Q;
  cin >> A >> B >> Q;
  vector<long> a(A+2);
  vector<long> b(B+2);
  for(int i=1;i<A+1;i++)cin >> a[i];
  for(int i=1;i<B+1;i++)cin >> b[i];
  a[0]=-10000000000;
  b[0]=-10000000000;
  a[A+1]=10000000000000;
  b[B+1]=100000000000;
  for(int i=1;i<Q+1;i++){
    long x;
    cin >> x;
    auto iia=lower_bound(a.begin(),a.end(),x);
    auto iib=lower_bound(b.begin(),b.end(),x); // OK
    long p,q,r,s;
    int ia=iia-a.begin();
    int ib=iib-b.begin(); // OK
    p=max(a[ia]-x,b[ib]-x);
    ib--;
    q=min(2*(a[ia]-x)+x-b[ib],a[ia]-x+2*(x-b[ib]));
    ia--;
    ib++;
    r=min(2*(x-a[ia])+b[ib]-x,x-a[ia]+2*(b[ib]-x));
    ib--;
    s=max(x-a[ia],x-b[ib]);
    cout << min({p,q,r,s}) << endl;
  }
}
 

Measured memory_bytes: 2944
//
//  AOJ 0189 Convenient Location
//
//  Created by TaoSama on 2015-03-20
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#define CLR(x,y) memset(x, y, sizeof(x))

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

int n, dp[15][15];

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	while(cin >> n && n) {
		int V = 0;
		memset(dp, 0x3f, sizeof dp);
		for(int i = 1; i <= n; ++i) {
			int x, y, v; cin >> x >> y >> v;
			dp[x][y] = dp[y][x] = v;
			V = max(V, max(x, y));
		}
		for(int k = 0; k <= V; ++k)
			for(int i = 0; i <= V; ++i)
				for(int j = 0; j <= V; ++j)
					dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);

		int ans = INF, loc;
		for(int i = 0; i <= V; ++i) {
			int t = 0;
			for(int j = 0; j <= V; ++j) {
				if(i == j) continue;
				t += dp[i][j];
			}
			if(t < ans) ans = t, loc = i;
		}
		cout << loc << ' ' << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
import fractions
a,b,c,d = map(int, input().split())

def lcm(a,b):
    return a * b // fractions.gcd(a, b)

def count(num, a, b):
    return int(num - num//a - num//b + num//lcm(a,b))

print(count(b,c,d)-count(a-1,c,d))


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,x;
  cin>>a>>b>>x;
  if(a <= x && x <= a+b) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define met(a,x) memset(a,x,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
ll a[2010];
ll maxn[2010],minn[2010];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int i,j,k,m,n,T;
    ll ans=-inf;
    ll l,r;
    ll x,y,z,w;
    cin>>n>>z>>w;
    for(i=1; i<=n; i++)
        cin>>a[i];
    if(n==1)
        ans=abs(a[1]-w);
    else
    {
        ans=-inf;
        ans=max(ans,abs(a[n-1]-a[n]));
        ans=max(ans,abs(a[n]-w));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  std::string S;

  std::cin >> N >> S;

  if (N % 2 == 0)
    if (S.substr(0, N / 2) == S.substr(N / 2, N / 2)) {
      std::cout << "Yes" << std::endl;

      return 0;
    }
  
  std::cout << "No" << std::endl;

  return 0;
}


Measured memory_bytes: 256