akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max)) 

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

bool judge(VI as){
	for(auto a : as){
		if(!a) return false;
	}
	return true;
}

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

	int N, W, H;
	string ans = "No";
	cin >> N >> W >> H;
	VI Hs(H), Ws(W);
	rep(i, N) {
		int x, y, w;
		cin >> x >> y >> w;
		Hs[min(H,y + w)]--;
		Ws[min(W,x + w)]--;
		Hs[max(0,y - w)]++;
		Ws[max(0,x - w)]++;
	}
	rep(i, Hs.size()){
		Hs[i + 1] += Hs[i];
	}
	rep(i, Ws.size()){
		Ws[i + 1] += Ws[i];
	}
	if(judge(Hs) || judge(Ws))
		ans = "Yes";
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2584
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
#define lambdify(x) [&](auto &&...args){ return x(forward<decltype(args)>(args)...); }
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	vector<vector<int>> dist(n, vector<int>(n)), next(dist), state(n, vector<int>(n, 1));
	for(auto i = 0; i < n; ++ i){
		for(auto j = 0; j < n; ++ j){
			dist[i][j] = min({i, j, n - 1 - i, n - 1 - j});
		}
	}
	int res = 0;
	static const vector<pair<int, int>> dr{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
	for(auto REP = 0; REP < n * n; ++ REP){
		int x;
		cin >> x, -- x;
		int y = x % n;
		x /= n;
		res += dist[x][y];
		function<void(int, int)> update = [&](int x, int y){
			for(auto &[dx, dy]: dr){
				int nx = x + dx, ny = y + dy;
				if(0 <= nx && nx < n && 0 <= ny && ny < n && dist[nx][ny] > dist[x][y] + state[x][y]){
					dist[nx][ny] = dist[x][y] + state[x][y];
					update(nx, ny);
				}
			}
		};
		state[x][y] = 0;
		update(x, y);
	}
	cout << res << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 29452
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	vector<int> C(N);
	for( int &i : A ) cin >> i;
	for( int &i : B ) cin >> i;
	for( int &i : C ) cin >> i;
	sort(A.begin(), A.end());
	sort(C.begin(), C.end());
	vector<long long int> result;

	for( auto i : B ){
		long long int Adex, Cdex;
		// if( A[N-1] >= i ){
			auto Aitr = lower_bound(A.begin(), A.end(), i);
			Adex = (long long int)distance(A.begin(), Aitr);
		// } else {
		//	Adex = (long long int)(N);
		// }
		// if( i <= C[N-1] ){
			auto Citr = upper_bound(C.begin(), C.end(), i);
			Cdex = (long long int)(N - distance(C.begin(), Citr));
		// } else {
		//	Cdex = 0ll;
		// }
		result.push_back(Adex*Cdex);
	}
	
	long long int sum = accumulate(result.begin(), result.end(), 0ll);
	cout << sum << endl;
	return 0;
}

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

using namespace std;

const int MaxN = 1e5 + 13;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int n;

int main()
{
//    freopen("input.txt", "r", stdin);
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;

    int T = 0, X = 0, Y = 0;

    for(int i = 1; i <= n; ++i)
    {
        int t, x, y;
        cin >> t >> x >> y;
        int dif = abs(x - X) + abs(y - Y);
        int difT = t - T;
        if(dif <= difT && (difT - dif) % 2 == 0)
        {
            X = x;
            Y = y;
            T = t;
        }else
            return cout << "No\n", 0;
    }

    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int K = 0;
	int N = 0;
	int min = 0;
	cin >> K >> N;
	int Min = K;
	vector<int> A(N+2);
	for (int i = 1; i < N+1; i++) {
		cin >> A.at(i);
	}
	A.at(0) = A.at(N) - K ;
	A.at(N+1) = A.at(1);
	for (int i = 1; i < N+1; i++) {
		if (A.at(i + 1) - A.at(i) > A.at(i) - A.at(i - 1)) {
			min = K - (A.at(i + 1) - A.at(i));
		}
		else {
			min = K - (A.at(i) - A.at(i - 1));
		}
		if (Min > min) {
			Min = min;
		}
	}
	cout << Min << endl;
	return 0;
}

Measured memory_bytes: 1024
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
const int M = 2e5 + 9 ;
int a[M];
int b[M];

int n ;
int main ()
{
    scanf ("%d" , &n);
    for (int i =0 ; i < n ;i++)scanf ("%d" , a+i);
    for (int i =0 ; i < n ;i++)
    {
        b[i] = a[i] - i-1 ;
    }
    sort(b,b+n);
    ll sum =0 ;
    for (int i =0 ; i < n ;i++)
    {
        sum += abs (a[i] - (i+1+b[n/2]));
    }
    printf ("%lld\n" ,sum );
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
class Main
{
  public static void main (String[] args) throws Exception
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str1 = br.readLine();
        String str2 = br.readLine();
        int n = str1.length();
        int m = str2.length();
        int[][] dp = new int[n+1][m+1];
        for(int i = 0; i <= n; i++)
        {
            for(int j = 0; j <= m; j++)
            {
                if(i == 0 || j == 0)
                {
                    dp[i][j] = 0;
                }
                else if(str1.charAt(i-1) == str2.charAt(j-1))
                {
                    dp[i][j] = dp[i-1][j-1]+1;
                }
                else
                {
                    dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        //System.out.println(dp[n][m]);
        StringBuffer res = new StringBuffer();
        int p = n, q = m;
        while(p > 0 && q > 0)
        {
            if(str1.charAt(p-1) == str2.charAt(q-1))
            {
                res.append(str1.charAt(p-1));
                p--;
                q--;
            }
            else if(dp[p][q] == dp[p-1][q])
            {
                p--;
            }
            else
            {
                q--;
            }
        }
        System.out.println(res.reverse());
    }
}

Measured memory_bytes: 81620
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define rg register  
const int MN=10000+5;
using namespace std;
typedef long long ll;
template<typename T>inline T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n,ans,s;
int a[MN];
void input(){
	IN(n);IN(s);
	for(int i=1;i<=n;++i)IN(a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i){
		if(a[i]<=s){
			ans++,s-=a[i];
		}
	}
	if(s&&ans==n)ans--;
	
	printf("%d\n",ans);
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline()[:-1]
n=int(input())
A=list(map(int,input().split()))
q=int(input())
M=list(map(int,input().split()))

dp=[[0]*2001 for i in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
	for j in range(2001):
		# print(i-1)
		if 0<=j-A[i-1]<=2000:
			dp[i][j]=dp[i-1][j-A[i-1]] or dp[i-1][j]
		else:
			dp[i][j]=dp[i-1][j]

for m in M:
		print('yes' if dp[n][m] else 'no')
# for i in dp:
# 	print(i)
# print(dp[0][0])





Measured memory_bytes: 5952
//--------------------------------------------------------------------------------
// Code By:
//					######                  #               ######
//					##   #                  #               #
//					#####      ##       #####      ##       #   ###
//					##   #              #   #               #   # #
//					##    #	            #####               ##### #
//---------------------------------------------------------------------------------

#include<bits/stdc++.h>
using namespace std;

                             /* ----------------------------- START of Template ---------------*/
#define ll long long int
#define FOR(x,to) for(x=0;x<(to);x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<long long int> >
#define vll vector<long long int>
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SZ(X) ((int)(X).size())
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second

void getZarr(string str, vll &Z)
{
    ll n = str.length();
    ll L, R, k;
    L = R = 0;
    for (ll i = 1; i < n; ++i)
    {
        if (i > R)
        {
            L = R = i;
            while (R<n && str[R-L] == str[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            k = i-L;
            if (Z[k] < R-i+1)
                Z[i] = Z[k];
            else
            {
                L = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
   } } }}
vector<ll>isprime;
void seive(ll size){
	isprime.resize(size+1,1);
	ll i,j;
	isprime[0]=0;
	isprime[1]=0;
	for(i=2;i*i<=size;i++){
		if(isprime[i]){
			for(j=2;j*i<=size;j++)isprime[i*j]=0;
		}
	}
}
ll power(ll x,unsigned ll y, ll m){
	if(y==0)return 1;
	ll p=power(x,y/2,m);
	p=(p*p)%m;
	if(y%2!=0)p=(p*x)%m;
	return p;
}
ll modinverse(ll a,ll m){
	return power(a,m-2,m);
}


                       /* ----------------------          End Of Template --------------------------------*/

ll findans(){
	ll l,r,d;
	cin>>l>>d>>r;
	ll ans=d/r-l/r;
	if(l%r==0)ans++;
	cout<<ans<<endl;
	return 0;



}

int main(){
	ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll t,i;
//	cin>>t;
t=1;
	for(i=0;i<t;i++){
		findans();
	}
return 0;
}






Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n,m;
  cin >> n >> m;
  int a[m],b[m],bbit[m];
  rep(i,m){
    cin >> a[i] >> b[i];
    bbit[i]=0;
    rep(j,b[i]){
      int c;
      cin >> c;
      c--;
      bbit[i]|=(1<<c);
    }
  }
  ll dp[(1<<n)];
  rep(i,(1<<n)) dp[i]=INT_MAX;
  dp[0]=0;
  rep(i,m){
    rep(j,(1<<n)){
      dp[(j|bbit[i])] = min(dp[(j|bbit[i])], dp[j]+a[i]);      
    }
  }
  //  cout << dp[(1<<n)-1] <<endl;
  if(dp[(1<<n)-1]>=INT_MAX) cout << -1 << endl;
  else cout << dp[(1<<n)-1] <<endl;
  
  
  return 0;
    

}


Measured memory_bytes: 256
#include<iostream>
int main(){
int na,nb;
std::cin>>na>>nb;
if(na < nb)
std::cout<<"a < b"<<std::endl;
else if(na > nb)
std::cout<<"a > b"<<std::endl;
else 
std::cout<<"a == b"<<std::endl;
return 0;
}

Measured memory_bytes: 1156
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_MOD			1000000007								// 除数(10の9乗+7)
#define D_ARRAY_MAX		300000									// 最大配列数
#define D_DIGIT_MAX		65										// 最大桁数

// 内部変数
static FILE *szpFpI;											// 入力
static int siACnt;												// 配列数
static int si2Array[D_ARRAY_MAX][D_DIGIT_MAX];					// 配列
static int si1Sum[D_DIGIT_MAX];									// 合計

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 合計 - 加算
int
fAddSum(
	int piAdd					// <I> [1]加算 [-1]減算
	, int *pipArray				// <I> 配列
)
{
	int i;

	for (i = 0; i < D_DIGIT_MAX; i++) {
		si1Sum[i] += pipArray[i] * piAdd;
	}

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i, j;
	char lc1Buf[1024];

	// 配列数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列 - 取得
	for (i = 0; i < siACnt; i++) {
		long long llVal;
		fscanf(szpFpI, "%lld", &llVal);

		// ２進数化
		for (j = 0; llVal > 0; j++) {
			if (llVal % 2 == 1) {
				si2Array[i][j] = 1;
			}
			llVal /= 2;
		}

		// 合計 - 加算
		fAddSum(1, si2Array[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 解答 - 取得
	int liAns = 0;
	for (i = 0; i < siACnt; i++) {

		// 合計 - 減算
		fAddSum(-1, si2Array[i]);

		// 各桁 - チェック
		long long llRate = 1;
		for (j = 0; j < D_DIGIT_MAX; j++) {
			long long llAdd = llRate % D_MOD;
			if (si2Array[i][j] == 0) {
				llAdd *= si1Sum[j];
			}
			else {
				llAdd *= siACnt - i - 1 - si1Sum[j];
			}
			llAdd %= D_MOD;
			liAns += (int)llAdd;
			liAns %= D_MOD;
			llRate *= 2;
		}
	}

	return liAns;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	memset(si2Array, 0, sizeof(si2Array));						// 配列
	memset(si1Sum, 0, sizeof(si1Sum));							// 合計

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 76288
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll a,b;cin>>a>>b;b*=2;b++;
    cout<<a/b+(a%b==0?0:1)<<"\n";
}


Measured memory_bytes: 256
h, w, d = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]

L = [[0, 0] for _ in range(h*w)]
for i in range(h):
    for j in range(w):
        id = A[i][j]
        id -= 1
        L[id][0] = i
        L[id][1] = j

C = [0]*(h*w)
for i in range(h*w):
    ni = i+d
    if ni <= h*w-1:
        C[ni] = C[i]+abs(L[ni][0]-L[i][0])+abs(L[ni][1]-L[i][1])
#print(C)

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    l, r = l-1, r-1
    print(C[r]-C[l])


Measured memory_bytes: 61916
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  vector<queue<char>> vec(3);
  rep(i,3){
    string s;
    cin >> s;
    int n = s.size();
    rep(j,n)vec[i].push(s[j]);
  }
  
  int now=0;
  while(true){
    if(vec[now].empty()){
      cout << char(now+'A') << endl;
      return 0;
    }
    char c=vec[now].front();
    vec[now].pop();
    now = c-'a';
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


vector<int>v[105];
int t[105]={};
bool flag[105]={};
void BFS(int p)
{
	queue<int>Q;	
	Q.push(p);
	flag[p]=true;
	while(!Q.empty())
	{
		p=Q.front();
		Q.pop();
		for(int i=0;i<v[p].size();i++)
		{
			if(!flag[v[p][i]])
			{
				t[v[p][i]]=t[p]+1;
				Q.push(v[p][i]);
			}
			flag[v[p][i]]=true;
		}
	}
}
int main()
{	
	int n,a,b,k;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>k;
		for(int j=0;j<k;j++)
		{
			cin>>b;
			v[a].push_back(b);
		}
	}
	BFS(1);
	for(int i=1;i<=n;i++)
	{
		cout<<i<<" ";
		if(i!=1&&t[i]==0)cout<<-1<<endl;
		else cout<<t[i]<<endl;
	}
	return 0;
}



Measured memory_bytes: 3156
N = int(input())
arr = [[[0 for i in range(10)] for j in range(3)]for r in range(4)]
for i in range(N):
    a=[]
    a.append(list(map(int,input().split())))
    b=a[0][0]-1
    f=a[0][1]-1
    r=a[0][2]-1
    v=a[0][3]
    arr[b][f][r]+=v

for i in range(0,3):
    for j in range(0,3):
        print(" "+" ".join(map(str,arr[i][j])))
    print("#"*20)
for i in range(3):
    print(" "+" ".join(map(str,arr[3][i])))

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

struct Dice {
	int d[6], E, S, U;
	Dice(int a[]) {
		rep(i, 6)d[i] = a[i];
		E = 2; S = 1; U = 0;
	}
	void rotate(char C) {
		int a = E, b = S, c = U;
		switch (C) {
		case'E':
			E = U; U = 5 - a;
			break;
		case'N':
			U = S; S = 5 - c;
			break;
		case'S':
			S = U; U = 5 - b;
			break;
		case'W':
			U = E; E = 5 - c;
			break;
		}
	}
};
int main() {
	int a[6]; rep(i, 6)cin >> a[i];
	string s; cin >> s;
	Dice d(a);
	for (char c : s)d.rotate(c);
	cout << d.d[d.U] << endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);++i)
#define test(x) cout << #x << ' ' << x << endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair 


int main () {
	lli n;
	cin >> n;
	cout << n*(n-1)/2 << endl;
}

Measured memory_bytes: 384
days = input()

day1 = days[0]
day2 = days[1]
day3 = days[2]

ans = 0

if day1 == "R":
    ans += 1
    if day2 == "R":
        ans += 1
        if day3 == "R":
            ans +=1
elif day2 == "R":
    ans += 1
    if day3 == "R":
         ans +=1

elif day3 == "R":
    ans +=1

print(ans)

Measured memory_bytes: 8956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=100005;
vector<int> v[N];
int ans,sz[N],q[N],f[N],x,y,vis[N],dep[N];
void GG(){
	puts("-1"); exit(0);
}
void dfs(int p,int fa){
	vis[p]=1; f[p]=fa;
	for(auto i:v[p])if(i!=fa){
		if(vis[i]){x=p; y=i; continue;}
		dep[i]=dep[p]^1; dfs(i,p);
		sz[p]+=sz[i];
	}
	sz[p]=-(sz[p]-1);
	ans+=abs(sz[p]);
}
int lca(int x,int y){
	static int v[N];
	memset(v,0,sizeof(v));
	for(int i=x;i;i=f[i])v[i]=1;
	for(int i=y;i;i=f[i])if(v[i])return i;
}
int main(){
	int n=read(),m=read();
	For(i,1,m){
		int s=read(),t=read();
		v[s].pb(t); v[t].pb(s);
	}
	dfs(1,0);
	if(n&1)GG();
	if(m+1==n){
		if(sz[1])GG();
		cout<<ans<<endl;
	}else{
		if(dep[x]==dep[y]){
			int cn=sz[1]/2;
			if(dep[x]==0)cn=-cn;
			for(int i=x;i;i=f[i]){
				ans-=abs(sz[i]); sz[i]+=cn*(((dep[x]-dep[i])&1)?-1:1); ans+=abs(sz[i]);
			}
			for(int i=y;i;i=f[i]){
				ans-=abs(sz[i]); sz[i]+=cn*(((dep[y]-dep[i])&1)?-1:1); ans+=abs(sz[i]);
			}
			cout<<ans+abs(cn)<<endl;
		}else{
			if(sz[1])GG(); 
			int t=lca(x,y);
			for(int i=x;i!=t;i=f[i]){
				q[++*q]=(((dep[x]-dep[i])&1)?-1:1)*sz[i]; ans-=abs(sz[i]);
			}
			for(int i=y;i!=t;i=f[i]){
				q[++*q]=(((dep[y]-dep[i])&1)?-1:1)*sz[i]; ans-=abs(sz[i]);
			}
			sort(&q[1],&q[*q+1]); q[++*q]=0;
			int jj=q[(*q+1)/2];
			//cout<<ans<<" "<<jj<<endl;
			//For(j,1,*q)wri(q[j]);
			For(j,1,*q)ans+=abs(q[j]-jj);
			cout<<ans<<endl;
		}
	}
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int main()
{
    int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};
    int w,h;
    while(scanf(" %d %d", &w, &h), w)
    {
        int n;
        scanf(" %d", &n);

        vector<int> x1(n), y1(n), x2(n), y2(n);
        vector<int> x,y;

        rep(i,n)
        {
            scanf(" %d %d %d %d", &x1[i], &y1[i], &x2[i], &y2[i]);
            x.pb(x1[i]);
            x.pb(x2[i]);
            y.pb(y1[i]);
            y.pb(y2[i]);
        }

        x.pb(0);
        x.pb(w);
        y.pb(0);
        y.pb(h);

        sort(all(x));
        x.erase(unique(all(x)),x.end());
        sort(all(y));
        y.erase(unique(all(y)),y.end());

        int X=x.size(), Y=y.size();

        vector<vector<int>> f(Y,vector<int>(X,0)), dp(Y,vector<int>(X));

        rep(i,X) f[Y-1][i]=1;
        rep(i,Y) f[i][X-1]=1;

        rep(i,n)
        {
            int lx = lower_bound(all(x),x1[i])-x.begin();
            int rx = lower_bound(all(x),x2[i])-x.begin();
            int ly = lower_bound(all(y),y1[i])-y.begin();
            int ry = lower_bound(all(y),y2[i])-y.begin();

            // printf("%d,%d  %d %d\n", lx,rx, ly,ry);
            ++f[ly][lx];
            --f[ly][rx];
            --f[ry][lx];
            ++f[ry][rx];
        }

        dp[0][0]=f[0][0];
        for(int i=1; i<X; ++i) dp[0][i] = dp[0][i-1]+f[0][i];
        for(int i=1; i<Y; ++i) dp[i][0] = dp[i-1][0]+f[i][0];

        for(int i=1; i<Y; ++i)for(int j=1; j<X; ++j) dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+f[i][j];

        // for(int i=Y-1; i>=0; --i)
        // {
        //     rep(j,X) printf("%d", dp[i][j]);
        //     printf("\n");
        // }

        vector<vector<bool>> vis(Y,vector<bool>(X,false));

        #define IN(a,b) (0<=a && a<X && 0<=b && b<Y)
        int ans=0;
        rep(i,Y)rep(j,X)
        {
            if((dp[i][j]>0) || vis[i][j]) continue;

            ++ans;

            queue<pi> que;
            que.push(pi(i,j));
            vis[i][j]=true;
            while(!que.empty())
            {
                pi now=que.front();
                que.pop();
                rep(k,4)
                {
                    int nx=now.se+dx[k], ny=now.fi+dy[k];
                    if(IN(nx,ny) && !vis[ny][nx] && dp[ny][nx]==0)
                    {
                        vis[ny][nx]=true;
                        que.push(pi(ny,nx));
                    }
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

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

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

  string a, b;
  cin >> a >> b;

  int c = stoi(a + b);
  int root = sqrt(c);

  if (root * root == c) cout << "Yes" << "\n";
  else cout << "No" << "\n";
}


Measured memory_bytes: 3664
#include<iostream>
#include<stack>
#include<queue>
#include<map>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%lld",&x);
int main(){
    ll n, m, ans;
    sc(n) sc(m)
    if (n * 2 < m) ans = (m - 2 * n) / 4 + n;
    else if (n * 2 == m) ans = n;
    else if (n * 2 > m) ans = m / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int a[100][100],b[100][100];
main()
{
	while(cin>>m>>n,n)
	{
    	for(int i=0;i<n;i++)for(int j=0;j<n;j++)
    	{
    		if(i==j)continue;
    		a[i][j]=1e9;
    		b[i][j]=1e9;
    	}
    	for(int i=0;i<m;i++)
    	{
    		int s,t,u,v;cin>>s>>t>>u>>v;
    		s--,t--;
    		a[s][t]=min(a[s][t],u);
    		a[t][s]=min(a[t][s],u);
    		b[s][t]=min(b[s][t],v);
    		b[t][s]=min(b[t][s],v);
    	}
    	for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)
    	{
    		a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
    		b[i][j]=min(b[i][j],b[i][k]+b[k][j]);
    	}
    	int k;cin>>k;
    	for(;k--;)
    	{
    		int p,q,r;cin>>p>>q>>r;
    		p--,q--;
    		if(r)cout<<b[p][q]<<endl;
    		else cout<<a[p][q]<<endl;
    	}
	}
}



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

#define all(x) (x).begin(),(x).end()
#define init() \
  ios::sync_with_stdio(false); \
  cin.tie(0)

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
  return a == 0 ? b
    : b == 0 ? a
    : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

int main() {
  init();

  int n, y;
  cin >> n >> y;

  for (int i = n; i >= 0; i--) {
    for (int j = n - i; j >= 0; j--) {
      int k = n - j - i;
      if (i * 1000 + j * 5000 + k * 10000 == y) {
        cout << k << ' ' << j << ' ' << i << '\n';
        return 0;
      }
    }
  }

  cout << -1 << ' ' << -1 << ' ' << -1 << '\n';
  return 0;
}


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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;

int main(void) {
    int x, y, z;
    cin >> x >> y >> z;

    

    printf("%d %d %d\n", z, x, y);

	return 0;
}


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

bool check(string S){
  if(S[0]!='A') return false;
  int C=0;
  for(int i=2;i<S.length()-1;i++){
    if(S[i]=='C'){
      C++;
    }
  }
  if(C!=1) return false;
  int upper=0;
  for(int i=0;i<S.length();i++){
    if(S[i]>='A'&&S[i]<='Z'){
      upper++;
    }
  }
  if(upper!=2) return false;
  return true;
}
 
int main(){
  string S;
  cin>>S;
  if(check(S)){
    cout<<"AC"<<endl;
  }
  else{
    cout<<"WA"<<endl;
  }
}

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

#define int long long

vector<int> tree[200010];
int imos[200010];
int cnt[200010];

void solve(int idx, int par, int c){
    c += imos[idx];
    cnt[idx] = c;

    for(auto e : tree[idx]){
        if(e != par) solve(e, idx, c);
    }
    return;

}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;

    for(int i = 0;i < n-1;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    for(int i = 0;i < q;i++){
        int p, x;
        cin >> p >> x;
        imos[--p] += x;
    }

    solve(0, -1, 0);

    cout << cnt[0];
    for(int i = 1;i < n;i++){
        cout << " " << cnt[i]; 
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 25600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cost=0;
ll a,b,c,d;
void solve(ll sz)
{
	ll x1=a/sz,y1=b/sz,x2=c/sz,y2=d/sz;
	if(x1!=x2||y1!=y2)
	{
		if(x1==x2&&x1%3==1&&abs(y1-y2)>1)
		{
			cost=min(a%sz+c%sz+2,2*sz-a%sz-c%sz)+abs(d-b);
			return;
		}
		if(y1==y2&&y1%3==1&&abs(x1-x2)>1)
		{
			cost=min(b%sz+d%sz+2,2*sz-b%sz-d%sz)+abs(a-c);
			return;
		}
	}
	if(sz>1)
	{
		solve(sz/3);
	}
}
int main(void)
{
	ll q;
	ll three=1;
	scanf("%lld",&q);
	for(ll i=0;i<30;i++) three*=3;
	while(q--)
	{

		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		a--,b--,c--,d--;
		cost=abs(a-c)+abs(b-d);
		solve(three/3);
		printf("%lld\n",cost);
	}
}

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

int main() {
    int H, W, N;
    cin >> H >> W;
    cin >> N;

    vector<vector<int>> grid(H, vector<int>(W));    
    vector<int> a(N);

    for(int i=0; i<N; ++i) {
        cin >> a[i];
    }
    int h=0, w=0;
    for(int i=0; i<N; ++i) {
        int cnt=a[i];
        while(cnt>0) {
            if((h+1)%2 != 0) {
                grid[h][w] = (i+1);
                w++;
                cnt--;
                if(w == W) {
                    w--;
                    h++;
                }  
            }
            else {
                grid[h][w] = (i+1);
                w--;
                cnt--; 
                if(w == -1) {
                    w++;
                    h++;
                }           
            }
            
        }
    }

    for(auto g1: grid){
        for(auto g2 :g1) {
            cout << g2 << " ";
        }
        cout << endl;
    } 
}

Measured memory_bytes: 384
def ss():
    N,Q = list(map(int,input().split()))
    s = input()
    lis=[0]*N
     
    count = 0
    for i in range(1,len(s)):
        if s[i-1] == 'A' and s[i] == 'C':
            count +=1
        lis[i]+=count
    for i in range(Q):
        l,r = list(map(int,input().split()))
        print(lis[r-1]-lis[l-1])

ss()

Measured memory_bytes: 13124
N, Q = map(int, input().split())
S = input()

orders = []
for i in range(Q):
    t, d = input().split()
    orders.append([t, d])

def check(i):
    cur = i
    for o in orders:
        if o[0] == S[cur]:
            if o[1] == 'L':
                if cur == 0:
                    return -1
                cur -= 1
            else:
                if cur == len(S) - 1:
                    return 1
                cur += 1
    return 0


left_most = 0
right_most = len(S)-1
ci = (right_most + left_most) // 2
res = 0
while True:
    res = check(ci)
    if res < 0:
        left_most = ci + 1
    elif res >= 0:
        right_most = ci - 1

    if left_most > right_most:
        break
    ci = (right_most + left_most) // 2


# see left_most
l = left_most

left_most = 0
right_most = len(S)-1
ci = (right_most + left_most) // 2
res = 0
while True:
    res = check(ci)
    if res <= 0:
        left_most = ci + 1
    elif res > 0:
        right_most = ci - 1

    if left_most > right_most:
        break
    ci = (right_most + left_most) // 2

r = right_most


print(max(r - l + 1, 0))

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

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

    string n;
    cin >> n;

    if(n[0] == '9' || n[1] == '9'){
        puts("Yes");
    }else{
        puts("No");

    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    int count = 1;
		while(true){
			int num = sc.nextInt();
			if(num == 0){
				break;
			}else{
				System.out.println("Case " + count +": " + num);
			}
			count++;
		}
		
	}
}


Measured memory_bytes: 40988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

vector<int> eratosthenes(int n){
    vector<int> arr(n,1);
	for(int i = 2; i < sqrt(n); i++){
		if(arr[i]){
			for(int j = 2; i * j < n; j++){
				arr[i*j] = 0;
			}
		}
	}
    return arr;
}

vector<int> make_prime_list(int n){
    vector<int> prime = eratosthenes(n);
    vector<int> prime_list;
    for(int i = 2; i < n; i++){
		if(prime[i]){
			prime_list.push_back(i);
		}
	}
    return prime_list;
}

int main() {
    int n;
    cin >> n;
    vector<int> prime_list = make_prime_list(n);
    map<int,int> mp;
    for(int i = 2; i <= n; i++){
        int t = i;
    	for(auto elem: prime_list){
            while(t%elem == 0){
                t /= elem;
                mp[elem]++;
            }
    	}
    }
    int ans = 0;
    int num74=0, num24=0, num14=0, num4=0, num2=0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if(itr->second>=74){num74++;}
        if(itr->second>=24){num24++;}
        if(itr->second>=14){num14++;}
        if(itr->second>=4){num4++;}
        if(itr->second>=2){num2++;}
    }
    ans += num74;
    ans += num24*(num2-1);
    ans += num14*(num4-1);
    ans += num4*(num4-1)*(num2-2)/2;

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


Measured memory_bytes: 256
#include <iostream>
#include <string>

std::string s;
int g_cou, p_cou, ans;

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

	for (int i = 0; i < s.length(); ++i)
	{
		if (s[i] == 'g')
		{
			if (p_cou >= g_cou)
			{
				++g_cou;
			}
			else
			{
				++ans;
				++p_cou;
			}
		}
		else
		{
			if (p_cou >= g_cou)
			{
				--ans;
				++g_cou;
			}
			else
			{
				++p_cou;
			}
		}
	}

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

Measured memory_bytes: 512
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        
        if(A*B > C*D){
            System.out.println(A*B);
        }else if(A*B == C*D){
            System.out.println(A*B);
        }else if(A*B < C*D){
            System.out.println(C*D);
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{long long n,x,t,y,i;
 string s;
 cin>>s;n=s.length();y=0;
for(i=0;i<n;i++)
{y=y+s[i]-'0';}
 if(y%9==0)cout<<"Yes";
 else cout<<"No";
return 0;}

Measured memory_bytes: 3668
# input
N = int(input())
A = [ list(map(int,input().split()))
      for i in range(N) ]

# 初期化
dp = [[0,0,0] for i in range(N)] # (N, 3)
dp[0] = A[0]; 

for i_day in range(1,N):
  dp[i_day][0] = max(dp[i_day-1][1]+A[i_day][0], dp[i_day-1][2]+A[i_day][0])
  dp[i_day][1] = max(dp[i_day-1][0]+A[i_day][1], dp[i_day-1][2]+A[i_day][1])
  dp[i_day][2] = max(dp[i_day-1][0]+A[i_day][2], dp[i_day-1][1]+A[i_day][2])
  
print(max(dp[-1]))
    

Measured memory_bytes: 47344
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD3 1000000000
#define MOD2 998244353
float PHI = 1.6180339;
const float  PI_F=3.14159265358979f;
#define MAX 1000 m
#define endl "\n"    
#define manhunt 32 
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define pi 3.1415926535897932384626433
//typedef long long float;
#define int long long
//#define double long long
typedef pair<int, int> pii;
//#define float unsigned long long
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define CHAR_SIZE 26 

int modpow(int x, int n, int m) { if (n == 0) return 1%m; long long u = modpow(x,n/2,m); u = (u*u)%m; if (n%2 == 1) u = (u*x)%m; return u; } 


int add(int x, int y) 
{
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
int sub(int x, int y) 
{
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
int inv(int a, int m = MOD2)
{
	return modpow(a, m - 2, m);
}
int mul(int a, int b) 
{
	return (long long) a * b % MOD2;
}


int nCrModp(int n, int r, int p) 
{ 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (int i = 1; i <= n; i++) 
    { 
        for (int j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 

int32_t main()
{
    /* freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); */
    FAST
    cout << fixed << setprecision(12);
 
    
    int n,k;
    cin>>n>>k;
    int arr[n+10];
    int pos[n+10];
    set<int>s;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        pos[i]=arr[i];
    }
    
    int st=1;
    int cnt=0;
    int flag=0;
    vector<int>v;
    int value;
    while(true)
    {
        s.insert(st);
        v.push_back(st);
        int nxt=pos[st];
        st=nxt;
        ++cnt;
        if(cnt==k)
        {
            flag=1;
            cout<<st<<endl;
            break;
        }
        if(s.find(st)!=s.end())
        {
            value=st;
            break;
        }
    }
    if(flag!=1)
    {
        // for(int c:v)
        // cout<<c<<" ";
        int p=0;
        vector<int>dp;
        for(int i=0;i<v.size();i++)
        {
            if(v[i]==value)
            break;
            ++p;
        }
        for(int i=p;i<v.size();i++)
        {
            dp.push_back(v[i]);
        }
        int left=k-v.size();
        //cout<<k<<" "<<dp.size()<<endl;
        int val=left%(dp.size());
        int ans=dp[val];
        cout<<ans<<endl;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 


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

int K; cin >> K;
VI A(K); invec(A);

i64 mini, maxi;
i64 l = 0, r = INF;
while (r - l > 1){
    i64 mid = (r + l) / 2;
    i64 m = mid;
    for(i64 a: A) m -= m%a;

    if (m >= 2) r = mid;
    else l = mid;
}
mini = r;

l = 0, r = INF;
while (r - l > 1){
    i64 mid = (r + l) / 2;
    i64 m = mid;
    for(i64 a: A) m -= m%a;

    if (m <= 2) l = mid;
    else r = mid;
}
maxi = l;

if (mini > maxi ) cout << "-1\n";
else cout << mini << ' ' << maxi << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 1024
import heapq
N=int(input())
a=[int(i) for i in input().split()]
#ans[i]-> k=i+N,
red=[0 for i in range(N+1)]
blue=[0 for i in range(N+1)]
r=list(a[:N])
b=list([-i for i in a[2*N:]])
heapq.heapify(r)
heapq.heapify(b)
red[0]=sum(a[:N])
for i in range(N):
    k=i+N
    tmp1=a[k]
    heapq.heappush(r,a[k])
    tmp2=heapq.heappop(r)
    red[i+1]=red[i]-tmp2+tmp1
blue[-1]=sum(a[2*N:])
for i in range(N)[::-1]:
    k=i+N
    tmp1=a[k]
    heapq.heappush(b,-a[k])
    tmp2=-heapq.heappop(b)
    blue[i]=blue[i+1]-tmp2+tmp1
ans=[red[i]-blue[i] for i in range(N+1)]
print(max(ans))


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

int main()
{
    long long int a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    
    if(a<k)
    {
        ans+=a;
        k-=a;
    }
    else
    {
        cout<<k;
        return 0;
    }
    
    if(b<k)
        k-=b;
    else
    {
        cout<<ans;
        return 0;
    }
    
    cout<<ans-k;
}

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

int main() {
	// your code goes here
	long long a[5];
	for (int i = 0; i < 5; i++) {
	    cin>>a[i];
	}
	for (int i = 0; i < 5; i++) {
	    if(a[i]==0)
	    {
	        cout<<i+1;
	    }
	}
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 1001

ll n,m;
ll cost[MAX],keys[MAX];
ll a[MAX];
ll dp[MAX][(1<<13)];

ll f(ll i,ll mask){
	if((mask)+1==(1LL<<n)) return 0;
	if(i==m) return 1e18;

	if(dp[i][mask]!=-1) return dp[i][mask];

	ll t1 = f(i+1,mask);
	ll t2 = f(i+1,mask|a[i]) + cost[i];

	dp[i][mask] = min(t1,t2);
	return min(t1,t2);

}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	For(i,0,m){
		cin>>cost[i]>>keys[i];
		a[i] = 0;
		For(j,0,keys[i]){
			ll t;cin>>t;
			t--;
			a[i] = (a[i]|(1LL<<t));
		}
	}
	ll ans = f(0,0);
	if(ans==1e18){
		cout<<-1<<endl;
		return 0;
	}
	cout<<ans<<endl;






























	
}

Measured memory_bytes: 64512
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 62;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

struct Ruiseki {
	int N;
	vector<ll> B;
	void init(int n) {
		N = n; B = vector<ll>(N + 1, 0);
	}
	Ruiseki() {}
	Ruiseki(int n) { init(n); }
	void add(int a, ll v) {
		if(a < 0 || N <= a) return;
		B[a + 1] += v;
	}
	void sweep() {
		rep(i, 1, N + 1) B[i] += B[i - 1];
	}
	ll get(int a, int b) { //[a, b)
		if(a >= b) return 0;
		a = max(a, 0); b = min(b, N);
		return B[b] - B[a];
	}
};

int N; ll X;
Ruiseki B;

void solve() {
	cin >> N >> X;
	B.init(N);
	rep(i, 0, N) {
		ll a; cin >> a;
		B.add(i, a);
	}
	B.sweep();

	ll res = linf;

	rep(i, 1, N + 1) {
		int cnt = 3;
		int at = N;
		ll tmp = N * X + i * X + B.get(N - i, N) * 2;
		while(at > 0 && tmp < res) {
			tmp += B.get(at - i, at) * cnt;
			cnt += 2;
			at -= i;
		}
		// debug(i, tmp);
		if(at <= 0) MIN(res, tmp);
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
signed main(){

    int N, M;
    cin>>N>>M;
    cout<<N*(N-1)/2+M*(M-1)/2<<endl;

    return 0;
}


Measured memory_bytes: 256