akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
#include <ctype.h> // isdigit
#include <cassert>
using namespace std;

#define LE(n,m) ((n) < (m) + EPS * (abs(n) + abs(m)))
#define GE(n,m) ((n) + EPS * (abs(n) + abs(m)) > (m))
#define LT(n,m) ((n) + EPS * (abs(n) + abs(m)) < (m))
#define GT(n,m) ((n) > (m) + EPS * (abs(n) + abs(m)))
#define EQ(n,m) (abs((n)-(m)) < EPS * (abs(n) + abs(m)))

typedef long long int ll;
const int INF = (1<<30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

ll H, W;

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    cin >> W >> H;
    vector<pair<ll, ll>> vec;
    ll v;
    for(int i=0; i<W; i++){
        cin >> v;
        vec.push_back({v, 0});
    }
    for(int i=0; i<H; i++){
        cin >> v;
        vec.push_back({v, 1});
    }
    sort(vec.begin(), vec.end());
    
    ll ans = 0;
    for(int i=0; i<vec.size(); i++){
        auto p = vec[i];
        if(p.second == 0){
            ans += p.first * (H + 1);
            W--;
        }else{
            ans += p.first * (W + 1);
            H--;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4464
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

int main(){
    ll n;
    cin>>n;
    vll a(n);
    rep(i,n) cin>>a[i];
    vll left(n,-1e10);
    vll right(n,-1e10);
    vll mid(n,-1e10);
    if(n%2==0){
        left[0]=a[0];
        right[0]=a[1];
        rep(i,n/2-1){
            left[i+1]=left[i]+a[i*2+2];
            right[i+1]=max(left[i],right[i])+a[i*2+3];
        }
        cout<<max({left[n/2-1],right[n/2-1]})<<endl;
    }
    else{
        left[0]=a[0];
        mid[0]=a[1];
        right[0]=a[2];
        rep(i,n/2-1){
            left[i+1]=left[i]+a[i*2+2];
            mid[i+1]=max(left[i],mid[i])+a[i*2+3];
            right[i+1]=max({left[i],mid[i],right[i]})+a[i*2+4];
        }
        cout<<max({left[n/2-1],mid[n/2-1],right[n/2-1]})<<endl;
    }
}


Measured memory_bytes: 9560
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        while(true){
            int x = scan.nextInt();
            int y = scan.nextInt();
        
        if(x == 0 && y == 0){
            break;
        }
              System.out.println((x < y)? (x + " " + y): (y + " " + x));  
        }

    }
}



Measured memory_bytes: 36176
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795


using ll=long long;

class mod_ll
{
public:
	ll m_v;
	static const ll m_m=1000000007; // prime value ex. 1000000009
	mod_ll(ll v=0) : m_v(v) {}
	mod_ll operator = (ll rhs)
	{
		m_v=rhs%m_m;
		return *this;
	}
	ll operator ()(){return m_v;}
	mod_ll operator = (mod_ll rhs)
	{
		m_v=rhs.m_v;
		return *this;
	}
	mod_ll operator += (ll rhs)
	{
		m_v=(m_v+rhs)%m_m;
		return *this;
	}
	mod_ll operator += (mod_ll rhs)
	{
		m_v=(m_v+rhs.m_v)%m_m;
		return *this;
	}
	mod_ll operator + (mod_ll rhs)
	{
		auto ret=*this;
		return ret+=rhs;
	}
	mod_ll operator -= (mod_ll rhs)
	{
		m_v=(m_v-rhs.m_v+m_m)%m_m;
		return *this;
	}
	mod_ll operator - (mod_ll rhs)
	{
		auto ret=*this;
		return ret-=rhs;
	}
	mod_ll operator *= (ll rhs)
	{
		m_v=(m_v*rhs)%m_m;
		return *this;
	}
	mod_ll operator *= (mod_ll rhs)
	{
		m_v=(m_v*rhs.m_v)%m_m;
		return *this;
	}
	mod_ll operator * (mod_ll rhs)
	{
		mod_ll ret=*this;
		return ret*=rhs;
	}
	mod_ll operator ^ (ll rhs)
	{
		mod_ll t=*this;
		mod_ll ret(1LL);

		for(;rhs>0;rhs>>=1)
		{
			if(rhs&1) ret*=t;
			t*=t;
		}
		return ret;
	}
	mod_ll operator /= (mod_ll rhs)
	{
		return *this*=(rhs^(m_m-2));
	}
	mod_ll operator /= (ll rhs)
	{
		mod_ll t(rhs);
		return *this/=t;
	}
	mod_ll operator / (mod_ll rhs)
	{
		mod_ll ret=*this;
		return ret/=rhs;
	}
};


mod_ll mod_fact(int n)
{
	static vector<mod_ll> memo(1);

	if((int)memo.size()<=n)
	{
		if(memo.size()==1)
		{
			memo[0]=1;
		}
		for(int i=memo.size();i<=n;i++)
		{
			memo.push_back(memo.back()*i);
		}
	}
	return memo[n];
}


mod_ll mod_nCr(int n, int r)
{
	mod_ll bunsi=mod_fact(n);
	mod_ll bunbo=mod_fact(n-r)*mod_fact(r);
	return bunsi/bunbo;
}


mod_ll mod_nPr(int n, int r)
{
	mod_ll ret(1);

	for(int i=0;i<r;i++)
	{
		ret*=(n-i);
	}
	return ret;
}


int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vi c(n);
		for(auto&m:c) scanf("%d", &m);

		sort(c.rbegin(), c.rend());

		mod_ll ans;
		mod_ll r(2);
		for(int i=0;i<n;i++)
		{
			ans+=r*c[i];
			r+=1;
		}
		mod_ll two(2);
		ans*=two^(n*2-2);
		printf("%lld\n", ans());
	}
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main() {
    int i, n, k, h, count=0;
    fscanf(stdin, "%d %d", &n, &k);

    for(i=0;i<n;i++) {
        fscanf(stdin, "%d", &h);
        count += (h>=k?1:0);
    }

    fprintf(stdout, "%d\n", count);

    return 0;
}

Measured memory_bytes: 128
//
//  安定なソート
//  バブルソートと選択ソート
//
#include <iostream>

class Trump {
private:
    char type;
    int  value;
public:
    Trump() { type = ' '; value = 0; }
    void setType(char c) { type = c; }
    void setValue(int i) { value = i; }
    char getType()  const { return type; }
    int  getValue() const { return value; }
};

void swap(Trump& a, Trump& b) {
    Trump tmp = a; a = b; b = tmp;
}
bool isStable(Trump* a, Trump* b, int n) {
    for (int i = 0; i < n; i++) {
        if (a[i].getType() != b[i].getType()) {
            return false;
        }
    }
    return true;
}

int bubbleSort(Trump* a, int n) {
    int count = 0;
    bool flag = true;
    while (flag) {
        flag = false;
        for (int j = n - 1; j > 0; j--) {
            // 配列の最後の要素から値をチェックする。
            // もし、配列の要素の値がソートできたら、flagはfalseのまま。
            if (a[j].getValue() < a[j - 1].getValue()) {
                // ひとつ前の要素の値のほうが大きいので、
                // 値を入れ替える。
                swap(a[j - 1], a[j]);
                flag = true;
                count++;
            }
        }
    }
    return (count);
}
int selectionSort(Trump* a, int n) {
    int count = 0;
    // 配列の中から最小値を探し、
    // 前から順に格納する。
    for (int i = 0; i < n; i++) {
        int min = i;
        for (int j = i; j < n; j++) {
            if (a[j].getValue() < a[min].getValue())
                min = j;
        }
        if (i < min) {
            swap(a[i], a[min]);
            count++;
        } // i == minであれば入れ替える必要がない
    }
    return (count);
}

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

    Trump* a = new Trump[n];
    Trump* b = new Trump[n];

    for (int i = 0; i < n; i++) {
        char type;
        int  value;
        std::cin >> type >> value;
        a[i].setType(type);
        a[i].setValue(value);
    }
    for (int i = 0; i < n; i++)
        b[i] = a[i];

    int cnt1 = bubbleSort(a, n);
    int cnt2 = selectionSort(b, n);

    // バブルソートの結果を出力
    for (int i = 0; i < n; i++) {
        std::cout << a[i].getType() << a[i].getValue();
        if (i == n - 1)
            std::cout << std::endl;
        else
            std::cout << ' ';
    }
    std::cout << "Stable\n";

    // 選択ソートの結果を出力
    for (int i = 0; i < n; i++) {
        std::cout << b[i].getType() << b[i].getValue();
        if (i == n - 1)
            std::cout << std::endl;
        else
            std::cout << ' ';
    }
    if (isStable(a, b, n)) {
        std::cout << "Stable\n";
    }
    else {
        std::cout << "Not stable\n";
    }

    return (0);
}


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

int main() {
	char w[11], t[1001];
	int cnt = 0;
	int i = 0;
	scanf("%s", w);
	for(i=0; w[i]!='\0'; i++) {
		if('A' <= w[i] && w[i] <= 'Z') {
			w[i] += 'a' - 'A';
		}
	}
	while(1) {
		scanf("%s", t);
		if( !strcmp("END_OF_TEXT", t) ) break; 
		for(i=0; t[i]!='\0'; i++) {
			if('A' <= t[i] && t[i] <= 'Z') {
				t[i] += 'a' - 'A';
			}
		}
		if( !strcmp(w, t) ) cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 548
// Author : ps41

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll M = 1e9 + 7, N = 1e6 + 5;

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll h, w, m;
    cin >> h >> w >> m;
    map<ll, ll> row, col;
    map<pair<ll, ll>, ll> mp;
    for (ll i = 0; i < m; i++)
    {
        ll u, v;
        cin >> u >> v;
        mp[{u, v}] = 1;
        row[u]++;
        col[v]++;
    }
    ll mxrow = 0, mxcol = 0;
    for (auto i: row) mxrow = max(mxrow, i.second);
    for (auto i: col) mxcol = max(mxcol, i.second);

    vector<ll> indrow, indcol;

    for (auto i: row)
    {
        if (i.second == mxrow) indrow.push_back(i.first);
    }

    for (auto i: col)
    {
        if (i.second == mxcol) indcol.push_back(i.first);
    }

    ll ans = mxrow + mxcol - 1;

    for (auto i: indrow)
    {
        for (auto j: indcol)
        {
            if (mp[{i, j}] == 0) cout << ans + 1, exit(0);
        }
    }

    cout << ans;
}

Measured memory_bytes: 67796
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

LL extgcd(LL a, LL b, LL &x, LL &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    LL g = extgcd(b, a % b, x, y);
    LL nextx = y, nexty = x-(a/b)*y;
    x = nextx; y = nexty;
    return g;
}

LL fact[200010];
LL invfact[200010];
const LL mod = 1e9 + 7;

LL nCr(int n, int r){
    LL ret = fact[n];
    (ret *= invfact[n-r]) %= mod;
    (ret *= invfact[r]) %= mod;
    return ret;
}

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

    int H, W, A, B;
    cin >> H >> W >> A >> B;
    fact[0] = 1;
    for(LL i=1; i<=200000; i++){
        fact[i] = (fact[i-1] * i) % mod;
    }
    for(LL i=0; i<=200000; i++){
        LL x, y;
        LL g = extgcd(fact[i], mod, x, y);
        while(x < 0) x += mod;
        x %= mod;
        invfact[i] = x;
    }

    LL ans = 0;
    for(int i=B; i<W; i++){
      	//(a+b-2)!/(a-1)!(b-1)! = (a+b-2)C(a-1) というのを利用する
        LL tmp = nCr((H-A-1)+i, H-A-1); //(1,1)→(必ず通る地点)
        (tmp *= nCr((A-1)+(W-i-1), A-1)) %= mod;//(必ず通る地点)→(h,w)
        (ans += tmp) %= mod;
    }
    cout << ans << endl;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[30];
bool dp[100000];

int main() {
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    memset(dp, 0, sizeof(dp));
    dp[0] = true;
    ll max = 0;
    REP(i, N) {
        for (ll j = max; j >= 0; --j) {
            if (dp[j])
                dp[j + A[i]] = true;
            max = std::max(max, j + A[i]);
        }
    }

    ll Q;
    cin >> Q;
    REP(i, Q) {
        ll q;
        cin >> q;
        if (dp[q])
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
    return 0;
}


Measured memory_bytes: 3196
//E - Bomber
#include<bits/stdc++.h>
using namespace std;
int read(){
	int x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,m,k;
int maxx,maxy;
unordered_map<int,int> x,y;
#define P pair<int,int>
map<pair<int,int>,bool> vis;
bool pd(int xx,int yy){
	return vis[P(xx,yy)];
}
vector<int> Ax,Ay;
int main()
{
	n = read();m = read();k =read();
	for(int i = 1;i <= k;i++)
	{
		int a = read(), b = read();
		x[a] ++;
		y[b] ++;
		vis[P(a,b)] = 1;
		if(x[a] > maxx)
		{
			Ax.clear();maxx = x[a];Ax.push_back(a);
		} 
		else if(x[a] == maxx) Ax.push_back(a);
		if(y[b] > maxy) 
		{
			Ay.clear();maxy = y[b];Ay.push_back(b);
		}
		else if(y[b] == maxy) Ay.push_back(b);
//		cout << x[a] << " "<<y[b]<<endl;
	}
	int ans = 0;
	for(int i = 0;i < Ax.size();i++)
	{
		for(int j = 0;j < Ay.size();j++){
			ans = maxx+maxy-pd(Ax[i],Ay[j]);
			if(ans == maxy + maxx) {
				cout << ans << endl;
				return 0;
			}
		}
	}
	cout << maxx+maxy - 1 << endl;
	return 0;
//	cout << maxx <<" "<< maxy <<endl;
//	cout << x[maxx]+y[maxy]-pd(maxx,maxy) << endl;
	return 0;
}

Measured memory_bytes: 51240
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define CLR(a,x) memset(a,x,sizeof(a))
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pa;
const int maxn=1e5+10;

inline ll rd(){
    ll x=0;char c=getchar();int neg=1;
    while(c<'0'||c>'9'){if(c=='-') neg=-1;c=getchar();}
    while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*neg;
}

int N,a[maxn];

int main(){
    //freopen("","r",stdin);
	N=rd();
	for(int i=1;i<=N;i++) a[i]=rd();
	int tp=-1,ans=1;
	for(int i=2;i<=N;i++){
		if(tp==-1){
			if(a[i]>a[i-1]) tp=1;
			else if(a[i]<a[i-1]) tp=0;
		}else{
			if(a[i]>a[i-1]&&tp==0) tp=-1,ans++;
			else if(a[i]<a[i-1]&&tp==1) tp=-1,ans++;
		}
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    print(c - min(b + c, a) + b)
    return

#B
def B():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        if len(str(i)) % 2:
            ans += 1
    print(ans)
    return

#C
def C():
    n = II()
    h = LI()
    h = h[::-1]
    for i in range(1, n):
        if h[i] <= h[i-1]:
            continue
        if h[i] == h[i - 1] + 1:
            h[i] -= 1
            continue
        print("No")
        return
    print("Yes")
    return

#D
def D():
    s = S()
    lens = len(s)
    ans = [0] * len(s)
    i = 0
    while i != len(s):
        for j in range(i, lens):
            if s[j] == "R":
                continue
            break
        R = j - i
        for i in range(j, lens):
            if s[i] == "L":
                continue
            break
        else:
            i += 1
        L = i - j
        ans[j] = R // 2 + (L+1) // 2
        ans[j - 1] = L // 2 + (R+1) // 2

    print(*ans)
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39280
a,b,c,d=map(float,input().split())
c-=a;d-=b
for _ in [0]*int(input()):
    x,y=map(float,input().split())
    x-=a;y-=b
    z=(c*x+d*y)/(c*c+d*d)
    print(a+c*z,b+d*z)



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

using namespace std;
const int MAXN = 1e5+10;
int dp[MAXN],a[101];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	bool win=0;
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=k;i++){
		bool win=0;
		for(int j=1;j<=n&&a[j]<=i;j++){
			if(dp[i-a[j]]==0){
				win=1;
			}
		}
		dp[i]=win;
	}
	cout<<(dp[k]==1?"First":"Second") <<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main {

	private static final int mod =(int)1e9+7;
	public static void main(String[] args) throws Exception  {
	      Scanner  sc=new Scanner(System.in);
	      PrintWriter out=new PrintWriter(System.out);
	     int n=sc.nextInt();
	     int m=sc.nextInt();
	     ArrayList<ArrayList<Integer>> aa=new ArrayList<>();
	     for(int i=0;i<n;i++) {
	       aa.add(new ArrayList<>());
	     }
	     for(int i=0;i<m;i++) {
	       int a=sc.nextInt();
	       int b=sc.nextInt();
	       aa.get(a-1).add(b-1);
	       aa.get(b-1).add(a-1);
	     }
	       for(ArrayList<Integer> i:aa) {
	         System.out.println(i.size());
	       }
	}


	static boolean vis[]=new boolean[10001];
	      static long gcd(long a, long b) 
	      { 
	          if (a == 0) 
	              return b; 
	          return gcd(b % a, a); 
	      } 

static long nCr(int n,int r) {
  int dp[][]=new int[2001][2001];
  for(int i=0;i<2001;i++) {
    dp[0][i]=0;
  }
  for(int i=0;i<2001;i++) {
    dp[i][0]=1;
  }
  for(int i=1;i<2001;i++) {
    for(int j=1;j<2001;j++) {
      if(i==j) {
        dp[i][j]=1;
      }else {
        dp[i][j]=dp[i-1][j-1]+dp[i][j-1];
      }
    }
  }
  return dp[n][r];
}


      
}
class pair{
  int wt,val;
  pair(int wt,int val){
    this.wt=wt;
    this.val=val;
  }
}

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

using namespace std;

#define _int64 long long

int a[300000];
int b[300000];

int main()
{
  int i,j,m,n;
  scanf("%d",&m);
  //cout<<m<<" "<<n<<endl;
  for (i=0;i<m;i++)
    scanf("%d",&a[i]);
  scanf("%d",&n);
  for (i=0;i<n;i++)
    scanf("%d",&b[i]);
  sort(a,a+m);
  sort(b,b+n);
  j=0;
  for (i=0;i<n;i++)
  {
    //cout<<i<<" "<<j<<endl;
    while ((j<m)&&(a[j]!=b[i])) j++;
    if (j>=m)
    {
      printf("NO\n");return 0;
    }
    j++;
  }
  printf("YES\n");
  return 0;
}

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

using namespace std;
#define rep(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>

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; }

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

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

  lgcd[0] = a[0];
  for (int i = 1; i < n; i++) lgcd[i] = gcd(lgcd[i-1],a[i-1]);

  rgcd[n-1] = a[n-1];
  for (int i = n-2; i >= 0; i--) rgcd[i] = gcd(rgcd[i+1],a[i+1]);

  int ans = 0;
  chmax(ans,rgcd[0]);// i = 0 は別処理
  for(int i = 1; i < n-1; i++){
    chmax(ans, gcd(lgcd[i],rgcd[i]));
  }
  chmax(ans, lgcd[n-1]);// i = n-1 も別処理

  cout << ans << '\n';
}


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

int main() {
    string str;
    cin >> str;
    int n = str.size();
    reverse(str.begin(), str.end());
    vector<int> cnts(2019);
    cnts[0]++;
    int mod_digits = 1;
    int carry = 0;
    rep(i, n) {
        char c = str[i];
        int x = atoi(&c);
        carry = (carry + x * mod_digits) % 2019;
        mod_digits = (mod_digits*10) % 2019;
        cnts[carry]++;
    }

    ll cnt = 0;
    rep(i,2019){
        cnt += cnts[i] * (cnts[i]-1) / 2;
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3732
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int l, r, count, n, ud;
    String f;

    for(;;){
      n = sc.nextInt(); if(n == 0)break;
      count = 0; l = 0; r = 0; ud = 0;
      for(;n-- > 0;){
        f = sc.next();
        if("lu".equals(f)){
          if(ud == 0 && l == 0 && r == 1){
            count++; ud = 1;
          }
          l = 1;
        }else if("ru".equals(f)){
          if(ud == 0 && l == 1 && r == 0){
            count++; ud = 1;
          }
          r = 1;
        }else if("ld".equals(f)){
          if(ud == 1 && l == 1 && r == 0){
            count++; ud = 0;
          }
          l = 0;
        }else{
          if(ud == 1 && l == 0 && r == 1){
            count++; ud = 0;
          }
          r = 0;
        }
      }
      out.println(count);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 26952
import sys
def input():
    return sys.stdin.readline()[:-1]

class UnionFind:
    def __init__(self, N):
        self.roots = list(range(N + 1))
        self.counter = [1] * (N + 1)

    def get_root(self, n):
        if self.roots[n] != n:
            self.roots[n] = self.get_root(self.roots[n])
        return self.roots[n]

    def union(self, a, b):
        a, b = sorted([self.get_root(a), self.get_root(b)])
        if a != b:
            self.roots[b] = a
            self.counter[a] += self.counter[b]
            self.counter[b] = 0

    def find(self, a, b):
        return self.get_root(a) == self.get_root(b)

    def count(self, x):
        return (self.counter[self.get_root(x)])

def resolve():
    N, M, K = [int(x) for x in input().split()]
    list = [[] for _ in range(N)]
    block = [[] for _ in range(N)]

    uf = UnionFind(N)

    for _ in range(M):
        A, B = [int(x)-1 for x in input().split()]
        list[A].append(B)
        list[B].append(A)
        uf.union(A,B)

    for _ in range(K):
        C, D = [int(x)-1 for x in input().split()]
        block[C].append(D)
        block[D].append(C)

    for i in range(N):
        ans = uf.count(i) - len(list[i]) - 1
        for j in block[i]:
            if uf.find(i ,j):
                ans -= 1

        print(ans, end=" ")

resolve()

Measured memory_bytes: 140200
#include <iostream>

using namespace std;

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

    bool exists = false;
    for (int i = 0; 4 * i <= n; i++) {
        if ((n - 4 * i) % 7 == 0) {
            exists = true;
        }
    }

    cout << (exists ? "Yes" : "No") << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B[i];
    if (B[i] > i + 1) {
      cout << -1 << '\n';
      return 0;
    }
  }
  vector<int> res(N);
  for (int i = 0; i < N; i++) {
    for (int j = B.size() - 1; j >= 0; j--) {
      if (B[j] == j + 1) {
        res[i] = j + 1;
        B.erase(B.begin() + j);
        break;
      }
    }
  }
  reverse(res.begin(), res.end());
  for (int i = 0; i < res.size(); i++)
    cout << res[i] << '\n';
  return 0;
}


Measured memory_bytes: 256
n = int(input())
sp = []
setS =[]
for i in range(1,n+1):
    s, p = input().split()
    sp.append([s, int(p), i])

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


for i in sp:
    print(i[2])

Measured memory_bytes: 3060
import sys
from bisect import bisect_left

n, q = map(int, input().split())
lines = sys.stdin.readlines()
kkk = []
for line in lines[:n]:
    s, t, x = map(int, line.split())
    kkk.append((x, s, t))
kkk.sort()
ddd = list(map(int, lines[n:]))

ans = [-1] * q
skip = [-1] * q
for x, s, t in kkk:
    ss = bisect_left(ddd, s - x)
    tt = bisect_left(ddd, t - x)
    while ss < tt:
        if skip[ss] == -1:
            ans[ss] = x
            skip[ss] = tt
            ss += 1
        else:
            ss = skip[ss]
print('\n'.join(map(str, ans)))


Measured memory_bytes: 101580
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>
int max(int a, int b){return a>b?a:b;}
int min(int a, int b){return a<b?a:b;}
int gcd(int a, int b){return min(a,b)==0?max(a,b):gcd(min(a,b),max(a,b)%min(a,b));}
long long llmax(long long a, long long b){return a>b?a:b;}
long long llmin(long long a, long long b){return a<b?a:b;}
long long llgcd(long long a, long long b){return min(a,b)==0 ?llmax(a,b):llgcd(llmin(a,b),llmax(a,b)%llmin(a,b));}
int assort(const void *a, const void *b){return *(int*)a-*(int*)b;}
int dessort(const void *a, const void *b){return *(int*)b-*(int*)a;}
int llassort(const void *a, const void *b){return *(long long*)a-*(long long*)b;}
int lldessort(const void *a, const void *b){return *(long long*)b-*(long long*)a;}
int charassort(const void *a, const void *b){return strcmp((char*)a ,(char*)b);}
int chardessort(const void *a, const void *b){return strcmp((char*)b ,(char*)a);}
int ntoi(char c){return c-'0';}
int ltoi(char c){return c-'a';}
int utoi(char c){return c-'A';}

char lowcmp[26]="abcdefghijklmnopqrstuvwxyz";
char upcmp[26]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
long long mod=1000000007;


int main(void){
    int n;
    scanf("%d",&n);
    int x[n],y[n],h[n];
    for (int i=0; i<n; i++){
        scanf("%d%d%d",&x[i],&y[i],&h[i]);
    }
    
    int ans[101][101]={};
    
    
    for (int k=0; k<n; k++){
        if (h[k]!=0){
            for (int i=0; i<101; i++){
                for (int j=0; j<101; j++){
                    ans[i][j]= h[k]+abs(i-x[k])+abs(j-y[k]);{
                    }
                }
            }
        break;
        }
    }
    
    for (int k=0; k<n; k++){
        if (h[k]!=0){
        for (int i=0; i<101; i++){
            for (int j=0; j<101; j++){
                if (ans[i][j]!= h[k]+abs(i-x[k])+abs(j-y[k]) ){
                    ans[i][j]=-5;
                }
            }
        }
        }
    }
    for (int i=0; i<101; i++){
        for (int j=0; j<101; j++){
            if (ans[i][j]!=-5){
                for (int k=0; k<n; k++){
                    
                    if (h[k]==0){
                        if(ans[i][j]-abs(x[k]-i)-abs(y[k]-j)>0){
                            ans[i][j]=-5;
                        }
                    }
                }
            }
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    for (int i=0; i<101; i++){
        for (int j=0; j<101; j++){
            if (ans[i][j]!=-5){
                printf("%d %d %d\n",i,j,ans[i][j]);
            }
        }
    }
	return 0 ;
}


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

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    for (int i = 0; i < N; i++)
        cin >> t[i];

    vector<int> diff(N - 1);
    for (int i = 0; i < N - 1; i++)
        diff[i] = t[i + 1] - t[i];

    long long res = 0;
    for (int i = 0; i < N - 1; i++)
        res += min(diff[i], T);
    res += T;

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    string a, b; cin >> a >> b;
    rep(i, 0, a.size()) {
        if (a[i]) cout << a[i];
        if (b[i]) cout << b[i];
    }
    cout << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int x = (1800 * m + 100 * n) * pow(2, m);
  cout << x << endl;
  return 0;
}

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

int main() {
  int N, K;
  int h[100102];
  int64_t dp[100102];
  cin >> N >> K;
  for (int i=0;i<N;++i ) {
    cin >> h[i];
    dp[i] = 100000 * 10001;
  }
  dp[0] = 0;
  for (int i=0;i<N-1;++i){
    for (int j=1;j<K+1; ++j ) {
      dp[i+j] = min( dp[i+j], dp[i] + abs(h[i+j]-h[i]));
    }
  }
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1408
h,w = map(int,input().split())
a = []

while True:
  try:
    a.append(input())
  except:
    break
    
for i in range(h):
  a[i] = "#"+a[i]+"#"

print("#"*(w+2))
for i in range(h):
  print(a[i])
print("#"*(w+2))

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

int main() {
  int N,M,ans=0;
  cin>>N>>M;
  vector<int>min(M) ;
   vector<int>max(M) ;
  for(int i=0 ; i<M ;i++){
  cin>>min.at(i)>>max.at(i);
  }
sort(min.begin(), min.end());
  sort(max.begin(), max.end());
 // cout<<min.at(M-1)<<max.at(0)<<endl ;
for(int i=1; i<=N;i++){
  if(i>=min.at(M-1)&&i<=max.at(0)){
   ans++;
  }
}
  cout<<ans<<endl ;
  
}

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

class Dice{
    public:
        int s[6];
        void roll(char c){
            int temp;
            if(c=='E'){
                temp=s[2];
                s[2]=s[0];
                s[0]=s[3];
                s[3]=s[5];
                s[5]=temp;
            }
            if(c=='N'){
                temp=s[4];
                s[4]=s[0];
                s[0]=s[1];
                s[1]=s[5];
                s[5]=temp;
            }
            if(c=='S'){
                temp=s[1];
                s[1]=s[0];
                s[0]=s[4];
                s[4]=s[5];
                s[5]=temp;
            }
            if(c=='W'){
                temp=s[3];
                s[3]=s[0];
                s[0]=s[2];
                s[2]=s[5];
                s[5]=temp;
            }
        }
        int top(){
            return s[0];
        }
};

int main(){
    Dice dice;
    for(int i=0;i<6;i++){
        cin>>dice.s[i];
    }
    string str;
    cin>>str;
    for(int i=0;i<str.length();i++){
        dice.roll(str[i]);
    }
    cout<<dice.top()<<endl;
    return 0;
}


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

int main() {
  int n; 
  cin >> n;
  int a[4];
  a[0] = n/1000;
  n-=a[0]*1000;
  a[1] = n/100;
  n-=a[1]*100;
  a[2] = n/10;
  n-=a[2]*10;
  a[3] = n;
  
  int bits;
  
  char c[3];
  for (bits = 0; bits < (1 << 3); bits++) {
    int k = a[0];
    for (int i = 0; i < 3; i++) {
      if ((bits >> i) & 1) {
        k += a[i+1];
        c[i] = '+';
      } else {
        k -= a[i+1];
        c[i] = '-';
      }
    }
    if (k == 7) break;
  }
  
  cout << a[0] << c[0] << a[1] << c[1] << a[2] << c[2] << a[3] << "=7" << endl;
  
}

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

using namespace std;

typedef long long ll;
#define NG (-1);

int x,y,z;
ll k,temp,times;
bool pivot = true;
vector <ll> a,b,c;
vector <ll> sumbc;

void enter()
{
    cin >> x >> y >> z >> k;
    a.resize(x);
    b.resize(y);
    c.resize(z);
    for (int i = 0; i < x ; i ++) cin >> a[i];
    for (int i = 0; i < y ; i ++) cin >> b[i];
    for (int i = 0; i < z ; i ++) cin >> c[i];
}

void process()
{
    for (int i = 0 ; i < y ; i ++)
        for (int j = 0 ; j < z ; j++)
        {
            temp = b[i] + c[j];
            sumbc.push_back(temp);
        }
    sort(sumbc.rbegin(),sumbc.rend());

    /*for (int i = 0; i < x ; i ++) cout << a[i] << " ";
    cout << endl;
    for (int i = 0; i < sumbc.size() ; i ++) cout << sumbc[i] << " ";
    cout << endl;*/

    vector <int> bcidx(x);

    for (int turn = 0; turn < k; ++turn)
	{
	    ll bestval = NG;
	    int besti = NG;
	    ll val;

		for (int i = 0 ; i < x ; i ++)
        {
            val = a[i] + sumbc[bcidx[i]];
            if (val > bestval)
            {
                bestval = val;
                besti = i;
            }
        }

        cout << bestval << endl;
        bcidx[besti]++;
	}
}

int main()
{

    enter();
    process();
    return 0;

}


Measured memory_bytes: 10608
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce


# 画像でおいた自分の解説見て
N = a_int()
B = []
for _ in ra(N):
    # A = float(read()[:-1])  # floatなら小数13桁ぐらい入る
    # B.append(int(A * (10**9)))
    A = read()[:-1]
    if '.' not in A:
        A += '.'
    for _ in range(9 - A[::-1].index('.')):
        A += '0'
    B.append(int(A[:-10] + A[-9:]))

N = []
M = []
for b in B:
    n = 0
    while b % 2 == 0:  # 偶数である限り
        b >>= 1
        n += 1
    N.append(n)

    m = 0
    while b % 5 == 0:  # 5で割れる限り
        b //= 5
        m += 1
    M.append(m)

cnt = [[0] * 19 for _ in ra(19)]
ans = 0
for n, m in zip(N, M):
    x = max(18 - n, 0)
    y = max(18 - m, 0)
    for i, j in product(range(x, 19), range(y, 19)):
        ans += cnt[i][j]

    # このデータをcntに追加
    cnt[min(n, 18)][min(m, 18)] += 1

print(ans)


Measured memory_bytes: 105852
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The Value Of " << #val << " is : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 2e5+5;
ll n, arr[nax];
vector<ll>v;
	
int main(){
	IOS
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> arr[i];
		v.pb(arr[i]);
	}
	sort(v.begin(), v.end());
	for(int i=0;i<n;i++){
		if(arr[i]<v[n/2]){
			cout << v[n/2] << '\n';
		}
		else{
			cout << v[n/2-1] << '\n';
		}
	}
}


Measured memory_bytes: 6484
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, K; cin >> A >> B >> K;
for (int i = min(A, B); i >= 1; --i) {
if (A % i == 0 && B % i == 0) {
--K;
if (K == 0) {
cout << i << endl;
return 0;
}
}
}
assert(false);
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    String s[] = str.split("");
    int count = 0;

    for (int i = 0; i < str.length(); i++) {
      if (s[i].equals(Integer.toString(i%2)) == false)
        count++;
    }
    System.out.println(str.length()-count<count ? str.length()-count : count);
  }
}


Measured memory_bytes: 38416
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


int main()
{
    int x[3];
    cin >> x[0] >> x[1] >> x[2] ;
    sort(x,x+3);
    cout << x[0] + x[1] << endl ;
    return 0 ;
}

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

int solve(vector<int> &h) {
	int a = 0;
	int b = abs(h[1]-h[0]);
	for (int i = 2; i < h.size(); ++i)
	{
		int tmp = min(b + abs(h[i]-h[i-1]), a + abs(h[i]-h[i-2]));
		a = b;
		b = tmp;
	}
	return b;
}


int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}
	cout << solve(h) << "\n";
	return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
#define MOD 1000000007
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main(){
    ll n;cin>>n;
    vector<double> vec(n);
    For(i,n){
        cin>>vec.at(i);
    }
    sort(vec.begin(),vec.end());
    double ans=(vec.at(0)+vec.at(1))/2;
    for(ll i=2;i<n;i++){
        ans=(ans+vec.at(i))/2;
    }
    cout << fixed << setprecision(6);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static Scanner sc = new Scanner(System.in);
	private static Scanner s = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");
	public static void main(String[] args) {
		int N=s.nextInt();			
		long ans=0;
		for(int i=1;i<=N;i++) {
			if(i%5==0||i%3==0) {
				
			}else {
				ans+=i;
			}
		}
		p(ans);
		/*int N=sc.nextInt();
		for(int i=0;i<N;i++) {
			int x=sc.nextInt();
		}*/
		
		
		
				
		
	}
}


















Measured memory_bytes: 27244
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
using namespace std;
 
const int INF = (int)10e9;
 
#define X first
#define Y second
 
int main() {
  int w, h, n;
  deque<pair<int, int> > p;
   
  cin >> w >> h >> n;
   
  for(int i=0; i<n; i++) {
    int x, y;
    cin >> x >> y;
    p.push_back(make_pair(x, y));
  }
   
  int res = 0;
  const int N = p.size();
  for(int i=0; i<N-1; i++) {
    int ww = abs(p[i].X-p[i+1].X);
    int hh = abs(p[i].Y-p[i+1].Y);
    if(p[i].X < p[i+1].X && p[i].Y < p[i+1].Y) res += min(ww, hh) + abs(ww-hh);
    else if(p[i+1].X < p[i].X && p[i+1].Y < p[i].Y) res += min(ww, hh) + abs(ww-hh);
    else res += ww+hh;
  }
   
  cout << res << endl;
   
   
  return 0;
}

Measured memory_bytes: 1224
# input = readlines()
# a, b = input.shift().chomp.split("\s").map{|x| x.to_i}

n = gets().chomp.to_i

odd_cnt = 0
(1..n).each do |num|
  odd_cnt += 1 if num.odd?
end

puts odd_cnt.to_f / n.to_f


Measured memory_bytes: 14272
//Wrong answer on test inf.
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
#define y1 y1___
using namespace std;
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
ll read(){
	char ch=gc();ll x=0;int op=1;
	for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 100005
int n,sl,q[N],a[N],bit[N];ll k;
struct node{int x,y;node(){}node(int x_,int y_){x=x_,y=y_;}}b[N];
bool cmp(node x,node y){return x.x<y.x||x.x==y.x&&x.y>y.y;}
void add(int x){if (!x){bit[x]++;return;}for (int i=x;i<=n;i+=i&-i) bit[i]++;}
int qry(int x){int s=bit[0];for (int i=x;i;i-=i&-i) s+=bit[i];return s;}
bool check(int x){
	int sum=0,sl;
	rep (i,1,n) sum+=(a[i]<=x?1:-1),b[i]=node(sum,i);//sum[r]-sum[l]>0
	sl=n;b[++sl]=node(0,0);
	sort(&b[1],&b[sl+1],cmp);
	memset(bit,0,sizeof(bit));
	ll res=0;
	rep (i,1,sl){res+=qry(b[i].y);add(b[i].y);}
	return res>=k;
}
int main(){
	n=read();
	rep (i,1,n) q[i]=a[i]=read();
	sort(&q[1],&q[n+1]);sl=unique(&q[1],&q[n+1])-q-1;
	k=((ll)n*(n+1)/2)/2+1;
	int l=1,r=sl,mid;
	while (l<=r){
		mid=l+r>>1;
		if (check(q[mid])) r=mid-1;else l=mid+1;
	}
	printf("%d\n",q[r+1]);
	return 0;
}

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

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

  int sum = 0;
  vector<int> x(n);

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

    if(k - x[i] > x[i]) sum += (x[i]*2);
    else sum += ((k - x[i]) * 2);
  }

  cout << sum << endl;

  return 0;

}


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

using namespace std;

int loadCheck(int N[], int n, int k, int P) {
	int i = 0;
	for (int j = 0; j < k; ++j) {
		int load = 0;
		while (load + N[i] <= P) {
			load += N[i];
			++i;
			if (i == n)
				return n;
		}
	}

	return i;
}

int main() {

	int n, k;
	scanf("%d %d", &n, &k);

	int N[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &N[i]);
	}

	int left = 0;
	int right = 1000000000;
	while (left < right) {
		int mid = (left + right) / 2;
		if (loadCheck(N, n, k, mid) == n) {
			right = mid;
		} else {
			left = mid + 1;
		}
	}
	cout << right << endl;

	return 0;
}

Measured memory_bytes: 3616
while True :
  m, f, r = map(int, input().split())
  if(m == -1 and f == -1 and r == -1) :
    break
  elif(m == -1 or f == -1) :
    print("F")
  elif(m + f >= 80) :
    print("A")
  elif(65 <= m + f and m + f < 80) :
    print("B")
  elif(50 <= m + f and m + f < 65) :
    print("C")
  elif(30 <= m + f and m + f < 50) :
    if(50 <= r) :
      print("C")
    else :
      print("D")
  else :
    print("F")


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

const ll INF = 1e18;
int main(void){
    int n, W;
    cin >> n >> W;
    int M = 100010;
    vector<ll> dp(M, INF);
    dp[0] = 0;
    rep(i,n){
        ll w,v;
        cin >> w >> v;
        for (int j = M; j >= 0; j--) {
            if (dp[j] == INF) continue;
            if (j+v > M) continue;
            dp[j+v] = min(dp[j+v], dp[j]+w);
        }
    }
    int res = 0;
    rep(j,M){
        if (dp[j] > W) continue;
        res = max(res, j);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<cmath>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}
int digits(int n) {
	int count = 0;
	while (n > 0) {
		n /= 10;
		count++;
	}
	return count;
}
ll combination(ll n, ll r) {
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int main() { 
	int n;
	cin >> n;
	vector<int>h(n);
	rep(i, n)cin >> h[i];
	int pre = h[0];
	bool ans = true;
	rep(i, n) {
		if (h[i] < pre) {
			ans = false;
		}
		pre = max(h[i]-1,pre);
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 640
n, k = map(int, input().split())

def x_sum(x):
    return (2*n-x+1)*x//2 - x*(x-1)//2 + 1

ans = 0 
for i in range(k, n+2):
    ans += x_sum(i)
ans %= 10 ** 9 + 7

print(ans)


Measured memory_bytes: 63884
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
  string s;
  cin >> s;
  ll dp[100005][13] = {};

  //dp[0]の決定
  if (s[0] == '?') {
    rep(i, 10) dp[0][i] = 1;
  }
  else {
    int a = s[0] - '0';
    dp[0][a] = 1;
  }
  //inductiveにdp[s.size()-1]まで決定する
  rep(i, s.size() - 1) {
    rep(a, 13) {
      if (s[i + 1] == '?') {
        rep(b, 10) {
          int c = (10 * a + b) % 13;
          dp[i + 1][c] = (dp[i + 1][c] + dp[i][a]) % MOD1;
        }
      }
      else {
        int d = s[i + 1] - '0';
        int c = (10 * a + d) % 13;
        dp[i + 1][c] = (dp[i + 1][c] + dp[i][a]) % MOD1;
      }
    }
  }

  cout << dp[s.size() - 1][5] << endl;

}


Measured memory_bytes: 10624
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			if (isIncreasing(a)) {
				System.out.println(0);
				return;
			}
			int maxValue = 0, maxIndex = 0;
			int minValue = Integer.MAX_VALUE, minIndex = 0;
			for (int i = 0; i < a.length; i++) {
				if (a[i] > maxValue) {
					maxValue = a[i];
					maxIndex = i + 1;
				}
				if (a[i] < minValue) {
					minValue = a[i];
					minIndex = i + 1;
				}
			}
			if ((maxValue <= 0) || (minValue >= 0)) {
				System.out.println(n - 1);
				// すべてが負の数か正の数の場合
				printSteps(n, (maxValue <= 0));
			} else {
				int fromIndex = (Math.abs(maxValue) > Math.abs(minValue)) ? maxIndex : minIndex;
				System.out.println(2 * n - 1);
				printAddSteps(n, fromIndex);
				printSteps(n, (fromIndex == minIndex));
			}
		}
	}

	/**
	 * @param a 入力配列
	 * @return 入力配列は単調増加かどうか
	 */
	static boolean isIncreasing(int[] a) {
		for (int i = 1; i < a.length; i++) {
			if (a[i] < a[i - 1]) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 長さnの数列の計算ステップを出力する
	 * 
	 * @param n       数列の長さ
	 * @param reverse 逆順かどうか
	 */
	private static void printSteps(int n, boolean reverse) {
		if (reverse) {
			IntStream.range(1, n).map(i -> n - i).forEach(i -> System.out.println((i + 1) + " " + i));
		} else {
			IntStream.range(1, n).forEach(i -> System.out.println(i + " " + (i + 1)));
		}
	}

	/**
	 * 数列のすべてにindexの数字を足す計算ステップを出力する
	 * 
	 * @param n     数列の長さ
	 * @param index 加算もととなるindex
	 */
	private static void printAddSteps(int n, int index) {
		IntStream.rangeClosed(1, n).forEach(i -> System.out.println(index + " " + i));
	}
}


Measured memory_bytes: 39692