akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

bool chmin(long long& a, long long b) {
    if( a > b ) {
        a = b;
        return true;
    }
    return false;
}

bool chmax(long long& a, long long b) {
    if( a < b ) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    // INPUT
    int N = 0;
    cin >> N;
    vector<vector<long long>> happiness(N, vector<long long>(3));
    for(int i=0; i < N; i++) {
        cin >> happiness[i][0] >> happiness[i][1] >> happiness[i][2];
    }
    vector<vector<long long>> total(N+1, vector<long long>(3, 0));

    // SOURCE
    for(int i=1; i < N+1; i++) {
        for(int j=0; j < 3; j++) {
            for(int k=0; k < 3; k++) {
                if(j != k) chmax(total[i][j], total[i-1][k] + happiness[i-1][j]);
            }
        }
    }
    long long ans = 0;
    for(int i=0; i<3; i++) {
        chmax(ans, total[N][i]);
    }

    // OUTPUT
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <vector>

#define SIZE 8
#define INF  10000000

int N;
int A, B, C;
int bamboo[SIZE];
int ans = INF;


int dfs(int idx, int a, int b, int c) {
    if (idx == N) {
        if ( std::min( a, std::min(b, c) ) > 0 ) {
            return std::abs(a - A) + std::abs(b - B) + std::abs(c - C) - 30;
        } else {
            return INF;
        }
    }
    int res0 = dfs(idx+1, a, b, c);
    int res1 = dfs(idx+1, a+bamboo[idx], b, c) + 10;
    int res2 = dfs(idx+1, a, b+bamboo[idx], c) + 10;
    int res3 = dfs(idx+1, a, b, c+bamboo[idx]) + 10;
    return std::min( res0, std::min(res1, std::min(res2, res3)) );
}

void solve() {
    ans = dfs(0, 0, 0, 0);
    std::cout << ans << std::endl;
}

int main() {
    std::cin >> N >> A >> B >> C;
    for (int i=0; i<N; ++i) std::cin >> bamboo[i];
    solve();
    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 ll;

int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
        
    char left=s[0];
    ll cnt=1;
    for(ll i=1;i<n;++i){
        if(s[i-1] != s[i]){
            ++cnt;
        }
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 512
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define lu unsigned long long int
#define pi pair<ll, ll>
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for (ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define be begin
#define sz(a) (ll)(a.size())
#define INF 1e18
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

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

// ll mod = 1e9+7;

// ll mult(ll x, ll y){
//     ll rem=1;
//     while(y){
//         if(y&1){
//             rem=(rem*x)%mod;
//         }
//         x=(x*x)%mod;
//         y>>=1;
//     }
//     return rem;
// }


void solve(ll T){
	ll h,w,m;
	cin>>h>>w>>m;
	ve<set<ll>>ar(300001);
	priority_queue<pi>pq;
	{
		map<ll,ll, greater<ll>>mp;
		lr(m){
			ll x,y;
			cin>>x>>y;
			ar[x].insert(y);
			mp[y]++;
		}
		for(auto i:mp){
			pq.push({i.se, i.fi});
		}
	}
	ll ans = 0;
	for(ll i=1;i<=300000;i++){
		ll x=pq.top().fi-1;
		queue<pi>q;
		while(!pq.empty() && ar[i].find(pq.top().se) != ar[i].end()){
			q.push(pq.top()); pq.pop();
		}
		if(!pq.empty()){
			x=max(pq.top().fi, x);
		}
		while(!q.empty()){
			pq.push(q.front()); q.pop();
		}
		x+=sz(ar[i]);
		ans=max(ans, x);
	}
	cout << ans << "\n";
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// std::cout << std::unitbuf;
	ll T=1;
	// cin>>T;
	for(ll t=1;t<=T;t++){
		solve(t);
	}
	return 0;
}


Measured memory_bytes: 58484
import java.util.Scanner

/**
 * Created by sonetsuyoshi on 2015/12/16.
 */
object Main extends App {
  val sc = new Scanner(System.in)
  val (n, m) = (sc.nextInt, sc.nextInt)
  val a = Array.ofDim[Long](n)
  val b = Array.ofDim[Long](n)

  val s = Array.ofDim[Long](n + 1)
  val t = Array.ofDim[Long](n + 1)

  for(i <- 0 until n) {
    a(i) = sc.nextLong()
    b(i) = Math.max(0, a(i))

    t(i + 1) = t(i) + a(i)
    s(i + 1) = s(i) + b(i)
  }

  def partialSum(i: Int, j: Int, sum: Array[Long]):Long = {
    sum(j) - sum(i)
  }

  val ans = (for(i <- 0 to n - m) yield partialSum(0, i, s) + Math.max(partialSum(i, i + m, t), 0) + partialSum(i + m, n, s)).max
  println(ans)
}

Measured memory_bytes: 56672
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;


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

	bool judge = true;
	int s[3] = {-1, -1, -1};
	int sm, tm;
	rep(i, M) {
			cin >> sm >> tm;
			if (s[sm - 1] != -1 && s[sm - 1] != tm) {
				judge = false;
				break;
			}
			else {
				s[sm - 1] = tm;
			}
	}

	if (s[0] == 0 && N != 1) judge = false;
	if (s[0] == -1 && N != 1) s[0] = 1;

	int ans = -1;
	if (judge) {
		ans = 0;
		rep(i, N) {
			if (s[i] == -1){
				s[i] = 0;
			}
			ans += s[i] * pow(10, (N - i - 1));
		}
	}

	cout << ans << endl;

	return 0;
} 

Measured memory_bytes: 3744
N,M=map(int,input().split())
A=[]  
B=[]
for i in range(M) :
  L=list(map(int,input().split()))
  A.append(L)
  B.append(L)
B.sort()
P=1
Q=1
for m in range(M):
  if B[m][0]==P :
    B[m].append(Q)
  else :
    Q=1
    B[m].append(Q)
  P=B[m][0]
  Q+=1
for i in A :
  X=str(i[0])
  Y=str(i[2])
  print("0"*(6-len(X))+X+"0"*(6-len(Y))+Y)


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

int calc(int i) {
	int N = i;
	int d[201] = { 0 };
	int j = 2;
	while (i > 1) {
		if (i%j == 0) {
			d[j]++;
			i /= j;
		}
		else {
			j++;
		}
	}

	int num = 1;
	for (int j = 2; j <= N; j++) {
		if (d[j]>0) num *= (d[j] + 1);
	}

	return num;
}

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

	int count = 0;
	for (int i = 2; i <= N; i++) {
		if (i % 2 != 0) {
			int num = calc(i);
			if (num == 8)count++;
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <set>


int main() {
	int n; std::cin >> n;
	std::vector<int> papers(n); for (auto& t : papers) std::cin >> t;
	const auto sum = std::accumulate(papers.begin(), papers.end(), 0);
	std::vector<std::vector<std::vector<bool>>> memo(n + 1, std::vector<std::vector<bool>>((sum + 2) / 3 + 51, std::vector<bool>((sum + 2) / 3 + 1, false)));
	memo[0][0][0] = true;
	for (auto i = 0; i < papers.size(); ++i) {
		for (auto j = 0; j < memo[i].size(); ++j) {
			for (auto k = 0; k < memo[i][j].size(); ++k) {
				bool res = memo[i][j][k];
				if (j >= papers[i]) {
					res = res || memo[i][j - papers[i]][k];
				}
				if (k >= papers[i]) {
					res = res || memo[i][j][k - papers[i]];
				}
				memo[i + 1][j][k] = res;
			}
		}
	}
	for (auto i = sum / 3; i < memo.back().size(); ++i) {
		for (auto j = std::max(0, sum - i * 2); j < memo.back()[i].size() && j <= sum - i - j; ++j) {
			if (memo.back()[i][j]) {
				std::cout << i << '\n';
				return 0;
			}
		}
	}
}



Measured memory_bytes: 9504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

bool pattern[110][10100];
int pos[110];
int n,m;

void solve() {
while (cin >> n >> m) {
    if (n == 0 && m == 0) break;
    
    for (int i = 0; i < n; i++) {
        pos[i] = 0;
        vector<int> v;
        int k;
        while (cin >> k, k) {
            v.pb(k);
        }
        int p = 0;
        bool status = 0;
        int vv = 0;
        while (p <= 10090) {
            int kk = v[vv];
            REP(j,kk) {
                if (p + 1 >= 10100) break;
                pattern[i][p++] = status;
            }
            vv = (vv + 1) % sz(v);
            status = !status;
        }
    }

    ll ans = 0;
    bool inque[110] = {};
    queue<int> que;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (!pattern[j][pos[j]]) pos[j]++;
            else {
                if (!inque[j]) {
                    que.push(j);
                    inque[j] = 1;
                }
            }
        }
        if (!que.empty()) {
            pos[que.front()]++;
            ans += que.size() - 1;
            if (pattern[que.front()][pos[que.front()]] == 0) {
                inque[que.front()] = 0;
                que.pop();
            }
        }
        // REP(j,n) {
        //     cout << pos[j] << " ";
        // }
        // cout << endl;
    }
    cout << ans << endl;
}
}


int main(int argc, char *argv[]){

    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }

    /* AOJ */
    solve();

    return 0;
}


Measured memory_bytes: 4036
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  ll N, M;
  cin >> N >> M;
  vector<ll> solved(N,0);
  vector<ll> wrong(N,0);

  ll p;
  string S;

  ll cor = 0;
  ll pen = 0;
  REP(i, M){
    cin >> p >> S;
    p--;
    if (solved[p] == 1) continue;
    if (S=="AC"){
      solved[p] = 1;
      pen += wrong[p];
      cor++;
    } else {
      wrong[p]++;
    }
  }

  cout << cor << " " << pen << "\n";
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#define N 200000
 
int main(){
 
  int i,n,maxv,minv;
  int arr[N];
   
  scanf("%d",&n);
   
  for(i=0;i<n;i++){
    scanf("%d",&arr[i]);
  }
   
  maxv = arr[1] - arr[0];
  minv = arr[0];
   
  for(i=1;i<n;i++){
    if(maxv<arr[i]-minv){  
    maxv = arr[i]-minv;
    }
    if(minv>arr[i]){
      minv = arr[i];
    }
  }
     
  printf("%d\n",maxv);
 
  return 0;
}


Measured memory_bytes: 2620
#include<stdio.h>
int main(){
  int m,f,b;
  scanf("%d%d%d",&m,&f,&b);
  if(m<b){
    m = b-m;
    //printf("%d\n",m);
    if(m<=f){
      printf("%d\n",m);
    }
    else printf("NA\n");
  }
  else printf("0\n");
    
  return 0;
}



Measured memory_bytes: 2140
#define lp(i,n) for(int i=0;i<n;i++)
#define pau system("pause")
#include<bits/stdc++.h>

using namespace std;
int main(){
   string s[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
   string a;
   cin>>a;
   lp(i,7){
       if(a==s[6]){
           cout<<7<<endl;
           break;
       }
        else if(a==s[i]){
            cout<<6-i<<endl;
            break;
        }
   }
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100

int N,A[MAX];

void print(){
    int i;
    for(i=0;i<N;i++){
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

void sort(){
    int j,i,val;
    for(i=1;i<N;i++){
        val=A[i];
        j=i-1;
        while((j>=0)&&(A[j]>val)){
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=val;
        print();
        }
    }
    
int main(void){
    int i,j;
    
    scanf("%d",&N);
    for(i=0;i<N;i++){
     scanf("%d",&A[i]);
    }
    print();
    sort();
    
    return 0;
}    


Measured memory_bytes: 2044
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

void cout_vec(vector<int> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int find_all(string str, string subStr){
    int ret=0;

    int pos=str.find(subStr);
    int subStrSize=subStr.size();

    while(pos!=string::npos){
        ret++;
        pos=str.find(subStr,pos+subStrSize);
    }
    return ret;
}

int main(){
    int N;
    cin >> N;
    vector<string> s(N,"");

    int cntA, cntB, cnt;
    cntA=cntB=cnt=0;
    int ans=0;
    for(int i=0; i<N; i++){
        cin >> s[i];
        //cout << s[i] << endl;
        ans+=find_all(s[i], "AB");
        
        int size_=s[i].size();
        if(s[i][0]=='B' && s[i][size_-1]=='A'){
            cnt++;
        }
        if(s[i][0]=='B'){
            cntB++;
        }
        if(s[i][size_-1]=='A'){
            cntA++;
        }
    }
    if(cnt>=2){
        ans+=cnt-1;
        cntA-=cnt-1;
        cntB-=cnt-1;
        cnt=1;
    }
    if(cnt==1 && cntA==1 && cntB==1){
        cout<< ans << endl;
        return 0;
    }
    ans+=min(cntA,cntB);
    cout << ans << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(obj) (obj).begin(), (obj).end() //イテレータの簡略化（コンテナじゃないと使えない）
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 100100100;

// 最大公約数
int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

// 最小公倍数
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

/* 二分探索 */

//indexが条件を満たすかどうか
bool isOK(int index, int key, vector<int> a) {
    if (a[index] >= key) return true;
    else return false;
}

//汎用的な二分探索のテンプレ
int meguru_binary_search(int key, vector<int> A){
    int ng = -1; // lowerの時は-1, upperの時は(int)A.size() //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)A.size(); // lowerの時は(int)A.size(), upperの時は-1 // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if(isOK(mid, key, A)) ok = mid;
        else ng = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている(lowerだと) */
    return ok;
}
/* lower_boundとかでイテレータから配列の添え字を求めたいとき(lower_bound(v.begin(),v.end(),hoge)-v.begin())というようにする */
//distanceも使える

//三項演算子 ?:

int main(void){
    string s;
    int n, k;
    cin >> n >> s >> k;
    char moji = s[k - 1];
    REP(i, n) {
        if(s[i] != moji) s[i] = '*';
    }
    cout << s << endl;
    
}

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

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define int double
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
const ll mod = 1e9+7;
const int MAXN = 2e5+5;

int32_t main() {
	int n;
	cin >> n;
	priority_queue<double, vector<double>, greater<double>> fila;
	
	while(n--) {
		int x;
		cin >> x;
		fila.push(x);
	}
	while(fila.size() > 1.0) {
		double x = fila.top();
		fila.pop();
		double y = fila.top();
		fila.pop();
		fila.push((x+y)/2.0);
	}
	cout << fila.top() << endl;
}


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

int findsum(int n){
  int sum = 0;
  while(n > 0){
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int count = 0;
  int sum;
  for(int i = 1; i <= N; i++){
    sum = findsum(i);
    if(sum >= A && sum <= B){
      count += i;
    }
  }
  cout << count << endl;
}
  


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    task = []
    for _ in range(n):
        a, b = mi()
        task.append([a, b])
    task.sort(key=lambda x: x[1])
    t = max(task, key=lambda x: x[1])[1]
    while task:
        required_slot, end = task.pop()
        # time slot が時間軸の後ろ側へしシフトするのは許されない
        if t > end:
            t = end
        t -= required_slot
    print('No') if t < 0 else print('Yes')



if __name__ == "__main__":
    main()

Measured memory_bytes: 38064
#include<stdio.h>

void func(int);

int main(void)
{
	int n;
	scanf("%d",&n);
	while(n!=0) {
		func(n);
		scanf("%d",&n);
	}
	return 0;
}
void func(int n)
{
	int xg,yg,x,y;
	int map[21][21];
	int i,j,m,l;
	char d;
	int cnt;
	for(i=0;i<=20;i++) {
		for(j=0;j<=20;j++) {
			map[i][j]=0;
		}
	}
	for(i=0;i<n;i++) {
		scanf("%d %d",&xg,&yg);
		map[yg][xg]=1;
	}
	scanf("%d",&m);
	x=10;
	y=10;
	cnt=0;
	for(i=0;i<m;i++) {
		scanf(" %c %d",&d,&l);
		if(d=='N') {
			for(j=0;j<l;j++) {
				y++;
				if(map[y][x]==1) {
					cnt++;
					map[y][x]=0;
				}
			}
		}
		if(d=='S') {
			for(j=0;j<l;j++) {
				y--;
				if(map[y][x]==1) {
					cnt++;
					map[y][x]=0;
				}
			}
		}
		if(d=='E') {
			for(j=0;j<l;j++) {
				x++;
				if(map[y][x]==1) {
					cnt++;
					map[y][x]=0;
				}
			}
		}
		if(d=='W') {
			for(j=0;j<l;j++) {
				x--;
				if(map[y][x]==1) {
					cnt++;
					map[y][x]=0;
				}
			}
		}
	}
	if(cnt==n) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
}

Measured memory_bytes: 584
N, M = map(int, input().split())
AB = [[int(i) for i in input().split()] for i in range(N)]
AB.sort(key=lambda x: x[0])
min_pay = 0
num_buy = 0

for n in range(N):
    cost = AB[n][0]
    max_buy = AB[n][1]
    for mb in range(max_buy):
        min_pay += cost
        num_buy += 1
        if num_buy == M:
            print(min_pay)
            exit()


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

struct Node{
	int key;
	Node *parent, *left, *right;
};
Node *root, *NIL;
void insert(int x);
void Inorder(Node *u);
void Preorder(Node *u);
Node *Find(Node *u, int t);
void delete_(Node *u);
Node *getSuccessor(Node *u);
int main()
{
	int n, t;
	string s;
	cin >> n;
	while(n--){
		cin >> s;
		if(s == "insert"){
			cin >> t;
			insert(t);
		}
		else if(s == "print"){
			Inorder(root);
			printf("\n");
			Preorder(root);
			printf("\n");
		}
		else if(s == "find"){
			cin >> t;
			if(Find(root, t) != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if(s == "delete"){
			cin >> t;
			delete_(Find(root, t));
		} 
	}
	return 0;
}
void insert(int t){
	Node *z, *y = NIL, *x = root;
	z = (Node *)malloc(sizeof(Node));//神奇了 ,不加不行？？？？？？ 
	z -> key = t;
	z -> left = NIL;
	z -> right = NIL;
	while(x != NIL){
		y = x;
		if(t < x -> key){
			x = x -> left;
		}
		else x = x -> right;
	}
	z -> parent = y;
	if(y == NIL) root = z;
	else{
		if(t < y -> key) y -> left = z;
		else y -> right = z;
	}
}

void Inorder(Node *u){
	if(u == NIL) return;
	Inorder(u -> left);
	printf(" %d", u -> key);
	Inorder(u -> right);
}

void Preorder(Node *u){
	if(u == NIL) return;
	printf(" %d", u -> key);
	Preorder(u -> left);
	Preorder(u -> right);
}
Node* Find(Node *u, int t){
	if(u == NIL) return false;
	if(t == u -> key) return u;
	else if(t > u -> key) return Find(u -> right, t);
	else return Find(u -> left, t);
}
void delete_(Node *u){
	Node *x, *y;
	if(u -> left == NIL || u -> right == NIL){
		y = u;		
	}
	else{
		y = getSuccessor(u); 
	}
	if(y -> left != NIL) x = y -> left;
	else x = y -> right;
	if(x != NIL) x -> parent = y -> parent;	
 	if(y -> parent == NIL) root = x;
	else if(y -> parent -> left == y) y -> parent -> left = x;
	else y -> parent -> right = x;
	u -> key = y -> key;
	free(y); 
}
Node *getSuccessor(Node *u){
	Node *y = u -> right;
	while(y -> left != NIL) y = y -> left;
	return y;
}


Measured memory_bytes: 21972
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int q;
    cin>>q;
    multiset<int>lo,hi;
    int sl=0,sh=0;
    int mid=0,cnt=0,bsum=0;
    while(q--)
    {
        int typ;
        cin>>typ;
        if(typ==1)
        {
           int x,y;
           cin>>x>>y;
           bsum+=y;
           cnt++;
           if(cnt==1)
           {
               mid=x;continue;
           }
           if(hi.size()>lo.size())
           {
              if(x>=mid)
              {
                  hi.insert(x);
                  int val=*hi.begin();
                  hi.erase(hi.begin());
                  sh+=x;
                  sh-=val;
                  sl+=mid;
                  lo.insert(mid);
                  mid=val;
              }
              else
              {
                  lo.insert(x);
                  sl+=x;
              }
           }
           else
           {
               if(x>mid)
               {
                   hi.insert(x);
                   sh+=x;
               }
               else
               {
                   lo.insert(x);
                   int val=*lo.rbegin();
                   lo.erase(lo.find(val));
                   sl+=x;
                   sl-=val;
                   sh+=mid;
                   hi.insert(mid);
                   mid=val;
               }
           }

        }
        else
        {
            int ses=mid*lo.size()-sl;
            ses+=bsum;
            ses+=(sh-hi.size()*mid);
            cout<<mid<<" "<<ses<<"\n";
        }
    }
    return 0;

}





































Measured memory_bytes: 12972
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define debug(x) #x << " = " << (x) << " (L" << __LINE__ << ")"

typedef long long ll;
typedef vector<int> vi;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& val){
    os << "[ ";
    for(typename vector<T>::const_iterator it=val.begin();
        it != val.end();++it){
        os << *it << " ";
    }
    os << "]";
    return os;
}

pair<int,int> solve(ll a,ll b,ll d){
    int mini = 100000000;
    int minf = 100000000;
    int ra=-1,rb=-1;
    for(int u_a=-10000;u_a<=10000;u_a++){
        int td = d + a * u_a;
        if(td < 0) td = -td;
        if(td % b == 0){
            int u_b = td / b;
            int a_u_a = abs(u_a);
            int a_u_b = abs(u_b);
            int used = a_u_a + a_u_b;
            if(mini > used or
               (mini == used and minf > a * a_u_a + b * a_u_b)){
                mini = used;
                minf = a * a_u_a + b * a_u_b;
                ra = a_u_a;rb = a_u_b;
                // cerr << debug(a_u_a) << debug(a_u_b) << endl;
            }
        }
    }
    return make_pair(ra,rb);
}

int main(){
    while(true){
        int a,b,d;
        cin >> a >> b >> d;
        if(a == 0 and b == 0 and d == 0) break;
        pair<int,int> ret = solve(a,b,d);
        cout << ret.first << " " << ret.second << endl;
    }
    return 0;
}

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

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

    vector<char> v(52, '#');

    for(int i = 0; i < n; i++){
        char m;
        int num;
        cin >> m >> num;

        if(m == 'S'){
            v[num - 1] = 'S';
        }
        if(m == 'H'){
            v[num - 1 + 13] = 'H';
        }
        if(m == 'C'){
            v[num - 1 + 26] = 'C';
        }
        if(m == 'D'){
            v[num - 1 + 39] = 'D';
        }
    }
    for(int i = 0; i < 52; i++){
        if(v[i] == '#'){
            if(i >= 0 && i < 13){
                cout << 'S' << " " << i + 1 << endl;
            }
            if(i >= 13 && i < 26){
                cout << 'H' << " " << i + 1 - 13 << endl;
            }
            if(i >= 26 && i < 39){
                cout << 'C' << " " << i + 1 - 26 << endl;
            }
            if(i >= 39 && i < 52){
                cout << 'D' << " " << i + 1 - 39 << endl;
            }
        }
    }
}    


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    ll A,B,K;
    cin >> A >> B >> K;
    ll ansA = A;
    ll ansB = B;

    if(A > 0){
        ansA = A - K;
        K = K - A;
    }

    if(ansA <= 0 ){
        ansA = 0;
    }

    if(B > 0 && ansA == 0){
        ansB = B - K;
    }

    if(ansB <= 0 ){
        ansB = 0;
    }

    cout << ansA << " " << ansB << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
///...................................*****.................................................///
///        Author :  MD. Rakibul Islam ( mmdrakibul2912@gmail.com )                         ///
///                  Department of Computer Science                                         ///
///                  & Engineering,                                                         ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///
using namespace std;
int main()
{
    int n, m, i;
    string s;
    cin>>n>>m;
    cin>>s;
    for(i=0; i<s.size(); i++)
    {
        if(i+1==m)
        {
            char c;
            c=s[i]+32;
            cout<<c;
        }
        else
            cout<<s[i];
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int k,n,i,j;
  set<string> z;
  cin>>s>>k;
  n=s.length();
  for(i=0;i<n;i++) for(j=1;j<=min(n-i,5);j++) z.insert(s.substr(i,j));
  cout<<*next(z.begin(),k-1)<<endl;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MM=1000000007;
 
int main() {
  int N;
  ll K;
  cin >> N;
  cin >> K;
 
  int A[N];
  rep(i,N){
    cin >> A[i];
  }
 
  ll b[N]={};
  ll c[N]={};
 
 
  rep(i,N){
    rep(j,N){
      if(A[i] > A[j] && i > j ) b[i]++;
      if(A[i] > A[j] && i < j ) c[i]++;
    }
  }
 

 
  ll ans = 0;
 
  rep(i,N){
    ll x0 = (K * (K + 1) / 2) % MM;
    ll y0 = (K * (K - 1) / 2) % MM;
    ll x1 = (c[i] * x0) % MM;
    ll y1 = (b[i] * y0) % MM;
    ll z = (x1 + y1) % MM;
    ans = (ans + z) % MM;
  }
 
 
  cout << ans << endl;
 
 
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775807LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;
vi a;


ll solve(ll mid,ll &minout){
  ll muno;
  ll y;
  ll num;
  ll gk=0;
  REP(i,n){
    muno=a[i];
    if (muno>=1LL){//mid以下の数値がいくつあるか
      y=mid/muno;
      //if (mid%muno<0)y--;
      if (y*muno>mid)y--;
      
      //y以下の数を求めたい
      auto Iter2 = upper_bound(a.begin(),a.end(), y);
      num=(Iter2-a.begin());
      
      if (muno<=y)num--;
    }else{
      if (muno!=0LL){//y以上の数値がいくつあるか
        y=mid/muno;
        if (y*muno>mid)y++;

        //y未満の数を求めたい
        auto Iter2 = lower_bound(a.begin(),a.end(), y);
        num=(Iter2-a.begin());

        num=n-num;
        if (muno>=y)num--;

      }else{
        if (mid>=0){
          num=n-1;
        }else{
          num=0;
        }
      }
    }

    gk+=num;
  }
  return gk/2;
}



int main(){
  ll ans=0;
  cin >> n >> k;
  
  a.resize(n);
  REP(i,n) cin>>a[i];
  sort(a.begin(), a.end());

 //2分岐探索
 ll ok=1000000000000000000LL;//解が存在する値
 ll ng=-1000000000000000001LL;//解が存在しない値
 ll mid;


while(abs(ok-ng)>1)
{
  mid=(ok+ng)/2;
  ans=llMIN;
  if (k<=solve(mid,ans))//これを満たす最小のmidがokになる
  {
    ok=mid;
  }
  else
  {
    ng=mid;
  }
}

cout<<ok<<endl;

  return 0;
}

Measured memory_bytes: 1792
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var n = parseInt(input[0][0], 10);
    var originalN = n;
    var v_ans = [];
    var start = 2;
    whole_loop:
    while (true){
        for (var i = start; i <= Math.sqrt(n); i++){
            if (n % i === 0) {
                v_ans.push(i);
                n /= i;
                start = i;
                continue whole_loop;
            }
        }
        v_ans.push(n);
        break;
    }
    console.log(originalN.toString() + ": " + v_ans.join(" "));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 16444
#include<stdio.h>
#include<string.h>
int a,b,c,d;
int cur;
char str[100];
int form(){
    if(str[cur]=='a'){return a;}
    if(str[cur]=='b'){return b;}
    if(str[cur]=='c'){return c;}
    if(str[cur]=='d'){return d;}
    if(str[cur]==']'){
        cur++;
        return form();
    }
    if(str[cur]=='['){
        cur++;
        if(str[cur]=='+'){
            cur++;
            int L=form();
            cur++;
            int R=form();
            return L|R;
        }
        if(str[cur]=='*'){
            cur++;
            int L=form();
            cur++;
            int R=form();
            return L&R;
        }
        if(str[cur]=='^'){
            cur++;
            int L=form();
            cur++;
            int R=form();
            return L^R;
        }
    }
    return 0;
}
int main(void){
    while(1){
        scanf("%s",str);
        if(str[0]=='.') break;
        getchar();
        char abcd[10];
        scanf("%s",abcd); getchar();
        a=abcd[0]-'0'; b=abcd[1]-'0'; c=abcd[2]-'0'; d=abcd[3]-'0';
        cur=0;
        int hash=form();
        int cnt=0;
        for(a=0;a<=9;a++){
            for(b=0;b<=9;b++){
                for(c=0;c<=9;c++){
                    for(d=0;d<=9;d++){
                        cur=0;
                        if(hash==form()){
                            cnt++;
                        }
                    }
                }
            }
        }
        printf("%d %d\n",hash,cnt);
    }
}



Measured memory_bytes: 2048
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class BinaryIndexedTree
{
private:
    typedef long long T;
    int n;
    vector<T> data;
public:
    // コンストラクタ
    BinaryIndexedTree(int n){
        this->n = n;
        data.assign(n+1, 0);
    }
    // k番目の要素にxを加算する
    void add(int k, T x){
        ++ k;
        while(k <= n){
            data[k] += x;
            k += k & -k;
        }
    }
    // 区間[0,k)の総和を返す
    T sum(int k){
        T ret = 0;
        while(k > 0){
            ret += data[k];
            k -= k & -k;
        }
        return ret;
    }
    // 区間[a,b)の総和を返す
    T sum(int a, int b){
        return sum(b) - sum(a);
    }
};

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

    BinaryIndexedTree bit(n);
    for(int i=0; i<n; ++i){
        int a;
        cin >> a;
        bit.add(i, a);
    }

    for(int i=0; i<q; ++i){
        int t, x, y;
        cin >> t >> x >> y;

        if(t == 0)
            bit.add(x, y);
        else
            cout << bit.sum(x, y) << endl;
    }

    return 0;
}


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

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    ll a, b;
    double num;
    cin >> a >> b;
    for (int i = 1; i <= 100; i *= 10) {
        if (b / i == 0) {
            num = a * i + b;
            break;
        }

        if (i == 100) {
            num = a * i*10 + b;
        }
    }

    double n = sqrt(num);
    int n_i = n;
    if (n == n_i) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
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; }

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

const ll MOD = 1e9 + 7;
const int SIZE = 200010;

ll f[SIZE];
void init() {
    f[0] = 1;
    for(int i = 1; i< SIZE; i++) f[i] = (f[i - 1] * i) % MOD;
}

ll inv(ll x) {
    ll res = 1;
    ll k = MOD - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}

ll pow_mod(ll n, ll k, ll m){
    if(k==0)return 1;
    else if(k%2==1){
        return pow_mod(n, k-1, m)*n %m;
    }else{
        ll t = pow_mod(n, k/2, m);
        return t*t%m;
    }
}

int main() {
    init();
    ll n, a, b;
    cin>>n>>a>>b;

    ll all = pow_mod(2, n, MOD);
    ll x = 1;
    for (ll i = n; i > n-a ; --i) {
        x = (x*i)%MOD;
    }
    x = (x * inv(f[a])) %MOD;

    ll y = 1;
    for (ll i = n; i > n-b ; --i) {
        y = (y*i)%MOD;
    }
    y = (y*inv(f[b]))%MOD;

    ll ans = (all - x - y - 1)%MOD;
    if(ans >= 0){
        cout<<ans%MOD<<endl;
    }else{
        cout<<(ans + MOD)<<endl;
    }

    return 0;
}

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

def solve():
    """ DP """
    N = int(input())
    H = list(map(int, input().split()))

    INF = 10**4+10
    dp = [INF]*(N+10)
    dp[0] = 0
    dp[1] = abs(H[1] - H[0])
    for i in range(2, N):
        dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))
    
    print(dp[N-1])


def solve2():
    """ メモ化再帰 
    N=1000以上で RecursionError: maximum recursion depth exceeded in comparison

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    """
    import sys
    sys.setrecursionlimit(10**5+10)  # RecursionError対策

    N = int(input())
    H = list(map(int, input().split()))

    INF = 10**14+10
    dp = [INF] * (N+10)
    dp[0] = 0
    dp[1] = abs(H[0]-H[1])

    def dfs(i):
        """ 足場iの時点の最小値を返す """
        if dp[i] < INF: return dp[i]
                
        ans1, ans2 = INF, INF
        ans1 = dfs(i-1) + abs(H[i]-H[i-1])  # i-1の足場から来た場合
        if i-2 >= 0:
            ans2 = dfs(i-2) + abs(H[i]-H[i-2])  # i-2の足場から来た場合

        dp[i] = min(ans1, ans2)

        return dp[i]
    
    print(dfs(N-1))



if __name__ == "__main__":
    solve2()

Measured memory_bytes: 119956
import numpy
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = []
for i in range(N):
    diff.append(A[i] - B[i])
neg_diff = [i for i in diff if i < 0]
pos_diff = [i for i in diff if i > 0]
pos_diff.sort(reverse=True)
if abs(sum(neg_diff)) > abs(sum(pos_diff)):
    print(-1)
    exit(0)
else:
    if sum(neg_diff) == 0:
        print(0)
        exit(0)

cum_pos_diff = numpy.cumsum(pos_diff)
insert_index = bisect.bisect_left(cum_pos_diff, abs(sum(neg_diff)))
print(len(neg_diff)+insert_index+1)


Measured memory_bytes: 34600
#include<stdio.h>

typedef long long int int64;

void run(void){
  int x,y;
  scanf("%d%d",&x,&y);
  if(x%y==0){
    printf("-1\n");
    return;
  }
  int64 ans=(int64)x*y-x;
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}


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

int main(){
  string N;
  cin >> N;
  if(N.at(0)=='7'){
    cout << "Yes" << endl;
  }
  else if(N.at(1)=='7'){
    cout << "Yes" << endl;
  }
  else if(N.at(2)=='7'){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
#define rep(i, n) for (int i = 0; i < (n); i++)
using P=pair<int,int>;
int main() {
    ll x;cin>>x;
    ll sixfive=x/11;
    ll rest=x%11;
    if(sixfive%2==0){
        if(rest==0){
            cout<<sixfive*2<<endl;
        }
        else if(rest<=6){
            cout<<sixfive*2+1<<endl;
        }else{
            cout<<sixfive*2+2<<endl;
        }
    }else{
        if(rest==0){
            cout<<sixfive*2<<endl;
        }
        else if(rest<=5){
            cout<<sixfive*2+1<<endl;
        }else{
            cout<<sixfive*2+2<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

bool mainmain(){
	ll n;
	cin>>n;
	if(n==1){
		return true;
	}
	vll v(n);
	rep(i,n) cin>>v[i];
	ll sum = 0;
	rep(i,n) sum += v[i];
	if(sum%(n*(n+1)/2)){
		return false;
	}
	// cout<<sum<<endl;
	vll cnt(n);
	ll m = sum/(n*(n+1)/2);
	// cout<<m<<endl;
	rep(i,n){
		ll diff = v[i] - v[(i+n-1)%n];
		cnt[i] = (m-diff)/n;
		if(cnt[i] < 0 || cnt[i] > m) return false;
		// cout<<diff << " " << cnt[i]<<endl;
	}
	vll tmp(2*n);
	ll now = 0;
	ll p = 0;
	rep(i,2*n){
		if(i<n) p += cnt[i];
		if(i-n>=0){
			p -= cnt[i-n];
			now -= cnt[i-n]*n;
		}
		now += p;
		tmp[i] = now;
		// cout<<i<<" "<<tmp[i]<<" "<<p<<" "<<now<<endl;
	}
	rep(i,n){
		if(v[i]!=tmp[i]+tmp[i+n]) return false;
	}
	return true;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    cout<<(mainmain()?"YES":"NO")<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main(){
  int n;
  cin >> n;
  vector<P> pairs(n);
  rep(i,n){
    int x;
    cin >> x;
    pairs[i].first = x;
    pairs[i].second = i;
  }
  sort(pairs.begin(),pairs.end());
  rep(i,n){
    cout << pairs[i].second+1 << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1664