akhauriyash/Code-Regression huggingface dataset:
def gcd(x,y):
    if x==y:
        return x
    elif x>y:
        r=-1
        while r!=0:
            r=x%y
            x=y
            y=r
        return x
    else:
        r=-1
        while r!=0:
            r=y%x
            y=x
            x=r
        return y

k=int(input())
ans=0
d=[[0]*(1+k) for i in range(1+k)]
for i in range(1,1+k):
    for j in range(1,1+k):
        d[i][j]=gcd(i,j)
for i in range(1,1+k):
    for j in range(1,1+k):
        for l in range(1,1+k):
            ans+=d[d[i][j]][l]

print(ans)


Measured memory_bytes: 68576
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  ll n;
  cin >> n;
 
  ll ans = 1;
  
  repo(i,n+1){
    ans = (ans*i)%num;
  }
  
  cout << ans << endl;
  
}


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

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

using namespace std;

struct Data {
  int start,end,onAir,recorded;
  bool operator < ( const Data &data ) const {
    if( end != data.end ) return end < data.end;
    if( start != data.start ) return start < data.start;
    return ( onAir != data.onAir ) ? onAir < data.onAir : recorded < data.recorded;
  }
};

const int MAX_N = 1100;
const int IINF = INT_MAX;
int N,s[MAX_N],t[MAX_N],score[MAX_N][2],dp[2000][2000];
vector<int> buf;

int toTime(string s){
  rep(i,(int)s.size()) if( s[i] == ':' ) s[i] = ' ';
  stringstream ss;
  ss << s;
  int h,m;
  ss >> h >> m;
  return h * 60 + m;
}

int main(){
  while( cin >> N, N ){
    vector<Data> vec;
    rep(i,N) {
      string a,b,c;
      cin >> a >> b >> c >> score[i][0] >> score[i][1];
      assert( b != c );
      s[i] = toTime(b), t[i] = toTime(c);
      vec.push_back((Data){s[i],t[i],score[i][0],score[i][1]});
    }
    vec.push_back((Data){0,0,0,0});
    vec.push_back((Data){IINF,IINF,0,0});
    rep(i,N+2) rep(j,N+2) dp[i][j] = 0; 
    sort(vec.begin(),vec.end());
    //rep(i,vec.size()) cout << "[" <<vec[i].start << "," << vec[i].end << "] : " << vec[i].onAir << " and " << vec[i].recorded << endl;
    buf.clear();
    int maxi = 0;
    rep(i,vec.size()) buf.push_back(vec[i].end);
    rep(i,vec.size()){
      rep(j,vec.size()){
        if( i == j ) {
          dp[i][j] = max((i?dp[i-1][j]:0),(j?dp[i][j-1]:0));
        } else if( i < j ) {
          dp[i][j] = dp[i][j-1];
          int prev = upper_bound(buf.begin(),buf.begin()+j,vec[j].start) - buf.begin();
          //if( prev == j ) -- prev;
          if( buf[prev] > vec[j].start ) --prev;

          dp[i][j] = max(dp[i][j],((prev!=-1)?dp[i][prev]:0)+vec[j].recorded);
        } else {
          dp[i][j] = dp[i-1][j];
          int prev = upper_bound(buf.begin(),buf.begin()+i,vec[i].start) - buf.begin();
          //if( prev == i ) -- prev;
          if( buf[prev] > vec[i].start ) --prev;
          dp[i][j] = max(dp[i][j],((prev!=-1)?dp[prev][j]:0)+vec[i].onAir);
        }
        maxi = max(maxi,dp[i][j]);
        //cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
      }
    }
    cout << maxi << endl;
  }
  return 0;
}

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

#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)

int main(){
    int n,k;
    cin >> n >> k;
    int a[n];
    rep(i,0,n){
         cin >> a[i];   
    }
    bool dp[k + 1];
    dp[0] = false;
    rep(i,1,k + 1){
            dp[i] = false;
            rep(j,0,n){
                    if(i >= a[j]){
                            if(dp[i - a[j]] == false) dp[i] = true; 
                    }
            }
    }
    if(dp[k]) cout << "First";
    else cout << "Second";

}

Measured memory_bytes: 384
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>
#include <complex>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;

/*-----------------------------------------------------------------------------
　幾何学ライブラリ
 -------------------------------------------------------------------------------*/
/* 基本要素 */
typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = 1e-9;    // 許容誤差。問題によって変える
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
namespace std {
  bool operator<(const P a, const P b) {
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}

/*-----------------------------------------------------------------------------
　メイン
 -------------------------------------------------------------------------------*/
int main()
{
	int A, B;
	cin >> A >> B;
	int ans = A + B;
	ans = max(ans, A - B);
	ans = max(ans, A * B);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <complex>
#include <cmath>

using Real = long double;
using Point = std::complex<Real>;
using Segment = std::pair<Point, Point>;

template <class T>
inline T sq(T x) { return x * x; }

inline Real length(Segment l) {
    return std::abs(l.second - l.first);
}

// 内積
inline Real prod(Point x, Point y) {
    return std::real(std::conj(x) * (y));
}

// lに対するxの正射影
Point proj(Segment l, Point p) {
    Real ratio = prod(l.second - l.first, p - l.first) / sq(length(l));
    return l.first + (l.second - l.first) * ratio;
}

// lを軸としてxに対称な点
Point refl(Segment l, Point p) {
    Point t = proj(l, p);
    return t + (t - p);
}

using namespace std;

int main() {
    cout << fixed << setprecision(10);

    Real x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Segment l(Point(x1, y1), Point(x2, y2));

    int Q;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        Real x, y;
        cin >> x >> y;
        Point p(x, y);

        Point ret = refl(l, p);
        cout << ret.real() << " " << ret.imag() << endl;
    }
    return 0;
}



Measured memory_bytes: 3336
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


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

    int h,a;
    cin>>h>>a;
    cout<<(h+a-1)/a<<endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,W,sum;
int w[101],v[101];
int dp[101][100001];
int main()
{
	cin>>n>>W;
	
	for(int i=0;i<n;i++)
	{
		cin>>w[i]>>v[i];
		sum+=v[i];
	}

	for(int i=0;i<n;i++)
	{
		dp[i][0]=0;
		for(int j=1;j<=sum;j++)
			dp[i][j]=1000000000;
	}

	dp[0][v[0]]=w[0];

	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=sum;j++)
		{
			if(j<v[i])
			{
				dp[i][j]=dp[i-1][j];

			}
			else
			dp[i][j]=min(dp[i-1][j],w[i]+dp[i-1][j-v[i]]);
		}
	}

	for(int i=sum;i>=0;i--)
		if(dp[n-1][i]<=W)
			{
			    cout<<i;
			    exit(0);
			}
}

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

using namespace std;

#define mz 1000000007
#define pq priority_queue

long long num[100005];

int main()
{
    int n;
    bool flag=0;
    long long minn,maxx,tmax,tmin;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld",&num[i]);
    minn=2;
    maxx=2;
    for(int i=n;i>0;i--)
    {
        tmax=(maxx/num[i])*num[i];
        tmin=((minn-1)/num[i]+1)*num[i];
        maxx=tmax+num[i]-1;
        minn=tmin;
        if(minn>maxx)
            flag=1;
    }
    if(flag)
        printf("-1\n");
    else
        printf("%lld %lld\n",minn,maxx);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N, K;
	cin >> N >> K;

	vector<int> numlist(N);
	for (int i = 0; i < N; i++)
	{
		cin >> numlist[i];
	}

	int max_sum = 0;
	for (int i = 0; i < K; i++)
	{
		max_sum += numlist[i];
	}

	int check_sum = max_sum;
	for (int i = K; i < N; i++)
	{
		check_sum -= numlist[i - K];
		check_sum += numlist[i];

		max_sum = max(max_sum, check_sum);
	}

	cout.setf(ios::fixed);
	cout.precision(12);

	double result = max_sum + K;
	cout << result / 2;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <ctime>

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
#define TT int test_cases; cin >> test_cases; while(test_cases--)
#define TT1 int test_cases=1; while(test_cases--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
using namespace std;
typedef long long int ll;

 
int main() {
    
    FAST;
    TT1{
        char ch;cin>>ch;
        if(ch<'a') cout<<'A'<<"\n";
        else cout<<'a'<<"\n";
    }
}

Measured memory_bytes: 3608
n, m = map(int, input().split())
a = [int(input()) for i in range(m)]
MOD = 10**9 + 7
memo = {}
for i in range(n+1):
    memo[i] = 1
for i in range(m):
    memo[a[i]] = 0

dp = [0] * (n+1)

dp[0] = 1
dp[1] = memo[1]

for i in range(0, n-1):
    if memo[i+2] == 0:
        dp[i+2] = 0
    else:
        dp[i+2] = dp[i+1] + dp[i]
    dp[i+2] %= MOD
print(dp[n])

Measured memory_bytes: 19104
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 全ての点を読み込む
		int n = sc.nextInt();
		long[][] points = new long[n][2];
		for (int i = 0; i < n; i++) {
			points[i][0] = sc.nextInt();
			points[i][1] = sc.nextInt();
		}
		// xの値でソート
		Arrays.sort(points, new Comparator<long[]>(){
			@Override
			public int compare(long[] p1, long[] p2) {
				return Long.compare(p1[0], p2[0]);
			}
		});
		// 初期の最大値
		double l = Double.MAX_VALUE;
		long sq = Long.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++){
				long[] p1 = points[i];
				long[] p2 = points[j];
				if (p2[0] - p1[0] > l) break;
				long dx = p2[0] - p1[0];
				long dy = p2[1] - p1[1];
				long sq_tmp = dx * dx + dy * dy;
				if (sq_tmp < sq) {
					sq = sq_tmp;
					l = Math.sqrt(sq);
				}
			}
		}
		System.out.println(sq);
	}
}



Measured memory_bytes: 293696
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

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


    int res = 0;
    for (int i = 0; i < n; ++i) {
        if (P[i] == i) {
            ++res;
            ++i;
        }
    }

    cout << res << '\n';


    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n, m; cin >> n >> m;
	vector<int> a(n); rep(i, n) cin >> a[i];
	int sum = accumulate(a.begin(), a.end(), 0);
	int cnt = 0;
	for (int u : a) {
		if (4 * m * u >= sum) {
			cnt++;
		}
	}
	cout << (cnt >= m ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>

using namespace std;


int main() {
    string s;
    cin >> s;
    long long int ans = 0;
    for(int mask=0; mask < 1 << (s.size()-1); mask++){
        long long int tmp = 0;
        for(int i=0; i<s.size()-1; i++){
            tmp += s[i]-'0';
            if(mask & (1 << i)){
                ans += tmp;
                tmp = 0;
            }else{
                tmp *= 10;
            }
        }
        ans += tmp + s[s.size()-1] - '0';
    }
    cout << ans << endl;
    
    return 0;
}

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

int main()
{   int a,b,c,d;
    scanf("%d%d",&a,&b);
    if(a+b>=a-b)
    c=a+b;
    else
        c=a-b;
    d=c>=a*b?c:a*b;
    printf("%d",d);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s,t;
    cin>>s>>t;
    char tmp;
    int n=s.size();
    bool flag=false;
    rep(i,n){
        tmp=s[n-1];
        for(int j=n-1;j>0;j--){
            s[j]=s[j-1];
        }
        s[0]=tmp;
        if(s==t) flag=true;
    }
    if(flag) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        String[] values = line.split(" ");
        long N = Long.parseLong(values[0]);
        if (N == 1) {
            System.out.println("1");
            return;
        }
        long temp = N;
        long atks = 0;
        long n = 0;
        while (temp >= 1) {
            temp = temp / 2;
            n += Math.pow(2,atks);
            atks ++;
        }
        System.out.println(n);
    }
}

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

int main() {
  string s; cin >>s;
  for(int i=0;i<5;i++) {
    cout << s[i];
  }
  cout << " ";
  for(int i=6;i<13;i++) {
    cout << s[i];
  }
  cout << " ";
  for(int i=14;i<19;i++) {
    cout << s[i];
  }
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{
    int a[10];
    for(int i=0;i<10;i++){
        cin>>a[i];
    }
    sort(a,a+10);
    
    cout<<a[9]<<endl<<a[8]<<endl<<a[7]<<endl;
    

    return 0;
}

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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;

typedef long long int ll;

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

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

	int T;
	//cin >> T;
 	T = 1;
	while(T--){
		solve();
	}
	return 0;
}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Set;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");
		int n = Integer.parseInt(tmpArray[0]);
		int K = Integer.parseInt(tmpArray[1]);
		
		long result = 0;
//		for(int i = 1; i <= n; i++){
//			int s1 = K - i%K;
//			for(int j = s1; j <= n; j += K){
//				System.out.println("i = "+i + " j = "+j);
//				
//				int s2 = K - j%K;
//				System.out.println("s2 = "+s2);
//				
//				int x = n/K;
//				if(s2 < K){
//					x = (n + s2)/K;
//				}
//				result += x;
//				System.out.println("result = "+result);
//			}
//		}
		
		for(int i = 1; i <= n; i++){
			int m1 = K - i%K;
//			System.out.println("i = "+i);
			if((m1 *2)%K != 0){
//				System.out.println("invalid");
				continue;
			}
			else {
				//bやcの候補の数
				long tmp = (n - m1)/K + 1;
//				System.out.println("(n - m1) = "+(n - m1) +" tmp = "+tmp);
				
				result += tmp*tmp;
			}
		}
	
		
		System.out.println(result);
		
	}
	
}

Measured memory_bytes: 21332
#include <iostream>
using namespace std;
 
int main() {
  
  int A, B, N;
  int sum = 0;
  int a, b, c, d, e, X;
  cin >> A >> B;
  N = B - A + 1;
  
  for (int i = 0; i < N; i++) {
    
    //それぞれの桁数の求め方はHarshad Numberでf(N)を求めたときのと似てる。
    X = A + i;
    //cout << X << endl;
    
    e = X % 10;
       X = X / 10;
    d = X % 10;
       X = X / 10;
    c = X % 10;
       X = X / 10;
    b = X % 10;
       X = X / 10;
    a = X % 10;
    //cout << a << b << c << d << e << endl;
    
    if (a == e && b == d) {
      //cout << a << b << c << d << e << endl;
      sum = sum + 1;
    }
      
  } 
   cout << sum << endl;     
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
const int mod1=998244353;

int n,k;
ll ans=4000000000000000000;
vector<pair<ll,ll>> a;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	a.resize(n);
	rep(i,n) cin >> a.at(i).first >> a.at(i).second;
	sort(a.begin(),a.end());
	ll ans=4000000000000000000;
	if(k==2){
		rep(i,n){
			rep(j,n){
				if(i==j) continue;
				ans=min(ans,abs(a.at(i).first-a.at(j).first)*abs(a.at(i).second-a.at(j).second));
			}
		}
	}
	else if(k==3){
		rep(i,n){
			rep(j,n){
				if(i==j) continue;
				rep(l,n){
					if(i==l || j==l) continue;
					ans=min(ans,abs(max(a.at(i).first,max(a.at(j).first,a.at(l).first))-min(a.at(i).first,min(a.at(j).first,a.at(l).first)))*abs(max(a.at(i).second,max(a.at(j).second,a.at(l).second))-min(a.at(i).second,min(a.at(j).second,a.at(l).second))));
				}
			}
		}
	}
	else{
		rep(i,n){
			for(int j=i+1;j<n;++j){
				for(int l=j+1;l<n;++l){
					for(int m=l+1;m<n;++m){
						ll maxx=max(a.at(i).first,max(a.at(j).first,max(a.at(l).first,a.at(m).first)));
						ll minx=min(a.at(i).first,min(a.at(j).first,min(a.at(l).first,a.at(m).first)));
						ll maxy=max(a.at(i).second,max(a.at(j).second,max(a.at(l).second,a.at(m).second)));
						ll miny=min(a.at(i).second,min(a.at(j).second,min(a.at(l).second,a.at(m).second)));
						int cnt=0;
						rep(o,n){
							if(a.at(o).first>=minx && a.at(o).first<=maxx && a.at(o).second>=miny && a.at(o).second<=maxy) cnt++;
						}
						if(cnt>=k) ans=min(ans,(maxx-minx)*(maxy-miny));
					}
				}
			}
		}
	}
	cout << ans << endl;
}


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

map<int, int> prime_factors(int n) {
    map<int, int> res;
    if(n == 1) { // n=1 の素因数分解は n^1
        res[n] = 1;
        return res;
    }
    for(int i = 2, _n = n; i*i <= _n; ++i) {
        while(n % i == 0) {
            ++res[i]; // 素数i^{res[i]}
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

int main() {
   int N;
   cin >> N;
   map<int, int> log;
   for (int i = 0; i <= N; i++) {
      map<int, int> res = prime_factors(i);
      for(map<int, int>::iterator it = res.begin(), end = res.end(); it != end; ++it) {
        log[it->first] += it->second;
      }
   }
   int cnt3 = 0;
   int cnt5 = 0;
   int cnt15 = 0;
   int cnt25 = 0;
   int cnt75 = 0;
   for (map<int, int>::iterator it = log.begin(); it != log.end(); ++it) {
      if (it->second >= 2) cnt3++;
      if (it->second >= 4) cnt5++;
      if (it->second >= 14) cnt15++;
      if (it->second >= 24) cnt25++;
      if (it->second >= 74) cnt75++;
   }
   int ans = 0;
   if (cnt3 >= 2) {
      ans += cnt5 * (cnt5 - 1) * (cnt3 - 2) / 2;
      ans += cnt15 * (cnt5 - 1);
      ans += cnt25 * (cnt3 - 1);
      ans += cnt75;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools



#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

K = int(input())
KK=K
A, B= map(int, input().split())
ans = 0

while True:
    if(A<=KK and KK<=B):
        print("OK")
        break
    elif(B<KK):
        print("NG")
        break
    KK+=K


Measured memory_bytes: 74860
#include <cstdio>

int n, m, q, *cnt, *a, *b;

int main() {
  scanf("%d%d", &n, &q);
  cnt = new int[n + 1]();
  a = new int[n];
  b = new int[n]();
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    ++cnt[a[i]];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i - cnt[i]; j < i; ++j) {
      if(j >= 0 && !b[j]++) {
        ++m;
      }
    }
  }
  while(q--) {
    int i;
    scanf("%d", &i);
    i--;
    if(a[i] - cnt[a[i]] >= 0 && !--b[a[i] - cnt[a[i]]]) {
      --m;
    }
    --cnt[a[i]];
    scanf("%d", a + i);
    ++cnt[a[i]];
    if(a[i] - cnt[a[i]] >= 0 && !b[a[i] - cnt[a[i]]]++) {
      ++m;
    }
    printf("%d\n", n - m);
  }
  return 0;
}

Measured memory_bytes: 3840
n = int(input())
hs = list(map(int, input().split()))

diffs = [hs[i - 1] - hs[i] for i in range(1, len(hs))]

max_count = 0
tmp_counter = 0

for d in diffs:
    if d >= 0:
        tmp_counter += 1
        if tmp_counter >= max_count:
            max_count = tmp_counter
    else:
        tmp_counter = 0


print(max_count)



Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
inline int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
inline int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
inline int mul(int a, int b) {return 1ll * a * b % P;}
inline int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
const int N = 202020;
int n;
int a[N], b[N], c[3];
int main(){
	scanf("%d", &n);
	rep(i, 0, n) scanf("%d%d", a + i, b + i);
	rep(i, 0, n) {
		if(a[i] == b[i]) c[0]++;
		if(a[i] < b[i]) c[1]++;
		if(a[i] > b[i]) c[2]++;
	}
	ll ans = 0;
	if(c[0] && c[1] == 0 && c[2] == 0) ans = 0;
	else if(c[1] > 0 && c[2] == 1) {
		rep(i, 0, n)
			if(a[i] <= b[i]) ans += b[i];
	} else{
		ll t = 0;
		rep(i, 0, n) t += b[i];
		rep(i, 0, n) {
			if(a[i] > b[i]) ans = max(ans, t - b[i]);
		} 
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;


int n;

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

  sort(a,a+n);
  int ans=inf;
  for(int i=a[0];i<=a[n-1];i++){
    int tmp=0;
    rep(j,n){
      tmp+=abs(pow(i-a[j],2));
    }
    ans=min(ans,tmp);
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
n,m = [int(it) for it in input().split()]
li=[]
lim=[]
dcli=[ [] for i in range(n)]
for i in range(m):
  a,b = [int(it)-1 for it in input().split()]
  li.append( (a,b) )
  li.append( (b,a) )
  lim.append((a,b))
  dcli[a].append(b)
  dcli[b].append(a)
[ dcli[i].sort() for i in range(n)]
import numpy as np
import copy 
#print (n,m,li)
#print (dcli)
mi=np.ones([n],dtype=np.int)-1
ma=np.ones([n],dtype=np.int)-1
now = 0
stc=[0]
al=[0]
for i in range(10000):
  if len(dcli[now])>0:
    _now = dcli[now][0]
    if (len(stc)>1):
      if stc[-2] != _now:
        #print (_now,stc) 
        tmp = copy.copy(stc)
        tmp.append(_now)
        #print ("*",tmp)
        ind = 0
        for k in range(len(tmp)):
          if (tmp[k]==_now):
            ind = k
            break
        cut = tmp[ind:]
        if (len(cut)>1):
          for i in range(len(cut)-1):
            #print ("cut",cut[i],cut[i+1])
            if (min(cut[i],cut[i+1]),max(cut[i],cut[i+1])) in lim:
              lim.remove((min(cut[i],cut[i+1]),max(cut[i],cut[i+1])))
    else:
      pass
      #print (_now,stc)
    if _now in al:
      dcli[now] = dcli[now][1:]
      #print ("<"+str(_now)+">",end="")
      
      continue
    #print (_now,end=",") 
    al.append(_now)
    stc.append(_now)
    #mi[now]=min(mi[now],_now)
    #mi[now]=min(mi[now],_now)
    now = _now
  else:
    stc = stc[:-1]
    if (len(stc)==0):
      break
    now = stc[-1]
    #print ("R",end="")
#print ( lim , "happy" ) 
print (len(lim))

  

Measured memory_bytes: 12460
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;
typedef long long ll;
const long long MOD = 1000000007;

int N;
int AA[200001];
unordered_map<int, int> mp;
bool used[200001];
int ans = 0;

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> AA[i];
    }
    sort(AA, AA + N);
    reverse(AA, AA + N);
    for (int i = 0; i < N; i++) {
        mp[AA[i]] = i;
    }

    for (int i = 0; i < N; i++) {
        if (used[i]) continue;
        int A = AA[i];
        int p = 1 << 30;
        while (p > AA[i]) {
            if (mp.find(p - A) != mp.end()) {
                int id = mp[p - A];
                if (id != i && !used[id] && id >= 0 && AA[id] == p - A) {
                    used[i] = true;
                    used[id] = true;
                    mp[p - A]--;
                    ans += 1;
                    break;
                }
            }
            p /= 2;
        }
    }

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

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }

int main(){
    ll n,m;
    cin >> n >> m;
    ll a[n] = {};
    ll memo = 0;

    rep(i,0,n){
        cin >> a[i];
        a[i] /= 2;
        if(i == 0) memo = a[i];
        memo = lcm(memo,a[i]);
        
        if(memo > m){
            cout << 0 << endl;
            return 0;
        }
    }

    rep(i,0,n){
        if((memo / a[i])%2 == 0){
            cout << 0 << endl;
            return 0;
        }
    }

    cout << (m/memo+1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 4368
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int const MOD = 1000000007;

int main() {
    string s;
    int a[51];
    while(cin >> s) {
        memset(a, -1, sizeof(a));
        repr(i,s.length() - 1,0) {
            if(s[i] == 'I') a[i] = 1;
            else if(s[i] == 'V') a[i] = 5;
            else if(s[i] == 'X') a[i] = 10;
            else if(s[i] == 'L') a[i] = 50;
            else if(s[i] == 'C') a[i] = 100;
            else if(s[i] == 'D') a[i] = 500;
            else if(s[i] == 'M') a[i] = 1000;
        }

        int prev = -1, ret = 0;
        repr(i,s.length() - 1,0) {
            if(a[i] >= prev) {
                prev = a[i];
                ret += a[i];
            }
            else {
                ret -= a[i];
            }
        }

        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 1180
N,M = map(int,input().split())
Shop_List = [list(map(int,input().split())) for i in range(N)]
Shop_List = sorted(Shop_List, key=lambda x:x[0])
Number_Counter = 0
Yen_Counter = 0
for i in range(N):
    if Number_Counter + Shop_List[i][1] <= M:
        Number_Counter += Shop_List[i][1]
        Yen_Counter += Shop_List[i][0]*Shop_List[i][1]
    elif Number_Counter + Shop_List[i][1] > M:
        Yen_Counter += (M-Number_Counter)*Shop_List[i][0]
        Number_Counter = M
    elif Number_Counter == M:
        break

print(Yen_Counter)


Measured memory_bytes: 29372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

constexpr int N = 64;
constexpr ld EPS = 1E-10L;
int n;
ld x[N], y[N];
ld dist(ld a, ld b, ld c, ld d){
	return sqrt( (a-c) * (a-c) + (b-d) * (b-d) );
}
bool check(ld p, ld q, ld r){
	REP(i, n) if(dist(p, q, x[i], y[i]) >= r + EPS) return false;
	return true;
}

int main(){
	scanf("%d", &n);
	REP(i, n) scanf("%Lf%Lf", x+i, y+i);
	
	ld ans = LDBL_MAX;
	REP(i, n){
		REP(j, n){
			if(i == j) continue;
			ld p = (x[i] + x[j]) / 2, q = (y[i] + y[j]) / 2;
			ld r = dist(x[i], y[i], p, q);
			if(check(p, q, r)) SML(ans, r);
		}
	}
	REP(i, n){
		REP(j, n){
			REP(k, n){
				if( (x[j] - x[i]) * (y[k] - y[i]) - (y[j] - y[i]) * (x[k] - x[i]) < EPS) continue;
				ld p = (
						+(x[i]*x[i] + y[i]*y[i]) * (y[j]-y[k])
						+(x[j]*x[j] + y[j]*y[j]) * (y[k]-y[i])
						+(x[k]*x[k] + y[k]*y[k]) * (y[i]-y[j])
					) / 2 / (
						+ x[i] * (y[j] - y[k]) 
						- y[i] * (x[j] - x[k])
						+ x[j] * y[k] 
						- x[k] * y[j]
					);
				ld q = (
						+(x[i]*x[i] + y[i]*y[i]) * (x[k]-x[j])
						+(x[j]*x[j] + y[j]*y[j]) * (x[i]-x[k])
						+(x[k]*x[k] + y[k]*y[k]) * (x[j]-x[i])
					) / 2 / (
						+ x[i] * (y[j] - y[k]) 
						- y[i] * (x[j] - x[k])
						+ x[j] * y[k] 
						- x[k] * y[j]
					);
				ld r = dist(x[i], y[i], p, q);
				assert(dist(p, q, x[i], y[i]) <= r + EPS);
				assert(dist(p, q, x[j], y[j]) <= r + EPS);
				assert(dist(p, q, x[k], y[k]) <= r + EPS);
				DEBUG("(%Lf, %Lf), (%Lf, %Lf), (%Lf, %Lf) => (%Lf, %Lf), %Lf\n",
						x[i], y[i], x[j], y[j], x[k], y[k], p, q, r);
				if(check(p, q, r)) SML(ans, r);
			}
		}
	}
	printf("%.30Lf\n", ans);
}


Measured memory_bytes: 384
#import sys
#sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
S = str(input())
Scount = []
ans = int(0)
count= int(0)
max = int(0)

count +=1
for i in range(1,N):
#    print(S[i])
    if S[i]==S[i-1]:
        count +=1
        if i==N-1:
            Scount.append(count)
    else:
        Scount.append(count)
        count = int(1)
#print(Scount)

for i in Scount:
#    print(i)
    max += i
    max -= 1
#print(max)
max += K*2

ans = min(max,N-1)

print(ans)

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    if(n%2 == 1) {
        cout << "No" << '\n';
        return 0;
    }
    for(int i = 0; i < n/2; ++i) {
        if(s[i] != s[i+n/2]) {
            cout << "No" << '\n';
            return 0;
        }
    }
    cout << "Yes" << '\n';
}


Measured memory_bytes: 256
n = int(input())
p = [int(s) for s in input().split()]
sortedP = sorted(p)
sortedP.sort(key=int)
diffcount = 0
for i in range(n):
    if p[i] != sortedP[i]:
        diffcount += 1
if diffcount == 0 or diffcount == 2:
    print("YES")
else:
    print("NO")

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

    string s;
    cin >> s;

    long long sum =0;
    int n =s.size();

    rep(i,1 << n -1){
        long long t  =s[0] -'0';

        rep(j, n-1){

            if(i & (1 << j)){
                sum += t;
                t = s[j+1] -'0';
            }
            else{
                t *= 10;
                t += s[j+1] - '0';
            }
        }
        sum += t;
    }

    cout << sum << endl;

}


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

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

	if (r < 1200) {
		cout << "ABC" << endl;
	}
	else if (r >= 1200 && r < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}
	return 0;


}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){

	double x1,y1,x2,y2,xq,yq;
	double a,b,a2,b2;
	char gav;
	double ansx,ansy;

	while(cin>>x1>>gav>>y1>>gav>>x2>>gav>>y2>>gav>>xq>>gav>>yq){
		if(x1==x2) printf("%.6f %.6f\n",xq+(x1-xq)*2,yq);
		else if(y1==y2) printf("%.6f %.6f\n",xq,yq+(y1-yq)*2);
		else{
			a=(y1-y2)/(x1-x2);
			b=(x1*y2-y1*x2)/(x1-x2);
			a2=-1*(1/a);
			b2=yq+xq/a;
			ansx=(b-b2)/(a2-a);
			ansy=(a2*b-a*b2)/(a2-a);

			printf("%.6f %.6f\n",xq+(ansx-xq)*2,yq+(ansy-yq)*2);

		}
	}
}

Measured memory_bytes: 1240
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;
int main() {
	int n, a, b; cin >> n >> a >> b;

	int x = n * a;
	cout << min(x, b) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}

int dp[n];
dp[0]=0;
dp[1]=abs(arr[1]-arr[0]);
for(int i=2;i<n;i++)
{
dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
}
cout<<dp[n-1];
}


Measured memory_bytes: 4392
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int H = sc.nextInt();
		int M = sc.nextInt();

		int pass_time = H*60 + M;
		double digA = (0.5 * (double)pass_time) % 360;
		double digB = (6 * pass_time) % 360;

		double C = Math.sqrt(A*A + B*B -2*A*B*Math.cos(Math.toRadians(Math.abs(digA-digB))));

		System.out.println(C);

	}
}


Measured memory_bytes: 36048
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
   int a[3],ans=0;
   cin>>a[0]>>a[1]>>a[2];
   sort(a,a+3);
   for(int i=1;i<3;i++)
   {
       ans+=a[i]-a[i-1];
   }
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=500010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int main(){
    int n,k;cin>>n>>k;
    int a[5010];for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    int ng=0;int ok=n+1;
    while(ok-ng>1){
        bool dp[5010][5010]={false};
        int mid=(ng+ok)/2;
        int s=a[mid];
        a[mid]=0;
        memset(dp,false,sizeof(dp));
        dp[0][0]=true;
        for(int i=1;i<=n;i++){
            for(int j=0;j<=k;j++){
                dp[i][j]|=dp[i-1][j];
                if(j-a[i]>=0){
                    dp[i][j]|=dp[i-1][j-a[i]];
                }
            }
        }    
        bool f=false;
        for(int i=max(0,k-s);i<k;i++){
            f|=dp[n][i];
        }
        if(f){
            ok=mid;
        }else{
            ng=mid;
        }
        a[mid]=s;
    }
    cout<<ng<<endl;
    return 0;
}


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

using namespace std;

#define MAX(x, y) (x >= y ? x : y)

int main(void)
{
    int N;
    vector<int> B;
    long sum = 0;

    cin >> N;
    for (int i = 0; i < N - 1; i++)
    {
        int n;
        cin >> n;
        B.push_back(n);
    }
    B.push_back(1000000);

    sum += B[0];
    for (int i = 0; i < N - 1; i++)
    {
        if (B[i] <= B[i + 1])
        {
            sum += B[i];
        }
        else
        {
            sum += B[i + 1];
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define f first
#define s second
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;
 
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
 
mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(61378913);
/* usage - just do rng() */
 
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}
 
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
 

 
ll n, m, k, q, l, r, x, y, z;
const ll template_array_size = 1e6 + 1389;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
ll ans = 0;
 

 
void solve(int tc = 0) {
	ll dp[2005] = {0};
	dp[0] = 1;
	
	cin >> n;
	for (ll i = 0; i < n; i++) {
		for (ll j = i + 3; j <= n; j++) {
			dp[j] = (dp[j] + dp[i]) % mod;
		}
	}
	
	cout << dp[n] << '\n';
}
 
int main() {
	#ifdef galen_colin_local
		auto begin = std::chrono::high_resolution_clock::now();
	#endif
	
	send help
 
	#ifndef galen_colin_local
		// usaco("moop");
	#endif
	
	// usaco("cowland");
	
	// freopen("tc.cpp", "r", stdin);
 
	int tc = 1;
	// cin >> tc;
	for (int t = 0; t < tc; t++) solve(t);
	
	#ifdef galen_colin_local
		auto end = std::chrono::high_resolution_clock::now();
		cout << setprecision(4) << fixed;
		// cout << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
	#endif
} 

Measured memory_bytes: 3652
n=int(input())
lst=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x : x[1])
tmptime=0
hp=0
flag=True
for i in range(n):
    hp+=lst[i][1]-tmptime
    tmptime=lst[i][1]
    hp-=lst[i][0]
    if hp<0:
        flag=False
        break
if flag:
    print('Yes')
else:
    print('No')
        
    
    

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

int N;
int A[100005];
long long prefixsum[100005];
long long counter=1;

int main()
{
    cin>>N;
    
    for (int i=1; i<=N; i++)
    {
        cin>>A[i];
    }

    sort(A+1, A+N+1);

    for (int i=1; i<=N; i++)
    {
        prefixsum[i]=prefixsum[i-1]+A[i];
    }

    for (int i=N; i>=1; i--)
    {
        if (i!=N)
        {
            if(prefixsum[i]*2>=A[i+1])
            {
                counter++;
            }

            else
            {
                break;
            }
        }
    }

    cout<<counter<<endl;
}





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

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
	freopen("../input.txt", "r", stdin);
	freopen("../output.txt", "w", stdout);
#endif
	long long X, K, D;
	cin >> X >> K >> D;
	if (X < 0) {
		X = -X;
		long long div = X / D;
		if (div >= K) {
			cout << X - K * D << endl;
		}
		else {
			X = X - div * D;
			long long sub = K - div;
			if (sub % 2 == 0) {
				cout << abs(X) << endl;
			}
			else {
				cout << abs(X - D) << endl;
			}
		}
	}
	else {
		long long div = X / D;
		if (div >= K) {
			cout << X - K * D << endl;
		}
		else {
			X = X - div * D;
			long long sub = K - div;
			if (sub % 2 == 0) {
				cout << abs(X) << endl;
			}
			else {
				cout << abs(X - D) << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Integer[] choices = { 1, 2, 3 };
        Scanner sc = new Scanner(System.in);

        Integer A = sc.nextInt();
        Integer B = sc.nextInt();

        for (Integer choice : choices) {
            if (choice != A && choice != B) {
                System.out.println(choice);
                break;
            }
        }

        sc.close();

    }

}

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

int main(){
  int A,B,ans;
  cin >> A >> B;
  for(int i=A;i<B+1;i++){
    int s = i;
    if((s-s%10000)/10000 == s%10 && (s%10000 - s%1000)/1000 == (s%100-s%10)/10)
      ans++;
  }
	cout << ans << endl;
}

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

int main() {
  int n, t;
  cin >> n >> t;
  vector<int> a(n), b(n);
  for(int i=0; i<n; i++)
    cin >> a.at(i) >> b.at(i);
  
  int ans = 10000;
  
  for(int i=0; i<n; i++) {
    if(b.at(i) <= t) {
      if(a.at(i) < ans)
        ans = a.at(i);
    }
  }
  
  if(ans == 10000)
    cout << "TLE" << endl;
  else
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX=100005;
long long int a[MAX],prefix[MAX],ansA,ansB;
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=n;++i){
		prefix[i]=prefix[i-1]+a[i];
		if(i%2==0){
			if(prefix[i]<=0){
				ansA+=1-prefix[i];
				prefix[i]=1;	
			}
		}
		else{
			if(prefix[i]>=0){
				ansA+=prefix[i]+1;
				prefix[i]=-1;
			}
		}
	}
	for(int i=1;i<=n;++i){
		prefix[i]=prefix[i-1]+a[i];
		if(i%2==1){
			if(prefix[i]<=0){
				ansB+=1-prefix[i];
				prefix[i]=1;	
			}
		}
		else{
			if(prefix[i]>=0){
				ansB+=prefix[i]+1;
				prefix[i]=-1;
			}
		}
	}
	cout<<min(ansA,ansB)<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> p(W);
  REP(i, W) cin >> p[i];

  vector<int> q(H);
  REP(i, H) cin >> q[i];

  sort(ALL(p));
  sort(ALL(q));
  p.emplace_back(INF);
  q.emplace_back(INF);

  int cnt = H+W;
  int ans = 0;
  int cntp = H+1;
  int cntq = W+1;
  int pp = 0, qq = 0;
  while(cnt--){
    if(p[pp] <= q[qq]){
      cntq--;
      ans += cntp*p[pp]; pp++;
    }else{
      cntp--;
      ans += cntq*q[qq]; qq++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560