akhauriyash/Code-Regression huggingface dataset:
#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);

    int n, m;
    cin >> n >> m;

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

    vector<int> other(n, 0);
    auto match = [&](int a, int b, vector<int>& other) {
        // cout << "match " << a << " " << b << endl;
        for (int i = 0; i < n; ++i) {
            if (M[i][a] != M[other[i]][b]) {
                return false;
            }
        }
        return true;
    };

    auto check = [&](vector<int>& other) {
        // for (int i = 0; i < n; ++i) {
        //     cout << i << ":" << other[i] << ' ';
        // }
        // cout << endl;

        int used = 0;
        int mid = 0;
        for (int i = 0; i < m; ++i) {
            if (used & (1 << i)) {
                continue;
            }
            bool ok = false;
            for (int j = i + 1; j < m; ++j) {
                if (used & (1 << j)) {
                    continue;
                }
                if (match(i, j, other)) {
                    ok = true;
                    used |= 1 << i;
                    used |= 1 << j;
                    break;
                }
            }
            if (!ok) {
                if (!match(i, i, other)) {
                    return false;
                } 
                ++mid;
                if (mid > 1 || m % 2 == 0) {
                    return false;
                }
                used |= i;
            }
        }
        return true;
    };

    function<bool(int, int, int)> dfs = [&](int i, int rem, int used) -> bool {
        // cout << "dfs " << i << " " << used << endl;
        if (i == n) {
            if (check(other)) {
                return true;
            }
        }

        if (used & (1 << i)) {
            return dfs(i + 1,  rem, used);
        }

        used |= 1 << i;
        if (rem > 0) {
            other[i] = i;
            if (dfs(i + 1, rem - 1, used)) {
                return true;
            }
            other[i] = 0;
        }
        if (rem == 0 || i + 1 < n) {
            for (int j = i + 1; j < n; ++j) {
                if ((used & (1 << j)) == 0) {
                    other[i] = j;
                    other[j] = i;

                    if (dfs(i + 1, rem, used | (1 << j))) {
                        return true;
                    }
          
                    other[i] = 0;
                    other[j] = 0;
                }
            }
        }
        return false;
    };

    if (dfs(0, n % 2, 0)) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }


    return 0;
}

Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
plus=0
minus=[]
for a,b in zip(A,B):
    if a<b:
        ans += 1
        plus += (b-a)
    elif a>b:
        minus.append(a-b)
minus.sort(reverse=True)
while True:
    if plus<=0:
        print(ans)
        break
    if minus==[]:
        print(-1)
        break
    plus -= minus.pop(0)
    ans += 1

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

int main(){
  int H,W,N;
  cin>>H>>W>>N;
  
  int whiterow=H;
  int whitecol=W;
    
  int blackgrid=0;
  int ans=0;
  
  while(blackgrid<N){
    if(whiterow>whitecol){
      blackgrid+=whiterow;
      whitecol--;
    }else{
      blackgrid+=whitecol;
      whiterow--;
    }
    ans++;
    
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define fi first
#define se second
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
 
#define INF ((1ll<<60)-233)
#define sqr(x) ((x)*(x))
#define debug puts("wzpkking")
using namespace std;

const int N=100005;
int n,f[N],h,t;
multiset<int> s[N];
map<pii,int> mp;
pii q[N*50];
int get(int x){
	return x==f[x]?x:f[x]=get(f[x]);
}
int main(){
	scanf("%d",&n);
	For(i,1,n) f[i]=i;
	For(i,1,2*n-2){
		int x,y; scanf("%d%d",&x,&y);
		s[x].insert(y); s[y].insert(x);
		mp[pii(x,y)]++; mp[pii(y,x)]++;
		if (mp[pii(x,y)]==2) q[++t]=pii(x,y);
	}
	multiset<int>::iterator it;
	while (h!=t){
		int x=q[++h].fi,y=q[h].se;
		if ((x=get(x))==(y=get(y))) continue;
		s[x].erase(y); s[y].erase(x);
		if (s[x].size()<s[y].size()) swap(x,y);
		for (it=s[y].begin();it!=s[y].end();it++){
			int i=*it;
			s[i].erase(y); s[i].insert(x);
			++mp[pii(i,x)]; ++mp[pii(x,i)];
			if (mp[pii(x,i)]==2) q[++t]=pii(x,i);
			s[x].insert(i);
		}
		f[y]=x; s[y].clear();
	}
	For(i,1,n) if (get(i)!=get(1))
		return puts("NO"),0;
	puts("YES");
}

Measured memory_bytes: 56832
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;




int main(){
    double r;
    cin >> r;
    double pi = 3.14159265358979323846;
    double ans = 2*pi*r;
    printf ("%.10f",ans);


}









Measured memory_bytes: 3788
#include<stdio.h>
	int main(void)
{
	int x, y, temp;
	while(1){
		scanf("%d %d", &x, &y);
		if(x > y){
			temp = x;
			x = y;
			y = temp;
		}else if(x == 0 && y == 0){
			break;
		}
		printf("%d %d\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    rep(i, l, r + 1) if (i % d == 0) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3556
import numpy as np

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

n, X = map(int, input().split())
if n==1:
    x = int(input())
    print(abs(x-X))
    quit()    
else:
    x = list(map(int, input().split()))

    a = np.ones(n)*X
    b = np.abs(x - a)
    c = b[1]
    for i in range(n-1):
        c = gcd(c, b[i])
    print(int(c))


Measured memory_bytes: 23116
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,a[200005],l=1,r=(n*2-1),ans;
bool check(int x){
	for(int i=0;i<=n-2;i++){
		if((a[n+i]<=x&&a[n+i+1]<=x)||(a[n-i]<=x&&a[n-i-1]<=x))return 1;
		if((a[n+i]>x&&a[n+i+1]>x)||(a[n-i]>x&&a[n-i-1]>x))return 0;
	}
	if(a[1]>x)return 0;
	else return 1;
}
int main(){
	in(n);
	for(int i=1;i<=n*2-1;i++)in(a[i]);
	r=n*2-1;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
# ABC 057: B – Checkpoints
n, m = [int(s) for s in input().split()]

a = []
b = []

for i in range(n):
    tmp = [int(s) for s in input().split()]
    a.append(tmp[0])
    b.append(tmp[1])

c = []
d = []

for j in range(m):
    tmp = [int(s) for s in input().split()]
    c.append(tmp[0])
    d.append(tmp[1])

for i in range(n):
    checkpoint = 0
    distance = abs(c[0] - a[i]) + abs(d[0] - b[i])
    
    for j in range(m):
        if distance > abs(c[j] - a[i]) + abs(d[j] - b[i]):
            distance = abs(c[j] - a[i]) + abs(d[j] - b[i])
            checkpoint = j
    
    print(checkpoint + 1)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int staNum = sc.nextInt();
        int endNum = sc.nextInt();
        int divisor = sc.nextInt();
        int cnt = 0;
        for(int i=staNum;i<=endNum;i++){
            if(divisor%i == 0) {
                cnt++;
            }
        }
        System.out.println(cnt);
        sc.close();
    }
}


Measured memory_bytes: 26300
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication57
{
    class Program
    {
        static void Main()
        {
            int a = int.Parse(Console.ReadLine());
            for(int b = 0; b < a; b++)
            {
                string c = Console.ReadLine();//999
                string d = Console.ReadLine();//1
                string[] e = { c, d };
                if (c.Length > d.Length) { e[0] = d;e[1] = c; }//1 999
                int[] f = new int[e[1].Length+1];//4
                for (int g = 0; g < e[0].Length; g++)//1
                {
                    int p = e[0][e[0].Length - g - 1];//1
                    int q = e[1][e[1].Length - g - 1];//
                    int y= (p+q-96) % 10;
                    f[f.Length - g - 1] +=y;
                    f[f.Length-g-2]= (e[0][e[0].Length - g - 1] + e[1][e[1].Length - g - 1] - 96) /10;
                }          
                for(int h = e[0].Length; h < f.Length-1; h++)
                {
                    int q = e[1][e[1].Length - h - 1];
                    int y = ( q - 48) % 10;
                    f[f.Length - h- 1] += y;
                    int w = f[f.Length - h - 1];
                    f[f.Length - h - 1] %= 10;
                    f[f.Length - h - 2] = w / 10;
                }
                if (f[0] == 0)
                {
                    if (f.Length > 81) Console.WriteLine("overflow");
                    else
                    {
                       for(int q = 1; q < f.Length; q++)
                        {
                            Console.Write(f[q]);
                        }
                        Console.WriteLine();
                    }
                }
                else
                {
                    if (f.Length >80) Console.WriteLine("overflow");
                    else
                    {
                        foreach (int q in f)
                        {
                            Console.Write(q);
                        }
                        Console.WriteLine();
                    }
                }
            }
            }
        }
    }

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

int main(){
    int H, W;
    while(1){
        cin >> H >>W;
        if(W==0||H==0){
            break;
        }
        for(int i=1; i<=H; i++){
            for(int a=1; a<=W; a++){
                cout<<'#';
            }
        cout<<'\n';
        }
    cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3032
#include<bits/stdc++.h>
#define chmax(a,b) (a)=max((a),(b))
using namespace std;
int ac[3][100001],dp[3][100001];
int n;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=0;j<3;j++)
			scanf("%d",&ac[j][i]);
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++){
			chmax(dp[(j+2)%3][i+1],dp[j][i]+ac[(j+2)%3][i+1]);
			chmax(dp[(j+1)%3][i+1],dp[j][i]+ac[(j+1)%3][i+1]);
		}
	int ans=max(dp[0][n],max(dp[1][n],dp[2][n]));
	cout<<ans<<endl;
	return 0;
}

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

#define YET 0
#define HALFWAY 1
#define DONE 2
#define MOD 1000000007

typedef long long int LLI;

int N;
int M;
int num_cycle;
int state[1145];
int dest[1145];
vector<int> es[1145];
vector<int> cycles[1145];

LLI Pow(LLI base, LLI exp) {
  if (exp == 0) return 1;

  LLI res = Pow(base*base%MOD, exp/2);
  if (exp%2 == 1) {
    res = res*base%MOD;
  }
  return res;
}

LLI calc(int v, int prev) {
  LLI ret = 1;
  for (int u : es[v]) {
    if (prev == u) continue;
    ret = ret*calc(u, v)%MOD;
  }
  return (ret+1)%MOD;
}

bool dfs(int v, int u) {
  if (state[v] == DONE) {
    if (u != -1) es[v].emplace_back(u);
    return false;
  }

  if (state[v] == HALFWAY) {
    state[v] = DONE;
    return true;
  }

  if (dest[v] == -1) {
    state[v] = DONE;
    if (u != -1) es[v].emplace_back(u);
    cycles[num_cycle].emplace_back(v);
    num_cycle++;
    return false;
  }

  state[v] = HALFWAY;
  bool ret = dfs(dest[v], v);
  if (ret) {
    auto &cycle = cycles[num_cycle];
    cycle.emplace_back(v);
    if (state[v] == DONE) {
      reverse(cycle.begin(), cycle.end());
      if (u != -1) es[v].emplace_back(u);
      num_cycle++;
      return false;
    }
  } else {
    if (u != -1) es[v].emplace_back(u);
  }
  state[v] = DONE;
  return ret;
}

int main() {
  scanf("%d%d", &N, &M);
  fill(dest, dest+N, -1);
  for (int i=0; i<M; i++) {
    int s, t;
    scanf("%d%d", &s, &t);
    --s;
    --t;
    dest[s] = t;
  }

  for (int i=0; i<N; i++) {
    if (state[i] != DONE) dfs(i, -1);
  }

  LLI ans = 1;
  for (int i=0; i<num_cycle; i++) {
    LLI t = 1;
    //printf("cycles[%d]: ", i);
    for (int root : cycles[i]) {
      //printf("%d ", root);
      t = t*((MOD+calc(root, root)-1)%MOD)%MOD;
    }
    //puts("");
    t = (t+1)%MOD;
    //printf("t: %lld\n", t);
    ans = ans*t%MOD;
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 3276
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		if(n % 500 <= a) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string t;
	cin>>t;
	int l=LEN(t);
	rep(i,l)cout<<(t[i]=='?'?'D':t[i]);
	cout<<endl;
}

Measured memory_bytes: 3744
#include"bits/stdc++.h"
using namespace std;

struct UnionFind {
    vector<int> parent;
    UnionFind(int size) : parent(size) {
        for (int i = 0; i < size; i++) {
            parent[i] = i;
        }
    }
    void unionSet(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            parent[x] = y;
        }
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return (parent[x] == x ? x : parent[x] = root(parent[x]));
    }
};

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

    struct Point {
        int x, y, index;
    };

    vector<Point> points_sorted_by_x(N), points_sorted_by_y(N);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        points_sorted_by_x[i].x = points_sorted_by_y[i].x = x;
        points_sorted_by_x[i].y = points_sorted_by_y[i].y = y;
        points_sorted_by_x[i].index = points_sorted_by_y[i].index = i;
    }

    sort(points_sorted_by_x.begin(), points_sorted_by_x.end(), [&](Point& lhs, Point& rhs){
        return (lhs.x != rhs.x ? lhs.x < rhs.x : lhs.y < rhs.y);
    });
    sort(points_sorted_by_y.begin(), points_sorted_by_y.end(), [&](Point& lhs, Point& rhs) {
        return (lhs.y != rhs.y ? lhs.y < rhs.y : lhs.x < rhs.x);
    });

    struct Edge {
        int index1, index2, cost;
    };

    vector<Edge> edges;
    for (int i = 0; i < N - 1; i++) {
        Edge tmp;
        tmp.index1 = points_sorted_by_x[i].index;
        tmp.index2 = points_sorted_by_x[i + 1].index;
        tmp.cost = min(abs(points_sorted_by_x[i].x - points_sorted_by_x[i + 1].x),
            abs(points_sorted_by_x[i].y - points_sorted_by_x[i + 1].y));
        edges.push_back(tmp);
    }
    for (int i = 0; i < N - 1; i++) {
        Edge tmp;
        tmp.index1 = points_sorted_by_y[i].index;
        tmp.index2 = points_sorted_by_y[i + 1].index;
        tmp.cost = min(abs(points_sorted_by_y[i].x - points_sorted_by_y[i + 1].x),
            abs(points_sorted_by_y[i].y - points_sorted_by_y[i + 1].y));
        edges.push_back(tmp);
    }
    sort(edges.begin(), edges.end(), [&](Edge& lhs, Edge& rhs) {
        return lhs.cost < rhs.cost;
    });

    //クラスカル法
    long long ans = 0;
    UnionFind uf(N);
    for (Edge e : edges) {
        if (!uf.same(e.index1, e.index2)) {
            uf.unionSet(e.index1, e.index2);
            ans += e.cost;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 7284
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
ll n;
cin >> n;
vector<ll> a(n);
map<ll,ll> m;
REP(i,n) {
  cin >> a[i];
  m[a[i]]++;
}
ll ans=0;
for(auto j=m.begin();j!=m.end();j++) {
  if(j->second<=1) continue;
  ans+=j->second*(j->second-1)/2;
}
ll temp;
REP(i,n) {
  if(m[a[i]]>=1) {
    temp = ans+1-m[a[i]];
  } else {
    temp = ans;
  }
  
  cout << temp << endl;
}

return 0;
}


Measured memory_bytes: 11008
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    p.back()/=2;
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=p[i];
    }
    cout<<sum<<endl;
    
    return 0;
}

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

int money1(int x , int y){
    int ans;
    ans=x*y*2;
    return ans;
}

int money2(int a , int b , int c , int d){
    int x,y,ans;
    x=a-b;
    ans=b*d*2+x*c;
    return ans;
}

int main()
{
    int A,B,C,X,Y,ans;
    cin>>A>>B>>C>>X>>Y;
    if(A+B<=C*2){
        ans=A*X+B*Y;
    }else{
        if(X>=Y){
            if(A>2*C){
                ans=money1(X,C);
            }else{
                ans=money2(X,Y,A,C);
            }
        }else{
            if(B>2*C){
                ans=money1(Y,C);
            }else{
                ans=money2(Y,X,B,C);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
 * Code be weshen zyk :'(
 */
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define F first
#define S second

using ll = long long;
using ii = pair<int, int>;
using db = long double;

#ifdef ONLINE_JUDGE
#define cerr if(0)cerr
#endif

template<class C> void amin(C &a4, C b4) {
	a4 = min(a4, b4);
}
template<class C> void amax(C &a4, C b4) {
	a4 = max(a4, b4);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
	os << "[";
	for (auto vv : V)
		os << vv << ",";
	return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
	return os << "(" << P.first << "," << P.second << ")";
}

const int N = 2e5 + 5;
int n, m;
int b[N + N];
ll a[N];
int cnt[N];
int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif

	int n;
	cin >> n;
	vector<int>dp(n + 1), h(n+1);
	for(int i = 1; i <= n; i++)
		cin >> h[i];

	for(int i = 2; i <= n; i++){
		dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
		if(i > 2)
			dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
	}

	cout << dp[n] << '\n';


	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll c=a+b;
    ll r=n/c;
    ll x=a*r;
    n=n-c*r;
    cout << x+min(n,a)<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static int N_MAX = 100;

void p(int A[], int N) {
	for (int i = 0; i < N; ++i) {
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

void swap(int &a, int &b) {
	int c = a;
	a = b;
	b = c;
}

int selectionSort(int A[], int N) {
	int count = 0;
	for (int i = 0; i < N; ++i) {
		int minj = i;
		for (int j = i; j < N; ++j)
			if (A[j] < A[minj])	minj = j;
		if (minj != i) {
			swap(A[i], A[minj]);
			++count;
		}
	}
	return count;
}

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

	int count = selectionSort(A, N);
	p(A, N);
	cout << count << endl;
}

Measured memory_bytes: 1164
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
using namespace std;
int a[2];
int b[2];
int main(){ 
  for (int i=0;i<2;i++)
    cin>>a[i];
  for (int j=0;j<2;j++)
    cin>>b[j];
  sort(a,a+2);
  sort(b,b+2);
  cout<<a[0]+b[0];
  system ("pause");
  return 0;
}

Measured memory_bytes: 504
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cassert>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define debug(x) {cout<<(#x)<<" "<<x<<endl;}
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

LL A,B;

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	scanf("%lld %lld",&A,&B);
	if (A==B) {puts("1"); return 0;}
	LL r=-1,k=-1;
	LL ans=0,tmp=0;
	per(i,60,0) {
		LL t1=(1LL<<i)&A,t2=(1LL<<i)&B;
		if (t1!=t2) {r=i; break;}
		tmp+=(1LL<<i)&A;
	}
	LL T=(1LL<<r);
	A-=tmp,B-=tmp;
	ans+=T-A;
	per(i,r-1,0) if (B&(1LL<<i)) {k=i; break;}
	LL Q=(1LL<<(k+1))-1;
	ans+=Q+1;
	ans+=T-A;
	if (A<=Q) ans-=(Q-A+1);
	if (T-1<=Q) ans+=(Q-T+1);
		
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

int main()
{
    int n, m;
    cin >> n >> m;
    bool grid[n][m];
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            char w; cin >> w;
            if(w == '.') grid[i][j] = true;
            else grid[i][j] = false;
        }
    }

    // int dp[n][n];
    vector<vector<int>> dp(n, vector<int>(m));
    dp[0][0] = 1;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            if(!grid[i][j]) continue;
            if(i > 0) dp[i][j] += dp[i - 1][j], dp[i][j] %= MOD;
            if(j > 0) dp[i][j] += dp[i][j - 1], dp[i][j] %= MOD;
        }
    }

    if(!grid[0][0]) cout << 0;
    else cout << dp[n - 1][m - 1];
    return 0;
}

Measured memory_bytes: 5120
# B - Coins
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0

for a in range(A + 1):
	for b in range(B + 1):
		for c in range(C + 1):
			if 500 * a + 100 * b + 50 * c == X:
				ans += 1

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N; cin >> N;
  char c;
  int cnt = 0,maxc = 0;
  rep(i,N){
    cin >> c;
    if (c=='I') cnt++;
    else cnt--;

    maxc = max(maxc, cnt);
  }

  cout << maxc << endl;
  
  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
    B[i] = B[i-1]+A[i-1]
cmin = 10**15
for i in range(1,N):
    cmin = min(cmin,abs(2*B[i]-B[N]))
print(cmin)

Measured memory_bytes: 100536
#include <atcoder/dsu>
#include <cstdio>
 
using namespace std;
using namespace atcoder;
 
int main() {
    int n, q;
    scanf("%d %d", &n, &q);
 
    dsu d = dsu(n);
    int t, u, v;
    for (int i = 0; i < q; ++i) {
        scanf("%d %d %d", &t, &u, &v);
        if (t == 1) {
            printf("%d\n", d.same(u, v));
        } else {
            d.merge(u, v);
        }
    }
 
    return 0;
}


Measured memory_bytes: 3504
#include<cstring>
#include<cstdio>
#include<iostream>
#define mod 1000000007
using namespace std;
typedef long long ll;

ll dp[3010][3010][2];
int main() {
	int n,m;
	scanf("%d%d",&n,&m);
	memset(dp,0,sizeof(dp));
	dp[0][0][1]=1;
	dp[0][0][0]=0;
	for(int j=1; j<=n; j++) {
		dp[0][j][0]=1;
		dp[0][j][1]=0;
	}
	for(int i=1; i<=m; i++) {

		for(int j=0; j<=n; j++) {
			if(j==0) {
				dp[i][j][1]+=((dp[i-1][j][1]+dp[i-1][j+1][0])%mod+dp[i-1][j+1][1])%mod;
				dp[i][j][1]%=mod;
			} else if(j==n) {
				dp[i][j][0]+=(dp[i-1][j][0]+dp[i-1][j-1][0])%mod;
				dp[i][j][1]+=(dp[i-1][j][1]+dp[i-1][j-1][1])%mod;
				dp[i][j][0]%=mod;
				dp[i][j][1]%=mod;
			} else if(j==1) {
				dp[i][j][0]+=((dp[i-1][j][0]+dp[i-1][j-1][0])%mod+dp[i-1][j+1][0])%mod;
				dp[i][j][1]+=(((dp[i-1][j][1]*2+dp[i-1][j][0])%mod+dp[i-1][j-1][1])%mod+dp[i-1][j+1][1])%mod;
				dp[i][j][0]%=mod;
				dp[i][j][1]%=mod;
			}else {
				dp[i][j][0]+=((dp[i-1][j][0]*2%mod+dp[i-1][j-1][0])%mod+dp[i-1][j+1][0])%mod;
				dp[i][j][1]+=(((dp[i-1][j][1]*2)%mod+dp[i-1][j-1][1])%mod+dp[i-1][j+1][1])%mod;
				dp[i][j][0]%=mod;
				dp[i][j][1]%=mod;
			}
		}
	}
	ll ans=0;
	if(n==1) ans++;
//	cout << dp[m][n][1];
	for(int j=0; j<=n; j++) {
		ans+=dp[m][j][1];
		ans%=mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 141824
#include<bits/stdc++.h>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define pb(s) push_back(s)
#define CST(x) cout<<fixed<<setprecision(x)
#define ci(x) cin >>x
#define co(x) cout<<x<<endl
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vvpl=vector<vector<pl>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a) {
 long long ans=1;
 while(a>1){
 ans*=a;
 ans%=1000000007;
     a--;
    }
    return ans;
     }

ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

struct UF{
    vl par;
    UF(ll N):par(N){
        rep(i,N)par[i]=i;
    }
    ll root(ll x){
        if(par[x]==x)return x;
        return par[x]=root(par[x]);
    }
    bool same(ll x,ll y){
        return root(x)==root(y);
    }
    void unite(ll x,ll y){
        x=root(x),y=root(y);
        if(x==y)return;
        par[x]=y;
        return;
    }
};

ll dp[1010][1010];

int main() {
ll N;
  cin >>N;
  vector<string> vec(N);
  rep(i,N) {
cin >>vec.at(i);
  }
  
  
  ll a=0;
  ll b=0;
  ll c=0;
  ll d=0;
  rep(i,N) {
    if(vec.at(i)=="AC") {
a++;
    }
    else if(vec.at(i)=="WA") {
b++;
    }
    else if(vec.at(i)=="TLE") {
c++;
    }
    else if(vec.at(i)=="RE") {
d++;
    }
  }
  
  cout<<"AC"<<" "<<'x'<<" "<<a<<endl;
  cout<<"WA"<<" "<<'x'<<" "<<b<<endl;
  cout<<"TLE"<<" "<<'x'<<" "<<c<<endl;
  cout<<"RE"<<" "<<'x'<<" "<<d<<endl;
}
    

Measured memory_bytes: 6404
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

diff_min = float('inf')
for i in range(n):
    diff = abs(a - (t - h[i] * 0.006))
    if diff < diff_min:
        ans = i + 1
        diff_min = diff
print(ans)


Measured memory_bytes: 9232
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
	string str;
	cin>>str;
	stack<char> s;
	for(int i=0;i<str.size();i++){
		if(s.empty()) s.push(str[i]);
		else{
			if(str[i]=='T'){
				char ch=s.top();
				if(ch=='S') s.pop();
				else{
					s.push(str[i]);
				}	
			}else{
				s.push(str[i]);
			}
		}
	}
	cout<<s.size();
	return 0;
}

Measured memory_bytes: 644
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

char s[110][110];
int H, W, f[110][110];

int main() {
    scanf("%d%d", &H, &W);
    for (int i = 1; i <= H; ++i) scanf("%s", s[i] + 1);

    f[1][1] = s[1][1] == '#';
    for (int i = 2; i <= W; ++i)
        f[1][i] = f[1][i - 1] + (s[1][i - 1] == '.' && s[1][i] == '#');
    for (int i = 2; i <= H; ++i)
        f[i][1] = f[i - 1][1] + (s[i - 1][1] == '.' && s[i][1] == '#');
    for (int i = 2; i <= H; ++i)
        for (int j = 2; j <= W; ++j)
            f[i][j] = min(f[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#'),
                          f[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#'));
    printf("%d\n", f[H][W]);
    return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
 
using namespace std;
 
const ll MOD = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    sort(ALL(a));
    ll ok = -1e18 - 5;
    ll ng = 1e18 + 5;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
        // ここでmid未満の数がK未満かどうか調べる
        ll cnt = 0;
        for(int i=0;i<n;i++){
            if(a[i]*a[i]<mid)cnt--;
            int r = n;
            int l = -1;
            if(a[i]<0){ // 右側が一番小さくなる
                while(abs(r-l)>1){
                    int m = (r+l)/2;
                    if(a[m]*a[i]>=mid){
                        l = m;
                    }else r = m;
                }
                cnt += n - r;
            }else{ // 左側が一番小さくなる l を増やす
                while(abs(r-l)>1){
                    int m = (r+l)/2;
                    if(a[m]*a[i]>=mid){
                        r = m;
                    }else l = m;
                }
                cnt += l + 1;
            }
        }
        if( (cnt/2LL)<k)ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

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



int main() {

  int W, H, x, y;
  cin >> W >> H >> x >> y;

  double x_c = W/2.0, y_c = H/2.0;

  double s = W * (H / 2.0);
  int ans = 0;

  if(x==x_c&&y==y_c) ans = 1;

  cout << s <<" " << ans << endl;
  

  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    long long min1, min2;
    cin >> min1;
    min1 *= 4;
    long long a;
    cin >> a;
    a *= 2;
    min1 = min(a,min1);
    cin >> a;
    min1 = min(a,min1);
    cin >> min2;
    min2 = min(min1*2, min2);
    
    long long n;
    cin >> n;
    
    cout << (n / 2) * min2 + (n % 2) * min1 << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mp make_pair

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
    int k,n;
    cin>>k>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll ans = a[n-1] - a[0];
    for(int i=1;i<n;i++){
        ll temp = a[n-1] - a[i];
        temp += k-a[n-1] + a[i-1];
        ans = min(ans, temp);
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define pb push_back
int GCD(int x, int y) {
    return x ? GCD(y % x, x) : y;
}
int LCM(int x,int y){
    return x * y / GCD(x, y);
}
int main(){
    int n;
    cin>>n;
    cout << LCM(2, n) << endl;
    return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Graph;
const int M = 1e9 + 7;
const ll INF = 1e9;
const int MAX_V = 100000 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
  char c;
  cin >> c;
  int ans = int(c) + 1;
  out(char(ans));
}


Measured memory_bytes: 256
#include <cstdlib>
#include <array>
#include <iostream>


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

  std::array<int, 3> abc;
  for (auto&& e : abc) {
    std::cin >> e;
  }
  std::cout << (abc[0] <= abc[2] && abc[2] <= abc[1] ? "Yes" : "No") << std::endl;

  return EXIT_SUCCESS;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int n,m;
  cin >> n >> m;
  int a,b;
  vector<pair<int,int>> ba;

  REP(i,m){
    cin >> a >> b;
    ba.push_back(make_pair(b,a));
  }

  sort(ALL(ba));

  int prev_b = 0;
  int ans=0;
  for(auto &v: ba){
    int bb = v.first;
    int aa = v.second;

    if(aa >= prev_b){
      ans++;
      prev_b = bb;
    }
  }
  cout << ans << endl;
}



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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	int odd = 0;
	REPU(i, 0, n) {
		int a; cin >> a;
		if (a & 1) odd++;
	}
	if (odd & 1) puts("NO");
	else puts("YES");

	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import collections
N = int(input())
a = list(map(int,(input().split())))
b = list(range(N))
wa = [0]*N
sa = [0]*N
for i in range(N):
    wa[i] = a[i]+b[i]
    sa[i] = b[i]-a[i]

cw = collections.Counter(wa)
cs = collections.Counter(sa)
dw = defaultdict(lambda:0)
ds = defaultdict(lambda:0)

for k in cw:
    dw[k] = cw[k] 
for k in cs:
    ds[k] = cs[k] 

mash = []
for i in range(N):
    mash.append(wa[i])
    mash.append(sa[i])
mash = set(mash)

ans = 0
for num in mash:
    ans += dw[num]*ds[num]

print(ans)


Measured memory_bytes: 184720
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
int main() {
    double a, b, h, m;
    while (cin >> a >> b >> h >> m) {
        double da;
        da = 2 * pi * (h / 12.0 + m / 720 - m / 60.0);
        printf("%.18f\n", sqrt(a * a + b * b - 2 * a * b * cos(da)));
    }
    return 0;
}

Measured memory_bytes: 4200
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;
vector<pair<ll,ll>>pll,pll2;
ll cnt[3][111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;

  for(int i=0;i<n;i++){
    ll a;cin>>a;
    cnt[i%2][a]++;
  }
  ll od = 0,ev = 0;
  for(int i=0;i<111111;i++){
    if(cnt[0][i])pll.pb(mp(cnt[0][i],i));
    if(cnt[1][i])pll2.pb(mp(cnt[1][i],i));
  }
  pll.pb(mp(0,0));
  pll2.pb(mp(0,0));
  sort(ALL(pll),greater<pair<ll,ll>>());
  sort(ALL(pll2),greater<pair<ll,ll>>());
  if(pll[0].S == pll2[0].S){
    cout<<n-max(pll[1].F+pll2[0].F,pll[0].F+pll2[1].F)<<endl;
  }else{
    cout<<n-pll[0].F-pll2[0].F<<endl;
  }
    return 0;
}



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

typedef long long ll;
const int N = 2005;
const int M = 1e5 + 50;

int n, pri[M], isnt_pri[M], cnt;
ll a[N], b[N], c[N][N];

inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
inline ll lcm(ll x, ll y) { return (x && y) ? (x / gcd(x, y) * y) : (x | y); }

inline void init()
{
	for (int i = 2; i < M; ++i)
	{
		if (!isnt_pri[i]) pri[++cnt] = i;
		for (int j = 1; j <= cnt && i * pri[j] < M; ++j)
		{
			isnt_pri[i * pri[j]] = true;
			if (i % pri[j] == 0) break;
		}
	}
}

int main()
{
	scanf("%d", &n);
	init();
	if (n == 2)
	{
		printf("4 7\n23 10");
		return 0;
	}
	for (int i = 1; i <= n; ++i) a[i] = pri[i];
	for (int i = 1; i <= n; ++i) b[i] = pri[2 * n - i + 1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if ((i ^ j) & 1) c[i][j] = a[(i + j) / 2] * b[(i - j + n + 1) / 2];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (!((i ^ j) & 1)) c[i][j] = lcm(lcm(c[i - 1][j], c[i][j - 1]), lcm(c[i + 1][j], c[i][j + 1])) + 1;
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) 
	{
		assert(c[i][j] > 0 && c[i][j] <= 1e15);
		printf("%lld%c", c[i][j], j == n ? '\n' : ' ');
	}
	return 0;
}


Measured memory_bytes: 10752
// Candy Piles
// * frank_c1
// * 2017 / 09 / 29
 
 #include <bits/stdc++.h>
using namespace std;

const int maxn = (int)(1e5) + 5;
int a[maxn];

int main() {
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1, greater<int>()); 
	int pt = 0; for (; pt < n && pt < a[pt + 1]; ++pt);
	int ps = pt; for (; ps < n && a[ps + 1] == pt; ++ps); 
	if (!(((a[pt] - pt + 1) & 1) && ((ps - pt + 1) & 1))) printf("First\n"); else printf("Second\n");
	return 0;
}

Measured memory_bytes: 640
import math
ans=0
A=list()
M=list()
for i in range(5):
  a = int(input())
  if(a%10!=0):
    M.append(a%10)
  b=int(math.ceil(a/10)*10)
  A.append(b)
  ans+=b

if not M:
  print(ans)
else:
  ans+=min(M)-10
  print(ans)
  


Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
typedef long long ll;
using namespace std;
int n,a[100005],cnt;
int Abs(int x){
if (x>=0) 
 return x; 
 return -x;
}
int main(){
cin>>n;
for (int i=1;i<=n;i++){
cin>>a[i];
}
for (int i=1;i<=n+1;i++){
cnt+=Abs(a[i]-a[i-1]);
}
for (int i=1;i<=n;i++){
if (a[i]>a[i-1] && a[i]>a[i+1]){
cout<<cnt-2*(a[i]-max(a[i-1],a[i+1]))<<endl;
}
else 
if (a[i]<a[i-1] && a[i]<a[i+1]){
cout<<cnt-2*(min(a[i-1],a[i+1])-a[i])<<endl;
}
else{
cout<<cnt<<endl;
}
}
return 0;
} 


Measured memory_bytes: 1664
N = int(input())
S = list(input())

cnt = set()
for i in range(1, N):
    X = S[:i]
    Y = S[i:]
    x_set = set(X)
    y_set = set(Y)
    c = len(list(x_set & y_set))
    cnt.add(c)
print(max(cnt))

Measured memory_bytes: 3064
import Control.Monad
import Control.Applicative

solver :: Int -> Int -> String
solver a b
  | a < b = show a ++ " " ++ show b
  | otherwise = show b ++ " " ++ show a

main :: IO()
main = do
  (a:b:_) <- map (read :: String -> Int) . words <$> getLine
  unless (a == 0 && b == 0) $
    do putStrLn $ solver a b
       main

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

const ll mod = 1000000007;

ll fact[1000001];

ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while(n > 0) {
    if(n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

void init() {
  fact[0] = 1;
  for(ll i = 1; i < 1000001; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
}

ll inv(ll x) {
  return mod_pow(x, mod - 2, mod);
}

ll comb(ll n, ll k) {
  return ((fact[n] * inv(fact[k])) % mod * inv(fact[n - k])) % mod;
}

void solve() {
  init();

  ll H, W, A, B;
  cin >> H >> W >> A >> B;
  ll ans = 0;
  for(int j = B; j < W; j++) {
    ll N1 = (H - A - 1) + j;
    ll N2 = (A - 1) + (W - j - 1);
    ans += (comb(N1, j) * comb(N2, A - 1)) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

Measured memory_bytes: 8192
/*
    http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0001
    List of Top 3 Hills
*/

#include <stdio.h>
int main(void)
{
    int i, max1, max2, max3;
    int h[10];
    max1 = 0;
    max2 = 0;
    max3 = 0;
    for (i = 0; i < 10; i++)
    {
        scanf("%d",&h[i]);

    /* 1?????? */
        if (h[i] >= max1)
        {
            max3 = max2;
            max2 = max1;
            max1 = h[i];
        }

    /* 2?????? */
        else if (h[i] >= max2 && h[i] < max1)
        {
            max3 = max2;
            max2 = h[i];
        }

    /* 3?????? */
        else if (h[i] >= max3 && h[i] < max2)
        {
            max3 = h[i];
        }
    }

    printf("%d\n%d\n%d\n", max1,max2,max3);

    return 0;
}

Measured memory_bytes: 600
// #pragma GCC optimize(3)
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstring>
#include <iostream>
#include <algorithm>
#define maxn 2010
#define int long long
#define MOD 1000000007
using namespace std;
void write(int x){if(x<0){putchar('-');x=-x;}if(x>9) write(x/10);putchar(x%10+'0');}
int read(){int d=0,w=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')
w=-1;for(;c>='0'&&c<='9';c=getchar())d=(d<<1)+(d<<3)+c-48;return d*w;}
void wln(int x){write(x);putchar('\n');}
void wrs(int x){write(x);putchar(' ');}
int n,k,f[maxn][maxn],jc[maxn*maxn],ni[maxn*maxn],jcn[maxn*maxn];
int calc(int x,int y)
{
	return x>=y?jc[x]*jcn[y]%MOD*jcn[x-y]%MOD:0;
}
signed main()
{
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	n=read();
	k=read();
	if(k==1)
	{
		write(1);
		return 0;
	}
	jc[0]=1;
	for(int i=1;i<=k*n;i++)
		jc[i]=jc[i-1]*i%MOD;
	ni[0]=0;
	ni[1]=1;
	for(int i=2;i<=n*k;i++)
		ni[i]=(-MOD/i*ni[MOD%i]%MOD+MOD)%MOD;
	jcn[0]=1;
	for(int i=1;i<=n*k;i++)
		jcn[i]=jcn[i-1]*ni[i]%MOD;
	f[0][1]=1;
	for(int i=2;i<=n;i++)
		f[0][i]=f[0][i-1]*calc(i*(k-1)-1,k-2)%MOD;
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
			f[i][j]=(f[i-1][j]+f[i][j-1]*calc(i+j*(k-1)-1,k-2)%MOD)%MOD;
	write(f[n][n]*jc[n]%MOD);
	return 0;
}


Measured memory_bytes: 125568
#include <iostream>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
const int maxn = 500005;
struct node
{
	int l, r, sum;
} tree[maxn * 4];
struct ques
{
	int l, r, index;
}ask[maxn];
int a[maxn];
int ans[maxn];
void build(int i, int left, int right)
{
	tree[i].l = left, tree[i].r = right;
	tree[i].sum = 0;
	if (left == right)
		return;
	int mid = left + right >> 1;
	build(i << 1, left, mid);
	build(i << 1 | 1, mid + 1, right);
}
map<int, int> has;
void update(int i, int pos, int w)
{
	if (tree[i].l == pos && tree[i].r == pos)
	{
		tree[i].sum += w;
		return;
	}
	int mid = (tree[i].l + tree[i].r) >> 1;
	if (pos <= mid)
		update(i << 1, pos, w);
	else
		update(i << 1 | 1, pos, w);
	tree[i].sum = tree[i << 1].sum + tree[i << 1 | 1].sum;
}
int query(int i, int left, int right)
{
	if (tree[i].l == left && tree[i].r == right)
	{
		return tree[i].sum;
	}
	int mid = (tree[i].l + tree[i].r) >> 1;
	if (right <= mid)
		return query(i << 1, left, right);
	else if (left > mid)
		return query(i << 1 | 1, left, right);
	else
		return query(i << 1, left, mid) + query(i << 1 | 1, mid + 1, right);
}
bool cmp(ques a, ques b)
{
	return a.r < b.r;
}
int main()
{
	int n;
	scanf("%d", &n);
	int m;
	scanf("%d", &m);
	build(1, 1, n);
	for (int i = 1;i <= n;i++)
		scanf("%d", &a[i]);

	for (int i = 1;i <= m;i++)
	{
		ask[i].index = i;
		scanf("%d%d", &ask[i].l, &ask[i].r);
	}
	sort(ask + 1, ask + 1 + m, cmp);
	int cur = 1;
	for (int i = 1;i <= m;i++)
	{
		for (int j = cur;j <= ask[i].r;j++)
		{
			if (has.find(a[j]) != has.end())
			{
				int p = has[a[j]];
				update(1, p, -1);
			}
			update(1, j, 1);
			has[a[j]] = j;
		}
		cur = ask[i].r + 1;
		ans[ask[i].index] = query(1, ask[i].l, ask[i].r);
	}
	for (int i = 1;i <= m;i++)
		printf("%d\n", ans[i]);
}

Measured memory_bytes: 49252