akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int N, K;
  std::cin >> N >> K;
  
  long long result = 0;
  
  std::vector<int> H(N, 0);
  for (int i=0; i<N; ++i) {
    std::cin >> H.at(i);
    result += H.at(i);
  }
  
  std::sort(H.begin(), H.end());
  
  while (!H.empty() && K-- > 0) {
    result -= H.back();
    H.pop_back();
  }
  
  std::cout << result << "\n";
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <limits>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
const int inf = 1000000000; //10^9
const  double PI = 3.1415926535897932;

int main(){
    double R,ans;
    cin >> R ;
    ans = 2*R*PI;

    cout << ans << endl;
}

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

using namespace std;

int main()
{
    //freopen("IN.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    while(1){
        c-=b;
        if(c<=0){
            cout<<"Yes";
            break;
        }
        a-=d;
        if(a<=0){
            cout<<"No";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int K; cin>>K;
	long A[K];
	rep(i,0,K) cin>>A[i];
	long a = 2,b = 2 + A[K-1] - 1;
	if(A[K-1] > 2){ cout<<-1<<endl; return 0; }
	for(int i = K - 1; i > 0; i--){
		if(b / A[i-1] * A[i-1] < a){ cout<<-1<<endl; return 0; }
		a = (a + A[i-1] - 1) / A[i-1] * A[i-1];
		b = b / A[i-1] * A[i-1] + A[i-1] - 1;
	}cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if(k <= a) cout << k << endl;
    else if(k <= a + b) cout << a << endl;
    else cout << a - (k - a - b) << endl;
}

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

int A, B, C, NA, NB;

int main(){
  int p = 0;
  cin >> A >> B >> C >> NA >> NB;
  A = min(A, 2*C);
  B = min(B, 2*C);
  if(2*C < A+B){
    int buy = min(NA, NB);
    p += 2*buy * C;
    NA -= buy;
    NB -= buy;
  }
  p += A * NA;
  p += B * NB;
  cout << p << endl;

  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: int, B: int):
    if (B-A)%2 != 1:
        print('Alice')
    else:
        print('Borys')
        
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define pi 3.1415926536
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define INF 2147483647
#define _INF -2147483647
#define MM multimap
#define PB push_back
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    int A, B, T;
    cin >> A >> B >> T;
    cout << T / A * B << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <climits>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int A,B;
	cin>>A>>B;
	if(A==B) cout<<0<<endl;
	else if((A+B)%2==0){
		cout<<(A+B)/2<<endl;
	}else{
		cout<<"IMPOSSIBLE"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
 int a,b,c;
 
 scanf("%d %d %d",&a,&b,&c);
 
 if( a < b && b < c )
 { 
   printf("Yes\n");
 }
 else
 { 
  printf("No\n");
 }
 
 return 0;
}

Measured memory_bytes: 580
N,P = map(int,input().split())
S = str(input())

if P == 2 or P == 5:
    S = list(map(int,list(S)))
    ans = 0
    for i in range(N):
        if S[i] % P == 0:
            ans += i + 1

else:
    data = [0] * P
    s = int(S)
    x = 1 ##10**iをPで割った数
    y = 0 ##S[i:N]をPで割った数
    for i in range(N):
        y += int(S[N-i-1]) * x
        y %= P
        data[y] += 1
        x *= 10
        x %= P
    #print(data)
    ans = data[0]
    for i in range(P):
        ans += (data[i]*(data[i]-1))//2

print(ans)

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

typedef long long ll;
#define fore(i,ii,iii) for(ll i=ii;i<iii;i++)
#define mset(a,b) memset(a,b,sizeof(a))
#define pb push_back

const ll N=2e5+15;
ll n,h[N],a[N],c[N];
map<ll,ll>mp;

struct STree { // [cerrado-abierto)
	vector<ll> st;ll n;
	STree(ll n): st(4*n+5,0), n(n) {}
	void upd(ll k, ll s, ll e, ll p, ll v){
		if(s+1==e){st[k]=max(st[k],v);return;}
		ll m=(s+e)/2;
		if(p<m)upd(2*k,s,m,p,v);
		else upd(2*k+1,m,e,p,v);
		st[k]=max(st[2*k],st[2*k+1]);
	}
	ll query(ll k, ll s, ll e, ll a, ll b){
		if(s>=b||e<=a)return 0;
		if(s>=a&&e<=b)return st[k];
		ll m=(s+e)/2;
		return max(query(2*k,s,m,a,b),query(2*k+1,m,e,a,b));
	}
	void upd(ll p, ll v){upd(1,0,n,p,v);}
	ll query(ll a, ll b){return query(1,0,n,a,b);}
}; // usage: STree st(n);st.upd(i,v);st.query(s,e);


int main() {
  ios::sync_with_stdio(false);
  cin>>n;
  fore(i,0,n)cin>>h[i],c[i]=h[i];
  fore(i,0,n)cin>>a[i];
  sort(c,c+n);
  fore(i,0,n)mp[c[i]]=i+1;
  fore(i,0,n)h[i]=mp[h[i]];
  //fore(i,0,n)cout<<h[i]<<" ";cout<<endl;
  assert(mp.size()==n);
  STree st(n+2);
  fore(i,0,n)st.upd(h[i],a[i]+st.query(0,h[i]));
  cout<<st.query(0,n+1)<<endl;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
typedef pair<int, int> P;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  int n, m;
  cin >> n >> m;
  map<P, int> mp;
  vector<P> v(m);
  REP(i, m) {
    int p, q;
    cin >> p >> q;
    mp[P(p, q)] = i;
    v[i] = P(p, q);
  }
  sort(all(v));
  vector<P> ans(m);
  int ord = 1;
  REP(i, m) {
    // cout << v[i].first << " " << v[i].second << " " << mp[v[i]] << endl;
    ans[mp[v[i]]] = P(v[i].first, ord);
    if (i < m - 1 && v[i].first == v[i + 1].first) {
      ord++;
    } else {
      ord = 1;
    }
  }
  REP(i, m) {
    cout << setw(6) << setfill('0') << ans[i].first;
    cout << setw(6) << setfill('0') << ans[i].second << endl;
  }
}

Measured memory_bytes: 9344
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <utility>
#include <sstream>
#include <iomanip>
#include <string>

typedef std::tuple<long long ,long long , int, std::string> llis;

int main(){
  int N , M;
  std::cin >> N >> M;
  std::vector<llis> v(M);
  for(int i = 0 ; i < M ; i++){
    std::cin >> std::get<0>(v[i]) >> std::get<1>(v[i]);
    std::get<2>(v[i]) = i;
    std::get<3>(v[i]) = "";
  }

  std::sort(v.begin(), v.end(),
	    [](llis &x , llis &y){
	      return (std::get<0>(x) == std::get<0>(y))?(std::get<1>(x) < std::get<1>(y)):(std::get<0>(x)<std::get<0>(y));});
  
  long long city  = 1;
  long long count = 1;
  for(int i = 0 ; i < (int)v.size() ; i++){
    long long first = std::get<0>(v[i]);
    if(first != city){
      city = first;
      count = 1;
    }
    if(first == city){
      std::ostringstream oss;
      oss << std::setw(6) << std::setfill('0') << first << std::setw(6) << std::setfill('0') << count;
      std::get<3>(v[i]) = oss.str();
      count++;
    }
  }
  std::sort(v.begin(), v.end(), [](llis &x, llis &y){return std::get<2>(x) < std::get<2>(y);});
  for(int i = 0 ; i < (int)v.size() ; i++){
    std::cout<<std::get<3>(v[i])<<std::endl;
  }
  return 0;
}



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

int main(){
    string S, T; cin >> S >> T;
    int A, B; cin >> A >> B;
    string U; cin >> U;
    if(S==U) cout << A-1 << " " << B << endl;
    else cout << A << " " << B-1 << endl;
}

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

using namespace std;

const int kMaxN = 100;

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

    string ss[kMaxN];

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

    sort(ss, ss + n);

    for (int i = 0; i < n; ++i) {
        cout << ss[i];
    }
    
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG edpc/f.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

// string s, t;

int score[3002][3002];
int before[3002][3002];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    string s, t;
    cin >> s;
    cin >> t;

    // cout << s << " " << t << "\n";
    s = "#" + s;
    t = "#" + t;



    int n = s.size();
    int m = t.size();

    for(int i = 0; i < n; i++){
        score[i][0] = 0;
    }
    for(int j = 0; j < m; j++){
        score[0][j] = 0;
    }

    for(int i = 1; i < n; i++){
        for(int j = 1; j < m; j++){
            if(s[i] == t[j]){
                score[i][j] = score[i-1][j-1] + 1;
                before[i][j] = 0;
            }else{
                if(score[i-1][j] > score[i][j-1]){
                    score[i][j] = score[i-1][j];
                    before[i][j] = -1;
                }else{
                    score[i][j] = score[i][j-1];
                    before[i][j] = 1;
                }
            }
        }
    }

    string ans = "";
    int y = n - 1;
    int x = m - 1;
    while(y != 0 && x != 0){
        if(before[y][x] == 0){
            ans = s[y] + ans;
            y--;
            x--;
        }else if(before[y][x] == -1){
            y--;
        }else if(before[y][x] == 1){
            x--;
        }
    }

    cout << ans << "\n";

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const ll LINF = 1e11;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


string RePath(string p) {
    string res = "";

    for (int i = 0; i < p.size(); ++i) {
        if (p[i] == 'R') {
            res += 'L';
        } else if (p[i] == 'L') {
            res += 'R';
        } else if (p[i] == 'U') {
            res += 'D';
        } else {
            res += 'U';
        }
    }

    return res;
}

void solve() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    string p1 = "";
    for (int i = 0; i < ty - sy; ++i) {
        p1 += 'U';
    }
    for (int i = 0; i < tx - sx; ++i) {
        p1 += 'R';
    }

    string p2 = "LU" + p1 + "RD";

    string ans = p1 + RePath(p1) + p2 + RePath(p2);
    cout << ans << "\n";
}


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

    solve();
    return 0;
}


Measured memory_bytes: 384
import bisect
import itertools
n ,m ,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a = list(itertools.accumulate(a))
b = list(itertools.accumulate(b))
A =bisect.bisect_left(a,k)
B =bisect.bisect_left(b,k)
if B<m:
  if b[B]==k:
    B+=1


if A<n:
  if a[A]==k:
    A+=1
count=max(A,B)
if b[0]>k:
  print(A)
  exit()
  
if a[0]>k:
  B =bisect.bisect_left(b,k)
  if B<m:
    if b[B]==k:
      B+=1
  print(B)
  exit()

for i in range(A,0,-1):
  ans=k-a[i-1]
  B =bisect.bisect_left(b,ans)
  if B<m:
    if b[B]==ans:
      B+=1
  count=max(count,i+B)
print(count)

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

int main(){
  
  int n;
  cin >>n;
  vector<int> p(n),q(n);
  for(int i=0; i<n; i++){
    cin >> p[i];
    q[i]=p[i];
  }
  sort(q.begin(),q.end());
  
  int count=0;
  for(int i=0; i<n; i++){
  	if(p[i]-q[i]!=0) count++;
  }
  
   if(count>2) cout << "NO" << endl;
  else cout << "YES" << endl;
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)
#define ll long long

int main()
{
    int a,b;
    cin >> a >> b;
    cout << a * b - a - b + 1 << endl;
    return 0;
}

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

int main() {
        int n;
        cin >> n;
        int d[n][2];
        rep(i,n) cin >> d[i][0] >> d[i][1];
        int ren = 0;
        rep(i,n) {
                if (d[i][0] == d[i][1]) {
                        ren++;
                } else {
                        ren = 0;
                }
                if(ren >= 3) {
                        cout << "Yes" << endl;
                        return 0;
                }
        }
        cout << "No" << endl;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n,k;
llong T[MAX];

//最大積載量Pのk台のトラックで何個の荷物を積めるか
int check(llong P){
	int i=0;
	for (int j=0; j<k; j++){
		llong s=0;
		while(s+T[i] <= P){
			s += T[i];
			i++;
			if(i==n) return n;
		}
	}
	return i;
}

int solve(){
	llong left=0;
	llong right = 100000 * 10000; //荷物の個数×1個当たりの最大重量
	llong mid;
	while(right - left > 1){
		mid = (left + right)/2;
		int v = check(mid); //mid==P を決めて何個積めるかチェック
		if(v>=n)right = mid;
		else left = mid;
	}
	
	return right;
}

main(){
	cin >> n >> k;
	for(int i = 0; i<n; i++)cin >> T[i];
	llong ans = solve();
	cout << ans << endl;
}



Measured memory_bytes: 3876
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        (n, m): (usize, usize),
        abs: [(usize, usize); m]
    };

    let mut edges = vec![vec![]; n + 1];

    for (a, b) in abs {
        edges[a].push(b);
        edges[b].push(a);
    }

    let mut dp = vec![std::usize::MAX; n + 1];
    dp[1] = 0;
    let mut arrow = vec![0; n + 1];

    let mut queue = std::collections::VecDeque::new();
    queue.push_back(1);

    while let Some(pos) = queue.pop_front() {
        for &n in edges[pos].iter() {
            if dp[n] < std::usize::MAX {
                continue;
            }

            dp[n] = dp[pos] + 1;
            arrow[n] = pos;
            queue.push_back(n);
        }
    }

    for i in 1..=n {
        if dp[i] == std::usize::MAX {
            println!("No");
            return;
        }
    }

    println!("Yes");

    for i in 2..=n {
        println!("{}", arrow[i]);
    }
}


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

#define   Pi     2*acos(0.0)
#define   LINF   1LL<<63
#define   ll     long long
#define   ull    unsigned long long
#define   pb     push_back
#define   mp     make_pair
#define   MAX    500006
#define   MAX1   10000008
#define   mem(a,v)   memset(a,v,sizeof(a))
#define   all(x) x.begin(),x.end()
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define yes   cout<<"YES"<<endl
#define no   cout<<"NO"<<endl
#define buga  cout<<1<<endl
#define bugb  cout<<2<<endl
#define bugc  cout<<3<<endl
#define bugd  cout<<4<<endl
#define buge  cout<<5<<endl


void fastIO (){ios_base::sync_with_stdio(false);cin.tie(0); cout.precision(20);}
void pr(ll n){ cout<<n<<endl;}

ll A[MAX];
ll B[MAX];
ll C[MAX];
vector< ll >V;
vector< ll >Ans;
vector< pair<ll,ll> >VP;
map< ll,ll >M;
vector<ll>prime;
bool mark[MAX1];
ll N=1e7;
void seive (){int limit = sqrt(N*1.0)+2;mark[1]=1;for (int i=4;i<=N;i+=2)mark[i]=1;prime.push_back(2);for (int i=3;i<=N;i+=2){if(!mark[i]){prime.push_back(i);if(i<=limit){for (int j=i*i;j<=N;j+=i*2)mark[j]=1;}}}}

/*
vector<int>s;
int seive[3125007],arr[100007],co[100007],n,q;
bool check(int n,int pos) {return (n& (1<<pos));}
int Set(int n,int pos) {return (n(1<<pos));}
void bitwise_seive(){
    int x=sqrt(100000000);
    for(int i=3;i<=x;i+=2){
        if(check(seive[i/32],i%32)==0)
        {
            for(int j=i*i;j<=100000000;j+=(i<<1)){
                seive[j/32]=Set(seive[j/32],j%32);
            }
        }
    }
    s.push_back(2);
    for(int i=3;i<=100000000;i+=2){
        if(check(seive[i/32],i%32)==0){
           // cout<<i<<endl;
            s.push_back(i);
        }
    }
}
*/
/*
ll bin_pow(ll o, ll s) {
    if (s == 0) return 1;
    if (s == 1) return o % mod;
    ll d = bin_pow(o, s/2);
    d = (d * 1ll * d) % mod;
    if (s % 2 == 1)
        d = (d * 1ll * o) % mod;
    return d;
}
*/
/*
vector<int> z_function (string s) {
    int n = (int) s.length();
    vector<int> z (n);
    for (int i=1, l=0, r=0; i<n; ++i) {
        if (i <= r)
            z[i] = min (r-i+1, z[i-l]);
        while (i+z[i] < n && s[z[i]] == s[i+z[i]])
            ++z[i];
        if (i+z[i]-1 > r)
            l = i,  r = i+z[i]-1;
    }
    return z;
}*/
int main ()
{
    fastIO();
    ll a,b,c,d,n,m,k,l,p,q,r,t,x,y;
    ll cnt=0,cntr=0,sum=0,ans=1,check=0;
    ll Max= 0,Max1=-1e18+1,Min=LINF;
    string s,s1,s3,s4;

    //cin>>n;
    //cin>>t;
    t=1;

    while(t--){
        cin>>n>>m>>k;
        a=n/k;
        if(n%k)a++;
        if(a<=m)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

    }

    return 0;
}


Measured memory_bytes: 3676
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
	return b>0?gcd(b,a%b):a;
}
ll lcm(ll a,ll b){
	int temp=gcd(a,b);
	return (a*b/temp);
} 
int main()
{
	ll a,b;
	cin>>a>>b;
	cout<<lcm(a,b)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	bool ans=false;
	long long a,b,c;
	cin>>a>>b>>c;
	long long sum=0;
	for(int i=0;i!=10000;++i){
		sum+=a;
		if(!((sum-c)%b)){
			ans=true;
			break;
		}
	}
	if(ans)
		cout<<"YES";
	else
		cout<<"NO";
}


Measured memory_bytes: 256
const gInput = require('fs').readFileSync('/dev/stdin', 'utf8')
const input = gInput.split(' ').map( s => parseInt(s))
var W = input[0]
var H = input[1]
var x = input[2]
var y = input[3]
var r = input[4]

var minX = x - r
var maxX = x + r
var minY = y - r
var maxY = y + r

const judge = 0 <= minX && maxX <= W && 0 <= minY && maxY <= H
if(judge){
    console.log('Yes')
} else{
    console.log('No')
}


Measured memory_bytes: 15124
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

char s[2048],t[2048];int n,r;
int a[2048],b[2048];

int doit2(vector<pair<int,int> >& w){
	if(!SZ(w))return 0;
	sort(w.begin(),w.end());
	int k=0,r=1<<30;
	for(int i=SZ(w)-1;i>=0;--i){
		r=min(r,k+w[i].fst);
		k=max(k,w[i].snd);
	}
	r=min(r,k);
	return r;
}

int doit(){
	int rr=(1<<30);
	fore(i,0,n){
		a[i]=b[i]=0;
		if(s[i]=='1'){
			while(t[(i+n-a[i])%n]!='1')a[i]++;
			while(t[(i+b[i])%n]!='1')b[i]++;
		}
	}
	fore(k,0,n){
		int r=k;
		vector<pair<int,int> > w;
		fore(i,0,n){
			r+=s[i]!=t[(i+k)%n];
			if(s[i]=='1'&&t[(i+k)%n]=='0'){
				if(a[i]&&b[i]>k)w.pb(mp(a[i],b[i]-k));
			}
		}
		r+=2*doit2(w);
		rr=min(rr,r);
	}
	return rr;
}

int main(){
	scanf("%s%s",s,t);n=strlen(s);
	bool z=true;
	fore(i,0,n)if(t[i]=='1'){z=false;break;}
	if(z){
		fore(i,0,n)if(s[i]=='1'){z=false;break;}
		puts(z?"0":"-1");
		return 0;
	}
	r=doit();
	reverse(s,s+n);reverse(t,t+n);
	r=min(r,doit());
	printf("%d\n",r);
	return 0;
}

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

using namespace std;

using ll = long long;

using Int = int;

struct ModInt {
    static constexpr Int mod = 1e9 + 7;
    Int v;

    ModInt(long long _v = 0) : v(set(_v)) {}
    ModInt(const ModInt &r) : v(set(r.v)) {}

    inline static Int set(const auto x) { return x < 0 ? (x % mod) + mod : x % mod; }
    inline void set() { v = set(v); }

    bool operator<(ModInt r) const { return v < r.v; }
    bool operator>(ModInt r) const { return r.v < v; }
    bool operator==(ModInt r) const { return v == r.v; }
    bool operator!= (ModInt r) const { return v != r.v; }

    ModInt operator-() const { return ModInt(v ? mod - v : v); }
    ModInt &operator=(const ModInt &r) { if (this != &r) v = set(r.v); return *this; }
    ModInt &operator+=(ModInt r) { (v += r.v) %= mod; return *this; }
    ModInt &operator-=(ModInt r) { (v -= r.v - mod) %= mod; return *this; }
    // ModInt &operator*=(ModInt r) { v = (__uint128_t(v) * r.v) % mod; return *this; }
    ModInt &operator*=(ModInt r) { v = 1ULL * v * r.v % mod; return *this; }
    ModInt &operator/=(ModInt r) { *this *= r.inv(); return *this; }
    ModInt operator+(ModInt r) const { return ModInt(*this) += r; }
    ModInt operator-(ModInt r) const { return ModInt(*this) -= r; }
    ModInt operator*(ModInt r) const { return ModInt(*this) *= r; }
    ModInt operator/(ModInt r) const { return ModInt(*this) /= r; }

    ModInt inv() const {
        long long a = v, b = mod, u = 1, w = 0;
        while (b) {
            long long t = a / b;
            std::swap(a -= t * b, b);
            std::swap(u -= t * w, w);
        }
        return ModInt(u);
    }

    ModInt pow(Int e) {
        ModInt a = *this, x(1);
        for ( ; 0 < e; e >>= 1) { if (e & 1) x *= a; a *= a; }
        return x;
    }
    inline ModInt pow(ModInt &e) { return pow(e.v); }
};
std::ostream &operator<<(std::ostream &os, const ModInt &r) { return os << r.v; }
std::istream &operator>>(std::istream &is, ModInt &r) { is >> r.v; r.set();return is; }


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

    int n;
    string s1, s2;
    cin >> n >> s1 >> s2;

    ModInt res;
    int i = 0;
    if (s1[i] == s2[i]) { res = 3; ++i; }
    else { res = 6; i += 2; }

    while (i < n) {
        if (s1[i] == s2[i]) {
            if (s1[i - 1] == s2[i - 1]) res *= 2;
            ++i;
        }
        else {
            if (s1[i - 1] == s2[i - 1]) res *= 2;
            else res *= 3;
            i += 2;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

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 merge(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 issame(ll x, ll y) {
        return root(x) == root(y);
    }

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    map<vector<char>,ll> mp;
    for (int i = 0; i < (1 << n); i++) {
        vector<char> f(n+1);
        ll now = 0;
        ll nows = n;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                f[now] = s[j];
                now++;
            }
            else {
                f[nows] = s[j];
                nows--;
            }
        }
        f[now] = 'Z';
        mp[f]++;
    }
    ll ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        vector<char> f(n + 1);
        ll now = 0;
        ll nows = n;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                f[now] = s[2 * n - 1 - j];
                now++;
            }
            else {
                f[nows] = s[2 * n - 1 - j];
                nows--;
            }
        }
        f[now] = 'Z';
        ans += mp[f];
    }
    cout << ans << endl;
}

Measured memory_bytes: 60744
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;


ll dist[100010];
int l[100010], r[100010];


int main(){
    int h, w, d;
    cin >> h >> w >> d;


    vector<P> b(h * w + 1);
    rep(i, h){
        rep(j, w){
            int a;
            cin >> a;
            P p;
            p = make_pair(j, i);
            b[a] = p;
        }
    }

    int q;
    cin >> q;
    rep(i, q) cin >> l[i] >> r[i];


    for(int i = 1; i <= h * w; i++){
        if (i <= d) dist[i] = 0;
        else dist[i] = dist[i - d] + abs(b[i].first - b[i - d].first) + abs(b[i].second - b[i - d].second);
    }

    // rep(i, h*w){
    //     cout << i + 1 << " " << dist[i + 1] << endl;
    // }


    rep(i, q){
        cout << dist[r[i]] - dist[l[i]] << endl;
    }


    return 0;
}

Measured memory_bytes: 3968
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls int
#define give main()
const int mod = 1000000007;
#pragma endregion

pls give {
    AC;
    int x, a, b;
    cin >> x >> a >> b;
    x -= a;
    cout << x%b << nl;
}

Measured memory_bytes: 256
typedef long long ll;

#include <iostream>
#include <map>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

class UnionFind{
private:
  mutable vector<int> id;

  int getId(int i) const{
    if(i == id[i]) return i;
    return id[i] = getId(id[i]);
  }
public:
  UnionFind(int size = 0){ init(size); }
  ~UnionFind(){}
  void init(int size){
    id = vector<int>(size);
    for(int i = 0; i < size; i++)
      id[i] = i;
  }
  void unite(int i, int j){
    int next = min( getId(i), getId(j) );
    id[getId(i)] = id[getId(j)] = next;
  }
  int operator [](int i) const{ return getId(i); }
  int count() const{
    set<int> s;
    for(int i = 0; i < (int)id.size(); i++)
      s.insert(getId(i));
    return s.size();
  }
};

template<class T>
class IdGenerator{
  std::map<T,int> _m;

public:
  IdGenerator(){}

  int getId(const T &v){
    if(_m.find(v) == _m.end()){
      int next = _m.size();
      return _m[v] = next;
    }
    return _m[v];
  }

  int size() const{
    return _m.size();
  }
};

int main(){
  const int n = getInt();
  vector<int> x(n);
  vector<int> y(n);

  map<int, set<int> > xy;
  map<int, set<int> > yx;
  IdGenerator<int> id;

  REP(i,n){
    const int x = getInt();
    const int y = getInt();

    xy[x].insert(y);
    yx[y].insert(x);
    id.getId(y);
  }

  UnionFind uf(id.size());

  for(const auto &a : xy){
    bool ok = false;
    for(const int y : a.second){
      if(yx[y].size() >= 2) ok = true;
    }
    if(!ok) continue;
    const int first = id.getId(*a.second.begin());
    for(const int y : a.second){
      const int second = id.getId(y);
      uf.unite(first, second);
    }
  }

  map<int, set<int> > m;
  map<int, int> cnt;

  for(const auto &a : yx){
    const int y = a.first;
    const int i = uf[id.getId(y)];
    m[i].insert(a.second.begin(), a.second.end());
    cnt[i]++;
  }

  ll ans = 0;
  for(const auto a : m){
    ans += (ll)cnt[a.first] * (ll)a.second.size();
  }
  ans -= n;
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 27008
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
bit = [0]*32
for i in A:
    for ind,j in enumerate(format(i,"32b")):
        if j == "1":
            bit[ind] += 1

bit.reverse()
for i in A:
    ans = 0
    tmp = 1
    for j,k in zip(bit,format(i,"32b")[::-1]):
        if k == "1":
            j -= 1
        
        if j % 2 != 0:
            ans += tmp
        tmp *= 2
    print(ans)

Measured memory_bytes: 105708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int dp[3005][3005];
int main(){
    string s,t;cin >> s >> t;
    for(int i=0; i<s.size();i++){
        for(int j=0; j<t.size();j++){
            if(s[i]==t[j]) dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
            else{
                dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
    int n=s.size(),m=t.size();
    string ans="";
    while(n>0&&m>0){
        if(s[n-1]==t[m-1]){
            ans=s[n-1]+ans;
            n--;
            m--;
        }
        else if(dp[n][m]==dp[n-1][m]) n--;
        else m--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35456
#include <iostream>

using namespace std;

int main() {

    string S;
    cin >> S;
    if(S[0]==S[1] && S[1] ==S[2])cout << "Yes" <<endl;
    else if(S[1]==S[2] && S[2] ==S[3])cout << "Yes" <<endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
int main()
{
	std::stack<double> s;
	double a,b;
	char c[80],d;
	while (std::cin>>c)
	{
		if (c[0]=='+')
		{
			b = s.top(), s.pop();
			a = s.top(), s.pop();
			s.push(a+b);
		}
		else if (c[0]=='-'&&c[1]==0)
		{
			b = s.top(), s.pop();
			a = s.top(), s.pop();
			s.push(a-b);
		}
		else if (c[0]=='*')
		{
			b = s.top(), s.pop();
			a = s.top(), s.pop();
			s.push(a*b);
		}
		else if (c[0]=='/')
		{
			b = s.top(), s.pop();
			a = s.top(), s.pop();
			s.push(a/b);
		}
		else	s.push(atof(c));
		if ((d=getchar()) == '\n')	printf("%.6f\n", s.top());
		if (d==-1)	break;
	}
}

Measured memory_bytes: 0
import math
def main():

    A, B = map(int, input().split())
    C = min(A, B)
    p = set()
    p.add(1)
    for i in range(2, int(math.sqrt(C))+1):
        if C % i == 0:
            if A % i == 0 and B % i == 0:
                if isprime(i): p.add(i)
            j = C // i
            if A % j == 0 and B % j == 0:
                if isprime(j): p.add(j)

    if isprime(C) and A%C == 0 and B%C == 0:
        p.add(C)

    return len(p)

def isprime(n):
    if n == 1 or n == 0: return False
    for i in range(2, int(math.sqrt(n))+1):
        if n % i  == 0: return False
    return True

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
from math import gcd

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

m = gcd(A, B)
#print(m)

num = int(m**0.5) #mに対する素因数分解は、int(√m)の場合を調べればよい
ans = 1

for i in range(2,num+1):
    if m%i:
        continue
    ans += 1
    while not m%i:
        m /= i

if m>1:
    ans+=1 #m+1が素因数の場合がある

print(ans)

Measured memory_bytes: 9444
//author: dxm
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
inline void Fail(){
	printf("0");
	exit(0);
}

const int maxn=200005;
int n;
int dp[maxn],a[maxn];
char c[maxn];
map<int,int>m;
int cur;

int main(){
	scanf("%s",c);
	n=strlen(c);
	rep(i,n)a[i]=c[i]-'a';
	m[0]=0;
	rep(i,n){
		dp[i]=INF;
		cur^=(1<<a[i]);
		if(m.find(cur)!=m.end())dp[i]=min(dp[i],m[cur]+1);
		rep(j,26){
			int tmp=cur^(1<<j);
			if(m.find(tmp)!=m.end())dp[i]=min(dp[i],m[tmp]+1);
		}
		dp[i]=min(dp[i],(!i?0:dp[i-1])+1);
		if(m.find(cur)==m.end())m[cur]=dp[i];
		else m[cur]=min(m[cur],dp[i]);
//		cout<<dp[i]<<endl;
	}
	printf("%d",dp[n-1]);
	return 0;
}

/*
Input:
aabxyyzz

byebye

abcdefghijklmnopqrstuvwxyz

abcabcxabcx
-----------------
Output:
2

1

26

3
*/

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

using namespace std;

int M, D;

int main(){
    scanf("%d %d", &M, &D);
    int ans = 0;
    for(int i = 1; i <= D; ++i){
        int A = i / 10, B = i % 10;
        if(A > 1 && B > 1){
            if(A * B <= M) ++ans;
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

int main(){
    ll a,b;
    cin >> a >> b;
    string ans = "Zero";
    if(a>0) ans = "Positive";
    else if(b<0){
        if((b-a)%2) ans = "Positive";
        else ans = "Negative";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
lis = list(map(int, input().split()))
res = 0
cnt = 0
flg = False
for i in lis:
    if i == 1:
        flg = True
        res = max(res, cnt)
        cnt = 1
    elif i == cnt + 1:
        cnt += 1

if not flg:
    print(-1)
else:
    print(n - max(res, cnt))

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

int main(void){
    string strN;
    cin >> strN;
    bool inc7 = false;
    for(int i=0; i<3; i++){
        if(strN[i] == '7'){
            inc7 = true;
            break;
        }
    }
    if(inc7){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
while 1:
    try:
        n=float(input())
        if n>91:
            print("heavy")
        elif n>81:
            print("light heavy")
        elif n>75:
            print("middle")
        elif n>69:
            print("light middle")
        elif n>64:
            print("welter")
        elif n>60:
            print("light welter")
        elif n>57:
            print("light")
        elif n>54:
            print("feather")
        elif n>51:
            print("bantam")
        elif n>48:
            print("fly")
        else:
            print("light fly")
    except:break


Measured memory_bytes: 5576
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e3+5 ;

int n ,m ,l[N][N] ,r[N][N] ,u[N][N] ,d[N][N] ;
char str[N][N] ;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;++i) scanf("%s",str[i]);
    for(int i=0;i<n;++i){
        int cur=0;
        for(int j=0;j<m;++j){
            if(str[i][j]=='#') cur=0;
            else ++cur ;
            l[i][j] = cur ;
        }
        cur = 0 ;
        for(int j=m-1;j>=0;--j){
            if(str[i][j]=='#') cur=0;
            else ++cur ;
            r[i][j] = cur ;
        }
    }
    for(int j=0;j<m;++j){
        int cur = 0 ;
        for(int i=0;i<n;++i){
            if(str[i][j]=='#') cur=0;
            else ++cur ;
            u[i][j] = cur ;
        }
        cur = 0 ;
        for(int i=n-1;i>=0;--i){
            if(str[i][j]=='#') cur=0;
            else ++cur ;
            d[i][j] = cur ;
        }
    }
    int mx = 0 ;
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            int x = u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3 ;
            mx = max(mx,x);
        }
    }
    cout << mx;
    return 0;
}


Measured memory_bytes: 66944
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def f(N):
    D = {}

    for i in range(2, int(N ** 0.5) + 1):
        c = 0
        while N % i == 0:
            c += 1
            N //= i
        if c > 0:
            D[i] = c
        if N == 1:
            break
            
    if N != 1:
        D[N] = 1
    return D


def main():
    N = int(input())
    D = f(N)

    res = 0
    for k, v in D.items():
        t = 1
        while t <= v:
            v -= t
            t += 1
        res += t - 1
    print(res)       


if __name__ == "__main__":
    main()



Measured memory_bytes: 10152
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n <= 111) cout << 111 << endl;
	else if (n <= 222) cout << 222 << endl;
	else if (n <= 333) cout << 333 << endl;
	else if (n <= 444) cout << 444 << endl;
	else if (n <= 555) cout << 555 << endl;
	else if (n <= 666) cout << 666 << endl;
	else if (n <= 777) cout << 777 << endl;
	else if (n <= 888) cout << 888 << endl;
	else if (n <= 999) cout << 999 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
  cin>>n;
  int* arr =new int[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  int *dp =new int[n];
  dp[0]=0;
  int a=INT_MAX,b=INT_MAX;
  for(int i=1;i<n;i++)
  {
    if(i-1>=0)
       a = dp[i-1] +abs(arr[i]-arr[i-1]);
    if(i-2>=0)
       b = dp[i-2] +abs(arr[i]-arr[i-2]);
       
       a= abs(a);
       b=abs(b);
    if(a>b)
    {
      dp[i]=b;
    }
    else
    {
    dp[i]=a;
    }
   
  }
  
  cout<<dp[n-1];
}

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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/

using namespace std;

int main()
{
	ll n,p;
    cin>>n>>p;
    ll ans=1;
    if(n==1) {
        cout <<p <<endl;
        return 0;
    }
	else {
        for(int i=2;i<=p;i++){
            ll tmp=1;
            for(int j=0;j<n;j++){
                tmp*=i;
                if(tmp>p) {
                    cout <<ans <<endl;
                    return 0;
                }
            }
            if(p%tmp==0) ans=i;
        }
    }
    cout <<ans <<endl;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

void main()
{
    auto nab = readln.split.to!(int[]);
    writeln(nab[0] * nab[1] > nab[2] ? nab[2] : nab[0] * nab[1]);
}

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

vector<int> to[200005];
vector<ll> counter;

void dfs(int v, int p){
	for(auto next : to[v]){
		if(next == p) continue;
		counter[next] += counter[v];
		dfs(next, v);
	}
}

int main(){
	int n,q;
	cin >> n >> q;
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		a--;b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	counter.resize(n, 0);
	rep(i,q){
		int p;
		ll x;
		cin >> p >> x;
		p--;
		counter[p] += x;
	}
	dfs(0,-1);
	rep(i,n){
		cout << counter[i] << " ";
	}
	cout << endl;
    return 0;
}



Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n>=400 && n<=599){
  cout<< 8<<endl;}
  else if(n>=600 && n<=799){
  cout<< 7<<endl;
  }
  else if(n>=800 && n<=999){
  cout<< 6<<endl;
  }
  else if(n>=1000 && n<=1199){
  cout<< 5<<endl;
  }
  else if(n>=1200 && n<=1399){
  cout<< 4<<endl;
  }
  else if(n>=1400 && n<=1599){
  cout<< 3<<endl;
  }
  else if(n>=1600 && n<=1799){
  cout<< 2<<endl;
  }
  else if(n>=1800 && n<=1999){
  cout<< 1<<endl;
  }
  
  
return 0;}

Measured memory_bytes: 3632
n = int(input())

g = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
    a = list(map(int, input().split()))
    for j in range(a[1]):
        g[a[0] - 1][a[j + 2] - 1] = 1

for i in range(n):
    print(*g[i])


Measured memory_bytes: 6392
"""

大事な要素
深さと高低差
まず、高低差の話が0であることは必須

もう一つ、現状が深さ以上ないと設置できない。
まず、高くするやつで置けるやつはどんどんおいていい。
置いたもん勝ち
→つまり、+で深さが浅い順においていけばいい

降りるときは、深い→浅いが置けない場合で浅い→深いが置ける場合はない
→深い順に億


"""


N = int(input())

ans = 0

pl_d = [] 
mi_d = []

for lp in range(N):

    S = input()

    dep = 0
    mindep = 0

    for i in S:
        if i == "(":
            dep += 1
        else:
            dep -= 1

        mindep = min(dep,mindep)

    if dep >= 0:
        pl_d.append([mindep,dep])
    else:
        mi_d.append([mindep-dep,-1 * dep])

pl_d.sort()
mi_d.sort()
pl_d.reverse()
mi_d.reverse()

#print (pl_d,mi_d)

nowp = 0

import sys
for i in range(len(pl_d)):

    nd,np = pl_d[i]

    if nowp + nd < 0:
        print ("No")
        sys.exit()

    nowp += np

nowm = 0

import sys
for i in range(len(mi_d)):

    nd,np = mi_d[i]

    if nowm + nd < 0:
        print ("No")
        sys.exit()

    nowm += np


if nowp != nowm:
    print ("No")
else:
    print ("Yes")
        
    

Measured memory_bytes: 186620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    int k, s; cin >> k >> s;
    int ans = 0;
    
    for(int x=0; x<=k; x++){
        for(int y=0; y<=k; y++){
            int res = s-x-y;
            if(0 <= res && res <= k) ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cstdio>
using namespace std;

char to(char c) {
    return (c + 0x20);
}

int main() {

    int n ,k;
    cin >> n >> k;

    char s[51];

    scanf("%s" ,s);

    s[k-1] = s[k-1] + 32;

    printf("%s" ,s);
    
    return 0;
    
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

using namespace std;

int main(){
  int c[3*3],x,y,z,w;
  REP(i,9) scanf("%d",&c[i]);
  x = c[0] + c[4] - c[3] - c[1];
  y = c[1] + c[5] - c[2] - c[4];
  z = c[3] + c[7] - c[4] - c[6];
  w = c[4] + c[8] - c[5] - c[7];
  if(x==0&y==0&z==0&w==0) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a,b ;
int main(){
    while(1){
        int sou[2][1000]={};
        cin>>a;
        if(a==0)break;
        for(int q=0;q<a;q++){
            cin>>b;
            sou[0][b]=true;
        }
        for(int i=1;i<a*2+1;i++){
            if(!sou[0][i]){sou[1][i]=true;}
        }
        int aaa[2]={a,a};
        int no=0, cu=1;
        while(aaa[0]&&aaa[1]){
            for(;cu<a*2+1;cu++){
                if(sou[no][cu]){
                    aaa[no]--;
                    sou[no][cu]=false;
                    break;
                }
            }
            if(cu==2*a+1){cu=1;}
            no^=1;
        }
        cout<<aaa[1]<<"\n"<<aaa[0]<<endl;
    }
}

Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
int  main(){
 int n;
 cin>>n;
 string s;
 cin>>s;
//  vector<int>a(n);
//  for(int i=0;i<n;i++){
//    if(s.at(i)=='W')a[i]=0;
//    else a[i]=1;
//  }
//累積s[0][n+1]はW、
vector<vector<int>>S(2,vector<int>(n+1,0));
for(int i=0;i<n;i++){
  if(s.at(i)=='W'){
    S[0][i+1]=S[0][i]+1;
    S[1][i+1]=S[1][i];
  }else{
    S[1][i+1]=S[1][i]+1;
    S[0][i+1]=S[0][i];
  }
}

//left[0][n]はW、lwft[1][n]はEの数格納
// vector<vector<int>>left(2,vector<int>(n,0));
 //vector<vector<int>>right(2,vector<int>(n,0));
//vector<int>ans(n,300100);
int mini=300100;
for(int i=0;i<n;i++){
  //if(s.at(i)=='W'){
    mini=min(mini,S[0][i]+S[1][n]-S[1][i+1]);
  //}
  // }else{
  //   mini=min(mini,S[0][i]+S[1][n]-S[1][i+1]);
  // }
  //cout<<mini<<endl;
}
cout<<mini<<endl;
}

Measured memory_bytes: 7156
let is_prime n = match n with
    2|3|5|7 -> true
    | n when n mod 2 = 0 -> false
    | n ->
       let rec loop i =
         if i*i > n then true
         else if n mod i = 0 then false
         else loop (i+2);
       in loop 3

let () =
  let n = read_int () in
  let rec read ct = function
      0 -> ct
    | i ->
       let m = read_int () in
       read (if is_prime m then ct+1 else ct) (i-1)
  in
  Printf.printf "%d\n" (read 0 n)

Measured memory_bytes: 3080