akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) \
  SORT(var);       \
  REVERSE(var)
#define OPTIMIZE_STDIO         \
  ios::sync_with_stdio(false); \
  cin.tie(0);                  \
  cout.precision(10);          \
  cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
  ll x;
  mint() : x(0) {
  }
  mint(ll x) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint& r) {
    if ((x += r.x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint& operator-=(const mint& r) {
    if ((x -= r.x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint& operator*=(const mint& r) {
    if ((x *= r.x) > MOD) {
      x %= MOD;
    }
    return *this;
  }
  mint& operator++() {
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint operator++(int) {
    mint ret = x;
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return ret;
  }
  mint& operator--() {
    if ((--x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint operator--(int) {
    mint ret = x;
    if ((--x) < 0) {
      x += MOD;
    }
    return ret;
  }
  mint operator+(const mint& r) {
    mint ret;
    return ret = x + r.x;
  }
  mint operator-(const mint& r) {
    mint ret;
    return ret = x - r.x;
  }
  mint operator*(const mint& r) {
    mint ret;
    return ret = x * r.x;
  }
  mint operator-() {
    return mint() - *this;
  }
  bool operator<(const mint& a) {
    return x < a.x;
  }
  bool operator>(const mint& a) {
    return x > a.x;
  }
  bool operator<=(const mint& a) {
    return x <= a.x;
  }
  bool operator>=(const mint& a) {
    return x >= a.x;
  }
  bool operator==(const mint& a) {
    return x == a.x;
  }
  bool operator!=(const mint& a) {
    return x != a.x;
  }
};
ostream& operator<<(ostream& os, const mint& r) {
  os << r.x;
  return os;
}
ostream& operator>>(ostream& os, const mint& r) {
  os >> r.x;
  return os;
}

void solve(istream& cin, ostream& cout) {
  ll x;
  cin >> x;
  long double a = 100;
  int i = 0;
  while (true) {
    a *= 1.01;
    ll b = ll(a);
    a = b;
    i++;
    if (a >= x) break;
  }
  cout << i << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


//System.out.println();
public class Main implements Runnable { //クラス名はMain

    public static void main(String[] args) {
    	Thread.setDefaultUncaughtExceptionHandler((t,e)->System.exit(1));
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行
    }

    public void run() {
    	try {
    	FastScanner sc = new FastScanner(System.in);
        int H = sc.nextInt();
        int A = sc.nextInt();

        if(H%A >0) {
        	System.out.println(H/A +1);
        }else {
        	System.out.println(H/A);
        }

    	}catch(Exception e) {
    		e.printStackTrace();
    	}

    }
}


//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 28372
from math import gcd
inpl = lambda: list(map(int,input().split()))
def primes(N):
    P = []
    firstfactor = [1]*N
    for i in range(2,N):
        sieve = 1
        for p in P:
            if p*p > i:
                break
            elif i % p == 0:
                sieve = 0
                firstfactor[i] = p
                break
        if sieve == 0:
            continue
        else:
            firstfactor[i] = i
            P.append(i)
    return P, firstfactor

N = int(input())
A = inpl()

g = A[0]
for a in A:
    g = gcd(g,a)
if g > 1:
    print('not coprime')
    exit()

ff = primes(max(A)+1)[1]
st = set()
for a in A:
    prev = 0
    while a > 1:
        p = ff[a]
        a //= p
        if p == prev:
            continue
        elif p in st:
            print('setwise coprime')
            exit()
        else:
            prev = p
            st.add(p)
print('pairwise coprime')


Measured memory_bytes: 189412
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  vector<int> sx(N);
  vector<int> sy(M);
  for (int i=0;i<N;i++) {
    cin>>sx[i];
  }
  for (int i=0;i<M;i++) {
    cin>>sy[i];
  }
  int XMAX = X;
  int YMIN = Y;
  for (int i=0;i<N;i++) {
    XMAX = max(XMAX,sx[i]);
  }
  for (int i=0;i<M;i++) {
    YMIN = min(YMIN,sy[i]);
  }
  if (XMAX<YMIN) {
    cout<<"No War"<<endl;
  }
  else {
    cout<<"War"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
 
struct Tuple {
  int a;
  int b;
  int c;
};
 
int main() {
  int n;
  std::cin >> n;
  
  std::vector<Tuple> t(n);
  for (auto&& ti : t) std::cin >> ti.a >> ti.b >> ti.c;
 
  std::vector<Tuple> h(n);
  h[0] = t[0];
  for (int i = 1; i < n; ++i) {
    h[i].a = t[i].a + std::max(h[i-1].b, h[i-1].c);
    h[i].b = t[i].b + std::max(h[i-1].a, h[i-1].c);
    h[i].c = t[i].c + std::max(h[i-1].a, h[i-1].b);
  }
  const auto& hn = h[n-1];
  std::cout << std::max({hn.a, hn.b, hn.c}) << std::endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define pb push_back
#define endl "\n"

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    set<ll> s;
    ll n;
    cin>>n;
    ll k; cin>>k;
    for (int i=0 ; i<k ; i++)
    {
        ll di;
        cin>>di;
        for (int j=0 ; j<di ; j++)
        {   ll h; cin>>h;
            s.insert(h);
        }
    }
    cout<<n-s.size();

    return 0;
}


Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(1000000)

n, m = map(int, input().split())
friends = [[] for i in range(n)]


def dfs(i):
    ans[-1] += 1
    flg[i] = 1
    for j in friends[i]:
        if not flg[j]:
            dfs(j)
    return


for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    friends[a].append(b)
    friends[b].append(a)

flg = [0]*n
ans = []

for i in range(n):
    ans.append(0)
    if not flg[i]:
        dfs(i)

print(max(ans))

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T>
T vec_sum(V<T> v, T init_val=0){return accumulate(ALL(v),T(init_val));}

int main(){
    LL N,K;
    cin>>N>>K;
    LL N_mod_K = N%K;
    cout<<min(N_mod_K,abs(N_mod_K-K))<<endl;
    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> h(n), diffs(n);
  for (auto&& e : h) {
    cin >> e;
  }
  adjacent_difference(cbegin(h), cend(h), begin(diffs));
  auto result = remove_if(begin(diffs), end(diffs), [](auto&& n){return n <= 0;});
  auto ans = accumulate(begin(diffs), result, 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int N = 1005;
const int M = 100005;
const int S = 1001, T = 1002;
const int INF = 0x3f3f3f3f;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

char g[N];
int n, m;
int level[N], q[N], head, tail;

struct Edge {
	int v, w, nxt;
}e[M];
int first[N], used[N], eCnt;

inline void AddEdge(int u, int v, int w) {
	e[++eCnt].v = v;
	e[eCnt].w = w;
	e[eCnt].nxt = first[u];
	first[u] = eCnt;
}

inline void Add(int u, int v, int w) {
	AddEdge(u, v, w);
	AddEdge(v, u, 0);
}

bool Layer() {
	for (int i=1;i<=T;++i) {
		level[i] = -1;
		used[i] = first[i];
	}
	level[S] = 0;
	q[head=tail=1] = S;
	while (head <= tail) {
		int u = q[head++];
		if (u == T) return 1;
		for (int i=first[u];i;i=e[i].nxt) {
			int v = e[i].v;
			if (e[i].w > 0 && level[v] == -1) {
				level[v] = level[u] + 1;
				q[++tail] = v;
			}
		}
	}
	return 0;
}

int DFS(int u, int flow) {
	if (u == T) return flow;
	int ret = 0;
	for (int i=used[u];i;i=e[i].nxt, used[u]=i) {
		int v = e[i].v;
		if (e[i].w > 0 && level[v] == level[u] + 1) {
			int tmp = DFS(v, min(flow, e[i].w));
			e[i].w -= tmp;
			e[i^1].w += tmp;
			flow -= tmp;
			ret += tmp;
			if (!flow) break;
		}
	}
	return ret;
}

void init() {
	read(n); read(m);
	eCnt = 1;
	for (int i=1;i<=n;++i) {
		scanf("%s", g + 1);
		for (int j=1;j<=m;++j) {
			if (g[j] == '.') continue;
			Add(i, n+j, 1);
			Add(n+j, i, 1);
			if (g[j] == 'S') {
				Add(S, i, INF);
				Add(S, n+j, INF);
			} else if (g[j] == 'T') {
				Add(i, T, INF);
				Add(n+j, T, INF);
			}
		}
	}
}

void solve() {
	int ans = 0;
	while (Layer()) {
		ans += DFS(S, INF);
	}
	printf("%d\n", (ans > n*m)? -1 : ans);
}

int main() {
	init();
	solve();
	return 0;
}


Measured memory_bytes: 768
from collections import defaultdict
N = int(input())

if N == 1:
    print(1)
    exit()

xy = []
for i in range(N):
    x, y = map(int, input().split())
    xy.append((x, y))

d = defaultdict(int)

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        p, q = (xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
        d[(p, q)] += 1

print(N-max(d.values()))


Measured memory_bytes: 3828
/*input
aaaccacabaababc
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long 
#define ld long double
#define pii pair<int,int>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e12;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1){
            res=(res*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=1e3+5;
const ll maxlg=__lg(maxn)+2;
string arr[maxn][15];
vector<pii> v[maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    string s;
    cin>>s;
    string pv="";
    string cur="";
    int ans=0;
    REP(i,sz(s)){
        cur+=s[i];
        if(cur!=pv){
            ans++;
            pv=cur;
            cur.clear();
        }
    }
    cout<<ans;
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;


const int MAXN = 100005;
set<int> G[MAXN];
int parent[MAXN];

int main() {
    int N, M; cin >> N >> M;
    rep(i, M) {
        int a, b; cin >> a >> b; // 1-indexed
        G[a].insert(b);
        G[b].insert(a);
    }

    if (M % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }

    memset(parent, -1, sizeof(parent));

    queue<int> que; //bfs用
    stack<int> stk; //有向グラフ構成用

    que.push(1); //1 を根とする
    stk.push(1);

    while (!que.empty()) {
        int a = que.front(); que.pop();

        for (auto x : G[a]) {
            if (x == parent[a]) continue;
            if (parent[x] != -1) continue;
            que.push(x);
            stk.push(x);
            parent[x] = a;
        }
    }

    vi C, D;

    while (stk.size() != 1) {
        int a = stk.top(); stk.pop();

        if (G[a].size() % 2 == 0) {
            for (auto x : G[a]) {
                C.pb(a); D.pb(x);
                G[x].erase(a);
            }
        }
        else {
            for (auto x : G[a]) {
                if (x == parent[a]) continue;
                C.pb(a); D.pb(x);
                G[x].erase(a);
            }
        }
    }

    int a = 1;

    if (G[a].size() % 2 == 1) {
        cout << -1 << endl;
    }
    else {
        for (auto x : G[a]) {
            C.pb(a); D.pb(x);
            G[x].erase(a);
        }

        rep(i, M) {
            cout << C[i] << " " << D[i] << endl;
        }
    }

    return 0;

}

Measured memory_bytes: 17216
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric,std.math,std.random,std.concurrency;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split();foreach(i,ref arg; args){ if (i >= line.length) return;arg = line[i].to!(typeof(arg));}};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
int read(){int n;read(n);return n;}
void times(int n,void delegate() stmt){foreach(i;iota(n))stmt();}
auto infIota = (int i=0) => new std.concurrency.Generator!int({for(;;)yield(i++);});
auto dot(R1,R2)(R1 a,R2 b){ElementType!(R1) res=0;for(;!a.empty&&!b.empty;a.popFront(),b.popFront())res+=a.front*b.front;return res;}

int calc(int n){
	if (n < 10) return 0;
	int [] ns;
	while(n){ns ~= n % 10;n /= 10;}
	int [] res;
	auto tens = ()=> iota(ns.length).map!"10^^a";
	foreach(i;1 .. ns.length){
		res ~= ns[0..i].dot(tens()) * ns[i..$].dot(tens());
	}
	return 1 + calc(res.reduce!(max));
}
void main(){ 
	read().times({ read().calc.writeln; });
}

Measured memory_bytes: 2996
#include<bits/stdc++.h>
#include <iostream>
#include<sstream>
using namespace std;
int main()
{
    char init[100];
    char add[100];

    cin>>init>>add;
    strcat(init, add);
  stringstream ss(init);

  int i;
  ss>>i;
  int m;
  m=sqrt(i);
  if(m*m==i)
  {
      cout<<"Yes"<<endl;
  }

  else
    cout<<"No"<<endl;

}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define int long long

signed main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n) if (a[i] > x) ans += a[i] - x, a[i] = x;
    int s;
    rep(i, n-1) if ((s = a[i] + a[i+1]) > x) {
        int d = s - x;
        ans += d;
        a[i+1] -= d;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
		as[i]--
	}
	ts := make([]int, 0)
	m := make(map[int]int)
	ts = append(ts, 0)
	m[0] = 0
	var cnt int
	for cnt < k {
		t := ts[len(ts)-1]
		if p, ok := m[as[t]]; ok {
			cycle := cnt - p + 1
			offset := (k - p) % (cycle)
			fmt.Println(ts[p+offset] + 1)
			return
		}
		ts = append(ts, as[t])
		cnt++
		m[as[t]] = cnt
	}
	fmt.Println(ts[len(ts)-1] + 1)
}

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 20028
N = int(input())
input_line = [input() for i in range(1)]
p = list(map(int,input_line[0].split()))

counter = 0
for i in range(0,N-2):
    b = p[i:i+3]
    b.sort()
    if b[1] == p[i:i+3][1]:
        counter += 1
print(counter)

Measured memory_bytes: 3064
from collections import defaultdict

from math import factorial
# 組み合わせ
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))


def main():
    num = int(input())

    parent_dic = [-1 for i in range(num)]
    now_dic = defaultdict(set)
    data_dic = []

    for i in range(num - 1):
        a, b = map(int, input().split())
        now_dic[a].add(b)
        now_dic[b].add(a)
        data_dic.append([a, b])

    ans_omomi = [-1 for i in range(num + 1)]

    omomi_data = list(map(int, input().split()))
    omomi_data.sort(reverse=True)

    # node_omomi = sorted(node_omomi.items(), key=lambda x: x[1])

    now_data = set()
    now_data.add(1)
    next_data = set()

    count = 0
    ans_omomi[1] = omomi_data[count]

    count += 1



    while len(now_data) > 0:
        for ele_pare in now_data:
            for ele in now_dic[ele_pare]:
                if ans_omomi[ele] != -1:
                    continue
                ans_omomi[ele] = omomi_data[count]
                count += 1
                next_data.add(ele)
        now_data = next_data
        next_data = set()

    # print(ans_omomi)
    # print(data_dic)


    final_omomi = 0
    for i in range(num - 1):
        kari = min(ans_omomi[data_dic[i][0]], ans_omomi[data_dic[i][1]])
        final_omomi += kari
    print(final_omomi)
    print(' '.join(list(map(str, ans_omomi[1:]))))


if __name__ == '__main__':
    main()



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

int main() {
  int n;
  cin >> n;
  bool answer = true;
  std::vector<int64_t> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    if(a.at(i) % 2 != 0){
      answer = false;
    }
  }
  int count = 0;
  while(answer){
    count++;
    for(int i = 0; i < n; i++){
      a.at(i) = a.at(i) / 2;
      if(a.at(i) % 2 != 0){
        answer = false;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;

            List<Integer>[] edges = new List[N];
            for (int i = 0; i < N; i++) {
                edges[i] = new ArrayList<>();
            }

            for (int i = 0; i < N - 1; i++) {
                int a = sc.nextInt() - 1;
                int b = sc.nextInt() - 1;
                edges[a].add(b);
                edges[b].add(a);
            }

            int[] d = new int[N];
            for (int i = 0; i < N; i++) {
                d[i] = Integer.MAX_VALUE;
            }
            d[u] = 0;
            dfs(u, d, edges);

            int[] e = new int[N];
            for (int i = 0; i < N; i++) {
                e[i] = Integer.MAX_VALUE;
            }
            e[v] = 0;
            dfs(v, e, edges);

            int q = 0;
            for (int i = 0; i < N; i++) {
                if (d[i] < e[i]) {
                    if (e[i] > q) {
                        q = e[i];
                    }
                }
            }

            if (q == 0) {
                System.out.println(0);
            } else {
                System.out.println(q - 1);
            }
        }
    }

    static void dfs(int u, int[] d, List<Integer>[] edges) {
        for (Integer nu : edges[u]) {
            if (d[nu] == Integer.MAX_VALUE) {
                d[nu] = d[u] + 1;
                dfs(nu, d, edges);
            }
        }
    }

}


Measured memory_bytes: 111104
import java.io.*;
import java.util.*;

public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;

  private static PrintWriter _err = new PrintWriter(System.err);

  private static long MOD = 1_000_000_007;

  private int N;
  private int[] A;

  private void solve(Scanner sc, PrintWriter out) {
    N = sc.nextInt();
    A = new int[N];
    for (int i = 0; i < N; ++i) {
      A[i] = sc.nextInt();
    }

    boolean[] b = new boolean[N];
    long total = 1;
    for (int i = 0; i < N; ++i) {
      if (!b[(N - A[i]) / 2]) {
        b[(N - A[i]) / 2] = true;
      } else if (!b[N - ((N - A[i]) / 2) - 1]) {
        b[N - ((N - A[i]) / 2) - 1] = true;
        total <<= 1;
        total %= MOD;
      } else {
        out.println(0);
        return;
      }
    }
    out.println(total);
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  private long ceil2pow(long n) {
    if (n == 0) {
      return 1;
    }
    n--;
    n |= (n >>> 1);
    n |= (n >>> 2);
    n |= (n >>> 4);
    n |= (n >>> 8);
    n |= (n >>> 16);
    n++;
    return n;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();

    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();

    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}

Measured memory_bytes: 31820
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <functional>
#include <cassert>
#include <iomanip>
#include <array>
#include <time.h>
#include <limits.h>
#pragma comment(lib, "winmm.lib")
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)


using namespace std;

class task{
public:
	string name;
	int time;
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif

	queue<task> Q;
	int n, quantum, sum = 0;

	cin >> n >> quantum;
	string tmp1, tmp2;
	rep(i, n){
		cin >> tmp1 >> tmp2;
		Q.push({ tmp1, stoi(tmp2) });
	}
	while (!Q.empty()){
		if (Q.front().time <= quantum){
			
			sum += Q.front().time;
			cout << Q.front().name << " " << sum << endl;
			Q.pop();
		}
		else{
			sum += quantum;
			string str = Q.front().name; int in = Q.front().time - quantum;
			Q.push({ str, in });
			Q.pop();
		}
	}
	
	return 0;
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define lp(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)4e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1 << (x))
using namespace std;

int main(){
	int K, N;
	cin>>N>>K;
	vector<PLL> pos(N);
	vector<LL> xs, ys;
	foreach(i, pos){
		cin>>i.first>>i.second;
		xs.push_back(i.first);
		ys.push_back(i.second);
	}
	sort(ALL(xs));
	sort(ALL(ys));
	LL ans = INFLL;
	for(int xl=0;xl<N;++xl){
		for(int xr=xl;xr<N;++xr){
			for(int yb=0;yb<N;++yb){
				for(int yt=yb;yt<N;++yt){
					int count = 0;
					foreach(i, pos){
						if(xs[xl]<=i.first&&i.first<=xs[xr]&&ys[yb]<=i.second&&i.second<=ys[yt])++count;
					}
					if(count>=K){
						ans = min(ans, (xs[xr]-xs[xl])*(ys[yt]-ys[yb]));
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
    
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef set<int> SI;
typedef long long LL;
    
#ifdef DEBUG
const bool debug = true;
#else
const bool debug = false;
#endif

// #define MULTI_TASK true

const int inf = 1000 * 1000 * 1000;
const int MAKSN = 1000 * 1000 + 13;
const LL MOD = 123456789LL;
int n, m, k, l, x, y, a, b;
string s;
vector<int> v;
int dist[MAKSN];

void zeruj() {
    v.clear();
}

void readIn() {
    cin >> n >> x >> y;

}
        
void solve() {
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int d = j - i;
            d = min(d, (abs(x - i) + abs(y - j) + 1));
            // cerr << i <<  " " << j << " " << d << "\n";
            dist[d]++;
        }
    }
    

    for(int i = 1; i < n; i++) {
        cout << dist[i] << "\n";
    }   
}

int main() {
    ios_base::sync_with_stdio(0);
#ifdef MULTI_TASK
    int test;
    cin >> test;
    while (test--) {
#endif
        zeruj();
        readIn();
        solve();
#ifdef MULTI_TASK
    }
#endif 
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int h, n;
  cin >> h >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
  }
  const char* s = sum >= h ? "Yes" : "No";
  cout << s << endl;
  return 0;
}


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

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    string s;
    cin >> s;
    vector<int> x;
    for(auto c: s)
        x.push_back(c - '0');

    int n = x.size();
    
    ll ans = 0;
    for(int bit=(1<<(n-1))-1; bit >= 0; bit--){
        ll now = x[0];
        ll sumx = 0;
        FOR(i, 0, n-1){
            if((bit >> i) & 1){
                sumx += now;
                now = x[i+1];
            }
            else{
                now = 10 * now + x[i+1];
            }
        }
        sumx += now;
        ans += sumx;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


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


def LS(): return list(sys.stdin.readline().rstrip().split())


while 1:
    a = LS()
    if a[1] == '?':
        break
    if a[1] == '+':
        print(int(a[0]) + int(a[2]))
    if a[1] == '-':
        print(int(a[0]) - int(a[2]))
    if a[1] == '*':
        print(int(a[0]) * int(a[2]))
    if a[1] == '/':
        print(int(a[0]) // int(a[2]))



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

int A,B,C,D,E;
vector<int> N;
int main(void){
  cin>>A>>B>>C>>D>>E;
  N.push_back((10-A%10)%10);
  N.push_back((10-B%10)%10);
  N.push_back((10-C%10)%10);
  N.push_back((10-D%10)%10);
  N.push_back((10-E%10)%10);
  sort(N.begin(),N.end());
  cout << A+B+C+D+E+N[0]+N[1]+N[2]+N[3] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    string s;
    cin>>s;
    char a=s[s.size()-1];
    if(a=='2'||a=='4'||a=='5'||a=='7'||a=='9') cout<<"hon";
    if(a=='0'|a=='1'||a=='6'||a=='8') cout<<"pon";
    if(a=='3') cout<<"bon";
}

Measured memory_bytes: 3628
#include<stdio.h>

int main(void)
{
    int n, j=0;
    int a[200000];
    int count=0, num=1;

    scanf("%d", &n);

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

    for(int i=0;i<n;i++){
        if(a[i]==num) num++;    
        else count++;
    }

    if(num==1) count=-1;

    printf("%d", count);

    return 0;
}

Measured memory_bytes: 896
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	double calc() {
		
		return 0;
	}
	
	void run() {
		while (true) {
			if (!sc.hasNext()) break;
			int a = sc.nextInt(), l = sc.nextInt(), x = sc.nextInt();
			double ans = (double)a/2*Math.sqrt(l*l-(double)a*a/4.0);
			double lower = 0.0, upper = 1000;
			double mid;
			while (upper - lower > 1e-10) {
				mid = (lower+upper)/2;
				double t = Math.sqrt((double)l*l/4 + mid*mid);
				if (t+t < l+x) {
					lower = mid;
				} else {
					upper = mid;
				}
			}
			ans += (double)l*(lower+upper)/2;
			out.printf("%.10f\n", ans);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 28348
#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<int,int>;

int main(){
    int N, K;
    cin >> N >> K;
    int ans = 1;
    rep(i, N) ans = min(ans*2, ans+K);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */

int		a[200001];
/* main *************************************************************/
int main()
{
	int		b,c,i,j,k,n,m,x,y,ans = 0;

	scanf("%d", &n);
	for(i=1;i<=n;i++) {
		scanf("%d", &a[i]);
	}
	
	k = 1;
	for(i=1;i<=n;i++) {
		if (a[i] == k) {
			k++;
		} else {
			ans++;
		}
	}
	
	if (ans == n) ans = -1;

	printf("%d\n",ans);


	return 0;
}


Measured memory_bytes: 896
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {
	int n,x;
	cin>>n>>x;
	int ans = -1;
	while(n--) {
		int val;
		cin>>val;
		if(ans==-1)ans = abs(val-x);
		else 
		ans = __gcd(abs(val-x),ans);
	}
	cout<<ans;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;
 
const int MAXN = 200200;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;
 
template<typename T> inline void CheckMax(T &A, T B) {
	A < B ? A = B : A;
}
 
template<typename T> inline void CheckMin(T &A, T B) {
	A > B ? A = B : A;
}
 
template <typename T> inline void read(T &x) {
    int c = getchar();
    bool f = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            f = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (f) {
        x = -x;
    }
}

LL n;
long long k;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
#define X first
#define Y second

LL num[100], len[100], add[100], ans;

int Find(LL x) {
	for(int i = 50; i >= 0; i--) {
		if(x >= len[i]) return i;
	}
	return -1;
}

signed main() {
	read(n), read(k);
	num[0] = len[0] = 1;
	for(int i = 1; i <= 50; i++) num[i] = num[i - 1] * 2 + 1;
	for(int i = 1; i <= 50; i++) len[i] = len[i - 1] * 2 + 3;
	if(k == len[n]) {
		cout << num[n] << endl;
		return 0;
	}
	long long l = 1, m = n - 1;
	while(l < k) {
		if(l == k) break;
		for(LL i = m; i >= 0; i--) {
			if(k >= len[i] + l) {
				ans += num[i];
				l += len[i];
				m = i;
				break;
			}
			l++;
			if(l == k) break;
		}
		if(l == k) break;
		ans++, l++;
		if(l == k) break;
	}
	cout << ans << endl;
	return 0;
}

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


int main() {
  int n;
  string s,t;
  cin>>n>>s>>t;
  string ans=s+t;
  for(int i=n; i>=1; i--){
    string s_=s.substr(n-i, i);
    string t_=t.substr(0,i);
    if(s_==t_){ans=s.substr(0,n-i)+t;break;}
  }
  cout<<ans.size();
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
using namespace std;    
const int N = int(3e5), mod = int(1e9)  + 7; 

ll q,h,s,d;

ll n;

int main () {
	cin >> q >> h >> s >> d;
	cin >> n;
	ll r1, r2;
	r1 = min(q * 4, min(h * 2, s));
	r2 = min(r1 * 2, d);
	ll ans = n / 2 * r2;
	if(n & 1) ans += r1;
	cout << ans;
	

return 0;
}

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

int main(){
    int n;
    cin>>n;
    double ans;
    if(n%2==0){
        ans = 0.5000000000;
    }
    else{
        ans=(n+1)/2.0/n;
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
ll a[100005];
ll b[100005];
ll c[100005];
ll dp[105][100005];
ll n;
ll  rec(ll i,ll rem)
{
	if(i==n)
		return 0;
	ll &res=dp[i][rem];
	if(res!=-1)
		return res;
	
	res=0;
	if(rem-a[i]>=0)
		res=max(rec(i+1,rem-a[i])+b[i],rec(i+1,rem));
	else
		res=rec(i+1,rem);
	return res;
}


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

	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<rec(0,w);
	
	
 
	return 0;
}

Measured memory_bytes: 84224
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <initializer_list>
#define EXPSIZE 4194304
#define SIZE 22

  const int mod = (int)1e9 + 7;
  int can[SIZE][SIZE], dp[EXPSIZE];

  inline int add(int a, int b, int mod) {a += b; return a >= mod ? a - mod : a;}

  int main(void) {
        int n;
        scanf("%d",&n);
        for(int i=0; i<n; i++) for(int j=0; j<n; j++) scanf("%d",&can[i][j]);

        dp[0] = 1;
        for(int mask=0; mask<(1<<n)-1; mask++) {
                int a = __builtin_popcount(mask);
                for(int b=0; b<n; b++) {
                        if(can[a][b] && !(mask & (1 << b))) {
                                int mask2 = mask | (1 << b);
                                dp[mask2] = add(dp[mask2], dp[mask], mod);
                        }
                }
        }

        printf("%d", dp[(1<<n)-1]);
        return 0;
  }










Measured memory_bytes: 10368
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

max_x,min_y = max(x),min(y)

ans = ''
for Z in range(X+1,Y+1):
    if max_x < Z and Z <= min_y:
        ans = 'No '

print(ans+'War')


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

int p[1000010];

int main(){
	int n;
	
	for(int i = 2 ; i <= 1000000 ; i++){
		p[i] = 1;
		for(int j = 2 ; j*j <= i ; j++){
			if( i % j == 0 ){
				p[i] = 0;
				break;
			}
		}
		p[i] += p[i-1];
	}
	
	while(cin >> n){
		cout << p[n] << endl;
	}
}

Measured memory_bytes: 6864
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, H;
  cin >> N >> H;
  Vll A(N), B(N);
  ll max_a = 0;
  REP(i, N)
  {
    ll a, b;
    cin >> a >> b;
    max_a = max(max_a, a);
    A[i] = a;
    B[i] = b;
  }
  ll dam = 0;
  priority_queue<ll> which;
  REPx(b, B)
  {
    if (b >= max_a)
    {
      dam += b;
      which.push(b);
    }
  }
  ll ans = 0;
  while(H > 0)
  {
    if (H <= dam)
    {
      ll b = which.top(); which.pop();
      H -= b;
    }
    else H -= max_a;
    ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define MAXS 500007
#define INF 2147483647
 
#define mp(a, b) make_pair(a,b)
#define pb(a) push_back(a)
#define INP freopen("input.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define STREE int bch = no*2, mid = (l+r)/2
#define ALL(a) a.begin(), a.end()
 
using namespace std;
typedef long long ll;
typedef vector < int > vi;
typedef pair < int, int > pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int n, k;
int arr[MAXS];
int dp[MAXS];

ll solve(int i){
  if(i == n) return 0;
  if(i > n) return INF;
  if(dp[i] != -1) return dp[i];
  ll ans = INF;
  for(int j = 1; j <= k; ++j){
    ans = min(ans, solve(i+j) + abs(arr[i] - arr[i+j]));
  }
  return dp[i] = ans;
}



int main(){
  cin >> n >> k;
  for(int i = 1; i <= n; ++i){
    cin >> arr[i];
  }
  arr[0] = arr[1];
  memset(dp, -1, sizeof dp);
  cout << solve(0) << endl;
}

Measured memory_bytes: 7296
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,0);
  switch(input){
    case "SUN":
      myout("7");
      break;
    case "MON":
      myout("6");
      break;
    case "TUE":
      myout("5");
      break;
    case "WED":
      myout("4");
      break;
    case "THU":
      myout("3");
      break;
    case "FRI":
      myout("2");
      break;
    case "SAT":
      myout("1");
      break;
              }
}

Main(myin());


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

int main() {
    int n; cin >> n;
    vector<int> a_even(n/2);
    vector<int> a_odd(n/2);
    rep(i,n/2) cin >> a_even[i] >> a_odd[i];

    vector<int> cnt_even(100000);
    for(int b : a_even) cnt_even[b-1]++;
    vector<int> cnt_odd(100000);
    for(int b : a_odd) cnt_odd[b-1]++;

    vector<pair<int,int>> pair_even;
    rep(i,100000) pair_even.push_back(make_pair(cnt_even[i],i));
    vector<pair<int,int>> pair_odd;
    rep(i,100000) pair_odd.push_back(make_pair(cnt_odd[i],i));

    sort(pair_even.begin(),pair_even.end());
    reverse(pair_even.begin(),pair_even.end());
    sort(pair_odd.begin(),pair_odd.end());
    reverse(pair_odd.begin(),pair_odd.end());

    int m;
    int pe01 = pair_even[0].first;
    int pe02 = pair_even[0].second;
    int po01 = pair_odd[0].first;
    int po02 = pair_odd[0].second;
    int pe11 = pair_even[1].first;
    int pe12 = pair_even[1].second;
    int po11 = pair_odd[1].first;
    int po12 = pair_odd[1].second;
    if(pe02 == po02) m = max(pe01+po11,pe11+po01);
    else m = pe01+po01;

    cout << n-m << endl;
}


Measured memory_bytes: 3700
#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<int,int>;
int main(){
  int n=0,ac=0,wa=0,tle=0,re=0;
  string s;
  cin >> n;
  rep(i,n){
  string s;
    cin >> s;
  if(s == "AC") ac++;
     else if(s == "WA") wa++;
     else if(s == "TLE") tle++;
     else if(s == "RE") re++;
  }
  cout << "AC x " << ac <<endl;
  cout << "WA x " << wa <<endl;
  cout << "TLE x " << tle <<endl;
  cout << "RE x " << re <<endl;
    return 0;
}


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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> B[i];
    }
    vector<pair<int, int>> ba(N);
    for (int i = 0; i < N; ++i) {
        ba[i] = {B[i], A[i]};
    }
    sort(begin(ba), end(ba));
    sort(begin(A), end(A));
    map<int, int> pos;
    for (int i = 0; i < N; ++i) {
        pos[ba[i].second] = i;
        if (A[i] > ba[i].first) {
            cout << "No\n";
            return 0;
        }
    }
    for (int i = 0; i + 1 < N; ++i) {
        if (A[i + 1] <= ba[i].first) {
            cout << "Yes\n";
            return 0;
        }
    }
    vector<int> vis(N, 0);
    int i = A[0];
    while (!vis[i]) {
        vis[i] = 1;
        int need = pos[A[i]];
        //cout << i << "->" << need << endl;
        i = need;
    }
    if (count(begin(vis), end(vis), 0) == 0) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }

    return 0;
}

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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	int a, b;
	cin >> a >> b;
	if((a - b) % 2 == 0) cout << (a + b) / 2 << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

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

using namespace std;

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

using ll = long long;

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
    cout << '[';
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len-1) s << ", ";
	}
    cout << ']';
	return s;
}

vector<long long> calc_divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n;
	cin >> n;

	int ans = 100;
	vector<ll> div = calc_divisor(n);
	for(auto x : div){
		if(x*x > n) break;
		ll y = n/x;

		int tmp = max(to_string(x).size(), to_string(y).size());
		ans = min(ans, tmp);
	}

	ppp(ans);


    return 0;
}


Measured memory_bytes: 256