akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MAX 305
#define mod 1000000007
ll dp[MAX][MAX][MAX];
vector<pair<int, int> > Q[MAX];

int main(void) {
    int n, m;
    ll ans = 0;
    scanf("%d%d", &n, &m);
    for(int i=0; i<m; i++) {
        int l, r, x;
        scanf("%d%d%d", &l, &r, &x);
        Q[r].emplace_back(l, x);
    }
    dp[0][0][0] = 1;
    for(int i=0; i<=n; i++) for(int j=0; j<=n; j++) for(int k=0; k<=n; k++) {
        if(dp[i][j][k] == 0) continue;
        int mx = max(i, max(j, k));
        bool ok = true;
        for(auto q : Q[mx]) {
            int cnt = 0;
            if(q.first <= i) cnt++;
            if(q.first <= j) cnt++;
            if(q.first <= k) cnt++;
            if(cnt != q.second) {ok = false; break;}
        }
        if(!ok) continue;
        dp[i][j][k] %= mod;
        if(mx == n) ans += dp[i][j][k];
        dp[mx+1][j][k] += dp[i][j][k];
        dp[i][mx+1][k] += dp[i][j][k];
        dp[i][j][mx+1] += dp[i][j][k];
    }
    ans %= mod;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 221440
from collections import Counter
N, M = map(int, input().split())
A = []
for i in range(N):
    a = [int(i) for i in input().split()]
    A.append(Counter(a[1:]))
b = Counter()
for i in A:
    b += i
ans = 0
for i in b.values():
    if i == N:
        ans += 1
print(ans)

Measured memory_bytes: 3444
package main
import (
  "fmt"
)

func min(a, b int) int {
  if a < b {
    return a
  }
  return b
}

func main() {
  var n, a, b int
  fmt.Scan(&n, &a, &b)
  xs := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&xs[i])
  }
  result := 0
  for i, x := range xs {
    if i == n-1 {
      break
    }
    nextX := xs[i+1]
    result += min(a*(nextX-x), b)
  }
  fmt.Println(result)
}

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

int main()
{
    int p[2000];
    int n,i,ans=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&p[i]);
    }
    for(i=1;i<n-1;i++)
    {
        if(p[i-1]<p[i]&&p[i]<p[i+1]) ans++;
        else if(p[i-1]>p[i]&&p[i]>p[i+1]) ans++;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            double su = 0.0;
            for (int i = 0; i < N; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                double x = double.Parse(s[0]);
                if (s[1] == "JPY")
                {
                    su += x;
                }
                else if (s[1] == "BTC")
                {
                    su += x * 380000.0;
                }
            }
            Console.WriteLine("{0:0.00000}", su);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#define ll long long
using namespace std;

string s;
void solve() {
  if (s.find("AC") == string::npos) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

int main() {
  cin >> s;

  solve();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	int N;
	cin >> N;
	vector<int> W(N);
	int sum;
	rep(i, N) {
		cin >> W[i];
		sum += W[i];
	}
	int left, right;
	left = W[0];
	right = sum - W[0];
	vector<int> S(N-1);
	S[0] = abs(left-right);
	rept(i, 1, N-1) {
		left += W[i];
		right -= W[i];
		S[i] = abs(left-right);
	}
	int mini = INT_MAX;
	rep(i, N-1) {
		mini = min(S[i], mini);
	}
	cout << mini << endl;



	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
using namespace std;

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

const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl

int n;
vector<int> G[maxn];
bool mark[maxn];
int from[maxn], sz[maxn];

void addedge(int u, int v) {
    G[u].push_back(v);
}

void dfs(int id, int fa) {
    sz[id] = 1;
    for (auto v: G[id]) {
        if (v == fa) continue;
        dfs(v, id);
        sz[id] += sz[v];
        from[v] = id;
    }
}

vector<int> ve;

int main() {
    //freopen(".in", "r", stdin);
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        addedge(u, v);
        addedge(v, u);
    }
    mark[n] = true;
    dfs(1, -1);
    int pos = n;
    while (pos) {
        ve.push_back(pos);
        pos = from[pos];
    }
    reverse(ve.begin(), ve.end());
    int len = ve.size();
    int A, B;
    if (len & 1) {
        A = sz[ve[(int)ve.size() / 2 + 1]];
        B = n - A;
    } else {
        A = sz[ve[(int)ve.size() / 2]];
        B = n - A;
    }
    if (A + 1 <= B) puts("Fennec");
    else puts("Snuke");
    return 0;
}


Measured memory_bytes: 13436
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	switch(a*b)
	{
	case 2:cout<<"3";break;
	case 3:cout<<"2";break;
	case 6:cout<<"1";break;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<int,vector<int> >mp;
int dp[100009],vis[100009];

void dfs(int n){
  vis[n]=1;
  for(int i=0;i<mp[n].size();i++){
  	if(!vis[mp[n][i]])
  	  dfs(mp[n][i]);
  dp[n]=max(dp[n],1+dp[mp[n][i]]);
  }
}
int main (){
int n,m,x,y;
cin>>n>>m;

while(m--)
cin>>x>>y,mp[x].push_back(y);

for(int i=1;i<=n;i++)
if(!vis[i])dfs(i);

int maxx=0;
for(int i=1;i<=n;i++)
  maxx=max(maxx,dp[i]); 

cout<<maxx<<endl;

return 0;
}

Measured memory_bytes: 15360
#include <map>
#include <cmath>
#include <cstdio>
#include <iostream>

typedef long long LL;
#define int LL

const int MAXN = 1e5, MAXFAC = 2155;
const LL MAXV = 1e10;
int n, pn, pr[MAXFAC + 5], siz[MAXN + 5], rev[MAXN + 5];
LL val[MAXN + 5];
bool vis[MAXFAC + 5];
std::map<LL, int> buc;

inline LL rint () {
	LL x = 0; char s = getchar ();
	for ( ; s < '0' || '9' < s; s = getchar () );
	for ( ; '0' <= s && s <= '9'; s = getchar () ) x = x * 10 + ( s ^ '0' );
	return x;
}

inline void sieve ( const int n ) {
	for ( int i = 2; i <= n; ++ i ) {
		if ( ! vis[i] ) pr[++ pn] = i;
		for ( int j = 1; j <= pn && i * pr[j] <= n; ++ j ) {
			vis[i * pr[j]] = true;
			if ( ! ( i % pr[j] ) ) break;
		}
	}
}

inline bool issqr ( const LL x ) {
	LL t = pow ( x, 1.0 / 3 );
	return t * t * t == x || ( t + 1 ) * ( t + 1 ) * ( t + 1 ) == x;
}

signed main () {
	n = rint (), sieve ( MAXFAC );
	int ans = 0;
	for ( int i = 1; i <= n; ++ i ) {
		LL a = rint ();
		if ( issqr ( a ) ) { ans = 1; continue; }
		LL cur = 1, mtc = 1;
		for ( int j = 1; j <= pn && pr[j] <= a; ++ j ) {
			int cnt = 0;
			for ( ; ! ( a % pr[j] ); a /= pr[j], ++ cnt );
			if ( ! ( cnt %= 3 ) ) continue;
			cur *= pr[j], mtc *= pr[j];
			if ( cnt == 1 ) mtc *= pr[j];
			else cur *= pr[j];
			if ( mtc > MAXV ) mtc = 0;
		}
		LL sqt = sqrt ( a );
		cur *= a;
		if ( sqt * sqt == a || ( sqt + 1 ) * ( sqt + 1 ) == a ) mtc *= sqt;
		else {
			mtc *= a;
			if ( mtc > MAXV ) mtc = 0;
			mtc *= a;
		}
		if ( mtc > MAXV ) mtc = 0;
		if ( ! buc.count ( cur ) ) siz[buc[cur] = i] = 1, rev[i] = mtc;
		else ++ siz[buc[cur]];
		val[i] = cur;
	}
	for ( int i = 1; i <= n; ++ i ) {
		if ( ! siz[i] ) continue;
		if ( ! buc.count ( rev[i] ) ) {
			ans += siz[i], siz[i] = 0;
		} else {
			ans += std::max ( siz[i], siz[buc[rev[i]]] );
			siz[i] = siz[buc[rev[i]]] = 0;
		}
	}
	printf ( "%lld\n", ans );
	return 0;
}

Measured memory_bytes: 12404
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], T = I[1];
		var c = int.MaxValue;
		for (var i = 0; i < N; i++)
		{
			I = G;
			if (I[1] <= T) c = Min(c, I[0]);
		}
		if (c < int.MaxValue) WriteLine(c);
		else WriteLine("TLE");
	}
}


Measured memory_bytes: 13268
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    // x * 2 -> x * 4
    boolean flag = false;
    for (int i = 0; i <= x; i++) {
      if (i * 4 + (x-i) * 2 == y) flag = true;
    }
    System.out.println((flag ? "Yes" : "No"));
  }
}


Measured memory_bytes: 35784
a = int(input())
b = int(input())
c = int(input())
x = int(input())
 
count = 0
 
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      total = 500 * i + 100 * j + 50 * k
      if total == x:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MAX 100000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;

int main(void) {
    ll n;
    string s;
    cin >> n >> s;
    ll i, j;
    ll ans=0;
    map<pair<string, string>, ll> cnt;
    for(i=0; i<1<<n; i++) {
        string a, b;
        for(j=0; j<n; j++) {
            if(1&i>>j) a+=s[j];
            else b+=s[j];
        }
        cnt[{a, b}]++;
    }
    
    for(i=0; i<1<<n; i++) {
        string a, b;
        for(j=0; j<n; j++) {
            if(1&i>>j) a=s[j+n]+a;
            else b=s[j+n]+b;
        }
        ans+=cnt[{b, a}];
    }
    
    cout << ans << endl;
}


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

int n;
int m;

#define MAX 200002

vector<pair<int, int> > v;

bool cmp(pair<int,int>  a,pair<int,int> b){
	return a.first > b.first;
}
deque<int> d;
int L(){
	for (int i = 0; i < v.size(); i++){
		d.push_back(v[i].first);
	}
	sort(d.begin(), d.end());
	int siz = 0;
	for (int i = m; i >= 1; i--){
		if (d.size()&&d.back() >= i){
			d.pop_back();
			siz++;
		}
	}
	return siz;
}
int R(){
	d.clear();
	for (int i = 0; i < v.size(); i++){
		d.push_back(v[i].second);
	}
	sort(d.begin(), d.end());
	int siz = 0;
	for (int i = m; i >= 1; i--){
		while (d.size()&&d.back() > i){
			d.pop_back();
		}
		if (d.size() ){
			d.pop_back();
			siz++;
		}
	}
	return siz;
}
deque<pair<int, int> > dd;
multiset<int> mt;
int calc(int Len){
	dd.clear();
	mt.clear();
	for (int i = 0; i < v.size(); i++){
		dd.push_back(make_pair(v[i].second, v[i].first));
	}
	sort(dd.begin(), dd.end());
	int sz = 0;
	for (int i = Len + 1; i <= m; i++){
		while (dd.size() && dd.front().first <= i){
			mt.insert(dd.front().second);
			dd.pop_front();
		}
		if (mt.size()){
			auto f = (mt.begin());
			mt.erase(f);
			sz++;
		}
	}
	while (dd.size()){
		mt.insert(dd.front().second);
		dd.pop_front();
	}
	for (int i = Len; i >= 1; i--){
		if (mt.size()){
			int k = (*mt.rbegin());
			if (k >= i){
				mt.erase(mt.lower_bound(k));
				sz++;
			}
		}
	}
	return sz;
}
int main(){
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		v.push_back(make_pair(a, b));
	}
	int szl = L();
	int szr = R();
	vector<int> S;
	S.push_back(0);
	S.push_back(m);
	S.push_back(szl);
	S.push_back(max(0,szl - 1));
	S.push_back(min(m, szl + 1));
	S.push_back(m - szr);
	S.push_back(max(0, m - szr - 1));
	int ans = 0;
	for (int i = 0; i < S.size(); i++){
		int go = calc(S[i]);
		ans = max(ans, go);
	}
	cout << n-ans << endl;
	return 0;
}

Measured memory_bytes: 11744
#!/usr/bin/env python3
import sys


def solve(S: str):
    print("ABC" if S == "ARC" else "ARC")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61680
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
S = readline().decode("utf-8").rstrip()

res = ""
left_cnt = 0
for c in S:
    if '(' == c:
        left_cnt += 1
        res += '('
    elif ')' == c:
        if left_cnt > 0:
            res += ')'
            left_cnt -= 1
        else:
            res = '(' + res + ')'
if left_cnt != 0:
    res += ")" * left_cnt

print(res)


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

#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  ll n,i,j,k;
  vector<vector<int>> a(3, vector<int>(3));
  rep(i,3){
    rep(j,3){
      cin >> a.at(i).at(j);
    }
  }
  
  cin >> n;
  
  vector<int> b(n);
  rep(i,n){
    cin >> b.at(i);
  }
  
  rep(i,n){
    rep(j,3){
      rep(k,3){
        if(b.at(i) == a.at(j).at(k)){
          a.at(j).at(k) = 0;
        }
      }
    }
  }
  
  bool ok = false;
  
  if(!a.at(0).at(0) && !a.at(0).at(1) && !a.at(0).at(2))
    ok = true;
  else if(!a.at(1).at(0) && !a.at(1).at(1) && !a.at(1).at(2))
    ok = true;
  else if(!a.at(2).at(0) && !a.at(2).at(1) && !a.at(2).at(2))
    ok = true;
  else if(!a.at(0).at(0) && !a.at(1).at(0) && !a.at(2).at(0))
    ok = true;
  else if(!a.at(0).at(1) && !a.at(1).at(1) && !a.at(2).at(1))
    ok = true;
  else if(!a.at(0).at(2) && !a.at(1).at(2) && !a.at(2).at(2))
    ok = true;
  else if(!a.at(0).at(0) && !a.at(1).at(1) && !a.at(2).at(2))
    ok = true;
  else if(!a.at(0).at(2) && !a.at(1).at(1) && !a.at(2).at(0))
    ok = true;
  
  
  if(ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  
  //cout << n << endl;
}




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

int main(){
	int n;
	cin >> n;
	int* a = new int[n]{};
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = n - 1; i >= 0; i--){
		if (i == n - 1) cout << a[i];
		else cout << ' ' << a[i];
	}
cout<<endl;
	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,n,ans=0;cin>>a>>b>>n;
  if(n<b) ans=floor(a*n/b);
  else ans=floor(a*(b-1)/b);
  print(ans);
  return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define MAX 10000001
using namespace std;
int main(){
    int N;
    string C;
    cin >> N >> C;
    int w[N]={0},r[N]={0};
    if(C.at(0)=='W')w[0]=1;
    if(C.at(N-1)=='R')r[N-1]=1;
    for(int i=1; i<N; i++){
        w[i]=w[i-1];
        if(C.at(i)=='W'){
            w[i]++;
        }
    }
    for(int i=N-1; i>0; i--){
        r[i-1]=r[i];
        if(C.at(i-1)=='R'){
            r[i-1]++;
        }
    }
    int ans=0;
    for(int i=0; i<N-1; i++){
        if(w[i]==r[i+1]){
            ans=w[i];
            break;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 5316
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,m;
 cin>>n>>m;
 vector<int> a[n+1];
 int i;
 int v[n+1];
 memset(v,0,sizeof(v));
 for(i=0;i<m;i++)
 {
 	int x,y;
 	cin>>x>>y;
 	a[x].push_back(y);
 	a[y].push_back(x);
 }
 int x=0;
 int cnt=0;
 v[1]=1;
 queue<int> q;
 q.push(1);
 q.push(-1);
 int ans[n+1];
 int aans[n+1];
 memset(ans,0,sizeof(ans));
 while(cnt<n && !(q.front()==-1 && q.back()==-1))
 {
 	if(q.front()==-1)
 	{
 	  q.pop();
	  q.push(-1);
	  x++;	
	}
	else
	{
		int y=q.front();
		//cout<<q.front()<<"POP"<<x<<cnt<<endl;
		ans[y]=x;
		cnt++;
		i=0;
		//cout<<q.front()<<" ";
		while(i<a[y].size())
		{
		if(v[a[y][i]]==0)
		{
			//cout<<a[y][i]<<" ";
			q.push(a[y][i]);
			v[a[y][i]]=1;
			aans[a[y][i]]=y;
		}
		i++;
		}
	//	cout<<endl;
		q.pop();
	}
 }
 if(cnt==n)
 {
 	cout<<"Yes"<<endl;
 	for(i=2;i<=n;i++)
 	{
 		cout<<aans[i]<<endl;
	}
 }
 else
 cout<<"No"<<endl;
 return 0;
}


Measured memory_bytes: 11332
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static BitSet primes;

	static BitSet eratosthenes(int m) {
		int n = m + 1;
		BitSet isp = new BitSet();
		if (n < 2) return isp;

		isp.set(2, n, true);

		for (int i=2; i*i<n; i=isp.nextSetBit(i+1)) {
			for (int j=i+i; j<n; j+=i) {
				isp.set(j,false);
			}
		}

		return isp;
	}

	static void init() {
		primes = eratosthenes(1000000);
		// dump(primes);
	}

	static boolean solve() {
		int n = in.nextInt();
		int p = in.nextInt();
		if (n + p == -2) return false;

		int[] ps = new int[50];
		int pos = n;
		for (int i=0; i<50; i++) {
			while(!primes.get(++pos));
			ps[i] = pos;
		}

		PriorityQueue<Integer> pQ = new PriorityQueue<>();

		for (int i=0; i<50; i++) {
			for (int j=i; j<50; j++) {
				pQ.add(ps[i]+ps[j]);
			}
		}

		for (int i=0; i<p-1; i++) {
			pQ.poll();
		}

		// dump(pQ);

		out.println(pQ.poll());

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		init();
		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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


int main (){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i,n){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(),b.end(),greater<int>());
    rep(i,n){
        if(a[i] == b[0]) cout << b[1] << endl;
        else cout << b[0] << endl;
    }

    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
// increment
#define rep_n(_1, _2, _3, NAME,...) NAME
#define rep_2(i, n) for(int i = 0; i < (int)(n); ++i)
#define rep_3(i, initial, n) for(int i = (int)(initial); i < (int)(n); ++i)
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME,...) NAME
#define rep_r_2(i, n) for(int i = (int)(n); i > 0; i--) 
#define rep_r_3(i, initial, n) for(int i = (int)(initial); i > (int)(n); i--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
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; }

int main() {
	ll N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;

	cout << max({ (N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D, (N - 1) / E }) + 5 << endl;
	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

// Problem Specific Parameter:

int t[100010], f[100010];

int main(void) {
	int n, d;
	cin >> n >> d;

	rep(i, n) cin >> t[i] >> f[i];

	ll cur = 0, pos = 1, num = 0, ans = 0;



	rep(i, n) {
		const int rest = t[i] - cur;

		if (pos - 1 + f[i] - 1 <= rest) {
			ans += 1LL * num * (pos - 1);
			num = 1;
		} else if (abs(f[i] - pos) <= rest and num < d) {
			ans += 1LL * num * rest;
			num++;
		} else {
			puts("-1");
			return 0;
		}

		cur = t[i], pos = f[i];
	}

	ans += (pos - 1) * num;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3856
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <unordered_map>
// #include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
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 powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '\n' : ' ');}}
void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '\n' : ' ');}}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
#define DEBUG_Switch 0
int main()
{
#if DEBUG_Switch
    freopen("C:\\code\\input.txt", "r", stdin);
#endif
    //freopen("C:\\code\\output.txt","r",stdin);
    int r = readint();
    printf("%.6f\n", acos(-1) * 2 * r );
    return 0;
}




Measured memory_bytes: 3120
n = int(input())
A= list(map(int, input().split()))

count = 0
f = True
while(True):
    flag = True
    for i in range(n):
        if A[i]%2 !=0:
            flag=False
    if flag == False:
        break
    for i in range(n):
        if A[i]%2 == 0:
            A[i]/=2
    count+=1
print(count)

Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N=56001;
vector<bool> prime(N,1);
vector<int> p;

int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("in","r",stdin);
		freopen("out","w", stdout);
	#endif

	prime[0]=prime[1]=0;
	for(int i=2;i<N;i++)
	{
		if(!prime[i])continue;
		for(int j=i*i;j<N;j+=i)prime[j]=0;
	}
	int rem=0;
	for(int i=0;i<=55555;i++)
	{
		if(prime[i])
		{
			rem=i%5;
			if(rem==1)p.push_back(i);
		}
	}
	
	int n;cin>>n;
	for(int i=0;i<n;i++)cout<<p[i]<<" ";


	

}

Measured memory_bytes: 3668
x,y = map(int,input().split())

if x*y<0:print(abs(abs(x)-abs(y))+1)
elif x>=0 and x<y:print(y-x)
elif x>=0 and y>0 and y<x:print(x-y+2)
elif x>=0 and y==0 and y<x:print(x-y+1)
elif x<y<=0:print(y-x)
elif y<x<0:print(x-y+2)
elif x == 0 and y<0:print(abs(y)+1)



Measured memory_bytes: 3060
// AtCoder Regular Contest 078
// E - Awkward Response

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


bool query(ll n) {
    char c;
    cout << "? " << n << endl;
    cin >> c;
    return c == 'Y';
}

int main() {

    int d;
    ll n, l, r, m;

    for (d = 1, n = 1; d < 11 && query(n); d++, n *= 10) {}
    if (d == 11) {
        for (d = 1, n = 1; d < 11 && !query(n * 10 - 1); d++, n *= 10) {}
        cout << "! " << n << endl;
        return 0;
    }
    d--;
    n /= 10;

    l = n;
    r = n * 10;
    m = (l + r + 1) / 2;
    while (r - l > 1) {
        if (query(m * 10)) {
            r = m;
        } else {
            l = m;
        }
        m = (l + r + 1) / 2;
    }

    cout << "! " << m << endl;

    return 0;

}





Measured memory_bytes: 680
import sys

input = sys.stdin.readline

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

p = []
S = []
ans = 0
pena = 0
count = [0] * N
check = set()
for _ in range(M):
    l = list(map(str, input().split()))
    p.append(int(l[0]))
    S.append(l[1])

for i in range(M):
    if p[i] not in check:
        if S[i] == 'AC':
            pena += count[p[i]-1]
            ans += 1
            check.add(p[i])
        elif S[i] == 'WA':
            count[p[i]-1] += 1

print(ans, pena)


Measured memory_bytes: 20336
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


if __name__ == '__main__':
    a,b = map(int, input().split())
    c = 0
    d = 0
    if a > 1:
        c = cmb(a,2)
    if b > 1:
        d = cmb(b,2)
    print(c+d)

Measured memory_bytes: 3700
//contest 162 at coder
#include<bits/stdc++.h>
using namespace std;
#define rep(n) for(int i=0;i<n;i++)
typedef long long ll;
#define mod 1000000007
#define pb push_back
int main(){
	ll n,k;
	cin>>n>>k;
	ll ans=1;
	
	ll minn,max,refmax=INT_MAX;
	for(ll i=n;i>=k;i--){
			minn=i*(i-1);
			minn/=2;
			max=i*n-minn;
			ans+=max;
			ans=ans-minn+1;
			
			ans=ans%mod;
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int64_t INF = (1LL << 62);
int64_t N, U, V, MAXN = 100010;
vector<vector<int64_t>> Graph(MAXN);

void bfs(vector<int64_t> &D, int64_t init)
{
  D[init] = 0;
  queue<int64_t> Q;
  Q.push(init);
  while (Q.size())
  {
    int64_t cur = Q.front();
    Q.pop();
    for (int i = 0; i < Graph[cur].size(); i++)
    {
      int64_t nxt = Graph[cur][i];
      if (D[nxt] != INF)
        continue;
      D[nxt] = D[cur] + 1;
      Q.push(nxt);
    }
  }
}

int main()
{
  int64_t a, b;
  cin >> N >> U >> V;
  U--;
  V--;
  for (int i = 0; i < N - 1; i++)
  {
    cin >> a >> b;
    a--;
    b--;
    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }
  vector<int64_t> A(MAXN, INF), B(MAXN, INF);
  bfs(A, U);
  bfs(B, V);
  int64_t mx = -1;
  for (int i = 0; i < N; i++)
  {
    if (A[i] >= B[i])
      continue;
    mx = max(mx, B[i]);
  }
  cout << mx - 1 << endl;
}


Measured memory_bytes: 10812
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int n,a[1000000+100],sol,k;
string s;

int main()
{
	scanf("%d %d",&n,&k);
	for (int i =1;i<=n;i++)scanf("%d",&a[i]);


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

	int d = n-pok;
	pok = max(1,pok-d%(k-1));
	d = n-pok;
	sol += d/(k-1);

	if (d%(k-1))sol++;


	int l = pok-1;

	sol += l/(k-1);
	if (l%(k-1))sol++;

	int sol1 = 0;
	l = pok-1;
	pok = min(pok-l%(k-1),n);
	l = pok-1;
	sol1 += l/(k-1);
	if (l%(k-1))sol1++;
	d = n-pok;
	sol1 += d/(k-1);

	if (d%(k-1))sol1++;


	cout<<min(sol,sol1)<<endl;

	return 0;
}

Measured memory_bytes: 640
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n,m = gets.chomp.split.map(&:to_i)
x = gets.chomp.split.map(&:to_i)

h = Hash.new(0)
x.each do |num|
  h[num] += 1
end
onazi = Array.new(m, 0)
a = Array.new(m, 0)

x.each do |num|
  a[num % m] += 1
  # o = h[num]
  # o -= 1 if o.odd?
  # onazi[num % m] += o
end

h.each do |k, v|
  v -= 1 if v.odd?
  onazi[k % m] += v
end

ans = 0

mid = m / 2
mid -= 1 if m.even?
1.upto(m/2) do |i|
  snum = [a[i], a[m - i]].min
  a[i] -= snum
  a[m-i] -= snum
  ans += snum
end
if m.even?
  ans += a[m/2] / 2
  a[m/2] = 0
end
ans += a[0] / 2
a[0] = 0

m.times do |i|
  if onazi[i] > a[i]
    tmp = a[i]
    ans += tmp / 2
  else
    ans += onazi[i] / 2
  end
end
puts ans

=begin
10 20
1 11 11 11 21
5 25 25
6 26
99 99 99

=end


Measured memory_bytes: 20100
#include<iostream>
#include<string>
using namespace std;
string s;
using namespace std;
int main(){
    int N;
    cin >> N;
    if(N==0){
	cout<<"0"<<endl;
	return 0;
    }
    bool even=true;
    while(N!=0){
	if(even){
	    even=false;
	    if(abs(N)%2==1){
		N--;
		s.insert(s.begin(),'1');
	    }else s.insert(s.begin(),'0');
	}
	else{
	    even=true;
	    if(abs(N)%2==1){
		N++;
		s.insert(s.begin(),'1');
	    }else s.insert(s.begin(),'0');
	}
	N/=2;
    }
    cout<<s<<endl;




}


Measured memory_bytes: 256
/**
 * @author      : omgursocute
 * @created     : 27/01/2020
 * @task        : C
 */

// ===== TEMPLATE STARTS HERE ===== //

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define FORa(i, a, b) for(ll i = (a); i <= (b); ++i)
#define FORb(i, a, b, c) for(ll i = (a); i <= (b); i += (c))
#define FORn(i, n) for(ll i = 0; i < (n); ++i)
#define FORra(i, a, b) for(ll i = (a); i >= (b); --i)
#define FORrb(i, a, b, c) for(ll i = (a); i >= (b); i -= (c))
#define FORrn(i, n) for(ll i = ((n)-1); i >= 0; --i)
#define NUMARGC(_1, _2, _3, _4, NAME, ...) NAME
#define FOR(...) NUMARGC(__VA_ARGS__, FORb, FORa, FORn)(__VA_ARGS__)
#define RFOR(...) NUMARGC(__VA_ARGS__, FORrb, FORra, FORrn)(__VA_ARGS__)

#define XFOR(i, x) for(__typeof((x).begin()) i = (x).begin(); i != (x).end(); ++i)
#define RXFOR(i, x) for(__typeof((x).rbegin()) i = (x).rbegin(); i != (x).rend(); ++i)

#define pll pair<ll, ll>
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range(x, a, b) ((x).begin()+a), ((x).begin()+b)
#define pb push_back

#define sqr(x) 1ll*(x)*(x)
#ifndef ONLINE_JUDGE
#define debug(x) cerr << '[' << #x << ']' << " = " << x << '\n'
#else
#define debug(x) "cute"
#endif

namespace io {
	void Speed() {
		ios::sync_with_stdio(false);
		cin.tie(NULL); cout.tie(NULL);
	}
#ifndef ONLINE_JUGDE
	void In(string s) {freopen(s.c_str(), "r", stdin);}
	void Out(string s) {freopen(s.c_str(), "w", stdout);}
	void setIO(string s) {In(s + ".inp"); Out(s + "out");}
#endif
}

// ======= TEMPLATE ENDS HERE ======= //

int main() {
	io::Speed();
	
	int n, k;
	cin >> n >> k;
	vll a(n);
	XFOR(i, a) cin >> *i;

	sort(all(a), greater<ll>());
	ll sum = 0;

	FOR(i, k, n-1) sum += a[i];

	cout << sum;

	return 0;
}



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

int main() {
	size_t N, M;
	cin >> N >> M;
	vector<int> X(M);
	for (auto& x : X) cin >> x;
	if (N >= M) cout << 0;
	else {
		sort(X.begin(), X.end());
		vector<int> diff(M - 1);
		for (size_t i = 1; i < M; ++i) diff.at(i - 1) = X.at(i) - X.at(i - 1);
		sort(diff.begin(), diff.end());
		int ans = 0;
		for (size_t i = 0; i < M - N; ++i) ans += diff.at(i);
		cout << ans;
	}
}

Measured memory_bytes: 1024
N, T = map(int, input().split())
*A, = map(int, input().split())
max_price = A[N-1]
max_prof = 0
count = 1
for a in reversed(A[:N-1]):
    prof = max_price - a
    if prof < 0: max_price = a
    elif prof == max_prof: count += 1
    elif prof > max_prof: max_prof = prof; count = 1;
print(count)

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,n,x=0;
    cin >> n;
    PII a[n+1];
    for(i=1;i<=n;i++)cin >> a[i].FI,a[i].SE=i;
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++)
    {
        if(a[i].SE != i)++x;
    }
    if(x > 2)cout << "NO";
    else cout << "YES";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
using ll = long long;

using namespace std;



int main() {
    string S;
    cin>>S;
    int ans = 0;
    if(S[0]=='S') {
        if(S[1]=='S') {
            if(S[2]=='S') ans = 0;
            else ans = 1;
        } else if(S[2]=='S') ans = 1;
        else ans = 2;
    } else if(S[1]=='S') ans = 1;
    else if(S[2]=='S') ans = 2;
    else ans = 3;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3620
def main():
    n = int(input())
    d_lst = list(map(int, input().split()))
    ans = 0

    for i in range(n - 1):
        for j in range(i + 1, n):
            ans += d_lst[i] * d_lst[j]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 63064
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// }}}
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int sum = 0;
  cin >> n;
  int a[100];
  for(int i = 0; i < n; i++) cin >> a[i], sum += a[i];
  pair<int, int> mi(1e9, 1e9);
  for(int i = 0; i < n; i++) {
    mi = min(mi, make_pair(abs(sum - a[i] * n), i));
  }
  cout << mi.second << endl;
  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
const int mx = 100010;
long long a[mx], cost[mx], h[mx]; 

main()
{
	int n;
	cin >> n;
	
	for(int i = 1; i <= n; i++){
		cin >> h[i];
	}

	cost[1] = 0;
	cost[2] = abs(h[2] - h[1]);
	
	for(int i = 3; i <= n; i++){
		
		cost[i] = min(abs(h[i]-h[i-1])+cost[i-1], abs(h[i]-h[i-2])+cost[i-2]);
	}
	
	cout << cost[n];


return 0;
}


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

using namespace std;

int main() {
    long long int n, a, b;
    scanf("%lld %lld %lld", &n, &a, &b);

    long long int all_inside = n / (a + b);
    long long int rest = min(a, n % (a + b));

    printf("%lld\n", all_inside * a + rest);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,ans=1;
	cin>>x;
	for(int i=2;i<=35;i++)
	{
		int k=i*i;
		if(k>x)
		   break;
		while(k*i<=x)
		   k*=i;
		if(k>ans)
		   ans=k;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
M, D = map(int, input().split())

ans = 0
for i in range(1, M+1):  # 月
    for j in range(10, D+1):  # 日付
        d1 = int(str(j)[0])
        d2 = int(str(j)[1])

        if d1 > 1 and d2 > 1:
            if i == (d1 * d2):
                ans += 1

print(ans)


Measured memory_bytes: 3060
max_row, max_col = map(int, input().split(" "))
rows = [[0 for i in range(max_col)] for j in range(max_row)]
row = ""

for i in range(max_row):
    row =  input().split(" ")
    total_row = 0
    for j in range(max_col):
        rows[i][j] = int(row[j])
        total_row = total_row + int(row[j])
    rows[i].append(total_row)
    
#get summery of each columns
total = [0 for i in range(max_col+1)]
for m in range(max_col+1):
    for n in range(max_row):
        total[m] = total[m] + rows[n][m]
rows.append(total)


for i in range(max_row+1):
    out_str = ""
    for j in range(max_col+1):    
        out_str = out_str + " " + str(rows[i][j]) 
    
    print(out_str.strip())

Measured memory_bytes: 7716
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();int sum=0;
        while(sc.hasNext()){
            if(s.equals(sc.next().toLowerCase()))sum++;
        }
        System.out.println(sum);
    }
}



Measured memory_bytes: 26024
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

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

    if (K == 1) {
        cout << 0 << endl;
        return 0;
    }

    if (N < K) {
        cout << 0 << endl;
        return 0;
    }

    cout << (N - K) << endl;
    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())

a=N
while True:
    if a-10**16*K>=0:
        a=a-10**16*K
    elif a-10**14*K>=0:
        a=a-10**14*K
    elif a-10**12*K>=0:
        a=a-10**12*K
    elif a-10**10*K>=0:
        a=a-10**10*K
    elif a-10**8*K>=0:
        a=a-10**8*K
    elif a-10**6*K>=0:
        a=a-10**6*K
    elif a-10**4*K>=0:
        a=a-10**4*K
    elif a-10**2*K>=0:
        a=a-10**2*K
    elif a-K>=0:
        a=a-K
    elif K-a>=a:
        a=a
        break
    else:
        a=K-a
print(a)

Measured memory_bytes: 38384
module Main where

import Control.Applicative
import Text.Printf
import Numeric

main :: IO()
main = loop

loop :: IO()
loop = do
  { [h, w] <- getInts
  ; if h == 0 && w == 0 then return ()
    else do
      { let oneline = replicate w '#'
      ; let rect    = replicate h oneline
      ; putStr $ unlines rect
      ; putStrLn ""
      ; loop
      }
  }
--
  
getInts :: IO[Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO()
putInts = putStrLn . unwords. map show

getDoubles :: IO[Double]
getDoubles = map read. words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble x = showFFloat Nothing x ""

getStrings :: IO [String]
getStrings = words <$> getLine

readInt' :: String -> Int
readInt' = read



Measured memory_bytes: 4256
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0;i < n - 2;i++){
        if(s.substr(i,3) == "ABC"){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//解説あり
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;
static const long long MAX = 200005;

ll n, k, ans;

long long fac[MAX], finv[MAX], inv[MAX];

void init_comb() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long combination(long long n, long long k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(void) {
    cin >> n >> k;
    init_comb();

    for (int i=0; i<=min(k, n-1); i++) {
        ans += combination(n, i) * combination(n-1, i);
        ans %= MOD;
    }
   
    printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	/** 1の文字 */
	private static final char ONE = '1';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] s = scanner.next().toCharArray();
			long k = scanner.nextLong();
			for (char c : s) {
				if (ONE == c) {
					k--;
					if (0L == k) {
						System.out.println(c);
						return;
					}
				} else {
					System.out.println(c);
					return;
				}
			}
		}
	}
}


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define all(x) begin(x), end(x)
#define range(x) begin(x), begin(x)
#define what(x) cout << #x << ": " << x << '\n'
#define print(x) for (auto &el: x) cout << el << ' '; cout << '\n'
using namespace std;
 
template<typename S, typename T>
ostream& operator <<(ostream &os, pair<S, T> &m) { 
    os << '[' << m.first << " " << m.second << ']'; 
    return os; 
}

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

    int n;
    cin >> n;

    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        if (i % 2 == 1 && x % 2 == 1) cnt++;
        
    }
    cout << cnt << endl;
    
    

    return 0;
}

Measured memory_bytes: 3664
#include <cstdio>
#include <iostream>
#include <utility>
using namespace std;

int main(){
  long long n, k;
  scanf("%lld %lld", &n, &k);

  long long s = 0;

  for (int i = 1; i <= n; i++){
    long long u = n / i;
    long long v = n % i;
    s += u * max(0LL, i - k) + max(0LL, v - k + 1);
  }

  if (k == 0) s = n * n;

  printf("%lld\n", s);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

string s;

bool check(int k) {
	bool zero = true, one = true;
	for (int i = 0; i < (int)s.length(); ++i) {
		if (i >= k || i + k < (int)s.length()) continue;
		zero &= s[i] == '0';
		one &= s[i] == '1';
	}
	return zero || one;
}

int main() {
	cin >> s;
	int lb = 1, ub = (int)s.length() + 1;
	while (ub - lb > 1) {
		int mid = lb + (ub - lb) / 2;
		if (check(mid)) lb = mid;
		else ub = mid;
	}
	cout << lb << endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
    int i,x,y,pocket;
    for(i = 1;i<=3000;i++){
        scanf("%d%d",&x,&y);
        if(x ==0 && y == 0)break;
        
        if(x > y){
            pocket = x;
            x = y;
            y = pocket;        
        }
        
        printf("%d %d\n",x,y);
    }

    return 0;
}


Measured memory_bytes: 2044
N, x = map(int, input().split())
A = [int(x) for x in input().split()]
A = sorted(A)
cnt=0

for i in range(N):
    x -= A[i]
    if x < 0:
        break
    cnt += 1

if cnt==N and x > 0:
    cnt -= 1
print(cnt)

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

#define LL long long
#define pii pair<int,int>
using namespace std;
const int inf = 2147483647;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

char ss[101];

int main() {
	scanf("%s", ss + 1);
	int len = strlen(ss + 1);
	for(int i = 1; i <= len; i++) {
		if(i & 1) {
			if(ss[i] == 'L') {
				puts("No");
				return 0;
			}
		} else {
			if(ss[i] == 'R') {
				puts("No");
				return 0;
			}
		}
	} puts("Yes");
	return 0;
}


Measured memory_bytes: 256
import math
import heapq
import sys
from collections import Counter
import datetime
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

#N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N=int(input())

for i in range(0,N//4+1):
    if (N-4*i)%7==0:
        print('Yes')
        sys.exit()
        
print('No')

Measured memory_bytes: 5276
#include <stdio.h>
int main()
{
  int x,y;
  while(1){
    scanf("%d %d",&x,&y);
    if(x==0 && y==0) break;
    if(x < y){
      printf("%d %d\n",x,y);
    } else {
    printf("%d %d\n",y,x);
    }
  }
  return 0;
}

Measured memory_bytes: 596