akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void) {
	int K;
	int gusu, kisu;
	if (scanf("%d", &K) != 1) return 1;
	gusu = K / 2;
	kisu = (K + 1) / 2;
	printf("%d\n", gusu * kisu);
	return 0;
}


Measured memory_bytes: 128
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    
    ans = sum(B)
    for i in range(N-1):
        if A[i] + 1 == A[i+1]:
            ans += C[A[i] - 1]
    
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
#include <iostream>
#include <string>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main()
{
	int s,w;
	cin >> s;
	cin >> w;

	if (w >= s) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}
}

Measured memory_bytes: 3624
n = int(input())
s = input()
s += s[0]
ans = [''] * (n+1)
rev_dic = {'S':'W', 'W':'S'}
for a0,a1 in zip('SSWW','SWSW'):
    ans[0] = a0
    ans[1] = a1
    for i in range(1,n):
        if(ans[i] == 'S')&(s[i] == 'o'):
            ans[i+1] = ans[i-1]
        elif(ans[i] == 'S')&(s[i] == 'x'):
            ans[i+1] = rev_dic[ans[i-1]]
        elif(ans[i] == 'W')&(s[i] == 'o'):
            ans[i+1] = rev_dic[ans[i-1]]
        elif(ans[i] == 'W')&(s[i] == 'x'):
            ans[i+1] = ans[i-1]
    if(ans[0] == ans[-1]):
        if(ans[0]=='S')&(s[0]=='o')&(ans[n-1]==ans[1]):
            print(''.join(ans[:-1]))
            exit()
        if(ans[0]=='S')&(s[0]=='x')&(ans[n-1]!=ans[1]):
            print(''.join(ans[:-1]))
            exit()
        if(ans[0]=='W')&(s[0]=='o')&(ans[n-1]!=ans[1]):
            print(''.join(ans[:-1]))
            exit()
        if(ans[0]=='W')&(s[0]=='x')&(ans[n-1]==ans[1]):
            print(''.join(ans[:-1]))
            exit()
print(-1)

Measured memory_bytes: 69964
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		for (int i = 1, j = m + 1; i < j; i++, j--)
			println(i + " " + j);
		for (int i = m + 2, j = m + m + 1; i < j; i++, j--)
			println(i + " " + j);
	}
}


Measured memory_bytes: 44800
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int A, B;
    cin >> A >> B;
    cout << max({A + B, A - B, A * B}) << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

H, W = mi()
C = li2(10)
A = li2(H)

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k]+C[k][j])

ans = 0
for i in range(H):
    for j in range(W):
        if abs(A[i][j]) != 1:
            ans += C[A[i][j]][1]

print(ans)

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main
{
    private final static Main main = new Main();

    public static void main(String[] args)
    {
        long l = System.currentTimeMillis();
        main.contest();
        //System.out.println("処理時間：" + (System.currentTimeMillis() - l));
    }

    private void contest()
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.nextLine();
        char[] cs = sc.nextLine().toCharArray();
        int _a = 0;
        int _b = 0;
        for(char c : cs)
        {
            switch(c)
            {
                case 'a':
                {
                    if(a+b > _a+_b)
                    {
                        ++_a;
                        System.out.println("Yes");
                    }
                    else
                    {
                        System.out.println("No");
                    }
                    break;
                }
                case 'b':
                {
                    if(a+b > _a+_b && b > _b)
                    {
                        ++_b;
                        System.out.println("Yes");
                    }
                    else
                    {
                        System.out.println("No");
                    }
                    break;
                }
                default:
                {
                    System.out.println("No");
                }
            }
        }
    }
}


Measured memory_bytes: 24060
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define eb emplace_back
#define in insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define OUT(a, e) FOR(i, e, 0) cout << a[i] << ' '
#define OUTV(a) for(auto i : a) cout << i << ' ';
#define maxim(a, n, mx) FOR(i, n, x)mx = max(mx, a[i]);

using namespace std;

int main()
{
    int n; cin >> n;
    ld cnt = 0;
    FOR(i, n + 1, 1)
    {
        if(i % 2)cnt++;
    }
    cout << fixed << setprecision(6) << cnt / n;
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

    int n=N;
    int S=0;
    while(n){
        S+=n%10;
        n/=10;
    }
    if(N%S==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);

// --------- UnionFind木 ---------
class UnionFind {
public:
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) std::swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
private:
    std::vector<int> data;
};

// --------- KMP法 ---------
// 計算量: O(n+m)
std::vector<int> kmp(const std::string& s, const std::string& t) {
    std::vector<int> ta(t.size() + 1);

    {
        ta[0] = -1;
        int j = -1;
        for (int i = 0; i < (int)t.size(); ++i) {
            while (j >= 0 && t[i] != t[j])
                j = ta[j];
            ta[i + 1] = ++j;
        }
    }

    std::vector<int> ret;
    int m = 0, i = 0, n = (int)s.size();
    while (m + i < n) {
        if (t[i] == s[m + i]) {
            if (++i == (int)t.size()) {
                ret.push_back(m);
                m = m + i - ta[i];
                i = ta[i];
            }
        }
        else {
            m = m + i - ta[i];
            if (i > 0)
                i = ta[i];
        }
    }

    return ret;
}


std::string s, t;
int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> s >> t;

    int n = (int)s.size(), m = (int)t.size();
    {
        std::string ss;
        while ((int)ss.size() < m)
            ss += s;
        s = ss;
        s += ss;
    }

    auto z = kmp(s, t);
    auto uf = UnionFind(n);
    for (int i = 0; i < (int)z.size(); ++i) {
        auto x = z[i];

        if (x >= n)
            continue;
        auto y = (x + m) % n;
        if (!uf.unionSet(x, y)) {
            std::cout << -1 << std::endl;
            return 0;
        }
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i)
        ans = std::max(ans, uf.size(i) - 1LL);

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 14036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,q,ans;
    string s;
    cin>>n>>s>>q;
    set<ll>se[26];
    rep(0,i,n)se[s[i]-'a'].insert(i+1);
    rep(0,nq,q){
        ll q0;
        cin>>q0;
        if(q0==1){
            ll i;
            char c;
            cin>>i>>c;
            rep(0,al,26)if(se[al].erase(i))break;
            se[c-'a'].insert(i);
        }else{
            ll l,r;
            cin>>l>>r;
            ans=0;
            rep(0,al,26){
                auto r0=se[al].lower_bound(l);
                if(r0!=se[al].end()&&*r0<r+1)++ans;
            }
            cout<<ans<<endl;
        }
    }
    
}


Measured memory_bytes: 26244
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int charcount = s.length() - 2;
		System.out.println(s.substring(0, 1) + charcount + s.substring(s.length() - 1,s.length()));
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <bitset>
#include <utility>
#include <sstream>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <complex>
#include <set>
#include <iomanip>

using namespace std;

#define INF 1070000000LL
#define pb push_back
#define irep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) irep(i,0,n)

typedef long long lint;
typedef pair<int, int> pint;
struct Edge{
    int to,weight;
};
typedef vector<vector<Edge> > Graph;


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    double ans = 0;
    rep(i,n){
	ans += (double)1/a[i];
    }
    cout << fixed << setprecision(5) << (double)1/ans << endl;
}


Measured memory_bytes: 256
// 未解決

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
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;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

//**********

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

  string s, t;
  cin >> s >> t;
  if (s.size() + 1 == t.size() && t.substr(0, s.size()) == s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
};


Measured memory_bytes: 3656
import os

import math
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

A, B, H, M = list(map(int, sys.stdin.buffer.readline().split()))

h = (H / 12 + M / (12 * 60)) * math.pi * 2
m = M / 60 * math.pi * 2

theta = abs(h - m)
if theta > math.pi * 2:
    theta = math.pi * 2 - theta
cc = A ** 2 + B ** 2 - 2 * A * B * math.cos(theta)
ans = math.sqrt(cc)
print(ans)


Measured memory_bytes: 9596
n=str(input())
a=set(n)
p=0
if len(a)==1:
  p=1
elif len(a)==2:
  b=n[0]
  if b==n[1] and b==n[2]:
      p=1
  b=n[1]
  if b==n[2] and b==n[3]:
      p=1
if p==1:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		for(int i=0;i<input.length();i++) {
			char c = input.charAt(i);
			if (c>='D') {
				c-=3;
			}else{
				c+=23;
			}
			System.out.print(c);
		}
		System.out.println();
	}
}

Measured memory_bytes: 17224
#include<bits/stdc++.h>
using namespace std;
int main() {
    int count=0;
    int d, n, f;
    cin >> n;
    f = n;
    d = log10(n)+1;
    for(int i=0; d > 0; i++){
        count += n % 10;
        n /= 10;
        d--;
    }
    if(f%count == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
ll N, M;
vector<vector<int> > G(100005);
int col[100005]; // 白-1黒1
// 奇サイクルがあるかどうか
bool dfs(int v, int c) {
  if(col[v] && col[v] != c) return true;
  bool ret = false;
  if(col[v] == 0) {
    col[v] = c;
    for(int to : G[v]) {
      ret |= dfs(to, -c);
    }
  }
  return ret;
} 
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  FOR(i,0,M) {
    int a, b; cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  if(dfs(1, 1)) {
    cout << N * (N - 1) / 2 - M << endl;
  } else {
    int cnt = 0;
    FOR(i,1,N+1) {
      if(col[i] == 1) cnt++;
    }
    cout << cnt * (N - cnt) - M << endl;
  }
  return 0;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    int **A = new int*[n];
    for(int i = 0; i < n; i++) A[i] = new int[m];
    int *b = new int[m];
    int *ans = new int[n];

    // ?????????????????????
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> A[i][j];
        }
        ans[i] = 0; // ??????????´???´???????????????
    }
    for(int i = 0; i < m; i++) cin >> b[i];

    // ?¨??????¨???
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            ans[i] += A[i][j] * b[j];
        }
    }

    // ???????????¨???
    for(int i = 0; i < n; i++) cout << ans[i] << endl;

    // ?¢???????????????¢??????????????????
    for(int i = 0; i < n; i++) delete[] A[i];
    delete[] A;
    delete[] b;
    delete[] ans;

    return 0;
}

Measured memory_bytes: 1236
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>
#include <random>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFR INT_MAX
#define INFL (long long)(4e18)
#define INFLR LLONG_MAX
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

// デバッグ用変数ダンプ関数
void dump() {
	cout << endl;
}
template <class Head, class... Tail>
void dump(Head&& head, Tail&&... tail)
{
	cout << head << ", ";
	dump(std::move(tail)...);
}

string YN(bool y) { return (y ? "YES" : "NO"); }
string yn(bool y) { return (y ? "Yes" : "No"); }
string ON(bool y) { return (y ? "OK" : "NG"); }

int dir4[4][2] = { { 0,-1 },{ -1,0 },{ 1,0 },{ 0,1 } };
int dir8[8][2] = { { -1,-1 },{ 0,-1 },{ 1,-1 },{ -1,0 },{ 1,0 },{ -1,1 },{ 0,1 },{ 1,1 } };

// [a,b]の乱数
int irand(int a, int b) {
	static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
	uniform_int_distribution<int> dist(a, b);
	return dist(Rand);
}

// [a,b)の乱数
double drand(int a, int b) {
	static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
	uniform_real_distribution<double> dist(a, b);
	return dist(Rand);
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}
//=======ここまでテンプレート===============================================

bool check(const string &s, int k) {
	repr(i, s.size() - k + 1, k) {
		if (s[i] != s[i - 1])return false;
	}
	return true;
}

int main(void) {
	string s;
	cin >> s;
	int ok = s.size() / 2, ng = s.size() + 1;
	while (ng - ok > 1) {
		int m = (ok + ng) / 2;
		if (check(s, m))ok = m;
		else ng = m;
	}
	cout << ok << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
#include <cmath>
using namespace std;
#define lli long long int
#define f first
#define s second
#define Max 1e9+7
#define fw(i, start, end) for (lli i = start; i < end; ++i)
int dp[100005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    lli looper,K;
    cin >> looper>>K;
    int a[looper + 1];
    fw(i, 0, looper)
    {
        cin >> a[i];
    }
    // lli K = 2;
    fw(i, 1, looper+1)
    {
        dp[i] = Max;
        for (lli j = i ; j >= fmax(i - K, 0); j--)
        {
            dp[i] = fmin(dp[i], dp[j] + fabs(a[i] - a[j]));
        }
    }
    cout << dp[looper-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
	int a,b,F,G;
	scanf("%d %d",&a,&b);
	
	F=a*b;
	G= a*b*F;
	
	if(G%2 != 0)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	
		
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 
 
using namespace std;
 
long long N, M;
vector<long long> tree[3600];
 
double memo[605];
 
 
double dfs(long long cur) {
	if(cur == N - 1) {
		return 1;
	}
 
	if(memo[cur] > 0) {
		return memo[cur] + 1;
	}
 
	double sumi = 0;
	long long num = tree[cur].size();
 
	for(auto next: tree[cur]) {
		sumi += dfs(next);
	}
 
	memo[cur] = sumi/num;
 
	return memo[cur] + 1;
}
 
long long ngfrom, ngto;
 
double memo2[605];
 
double dfs2(long long cur) {
	if(cur == N - 1) {
		return 1;
	}
 
	if(memo2[cur] > 0) {
		return memo2[cur] + 1;
	}
 
	double sumi = 0;
	long long num = tree[cur].size();
 
	for(auto next: tree[cur]) {
		if(cur == ngfrom && next == ngto) {
			num--;
			continue;
		}
		sumi += dfs2(next);
	}
 
	memo2[cur] = sumi/num;
 
	return memo2[cur] + 1;
}
 
int main(){
	cin >> N >> M;
	
	rep(i, M) {
		long long s, t;
		cin >> s >> t;
		s--;t--;
		tree[s].push_back(t);
	}
 
		dfs(0);
	double ans = memo[0];
 
 
	for(long long i = 0; i < N - 1; i++) {
		double maxi = 0;
		long long maxito = 0;
		if(tree[i].size() == 1) continue;
 
		for(long long j = 0; j < tree[i].size(); j++) {
			if(memo[tree[i][j]] > maxi) {
				maxi = memo[tree[i][j]];
				maxito = tree[i][j];
			}
		}
 
		ngfrom = i;
		ngto = maxito;
			dfs2(0);
			
		ans = min(ans, memo2[0]);
 
 
		rep(i, N + 2) {
			memo2[i] = 0;
		}
	}
 
	printf("%.10f\n", ans);
 
}

Measured memory_bytes: 6036
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;
signed main(){
    int h; cin >> h;
    int res=0;
    int num=1;
    while(h>0){
        h/=2;
        res+=num;
        num*=2;
    }
    cout<<res<<endl;
}

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

int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  bool result = false;
  if(s.at(0) < t.at(t.size()-1)){
    result = true;
  }else if(s.size() < t.size()){
    string sub = t.substr(0,s.size());
    if(sub == s){
      result = true;
    }
  }
  if(result){
    cout << "Yes";
  }else{
    cout << "No";
  }
  cout << endl;
  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;

void solve()
{
	ld a, b;
	cin >> a >> b;
	cout << (ll)(a * b) << "\n";
	return;
	ll n;
	cin >> n;
	ll sum = 1;
	ll arr[n];
	
	for(int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		arr[i] = x;
//		sum = sum * x;
	}
	sort(arr,arr+n);
	for(int i = 0; i < n; i++) 
	{
		if(arr[i] == 0)
		{
			cout << "0\n";
			return;
		}
		if(sum * arr[i] > 1000000000000000000)
		{
			cout << "-1\n";
			return;
		}
		sum = sum * arr[i];
	}
	cout << sum << "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  int result = d[n / 2] - d[n / 2 - 1];
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 640
def main():
    N = int(input())
    L = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            for k in range(j+1, N):
                if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                    continue
                if max(L[i], L[j], L[k]) * 2 < L[i] + L[j] + L[k]:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73960
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
#define eps 1.0e-14;

int main(){
    int N;
    int A[200005];
    int B[200005];
    map<int,int> pairs;
    cin >> N;
    rep(i,N){
        cin >> A[i];
        B[i] = A[i];
    }
    sort(A, A + N);
    int max = A[N - 1];
    int secmax = A[N - 2];
    //cout << "secmax" << secmax << endl;
    rep(i,N){
        //cout << i << " " << B[i] << endl;
        if(B[i] == max){
            cout << secmax << endl;
        }else{
            cout << max << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3200
import sys
input = sys.stdin.readline
from collections import *

def bfs(s):
    q = deque([s])
    color[s] = 1
    w, b = 1, 0
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if color[nv]==0:
                color[nv] = -color[v]
                q.append(nv)
                
                if color[nv]==1:
                    w += 1
                else:
                    b += 1
            else:
                if color[nv]==color[v]:
                    return -1, -1
    
    return w, b

N, M = map(int, input().split())
A = [[0]*N for _ in range(N)]

for _ in range(M):
    u, v = map(int, input().split())
    A[u-1][v-1] = 1
    A[v-1][u-1] = 1

G = [[] for _ in range(N)]

for i in range(N):
    for j in range(i+1, N):
        if A[i][j]==0:
            G[i].append(j)
            G[j].append(i)

color = [0]*N
ws, bs = [], []

for i in range(N):
    if color[i]==0:
        w, b = bfs(i)
        
        if w==-1:
            print(-1)
            exit()
        
        ws.append(w)
        bs.append(b)

dp = [[False]*(N+1) for _ in range(len(ws)+1)]
dp[0][0] = True

for i in range(len(ws)):
    for j in range(N+1):
        if j+ws[i]<=N:
            dp[i+1][j+ws[i]] |= dp[i][j]
        
        if j+bs[i]<=N:
            dp[i+1][j+bs[i]] |= dp[i][j]

ans = 10**18

for i in range(N+1):
    if dp[-1][i]:
        ans = min(ans, i*(i-1)//2+(N-i)*(N-i-1)//2)

print(ans)

Measured memory_bytes: 50396
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int s=nxt(),w=nxt();   
    if(w>=s)
        cout<<"unsafe\n";
    else
        cout<<"safe\n";
    
    return 0;   
}




 
 


Measured memory_bytes: 3644
import itertools
def main():
    A=[list(map(int,input().split())) for _ in range(3)]
    n=int(input())
    B=list(int(input()) for _ in range(n))
    B=sorted(B)
    C=itertools.combinations(B,3)
    if n<3:
        print('No')
        return
    
    ans=[]
    ans.append(sorted(A[0]))
    ans.append(sorted(A[1]))
    ans.append(sorted(A[2]))
    ans.append(sorted([a[0] for a in A]))
    ans.append(sorted([a[1] for a in A]))
    ans.append(sorted([a[2] for a in A]))
    ans.append(sorted([A[0][0],A[1][1],A[2][2]]))
    ans.append(sorted([A[0][2],A[1][1],A[2][0]]))
    for c in C:
        if list(c) in ans:
            print('Yes')
            return
    print('No')
    
main()

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

#define testcases ll t;cin>>t;while(t--)
#define queries ll q;cin>>q;while(q--)
#define ll long long 
#define loop(i,x,n) for(ll i=x;i<n;i++)
#define ff first
#define ss second
#define elif else if
#define flush cout<<endl;
#define pb push_back;
#define mod 1000000007




int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//testcases{
		long long int n,x,y,z,k,p,q,r,ct=0,sum=0,e=0;;
		cin>>n;
		std::vector<long> factors;

		loop(i,1,n+1){
			if(n%i==0)
				factors.push_back(i);
		}
		bool ans=false;
		loop(i,0,factors.size()){
			x=factors[i];
			if(x>=1 && x<=9){
				y = n/x;

				if(y>=1 && y<=9)
					ans=true;
			}
		}
		if(ans)
			cout<<"Yes";
		else
			cout<<"No";
		flush;

				
	//}
	
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
    string s;
    cin>>s;
    ll sum=0;
    rep(i,0,s.size()){
        sum+=s[i]-'0';
    }
    if(sum%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };



void solve() {
    ll a, b, c, d, e , m, n, k, x,l,r;
    string s;
    ll ans = 0;
    double dans = 0;
    string sans = "Yes";
    vector<ll> ar;

    cin >> n;

    ll max = 0;
    ll sum=0;

    rep(i,n){
        ll tmp;
        cin >> tmp;
        sum += tmp*2;
        max = std::max(max, tmp);
    }

    ans = (sum-max)/2;

    std::cout << ans << endl; 

    // std::cout << sans << endl; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    sushi = [list(map(int, input().split())) for _ in range(n)]
    sushi = sorted(sushi, key=lambda x: x[1], reverse=True)

    first = set()
    second = []
    point = 0
    for s in sushi[:k]:
        if s[0] not in first:
            first.add(s[0])
        else:
            second.append(s)
        point += s[1]
    point += len(first) ** 2
    ans = point

    for s in sushi[k:]:
        if len(second) == 0:
            break
        if s[0] not in first:
            point = point + s[1] - second.pop()[1] + \
                (len(first) + 1) ** 2 - len(first) ** 2
            first.add(s[0])
            ans = max(ans, point)
    print(ans)


main()


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

    for (int i=0; ;i++){
      int tmp = (i+1)*1000 - n;
      if (tmp >= 0){
        System.out.println(tmp);
        break;
      }
    }
  }
}


Measured memory_bytes: 35544
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;


int main() {
	
	int size;
	int a[100];

	cin >> size;

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

	for (int i = 0; i < size; i++) {
		printf("%d", a[size - 1 - i]);
		if (i + 1 != size)printf(" ");


	}
	printf("\n");

	//system("pause");
	return 0;
}


Measured memory_bytes: 3120
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = a[::2]
    c = a[1::2]

    retB = {}
    for i in b:
        retB[i] = retB.get(i, 0) + 1

    retC = {}
    for i in c:
        retC[i] = retC.get(i, 0) + 1

    retB = sorted(retB.items(), key=lambda x: x[1], reverse=True)
    retC = sorted(retC.items(), key=lambda x: x[1], reverse=True)
    if retB[0][0] != retC[0][0]:
        tmpB = len(b) - retB[0][1]
        tmpC = len(c) - retC[0][1]
        print(tmpC + tmpB)
    else:
        if len(retB) == 1 and len(retC) == 1:
            print(len(c))
            return
        if len(retB) == 1:
            tmpB = len(b) - retB[0][1]
            tmpC = len(c) - retC[1][1]
            print(tmpB + tmpC)
            return
        if len(retC) == 1:
            tmpB = len(b) - retB[1][1]
            tmpC = len(c) - retC[0][1]
            print(tmpB + tmpC)
            return
        tmpB = len(b) - retB[1][1]
        tmpC = len(c) - retC[0][1]
        ret = [tmpB + tmpC]
        tmpB = len(b) - retB[0][1]
        tmpC = len(c) - retC[1][1]
        ret.append(tmpB + tmpC)
        print(min(ret))


main()


Measured memory_bytes: 20192
N, M, X = map(int, input().split())
A, C = [], []
for _ in range(N):
    tmp = input().split()
    C.append(int(tmp[0]))
    A.append([int(i) for i in tmp[1:]])
is_clear = False
min_cost = 10**10
for flg_number in range(2 ** N):
    flgs = format(flg_number, '0'+str(N)+'b')
    thr = [X] * M
    cost = 0
    for i in range(N):
        if flgs[i] == '1':
            cost += C[i]
            for j in range(M):
                thr[j] -= A[i][j]
    is_all_clear = True
    for j in range(M):
        if thr[j] > 0:
            is_all_clear = False
            break
    if is_all_clear:
        is_clear = True
        if min_cost > cost:
            min_cost = cost
if is_clear:
    print(min_cost)
else:
    print(-1)


Measured memory_bytes: 9244
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE



signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M, V, P;
  cin>>N>>M>>V>>P;

  vector<Int> A(N);
  cin>>A;
  sort(A.begin(), A.end(), greater<Int>());

  auto check = [&](Int x)->Int{
    if(x <= P-1) return 1;
    if(A[x] + M < A[P-1]) return 0;
    Int v = V - (P + (N - 1 - x));
    if(v <= 0) return 1;
    Int cap = 0;
    for(Int i=P - 1;i<x;i++) cap += min(M, A[x] + M - A[i]);
    return cap >= v * M;
  };

  Int L = 0, R = N;
  while(L + 1 < R){
    Int M = (L + R) / 2;
    check(M)? (L = M):(R = M);
  }
  Int ans = L + 1;

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1152
import sys
stdin = sys.stdin
import numpy as np

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, k = na()
p = np.array(na())
p = (1+p)/2
now = sum(p[:(k)])
ans = now
for i in range(0, n-k):
    now = now - p[i] + p[i+k]
    ans = max(now, ans)
print("{:.8f}".format(ans))

Measured memory_bytes: 34008
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005
#define ll signed long long int
using namespace std;
 
ll ans = 0, a[MAXX],b[MAXX] ,n,c,  t, m = 0, z= 0,x = 1,f=0, mx, mn;
signed main()
{
    FAST;
	string st;
	cin >> st;
	for(ll i = 0; i < (st.size())/2; i++){
		if(st[i] != st[st.size()-i-1]){
			m ++;
		}
	}
	cout << m;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int a[110000];
int b[110000];
int c[110000];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	long ans = 0;
	for (int i = 0; i < n; i++)
		ans += (lower_bound(a, a + n, b[i]) - a) * (n - (upper_bound(c, c + n, b[i]) - c));
	cout << ans << endl;
}

Measured memory_bytes: 4828
def takoyaki(n,x,t):
    if n == 0:
        return 0
    temp_x = x
    temp_t = t
    while n > temp_x:
        temp_x += x
        temp_t += t
    return temp_t

def start():
    n,x,t = [int(x) for x in input().split(" ")]
    print(takoyaki(n,x,t))
start()

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<long long int>
#define fi first
#define se second
#define sc(n) scanf("%d",&n);
#define scll(n) scanf("%lld",&n);
#define scld(n) scanf("%Lf",&n);
#define scr(s) {char temp[1000000];scanf("%s",temp);s = temp;}
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" :" <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cout<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}


using namespace std;

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



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    ll num=0;
    ll mo=1000;
    rep(i,n){
        if(i!=0&&i+1!=n&&a[i-1]==a[i]&&a[i]==a[i+1])continue;
        if(i+1!=n&&((i==0&&a[0]<a[1])||(i!=0&&i+1!=n&&a[i-1]>=a[i]&&a[i]<=a[i+1]))){
            //買えるだけ買う
            num+=mo/a[i];
            mo%=a[i];
            //cout << i << ' ' << "low" << endl;
        }
        else if(i!=0&&((i+1==n&&a[i-1]<=a[i])||(i!=0&&i+1!=n&&a[i-1]<=a[i]&&a[i]>a[i+1]))){
            //売れるだけ売る
            mo+=num*a[i];
            num=0;
            //cout << i << ' ' << "high" << endl;
        }
    }
    cout << mo << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
#define MAXX 200010
 
#define PI   3.14159265358979323846264338327950
 
#define PB push_back 
#define F first
#define S second
 
#define fixx(n) fixed << setprecision(n)
 
#define ll 	  long long 
 
#define mod  1000000007
 
 
 
int main()
{
	FAST;
	int n, k, t;
	cin >> n >> k >> t;
	int x = n/ k;
	if(n % k){
		x ++;
	}
	cout << x * t;
	return 0;
}

Measured memory_bytes: 3648
N=int(input())
S=[]
L=0
R=0
for i in range(N):
    s=input()
    n=len(s)
    data=[s[j] for j in range(n)]
    l=0
    r=0
    yabai=float("inf")
    for j in range(n):
        l+=(s[j]=="(")
        r+=(s[j]==")")
        yabai=min(l-r,yabai)
    S.append([yabai,l-r])
    L+=l
    R+=r

if L!=R:
    print("No")
else:
    first=[]
    last=[]
    for i in range(N):
        yabai,gap=S[i]
        if gap>0:
            first.append(S[i])
        else:
            last.append([gap-yabai,yabai])
    first.sort(reverse=True)
    last.sort(reverse=True)
    G=0
    for i in range(len(first)):
        yabai,gap=first[i]
        if 0>G+yabai:
            print("No")
            exit()
        else:
            G+=gap
    for j in range(len(last)):
        gapminus,yabai=last[j]
        if 0>G+yabai:
            print("No")
            break
        else:
            G+=gapminus+yabai
    else:
        print("Yes")


Measured memory_bytes: 254328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e18;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)

int main()
{
    ll X,Y;
    cin >> X >> Y;
    ll ans = 0;
    if(X == 1 && Y == 1){
        ans += 400000;
    }
    if(X <= 3){
        ans += (4-X) * 100000;
    }
    if(Y <= 3){
        ans += (4-Y) * 100000;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    num_str = input()
    num_int = int(num_str)
    num_list = list(num_str)
    num_list = [int(n) for n in num_list]
    #print(num_str)
    #print(sum(num_list))
    if num_int % sum(num_list) == 0: print("Yes")
    else: print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr+n);
    long long int ans=arr[n-1];
  
    if(n>=3)
    { int i=n-2;
    	int x=n-2;
    	while(x>1)
    	{
    		ans=ans+2*arr[i];
    		i--;
    		x=x-2;
         
    	}
    	if(x==1)
    	{
    		ans=ans+arr[i];
    	}
    }
	cout<<ans<<endl;

}

Measured memory_bytes: 4392
import numpy as np
import heapq as hq
N, M = map(int, input().split())
A = list(map(int, input().split()))

class BC():
    def __init__(self, b, c):
        self.b = b
        self.c = c

    def __eq__(self, other):
        return self.c == other.c    

    def __lt__(self, other):
        return self.c > other.c

    def __ne__(self, other):
        return not self.__eq__(other)

    def __le__(self, other):
        return self.__lt__(other) or self.__eq__(other)

    def __gt__(self, other):
        return not self.__le__(other)

    def __ge__(self, other):
        return not self.__lt__(other)

heap = []
for _ in range(M):
    hq.heappush(heap, BC(*map(int, input().split())) )

result = []
for _ in range(M):
    bc = hq.heappop(heap)
    result.extend([bc.c] * bc.b)

    if len(result) > N:
        break

A.extend(result)
A.sort(reverse=True)
print(np.sum(A[:N]))


Measured memory_bytes: 44744
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

ll lcm(ll a, ll b) {
	ll x, tmp;
	x = a * b;
	if(a<b){
		tmp = a;
   	a = b;
    b = tmp;
  }

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

	return x/b;
}

int main() {
	ll a, b;
	cin >> a >> b;
	cout << lcm(a, b) << endl;

	return 0;
}

Measured memory_bytes: 256