akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(), M = sc.nextInt();
        int adj[][] = new int[N][N];
        for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) adj[i][j] = 0;
        for (int i = 0; i < M; i++) {
            int a = sc.nextInt() - 1, b = sc.nextInt() - 1;
            adj[a][b] = adj[b][a] = 1;
        }

        System.out.println(dfs(0, 1, N, adj));
    }

    private static int dfs(int v, int state, int N, int adj[][]) {
        if (state == (1 << N) - 1) return 1;
        int ret = 0;
        for (int i = 0; i < N; i++) {
            if ((state >> i & 1) == 0 && adj[v][i] == 1) {
                ret += dfs(i, state | 1 << i, N, adj);
            }
        }
        return ret;
    }
}


Measured memory_bytes: 9808
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int cnt[26];
signed main() {
    string s; cin >> s;
    rep(i,0,s.length()) {
        cnt[ s[i] - 'a' ]++;
    }

    int ans = 1;
    rep(i,0,26) rep(j,i+1,26) ans += cnt[i] * cnt[j];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;
typedef long long ll;

int main(void)
{
    ll X, K, D;

    cin >> X >> K >> D;

    ll ans = 0;
    X = abs(X);
    if (X == 0) {
        if (K % 2 == 0) {
            ans = 0;
        } else {
            ans = D;
        }
    } else {
        ll n = abs(X) / D;
        if (n >= K) {
            ans = X - K * D;
        } else {
            X -= n * D;
            K -= n;
            if (K % 2 == 0) {
                ans = abs(X);
            } else {
                ans = abs(X - D);
            }
        }
    } 
    cout << abs(ans) << endl;

    return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  int n;
  cin>>n;
  int p[n];
  int ans=0;
  REP(i,n){
    cin>>p[i];
  }
  REP(i,n-2){
    int x=p[i];
    int y=p[i+1];
    int z=p[i+2];
    if(y<z&&x<y){
      ans++;
    }
    if(y<x&&z<y){
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	vector<int > a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];

	int cnt = 0;
	for (int i = 0; i < n - 1; ++i)
		if (a[i] < a[i + 1])
			++cnt;

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3104
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
    char s[100000];
    int a[200],i;
    cin>>s;
    int len=strlen(s);
    for(i=0;i<len;i++)
    {
        if(a[s[i]]==0)
        a[s[i]]=1;
    }
    for(i='a';i<='z';i++)
    {
        if(a[i]==0)
        {printf("%c\n",i);break;}
    }
    if(i=='z'+1)
    printf("None\n");
}

Measured memory_bytes: 384
#include <cstdio>
using namespace std;

int main(){

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

float x[4],y[4];

for(int i=0;i<n;i++){
scanf("%f %f %f %f %f %f %f %f",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3]);

float det=(y[1]-y[0])*(x[2]-x[3])-(x[0]-x[1])*(y[3]-y[2]);

if(det==0)
	printf("YES\n");
else
	printf("NO\n");
}

return 0;
}

Measured memory_bytes: 1044
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<deque>
#include<stack>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll maxn = 1e5 + 5;
const double eps = 1e-7;
const double PI = acos(-1);
void std_quick_io () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main () {
    //std_quick_io();
    ll x, y;
    cin >> x >> y;
    if(abs(x - y) >= 2) {
        cout << "Alice";
    } else {
        cout << "Brown";
    }
    return 0;
}

Measured memory_bytes: 256
function Main(input){
  input = input.split("\n");
  tmp = input[0]
  
  var searchResult = tmp.match(/1/gi);
  if(searchResult){
  console.log(searchResult.length);
  }else{
    console.log("0");
  }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import math
A = int(input())
def gcd(A):
    total = 0
    for i in range(1,A+1):
        for j in range(1,A+1):
            B = math.gcd(i,j)
            for k in range(1,A+1):
                total += math.gcd(B,k)
    return total
print(gcd(A))

Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
ll kaizyou(ll k);
 
int main() {
	ll N,M;
  	ll even = 0, odd = 0;
  	ll ans = 0;
	cin >> N >> M;
    if(N <= 1 && M <= 1){
      cout << ans << endl;
      return 0;
    }
    if(2 <= N){
      even = (N * (N - 1))/2; //nC2
      //cout << even << endl;
    }
    if(2 <= M){
      odd = (M * (M - 1)) / 2; //mC2
      //cout << odd << endl;
    }

  	
  	ans = even + odd;
    cout << ans << endl;
}
 
ll kaizyou(ll k){
    ll sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

Measured memory_bytes: 256
#include <cstdio>

int main() {
  int N;
  scanf("%d", &N);

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

  int result = 0;
  int count = 1;
  for (int i = 1; i < N; i++) {
    if (a[i] == a[i-1]) {
      count += 1;
    } else {
      result += count / 2;
      count = 1;
    }
  }
  if (count > 0) {
    result += count / 2;
  }

  printf("%d\n", result);
}


Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	d := 0
	cnt := 1
	var l int
	for i := 1; i <= n; i++ {
		fmt.Scan(&l)
		d = d + l
		if d <= x {
			cnt++
		}
	}
	fmt.Println(cnt)
}


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

int main(){
    int T,n,m,k;
    char c[10000];
    int x;
    scanf("%d%d",&n,&x);
    long long a[100005];
    for(int i = 0;i < n;i ++){
        scanf("%lld",&a[i]);
    }
    long long ans = 0;
    if(a[0] > x){
        ans += a[0] - x;
        a[0] = x;
    }
    for(int i = 1;i < n;i ++){
        if(a[i - 1] + a[i] > x){
            ans += a[i - 1] + a[i] - x;
            a[i] -= a[i - 1] + a[i] - x;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1024
use proconio::input;

fn main() {
    input! {
        n: usize,
        v: [usize; n]
    }

    let (set,max,count1) = {
        let mut max = 1;
        let mut set = vec![false; 1_000_001];
        let mut count1 = 0;
        for &x in &v {
            set[x] = true;
            if max < x {
                max = x;
            }
            if x == 1 {
                count1 += 1;
            }
        }
        (set,max,count1)
    };

    let ll = set.iter().filter(|&&x| x).count();

    let flag = if ll >= count1+1 && count1 >= 1 || (ll < n-count1) {
        true
    } else {
        let mut flag = false;

        let mut tbl = vec![true; max+1];
        tbl[0] = false;
        tbl[1] = false;
        for i in 2..=max {
            if flag {
                break;
            }
            if tbl[i] {
                let mut j = i+i;
                let mut ff = false;
                if set[i] {
                    ff = true;
                }
                while j <= max {
                    tbl[j] = false;
                    if !ff && set[j] {
                        ff = true;
                    } else if ff && set[j] {
                        flag = true;
                        break;
                    }
                    j += i;
                }
            }
        }

        flag
    };


    if !flag || max == 1 {
        println!("pairwise coprime")
    } else {
        let mut jj = v[0];
        for &x in &v[1..] {
            jj = num::integer::gcd(jj,x);
        }
        if jj == 1 {
            println!("setwise coprime")
        } else {
            println!("not coprime")
        }
    }
}

Measured memory_bytes: 17768
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]

count = 0
for i in range(n-1):
    for k in range(i+1, n):
        dis = 0
        for j in range(d):
            dis += (x[i][j] - x[k][j])**2
        dis = math.sqrt(dis)
        if dis == int(dis):
            count += 1
print(count)

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

typedef complex<double> Point;
double cross(const Point& a, const Point& b){
    return (conj(a) * b).imag();
}
int main() {
    vector<Point> poly;
    double x_, y_;
    char gomi;
    cin.tie(0); ios::sync_with_stdio(false);
    while(cin >> x_ >> gomi >>  y_) poly.push_back(Point(x_, y_));
//    rep(i, 5) {
//      cin >> x_ >> gomi >>  y_;
//      poly.push_back(Point(x_, y_));}
    double sum = 0.0;
    REP(i, 1, poly.size() - 1)
      sum += cross(poly[i] - poly[0], poly[i + 1] - poly[0]) / 2.0;
    cout << fixed << setprecision(10) << abs(sum) << endl;
    return 0;
}

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

using namespace std;
const int MOD = 1000000007,MAX = 510000;
long int pow107 = (int)pow(10, 9) + 7,llimit = LONG_MAX,fac[MAX], finv[MAX], inv[MAX];
int ilimit = INT_MAX;

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long int COM(long int n,long int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2
//コンビネーションCOMinit(),COM(n,m)

int main(){
    int n;
    long int s[int(pow(10,5))];
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }
    sort(s,s+n);
    
    for(int i = n-1; i >= 0; --i){
        if(s[i] == s[i-1]){
            for(int j = i - 2; j >= 0; --j){
                if(s[j] == s[j-1]){
                    cout << s[i] * s[j] << endl;
                    return 0;
                }
            }
            break;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 1024
a = [0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())
print(a[k])


Measured memory_bytes: 2940
s=input()+" "
count=[]
left,right=0,0
for i in range(len(s)):
    if s[i]==">" and s[i+1]=="<":
        count.append(s[left:i+1])
        left=i+1
count.append(s[left:])

ans=0
for i in range(len(count)):
    left,right=0,0
    for j in count[i]:
        if j==">":right +=1
        elif j=="<":left +=1
    big_one=max(left,right)
    small_one=min(left,right)
    for k in range(big_one+1):
        ans +=k
    for l in range(small_one):
        ans +=l

print(ans)

Measured memory_bytes: 13892
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  ll n,k;
  cin >> n >> k;
  map<int,ll> x; 
  rep(i,n) {
    int a,b;
    cin >> a >> b;
    x[a] += b;
  }
  vector<pair<int,ll>> y;
  rep(i,100001) {
    if (x[i] > 0) y.push_back(make_pair(i,x[i]));
  }
  sort(y.begin(), y.end());
  ll cnt = 0;
  for (auto v: y) {
    if (cnt + v.second >= k) {cout << v.first << endl; break;}
    cnt += v.second;
  }
  return 0;
}

Measured memory_bytes: 10500
h,w=map(int,input().split());f=lambda x:max(x)-min(x);g=lambda h,w:min([min(f([j if j else -1e9for j in[i*w,((h-i)//2)*w,((h-i)-(h-i)//2)*w]]),f([j if j else -1e9for j in[i*w,(h-i)*(w//2),(h-i)*(w-w//2)]]))for i in range(1,h)]);print(min(g(h,w),g(w,h)))

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

int main()
{
  map<string, int>youbi = {
    {"SUN", 7},
    {"MON", 6},
    {"TUE", 5},
    {"WED", 4},
    {"THU", 3},
    {"FRI", 2},
    {"SAT", 1}
  };
  string N;
  cin >> N;
  cout << youbi[N] << endl;
  return 0;
}

Measured memory_bytes: 256
#template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#template
li = inputlist()
li.sort()
A,B,C = li[0],li[1],li[2]
if C % 2 == 0:
    print(0)
if C % 2 == 1:
    print(A*B)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,y;
    cin>>n>>x>>y;
    map<int,int>freq;
    for (int i = 1;i<=n;i++){
        for (int j = i+1;j<=n;j++){
            int shortest_dist = min(min(j-i,abs(x-i)+1+abs(j-y)),abs(y-i)+1+abs(j-x));
            freq[shortest_dist]++;
        }
    }
    for (int i = 1;i<n;i++){
        cout<<freq[i]<<endl;
    }
    return 0;
}

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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if(c>a&&c>b) cout << (a*b/2) << endl;
	if(b>a&&b>c) cout << (a*c/2) << endl;
	if(a>b&&a>c) cout << (c*b/2) << endl;
	return 0;
}


Measured memory_bytes: 256
/***********************************
*******AUTHOR SHASHI KANT **********         
****GMAIL Shshiksnt140895@gmail.com*
************************************                                  
***********************************/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
/*class graph
{
	map<int,list<int>>adj;
	public :
	       void addedge(int a, int b)
	       {
	           adj[a].push_back(b);
	           adj[b].push_back(a);
	       }
 
}*/
int max_val(int n, vector<ll>in)
{
	vector<ll>dp(n+1, 0);
	int op1,op2;
	for(int i=2; i<=n; i++)
	{
        op1 = abs(in[i] - in[i-1]) + dp[i-1];
        op2 = (i==2)?INT_MAX: abs(in[i] - in[i-2]) + dp[i-2];
        dp[i] = min(op1,op2);
	}
 
	return dp[n];
}
int main(){
      
      int n;
      cin>>n;
     vector<ll>in(n+1);
      for(int i=1; i<=n; i++)
      	cin>>in[i];
    cout<<  max_val(n, in) <<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int main(void){
  int j,N,ans,i,min;
  int P[200000]={};
    
  if(scanf("%d",&N)>1){
    exit(0);
  }
  for(i=0;i<N;i++){
  if(scanf("%d",&P[i])>1){
     exit(0);
   }
   }
  ans=0;
  min=P[0];
  //printf("%d %d\n",P[0],P[1]);
  for(j=0;j<N;j++){
    if(P[j]<(min+1)){
	 ans++;
	 min=P[j];
       }
  }
  printf("%d",ans);
  return 0;
}




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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    const int MOD=1e9+7;
    ll mod(ll x){
        return (x%MOD + MOD)%MOD;
    }
    ll mul(ll a , ll b){
        return mod(mod(a)*mod(b));
    }

    void solve(){
        int n,k;
        cin>>n>>k;
        vector<ll>pos;
        vector<ll>neg;
        for(int i=0;i<n;i++){
            int x;
            cin>>x;
            if(x>0)
                pos.push_back(x);
            else
                neg.push_back(x);
        }
        ll ans=1;
        if((int)pos.size()){
            if(k%2){
                sort(pos.begin(),pos.end());
                ans=mul(ans,pos.back());
                pos.pop_back();
                --k;
            }
            vector<ll>ok;
            sort(pos.begin(),pos.end(),greater<>());
            sort(neg.begin(),neg.end());
            for(int i=0;i+1<(int)pos.size();i+=2)
                ok.push_back(pos[i]*pos[i+1]);
            for(int i=0;i+1<(int)neg.size();i+=2)
                ok.push_back(neg[i]*neg[i+1]);
            if((int)pos.size()%2 && (int)neg.size()%2)
                ok.push_back(pos.back()*neg.back());
            sort(ok.begin(),ok.end(),greater<>());
            for(int i=0;i<(k/2);i++)
                ans=mul(ans,ok[i]);
            cout<<ans;
        }
        else{
            sort(neg.begin(),neg.end());
            if(k%2)
                reverse(neg.begin(),neg.end());
            for(int i=0;i<k;i++)
                ans=mul(ans,neg[i]);
            cout<<ans;
        }
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


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

typedef long long ll;
const long double pi = acos(-1);
ll X1,Y1,X2,Y2,n,a[200020],d[200020],len;
map<ll,ll> x,y;

int main(){
    ios::sync_with_stdio(false);
    cin >> X1 >> Y1 >> X2 >> Y2 >> n;
    if(X2 < X1){
        swap(X1,X2);
        swap(Y1,Y2);
    }
    for(int i = 1,u,v;i <= n;++i){
        cin >> u >> v;
        x[u] = v;
        y[v] = u;
    }
    long double qc = 5 * pi, ans = 0;
    if(X1 == X2){
        int p = min(Y1,Y2), q = max(Y1,Y2);
        ans = 100.0 * (q - p);
        if(x.count(X1) && x[X1] > p && x[X1] < q) ans += 2*qc - 20;
        cout << fixed << setprecision(12) << ans << endl;
        return 0;
    }
    if(Y1 == Y2){
        int p = min(X1,X2), q = max(X1,X2);
        ans = 100.0 * (q - p);
        if(y.count(Y1) && y[Y1] > p && y[Y1] < q) ans += 2*qc - 20;
        cout << fixed << setprecision(12) << ans << endl;
        return 0;
    }

    ll cnt = 0, mny = min(Y1,Y2), mxy = max(Y1,Y2);
    ans = 100.0 * (X2 - X1 + mxy - mny);
    for(auto p: x){
        if(p.first < X1 || p.first > X2) continue;
        if(p.second >= mny && p.second <= mxy) a[++cnt] = (Y1 < Y2 ? 1 : -1) * p.second;
    }

    for(int i = 1;i <= cnt;++i){
        int pos = lower_bound(d+1,d+1+len,a[i]) - d;
        if(pos == len + 1) len++;
        d[pos] = a[i];
    }

    ans -= 20*len - pi * (5 * len);
    if(len > min(X2 - X1,mxy - mny)) ans += qc;

    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}


Measured memory_bytes: 28416
import Control.Monad
import Data.Char
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn -- 2 <= n <= 10^5
  h <- V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  -- hi <= 10^4
  let dp = V.create $ do
        dp <- VM.new n
        VM.write dp 0 0
        VM.write dp 1 (abs (h V.! 0 - h V.! 1))
        forM_ [2..n-1] $ \i -> do
          c2 <- VM.read dp (i - 2)
          c1 <- VM.read dp (i - 1)
          let c2' = c2 + abs (h V.! i - h V.! (i - 2))
              c1' = c1 + abs (h V.! i - h V.! (i - 1))
          VM.write dp i (min c1' c2')
        return dp
  print (V.last dp :: Int)


Measured memory_bytes: 3580
n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i).sort
if k>a[-1]
  puts "IMPOSSIBLE"
  exit
end
b=a[0]
while true
  f=false
  a.each do |aa|
    if aa%b!=0
      b=aa%b
      a.shift(b)
      f=true
      break
    end
  end
  if !f
    if k%b==0
      puts "POSSIBLE"
    else
      puts "IMPOSSIBLE"
    end
    exit
  end
end


Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



Int n,m,_,x,y,q;
string s,sb;
bool ok;

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

  cin>>n>>x>>y; Int a[n]; rep(i,n)cin>>a[i];
  Int ans=0;
  rep(i,n-1){
    ans+=min((a[i+1]-a[i])*x,y);
  }
  END
}

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

int const N = 200000;
pair<int, int> v[N + 1];
int an[N], n;

int main(){
	scanf("%d", &n);
	f(i, 0, n){
		int x, y;
		scanf("%d%d", &x, &y);
		v[x] = make_pair(y, i);
	}
	int mx = 0, need = 0;
	for (int i = n; i > 0; --i){
		int j = i;
		do{
			if (v[j].first > mx){
				need += v[j].first - mx;
				mx = v[j].first;
			}
			--need;
			--j;
		}while (need);
		f(k, j + 1, i + 1)an[v[k].second] = i - j;
		i = j + 1;
	}
	f(i, 0, n)printf("%d\n", an[i]);
}

Measured memory_bytes: 6156
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x)
{
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=6e5+10,mod=1e9+7;
inline void Add(int &x,int y) { x+=y; if(x>=mod) x-=mod; }
inline void Dec(int &x,int y) { x-=y; if(x<0) x+=mod; }
int Pow(int x,int y) {
	int res=1;
	while(y) {
		if(y&1) res=res*(ll)x%mod;
		x=x*(ll)x%mod,y>>=1;
	}
	return res;
}
int fac[N],inv[N];
inline void predo(int n) {
	fac[0]=1; for(int i=1;i<=n;++i) fac[i]=fac[i-1]*(ll)i%mod;
	inv[n]=Pow(fac[n],mod-2); for(int i=n;i>=1;--i) inv[i-1]=inv[i]*(ll)i%mod;
}
int C(int n,int m) { return fac[n]*(ll)inv[m]%mod*inv[n-m]%mod; }
int n,m,ans,L,R;
int get(int s) { return C(s+n,n); }
int calc(int s,int a,int b) {
	int ans=0;
	for(int j=0;j<=n-m&&s-a*m-j*(b+1)>=0;++j) {
		int tmp=get(s-a*m-j*(b+1))*(ll)C(n-m,j)%mod;
		if(j&1) Dec(ans,tmp);
		else Add(ans,tmp);
	}
	return ans*(ll)C(n,m)%mod;
}
int sol(int s) {
	int ans=get(s);
	for(int i=1;i*m<=s;++i) {
		Dec(ans,calc(s,i,i-1));
		Add(ans,calc(s,i+1,i-1));
	}
//	cout<<s<<' '<<ans<<endl;
	return ans;
}
int main() {
	predo(6e5);
	rd(n),rd(m),rd(L),rd(R);
	int ans=sol(R)-sol(L-1);
	printf("%d",(ans%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int d;
	cin>>d;
	if(d==25)
	cout<<"Christmas";
	if(d==24)
	cout<<"Christmas Eve";
	if(d==23)
	cout<<"Christmas Eve Eve";
	if(d==22)
	cout<<"Christmas Eve Eve Eve";
    return 0;	
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    static Scanner sc = new Scanner(System.in);
    
    private static int[] inputArray(){
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }
        return array;
    }
    
    public static void main(String[] args){
        int[] s = inputArray();
        int[] t = inputArray();
        int count = 0;
        for(int i = 0; i < t.length; i++){
            for(int j = 0; j < s.length; j++){
                if(t[i] == s[j]){
                    count++;
                    break;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 40160
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    map<int, int> m; //! # of occurance -> # of colours
    m[0] = 3;

    LL ans = 1;
    rep(i, N) {
        int c = m[A[i]];
        if (c) {
            ans = (ans * c) % MOD;
            --m[A[i]];
            ++m[A[i]+1];
        } else {
            ans = 0;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    int n, temp, ans = 0;
    cin >> n;
    vector<int> cnt(1e5 + 1, 0);
    rep(i, n) {
        cin >> temp;
        cnt.at(temp)++;
    }
    rep(i, 1e5 - 1) {
        temp = cnt.at(i) + cnt.at(i + 1) + cnt.at(i + 2);
        ans = max(ans, temp);
    }
    cout << ans << endl;
}

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

int main(){
    int n, m, sum=0;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        sum+=a[i];
    }

    sort(a.begin(), a.end(), greater<int>());
    if(a[m-1]<float(sum)/float(4*m)) puts("No");
    else puts("Yes");
}


Measured memory_bytes: 3612
//失敗するからこそそこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/pavan/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

const int MAX_N = 1e5 + 100;
const long long inf = 1e12;
int main() {
	FIO

	int n;cin >> n;
	long long a[n];
	for(int i = 0; i < n;i++)cin >> a[i];
	long long ans = inf;
	for(int x = 0; x <= 100000; x++){
		long long cans = 0;
		for(int i = 0; i < n;i++){
			cans += ((x - a[i]) * (x - a[i]));
		}
		ans = min(ans, cans);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 25

typedef struct{

  int parent;
  int left;
  int right;

}Node;

int n;
Node in[N];

void init();
void PreOrder(Node *, int);
void InOrder(Node *, int);
void PostOrder(Node *, int);


int main(){

  int i, id;

  init();

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&id);
    scanf("%d %d", &in[id].left, &in[id].right);

    if(in[id].left == -1 && in[id].right == -1) continue;

    in[in[id].left].parent = id;
    in[in[id].right].parent = id;

  }

  for(i = 0; i < n; i++){
    if(in[i].parent == -1) break;
  }

    printf("Preorder\n");
    PreOrder(in, i);
    printf("\n");

    printf("Inorder\n");
    InOrder(in, i);
    printf("\n");

    printf("Postorder\n");
    PostOrder(in, i);
    printf("\n");

  return 0;

}


void init(){
  int i;

  for(i = 0; i < N; i++){
    in[i].parent = -1;
    in[i].left = -1;
    in[i].right = -1;
  }

}


void PreOrder(Node *preA, int num){

  printf(" %d",num);
  
  if(preA[num].left != -1){
    PreOrder(preA, preA[num].left);
  }

  if(preA[num].right != -1){
    PreOrder(preA, preA[num].right);
  }

}


void InOrder(Node *inA, int num){
 
 if(inA[num].left != -1){
    InOrder(inA, inA[num].left);
  }

  printf(" %d",num);
  
  if(inA[num].right != -1){
    InOrder(inA, inA[num].right);
  }

}


void PostOrder(Node *postA, int num){
  
  if(postA[num].left != -1){
    PostOrder(postA ,postA[num].left);
  }

  if(postA[num].right != -1){
    PostOrder(postA, postA[num].right);
  }

  printf(" %d",num);

}

Measured memory_bytes: 0
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

ll solve(int u, int pab, int m, ll p, int n, vector <ll> &V, vector <ll> &D) {
	ll x=V[pab-u+1]*m;
	x=x%p;
	x*=D[n-pab];
	x=x%p;
	//cout<<"funkcija "<<u<<" "<<pab<<" "<<m<<" "<<x<<endl;
	return x;
	}

void solve(set <int> &A, map<int,int> &M, map <int,int> &P, int l, int r, int d, ll p, ll &ats, vector <ll> &V, vector <ll> &D, int n) {
	auto it=A.lower_bound(l);
	if (it!=A.begin()) {it--;}
	int u=*it;
	set <int> B;
	while (it!=A.end() && u<=r) {
		B.insert(u);
		//cout<<"DABAR "<<u<<endl;
		it++;
		u=*it;
		}
	int a=*B.begin();
	int b=*B.rbegin();
	int f=P[b];
	int g=M[b];
	//cout<<a<<" "<<b<<endl;
	for (int c:B) {
		A.erase(c);
		ats-=solve(c,P[c],M[c],p,n,V,D);
		//cout<<"Jau atemiau "<<ats<<endl;
		}
	if (a<l) {
		P[a]=l-1;
		A.insert(a);
		ats+=solve(a,P[a],M[a],p,n,V,D);
		}
	//cout<<l<<" "<<r<<" "<<b<<" "<<f<<endl;
	if (f>r) {
		A.insert(r+1);
		P[r+1]=f;
		M[r+1]=g;
		//cout<<"DABAR "<<r+1<<endl;
		ats+=solve(r+1,P[r+1],M[r+1],p,n,V,D);
		}
	A.insert(l);
	M[l]=d;
	P[l]=r;
	ats+=solve(l,r,d,p,n,V,D);
	ats=ats%p;
	ats+=p;
	ats=ats%p;
	return;
	}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin>>n>>q;
    ll p=998244353;
    vector <ll> V(n+1,1);
    vector <ll> D(n+1,1);
    V[1]=1;
    D[1]=10;
    for (int i=2;i<n+1;i++) {
		V[i]=(V[i-1]*10+1)%p;
		D[i]=(D[i-1]*10)%p;
		}
	set <int>A;
	A.insert(1);
	map <int,int> M;
	map <int,int> P;
	P[1]=n;
	M[1]=1;
	ll ats=V[n];
	for (int i=0;i<q;i++) {
		int l,r,d;
		cin>>l>>r>>d;
		solve(A,M,P,l,r,d,p,ats,V,D,n);
		cout<<ats<<endl;
		}
    return 0;
}


Measured memory_bytes: 34660
#include <bits/stdc++.h>
#include <vector>
using namespace std;
long long n, d, hasil;
int main(){
	while(cin >> d){
		hasil = 0;
		for(int i = d; i <= 600-d; i += d){
			hasil += d * pow(i, 2);
		}
		cout << hasil << endl;
	}
	return 0;
}

Measured memory_bytes: 2988
#include <bits/stdc++.h>
#define rep(i, n, s) for (int i = s; i < n; i++)
#define graph map<int, vector<int>>
#define field vector<vector<int>>
using namespace std;
int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    rep(i, k, 0)
    {
        if (a >= b)
        {
            b *= 2;
        }
        else if (b >= c)
        {
            c *= 2;
        }
    }
    if (a < b and b < c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
import collections
K = int(input())

if K < 10:
    print(K)
    exit()

q = collections.deque()
for i in range(1, 10):
    q.append(i)
i = 9
while True:
    x = q.popleft()
    lsk = x % 10
    shifted = x * 10
    if lsk != 0:
        q.append(shifted + lsk - 1)
        i += 1
        if i == K:
            print(shifted + lsk - 1)
            break
    q.append(shifted + lsk)
    i += 1
    if i == K:
        print(shifted + lsk)
        break
    if lsk != 9:
        q.append(shifted + lsk + 1)
        i += 1
        if i == K:
            print(shifted + lsk + 1)
            break


Measured memory_bytes: 12164
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

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

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

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(3);
  REP(i, 3) cin >> A[i];

  vector<string> s(N);
  REP(i, N) cin >> s[i];

  vector<char> ans;

  auto f = [&](int p, int q){
    char c = 'A'+p;
    ans.emplace_back(c);
    A[p]++; A[q]--;
  };

  REP(i, N){
    int p = s[i][0]-'A', q = s[i][1]-'A';

    if(!A[p] && !A[q]){
      No;
      return 0;
    }
    if(!A[p]) f(p, q);
    else if(!A[q] || i == N-1) f(q, p);
    else{
      int np = s[i+1][0]-'A', nq = s[i+1][1]-'A';
      if(p == np || p == nq) f(p, q);
      else f(q, p);
    }
  }

  Yes;
  REP(i, N){
    cout << ans[i] << "\n";
  }

  return 0;
}

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

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

  int ans = 0;
  int a = 0, b = 1000;
  REP(i,n) {
    a = l+i;
    ans += a;
    b = min(b, abs(a));
  }
  
  if (l+n <= 0) cout << ans+b << endl;
  else cout << ans-b << endl;
}

Measured memory_bytes: 256
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int ll;
ll powmod(ll a, ll b) {
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

const int nax = 3005;
ll dp[nax][nax];
int main() {
    int n = nxt();
    VI a(n);
    generate(all(a), nxt);
    // dp[0][n-1]
    for (int L = n - 1; L >= 0; L--) {
        for (int R = L; R < n; R++) {
            if (L == R) dp[L][R] = a[L];
            dp[L][R] = max(a[L] - dp[L + 1][R], a[R] - dp[L][R - 1]);
        }
    }
    printf("%lld\n", dp[0][n - 1]);
    return 0;
}


Measured memory_bytes: 70016
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=1e6+10;
int a[N];
bool cmp(int x,int y){
	return x>y;
}
int main(){
	int i,j,k,n;
	cin>>n>>k;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1,cmp);
	int sum=0;
	for(i=1;i<=k;i++){
		sum+=a[i];
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
long long p=998244353;
long long rui(long long a,long long b){
    if(b==0)return 1;
    if(b==1)return a;
    if(b==2)return a*a%p;
    if(b%2==0)return rui(rui(a,b/2),2);
    if(b%2==1)return rui(rui(a,(b-1)/2),2)*a%p;
}
int main(){
    long long kai[300001];
    kai[0]=1;
    for(int i=1;i<300001;i++){
        kai[i]=i*kai[i-1]%p;
    }
    long long n,a,b,k;
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    long long kam[300002];
    kam[0]=1;
    for(int i=1;i<300002;i++){
        kam[i]=kam[i-1]*(n-i+1)%p;
    }
    long long koi[300001];
    for(int i=0;i<300001;i++){
        koi[i]=rui(kai[i],p-2);
    }
    int x=0;
    long long y=0;
    while(x==0&&y<=n){
        if( (k-(y*a))%b==0){
            x++;
        }
        else {y++;}
    }
    if(y==n+1){
        printf("0\n");
        return 0;
    }
    long long aa[300001];
    long long bb[300001];
    for(int i=0;i<300001;i++)aa[i]=-1;
    int w=1;
    for(int i=1;i<300001;i++){
        if(a%i==0&&b%i==0)w=i;
    }
    x=0;
    while(a*y<=k&&y<=n){
        if(0<=y&&y<=n&&0<=(k-a*y)/b&&(k-a*y)/b<=n){
            aa[x]=y;
            bb[x]=(k-a*y)/b;
            x++;
        }
        y+=b/w;
    }
    x=0;
    long long ans=0;
    while(aa[x]!=-1){
        ans+=koi[aa[x]]*kam[aa[x]]%p*koi[bb[x]]%p*kam[bb[x]]%p;
        if(ans>p)ans-=p;
        x++;
    }
    printf("%lld\n",ans%p);
}

Measured memory_bytes: 11904
#include<stdio.h>
#include<string.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
int  n,m,e[8][8],visit[8],sum = 0;

void roop(int point,int num){

	if(num == n){
		sum ++;
		return;
	}

	FOR(i,0,n){
		if(e[point][i] == 1 && visit[i] == 0){
			visit[i] = 1;
			roop(i,num+1);
			visit[i] = 0;
		}
	}
}

int main(){
	int ai,bi;
	scanf("%d %d",&n,&m);

	memset(e,0,sizeof(e));
	memset(visit,0,sizeof(visit));

	FOR(i,0,m){
		scanf("%d %d",&ai,&bi);
		e[ai-1][bi-1] = 1; e[bi-1][ai-1] = 1;
	}

	visit[0] = 1;
	roop(0,1);

	printf("%d\n",sum);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define rrep(i, n) rREP(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) std::sort(all(x))
#define REV(x) std::reverse(all(x))
#define UNIQUE(x) x.erase(std::unique(all(x)), x.end());
#define MAX(x) *std::max_element(all(x))
#define MIN(x) *std::min_element(all(x))
#define LOWitr(x, n) std::lower_bound(all(x), n)
#define UPRitr(x, n) std::upper_bound(all(x), n)
#define cii(x) int x; std::cin >> x
#define cill(x) signed long long int x; std::cin >> x
#define cis(x) std::string x; std::cin >> x
#define co(x) std::cout << x << "\n"
#define pb push_back
#define mp std::make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) if(DEBUG) std::cout<<#x<<" : "<<(x)<<"\n"
template<class T>using V = std::vector<T>;
template<class T>using VV = std::vector<std::vector<T>>;
template<class T>using Q = std::queue<T>;
template<class T>using PQ = std::priority_queue<T>;
template<class T,class U>using P = std::pair<T, U>;
template<class T,class U>using M = std::map<T, U>;
template<class T,class U>using UM = std::unordered_map<T, U>;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T>inline void vcin(T &v){for(auto&& i : v) std::cin >> i;}
template<class T>inline void dumpv(const T& v, std::ostream& os = std::cout){
    if(DEBUG){
        os<<"{";
        std::for_each(all(v),[&os](typename T::value_type p){os<<p<<',';});
        os<<"}\n";
    }
}
using std::cin;
using std::cout;
using std::string;
using std::min;
using std::next_permutation;
using LL = signed long long int;
using VL = V<LL>;
using VVL = V<VL>;
const int INF = INT_MAX, MOD = 1e9 + 7;
const LL LLINF = LLONG_MAX;
const double PI = M_PI;

void Main(){
    cill(n);
    cill(w);
    V<LL> dp(100100, INF);
    dp[0]=0;
    rep(i, n){
        LL a, b;
        V<LL> ndp(100100, INF);
        cin >> a >> b;
        rep(j, 100100){
            if(j >= b) chmin(ndp[j], dp[j-b]+a);
            chmin(ndp[j], dp[j]);
        }
        dp = ndp;
    }
    LL ans=0;
    rep(i, 100100){
        if (dp[i] <= w){
            ans = i;
        }
    }
    co(ans);
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    
    double l = sqrt(fabs(x2-x1)*fabs(x2-x1) + fabs(y2-y1)*fabs(y2-y1));

    printf("%lf\n", l);
    
    return 0;
}



Measured memory_bytes: 3212
n=int(input())
plist=[int(i) for i in input().split()]
result=0
for i in range(n-2):
	if (plist[i]<plist[i+1] and plist[i+1]<plist[i+2]) or (plist[i]>plist[i+1] and plist[i+1]>plist[i+2]):
		result+=1
print(result)

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

signed main(void)
{
	int n, m;
	long long sum;
	cin >> n >> m;
	vector<int> a(n);
	vector<pair<int, int>> b(m);
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i].second >> b[i].first;
	sort(a.begin(), a.end());
	sort(b.rbegin(), b.rend());
	rep(i, n)
	{
		if (a[i] < b[0].first && b[0].second > 0)
		{
			a[i] = b[0].first;
			b[0].second--;
			if(b[0].second == 0)
				b.erase(b.begin());
		}
	}	
	sum = 0;
	rep(i, n) sum += a[i];
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1408
N ,M = map(int,input().split())
A = list(map(int,input().split()))

a = 0
count = 0
for i in range(N):
  a = a + A[i]

for i in range(N):
	if A[i] >= a / 4/M :
		count +=1
		

if count >= M:
  print("Yes")

else:
  print("No")

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG    //空コンテナ操作禁止　Clang環境では#define _LIBCPP_DEBUG 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  int A, B;
  cin >> A >> B;
  
  cout << max( A-2*B, 0 );

  return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;

class UnionFind {
public:
    vector <LL> par;
    vector <LL> siz;

    UnionFind(LL sz_): par(sz_), siz(sz_, 1LL) {
        for (LL i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(LL sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (LL i = 0; i < sz_; ++i) par[i] = i;
    }

    LL root(LL x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool unite(LL x, LL y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(LL x, LL y) {
        return root(x) == root(y);
    }

    LL size(LL x) {
        return siz[root(x)];
    }
};

int main(){
	LL N, M;
	cin >> N >> M;
	UnionFind uf(N);
	LL num=N*(N-1)/2;
	vector<P> p(M);
	rep(i,M){
		int A, B;
		cin >> A >> B;
		A--; B--;
		p[i]={A,B};
	}
	reverse(p.begin(),p.end());
	vector<LL> ans(M);
	rep(i,M){
		ans[i]=num;
		int A=p[i].first, B=p[i].second;
		if(!uf.same(A,B)){
			num-=uf.size(A)*uf.size(B);
			uf.unite(A,B);
		}
	}
	reverse(ans.begin(),ans.end());
	rep(i,M) cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 4480
int main(void){
  int n, tmp;
  scanf("%d", &n);
  long int Max = -1 *  pow(10,12);
  long int Min = pow(10,12);
  
  for(int i=0; i<n; i++){
    scanf("%d", &tmp);
    if(Max < tmp - Min) Max = tmp - Min;
    if(Min > tmp) Min = tmp;
  }

  printf("%ld\n", Max);
  
  return 0;
}


Measured memory_bytes: 2100
#include<stdio.h>
 
int so(int p) 
{
	if (p <= 1)return 0;
	for (int i = 2; i * i <= p; i++)
		if (p % i == 0)return 0;
	return 1;
}
 
int main(void)
{
	int x;
	scanf("%d", &x);
 
	int p = x;
	
	while (!so(p))p++;
 
	printf("%d", p);
	
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    s=input()
    if s[0]==s[1]==s[2] or s[3]==s[1]==s[2]:
        print("Yes")
    else:
        print("No")

main()

Measured memory_bytes: 2940
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt(scanner)
	b := getNextInt(scanner)
	fmt.Fprintln(writer, a*b)
}


Measured memory_bytes: 1800