akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<deque>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
using namespace std;

int ans[200];
int seat[17];

int check(int n)
{
  int size = (n%5==1?5:2);
  int cnt = 0;
  rep(i,17)
    {
      if(seat[i] == 0)cnt++;
      else            cnt = 0;
      if(cnt >= size)
	return i-size+1;
    }
  return -1;
}

int main()
{
  rep(i,200)ans[i] = 0;
  int phase = 0;
  int group = 0;

  deque<int> que;
  rep(i,17)seat[i] = 0;
  while(phase < 600)
    {
      /*
      cout << phase << " --------- " << endl;
      if(!que.empty())
      cout << "top = " <<que.front() << endl;
      */
      if(phase%5 == 0 && group < 101)
	{
	  que.push_back(group++);
	}
      rep(i,17)if(seat[i] > 0)seat[i]--;
      int pos;

      while(!que.empty() && ((pos = check(que.front())) != -1) )
	{
	  int i = que.front();
	  int tm = 17 * (i % 2) + 3 * (i % 3) + 19;
	  //cout << "top = " << i << " tm = " << tm << " pos = " << pos<< endl; 

	  REP(j,pos,pos+(i%5==1?5:2))
	    {
	      assert(j < 17 && seat[j] == 0);
	      seat[j] = tm;
	    }
	  que.pop_front();
	}

      for(deque<int>::iterator it = que.begin(); it != que.end();it++)
	{
	  if(*it <= 100)
	  ans[*it]++;
	}
      /*
      rep(i,17)cout << seat[i] << " ";
      cout << endl << endl;
      */    
      phase++;
    }
  int n;
  while(cin >> n)cout << ans[n] << endl;
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n, k; cin >> n >> k;
    if (k < n) {
        n -= ((n - k) / k) * k;
        cout << min(abs(n - k), abs(k - (n - k))) << "\n";
    }
    else {
        cout << min(n, abs(k - n)) << "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;
int cnt[100005];
int main(void){
	int N,M;
	cin >> N >> M;
	for(int i=0;i<M;i++){
		int a,b;
		cin >> a >> b;
		a--;b--;
		cnt[a]++;
		cnt[b]++;
	}
	bool yes = 1;
	for(int i=0;i<N;i++){
		if(cnt[i]%2)yes = 0;
	}
	if(yes)cout << "YES"<<endl;
	else cout <<"NO"<<endl;
}

Measured memory_bytes: 640
# 2軸は使い切る

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

answer = 10**18
for x,y,z in [[A,B,C], [B,C,A], [C,A,B]]:
  if x % 2 == 0:
    d = 0
  else:
    d = y*z
  answer = min(answer, d)

print(answer)

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

int main(){
  ll X;
  cin>>X;
  ll happy;
  happy=X/500*1000;
  X%=500;
  happy+=X/5*5;
  cout<<happy<<endl;
}


Measured memory_bytes: 256
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]
ans = float("inf")

for i in range(2**d):
    sum_temp = 0
    count_temp = 0
    remain = set(range(1, d+1))
    for j in range(d):
        if i >> j & 1:
            sum_temp += 100 * (j + 1) * pc[j][0] + pc[j][1]
            count_temp += pc[j][0]
            remain -= {j+1}
    if sum_temp < g:
        use = max(remain)
        n = min(pc[use - 1][0], -(-(g - sum_temp) // (use * 100)))
        count_temp += n
        sum_temp += n * 100 * use
    if sum_temp >= g:
        ans = min(ans, count_temp)

print(ans)

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

using lint = long long;
const int MAXN = 6005;
const int INF = 1e5;

int N;
int A[MAXN];

int ans = 0;
int base = 0;
int nxt[MAXN];
int dp[MAXN][MAXN];

inline int Cost(int a, int b, int c) {
  return A[a] == A[b] && A[b] == A[c];
}

inline void Transition(int i, int j, int cur) {
  if (cur > 3 * N) return;
  if (cur == 3 * N) {
    ans = max(ans, dp[i][j] + Cost(i, j, cur));
    return;
  }
  dp[cur + 0][cur + 1] = max(dp[cur + 0][cur + 1], dp[i][j] + Cost(i, j, cur + 2));
  dp[cur + 0][cur + 2] = max(dp[cur + 0][cur + 2], dp[i][j] + Cost(i, j, cur + 1));
  dp[cur + 1][cur + 2] = max(dp[cur + 1][cur + 2], dp[i][j] + Cost(i, j, cur + 0));

  dp[i][cur + 0] = max(dp[i][cur + 0], dp[i][j] + Cost(j, cur + 1, cur + 2));
  dp[i][cur + 1] = max(dp[i][cur + 1], dp[i][j] + Cost(j, cur + 0, cur + 2));
  dp[i][cur + 2] = max(dp[i][cur + 2], dp[i][j] + Cost(j, cur + 0, cur + 1));

  dp[j][cur + 0] = max(dp[j][cur + 0], dp[i][j] + Cost(i, cur + 1, cur + 2));
  dp[j][cur + 1] = max(dp[j][cur + 1], dp[i][j] + Cost(i, cur + 0, cur + 2));
  dp[j][cur + 2] = max(dp[j][cur + 2], dp[i][j] + Cost(i, cur + 0, cur + 1));
}

int main() {

  cin >> N;
  for (int i = 1; i <= 3 * N; i++)
    cin >> A[i];


  while (true) {
    bool change = false;
    for (int i = 3; i + 2 <= 3 * N; i += 3) {
      if (A[i] == A[i + 1] && A[i + 1] == A[i + 2]) {
        base += 1;
        for (int j = i + 3; j <= 3 * N; j++) {
          A[j - 3] = A[j];
        }
        N -= 1;
        change = true;
        break;
      }
    }
    if (!change) {
      break;
    }
  }

  vector<int> last(3 * N + 1, 3 * N + 1);
  for (int i = 3 * N; i > 0; i--) {
    nxt[i] = last[A[i]];
    last[A[i]] = i;
  }
  for (int i = 0; i < MAXN; i++) {
    for (int j = 0; j < MAXN; j++) {
      dp[i][j] = -INF;
    }
  }
  dp[1][2] = 0;
  for (int i = 1; i <= 3 * N; i++) {
    for (int j = i + 1; j <= 3 * N; j++) {
      Transition(i, j, (j + 3) / 3 * 3);
      // Find next occurrence of A[i]
      if (j / 3 * 3 <nxt[i] / 3 * 3)
        Transition(i, j, nxt[i] / 3 * 3);

      // Find next occurrence of A[j]
      if (j / 3 * 3 < nxt[j] / 3 * 3)
        Transition(i, j, nxt[j] / 3 * 3);

    }
  }

  cout << ans + base << "\n";
  return 0;
}


Measured memory_bytes: 144512
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/


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

    string s;
    cin>>s;
    int n = s.size();
    if (s[n-1]=='1'||s[0]=='0') {cout<<-1; return 0;}
    for (int i = 0; i<n-1; i++) if (s[i]!=s[n-2-i]) {cout<<-1; return 0;}

    vector<int> guys;
    for (int i = 1; i<=n/2; i++) if (s[i-1]=='1') guys.push_back(i);

    int k = guys.size();
    for (int i = 1; i<k; i++) cout<<i<<' '<<i+1<<'\n';
    int cur = k+1;
    for (int i = 2; i<=k; i++)
    {
        int add = guys[i-1] - guys[i-2] - 1;
        for (int j = 0; j<add; j++)
        {
            cout<<i<<' '<<cur<<'\n';
            cur++;
        }
    }
    if (cur<=n)
    {
        cout<<k<<' '<<cur<<'\n';
        int old = cur;
        cur++;
        while (cur<=n)
        {
            cout<<old<<' '<<cur<<'\n';
            cur++;
        }
    }


}




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

int main() {
  vector<char> a(3);
  for(int i = 0; i < 3; i++){
    cin >> a.at(i);
    if(a.at(i) == '1') a.at(i) = '9';
    else if(a.at(i) == '9') a.at(i) = '1';
  }
  for(char x : a) cout << x;
  cout << endl;
}


Measured memory_bytes: 256
from itertools import permutations

def main():
    N, C = map(int, input().split())
    D = list(list(map(int, input().split())) for _ in range(C))
    c = list(list(map(int, input().split())) for _ in range(N))
    cost = [[0] * (C + 5) for _ in range(3)]

    for k in range(C):
        for i in range(N):
            for j in range(N):
                cost[(i + j) % 3][k + 1] += D[c[i][j]-1][k]

    ans = float('inf')

    for a, b, c in permutations(range(1,C+1), 3):
        tmp = cost[0][a] + cost[1][b] + cost[2][c]
        ans = min(tmp, ans)

    print(ans)


    







if __name__ == "__main__":
    main()

Measured memory_bytes: 43228
N=int(input())
A=[]
B=[]
for i in range(N):
  A.append(input())
M=int(input())
for i in range(M):
  B.append(input())
ans=0  
for i in set(A):
  s=0
  s+=A.count(i)-B.count(i)
  ans=max(ans,s)
print(ans)  

Measured memory_bytes: 3060
import java.util.*;
import java.math.BigInteger;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		BigInteger A = sc.nextBigInteger();
		BigInteger B = sc.nextBigInteger();
		if(A.compareTo(B) > 0){
		    System.out.println("GREATER");
		}else if(A.compareTo(B) < 0){
		    System.out.println("LESS");
		}else{
		    System.out.println("EQUAL");
		}
    }
}

Measured memory_bytes: 36024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define lint long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
struct Node{
    int no;
    vector<int> par;
    void input(int i,int a){
        no=i;par.push_back(a);
    }
};
signed main(){
  lint n,k;cin>>n>>k;
  vector<Node> a(n+1);
  rep1(i,n){
      int buf;cin>>buf;
      a[i].input(i,i);
      a[i].input(i,buf);
  }
  lint cur=1;
  lint ind=1;
  while(cur<2*k){
      cur*=2;
      rep1(i,n){
          a[i].par.push_back(a[a[i].par[ind]].par[ind]);
      }
      ++ind;
  }
  cur=1;
  ind=1;
  while(k>0){
      int buf=k%2;
      if(buf==1){
          ind=a[ind].par[cur];
      }
      k/=2;
      ++cur;
  }
  cout<<ind<<"\n";
  return 0;
}

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

using namespace std;
typedef long long ll;

int h, w, cnt = 0, color = 1;

int a[1010][1010];
struct node {
    int i, j;
} res[1000010];

void change(int i, int j) {
    if (i - 1 >= 1 && !a[i - 1][j]) {
        a[i - 1][j] = color;
        res[cnt].i = i - 1;
        res[cnt++].j = j;
    }
    if (i + 1 <= h && !a[i + 1][j]) {
        a[i + 1][j] = color;
        res[cnt].i = i + 1;
        res[cnt++].j = j;
    }
    if (j - 1 >= 1 && !a[i][j - 1]) {
        a[i][j - 1] = color;
        res[cnt].i = i;
        res[cnt++].j = j - 1;
    }
    if (j + 1 <= w && !a[i][j + 1]) {
        a[i][j + 1] = color;
        res[cnt].i = i;
        res[cnt++].j = j + 1;
    }
}

int main() {
    int pos = 0;
    char temp;
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> temp;
            if (temp == '.')
                a[i][j] = 0;
            else {
                a[i][j] = -1;
                res[cnt].i = i;
                res[cnt++].j = j;
            }
        }
    }
    while (cnt < h * w) {
        int num = cnt;
        for (; pos < num; pos++) {
            change(res[pos].i, res[pos].j);
        }
        color++;
    }

    cout << color - 1 << endl;


    return 0;
}

Measured memory_bytes: 12032
#include <stdio.h>
#include <math.h>
int main(void){
    // Your code here!
    int x[10][10];
    int n,d;
    int count=0;
    scanf("%d %d",&n,&d);
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            scanf("%d",&x[i][j]);//printf("%d\n",x[i][j]);
        }
        
        for(int k=i-1;k>=0;k--){
            double p=0;
            for(int j=0;j<d;j++){
                p+=powf((x[k][j]-x[i][j]),2);
                //printf("%f\n",powf((x[k][j]-x[i][j]),2));
            }
            p=sqrt(p);
            if(floor(p)==p)count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
  int a,b;
  cin>>a>>b;
  if(a+b==15)cout<<'+'<<endl;
  else if(a*b==15)cout<<'*'<<endl;
  else cout<<'x'<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&!(1<<i);}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mul(int a, int b) {return ((a%MOD)*(b%MOD))%MOD;}
int add(int a, int b) {return (a+b)%MOD;}
int sub(int a, int b) {return (((a-b)%MOD)+MOD)%MOD;}
int __div(int a, int b) {return mul(a, powmod(b, MOD-2, MOD));} //if MOD is prime;
const int inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

int32_t main(void)
{
	IOS;
	int n, W; 
	cin>>n>>W;
	vi v(n); vi w(n);
	for(int i = 0; i < n; i++)
		cin>>w[i]>>v[i];
	int dp[n][W+1];
	memset(dp, 0, sizeof(dp));
	dp[0][w[0]]=v[0];
	for(int i = 1; i < n; i++) {
		for(int j = 0; j < W+1; j++) {
			int mx1 = -1, mx2 = -1;
			if(j-w[i] >= 0)
				mx1=v[i]+dp[i-1][j-w[i]];
			mx2=dp[i-1][j];
			dp[i][j]=max(mx1, mx2);
		}
	}
	int mx=-1;
	for(int i = 0; i < W+1; i++)
		mx=max(dp[n-1][i], mx);
	cout<<mx<<endl;
	time();	
	return 0;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll a, b, c, d; cin >>a>>b>>c>>d;
    bool flag = true;
    while(a>0 && c>0){
        c -= b;
        if(c <= 0) break;
        a -= d;
        if(a <= 0) break;
    }
    if(a <= 0) flag = false;
    if(flag) Yes();
    else No();
}

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

Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li h, w, m;
    cin >> h >> w >> m;
    vector<li> xs(m), ys(m);
    vector<li> row_scores(h), col_scores(w);
    for (int i = 0; i < m; ++i) {
        cin >> xs[i] >> ys[i];
        xs[i]--; ys[i]--;
        row_scores[xs[i]]++;
        col_scores[ys[i]]++;
    }
    map<li, li> row_comp, col_comp;
    const li row_max = *max_element(row_scores.begin(), row_scores.end());
    const li col_max = *max_element(col_scores.begin(), col_scores.end());
    for (int i = 0; i < h; ++i) {
        if (row_scores[i] == row_max) {
            li idx = row_comp.size();
            row_comp[i] = idx;
        }
    }
    for (int i = 0; i < w; ++i) {
        if (col_scores[i] == col_max) {
            li idx = col_comp.size();
            col_comp[i] = idx;
        }
    }
    vector<pair<li, li>> comp_points;
    for (int i = 0; i < m; ++i) {
        if (row_comp.find(xs[i]) == row_comp.end()) {
            continue;
        }
        if (col_comp.find(ys[i]) == col_comp.end()) {
            continue;
        }
        comp_points.emplace_back(row_comp[xs[i]], col_comp[ys[i]]);
    }
    sort(comp_points.begin(), comp_points.end());

    bool ok = false;
    for (li i = 0; i < row_comp.size(); ++i) {
        auto lb = lower_bound(comp_points.begin(), comp_points.end(), make_pair(i, -1LL));
        auto ub = lower_bound(comp_points.begin(), comp_points.end(), make_pair(i, w + 1));
        ok |= (ub - lb) < col_comp.size();
    }
    cout << (ok ? (row_max + col_max) : (row_max + col_max - 1)) << endl;

    return 0;
}

Measured memory_bytes: 58436
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
a = inpl()
f = inpl()
a.sort()
f.sort(reverse=True)
l = -1
r = 10**18

def sol(x):
    cnt = 0
    for i in range(n):
        cnt += max(0, a[i] - x//f[i])
    # print(cnt)
    if cnt <= k:
        return True
    else:
        return False

while l + 1 < r:
    mid = (l+r)//2
    if sol(mid):
        r = mid
    else:
        l = mid
    # print(mid)
print(r)





Measured memory_bytes: 109172
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

double round(double r) {
    return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
}

using namespace std;




int main() {
	
string s;
cin>>s;
int a=0,b=0,c=0,d=0;;
for(int i=0;i<s.size();i++){
	if(s[i]=='N')a++;
	else if(s[i]=='S')b++;
	else if(s[i]=='W')c++;
	else d++;
	if(a&&b&&c&&d){cout<<"Yes"<<endl;return 0;}
}
	if(!a&&!b&&c&&d)cout<<"Yes"<<endl;
	else if(!c&&!d&&a&&b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
    return 0;
}

	
	


	

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

bool sortbysec(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 
int main()
{
    ll n,w,sum=0;
    cin>>n>>w;
    vector< pair<ll,ll> > v;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        v.push_back({x,y});
        sum+=y;
    }
    sort(v.begin(),v.end(),sortbysec);
    ll dp[n][sum+1];
    dp[0][0]=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<=sum;j++)
        {
            if(j==0)
             dp[i][j]=0;
             else
              dp[i][j]=1e12;
        }
    }
    for(ll i=0;i<n;i++)
    {
        ll val=v[i].second;
        for(ll j=0;j<=sum;j++)
        {
            if(i==0)
            {
                if(j==val)
                dp[i][j]=v[i].first;
            }
            else
            {
                if(j>=val)
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-val]+v[i].first);
                else
                 dp[i][j]=dp[i-1][j];
            }
        }
    }
    ll maxn;
    for(int j=0;j<=sum;j++)
    {
        //cout<<dp[n-1][j]<<" ";
        if(dp[n-1][j]<=w)
         maxn=j;
    }
    cout<<maxn<<"\n";
    return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;
}


Measured memory_bytes: 256
local read = io.read
local insert = table.insert

local N = read("n")
local L = {}
local L_have_same_num = {}
for i = 1, N do
	local num = read("n")
	if L_have_same_num[num] == nil then
		insert(L, num)
		L_have_same_num[num] = 1
	else
		L_have_same_num[num] = L_have_same_num[num] + 1
	end
end

table.sort(L)

local count = 0
for i = 1, #L - 2 do
	for j = i + 1, #L - 1 do
		for k = j + 1, #L do
			if L[k] >= L[j] + L[i] then
				break
			end
			count = count + L_have_same_num[L[i]] * L_have_same_num[L[j]] * L_have_same_num[L[k]]
		end
	end
end

print(count)


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

typedef long long LL;

int main() {
    LL N, P;
    cin >> N >> P;
    LL P_aux = P;
    vector<pair<LL, int>> divisors;

    int rep = 0;

    if (N == 1)
    {
        cout << P;
        return 0;
    }

    while (!(P_aux % 2)) {
        rep++;
        P_aux /= 2;
    }

    divisors.push_back(make_pair(2, rep));

    for (LL i = 3; i <= sqrt(P); i += 2) {
        rep = 0;
        if (!(P_aux % i)) {
            while (!(P_aux % i)) {
                rep++;
                P_aux /= i;
            }
            divisors.push_back(make_pair(i, rep));
        }
    }
    LL out = 1;
    for (LL i = 0; i < divisors.size(); i++)
    {
        if (divisors[i].second >= N) {
            LL coeff = (LL)floor((double)divisors[i].second / (double)N);
            for (int j = 1; j <= coeff; j++)
                out *= divisors[i].first;
        }
    }

    cout << out;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int n; cin >> n;
    VI p(n); REP(i,n) cin >> p[i];
    int count = 0;
    REP(i,n) if(p[i] != i+1) count++;
    YN(count<=2);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main(){
	string s;cin>>s;long long n=s.size();
	long long ans=n*(n-1)/2+1;
	long long cnt[26]={0};
	for(int i=0;i<n;i++){
		cnt[s[i]-'a']++;
	}
	for(int i=0;i<26;i++){
		if(cnt[i]==0)continue;
		ans-=(cnt[i]*(cnt[i]-1))/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
from bisect import bisect_left, bisect_right, bisect
n = int(input())
alis = sorted(list(map(int, input().split())))
blis = list(map(int, input().split()))
clis = sorted(list(map(int, input().split())))
ans = 0
for b in blis:
    up = bisect_left(alis, b)
    down = n - bisect(clis, b)
    ans += up*down
print(ans)

Measured memory_bytes: 23476
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 1050;
const double INF = 1e50;

double dist(double x1, double y1, double x2, double y2) {
  return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}

int n;
double x[MAXN], y[MAXN];
double r[MAXN];
double d[MAXN][MAXN];
priority_queue <pair<double, int>> q;
bool used[MAXN];
double dst[MAXN];

int main() { 

  scanf("%lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1]);
  scanf("%d", &n);
  n = n + 2;

  for (int i = 2; i < n; i++) {
    scanf("%lf %lf %lf", &x[i], &y[i], &r[i]);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) {
        continue;
      }
      d[i][j] = max(0.0, dist(x[i], y[i], x[j], y[j]) - r[i] - r[j]);
    }
  }

  for (int i = 0; i < n; i++) {
    dst[i] = INF;
  }
  dst[0] = 0.0;
  q.push({0.0, 0});

  while (!q.empty()) {
    int cur = q.top().second;
    q.pop();
    if (used[cur]) {
      continue;
    }
    used[cur] = true;
    for (int i = 0; i < n; i++) {
      dst[i] = min(dst[i], dst[cur] + d[cur][i]);
      q.push({-dst[i], i});
    }
  }

  printf("%.12lf\n", dst[1]);

  return 0;
}


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

int main(){
    int n;
    int cnt=0;
    int i_1, i_2;
    cin >> n;
    vector<int> p(n+1);
    for(int i=1; i<=n; i++){
        cin >> p[i];
    }
    for(int i=1; i<=n; i++){
        if(i == p[i]){
            continue;
        }

        cnt++;
        if(cnt > 2){
            cout << "NO" << endl;
            return 0;
        }
        
        if(cnt == 1){
            i_1 = i;
        }else{ // cnt == 2
            i_2 = i;
            if((p[i_1] == i_2) && (p[i_2] == i_1)){
                cout << "YES" << endl;
                return 0;
            }else{
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    if(cnt == 0){
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF=1e9;
const int maxn=1e5+10;
const int maxm=2e5+10;
const ll mod=1e9+7;
ll to[maxm<<1],nex[maxm<<1],beg[maxn],w[maxm<<1];
ll vis[maxn],q[maxn*100];
ll dis1[maxn],dis2[maxn];
ll sum[maxn],sum1[maxn],sum2[maxn];
ll mindis;
int e;
struct node{
	ll x,y,z;
}edge[maxm<<1];
inline ll read(){
    ll x=0,flag=1;
    char ch=getchar();
    while(!isdigit(ch) && ch!='-')ch=getchar();
    if(ch=='-')flag=-1,ch=getchar();
    while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return x*flag;
}
inline void add(int x,int y,int z){
    to[++e]=y;
    nex[e]=beg[x];
    beg[x]=e;
    w[e]=z;
}
inline void Spfa(ll st,ll dis[]){
    ll f=0,l=1,i;
    memset(vis,0,sizeof(vis));
    dis[st]=0;q[1]=st;vis[st]=1;
    while(f<l){
        f++;
        ll x=q[f];
        for(i=beg[x];i;i=nex[i]){
            if(dis[to[i]]>dis[x]+w[i]){
                dis[to[i]]=dis[x]+w[i];
                if(!vis[to[i]]){
                    vis[to[i]]=1;
                    q[++l]=to[i];
                }
            }
        }
        vis[x]=0;
    }
}
inline ll Dp(ll x){
	if(sum[x])return sum[x];
	for(int i=beg[x];i;i=nex[i])
		if(dis1[x]+dis2[to[i]]+w[i]==mindis)
			sum[x]=(sum[x]+Dp(to[i]))%mod;
	return sum[x];
}
int main(){
    ll i,j,m,n,s,t;
    n=read();m=read();s=read();t=read();
    ll cnt=0;
    for(i=1;i<=m;i++){
        ll x,y,z;
        x=read();y=read();z=read();
        edge[++cnt]=((node){x,y,z});edge[++cnt]=((node){y,x,z});
        add(x,y,z);add(y,x,z);
    }
    memset(dis1,63,sizeof(dis1));
    memset(dis2,63,sizeof(dis2));
    Spfa(s,dis1);Spfa(t,dis2);
    mindis=dis1[t];
    sum[t]=1;Dp(s);
    swap(dis1,dis2);swap(sum,sum2);
    sum[s]=1;Dp(t);
    swap(dis1,dis2);swap(sum,sum1);
    ll ans=0;
    for(i=1;i<=n;i++)
		if(dis1[i]==dis2[i] && dis1[i]+dis2[i]==mindis)
			(ans+=1ll*sum1[i]%mod*sum1[i]%mod*sum2[i]%mod*sum2[i]%mod)%=mod;
	for(i=1;i<=cnt;i++){
		int x=edge[i].x,y=edge[i].y,z=edge[i].z;
		if(dis1[x]+dis2[y]+z==mindis && abs(dis1[x]-dis2[y])<z)
			(ans+=1ll*sum1[x]%mod*sum1[x]%mod*sum2[y]%mod*sum2[y]%mod)%=mod;
	}
	printf("%lld\n",((1ll*sum1[t]%mod*sum1[t]%mod-ans)%mod+mod)%mod);
    return 0;
}

Measured memory_bytes: 39808
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;

const int maxn = 100009;
LL l[maxn], c[maxn];
int n, m, s, t; LL ans = 1e15;

inline int read(){
	char ch = getchar(); int x = 0;
	while (ch < '0' || '9' < ch) ch = getchar();
	while ('0' <= ch && ch <= '9') { x = x*10+ch-'0'; ch = getchar(); }
	return x;
}

int main(){
	n = read(); m = read(); s = read();
	while (--n){
		t = read();
		if (s < t){
			c[1] += t-s; c[s+1] -= t-s;
			c[s+1] += t+1; c[t+1] -= t+1;
			l[s+1] += -1; l[t+1] -= -1;
			c[t+1] += t-s;
		}
		else{
			c[1] += t+1; c[t+1] -= t+1;
			l[1] += -1; l[t+1] -= -1;
			c[t+1] += m-s+t; c[s+1] -= m-s+t;
			c[s+1] += m+t+1;
			l[s+1] += -1;
		}
		s = t;
	}
	for (int i=1; i<=m; i++){
		c[i] += c[i-1];
		l[i] += l[i-1];
		ans = min(ans, c[i]+l[i]*i);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1664
#include <cstdio>  
#include <iostream>  
#include <cstring>  
#include <string>  
#include <cmath>  
#include <algorithm>  
#include <cstdlib>  
#include <utility>  
#include <map>  
#include <stack>  
#include <set>  
#include <vector>  
#include <queue>  
#include <deque>  
#include <sstream>  
#include <bitset>
#include<bits/stdc++.h>      
using namespace std;
string s,t;
int main()
{
    int n,f,l,m;
	cin>>n;
	f=0;
	l=n;
    cout<<0<<endl;
    cin>>s;
    if(s=="Vacant")return 0;
    while(t!="Vacant"){
        m=(f+l)/2;
        cout<<m<<endl;
        cin>>t;
        if(m%2^s==t)f=m;
        else l=m;
    }
    return 0;
}

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

int main() {
    double t1, t2;

    while (cin >> t1 >> t2) {
        if (t1 < 35.5 && t2 < 71.0)
            puts("AAA");
        else if (t1 < 37.5 && t2 < 77.0)
            puts("AA");
        else if (t1 < 40.0 && t2 < 83.0)
            puts("A");
        else if (t1 < 43.0 && t2 < 89.0)
            puts("B");
        else if (t1 < 50.0 && t2 < 105.0)
            puts("C");
        else if (t1 < 55.0 && t2 < 116.0)
            puts("D");
        else if (t1 < 70.0 && t2 < 148.0)
            puts("E");
        else
            puts("NA");
    }
}


Measured memory_bytes: 3012
n = int(input())
h = [ int(x) for x in input().split() ]
 
cnt = 0
while True:
    if max(h) == 0:
        break
    idx = 0
    while idx < n:
        if h[idx] == 0:
            idx += 1
        else:
            cnt += 1
            while idx < n and h[idx] != 0:
                h[idx] -= 1
                idx += 1
print(cnt)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
  int num[5];
  scanf("%d %d %d %d %d",&num[0],&num[1],&num[2],&num[3],&num[4]);
  sort(num,num+5,greater<int>());
  printf("%d %d %d %d %d\n",num[0],num[1],num[2],num[3],num[4]);
}
  

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define mod 1000000007
// #define pie 3.141592653589793238
#define mod1 998244353
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=(ans%mod)*(x%mod)%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
li nCrModp(int n, int r)
{
    // Optimization for the cases when r is large
    if (r > n - r)
        r = n - r;

    // The array C is going to store last row of
    // pascal triangle at the end. And last entry
    // of last row is nCr
    li C[r + 1];
    memset(C, 0, sizeof(C));

    C[0] = 1; // Top row of Pascal Triangle

    // One by constructs remaining rows of Pascal
    // Triangle from top to bottom
    for (int i = 1; i <= n; i++) {

        // Fill entries of current row using previous
        // row values
        for (int j = min(i, r); j > 0; j--)

            // nCj = (n-1)Cj + (n-1)C(j-1);
            C[j] = (C[j] + C[j - 1]) % mod;
    }
    return C[r];
}
int main()
{
fast_io
li n,k,i,j;
cin>>n>>k;
li ans[k+1];
ans[k]=1;
li a=0;
for(i=k;i>=1;i--)
{
  li x=k/i;
  li p=0;
  x=mpow(x,n);
  for(j=2*i;j<=k;j+=i)
  {
    p=(p%mod+ans[j]%mod)%mod;
  }
  ans[i]=(x-p+mod)%mod;
  a=(a%mod+((ans[i]%mod)*(i%mod))%mod)%mod;
}
cout<<a;
  return 0;
}


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

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

ll df(ll h){
    ll ans;
    if(h==1)ans=1;
    else ans=2*df(h/2)+1;
    return ans;
}

int main(){
	ll h;
    cin>>h;
    ll ans=df(h);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define sp  set< pair<ll,ll> >
#define vp vector< pair<ll,ll> >
#define spp set< pair<pair<ll,ll>,ll> >
#define maxe 100000000
#define MOD 1000000007
#define ll long long int
#define pb push_back
#define mp  make_pair
#define sz(a) sizeof(a)
#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int,int> PI;
typedef vector<PI> VPI;
typedef map<int,int> MPII;
typedef set<int> SETI;
#define ps(y,x) fixed<<setprecision(y)<<x;
#define F first
#define S second
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define REP(i,n) FOR(i,0,(int)n-1)
#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define FOREACH_FN(v, fn) for_each(ALL(v), myobject);

#define SORT(a) sort(a.begin(),a.end())
#define RSORT(a) sort(a.rbegin(),a.rend())
#define REV(a) reverse(a.begin(),a.end())
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MINIMUM(a)  *min_element(a.begin(), a.end())
#define MAXIMUM(a)  *max_element(a.begin(), a.end())
#define deb(x) cout << #x << "=" << x << endl;
#define ld long double
#define bigint int64_t
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define hurry ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define W(t)  while(t--)
#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define forr(i,n) for(ll (i) = (n)-1 ; (i)>=0 ; --(i))
#define forab(i,a,b,c) for(ll (i) = a ; (i) <= (b) ; (i)+=(c))

const int N =2e+5;


int main()
{
    hurry;


#ifndef ONLINE_JUDGE
 freopen("inputs.txt", "r",stdin);
 freopen("output.txt","w",stdout);
#endif

ll i,h[N],n; 
  cin>>n;
    
    forn(i,n)
    cin>>h[i];

    int dp[n+1];

    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);

    for(i=2;i<n;i++)
    {
      dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
      //cout<<dp[i]<<' ';

    }
    //for(i=0;i<=n;i++)
      //cout<<dp[i]<<' ';
    cout<<dp[n-1];


 
}

Measured memory_bytes: 4776
#include<bits/stdc++.h>
using namespace std;
 
using lint=long long;
template<int mod> class ModInt
{
 private:
    lint val;
 public:
    lint value(){ return val; }
    ModInt(lint x=0){ val=x%mod; }
    ModInt pow(int n){
        ModInt res(1),x(val);
        while(n>0){ if(n&1) res*=x; x*=x; n>>=1; }
        return res;
    }
    ModInt inv(){ return pow(mod-2); }
    ModInt& operator+=(ModInt rhs){ val+=rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator-=(ModInt rhs){ val+=mod-rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator*=(ModInt rhs){ val=val*rhs.val%mod; return *this; }
    ModInt& operator/=(ModInt rhs){ *this*=rhs.inv(); return *this; }
    ModInt operator+(ModInt rhs){ return ModInt(val)+=rhs; }
    ModInt operator-(ModInt rhs){ return ModInt(val)-=rhs; }
    ModInt operator*(ModInt rhs){ return ModInt(val)*=rhs; }
    ModInt operator/(ModInt rhs){ return ModInt(val)/=rhs; }
};
using mint=ModInt<1000000007>;

template<typename T> class BiCoef
{
 public:
    vector<T> fact,ifact,inv;
    BiCoef(int N):fact(N+1),ifact(N+1),inv(N+1){
        fact[0]=ifact[N]=inv[0]=1;
        for(int i=1;i<=N;i++) fact[i]=fact[i-1]*i;
        ifact[N]/=fact[N];
        for(int i=N-1;i>=0;i--) ifact[i]=ifact[i+1]*(i+1);
        for(int i=1;i<=N;i++) inv[i]=ifact[i]*fact[i-1];
    }
    T comb(int n,int k){
        if(n<0 or k<0 or n<k) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

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

   int N,K; cin>>N>>K;
   BiCoef<mint> bc(N);

   mint ans=0;
   for(int i=0;i<=min(N-1,K);i++){
      ans+=bc.comb(N,i)*bc.comb(N-1,N-i-1);
   }
   cout<<ans.value()<<endl;
   return 0;
}


Measured memory_bytes: 4992
// A - Fifty-Fifty
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	map<int, int> m;
	for (int i = 0; i < s.size(); i++) m[s[i]]++;
	cout << ((m.size() == 2 && m.begin()->second == 2) ? "Yes" : "No") << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int a[300000];
int main() {
	int n;
	long long ans = 0;
	cin >> n;
	int k = n * 3 - 2;
	for (int i = 0; i < n * 3; i++) {
		cin >> a[i];
	}
	sort(a, a + n * 3);
	for (int j = 0; j < n; j++) {
		ans += a[k];
		k -= 2;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

const int  N = 1e4+7;
const int inf = INT_MAX;
const int MOD = 1e9+7;

void solve()
{
   int x;
   cin >> x;
   char ans;
   if(x>=400 && x<=599) ans = '8';
   else if(x>=600 && x<=799) ans = '7';
   else if(x>=800 && x<=999)  ans = '6';
   else if(x>=1000 && x<=1199)   ans = '5';
   else if(x>=1200 && x<=1399)   ans = '4';
   else if(x>=1400 && x<=1599)   ans = '3';
   else if(x>=1600 && x<=1799)   ans = '2';
   else if(x>=1800 && x<=1999)   ans = '1';
   cout << ans;
}

int32_t main()
{
   IOS;
   //freopen("input.txt", "rt", stdin);
   //freopen("output.txt", "wt", stdout);
   int t=1;
   //cin >> t;
   for(int i=1;i<=t;i++)
   {
      //cout<<"Case #"<<i<<": ";
      solve();
   }
   return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int gcd(int a,int b) {
	if(b==0) return a;
	return gcd(b,a%b);
}
int main() {
	int n;
	cin >>n ;
	vector<int>a(n);
	rep(i,n) cin >> a[i];
	sort(a.begin(),a.end());
	int minv = a[0];
	rep(i,n) {
		if(i==n-1) continue;
		minv = min(minv,gcd(a[i],a[i+1]));
	}
	cout << minv << endl;
}

Measured memory_bytes: 768
N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append(a)
    
num_list = zip(A[:], range(N))
num_list = sorted(num_list, reverse=True)

max_n = num_list[0][0]
max_i = num_list[0][1]
sec_n = num_list[1][0]

for i in range(N):
    if i == max_i:
        print(sec_n)
    else:
        print(max_n)

Measured memory_bytes: 80600
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

int main(){

	string s;
	cin>>s;

	int n=s.size()-1,N=(1<<n);
	long long sum=0;

	for(int bit=0;bit<N;bit++){
		long long x=0;
		for(int i=0;i<n;i++){
			x=x*10+s[i]-'0';
			if(bit&(1<<i)) sum+=x,x=0;
		}
		x=x*10+s[n]-'0';
		sum+=x;

	}
	cout<<sum<<endl;

}

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

vector<int> v[100100];
int node[100100];
int in[100100];

main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		v[a].push_back(b);
		in[b]++;
	}
	queue<int> q;
	for(int i=1;i<=n;i++)
	{
		if(in[i]==0)
		{
			q.push(i);
		}
	}
	while(!q.empty())
	{
		int nw=q.front();
		q.pop();
		for(int i=0;i<v[nw].size();i++)
		{
			int go=v[nw][i];
			in[go]--;
			if(in[go]==0)
			{
				q.push(go);
			}
			node[go]=max(node[go],node[nw]+1);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans=max(ans,node[i]);
	}
	printf("%d",ans);
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    //Sunny, Cloudy, Rainy
    if(s=="Sunny"){
       cout<<"Cloudy";

    }
    else if(s=="Cloudy"){
        cout<<"Rainy";

    }
    else if(s=="Rainy"){
        cout<<"Sunny";

    }else{cout<<"enter a vaild weather";}
return 0;}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);		
		// shift By		
		int shiftBy = sc.nextInt();
		
		char[] input = sc.next().toCharArray();
		
		StringBuilder output = new StringBuilder();
		for (char c : input)
		{
			int findInt = c + shiftBy;
			if ( findInt > 90 )  findInt -= 26;
			char tchar = (char) (findInt);
			output.append(tchar);
		}
		
		sc.close();
		System.out.println(output.toString());
	}
}

Measured memory_bytes: 23124