akhauriyash/Code-Regression huggingface dataset:
import sys

s=list(input())
ret=0
while True:
    tmp=0
    for i in s:
        tmp+=int(i)
    ret=max(ret,tmp)
    for i in reversed(range(len(s))):
        if s[i]!="9":
            if i==0:
                print(ret)
                sys.exit()
            else:
                j=i-1
                while s[j]=="0":
                    j-=1
                s[j]=str(int(s[j])-1)
                j+=1
                while j<len(s):
                    s[j]="9"
                    j+=1
                break
    else:
        print(ret)
        break

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

int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    long long ans=1e10;
    for(int i=0;i<=1e5;i++){
        long long tmp=i*2*c+max(0,x-i)*a+max(0,y-i)*b;
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3596
a, s = [0]*100003, [0]*100003
while True:
	n, k = map(int, input().split())
	if n == 0: break
	s[0] = a[0] = int(input())
	for i in range(1, n):
		a[i] = int(input())
		s[i] = s[i-1] + a[i]
		if i >= k: s[i] -= a[i-k]
	ans = s[k-1]
	for i in range(k, n):
		if s[i] > ans: ans = s[i]
	print(ans)


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


int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

	if (s < t) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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

int A[100001];

int partision(int p, int r) {
  int x = A[r];
  int i = p - 1;
  for (int j = p; j < r; j ++) {
    if (A[j] <= x) {
      i ++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i+1;
}

int main(){
  int n;cin>>n;
  rep(i, n) cin >> A[i];
  int idx = partision(0, n-1);

  rep(i, n) {
    if (i != idx) {
      cout << A[i];
    } else {
      cout << "[" << A[i] << "]";
    }
    if (i != n-1) cout << " ";
    else cout << endl;
  }
}


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

int main() {
  string s; cin >> s;
  map<char, int> mp;
  bool ans = true;
  for (char e: s) {
    mp[e]++;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if (it->second != 2) ans = false;
  }
  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i:a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	int q; cin >> q;
	rep(i, q) {
		int c, a, n; cin >> c >> a >> n;

		int c1 = min(c, min(a, n));
		c -= c1; a -= c1; n -= c1;
		int c2 = min(c / 2, a);
		c -= c2 * 2; a -= c2;
		int c3 = c / 3;

		cout << c1 + c2 + c3 << endl;
	}
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll a,b,c;
    cin>>a>>b>>c;
    Yes(a+b>=c)
    return  0;
}


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

int main() {
  int K, A, B, C;
  cin >> K >> A >> B;
  C = 0;
  
  for (int i = 1; i < B / K + 1; i++) {
    if ((A <= K * i) && (B >= K * i)) {
      C = C + 1;
    }
  }
  
  if (C > 0) {
    cout << "OK";
  }
  else {
    cout << "NG";
  }

}

Measured memory_bytes: 3636
#a,b=map(int,input().split())
#p_3,p_4=map(int,input().split())
n=int(input())
#S=input()
#T=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
#s=[list(input())for _ in range(n)]
h=list(map(int,input().split()))
#v=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#s=[list(input().split())for _ in range(n)]
#s=[input()for _ in range(n)]
h.reverse()
cnt=0
ans=0
for i in range(1,n):
    if h[i-1]<=h[i]:
        cnt+=1
    else:
        cnt=0
    ans=max(ans,cnt)
print(ans)

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

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

using namespace std;

int main() {
  int n;
  cin>>n;
  REP(cnt,n){
    set<pair<int,int>> p;
    p.insert(make_pair(0,0));
    int x,y;
    x=y=0;
    while(1){
      int dx,dy;
      cin>>dx>>dy;
      if(!(dx||dy)) break;
      x+=dx;y+=dy;
      p.insert(make_pair(x,y));
    }
    int mx,my;
    mx=my=0;
    for(auto pos:p){
      tie(x,y)=pos;
      int d=x*x+y*y;
      int od=mx*mx+my*my;
      if(d > od || (d == od && x > mx)) {
        mx = x;
        my = y;
      }
    }
    cout << mx << ' ' << my << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
public class Main{
  static public void main(String[] args){
  	
  	 java.util.Scanner scan = new java.util.Scanner(System.in);

  	
  	int n = scan.nextInt();
    int x = scan.nextInt();
  	int t = scan.nextInt();
  	int result;
  	/*
  	int n = Integer.parseInt(args[0]);
    int x = Integer.parseInt(args[1]);
  	int t = Integer.parseInt(args[2]);
    int result;
  	*/
  	if(n%x != 0){
  		result = (((int)(n/x))+1)*t;
  		
  	}else{
  		result = ((int)(n/x))*t;
  	}
  	System.out.println(result);
  	
  }
}

Measured memory_bytes: 35696
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////


int main(){
  int n;
  cin >> n;
  unsigned long long r;
  cin >> r;
  rep(i,0,n-1){
    unsigned long long b;
    cin >> b;
    if(b < r){
      swap(r,b);
    }
    if(b%r==0)
      r = b;
    else{
      unsigned long long c,d = b,e = r;
      c = d%e;
      while(c!=0){
        d = e;
        e = c;
        c = d%e;
      }
      r = b/e*r;
    }
  }
  cout << r << endl;
  ret 0;
}

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

typedef long long lint;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const lint inv = MOD - 2;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    int minH = IINF, maxH = 1;
    rep(i, n){
        cin >> x[i] >> y[i] >> h[i];
        minH = min(minH, h[i]);
        maxH = max(maxH, h[i]);
    }
    minH = max(minH, 1);
    maxH += 201;
    int ansx, ansy, ansh;
    rep(cx, 101){
        bool flag = false;
        rep(cy, 101){
            REP(H, minH, maxH){
                flag = true;
                rep(i, n){
                    int tmp = H - abs(x[i] - cx) - abs(y[i] - cy);
                    if(h[i] == 0){
                        if(tmp > 0){
                            flag = false;
                            break;
                        }
                    }else{
                        if(tmp != h[i]){
                            flag = false;
                            break;
                        }
                    }
                }
                if(flag){
                    ansx = cx;
                    ansy = cy;
                    ansh = H;
                    break;
                }
            }
            if(flag){
                break;
            }
        }
        if(flag){
            break;
        }
    }
    cout << ansx << " " << ansy << " " << ansh << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int s;
  cin >> s;
  int y, m;
  y = s/100;
  m = s%100;
  if(0 < y && y <13 && 0 < m && m <13) cout << "AMBIGUOUS" << endl;
  else if (0 < y && y <13) cout << "MMYY" << endl;
  else if (0 < m && m <13) cout << "YYMM" << endl;
  else cout << "NA" << endl;
}


Measured memory_bytes: 256
N = int(input())

W = [input() for i in range(N)]

endOneWord = W[0][0]

for i in range(N):
    # 重複チェック
    if(W.count(W[i]) > 1):
        print("No")
        exit()

    # 最初と最後の文字が一致するかチェック
    if(endOneWord != W[i][0]):
        print("No")
        exit()

    endOneWord = W[i][-1]

print("Yes")


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

int main() {
  string s, p;
  bool flag = false;
  cin >> s >> p;
  for (int i=0; i<s.length(); i++) {
    for (int j=0; j<p.length(); j++) {
      if (s[(i+j)%s.length()] != p[j]) break;
      if (j == p.length()-1) {
        flag = true;
        i = s.length();
      }
    }
  }
  cout << (flag?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 3204
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

////////// 繰り返し二乗法 //////////

ll power(ll a,ll b){
  ll res=1;
  while(b>0){
    if(b&1) res=res*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return res;
}

//////////////////////////////////////////////////

int main(){
  ll N,ans=1,cnt=0;
  cin>>N;
  map<pair<ll,ll>,ll> L;
  REP(i,N){
    ll A,B;
    cin>>A>>B;
    if(A==0 && B==0) cnt++;
    else if(A==0 && B!=0) L[MP(0,-1)]++;
    else if(A!=0 && B==0) L[MP(1,0)]++;
    else{
      ll GCD=gcd(A,B);
      A/=GCD,B/=GCD;
      if(A<0) A*=-1,B*=-1;
      L[MP(A,B)]++;
    }
  }
  
  FORE(v,L){
    ll count=L[MP(v.first.first,v.first.second)],pair_count;
    L[MP(v.first.first,v.first.second)]=0;
    if(v.first.second<0){
      pair_count=L[MP(v.first.second*(-1ll),v.first.first)];
      L[MP(v.first.second*(-1ll),v.first.first)]=0;
    }
    else{
      pair_count=L[MP(v.first.second,v.first.first*(-1ll))];
      L[MP(v.first.second,v.first.first*(-1ll))]=0;
    }
    ans*=power(2,count)+power(2,pair_count)-1;
    ans%=MOD;
  }
  
  ans--;
  ans+=cnt;
  if(ans<0) ans+=MOD;
  co(ans);
  return 0;
}

Measured memory_bytes: 28628
import heapq

N,M=map(int,input().split())

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

for i in  range (0,len(A)):
    A[i]*=(-1)

heapq.heapify(A)

def chaep(n):
    n=int(n/2)
    return  n
i=0
while(i<M):
    tmp=heapq.heappop(A)
    tmp=chaep(tmp)
    heapq.heappush(A,tmp)
    i+=1

ans=0
for i in range (0,N):
    ans+=A[i]

print(ans*(-1))

Measured memory_bytes: 72556
from collections import deque


S = deque(input())
Q = int(input())
reverse_count = 0

for _ in range(Q):
    Query = input().split()
    if Query[0] == "1":
        reverse_count += 1
    else:
        F, C = Query[1], Query[2]
        if F == "1":
            if reverse_count % 2 == 0:
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if reverse_count % 2 == 0:
                S.append(C)
            else:
                S.appendleft(C)

if reverse_count % 2 == 1:
    S.reverse()
print("".join(S))


Measured memory_bytes: 102860
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n+1)
for i in range(n):
    r[i+1]=r[i]+l[i]
r.sort()
r.append(100000000000)
f=1
ans=0
for i in range(n+1):
    if r[i]==r[i+1]:
        f+=1
    else:
        ans+=f*(f-1)//2
        f=1
print(ans)


Measured memory_bytes: 25720
#include "bits/stdc++.h"

using namespace std;

int k, s;

int main() {
	cin >> k >> s;
	int ans = 0;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int buf = s - x - y;
			if (0 <= buf && buf <= k)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  rep(i, m) {
    pii p;
    cin >> p.fi >> p.se, --p.fi, --p.se;
    if (p.fi > p.se) swap(p.fi, p.se);
    mp[p.fi]++;
    mp[p.se]++;
  }
  rep(i, n) out(mp[i]);
}
int main(void) { solve(); }

Measured memory_bytes: 3616
using System;
using System.Collections;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        string[] sa = Console.ReadLine().Split(' ');
        int N = int.Parse(sa[0]);
        int M = int.Parse(sa[1]);
        sa = Console.ReadLine().Split(' ');
        int[] V = new int[M];

        for (int i = 0; i < M; i++)
            V[i] = int.Parse(sa[i]);

        Array.Sort(V);
        
        int[] D = new int[M];
        D[0] = 0;
        for (int i = 1; i < M ; i++)
            D[i] = V[i] - V[i - 1];
        
        Array.Sort(D);

        int s = 0;
        for (int i = 0; i < M - N; i++)
            s += D[i + 1];

        Console.WriteLine(s);
    }
}

Measured memory_bytes: 17376
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

int main() {
  // https://atcoder.jp/contests/dp/tasks/dp_a

  int N;
  cin >> N;
  vector<int> h(N+1);
  for (auto i = 1; i <= N; i++) {
    cin >> h[i];
  }

  // C[i] cost jump 1 -> i 
  vector<int> C(N+1, 0);
  C[0] = 0;
  C[1] = 0;
  C[2] = abs(h[2] - h[1]);

  for (int i=3; i <= N; i++ ) {
    C[i] = min( 
      C[i-2] + abs( h[i] - h[i-2] ),
      C[i-1] + abs( h[i] - h[i-1] )
     );
  }

  cout << C[N] << endl;

  return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

A, B = MAP()

# 上半分白、下半分黒
grid = list2d(100, 100, '.')
for i in range(50, 100):
    for j in range(100):
        grid[i][j] = '#'

A -= 1; B -= 1
# 黒の数だけ白い中に黒点
for i in range(0, 50, 2):
    for j in range(0, 100, 2):
        if B == 0:
            break
        grid[i][j] = '#'
        B -= 1
    else:
        continue
    break
# 白の数だけ黒い中に白点
for i in range(99, 49, -2):
    for j in range(0, 100, 2):
        if A == 0:
            break
        grid[i][j] = '.'
        A -= 1
    else:
        continue
    break

print(100, 100)
for i in range(100):
    print(''.join(grid[i]))


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

string s;
bool f;

int main(){
	cin >> s;
	f = true;
	for (size_t i = 0; i < s.size(); ++i){
		if ((s[i] == 'R' && i % 2 == 1) || (s[i] == 'L' && i % 2 == 0)){
			f = false;
			break;
		}
	}
	printf("%s\n", f ? "Yes" : "No");
}

Measured memory_bytes: 256
import java.io.{BufferedReader, InputStreamReader}

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val n = in.readLine().toInt
    val ls = in.readLine().split("\\s+").map(_.toInt).sorted

    def countWhile(index: Int, cond: Int => Boolean): Int = {
      @tailrec
      def inner(count: Int, index: Int): Int = {
        if (ls.length <= index) {
          count
        } else if (cond(ls(index))) {
          inner(count + 1, index + 1)
        } else {
          count
        }
      }

      inner(0, index)
    }

    var count = 0
    (0 until ls.length - 2).foreach(ai => {
      val a = ls(ai)
      ((ai + 1) until ls.length - 1).foreach(bi => {
        val b = ls(bi)
        val apb = a + b
        val amb = a - b
        count += countWhile(bi + 1, c => c < apb && amb < c && 0 < c + amb)
      })
    })
    System.out.println(count)
  }
}


Measured memory_bytes: 30292
N = int(input())
list_p = list(map(int, input().split()))
cnt = 0
for i in range(1, N-1):
    if list_p[i-1] < list_p[i] < list_p[i+1] or list_p[i+1] < list_p[i] < list_p[i-1]:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<queue>
#define mp make_pair 
using namespace std;
typedef long long ll;
typedef pair<ll,int>pa;
const ll INF=1LL<<61;
ll x[200010],a[200010];
struct que{
	priority_queue<pa>q;
	int flag[100010];
	void Push(pa x)
	{
		q.push(x);
	}
	pa Top()
	{
		while (!q.empty()&&flag[q.top().second]) q.pop();
		if (q.empty()) return mp(-INF,0);
		return q.top();
	}
	void Del(int pos)
	{
		flag[pos]=1;
	}
}Q1,Q2;
int main()
{
	int n;
	ll C;
	scanf("%d%lld",&n,&C);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&x[i],&a[i]);
	}
	ll val=0;
	for (int i=n;i;i--)
	{
		ll dist=C-x[i];
		val+=a[i];
		Q1.Push(mp(val-dist,i));
	}
	ll ans=max(0LL,Q1.Top().first);
	val=0;
	for (int i=1;i<=n;i++)
	{
		val+=a[i];
		ll dist=x[i];
		Q1.Del(i);
		ans=max(ans,val-dist-dist+Q1.Top().first);
	}
	val=0;
	for (int i=1;i<=n;i++)
	{
		ll dist=x[i];
		val+=a[i];
		Q2.Push(mp(val-dist,i));
	}
	ans=max(ans,Q2.Top().first);
	val=0;
	for (int i=n;i;i--)
	{
		val+=a[i];
		ll dist=C-x[i];
		Q2.Del(i);
		ans=max(ans,val-dist-dist+Q2.Top().first);
	}
	printf("%lld\n",ans);
	return 0;
 } 


Measured memory_bytes: 6768
#include<bits/stdc++.h>
using namespace std;
int a, b;
int main()
{
    //ios::sync_with_stdio(0);cin.tie(0);
    cin >> a >> b;
    if(a >= 13) cout << b;
    else if(a >= 6) cout << b / 2;
    else cout << 0;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] aArray = new int[n];
		for (int i = 0; i < n; i++) {
			aArray[i] = scan.nextInt();
		}

		int opeCount = 0;
		end: while (true) {
			for (int i = 0; i < n; i++) {
				if (aArray[i] % 2 == 0) {
					aArray[i] = aArray[i] / 2;
				} else {
					break end;
				}
			}
			opeCount++;
		}
		System.out.println(opeCount);

	}

}


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

int main() {
    string s; cin >> s;
    int n = (int)s.size();
    int ans = 0;
    for(int i = 0, j = n - i - 1; i <= j; ++i, --j) {
        if(s[i] != s[j]) ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
using namespace std;

inline int gcd_of_all(vi v){
  int l = v.size();

  int temp = v[0];
  for(int i = 0; i < l ; i++){
    temp = __gcd(temp,v[i]);
  }

  return temp;
}
int main(){
  int N;
  cin >> N;
  vi As(N);
  rep(i,N){
    cin >> As[i];
  }

  int ans = gcd_of_all(As);
  cout << ans << endl;

}


Measured memory_bytes: 1024
(let ((answer 0)
        (n (read))
        (m (read)))
    (let ((s (min n (truncate (/ m 2)))))
      (if (< s n)
          (setf answer s)
          (setf answer (+ s (truncate (/ (- m (* n 2)) 4))))))
    (print answer)
    (terpri))

Measured memory_bytes: 3688
import collections

n,m=map(int,input().split())
g=[[] for _ in range(n+1)]
for _ in range(m):
  a,b=map(int,input().split())
  g[a].append(b)
s,t=map(int,input().split())
check=[[0]*3 for _ in range(n+1)]
check[s][0]=1
q=collections.deque()
q.append([s,0])
ans=0
while len(q)!=0:
  v,c=q.popleft()
  if v==t and c%3==0:
    ans=c//3
    break
  for i in g[v]:
    if check[i][(c+1)%3]==0:
      q.append([i,c+1])
      check[i][(c+1)%3]=1
if ans==0:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 28568
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<cmath>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    int h[n];
    rep(i, n) cin >> h[i];
    int ans = 0;
    rep(i, 100){
        if(h[0] >= i + 1) ans++;
        rep(j, n - 1){
            if (h[j] < i + 1 && h[j+1] >= i + 1){
                ans++;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007;
inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}
inline int pl(int x,int y){return (x+=y)>=mod?x-=mod:x;}
inline int kpow(int a,long long b)
{
	int s=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)s=1ll*s*a%mod;
	return s;
}
int n,m;
long long k;
char mp[1010][1010];
struct matrix
{
	int a[2][2];
	friend matrix operator * (matrix a,matrix b)
	{
		static matrix c;
		#define calc(i,j) (1ll*a.a[i][0]*b.a[0][j]+1ll*a.a[i][1]*b.a[1][j])%mod
		for(int i=0;i<2;++i)
			for(int j=0;j<2;++j)
				c.a[i][j]=calc(i,j);
		return c;
		#undef calc
	}
}t,s;
int main()
{
	scanf("%d %d %lld",&n,&m,&k);
	for(int i=1;i<=n;++i)scanf("%s",mp[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			mp[i][j]=mp[i][j]=='#';
	bool flag1=0,flag2=0;
	for(int i=1;i<=n;++i)if(mp[i][1]&&mp[i][m])flag1=1;
	for(int i=1;i<=m;++i)if(mp[1][i]&&mp[n][i])flag2=1;
	if((flag1&&flag2)||k==0)return printf("1"),0;
	int c0=0,c1=0,c2=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			c0+=mp[i][j];
			if(mp[i][j]&&mp[i][j+1])++c1;
			if(mp[i][j]&&mp[i+1][j])++c2;
		}
	--k;
	if(!flag1&&!flag2)return printf("%d",kpow(c0,k)),0;
	s.a[0][0]=1;
	if(flag1)
	{
		t.a[0][0]=c0,t.a[0][1]=c1;
		for(int i=1;i<=n;++i)if(mp[i][1]&&mp[i][m])++t.a[1][1];
		for(;k;k>>=1,t=t*t)if(k&1)s=s*t;
	}
	else
	{
		t.a[0][0]=c0,t.a[0][1]=c2;
		for(int i=1;i<=m;++i)if(mp[1][i]&&mp[n][i])++t.a[1][1];
		for(;k;k>>=1,t=t*t)if(k&1)s=s*t;
	}
	printf("%d",pl(s.a[0][0],mod-s.a[0][1]));
	return 0;
}

Measured memory_bytes: 2708
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml.Schema;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public ulong NextUlong()
        {
            return ulong.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private int N, T;
        private int[] c, t;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            T = sc.NextInt();
            c = new int[N];
            t = new int[N];
            for (int i = 0; i < N; i++)
            {
                c[i] = sc.NextInt();
                t[i] = sc.NextInt();
            }
        }

        public void Solve()
        {
            Scan();
            int ans = int.MaxValue;
            for (int i = 0; i < N; i++)
            {
                if (t[i] <= T)
                {
                    ans = Math.Min(ans, c[i]);
                }
            }
            if (ans == int.MaxValue)
            {
                Console.WriteLine("TLE");
            }
            else
            {
                Console.WriteLine(ans);
            }
        }

        static void Main() => new Program().Solve();
    }
}

Measured memory_bytes: 13140
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int N = 60;
int n, d[N], ans;
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", d + i);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < i; j++)
			ans += d[i] * d[j];
	printf("%d", ans);	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
 
string S = "CODEFESTIVAL2016";

int main(){
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < 16; i++){
		if(s.at(i) != S.at(i)) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 5050, mlg = 17, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string s, t;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n >> s >> t;
	int ans = 2*n;
	for(int i = 0; i <= s.size(); i++) {
		int ok = 1;
		for(int x = i, y = 0; y < t.size() && x < s.size(); x++, y++) {
			ok &= s[x] == t[y];
		}
		if(ok) ans = min(ans, i+n);
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();
//16:13

int main(){
  int n; cin>>n;
  map<char,int> m;
  m['P']=0;
  m['W']=0;
  m['G']=0;
  m['Y']=0;

  REP(i,n){
    char s; cin>>s;
    m[s]+=1;
  }

if(m['Y'])cout<<"Four"<<endl;
else cout<<"Three"<<endl;
  
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.println(br.readLine().replace("apple", "**").replace("peach", "apple").replace("**", "peach"));
	}
}

Measured memory_bytes: 16876
#include<stdio.h>
int main(void){
    int H,W;
    
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0){
            break;
        }
        for(int row=0;row<H;row++){
            for(int col=0;col<W;col++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 2044
#include<cstdio>
#include<vector>
using namespace std;
int a[105];
vector<int> v;
int main(){
	int n,i,j,x;
	bool ok;
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%d",&x);
		v.push_back(x);
	}
	for(i=1;i<=n;++i){
		ok=0;
		for(j=v.size()-1;j>=0;--j)if(v[j]==j+1){
			a[i]=j+1;
			v.erase(v.begin()+j);
			ok=1;
			break;
		}
		if(!ok){
			puts("-1");
			return 0;
		}
	}
	for(i=n;i;--i)printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int i,n;
	
	for (n=1; n<10; n++){
		for (i=1; i<10; i++){
			printf("%dx%d=%d\n",n,i,n*i);
		}
	}
	
	return 0;

	
	
}

Measured memory_bytes: 524
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "YES"
#define NO  "NO"
#define MOD 1000000000+7
#define forit(v) for(auto it = v.begin(); it != v.end(); ++it)

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int a, b, c, d; cin >> a >> b >> c >> d;
  num = max(min(b, d) - max(a, c), 0);
  
  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


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

int main(void) {
  int a;
  scanf("%d",&a);
  int n = a;
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  if (a % sum == 0) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
	int i,s,o,n[4],q[4],toread,L,S,a,b,c,A;
	while(1){
		for(i=0;i<=3;i++){
			scanf("%1d",&n[i]);
			q[i]=n[i];
		}
		A=0;
		if(n[0]==n[1]&&n[1]==n[2]&&n[2]==n[3]){
			if(n[0]==0){
			break;
			}
			printf("NA\n");
		}
		else if(n[0]==6&&n[1]==1&&n[2]==7&&n[3]==4){
			printf("0\n");
		}
		else{
			for(s=0;A!=6174;s++){
			for(o=0;o<=3;o++){
				for(i=0;i<=3;i++){
					if(n[i]<n[o]){
						toread=n[i];
						n[i]=n[o];
						n[o]=toread;
					}
				}
			}
			L=n[0]*1000+n[1]*100+n[2]*10+n[3];
			for(o=0;o<=3;o++){
				for(i=0;i<=3;i++){
					if(n[i]>n[o]){
						toread=n[i];
						n[i]=n[o];
						n[o]=toread;
					}
				}
			}
			S=n[0]*1000+n[1]*100+n[2]*10+n[3];
			A=L-S;
			a=A/1000;
			n[0]=a;
			n[1]=(A-(n[0]*1000))/100;
			n[2]=(A-((n[0]*1000)+(n[1]*100)))/10;
			n[3]=A-((n[0]*1000)+(n[1]*100)+(n[2]*10));
			}
		printf("%d\n",s);
		}
	}
	return 0;
}

Measured memory_bytes: 608
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin>> s;
    if (n%2 == 1)
    {
        cout << "No" << endl;
        return 0;
    }

    for(int i=0;i<n/2;i++)
    {
        if (s[i]!=s[i+n/2])
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;

}




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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    int A, B;
    cin >> A >> B;
    for (int i = 1; i < 1150; ++i)
    {
        int eight = i * 0.08;
        int ten = i * 0.1;
        if (eight == A && ten == B)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */


/** Problem0558 : Cheese **/
int main()
{
	int H, W, N; cin>>H>>W>>N;
	char field[1000][1000];
	int sx, sy;
	rep(i, H) {
		rep(j, W) {
			cin>>field[j][i];
			if (field[j][i] == 'S') {
				sx = j, sy = i;
			}
		}
	}
	
	int ans=0;
	for (int i=0; i<N; i++) {
		queue<P> Q;
		int vis[1000][1000] = {0};
		Q.push(P(sx, sy));
		vis[sx][sy] = 0;
		
		while (Q.size()) {
			P p = Q.front(); Q.pop();
			if (field[p.first][p.second] == i+1+'0') {
				ans += vis[p.first][p.second];
				sx = p.first, sy = p.second;
				break;
			}
			
			for (int i=0; i<4; i++ ) {
				int nx = p.first+dx[i], ny = p.second+dy[i];
				if_range(nx, ny, W, H) {
					if (vis[nx][ny] == 0 && field[nx][ny]!='X') {
						vis[nx][ny] = vis[p.first][p.second]+1;
						Q.push(P(nx, ny));
					}
				}
			}
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 6104
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

int n;
ll p[100100];

ll a[100100];
ll b[100100];

set<int>st;
set<int>::iterator it;
set<int>::iterator it1;

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

    for(int i=0 ; i<n ;i++){
        a[i] = (i+1)*(n+1);
        b[i] = (n-i)*(n+1);
    }
    int sum = 0;
    for(int i=0 ; i<n ; i++){
        a[p[i]-1] += sum;
        sum++;
    }
    for(int i=0 ; i<n ; i++){
        if(i)
            printf(" ");
        printf("%d",a[i]);
    }
    cout<<"\n";
    for(int i=0 ; i<n ; i++){
        if(i)
            printf(" ");
        printf("%d",b[i]);
    }
    cout<<"\n";

    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int n,m,f[maxn*3],e[maxn];
int getf(int x)
{
	if(f[x]==x)return x;
	return f[x]=getf(f[x]);
}
int main()
{
	int x,y,tx,ty,a,b,opt,ans=0;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n*3;i++)f[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d %d %d",&x,&y,&opt);opt%=2;
		tx=x+n;ty=y+n;a=getf(x+2*n);b=getf(y+2*n);
		f[a]=b;
		if(!opt)
		{
			if(getf(x)==getf(ty))printf("0"),exit(0);
			f[getf(x)]=getf(y);f[getf(tx)]=getf(ty);
		}
		else
		{
			if(getf(x)==getf(y))printf("0"),exit(0);
			f[getf(x)]=getf(ty);f[getf(tx)]=getf(y);
		}
	}
	for(int i=2*n+1;i<=3*n;i++)if(f[i]==i)ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4972
#include<bits/stdc++.h>
using namespace std;
const int N(222222);
int ocr[N], le[N], ri[N];
int main() {
	int n;
	scanf("%d", &n);
	for(int i(1); i <= n; i++) {
		int x;
		scanf("%d", &x);
		ocr[x] = i;
	}
	for(int i(1); i <= n; i++) {
		le[i] = i == 1 ? 0 : i - 1;
		ri[i] = i == n ? n + 1 : i + 1;
	}
	le[0] = 0;
	ri[n + 1] = n + 1;
	long long ans(0);
	for(int i(n); i >= 1; i--) {
		int p(ocr[i]);
		//printf("%d %d %d %d\n", i, p, le[p], ri[p]);
		ans += (long long)i * (ri[p] - p) * (p - le[p]);
		ri[le[p]] = ri[p];
		le[ri[p]] = le[p];
	}
	cout << ans << endl;
}


Measured memory_bytes: 2560
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

bag = []
for i in range(X):
    bag.append(p[i])
for j in range(Y):
    bag.append(q[j])

bag = sorted(bag)
for i in range(len(bag)):
    if len(r) == 0:
        break
    if bag[i] < r[0]:
        bag[i] = r.pop(0)
        i += 1
    else:
        break

print(sum(bag))

Measured memory_bytes: 22720
package main

import "fmt"

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)

	if (b-a+1)/2 < k {
		for i := a; i <= b; i++ {
			fmt.Println(i)
		}
	} else {
		for i := a; i < a+k; i++ {
			fmt.Println(i)
		}
		for i := b - k + 1; i <= b; i++ {
			fmt.Println(i)
		}
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

ll pow2[100001];

void init() {
	pow2[0] = 1;
	for(int i = 0; i < 100000; i++) {
		pow2[i+1] = (pow2[i]*3LL)%MOD;
	}
	pow2[0] = 3;
}

int main() {
	string l;
	cin >> l;
	int n = l.size();
	init();
	ll ans = 0;
	ll base = 1;
	for(int i = 0; i < n; i++) {
		if(l[i]=='1') {
			ans = (ans+(pow2[n-i-1]*base)%MOD)%MOD;
			//cout << ans << endl;
			base = (base*2LL)%MOD;
		}
	}
	if(l[n-1]=='0') ans = (ans+base)%MOD;
	//ans = ((ans)%MOD+2)%MOD;
	//ans = ((ans)%MOD+1)%MOD;
	cout << ans << endl;
}


Measured memory_bytes: 1280
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    AB = [list(map(int, input().split())) for _ in range(n)]
    for i in range(n):
        a, b = AB[i]
        AB[i] = [a + b, a, b]
    AB.sort(key=lambda x: x[0], reverse=True)

    score_t, score_a = 0, 0
    for i in range(n):
        if i % 2 == 0:
            score_t += AB[i][1]
        else:
            score_a += AB[i][2]

    print(score_t - score_a)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 30580
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  bool flg = false;
  for (int i = 0; i < 10000; i++){
    int a = i * 8 / 100;
    int b = i * 10 / 100;
    if (a == A && b == B){
      flg = true;
      cout << i;
      break;
    }
  }
  if (!flg){
    cout << -1;
  }
}

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

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int a, b, c; readV(a, b, c);
  writeln(max(a*10+b+c, a+b*10+c, a+b+c*10));
}


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

int main() {
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  sort(all(a));
  int cnt = 0;
  rep(i, N) {
    x -= a[i];
    if(x >= 0)
      cnt++;
    if(x <= 0)
      break;
  }
  if(x > 0 && cnt > 0)
    cnt--;
  cout << cnt << endl;
}

Measured memory_bytes: 256
from collections import deque
import sys

input = sys.stdin.readline
N, q = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N-1)]

graph = [[] for i in range(N+1)]
for i,j in AB:
    graph[i].append(j)
    graph[j].append(i)

c = [0] * (N+1)
for i in range(q):
    p1 , x1 = map(int, input().split())
    c[p1] += x1
    
r = [-1 for i in range(N+1)] 
Q = deque()
Q.append(1)
r[1] = 0

while Q:
    x = Q.pop()
    for to in graph[x]:
        if r[to] == -1:
            c[to] += c[x]
            r[to] = 0 
            Q.append(to)

ans = ""
for i in range(1,N+1):
    ans += str(c[i]) + " "
print(ans)

Measured memory_bytes: 84052
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>
#include<queue>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 500005
#define M 200005
#define seed 23333

using namespace std;
priority_queue<int>Q;
int i,j,m,n,p[N],k,Max[N],st[N],ed[N],tree[N*4],Good[N],tot,ans[N];
void build_tree(int l,int r,int t)
{
		if (l==r) tree[t]=l;
		else 
		{
				build_tree(l,mid,ls); build_tree(mid+1,r,rs);
				tree[t]=p[tree[ls]]>p[tree[rs]]?tree[ls]:tree[rs];
		}
}
void FindMax(int &x,int ll,int rr,int l,int r,int t)
{
		if (ll<=l&&r<=rr)
		{
				if (p[tree[t]]>p[x]) x=tree[t];
		}
		else 
		{
				if (ll<=mid) FindMax(x,ll,rr,l,mid,ls);
				if (rr>mid)  FindMax(x,ll,rr,mid+1,r,rs);
		}
}
void upd(int ll,int l,int r,int t)
{
		if (l==r) return;
		if (ll<=mid) upd(ll,l,mid,ls);
		else upd(ll,mid+1,r,rs);
		tree[t]=p[tree[ls]]>p[tree[rs]]?tree[ls]:tree[rs];
}
int check(int x)
{
		if (!p[x]) return 0;
		int g=0;
		FindMax(g,max(1,x-k+1),min(n,x+k-1),1,n,1);
		if (g==x) return 1;
		return 0;
}
int main()
{
	scanf("%d%d",&n,&k);
	for (i=1;i<=n;++i) scanf("%d",&p[i]);
	build_tree(1,n,1); 
	for (i=1;i<=n;i=ed[tot]+1)
	{
			st[++tot]=i;
			ed[tot]=min(n,i+k-1);
	}
	for (i=1;i<=tot;++i)
	{
			FindMax(Max[i],st[i],ed[i],1,n,1);
			if (check(Max[i])) Good[i]=1,Q.push(Max[i]);
	}
	for (i=n;i;--i)
	{
			int x=Q.top(); Q.pop();
			ans[x]=i;
			int bl=(x-1)/k+1;
			p[Max[bl]]=0;
			Good[bl]=0;
			upd(Max[bl],1,n,1);
			FindMax(Max[bl],st[bl],ed[bl],1,n,1);
			if (check(Max[bl])) Good[bl]=1,Q.push(Max[bl]);
			if (!Good[bl-1]&&check(Max[bl-1])) Good[bl-1]=1,Q.push(Max[bl-1]);
			if (!Good[bl+1]&&check(Max[bl+1])) Good[bl+1]=1,Q.push(Max[bl+1]);
	}
	for (i=1;i<=n;++i) printf("%d\n",ans[i]);
}


Measured memory_bytes: 21488