akhauriyash/Code-Regression huggingface dataset:
/*#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>*/
#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = {1,0,-1,0};
ll dy[4] = {0,1,0,-1};


int main(){
    ll n, x;
	cin >> n >> x;
	vll a(n+1);
	REP(i,1,n+1) cin >> a[i];
	ll ans = 0;
	//REP(i,0,n+1) cout << a[i] << " ";
	//cout << endl;
	REP(i,1,n+1){
		if(a[i] + a[i-1] > x){
			ans += ((a[i] + a[i-1]) - x);
			a[i] -= ((a[i] + a[i-1]) - x);
		}
	}
	cout << ans << endl;
    return 0;
}  


Measured memory_bytes: 1024
from collections import deque
H,W = list(map(int,input().split()))
L = [list(input()) for _ in range(H)]  #L[H][W]
s = sum(l.count('.') for l in L)
dd = [(0,1),(0,-1),(1,0),(-1,0)]

res = None
que = deque([(0,0,0)])
used = {(0,0)}
while que:
    i,j,cost = que.popleft()
    if i == H-1 and j == W-1:
        res = cost
        break
    for di,dj in dd:
        ni = i+di; nj = j+dj
        if not(0<=ni<H) or not (0<=nj<W) or L[ni][nj]=='#' or (ni,nj) in used:
            continue
        que.append((ni,nj,cost+1))
        used.add((ni,nj))
if res:
    print(s-res-1)
else:
    print(-1)


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

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

# ifdef Local
# define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
# else
# define debug(...) (__VA_ARGS__)
# define cerr if(0)cout
# endif

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}


int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  int n;
  cin >> n;

  int ans = 0;

  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];           
    ans ^= a[i];
  }
  bool e = 1;
  for (int i = 1; i <= n; i++)
    if (a[i] % 2 == 1)
      e = 0;

    cout << (e ? "second" : "first");
   


  return 0;
}






// Coded by Z..


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int n,m,a[1001],b,z[1001],i,j,w,x;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		z[i]=0;
	}
	for(j=0;j<m;j++){
		scanf("%d",&b);
		for(i=1;i<=n;i++){
			if(a[i]<=b){
				z[i]++;
				break;
			}
		}
	}
	w=0;
	x=0;
	for(i=1;i<=n;i++){
		if(w<z[i]){
			w=z[i];
			x=i;
		}
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 1032
n,y = map(int,input().split())

price = 0
ok = 0

for i in range(n+1):
    for j in range(n+1):
            k = n - i - j
            if k < 0:
                k = 0

            price = 10000 * i + 5000 * j + 1000 * k   
            
            if price == y and i+j+k == n and ok == 0:
                print(i, j, k)
                ok = 1
                break

    else:
        continue
    break

if ok == 0:
    print(-1, -1, -1 )

Measured memory_bytes: 3188
# Q.C
N = int(input())
txy = [[0,0,0]]
for i in range(N):
    txy.append(list(map(int,input().split(" "))))


def matchdist(x,y):
    dt = abs(x[0]-y[0])
    ds = abs(x[1]-y[1]) + abs(x[2]-y[2])
    if ds%2 == dt%2 and ds<=dt:
        return True
    else:
        return False
flag = False
for i in range(N):
    if matchdist(txy[i],txy[i+1]):
        continue
    else:
        print("No")
        flag = True
        break
if not flag:
    print("Yes")

Measured memory_bytes: 27380
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int p[n];
    vector<int> vmin(n,0);
    cin>>p[0];
    vmin[0]=p[0];
    int ans=1;
    for(int i=1;i<n;i++){
        cin>>p[i];
        vmin[i]=min(p[i],vmin[i-1]);
        if(p[i]<vmin[i-1]){
            ans++;
        }
    }
    cout<<ans<<"\n";
    return(0);
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  vector<vector<string>> b(h+2, vector<string>(w+2));

  for (int i = 0; i < h; i++) {
    cin >> a.at(i);
  }

  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++) {
      b.at(i).at(j) = '#';
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      b.at(i+1).at(j+1) = a.at(i).at(j);
    }
  }

  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++) {
      cout << b.at(i).at(j);
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 896
N = int(input())
A = list(map(int, input().split()))
import collections

count_dict = collections.Counter(A)
combination_dict = count_dict.copy()
diff_dict = count_dict.copy()

for k, v in count_dict.items():
    temp = combination_dict[k]
    combination_dict[k] = int(temp * (temp - 1) / 2)

for k, v in count_dict.items():
    temp = count_dict[k]
    diff_dict[k] = temp - 1

s = sum(combination_dict.values())

for k in A:
    print(s - diff_dict[k])

Measured memory_bytes: 33596
from collections import defaultdict
"""
N 以下の全ての整数に対して, (先頭, 末尾) を数える.
(先頭, 末尾), (末尾, 先頭)の組は, 独立しているので掛け算で求められる.
"""
n = int(input())
ansl = defaultdict(lambda: 0)
for i in range(1,n+1):
	sentou = int(str(i)[0])
	ushiro = int(str(i)[-1])
	ansl[(sentou, ushiro)] += 1
ans = 0
for i in range(1, 10):
	for j in range(1, 10):
		ans += ansl[(i, j)]*ansl[(j, i)]
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int INF = 100000000;

int main(){
    int n, d;
    cin >> n >> d;
    int x[n][d];
    REP(i, n){
        REP(j, d){
            cin >> x[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int norm = 0;
            for(int k = 0; k < d; k++){
                int diff = abs(x[i][k] - x[j][k]);
                norm += diff * diff;
            }
            for(int l = 0; l <= norm; l++){
                if(norm == l * l){
                    ans++;
                }
            } 
        }
    }
    cout << ans << endl;
}

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

class Dice {
    int num[6];
    public:
        void set(int n, int d){
            num[n] = d;
        }
        
        void roll(char c){
            if(c == 'N'){
                swap(num[0],num[1]);
                swap(num[1],num[5]);
                swap(num[5],num[4]);
            }else if(c == 'W') {
                swap(num[0],num[2]);
                swap(num[2],num[5]);
                swap(num[5],num[3]);
            }else if(c == 'S') {
                swap(num[0],num[4]);
                swap(num[4],num[5]);
                swap(num[5],num[1]);
            }else{
                swap(num[0],num[3]);
                swap(num[3],num[5]);
                swap(num[5],num[2]);
            }
        }
        
        int up(){
            return num[0];
        }
};

int main(){
    Dice d;
    int num;
    string order;
    for(int i=0;i<6;i++){
        cin >> num;
        d.set(i,num);
    }
    cin >> order;
    for(int i=0;i<order.length();i++){
        d.roll(order[i]);
    }
    cout << d.up() << endl;
}


Measured memory_bytes: 3180
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    int k, s;
    int x, y, z, ans = 0;
    
    cin >> k >> s;
    
    for(y = 0; y <= k; y++) {
        for(z = 0; z <= y; z++) {
            x = s - y - z;
            
            if((y <= x) && (x <= k)) {
                
                if((x == y) && (y == z)) {
                    ans++;
                } else if((x == y) || (y == z)) {
                    ans = ans + 3;
                } else {
                    ans = ans + 6;
                }
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

ans = 0
for x in range(0, 1000):
    pin = str(x).zfill(3)

    i = S.find(pin[0])
    if i == -1:
        continue
    i = S.find(pin[1], i + 1)
    if i == -1:
        continue
    i = S.find(pin[2], i + 1)
    if i == -1:
        continue
    ans += 1

print(ans)


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

typedef long long ll;

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

	int n, m, x, sum=0;
	cin >> n >> m;
	for(int i=0; i<m; i++) {
		cin >> x;
		sum += x;
	}
	sum <= n? cout << n-sum : cout << -1;
	cout << "\n";

	return 0;
}


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

int main(){ 
  int x, y;
  cin >> x >> y;
  
  for (int a = 0; a <= x; a++) {
    int b = x - a;
    int sum = a * 2 + b * 4;
    if (sum == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
} 

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int  n,k;
  cin>>n>>k;
  veci v(n);
  rep(i,n)cin>>v[i];
  sort(v.begin(),v.end());
  int mi=INT_MAX;
  rep(j,n+1-k){
    mi=min(v[j+k-1]-v[j],mi);
  }
  cout<<mi<<endl;
}

Measured memory_bytes: 640
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
//~ #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#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 sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1507;
using bn=bitset<nax*nax>;
const int d=63;

int n;

struct bity
{
	vll wek;
	bity(){}
	bity(int v)
	{
		wek.resize((v/d)+2, 0);
	}
	void ustaw(int v)
	{
		wek[v/d]|=(1LL<<(v%d));
	}
	void zeruj()
	{
		fill(wek.begin(), wek.end(), 0);
	}
	int licz()
	{
		int ret=0;
		for (const ll &i : wek)
			ret+=__builtin_popcountll(i);
		return ret;
	}
};

void oruj(bity &a, const bity &b)
{
	int r=min(a.wek.size(), b.wek.size());
	while(r%4)
	{
		r--;
		a.wek[r]|=b.wek[r];
	}
	for (int i=0; i<r; i+=4)
	{
		a.wek[i]|=b.wek[i];
		a.wek[i+1]|=b.wek[i+1];
		a.wek[i+2]|=b.wek[i+2];
		a.wek[i+3]|=b.wek[i+3];
	}
}

char wcz[nax];
int tab[nax][nax];

bity oso[nax][10];

ll wyn;

int ile[nax];
int num[nax][nax];

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		scanf("%s", wcz+1);
		for (int j=1; j<=n; j++)
		{
			if (wcz[j]=='#')
			{
				tab[i][j]=-1;
			}
			else
			{
				tab[i][j]=wcz[j]-'0';
				ile[tab[i][j]]++;
				num[i][j]=ile[tab[i][j]];
			}
		}
	}
	for (int i=1; i<=n; i++)
		for (int j=1; j<=9; j++)
			oso[i][j]=bity(ile[j]);
	for (int i=n; i; i--)
	{
		for (int j=n; j; j--)
		{
			if (tab[i][j]==-1)
			{
				for (int l=1; l<=9; l++)
					oso[j][l].zeruj();
				continue;
			}
			for (int l=1; l<10; l++)
				oruj(oso[j][l], oso[j+1][l]);
			//~ oso[j]|=oso[j+1];
			for (int l=1; l<10; l++)
			{
				//~ if (oso[j][l].licz())
					//~ debug() << i << " " << j << " to " << l << " " << oso[j][l].licz();
				wyn+=l*tab[i][j]*oso[j][l].licz();
			}
			//~ oso[j][num(i, j)]=1;
			oso[j][tab[i][j]].ustaw(num[i][j]);
		}
	}
	printf("%lld\n", wyn);
	return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;




int n;
int a[maxn];

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

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

    multiset<int> ms;
    ms.insert(0);ms.insert(0);ms.insert(0);
    
    ll res = 1;

    for (int i=0; i<n; i++) {
	res=res*ms.count(a[i])%mod;
	if (res==0) out(0);
	ms.erase(ms.find(a[i]));
	ms.insert(a[i]+1);
    }
    cout<<res<<endl;    
    return 0;
}


Measured memory_bytes: 4052
#include <stdio.h>
#include <math.h>

int main(void) {

	double x1, x2, y1, y2;
	double dis;


	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

	dis = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));

	printf("%f\n", dis);

	return 0;
}

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

int main(){
    int N, x;
    cin >> N >> x;
    vector<int> rem(4);
    set<int>    s;
    for(int i = 1;i <= 2*N-1;i++)   s.insert(i);
    if(x > 1 && x < 2*N-1){
        cout << "Yes" << endl;
        int d = 1;
        if(x == 2*N-2)  d = -1;
        rem[0] = x+1*d;
        rem[1] = x;
        rem[2] = x-1*d;
        rem[3] = x+2*d;
        for(auto itr : rem) s.erase(itr);
        vector<int> vp;
        vp.push_back(-1);
        for(auto itr : s)   vp.push_back(itr);
        for(int i = 1;i < min(N-1, (int)vp.size());i++)  cout << vp[i] << endl;
        for(int i = 0;i < 3;i++)    cout << rem[i] << endl;
        if(N > 2)   cout << rem[3] << endl;
        for(int i = N-1;i < vp.size();i++)  cout << vp[i] << endl;
    }else{
        cout << "No" << endl;
    }
}

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

bool zero(double f){
	return fabs(f) < 0.0000001;
}

int main(){
	double n;
	while(scanf("%lf",&n), n >= 0.0){
		int r = (int)n;
		double f = ((n-r) * 16);
		
		if(r >= (1<<8)){
			printf("NA\n");
			continue;
		}
		if(!zero(f-(int)f)){
			printf("NA\n");
			continue;
		}
		for(int i = 7; i >= 0; i--){
			printf("%d",r / (1<<i));
			r %= (1<<i);
		}
		printf(".");
		int fr = (int)f;
		for(int i = 3; i >= 0; i--){
			printf("%d",fr / (1<<i));
			fr %= (1<<i);
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 3156
#include <stdio.h>
#include <string.h>

int main(void)
{
	int matrix[10][10];
	int vertical_sum[10];
	int horizontal_sum[10];
	int all_sum;
	int i, j;
	int n;
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		memset(matrix, 0, sizeof(matrix));
		memset(vertical_sum, 0, sizeof(vertical_sum));
		memset(horizontal_sum, 0, sizeof(horizontal_sum));
		all_sum = 0;
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				scanf("%d", &matrix[i][j]);
				horizontal_sum[i] += matrix[i][j];
				vertical_sum[j] += matrix[i][j];
				all_sum += matrix[i][j];
			}
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				printf("%5d", matrix[i][j]);
			}
			printf("%5d\n", horizontal_sum[i]);
		}
		
		for (i = 0; i < n; i++){
			printf("%5d", vertical_sum[i]);
		}
		printf("%5d\n", all_sum);
	}
	
	return (0);
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Text.RegularExpressions;

namespace ABC137
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
            Console.Read();
        }

        static void A()
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);

            int plus = A + B;
            int minus = A - B;
            int product = A * B;

            int max = Math.Max(plus, minus);
            max = Math.Max(max, product);
            Console.WriteLine(max.ToString());


        }

    }
}


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

int N;
int A[300010] = {0},B[300010] = {0};
string S;
int main(){
	cin >> N >> S;
	int ans = 1e9;
	for(int i=0;i<N-1;i++){
		if(S[i]=='W') A[i+1]++;//A:i未満までののeの数
		A[i+1] += A[i];
	}
	for(int i=N-1;i>0;i--){
		if(S[i]=='E') B[i-1]++;
		B[i-1] += B[i];
	}
	for(int i=0;i<N;i++){
		ans = min(A[i]+B[i],ans);
	}
	cout << ans << endl;
}

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

int main(){
	int m1,d1,m2,d2;
	scanf("%d %d %d %d",&m1,&d1,&m2,&d2);
	if(d2 == 1) printf("1\n");
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int c[1000005];
int v1[1000005];
int solve(){
    int i,j; cin>>i>>j;
    if((i-1)/2019!=j/2019){
        cout<<0;
    }
    else{
        int m=2000000000;
        for (int k = i; k <= j; ++k)
        {
            for (int p = k+1; p <= j; ++p)
            {
                m=min(m,(k%2019*p%2019)%2019);
            }
        }
        cout<<m%2019;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
// review

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;

ll n;
ll a[MAXN];
ll sortedA[MAXN];
ll sum[MAXN];

class BIT {
  public:
    void init(ll size) {
      bit.resize(size + 1, 0);
    }
    ll sum(ll i) {
      if (!i) {
        return 0;
      }
      return bit[i] + sum(i - (i & -i));
    }

    void add(ll i, ll x) {
      if (i >= (ll)bit.size()) {
        return;
      }
      bit[i] += x;
      add(i + (i&-i), x);
    }
    std::vector<ll> bit;
};

bool check(ll x) {
  memset(sum, 0, sizeof(sum));
  for (ll i=0;i<n;i++) {
    if (a[i] >= x) {
      sum[i+1] = 1;
    } else {
      sum[i+1] = -1;
    }
  }
  for (ll i=0;i<n;i++) {
    sum[i+1] += sum[i];
  }
  ll cnt = 0;
  BIT bit;
  bit.init(2 * (n + 1));
  for (ll i=0;i<=n;i++) {
    cnt += bit.sum(sum[i] + n);
    bit.add(sum[i] + n, 1);
  }
  return cnt >= n * (n+1) / 4;
}

void solve() {
  memcpy(sortedA, a, sizeof(a));
  sort(sortedA, sortedA + n);
  ll low = 0, high = n;
  while (high - low > 1) {
    ll mid = (low + high) / 2;
    if (check(sortedA[mid])) {
      low = mid;
    } else {
      high = mid;
    }
  }
  cout << sortedA[low] << endl;
}

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


Measured memory_bytes: 4204
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,c=0,sum=0;
    cin>>n;
    vec<ll> a(n),b(n);
    rep(i,n){
        cin>>a[i];
        if(a[i]<0) c++;
        b[i]=abs(a[i]);
        sum+=b[i];
    }
    sort(ALL(b));
    if(c%2==0) cout<<sum<<endl;
    else cout<<sum-(b[0]*2)<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  string s;
  cin>>s;
  if(s.at(0)=='7'||s.at(1)=='7'||s.at(2)=='7')
    Yes;
  else
    No;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main (){
  string s;
  ll n;
  cin>>n;
  cin>>s;
  ll ans=1;
  vector<ll>v(256,1);
  for(ll i=0;i<n;i++){
    v[s[i]]++;
  }
  for(ll i=0;i<256;i++){
    ans*=v[i];
    ans%=MOD;
  }
  ans--;
  cout<<ans<<endl;
}


Measured memory_bytes: 512
while True:
    a,b,c = input().split()
    a,c = int(a),int(c)
    if b == "+":
        print(a+c)
    elif b == "-":
        print(a-c)
    elif b ==  "*":
        print(a*c)
    elif b == "/":
        print(int(a/c))
    elif b == "?":
        break
    else:
        pass



Measured memory_bytes: 5596
# -*- coding: utf-8 -*-


def main():
    from math import ceil
    from math import sqrt

    n = int(input())
    point_min = ceil((-1 + sqrt(1 + 8 * n)) / 2)
    diff = point_min * (point_min + 1) // 2 - n

    for i in range(1, point_min + 1):
        if i != diff:
            print(i)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3408
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
signed main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    c-=a;d-=b;
 
    string U=string(d,'U');
    string D=string(d,'D');
    string L=string(c,'L');
    string R=string(c,'R');
 
    cout<<U+R+D+L+"L"+U+"UR"+R+"DR"+D+"DL"+L+"U"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int r0, w0, c, r;
    while(1){
        cin >> r0 >> w0 >> c >> r;
        if(r0 == 0 && w0 == 0 && c == 0 && r == 0) break;
        int cnt = max( (c*w0 - r0 + r - 1)/r, 0 );
        cout << cnt << endl;
    }

    return 0;
}


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

int main() {
  int N;
  scanf("%d", &N);

  int bucket[100000] = {0};

  vector<int> a(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a.at(i));
  }

  int ans = 0;
  int next = 0;
  while (true) {
    ans++;
    if (a.at(next) == 2) {
      break;
    }
    
    bucket[a.at(next)]++;
    if (bucket[a.at(next)] > 1) {
      printf("-1");
      return 0;
    }
    
    next = a.at(next) - 1;
  }

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

Measured memory_bytes: 1024
import sys
n=int(input())
jsum=0
gjlist=[]
ejlist=[]
esum=0

def jouka(t):
	global jsum
	global gjlist
	global ejlist
	global esum
	
	tmpj=0
	tmpe=0
	
	for i in range(len(t)):
		if t[i] == "(":
			tmpj += 1
		else:
			if tmpj == 0:
				tmpe +=1
			else:
				tmpj -=1
		
	if tmpe == 0:
		jsum += tmpj
	elif tmpj == 0:
		esum += tmpe
	elif tmpj > tmpe:
		gjlist.append([tmpe,tmpj])
	else:
		ejlist.append([tmpe,tmpj])

for j in range(n):
	jouka(input())

gjlist.sort(key=lambda x:x[0])
ejlist.sort(reverse = True,key=lambda x:x[0])

streak=jsum
for gj in gjlist:
	if gj[0] > streak:
		print("No")
		sys.exit()
	else:
		streak += gj[1]-gj[0]

for ej in ejlist:
	if ej[0] > streak:
		print("No")
		sys.exit()
	else:
		streak += ej[1]-ej[0]

if streak == esum:
	print("Yes")
else:
	print("No")





Measured memory_bytes: 28428
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;


public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		char[] s = sc.next().toCharArray();
		dfs(s, 0, 0);
		System.out.println(sum);
	}
	
	private static long sum = 0;
	private static void dfs(char[] s, int n, long now) {
		if (n == s.length) {
			sum += now;
			return;
		}

		long v = 0;
		for (int i = n; i < s.length; i ++) {
			v *= 10;
			v += s[i] - '0';
			dfs(s, i + 1, now + v);
		}
	}
}



class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 7892
#!/usr/bin/env python3
import sys
from collections import deque


def solve(N: int, Q: int, a: "List[int]", b: "List[int]", p: "List[int]", x: "List[int]"):

    edges = [[] for _ in range(N)]
    for ai, bi in zip(a,b):
        edges[ai-1].append(bi)
        edges[bi-1].append(ai)
    pls = [0]*N
    for pi, xi in zip(p, x):
        pls[pi-1]+=xi
    
    ans = [0]*N
    ans[0] = pls[0]
    q = deque([1])
    while q:
        temp = q.pop()
        for t in edges[temp-1]:
            edges[t-1].remove(temp)
            ans[t-1] = pls[t-1] + ans[temp-1]
        q.extend(edges[temp-1])

    print(*ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    p = [int()] * (Q)  # type: "List[int]"
    x = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        p[i] = int(next(tokens))
        x[i] = int(next(tokens))
    solve(N, Q, a, b, p, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 93168
N, L, T = map(int, input().split())
ants = []
touch = 0  # すべての蟻が0を通る合計数

for i in range(N):
    x, w = map(int, input().split())
    if w == 1:  # 時計回り
        touch += (x + T) // L  # 0を通る回数
        x1 = (x + T) % L       # 最終的な座標
    else:
        touch += (x - T) // L  # 0を通る回数
        x1 = (x - T) % L
    ants.append(x1)
touch = touch % N  # 0にいた蟻のindex
ants.sort()
ants = ants[touch:]+ants[:touch]

print(" ".join(map(str, ants)))

Measured memory_bytes: 15744
#include<iostream>
#include<cstdio>
#include<cstring>
#define INF 1000000000
using namespace std;
int h[210],nxt[22000],to[22000],K=1,cap[22000];
int iter[210],q[210],hh,tt,lvl[210];
void ins(int u,int v,int c){nxt[++K]=h[u];h[u]=K;to[K]=v;cap[K]=c;}
bool bfs(int S,int T)
{
	hh=tt=0;q[tt++]=S;memset(lvl,0,sizeof(lvl));lvl[S]=1;
	while(hh<tt)
	{
		int u=q[hh++];
		for(int i=h[u];i;i=nxt[i])
		{
			if(cap[i]&&!lvl[to[i]])
			{
				lvl[to[i]]=lvl[u]+1;
				q[tt++]=to[i];
			}
		}
	}
	if(lvl[T]==0)return 0;return 1;
}
int dfs(int u,int T,int f)
{
	if(u==T)return f;
	int used=0;
	for(int &i=iter[u];i;i=nxt[i])
	{
		if(cap[i]&&lvl[to[i]]==lvl[u]+1)
		{
			int w=dfs(to[i],T,min(f-used,cap[i]));
			if(w){cap[i]-=w;cap[i^1]+=w;used+=w;if(used==f)return f;}
		}
	}
	return used;
}
int dinic(int S,int T)
{
	int f=0;
	while(bfs(S,T)){for(int i=1;i<=T;i++)iter[i]=h[i];f+=dfs(S,T,INF);}
	return f;
}
int main()
{
	int n,m;scanf("%d%d",&n,&m);
	int S=n+m+1,T=n+m+2;
	int xs,ys,xt,yt;
	for(int i=1;i<=n;i++)
	{
		char s[110];scanf("%s",s);
		for(int j=0;j<m;j++)
		{
			if(s[j]=='S')xs=i,ys=j+1,ins(S,i,INF),ins(i,S,0),ins(S,n+j+1,INF),ins(n+j+1,S,0);
			if(s[j]=='o')ins(i,j+n+1,1),ins(j+n+1,i,1);
			if(s[j]=='T')xt=i,yt=j+1,ins(i,T,INF),ins(T,i,0),ins(n+j+1,T,INF),ins(T,n+j+1,0);
		}
	}
	if(xs==xt||ys==yt)return 0*puts("-1");
	return 0*printf("%d",dinic(S,T));
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		long re = 0;
		int A[] = new int[N];
		for (int i=0;i<N;i++) {
			A[i]= sc.nextInt();
		}
		long k = ((K+1)*K/2)%1000000007;
		long kminus1 = ((K-1)*K/2)%1000000007;
		for (int i=0;i<N;i++) {
			long aftcount =0;
			long befcount=0;
			for (int j=i+1;j<N;j++) {
				if (A[i]>A[j]) {
					aftcount++;
				}
			}
			for (int j=0;j<i;j++) {
				if (A[i]>A[j]) {
					befcount++;
				}
			}
			re = (re+(k*aftcount))%1000000007;
			re = (re+((kminus1)*befcount))%1000000007;
		}
		System.out.println(re);
	}
}

Measured memory_bytes: 39220
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
x = 0
s = sum(A)
ab = -1
for i in range(n-1):
    a = A[i]
    x += a
    if ab == -1:
        ab = abs(s - 2*x)
    else:
        ab = min(ab, abs(s - 2*x))
print(ab)


Measured memory_bytes: 23780
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, v, p;
	cin >> n >> m >> v >> p;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	sort(a.rbegin(), a.rend());
	int low = p, high = n;
	while(low < high){
		int mid = (low + high + 1) >> 1;
		ll total = 0;
		rep(i,n){
			if(i < p-1 || i >= mid-1) total += m;
			else{
				if(a[i] > a[mid-1]+m){
					total = -1;
					break;
				}
				total += (a[mid-1] + m) - a[i];
			}
		}
		if(total >= (ll) m * v) low = mid;
		else high = mid - 1;
	}
	cout << low << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int getint() {
	char C;
	while (!isdigit(C = getchar()));
	int A = C - '0';
	while (isdigit(C = getchar())) A = A * 10 + C - '0';
	return A;
}

void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		C[keta] = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--) putchar(C[i]);
	putchar(' ');
}

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

	
	int N, A, B;
	N = getint();
	A = getint();
	B = getint();
	int flag = 0;
	if (A < B) {
		swap(A, B);
		flag = 1;
	}

	ll saidai = (ll)A * B;
	int saishou = A + B - 1;
	if (N < saishou || N > saidai) {
		putchar('-');
		putchar('1');
		putchar('\n');
		return 0;
	}
	
	int amari = N - B;
	vector<int> K;
	rep(i, B) {
		int kari = min(A - 1, amari);
		K.pb(kari);
		amari -= kari;
	}

	if (flag) {
		int kari = 0;
		rep(i, B) {
			rep(j, K[i] + 1) putint(K[i] - j + 1 + kari);
			kari += K[i] + 1;
		}
	}
	else {
		rep(i, B) {
			rep(j, K[i] + 1) putint(N - K[i] + j);
			N -= K[i] + 1;
		}
	}

	Would you please return 0;
}

Measured memory_bytes: 2932
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x;
	cin>>x;
	int num=0;
	int i=1;
	while(1)
	{
		++num;
		if((x*(i++))%360==0)break;
	}
	cout<<num;
	return 0;
}

Measured memory_bytes: 3632
import sys
from bisect import bisect_left
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
A = sorted([int(x) for x in input().strip().split()])
BC = [0] * M

for m in range(M):
    BC[m] = tuple([int(x) for x in input().strip().split()])

BC.sort(reverse=True, key=lambda x: x[1])

offset = 0
ans = 0
for i, bc in enumerate(BC):
    if offset >= len(A):
        break
    if bc[1] >= A[min(offset+bc[0]-1, len(A)-1)]:
        ans += min(bc[0], N - offset) * bc[1]
        offset += bc[0]
        continue
    elif bc[1] <= A[offset]:
        ans += sum(A[offset:])
        break
    else:
        c = 0
        while bc[1] >= A[offset+c]:
            ans += bc[1]
            c += 1
        else:
            offset += c
else:
    if offset < len(A):
        ans += sum(A[offset:])
print(ans)

Measured memory_bytes: 22520
# 3
import math

n = int(input())
a = list(map(int, input().split()))

def f(m,a):
    ans=0
    for i in a:
        ans+=m%i
    return ans

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    ans=numbers[0]
    for i in range(1,len(numbers)):
        ans=lcm_base(ans,numbers[i])
    return ans

m= lcm_list(a)-1
print(f(m,a))

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

int main() {
  int N;
  std::cin >> N;
  int A[N];
  int Arry[N];

  for (int ii = 0; ii < N; ii++) {
    std::cin >> A[ii];  // input array
  }

  for (int i = 0; i < N; i++) {
    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;

    for (int p_index = 0; p_index < N; p_index++) {
      std::cout << (p_index == 0 ? "" : " ") << A[p_index];  // print array
    }
    std::cout << std::endl;
  }
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    map<int, int> pos;

    rep2(i, n) {
        int a;
        cin >> a;
        pos[a] = i;
    }

    int Max = 1;

    int cnt = 1;

    rep2(i, n - 1) {
        if (pos[i] < pos[i + 1]) cnt++;
        else {
            Max = max(Max, cnt);
            cnt = 1;
        }
        if (i == n - 1) Max = max(Max, cnt);
    }

    cout << n - Max << endl;



    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef  long double lld;
const ll mod = 1e9 + 7;
const ll mx = 2e3 + 1;

void input(){
    char a, b;
    cin >> a >> b;
    int a1, b1;
    a1 = a - '0';
    b1 = b - '0';
    string s1("\0"), s2("\0");
    f(i, a1)s2 += b;
    f(i, b1)s1 += a;
    cout << ((s1 <= s2) ? s1 : s2) << endl;
}
int main(){
    input();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<#x<<": " <<x<<endl;
#define ll long long
const long long  N=2e5+12,big=1e18,mod=1e9+7;
const double pi=acos(-1);

long long n,seg[N*6];
pair<long long ,long long >a[N];

void update(int i, ll val, int p = 1, int L = 1, int R = n){
	if (L > i || R < i) return;
	if (L == i && R == i){
		seg[p] = val;
		return;
	}

	int mid = (L + R) / 2;
	update(i, val, p * 2, L, mid);
	update(i, val, p * 2 + 1, mid + 1, R);

	seg[p]=max(seg[p*2],seg[p*2 + 1]);
}

ll query(int i, int j, int p = 1, int L = 1, int R = n){

	if (L > j || R < i) return 0;
	if (L >= i && R <= j) return seg[p];

	int mid = (L + R) / 2;
	ll c1 = query(i, j, p * 2, L, mid);
	ll c2 = query(i, j, p * 2 + 1, mid + 1, R);
	return max(c1, c2);
}
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i].first;
    for(int i=1;i<=n;i++)
        cin>>a[i].second;

    for(int i=n;i>=1;i--)
        update(a[i].first,query(a[i].first,n)+a[i].second);

    cout<<query(1,n);

}


Measured memory_bytes: 8448
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename T>
std::vector<T> divisor(T val) {
  std::vector<T> res;
  for (T i = 1; i * i <= val; ++i) {
    if (val % i == 0) {
      res.emplace_back(i);
      if (i * i != val) res.emplace_back(val / i);
    }
  }
  std::sort(res.begin(), res.end());
  return res;
}

template <typename T>
std::pair<T, T> ext_gcd(T a, T b) {
  if (b == 0) return {1, 0};
  T fst, snd; std::tie(fst, snd) = ext_gcd(b, a % b);
  return {snd, fst - a / b * snd};
}

template <typename T>
std::pair<T, T> crt(const std::vector<T> &b, const std::vector<T> &m) {
  T x = 0, md = 1;
  int n = b.size();
  for (int i = 0; i < n; ++i) {
    T g = std::__gcd(md, m[i]);
    if ((b[i] - x) % g != 0) return {0, -1};
    x += md * ((b[i] - x) / g * ext_gcd(md, m[i]).first % (m[i] / g));
    md *= m[i] / g;
  }
  return {x < 0 ? x + md : x, md};
}

#include <atcoder/math>

int main() {
  ll n; cin >> n;
  n <<= 1;
  ll ans = LINF;
  for (ll x : divisor(n)) {
    vector<ll> b{0, n / x - 1}, m{x, n / x};
    auto [tmp, md] = atcoder::crt(b, m);
    if (md != 0) chmin(ans, tmp == 0 ? md : tmp);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3752
void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], x = tmp[1];
    int[] m = new int[n];
    foreach (i; 0 .. n) {
        m[i] = readln.chomp.to!int;
    }
    int cnt = n;
    x -= m.sum;
    cnt += x / m.reduce!min;
    cnt.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
import bisect

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

ans = 0
for i in B:
    ins_a = bisect.bisect_left(A,i)
    ins_c = bisect.bisect_right(C,i)
    ans+=ins_a*(N-ins_c)

print(ans)





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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if(a < b && b < c)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <algorithm>
#include<limits>
#include <cmath>
#include <string>
typedef long long ll;
typedef long l;
using namespace std;
using std::cin ;
#define f1(i,a,b) for(i=a;i<b;i++)
#define f(i,b) for(i=0;i<b;i++)

int main(){
	int test=1,z,i,j,k;
	//cin>>test;
	int h,w;
	for(z=0;z<test;z++){
		cin>>h>>w;
		string s[h];
		f(i,h){
			cin>>s[i];
		}
		f(i,w+2){
			cout<<"#";
		}
		cout<<'\n';
		f(i,h){
			cout<<"#"<<s[i]<<"#\n";
		}
		f(i,w+2){
			cout<<"#";
		}
		cout<<'\n';;

	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint H, W;
	cin >> H >> W;
	if (H % 3 == 0 || W % 3 == 0) {
		cout << 0 << enld;
		return 0;
	}

	lint ans1 = min(H, W);
	lint ans2 = 10000000000;
	for (lint i = 1; i < W; i++) {
		ans2 = min(ans2,max(max(H * i, (H / 2) * (W - i)), (H - H / 2) * (W - i))- min(min(H * i, (H / 2) * (W - i)), (H - H / 2) * (W - i)));
	}
	lint ans3 = 10000000000;
	for (lint i = 1; i < H; i++) {
		ans3 = min(ans3, max(max(W * i, (W / 2) * (H - i)), (W - W / 2) * (H - i)) - min(min(W * i, (W / 2) * (H - i)), (W - W / 2) * (H - i)));
	}

	//cout << ans1 << ' ' << ans2 << ' ' << ans3 << endl;

	cout << min(min(ans1, ans2), ans3) << endl;
}

Measured memory_bytes: 3632