akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int A, B; cin >> A >> B;

	FOR(i, 1, 20000) {
		if ((int)(i*0.08) == A && (int)(i*0.1) == B) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 2e5+5, M = 1e6+6, OO = 0x3f3f3f3f, MOD = 1e9+7;
int tc;
ll s;
ll mem[2005];
ll solve(ll sum)
{
    if(sum == 0)
        return 1;
    if(sum < 0)
        return 0;
    if(mem[sum]!= -1)
        return mem[sum];
    ll op = 0;
    for(int i = 3 ; i<= s; i++)
    {
        if(sum - i >= 0)
        {
            op += (solve(sum-i)%MOD);
            op%= MOD;
        }

    }
    return mem[sum] = op;
}
int main()
{
    FIO
    cin>>s;
    memset(mem, -1, sizeof mem);
    cout<<solve(s);
    return 0;
}

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

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

// };
 
int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> k_array(100, 0);
  int counter = 0;
  for (int k = 1; k < 101; k++) {
    if ((A % k) == 0 && (B % k) == 0) {
      k_array.at(counter) = k;
      counter += 1;
    }
  }

  vector<int> k_array_1(counter, 0);
  for (int i = 0; i < counter; i++) {
    k_array_1.at(i) = k_array.at(i);
  }

  sort(k_array_1.begin(), k_array_1.end());
  reverse(k_array_1.begin(), k_array_1.end());

  cout << k_array_1.at(K - 1) << endl;
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    #define int long long
    ios_base::sync_with_stdio(0);
    int n,m;
    cin >> n >> m;
    vector <int> s(n),t(n),x(n), d(m), ans(m, -1);
    
    vector <pair <int ,pair <int,int> > > V(n);
    for(int i = 0; i < n; ++i){
        cin >> s[i] >> t[i] >> x[i];
        V[i] = {x[i],{s[i],t[i]}};
    }
    // for(int i = 0; i <n; ++i){
    //     cerr << s[i] << ' ' << t[i] << ' '<< x[i] << '\n';
    // }
    // for(int i = 0; i <n; ++i){
    //     cerr << V[i].first << ' ' << V[i].second.first << ' ' << V[i].second.second << '\n';
    // }
    sort(V.begin(), V.end());
    set <pair <int,int> > S;
    for(int i = 0; i < m; ++i){
        cin >> d[i];
        S.insert({d[i], i});
    }
    for(auto sdf : V){
        int ss = sdf.second.first, sx = sdf.first, st = sdf.second.second;
        auto it = S.lower_bound({ss-sx,0});
        // cerr << "in S: "<< it -> second << '\n';
        // cerr << ss << ' ' << sx << ' ' << st << '\n';
        while(it != S.end() && it -> first < st - sx){
            ans[it -> second] = sx;
            auto it2 = it;
            ++it2;
            S.erase(it);
            it = it2;
        }
    }
    for(int i = 0; i < m; ++i){
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 26880
n,m=map(int,input().split())
edge=[[] for i in range(n)]
for i in range(m):
    u,v,s=map(int,input().split())
    edge[u-1].append((v-1,s))
    edge[v-1].append((u-1,s))

ans=[1 for i in range(n)]
pm=[True]*n

used=[False]*n
used[0]=True

que=[0]
while que:
    u=que.pop()
    for v,s in edge[u]:
        if not used[v]:
            pm[v]=(not pm[u])
            ans[v]=s-ans[u]
            used[v]=True
            que.append(v)

flag=True
bipart=True
for u in range(n):
    for v,s in edge[u]:
        if ans[u]+ans[v]!=s:
            flag=False
        if pm[u]==pm[v]:
            bipart=False
            check=(u,v,s)

if bipart:
    upper=float("inf")
    lower=1

    for v in range(1,n):
        if pm[v]:
            lower=max(lower,2-ans[v])
        else:
            upper=min(upper,ans[v])

    if flag:
        if upper<lower:
            print(0)
        else:
            print(upper-lower+1)
    else:
        print(0)
else:
    u,v,s=check
    a,b=ans[u],ans[v]
    if pm[u]:
        diff=s-(ans[u]+ans[v])
        if diff%2==1:
            print(0)
            exit()
        else:
            for i in range(n):
                if pm[i]:
                    ans[i]+=diff//2
                    if ans[i]<1:
                        print(0)
                        exit()
                else:
                    ans[i]-=diff//2
                    if ans[i]<1:
                        print(0)
                        exit()
            flag=True
            for u in range(n):
                for v,s in edge[u]:
                    if ans[u]+ans[v]!=s:
                        flag=False
            print(int(flag))

    else:
        diff=(ans[u]+ans[v])-s
        if diff%2==1:
            print(0)
            exit()
        else:
            for i in range(n):
                if pm[i]:
                    ans[i]+=diff//2
                    if ans[i]<1:
                        print(0)
                        exit()
                else:
                    ans[i]-=diff//2
                    if ans[i]<1:
                        print(0)
                        exit()
            flag=True
            for u in range(n):
                for v,s in edge[u]:
                    if ans[u]+ans[v]!=s:
                        flag=False
            print(int(flag))

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

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

    int ans = 0;
    for(int i = 1; i <= n; i++){
        string s = to_string(i);
        int sumi = 0;
        for(char c : s){
            sumi += (c-'0');
        }
        if(a <= sumi && sumi <= b){
            ans += i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace Sample
{
	class Program
	{
		static void Main(string[] args)
		{
			var v = int.Parse(Console.ReadLine());
			var h = v / 3600;
			var m = v / 60 - h * 60;
			var s = v - m * 60 - h * 3600;
			Console.WriteLine($"{h}:{m}:{s}");
		}
	}
}



Measured memory_bytes: 17980
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X, Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%(m))
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_M = 200000;
int M;
int d[MAX_M];
ll c[MAX_M];


int main() {
    cin >> M;
    rep(i, M) cin >> d[i] >> c[i];

    ll D = 0, S = 0;
    rep(i, M) {
        D += c[i];
        S += d[i] * c[i];
    }

    cout << (D - 1) + (S - 1) / 9;

    return 0;
}


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

using namespace std;

long long int abs(long long int a,long long int b)
{
    if(a>b)
    {
        return a % b;
    }
    else{
        b - a;
    }
}

int main()
{
    long long int n,k;
    cin>>n>>k;

    long long int tn = n;

    long long int dif = abs(n,k);

    if(n <= k)
    {
        if(n < k - n)
        {
            cout<<n;
        }
        else{
            cout<<k-n;
        }

    }
    else{

        long long int temp = n % k;

        if(n %k == 0)
        cout<<"0";

        else{
            if(temp < k - temp)
        {
            cout<<temp;
        }
        else{
            cout<<k-temp;
        }

        }

    
    


    
    }




    
  
}

Measured memory_bytes: 384
a,b,c=map(int,input().split())
if a==b and a==c and a%2==0:
  print(-1)
else:
  cnt=0
  while a%2==0 and b%2==0 and c%2==0:
    cnt+=1
    k=a
    l=b
    a=(b+c)//2
    b=(k+c)//2
    c=(k+l)//2
  print(cnt)

Measured memory_bytes: 9092
A, B, M = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))

ans = min(al) + min(bl)
for _ in range(M):
    a, b, m = list(map(int, input().split()))
    ans = min(ans, al[a-1]+bl[b-1]-m)
print(ans)


Measured memory_bytes: 18736
#include<bits/stdc++.h>
using namespace std;
const int maxn=1E5+5;
int n,pl,pr,ans;
struct line
{
	int l,r;
}a[maxn];
inline void solve1()
{
	int x=0;
	for(int i=1;i<=n;++i)
		if(i!=pl&&i!=pr)
			x=max(x,a[i].r-a[i].l+1);
	ans=max(ans,x+max(0,a[pr].r-a[pl].l+1));
}
struct pt
{
	int x,y;
	bool operator<(const pt&A)const
	{
		return x<A.x;
	}
}b[maxn];
int pre[maxn];
bool cmp(const pt&x,const pt&y)
{
	return x.y<y.y;
}
inline void solve2()
{
	for(int i=1;i<=n;++i)
	{
		b[i].x=max(0,a[i].r-a[pl].l+1);
		b[i].y=max(0,a[pr].r-a[i].l+1);
	}
	sort(b+1,b+n+1);
	pre[1]=b[1].y;
	for(int i=2;i<=n;++i)
		pre[i]=min(pre[i-1],b[i].y);
	for(int i=2;i<=n;++i)
		ans=max(ans,b[i].x+pre[i-1]);
	sort(b+1,b+n+1,cmp);
	pre[1]=b[1].x;
	for(int i=2;i<=n;++i)
		pre[i]=min(pre[i-1],b[i].x);
	for(int i=2;i<=n;++i)
		ans=max(ans,b[i].y+pre[i-1]);
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i].l>>a[i].r;
	pl=pr=1;
	for(int i=1;i<=n;++i)
	{
		if(a[i].l>a[pl].l)
			pl=i;
		if(a[i].r<a[pr].r)
			pr=i;
	}
	solve1();
	solve2();
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5608
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int A, B;
    cin >> A >> B;

    write(max(0, A - 2 * B));
}

Measured memory_bytes: 892
import java.util.Scanner;	//Scannerクラス：Java標準入力を取得する

class Main{
	public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {	//Scanerクラスを変数scで使えるようにする
            int W = sc.nextInt();	//二つの変数a,b,cに整数を入力
            int H = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            int r = sc.nextInt();

            if(W - r < x || r > x || H - r < y || r > y) {
            	System.out.println("No");
            }else {
            	System.out.println("Yes");
            }
         }
     }
}



Measured memory_bytes: 26412
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    long double a,b;cin>>a>>b;
    long double res=a*b+0.005;
    ll ans=floorl(res);
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  vector<int> a(3);
  for(int i = 0; i < 3; i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  cout << a.at(0) << " " << a.at(1) << " " << a.at(2) << endl;

}


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


void solve () {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a[x]++;
    }
    int start = 1;
    if (n % 2) start = 0;
    for (int i = start; i < n; i += 2) {
        if (a[i] != 2) {
            if(i == 0 && a[i] == 1) continue;
            cout << 0;
            return;
        }
    }
    long long ans = 1;
    long long md = 1e9 + 7;
    for (int i = 0; i < n/2; i++) {
        ans = (ans * 2) % md;
    }
    cout << ans;
}

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


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll X;
  cin >> X;

  ll a = X / 500;

  X -= a * 500;

  ll b = X / 5;

  cout << a * 1000 + b * 5 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#define maxn 100009
using namespace std;
int n, a[maxn];
int dp[maxn][30];

int gcd(int a, int b){
	if (a < b)
		swap(a, b);
	return b == 0 ? a : gcd(b, a % b);
}

void init(){
	for(int i = 0; i < n; i++)
		dp[i][0] = a[i];
	for(int j = 1; 1 << j <= n; j++){
		for (int i = 0; i + (1 << j) - 1 < n; i++){
			dp[i][j] = gcd(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
		}
	}
}

int rmq(int l, int r){
	int k = log2(r - l + 1);
	return gcd(dp[l][k], dp[r - (1 << k) + 1][k]);
}

int main(){
	cin >> n;
	for(int i = 0 ; i < n; i++)
		scanf("%d", &a[i]);
	init();
	int ans = 1;
	for(int i = 0; i < n; i++){
		if(i == 0)
			ans = max(ans, rmq(i + 1, n - 1));
		else if(i == n - 1)
			ans = max(ans, rmq(0, n - 2));
		else
			ans = max(ans, gcd(rmq(0, i - 1), rmq(i + 1, n - 1)));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12416
package main

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

var ar []int
var br []bool
var g map[int][]int
var qr []int

func main() {
	sc.Split(bufio.ScanWords)
	n, q := ri(), ri()
	g = map[int][]int{}
	for i := 1; i < n; i++ {
		a, b := ri(), ri()
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}
	qr = make([]int, n+1)
	for i := 0; i < q; i++ {
		p, x := ri(), ri()
		qr[p] += x
	}
	ar = make([]int, n+1)
	br = make([]bool, n+1)
	dfs(1, 0)
	ans := fmt.Sprint(ar)
	fmt.Println(ans[3 : len(ans)-1])
}

func dfs(key, sum int) {
	if br[key] {
		return
	}
	br[key] = true
	sum += qr[key]
	ar[key] = sum
	ret := g[key]
	for _, v := range ret {
		dfs(v, sum)
	}
}

var sc = bufio.NewScanner(os.Stdin)

func ri() int {
	sc.Scan()
	s := sc.Text()
	a, _ := strconv.Atoi(s)
	return a
}


Measured memory_bytes: 79872
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N){
        cin >> A[i];
    }
    sort(ALL(A), greater<int>());
    A.emplace_back(0);
    int i=0;
    while (i<N && A[i+1]-(i+1)>0){
        i++;
    }
    // debug(mp(i,A[i]))
    if((A[i]-i)&1){ //上に進む回数が奇数なら上に行った時自分が負ける
        int right_cnt = 0;
        do{
            right_cnt++;
        }while(A[i+right_cnt]>i);
        // debug(right_cnt)
        if(right_cnt&1){ //右に進む回数が奇数なら右に行った時自分が負ける
            cout << "Second" << bn;
            return 0;
        }
    }
    cout << "First" << bn;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef pair<int,int> Pt;
typedef pair<int,Pt> P;
#define fr first
#define sc second
#define INF 10000000
struct edge{
  int to,cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
int N,M,L,K,A,H,d[100][101];
bool cool[100];
vector< vector<edge> > info;
void init();
int Dijkstra();
int main(){
  int n,m,a,b,c;
  while(cin >> N >> M >> L >> K >> A >> H && N){
    init();
    while(L--){
      cin >> a;
      cool[a] = true;
    }
    while(K--){
      cin >> a >> b >> c;
      info[a].push_back(edge(b,c));
      info[b].push_back(edge(a,c));
    }
    int ans = Dijkstra();
    if(ans == -1) cout << "Help!" << endl;
    else cout << ans << endl;
    info.clear();
  }
}
void init(){
  info.resize(N);
  for(int i=0;i<N;i++){
    for(int j=0;j<=M;j++) d[i][j] = INF;
    cool[i] = false;
  }
}
int Dijkstra(){
  priority_queue<P,vector<P>,greater<P> > que;
  d[A][M] = 0;
  que.push(P(0,Pt(A,M)));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int c = p.fr,now = p.sc.fr,lim = p.sc.sc;
    if(d[now][lim] < c) continue;
    if(now == H) return c;
    if(!cool[now]){
      for(int i=0;i<info[now].size();i++){
        edge e = info[now][i];
        if(lim - e.cost >= 0 && c + e.cost < d[e.to][lim - e.cost]){
          d[e.to][lim - e.cost] = c + e.cost;
          que.push(P(d[e.to][lim - e.cost],Pt(e.to,lim - e.cost)));
        }
      }
    }else{
      for(int i=0;i<info[now].size();i++){
        for(int j=lim,k=0;j<=M;j++,k++){
          edge e = info[now][i];
          if(j - e.cost >= 0 && c + e.cost + k < d[e.to][j - e.cost]){
            d[e.to][j - e.cost] = c + e.cost + k;
            que.push(P(d[e.to][j - e.cost],Pt(e.to,j - e.cost)));
          }
        }
      }
    }
  }
  return -1;
}

Measured memory_bytes: 1628
import sys
import math


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    X = list(map(int, input().split()))
    X.sort()
    if M <= N:
        print(0)
        exit()

    diff = [0] * (M - 1)
    for i in range(M - 1):
        diff[i] = X[i + 1] - X[i]

    diff.sort()
    print(sum(diff[:M-N]))


if __name__ == "__main__":
    main()


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

using namespace std;

int main(){
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<int64_t> A(x), B(y), C(z);
  for (int i = 0; i < x; i++) cin >> A[i];
  for (int i = 0; i < y; i++) cin >> B[i];
  for (int i = 0; i < z; i++) cin >> C[i];
  
  sort(A.begin(), A.end(), greater<int64_t>());
  sort(B.begin(), B.end(), greater<int64_t>());
  sort(C.begin(), C.end(), greater<int64_t>());
  
  priority_queue<tuple<int64_t, int, int, int>> q;
  q.push(make_tuple(A[0] + B[0] + C[0], 0, 0, 0));
  int a, b, c;
  vector<int> d = {1, 0, 0};
  int64_t sum = 0;
  vector<int64_t> ans;
  set<tuple<int, int, int>> used;
  while(ans.size() != k){
    tie(sum, a, b, c) = q.top(); q.pop();
    if (used.count(make_tuple(a, b, c)) > 0)
      continue;
    used.insert(make_tuple(a, b, c));
    ans.push_back(sum);
    int na, nb, nc;
    for (int j = 0; j < 3; j++){
      na = a + d[j];
      nb = b + d[(j + 1) % 3];
      nc = c + d[(j + 2) % 3];
      if (na >= x) continue;
      if (nb >= y) continue;
      if (nc >= z) continue;
      q.push(make_tuple(A[na] + B[nb] + C[nc], na, nb, nc));
    }
  }
    
  for (const auto &ans_: ans)
    cout << ans_ << endl;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


T = input()

ans = list()
for i, c in enumerate(T):
    if c == '?':
        if len(ans) > 0 and ans[-1] == 'D' and i < len(T) - 1 and T[i + 1] in '?D':
            ans.append('P')
        else:
            ans.append('D')
    else:
        ans.append(c)
print(''.join(ans))


Measured memory_bytes: 83308
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

N, M = LI()
X = LI()
X = sorted(X)
X_dist = []
for i in range(M-1):
    X_dist.append(abs(X[i] - X[i+1]))
#  print(X_dist)
X_dist = sorted(X_dist, reverse=True)
print(sum(X_dist[N-1:]))


Measured memory_bytes: 15668
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666,inf=0x3f3f3f3f,mo=1e9+7;
int n,x,y,val[N],a[N],fac[N],ifac[N],len;Vi e[N];
struct ele{
	int c,w;
}s[N];
bool cmp(int a, int b){return val[a]<val[b];}
void lisan(){
	static int a[N];len=0;rep(i,1,n)a[++len]=s[i].c;
	sort(a+1,a+len+1);len=unique(a+1,a+len+1)-a-1;
	rep(i,1,n)s[i].c=lower_bound(a+1,a+len+1,s[i].c)-a;
	rep(i,1,len)val[i]=inf;rep(i,1,n)val[s[i].c]=min(val[s[i].c],s[i].w);
	static int id[N];rep(i,1,len)id[i]=i;sort(id+1,id+len+1,cmp);
	static int pos[N];rep(i,1,len)pos[id[i]]=i;
	rep(i,1,n)s[i].c=pos[s[i].c];
	rep(i,1,len)val[i]=inf;rep(i,1,n)val[s[i].c]=min(val[s[i].c],s[i].w);
	rep(i,1,len-1)assert(val[i]<=val[i+1]);
}
int power(int a, int n){
	int res=1;
	while(n){
		if(n&1)res=1LL*res*a%mo;
		a=1LL*a*a%mo;n>>=1;
	}
	return res;
}
int main() {
	read(n);read(x);read(y);rep(i,1,n)read(s[i].c),read(s[i].w);
	lisan();while(len>1&&val[len]+val[1]>y)len--;if(len==1){puts("1");return 0;}
	rep(i,1,n)e[s[i].c].pb(s[i].w);rep(i,1,len)sort(e[i].begin(),e[i].end());
	fac[0]=1;rep(i,1,n)fac[i]=1LL*fac[i-1]*i%mo;
	ifac[n]=power(fac[n],mo-2);per(i,n-1,0)ifac[i]=1LL*ifac[i+1]*(i+1)%mo;
	int tot=0,res=1;
	rep(i,1,len){
		int mn=i>1?val[1]:val[2];
		a[i]=0;while(a[i]+1<SZ(e[i])&&(e[i][0]+e[i][a[i]+1]<=x||mn+e[i][a[i]+1]<=y))a[i]++;
		tot+=a[i]+1;res=1LL*res*ifac[a[i]+1]%mo;
	}
	res=1LL*res*fac[tot]%mo;cout<<(res+mo)%mo;
	return 0;
}


Measured memory_bytes: 40960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N;
	cin >> N;

	int A[1001][999];
	rep1(i, N) rep(j, N - 1) {
		cin >> A[i][j];
	}

	int k[1001] = {};
	vector<int> V;
	rep1(i, N) {
		V.pb(i);
	}

	set<pair<int, int>> ST;

	int kotae = 0;
	int OK = 1;
	while (V.size()) {

		vector<int> kari;

		int hiita = 0;
		pair<int, int> mae = mp(-1, -1);
		for (auto v : V) {


			int a = A[v][k[v]];
			int b = v;
			if (a > b) swap(a, b);
			k[v]++;

			auto itr = ST.find(mp(a, b));
			if (itr != ST.end()) {
				hiita = 1;
				ST.erase(itr);
				if (k[a] < N - 1) {
					kari.pb(a);
				}
				if (k[b] < N - 1) {
					kari.pb(b);
				}
				//if (k[a] < N - 1) {
				//	int aa = A[a][k[a]];
				//	int bb = a;
				//	if (aa > bb) swap(aa, bb);
				//	kari.pb(mp(aa, bb));
				//	k[a]++;
				//}
				//if (k[b] < N - 1) {
				//	int aa = A[b][k[b]];
				//	int bb = b;
				//	if (aa > bb) swap(aa, bb);
				//	kari.pb(mp(aa, bb));
				//	k[b]++;
				//}
			}
			else {
				ST.insert(mp(a, b));
			}
		}

		V = kari;

		if (hiita == 0) {
			OK = 0;
			break;
		}

		kotae++;
	}

	if (OK) co(kotae);
	else co(-1);


	Would you please return 0;
}

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

int main()
{
    vector<int> vec(5) ;
    rep(i,5)
    {
        cin >> vec.at(i) ;
        if(vec.at(i) == 0)
        {
            cout << i+1  << endl ;
            return 0 ;
        }   
    }
    
}

Measured memory_bytes: 3624
#include <iostream>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int a[3];
    rep(i, 3)   cin >> a[i];
    int count5 = 0;
    int count7 = 0;
    rep(i, 3){
        if(a[i] == 5)   count5++;
        if(a[i] == 7)   count7++;
    }
    if(count5 == 2 && count7 == 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#define INF (int)1e09
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

template <typename T> using Vec = vector<T>; // c++11

struct POST {
    int number;
    int depth;
    string name;
    Vec<POST> reply;
    POST() {}
    POST(int new_number, int new_depth, string new_name) {
        number = new_number;
        depth = new_depth;
        name = new_name;
    }
};

void init_data (POST &data, string m, int k) {
    data.number = 0;
    data.depth = 0;
    data.name = m;
    return;
}

void history (Vec<int> &parent, Vec<int> &pursue_list, int k) {
    int temp = k;
    while (1) {
        if (temp == 0) {
            break;
        }
        temp = parent[temp];
        pursue_list.push_back(temp);
    }
    return;
}

void pursue (POST &data, Vec<int> &pursue_list, int pursue_len, int now_depth, int k, string m, int i) {
    if (now_depth == pursue_len - 1) {
        string dot(data.depth + 1, '.');
        POST new_data(i, data.depth + 1, dot + m);
        data.reply.push_back(new_data);
    } else {
        int loop = 0;
        while (1) {
            if (data.reply[loop].number == pursue_list[pursue_len - now_depth - 2]) {
                pursue(data.reply[loop], pursue_list, pursue_len, now_depth + 1, k, m, i);
                break;
            } else {
                loop++;
            }
        }
    }
    return;
}

void output (POST& data) {
    int rep_len = (int)data.reply.size();
    for (int i = 0; i < rep_len; i++) {
        cout << data.reply[i].name << endl;
        output(data.reply[i]);
    }
    return;
}

int main(void) {
    int n;
    cin >> n;
    POST data;
    Vec<int> parent;
    parent.push_back(-1);

    int k;
    string m;
    cin >> k >> m;
    k--;
    init_data(data, m, k);
    cout << m << endl;

    for (int i = 1; i < n; i++) {
        cin >> k >> m;
        k--;
        parent.push_back(k);
        Vec<int> pursue_list;
        pursue_list.push_back(k);
        history(parent, pursue_list, k);
        int pursue_len = (int)pursue_list.size();
        pursue (data, pursue_list, pursue_len, 0, k, m, i);
    }

    output(data);
    return 0;
}

Measured memory_bytes: 4504
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<utility>
#include<vector>
#define maxn 10005
#define maxm 40005
#define inf 0x3f3f3f3f
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
struct edge{
	int to,dis,cst;
}el[maxm];
int n,m,head[maxn],nxt[maxm],d[maxn],E;
vector <int> prv[maxn];
inline void addedge(int u,int v,int w,int x){
	E++;
	el[E].to = v;el[E].dis = w;el[E].cst = x;
	nxt[E] = head[u];
	head[u] = E;
}
inline void dij(){
	memset(d,0x3f,sizeof(d));
	d[1] = 0;
	priority_queue <P,vector<P>,greater<P> > que;
	while(!que.empty()) que.pop();
	que.push(mp(0,1));
	while(!que.empty()){
		P p = que.top();que.pop();
		if(p.first > d[p.second]) continue;
		for(int i=head[p.second];i!=-1;i=nxt[i]){
			if(d[p.second] + el[i].dis < d[el[i].to]){
				d[el[i].to] = d[p.second] + el[i].dis;
				prv[el[i].to].clear();
				prv[el[i].to].pb(i);
				que.push(mp(d[el[i].to],el[i].to));
			}else if(d[p.second] + el[i].dis == d[el[i].to]){
				prv[el[i].to].pb(i);
			}
		}
	}
}
int main(){
	while(~scanf("%d%d",&n,&m) && (n!=0||m!=0)){
		memset(head,-1,sizeof(head));
		E=0;
		for(int i=1;i<=n;i++) prv[i].clear();
		for(int i=1;i<=m;i++){
			int u,v,w,x;
			scanf("%d%d%d%d",&u,&v,&w,&x);
			addedge(u,v,w,x);
			addedge(v,u,w,x);
		}
		dij();
		int ans = 0;
		for(int i=2;i<=n;i++){
			int mn = inf;
			for(int j=0;j<prv[i].size();j++) mn = min(mn,el[prv[i][j]].cst);
			ans += mn;
		}
		printf("%d\n",ans);
	}
	return 0;
}



Measured memory_bytes: 4520
#include <iostream>

using namespace std;

int main(){
	int N[2];
	
	cin >> N[0] >> N[1];
	unsigned long long map[2][64];
	
	for (int i = 0; i < 2; i++){
		for (int j = 0; j < N[i]; j++){
			char in[50];
			cin >> in;
			map[i][j] = 0;
			for (int k = 0; k < N[i]; k++){
				unsigned long long tmp = 1;
				if (in[k] == '#') map[i][j] = map[i][j] | (tmp<<k);
			}
		}
	}
	unsigned long long mask = 1;
	mask = (mask << N[1]);
	mask--;
	
	for (int i = 0; i <= (N[0] - N[1]); i++){
		for (int j = 0; j <= (N[0] - N[1]); j++){
			for (int k = 0; k < N[1]; k++){
				if (((map[0][i+k] & (mask << j)) != (map[1][k] << j))){break;}
				if (k == (N[1] - 1)) { cout << "Yes" << endl;  return 0; }
			}
		}
	}
	cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

const int N=1e5+9;

int bit[N],ans[2];
int n,g[N][3],p[N];

inline int lolbit(int x){return x&(-x);}

inline void add(int pos)
{
	for(int i=pos;i;i-=lolbit(i))
		bit[i]++;
}
inline int query(int pos)
{
	int ret=0;
	for(int i=pos;i<=N;i+=lolbit(i))
		ret+=bit[i];
	return ret;
}

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

inline void end()
{
	puts("No");
	exit(0);
}

int main()
{
	n=read();
	for(int i=0;i<=2;i++)
		for(int j=1;j<=n;j++)
			g[j][i]=read();
	for(int i=1;i<=n;i++)
	{
		int a=g[i][0],b=g[i][1],c=g[i][2];
		if(c-b==1 && b-a==1 && c%3==0)
			p[i]=c/3;
		else if(a-b==1 && b-c==1 && a%3==0)
			p[i]=a/3,ans[i&1]^=1;
		else end();
		if((p[i]-i)&1)
			end();
	}

	for(int i=1;i<=n;i+=2)
	{
		ans[0]^=(query(p[i])&1);
		add(p[i]);
	}
	memset(bit,0,sizeof(bit));
	for(int i=2;i<=n;i+=2)
	{
		ans[1]^=(query(p[i])&1);
		add(p[i]);
	}

	if(!(ans[0]|ans[1]))
		puts("Yes");
	else end();
	return 0;
}


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


#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int N = 2e5 + 10;

int ans;

using namespace std;

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  IOS;


  
  string  s;

  cin>>s;

  int i=0;

  if(s[i] >= 'A' && s[i] <= 'Z' )
  {
    cout<<"A"<<endl;
  }

  else
  {
    cout<<"a"<<endl;
  }

  
}


Measured memory_bytes: 3584
#include <stdio.h>

int main(void){
	int N,K,X,Y,ans;
	scanf("%d",&N);
	scanf("%d",&K);
	scanf("%d",&X);
	scanf("%d",&Y);
	if(N <= K){
		printf("%d\n",N*X);
	}else{
		ans = K*X + (N-K)*Y;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
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; }
 
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 
inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
 
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int N,A,B,C;
vi L;
int rec(int i, int a, int b, int c){
  if(i==N){
    if(!a||!b||!c) return INF;
    return abs(A-a)+abs(B-b)+abs(C-c);
  }
  int res=rec(i+1,a,b,c);
  
  chmin(res,rec(i+1,a+L[i],b,c)+(a?10:0));
  chmin(res,rec(i+1,a,b+L[i],c)+(b?10:0));
  chmin(res,rec(i+1,a,b,c+L[i])+(c?10:0));
  
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int d,g; cin>>d>>g;
  vi p(d), c(d);
  rep(i,d) cin>>p[i]>>c[i];
  
  int ans=INF;
  for(int bit=0; bit<(1<<d); bit++){
    int tmp=0;
    int score=0;
    rep(i,d){
      if(bit&(1<<i)){
        tmp+=p[i];
        score+=(100*(1+i))*p[i]+c[i];
      }
    }
    if(score<g){
      rrep(i,d){
        bool flg=false;
        if(bit&(1<<i)) continue;
        rep(j,p[i]){
          tmp++;
          score+=100*(i+1);
          if(score>=g){
            flg=true;
            break;
          }
        }
        if(flg) break;
      }
    }
    chmin(ans, tmp);
  }
  cout<<ans<<endl;
}

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

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
int main()
{
    fast();
    ll a =lD();
    cout<<a+a*a+a*a*a<<endl;
}


Measured memory_bytes: 3620
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int max = 0;
		int temp = 0;
		for(int i = 0; i < S.length(); i++) {
			if(S.substring(i, i + 1).equals("A") || S.substring(i, i + 1).equals("C") || S.substring(i, i + 1).equals("G") || S.substring(i, i + 1).equals("T")) {
				temp++;
			} else {
				max = Math.max(max, temp);
				temp = 0;
			}
		}
		System.out.println(Math.max(max, temp));
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <float.h>
#include <stdlib.h>
#include <functional>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define in cin >>
#define out cout <<
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define all(v) v.begin(),v.end()
typedef long long ll;

int main() {
    int n;
      cin >> n;
    int n2=n+2;
    vector<int> h(n2);
    vector<int> dp(n2);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1];
}


Measured memory_bytes: 1024
MOD = 2019

L, R = [int(i) for i in input().strip().split()]

if (L // MOD) != (R // MOD):
  print(0)
else:
  res = R*R
  for i in range(L, R):
    for j in range(i+1, R+1):
      _, r = divmod(i*j, MOD)
      if r < res:
        res = r
  print(res)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    string s, t;
    cin >> s >> t;
    int Ns = s.size();
    int Nt = t.size();
    vector<vector<int>> dp(Ns+1, vector<int>(Nt+1));
    REP(i, Ns) REP(j, Nt){
        dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + int(s[i]==t[j]));
    }

    string ans = "";
    int i = Ns;
    int j = Nt;
    while(i != 0 && j != 0){
        if(dp[i][j] == dp[i-1][j]) i--;
        else if(dp[i][j] == dp[i][j-1]) j--;
        else{
            ans = s[i-1] + ans;
            i--; j--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
//https://atcoder.jp/contests/abc121/tasks/abc121_b
#include<iostream>
using namespace std;

int main() {
    int N,M,C;
    cin >> N >> M >> C;
    int *B = new int[M];
    for(int i=0;i<M;i++)cin>>B[i];
    int *A = new int[M];
    int ans=0;
    for (int i = 0; i < N; i++)
    {
        for(int j=0;j<M;j++)cin>>A[j];
        int saurce = C;
        for(int j=0;j<M;j++)saurce+=A[j]*B[j];
        //cout << saurce << endl;
        if(saurce>0)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = list(zip(B, A))
C.sort()
B, A = zip(*C)
t = 0
for c in C:
    t += c[1]
    if t <= c[0]:
        continue
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 53332
/*
                                                  __          __
      /\   |   |     /\   |  | |  |     /\   | / |  )   /\   |  )
     /__\  |   |    /__\  |--| |  |    /__\  |<  |-<   /__\  |-<
    /    \ |__ |__ /    \ |  | \__/   /    \ | \ |__) /    \ |  \

*/

#import<bits/stdc++.h>
typedef long long ll;
#define forl(n) for(int i=0; i<n; i++)
#define forll(i,a,b,c) for(int i=a; i<b; i+=c)
#define pb(n) push_back(n)

using namespace std;

int main()
{
    int m=0,b,n;
    cin>>n>>b;
    int p[n],x=0;
    forl(n){cin>>p[i];x+=p[i];}
    if(x%(4*b)==0)x=x/(4*b);
    else x=(x/(4*b))+1;
    forl(n)
    {
        if(p[i]>=x){m++;}
    }
    if(m>=b){cout<<"Yes\n";}
    else{cout<<"No\n";}
}


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

int main(){
    int h1,h2,k1,k2,a,b,c,d,hiroshi=0,kenjiro=0;
    cin>>h1>>h2;
    cin>>k1>>k2;
    cin>>a>>b>>c>>d;

    hiroshi=(h1*a)+(h2*b)+((h1/10)*c)+((h2/20)*d);
    kenjiro=(k1*a)+(k2*b)+((k1/10)*c)+((k2/20)*d);
    if(hiroshi<kenjiro){
        cout<<"kenjiro"<<endl;
    }else if(kenjiro<hiroshi){
        cout<<"hiroshi"<<endl;
    }else{
        cout<<"even"<<endl;
    }
    return 0;

}


Measured memory_bytes: 3096
function Main(input) {
	var a = 0;
    input = input.split("\n");
	a = parseInt(input[0], 10);
	var a1 = Math.floor(a/100);
	a = a%100;
	var a2 = Math.floor(a/10);
	a = a%10;
	var a3 = Math.floor(a);
	console.log(a1+a2+a3);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    int n;
    cin>>n;
    if(n<1200) cout<<"ABC";
    else if(n<2800) cout<<"ARC";
    else cout<<"AGC";
}

Measured memory_bytes: 256
# coding: utf-8
import re
import math
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 

 
#main
h,n=map(int,input().split())
AB=[list(map(int,input().split())) for a in range(n)]
dp=[inf]*(h+1)
dp[0]=0

for a in range(1,n+1):
    for b in range(0,h+1):
        key=min(h,b+AB[a-1][0])
        dp[key]=min(dp[key],dp[b]+AB[a-1][1])
print(dp[h])

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	vector<int> num(100);
	int ans=0;
	num.at(a-1)++;
	num.at(b-1)++;
	num.at(c-1)++;
	for(int i=0; i<100; i++){
		if(num.at(i)!=0){
			ans++;
		}
	}
	cout << ans << endl;
}


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


int main(){
  int N,M;
  map<string, int> m;
  map<string, int>::iterator ite;

  cin >> N;
  for(int i=0; i<N; i++){
    string s; cin >> s;
    ite = m.find(s);

    if (ite == m.end()){
      m[s] = 1;
    } else {
      m[s]++;
    }
  }

  cin >> M;
  for(int i=0; i<M; i++){
    string s; cin >> s;
    ite = m.find(s);

    if (ite == m.end()){
      m[s] = -1;
    } else {
      m[s]--;
    }
  }

  int max = 0;
  for(ite = m.begin(); ite != m.end(); ite++){
    if(max < ite->second) max = ite->second;
  }

  cout << max << endl;
}

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

int main(){
    int N;
    cin >> N;
    int64_t L0 = 2;
    int64_t L1 = 1;
    for (int i=0;i<N-1;i++){
        int64_t L2 = L1 + L0;
        L0 = L1;
        L1 = L2;
    }
    cout << L1 << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

string s;
int n;
ll dp[100005][13];  // dp[i][j] : 先頭i文字として考えられるもののうち13で割ったあまりがjのものの数

void solve() {
    ll ans = 0;
    n = s.size();

    dp[0][0] = 1;
    rep(i, n) {
        int c;
        //s[i]が?だったら-1,それ以外はs[i]がcに入る
        if(s[i] == '?') {
            c = -1;
        }
        else {
            c = s[i] - '0';
        }

        // sのi+1文字目をjとする
        // c = -1のとき j = 0 ～ 9 全てで処理が行われる
        // それ以外は j = c のとき処理が行われる
        rep(j, 10) {

            if(c != -1 && j != c) {
                continue;
            }
            /* 先頭i文字を13で割った余りをkとすると
               i+1文字目までの余りは (10*k + j)%13 になる */
            rep(k, 13) {
                dp[i+1][ (10*k + j)%13 ] += dp[i][k];
            }
        }

        rep(j, 13) {
            dp[i+1][j] %= mod;
        }
    }

    cout << dp[n][5] << endl;
}

int main() {
    cin >> s;
    
    solve();
    
    return 0;
}

Measured memory_bytes: 10624
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	string s;
	cin >> s;
	if (s == "SUN") { cout << 7 << endl; }
	else if (s == "MON") { cout << 6 << endl; }
	else if (s == "TUE") { cout << 5 << endl; }
	else if (s == "WED") { cout << 4 << endl; }
	else if (s == "THU") { cout << 3 << endl; }
	else if (s == "FRI") { cout << 2 << endl; }
	else if (s == "SAT") { cout << 1 << endl; }
	return 0;
}


Measured memory_bytes: 256