akhauriyash/Code-Regression huggingface dataset:
n = int(input())

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

score = 0
for i in range(1, n-1):
    list_p[i]

    if list_p[i] < list_p[i+1] and list_p[i] > list_p[i-1]:
        score += 1

    if list_p[i] > list_p[i+1] and list_p[i] < list_p[i-1]:
        score += 1

print(score)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int a,b,c,d,e;
    scanf("%d%d",&a,&b);
    c=a+b;
    d=a-b;
    e=a*b;
    if(c>=d&&c>=e)
    {
        printf("%d",c);
    }
    else if(d>=c&&d>=e)
    {
        printf("%d",d);
    }
    else if(e>=c&&e>=d)
    {
        printf("%d",e);
    }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;


const int N=400;
vector<int>a(N+1);
vector<int>psum(N+1);
vector<vector<int>>dp(N+1,vector<int>(N+1,-1));
int n;
int solve(int l,int r){
	if(l==r)return 0;
	if(dp[l][r]!=-1)return dp[l][r];
	dp[l][r]=1e15;
	for(int i=l;i<r;i++)
	dp[l][r]=min(dp[l][r],psum[r]-psum[l-1]+solve(l,i)+solve(i+1,r));
	return dp[l][r];
}
	
int32_t main()
{
   IOS
   cin>>n;
   for(int i=1;i<=n;i++)
   {
	   cin>>a[i];
	   psum[i]=psum[i-1]+a[i];
   }
   cout << solve(1,n) << endl;
   
   
  
   
  
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	int n;
	cin >> n;
	string s1, s2;
	cin >> s1 >> s2;
	string str[2];
	str[0] = s1;
	str[1] = s2;

	// 左から塗っていく
	// 縦棒の一本の場合と、横棒2本の場合のみ
	bool prevHori;
	vector<ll> num(n, 0);
	if (str[0][0] == str[1][0]) {
		num[0] = 3;
		prevHori = false;
	}
	else {
		num[0] = 6;
		num[1] = 6;
		prevHori = true;
	}
	Rep(j, 1, n) {
		if (num[j] != 0) continue;
		if (str[0][j] == str[1][j]) {
			if (prevHori) num[j] = 1;
			else num[j] = 2;
			prevHori = false;
		}
		else {
			if (prevHori) {
				num[j] = 3;
				num[j + 1] = 3;
			}
			else {
				num[j] = 2;
				num[j + 1] = 2;
			}
			prevHori = true;
		}
	}

	ll ans = 1;

	rep(j, n) {
		ans *= num[j];
		ans %= mod;
		if (str[0][j] != str[1][j])
			j++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define inf 100100100100
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

ll n, m, R, r[8], g[210][210];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m >> R;
    rep(i, 0, R) {
      cin >> r[i];
      r[i]--;
    }
    rep(i, 0, n) rep(j, 0, n) 
      g[i][j] = (i == j ? 0 : inf);
    rep(i, 0, m) {
      ll a, b, c;
      cin >> a >> b >> c;
      g[a-1][b-1] = g[b-1][a-1] = c;
    }
    rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) {
      g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
    }
    ll ans = inf;
    sort(r, r+R);
    do {
      ll sum = 0;
      rep(i, 0, R-1) {
        if (g[r[i]][r[i+1]] >= inf) {
          sum = inf;
          break;
        }
        sum += g[r[i]][r[i+1]];
      }
      ans = min(ans, sum);
    } while (next_permutation(r, r+R));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{
    int n;
    cin >> n;
    int *x = new int[n];
    int xmax = INT_MIN,xlow = INT_MAX;
    for(int i = 0; i < n; i++)
    {
        cin >> x[i];
        xmax = max(xmax,x[i]);
        xlow = min(xlow,x[i]);
    }
    ll cost = LONG_MAX,currcost;
    for(int i = xlow; i <= xmax; i++)
    {
        currcost = 0;
        for(int j = 0; j < n; j++)
        {
            currcost += (x[j]-i)*(x[j]-i);
        }
        cost = min(currcost,cost);
    }
    cout << cost << "\n";
 	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace AOJ0093
{
    class Program
    {
        private static void Main()
        {
            // 良い子は真似するわけがありません
            Console.WriteLine(string.Join("\n\n",
                                          (from values in ReadInput()
                                           let s = string.Join("\n",
                                                (from y in Enumerable.Range(values[0], values[1] - values[0] + 1)
                                                where (y % 4 == 0 && y % 100 != 0) || y % 400 == 0
                                                select y.ToString(CultureInfo.InvariantCulture)).ToArray())
                                           let s2 = s.Any() ? s : "NA"
                                           select s2).ToArray()));
        }

        private static IEnumerable<int[]> ReadInput()
        {
            string line;
            while ((line = Console.ReadLine()) != null && line != "0 0")
            {
                yield return line.Split(' ').Select(int.Parse).ToArray();
            }
        }
    }
}

Measured memory_bytes: 6204
grid = [[int(i) for i in input().split()] for j in range(3)]

match = True

for i in range(2):
    d1 = grid[0][i+1] - grid[0][i]
    d2 = grid[1][i+1] - grid[1][i]
    d3 = grid[2][i+1] - grid[2][i]
    if (d1 != d2) or (d1 != d3):
        match = False
        break

for i in range(2):
    d1 = grid[i+1][0] - grid[i][0]
    d2 = grid[i+1][1] - grid[i][1]
    d3 = grid[i+1][2] - grid[i][2]
    if (d1 != d2) or (d1 != d3):
        match = False
        break

if match:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

map<int, int> f;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int sum = 0;
    ll sol = 0;
    f[0] = 1;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        sum += x;
        sum %= m;
        sol += f[sum];
        f[sum]++;
    }
    cout << sol;
}


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

const int MAX = 510000;
const int MOD = 1000000007;

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

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

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

int main() {
  int n, p;
  cin >> n >> p;
  vector<int> A(n);
  int odd = 0;
  int even = 0;
  COMinit();
  for(int i = 0; i < n; ++i) {
    cin >> A[i];
    if(A[i] % 2 == 0) even++;
    else odd++;
  }

  long long int ans = 0;

  if(p == 0) {
    for(int i = 0; i <= odd; i+= 2) {
      ans += COM(odd, i);
    }
  } else {
    for(int i = 1; i <= odd; i+= 2) {
      ans += COM(odd, i);
    }
  }

  cout << ans * (long long int)pow(2, even) << endl;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    while(y > 0) {
        int tmp = x % y;
        x = y;
        y = tmp;
    }
    return x;
}

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];

    int ans = a[0];
    rep(i, 1, n) {
        ans = gcd(ans, a[i]);
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	const int MC = 30000;
	int N; cin >> N;
	cout << "2 3";
	if(N == 3) return cout << " 25" << endl, 0;
	cout << " 4 9";
	N -= 4;
	int x = 8;
	for( ; N > 1 && x <= MC ; x += 6){
		cout << ' ' << x << ' ' << x+2;
		N -= 2;
	}
	x = 15;
	for( ; N > 1 && x <= MC ; x += 12){
		cout << ' ' << x << ' ' << x+6;
		N -= 2;
	}
	while(N){
		cout << ' ' << 6*N;
		--N;
	}
	cout << endl;
	return 0;
}


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

int main(){
	int n,h,w;
	cin>>w>>h>>n;
	int ax,ay,bx,by;
	cin>>ax>>ay;
	int ans=0;
	n--;
	for(int i=0; i<n; i++){
		cin>>bx>>by;
		if(ax>bx){
			if(ay>by){
				ans+=max(ax-bx,ay-by);
			}else{
				ans+=(ax-bx)+(by-ay);
			}
		}else{
			if(ay<by){
				ans+=max(bx-ax,by-ay);
			}else{
				ans+=(bx-ax)+(ay-by);
			}
		}
		ax=bx;
		ay=by;
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
}
	
	 


Measured memory_bytes: 3088
import java.util.*;
import java.util.stream.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        // programming
        int a = Util.getInputInteger(sc);
        int b = Util.getInputInteger(sc);
        int c = Util.getInputInteger(sc);
        int[] sorted = Util.sort_desc(a,b,c);
        

		Util.output(String.valueOf(sorted[0]*10 + sorted[1] + sorted[2]));
	}
}

// =========common=========
class Util {
	public static String getInputString(Scanner sc) {
		return sc.next();
	}

	public static int getInputInteger(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	public static void output(String... params) {
		boolean isInit = true;
		String str = "";
		for (String s : params) {
			if (!isInit) {
				str += " ";
			}
			str += s;
			isInit = false;
		}
		System.out.println(str);
	}

    public static int[] toIntegerList(String... ss) {
        return Stream.of(ss).mapToInt(Integer::parseInt).toArray();
    }

    public static String[] toList(String s) {
        String[] ret = s.split("");
        return ret;
    }

    public static int sum(int... vals) {
        int sum = 0;
        for (int val : vals) {
            sum += val;
        }
        return sum;
    }

    public static int[] sort_asc(int... vals) {
        Arrays.sort(vals);
        return vals;
	}

    public static int[] sort_desc(int... vals) {
        vals = sort_asc(vals);
        int[] ret = new int[vals.length];
        for (int i = 0; i < vals.length; i++) {
            ret[vals.length - i - 1] = vals[i];
        }
		return ret;
	}

    public static void gc() {
        System.gc();
    }

	public static int diff(int a, int b) {
		return Math.abs(a - b);
	}

	public static int max(int... a) {
		int temp_max = Integer.MIN_VALUE;
		for (int v : a) {
			if (v > temp_max) {
				temp_max = v;
			}
		}
		return temp_max;
	}

	public static int min(int... a) {
		int temp_min = Integer.MAX_VALUE;
		for (int v : a) {
			if (v < temp_min) {
				temp_min = v;
			}
		}
		return temp_min;
	}
}

Measured memory_bytes: 21844
from numpy.linalg import solve

X, Y = map(lambda x: int(x), input().split(" "))

left = [[1,1],
        [2, 4]]

right = [X, Y]

answer = solve(left, right)

if answer[0].is_integer() and answer[0] >= 0 and answer[1].is_integer() and answer[1] >= 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 27356
#include <iostream>
#include <cstdio>

typedef long long ll;


using namespace std;


int main(){
	int n,cnt=0, t;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> t;
		if(t%2){cnt++;}
	}
	if(cnt%2){
		cout << "NO" << endl;
	}
	else{
		cout << "YES" << endl;
	}
	return 0;
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    vector<double> v(n);
    rep (i, n) {
      cin >> v[i];
    }
    sort(v.begin(), v.end());
    FOR (i, 1, n) {
      double tmp = (v[i] + v[i - 1]) / 2;
      v[i] = tmp;
    }
    cout << v[n - 1] << '\n';

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] S = sc.next().toCharArray();
		int ans = 0;
		for(int i = 0; i < S.length-1; i++) {
			if(S[i+1] != S[i])
				ans += 1;
		}
		System.out.println(ans);
	}

}


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

int main () {
  int N;
  cin >> N;
  vector <int> X(N);
  for(int i = 0; i < N; i++){
    cin >> X.at(i);
  }
  int answer = 0;
  int sum = 0;
  for(int i = 0; i < N; i++){
    sum = sum + X.at(i);
  }

  for(int P = 1; P < 101; P++){
    if(sum * 2 * P - N * P * P > answer){
      answer = sum * 2 * P - N * P * P; 
    }
  }

  int sumsum = 0;
  for(int i = 0; i < N; i++){
    sumsum += X.at(i) * X.at(i);
  }

  cout << sumsum - answer << endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<P> to(M);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        to[i] = P(b, a);
    }
    sort(to.begin(), to.end());

    int res = 0;
    int tr = -1;
    rep(i, M) {
        if(tr < to[i].second) {
            res++;
            tr = to[i].first-1;
        }
    }

    cout << res << endl;
    return 0; 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<bool> ans(n, false);
  ans[0] = true;
  vector<int> num(n, 1);

  for(int i = 0; i < m; ++i){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    num[x]--;
    num[y]++;
    if(ans[x]){
      ans[y] = true;
      if(num[x] == 0){
        ans[x] = false;
      }
    }
  }

  int num_ans = 0;
  for(int i = 0; i < n; ++i){
    num_ans += ans[i];
  }

  cout << num_ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <tuple>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    REP(i, 0, n) {
        cin >> x[i] >> y[i];
    }
    auto cx = x, cy = y;
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    const ll inf = 1LL << 60;
    auto ans = make_tuple(inf, inf, inf);
    for (int xx = (n - 1) / 2; xx <= n / 2; xx++) {
        for (int yy = (n - 1) / 2; yy <= n / 2; yy++) {
            ll sum = 0, mx = 0;
            REP(i, 0, n) {
                ll dist = abs(cx[i] - x[xx]) + abs(cy[i] - y[yy]);
                chmax(mx, dist);
                sum += 2 * dist;
            }
            chmin(ans, make_tuple(sum - mx, x[xx], y[yy]));
        }
    }
    ll dist, posX, posY;
    tie(dist, posX, posY) = ans;
    cout << dist << endl;
    cout << posX << " " << posY << endl;
}



Measured memory_bytes: 6048
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long
#define ld long double

int main(void)
{
    ll n, k, max = -10000000000000;
    cin >> n >> k;
    vector<ll>  p(n), c(n), sum(n), num(n, 0);
    vector<vector<ll>>  memo(n, vector<ll>(0));
    for(ll i = 0; i < n; i++) {
        cin >> p.at(i);
        p.at(i)--;
    }
    for(ll i = 0; i < n; i++) {
        cin >> c.at(i);
    }

    for(ll i = 0; i < n; i++) {
        ll wa = 0, roop = i;
        vector<bool>    tootta(n, false);
        while(1) {
            wa += c.at(roop);
            memo.at(i).push_back(wa);
            tootta.at(roop) = true;
            if(tootta.at(p.at(roop))) {
                break;
            }
            roop = p.at(roop);
        }

        sum.at(i) = wa;

        if(sum.at(i) <= 0) {
            for(ll j = 0; j < min((ll)memo.at(i).size(), k); j++) {
                if(max < memo.at(i).at(j)) {
                    max = memo.at(i).at(j);
                }
            }
        } else {
            for(ll j = 0; j < memo.at(i).size(); j++) {
                ll ij = sum.at(i) * (k / memo.at(i).size() - 1) + memo.at(i).at(j);
                if(max < ij) {
                    max = ij;
                }
            }
            for(ll j = 0; j < (k % memo.at(i).size()); j++) {
                ll ij = sum.at(i) * (k / memo.at(i).size()) + memo.at(i).at(j);
                if(max < ij) {
                    max = ij;
                }
            }
        }
    }

    cout << max;
}

Measured memory_bytes: 218948
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}
// 立っている ビットの数
int bitcount(unsigned int uc);
int bitcount(unsigned int uc)
{
	int bit;

	for (bit = 0; 0 != uc; uc = (unsigned int)(uc >> 1))
		if (0 != (uc & 1))++bit;

	return bit;
}//bitco

#define _rnd(a,b)    ((a+b-1)/b) //　A/Bの余りを繰り上げる
#define _abs(x) ((x)<0 ? -(x) : (x))
#define _MAX 200000
#pragma endregion

// ABC087 B - Coins

int main(void) {
	int a, b, c, x, cnt = 0;

	scanf("%d %d %d %d", &a, &b, &c, &x);

	for (int i = 0; i <= a; i++) 
		for (int j = 0; j <= b; j++) 
			for(int k=0;k<=c;k++)
		    	if (i * 500 +j*100+k*50 == x) 	
					cnt++;


	printf("%d\n", cnt);
	return 0;
}



Measured memory_bytes: 1732
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in));
        
        int n = Integer.valueOf(br.readLine());
        String input[] = br.readLine().split(" ", 0);
        
        int min = 1000000;
        int max = -1000000;
        long sum = 0;
        int num = 0;
        for (String s : input) {
            num = Integer.valueOf(s);
            sum += num;
            
            if (num < min) {
                min = num;
            }
            if (max < num) {
                max = num;
            }
        }
        
        System.out.println(min + " " + max + " " + sum);
    }
}


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

int h[100001];
//int mx[100001];
vector<int> edges[100001];
int n,m;

int main(){
	cin>>n>>m;
	for (int i=0;i<n;i++) cin>>h[i];
	for (int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		edges[a-1].push_back(b-1);
		edges[b-1].push_back(a-1);
	}
	int sum=0;
	for (int i=0;i<n;i++){
		bool ok=true;
		for (int j=0;j<edges[i].size();j++){
			if (h[edges[i][j]]>=h[i]){
				ok=0;
			}
		}
		if (ok)
			sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 9108
/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define DEBUG(x) cerr << '>' << #x << ':' << x << endl;
#define ll long long int
#define endl '\n'
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef queue<int> qii;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
#define all(x) x.begin(),x.end()
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;
double pi = 2 * acos(0.0); 

void solve(){
   int n;
   cin>>n;
   string s;
   map<string,int>m;
   rep(i,0,n){
      cin>>s;
      m[s]++;
   }
   cout<<"AC x "<<m["AC"]<<endl;
   cout<<"WA x "<<m["WA"]<<endl;
   cout<<"TLE x "<<m["TLE"]<<endl;
   cout<<"RE x "<<m["RE"]<<endl;
}

int main(){ 
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    fastio;
    int t=1;
   //  cin>>t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 3568
alp=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
s=set(input())
n=0
for i in alp:
  if i not in s:
    print(i)
    n=1
    break
if n==0:
  print('None')

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

namespace CSharpSample01
{

    

    class Program
    {
        static string[] char_list = new string[10];

        static void InitializeCharList()
        {
            
            char_list[1] = ".,!? #";
            char_list[2] = "abc#";
            char_list[3] = "def#";
            char_list[4] = "ghi#";
            char_list[5] = "jkl#";
            char_list[6] = "mno#";
            char_list[7] = "pqrs#";
            char_list[8] = "tuv#";
            char_list[9] = "wxyz#";
            
        }
      

        static string CreateLetter(string code)
        {
            string letter = "";
            bool selecting = false;
            int number = -1;
            int index = 0;

            for(int i = 0; i < code.Length; i++)
            {
                string st = code[i].ToString();

                if(st == "0")
                {
                    if (selecting)
                    {
                        letter += char_list[number][index].ToString();

                        selecting = false;
                        index = 0;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    if (!selecting)
                    {
                        number = int.Parse(st);
                        index = 0;
                        selecting = true;
                    }
                    else
                    {
                        index++;

                        if(char_list[number][index].ToString() == "#")
                        {
                            index = 0;
                        }

                    }
                    
                }



            }
            
            return letter;
        }

        

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            InitializeCharList();

            for(int i = 0; i < n; i++)
            {
                string code = Console.ReadLine();

                string letter = "";

                letter = CreateLetter(code);

                Console.WriteLine(letter);
            }
            
        }
    }
}


Measured memory_bytes: 19968
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.next() + sc.next();
        double num = Double.parseDouble(s);
        int root = (int)Math.sqrt(num);

        System.out.println(num == Math.pow(root, 2) ?  "Yes" : "No");
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int n;
LL a[N];
const LL mod=1e9+7;
LL Fac[N],Inv[N],f[N];
LL pm(LL a,LL b){
  LL ans=1;
  while(b){
    if(b&1)ans=a*ans%mod;
    a=a*a%mod;
    b>>=1;
  }
  return ans;
}
LL get(int a,int b){
  return Fac[a]*Inv[b]%mod*Inv[a-b]%mod;
}
int main() {
  ios::sync_with_stdio(false);
  Fac[0]=f[0]=1;
  for(int i=1;i<N;i++)Fac[i]=Fac[i-1]*i%mod,f[i]=f[i-1]*2%mod;
  Inv[N-1]=pm(Fac[N-1],mod-2);
  for(int i=N-2;i>=0;i--)Inv[i]=Inv[i+1]*(i+1)%mod;
//  for(int i=1;i<=100;i++){
//    LL sum=0,x=0;
//    for(int j=0;j<=i;j++){
//      sum+=get(i,j)*++x%mod;
//      sum%=mod;
//    }
//    cout<<sum<<endl;
//  }
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  sort(a+1,a+1+n);
  LL ans=0;
  for(int i=1;i<=n;i++){
    //i-n
    //i-1
    if(i!=n)ans+=f[i-1]*((n-i+2)*(n-i-1>=0?f[n-i-1]:1)%mod)%mod*a[i]%mod;
    else ans+=f[i-1]*a[i]%mod;
    ans%=mod;
  }
  cout<<ans*f[n]%mod<<endl;
  return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#define ll long long
#define maxn 4001000
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define rep(i,a,b) for(int i=a;i<=b;i++)
const ll P=1e9+7;
using namespace std;
const int N = 2e5 + 1000;
int a[N];
int main(){
	int t;
	cin>>t;
	for(int i = 1;i <= t;++i){
		cin>>a[i];
	}
	int l = 1;
	int sum = 0;
	for(int i = 1;i <= t;++i){
		if(a[i] == l){
			sum ++;
			l ++;
		}
	}
	if(sum == 0){
		cout<<-1;
	}
	else cout<<t - sum;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 N, M;
  cin >> N >> M;
  vector<vector<i64>> G(N);
  vector<i64> h(N);
  for(int i = 0;i < M;i++) {
    i64 x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
    h[y]++;
  }

  queue<i64> que;

  vector<i64> dist(N);

  for(int i = 0;i < N;i++) {
    if(h[i] == 0) {
      que.push(i);
    }
  }

  while(!que.empty()) {
    i64 v = que.front();
    que.pop();
    for(auto w : G[v]) {
      dist[w] = max(dist[w], dist[v] + 1);
      if(!(--h[w])) {
        que.push(w);
      }
    }
  }

  cout << *max_element(all(dist)) << endl;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h> 
#define ll                 long long                            
#define ra                 return a;                                          
#define pb                 push_back                                                     
#define sti                stack<ll>
#define spi                stack<pair<ll,ll>>
#define S                  second
#define msi                map<string,ll >
#define msi                map<string,ll >
#define mii                map<ll ,ll >
#define dbg(x)             { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y)          { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z)        { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define mis                map<ll , string>
#define rep(i,a,b)         for(ll  i=a;i<b;i++)
#define mpi                map<pair<ll ,ll >,ll >                                                
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define F                  first 
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define pqi                priority_queue<ll>
#define si                 set <ll>
#define vs                 vector<string>
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define hell               1000000007
#define bs                 binary_search
#define mp                 make_pair
#define qi                 queue<ll>
#define qs                 queue<string>
#define qpi                queue<pair<ll,ll>>
#define qps                queue<pair<ll,string>> 
#define inf                1e18L+1
#define endl               '\n' 
#define itr(a,it)          for(typeof(a.begin()) it=a.begin();it!=a.end();it++)// This will produce const_iterator for const object and normal iterator for non-const object
#define ss                 set<string>
using namespace std;
#define N  300005
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll tests=1;
//    cin>>tests;
    while(tests--)
{
    ll n;
    cin>>n;
    ll a[n];
    rep(i,0,n)
    {
    	cin>>a[i];
    	a[i]--;
    }
    mii m;
    ll b[n];
    rep(i,0,n)
    {
    	cin>>b[i];
    	m[i]=b[i];
    }
    ll c[n-1];
    rep(i,0,n-1)cin>>c[i];
    ll satis=0,prev=inf;
    rep(i,0,n)
    {
    	if(i&&a[i]==prev+1)
    	{
    //		dbg2(satis,prev);
    		satis+=c[prev];
    	}
    	satis+=m[a[i]];
    	prev=a[i];
   // 	dbg2(satis,a[i]);
    }
    cout<<satis;
}
    return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    int ans = 1;
    for (int i = 1; i * i <= m; i++) {
        if (m % i != 0) continue;
        if (m / i >= n) {
            ans = max(ans, i);
        }
        if (i >= n) {
            ans = max(ans, m / i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
  int n, k;
  scanf("%d %d", &n, &k);
  int p[n], i;
  for (i = 0; i < n; i++)
    scanf("%d", &p[i]);
  qsort(p, n, sizeof(int), compare_int);
  int sum = 0;
  for (i = 0; i < k; i++)
    sum += p[i];
  printf("%d", sum);
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;

int main(){
  int n; cin >> n;
  int max_profit=INT_MIN;
  int min_v = INT_MAX;
  rep(i,n) {
    int R; cin >> R;
    max_profit = max(max_profit, R - min_v);
    min_v = min(min_v,R);
  }
  //dump(min_v);
  //dump(max_profit);
  //if(max_profit != min_v) max_profit = -1;
  cout << max_profit << endl;
}



Measured memory_bytes: 3104
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    n = next_int()
    a = [0] * n
    b = [0] * n
    ans = 0

    for i in range(n):
        a[i] = next_int()
        b[i] = next_int()

    for i in range(n - 1, -1, -1):
        a[i] += ans
        if a[i] % b[i] != 0:
            ans += abs(a[i] % b[i] - b[i])

    print(ans)


if __name__ == '__main__':
    main()

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

int yakusuu(int N){
  int count=0;
  for(int i=1;i<N+1;i++){
    if(N%i==0){
      count++;
      if(N/i==i){
        count++;
      }
    }
  }
  return count;
}
         
int main(){
  int N,count=0;
  cin >> N;
  for(int i=1;i<N+1;i+=2){
    if(yakusuu(i)==8){
      count++;
    }
  }
  cout << count << endl;
}

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

long long int digit(long long int x){
  long long int p=0;
  while(x>0){
    p++;
    x/=10;
  }
  return p;
}

int main(){
  string before="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int a;
  string s;
  cin>>a>>s;
  int k;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<26;j++){
      if(before.at(j)==s.at(i)){
        k=j;
        break;
      }
    }
    s.at(i)=before.at((k+a)%26);
  }
  cout<<s<<endl;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
 
#if DEBUG
    #include "debug.h"
#else
    #define debug(args...)
#endif    

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;


#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = INT_MAX;
const int mod = 1e9+7;

const int N = 2e5 + 10;
inline int add(int x,int y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline int mul(int x,int y){
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p=clock();



int32_t main(){
	fast;

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);


	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	char prev = '#';
	FOR(i,0,n-1) {
		if(s[i] == prev) {
			continue;
		}
		else {
			ans++;
			prev = s[i];
		}
	}
	cout << ans << "\n";

	time_p=clock()-time_p;
	cerr<<"\nTime Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
        int n,k;
        cin>>n>>k;
        string s[100];
        string ans;
        for(int i=0;i<n;i++){
                cin>>s[i];
        }
        sort(s,s+n);
        for(int i=0;i<n;i++){
                ans=ans+s[i];
        }
        cout<<ans;
}

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

int main() {
  int n;
  cin >> n;
  int cnt = 1;
  pair<pair<string, int>, int> a[110];
  rep(i, n) {
    string s;
    int t;
    cin >> s >> t;
    a[i] = make_pair(make_pair(s, -t), cnt);
    cnt++;
  }
  sort(a, a + n);
  rep(i, n) { cout << a[i].second << endl; }
}


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


int a[12000];

int check(int i,int j)
{
    int pre=10;
    int x=a[i],y=a[j];
    int tmp=x*y;
    int rt=tmp;
    pre=tmp%10-1;
    tmp/=10;
    while(tmp)
    {
        int c=tmp%10;
        if(pre!=c) return -1;
        pre=c-1;
        tmp/=10;
    }
    return rt;
}

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        int ans=-1;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                int tmp=check(i,j);
                if(tmp>ans)
                ans=tmp;
            }
        }
        cout<<ans<<endl;
    }
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define M_PI 3.14159265358979323846

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }



int main()
{
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    int N,K;
    vector<int> h;
    cin >> N >> K;
    h = fetch_vec<int>(N);
    vector<int> dp(N,INT_INF);
    dp[0] = 0;
    dp[1] = dp[0]+abs(h[1]-h[0]);
    for (int i = 2; i < N; i++)
    {
        for (int k = 1; k <= K; k++)
        {
            if(i-k<0) continue;
            dp[i] = min(dp[i-k]+abs(h[i]-h[i-k]),dp[i]);
        }
        
    }
    cout << dp[N-1] << endl;
    

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <set>
#include <vector>

using namespace std;

#define CLR(x) memset(x,0,sizeof x)
#define ll long long

const int inf=0x3f3f3f3f;
const int maxn=1e5+5;
const int MOD=5e5+5;

typedef pair <string, int> st;  //?子

map <string, int> num;  //映射

int dir[4] = {-1, 1, 4, -4};  //可能的移?策略

void bfs()
{
    queue <st> que;
    num["01234567"] = 0;//映射的是改到初状?需要的?奏数
    que.push(st("01234567", 0));  //初状?入?，0表示??数

    while(!que.empty())
    {
        string s = que.front().first;
        int cur = que.front().second;
        que.pop();

        for(int i = 0; i < 4; i++)
        {
            string ns = s;
            int nxt = cur + dir[i];  //nxt和cur表示0的位置和能与0交?的位置
            if(nxt < 0 || nxt > 7|| nxt == 3 && cur == 4 || nxt == 4 && cur == 3) continue;
            swap(ns[cur], ns[nxt]);
            
            if(!num.count(ns))
            {
                //不能用num[ns]（?奏数），不然初状?（?奏?0，??次数?1），会?致初状?被改??
                num[ns] = num[s] + 1;
                que.push(st(ns, nxt));
            }
        }
    }
}

int main()
{
    bfs();
    string s;
    
    while(cin >> s)
    {
        for(int i = 0; i < 7; i++)
        {
            char x;
            cin >> x;
            s += x;
        }
        cout << num[s] << endl;
    }

    return 0;
}

/*
?目附?
?出0~7的序列（2*4），只能0和周?数字交?，?最少交?多少次可以是?出的序列?成0 1 2 3 4 5 6 7。
有一个2*4的8个格子
0 1 2 3
4 5 6 7
是最最初的状?
0代表?里没有放?牌，其他数字表示放了相?数字的?牌。
?可以?行如下操作：移?0周?的?牌到0，然后移?后，被移?的那个位置就没有?牌了。
?入??束的?个?牌的位置
比如：
1 0 2 3 4 5 6 7
1 0 2 3
4 5 6 7
只需要把1移?到0的位置，???1最少，?出此最少??。
*/

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

#define int long long

using namespace std;

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> f(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());

    int l = -1;
    int r = 1E6 * 1LL * 1E6;
    while (r - l > 1)
    {
        int m = (l + r) / 2;
        int s = 0;
        for (int i = 0; i < n; i++)
        {
            int need = m / f[i];
            if (a[i] > need) s += a[i] - need;
        }
        if (s > k) l = m;
        else r = m;
    }

    cout << r << "\n";

    return 0;
}


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




class Node {
   public:
   // long vertex;
   vector<long> to;
   vector<long> length;
   int grp;
   Node(){grp = -1;};
};
vector<Node> vGr;

void dfs(int vertex, int group) {
   if (vGr[vertex].grp >= 0) return;
   vGr[vertex].grp = group;
   for (int i = 0; i < vGr[vertex].to.size();i++) {
      dfs(vGr[vertex].to[i],(vGr[vertex].grp+vGr[vertex].length[i])%2);
   }
   return;
};

int main(void) {
   int N;
   cin>>N;
   vGr.resize(N);
   for (int i = 0; i<N-1;i++) {
      long u,v,w;
      cin>>u>>v>>w;
      vGr[u-1].to.push_back(v-1);
      vGr[u-1].length.push_back(w);
      vGr[v-1].to.push_back(u-1);
      vGr[v-1].length.push_back(w);
   }
   dfs(0,0);

   for (int i = 0; i<N;i++) {
      cout<<vGr[i].grp<<endl;
   }
   

   return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

ll digitsum(ll i) {
	ll d = 0;
	while (i > 0) { d += i % 10; i /= 10; }
	return d;
}
int main() {
	double m = 0;
	int K; cin >> K;
	ll x = 0;
	ll d = 1;
	ll table[16] = {
		1,
		10,
		100,
		1000,
		10000,
		100000,
		1000000,
		10000000,
		100000000,
		1000000000,
		10000000000,
		100000000000,
		1000000000000,
		10000000000000,
		100000000000000,
		1000000000000000
	};
	double s[16];
	for (int c = 0; c < K; c++) {
		for (int i = 0; i < 16; i++) {
			s[i] = (double)(x + table[i]) / (double)digitsum(x + table[i]);
		}
		int k = 0;
		double b = s[0];
		for (int i = 1; i < 16; i++) {
			if (b > s[i]) {
				b = s[i];
				k = i;
			}
		}
		x += table[k];
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
)

func main() {
	var n int
	fmt.Scan(&n)

	s := make([]string, 0, n)
	var tmp string
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		s = append(s, tmp)
	}

	for _, v := range s {
		if v == "Y" {
			fmt.Println("Four")
			os.Exit(0)
		}
	}

	fmt.Println("Three")
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, x;
	cin >> n >> x;

	int ans = n, mi = x;
	for(int i=0;i<n;i++){
		int m;
		cin >> m;
		mi = min(mi, m);
		x -= m;
	}
	cout << ans + x / mi << endl;
}

Measured memory_bytes: 256
M = 10 ** 9 + 7
s = gets().strip()

num = 0
q_list = []
d = 1

s.each_char.reverse_each{|c|
	if c != "?"
		num = (num + c.to_i() * d) % 13
	else
		q_list << d
	end
	d = (d * 10) % 13
}

counts = [0] * 13
counts[0] = 1
counts_save = [0] * 13
q_list.each{|d|
	13.times{|i|
		counts_save[i] = counts[i] % M
	}
	(1...10).each{|n|
		r = (d * n) % 13
		13.times{|m|
			counts[(r + m) % 13] += counts_save[m]
		}
	}
}

puts(counts[(13 + 5 - num) % 13] % M)


Measured memory_bytes: 10364
import math

def main():
    A, B = map(int, input().split())

    for i in range(1, 1250):
        if math.floor(0.08*i) == A and math.floor(0.1*i) == B:
            print(i)
            return

    print('-1')
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940